question_list_admin.inc.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. // Re sets the question list
  117. $objExercise->setQuestionList();
  118. echo '<div style="clear:both;"></div>';
  119. echo '<div id="message"></div>';
  120. $token = Security::get_token();
  121. //deletes a session when using don't know question type (ugly fix)
  122. unset($_SESSION['less_answer']);
  123. //echo Question::getMediaLabels();
  124. // If we are in a test
  125. $inATest = isset($exerciseId) && $exerciseId > 0;
  126. if (!$inATest) {
  127. echo "<p class='warning-message'>".get_lang("ChoiceQuestionType")."</p>";
  128. } else {
  129. // Title line
  130. echo "<div>";
  131. 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>";
  132. echo "<div style='font-weight:bold; width:4%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Type')."</div>";
  133. echo "<div style='font-weight:bold; width:22%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Category')."</div>";
  134. echo "<div style='font-weight:bold; width:6%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Difficulty')."</div>";
  135. echo "<div style='font-weight:bold; width:4%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Score')."</div>";
  136. echo "</div>";
  137. echo "<div style='clear:both'>&nbsp;</div>";
  138. echo '<div id="question_list">';
  139. if ($nbrQuestions) {
  140. //Always getting list from DB
  141. //$questionList = $objExercise->selectQuestionList(true);
  142. $objExercise->setCategoriesGrouping(false);
  143. // Show exercises as in category settings
  144. //$questionList = $objExercise->getQuestionListWithMediasUncompressed();
  145. // Show all questions no matter the category settings.
  146. $tempCategoryOrder = $objExercise->specialCategoryOrders;
  147. $objExercise->specialCategoryOrders = false;
  148. $questionList = $objExercise->selectQuestionList(true);
  149. $objExercise->specialCategoryOrders = $tempCategoryOrder;
  150. // Style for columns
  151. $styleQuestion = "width:50%; float:left;";
  152. $styleType = "width:4%; float:left; padding-top:4px; text-align:center;";
  153. $styleCat = "width:22%; float:left; padding-top:8px; text-align:center;";
  154. $styleLevel = "width:6%; float:left; padding-top:8px; text-align:center;";
  155. $styleScore = "width:4%; float:left; padding-top:8px; text-align:center;";
  156. $category_list = Testcategory::getListOfCategoriesNameForTest($objExercise->id, false);
  157. if (is_array($questionList)) {
  158. foreach ($questionList as $id) {
  159. //To avoid warning messages
  160. if (!is_numeric($id)) {
  161. continue;
  162. }
  163. /** @var Question $objQuestionTmp */
  164. $objQuestionTmp = Question::read($id);
  165. $question_class = get_class($objQuestionTmp);
  166. $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>';
  167. /*$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>';
  168. if ($objQuestionTmp->type == CALCULATED_ANSWER && $objQuestionTmp->isAnswered()) {
  169. $edit_link = '<a>'.Display::return_icon('edit_na.png',get_lang('Modify'), array(), ICON_SIZE_SMALL).'</a>';
  170. }*/
  171. $edit_link = ($objQuestionTmp->type == CALCULATED_ANSWER && $objQuestionTmp->isAnswered()) ?
  172. '<a>'.Display::return_icon(
  173. 'edit_na.png',
  174. get_lang('QuestionEditionNotAvailableBecauseItIsAlreadyAnsweredHoweverYouCanCopyItAndModifyTheCopy'),
  175. array(),
  176. ICON_SIZE_SMALL
  177. ).'</a>' :
  178. '<a href="'.api_get_self().'?'.api_get_cidreq().'&type='.
  179. $objQuestionTmp->selectType().'&myid=1&editQuestion='.$id.'">'.
  180. Display::return_icon(
  181. 'edit.png',
  182. get_lang('Modify'),
  183. array(),
  184. ICON_SIZE_SMALL
  185. ).'</a>';
  186. $delete_link = null;
  187. if ($objExercise->edit_exercise_in_lp == true) {
  188. $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>';
  189. }
  190. $edit_link = Display::tag('div', $edit_link, array('style'=>'float:left; padding:0px; margin:0px'));
  191. $clone_link = Display::tag('div', $clone_link, array('style'=>'float:left; padding:0px; margin:0px'));
  192. $delete_link = Display::tag('div', $delete_link, array('style'=>'float:left; padding:0px; margin:0px'));
  193. $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%;'));
  194. $title = Security::remove_XSS($objQuestionTmp->selectTitle());
  195. $move = Display::return_icon('all_directions.png',get_lang('Move'), array('class'=>'moved', 'style'=>'margin-bottom:-0.5em;'));
  196. // Question name
  197. $questionName = Display::tag(
  198. 'div',
  199. '<a href="#" title = "'.Security::remove_XSS($title).'">'.$move.' '.cut($title, 42).'</a>',
  200. array('style'=>$styleQuestion)
  201. );
  202. // Question type
  203. list($typeImg, $typeExpl) = $objQuestionTmp->get_type_icon_html();
  204. $questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), ICON_SIZE_MEDIUM), array('style'=>$styleType));
  205. // Question category
  206. $txtQuestionCat = Security::remove_XSS(Testcategory::getCategoryNameForQuestion($objQuestionTmp->id));
  207. if (empty($txtQuestionCat)) {
  208. $txtQuestionCat = "-";
  209. }
  210. $questionCategory = Display::tag('div', '<a href="#" style="padding:0px; margin:0px;" title="'.$txtQuestionCat.'">'.cut($txtQuestionCat, 42).'</a>', array('style'=>$styleCat));
  211. // Question level
  212. $txtQuestionLevel = $objQuestionTmp->level;
  213. if (empty($objQuestionTmp->level)) {
  214. $txtQuestionLevel = '-';
  215. }
  216. $questionLevel = Display::tag('div', $txtQuestionLevel, array('style'=>$styleLevel));
  217. // Question score
  218. $questionScore = Display::tag('div', $objQuestionTmp->selectWeighting(), array('style'=>$styleScore));
  219. echo '<div id="question_id_list_'.$id.'" >';
  220. echo '<div class="header_operations">';
  221. echo $questionName;
  222. echo $questionType;
  223. echo $questionCategory;
  224. echo $questionLevel;
  225. echo $questionScore;
  226. echo $actions;
  227. echo '</div>';
  228. echo '<div class="question-list-description-block">';
  229. echo '<p>';
  230. //echo get_lang($question_class.$label);
  231. echo get_lang($question_class);
  232. echo '<br />';
  233. //echo get_lang('Level').': '.$objQuestionTmp->selectLevel();
  234. echo '<br />';
  235. showQuestion($id, false, null, null, false, true, false, true, $objExercise->feedback_type, true);
  236. echo '</p>';
  237. echo '</div>';
  238. echo '</div>';
  239. unset($objQuestionTmp);
  240. }
  241. }
  242. }
  243. if (!$nbrQuestions) {
  244. echo Display::display_warning_message(get_lang('NoQuestion'));
  245. }
  246. echo '</div>'; //question list div
  247. }