addlimits.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php
  2. /*
  3. -----------------------------------------------------------
  4. including the global file
  5. -----------------------------------------------------------
  6. */
  7. include('../inc/global.inc.php');
  8. /*
  9. -----------------------------------------------------------
  10. Including necessary files
  11. -----------------------------------------------------------
  12. */
  13. include('exercise.class.php');
  14. include('question.class.php');
  15. include('answer.class.php');
  16. include_once(api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  17. /*
  18. -----------------------------------------------------------
  19. Answer types
  20. -----------------------------------------------------------
  21. */
  22. define('UNIQUE_ANSWER', 1);
  23. define('MULTIPLE_ANSWER', 2);
  24. define('FILL_IN_BLANKS', 3);
  25. define('MATCHING', 4);
  26. define('FREE_ANSWER', 5);
  27. /*
  28. -----------------------------------------------------------
  29. Language
  30. -----------------------------------------------------------
  31. */
  32. $langFile='exercice';
  33. /*
  34. -----------------------------------------------------------
  35. section (for the tabs)
  36. -----------------------------------------------------------
  37. */
  38. $this_section=SECTION_COURSES;
  39. api_protect_course_script();
  40. /*
  41. -----------------------------------------------------------
  42. Table definitions
  43. @todo: use the Database :: get_course_table functions
  44. -----------------------------------------------------------
  45. */
  46. $TBL_EXERCICE_QUESTION = $_course['dbNameGlu'].'quiz_rel_question';
  47. $TBL_EXERCICES = $_course['dbNameGlu'].'quiz';
  48. $TBL_QUESTIONS = $_course['dbNameGlu'].'quiz_question';
  49. $TBL_REPONSES = $_course['dbNameGlu'].'quiz_answer';
  50. $main_user_table = Database :: get_main_table(MAIN_USER_TABLE);
  51. $main_course_user_table = Database :: get_main_table(MAIN_COURSE_USER_TABLE);
  52. $statsdb = $statsDbName;
  53. $TABLETRACK_ATTEMPT = $statsDbName."`.`track_e_attempt";
  54. $TABLETRACK_EXERCICES = $statsDbName."`.`track_e_exercices";
  55. $dsp_percent = false;
  56. $debug=0;
  57. if($debug>0){echo str_repeat('&nbsp;',0).'Entered exercise_result.php'."<br />\n";var_dump($_POST);}
  58. // general parameters passed via POST/GET
  59. if ( empty ( $origin ) ) {
  60. $origin = $_REQUEST['origin'];
  61. }
  62. if ( empty ( $learnpath_id ) ) {
  63. $learnpath_id = mysql_real_escape_string($_REQUEST['learnpath_id']);
  64. }
  65. if ( empty ( $learnpath_item_id ) ) {
  66. $learnpath_item_id = mysql_real_escape_string($_REQUEST['learnpath_item_id']);
  67. }
  68. if ( empty ( $formSent ) ) {
  69. $formSent= $_REQUEST['formSent'];
  70. }
  71. if ( empty ( $exerciseResult ) ) {
  72. $exerciseResult = $_SESSION['exerciseResult'];
  73. }
  74. if ( empty ( $questionId ) ) {
  75. $questionId = $_REQUEST['questionId'];
  76. }
  77. if ( empty ( $choice ) ) {
  78. $choice = $_REQUEST['choice'];
  79. }
  80. if ( empty ( $questionNum ) ) {
  81. $questionNum = mysql_real_escape_string($_REQUEST['questionNum']);
  82. }
  83. if ( empty ( $nbrQuestions ) ) {
  84. $nbrQuestions = mysql_real_escape_string($_REQUEST['nbrQuestions']);
  85. }
  86. if ( empty ( $questionList ) ) {
  87. $questionList = $_SESSION['questionList'];
  88. }
  89. if ( empty ( $objExercise ) ) {
  90. $objExercise = $_SESSION['objExercise'];
  91. }
  92. $exercise_id = $_GET['exercise_id'];
  93. $is_allowedToEdit=$is_courseAdmin;
  94. $nameTools=get_lang('Exercice');
  95. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  96. Display::display_header($nameTools,"Exercise");
  97. /*
  98. -----------------------------------------------------------
  99. Action handling
  100. -----------------------------------------------------------
  101. */
  102. include('../inc/global.inc.php');
  103. if (isset($_POST['ok']))
  104. {
  105. $message = "Test limits added";
  106. Display::display_normal_message($message);
  107. }
  108. ?>
  109. <script type="text/javascript">
  110. function selectlimited()
  111. {
  112. document.getElementById('limited').checked="checked";
  113. }
  114. function selectattempts()
  115. {
  116. document.getElementById('attemptlimited').checked="checked";
  117. }
  118. </script>
  119. <h3>
  120. <?php
  121. echo "AddLimits"; ?>
  122. </h3>
  123. <br>
  124. <form action="addlimits.php" name="frmlimit" method="post">
  125. <h4>
  126. Time :
  127. </h4>
  128. <input type="hidden" name="exe_id" value="<?php echo $exercise_id; ?>" />
  129. <input type="radio" name="limit" checked="checked" value="0" id="unlimit"> Unlimited
  130. <br>
  131. <input type="radio" name="limit" value="1" id="limited"> Limited: Each question of the test should be answered in
  132. <select name="minutes" onfocus="selectlimited();" >
  133. <option selected="selected">1</option>
  134. <option>2</option>
  135. <option>3</option>
  136. <option>4</option>
  137. <option>5</option>
  138. <option>6</option>
  139. <option>7</option>
  140. <option>8</option>
  141. <option>9</option>
  142. <option>10</option>
  143. <option>15</option>
  144. <option>20</option>
  145. <option>25</option>
  146. <option>30</option>
  147. <option>40</option>
  148. <option>50</option>
  149. <option>60</option>
  150. </select> minute(s).
  151. <h4>
  152. Attempts :
  153. </h4>
  154. <input type="radio" name="attempt" checked="checked" value="0" id="attemptunlimited"> Unlimited
  155. <br>
  156. <input type="radio" name="attempt" value="1" id="attemptlimited"> Limited: The test can be taken only
  157. <select name="attempts" onfocus="selectattempts();">
  158. <option selected="selected">1</option>
  159. <option>2</option>
  160. <option>3</option>
  161. <option>4</option>
  162. <option>5</option>
  163. <option>6</option>
  164. <option>7</option>
  165. <option>8</option>
  166. <option>9</option>
  167. <option>10</option>
  168. </select> time(s).
  169. <br> <br>
  170. <input type="submit" name="ok" value="Ok">
  171. </form>
  172. <?php
  173. /**
  174. * @todo shouldn't this be moved to the part above (around line 111: action handling)
  175. */
  176. if (isset($_POST['ok']))
  177. {
  178. $exercise_id = $_POST['exe_id'];
  179. if ($_POST['limit']==1)
  180. {
  181. $minutes = $_POST['minutes'];
  182. $query = "update `".$TBL_EXERCICES."` set ques_time_limit= $minutes where id= $exercise_id";
  183. api_sql_query($query,_FILE_,_LINE_);
  184. }
  185. else
  186. {
  187. $query = "update `".$TBL_EXERCICES."` set ques_time_limit= 0 where id= $exercise_id";
  188. api_sql_query($query,_FILE_,_LINE_);
  189. }
  190. if ($_POST['attempt']==1)
  191. {
  192. $attempts = $_POST['attempts'];
  193. $query = "update `".$TBL_EXERCICES."` set num_attempts = $attempts where id= $exercise_id";
  194. api_sql_query($query,_FILE_,_LINE_);
  195. }
  196. else
  197. {
  198. $query = "update`".$TBL_EXERCICES."` set num_attempts = 0 where id= $exercise_id";
  199. api_sql_query($query,_FILE_,_LINE_);
  200. }
  201. }
  202. ?>