addlimits.php 6.3 KB

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