overview.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. require_once 'exercise.lib.php';
  17. $current_course_tool = TOOL_QUIZ;
  18. // Clear the exercise session just in case
  19. if (isset ($_SESSION['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 = 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. if ($time_control) {
  43. // Get time left for expiring time
  44. $time_left = api_strtotime($clock_expired_time,'UTC') - time();
  45. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/stylesheet/jquery.epiclock.css');
  46. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/renderers/minute/epiclock.minute.css');
  47. $htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.dateformat.min.js');
  48. $htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.epiclock.min.js');
  49. $htmlHeadXtra[] = api_get_js('epiclock/renderers/minute/epiclock.minute.js');
  50. $htmlHeadXtra[] = $objExercise->show_time_control_js($time_left);
  51. }
  52. if ($origin != 'learnpath') {
  53. Display::display_header();
  54. } else {
  55. Display::display_reduced_header();
  56. }
  57. $html = '';
  58. $message = '';
  59. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  60. $edit_link = '';
  61. if ($is_allowed_to_edit ) {
  62. $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);
  63. }
  64. //Exercise name
  65. $html .= Display::page_header( $objExercise->name.' '.$edit_link);
  66. //Exercise description
  67. if (!empty($objExercise->description)) {
  68. $html .= Display::div($objExercise->description, array('class'=>'exercise_description'));
  69. }
  70. $extra_params = '';
  71. if (isset($_GET['preview'])) {
  72. $extra_params = '&preview=1';
  73. }
  74. $exercise_stat_info = $objExercise->get_stat_track_exercise_info($learnpath_id, $learnpath_item_id, 0);
  75. $attempt_list = null;
  76. if (isset($exercise_stat_info['exe_id'])) {
  77. $attempt_list = get_all_exercise_event_by_exe_id($exercise_stat_info['exe_id']);
  78. }
  79. //1. Check if this is a new attempt or a previous
  80. $label = get_lang('StartTest');
  81. if ($time_control && !empty($clock_expired_time) || !empty($attempt_list)) {
  82. $label = get_lang('ContinueTest');
  83. }
  84. if (!empty($attempt_list)) {
  85. $message = Display::return_message(get_lang('YouTriedToResolveThisExerciseEarlier'));
  86. }
  87. //2. Exercise button
  88. //Notice we not add there the lp_item_view_id because is not already generated
  89. $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;
  90. $exercise_url_button = Display::url($label, $exercise_url, array('class'=>'btn btn-primary btn-large'));
  91. //3. Checking visibility of the exercise (overwrites the exercise button)
  92. $visible_return = $objExercise->is_visible($learnpath_id, $learnpath_item_id, null, false);
  93. //Exercise is not visible remove the button
  94. if ($visible_return['value'] == false) {
  95. if ($is_allowed_to_edit) {
  96. $message = Display::return_message(get_lang('ThisItemIsInvisibleForStudentsButYouHaveAccessAsTeacher'), 'warning');
  97. } else {
  98. $message = $visible_return['message'];
  99. $exercise_url_button = null;
  100. }
  101. }
  102. $attempts = get_exercise_results_by_user(api_get_user_id(), $objExercise->id, api_get_course_id(), api_get_session_id(), $learnpath_id, $learnpath_item_id, 'desc');
  103. $counter = count($attempts);
  104. $my_attempt_array = array();
  105. $table_content = '';
  106. /* Make a special case for IE, which doesn't seem to be able to handle the
  107. * results popup -> send it to the full results page */
  108. require_once api_get_path(LIBRARY_PATH).'browser/Browser.php';
  109. $browser = new Browser();
  110. $current_browser = $browser->getBrowser();
  111. $url_suffix = '';
  112. $btn_class = 'ajax ';
  113. if ($current_browser == 'Internet Explorer') {
  114. $url_suffix = '&amp;show_headers=1';
  115. $btn_class = '';
  116. }
  117. if (!empty($attempts)) {
  118. $i = $counter;
  119. foreach ($attempts as $attempt_result) {
  120. $score = show_score($attempt_result['exe_result'], $attempt_result['exe_weighting']);
  121. $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;
  122. $attempt_link = Display::url(get_lang('Show'), $attempt_url, array('class'=>$btn_class.'btn'));
  123. $teacher_revised = Display::label(get_lang('Validated'), 'success');
  124. //$attempt_link = get_lang('NoResult');
  125. //$attempt_link = Display::return_icon('quiz_na.png', get_lang('NoResult'), array(), ICON_SIZE_SMALL);
  126. if ($attempt_result['attempt_revised'] == 0) {
  127. $teacher_revised = Display::label(get_lang('NotValidated'), 'info');
  128. }
  129. $row = array('count' => $i,
  130. 'date' => api_convert_and_format_date($attempt_result['start_date'], DATE_TIME_FORMAT_LONG)
  131. );
  132. $attempt_link .= "&nbsp;&nbsp;&nbsp;".$teacher_revised;
  133. 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))) {
  134. $row['result'] = $score;
  135. }
  136. if (in_array($objExercise->results_disabled, array(RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS, RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES))) {
  137. $row['attempt_link'] = $attempt_link;
  138. }
  139. $my_attempt_array[] = $row;
  140. $i--;
  141. }
  142. $table = new HTML_Table(array('class' => 'data_table'));
  143. //Hiding score and answer
  144. switch ($objExercise->results_disabled) {
  145. case RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS:
  146. case RESULT_DISABLE_SHOW_FINAL_SCORE_ONLY_WITH_CATEGORIES:
  147. $header_names = array(get_lang('Attempt'), get_lang('StartDate'), get_lang('Score'), get_lang('Details'));
  148. break;
  149. case RESULT_DISABLE_NO_SCORE_AND_EXPECTED_ANSWERS:
  150. $header_names = array(get_lang('Attempt'), get_lang('StartDate'));
  151. break;
  152. case RESULT_DISABLE_SHOW_SCORE_ONLY:
  153. $header_names = array(get_lang('Attempt'), get_lang('StartDate'), get_lang('Score'));
  154. break;
  155. }
  156. $column = 0;
  157. foreach ($header_names as $item) {
  158. $table->setHeaderContents(0, $column, $item);
  159. $column++;
  160. }
  161. $row = 1;
  162. if (!empty($my_attempt_array)) {
  163. foreach ($my_attempt_array as $data) {
  164. $column = 0;
  165. $table->setCellContents($row, $column, $data);
  166. $class = 'class="row_odd"';
  167. if($row % 2) {
  168. $class = 'class="row_even"';
  169. }
  170. $table->setRowAttributes($row, $class, true);
  171. $column++;
  172. $row++;
  173. }
  174. }
  175. $table_content = $table->toHtml();
  176. }
  177. if ($objExercise->selectAttempts()) {
  178. if ($is_allowed_to_edit) {
  179. //$options.= Display::div(get_lang('ExerciseAttempts').' '.$objExercise->selectAttempts(), array('class'=>'right_option'));
  180. }
  181. $attempt_message = get_lang('Attempts').' '.$counter.' / '.$objExercise->selectAttempts();
  182. if ($counter == $objExercise->selectAttempts()) {
  183. $attempt_message = Display::return_message($attempt_message, 'error');
  184. } else {
  185. $attempt_message = Display::return_message($attempt_message, 'info');
  186. }
  187. if ($visible_return['value'] == true) {
  188. $message .= $attempt_message;
  189. }
  190. //$options.= $attempt_message; //Display::div($attempt_message, array('class'=>"offset2 span2"));
  191. }
  192. if ($time_control) {
  193. $html.= $objExercise->return_time_left_div();
  194. }
  195. $html .= $message;
  196. if (!empty($exercise_url_button)) {
  197. $html .= Display::div(Display::div($exercise_url_button, array('class'=>'exercise_overview_options span12')), array('class'=>' row'));
  198. }
  199. $html .= $table_content;
  200. echo $html;
  201. if ($origin != 'learnpath') {
  202. Display::display_footer();
  203. }