overview.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. $language_file = 'exercice';
  13. require_once 'exercise.class.php';
  14. require_once '../inc/global.inc.php';
  15. require_once 'exercise.lib.php';
  16. $this_section = SECTION_COURSES;
  17. // Notice for unauthorized people.
  18. api_protect_course_script(true);
  19. $exercise_id = isset($_REQUEST['exerciseId']) ? intval($_REQUEST['exerciseId']) : 0;
  20. $objExercise = new Exercise();
  21. $result = $objExercise->read($exercise_id);
  22. if (!$result) {
  23. api_not_allowed(true);
  24. }
  25. $gradebook = isset($_GET['gradebook']) ? Security :: remove_XSS($_GET['gradebook']) : null;
  26. $learnpath_id = isset($_REQUEST['learnpath_id']) ? intval($_REQUEST['learnpath_id']) : null;
  27. $learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? intval($_REQUEST['learnpath_item_id']) : null;
  28. $origin = isset($_REQUEST['origin']) ? Security::remove_XSS($_REQUEST['origin']) : null;
  29. $interbreadcrumb[] = array ("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices'));
  30. $interbreadcrumb[] = array ("url" => "#","name" => $objExercise->name);
  31. $time_control = false;
  32. if ($objExercise->expired_time != 0 && $origin != 'learnpath') {
  33. $time_control = true;
  34. }
  35. $clock_expired_time = get_session_time_control_key($objExercise->id);
  36. // Get time left for exipiring time
  37. $time_left = api_strtotime($clock_expired_time,'UTC') - time();
  38. if ($time_control) {
  39. $htmlHeadXtra[] = api_get_js('jquery.epiclock.min.js');
  40. $htmlHeadXtra[] = $objExercise->show_time_control_js($time_left);
  41. }
  42. if ($origin != 'learnpath') {
  43. Display::display_header();
  44. } else {
  45. Display::display_reduced_header();
  46. }
  47. $html = '';
  48. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  49. $edit_link = '';
  50. if ($is_allowed_to_edit ) {
  51. $edit_link = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), 22), api_get_path(WEB_CODE_PATH).'exercice/admin.php?'.api_get_cidreq().'&id_session='.api_get_session_id().'&exerciseId='.$objExercise->id);
  52. }
  53. $html .= Display::tag('h1', $objExercise->name .' '.$edit_link);
  54. $html .= Display::div($objExercise->description, array('class'=>'exercise_description'));
  55. $extra_params = '';
  56. if (isset($_GET['preview'])) {
  57. $extra_params = '&preview=1';
  58. }
  59. //Notice we not add there the lp_item_view__id because is not already generated
  60. $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;
  61. $label = get_lang('StartTest');
  62. if ($time_control && !empty($clock_expired_time)) {
  63. $label = get_lang('ContinueTest');
  64. }
  65. $exercise_stat_info = $objExercise->get_stat_track_exercise_info($learnpath_id, $learnpath_item_id, 0);
  66. if (isset($exercise_stat_info['exe_id'])) {
  67. $attempt_list = get_all_exercise_event_by_exe_id($exercise_stat_info['exe_id']);
  68. }
  69. $message = '';
  70. if (!empty($attempt_list)) {
  71. $message = Display::return_message(get_lang('YouTriedToResolveThisExerciseEarlier'));
  72. $label = get_lang('ContinueTest');
  73. }
  74. $html .= $message;
  75. $exercise_url_button = Display::url($label, $exercise_url, array('class'=>'a_button blue bigger round'));
  76. if (!$objExercise->is_visible($learnpath_id, $learnpath_item_id)) {
  77. $exercise_url = api_get_path(WEB_CODE_PATH).'exercice/exercise_report.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id;
  78. //$exercise_url_button = Display::url(get_lang('SeeResults'), $exercise_url, array('class'=>'a_button white bigger round no_link'));
  79. if ($origin == 'learnpath') {
  80. $exercise_url_button = Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $objExercise->title, $objExercise->selectAttempts()), 'warning');
  81. }
  82. $exercise_url_button = sprintf(get_lang('ReachedMaxAttempts'), $objExercise->title, $objExercise->selectAttempts());
  83. }
  84. $options = Display::div('', array('class'=>'left_option'));
  85. if (!empty($exercise_url_button)) {
  86. $options .= Display::div($exercise_url_button, array('class'=>'center_option'));
  87. }
  88. $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');
  89. $my_attempt_array = array();
  90. $counter = count($attempts)+1;
  91. $table_content = '';
  92. if (!empty($attempts)) {
  93. foreach ($attempts as $attempt_result) {
  94. $counter--;
  95. $score = show_score($attempt_result['exe_result'], $attempt_result['exe_weighting']);
  96. $attempt_url = api_get_path(WEB_CODE_PATH).'exercice/result.php?'.api_get_cidreq().'&id='.$attempt_result['exe_id'].'&id_session='.api_get_session_id().'&height=500&width=750';
  97. $attempt_link = Display::url(get_lang('Show'), $attempt_url, array('class'=>'thickbox'));
  98. $teacher_revised = Display::span(get_lang('Validated'), array('class'=>'label_tag notice'));
  99. //$attempt_link = get_lang('NoResult');
  100. //$attempt_link = Display::return_icon('quiz_na.png', get_lang('NoResult'), array(), 22);
  101. if ($attempt_result['attempt_revised'] == 0) {
  102. $teacher_revised = Display::span(get_lang('NotValidated'), array('class'=>'label_tag notice'));
  103. }
  104. $row = array('count' => $counter,
  105. 'date' => api_convert_and_format_date($attempt_result['start_date'], DATE_TIME_FORMAT_LONG)
  106. );
  107. $attempt_link .= "&nbsp;&nbsp;&nbsp;".$teacher_revised;
  108. if ($objExercise->results_disabled == EXERCISE_FEEDBACK_TYPE_END || $objExercise->results_disabled == EXERCISE_FEEDBACK_TYPE_EXAM) {
  109. $row['result'] = $score;
  110. }
  111. if ($objExercise->results_disabled == EXERCISE_FEEDBACK_TYPE_END) {
  112. $row['attempt_link'] = $attempt_link;
  113. }
  114. $my_attempt_array[] = $row;
  115. }
  116. $table = new HTML_Table(array('class' => 'data_table'));
  117. //Hiding score and answer
  118. switch($objExercise->results_disabled) {
  119. case EXERCISE_FEEDBACK_TYPE_END:
  120. $header_names = array(get_lang('Attempt'), get_lang('Date'), get_lang('Score'), get_lang('Details'));
  121. break;
  122. case EXERCISE_FEEDBACK_TYPE_DIRECT:
  123. $header_names = array(get_lang('Attempt'), get_lang('Date'));
  124. break;
  125. case EXERCISE_FEEDBACK_TYPE_EXAM:
  126. $header_names = array(get_lang('Attempt'), get_lang('Date'), get_lang('Score'));
  127. break;
  128. }
  129. $row = 0;
  130. $column = 0;
  131. foreach ($header_names as $item) {
  132. $table->setHeaderContents($row, $column, $item);
  133. $column++;
  134. }
  135. $row = 1;
  136. if (!empty($my_attempt_array)) {
  137. foreach ($my_attempt_array as $data) {
  138. $column = 0;
  139. $table->setCellContents($row, $column, $data);
  140. //$table->setRowAttributes($row, 'style="text-align:center"');
  141. $class = 'class="row_odd"';
  142. if($row % 2) {
  143. $class = 'class="row_even"';
  144. }
  145. $table->setRowAttributes($row, $class, true);
  146. $column++;
  147. $row++;
  148. }
  149. }
  150. $table_content = $table->toHtml();
  151. }
  152. if ($objExercise->selectAttempts()) {
  153. if ($is_allowed_to_edit) {
  154. //$options.= Display::div(get_lang('ExerciseAttempts').' '.$objExercise->selectAttempts(), array('class'=>'right_option'));
  155. } else {
  156. }
  157. $red_class = '';
  158. if ($counter == $objExercise->selectAttempts()) {
  159. $class = 'red_alert';
  160. }
  161. $options.= Display::div(get_lang('Attempts').' '.$counter.' / '.$objExercise->selectAttempts(), array('class'=>"right_option $class"));
  162. }
  163. if ($time_control) {
  164. $html.= '<div align="left" id="wrapper-clock"><div id="square" class="rounded"><div id="text-content" align="center" class="count_down"></div></div></div>';
  165. }
  166. $html.= Display::div($options, array('class'=>'exercise_overview_options'));
  167. $html .= $table_content;
  168. echo Display::div($html, array('class'=>'rounded_div', 'style'=>'width:92%'));
  169. if ($origin != 'learnpath') {
  170. Display::display_footer();
  171. }