question_list_admin.inc.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. heightStyle: "content",
  92. active: false, // all items closed by default
  93. collapsible: true,
  94. header: ".header_operations",
  95. beforeActivate: function (e, ui) {
  96. var data = ui.newHeader.data();
  97. if (typeof data === 'undefined') {
  98. return;
  99. }
  100. var exerciseId = data.exercise || 0,
  101. questionId = data.question || 0;
  102. if (!questionId || !exerciseId) {
  103. return;
  104. }
  105. var $pnlQuestion = $('#pnl-question-' + questionId);
  106. if ($pnlQuestion.html().trim().length) {
  107. return;
  108. }
  109. $pnlQuestion.html('<span class="fa fa-spinner fa-spin fa-3x fa-fw" aria-hidden="true"></span>');
  110. $.get('<?php echo api_get_path(WEB_AJAX_PATH) ?>exercise.ajax.php', {
  111. a: 'show_question',
  112. exercise: exerciseId,
  113. question: questionId
  114. }, function (response) {
  115. $pnlQuestion.html(response)
  116. });
  117. }
  118. })
  119. .sortable({
  120. cursor: "move", // works?
  121. update: function(event, ui) {
  122. var order = $(this).sortable("serialize") + "&a=update_question_order&exercise_id=<?php echo intval($_GET['exerciseId']);?>";
  123. $.post("<?php echo $ajax_url ?>", order, function(reponse){
  124. $("#message").html(reponse);
  125. });
  126. },
  127. axis: "y",
  128. placeholder: "ui-state-highlight", //defines the yellow highlight
  129. handle: ".moved", //only the class "moved"
  130. stop: function() {
  131. stop = true;
  132. }
  133. });
  134. });
  135. </script>
  136. <?php
  137. //we filter the type of questions we can add
  138. Question :: display_type_menu($objExercise);
  139. // Re sets the question list
  140. $objExercise->setQuestionList();
  141. echo '<div style="clear:both;"></div>';
  142. echo '<div id="message"></div>';
  143. $token = Security::get_token();
  144. //deletes a session when using don't know question type (ugly fix)
  145. unset($_SESSION['less_answer']);
  146. // If we are in a test
  147. $inATest = isset($exerciseId) && $exerciseId > 0;
  148. if (!$inATest) {
  149. echo "<div class='alert alert-warning'>".get_lang("ChoiceQuestionType")."</div>";
  150. } else {
  151. // Title line
  152. echo "<div class='table-responsive'>";
  153. echo "<table class='table table-condensed'>";
  154. echo "<tr>";
  155. echo "<th style=\"width: 50%;\">" .get_lang('Questions'). "</th>";
  156. echo "<th style=\"width: 6%;\">" .get_lang('Type'). "</th>";
  157. echo "<th style=\"width: 22%; text-align:center;\">" .get_lang('Category'). "</th>";
  158. echo "<th style=\"width: 6%;\">" .get_lang('Difficulty'). "</th>";
  159. echo "<th style=\"width: 16%; float:left;\">" .get_lang('Score'). "</th>";
  160. echo "</tr>";
  161. echo "</table>";
  162. echo "</div>";
  163. echo '<div id="question_list">';
  164. if ($nbrQuestions) {
  165. //Always getting list from DB
  166. //$questionList = $objExercise->selectQuestionList(true);
  167. $objExercise->setCategoriesGrouping(false);
  168. // Show exercises as in category settings
  169. //$questionList = $objExercise->getQuestionListWithMediasUncompressed();
  170. // Show all questions no matter the category settings.
  171. $tempCategoryOrder = $objExercise->specialCategoryOrders;
  172. $objExercise->specialCategoryOrders = false;
  173. $questionList = $objExercise->selectQuestionList(true);
  174. $objExercise->specialCategoryOrders = $tempCategoryOrder;
  175. // Style for columns
  176. $styleQuestion = "width:50%; float:left; margin-left: 25px;";
  177. $styleType = "width:4%; float:left; text-align:center;";
  178. $styleCat = "width:22%; float:left; text-align:center;";
  179. $styleLevel = "width:6%; float:left; text-align:center;";
  180. $styleScore = "width:4%; float:left; text-align:center;";
  181. $category_list = TestCategory::getListOfCategoriesNameForTest($objExercise->id, false);
  182. if (is_array($questionList)) {
  183. foreach ($questionList as $id) {
  184. //To avoid warning messages
  185. if (!is_numeric($id)) {
  186. continue;
  187. }
  188. /** @var Question $objQuestionTmp */
  189. $objQuestionTmp = Question::read($id);
  190. $question_class = get_class($objQuestionTmp);
  191. $clone_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&clone_question='.$id.'">'.
  192. Display::return_icon('cd.gif',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>' :
  200. '<a href="'.api_get_self().'?'.api_get_cidreq().'&type='.
  201. $objQuestionTmp->selectType().'&myid=1&editQuestion='.$id.'">'.
  202. Display::return_icon(
  203. 'edit.png',
  204. get_lang('Modify'),
  205. array(),
  206. ICON_SIZE_SMALL
  207. ).'</a>';
  208. $delete_link = null;
  209. if ($objExercise->edit_exercise_in_lp == true) {
  210. $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>';
  211. }
  212. $edit_link = Display::tag('div', $edit_link, array('style'=>'float:left; padding:0px; margin:0px'));
  213. $clone_link = Display::tag('div', $clone_link, array('style'=>'float:left; padding:0px; margin:0px'));
  214. $delete_link = Display::tag('div', $delete_link, array('style'=>'float:left; padding:0px; margin:0px'));
  215. $actions = Display::tag(
  216. 'div',
  217. $edit_link.$clone_link.$delete_link,
  218. array('class'=>'edition','style'=>'width:100px; right:10px; margin-top: 8px; position: absolute; top: 10%;')
  219. );
  220. $title = Security::remove_XSS($objQuestionTmp->selectTitle());
  221. $move = Display::return_icon(
  222. 'all_directions.png',
  223. get_lang('Move'),
  224. array('class'=>'moved', 'style'=>'margin-bottom:-0.5em;')
  225. );
  226. // Question name
  227. $questionName = Display::tag(
  228. 'div',
  229. '<a href="#" title = "'.Security::remove_XSS($title).'">'.$move.' '.cut($title, 42).'</a>',
  230. array('style' => $styleQuestion)
  231. );
  232. // Question type
  233. list($typeImg, $typeExpl) = $objQuestionTmp->get_type_icon_html();
  234. $questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), ICON_SIZE_MEDIUM), array('style'=>$styleType));
  235. // Question category
  236. $txtQuestionCat = Security::remove_XSS(TestCategory::getCategoryNameForQuestion($objQuestionTmp->id));
  237. if (empty($txtQuestionCat)) {
  238. $txtQuestionCat = "-";
  239. }
  240. $questionCategory = Display::tag('div', '<a href="#" style="padding:0px; margin:0px;" title="'.$txtQuestionCat.'">'.
  241. cut($txtQuestionCat, 42).'</a>', array('style'=>$styleCat));
  242. // Question level
  243. $txtQuestionLevel = $objQuestionTmp->level;
  244. if (empty($objQuestionTmp->level)) {
  245. $txtQuestionLevel = '-';
  246. }
  247. $questionLevel = Display::tag('div', $txtQuestionLevel, array('style'=>$styleLevel));
  248. // Question score
  249. $questionScore = Display::tag('div', $objQuestionTmp->selectWeighting(), array('style'=>$styleScore));
  250. echo '<div id="question_id_list_'.$id.'" >';
  251. echo '<div class="header_operations" data-exercise="' . $objExercise->selectId() . '" data-question="' . $id . '">';
  252. echo $questionName;
  253. echo $questionType;
  254. echo $questionCategory;
  255. echo $questionLevel;
  256. echo $questionScore;
  257. echo $actions;
  258. echo '</div>';
  259. echo Display::tag(
  260. 'div',
  261. null,
  262. ['class' => 'question-list-description-block', 'id' => "pnl-question-$id"]
  263. );
  264. echo '</div>';
  265. unset($objQuestionTmp);
  266. }
  267. }
  268. }
  269. if (!$nbrQuestions) {
  270. echo Display::display_warning_message(get_lang('NoQuestion'));
  271. }
  272. echo '</div>'; //question list div
  273. }