overview.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. if (isset ($_SESSION['objExercise'])) {
  19. Session::erase('objExercise');
  20. }
  21. $this_section = SECTION_COURSES;
  22. // Notice for unauthorized people.
  23. api_protect_course_script(true);
  24. $exercise_id = isset($_REQUEST['exerciseId']) ? intval($_REQUEST['exerciseId']) : 0;
  25. $objExercise = new Exercise();
  26. $result = $objExercise->read($exercise_id);
  27. if (!$result) {
  28. api_not_allowed(true);
  29. }
  30. $gradebook = isset($_GET['gradebook']) ? Security :: remove_XSS($_GET['gradebook']) : null;
  31. $learnpath_id = isset($_REQUEST['learnpath_id']) ? intval($_REQUEST['learnpath_id']) : null;
  32. $learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? intval($_REQUEST['learnpath_item_id']) : null;
  33. $origin = isset($_REQUEST['origin']) ? Security::remove_XSS($_REQUEST['origin']) : null;
  34. $interbreadcrumb[] = array ("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices'));
  35. $interbreadcrumb[] = array ("url" => "#","name" => $objExercise->name);
  36. $time_control = false;
  37. $clock_expired_time = ExerciseLib::get_session_time_control_key($objExercise->id, $learnpath_id, $learnpath_item_id);
  38. if ($objExercise->expired_time != 0 && !empty($clock_expired_time)) {
  39. $time_control = true;
  40. }
  41. if ($time_control) {
  42. // Get time left for expiring time
  43. $time_left = api_strtotime($clock_expired_time,'UTC') - time();
  44. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/stylesheet/jquery.epiclock.css');
  45. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/renderers/minute/epiclock.minute.css');
  46. $htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.dateformat.min.js');
  47. $htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.epiclock.min.js');
  48. $htmlHeadXtra[] = api_get_js('epiclock/renderers/minute/epiclock.minute.js');
  49. $htmlHeadXtra[] = $objExercise->show_time_control_js($time_left);
  50. }
  51. if ($origin != 'learnpath') {
  52. Display::display_header();
  53. } else {
  54. Display::display_reduced_header();
  55. }
  56. $html = '';
  57. $message = '';
  58. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  59. $edit_link = '';
  60. if ($is_allowed_to_edit ) {
  61. $edit_link = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), api_get_path(WEB_CODE_PATH).'exercice/admin.php?'.api_get_cidreq().'&id_session='.api_get_session_id().'&exerciseId='.$objExercise->id);
  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->getStatTrackExerciseInfo($learnpath_id, $learnpath_item_id, 0);
  74. $attempt_list = null;
  75. if (isset($exercise_stat_info['exe_id'])) {
  76. $attempt_list = 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($learnpath_id, $learnpath_item_id, null, false);
  92. //Exercise is not visible remove the button
  93. if ($visible_return['value'] == false) {
  94. if ($is_allowed_to_edit) {
  95. $message = Display::return_message(get_lang('ThisItemIsInvisibleForStudentsButYouHaveAccessAsTeacher'), 'warning');
  96. } else {
  97. $message = $visible_return['message'];
  98. $exercise_url_button = null;
  99. }
  100. }
  101. $attempts = getExerciseResultsByUser(api_get_user_id(), $objExercise->id, api_get_course_int_id(), api_get_session_id(), $learnpath_id, $learnpath_item_id, 'desc');
  102. $counter = count($attempts);
  103. $my_attempt_array = array();
  104. $table_content = '';
  105. /* Make a special case for IE, which doesn't seem to be able to handle the
  106. * results popup -> send it to the full results page */
  107. $browser = new Browser();
  108. $current_browser = $browser->getBrowser();
  109. $url_suffix = '';
  110. $btn_class = 'ajax ';
  111. if ($current_browser == 'Internet Explorer') {
  112. $url_suffix = '&amp;show_headers=1';
  113. $btn_class = '';
  114. }
  115. if (!empty($attempts)) {
  116. $i = $counter;
  117. foreach ($attempts as $attempt_result) {
  118. $score = ExerciseLib::show_score($attempt_result['exe_result'], $attempt_result['exe_weighting']);
  119. $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;
  120. $attempt_link = Display::url(get_lang('Show'), $attempt_url, array('class'=>$btn_class.'btn'));
  121. $teacher_revised = Display::label(get_lang('Validated'), 'success');
  122. //$attempt_link = get_lang('NoResult');
  123. //$attempt_link = Display::return_icon('quiz_na.png', get_lang('NoResult'), array(), ICON_SIZE_SMALL);
  124. if ($attempt_result['attempt_revised'] == 0) {
  125. $teacher_revised = Display::label(get_lang('NotValidated'), 'info');
  126. }
  127. $row = array('count' => $i,
  128. 'date' => api_convert_and_format_date($attempt_result['start_date'], DATE_TIME_FORMAT_LONG)
  129. );
  130. $attempt_link .= "&nbsp;&nbsp;&nbsp;".$teacher_revised;
  131. 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))) {
  132. $row['result'] = $score;
  133. }
  134. if (in_array($objExercise->results_disabled, array(RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS, RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES))) {
  135. $row['attempt_link'] = $attempt_link;
  136. }
  137. $my_attempt_array[] = $row;
  138. $i--;
  139. }
  140. $table = new HTML_Table(array('class' => 'data_table'));
  141. //Hiding score and answer
  142. switch ($objExercise->results_disabled) {
  143. case RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS:
  144. case RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES:
  145. $header_names = array(get_lang('Attempt'), get_lang('StartDate'), get_lang('Score'), get_lang('Details'));
  146. break;
  147. case RESULT_DISABLE_NO_SCORE_AND_EXPECTED_ANSWERS:
  148. $header_names = array(get_lang('Attempt'), get_lang('StartDate'));
  149. break;
  150. case RESULT_DISABLE_SHOW_SCORE_ONLY:
  151. $header_names = array(get_lang('Attempt'), get_lang('StartDate'), get_lang('Score'));
  152. break;
  153. }
  154. $column = 0;
  155. foreach ($header_names as $item) {
  156. $table->setHeaderContents(0, $column, $item);
  157. $column++;
  158. }
  159. $row = 1;
  160. if (!empty($my_attempt_array)) {
  161. foreach ($my_attempt_array as $data) {
  162. $column = 0;
  163. $table->setCellContents($row, $column, $data);
  164. $class = 'class="row_odd"';
  165. if($row % 2) {
  166. $class = 'class="row_even"';
  167. }
  168. $table->setRowAttributes($row, $class, true);
  169. $column++;
  170. $row++;
  171. }
  172. }
  173. $table_content = $table->toHtml();
  174. }
  175. if ($objExercise->selectAttempts()) {
  176. if ($is_allowed_to_edit) {
  177. //$options.= Display::div(get_lang('ExerciseAttempts').' '.$objExercise->selectAttempts(), array('class'=>'right_option'));
  178. }
  179. $attempt_message = get_lang('Attempts').' '.$counter.' / '.$objExercise->selectAttempts();
  180. if ($counter == $objExercise->selectAttempts()) {
  181. $attempt_message = Display::return_message($attempt_message, 'error');
  182. } else {
  183. $attempt_message = Display::return_message($attempt_message, 'info');
  184. }
  185. if ($visible_return['value'] == true) {
  186. $message .= $attempt_message;
  187. }
  188. }
  189. if ($time_control) {
  190. $html.= $objExercise->return_time_left_div();
  191. }
  192. $html .= $message;
  193. if (!empty($exercise_url_button)) {
  194. $html .= Display::div(Display::div($exercise_url_button, array('class'=>'exercise_overview_options span12')), array('class'=>' row'));
  195. }
  196. $html .= $table_content;
  197. echo $html;
  198. if ($origin != 'learnpath') {
  199. Display::display_footer();
  200. }