question_list_admin.inc.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Code library for HotPotatoes integration.
  5. * @package chamilo.exercise
  6. * @author Olivier Brouckaert & Julio Montoya & Hubert Borderiou 21-10-2011 (Question by category)
  7. * QUESTION LIST ADMINISTRATION
  8. *
  9. * This script allows to manage the question list
  10. * It is included from the script admin.php
  11. */
  12. // deletes a question from the exercise (not from the data base)
  13. if ($deleteQuestion) {
  14. // if the question exists
  15. if ($objQuestionTmp = Question::read($deleteQuestion)) {
  16. $objQuestionTmp->delete($exerciseId);
  17. // if the question has been removed from the exercise
  18. if ($objExercise->removeFromList($deleteQuestion)) {
  19. $nbrQuestions--;
  20. }
  21. }
  22. // destruction of the Question object
  23. unset($objQuestionTmp);
  24. }
  25. $ajax_url = api_get_path(WEB_AJAX_PATH)."exercise.ajax.php?".api_get_cidreq()."&exercise_id=".intval($exerciseId);
  26. ?>
  27. <style>
  28. .ui-state-highlight { height: 30px; line-height: 1.2em; }
  29. /*Fixes edition buttons*/
  30. .ui-accordion-icons .ui-accordion-header .edition a {
  31. padding-left:4px;
  32. }
  33. </style>
  34. <div id="dialog-confirm" title="<?php echo get_lang("ConfirmYourChoice"); ?>" style="display:none;">
  35. <p>
  36. <span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0; display:none;">
  37. </span>
  38. <?php echo get_lang("AreYouSureToDelete"); ?>
  39. </p>
  40. </div>
  41. <script>
  42. $(function() {
  43. var stop = false;
  44. $( "#question_list h3" ).click(function( event ) {
  45. if ( stop ) {
  46. event.stopImmediatePropagation();
  47. event.preventDefault();
  48. stop = false;
  49. }
  50. });
  51. var icons = {
  52. header: "ui-icon-circle-arrow-e",
  53. headerSelected: "ui-icon-circle-arrow-s"
  54. };
  55. /* We can add links in the accordion header */
  56. $("div > div > div > .edition > div > a").click(function() {
  57. //Avoid the redirecto when selecting the delete button
  58. if (this.id.indexOf('delete') == -1) {
  59. newWind = window.open(this.href,"_self");
  60. newWind.focus();
  61. return false;
  62. }
  63. });
  64. $( "#question_list" ).accordion({
  65. icons: icons,
  66. autoHeight: false,
  67. active: false, // all items closed by default
  68. collapsible: true,
  69. header: ".header_operations"
  70. })
  71. .sortable({
  72. cursor: "move", // works?
  73. update: function(event, ui) {
  74. var order = $(this).sortable("serialize") + "&a=update_question_order&exercise_id=<?php echo $exerciseId;?>";
  75. $.post("<?php echo $ajax_url ?>", order, function(reponse){
  76. $("#message").html(reponse);
  77. });
  78. },
  79. axis: "y",
  80. placeholder: "ui-state-highlight", //defines the yellow highlight
  81. handle: ".moved", //only the class "moved"
  82. stop: function() {
  83. stop = true;
  84. }
  85. });
  86. });
  87. </script>
  88. <?php
  89. // Filters the type of questions we can add.
  90. Question::display_type_menu($objExercise);
  91. // Re sets the question list
  92. $objExercise->setQuestionList();
  93. echo '<div style="clear:both;"></div>';
  94. echo '<div id="message"></div>';
  95. $token = Security::get_token();
  96. // Deletes a session when using don't know question type (ugly fix).
  97. unset($_SESSION['less_answer']);
  98. echo Question::getMediaLabels();
  99. // If we are in a test.
  100. $inATest = isset($exerciseId) && $exerciseId > 0;
  101. if (!$inATest) {
  102. echo "<p class='warning-message'>".get_lang("ChoiceQuestionType")."</p>";
  103. } else {
  104. // Title line
  105. echo "<div>";
  106. echo "<div style='font-weight:bold; width:50%; float:left; padding:10px 0px; text-align:center;'><span style='padding-left:50px;'>&nbsp;</span>".get_lang('Questions')."</div>";
  107. echo "<div style='font-weight:bold; width:4%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Type')."</div>";
  108. echo "<div style='font-weight:bold; width:22%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Category')."</div>";
  109. echo "<div style='font-weight:bold; width:6%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Difficulty')."</div>";
  110. echo "<div style='font-weight:bold; width:4%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Score')."</div>";
  111. echo "</div>";
  112. echo "<div style='clear:both'>&nbsp;</div>";
  113. echo '<div id="question_list">';
  114. if ($nbrQuestions) {
  115. // Always getting list from DB.
  116. $objExercise->setCategoriesGrouping(false);
  117. $questionList = $objExercise->getQuestionListWithMediasUncompressed();
  118. // Style for columns.
  119. $styleQuestion = "width:50%; float:left;";
  120. $styleType = "width:4%; float:left; padding-top:4px; text-align:center;";
  121. $styleCat = "width:22%; float:left; padding-top:8px; text-align:center;";
  122. $styleLevel = "width:6%; float:left; padding-top:8px; text-align:center;";
  123. $styleScore = "width:4%; float:left; padding-top:8px; text-align:center;";
  124. $category_list = Testcategory::getListOfCategoriesNameForTest($objExercise->id, false);
  125. if (is_array($questionList)) {
  126. foreach ($questionList as $id) {
  127. // To avoid warning messages.
  128. if (!is_numeric($id)) {
  129. continue;
  130. }
  131. /** @var Question $objQuestionTmp */
  132. $objQuestionTmp = Question :: read($id);
  133. $question_class = get_class($objQuestionTmp);
  134. $clone_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&clone_question='.$id.'">'.Display::return_icon('cd.gif',get_lang('Copy'), array(), ICON_SIZE_SMALL).'</a>';
  135. $edit_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&type='.$objQuestionTmp->selectType().'&myid=1&editQuestion='.$id.'">'.Display::return_icon('edit.png',get_lang('Modify'), array(), ICON_SIZE_SMALL).'</a>';
  136. if ($objExercise->edit_exercise_in_lp == true) {
  137. $delete_link = '<a id="delete_'.$id.'" class="opener" href="'.api_get_self().'?'.api_get_cidreq().'&exerciseId='.$exerciseId.'&deleteQuestion='.$id.'" >'.Display::return_icon('delete.png',get_lang('RemoveFromTest'), array(), ICON_SIZE_SMALL).'</a>';
  138. }
  139. $edit_link = Display::tag('div', $edit_link, array('style'=>'float:left; padding:0px; margin:0px'));
  140. $clone_link = Display::tag('div', $clone_link, array('style'=>'float:left; padding:0px; margin:0px'));
  141. $delete_link = Display::tag('div', $delete_link, array('style'=>'float:left; padding:0px; margin:0px'));
  142. $actions = Display::tag('div', $edit_link.$clone_link.$delete_link, array('class'=>'edition','style'=>'width:100px; right:10px; margin-top: 0px; position: absolute; top: 10%;'));
  143. $title = Security::remove_XSS($objQuestionTmp->selectTitle());
  144. $move = Display::return_icon('all_directions.png',get_lang('Move'), array('class'=>'moved', 'style'=>'margin-bottom:-0.5em;'));
  145. // Question name
  146. $questionName = Display::tag('div', '<a href="#" title = "'.$title.'">'.$move.' '.Text::cut($title, 42).'</a>', array('style'=>$styleQuestion));
  147. // Question type.
  148. list($typeImg, $typeExpl) = $objQuestionTmp->get_type_icon_html();
  149. $question_media = null;
  150. if (!empty($objQuestionTmp->parent_id)) {
  151. $objQuestionMedia = Question::read($objQuestionTmp->parent_id);
  152. $question_media = ' '.Question::getMediaLabel($objQuestionMedia->question);
  153. }
  154. $questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), ICON_SIZE_MEDIUM), array('style' => $styleType));
  155. // Question category.
  156. $category_labels = Testcategory::return_category_labels($objQuestionTmp->category_list, $category_list);
  157. if (empty($category_labels)) {
  158. $category_labels = "";
  159. }
  160. $questionCategory = Display::tag('div', '<a href="#" style="padding:0px; margin:0px;">'.$category_labels.$question_media.'</a>', array('style'=>$styleCat));
  161. // Question level.
  162. $txtQuestionLevel = $objQuestionTmp->level;
  163. if (empty($objQuestionTmp->level)) {
  164. $txtQuestionLevel = '-';
  165. }
  166. $questionLevel = Display::tag('div', $txtQuestionLevel, array('style'=>$styleLevel));
  167. // Question score
  168. $questionScore = Display::tag('div', $objQuestionTmp->selectWeighting(), array('style'=>$styleScore));
  169. echo '<div id="question_id_list_'.$id.'" >';
  170. echo '<div class="header_operations">';
  171. echo $questionName;
  172. echo $questionType;
  173. echo $questionCategory;
  174. echo $questionLevel;
  175. echo $questionScore;
  176. echo $actions;
  177. echo '</div>';
  178. echo '<div class="question-list-description-block">';
  179. echo '<p>';
  180. //echo get_lang($question_class.$label);
  181. echo get_lang($question_class);
  182. echo '<br />';
  183. //echo get_lang('Level').': '.$objQuestionTmp->selectLevel();
  184. echo '<br />';
  185. echo $objExercise->showQuestion($objQuestionTmp, false, null, null, false, true, false, true, $objExercise->feedback_type, true);
  186. echo '</p>';
  187. echo '</div>';
  188. echo '</div>';
  189. unset($objQuestionTmp);
  190. }
  191. }
  192. }
  193. if (!$nbrQuestions) {
  194. echo Display::display_warning_message(get_lang('NoQuestion'));
  195. }
  196. echo '</div>'; //question list div
  197. }