index.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  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).'sortabletable.class.php';
  9. require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
  10. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  11. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  12. require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
  13. require_once 'myspace.lib.php';
  14. // the section (for the tabs)
  15. $this_section = SECTION_TRACKING;
  16. unset($_SESSION['this_section']);//for hmtl editor repository
  17. ob_start();
  18. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  19. $csv_content = array();
  20. $nameTools = get_lang('MySpace');
  21. $user_id = api_get_user_id();
  22. $nb_sessions = 0;
  23. // access control
  24. api_block_anonymous_users();
  25. if (!$export_csv) {
  26. Display :: display_header($nameTools);
  27. } else {
  28. if ($_GET['view'] == 'admin') {
  29. if($_GET['display'] == 'useroverview') {
  30. MySpace::export_tracking_user_overview();
  31. exit;
  32. } else if($_GET['display'] == 'sessionoverview') {
  33. MySpace::export_tracking_session_overview();
  34. exit;
  35. } else if($_GET['display'] == 'courseoverview') {
  36. MySpace::export_tracking_course_overview();
  37. exit;
  38. }
  39. }
  40. }
  41. // Database table definitions
  42. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  43. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  44. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  45. $tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
  46. $tbl_sessions = Database :: get_main_table(TABLE_MAIN_SESSION);
  47. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  48. $tbl_session_user = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
  49. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  50. $tbl_admin = Database :: get_main_table(TABLE_MAIN_ADMIN);
  51. $tbl_track_cours_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  52. /* * FUNCTIONS */
  53. /*
  54. function count_teacher_courses() {
  55. global $nb_teacher_courses;
  56. return $nb_teacher_courses;
  57. }*/
  58. function count_coaches() {
  59. global $total_no_coaches;
  60. return $total_no_coaches;
  61. }
  62. function sort_users($a, $b) {
  63. return api_strcmp(trim(api_strtolower($a[$_SESSION['tracking_column']])), trim(api_strtolower($b[$_SESSION['tracking_column']])));
  64. }
  65. function rsort_users($a, $b) {
  66. return api_strcmp(trim(api_strtolower($b[$_SESSION['tracking_column']])), trim(api_strtolower($a[$_SESSION['tracking_column']])));
  67. }
  68. function count_sessions_coached() {
  69. global $nb_sessions;
  70. return $nb_sessions;
  71. }
  72. function sort_sessions($a, $b) {
  73. global $tracking_column;
  74. if ($a[$tracking_column] > $b[$tracking_column]) {
  75. return 1;
  76. } else {
  77. return -1;
  78. }
  79. }
  80. function rsort_sessions($a, $b) {
  81. global $tracking_column;
  82. if ($b[$tracking_column] > $a[$tracking_column]) {
  83. return 1;
  84. } else {
  85. return -1;
  86. }
  87. }
  88. /* * MAIN CODE */
  89. $is_coach = api_is_coach();
  90. $is_platform_admin = api_is_platform_admin();
  91. $is_drh = api_is_drh();
  92. $is_session_admin = api_is_session_admin();
  93. if ($is_session_admin) {
  94. header('location:session.php');
  95. exit;
  96. }
  97. // Get views
  98. $views = array('admin', 'teacher', 'coach', 'drh');
  99. $view = 'teacher';
  100. if (isset($_GET['view']) && in_array($_GET['view'], $views)) {
  101. $view = $_GET['view'];
  102. }
  103. $menu_items = array();
  104. $nb_teacher_courses = 0;
  105. $title = null;
  106. global $_configuration;
  107. // interbreadcrumbs
  108. // && isset($_GET['display']) && $_GET['display'] != 'yourstudents'
  109. if (api_is_allowed_to_create_course()) {
  110. $session_id = isset($_GET['session_id']) ? intval($_GET['session_id']): 0;
  111. if (!empty($session_id)) {
  112. $courses = Tracking::get_courses_followed_by_coach($user_id, $session_id);
  113. } else {
  114. $courses = CourseManager::get_course_list_of_user_as_course_admin($user_id);
  115. }
  116. $nb_teacher_courses = count($courses);
  117. $sessions = Tracking::get_sessions_coached_by_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 && isset($_GET['display']) && $_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 || (isset($_GET['display']) && $_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. if (!empty($session_id)) {
  178. echo '<a href="javascript: window.back();" ">'.Display::return_icon('back.png', get_lang('Back'),'','32').'</a>';
  179. }
  180. echo Display::url(Display::return_icon('stats.png', get_lang('MyStats'),'',32),api_get_path(WEB_CODE_PATH)."auth/my_progress.php" );
  181. //echo Display::url(Display::return_icon('printer.png', get_lang('Print'),'',32),"javascript: void(0);", array('onclick'=>'window.print();'));
  182. echo '<a href="javascript: void(0);" onclick="javascript: window.print()">'. Display::return_icon('printer.png', get_lang('Print'),'','32').'</a>';
  183. if (empty($session_id)) {
  184. if ($nb_menu_items > 1) {
  185. foreach ($menu_items as $key => $item) {
  186. echo $item;
  187. if ($key != $nb_menu_items - 1) {
  188. echo '&nbsp;|&nbsp;';
  189. }
  190. }
  191. }
  192. } else {
  193. //
  194. }
  195. echo '</div>';
  196. } else {
  197. echo '<div id="actions" class="actions">';
  198. echo '<a href="'.api_get_path(WEB_CODE_PATH).'auth/my_progress.php">'.Display::return_icon('stats.png', get_lang('MyStats'),'','32').'</a>';//
  199. echo '</div>';
  200. //Display::display_warning_message(get_lang('HaveNoCourse'));
  201. }
  202. echo Display::tag('h2', $title);
  203. if (($is_drh && $view == 'drh') || (isset($_GET['display']) && $_GET['display'] == 'yourstudents')) {
  204. // get data for human resources manager
  205. $students = array_keys(UserManager::get_users_followed_by_drh($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_id);
  213. $courses = Tracking::get_courses_followed_by_coach($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_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. } elseif (time() < $time_start) {
  380. $nb_sessions_future++;
  381. } elseif (time() > $time_end) {
  382. $nb_sessions_past++;
  383. }
  384. }
  385. $courses = array_merge($courses, Tracking::get_courses_list_from_session($session['id']));
  386. }
  387. if ($nb_sessions > 0) {
  388. $nb_courses_per_session = round(count($courses) / $nb_sessions, 2);
  389. $nb_students_per_session = round($nb_students / $nb_sessions, 2);
  390. } else {
  391. $nb_courses_per_session = null;
  392. $nb_students_per_session = null;
  393. }
  394. if ($export_csv) {
  395. //csv part
  396. $csv_content[] = array(get_lang('Sessions', ''));
  397. $csv_content[] = array(get_lang('NbActiveSessions', '').';'.$nb_sessions_current);
  398. $csv_content[] = array(get_lang('NbPastSessions', '').';'.$nb_sessions_past);
  399. $csv_content[] = array(get_lang('NbFutureSessions', '').';'.$nb_sessions_future);
  400. $csv_content[] = array(get_lang('NbStudentPerSession', '').';'.$nb_students_per_session);
  401. $csv_content[] = array(get_lang('NbCoursesPerSession', '').';'.$nb_courses_per_session);
  402. $csv_content[] = array();
  403. } else {
  404. // html part
  405. echo '
  406. <div class="report_section">
  407. <h4>
  408. <a href="session.php"><img src="'.api_get_path(WEB_IMG_PATH).'sessions.gif">&nbsp;'.get_lang('Sessions').' ('.$nb_sessions.')'.'</a>
  409. </h4>
  410. <table class="data_table">
  411. <tr>
  412. <td>
  413. '.get_lang('NbActiveSessions').'
  414. </td>
  415. <td align="right">
  416. '.$nb_sessions_current.'
  417. </td>
  418. </tr>
  419. <tr>
  420. <td>
  421. '.get_lang('NbPastSessions').'
  422. </td>
  423. <td align="right">
  424. '.$nb_sessions_past.'
  425. </td>
  426. </tr>
  427. <tr>
  428. <td>
  429. '.get_lang('NbFutureSessions').'
  430. </td>
  431. <td align="right">
  432. '.$nb_sessions_future.'
  433. </td>
  434. </tr>
  435. <tr>
  436. <td>
  437. '.get_lang('NbStudentPerSession').'
  438. </td>
  439. <td align="right">
  440. '.(is_null($nb_students_per_session) ? '' : $nb_students_per_session).'
  441. </td>
  442. </tr>
  443. <tr>
  444. <td>
  445. '.get_lang('NbCoursesPerSession').'
  446. </td>
  447. <td align="right">
  448. '.(is_null($nb_courses_per_session) ? '' : $nb_courses_per_session).'
  449. </td>
  450. </tr>
  451. </table>
  452. <a href="session.php">'.get_lang('SeeSessionList').'</a>
  453. </div>';
  454. }
  455. }
  456. echo '<div class="clear">&nbsp;</div>';
  457. if (api_is_allowed_to_create_course() && $view == 'teacher') {
  458. if ($nb_teacher_courses) {
  459. //Courses table
  460. $table = new SortableTable('courses', 'get_number_of_courses' ,array('MySpace','get_course_data'));
  461. $parameters['view'] = 'teacher';
  462. $parameters['class'] = 'data_table';
  463. $table->set_additional_parameters($parameters);
  464. $table -> set_header(0, get_lang('CourseTitle'), false, 'align="center"');
  465. $table -> set_header(1, get_lang('NbStudents'), false);
  466. $table -> set_header(2, get_lang('AvgTimeSpentInTheCourse').Display :: return_icon('info3.gif', get_lang('TimeOfActiveByTraining'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
  467. $table -> set_header(3, get_lang('AvgStudentsProgress').Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
  468. $table -> set_header(4, get_lang('AvgCourseScore').Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
  469. $table -> set_header(5, get_lang('AvgExercisesScore').Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
  470. $table -> set_header(6, get_lang('AvgMessages'), false);
  471. $table -> set_header(7, get_lang('AvgAssignments'), false);
  472. $table -> set_header(8, get_lang('Details'), false);
  473. $csv_content[] = array (
  474. get_lang('CourseTitle', ''),
  475. get_lang('NbStudents', ''),
  476. get_lang('AvgTimeSpentInTheCourse', ''),
  477. get_lang('AvgStudentsProgress', ''),
  478. get_lang('AvgCourseScore', ''),
  479. get_lang('AvgExercisesScore', ''),
  480. get_lang('AvgMessages', ''),
  481. get_lang('AvgAssignments', '')
  482. );
  483. $table->display();
  484. }
  485. // Display sessions
  486. if ($nb_sessions > 0 && !isset($_GET['session_id'])) {
  487. echo '<h2>'.get_lang('Sessions').'</h2>';
  488. $table = new SortableTable('tracking_sessions', 'count_sessions_coached');
  489. $table->set_header(0, get_lang('Title'), false);
  490. $table->set_header(1, get_lang('Date'), false);
  491. $table->set_header(2, get_lang('NbCoursesPerSession'), false);
  492. $table->set_header(3, get_lang('Details'), false);
  493. $all_data = array();
  494. foreach ($sessions as $session) {
  495. $count_courses_in_session = count(Tracking::get_courses_followed_by_coach($user_id, $session['id']));
  496. $row = array();
  497. $row[] = $session['name'];
  498. if ($session['date_start'] != '0000-00-00' && $session['date_end'] != '0000-00-00') {
  499. $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());
  500. } else {
  501. $row[] = ' - ';
  502. }
  503. $row[] = $count_courses_in_session;
  504. $row[] = '<a href="'.api_get_self().'?session_id='.$session['id'].'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  505. $all_data[] = $row;
  506. }
  507. if (!isset($tracking_column)) {
  508. $tracking_column = 0;
  509. }
  510. if (isset($_GET['tracking_direction']) && $_GET['tracking_direction'] == 'DESC') {
  511. usort($all_data, 'rsort_sessions');
  512. } else {
  513. usort($all_data, 'sort_sessions');
  514. }
  515. if ($export_csv) {
  516. usort($csv_content, 'sort_sessions');
  517. }
  518. foreach ($all_data as $row) {
  519. $table -> addRow($row);
  520. }
  521. $table -> setColAttributes(1, array('align' => 'center'));
  522. $table -> setColAttributes(2, array('align' => 'center'));
  523. $table -> setColAttributes(3, array('align' => 'center'));
  524. $table -> display();
  525. }
  526. }
  527. if ($is_platform_admin && $view == 'admin' && $_GET['display'] != 'yourstudents') {
  528. echo '<a href="'.api_get_self().'?view=admin&amp;display=coaches">'.get_lang('DisplayCoaches').'</a> | ';
  529. echo '<a href="'.api_get_self().'?view=admin&amp;display=useroverview">'.get_lang('DisplayUserOverview').'</a>';
  530. if ($_GET['display'] == 'useroverview') {
  531. echo ' | <a href="'.api_get_self().'?view=admin&amp;display=useroverview&amp;export=options">'.get_lang('ExportUserOverviewOptions').'</a>';
  532. }
  533. echo ' | <a href="'.api_get_self().'?view=admin&amp;display=sessionoverview">'.get_lang('DisplaySessionOverview').'</a>';
  534. echo ' | <a href="'.api_get_self().'?view=admin&amp;display=courseoverview">'.get_lang('DisplayCourseOverview').'</a>';
  535. echo ' | <a href="'.api_get_path(WEB_CODE_PATH).'tracking/question_course_report.php?view=admin">'.get_lang('LPQuestionListResults').'</a>';
  536. echo ' | <a href="'.api_get_path(WEB_CODE_PATH).'tracking/course_session_report.php?view=admin">'.get_lang('LPExerciseResultsBySession').'</a>';
  537. echo '<br /><br />';
  538. if ($_GET['display'] === 'useroverview') {
  539. MySpace::display_tracking_user_overview();
  540. } else if($_GET['display'] == 'sessionoverview') {
  541. MySpace::display_tracking_session_overview();
  542. } else if($_GET['display'] == 'courseoverview') {
  543. MySpace::display_tracking_course_overview();
  544. } else {
  545. if ($export_csv) {
  546. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  547. } else {
  548. $is_western_name_order = api_is_western_name_order();
  549. }
  550. $sort_by_first_name = api_sort_by_first_name();
  551. $tracking_column = isset($_GET['tracking_list_coaches_column']) ? $_GET['tracking_list_coaches_column'] : ($is_western_name_order xor $sort_by_first_name) ? 1 : 0;
  552. $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';
  553. // Prepare array for column order - when impossible, use some of user names.
  554. if ($is_western_name_order) {
  555. $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'));
  556. } else {
  557. $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'));
  558. }
  559. $table = new SortableTable('tracking_list_coaches', 'count_coaches', null, ($is_western_name_order xor $sort_by_first_name) ? 1 : 0);
  560. $parameters['view'] = 'admin';
  561. $table->set_additional_parameters($parameters);
  562. if ($is_western_name_order) {
  563. $table -> set_header(0, get_lang('FirstName'), true, 'align="center"');
  564. $table -> set_header(1, get_lang('LastName'), true, 'align="center"');
  565. } else {
  566. $table -> set_header(0, get_lang('LastName'), true, 'align="center"');
  567. $table -> set_header(1, get_lang('FirstName'), true, 'align="center"');
  568. }
  569. $table -> set_header(2, get_lang('TimeSpentOnThePlatform'), false);
  570. $table -> set_header(3, get_lang('LastConnexion'), false, 'align="center"');
  571. $table -> set_header(4, get_lang('NbStudents'), false);
  572. $table -> set_header(5, get_lang('CountCours'), false);
  573. $table -> set_header(6, get_lang('NumberOfSessions'), false);
  574. $table -> set_header(7, get_lang('Sessions'), false, 'align="center"');
  575. if ($is_western_name_order) {
  576. $csv_header[] = array (
  577. get_lang('FirstName', ''),
  578. get_lang('LastName', ''),
  579. get_lang('TimeSpentOnThePlatform', ''),
  580. get_lang('LastConnexion', ''),
  581. get_lang('NbStudents', ''),
  582. get_lang('CountCours', ''),
  583. get_lang('NumberOfSessions', '')
  584. );
  585. } else {
  586. $csv_header[] = array (
  587. get_lang('LastName', ''),
  588. get_lang('FirstName', ''),
  589. get_lang('TimeSpentOnThePlatform', ''),
  590. get_lang('LastConnexion', ''),
  591. get_lang('NbStudents', ''),
  592. get_lang('CountCours', ''),
  593. get_lang('NumberOfSessions', '')
  594. );
  595. }
  596. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  597. $sqlCoachs = "SELECT DISTINCT scu.id_user as id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
  598. FROM $tbl_user, $tbl_session_course_user scu, $tbl_track_login
  599. WHERE scu.id_user=user_id AND scu.status=2 AND login_user_id=user_id
  600. GROUP BY user_id ";
  601. if ($_configuration['multiple_access_urls']) {
  602. $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  603. $access_url_id = api_get_current_access_url_id();
  604. if ($access_url_id != -1) {
  605. $sqlCoachs = "SELECT DISTINCT scu.id_user as id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
  606. FROM $tbl_user, $tbl_session_course_user scu, $tbl_track_login , $tbl_session_rel_access_url session_rel_url
  607. 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
  608. GROUP BY user_id ";
  609. }
  610. }
  611. if (!empty($order[$tracking_column])) {
  612. $sqlCoachs .= "ORDER BY ".$order[$tracking_column]." ".$tracking_direction;
  613. }
  614. $result_coaches = Database::query($sqlCoachs);
  615. $total_no_coaches = Database::num_rows($result_coaches);
  616. $global_coaches = array();
  617. while ($coach = Database::fetch_array($result_coaches)) {
  618. $global_coaches[$coach['user_id']] = $coach;
  619. }
  620. $sql_session_coach = 'SELECT session.id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
  621. FROM '.$tbl_user.','.$tbl_sessions.' as session,'.$tbl_track_login.'
  622. WHERE id_coach=user_id AND login_user_id=user_id
  623. GROUP BY user_id
  624. ORDER BY login_date '.$tracking_direction;
  625. if ($_configuration['multiple_access_urls']) {
  626. $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  627. $access_url_id = api_get_current_access_url_id();
  628. if ($access_url_id != -1) {
  629. $sql_session_coach = 'SELECT session.id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
  630. FROM '.$tbl_user.','.$tbl_sessions.' as session,'.$tbl_track_login.' , '.$tbl_session_rel_access_url.' as session_rel_url
  631. 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
  632. GROUP BY user_id
  633. ORDER BY login_date '.$tracking_direction;
  634. }
  635. }
  636. $result_sessions_coach = Database::query($sql_session_coach);
  637. $total_no_coaches += Database::num_rows($result_sessions_coach);
  638. while ($coach = Database::fetch_array($result_sessions_coach)) {
  639. $global_coaches[$coach['user_id']] = $coach;
  640. }
  641. $all_datas = array();
  642. foreach ($global_coaches as $id_coach => $coaches) {
  643. $time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($coaches['user_id']));
  644. $last_connection = Tracking :: get_last_connection_date($coaches['user_id']);
  645. $nb_students = count(Tracking :: get_student_followed_by_coach($coaches['user_id']));
  646. $nb_courses = count(Tracking :: get_courses_followed_by_coach($coaches['user_id']));
  647. $nb_sessions = count(Tracking :: get_sessions_coached_by_user($coaches['user_id']));
  648. $table_row = array();
  649. if ($is_western_name_order) {
  650. $table_row[] = $coaches['firstname'];
  651. $table_row[] = $coaches['lastname'];
  652. } else {
  653. $table_row[] = $coaches['lastname'];
  654. $table_row[] = $coaches['firstname'];
  655. }
  656. $table_row[] = $time_on_platform;
  657. $table_row[] = $last_connection;
  658. $table_row[] = $nb_students;
  659. $table_row[] = $nb_courses;
  660. $table_row[] = $nb_sessions;
  661. $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>';
  662. $all_datas[] = $table_row;
  663. if ($is_western_name_order) {
  664. $csv_content[] = array(
  665. api_html_entity_decode($coaches['firstname'], ENT_QUOTES, $charset),
  666. api_html_entity_decode($coaches['lastname'], ENT_QUOTES, $charset),
  667. $time_on_platform,
  668. $last_connection,
  669. $nb_students,
  670. $nb_courses,
  671. $nb_sessions
  672. );
  673. } else {
  674. $csv_content[] = array(
  675. api_html_entity_decode($coaches['lastname'], ENT_QUOTES, $charset),
  676. api_html_entity_decode($coaches['firstname'], ENT_QUOTES, $charset),
  677. $time_on_platform,
  678. $last_connection,
  679. $nb_students,
  680. $nb_courses,
  681. $nb_sessions
  682. );
  683. }
  684. }
  685. if ($tracking_column != 3) {
  686. if ($tracking_direction == 'DESC') {
  687. usort($all_datas, 'rsort_users');
  688. } else {
  689. usort($all_datas, 'sort_users');
  690. }
  691. }
  692. if ($export_csv && $tracking_column != 3) {
  693. usort($csv_content, 'sort_users');
  694. }
  695. if ($export_csv) {
  696. $csv_content = array_merge($csv_header, $csv_content);
  697. }
  698. foreach ($all_datas as $row) {
  699. $table -> addRow($row, 'align="right"');
  700. }
  701. $table -> updateColAttributes(0, array('align' => 'left'));
  702. $table -> updateColAttributes(1, array('align' => 'left'));
  703. $table -> updateColAttributes(3, array('align' => 'left'));
  704. $table -> updateColAttributes(7, array('align' => 'center'));
  705. $table -> display();
  706. }
  707. }
  708. // send the csv file if asked
  709. if ($export_csv) {
  710. ob_end_clean();
  711. Export :: export_table_csv($csv_content, 'reporting_index');
  712. exit;
  713. }
  714. //footer
  715. if (!$export_csv) {
  716. Display::display_footer();
  717. }
  718. /**
  719. * Get number of courses for sortable with pagination
  720. * @return int
  721. */
  722. function get_number_of_courses() {
  723. global $courses;
  724. return count($courses);
  725. }