course.php 10 KB

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