addlimits.php 4.4 KB

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