question_list_admin.inc.php 13 KB

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