exercise_reminder.php 9.5 KB

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