overview.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Exercise preview
  5. *
  6. * @package chamilo.exercise
  7. * @author Julio Montoya <gugli100@gmail.com>
  8. */
  9. /**
  10. * Code
  11. */
  12. use \ChamiloSession as Session;
  13. $language_file = 'exercice';
  14. require_once 'exercise.class.php';
  15. require_once '../inc/global.inc.php';
  16. $current_course_tool = TOOL_QUIZ;
  17. // Clear the exercise session just in case
  18. $objExercise = Session::read('objExercise');
  19. if (isset($objExercise)) {
  20. Session::erase('objExercise');
  21. }
  22. $this_section = SECTION_COURSES;
  23. // Notice for unauthorized people.
  24. api_protect_course_script(true);
  25. $exercise_id = isset($_REQUEST['exerciseId']) ? intval($_REQUEST['exerciseId']) : 0;
  26. $objExercise = new Exercise();
  27. $result = $objExercise->read($exercise_id);
  28. if (!$result) {
  29. api_not_allowed(true);
  30. }
  31. $gradebook = isset($_GET['gradebook']) ? Security :: remove_XSS($_GET['gradebook']) : null;
  32. $learnpath_id = isset($_REQUEST['learnpath_id']) ? intval($_REQUEST['learnpath_id']) : null;
  33. $learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? intval($_REQUEST['learnpath_item_id']) : null;
  34. $origin = isset($_REQUEST['origin']) ? Security::remove_XSS($_REQUEST['origin']) : null;
  35. $interbreadcrumb[] = array ("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices'));
  36. $interbreadcrumb[] = array ("url" => "#", "name" => $objExercise->name);
  37. $time_control = false;
  38. $clock_expired_time = ExerciseLib::get_session_time_control_key($objExercise->id, $learnpath_id, $learnpath_item_id);
  39. if ($objExercise->expired_time != 0 && !empty($clock_expired_time)) {
  40. $time_control = true;
  41. }
  42. $urlMainExercise = api_get_path(WEB_CODE_PATH).'exercice/';
  43. $exercise_stat_info = $objExercise->getStatTrackExerciseInfo($learnpath_id, $learnpath_item_id, 0);
  44. if ($time_control) {
  45. // Get time left for expiring time
  46. $time_left = api_strtotime($clock_expired_time, 'UTC') - time();
  47. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/stylesheet/jquery.epiclock.css');
  48. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/renderers/minute/epiclock.minute.css');
  49. $htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.dateformat.min.js');
  50. $htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.epiclock.min.js');
  51. $htmlHeadXtra[] = api_get_js('epiclock/renderers/minute/epiclock.minute.js');
  52. $htmlHeadXtra[] = $objExercise->show_time_control_js($time_left);
  53. $htmlHeadXtra[] = '<script>
  54. function final_submit() {
  55. var lp_data = $.param({"learnpath_id": '.intval($learnpath_id).', "learnpath_item_id" : '.intval($learnpath_item_id).', "learnpath_item_view_id": '.intval($learnpath_item_view_id).'});
  56. var url = "'.$urlMainExercise.'exercise_result.php?'.api_get_cidreq().'&origin='.$origin.'&exe_id='.$exercise_stat_info['exe_id'].'&";
  57. window.location = url ;
  58. }
  59. </script>';
  60. }
  61. if ($origin != 'learnpath') {
  62. Display::display_header();
  63. } else {
  64. Display::display_reduced_header();
  65. }
  66. $html = '';
  67. $message = '';
  68. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  69. $edit_link = '';
  70. if ($is_allowed_to_edit) {
  71. $url = api_get_path(WEB_CODE_PATH).'exercice/admin.php?'.api_get_cidreq().'&id_session='.api_get_session_id().'&exerciseId='.$objExercise->id;
  72. $edit_link = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), $url);
  73. }
  74. //Exercise name
  75. $html .= Display::page_subheader($objExercise->name.' '.$edit_link);
  76. //Exercise description
  77. if (!empty($objExercise->description)) {
  78. $html .= Display::div($objExercise->description, array('class'=>'exercise_description'));
  79. }
  80. $extra_params = '';
  81. if (isset($_GET['preview'])) {
  82. $extra_params = '&preview=1';
  83. }
  84. $attempt_list = null;
  85. if (isset($exercise_stat_info['exe_id'])) {
  86. $attempt_list = getAllExerciseEventByExeId($exercise_stat_info['exe_id']);
  87. }
  88. //1. Check if this is a new attempt or a previous
  89. $label = get_lang('StartTest');
  90. if ($time_control && !empty($clock_expired_time) || !empty($attempt_list)) {
  91. $label = get_lang('ContinueTest');
  92. }
  93. if (!empty($attempt_list)) {
  94. $message = Display::return_message(get_lang('YouTriedToResolveThisExerciseEarlier'));
  95. }
  96. //2. Exercise button
  97. //Notice we not add there the lp_item_view_id because is not already generated
  98. $exercise_url = api_get_path(WEB_CODE_PATH).'exercice/exercise_submit.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'&origin='.$origin.'&learnpath_id='.$learnpath_id.'&learnpath_item_id='.$learnpath_item_id.$extra_params;
  99. $exercise_url_button = Display::url($label, $exercise_url, array('class'=>'btn btn-primary btn-large'));
  100. //3. Checking visibility of the exercise (overwrites the exercise button)
  101. $visible_return = $objExercise->is_visible($learnpath_id, $learnpath_item_id, null, false);
  102. //Exercise is not visible remove the button
  103. if ($visible_return['value'] == false) {
  104. if ($is_allowed_to_edit) {
  105. $message = Display::return_message(get_lang('ThisItemIsInvisibleForStudentsButYouHaveAccessAsTeacher'), 'warning');
  106. } else {
  107. $message = $visible_return['message'];
  108. $exercise_url_button = null;
  109. }
  110. }
  111. $attempts = getExerciseResultsByUser(api_get_user_id(), $objExercise->id, api_get_course_int_id(), api_get_session_id(), $learnpath_id, $learnpath_item_id, 'desc');
  112. $counter = count($attempts);
  113. $my_attempt_array = array();
  114. $table_content = '';
  115. /* Make a special case for IE, which doesn't seem to be able to handle the
  116. * results popup -> send it to the full results page */
  117. $browser = new Browser();
  118. $current_browser = $browser->getBrowser();
  119. $url_suffix = '';
  120. $btn_class = 'ajax ';
  121. if ($current_browser == 'Internet Explorer') {
  122. $url_suffix = '&amp;show_headers=1';
  123. $btn_class = '';
  124. }
  125. if (!empty($attempts)) {
  126. $i = $counter;
  127. foreach ($attempts as $attempt_result) {
  128. $score = ExerciseLib::show_score($attempt_result['exe_result'], $attempt_result['exe_weighting']);
  129. $attempt_url = api_get_path(WEB_CODE_PATH).'exercice/result.php?'.api_get_cidreq().'&amp;id='.$attempt_result['exe_id'].'&amp;id_session='.api_get_session_id().'&amp;height=500&amp;width=950'.$url_suffix;
  130. $attempt_link = Display::url(get_lang('Show'), $attempt_url, array('class'=>$btn_class.'btn'));
  131. $teacher_revised = Display::label(get_lang('Validated'), 'success');
  132. //$attempt_link = get_lang('NoResult');
  133. //$attempt_link = Display::return_icon('quiz_na.png', get_lang('NoResult'), array(), ICON_SIZE_SMALL);
  134. if ($attempt_result['attempt_revised'] == 0) {
  135. $teacher_revised = Display::label(get_lang('NotValidated'), 'info');
  136. }
  137. $row = array(
  138. 'count' => $i,
  139. 'date' => api_convert_and_format_date($attempt_result['start_date'], DATE_TIME_FORMAT_LONG)
  140. );
  141. $attempt_link .= "&nbsp;&nbsp;&nbsp;".$teacher_revised;
  142. if (in_array($objExercise->results_disabled, array(RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS, RESULT_DISABLE_SHOW_SCORE_ONLY, RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES))) {
  143. $row['result'] = $score;
  144. }
  145. if (in_array($objExercise->results_disabled, array(RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS, RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES))) {
  146. $row['attempt_link'] = $attempt_link;
  147. }
  148. $my_attempt_array[] = $row;
  149. $i--;
  150. }
  151. $table = new HTML_Table(array('class' => 'data_table'));
  152. //Hiding score and answer
  153. switch ($objExercise->results_disabled) {
  154. case RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS:
  155. case RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES:
  156. $header_names = array(get_lang('Attempt'), get_lang('StartDate'), get_lang('Score'), get_lang('Details'));
  157. break;
  158. case RESULT_DISABLE_NO_SCORE_AND_EXPECTED_ANSWERS:
  159. $header_names = array(get_lang('Attempt'), get_lang('StartDate'));
  160. break;
  161. case RESULT_DISABLE_SHOW_SCORE_ONLY:
  162. $header_names = array(get_lang('Attempt'), get_lang('StartDate'), get_lang('Score'));
  163. break;
  164. }
  165. $column = 0;
  166. foreach ($header_names as $item) {
  167. $table->setHeaderContents(0, $column, $item);
  168. $column++;
  169. }
  170. $row = 1;
  171. if (!empty($my_attempt_array)) {
  172. foreach ($my_attempt_array as $data) {
  173. $column = 0;
  174. $table->setCellContents($row, $column, $data);
  175. $class = 'class="row_odd"';
  176. if($row % 2) {
  177. $class = 'class="row_even"';
  178. }
  179. $table->setRowAttributes($row, $class, true);
  180. $column++;
  181. $row++;
  182. }
  183. }
  184. $table_content = $table->toHtml();
  185. }
  186. if ($objExercise->selectAttempts()) {
  187. if ($is_allowed_to_edit) {
  188. //$options.= Display::div(get_lang('ExerciseAttempts').' '.$objExercise->selectAttempts(), array('class'=>'right_option'));
  189. }
  190. $attempt_message = get_lang('Attempts').' '.$counter.' / '.$objExercise->selectAttempts();
  191. if ($counter == $objExercise->selectAttempts()) {
  192. $attempt_message = Display::return_message($attempt_message, 'error');
  193. } else {
  194. $attempt_message = Display::return_message($attempt_message, 'info');
  195. }
  196. if ($visible_return['value'] == true) {
  197. $message .= $attempt_message;
  198. }
  199. }
  200. if ($time_control) {
  201. $html.= $objExercise->returnTimeLeftDiv();
  202. }
  203. $html .= $message;
  204. if (!empty($exercise_url_button)) {
  205. $html .= Display::div(Display::div($exercise_url_button, array('class'=>'exercise_overview_options span12')), array('class'=>' row'));
  206. }
  207. $html .= $table_content;
  208. echo $html;
  209. if ($origin != 'learnpath') {
  210. Display::display_footer();
  211. }