question_list_admin.inc.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. autoHeight: false,
  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 "<p class='warning-message'>".get_lang("ChoiceQuestionType")."</p>";
  125. } else {
  126. // Title line
  127. echo "<div>";
  128. 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>";
  129. echo "<div style='font-weight:bold; width:4%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Type')."</div>";
  130. echo "<div style='font-weight:bold; width:22%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Category')."</div>";
  131. echo "<div style='font-weight:bold; width:6%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Difficulty')."</div>";
  132. echo "<div style='font-weight:bold; width:4%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Score')."</div>";
  133. echo "</div>";
  134. echo "<div style='clear:both'>&nbsp;</div>";
  135. echo '<div id="question_list">';
  136. if ($nbrQuestions) {
  137. //Always getting list from DB
  138. $questionList = $objExercise->selectQuestionList(true);
  139. // Style for columns
  140. $styleQuestion = "width:50%; float:left;";
  141. $styleType = "width:4%; float:left; padding-top:4px; text-align:center;";
  142. $styleCat = "width:22%; float:left; padding-top:8px; text-align:center;";
  143. $styleLevel = "width:6%; float:left; padding-top:8px; text-align:center;";
  144. $styleScore = "width:4%; float:left; padding-top:8px; text-align:center;";
  145. if (is_array($questionList)) {
  146. foreach ($questionList as $id) {
  147. //To avoid warning messages
  148. if (!is_numeric($id)) {
  149. continue;
  150. }
  151. $objQuestionTmp = Question::read($id);
  152. $question_class = get_class($objQuestionTmp);
  153. $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>';
  154. $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>';
  155. if ($objExercise->edit_exercise_in_lp == true) {
  156. $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>';
  157. }
  158. $edit_link = Display::tag('div', $edit_link, array('style'=>'float:left; padding:0px; margin:0px'));
  159. $clone_link = Display::tag('div', $clone_link, array('style'=>'float:left; padding:0px; margin:0px'));
  160. $delete_link = Display::tag('div', $delete_link, array('style'=>'float:left; padding:0px; margin:0px'));
  161. $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%;'));
  162. $title = Security::remove_XSS($objQuestionTmp->selectTitle());
  163. $move = Display::return_icon('all_directions.png',get_lang('Move'), array('class'=>'moved', 'style'=>'margin-bottom:-0.5em;'));
  164. // Question name
  165. $questionName = Display::tag('div', '<a href="#" title = "'.htmlentities($title).'">'.$move.' '.cut($title, 42).'</a>', array('style'=>$styleQuestion));
  166. // Question type
  167. list($typeImg, $typeExpl) = $objQuestionTmp->get_type_icon_html();
  168. $questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), ICON_SIZE_MEDIUM), array('style'=>$styleType));
  169. // Question category
  170. $txtQuestionCat = Security::remove_XSS(Testcategory::getCategoryNameForQuestion($objQuestionTmp->id));
  171. if (empty($txtQuestionCat)) {
  172. $txtQuestionCat = "-";
  173. }
  174. $questionCategory = Display::tag('div', '<a href="#" style="padding:0px; margin:0px;" title="'.$txtQuestionCat.'">'.cut($txtQuestionCat, 42).'</a>', array('style'=>$styleCat));
  175. // Question level
  176. $txtQuestionLevel = $objQuestionTmp->level;
  177. if (empty($objQuestionTmp->level)) {
  178. $txtQuestionLevel = '-';
  179. }
  180. $questionLevel = Display::tag('div', $txtQuestionLevel, array('style'=>$styleLevel));
  181. // Question score
  182. $questionScore = Display::tag('div', $objQuestionTmp->selectWeighting(), array('style'=>$styleScore));
  183. echo '<div id="question_id_list_'.$id.'" >';
  184. echo '<div class="header_operations">';
  185. echo $questionName;
  186. echo $questionType;
  187. echo $questionCategory;
  188. echo $questionLevel;
  189. echo $questionScore;
  190. echo $actions;
  191. echo '</div>';
  192. echo '<div class="question-list-description-block">';
  193. echo '<p>';
  194. //echo get_lang($question_class.$label);
  195. echo get_lang($question_class);
  196. echo '<br />';
  197. //echo get_lang('Level').': '.$objQuestionTmp->selectLevel();
  198. echo '<br />';
  199. showQuestion($id, false, null, null, false, true, false, true, $objExercise->feedback_type, true);
  200. echo '</p>';
  201. echo '</div>';
  202. echo '</div>';
  203. unset($objQuestionTmp);
  204. }
  205. }
  206. }
  207. if (!$nbrQuestions) {
  208. echo Display::display_warning_message(get_lang('NoQuestion'));
  209. }
  210. echo '</div>'; //question list div
  211. }