exercise_reminder.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * Exercise reminder overview
  6. * Then it shows the results on the screen.
  7. * @package chamilo.exercise
  8. * @author Julio Montoya switchable fill in blank option added
  9. */
  10. require_once __DIR__.'/../inc/global.inc.php';
  11. $this_section = SECTION_COURSES;
  12. /* ACCESS RIGHTS */
  13. // notice for unauthorized people.
  14. api_protect_course_script(true);
  15. if ($debug > 0) {
  16. error_log('Entered exercise_result.php: '.print_r($_POST, 1));
  17. }
  18. // general parameters passed via POST/GET
  19. $origin = api_get_origin();
  20. if (empty($learnpath_id)) {
  21. if (!empty($_REQUEST['learnpath_id'])) {
  22. $learnpath_id = intval($_REQUEST['learnpath_id']);
  23. } else {
  24. $learnpath_id = 0;
  25. }
  26. }
  27. if (empty($learnpath_item_id)) {
  28. if (!empty($_REQUEST['learnpath_item_id'])) {
  29. $learnpath_item_id = intval($_REQUEST['learnpath_item_id']);
  30. } else {
  31. $learnpath_item_id = 0;
  32. }
  33. }
  34. if (empty($learnpath_item_view_id)) {
  35. if (!empty($_REQUEST['learnpath_item_view_id'])) {
  36. $learnpath_item_view_id = intval($_REQUEST['learnpath_item_view_id']);
  37. } else {
  38. $learnpath_item_view_id = 0;
  39. }
  40. }
  41. if (empty($exerciseId)) {
  42. if (!empty($_REQUEST['exerciseId'])) {
  43. $exerciseId = intval($_REQUEST['exerciseId']);
  44. } else {
  45. $exerciseId = 0;
  46. }
  47. }
  48. if (empty($objExercise)) {
  49. $exerciseInSession = Session::read('objExercise');
  50. if (!empty($exerciseInSession)) {
  51. $objExercise = $exerciseInSession;
  52. } else {
  53. $objExercise = null;
  54. }
  55. }
  56. if (!$objExercise) {
  57. //Redirect to the exercise overview
  58. //Check if the exe_id exists
  59. header("Location: overview.php?exerciseId=".$exerciseId.'&'.api_get_cidreq());
  60. exit;
  61. }
  62. $time_control = false;
  63. $clock_expired_time = ExerciseLib::get_session_time_control_key(
  64. $objExercise->id,
  65. $learnpath_id,
  66. $learnpath_item_id
  67. );
  68. if ($objExercise->expired_time != 0 && !empty($clock_expired_time)) {
  69. $time_control = true;
  70. }
  71. if ($time_control) {
  72. // Get time left for expiring time
  73. $time_left = api_strtotime($clock_expired_time, 'UTC') - time();
  74. $htmlHeadXtra[] = api_get_js_epiclock();
  75. $htmlHeadXtra[] = $objExercise->show_time_control_js($time_left);
  76. }
  77. $exe_id = 0;
  78. if (isset($_GET['exe_id'])) {
  79. $exe_id = (int) $_GET['exe_id'];
  80. Session::write('exe_id', $exe_id);
  81. }
  82. $exe_id = (int) Session::read('exe_id');
  83. $exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
  84. if (!empty($exercise_stat_info['data_tracking'])) {
  85. $question_list = explode(',', $exercise_stat_info['data_tracking']);
  86. }
  87. if (empty($exercise_stat_info) || empty($question_list)) {
  88. api_not_allowed();
  89. }
  90. $nameTools = get_lang('Exercises');
  91. $interbreadcrumb[] = array("url" => "exercise.php?".api_get_cidreq(), "name" => get_lang('Exercises'));
  92. if ($origin != 'learnpath') {
  93. //so we are not in learnpath tool
  94. Display::display_header($nameTools, get_lang('Exercise'));
  95. } else {
  96. Display::display_reduced_header();
  97. }
  98. /* DISPLAY AND MAIN PROCESS */
  99. // I'm in a preview mode as course admin. Display the action menu.
  100. if (api_is_course_admin() && $origin != 'learnpath') {
  101. echo '<div class="actions">';
  102. echo '<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'">'.
  103. Display::return_icon('back.png', get_lang('GoBackToQuestionList'), array(), 32).'</a>';
  104. echo '<a href="exercise_admin.php?'.api_get_cidreq().'&modifyExercise=yes&exerciseId='.$objExercise->id.'">'.
  105. Display::return_icon('edit.png', get_lang('ModifyExercise'), array(), 32).'</a>';
  106. echo '</div>';
  107. }
  108. echo Display::page_header(get_lang('QuestionsToReview'));
  109. if ($time_control) {
  110. echo $objExercise->return_time_left_div();
  111. }
  112. echo Display::div('', array('id'=>'message'));
  113. echo '<script>
  114. lp_data = $.param({"learnpath_id": '.$learnpath_id.', "learnpath_item_id" : '.$learnpath_item_id.', "learnpath_item_view_id": '.$learnpath_item_view_id.'});
  115. function final_submit() {
  116. //Normal inputs
  117. window.location = "exercise_result.php?'.api_get_cidreq().'&exe_id='.$exe_id.'&" + lp_data;
  118. }
  119. function review_questions() {
  120. var is_checked = 1;
  121. $("input[type=checkbox]").each(function () {
  122. if ($(this).attr("checked") == "checked") {
  123. is_checked = 2;
  124. return false;
  125. }
  126. });
  127. if (is_checked == 1) {
  128. $("#message").addClass("warning-message");
  129. $("#message").html("'.addslashes(get_lang('SelectAQuestionToReview')).'");
  130. }
  131. window.location = "exercise_submit.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'&reminder=2&" + lp_data;
  132. }
  133. function save_remind_item(obj, question_id) {
  134. var action = "";
  135. if ($(obj).is(\':checked\')) {
  136. action = "add";
  137. } else {
  138. action = "delete";
  139. }
  140. $.ajax({
  141. url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?'.api_get_cidreq().'&a=add_question_to_reminder",
  142. data: "question_id="+question_id+"&exe_id='.$exe_id.'&action="+action,
  143. success: function(return_value) {
  144. }
  145. });
  146. }
  147. </script>';
  148. $attempt_list = Event::getAllExerciseEventByExeId($exe_id);
  149. $remind_list = $exercise_stat_info['questions_to_check'];
  150. $remind_list = explode(',', $remind_list);
  151. $exercise_result = array();
  152. foreach ($attempt_list as $question_id => $options) {
  153. foreach ($options as $item) {
  154. $question_obj = Question::read($item['question_id']);
  155. switch ($question_obj->type) {
  156. case FILL_IN_BLANKS:
  157. $item['answer'] = $objExercise->fill_in_blank_answer_to_string($item['answer']);
  158. break;
  159. case HOT_SPOT:
  160. break;
  161. }
  162. if ($item['answer'] != '0' && !empty($item['answer'])) {
  163. $exercise_result[] = $question_id;
  164. break;
  165. }
  166. }
  167. }
  168. echo Display::label(get_lang('QuestionWithNoAnswer'), 'warning');
  169. echo '<div class="clear"></div><br />';
  170. $table = '';
  171. $counter = 0;
  172. // Loop over all question to show results for each of them, one by one
  173. foreach ($question_list as $questionId) {
  174. // destruction of the Question object
  175. unset($objQuestionTmp);
  176. // creates a temporary Question object
  177. $objQuestionTmp = Question:: read($questionId);
  178. $quesId = $objQuestionTmp->selectId();
  179. $check_id = 'remind_list['.$questionId.']';
  180. $attributes = array('id' => $check_id, 'onclick' => "save_remind_item(this, '$questionId');");
  181. if (in_array($questionId, $remind_list)) {
  182. $attributes['checked'] = 1;
  183. }
  184. $label_attributes = array();
  185. $label_attributes['class'] = 'checkbox';
  186. $label_attributes['for'] = $check_id;
  187. $label_attributes['class'] = "checkbox";
  188. $checkbox = Display::input('checkbox', 'remind_list['.$questionId.']', '', $attributes);
  189. $url = 'exercise_submit.php?exerciseId='.$objExercise->id.'&num='.$counter.'&reminder=1';
  190. $counter++;
  191. if ($objExercise->type == ONE_PER_PAGE) {
  192. $question_title = Display::url(
  193. $counter.'. '.cut($objQuestionTmp->selectTitle(), 40),
  194. $url
  195. );
  196. $question_title = $counter.'. '.cut($objQuestionTmp->selectTitle(), 40);
  197. } else {
  198. $question_title = $counter.'. '.cut($objQuestionTmp->selectTitle(), 40);
  199. }
  200. //Check if the question doesn't have an answer
  201. if (!in_array($questionId, $exercise_result)) {
  202. $question_title = Display::label($question_title, 'warning');
  203. }
  204. $question_title = Display::tag('label', $checkbox.$question_title, $label_attributes);
  205. $table .= Display::div($question_title, array('class'=>'exercise_reminder_item'));
  206. } // end foreach() block that loops over all questions
  207. echo Display::div($table, array('class'=>'question-check-test'));
  208. $exerciseActions = Display::url(
  209. get_lang('ReviewQuestions'),
  210. 'javascript://',
  211. array('onclick'=>'review_questions();', 'class'=>'btn btn-success')
  212. );
  213. $exerciseActions .= '&nbsp;'.Display::url(
  214. get_lang('EndTest'),
  215. 'javascript://',
  216. array('onclick' => 'final_submit();', 'class' => 'btn btn-warning')
  217. );
  218. echo Display::div('', array('class'=>'clear'));
  219. echo Display::div($exerciseActions, array('class'=>'form-actions'));
  220. if ($origin != 'learnpath') {
  221. // We are not in learnpath tool
  222. Display::display_footer();
  223. }