question_list_admin.inc.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Code library for HotPotatoes integration.
  5. * @package chamilo.exercise
  6. * @author
  7. */
  8. /**
  9. * QUESTION LIST ADMINISTRATION
  10. *
  11. * This script allows to manage the question list
  12. * It is included from the script admin.php
  13. *
  14. * @author Olivier Brouckaert
  15. * Modified by Hubert Borderiou 21-10-2011 (Question by category)
  16. */
  17. // ALLOWED_TO_INCLUDE is defined in admin.php
  18. if (!defined('ALLOWED_TO_INCLUDE')) {
  19. exit();
  20. }
  21. // deletes a question from the exercise (not from the data base)
  22. if ($deleteQuestion) {
  23. // if the question exists
  24. if ($objQuestionTmp = Question::read($deleteQuestion)) {
  25. $objQuestionTmp->delete($exerciseId);
  26. // if the question has been removed from the exercise
  27. if ($objExercise->removeFromList($deleteQuestion)) {
  28. $nbrQuestions--;
  29. }
  30. }
  31. // destruction of the Question object
  32. unset($objQuestionTmp);
  33. }
  34. ?>
  35. <style>
  36. .ui-state-highlight { height: 30px; line-height: 1.2em; }
  37. /*Fixes edition buttons*/
  38. .ui-accordion-icons .ui-accordion-header .edition a {
  39. padding-left:4px;
  40. }
  41. </style>
  42. <div id="dialog-confirm" title="<?php echo get_lang("ConfirmYourChoice"); ?>">
  43. <p>
  44. <span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;">
  45. </span>
  46. <?php echo get_lang("AreYouSureToDelete"); ?>
  47. </p>
  48. </div>
  49. <script>
  50. $(function() {
  51. $( "#dialog:ui-dialog" ).dialog( "destroy" );
  52. $( "#dialog-confirm" ).dialog({
  53. autoOpen: false,
  54. show: "blind",
  55. resizable: false,
  56. height:150,
  57. modal: false
  58. });
  59. $(".opener").click(function() {
  60. var targetUrl = $(this).attr("href");
  61. $( "#dialog-confirm" ).dialog({
  62. modal: true,
  63. buttons: {
  64. "<?php echo get_lang("Yes"); ?>": function() {
  65. location.href = targetUrl;
  66. $( this ).dialog( "close" );
  67. },
  68. "<?php echo get_lang("No"); ?>": function() {
  69. $( this ).dialog( "close" );
  70. }
  71. }
  72. });
  73. $( "#dialog-confirm" ).dialog("open");
  74. return false;
  75. });
  76. var stop = false;
  77. $( "#question_list h3" ).click(function( event ) {
  78. if ( stop ) {
  79. event.stopImmediatePropagation();
  80. event.preventDefault();
  81. stop = false;
  82. }
  83. });
  84. var icons = {
  85. header: "ui-icon-circle-arrow-e",
  86. headerSelected: "ui-icon-circle-arrow-s"
  87. };
  88. /* We can add links in the accordion header */
  89. $("div > div > div > .edition > div > a").click(function() {
  90. //Avoid the redirecto when selecting the delete button
  91. if (this.id.indexOf('delete') == -1) {
  92. newWind = window.open(this.href,"_self");
  93. newWind.focus();
  94. return false;
  95. }
  96. });
  97. $( "#question_list" ).accordion({
  98. icons: icons,
  99. autoHeight: false,
  100. active: false, // all items closed by default
  101. collapsible: true,
  102. header: ".header_operations",
  103. })
  104. .sortable({
  105. cursor: "move", // works?
  106. update: function(event, ui) {
  107. var order = $(this).sortable("serialize") + "&a=update_question_order";
  108. $.post("<?php echo api_get_path(WEB_AJAX_PATH)?>exercise.ajax.php", order, function(reponse){
  109. $("#message").html(reponse);
  110. });
  111. },
  112. axis: "y",
  113. placeholder: "ui-state-highlight", //defines the yellow highlight
  114. handle: ".moved", //only the class "moved"
  115. stop: function() {
  116. stop = true;
  117. }
  118. });
  119. });
  120. </script>
  121. <?php
  122. echo '<div class="actionsbig">';
  123. //we filter the type of questions we can add
  124. Question :: display_type_menu ($objExercise->feedbacktype);
  125. echo '</div><div style="clear:both;"></div>';
  126. echo '<div id="message"></div>';
  127. $token = Security::get_token();
  128. //deletes a session when using don't know question type (ugly fix)
  129. unset($_SESSION['less_answer']);
  130. // If we are in a test
  131. $inATest = isset($exerciseId) && $exerciseId > 0;
  132. if (!$inATest) {
  133. echo "<p class='warning-message'>".get_lang("ChoiceQuestionType")."</p>";
  134. }
  135. else {
  136. echo '<div id="question_list">';
  137. if ($nbrQuestions) {
  138. $my_exercise = new Exercise();
  139. //forces the query to the database
  140. $my_exercise->read($_GET['exerciseId']);
  141. $questionList=$my_exercise->selectQuestionList();
  142. // -----------------------
  143. // Style for columns
  144. // -----------------------
  145. $styleQuestion = "width:50%; float:left;";
  146. $styleType = "width:4%; float:left; padding-top:4px; text-align:center;";
  147. $styleCat = "width:22%; float:left; padding-top:8px; text-align:center;";
  148. $styleLevel = "width:6%; float:left; padding-top:8px; text-align:center;";
  149. $styleScore = "width:4%; float:left; padding-top:8px; text-align:center;";
  150. $styleAction = "width:10%; float:left; padding-top:8px;";
  151. // -------------
  152. // Title line
  153. // -------------
  154. echo "<div>";
  155. echo "<div style='font-weight:bold; width:50%; float:left; padding:10px 0px; text-align:center;'><span style='padding-left:50px;'>&nbsp;</span>".get_lang('Questions')."</div>";
  156. echo "<div style='font-weight:bold; width:4%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Type')."</div>";
  157. echo "<div style='font-weight:bold; width:22%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Category')."</div>";
  158. echo "<div style='font-weight:bold; width:6%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Difficulty')."</div>";
  159. echo "<div style='font-weight:bold; width:4%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Score')."</div>";
  160. echo "</div>";
  161. echo "<div style='clear:both'>&nbsp;</div>";
  162. // -------------
  163. if (is_array($questionList)) {
  164. foreach($questionList as $id) {
  165. //To avoid warning messages
  166. if (!is_numeric($id)) {
  167. continue;
  168. }
  169. $objQuestionTmp = Question :: read($id);
  170. $question_class = get_class($objQuestionTmp);
  171. $clone_link = '<a href="'.api_get_self().'?'.api_get_cidreq().'&clone_question='.$id.'">'.Display::return_icon('cd.gif',get_lang('Copy'), array(), 22).'</a>';
  172. $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(), 22).'</a>';
  173. // this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications
  174. if ($show_quiz_edition) {
  175. $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(), 22).'</a>';
  176. }
  177. $edit_link = Display::tag('div',$edit_link, array('style'=>'float:left; padding:0px; margin:0px'));
  178. $clone_link = Display::tag('div',$clone_link, array('style'=>'float:left; padding:0px; margin:0px'));
  179. $delete_link = Display::tag('div',$delete_link, array('style'=>'float:left; padding:0px; margin:0px'));
  180. $actions = Display::tag('div',$edit_link.$clone_link.$delete_link, array('class'=>'edition','style'=>'width:100px; right:10px; margin-top: 0px; position: absolute; top: 10%;'));
  181. $title = Security::remove_XSS($objQuestionTmp->selectTitle());
  182. $move = Display::return_icon('move.png',get_lang('Move'), array('class'=>'moved', 'style'=>'margin-bottom:-0.5em;'));
  183. // ---------------------
  184. // Question name
  185. // ---------------------
  186. $questionName = Display::tag('div', '<a href="#" title = "'.$title.'">'.$move.' '.cut($title, 60).'</a>', array('style'=>$styleQuestion));
  187. // ---------------------
  188. // Question type
  189. // ---------------------
  190. $tabQuestionList = Question::get_types_information();
  191. list($typeImg, $typeExpl) = $objQuestionTmp->get_type_icon_html();
  192. $questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), 32), array('style'=>$styleType));
  193. // ---------------------
  194. // Question category
  195. // ---------------------
  196. $txtQuestionCat = Security::remove_XSS(Testcategory::getCategoryNameForQuestion($objQuestionTmp->id));
  197. if (empty($txtQuestionCat)) {
  198. $txtQuestionCat = "-";
  199. }
  200. $questionCategory = Display::tag('div', '<a href="#" style="padding:0px; margin:0px;" title="'.$txtQuestionCat.'">'.cut($txtQuestionCat, 55).'</a>', array('style'=>$styleCat));
  201. // ---------------------
  202. // Question level
  203. // ---------------------
  204. $txtQuestionLevel = $objQuestionTmp->level;
  205. if (empty($objQuestionTmp->level)) {
  206. $txtQuestionLevel = '-';
  207. }
  208. $questionLevel = Display::tag('div', $txtQuestionLevel, array('style'=>$styleLevel));
  209. // ---------------------
  210. // Question score
  211. // ---------------------
  212. $questionScore = Display::tag('div', $objQuestionTmp->selectWeighting(), array('style'=>$styleScore));
  213. // ---------------------
  214. echo '<div id="question_id_list_'.$id.'" >';
  215. echo '<div class="header_operations">';
  216. echo $questionName;
  217. echo $questionType;
  218. echo $questionCategory;
  219. echo $questionLevel;
  220. echo $questionScore;
  221. echo $actions;
  222. echo '</div>';
  223. echo '<div class="question-list-description-block">';
  224. echo '<p>';
  225. //echo get_lang($question_class.$label);
  226. echo get_lang($question_class);
  227. echo '<br />';
  228. //echo get_lang('Level').': '.$objQuestionTmp->selectLevel();
  229. echo '<br />';
  230. showQuestion($id, false, '', '',false, true);
  231. echo '</p>';
  232. echo '</div>';
  233. echo '</div>';
  234. unset($objQuestionTmp);
  235. }
  236. echo '</div>';
  237. }
  238. }
  239. if(!$nbrQuestions) {
  240. echo Display::display_warning_message(get_lang('NoQuestion'));
  241. }
  242. echo '</div>';
  243. }