question_list_admin.inc.php 10 KB

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