addlimits.php 4.9 KB

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