question_list_admin.inc.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. } else {
  135. echo '<div id="question_list">';
  136. if ($nbrQuestions) {
  137. $my_exercise = new Exercise();
  138. //forces the query to the database
  139. $my_exercise->read($_GET['exerciseId']);
  140. $questionList=$my_exercise->selectQuestionList();
  141. // Style for columns
  142. $styleQuestion = "width:50%; float:left;";
  143. $styleType = "width:4%; float:left; padding-top:4px; text-align:center;";
  144. $styleCat = "width:22%; float:left; padding-top:8px; text-align:center;";
  145. $styleLevel = "width:6%; float:left; padding-top:8px; text-align:center;";
  146. $styleScore = "width:4%; float:left; padding-top:8px; text-align:center;";
  147. $styleAction = "width:10%; float:left; padding-top:8px;";
  148. // Title line
  149. echo "<div>";
  150. 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>";
  151. echo "<div style='font-weight:bold; width:4%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Type')."</div>";
  152. echo "<div style='font-weight:bold; width:22%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Category')."</div>";
  153. echo "<div style='font-weight:bold; width:6%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Difficulty')."</div>";
  154. echo "<div style='font-weight:bold; width:4%; float:left; padding:10px 0px; text-align:center;'>".get_lang('Score')."</div>";
  155. echo "</div>";
  156. echo "<div style='clear:both'>&nbsp;</div>";
  157. if (is_array($questionList)) {
  158. foreach($questionList as $id) {
  159. //To avoid warning messages
  160. if (!is_numeric($id)) {
  161. continue;
  162. }
  163. $objQuestionTmp = Question :: read($id);
  164. $question_class = get_class($objQuestionTmp);
  165. $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>';
  166. $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>';
  167. // this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications
  168. if ($show_quiz_edition) {
  169. $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>';
  170. }
  171. $edit_link = Display::tag('div',$edit_link, array('style'=>'float:left; padding:0px; margin:0px'));
  172. $clone_link = Display::tag('div',$clone_link, array('style'=>'float:left; padding:0px; margin:0px'));
  173. $delete_link = Display::tag('div',$delete_link, array('style'=>'float:left; padding:0px; margin:0px'));
  174. $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%;'));
  175. $title = Security::remove_XSS($objQuestionTmp->selectTitle());
  176. $move = Display::return_icon('all_directions.png',get_lang('Move'), array('class'=>'moved', 'style'=>'margin-bottom:-0.5em;'));
  177. // Question name
  178. $questionName = Display::tag('div', '<a href="#" title = "'.$title.'">'.$move.' '.cut($title, 60).'</a>', array('style'=>$styleQuestion));
  179. // Question type
  180. list($typeImg, $typeExpl) = $objQuestionTmp->get_type_icon_html();
  181. $questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), 32), array('style'=>$styleType));
  182. // Question category
  183. $txtQuestionCat = Security::remove_XSS(Testcategory::getCategoryNameForQuestion($objQuestionTmp->id));
  184. if (empty($txtQuestionCat)) {
  185. $txtQuestionCat = "-";
  186. }
  187. $questionCategory = Display::tag('div', '<a href="#" style="padding:0px; margin:0px;" title="'.$txtQuestionCat.'">'.cut($txtQuestionCat, 55).'</a>', array('style'=>$styleCat));
  188. // Question level
  189. $txtQuestionLevel = $objQuestionTmp->level;
  190. if (empty($objQuestionTmp->level)) {
  191. $txtQuestionLevel = '-';
  192. }
  193. $questionLevel = Display::tag('div', $txtQuestionLevel, array('style'=>$styleLevel));
  194. // Question score
  195. $questionScore = Display::tag('div', $objQuestionTmp->selectWeighting(), array('style'=>$styleScore));
  196. echo '<div id="question_id_list_'.$id.'" >';
  197. echo '<div class="header_operations">';
  198. echo $questionName;
  199. echo $questionType;
  200. echo $questionCategory;
  201. echo $questionLevel;
  202. echo $questionScore;
  203. echo $actions;
  204. echo '</div>';
  205. echo '<div class="question-list-description-block">';
  206. echo '<p>';
  207. //echo get_lang($question_class.$label);
  208. echo get_lang($question_class);
  209. echo '<br />';
  210. //echo get_lang('Level').': '.$objQuestionTmp->selectLevel();
  211. echo '<br />';
  212. showQuestion($id, false, '', '',false, true);
  213. echo '</p>';
  214. echo '</div>';
  215. echo '</div>';
  216. unset($objQuestionTmp);
  217. }
  218. }
  219. }
  220. if(!$nbrQuestions) {
  221. echo Display::display_warning_message(get_lang('NoQuestion'));
  222. }
  223. echo '</div>'; //question list div
  224. }