exercise_reminder.php 8.5 KB

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