index.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. $language_file = array('registration', 'index', 'tracking');
  4. // resetting the course id
  5. $cidReset = true;
  6. require_once '../inc/global.inc.php';
  7. // including additional libraries
  8. require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
  9. require_once 'myspace.lib.php';
  10. // the section (for the tabs)
  11. $this_section = SECTION_TRACKING;
  12. unset($_SESSION['this_section']);//for hmtl editor repository
  13. ob_start();
  14. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  15. $display = isset($_GET['display']) ? Security::remove_XSS($_GET['display']) : null;
  16. $csv_content = array();
  17. $nameTools = get_lang('MySpace');
  18. $user_id = api_get_user_id();
  19. $is_coach = api_is_coach($_GET['session_id']); // This is used?
  20. $session_id = isset($_GET['session_id']) ? intval($_GET['session_id']) : 0;
  21. $is_platform_admin = api_is_platform_admin();
  22. $is_drh = api_is_drh();
  23. $is_session_admin = api_is_session_admin();
  24. $count_sessions = 0;
  25. $count_courses = 0;
  26. $title = null;
  27. // access control
  28. api_block_anonymous_users();
  29. if (!$export_csv) {
  30. Display :: display_header($nameTools);
  31. } else {
  32. if ($_GET['view'] == 'admin') {
  33. if($display == 'useroverview') {
  34. MySpace::export_tracking_user_overview();
  35. exit;
  36. } else if($display == 'sessionoverview') {
  37. MySpace::export_tracking_session_overview();
  38. exit;
  39. } else if($display == 'courseoverview') {
  40. MySpace::export_tracking_course_overview();
  41. exit;
  42. }
  43. }
  44. }
  45. // Database table definitions
  46. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  47. $tbl_sessions = Database :: get_main_table(TABLE_MAIN_SESSION);
  48. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  49. /* * FUNCTIONS */
  50. function count_coaches() {
  51. global $total_no_coaches;
  52. return $total_no_coaches;
  53. }
  54. function sort_users($a, $b) {
  55. return api_strcmp(trim(api_strtolower($a[$_SESSION['tracking_column']])), trim(api_strtolower($b[$_SESSION['tracking_column']])));
  56. }
  57. function rsort_users($a, $b) {
  58. return api_strcmp(trim(api_strtolower($b[$_SESSION['tracking_column']])), trim(api_strtolower($a[$_SESSION['tracking_column']])));
  59. }
  60. function count_sessions_coached() {
  61. global $count_sessions;
  62. return $count_sessions;
  63. }
  64. function sort_sessions($a, $b) {
  65. global $tracking_column;
  66. if ($a[$tracking_column] > $b[$tracking_column]) {
  67. return 1;
  68. } else {
  69. return -1;
  70. }
  71. }
  72. function rsort_sessions($a, $b) {
  73. global $tracking_column;
  74. if ($b[$tracking_column] > $a[$tracking_column]) {
  75. return 1;
  76. } else {
  77. return -1;
  78. }
  79. }
  80. /* * MAIN CODE */
  81. if ($is_session_admin) {
  82. header('location:session.php');
  83. exit;
  84. }
  85. // Get views
  86. $views = array('admin', 'teacher', 'coach', 'drh');
  87. $view = 'teacher';
  88. if (isset($_GET['view']) && in_array($_GET['view'], $views)) {
  89. $view = $_GET['view'];
  90. }
  91. $menu_items = array();
  92. global $_configuration;
  93. //If is a teacher or admin
  94. if (api_is_allowed_to_create_course() || api_is_drh()) {
  95. }
  96. if ($is_platform_admin) {
  97. if ($view == 'admin') {
  98. $title = get_lang('CoachList');
  99. $menu_items[] = Display::url(Display::return_icon('teacher.png', get_lang('TeacherInterface'), array(), 32), api_get_self().'?view=teacher');
  100. $menu_items[] = Display::url(Display::return_icon('star_na.png', get_lang('AdminInterface'), array(), 32), api_get_self().'?view=admin');
  101. $menu_items[] = Display::url(Display::return_icon('quiz.png', get_lang('ExamTracking'), array(), 32), api_get_path(WEB_CODE_PATH).'tracking/exams.php');
  102. $menu_items[] = Display::url(Display::return_icon('topics.png', get_lang('CurrentCoursesReport'), array(), 32), api_get_path(WEB_CODE_PATH).'mySpace/current_courses.php');
  103. } else {
  104. $menu_items[] = Display::return_icon('teacher_na.png', get_lang('TeacherInterface'), array(), 32);
  105. $menu_items[] = Display::url(Display::return_icon('star.png', get_lang('AdminInterface'), array(), 32), api_get_self().'?view=admin');
  106. $menu_items[] = Display::url(Display::return_icon('quiz.png', get_lang('ExamTracking'), array(), 32), api_get_path(WEB_CODE_PATH).'tracking/exams.php');
  107. $menu_items[] = Display::url(Display::return_icon('topics.png', get_lang('CurrentCoursesReport'), array(), 32), api_get_path(WEB_CODE_PATH).'mySpace/current_courses.php');
  108. }
  109. }
  110. if ($is_drh) {
  111. $view = 'drh';
  112. $menu_items[] = Display::return_icon('user_na.png', get_lang('Students'), array(), 32);
  113. $menu_items[] = Display::url(Display::return_icon('teacher.png', get_lang('Trainers'), array(), 32), 'teachers.php');
  114. $menu_items[] = Display::url(Display::return_icon('course.png', get_lang('Courses'), array(), 32), 'course.php');
  115. $menu_items[] = Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), 32), 'session.php');
  116. }
  117. echo '<div id="actions" class="actions">';
  118. echo '<span style="float:right">';
  119. if ($display == 'useroverview' || $display == 'sessionoverview' || $display == 'courseoverview') {
  120. echo '<a href="'.api_get_self().'?display='.$display.'&export=csv&view='.$view.'">';
  121. echo Display::return_icon("export_csv.png", get_lang('ExportAsCSV'),array(), 32);
  122. echo '</a>';
  123. }
  124. echo '<a href="javascript: void(0);" onclick="javascript: window.print()">'.Display::return_icon('printer.png', get_lang('Print'),'',ICON_SIZE_MEDIUM).'</a>';
  125. echo '</span>';
  126. if (!empty($session_id)) {
  127. echo '<a href="index.php">'.Display::return_icon('back.png', get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  128. } else {
  129. echo Display::url(Display::return_icon('stats.png', get_lang('MyStats'),'',ICON_SIZE_MEDIUM),api_get_path(WEB_CODE_PATH)."auth/my_progress.php" );
  130. }
  131. // Actions menu
  132. $nb_menu_items = count($menu_items);
  133. if (empty($session_id)) {
  134. if ($nb_menu_items > 1) {
  135. foreach ($menu_items as $key => $item) {
  136. echo $item;
  137. }
  138. }
  139. }
  140. echo '</div>';
  141. if (empty($session_id)) {
  142. //Getting courses followed by a coach (No session courses)
  143. $courses = CourseManager::get_course_list_as_coach($user_id, false);
  144. if (isset($courses[0])) {
  145. $courses = $courses[0];
  146. }
  147. //Getting students from courses and courses in sessions (For show the total students that the user follows)
  148. $students = CourseManager::get_user_list_from_courses_as_coach($user_id);
  149. // Sessions for the coach
  150. $sessions = Tracking::get_sessions_coached_by_user($user_id);
  151. //If is drh
  152. if ($is_drh) {
  153. // get data for human resources manager
  154. $students = array_keys(UserManager::get_users_followed_by_drh($user_id, STUDENT));
  155. $courses_of_the_platform = CourseManager :: get_real_course_list();
  156. foreach ($courses_of_the_platform as $course) {
  157. $courses[$course['code']] = $course['code'];
  158. }
  159. }
  160. //Courses for the user
  161. $count_courses = count($courses);
  162. //Sessions for the user
  163. $count_sessions = count($sessions);
  164. //Students
  165. $nb_students = count($students);
  166. $total_time_spent = 0;
  167. $total_courses = 0;
  168. $avg_total_progress = 0;
  169. $avg_results_to_exercises = 0;
  170. $nb_inactive_students = 0;
  171. $nb_posts = $nb_assignments = 0;
  172. if (!empty($students))
  173. foreach ($students as $student_id) {
  174. // inactive students
  175. $last_connection_date = Tracking :: get_last_connection_date($student_id, true, true);
  176. if ($last_connection_date !== false) {
  177. if (time() - (3600 * 24 * 7) > $last_connection_date) {
  178. $nb_inactive_students++;
  179. }
  180. } else {
  181. $nb_inactive_students++;
  182. }
  183. $total_time_spent += Tracking :: get_time_spent_on_the_platform($student_id);
  184. $total_courses += Tracking :: count_course_per_student($student_id);
  185. $avg_student_progress = $avg_student_score = 0;
  186. $nb_courses_student = 0;
  187. foreach ($courses as $course_code) {
  188. if (CourseManager :: is_user_subscribed_in_course($student_id, $course_code, true)) {
  189. $nb_courses_student++;
  190. $nb_posts += Tracking :: count_student_messages($student_id, $course_code);
  191. $nb_assignments += Tracking :: count_student_assignments($student_id, $course_code);
  192. $avg_student_progress += Tracking :: get_avg_student_progress($student_id, $course_code);
  193. $myavg_temp = Tracking :: get_avg_student_score($student_id, $course_code);
  194. if (is_numeric($myavg_temp))
  195. $avg_student_score += $myavg_temp;
  196. if ($nb_posts !== null && $nb_assignments !== null && $avg_student_progress !== null && $avg_student_score !== null) {
  197. //if one of these scores is null, it means that we had a problem connecting to the right database, so don't count it in
  198. $nb_courses_student++;
  199. }
  200. }
  201. }
  202. // average progress of the student
  203. $avg_student_progress = $nb_courses_student ?$avg_student_progress / $nb_courses_student:0;
  204. $avg_total_progress += $avg_student_progress;
  205. // average test results of the student
  206. $avg_student_score = $avg_student_score?$avg_student_score / $nb_courses_student:0;
  207. $avg_results_to_exercises += $avg_student_score;
  208. }
  209. if ($nb_students > 0 && $view != 'admin') {
  210. echo Display::tag('h2', '<img src="'.api_get_path(WEB_IMG_PATH).'students.gif">&nbsp;'.get_lang('Students').' ('.$nb_students.')');
  211. // average progress
  212. $avg_total_progress = $avg_total_progress / $nb_students;
  213. // average results to the tests
  214. $avg_results_to_exercises = $avg_results_to_exercises / $nb_students;
  215. // average courses by student
  216. $avg_courses_per_student = round($total_courses / $nb_students, 2);
  217. // average time spent on the platform
  218. $avg_time_spent = $total_time_spent / $nb_students;
  219. // average assignments
  220. $nb_assignments = $nb_assignments / $nb_students;
  221. // average posts
  222. $nb_posts = $nb_posts / $nb_students;
  223. if ($export_csv) {
  224. //csv part
  225. $csv_content[] = array(get_lang('Students', ''));
  226. $csv_content[] = array(get_lang('InactivesStudents', ''), $nb_inactive_students );
  227. $csv_content[] = array(get_lang('AverageTimeSpentOnThePlatform', ''), $avg_time_spent);
  228. $csv_content[] = array(get_lang('AverageCoursePerStudent', ''), $avg_courses_per_student);
  229. $csv_content[] = array(get_lang('AverageProgressInLearnpath', ''), is_null($avg_total_progress) ? null : round($avg_total_progress, 2).'%');
  230. $csv_content[] = array(get_lang('AverageResultsToTheExercices', ''), is_null($avg_results_to_exercises) ? null : round($avg_results_to_exercises, 2).'%');
  231. $csv_content[] = array(get_lang('AveragePostsInForum', ''), $nb_posts);
  232. $csv_content[] = array(get_lang('AverageAssignments', ''), $nb_assignments);
  233. $csv_content[] = array();
  234. } else {
  235. // html part
  236. echo '
  237. <div class="report_section">
  238. <table class="data_table">
  239. <tr>
  240. <td>'.get_lang('InactivesStudents').'</td>
  241. <td align="right">'.$nb_inactive_students.'</td>
  242. </tr>
  243. <tr>
  244. <td>'.get_lang('AverageTimeSpentOnThePlatform').'</td>
  245. <td align="right">'.(is_null($avg_time_spent) ? '' : api_time_to_hms($avg_time_spent)).'</td>
  246. </tr>
  247. <tr>
  248. <td>'.get_lang('AverageCoursePerStudent').'</td>
  249. <td align="right">'.(is_null($avg_courses_per_student) ? '' : $avg_courses_per_student).'</td>
  250. </tr>
  251. <tr>
  252. <td>'.get_lang('AverageProgressInLearnpath').'</td>
  253. <td align="right">'.(is_null($avg_total_progress) ? '' : round($avg_total_progress, 2).'%').'</td>
  254. </tr>
  255. <tr>
  256. <td>'.get_lang('AverageResultsToTheExercices').'</td>
  257. <td align="right">'.(is_null($avg_results_to_exercises) ? '' : round($avg_results_to_exercises, 2).'%').'</td>
  258. </tr>
  259. <tr>
  260. <td>'.get_lang('AveragePostsInForum').'</td>
  261. <td align="right">'.(is_null($nb_posts) ? '' : round($nb_posts, 2)).'</td>
  262. </tr>
  263. <tr>
  264. <td>'.get_lang('AverageAssignments').'</td>
  265. <td align="right">'.(is_null($nb_assignments) ? '' : round($nb_assignments, 2)).'</td>
  266. </tr>
  267. </table>
  268. <a href="student.php">'.get_lang('SeeStudentList').'</a>
  269. </div><br />';
  270. }
  271. } else {
  272. $avg_total_progress = null;
  273. $avg_results_to_exercises = null;
  274. $avg_courses_per_student = null;
  275. $avg_time_spent = null;
  276. $nb_assignments = null;
  277. $nb_posts = null;
  278. }
  279. } else {
  280. $courses = Tracking::get_courses_followed_by_coach($user_id, $session_id);
  281. //Courses for the user
  282. $count_courses = count($courses);
  283. }
  284. if ($count_courses || $count_sessions) {
  285. //If we are in course
  286. if (empty($session_id)) {
  287. if ($count_courses) {
  288. $title = '<img src="'.api_get_path(WEB_IMG_PATH).'course.gif"> '.get_lang('Courses').' ('.$count_courses.') ';
  289. }
  290. } else {
  291. //If we are in Course Session
  292. $session_name = api_get_session_name($session_id);
  293. $title = Display::return_icon('session.png', get_lang('Session'), array(), ICON_SIZE_SMALL).' '.$session_name;
  294. $menu_items[] = '<a href="'.api_get_self().'?view=teacher">'.get_lang('TeacherInterface').'</a>';
  295. }
  296. }
  297. if (api_is_allowed_to_create_course() && $view == 'teacher') {
  298. //Courses
  299. if ($count_courses) {
  300. echo Display::tag('h2', $title);
  301. $table = new SortableTable('courses_my_space', 'get_number_of_courses', array('MySpace','get_course_data'));
  302. $parameters['view'] = 'teacher';
  303. $parameters['class'] = 'data_table';
  304. $table->set_additional_parameters($parameters);
  305. $table -> set_header(0, get_lang('CourseTitle'), false, 'align="center"');
  306. $table -> set_header(1, get_lang('NbStudents'), false);
  307. $table -> set_header(2, get_lang('AvgTimeSpentInTheCourse').' '.Display :: return_icon('info3.gif', get_lang('TimeOfActiveByTraining'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
  308. $table -> set_header(3, get_lang('AvgStudentsProgress').' '.Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
  309. $table -> set_header(4, get_lang('AvgCourseScore').' '.Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
  310. $table -> set_header(5, get_lang('AvgExercisesScore').' '.Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
  311. $table -> set_header(6, get_lang('AvgMessages'), false);
  312. $table -> set_header(7, get_lang('AvgAssignments'), false);
  313. $table -> set_header(8, get_lang('Details'), false);
  314. $csv_content[] = array (
  315. get_lang('CourseTitle', ''),
  316. get_lang('NbStudents', ''),
  317. get_lang('AvgTimeSpentInTheCourse', ''),
  318. get_lang('AvgStudentsProgress', ''),
  319. get_lang('AvgCourseScore', ''),
  320. get_lang('AvgExercisesScore', ''),
  321. get_lang('AvgMessages', ''),
  322. get_lang('AvgAssignments', '')
  323. );
  324. $table->display();
  325. }
  326. // Display list of sessions
  327. if ($count_sessions > 0 && !isset($_GET['session_id'])) {
  328. echo '<h2><img src="'.api_get_path(WEB_IMG_PATH).'session.png">&nbsp;'.get_lang('Sessions').' ('.$count_sessions.')'.'</h2>';
  329. $table = new SortableTable('tracking_sessions_myspace', 'count_sessions_coached');
  330. $table->set_header(0, get_lang('Title'), false);
  331. $table->set_header(1, get_lang('Date'), false);
  332. $table->set_header(2, get_lang('NbCoursesPerSession'), false);
  333. $table->set_header(3, get_lang('Details'), false);
  334. $all_data = array();
  335. foreach ($sessions as $session) {
  336. $count_courses_in_session = count(Tracking::get_courses_followed_by_coach($user_id, $session['id']));
  337. $row = array();
  338. $row[] = $session['name'];
  339. if ($session['date_start'] != '0000-00-00' && $session['date_end'] != '0000-00-00') {
  340. $row[] = get_lang('From').' '.api_format_date($session['date_start'], DATE_FORMAT_SHORT).' '.get_lang('Until').' '.api_format_date($session['date_end'], DATE_FORMAT_SHORT);
  341. } else {
  342. $row[] = ' - ';
  343. }
  344. $row[] = $count_courses_in_session;
  345. $row[] = '<a href="'.api_get_self().'?session_id='.$session['id'].'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  346. $all_data[] = $row;
  347. }
  348. if (!isset($tracking_column)) {
  349. $tracking_column = 0;
  350. }
  351. if (isset($_GET['tracking_direction']) && $_GET['tracking_direction'] == 'DESC') {
  352. usort($all_data, 'rsort_sessions');
  353. } else {
  354. usort($all_data, 'sort_sessions');
  355. }
  356. if ($export_csv) {
  357. usort($csv_content, 'sort_sessions');
  358. }
  359. foreach ($all_data as $row) {
  360. $table -> addRow($row);
  361. }
  362. $table -> setColAttributes(1, array('align' => 'center'));
  363. $table -> setColAttributes(2, array('align' => 'center'));
  364. $table -> setColAttributes(3, array('align' => 'center'));
  365. /* Start session over view stats */
  366. $nb_sessions_past = $nb_sessions_future = $nb_sessions_current = 0;
  367. $courses = array();
  368. foreach ($sessions as $session) {
  369. if ($session['date_start'] == '0000-00-00') {
  370. $nb_sessions_current ++;
  371. } else {
  372. $date_start = explode('-', $session['date_start']);
  373. $time_start = mktime(0, 0, 0, $date_start[1], $date_start[2], $date_start[0]);
  374. $date_end = explode('-', $session['date_end']);
  375. $time_end = mktime(0, 0, 0, $date_end[1], $date_end[2], $date_end[0]);
  376. if ($time_start < time() && time() < $time_end) {
  377. $nb_sessions_current++;
  378. } elseif (time() < $time_start) {
  379. $nb_sessions_future++;
  380. } elseif (time() > $time_end) {
  381. $nb_sessions_past++;
  382. }
  383. }
  384. $courses = array_merge($courses, Tracking::get_courses_list_from_session($session['id']));
  385. }
  386. if ($nb_sessions > 0) {
  387. $nb_courses_per_session = round(count($courses) / $nb_sessions, 2);
  388. $nb_students_per_session = round($nb_students / $nb_sessions, 2);
  389. } else {
  390. $nb_courses_per_session = null;
  391. $nb_students_per_session = null;
  392. }
  393. if ($export_csv) {
  394. //csv part
  395. $csv_content[] = array(get_lang('Sessions', ''));
  396. $csv_content[] = array(get_lang('NbActiveSessions', '').';'.$nb_sessions_current);
  397. $csv_content[] = array(get_lang('NbPastSessions', '').';'.$nb_sessions_past);
  398. $csv_content[] = array(get_lang('NbFutureSessions', '').';'.$nb_sessions_future);
  399. $csv_content[] = array(get_lang('NbStudentPerSession', '').';'.$nb_students_per_session);
  400. $csv_content[] = array(get_lang('NbCoursesPerSession', '').';'.$nb_courses_per_session);
  401. $csv_content[] = array();
  402. } else {
  403. // html part
  404. echo '
  405. <div class="report_section">
  406. <table class="data_table">
  407. <tr>
  408. <td>'.get_lang('NbActiveSessions').'</td>
  409. <td align="right">'.$nb_sessions_current.'</td>
  410. </tr>
  411. <tr>
  412. <td>'.get_lang('NbPastSessions').'</td>
  413. <td align="right">'.$nb_sessions_past.'</td>
  414. </tr>
  415. <tr>
  416. <td>'.get_lang('NbFutureSessions').'</td>
  417. <td align="right">'.$nb_sessions_future.'</td>
  418. </tr>
  419. <tr>
  420. <td>'.get_lang('NbStudentPerSession').'</td>
  421. <td align="right">'.(is_null($nb_students_per_session) ? '' : $nb_students_per_session).'</td>
  422. </tr>
  423. <tr>
  424. <td>'.get_lang('NbCoursesPerSession').'</td>
  425. <td align="right">'.(is_null($nb_courses_per_session) ? '' : $nb_courses_per_session).'</td>
  426. </tr>
  427. </table>
  428. </div>';
  429. }
  430. /* End session overview */
  431. $table -> display();
  432. }
  433. }
  434. if ($is_platform_admin && $view == 'admin' && $display != 'yourstudents') {
  435. echo '<a href="'.api_get_self().'?view=admin&amp;display=coaches">'.get_lang('DisplayCoaches').'</a> | ';
  436. echo '<a href="'.api_get_self().'?view=admin&amp;display=useroverview">'.get_lang('DisplayUserOverview').'</a>';
  437. if ($display == 'useroverview') {
  438. echo ' ( <a href="'.api_get_self().'?view=admin&amp;display=useroverview&amp;export=options">'.get_lang('ExportUserOverviewOptions').'</a> )';
  439. }
  440. echo ' | <a href="'.api_get_self().'?view=admin&amp;display=sessionoverview">'.get_lang('DisplaySessionOverview').'</a>';
  441. echo ' | <a href="'.api_get_self().'?view=admin&amp;display=courseoverview">'.get_lang('DisplayCourseOverview').'</a>';
  442. echo ' | <a href="'.api_get_path(WEB_CODE_PATH).'tracking/question_course_report.php?view=admin">'.get_lang('LPQuestionListResults').'</a>';
  443. echo ' | <a href="'.api_get_path(WEB_CODE_PATH).'tracking/course_session_report.php?view=admin">'.get_lang('LPExerciseResultsBySession').'</a>';
  444. echo '<br /><br />';
  445. if ($display === 'useroverview') {
  446. MySpace::display_tracking_user_overview();
  447. } else if($display == 'sessionoverview') {
  448. MySpace::display_tracking_session_overview();
  449. } else if($display == 'courseoverview') {
  450. MySpace::display_tracking_course_overview();
  451. } else {
  452. if ($export_csv) {
  453. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  454. } else {
  455. $is_western_name_order = api_is_western_name_order();
  456. }
  457. $sort_by_first_name = api_sort_by_first_name();
  458. $tracking_column = isset($_GET['tracking_list_coaches_column']) ? $_GET['tracking_list_coaches_column'] : ($is_western_name_order xor $sort_by_first_name) ? 1 : 0;
  459. $tracking_direction = (isset($_GET['tracking_list_coaches_direction']) && in_array(strtoupper($_GET['tracking_list_coaches_direction']), array('ASC', 'DESC', 'ASCENDING', 'DESCENDING', '0', '1'))) ? $_GET['tracking_list_coaches_direction'] : 'DESC';
  460. // Prepare array for column order - when impossible, use some of user names.
  461. if ($is_western_name_order) {
  462. $order = array(0 => 'firstname', 1 => 'lastname', 2 => ($sort_by_first_name ? 'firstname' : 'lastname'), 3 => 'login_date', 4 => ($sort_by_first_name ? 'firstname' : 'lastname'), 5 => ($sort_by_first_name ? 'firstname' : 'lastname'));
  463. } else {
  464. $order = array(0 => 'lastname', 1 => 'firstname', 2 => ($sort_by_first_name ? 'firstname' : 'lastname'), 3 => 'login_date', 4 => ($sort_by_first_name ? 'firstname' : 'lastname'), 5 => ($sort_by_first_name ? 'firstname' : 'lastname'));
  465. }
  466. $table = new SortableTable('tracking_list_coaches_myspace', 'count_coaches', null, ($is_western_name_order xor $sort_by_first_name) ? 1 : 0);
  467. $parameters['view'] = 'admin';
  468. $table->set_additional_parameters($parameters);
  469. if ($is_western_name_order) {
  470. $table -> set_header(0, get_lang('FirstName'), true, 'align="center"');
  471. $table -> set_header(1, get_lang('LastName'), true, 'align="center"');
  472. } else {
  473. $table -> set_header(0, get_lang('LastName'), true, 'align="center"');
  474. $table -> set_header(1, get_lang('FirstName'), true, 'align="center"');
  475. }
  476. $table -> set_header(2, get_lang('TimeSpentOnThePlatform'), false);
  477. $table -> set_header(3, get_lang('LastConnexion'), false, 'align="center"');
  478. $table -> set_header(4, get_lang('NbStudents'), false);
  479. $table -> set_header(5, get_lang('CountCours'), false);
  480. $table -> set_header(6, get_lang('NumberOfSessions'), false);
  481. $table -> set_header(7, get_lang('Sessions'), false, 'align="center"');
  482. if ($is_western_name_order) {
  483. $csv_header[] = array (
  484. get_lang('FirstName', ''),
  485. get_lang('LastName', ''),
  486. get_lang('TimeSpentOnThePlatform', ''),
  487. get_lang('LastConnexion', ''),
  488. get_lang('NbStudents', ''),
  489. get_lang('CountCours', ''),
  490. get_lang('NumberOfSessions', '')
  491. );
  492. } else {
  493. $csv_header[] = array (
  494. get_lang('LastName', ''),
  495. get_lang('FirstName', ''),
  496. get_lang('TimeSpentOnThePlatform', ''),
  497. get_lang('LastConnexion', ''),
  498. get_lang('NbStudents', ''),
  499. get_lang('CountCours', ''),
  500. get_lang('NumberOfSessions', '')
  501. );
  502. }
  503. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  504. $sqlCoachs = "SELECT DISTINCT scu.id_user as id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
  505. FROM $tbl_user, $tbl_session_course_user scu, $tbl_track_login
  506. WHERE scu.id_user=user_id AND scu.status=2 AND login_user_id=user_id
  507. GROUP BY user_id ";
  508. if ($_configuration['multiple_access_urls']) {
  509. $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  510. $access_url_id = api_get_current_access_url_id();
  511. if ($access_url_id != -1) {
  512. $sqlCoachs = "SELECT DISTINCT scu.id_user as id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
  513. FROM $tbl_user, $tbl_session_course_user scu, $tbl_track_login , $tbl_session_rel_access_url session_rel_url
  514. WHERE scu.id_user=user_id AND scu.status=2 AND login_user_id=user_id AND access_url_id = $access_url_id AND session_rel_url.session_id=id_session
  515. GROUP BY user_id ";
  516. }
  517. }
  518. if (!empty($order[$tracking_column])) {
  519. $sqlCoachs .= "ORDER BY ".$order[$tracking_column]." ".$tracking_direction;
  520. }
  521. $result_coaches = Database::query($sqlCoachs);
  522. $total_no_coaches = Database::num_rows($result_coaches);
  523. $global_coaches = array();
  524. while ($coach = Database::fetch_array($result_coaches)) {
  525. $global_coaches[$coach['user_id']] = $coach;
  526. }
  527. $sql_session_coach = 'SELECT session.id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
  528. FROM '.$tbl_user.','.$tbl_sessions.' as session,'.$tbl_track_login.'
  529. WHERE id_coach=user_id AND login_user_id=user_id
  530. GROUP BY user_id
  531. ORDER BY login_date '.$tracking_direction;
  532. if ($_configuration['multiple_access_urls']) {
  533. $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  534. $access_url_id = api_get_current_access_url_id();
  535. if ($access_url_id != -1) {
  536. $sql_session_coach = 'SELECT session.id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
  537. FROM '.$tbl_user.','.$tbl_sessions.' as session,'.$tbl_track_login.' , '.$tbl_session_rel_access_url.' as session_rel_url
  538. WHERE id_coach=user_id AND login_user_id=user_id AND access_url_id = '.$access_url_id.' AND session_rel_url.session_id=session.id
  539. GROUP BY user_id
  540. ORDER BY login_date '.$tracking_direction;
  541. }
  542. }
  543. $result_sessions_coach = Database::query($sql_session_coach);
  544. $total_no_coaches += Database::num_rows($result_sessions_coach);
  545. while ($coach = Database::fetch_array($result_sessions_coach)) {
  546. $global_coaches[$coach['user_id']] = $coach;
  547. }
  548. $all_datas = array();
  549. foreach ($global_coaches as $id_coach => $coaches) {
  550. $time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($coaches['user_id']));
  551. $last_connection = Tracking :: get_last_connection_date($coaches['user_id']);
  552. $nb_students = count(Tracking :: get_student_followed_by_coach($coaches['user_id']));
  553. $nb_courses = count(Tracking :: get_courses_followed_by_coach($coaches['user_id']));
  554. $nb_sessions = count(Tracking :: get_sessions_coached_by_user($coaches['user_id']));
  555. $table_row = array();
  556. if ($is_western_name_order) {
  557. $table_row[] = $coaches['firstname'];
  558. $table_row[] = $coaches['lastname'];
  559. } else {
  560. $table_row[] = $coaches['lastname'];
  561. $table_row[] = $coaches['firstname'];
  562. }
  563. $table_row[] = $time_on_platform;
  564. $table_row[] = $last_connection;
  565. $table_row[] = $nb_students;
  566. $table_row[] = $nb_courses;
  567. $table_row[] = $nb_sessions;
  568. $table_row[] = '<center><a href="session.php?id_coach='.$coaches['user_id'].'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></center>';
  569. $all_datas[] = $table_row;
  570. if ($is_western_name_order) {
  571. $csv_content[] = array(
  572. api_html_entity_decode($coaches['firstname'], ENT_QUOTES, $charset),
  573. api_html_entity_decode($coaches['lastname'], ENT_QUOTES, $charset),
  574. $time_on_platform,
  575. $last_connection,
  576. $nb_students,
  577. $nb_courses,
  578. $nb_sessions
  579. );
  580. } else {
  581. $csv_content[] = array(
  582. api_html_entity_decode($coaches['lastname'], ENT_QUOTES, $charset),
  583. api_html_entity_decode($coaches['firstname'], ENT_QUOTES, $charset),
  584. $time_on_platform,
  585. $last_connection,
  586. $nb_students,
  587. $nb_courses,
  588. $nb_sessions
  589. );
  590. }
  591. }
  592. if ($tracking_column != 3) {
  593. if ($tracking_direction == 'DESC') {
  594. usort($all_datas, 'rsort_users');
  595. } else {
  596. usort($all_datas, 'sort_users');
  597. }
  598. }
  599. if ($export_csv && $tracking_column != 3) {
  600. usort($csv_content, 'sort_users');
  601. }
  602. if ($export_csv) {
  603. $csv_content = array_merge($csv_header, $csv_content);
  604. }
  605. foreach ($all_datas as $row) {
  606. $table -> addRow($row, 'align="right"');
  607. }
  608. $table -> updateColAttributes(0, array('align' => 'left'));
  609. $table -> updateColAttributes(1, array('align' => 'left'));
  610. $table -> updateColAttributes(3, array('align' => 'left'));
  611. $table -> updateColAttributes(7, array('align' => 'center'));
  612. $table -> display();
  613. }
  614. }
  615. // send the csv file if asked
  616. if ($export_csv) {
  617. ob_end_clean();
  618. Export :: export_table_csv($csv_content, 'reporting_index');
  619. exit;
  620. }
  621. //footer
  622. if (!$export_csv) {
  623. Display::display_footer();
  624. }
  625. /**
  626. * Get number of courses for sortable with pagination
  627. * @return int
  628. */
  629. function get_number_of_courses() {
  630. global $courses;
  631. return count($courses);
  632. }