question_list_admin.inc.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. // deletes a question from the exercise (not from the data base)
  18. if ($deleteQuestion) {
  19. // if the question exists
  20. if ($objQuestionTmp = Question::read($deleteQuestion)) {
  21. $objQuestionTmp->delete($exerciseId);
  22. // if the question has been removed from the exercise
  23. if ($objExercise->removeFromList($deleteQuestion)) {
  24. $nbrQuestions--;
  25. }
  26. }
  27. // destruction of the Question object
  28. unset($objQuestionTmp);
  29. }
  30. $ajax_url = api_get_path(WEB_AJAX_PATH)."exercise.ajax.php?".api_get_cidreq()."&exercise_id=".intval($exerciseId);
  31. ?>
  32. <style>
  33. .ui-state-highlight { height: 30px; line-height: 1.2em; }
  34. /*Fixes edition buttons*/
  35. .ui-accordion-icons .ui-accordion-header .edition a {
  36. padding-left:4px;
  37. }
  38. </style>
  39. <div id="dialog-confirm" title="<?php echo get_lang("ConfirmYourChoice"); ?>" style="display:none;">
  40. <p>
  41. <span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0; display:none;">
  42. </span>
  43. <?php echo get_lang("AreYouSureToDelete"); ?>
  44. </p>
  45. </div>
  46. <script>
  47. $(function() {
  48. $( "#dialog:ui-dialog" ).dialog( "destroy" );
  49. $( "#dialog-confirm" ).dialog({
  50. autoOpen: false,
  51. show: "blind",
  52. resizable: false,
  53. height:150,
  54. modal: false
  55. });
  56. $(".opener").click(function() {
  57. var targetUrl = $(this).attr("href");
  58. $( "#dialog-confirm" ).dialog({
  59. modal: true,
  60. buttons: {
  61. "<?php echo get_lang("Yes"); ?>": function() {
  62. location.href = targetUrl;
  63. $( this ).dialog( "close" );
  64. },
  65. "<?php echo get_lang("No"); ?>": function() {
  66. $( this ).dialog( "close" );
  67. }
  68. }
  69. });
  70. $( "#dialog-confirm" ).dialog("open");
  71. return false;
  72. });
  73. var stop = false;
  74. $( "#question_list h3" ).click(function( event ) {
  75. if ( stop ) {
  76. event.stopImmediatePropagation();
  77. event.preventDefault();
  78. stop = false;
  79. }
  80. });
  81. var icons = {
  82. header: "ui-icon-circle-arrow-e",
  83. headerSelected: "ui-icon-circle-arrow-s"
  84. };
  85. /* We can add links in the accordion header */
  86. $("div > div > div > .edition > div > a").click(function() {
  87. //Avoid the redirecto when selecting the delete button
  88. if (this.id.indexOf('delete') == -1) {
  89. newWind = window.open(this.href,"_self");
  90. newWind.focus();
  91. return false;
  92. }
  93. });
  94. $( "#question_list" ).accordion({
  95. icons: icons,
  96. autoHeight: false,
  97. active: false, // all items closed by default
  98. collapsible: true,
  99. header: ".header_operations",
  100. })
  101. .sortable({
  102. cursor: "move", // works?
  103. update: function(event, ui) {
  104. var order = $(this).sortable("serialize") + "&a=update_question_order&exercise_id=<?php echo intval($_GET['exerciseId']);?>";
  105. $.post("<?php echo $ajax_url ?>", order, function(reponse){
  106. $("#message").html(reponse);
  107. });
  108. },
  109. axis: "y",
  110. placeholder: "ui-state-highlight", //defines the yellow highlight
  111. handle: ".moved", //only the class "moved"
  112. stop: function() {
  113. stop = true;
  114. }
  115. });
  116. });
  117. </script>
  118. <?php
  119. //we filter the type of questions we can add
  120. Question :: display_type_menu($objExercise);
  121. echo '<div style="clear:both;"></div>';
  122. echo '<div id="message"></div>';
  123. $token = Security::get_token();
  124. //deletes a session when using don't know question type (ugly fix)
  125. unset($_SESSION['less_answer']);
  126. // If we are in a test
  127. $inATest = isset($exerciseId) && $exerciseId > 0;
  128. if (!$inATest) {
  129. echo "<p class='warning-message'>".get_lang("ChoiceQuestionType")."</p>";
  130. } else {
  131. // Title line
  132. echo "<div>";
  133. 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>";
  134. echo "<div style='font-weight:bold; width:4%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Type')."</div>";
  135. echo "<div style='font-weight:bold; width:22%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Category')."</div>";
  136. echo "<div style='font-weight:bold; width:6%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Difficulty')."</div>";
  137. echo "<div style='font-weight:bold; width:4%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Score')."</div>";
  138. echo "</div>";
  139. echo "<div style='clear:both'>&nbsp;</div>";
  140. echo '<div id="question_list">';
  141. if ($nbrQuestions) {
  142. //Always getting list from DB
  143. $questionList = $objExercise->selectQuestionList(true);
  144. // Style for columns
  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. if (is_array($questionList)) {
  151. foreach ($questionList as $id) {
  152. //To avoid warning messages
  153. if (!is_numeric($id)) {
  154. continue;
  155. }
  156. $objQuestionTmp = Question::read($id);
  157. $question_class = get_class($objQuestionTmp);
  158. $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>';
  159. $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>';
  160. if ($objExercise->edit_exercise_in_lp == true) {
  161. $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>';
  162. }
  163. $edit_link = Display::tag('div', $edit_link, array('style'=>'float:left; padding:0px; margin:0px'));
  164. $clone_link = Display::tag('div', $clone_link, array('style'=>'float:left; padding:0px; margin:0px'));
  165. $delete_link = Display::tag('div', $delete_link, array('style'=>'float:left; padding:0px; margin:0px'));
  166. $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%;'));
  167. $title = Security::remove_XSS($objQuestionTmp->selectTitle());
  168. $move = Display::return_icon('all_directions.png',get_lang('Move'), array('class'=>'moved', 'style'=>'margin-bottom:-0.5em;'));
  169. // Question name
  170. $questionName = Display::tag('div', '<a href="#" title = "'.htmlentities($title).'">'.$move.' '.cut($title, 42).'</a>', array('style'=>$styleQuestion));
  171. // Question type
  172. list($typeImg, $typeExpl) = $objQuestionTmp->get_type_icon_html();
  173. $questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), ICON_SIZE_MEDIUM), array('style'=>$styleType));
  174. // Question category
  175. $txtQuestionCat = Security::remove_XSS(Testcategory::getCategoryNameForQuestion($objQuestionTmp->id));
  176. if (empty($txtQuestionCat)) {
  177. $txtQuestionCat = "-";
  178. }
  179. $questionCategory = Display::tag('div', '<a href="#" style="padding:0px; margin:0px;" title="'.$txtQuestionCat.'">'.cut($txtQuestionCat, 42).'</a>', array('style'=>$styleCat));
  180. // Question level
  181. $txtQuestionLevel = $objQuestionTmp->level;
  182. if (empty($objQuestionTmp->level)) {
  183. $txtQuestionLevel = '-';
  184. }
  185. $questionLevel = Display::tag('div', $txtQuestionLevel, array('style'=>$styleLevel));
  186. // Question score
  187. $questionScore = Display::tag('div', $objQuestionTmp->selectWeighting(), array('style'=>$styleScore));
  188. echo '<div id="question_id_list_'.$id.'" >';
  189. echo '<div class="header_operations">';
  190. echo $questionName;
  191. echo $questionType;
  192. echo $questionCategory;
  193. echo $questionLevel;
  194. echo $questionScore;
  195. echo $actions;
  196. echo '</div>';
  197. echo '<div class="question-list-description-block">';
  198. echo '<p>';
  199. //echo get_lang($question_class.$label);
  200. echo get_lang($question_class);
  201. echo '<br />';
  202. //echo get_lang('Level').': '.$objQuestionTmp->selectLevel();
  203. echo '<br />';
  204. showQuestion($id, false, null, null, false, true, false, true, $objExercise->feedback_type, true);
  205. echo '</p>';
  206. echo '</div>';
  207. echo '</div>';
  208. unset($objQuestionTmp);
  209. }
  210. }
  211. }
  212. if (!$nbrQuestions) {
  213. echo Display::display_warning_message(get_lang('NoQuestion'));
  214. }
  215. echo '</div>'; //question list div
  216. }