exercise_reminder.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. * @author Julio Montoya switchable fill in blank option added
  9. */
  10. require_once __DIR__.'/../inc/global.inc.php';
  11. $this_section = SECTION_COURSES;
  12. api_protect_course_script(true);
  13. $origin = api_get_origin();
  14. $learnpath_id = isset($_REQUEST['learnpath_id']) ? (int) $_REQUEST['learnpath_id'] : 0;
  15. $learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? (int) $_REQUEST['learnpath_item_id'] : 0;
  16. $learnpath_item_view_id = isset($_REQUEST['learnpath_item_view_id']) ? (int) $_REQUEST['learnpath_item_view_id'] : 0;
  17. $exerciseId = isset($_REQUEST['exerciseId']) ? (int) $_REQUEST['exerciseId'] : 0;
  18. $objExercise = null;
  19. $exerciseInSession = Session::read('objExercise');
  20. if (!empty($exerciseInSession)) {
  21. $objExercise = $exerciseInSession;
  22. }
  23. if (!$objExercise) {
  24. // Redirect to the exercise overview
  25. // Check if the exe_id exists
  26. header('Location: '.api_get_path(WEB_CODE_PATH).'exercise/overview.php?exerciseId='.$exerciseId.'&'.api_get_cidreq());
  27. exit;
  28. }
  29. $time_control = false;
  30. $clock_expired_time = ExerciseLib::get_session_time_control_key(
  31. $objExercise->id,
  32. $learnpath_id,
  33. $learnpath_item_id
  34. );
  35. if ($objExercise->expired_time != 0 && !empty($clock_expired_time)) {
  36. $time_control = true;
  37. }
  38. if ($time_control) {
  39. // Get time left for expiring time
  40. $time_left = api_strtotime($clock_expired_time, 'UTC') - time();
  41. /*$htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/stylesheet/jquery.epiclock.css');
  42. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/renderers/minute/epiclock.minute.css');
  43. $htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.dateformat.min.js');
  44. $htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.epiclock.min.js');
  45. $htmlHeadXtra[] = api_get_js('epiclock/renderers/minute/epiclock.minute.js');*/
  46. $htmlHeadXtra[] = $objExercise->showTimeControlJS($time_left);
  47. }
  48. $htmlHeadXtra[] = api_get_build_js('exercise.js');
  49. $htmlHeadXtra[] = api_get_css_asset('pretty-checkbox/dist/pretty-checkbox.min.css');
  50. $exe_id = 0;
  51. if (isset($_GET['exe_id'])) {
  52. $exe_id = (int) $_GET['exe_id'];
  53. Session::write('exe_id', $exe_id);
  54. }
  55. $exe_id = (int) Session::read('exe_id');
  56. $exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
  57. if (!empty($exercise_stat_info['data_tracking'])) {
  58. $question_list = explode(',', $exercise_stat_info['data_tracking']);
  59. }
  60. if (empty($exercise_stat_info) || empty($question_list)) {
  61. api_not_allowed();
  62. }
  63. $nameTools = get_lang('Tests');
  64. $interbreadcrumb[] = ['url' => 'exercise.php?'.api_get_cidreq(), 'name' => get_lang('Tests')];
  65. $hideHeaderAndFooter = in_array($origin, ['learnpath', 'embeddable']);
  66. if (!$hideHeaderAndFooter) {
  67. //so we are not in learnpath tool
  68. Display::display_header($nameTools, get_lang('Test'));
  69. } else {
  70. Display::display_reduced_header();
  71. }
  72. /* DISPLAY AND MAIN PROCESS */
  73. // I'm in a preview mode as course admin. Display the action menu.
  74. if (api_is_course_admin() && !$hideHeaderAndFooter) {
  75. echo '<div class="actions">';
  76. echo '<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'">'.
  77. Display::return_icon('back.png', get_lang('Go back to the questions list'), [], 32).'</a>';
  78. echo '<a href="exercise_admin.php?'.api_get_cidreq().'&modifyTest=yes&exerciseId='.$objExercise->id.'">'.
  79. Display::return_icon('edit.png', get_lang('ModifyTest'), [], 32).'</a>';
  80. echo '</div>';
  81. }
  82. echo Display::page_header(get_lang('Questions to be reviewed'));
  83. if ($time_control) {
  84. echo $objExercise->returnTimeLeftDiv();
  85. }
  86. echo Display::div('', ['id' => 'message']);
  87. echo '<script>
  88. var lp_data = $.param({"learnpath_id": '.$learnpath_id.', "learnpath_item_id" : '.$learnpath_item_id.', "learnpath_item_view_id": '.$learnpath_item_view_id.'});
  89. function final_submit() {
  90. // Normal inputs
  91. window.location = "'.api_get_path(WEB_CODE_PATH).'exercise/exercise_result.php?'.api_get_cidreq().'&exe_id='.$exe_id.'&" + lp_data;
  92. }
  93. function changeOptionStatus(status)
  94. {
  95. $("input[type=checkbox]").each(function () {
  96. $(this).prop("checked", status);
  97. });
  98. var action = "";
  99. var extraOption = "remove_all";
  100. if (status == 1) {
  101. extraOption = "add_all";
  102. }
  103. $.ajax({
  104. url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?'.api_get_cidreq().'&a=add_question_to_reminder",
  105. data: "option="+extraOption+"&exe_id='.$exe_id.'&action="+action,
  106. success: function(returnValue) {
  107. }
  108. });
  109. }
  110. function review_questions() {
  111. var isChecked = 1;
  112. $("input[type=checkbox]").each(function () {
  113. if ($(this).prop("checked")) {
  114. isChecked = 2;
  115. return false;
  116. }
  117. });
  118. if (isChecked == 1) {
  119. $("#message").addClass("warning-message");
  120. $("#message").html("'.addslashes(get_lang('Select a question to revise')).'");
  121. } else {
  122. window.location = "exercise_submit.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'&reminder=2&" + lp_data;
  123. }
  124. }
  125. function save_remind_item(obj, question_id) {
  126. var action = "";
  127. if ($(obj).prop("checked")) {
  128. action = "add";
  129. } else {
  130. action = "delete";
  131. }
  132. $.ajax({
  133. url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?'.api_get_cidreq().'&a=add_question_to_reminder",
  134. data: "question_id="+question_id+"&exe_id='.$exe_id.'&action="+action,
  135. success: function(returnValue) {
  136. }
  137. });
  138. }
  139. </script>';
  140. $attempt_list = Event::getAllExerciseEventByExeId($exe_id);
  141. $remind_list = $exercise_stat_info['questions_to_check'];
  142. $remind_list = explode(',', $remind_list);
  143. $exercise_result = [];
  144. foreach ($attempt_list as $question_id => $options) {
  145. foreach ($options as $item) {
  146. $question_obj = Question::read($item['question_id']);
  147. switch ($question_obj->type) {
  148. case FILL_IN_BLANKS:
  149. $item['answer'] = $objExercise->fill_in_blank_answer_to_string($item['answer']);
  150. break;
  151. case HOT_SPOT:
  152. break;
  153. }
  154. if ($item['answer'] != '0' && !empty($item['answer'])) {
  155. $exercise_result[] = $question_id;
  156. break;
  157. }
  158. }
  159. }
  160. echo Display::label(get_lang('Questions without answer'), 'danger');
  161. echo '<div class="clear"></div><br />';
  162. $table = '';
  163. $counter = 0;
  164. // Loop over all question to show results for each of them, one by one
  165. foreach ($question_list as $questionId) {
  166. // destruction of the Question object
  167. unset($objQuestionTmp);
  168. // creates a temporary Question object
  169. $objQuestionTmp = Question:: read($questionId);
  170. $check_id = 'remind_list['.$questionId.']';
  171. $attributes = ['id' => $check_id, 'onclick' => "save_remind_item(this, '$questionId');"];
  172. if (in_array($questionId, $remind_list)) {
  173. $attributes['checked'] = 1;
  174. }
  175. $checkbox = Display::input('checkbox', 'remind_list['.$questionId.']', '', $attributes);
  176. $checkbox = '<div class="pretty p-svg p-curve">
  177. '.$checkbox.'
  178. <div class="state p-primary ">
  179. <svg class="svg svg-icon" viewBox="0 0 20 20">
  180. <path d="M7.629,14.566c0.125,0.125,0.291,0.188,0.456,0.188c0.164,0,0.329-0.062,0.456-0.188l8.219-8.221c0.252-0.252,0.252-0.659,0-0.911c-0.252-0.252-0.659-0.252-0.911,0l-7.764,7.763L4.152,9.267c-0.252-0.251-0.66-0.251-0.911,0c-0.252,0.252-0.252,0.66,0,0.911L7.629,14.566z" style="stroke: white;fill:white;"></path>
  181. </svg>
  182. <label>&nbsp;</label>
  183. </div>
  184. </div>';
  185. $counter++;
  186. $questionTitle = $counter.'. '.strip_tags($objQuestionTmp->selectTitle());
  187. // Check if the question doesn't have an answer
  188. if (!in_array($questionId, $exercise_result)) {
  189. $questionTitle = Display::label($questionTitle, 'danger');
  190. }
  191. $label_attributes = [];
  192. $label_attributes['for'] = $check_id;
  193. $questionTitle = Display::tag('label', $checkbox.$questionTitle, $label_attributes);
  194. $table .= Display::div($questionTitle, ['class' => 'exercise_reminder_item ']);
  195. } // end foreach() block that loops over all questions
  196. echo Display::div($table, ['class' => 'question-check-test']);
  197. $exerciseActions = Display::url(
  198. get_lang('Review selected questions'),
  199. 'javascript://',
  200. ['onclick' => 'review_questions();', 'class' => 'btn btn-primary']
  201. );
  202. $exerciseActions .= '&nbsp;'.Display::url(
  203. get_lang('Select all'),
  204. 'javascript://',
  205. ['onclick' => 'changeOptionStatus(1);', 'class' => 'btn btn-default']
  206. );
  207. $exerciseActions .= '&nbsp;'.Display::url(
  208. get_lang('UnSelect all'),
  209. 'javascript://',
  210. ['onclick' => 'changeOptionStatus(0);', 'class' => 'btn btn-default']
  211. );
  212. $exerciseActions .= '&nbsp;'.Display::url(
  213. get_lang('End test'),
  214. 'javascript://',
  215. ['onclick' => 'final_submit();', 'class' => 'btn btn-warning']
  216. );
  217. echo Display::div('', ['class' => 'clear']);
  218. echo Display::div($exerciseActions, ['class' => 'form-actions']);
  219. if (!$hideHeaderAndFooter) {
  220. // We are not in learnpath tool or embeddable quiz
  221. Display::display_footer();
  222. } else {
  223. Display::display_reduced_footer();
  224. }