addlimits.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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 = mysql_real_escape_string($_REQUEST['learnpath_id']);
  89. }
  90. if ( empty ( $learnpath_item_id ) )
  91. {
  92. $learnpath_item_id = mysql_real_escape_string($_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 = mysql_real_escape_string($_REQUEST['questionNum']);
  112. }
  113. if ( empty ( $nbrQuestions ) )
  114. {
  115. $nbrQuestions = mysql_real_escape_string($_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 = $_GET['exercise_id'];
  126. $is_allowedToEdit=$is_courseAdmin;
  127. $nameTools=get_lang('Exercice');
  128. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  129. Display::display_header($nameTools,"Exercise");
  130. /*
  131. -----------------------------------------------------------
  132. Action handling
  133. -----------------------------------------------------------
  134. */
  135. include('../inc/global.inc.php');
  136. if (isset($_POST['ok']))
  137. {
  138. $message = get_lang('TestLimitsAdded');
  139. Display::display_normal_message($message);
  140. }
  141. ?>
  142. <script type="text/javascript">
  143. function selectlimited()
  144. {
  145. document.getElementById('limited').checked="checked";
  146. }
  147. function selectattempts()
  148. {
  149. document.getElementById('attemptlimited').checked="checked";
  150. }
  151. </script>
  152. <h3><?php echo get_lang('AddLimits'); ?></h3>
  153. <br>
  154. <form action="addlimits.php" name="frmlimit" method="post">
  155. <h4>
  156. Time :
  157. </h4>
  158. <input type="hidden" name="exe_id" value="<?php echo $exercise_id; ?>" />
  159. <input type="radio" name="limit" checked="checked" value="0" id="unlimit"><?php echo get_lang('Unlimited'); ?>
  160. <br>
  161. <input type="radio" name="limit" value="1" id="limited"><?php echo get_lang('LimitedTime'); ?>
  162. <select name="minutes" onfocus="selectlimited();" >
  163. <option selected="selected">1</option>
  164. <option>2</option>
  165. <option>3</option>
  166. <option>4</option>
  167. <option>5</option>
  168. <option>6</option>
  169. <option>7</option>
  170. <option>8</option>
  171. <option>9</option>
  172. <option>10</option>
  173. <option>15</option>
  174. <option>20</option>
  175. <option>25</option>
  176. <option>30</option>
  177. <option>40</option>
  178. <option>50</option>
  179. <option>60</option>
  180. </select><?php echo get_lang('Minutes'); ?>.
  181. <h4>
  182. <?php echo get_lang('Attempts'); ?>:
  183. </h4>
  184. <input type="radio" name="attempt" checked="checked" value="0" id="attemptunlimited"><?php echo get_lang('Unlimited'); ?>
  185. <br>
  186. <input type="radio" name="attempt" value="1" id="attemptlimited"><?php echo get_lang('LimitedAttempts'); ?>
  187. <select name="attempts" onfocus="selectattempts();">
  188. <option selected="selected">1</option>
  189. <option>2</option>
  190. <option>3</option>
  191. <option>4</option>
  192. <option>5</option>
  193. <option>6</option>
  194. <option>7</option>
  195. <option>8</option>
  196. <option>9</option>
  197. <option>10</option>
  198. </select><?php echo get_lang('Times'); ?>.
  199. <br> <br>
  200. <input type="submit" name="ok" value="<?php echo get_lang('Ok'); ?>">
  201. </form>
  202. <?php
  203. /**
  204. * @todo shouldn't this be moved to the part above (around line 111: action handling)
  205. */
  206. if (isset($_POST['ok']))
  207. {
  208. $exercise_id = $_POST['exe_id'];
  209. if ($_POST['limit']==1)
  210. {
  211. $minutes = $_POST['minutes'];
  212. $query = "update `".$TBL_EXERCICES."` set ques_time_limit= $minutes where id= $exercise_id";
  213. api_sql_query($query,__FILE__,__LINE__);
  214. }
  215. else
  216. {
  217. $query = "update `".$TBL_EXERCICES."` set ques_time_limit= 0 where id= $exercise_id";
  218. api_sql_query($query,__FILE__,__LINE__);
  219. }
  220. if ($_POST['attempt']==1)
  221. {
  222. $attempts = $_POST['attempts'];
  223. $query = "update `".$TBL_EXERCICES."` set num_attempts = $attempts where id= $exercise_id";
  224. api_sql_query($query,__FILE__,__LINE__);
  225. }
  226. else
  227. {
  228. $query = "update`".$TBL_EXERCICES."` set num_attempts = 0 where id= $exercise_id";
  229. api_sql_query($query,__FILE__,__LINE__);
  230. }
  231. }
  232. ?>