question_pool.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <?php
  2. /*
  3. DOKEOS - elearning and course management software
  4. For a full list of contributors, see documentation/credits.html
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. See "documentation/licence.html" more details.
  10. Contact:
  11. Dokeos
  12. Rue des Palais 44 Paleizenstraat
  13. B-1030 Brussels - Belgium
  14. Tel. +32 (2) 211 34 56
  15. */
  16. /**
  17. * Question Pool
  18. * This script allows administrators to manage questions and add them into their exercises.
  19. * One question can be in several exercises
  20. * @package dokeos.exercise
  21. * @author Olivier Brouckaert
  22. * @version $Id: question_pool.php 13476 2007-10-12 11:38:16Z elixir_inter $
  23. */
  24. // name of the language file that needs to be included
  25. $language_file='exercice';
  26. include('exercise.class.php');
  27. include('question.class.php');
  28. include('answer.class.php');
  29. include('../inc/global.inc.php');
  30. $this_section=SECTION_COURSES;
  31. $is_allowedToEdit=api_is_allowed_to_edit();
  32. $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  33. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  34. $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
  35. $TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
  36. if ( empty ( $delete ) ) {
  37. $delete = $_GET['delete'];
  38. }
  39. if ( empty ( $recup ) ) {
  40. $recup = $_GET['recup'];
  41. }
  42. if ( empty ( $fromExercise ) ) {
  43. $fromExercise = $_GET['fromExercise'];
  44. }
  45. if(isset($_GET['exerciseId'])){
  46. $exerciseId = $_GET['exerciseId'];
  47. }
  48. // maximum number of questions on a same page
  49. $limitQuestPage=50;
  50. // document path
  51. $documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
  52. // picture path
  53. $picturePath=$documentPath.'/images';
  54. if($is_allowedToEdit)
  55. {
  56. // deletes a question from the data base and all exercises
  57. if($delete)
  58. {
  59. // construction of the Question object
  60. // if the question exists
  61. if($objQuestionTmp = Question::read($delete))
  62. {
  63. // deletes the question from all exercises
  64. $objQuestionTmp->delete();
  65. }
  66. // destruction of the Question object
  67. unset($objQuestionTmp);
  68. }
  69. // gets an existing question and copies it into a new exercise
  70. elseif($recup && $fromExercise)
  71. {
  72. // if the question exists
  73. if($objQuestionTmp = Question :: read($recup))
  74. {
  75. // adds the exercise ID represented by $fromExercise into the list of exercises for the current question
  76. $objQuestionTmp->addToList($fromExercise);
  77. }
  78. // destruction of the Question object
  79. unset($objQuestionTmp);
  80. // adds the question ID represented by $recup into the list of questions for the current exercise
  81. $objExercise->addToList($recup);
  82. api_session_register('objExercise');
  83. header("Location: admin.php?exerciseId=$fromExercise");
  84. exit();
  85. }
  86. }
  87. $nameTools=get_lang('QuestionPool');
  88. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  89. // if admin of course
  90. if($is_allowedToEdit)
  91. {
  92. Display::display_header($nameTools,"Exercise");
  93. ?>
  94. <h3>
  95. <?php echo $nameTools; ?>
  96. </h3>
  97. <form method="get" action="<?php echo api_get_self(); ?>">
  98. <input type="hidden" name="fromExercise" value="<?php echo $fromExercise; ?>">
  99. <table class="data_table">
  100. <tr>
  101. <td colspan="<?php echo $fromExercise?2:3; ?>" align="right">
  102. <?php echo get_lang('Filter'); ?> : <select name="exerciseId">
  103. <option value="0">-- <?php echo get_lang('AllExercises'); ?> --</option>
  104. <option value="-1" <?php if($exerciseId == -1) echo 'selected="selected"'; ?>>-- <?php echo get_lang('OrphanQuestions'); ?> --</option>
  105. <?php
  106. $sql="SELECT id,title FROM $TBL_EXERCICES WHERE id<>'$fromExercise' AND active<>'-1' ORDER BY id";
  107. $result=api_sql_query($sql,__FILE__,__LINE__);
  108. // shows a list-box allowing to filter questions
  109. while($row=mysql_fetch_array($result))
  110. {
  111. ?>
  112. <option value="<?php echo $row['id']; ?>" <?php if($exerciseId == $row['id']) echo 'selected="selected"'; ?>><?php echo $row['title']; ?></option>
  113. <?php
  114. }
  115. ?>
  116. </select> <input type="submit" value="<?php echo get_lang('Ok'); ?>">
  117. </td>
  118. </tr>
  119. <?php
  120. $from=$page*$limitQuestPage;
  121. // if we have selected an exercise in the list-box 'Filter'
  122. if($exerciseId > 0)
  123. {
  124. $sql="SELECT id,question,type FROM $TBL_EXERCICE_QUESTION,$TBL_QUESTIONS WHERE question_id=id AND exercice_id='$exerciseId' ORDER BY position";
  125. }
  126. // if we have selected the option 'Orphan questions' in the list-box 'Filter'
  127. elseif($exerciseId == -1)
  128. {
  129. $sql='SELECT id, question, type, exercice_id FROM '.$TBL_QUESTIONS.' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions ON questions.id=quizz_questions.question_id AND exercice_id IS NULL';
  130. }
  131. // if we have not selected any option in the list-box 'Filter'
  132. else
  133. {
  134. $sql="SELECT id,question,type FROM $TBL_QUESTIONS";
  135. // forces the value to 0
  136. $exerciseId=0;
  137. }
  138. $result=api_sql_query($sql,__FILE__,__LINE__);
  139. $nbrQuestions=mysql_num_rows($result);
  140. ?>
  141. <tr>
  142. <td colspan="<?php echo $fromExercise?2:3; ?>">
  143. <table border="0" cellpadding="0" cellspacing="0" width="100%">
  144. <tr>
  145. <td>
  146. <?php
  147. if($fromExercise)
  148. {
  149. ?>
  150. <a href="admin.php?exerciseId=<?php echo $fromExercise; ?>">&lt;&lt; <?php echo get_lang('GoBackToEx'); ?></a>
  151. <?php
  152. }
  153. else
  154. {
  155. ?>
  156. <a href="admin.php?newQuestion=yes"><?php echo get_lang('NewQu'); ?></a>
  157. <?php
  158. }
  159. ?>
  160. </td>
  161. <td align="right">
  162. <?php
  163. if($page)
  164. {
  165. ?>
  166. <a href="<?php echo api_get_self(); ?>?exerciseId=<?php echo $exerciseId; ?>&fromExercise=<?php echo $fromExercise; ?>&page=<?php echo ($page-1); ?>">&lt;&lt; <?php echo get_lang('PreviousPage'); ?></a> |
  167. <?php
  168. }
  169. elseif($nbrQuestions > $limitQuestPage)
  170. {
  171. ?>
  172. &lt;&lt; <?php echo get_lang('PreviousPage'); ?> |
  173. <?php
  174. }
  175. if($nbrQuestions > $limitQuestPage)
  176. {
  177. ?>
  178. <a href="<?php echo api_get_self(); ?>?exerciseId=<?php echo $exerciseId; ?>&fromExercise=<?php echo $fromExercise; ?>&page=<?php echo ($page+1); ?>"><?php echo get_lang('NextPage'); ?> &gt;&gt;</a>
  179. <?php
  180. }
  181. elseif($page)
  182. {
  183. ?>
  184. <?php echo get_lang('NextPage'); ?> &gt;&gt;
  185. <?php
  186. }
  187. ?>
  188. </td>
  189. </tr>
  190. </table>
  191. </td>
  192. </tr>
  193. <tr bgcolor="#E6E6E6">
  194. <?php
  195. if($fromExercise)
  196. {
  197. ?>
  198. <th><?php echo get_lang('Question'); ?></th>
  199. <th><?php echo get_lang('Reuse'); ?></th>
  200. <?php
  201. }
  202. else
  203. {
  204. ?>
  205. <td width="60%" align="center"><?php echo get_lang('Question'); ?></td>
  206. <td width="20%" align="center"><?php echo get_lang('Modify'); ?></td>
  207. <td width="20%" align="center"><?php echo get_lang('Delete'); ?></td>
  208. <?php
  209. }
  210. ?>
  211. </tr>
  212. <?php
  213. $i=1;
  214. while($row=mysql_fetch_array($result))
  215. {
  216. // if we come from the exercise administration to get a question, doesn't show the question already used by that exercise
  217. if(!$fromExercise || !$objExercise->isInList($row[id]))
  218. {
  219. ?>
  220. <tr <?php if($i%2==0) echo 'class="row_odd"'; else echo 'class="row_even"'; ?>>
  221. <td><a href="admin.php?editQuestion=<?php echo $row[id]; ?>&fromExercise=<?php echo $fromExercise; ?>"><?php echo $row[question]; ?></a></td>
  222. <td>
  223. <?php
  224. if(!$fromExercise)
  225. {
  226. ?>
  227. <a href="admin.php?editQuestion=<?php echo $row[id]; ?>"><img src="../img/edit.gif" border="0" alt="<?php echo get_lang('Modify'); ?>"></a>
  228. <?php
  229. }
  230. else
  231. {
  232. ?>
  233. <a href="<?php echo $phpSelf; ?>?recup=<?php echo $row[id]; ?>&fromExercise=<?php echo $fromExercise; ?>"><img src="../img/view_more_stats.gif" border="0" alt="<?php echo get_lang('Reuse'); ?>"></a>
  234. <?php
  235. }
  236. ?>
  237. </td>
  238. <?php
  239. if(!$fromExercise)
  240. {
  241. ?>
  242. <td align="center">
  243. <a href="<?php echo api_get_self(); ?>?exerciseId=<?php echo $exerciseId; ?>&delete=<?php echo $row[id]; ?>" onclick="javascript:if(!confirm('<?php echo addslashes(htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)); ?>')) return false;"><img src="../img/delete.gif" border="0" alt="<?php echo get_lang('Delete'); ?>"></a>
  244. </td>
  245. <?php
  246. }
  247. ?>
  248. </tr>
  249. <?php
  250. // skips the last question, that is only used to know if we have or not to create a link "Next page"
  251. if($i == $limitQuestPage)
  252. {
  253. break;
  254. }
  255. $i++;
  256. }
  257. }
  258. if(!$nbrQuestions)
  259. {
  260. ?>
  261. <tr>
  262. <td colspan="<?php echo $fromExercise?2:3; ?>"><?php echo get_lang('NoQuestion'); ?></td>
  263. </tr>
  264. <?php
  265. }
  266. ?>
  267. </table>
  268. </form>
  269. <?php
  270. Display::display_footer();
  271. }
  272. // if not admin of course
  273. else
  274. {
  275. api_not_allowed(true);
  276. }
  277. ?>