overview.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. // Clear the exercise session just in case
  17. if (isset ($_SESSION['objExercise'])) {
  18. api_session_unregister('objExercise');
  19. }
  20. $this_section = SECTION_COURSES;
  21. // Notice for unauthorized people.
  22. api_protect_course_script(true);
  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. if ($objExercise->expired_time != 0 && $origin != 'learnpath') {
  37. $time_control = true;
  38. }
  39. $clock_expired_time = get_session_time_control_key($objExercise->id);
  40. // Get time left for exipiring time
  41. $time_left = api_strtotime($clock_expired_time,'UTC') - time();
  42. if ($time_control) {
  43. $htmlHeadXtra[] = api_get_js('jquery.epiclock.min.js');
  44. $htmlHeadXtra[] = $objExercise->show_time_control_js($time_left);
  45. }
  46. if ($origin != 'learnpath') {
  47. Display::display_header();
  48. } else {
  49. Display::display_reduced_header();
  50. }
  51. $html = '';
  52. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  53. $edit_link = '';
  54. if ($is_allowed_to_edit ) {
  55. $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);
  56. }
  57. //Exercise name
  58. $html .= Display::tag('h1', $objExercise->name .' '.$edit_link);
  59. //Exercise description
  60. $html .= Display::div($objExercise->description, array('class'=>'exercise_description'));
  61. $extra_params = '';
  62. if (isset($_GET['preview'])) {
  63. $extra_params = '&preview=1';
  64. }
  65. //Exercise button
  66. //Notice we not add there the lp_item_view__id because is not already generated
  67. $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;
  68. $label = get_lang('StartTest');
  69. if ($time_control && !empty($clock_expired_time)) {
  70. $label = get_lang('ContinueTest');
  71. }
  72. $exercise_stat_info = $objExercise->get_stat_track_exercise_info($learnpath_id, $learnpath_item_id, 0);
  73. $attempt_list = null;
  74. if (isset($exercise_stat_info['exe_id'])) {
  75. $attempt_list = get_all_exercise_event_by_exe_id($exercise_stat_info['exe_id']);
  76. }
  77. $exercise_url_button = Display::url($label, $exercise_url, array('class'=>'a_button blue bigger round'));
  78. $visible_return = $objExercise->is_visible($learnpath_id, $learnpath_item_id, null, false);
  79. if ($visible_return['value'] == false) {
  80. $exercise_url = api_get_path(WEB_CODE_PATH).'exercice/exercise_report.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id;
  81. $exercise_url_button = $visible_return['message'];
  82. }
  83. //Message "you already try this exercise"
  84. $message = '';
  85. if (!empty($attempt_list)) {
  86. $message = Display::return_message(get_lang('YouTriedToResolveThisExerciseEarlier'));
  87. $label = get_lang('ContinueTest');
  88. }
  89. $html .= $message;
  90. $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');
  91. $counter = count($attempts);
  92. $options = '';
  93. if (!empty($exercise_url_button)) {
  94. $options .= $exercise_url_button;
  95. }
  96. $options = Display::div($options, array('class'=>'offset4 span3'));
  97. $my_attempt_array = array();
  98. $table_content = '';
  99. if (!empty($attempts)) {
  100. $i = $counter;
  101. foreach ($attempts as $attempt_result) {
  102. $score = show_score($attempt_result['exe_result'], $attempt_result['exe_weighting']);
  103. $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';
  104. $attempt_link = Display::url(get_lang('Show'), $attempt_url, array('class'=>'thickbox a_button white small'));
  105. $teacher_revised = Display::span(get_lang('Validated'), array('class'=>'label_tag success'));
  106. //$attempt_link = get_lang('NoResult');
  107. //$attempt_link = Display::return_icon('quiz_na.png', get_lang('NoResult'), array(), ICON_SIZE_SMALL);
  108. if ($attempt_result['attempt_revised'] == 0) {
  109. $teacher_revised = Display::span(get_lang('NotValidated'), array('class'=>'label_tag notice'));
  110. }
  111. $row = array('count' => $i,
  112. 'date' => api_convert_and_format_date($attempt_result['start_date'], DATE_TIME_FORMAT_LONG)
  113. );
  114. $attempt_link .= "&nbsp;&nbsp;&nbsp;".$teacher_revised;
  115. if ($objExercise->results_disabled == EXERCISE_FEEDBACK_TYPE_END || $objExercise->results_disabled == EXERCISE_FEEDBACK_TYPE_EXAM) {
  116. $row['result'] = $score;
  117. }
  118. if ($objExercise->results_disabled == EXERCISE_FEEDBACK_TYPE_END) {
  119. $row['attempt_link'] = $attempt_link;
  120. }
  121. $my_attempt_array[] = $row;
  122. $i--;
  123. }
  124. $table = new HTML_Table(array('class' => 'data_table'));
  125. //Hiding score and answer
  126. switch($objExercise->results_disabled) {
  127. case EXERCISE_FEEDBACK_TYPE_END:
  128. $header_names = array(get_lang('Attempt'), get_lang('Date'), get_lang('Score'), get_lang('Details'));
  129. break;
  130. case EXERCISE_FEEDBACK_TYPE_DIRECT:
  131. $header_names = array(get_lang('Attempt'), get_lang('Date'));
  132. break;
  133. case EXERCISE_FEEDBACK_TYPE_EXAM:
  134. $header_names = array(get_lang('Attempt'), get_lang('Date'), get_lang('Score'));
  135. break;
  136. }
  137. $row = 0;
  138. $column = 0;
  139. foreach ($header_names as $item) {
  140. $table->setHeaderContents($row, $column, $item);
  141. $column++;
  142. }
  143. $row = 1;
  144. if (!empty($my_attempt_array)) {
  145. foreach ($my_attempt_array as $data) {
  146. $column = 0;
  147. $table->setCellContents($row, $column, $data);
  148. //$table->setRowAttributes($row, 'style="text-align:center"');
  149. $class = 'class="row_odd"';
  150. if($row % 2) {
  151. $class = 'class="row_even"';
  152. }
  153. $table->setRowAttributes($row, $class, true);
  154. $column++;
  155. $row++;
  156. }
  157. }
  158. $table_content = $table->toHtml();
  159. }
  160. if ($objExercise->selectAttempts()) {
  161. if ($is_allowed_to_edit) {
  162. //$options.= Display::div(get_lang('ExerciseAttempts').' '.$objExercise->selectAttempts(), array('class'=>'right_option'));
  163. }
  164. $attempt_message = get_lang('Attempts').' '.$counter.' / '.$objExercise->selectAttempts();
  165. if ($counter == $objExercise->selectAttempts()) {
  166. $attempt_message = Display::return_message($attempt_message, 'error');
  167. } else {
  168. $attempt_message = Display::return_message($attempt_message, 'info');
  169. }
  170. $options.= Display::div($attempt_message, array('class'=>"offset2 span2"));
  171. }
  172. if ($time_control) {
  173. $html.= '<div align="left" id="wrapper-clock"><div id="square" class="rounded"><div id="text-content" align="center" class="count_down"></div></div></div>';
  174. }
  175. $html.= Display::div(Display::div($options, array('class'=>'exercise_overview_options span12')), array('class'=>' row'));
  176. $html .= $table_content;
  177. echo $html;
  178. if ($origin != 'learnpath') {
  179. Display::display_footer();
  180. }