addlimits.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. * Adding limits
  18. * @package dokeos.exercise
  19. * @author
  20. * @version $Id: admin.php 10680 2007-01-11 21:26:23Z pcool $
  21. */
  22. /*
  23. -----------------------------------------------------------
  24. including the global file
  25. -----------------------------------------------------------
  26. */
  27. include('../inc/global.inc.php');
  28. /*
  29. -----------------------------------------------------------
  30. Including necessary files
  31. -----------------------------------------------------------
  32. */
  33. include('exercise.class.php');
  34. include('question.class.php');
  35. include('answer.class.php');
  36. include_once(api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  37. /*
  38. -----------------------------------------------------------
  39. Answer types
  40. -----------------------------------------------------------
  41. */
  42. define('UNIQUE_ANSWER', 1);
  43. define('MULTIPLE_ANSWER', 2);
  44. define('FILL_IN_BLANKS', 3);
  45. define('MATCHING', 4);
  46. define('FREE_ANSWER', 5);
  47. /*
  48. -----------------------------------------------------------
  49. Language
  50. -----------------------------------------------------------
  51. */
  52. // name of the language file that needs to be included
  53. $language_file='exercice';
  54. /*
  55. -----------------------------------------------------------
  56. section (for the tabs)
  57. -----------------------------------------------------------
  58. */
  59. $this_section=SECTION_COURSES;
  60. api_protect_course_script();
  61. /*
  62. -----------------------------------------------------------
  63. Table definitions
  64. @todo: use the Database :: get_course_table functions
  65. -----------------------------------------------------------
  66. */
  67. $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  68. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  69. $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
  70. $TBL_REPONSES = Database::get_course_table('quiz_answer');
  71. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  72. $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  73. $TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  74. $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  75. $dsp_percent = false;
  76. $debug=0;
  77. if($debug>0)
  78. {
  79. echo str_repeat('&nbsp;',0).'Entered exercise_result.php'."<br />\n";var_dump($_POST);
  80. }
  81. // general parameters passed via POST/GET
  82. if ( empty ( $origin ) )
  83. {
  84. $origin = $_REQUEST['origin'];
  85. }
  86. if ( empty ( $learnpath_id ) )
  87. {
  88. $learnpath_id = $_REQUEST['learnpath_id'];
  89. }
  90. if ( empty ( $learnpath_item_id ) )
  91. {
  92. $learnpath_item_id = $_REQUEST['learnpath_item_id'];
  93. }
  94. if ( empty ( $formSent ) )
  95. {
  96. $formSent= $_REQUEST['formSent'];
  97. }
  98. if ( empty ( $exerciseResult ) )
  99. {
  100. $exerciseResult = $_SESSION['exerciseResult'];
  101. }
  102. if ( empty ( $questionId ) )
  103. {
  104. $questionId = $_REQUEST['questionId'];
  105. }
  106. if ( empty ( $choice ) ) {
  107. $choice = $_REQUEST['choice'];
  108. }
  109. if ( empty ( $questionNum ) )
  110. {
  111. $questionNum = $_REQUEST['questionNum'];
  112. }
  113. if ( empty ( $nbrQuestions ) )
  114. {
  115. $nbrQuestions = $_REQUEST['nbrQuestions'];
  116. }
  117. if ( empty ( $questionList ) )
  118. {
  119. $questionList = $_SESSION['questionList'];
  120. }
  121. if ( empty ( $objExercise ) )
  122. {
  123. $objExercise = $_SESSION['objExercise'];
  124. }
  125. $exercise_id = intval($_GET['exercise_id']);
  126. $is_allowedToEdit=$is_courseAdmin;
  127. if (isset($_SESSION['gradebook'])){
  128. $gradebook= $_SESSION['gradebook'];
  129. }
  130. if (!empty($gradebook) && $gradebook=='view') {
  131. $interbreadcrumb[]= array (
  132. 'url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']),
  133. 'name' => get_lang('Gradebook')
  134. );
  135. }
  136. $nameTools=get_lang('Exercice');
  137. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  138. Display::display_header($nameTools,"Exercise");
  139. /*
  140. -----------------------------------------------------------
  141. Action handling
  142. -----------------------------------------------------------
  143. */
  144. include('../inc/global.inc.php');
  145. if (isset($_POST['ok']))
  146. {
  147. $message = get_lang('TestLimitsAdded');
  148. Display::display_normal_message($message);
  149. }
  150. ?>
  151. <script type="text/javascript">
  152. function selectlimited()
  153. {
  154. document.getElementById('limited').checked="checked";
  155. }
  156. function selectattempts()
  157. {
  158. document.getElementById('attemptlimited').checked="checked";
  159. }
  160. </script>
  161. <h3><?php echo get_lang('AddLimits'); ?></h3>
  162. <br>
  163. <form action="addlimits.php" name="frmlimit" method="post">
  164. <h4>
  165. Time :
  166. </h4>
  167. <input type="hidden" name="exe_id" value="<?php echo $exercise_id; ?>" />
  168. <input type="radio" name="limit" checked="checked" value="0" id="unlimit"><?php echo get_lang('Unlimited'); ?>
  169. <br>
  170. <input type="radio" name="limit" value="1" id="limited"><?php echo get_lang('LimitedTime'); ?>
  171. <select name="minutes" onfocus="selectlimited();" >
  172. <option selected="selected">1</option>
  173. <option>2</option>
  174. <option>3</option>
  175. <option>4</option>
  176. <option>5</option>
  177. <option>6</option>
  178. <option>7</option>
  179. <option>8</option>
  180. <option>9</option>
  181. <option>10</option>
  182. <option>15</option>
  183. <option>20</option>
  184. <option>25</option>
  185. <option>30</option>
  186. <option>40</option>
  187. <option>50</option>
  188. <option>60</option>
  189. </select><?php echo get_lang('Minutes'); ?>.
  190. <h4>
  191. <?php echo get_lang('Attempts'); ?>:
  192. </h4>
  193. <input type="radio" name="attempt" checked="checked" value="0" id="attemptunlimited"><?php echo get_lang('Unlimited'); ?>
  194. <br>
  195. <input type="radio" name="attempt" value="1" id="attemptlimited"><?php echo get_lang('LimitedAttempts'); ?>
  196. <select name="attempts" onfocus="selectattempts();">
  197. <option selected="selected">1</option>
  198. <option>2</option>
  199. <option>3</option>
  200. <option>4</option>
  201. <option>5</option>
  202. <option>6</option>
  203. <option>7</option>
  204. <option>8</option>
  205. <option>9</option>
  206. <option>10</option>
  207. </select><?php echo get_lang('Times'); ?>.
  208. <br> <br>
  209. <input type="submit" name="ok" value="<?php echo get_lang('Ok'); ?>">
  210. </form>
  211. <?php
  212. /**
  213. * @todo shouldn't this be moved to the part above (around line 111: action handling)
  214. */
  215. if (isset($_POST['ok'])) {
  216. $exercise_id = Database::escape_string($_POST['exe_id']);
  217. if ($_POST['limit']==1) {
  218. $minutes = Database::escape_string($_POST['minutes']);
  219. $query = "UPDATE ".$TBL_EXERCICES." SET ques_time_limit= $minutes where id= $exercise_id";
  220. api_sql_query($query,__FILE__,__LINE__);
  221. } else {
  222. $query = "UPDATE ".$TBL_EXERCICES." SET ques_time_limit= 0 WHERE id= $exercise_id";
  223. api_sql_query($query,__FILE__,__LINE__);
  224. }
  225. if ($_POST['attempt']==1) {
  226. $attempts = Database::escape_string($_POST['attempts']);
  227. $query = "UPDATE ".$TBL_EXERCICES." SET num_attempts = $attempts WHERE id= $exercise_id";
  228. api_sql_query($query,__FILE__,__LINE__);
  229. } else {
  230. $query = "UPDATE ".$TBL_EXERCICES." SET num_attempts = 0 WHERE id= $exercise_id";
  231. api_sql_query($query,__FILE__,__LINE__);
  232. }
  233. }
  234. ?>