question_list_admin.inc.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. <div id="dialog-confirm"
  29. title="<?php echo get_lang("ConfirmYourChoice"); ?>"
  30. style="display:none;">
  31. <p>
  32. <?php echo get_lang("AreYouSureToDelete"); ?>
  33. </p>
  34. </div>
  35. <script>
  36. $(function () {
  37. $("#dialog:ui-dialog").dialog("destroy");
  38. $("#dialog-confirm").dialog({
  39. autoOpen: false,
  40. show: "blind",
  41. resizable: false,
  42. height: 150,
  43. modal: false
  44. });
  45. $(".opener").click(function () {
  46. var targetUrl = $(this).attr("href");
  47. $("#dialog-confirm").dialog({
  48. modal: true,
  49. buttons: {
  50. "<?php echo get_lang("Yes"); ?>": function () {
  51. location.href = targetUrl;
  52. $(this).dialog("close");
  53. },
  54. "<?php echo get_lang("No"); ?>": function () {
  55. $(this).dialog("close");
  56. }
  57. }
  58. });
  59. $("#dialog-confirm").dialog("open");
  60. return false;
  61. });
  62. var stop = false;
  63. $("#question_list h3").click(function (event) {
  64. if (stop) {
  65. event.stopImmediatePropagation();
  66. event.preventDefault();
  67. stop = false;
  68. }
  69. });
  70. /* We can add links in the accordion header */
  71. $(".btn-actions .edition a.btn").click(function () {
  72. //Avoid the redirecto when selecting the delete button
  73. if (this.id.indexOf('delete') == -1) {
  74. newWind = window.open(this.href, "_self");
  75. newWind.focus();
  76. return false;
  77. }
  78. });
  79. $("#question_list").accordion({
  80. icons: null,
  81. heightStyle: "content",
  82. active: false, // all items closed by default
  83. collapsible: true,
  84. header: ".header_operations",
  85. beforeActivate: function (e, ui) {
  86. var data = ui.newHeader.data();
  87. if (typeof data === 'undefined') {
  88. return;
  89. }
  90. var exerciseId = data.exercise || 0,
  91. questionId = data.question || 0;
  92. if (!questionId || !exerciseId) {
  93. return;
  94. }
  95. var $pnlQuestion = $('#pnl-question-' + questionId);
  96. if ($pnlQuestion.html().trim().length) {
  97. return;
  98. }
  99. $pnlQuestion.html('<span class="fa fa-spinner fa-spin fa-3x fa-fw" aria-hidden="true"></span>');
  100. $.get('<?php echo api_get_path(WEB_AJAX_PATH) ?>exercise.ajax.php?<?php echo api_get_cidreq() ?>', {
  101. a: 'show_question',
  102. exercise: exerciseId,
  103. question: questionId
  104. }, function (response) {
  105. $pnlQuestion.html(response)
  106. });
  107. }
  108. })
  109. .sortable({
  110. cursor: "move", // works?
  111. update: function (event, ui) {
  112. var order = $(this).sortable("serialize") + "&a=update_question_order&exercise_id=<?php echo $exerciseId; ?>";
  113. $.post("<?php echo $ajax_url ?>", order, function (result) {
  114. $("#message").html(result);
  115. });
  116. },
  117. axis: "y",
  118. placeholder: "ui-state-highlight", //defines the yellow highlight
  119. handle: ".moved", //only the class "moved"
  120. stop: function () {
  121. stop = true;
  122. }
  123. });
  124. });
  125. </script>
  126. <?php
  127. //we filter the type of questions we can add
  128. Question:: display_type_menu($objExercise);
  129. // Re sets the question list
  130. $objExercise->setQuestionList();
  131. echo '<div id="message"></div>';
  132. $token = Security::get_token();
  133. //deletes a session when using don't know question type (ugly fix)
  134. Session::erase('less_answer');
  135. // If we are in a test
  136. $inATest = isset($exerciseId) && $exerciseId > 0;
  137. if (!$inATest) {
  138. echo "<div class='alert alert-warning'>"
  139. .get_lang("ChoiceQuestionType")
  140. ."</div>";
  141. } else {
  142. echo '
  143. <div class="row hidden-xs">
  144. <div class="col-sm-5"><strong>'.get_lang('Questions').'</strong></div>
  145. <div class="col-sm-1"><strong>'.get_lang('Type').'</strong></div>
  146. <div class="col-sm-2"><strong>'.get_lang('Category').'</strong></div>
  147. <div class="col-sm-1"><strong>'.get_lang('Difficulty').'</strong></div>
  148. <div class="col-sm-1"><strong>'.get_lang('MaximumScore').'</strong></div>
  149. <div class="col-sm-2"><strong>'.get_lang('Actions').'</strong></div>
  150. </div>
  151. <div id="question_list">
  152. ';
  153. if ($nbrQuestions) {
  154. // Always getting list from DB
  155. //$questionList = $objExercise->selectQuestionList(true);
  156. // In the building exercise mode show question list ordered as is.
  157. $objExercise->setCategoriesGrouping(false);
  158. // Show exercises as in category settings
  159. //$questionList = $objExercise->getQuestionListWithMediasUncompressed();
  160. // In building mode show all questions not render by teacher order.
  161. $objExercise->questionSelectionType = EX_Q_SELECTION_ORDERED;
  162. // Get question list
  163. $questionList = $objExercise->selectQuestionList(true, true);
  164. $category_list = TestCategory::getListOfCategoriesNameForTest(
  165. $objExercise->id,
  166. false
  167. );
  168. if (is_array($questionList)) {
  169. foreach ($questionList as $id) {
  170. //To avoid warning messages
  171. if (!is_numeric($id)) {
  172. continue;
  173. }
  174. /** @var Question $objQuestionTmp */
  175. $objQuestionTmp = Question::read($id);
  176. $clone_link = Display::url(
  177. Display::return_icon(
  178. 'cd.png',
  179. get_lang('Copy'),
  180. [],
  181. ICON_SIZE_TINY
  182. ),
  183. api_get_self().'?'.api_get_cidreq().'&clone_question='.$id,
  184. ['class' => 'btn btn-default btn-sm']
  185. );
  186. $edit_link = ($objQuestionTmp->type == CALCULATED_ANSWER && $objQuestionTmp->isAnswered())
  187. ? Display::button(
  188. 'edit',
  189. Display::return_icon(
  190. 'edit_na.png',
  191. get_lang('QuestionEditionNotAvailableBecauseItIsAlreadyAnsweredHoweverYouCanCopyItAndModifyTheCopy'),
  192. [],
  193. ICON_SIZE_TINY
  194. ),
  195. ['class' => 'btn btn-default btn-sm']
  196. )
  197. : Display::url(
  198. Display::return_icon(
  199. 'edit.png',
  200. get_lang('Modify'),
  201. [],
  202. ICON_SIZE_TINY
  203. ),
  204. api_get_self().'?'.api_get_cidreq().'&'
  205. .http_build_query([
  206. 'type' => $objQuestionTmp->selectType(),
  207. 'myid' => 1,
  208. 'editQuestion' => $id
  209. ]),
  210. ['class' => 'btn btn-default btn-sm']
  211. );
  212. $delete_link = null;
  213. if ($objExercise->edit_exercise_in_lp == true) {
  214. $delete_link = Display::url(
  215. Display::return_icon(
  216. 'delete.png',
  217. get_lang('RemoveFromTest'),
  218. [],
  219. ICON_SIZE_TINY
  220. ),
  221. api_get_self().'?'.api_get_cidreq()
  222. .http_build_query([
  223. 'exerciseId' => $exerciseId,
  224. 'deleteQuestion' => $id
  225. ]),
  226. [
  227. 'id' => "delete_$id",
  228. 'class' => 'opener btn btn-default btn-sm'
  229. ]
  230. );
  231. }
  232. $btnActions = implode(
  233. PHP_EOL,
  234. [$edit_link, $clone_link, $delete_link]
  235. );
  236. $title = Security::remove_XSS($objQuestionTmp->selectTitle());
  237. $title = strip_tags($title);
  238. $move = Display::returnFontAwesomeIcon("arrows moved", 1, true);
  239. // Question name
  240. $questionName =
  241. '<a href="#" title = "'.Security::remove_XSS($title).'">
  242. '.$move.' '.cut($title, 42).'
  243. </a>';
  244. // Question type
  245. list($typeImg, $typeExpl) = $objQuestionTmp->get_type_icon_html();
  246. $questionType = Display::return_icon($typeImg, $typeExpl);
  247. // Question category
  248. $txtQuestionCat = Security::remove_XSS(
  249. TestCategory::getCategoryNameForQuestion($objQuestionTmp->id)
  250. );
  251. if (empty($txtQuestionCat)) {
  252. $txtQuestionCat = "-";
  253. }
  254. // Question level
  255. $txtQuestionLevel = $objQuestionTmp->level;
  256. if (empty($objQuestionTmp->level)) {
  257. $txtQuestionLevel = '-';
  258. }
  259. $questionLevel = $txtQuestionLevel;
  260. // Question score
  261. $questionScore = $objQuestionTmp->selectWeighting();
  262. echo '
  263. <div id="question_id_list_'.$id.'">
  264. <div class="header_operations" data-exercise="'.$objExercise->selectId().'"
  265. data-question="'.$id.'">
  266. <div class="row">
  267. <div class="question col-sm-5 col-xs-12">'
  268. .$questionName.'
  269. </div>
  270. <div class="type col-sm-1 col-xs-12">
  271. <span class="visible-xs-inline">'.get_lang('Type').' </span>'
  272. .$questionType.'
  273. </div>
  274. <div class="category col-sm-2 col-xs-12" title="'.$txtQuestionCat.'">
  275. <span class="visible-xs-inline">'.get_lang('Category').' </span>'
  276. .cut($txtQuestionCat, 42).'
  277. </div>
  278. <div class="level col-sm-1 col-xs-6">
  279. <span class="visible-xs-inline">'.get_lang('Difficulty').' </span>'
  280. .$questionLevel.'
  281. </div>
  282. <div class="score col-sm-1 col-xs-6">
  283. <span class="visible-xs-inline">'.get_lang('Score').' </span>'
  284. .$questionScore.'
  285. </div>
  286. <div class="btn-actions col-sm-2 col-xs-6">
  287. <div class="edition">'.$btnActions.'</div>
  288. </div>
  289. </div>
  290. </div>
  291. <div class="question-list-description-block" id="pnl-question-'.$id.'">
  292. </div>
  293. </div>
  294. ';
  295. unset($objQuestionTmp);
  296. }
  297. }
  298. }
  299. if (!$nbrQuestions) {
  300. echo Display::return_message(get_lang('NoQuestion'), 'warning');
  301. }
  302. echo '</div>'; //question list div
  303. }