exercise_reminder.php 8.5 KB

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