exercise_reminder.php 8.4 KB

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