overview.php 9.6 KB

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