overview.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. use \ChamiloSession as Session;
  10. $language_file = 'exercice';
  11. require_once 'exercise.class.php';
  12. require_once '../inc/global.inc.php';
  13. require_once 'exercise.lib.php';
  14. $current_course_tool = TOOL_QUIZ;
  15. // Clear the exercise session just in case
  16. if (isset($_SESSION['objExercise'])) {
  17. Session::erase('objExercise');
  18. }
  19. $this_section = SECTION_COURSES;
  20. // Notice for unauthorized people.
  21. api_protect_course_script(true);
  22. $sessionId = api_get_session_id();
  23. $exercise_id = isset($_REQUEST['exerciseId']) ? intval($_REQUEST['exerciseId']) : 0;
  24. $objExercise = new Exercise();
  25. $result = $objExercise->read($exercise_id);
  26. if (!$result) {
  27. api_not_allowed(true);
  28. }
  29. $gradebook = isset($_GET['gradebook']) ? Security :: remove_XSS($_GET['gradebook']) : null;
  30. $learnpath_id = isset($_REQUEST['learnpath_id']) ? intval($_REQUEST['learnpath_id']) : null;
  31. $learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? intval($_REQUEST['learnpath_item_id']) : null;
  32. $origin = isset($_REQUEST['origin']) ? Security::remove_XSS($_REQUEST['origin']) : null;
  33. $interbreadcrumb[] = array("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices'));
  34. $interbreadcrumb[] = array("url" => "#", "name" => $objExercise->name);
  35. $time_control = false;
  36. $clock_expired_time = get_session_time_control_key($objExercise->id, $learnpath_id, $learnpath_item_id);
  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->show_time_control_js($time_left);
  49. }
  50. if ($origin != 'learnpath') {
  51. Display::display_header();
  52. } else {
  53. $htmlHeadXtra[] = "
  54. <style>
  55. body { background: none;}
  56. </style>
  57. ";
  58. Display::display_reduced_header();
  59. }
  60. $html = '';
  61. $message = '';
  62. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  63. $edit_link = '';
  64. if ($is_allowed_to_edit && $objExercise->sessionId == $sessionId) {
  65. $edit_link = Display::url(
  66. Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL),
  67. api_get_path(WEB_CODE_PATH).'exercice/admin.php?'.api_get_cidreq().'&id_session='.api_get_session_id().'&exerciseId='.$objExercise->id
  68. );
  69. }
  70. // Exercise name.
  71. $html .= Display::page_header($objExercise->name.' '.$edit_link);
  72. //Exercise description
  73. if (!empty($objExercise->description)) {
  74. $html .= Display::div($objExercise->description, array('class'=>'exercise_description'));
  75. }
  76. $extra_params = '';
  77. if (isset($_GET['preview'])) {
  78. $extra_params = '&preview=1';
  79. }
  80. $exercise_stat_info = $objExercise->get_stat_track_exercise_info($learnpath_id, $learnpath_item_id, 0);
  81. $attempt_list = null;
  82. if (isset($exercise_stat_info['exe_id'])) {
  83. $attempt_list = get_all_exercise_event_by_exe_id($exercise_stat_info['exe_id']);
  84. }
  85. //1. Check if this is a new attempt or a previous
  86. $label = get_lang('StartTest');
  87. if ($time_control && !empty($clock_expired_time) || !empty($attempt_list)) {
  88. $label = get_lang('ContinueTest');
  89. }
  90. if (!empty($attempt_list)) {
  91. $message = Display::return_message(get_lang('YouTriedToResolveThisExerciseEarlier'));
  92. }
  93. // 2. Exercise button
  94. // Notice we not add there the lp_item_view_id because is not already generated
  95. $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;
  96. $exercise_url_button = Display::url($label, $exercise_url, array('class'=>'btn btn-primary btn-large'));
  97. //3. Checking visibility of the exercise (overwrites the exercise button)
  98. $visible_return = $objExercise->is_visible(
  99. $learnpath_id,
  100. $learnpath_item_id,
  101. null,
  102. false
  103. );
  104. // Exercise is not visible remove the button
  105. if ($visible_return['value'] == false) {
  106. if ($is_allowed_to_edit) {
  107. $message = Display::return_message(get_lang('ThisItemIsInvisibleForStudentsButYouHaveAccessAsTeacher'), 'warning');
  108. } else {
  109. $message = $visible_return['message'];
  110. $exercise_url_button = null;
  111. }
  112. } else {
  113. if ($visible_return['message'] != "") {
  114. $message = $visible_return['message'];
  115. }
  116. }
  117. $attempts = get_exercise_results_by_user(
  118. api_get_user_id(),
  119. $objExercise->id,
  120. api_get_course_id(),
  121. api_get_session_id(),
  122. $learnpath_id,
  123. $learnpath_item_id,
  124. 'desc'
  125. );
  126. $counter = count($attempts);
  127. $my_attempt_array = array();
  128. $table_content = '';
  129. /* Make a special case for IE, which doesn't seem to be able to handle the
  130. * results popup -> send it to the full results page */
  131. require_once api_get_path(LIBRARY_PATH).'browser/Browser.php';
  132. $browser = new Browser();
  133. $current_browser = $browser->getBrowser();
  134. $url_suffix = '';
  135. $btn_class = ' ';
  136. if ($current_browser == 'Internet Explorer') {
  137. $url_suffix = '&amp;show_headers=1';
  138. $btn_class = '';
  139. }
  140. if (!empty($attempts)) {
  141. $i = $counter;
  142. foreach ($attempts as $attempt_result) {
  143. $score = show_score(
  144. $attempt_result['exe_result'],
  145. $attempt_result['exe_weighting']
  146. );
  147. $attempt_url = api_get_path(WEB_CODE_PATH) . 'exercice/result.php?show_headers=1&' . api_get_cidreq() . '&amp;id=' . $attempt_result['exe_id'] . '&amp;id_session=' . api_get_session_id() . '&amp;height=500&amp;width=950' . $url_suffix;
  148. $attempt_link = Display::url(
  149. get_lang('Show'),
  150. $attempt_url,
  151. array('class' => $btn_class . 'btn')
  152. );
  153. $teacher_revised = Display::label(get_lang('Validated'), 'success');
  154. //$attempt_link = get_lang('NoResult');
  155. //$attempt_link = Display::return_icon('quiz_na.png', get_lang('NoResult'), array(), ICON_SIZE_SMALL);
  156. if ($attempt_result['attempt_revised'] == 0) {
  157. $teacher_revised = Display::label(get_lang('NotValidated'), 'info');
  158. }
  159. $row = array(
  160. 'count' => $i,
  161. 'date' => api_convert_and_format_date(
  162. $attempt_result['start_date'],
  163. DATE_TIME_FORMAT_LONG
  164. )
  165. );
  166. $attempt_link .= "&nbsp;&nbsp;&nbsp;" . $teacher_revised;
  167. if (in_array(
  168. $objExercise->results_disabled,
  169. array(
  170. RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS,
  171. RESULT_DISABLE_SHOW_SCORE_ONLY,
  172. RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES
  173. )
  174. )) {
  175. $row['result'] = $score;
  176. }
  177. if (in_array(
  178. $objExercise->results_disabled,
  179. array(
  180. RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS,
  181. RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES
  182. )
  183. )
  184. || ($objExercise->results_disabled == RESULT_DISABLE_SHOW_SCORE_ONLY && $objExercise->feedback_type == EXERCISE_FEEDBACK_TYPE_END)) {
  185. $row['attempt_link'] = $attempt_link;
  186. }
  187. $my_attempt_array[] = $row;
  188. $i--;
  189. }
  190. $table = new HTML_Table(array('class' => 'data_table'));
  191. //Hiding score and answer
  192. switch ($objExercise->results_disabled) {
  193. case RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS:
  194. case RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES:
  195. $header_names = array(get_lang('Attempt'), get_lang('StartDate'), get_lang('Score'), get_lang('Details'));
  196. break;
  197. case RESULT_DISABLE_NO_SCORE_AND_EXPECTED_ANSWERS:
  198. $header_names = array(get_lang('Attempt'), get_lang('StartDate'));
  199. break;
  200. case RESULT_DISABLE_SHOW_SCORE_ONLY:
  201. if ($objExercise->feedback_type != EXERCISE_FEEDBACK_TYPE_END) {
  202. $header_names = array(get_lang('Attempt'), get_lang('StartDate'), get_lang('Score'));
  203. }
  204. else {
  205. $header_names = array(get_lang('Attempt'), get_lang('StartDate'), get_lang('Score'), get_lang('Details'));
  206. }
  207. break;
  208. }
  209. $column = 0;
  210. foreach ($header_names as $item) {
  211. $table->setHeaderContents(0, $column, $item);
  212. $column++;
  213. }
  214. $row = 1;
  215. if (!empty($my_attempt_array)) {
  216. foreach ($my_attempt_array as $data) {
  217. $column = 0;
  218. $table->setCellContents($row, $column, $data);
  219. $class = 'class="row_odd"';
  220. if($row % 2) {
  221. $class = 'class="row_even"';
  222. }
  223. $table->setRowAttributes($row, $class, true);
  224. $column++;
  225. $row++;
  226. }
  227. }
  228. $table_content = $table->toHtml();
  229. }
  230. if ($objExercise->selectAttempts()) {
  231. $attempt_message = get_lang('Attempts').' '.$counter.' / '.$objExercise->selectAttempts();
  232. if ($counter == $objExercise->selectAttempts()) {
  233. $attempt_message = Display::return_message($attempt_message, 'error');
  234. } else {
  235. $attempt_message = Display::return_message($attempt_message, 'info');
  236. }
  237. if ($visible_return['value'] == true) {
  238. $message .= $attempt_message;
  239. }
  240. }
  241. if ($time_control) {
  242. $html.= $objExercise->return_time_left_div();
  243. }
  244. $html .= $message;
  245. if (!empty($exercise_url_button)) {
  246. $html .= Display::div(
  247. Display::div(
  248. $exercise_url_button,
  249. array('class' => 'exercise_overview_options span12')
  250. ),
  251. array('class' => ' row')
  252. );
  253. }
  254. $html .= $table_content;
  255. echo $html;
  256. if ($origin != 'learnpath') {
  257. Display::display_footer();
  258. }