addlimits.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. // name of the language file that needs to be included
  20. $language_file = 'exercice';
  21. /* section (for the tabs) */
  22. $this_section = SECTION_COURSES;
  23. api_protect_course_script();
  24. $dsp_percent = false;
  25. $debug=0;
  26. // general parameters passed via POST/GET
  27. if ( empty ( $origin ) )
  28. {
  29. $origin = $_REQUEST['origin'];
  30. }
  31. if ( empty ( $learnpath_id ) )
  32. {
  33. $learnpath_id = $_REQUEST['learnpath_id'];
  34. }
  35. if ( empty ( $learnpath_item_id ) )
  36. {
  37. $learnpath_item_id = $_REQUEST['learnpath_item_id'];
  38. }
  39. if ( empty ( $formSent ) )
  40. {
  41. $formSent= $_REQUEST['formSent'];
  42. }
  43. if ( empty ( $exerciseResult ) )
  44. {
  45. $exerciseResult = $_SESSION['exerciseResult'];
  46. }
  47. if ( empty ( $questionId ) )
  48. {
  49. $questionId = $_REQUEST['questionId'];
  50. }
  51. if ( empty ( $choice ) ) {
  52. $choice = $_REQUEST['choice'];
  53. }
  54. if ( empty ( $questionNum ) )
  55. {
  56. $questionNum = $_REQUEST['questionNum'];
  57. }
  58. if ( empty ( $nbrQuestions ) )
  59. {
  60. $nbrQuestions = $_REQUEST['nbrQuestions'];
  61. }
  62. if ( empty ( $questionList ) )
  63. {
  64. $questionList = $_SESSION['questionList'];
  65. }
  66. if ( empty ( $objExercise ) )
  67. {
  68. $objExercise = $_SESSION['objExercise'];
  69. }
  70. $exercise_id = intval($_GET['exercise_id']);
  71. $is_allowedToEdit=api_is_course_admin();
  72. if (isset($_SESSION['gradebook'])){
  73. $gradebook= $_SESSION['gradebook'];
  74. }
  75. if (!empty($gradebook) && $gradebook=='view') {
  76. $interbreadcrumb[]= array (
  77. 'url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']),
  78. 'name' => get_lang('ToolGradebook')
  79. );
  80. }
  81. $nameTools=get_lang('Exercice');
  82. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  83. Display::display_header($nameTools,"Exercise");
  84. /*
  85. Action handling
  86. */
  87. require_once '../inc/global.inc.php';
  88. if (isset($_POST['ok'])) {
  89. $message = get_lang('TestLimitsAdded');
  90. Display::display_normal_message($message);
  91. }
  92. ?>
  93. <script type="text/javascript">
  94. function selectlimited()
  95. {
  96. document.getElementById('limited').checked="checked";
  97. }
  98. function selectattempts()
  99. {
  100. document.getElementById('attemptlimited').checked="checked";
  101. }
  102. </script>
  103. <h3><?php echo get_lang('AddLimits'); ?></h3>
  104. <br>
  105. <form action="addlimits.php" name="frmlimit" method="post">
  106. <h4>
  107. Time :
  108. </h4>
  109. <input type="hidden" name="exe_id" value="<?php echo $exercise_id; ?>" />
  110. <input type="radio" name="limit" checked="checked" value="0" id="unlimit"><?php echo get_lang('Unlimited'); ?>
  111. <br>
  112. <input type="radio" name="limit" value="1" id="limited"><?php echo get_lang('LimitedTime'); ?>
  113. <select name="minutes" onfocus="selectlimited();" >
  114. <option selected="selected">1</option>
  115. <option>2</option>
  116. <option>3</option>
  117. <option>4</option>
  118. <option>5</option>
  119. <option>6</option>
  120. <option>7</option>
  121. <option>8</option>
  122. <option>9</option>
  123. <option>10</option>
  124. <option>15</option>
  125. <option>20</option>
  126. <option>25</option>
  127. <option>30</option>
  128. <option>40</option>
  129. <option>50</option>
  130. <option>60</option>
  131. </select><?php echo get_lang('Minutes'); ?>.
  132. <h4>
  133. <?php echo get_lang('Attempts'); ?>:
  134. </h4>
  135. <input type="radio" name="attempt" checked="checked" value="0" id="attemptunlimited"><?php echo get_lang('Unlimited'); ?>
  136. <br>
  137. <input type="radio" name="attempt" value="1" id="attemptlimited"><?php echo get_lang('LimitedAttempts'); ?>
  138. <select name="attempts" onfocus="selectattempts();">
  139. <option selected="selected">1</option>
  140. <option>2</option>
  141. <option>3</option>
  142. <option>4</option>
  143. <option>5</option>
  144. <option>6</option>
  145. <option>7</option>
  146. <option>8</option>
  147. <option>9</option>
  148. <option>10</option>
  149. </select><?php echo get_lang('Times'); ?>.
  150. <br> <br>
  151. <input type="submit" name="ok" value="<?php echo get_lang('Ok'); ?>">
  152. </form>
  153. <?php
  154. /**
  155. * @todo shouldn't this be moved to the part above (around line 111: action handling)
  156. */
  157. if (isset($_POST['ok'])) {
  158. $exercise_id = Database::escape_string($_POST['exe_id']);
  159. if ($_POST['limit']==1) {
  160. $minutes = Database::escape_string($_POST['minutes']);
  161. $query = "UPDATE ".$TBL_EXERCICES." SET ques_time_limit= $minutes WHERE id= $exercise_id";
  162. Database::query($query);
  163. } else {
  164. $query = "UPDATE ".$TBL_EXERCICES." SET ques_time_limit= 0 WHERE id= $exercise_id";
  165. Database::query($query);
  166. }
  167. if ($_POST['attempt']==1) {
  168. $attempts = Database::escape_string($_POST['attempts']);
  169. $query = "UPDATE ".$TBL_EXERCICES." SET num_attempts = $attempts WHERE id= $exercise_id";
  170. Database::query($query);
  171. } else {
  172. $query = "UPDATE ".$TBL_EXERCICES." SET num_attempts = 0 WHERE id= $exercise_id";
  173. Database::query($query);
  174. }
  175. }