question_list_admin.inc.php 9.9 KB

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