question_pool.php 8.8 KB

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