addlimits.php 5.6 KB

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