overview.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. require_once 'exercise.class.php';
  13. require_once 'exercise.lib.php';
  14. $language_file = 'exercice';
  15. require_once '../inc/global.inc.php';
  16. $this_section = SECTION_COURSES;
  17. // Notice for unauthorized people.
  18. api_protect_course_script(true);
  19. if (empty ($exerciseId)) {
  20. $exercise_id = intval($_REQUEST['exerciseId']);
  21. }
  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. if ($origin != 'learnpath') {
  34. Display::display_header();
  35. } else {
  36. Display::display_reduced_header();
  37. }
  38. $html = '';
  39. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  40. $edit_link = '';
  41. if ($is_allowed_to_edit ) {
  42. $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);
  43. }
  44. $html .= Display::tag('h1', $objExercise->name .' '.$edit_link);
  45. $html .= Display::div($objExercise->description, array('class'=>'exercise_description'));
  46. //Buttons
  47. //Notice we not add there the lp_item_view__id because is not already generated
  48. $exercise_url = api_get_path(WEB_CODE_PATH).'exercice/exercise_submit.php?'.api_get_cidreq().'&id_session='.api_get_session_id().'&exerciseId='.$objExercise->id.'&origin='.$origin.'&learnpath_id='.$learnpath_id.'&learnpath_item_id='.$learnpath_item_id;
  49. $exercise_url = Display::url(get_lang('StartTest'), $exercise_url, array('class'=>'a_button orange bigger round'));
  50. if (!$objExercise->is_visible()) {
  51. $exercise_url = Display::div(get_lang('StartTest'), array('class'=>'a_button white bigger round no_link'));
  52. }
  53. $options = Display::div('', array('class'=>'left_option'));
  54. $options .= Display::div($exercise_url, array('class'=>'center_option'));
  55. $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);
  56. $my_attempt_array = array();
  57. $counter = 0;
  58. $table_content = '';
  59. if (!empty($attempts)) {
  60. foreach($attempts as $attempt_result) {
  61. $counter++;
  62. $score = show_score($attempt_result['exe_result'], $attempt_result['exe_weighting']);
  63. $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';
  64. $attempt_link = Display::url(Display::return_icon('quiz.png', get_lang('Result'), array(), 22), $attempt_url, array('class'=>'thickbox'));
  65. if (!$is_allowed_to_edit && $attempt_result['attempt_revised'] == 0) {
  66. $attempt_link = get_lang('NoResult');
  67. $attempt_link = Display::return_icon('quiz_na.png', get_lang('NoResult'), array(), 22);
  68. }
  69. $row = array('count' => $counter,
  70. 'date' => api_convert_and_format_date($attempt_result['start_date'], DATE_TIME_FORMAT_LONG)
  71. );
  72. if ($objExercise->results_disabled == EXERCISE_FEEDBACK_TYPE_END || $objExercise->results_disabled == EXERCISE_FEEDBACK_TYPE_EXAM) {
  73. $row['result'] = $score;
  74. }
  75. if ($objExercise->results_disabled == EXERCISE_FEEDBACK_TYPE_END) {
  76. $row['attempt_link'] = $attempt_link;
  77. }
  78. $my_attempt_array[] = $row;
  79. }
  80. $table = new HTML_Table(array('class' => 'data_table'));
  81. //Hiding score and answer
  82. switch($objExercise->results_disabled) {
  83. case EXERCISE_FEEDBACK_TYPE_END:
  84. $header_names = array(get_lang('Attempt'), get_lang('Date'), get_lang('Score'), get_lang('Details'));
  85. break;
  86. case EXERCISE_FEEDBACK_TYPE_DIRECT:
  87. $header_names = array(get_lang('Attempt'), get_lang('Date'));
  88. break;
  89. case EXERCISE_FEEDBACK_TYPE_EXAM:
  90. $header_names = array(get_lang('Attempt'), get_lang('Date'), get_lang('Score'));
  91. break;
  92. }
  93. $row = 0;
  94. $column = 0;
  95. foreach ($header_names as $item) {
  96. $table->setHeaderContents($row, $column, $item);
  97. $column++;
  98. }
  99. $row = 1;
  100. if (!empty($my_attempt_array)) {
  101. foreach ($my_attempt_array as $data) {
  102. $column = 0;
  103. $table->setCellContents($row, $column, $data);
  104. //$table->setRowAttributes($row, 'style="text-align:center"');
  105. $class = 'class="row_odd"';
  106. if($row % 2) {
  107. $class = 'class="row_even"';
  108. }
  109. $table->setRowAttributes($row, $class, true);
  110. $column++;
  111. $row++;
  112. }
  113. }
  114. $table_content = $table->toHtml();
  115. }
  116. if ($objExercise->selectAttempts()) {
  117. if ($is_allowed_to_edit) {
  118. $options.= Display::div(get_lang('ExerciseAttempts').' '.$objExercise->selectAttempts(), array('class'=>'right_option'));
  119. } else {
  120. $red_class = '';
  121. if ($counter == $objExercise->selectAttempts()) {
  122. $class = 'red_alert';
  123. }
  124. $options.= Display::div(get_lang('Attempts').' '.$counter.' / '.$objExercise->selectAttempts(), array('class'=>"right_option $class"));
  125. }
  126. }
  127. $html.= Display::div($options, array('class'=>'exercise_overview_options'));
  128. $html .= $table_content;
  129. echo Display::div($html, array('class'=>'rounded_div', 'style'=>'width:92%'));
  130. if ($origin != 'learnpath') {
  131. Display::display_footer();
  132. }