index.php 29 KB

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