question_list_admin.inc.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * Code library for HotPotatoes integration.
  6. * @package chamilo.exercise
  7. * @author Olivier Brouckaert & Julio Montoya & Hubert Borderiou 21-10-2011 (Question by category)
  8. * QUESTION LIST ADMINISTRATION
  9. *
  10. * This script allows to manage the question list
  11. * It is included from the script admin.php
  12. */
  13. // deletes a question from the exercise (not from the data base)
  14. if ($deleteQuestion) {
  15. // if the question exists
  16. if ($objQuestionTmp = Question::read($deleteQuestion)) {
  17. $objQuestionTmp->delete($exerciseId);
  18. // if the question has been removed from the exercise
  19. if ($objExercise->removeFromList($deleteQuestion)) {
  20. $nbrQuestions--;
  21. }
  22. }
  23. // destruction of the Question object
  24. unset($objQuestionTmp);
  25. }
  26. $ajax_url = api_get_path(WEB_AJAX_PATH)."exercise.ajax.php?".api_get_cidreq()."&exercise_id=".intval($exerciseId);
  27. ?>
  28. <style>
  29. .ui-state-highlight { height: 30px; line-height: 1.2em; }
  30. /*Fixes edition buttons*/
  31. .ui-accordion-icons .ui-accordion-header .edition a {
  32. padding-left:4px;
  33. }
  34. </style>
  35. <div id="dialog-confirm" title="<?php echo get_lang("ConfirmYourChoice"); ?>" style="display:none;">
  36. <p>
  37. <span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0; display:none;">
  38. </span>
  39. <?php echo get_lang("AreYouSureToDelete"); ?>
  40. </p>
  41. </div>
  42. <script>
  43. $(function() {
  44. $( "#dialog:ui-dialog" ).dialog( "destroy" );
  45. $( "#dialog-confirm" ).dialog({
  46. autoOpen: false,
  47. show: "blind",
  48. resizable: false,
  49. height:150,
  50. modal: false
  51. });
  52. $(".opener").click(function() {
  53. var targetUrl = $(this).attr("href");
  54. $( "#dialog-confirm" ).dialog({
  55. modal: true,
  56. buttons: {
  57. "<?php echo get_lang("Yes"); ?>": function() {
  58. location.href = targetUrl;
  59. $( this ).dialog( "close" );
  60. },
  61. "<?php echo get_lang("No"); ?>": function() {
  62. $( this ).dialog( "close" );
  63. }
  64. }
  65. });
  66. $( "#dialog-confirm" ).dialog("open");
  67. return false;
  68. });
  69. var stop = false;
  70. $( "#question_list h3" ).click(function( event ) {
  71. if ( stop ) {
  72. event.stopImmediatePropagation();
  73. event.preventDefault();
  74. stop = false;
  75. }
  76. });
  77. /* We can add links in the accordion header */
  78. $(".btn-actions .edition .items a").click(function() {
  79. //Avoid the redirecto when selecting the delete button
  80. if (this.id.indexOf('delete') == -1) {
  81. newWind = window.open(this.href,"_self");
  82. newWind.focus();
  83. return false;
  84. }
  85. });
  86. $( "#question_list" ).accordion({
  87. icons: null,
  88. heightStyle: "content",
  89. active: false, // all items closed by default
  90. collapsible: true,
  91. header: ".header_operations",
  92. beforeActivate: function (e, ui) {
  93. var data = ui.newHeader.data();
  94. if (typeof data === 'undefined') {
  95. return;
  96. }
  97. var exerciseId = data.exercise || 0,
  98. questionId = data.question || 0;
  99. if (!questionId || !exerciseId) {
  100. return;
  101. }
  102. var $pnlQuestion = $('#pnl-question-' + questionId);
  103. if ($pnlQuestion.html().trim().length) {
  104. return;
  105. }
  106. $pnlQuestion.html('<span class="fa fa-spinner fa-spin fa-3x fa-fw" aria-hidden="true"></span>');
  107. $.get('<?php echo api_get_path(WEB_AJAX_PATH) ?>exercise.ajax.php?<?php echo api_get_cidreq() ?>', {
  108. a: 'show_question',
  109. exercise: exerciseId,
  110. question: questionId
  111. }, function (response) {
  112. $pnlQuestion.html(response)
  113. });
  114. }
  115. })
  116. .sortable({
  117. cursor: "move", // works?
  118. update: function(event, ui) {
  119. var order = $(this).sortable("serialize") + "&a=update_question_order&exercise_id=<?php echo intval($_GET['exerciseId']); ?>";
  120. $.post("<?php echo $ajax_url ?>", order, function(reponse){
  121. $("#message").html(reponse);
  122. });
  123. },
  124. axis: "y",
  125. placeholder: "ui-state-highlight", //defines the yellow highlight
  126. handle: ".moved", //only the class "moved"
  127. stop: function() {
  128. stop = true;
  129. }
  130. });
  131. });
  132. </script>
  133. <?php
  134. //we filter the type of questions we can add
  135. Question :: display_type_menu($objExercise);
  136. // Re sets the question list
  137. $objExercise->setQuestionList();
  138. echo '<div style="clear:both;"></div>';
  139. echo '<div id="message"></div>';
  140. $token = Security::get_token();
  141. //deletes a session when using don't know question type (ugly fix)
  142. Session::erase('less_answer');
  143. // If we are in a test
  144. $inATest = isset($exerciseId) && $exerciseId > 0;
  145. if (!$inATest) {
  146. echo "<div class='alert alert-warning'>".get_lang("ChoiceQuestionType")."</div>";
  147. } else {
  148. // Title line
  149. echo "<div class='table-responsive'>";
  150. echo "<table class='table table-condensed'>";
  151. echo "<tr>";
  152. echo "<th style=\"width: 40%;\">".get_lang('Questions')."</th>";
  153. echo "<th style=\"width: 10%;\">".get_lang('Type')."</th>";
  154. echo "<th style=\"width: 20%;\">".get_lang('Category')."</th>";
  155. echo "<th style=\"width: 10%;\">".get_lang('Difficulty')."</th>";
  156. echo "<th style=\"width: 10%;\">".get_lang('MaximumScore')."</th>";
  157. echo "<th style=\"width: 10%;\">".get_lang('Actions')."</th>";
  158. echo "</tr>";
  159. echo "</table>";
  160. echo "</div>";
  161. echo '<div id="question_list">';
  162. if ($nbrQuestions) {
  163. // Always getting list from DB
  164. //$questionList = $objExercise->selectQuestionList(true);
  165. // In the building exercise mode show question list ordered as is.
  166. $objExercise->setCategoriesGrouping(false);
  167. // Show exercises as in category settings
  168. //$questionList = $objExercise->getQuestionListWithMediasUncompressed();
  169. // In building mode show all questions not render by teacher order.
  170. $objExercise->questionSelectionType = EX_Q_SELECTION_ORDERED;
  171. // Get question list
  172. $questionList = $objExercise->selectQuestionList(true, true);
  173. // Style for columns
  174. $styleQuestion = "question";
  175. $styleType = "type";
  176. $styleCat = "category";
  177. $styleLevel = "level";
  178. $styleScore = "score";
  179. $category_list = TestCategory::getListOfCategoriesNameForTest(
  180. $objExercise->id,
  181. false
  182. );
  183. if (is_array($questionList)) {
  184. foreach ($questionList as $id) {
  185. //To avoid warning messages
  186. if (!is_numeric($id)) {
  187. continue;
  188. }
  189. /** @var Question $objQuestionTmp */
  190. $objQuestionTmp = Question::read($id);
  191. $clone_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&clone_question='.$id.'">'.
  192. Display::return_icon('cd.png', get_lang('Copy'), array(), ICON_SIZE_SMALL).'</a>';
  193. $edit_link = ($objQuestionTmp->type == CALCULATED_ANSWER && $objQuestionTmp->isAnswered()) ?
  194. '<a>'.Display::return_icon(
  195. 'edit_na.png',
  196. get_lang('QuestionEditionNotAvailableBecauseItIsAlreadyAnsweredHoweverYouCanCopyItAndModifyTheCopy'),
  197. array(),
  198. ICON_SIZE_SMALL
  199. ).'</a>' : '<a href="'.api_get_self().'?'.api_get_cidreq().'&type='.
  200. $objQuestionTmp->selectType().'&myid=1&editQuestion='.$id.'">'.
  201. Display::return_icon(
  202. 'edit.png',
  203. get_lang('Modify'),
  204. array(),
  205. ICON_SIZE_SMALL
  206. ).'</a>';
  207. $delete_link = null;
  208. if ($objExercise->edit_exercise_in_lp == true) {
  209. $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>';
  210. }
  211. $edit_link = Display::tag('span', $edit_link, array('class'=>'items'));
  212. $clone_link = Display::tag('span', $clone_link, array('class'=>'items'));
  213. $delete_link = Display::tag('span', $delete_link, array('class'=>'items'));
  214. $btnActions = Display::tag('td', Display::tag(
  215. 'div',
  216. $edit_link.$clone_link.$delete_link,
  217. array('class'=>'edition')
  218. ), array('class'=>'btn-actions'));
  219. $title = Security::remove_XSS($objQuestionTmp->selectTitle());
  220. $title = strip_tags($title);
  221. $move = Display::returnFontAwesomeIcon("arrows moved", 'lg');
  222. // Question name
  223. $questionName = Display::tag(
  224. 'td',
  225. '<a href="#" title = "'.Security::remove_XSS($title).'">
  226. '.$move.' '.cut($title, 42).'
  227. </a>',
  228. array('class' => $styleQuestion)
  229. );
  230. // Question type
  231. list($typeImg, $typeExpl) = $objQuestionTmp->get_type_icon_html();
  232. $questionType = Display::tag('td', Display::return_icon($typeImg, $typeExpl, array(), ICON_SIZE_SMALL), array('class'=>$styleType));
  233. // Question category
  234. $txtQuestionCat = Security::remove_XSS(TestCategory::getCategoryNameForQuestion($objQuestionTmp->id));
  235. if (empty($txtQuestionCat)) {
  236. $txtQuestionCat = "-";
  237. }
  238. $questionCategory = Display::tag('td', '<a href="#" style="padding:0px; margin:0px;" title="'.$txtQuestionCat.'">'.
  239. cut($txtQuestionCat, 42).'</a>', array('class'=>$styleCat));
  240. // Question level
  241. $txtQuestionLevel = $objQuestionTmp->level;
  242. if (empty($objQuestionTmp->level)) {
  243. $txtQuestionLevel = '-';
  244. }
  245. $questionLevel = Display::tag('td', $txtQuestionLevel, array('class'=>$styleLevel));
  246. // Question score
  247. $questionScore = Display::tag('td', $objQuestionTmp->selectWeighting(), array('class'=>$styleScore));
  248. echo '<div id="question_id_list_'.$id.'" >';
  249. echo '<div class="header_operations" data-exercise="'.$objExercise->selectId().'" data-question="'.$id.'">';
  250. echo "<div class='table-responsive'>";
  251. echo "<table class='table'>";
  252. echo "<tr>";
  253. echo $questionName;
  254. echo $questionType;
  255. echo $questionCategory;
  256. echo $questionLevel;
  257. echo $questionScore;
  258. echo $btnActions;
  259. echo "</tr>";
  260. echo "</table>";
  261. echo "</div>";
  262. echo '</div>';
  263. echo Display::tag(
  264. 'div',
  265. null,
  266. ['class' => 'question-list-description-block', 'id' => "pnl-question-$id"]
  267. );
  268. echo '</div>';
  269. unset($objQuestionTmp);
  270. }
  271. }
  272. }
  273. if (!$nbrQuestions) {
  274. echo Display::display_warning_message(get_lang('NoQuestion'));
  275. }
  276. echo '</div>'; //question list div
  277. }