addlimits.php 4.9 KB

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