exercise_reminder.php 8.6 KB

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