question_list_admin.inc.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. })
  96. .sortable({
  97. cursor: "move", // works?
  98. update: function(event, ui) {
  99. var order = $(this).sortable("serialize") + "&a=update_question_order&exercise_id=<?php echo intval($_GET['exerciseId']);?>";
  100. $.post("<?php echo $ajax_url ?>", order, function(reponse){
  101. $("#message").html(reponse);
  102. });
  103. },
  104. axis: "y",
  105. placeholder: "ui-state-highlight", //defines the yellow highlight
  106. handle: ".moved", //only the class "moved"
  107. stop: function() {
  108. stop = true;
  109. }
  110. });
  111. });
  112. </script>
  113. <?php
  114. //we filter the type of questions we can add
  115. Question :: display_type_menu($objExercise);
  116. echo '<div style="clear:both;"></div>';
  117. echo '<div id="message"></div>';
  118. $token = Security::get_token();
  119. //deletes a session when using don't know question type (ugly fix)
  120. unset($_SESSION['less_answer']);
  121. // If we are in a test
  122. $inATest = isset($exerciseId) && $exerciseId > 0;
  123. if (!$inATest) {
  124. echo "<div class='alert alert-warning'>".get_lang("ChoiceQuestionType")."</div>";
  125. } else {
  126. // Title line
  127. echo "<div class='table-responsive'>";
  128. echo "<table class='table table-condensed'>";
  129. echo "<tr>";
  130. echo "<th style=\"width: 50%;\">" .get_lang('Questions'). "</th>";
  131. echo "<th style=\"width: 6%;\">" .get_lang('Type'). "</th>";
  132. echo "<th style=\"width: 22%; text-align:center;\">" .get_lang('Category'). "</th>";
  133. echo "<th style=\"width: 6%;\">" .get_lang('Difficulty'). "</th>";
  134. echo "<th style=\"width: 16%; float:left;\">" .get_lang('Score'). "</th>";
  135. echo "</tr>";
  136. echo "</table>";
  137. echo "</div>";
  138. echo '<div id="question_list">';
  139. if ($nbrQuestions) {
  140. //Always getting list from DB
  141. $questionList = $objExercise->selectQuestionList(true);
  142. // Style for columns
  143. $styleQuestion = "width:50%; float:left; margin-left: 25px;";
  144. $styleType = "width:4%; float:left; text-align:center;";
  145. $styleCat = "width:22%; float:left; text-align:center;";
  146. $styleLevel = "width:6%; float:left; text-align:center;";
  147. $styleScore = "width:4%; float:left; text-align:center;";
  148. if (is_array($questionList)) {
  149. foreach ($questionList as $id) {
  150. //To avoid warning messages
  151. if (!is_numeric($id)) {
  152. continue;
  153. }
  154. $objQuestionTmp = Question::read($id);
  155. $question_class = get_class($objQuestionTmp);
  156. $clone_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&clone_question='.$id.'">'.Display::return_icon('cd.gif',get_lang('Copy'), array(), ICON_SIZE_SMALL).'</a>';
  157. /*$edit_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&type='.$objQuestionTmp->selectType().'&myid=1&editQuestion='.$id.'">'.Display::return_icon('edit.png',get_lang('Modify'), array(), ICON_SIZE_SMALL).'</a>';
  158. if ($objQuestionTmp->type == CALCULATED_ANSWER && $objQuestionTmp->isAnswered()) {
  159. $edit_link = '<a>'.Display::return_icon('edit_na.png',get_lang('Modify'), array(), ICON_SIZE_SMALL).'</a>';
  160. }*/
  161. $edit_link = ($objQuestionTmp->type == CALCULATED_ANSWER && $objQuestionTmp->isAnswered()) ?
  162. '<a>'.Display::return_icon(
  163. 'edit_na.png',
  164. get_lang('QuestionEditionNotAvailableBecauseItIsAlreadyAnsweredHoweverYouCanCopyItAndModifyTheCopy'),
  165. array(),
  166. ICON_SIZE_SMALL
  167. ).'</a>' :
  168. '<a href="'.api_get_self().'?'.api_get_cidreq().'&type='.
  169. $objQuestionTmp->selectType().'&myid=1&editQuestion='.$id.'">'.
  170. Display::return_icon(
  171. 'edit.png',
  172. get_lang('Modify'),
  173. array(),
  174. ICON_SIZE_SMALL
  175. ).'</a>';
  176. $delete_link = null;
  177. if ($objExercise->edit_exercise_in_lp == true) {
  178. $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>';
  179. }
  180. $edit_link = Display::tag('div', $edit_link, array('style'=>'float:left; padding:0px; margin:0px'));
  181. $clone_link = Display::tag('div', $clone_link, array('style'=>'float:left; padding:0px; margin:0px'));
  182. $delete_link = Display::tag('div', $delete_link, array('style'=>'float:left; padding:0px; margin:0px'));
  183. $actions = Display::tag(
  184. 'div',
  185. $edit_link.$clone_link.$delete_link,
  186. array('class'=>'edition','style'=>'width:100px; right:10px; margin-top: 8px; position: absolute; top: 10%;')
  187. );
  188. $title = Security::remove_XSS($objQuestionTmp->selectTitle());
  189. $move = Display::return_icon(
  190. 'all_directions.png',
  191. get_lang('Move'),
  192. array('class'=>'moved', 'style'=>'margin-bottom:-0.5em;')
  193. );
  194. // Question name
  195. $questionName = Display::tag(
  196. 'div',
  197. '<a href="#" title = "'.Security::remove_XSS($title).'">'.$move.' '.cut($title, 42).'</a>',
  198. array('style' => $styleQuestion)
  199. );
  200. // Question type
  201. list($typeImg, $typeExpl) = $objQuestionTmp->get_type_icon_html();
  202. $questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), ICON_SIZE_MEDIUM), array('style'=>$styleType));
  203. // Question category
  204. $txtQuestionCat = Security::remove_XSS(TestCategory::getCategoryNameForQuestion($objQuestionTmp->id));
  205. if (empty($txtQuestionCat)) {
  206. $txtQuestionCat = "-";
  207. }
  208. $questionCategory = Display::tag('div', '<a href="#" style="padding:0px; margin:0px;" title="'.$txtQuestionCat.'">'.
  209. cut($txtQuestionCat, 42).'</a>', array('style'=>$styleCat));
  210. // Question level
  211. $txtQuestionLevel = $objQuestionTmp->level;
  212. if (empty($objQuestionTmp->level)) {
  213. $txtQuestionLevel = '-';
  214. }
  215. $questionLevel = Display::tag('div', $txtQuestionLevel, array('style'=>$styleLevel));
  216. // Question score
  217. $questionScore = Display::tag('div', $objQuestionTmp->selectWeighting(), array('style'=>$styleScore));
  218. echo '<div id="question_id_list_'.$id.'" >';
  219. echo '<div class="header_operations">';
  220. echo $questionName;
  221. echo $questionType;
  222. echo $questionCategory;
  223. echo $questionLevel;
  224. echo $questionScore;
  225. echo $actions;
  226. echo '</div>';
  227. echo '<div class="question-list-description-block">';
  228. echo '<p>';
  229. //echo get_lang($question_class.$label);
  230. echo get_lang($question_class);
  231. echo '<br />';
  232. //echo get_lang('Level').': '.$objQuestionTmp->selectLevel();
  233. echo '<br />';
  234. ExerciseLib::showQuestion($id, false, null, null, false, true, false, true, $objExercise->feedback_type, true);
  235. echo '</p>';
  236. echo '</div>';
  237. echo '</div>';
  238. unset($objQuestionTmp);
  239. }
  240. }
  241. }
  242. if (!$nbrQuestions) {
  243. echo Display::display_warning_message(get_lang('NoQuestion'));
  244. }
  245. echo '</div>'; //question list div
  246. }