index.php 29 KB

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