addlimits.php 5.9 KB

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