question_list_admin.inc.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. </style>
  57. <script>
  58. $(function() {
  59. var stop = false;
  60. $( "#question_list h3" ).click(function( event ) {
  61. if ( stop ) {
  62. event.stopImmediatePropagation();
  63. event.preventDefault();
  64. stop = false;
  65. }
  66. });
  67. $( "#question_list" )
  68. .accordion({
  69. autoHeight: false,
  70. active: false, // all items closed by default
  71. collapsible: true,
  72. header: "> div > h3"
  73. })
  74. .sortable({
  75. cursor: "move", // works?
  76. update: function(event, ui) {
  77. var order = $(this).sortable("serialize") + "&a=update_question_order";
  78. $.post("<?php echo api_get_path(WEB_AJAX_PATH)?>exercise.ajax.php", order, function(reponse){
  79. $("#message").html(reponse);
  80. });
  81. },
  82. axis: "y",
  83. placeholder: "ui-state-highlight", //defines the yellow highlight
  84. handle: ".moved", //only the class "moved"
  85. stop: function() {
  86. stop = true;
  87. }
  88. });
  89. });
  90. </script>
  91. <?php
  92. echo '<div class="actionsbig">';
  93. //we filter the type of questions we can add
  94. Question :: display_type_menu ($objExercise->feedbacktype);
  95. echo '</div><div style="clear:both;">';
  96. echo '<div id="message"></div>';
  97. $token = Security::get_token();
  98. if ($nbrQuestions) {
  99. $my_exercise = new Exercise();
  100. //forces the query to the database
  101. $my_exercise->read($_GET['exerciseId']);
  102. $questionList=$my_exercise->selectQuestionList();
  103. $i=1;
  104. if (is_array($questionList)) {
  105. echo '<div id="question_list">';
  106. foreach($questionList as $id) {
  107. //To avoid warning messages
  108. if (!is_numeric($id)) {
  109. continue;
  110. }
  111. $objQuestionTmp = Question :: read($id);
  112. $question_class = get_class($objQuestionTmp);
  113. $label = $question_class->$explanationLangVar;
  114. $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>';
  115. // this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications
  116. if ($show_quiz_edition) {
  117. $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;">'.Display::return_icon('delete.gif',get_lang('Delete')).'</a>';
  118. }
  119. $actions = Display::tag('div',$edit_link.$delete_link, array('style'=>'float:right'));
  120. echo '<div id="question_id_list_'.$id.'" >';
  121. $move = Display::return_icon('move.png',get_lang('Move'), array('class'=>'moved', 'style'=>'margin-bottom:-0.5em;'));
  122. echo Display::tag('h3','<a href="#">'.$move.' '.$objQuestionTmp->selectTitle().' <span style="float: right; padding-top: 0.3em;">['.get_lang('QualificationNumeric').': '.$objQuestionTmp->selectWeighting().']</span></a>');
  123. echo '<div class="question-list-description-block">';
  124. echo '<p>';
  125. echo $actions;
  126. echo get_lang($question_class.$label);
  127. echo '<br />';
  128. echo get_lang('Level').': '.$objQuestionTmp->selectLevel();
  129. echo '<br />';
  130. showQuestion($id, false, '', '',false, true);
  131. echo '</p>';
  132. echo '</div>';
  133. echo '</div>';
  134. unset($objQuestionTmp);
  135. }
  136. echo '</div>';
  137. }
  138. }
  139. ?>
  140. </table></div>
  141. <table border="0" align="center" cellpadding="2" cellspacing="2" width="100%">
  142. <?php
  143. if(!$i) {
  144. ?>
  145. <tr>
  146. <td><?php echo get_lang('NoQuestion'); ?></td>
  147. </tr>
  148. <?php
  149. }
  150. ?>
  151. </table>