course.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Courses reporting
  5. * @package chamilo.reporting
  6. */
  7. /**
  8. * Code
  9. */
  10. ob_start();
  11. $nameTools = 'Cours';
  12. // name of the language file that needs to be included
  13. $language_file = array ('admin', 'registration', 'index', 'tracking');
  14. $cidReset = true;
  15. require_once '../inc/global.inc.php';
  16. $this_section = SECTION_TRACKING;
  17. $id_session = intval($_GET['id_session']);
  18. api_block_anonymous_users();
  19. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
  20. if (isset($_GET["id_session"]) && $_GET["id_session"] != "") {
  21. $interbreadcrumb[] = array ("url" => "session.php", "name" => get_lang('Sessions'));
  22. }
  23. if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && isset($_GET["type"]) && $_GET["type"] == "coach") {
  24. $interbreadcrumb[] = array ("url" => "coaches.php", "name" => get_lang('Tutors'));
  25. }
  26. if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && isset($_GET["type"]) && $_GET["type"] == "student") {
  27. $interbreadcrumb[] = array ("url" => "student.php", "name" => get_lang('Students'));
  28. }
  29. if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && !isset($_GET["type"])) {
  30. $interbreadcrumb[] = array ("url" => "teachers.php", "name" => get_lang('Teachers'));
  31. }
  32. function count_courses() {
  33. global $nb_courses;
  34. return $nb_courses;
  35. }
  36. //checking if the current coach is the admin coach
  37. $show_import_icon = false;
  38. if (api_get_setting('add_users_by_coach') == 'true') {
  39. if (!api_is_platform_admin()) {
  40. $sql = 'SELECT id_coach FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$id_session;
  41. $rs = Database::query($sql);
  42. if (Database::result($rs, 0, 0) != $_user['user_id']) {
  43. api_not_allowed(true);
  44. } else {
  45. $show_import_icon=true;
  46. }
  47. }
  48. }
  49. Display :: display_header($nameTools);
  50. $a_courses = array();
  51. if (api_is_drh() || api_is_session_admin() || api_is_platform_admin()) {
  52. $title = '';
  53. if (empty($id_session)) {
  54. if (isset($_GET['user_id'])) {
  55. $user_id = intval($_GET['user_id']);
  56. $user_info = api_get_user_info($user_id);
  57. $title = get_lang('AssignedCoursesTo').' '.api_get_person_name($user_info['firstname'], $user_info['lastname']);
  58. $courses = CourseManager::get_course_list_of_user_as_course_admin($user_id);
  59. } else {
  60. $title = get_lang('YourCourseList');
  61. $courses = CourseManager::get_courses_followed_by_drh($_user['user_id']);
  62. }
  63. } else {
  64. $session_name = api_get_session_name($id_session);
  65. $title = api_htmlentities($session_name,ENT_QUOTES,$charset).' : '.get_lang('CourseListInSession');
  66. $courses = Tracking::get_courses_list_from_session($id_session);
  67. }
  68. $a_courses = array_keys($courses);
  69. if (!api_is_session_admin()) {
  70. $menu_items[] = Display::url(Display::return_icon('stats.png', get_lang('MyStats'),'',ICON_SIZE_MEDIUM),api_get_path(WEB_CODE_PATH)."auth/my_progress.php" );
  71. $menu_items[] = Display::url(Display::return_icon('user.png', get_lang('Students'), array(), 32), "index.php?view=drh_students&amp;display=yourstudents");
  72. $menu_items[] = Display::url(Display::return_icon('teacher.png', get_lang('Trainers'), array(), 32), 'teachers.php');
  73. $menu_items[] = Display::return_icon('course_na.png', get_lang('Courses'), array(), 32);
  74. $menu_items[] = Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), 32), 'session.php');
  75. }
  76. echo '<div class="actions">';
  77. $nb_menu_items = count($menu_items);
  78. if ($nb_menu_items > 1) {
  79. foreach ($menu_items as $key => $item) {
  80. echo $item;
  81. }
  82. }
  83. if (count($a_courses) > 0) {
  84. echo '<span style="float:right">';
  85. echo Display::url(Display::return_icon('printer.png', get_lang('Print'), array(), 32), 'javascript: void(0);', array('onclick'=>'javascript: window.print();'));
  86. echo '</span>';
  87. }
  88. echo '</div>';
  89. echo Display::page_header($title);
  90. }
  91. // Database Table Definitions
  92. $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  93. $tbl_user_course = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  94. if (isset($_GET['action'])) {
  95. if ($_GET['action'] == 'show_message') {
  96. Display :: display_normal_message(stripslashes($_GET['message']), false);
  97. }
  98. if ($_GET['action'] == 'error_message') {
  99. Display :: display_error_message(stripslashes($_GET['message']), false);
  100. }
  101. }
  102. if ($show_import_icon) {
  103. echo "<div align=\"right\">";
  104. echo '<a href="user_import.php?id_session='.$id_session.'&action=export&amp;type=xml">'.Display::return_icon('excel.gif', get_lang('ImportUserListXMLCSV')).'&nbsp;'.get_lang('ImportUserListXMLCSV').'</a>';
  105. echo "</div><br />";
  106. }
  107. if (!api_is_drh() && !api_is_session_admin() && !api_is_platform_admin()) {
  108. $courses = Tracking::get_courses_followed_by_coach($_user['user_id'], $id_session);
  109. $a_courses = array_keys($courses);
  110. }
  111. $nb_courses = count($a_courses);
  112. $table = new SortableTable('tracking_list_course', 'count_courses');
  113. $table -> set_header(0, get_lang('CourseTitle'), false);
  114. $table -> set_header(1, get_lang('NbStudents'), false);
  115. $table -> set_header(2, get_lang('TimeSpentInTheCourse').Display :: return_icon('info3.gif', get_lang('TimeOfActiveByTraining'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
  116. $table -> set_header(3, get_lang('ThematicAdvance'), false);
  117. $table -> set_header(4, get_lang('AvgStudentsProgress').Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
  118. $table -> set_header(5, get_lang('AvgCourseScore').Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
  119. //$table -> set_header(5, get_lang('AvgExercisesScore'), false);// no code for this?
  120. $table -> set_header(6, get_lang('AvgMessages'), false);
  121. $table -> set_header(7, get_lang('AvgAssignments'), false);
  122. $table -> set_header(8, get_lang('Details'), false);
  123. $csv_header[] = array(
  124. get_lang('CourseTitle', ''),
  125. get_lang('NbStudents', ''),
  126. get_lang('TimeSpentInTheCourse', ''),
  127. get_lang('ThematicAdvance', ''),
  128. get_lang('AvgStudentsProgress', ''),
  129. get_lang('AvgCourseScore', ''),
  130. //get_lang('AvgExercisesScore', ''),
  131. get_lang('AvgMessages', ''),
  132. get_lang('AvgAssignments', '')
  133. );
  134. if (is_array($a_courses)) {
  135. foreach ($a_courses as $courseId) {
  136. $courseId = intval($courseId);
  137. $nb_students_in_course = 0;
  138. $course = api_get_course_info_by_id($courseId);
  139. $course_code = $course['code'];
  140. $avg_assignments_in_course = $avg_messages_in_course = $avg_progress_in_course = $avg_score_in_course = $avg_time_spent_in_course = 0;
  141. // students directly subscribed to the course
  142. if (empty($id_session)) {
  143. $sql = "SELECT user_id FROM $tbl_user_course as course_rel_user
  144. WHERE course_rel_user.status='5' AND course_rel_user.c_id =".$courseId;
  145. } else {
  146. $sql = "SELECT id_user as user_id FROM $tbl_session_course_user srcu
  147. WHERE srcu.c_id='$courseId' AND id_session = '$id_session' AND srcu.status<>2";
  148. }
  149. $rs = Database::query($sql);
  150. $users = array();
  151. while ($row = Database::fetch_array($rs)) {
  152. $users[] = $row['user_id'];
  153. }
  154. if (count($users) > 0) {
  155. $nb_students_in_course = count($users);
  156. // tracking datas
  157. $avg_progress_in_course = Tracking :: get_avg_student_progress ($users, $courseId, array(), $id_session);
  158. $avg_score_in_course = Tracking :: get_avg_student_score ($users, $courseId, array(), $id_session);
  159. $avg_time_spent_in_course = Tracking :: get_time_spent_on_the_course ($users, $courseId, $id_session);
  160. $messages_in_course = Tracking :: count_student_messages ($users, $courseId, $id_session);
  161. $assignments_in_course = Tracking :: count_student_assignments ($users, $courseId, $id_session);
  162. $avg_time_spent_in_course = api_time_to_hms($avg_time_spent_in_course / $nb_students_in_course);
  163. $avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course, 2);
  164. if (is_numeric($avg_score_in_course)) {
  165. $avg_score_in_course = round($avg_score_in_course / $nb_students_in_course, 2).'%';
  166. }
  167. } else {
  168. $avg_time_spent_in_course = null;
  169. $avg_progress_in_course = null;
  170. $avg_score_in_course = null;
  171. $messages_in_course = null;
  172. $assignments_in_course = null;
  173. }
  174. $tematic_advance_progress = 0;
  175. $thematic = new Thematic($course);
  176. $tematic_advance = $thematic->get_total_average_of_thematic_advances($course_code, $id_session);
  177. if (!empty($tematic_advance)) {
  178. $tematic_advance_csv = $tematic_advance_progress.'%';
  179. $tematic_advance_progress = '<a title="'.get_lang('GoToThematicAdvance').'" href="'.api_get_path(WEB_CODE_PATH).'course_progress/index.php?cidReq='.$course_code.'&id_session='.$id_session.'">'.$tematic_advance.'%</a>';
  180. } else {
  181. $tematic_advance_progress = '-';
  182. }
  183. $table_row = array();
  184. $table_row[] = $course['title'];
  185. $table_row[] = $nb_students_in_course;
  186. $table_row[] = is_null($avg_time_spent_in_course)?'-':$avg_time_spent_in_course;
  187. $table_row[] = $tematic_advance_progress;
  188. $table_row[] = is_null($avg_progress_in_course) ? '-' : $avg_progress_in_course.'%';
  189. $table_row[] = is_null($avg_score_in_course) ? '-' : $avg_score_in_course;
  190. $table_row[] = is_null($messages_in_course)?'-':$messages_in_course;
  191. $table_row[] = is_null($assignments_in_course)?'-':$assignments_in_course;
  192. $table_row[] = '<a href="../tracking/courseLog.php?cidReq='.$course_code.'&id_session='.$id_session.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  193. $csv_content[] = array (
  194. $course['title'],
  195. $nb_students_in_course,
  196. $avg_time_spent_in_course,
  197. $tematic_advance_csv,
  198. is_null($avg_progress_in_course) ? null : $avg_progress_in_course.'%',
  199. is_null($avg_score_in_course) ? null : $avg_score_in_course,
  200. $messages_in_course,
  201. $assignments_in_course,
  202. );
  203. $table -> addRow($table_row, 'align="right"');
  204. }
  205. // $csv_content = array_merge($csv_header, $csv_content); // Before this statement you are allowed to sort (in different way) the array $csv_content.
  206. }
  207. //$table -> setColAttributes(0);
  208. //$table -> setColAttributes(7);
  209. $table -> display();
  210. Display :: display_footer();