exercise_reminder.php 8.7 KB

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