exercise_reminder.php 9.4 KB

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