question_list_admin.inc.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Code library for HotPotatoes integration.
  5. * @package chamilo.exercise
  6. * @author
  7. */
  8. /**
  9. * QUESTION LIST ADMINISTRATION
  10. *
  11. * This script allows to manage the question list
  12. * It is included from the script admin.php
  13. *
  14. * @author Olivier Brouckaert
  15. */
  16. // ALLOWED_TO_INCLUDE is defined in admin.php
  17. if(!defined('ALLOWED_TO_INCLUDE')) {
  18. exit();
  19. }
  20. /*
  21. // moves a question up in the list
  22. if(isset($_GET['moveUp'])) {
  23. $check = Security::get_token('get');
  24. if ($check) {
  25. $objExercise->moveUp(intval($_GET['moveUp']));
  26. $objExercise->save();
  27. }
  28. Security::clear_token();
  29. }
  30. // moves a question down in the list
  31. if(isset($_GET['moveDown'])) {
  32. $check = Security::get_token('get');
  33. if ($check) {
  34. $objExercise->moveDown(intval($_GET['moveDown']));
  35. $objExercise->save();
  36. }
  37. Security::clear_token();
  38. }
  39. */
  40. // deletes a question from the exercise (not from the data base)
  41. if($deleteQuestion) {
  42. // if the question exists
  43. if($objQuestionTmp = Question::read($deleteQuestion)) {
  44. $objQuestionTmp->delete($exerciseId);
  45. // if the question has been removed from the exercise
  46. if($objExercise->removeFromList($deleteQuestion)) {
  47. $nbrQuestions--;
  48. }
  49. }
  50. // destruction of the Question object
  51. unset($objQuestionTmp);
  52. }
  53. ?>
  54. <style>
  55. .ui-state-highlight { height: 30px; line-height: 1.2em; }
  56. /*Fixes edition buttons*/
  57. .ui-accordion-icons .ui-accordion-header .edition a {
  58. padding-left:4px;
  59. }
  60. </style>
  61. <div id="dialog-confirm" title="<?php echo get_lang("ConfirmYourChoice"); ?>">
  62. <p>
  63. <span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;">
  64. </span>
  65. <?php echo get_lang("AreYouSureToDelete"); ?>
  66. </p>
  67. </div>
  68. <script>
  69. $(function() {
  70. $( "#dialog:ui-dialog" ).dialog( "destroy" );
  71. $( "#dialog-confirm" ).dialog({
  72. autoOpen: false,
  73. show: "blind",
  74. resizable: false,
  75. height:150,
  76. modal: false
  77. });
  78. $(".opener").click(function() {
  79. var targetUrl = $(this).attr("href");
  80. $( "#dialog-confirm" ).dialog({
  81. buttons: {
  82. "<?php echo get_lang("Ok"); ?>": function() {
  83. location.href = targetUrl;
  84. $( this ).dialog( "close" );
  85. },
  86. "<?php echo get_lang("Cancel"); ?>": function() {
  87. $( this ).dialog( "close" );
  88. }
  89. }
  90. });
  91. $( "#dialog-confirm" ).dialog("open");
  92. return false;
  93. });
  94. var stop = false;
  95. $( "#question_list h3" ).click(function( event ) {
  96. if ( stop ) {
  97. event.stopImmediatePropagation();
  98. event.preventDefault();
  99. stop = false;
  100. }
  101. });
  102. var icons = {
  103. header: "ui-icon-circle-arrow-e",
  104. headerSelected: "ui-icon-circle-arrow-s"
  105. };
  106. /* We can add links in the accordion header */
  107. $("div > div > div > .edition > div > a").click(function() {
  108. //Avoid the redirecto when selecting the delete button
  109. if (this.id.indexOf('delete') == -1) {
  110. newWind = window.open(this.href,"_self");
  111. newWind.focus();
  112. return false;
  113. }
  114. });
  115. $( "#question_list" ).accordion({
  116. icons: icons,
  117. autoHeight: false,
  118. active: false, // all items closed by default
  119. collapsible: true,
  120. header: ".header_operations",
  121. })
  122. .sortable({
  123. cursor: "move", // works?
  124. update: function(event, ui) {
  125. var order = $(this).sortable("serialize") + "&a=update_question_order";
  126. $.post("<?php echo api_get_path(WEB_AJAX_PATH)?>exercise.ajax.php", order, function(reponse){
  127. $("#message").html(reponse);
  128. });
  129. },
  130. axis: "y",
  131. placeholder: "ui-state-highlight", //defines the yellow highlight
  132. handle: ".moved", //only the class "moved"
  133. stop: function() {
  134. stop = true;
  135. }
  136. });
  137. });
  138. </script>
  139. <?php
  140. echo '<div class="actionsbig">';
  141. //we filter the type of questions we can add
  142. Question :: display_type_menu ($objExercise->feedbacktype);
  143. echo '</div><div style="clear:both;">';
  144. echo '<div id="message"></div>';
  145. $token = Security::get_token();
  146. //deletes a session when using don't know question type (ugly fix)
  147. unset($_SESSION['less_answer']);
  148. if ($nbrQuestions) {
  149. $my_exercise = new Exercise();
  150. //forces the query to the database
  151. $my_exercise->read($_GET['exerciseId']);
  152. $questionList=$my_exercise->selectQuestionList();
  153. if (is_array($questionList)) {
  154. echo '<div id="question_list">';
  155. foreach($questionList as $id) {
  156. //To avoid warning messages
  157. if (!is_numeric($id)) {
  158. continue;
  159. }
  160. $objQuestionTmp = Question :: read($id);
  161. $question_class = get_class($objQuestionTmp);
  162. //$label = $question_class->$explanationLangVar;
  163. $edit_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&type='.$objQuestionTmp->selectType().'&myid=1&editQuestion='.$id.'">'.Display::return_icon('edit.gif',get_lang('Modify')).'</a>';
  164. // this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications
  165. if ($show_quiz_edition) {
  166. $delete_link = '<a id="delete_'.$id.'" class="opener" href="'.api_get_self().'?'.api_get_cidreq().'&exerciseId='.$exerciseId.'&deleteQuestion='.$id.'" >'.Display::return_icon('delete.gif',get_lang('Delete')).'</a>';
  167. //$delete_link = '<a id="delete_'.$id.'" class="opener" href="#">'.Display::return_icon('delete.gif',get_lang('Delete')).'</a>';
  168. }
  169. $edit_link = Display::tag('div',$edit_link, array('style'=>'float:left;padding:0px; margin:0px'));
  170. $delete_link = Display::tag('div',$delete_link, array('style'=>'float:left;padding:0px; margin:0px'));
  171. $actions = Display::tag('div',$edit_link.$delete_link, array('class'=>'edition','style'=>'width:70px; right:10px; margin-top: 0px; position: absolute; top: 10%;'));
  172. echo '<div id="question_id_list_'.$id.'" >';
  173. echo '<div class="header_operations">';
  174. $move = Display::return_icon('move.png',get_lang('Move'), array('class'=>'moved', 'style'=>'margin-bottom:-0.5em;'));
  175. $level = '';
  176. if (!empty($objQuestionTmp->level)) {
  177. $level = '('.get_lang('Difficulty').' '.$objQuestionTmp->level.')';
  178. }
  179. echo Display::tag('span','<a href="#">'.$move.' '.$objQuestionTmp->selectTitle().' '. Display::tag('span',$level.' ['.get_lang('QualificationNumeric').': '.$objQuestionTmp->selectWeighting().']', array('style'=>"right:90px; position: absolute;padding-top: 0.3em;")).'</a>', array('style'=>''));
  180. echo $actions;
  181. echo '</div>';
  182. echo '<div class="question-list-description-block">';
  183. echo '<p>';
  184. //echo get_lang($question_class.$label);
  185. echo get_lang($question_class);
  186. echo '<br />';
  187. //echo get_lang('Level').': '.$objQuestionTmp->selectLevel();
  188. echo '<br />';
  189. showQuestion($id, false, '', '',false, true);
  190. echo '</p>';
  191. echo '</div>';
  192. echo '</div>';
  193. unset($objQuestionTmp);
  194. }
  195. echo '</div>';
  196. }
  197. }
  198. echo '</table></div>';
  199. if(!$nbrQuestions) {
  200. echo Display::display_warning_message(get_lang('NoQuestion'));
  201. }