question_list_admin.inc.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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', {
  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('Score'). "</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. $objExercise->setCategoriesGrouping(false);
  166. // Show exercises as in category settings
  167. //$questionList = $objExercise->getQuestionListWithMediasUncompressed();
  168. // Show all questions no matter the category settings.
  169. $tempCategoryOrder = isset($objExercise->specialCategoryOrders) ? $objExercise->specialCategoryOrders : false;
  170. $objExercise->specialCategoryOrders = false;
  171. $questionList = $objExercise->selectQuestionList(true);
  172. $objExercise->specialCategoryOrders = $tempCategoryOrder;
  173. // Style for columns
  174. $styleQuestion = "question";
  175. $styleType = "type";
  176. $styleCat = "category";
  177. $styleLevel = "level";
  178. $styleScore = "score";
  179. $category_list = TestCategory::getListOfCategoriesNameForTest($objExercise->id, false);
  180. if (is_array($questionList)) {
  181. foreach ($questionList as $id) {
  182. //To avoid warning messages
  183. if (!is_numeric($id)) {
  184. continue;
  185. }
  186. /** @var Question $objQuestionTmp */
  187. $objQuestionTmp = Question::read($id);
  188. $question_class = get_class($objQuestionTmp);
  189. $clone_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&clone_question='.$id.'">'.
  190. Display::return_icon('cd.png',get_lang('Copy'), array(), ICON_SIZE_SMALL).'</a>';
  191. $edit_link = ($objQuestionTmp->type == CALCULATED_ANSWER && $objQuestionTmp->isAnswered()) ?
  192. '<a>'.Display::return_icon(
  193. 'edit_na.png',
  194. get_lang('QuestionEditionNotAvailableBecauseItIsAlreadyAnsweredHoweverYouCanCopyItAndModifyTheCopy'),
  195. array(),
  196. ICON_SIZE_SMALL
  197. ).'</a>' :
  198. '<a href="'.api_get_self().'?'.api_get_cidreq().'&type='.
  199. $objQuestionTmp->selectType().'&myid=1&editQuestion='.$id.'">'.
  200. Display::return_icon(
  201. 'edit.png',
  202. get_lang('Modify'),
  203. array(),
  204. ICON_SIZE_SMALL
  205. ).'</a>';
  206. $delete_link = null;
  207. if ($objExercise->edit_exercise_in_lp == true) {
  208. $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>';
  209. }
  210. $edit_link = Display::tag('span', $edit_link, array('class'=>'items'));
  211. $clone_link = Display::tag('span', $clone_link, array('class'=>'items'));
  212. $delete_link = Display::tag('span', $delete_link, array('class'=>'items'));
  213. $btnActions = Display::tag('td',Display::tag(
  214. 'div',
  215. $edit_link.$clone_link.$delete_link,
  216. array('class'=>'edition')
  217. ), array ('class'=>'btn-actions'));
  218. $title = Security::remove_XSS($objQuestionTmp->selectTitle());
  219. /* $move = Display::return_icon(
  220. 'all_directions.png',
  221. get_lang('Move'),
  222. array('class'=>'moved', 'style'=>'margin-bottom:-0.3em;')
  223. ); */
  224. $move = Display::returnFontAwesomeIcon("arrows moved", 'lg');
  225. // Question name
  226. $questionName = Display::tag(
  227. 'td',
  228. '<a href="#" title = "'.Security::remove_XSS($title).'">'.$move.' '.cut($title, 42).'</a>',
  229. array('class' => $styleQuestion)
  230. );
  231. // Question type
  232. list($typeImg, $typeExpl) = $objQuestionTmp->get_type_icon_html();
  233. $questionType = Display::tag('td', Display::return_icon($typeImg, $typeExpl, array(), ICON_SIZE_SMALL), array('class'=>$styleType));
  234. // Question category
  235. $txtQuestionCat = Security::remove_XSS(TestCategory::getCategoryNameForQuestion($objQuestionTmp->id));
  236. if (empty($txtQuestionCat)) {
  237. $txtQuestionCat = "-";
  238. }
  239. $questionCategory = Display::tag('td', '<a href="#" style="padding:0px; margin:0px;" title="'.$txtQuestionCat.'">'.
  240. cut($txtQuestionCat, 42).'</a>', array('class'=>$styleCat));
  241. // Question level
  242. $txtQuestionLevel = $objQuestionTmp->level;
  243. if (empty($objQuestionTmp->level)) {
  244. $txtQuestionLevel = '-';
  245. }
  246. $questionLevel = Display::tag('td', $txtQuestionLevel, array('class'=>$styleLevel));
  247. // Question score
  248. $questionScore = Display::tag('td', $objQuestionTmp->selectWeighting(), array('class'=>$styleScore));
  249. echo '<div id="question_id_list_'.$id.'" >';
  250. echo '<div class="header_operations" data-exercise="' . $objExercise->selectId() . '" data-question="' . $id . '">';
  251. echo "<div class='table-responsive'>";
  252. echo "<table class='table'>";
  253. echo "<tr>";
  254. echo $questionName;
  255. echo $questionType;
  256. echo $questionCategory;
  257. echo $questionLevel;
  258. echo $questionScore;
  259. echo $btnActions;
  260. echo "</tr>";
  261. echo "</table>";
  262. echo "</div>";
  263. echo '</div>';
  264. echo Display::tag(
  265. 'div',
  266. null,
  267. ['class' => 'question-list-description-block', 'id' => "pnl-question-$id"]
  268. );
  269. echo '</div>';
  270. unset($objQuestionTmp);
  271. }
  272. }
  273. }
  274. if (!$nbrQuestions) {
  275. echo Display::display_warning_message(get_lang('NoQuestion'));
  276. }
  277. echo '</div>'; //question list div
  278. }