exercise_reminder.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. api_protect_course_script(true);
  15. $origin = api_get_origin();
  16. if (empty($learnpath_id)) {
  17. if (!empty($_REQUEST['learnpath_id'])) {
  18. $learnpath_id = (int) $_REQUEST['learnpath_id'];
  19. } else {
  20. $learnpath_id = 0;
  21. }
  22. }
  23. if (empty($learnpath_item_id)) {
  24. if (!empty($_REQUEST['learnpath_item_id'])) {
  25. $learnpath_item_id = (int) $_REQUEST['learnpath_item_id'];
  26. } else {
  27. $learnpath_item_id = 0;
  28. }
  29. }
  30. if (empty($learnpath_item_view_id)) {
  31. if (!empty($_REQUEST['learnpath_item_view_id'])) {
  32. $learnpath_item_view_id = (int) $_REQUEST['learnpath_item_view_id'];
  33. } else {
  34. $learnpath_item_view_id = 0;
  35. }
  36. }
  37. if (empty($exerciseId)) {
  38. if (!empty($_REQUEST['exerciseId'])) {
  39. $exerciseId = (int) $_REQUEST['exerciseId'];
  40. } else {
  41. $exerciseId = 0;
  42. }
  43. }
  44. if (empty($objExercise)) {
  45. $exerciseInSession = Session::read('objExercise');
  46. if (!empty($exerciseInSession)) {
  47. $objExercise = $exerciseInSession;
  48. } else {
  49. $objExercise = null;
  50. }
  51. }
  52. if (!$objExercise) {
  53. // Redirect to the exercise overview
  54. // Check if the exe_id exists
  55. header('Location: '.api_get_path(WEB_CODE_PATH).'exercise/overview.php?exerciseId='.$exerciseId.'&'.api_get_cidreq());
  56. exit;
  57. }
  58. $time_control = false;
  59. $clock_expired_time = ExerciseLib::get_session_time_control_key(
  60. $objExercise->id,
  61. $learnpath_id,
  62. $learnpath_item_id
  63. );
  64. if ($objExercise->expired_time != 0 && !empty($clock_expired_time)) {
  65. $time_control = true;
  66. }
  67. if ($time_control) {
  68. // Get time left for expiring time
  69. $time_left = api_strtotime($clock_expired_time, 'UTC') - time();
  70. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/stylesheet/jquery.epiclock.css');
  71. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/renderers/minute/epiclock.minute.css');
  72. $htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.dateformat.min.js');
  73. $htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.epiclock.min.js');
  74. $htmlHeadXtra[] = api_get_js('epiclock/renderers/minute/epiclock.minute.js');
  75. $htmlHeadXtra[] = $objExercise->showTimeControlJS($time_left);
  76. }
  77. $htmlHeadXtra[] = api_get_css_asset('pretty-checkbox/dist/pretty-checkbox.min.css');
  78. $exe_id = 0;
  79. if (isset($_GET['exe_id'])) {
  80. $exe_id = (int) $_GET['exe_id'];
  81. Session::write('exe_id', $exe_id);
  82. }
  83. $exe_id = (int) Session::read('exe_id');
  84. $exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
  85. if (!empty($exercise_stat_info['data_tracking'])) {
  86. $question_list = explode(',', $exercise_stat_info['data_tracking']);
  87. }
  88. if (empty($exercise_stat_info) || empty($question_list)) {
  89. api_not_allowed();
  90. }
  91. $nameTools = get_lang('Exercises');
  92. $interbreadcrumb[] = ['url' => 'exercise.php?'.api_get_cidreq(), 'name' => get_lang('Exercises')];
  93. $hideHeaderAndFooter = in_array($origin, ['learnpath', 'embeddable']);
  94. if (!$hideHeaderAndFooter) {
  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() && !$hideHeaderAndFooter) {
  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->returnTimeLeftDiv();
  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 = "'.api_get_path(WEB_CODE_PATH).'exercise/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'), 'danger');
  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. $checkbox = Display::input('checkbox', 'remind_list['.$questionId.']', '', $attributes);
  205. $checkbox = '<div class="pretty p-default">
  206. '.$checkbox.'
  207. <div class="state p-primary ">
  208. <label>&nbsp;</label>
  209. </div>
  210. </div>';
  211. $url = 'exercise_submit.php?exerciseId='.$objExercise->id.'&num='.$counter.'&reminder=1&'.api_get_cidreq();
  212. $counter++;
  213. $questionTitle = $counter.'. '.strip_tags($objQuestionTmp->selectTitle());
  214. // Check if the question doesn't have an answer
  215. if (!in_array($questionId, $exercise_result)) {
  216. $questionTitle = Display::label($questionTitle, 'danger');
  217. }
  218. $label_attributes = [];
  219. $label_attributes['for'] = $check_id;
  220. $questionTitle = Display::tag('label', $checkbox.$questionTitle, $label_attributes);
  221. $table .= Display::div($questionTitle, ['class' => 'exercise_reminder_item ']);
  222. } // end foreach() block that loops over all questions
  223. echo Display::div($table, ['class' => 'question-check-test']);
  224. $exerciseActions = Display::url(
  225. get_lang('ReviewQuestions'),
  226. 'javascript://',
  227. ['onclick' => 'review_questions();', 'class' => 'btn btn-primary']
  228. );
  229. $exerciseActions .= '&nbsp;'.Display::url(
  230. get_lang('SelectAll'),
  231. 'javascript://',
  232. ['onclick' => 'changeOptionStatus(1);', 'class' => 'btn btn-default']
  233. );
  234. $exerciseActions .= '&nbsp;'.Display::url(
  235. get_lang('UnSelectAll'),
  236. 'javascript://',
  237. ['onclick' => 'changeOptionStatus(0);', 'class' => 'btn btn-default']
  238. );
  239. $exerciseActions .= '&nbsp;'.Display::url(
  240. get_lang('EndTest'),
  241. 'javascript://',
  242. ['onclick' => 'final_submit();', 'class' => 'btn btn-warning']
  243. );
  244. echo Display::div('', ['class' => 'clear']);
  245. echo Display::div($exerciseActions, ['class' => 'form-actions']);
  246. if (!$hideHeaderAndFooter) {
  247. // We are not in learnpath tool or embeddable quiz
  248. Display::display_footer();
  249. } else {
  250. Display::display_reduced_footer();
  251. }