index.php 29 KB

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