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