exercise_reminder.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Exercise reminder overview
  5. * Then it shows the results on the screen.
  6. * @package chamilo.exercise
  7. * @author Julio Montoya Armas switchable fill in blank option added
  8. */
  9. /**
  10. * INIT SECTION
  11. */
  12. require_once 'exercise.class.php';
  13. require_once 'question.class.php';
  14. require_once 'answer.class.php';
  15. $language_file = 'exercice';
  16. require_once '../inc/global.inc.php';
  17. if ($_GET['origin'] == 'learnpath') {
  18. require_once '../newscorm/learnpath.class.php';
  19. require_once '../newscorm/learnpathItem.class.php';
  20. require_once '../newscorm/scorm.class.php';
  21. require_once '../newscorm/scormItem.class.php';
  22. require_once '../newscorm/aicc.class.php';
  23. require_once '../newscorm/aiccItem.class.php';
  24. }
  25. $this_section = SECTION_COURSES;
  26. /* ACCESS RIGHTS */
  27. // notice for unauthorized people.
  28. api_protect_course_script(true);
  29. // General parameters passed via POST/GET
  30. if ( empty ( $origin ) ) { $origin = Security::remove_XSS($_REQUEST['origin']);}
  31. if ( empty ( $learnpath_id ) ) { $learnpath_id = intval($_REQUEST['learnpath_id']);}
  32. if ( empty ( $learnpath_item_id ) ) { $learnpath_item_id = intval($_REQUEST['learnpath_item_id']);}
  33. if ( empty ( $learnpath_item_view_id ) ) { $learnpath_item_view_id = intval($_REQUEST['learnpath_item_view_id']);}
  34. if ( empty ($exerciseId)) { $exerciseId = intval($_REQUEST['exerciseId']);}
  35. if ( empty ($objExercise)) { $objExercise = $_SESSION['objExercise'];}
  36. if (!$objExercise) {
  37. //Redirect to the exercise overview
  38. //Check if the exe_id exists
  39. header("Location: ".$urlMainExercise."overview.php?exerciseId=".$exerciseId."&".api_get_cidreq());
  40. exit;
  41. }
  42. $time_control = false;
  43. $clock_expired_time = ExerciseLib::get_session_time_control_key($objExercise->id, $learnpath_id, $learnpath_item_id);
  44. if ($objExercise->expired_time != 0 && !empty($clock_expired_time)) {
  45. $time_control = true;
  46. }
  47. if ($time_control) {
  48. // Get time left for expiring time
  49. $time_left = api_strtotime($clock_expired_time,'UTC') - time();
  50. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/stylesheet/jquery.epiclock.css');
  51. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/renderers/minute/epiclock.minute.css');
  52. $htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.dateformat.min.js');
  53. $htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.epiclock.min.js');
  54. $htmlHeadXtra[] = api_get_js('epiclock/renderers/minute/epiclock.minute.js');
  55. $htmlHeadXtra[] = $objExercise->show_time_control_js($time_left);
  56. }
  57. $exe_id = null;
  58. if (isset($_SESSION['exe_id'])) {
  59. $exe_id = intval($_SESSION['exe_id']);
  60. }
  61. $exercise_stat_info = $objExercise->getStatTrackExerciseInfoByExeId($exe_id);
  62. if (!empty($exercise_stat_info['data_tracking'])) {
  63. $question_list = explode(',', $exercise_stat_info['data_tracking']);
  64. }
  65. if (empty($exercise_stat_info) || empty($question_list)) {
  66. api_not_allowed();
  67. }
  68. $gradebook = isset($_SESSION['greadebook']) ? Security::remove_XSS($_SESSION['greadebook']) : null;
  69. $nameTools = get_lang('Exercice');
  70. $interbreadcrumb[] = array("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices'));
  71. if ($origin != 'learnpath') {
  72. //so we are not in learnpath tool
  73. Display::display_header($nameTools,get_lang('Exercise'));
  74. } else {
  75. Display::display_reduced_header();
  76. }
  77. /* DISPLAY AND MAIN PROCESS */
  78. // I'm in a preview mode as course admin. Display the action menu.
  79. if (api_is_course_admin() && $origin != 'learnpath') {
  80. echo '<div class="actions">';
  81. echo '<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'">'.Display::return_icon('back.png', get_lang('GoBackToQuestionList'), array(), 32).'</a>';
  82. 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>';
  83. echo '</div>';
  84. }
  85. echo Display::page_subheader2(get_lang('QuestionsToReview'));
  86. if ($time_control) {
  87. echo $objExercise->returnTimeLeftDiv();
  88. }
  89. echo Display::div('', array('id' => 'message'));
  90. $urlMainExercise = api_get_path(WEB_CODE_PATH).'exercice/';
  91. echo $objExercise->returnWarningJs($urlMainExercise.'exercise_result.php?origin='.$origin.'&exe_id='.$exe_id);
  92. echo '<script>
  93. lp_data = $.param({"learnpath_id": '.$learnpath_id.', "learnpath_item_id" : '.$learnpath_item_id.', "learnpath_item_view_id": '.$learnpath_item_view_id.'});
  94. function final_submit() {
  95. $("#dialog-confirm").dialog("open");
  96. }
  97. function review_questions() {
  98. var is_checked = 1;
  99. $("input[type=checkbox]").each(function () {
  100. if ($(this).attr("checked") == "checked") {
  101. is_checked = 2;
  102. return false;
  103. }
  104. });
  105. if (is_checked == 1) {
  106. $("#message").addClass("warning-message");
  107. $("#message").html("'.addslashes(get_lang('SelectAQuestionToReview')).'");
  108. }
  109. window.location = "'.$urlMainExercise.'exercise_submit.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'&reminder=2&origin='.$origin.'&" + lp_data;
  110. }
  111. function save_remind_item(obj, question_id) {
  112. var action = "";
  113. if ($(obj).is(\':checked\')) {
  114. action = "add";
  115. } else {
  116. action = "delete";
  117. }
  118. $.ajax({
  119. url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=add_question_to_reminder",
  120. data: "question_id="+question_id+"&exe_id='.$exe_id.'&action="+action,
  121. success: function(return_value) {
  122. },
  123. });
  124. }
  125. </script>';
  126. $exercise_result = getAnsweredQuestionsFromAttempt($exe_id, $objExercise);
  127. $remind_list = $exercise_stat_info['questions_to_check'];
  128. $remind_list = explode(',', $remind_list);
  129. $table = '<div class="row">';
  130. $counter = 0;
  131. $split_by = 25;
  132. //$count_cols = round(count($question_list)/$split_by);
  133. $count_cols = 3;
  134. $span_size = 12/$count_cols;
  135. $span_class = "span$span_size";
  136. $table .= '<div class="'.$span_class.'">';
  137. $table .= '<ul class="nav nav-list">';
  138. $cols = 1;
  139. // Loop over all question to show results for each of them, one by one
  140. $currentCategory = null;
  141. foreach ($question_list as $questionId) {
  142. // creates a temporary Question object
  143. $objQuestionTmp = Question::read($questionId);
  144. // initialize question information
  145. $check_id = 'remind_list['.$questionId.']';
  146. $attributes = array('id' => $check_id, 'onclick' => "save_remind_item(this, '$questionId');");
  147. if (in_array($questionId, $remind_list)) {
  148. $attributes['checked'] = 1;
  149. }
  150. $label_attributes = array();
  151. $label_attributes['class'] = 'checkbox';
  152. $label_attributes['for'] = $check_id;
  153. $label_attributes['class'] = "checkbox";
  154. if (in_array($objQuestionTmp->type, Question::question_type_no_review())) {
  155. $attributes['disabled'] = 'disabled';
  156. }
  157. $checkbox = Display::input('checkbox', 'remind_list['.$questionId.']', '', $attributes);
  158. $url = $urlMainExercise.'exercise_submit.php?exerciseId='.$objExercise->id.'&num='.$counter.'&reminder=1';
  159. $counter++;
  160. if ($objExercise->type == ONE_PER_PAGE) {
  161. $question_title = Display::url($counter.'. '.Text::cut($objQuestionTmp->selectTitle(), 40), $url);
  162. $question_title = $counter.'. '.Text::cut($objQuestionTmp->selectTitle(), 40);
  163. } else {
  164. $question_title = $counter.'. '.Text::cut($objQuestionTmp->selectTitle(), 40);
  165. }
  166. //Check if the question doesn't have an answer
  167. if (!in_array($questionId, $exercise_result)) {
  168. $question_title = Display::label($question_title, 'warning');
  169. }
  170. $rootCategories = null;
  171. global $app;
  172. $repo = $app['orm.em']->getRepository('Entity\CQuizCategory');
  173. foreach ($objQuestionTmp->category_list as $categoryId) {
  174. $cat = $repo->find($categoryId);
  175. $parentCat = $repo->getPath($cat);
  176. if (isset($parentCat[0])) {
  177. $rootCategories .= $parentCat[0]->getTitle();
  178. }
  179. }
  180. if ($currentCategory != $rootCategories) {
  181. $currentCategory = $rootCategories;
  182. } else {
  183. $rootCategories = null;
  184. }
  185. if (!empty($rootCategories)) {
  186. $table .= '<li class="nav-header"><h5>'.$rootCategories.'</h5></li>';
  187. }
  188. $question_title = Display::tag('label', $checkbox.$question_title, $label_attributes);
  189. $table .= '<li>'.Display::div($question_title, array('class' => 'exercise_reminder_item')).'</li>';
  190. if (($counter % $split_by) == 0) {
  191. if ($counter > 1) {
  192. $table .= '</ul></div>';
  193. if ($cols % $count_cols == 0) {
  194. $table .= '</div>';
  195. $table .= '<hr>';
  196. $table .= '<div class="row">';
  197. }
  198. $cols++;
  199. }
  200. $table .= '<div class="'.$span_class.'">';
  201. $table .= '<ul class="nav nav-list">';
  202. }
  203. }
  204. $table .= "</div>";
  205. $table .= "</div>";
  206. $exercise_actions = Display::url(get_lang('EndTest'), 'javascript://', array('onclick' => 'final_submit();', 'class' => 'btn btn-warning'));
  207. //$exercise_actions .= '&nbsp;'.Display::url(get_lang('ReviewQuestions'), 'javascript://', array('onclick' => 'review_questions();', 'class' => 'btn btn-success'));
  208. $questionList = explode(',', $exercise_stat_info['data_tracking']);
  209. $questionListFlatten = $objExercise->transformQuestionListWithMedias($questionList, true);
  210. $mediaQuestions = $objExercise->getMediaList($questionList);
  211. $params = "exe_id=$exe_id&exerciseId=$exerciseId&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id&".api_get_cidreq();
  212. $url = api_get_path(WEB_CODE_PATH).'exercice/exercise_submit.php?'.$params;
  213. echo $objExercise->getProgressPagination(
  214. $exe_id,
  215. $questionList,
  216. $questionListFlatten,
  217. $remind_list,
  218. 2,
  219. null,
  220. $url,
  221. null
  222. );
  223. echo Display::div('', array('class' => 'clear'));
  224. echo Display::div($exercise_actions, array('class' => 'form-actions'));
  225. echo $objExercise->returnWarningHtml();
  226. if ($origin != 'learnpath') {
  227. //we are not in learnpath tool
  228. Display::display_footer();
  229. }