question_list_admin.inc.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. * @package chamilo.exercise
  16. */
  17. // ALLOWED_TO_INCLUDE is defined in admin.php
  18. if(!defined('ALLOWED_TO_INCLUDE')) {
  19. exit();
  20. }
  21. /*
  22. // moves a question up in the list
  23. if(isset($_GET['moveUp'])) {
  24. $check = Security::get_token('get');
  25. if ($check) {
  26. $objExercise->moveUp(intval($_GET['moveUp']));
  27. $objExercise->save();
  28. }
  29. Security::clear_token();
  30. }
  31. // moves a question down in the list
  32. if(isset($_GET['moveDown'])) {
  33. $check = Security::get_token('get');
  34. if ($check) {
  35. $objExercise->moveDown(intval($_GET['moveDown']));
  36. $objExercise->save();
  37. }
  38. Security::clear_token();
  39. }
  40. */
  41. // deletes a question from the exercise (not from the data base)
  42. if($deleteQuestion) {
  43. // if the question exists
  44. if($objQuestionTmp = Question::read($deleteQuestion)) {
  45. $objQuestionTmp->delete($exerciseId);
  46. // if the question has been removed from the exercise
  47. if($objExercise->removeFromList($deleteQuestion)) {
  48. $nbrQuestions--;
  49. }
  50. }
  51. // destruction of the Question object
  52. unset($objQuestionTmp);
  53. }
  54. ?>
  55. <style>
  56. .ui-state-highlight { height: 30px; line-height: 1.2em; }
  57. </style>
  58. <script>
  59. $(function() {
  60. var stop = false;
  61. $( "#question_list h3" ).click(function( event ) {
  62. if ( stop ) {
  63. event.stopImmediatePropagation();
  64. event.preventDefault();
  65. stop = false;
  66. }
  67. });
  68. $( "#question_list" )
  69. .accordion({
  70. autoHeight: false,
  71. active: false, // all items closed by default
  72. collapsible: true,
  73. header: "> div > h3"
  74. })
  75. .sortable({
  76. cursor: "move", // works?
  77. update: function(event, ui) {
  78. var order = $(this).sortable("serialize") + "&a=update_question_order";
  79. $.post("<?php echo api_get_path(WEB_AJAX_PATH)?>exercise.ajax.php", order, function(reponse){
  80. $("#message").html(reponse);
  81. });
  82. },
  83. axis: "y",
  84. placeholder: "ui-state-highlight", //defines the yellow highlight
  85. handle: ".moved", //only the class "moved"
  86. stop: function() {
  87. stop = true;
  88. }
  89. });
  90. });
  91. </script>
  92. <?php
  93. echo '<div class="actionsbig">';
  94. //we filter the type of questions we can add
  95. Question :: display_type_menu ($objExercise->feedbacktype);
  96. echo '</div><div style="clear:both;">';
  97. echo '<div id="message"></div>';
  98. $token = Security::get_token();
  99. if ($nbrQuestions) {
  100. $my_exercise = new Exercise();
  101. //forces the query to the database
  102. $my_exercise->read($_GET['exerciseId']);
  103. $questionList=$my_exercise->selectQuestionList();
  104. $i=1;
  105. if (is_array($questionList)) {
  106. echo '<div id="question_list">';
  107. foreach($questionList as $id) {
  108. //To avoid warning messages
  109. if (!is_numeric($id)) {
  110. continue;
  111. }
  112. $objQuestionTmp = Question :: read($id);
  113. $question_class = get_class($objQuestionTmp);
  114. $label = $question_class->$explanationLangVar;
  115. $edit_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&type='.$objQuestionTmp->selectType().'&myid=1&editQuestion='.$id.'"><img src="../img/edit.gif" border="0" alt="'.get_lang('Modify').'" /></a>';
  116. // this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications
  117. if ($show_quiz_edition) {
  118. $delete_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&exerciseId='.$exerciseId.'&deleteQuestion='.$id.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'))).' \')) return false;"><img src="../img/delete.gif" border="0" alt="'.get_lang('Delete').'" /></a>';
  119. }
  120. $actions = Display::tag('div',$edit_link.$delete_link, array('style'=>'float:right'));
  121. echo '<div id="question_id_list_'.$id.'" >';
  122. $move = Display::return_icon('move.png',get_lang('Move'), array('class'=>'moved'));
  123. echo Display::tag('h3','<a href="#">'.$move.' '.$objQuestionTmp->selectTitle().'</a>');
  124. echo '<div>';
  125. echo '<p>';
  126. echo $actions;
  127. echo get_lang($question_class.$label);
  128. echo '<br />';
  129. echo get_lang('Level').': '.$objQuestionTmp->selectLevel();
  130. echo '<br />';
  131. showQuestion($id, false, '', '',false, true);
  132. echo '</p>';
  133. echo '</div>';
  134. echo '</div>';
  135. unset($objQuestionTmp);
  136. }
  137. echo '</div>';
  138. }
  139. }
  140. ?>
  141. </table></div>
  142. <table border="0" align="center" cellpadding="2" cellspacing="2" width="100%">
  143. <?php
  144. if(!$i) {
  145. ?>
  146. <tr>
  147. <td><?php echo get_lang('NoQuestion'); ?></td>
  148. </tr>
  149. <?php
  150. }
  151. ?>
  152. </table>