PageRenderTime 40ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/php/main/exercice/exercise_reminder.php

https://bitbucket.org/frchico/chamilo_openshift
PHP | 238 lines | 171 code | 40 blank | 27 comment | 34 complexity | de565d4905168ef73104da45348997b5 MD5 | raw file
  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. require_once api_get_path(LIBRARY_PATH).'exercise_show_functions.lib.php';
  27. require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
  28. $this_section = SECTION_COURSES;
  29. /* ACCESS RIGHTS */
  30. // notice for unauthorized people.
  31. api_protect_course_script(true);
  32. if($debug>0){error_log('Entered exercise_result.php: '.print_r($_POST,1));}
  33. // general parameters passed via POST/GET
  34. if ( empty ( $origin ) ) { $origin = Security::remove_XSS($_REQUEST['origin']);}
  35. if ( empty ( $learnpath_id ) ) { $learnpath_id = intval($_REQUEST['learnpath_id']);}
  36. if ( empty ( $learnpath_item_id ) ) { $learnpath_item_id = intval($_REQUEST['learnpath_item_id']);}
  37. if ( empty ( $learnpath_item_view_id ) ) { $learnpath_item_view_id = intval($_REQUEST['learnpath_item_view_id']);}
  38. if ( empty ($exerciseId)) { $exerciseId = intval($_REQUEST['exerciseId']);}
  39. if ( empty ($objExercise)) { $objExercise = $_SESSION['objExercise'];}
  40. if (!$objExercise) {
  41. //Redirect to the exercise overview
  42. //Check if the exe_id exists
  43. header("Location: overview.php?exerciseId=".$exerciseId);
  44. exit;
  45. }
  46. $time_control = false;
  47. $clock_expired_time = get_session_time_control_key($objExercise->id, $learnpath_id, $learnpath_item_id);
  48. if ($objExercise->expired_time != 0 && !empty($clock_expired_time)) {
  49. $time_control = true;
  50. }
  51. if ($time_control) {
  52. // Get time left for exipiring time
  53. $time_left = api_strtotime($clock_expired_time,'UTC') - time();
  54. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/stylesheet/jquery.epiclock.css');
  55. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/renderers/minute/epiclock.minute.css');
  56. $htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.dateformat.min.js');
  57. $htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.epiclock.min.js');
  58. $htmlHeadXtra[] = api_get_js('epiclock/renderers/minute/epiclock.minute.js');
  59. $htmlHeadXtra[] = $objExercise->show_time_control_js($time_left);
  60. }
  61. if (isset($_SESSION['exe_id'])) {
  62. $exe_id = intval($_SESSION['exe_id']);
  63. }
  64. $exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
  65. if (!empty($exercise_stat_info['data_tracking'])) {
  66. $question_list = explode(',', $exercise_stat_info['data_tracking']);
  67. }
  68. if (empty($exercise_stat_info) || empty($question_list)) {
  69. api_not_allowed();
  70. }
  71. $nameTools = get_lang('Exercice');
  72. $interbreadcrumb[] = array("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices'));
  73. if ($origin != 'learnpath') {
  74. //so we are not in learnpath tool
  75. Display::display_header($nameTools,get_lang('Exercise'));
  76. } else {
  77. Display::display_reduced_header();
  78. }
  79. /* DISPLAY AND MAIN PROCESS */
  80. // I'm in a preview mode as course admin. Display the action menu.
  81. if (api_is_course_admin() && $origin != 'learnpath') {
  82. echo '<div class="actions">';
  83. echo '<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'">'.Display::return_icon('back.png', get_lang('GoBackToQuestionList'), array(), 32).'</a>';
  84. 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>';
  85. echo '</div>';
  86. }
  87. echo Display::page_header(get_lang('QuestionsToReview'));
  88. if ($time_control) {
  89. echo $objExercise->return_time_left_div();
  90. }
  91. echo Display::div('', array('id'=>'message'));
  92. echo '<script>
  93. lp_data = $.param({"learnpath_id": '.$learnpath_id.', "learnpath_item_id" : '.$learnpath_item_id.', "learnpath_item_view_id": '.$learnpath_item_view_id.'});
  94. function final_submit() {
  95. //Normal inputs
  96. window.location = "exercise_result.php?origin='.$origin.'&exe_id='.$exe_id.'&" + lp_data;
  97. }
  98. function review_questions() {
  99. var is_checked = 1;
  100. $("input[type=checkbox]").each(function () {
  101. if ($(this).attr("checked") == "checked") {
  102. is_checked = 2;
  103. return false;
  104. }
  105. });
  106. if (is_checked == 1) {
  107. $("#message").addClass("warning-message");
  108. $("#message").html("'.addslashes(get_lang('SelectAQuestionToReview')).'");
  109. }
  110. window.location = "exercise_submit.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'&reminder=2&origin='.$origin.'&" + lp_data;
  111. }
  112. function save_remind_item(obj, question_id) {
  113. var action = "";
  114. if ($(obj).is(\':checked\')) {
  115. action = "add";
  116. } else {
  117. action = "delete";
  118. }
  119. $.ajax({
  120. url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=add_question_to_reminder",
  121. data: "question_id="+question_id+"&exe_id='.$exe_id.'&action="+action,
  122. success: function(return_value) {
  123. },
  124. });
  125. }
  126. </script>';
  127. $attempt_list = get_all_exercise_event_by_exe_id($exe_id);
  128. $remind_list = $exercise_stat_info['questions_to_check'];
  129. $remind_list = explode(',', $remind_list);
  130. $exercise_result = array();
  131. foreach ($attempt_list as $question_id => $options) {
  132. //echo $question_id.'<br />';
  133. foreach($options as $item) {
  134. $question_obj = Question::read($item['question_id']);
  135. switch($question_obj->type) {
  136. case FILL_IN_BLANKS:
  137. $item['answer'] = $objExercise->fill_in_blank_answer_to_string($item['answer']);
  138. break;
  139. case HOT_SPOT:
  140. //var_dump($item['answer']);
  141. break;
  142. }
  143. if ($item['answer'] != '0' && !empty($item['answer'])) {
  144. $exercise_result[] = $question_id;
  145. break;
  146. }
  147. }
  148. }
  149. echo Display::label(get_lang('QuestionWithNoAnswer'), 'warning');
  150. echo '<div class="clear"></div><br />';
  151. $table = '';
  152. $counter = 0;
  153. // Loop over all question to show results for each of them, one by one
  154. foreach ($question_list as $questionId) {
  155. // destruction of the Question object
  156. unset($objQuestionTmp);
  157. // creates a temporary Question object
  158. $objQuestionTmp = Question :: read($questionId);
  159. // initialize question information
  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. }