index.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. <?php
  2. /**
  3. * @todo use constant for $this_section
  4. */
  5. // name of the language file that needs to be included
  6. $language_file = array ('registration', 'index','tracking');
  7. $cidReset=true;
  8. require ('../inc/global.inc.php');
  9. require (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).'export.lib.inc.php');
  12. ob_start();
  13. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  14. $csv_content = array();
  15. $nameTools= get_lang("MySpace");
  16. $this_section = "session_my_space";
  17. api_block_anonymous_users();
  18. if(!$export_csv)
  19. {
  20. Display :: display_header($nameTools);
  21. }
  22. // Database table definitions
  23. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  24. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  25. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  26. $tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
  27. $tbl_sessions = Database :: get_main_table(TABLE_MAIN_SESSION);
  28. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  29. $tbl_session_user = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
  30. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  31. $tbl_admin = Database :: get_main_table(TABLE_MAIN_ADMIN);
  32. /********************
  33. * FUNCTIONS
  34. ********************/
  35. function count_teacher_courses()
  36. {
  37. global $nb_teacher_courses;
  38. return $nb_teacher_courses;
  39. }
  40. function count_coaches()
  41. {
  42. global $total_no_coachs;
  43. return $total_no_coachs;
  44. }
  45. function sort_users($a,$b){
  46. $a = trim(strtolower($a[$_SESSION['tracking_column']]));
  47. $b = trim(strtolower($b[$_SESSION['tracking_column']]));
  48. if($_SESSION['tracking_direction'] == 'DESC')
  49. return strcmp($b, $a);
  50. else
  51. return strcmp($a, $b);
  52. }
  53. /**************************
  54. * MAIN CODE
  55. ***************************/
  56. $isCoach = api_is_coach();
  57. $isPlatformAdmin = api_is_platform_admin();
  58. $view = isset($_GET['view']) ? $_GET['view'] : 'teacher';
  59. $menu_items = array();
  60. if(api_is_allowed_to_create_course())
  61. {
  62. $sqlNbCours = " SELECT course_rel_user.course_code, course.title
  63. FROM $tbl_course_user as course_rel_user
  64. INNER JOIN $tbl_course as course
  65. ON course.code = course_rel_user.course_code
  66. WHERE course_rel_user.user_id='".$_user['user_id']."' AND course_rel_user.status='1'
  67. ORDER BY course.title";
  68. $resultNbCours = api_sql_query($sqlNbCours, __FILE__, __LINE__);
  69. $a_courses = api_store_result($resultNbCours);
  70. $nb_teacher_courses = count($a_courses);
  71. if($nb_teacher_courses)
  72. {
  73. if(!$isCoach && !api_is_platform_admin())
  74. {
  75. $view = 'teacher';
  76. }
  77. if($view=='teacher')
  78. {
  79. $menu_items[] = get_lang('TeacherInterface');
  80. $title = get_lang('YourCourseList');
  81. }
  82. else
  83. {
  84. $menu_items[] = '<a href="'.api_get_self().'?view=teacher">'.get_lang('TeacherInterface').'</a>';
  85. }
  86. }
  87. }
  88. if($isCoach)
  89. {
  90. if($nb_teacher_courses==0 && !api_is_platform_admin())
  91. {
  92. $view = 'coach';
  93. }
  94. if($view=='coach')
  95. {
  96. $menu_items[] = get_lang('CoachInterface');
  97. $title = get_lang('YourStatistics');
  98. }
  99. else
  100. {
  101. $menu_items[] = '<a href="'.api_get_self().'?view=coach">'.get_lang('CoachInterface').'</a>';
  102. }
  103. }
  104. if(api_is_platform_admin())
  105. {
  106. if(!$isCoach && $nb_teacher_courses==0)
  107. {
  108. $view = 'admin';
  109. }
  110. if($view=='admin')
  111. {
  112. $menu_items[] = get_lang('AdminInterface');
  113. $title = get_lang('CoachList');
  114. }
  115. else
  116. {
  117. $menu_items[] = '<a href="'.api_get_self().'?view=admin">'.get_lang('AdminInterface').'</a>';
  118. }
  119. }
  120. if($_user['status']==DRH)
  121. {
  122. $view = 'drh';
  123. $title = get_lang('DrhInterface');
  124. $menu_items[] = '<a href="'.api_get_self().'?view=drh">'.get_lang('DrhInterface').'</a>';
  125. }
  126. $nb_menu_items = count($menu_items);
  127. if($nb_menu_items>1)
  128. {
  129. foreach($menu_items as $key=> $item)
  130. {
  131. echo $item;
  132. if($key!=$nb_menu_items-1)
  133. {
  134. echo ' | ';
  135. }
  136. }
  137. echo '<br />';
  138. }
  139. echo '<div align="left" style="float:left"><h4>'.$title.'</h4></div>
  140. <div align="right">
  141. <a href="#" onclick="window.print()"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>
  142. <a href="'.api_get_self().'?export=csv&view='.$view.'"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>
  143. </div>
  144. <div class="clear"></div>';
  145. if($_user['status']==DRH && $view=='drh')
  146. {
  147. $a_students = Tracking :: get_student_followed_by_drh($_user['user_id']);
  148. $courses_of_the_platform = CourseManager :: get_real_course_list();
  149. foreach($courses_of_the_platform as $course)
  150. $a_courses[$course['code']] = $course['code'];
  151. }
  152. if($isCoach && $view=='coach')
  153. {
  154. $a_students = Tracking :: get_student_followed_by_coach($_user['user_id']);
  155. $a_courses = Tracking :: get_courses_followed_by_coach($_user['user_id']);
  156. }
  157. if($view=='coach' || $view=='drh')
  158. {
  159. $nbStudents = count($a_students);
  160. $totalTimeSpent = 0;
  161. $totalCourses = 0;
  162. $avgTotalProgress = 0;
  163. $avgResultsToExercises = 0;
  164. $nb_inactive_students = 0;
  165. $nb_posts = $nb_assignments = 0;
  166. foreach($a_students as $student_id)
  167. {
  168. // inactive students
  169. if($last_connection_date = Tracking :: get_last_connection_date($student_id))
  170. {
  171. list($last_connection_date, $last_connection_hour) = explode(' ',$last_connection_date);
  172. $last_connection_date = explode('-',$last_connection_date);
  173. $last_connection_hour = explode(':',$last_connection_hour);
  174. $last_connection_time = mktime($last_connection_hour[0],$last_connection_hour[1],$last_connection_hour[2],$last_connection_date[1],$last_connection_date[2],$last_connection_date[0]);
  175. if(time()-(3600*24*7) > $last_connection_time)
  176. {
  177. $nb_inactive_students++;
  178. }
  179. }
  180. else
  181. {
  182. $nb_inactive_students++;
  183. }
  184. $totalTimeSpent += Tracking :: get_time_spent_on_the_platform($student_id);
  185. $totalCourses += Tracking :: count_course_per_student($student_id);
  186. $avgStudentProgress = $avgStudentScore = 0;
  187. $nb_courses_student = 0;
  188. foreach($a_courses as $course_code)
  189. {
  190. if(CourseManager :: is_user_subscribed_in_course($student_id, $course_code, true))
  191. {
  192. $nb_courses_student++;
  193. $nb_posts += Tracking :: count_student_messages($student_id,$course_code);
  194. $nb_assignments += Tracking :: count_student_assignments($student_id,$course_code);
  195. $avgStudentProgress += Tracking :: get_avg_student_progress($student_id,$course_code);
  196. $avgStudentScore += Tracking :: get_avg_student_score($student_id,$course_code);
  197. if($nb_posts !== null && $nb_assignments !== null && $avgStudentProgress !== null && $avgStudentScore !== null)
  198. {
  199. //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
  200. $nb_courses_student++;
  201. }
  202. }
  203. }
  204. // average progress of the student
  205. $avgStudentProgress = $avgStudentProgress / $nb_courses_student;
  206. $avgTotalProgress += $avgStudentProgress;
  207. // average test results of the student
  208. $avgStudentScore = $avgStudentScore / $nb_courses_student;
  209. $avgResultsToExercises += $avgStudentScore;
  210. }
  211. // average progress
  212. $avgTotalProgress = $avgTotalProgress/$nbStudents;
  213. // average results to the tests
  214. $avgResultsToExercises = $avgResultsToExercises/$nbStudents;
  215. // average courses by student
  216. $avgCoursesPerStudent = round($totalCourses / $nbStudents,2);
  217. // average time spent on the platform
  218. $avgTimeSpent = $totalTimeSpent / $nbStudents;
  219. // average assignments
  220. $nb_assignments = $nb_assignments / $nbStudents;
  221. // average posts
  222. $nb_posts = $nb_posts / $nbStudents;
  223. //csv part
  224. if($export_csv)
  225. {
  226. $csv_content[] = array( get_lang('Probationers'));
  227. $csv_content[] = array( get_lang('InactivesStudents'),$nb_inactive_students );
  228. $csv_content[] = array( get_lang('AverageTimeSpentOnThePlatform'),$avgTimeSpent);
  229. $csv_content[] = array( get_lang('AverageCoursePerStudent'),$avgCoursesPerStudent);
  230. $csv_content[] = array( get_lang('AverageProgressInLearnpath'),$avgTotalProgress);
  231. $csv_content[] = array( get_lang('AverageResultsToTheExercices'),$avgResultsToExercises);
  232. $csv_content[] = array( get_lang('AveragePostsInForum'),$nb_posts);
  233. $csv_content[] = array( get_lang('AverageAssignments'),$nb_assignments);
  234. $csv_content[] = array();
  235. }
  236. // html part
  237. else
  238. {
  239. echo '
  240. <div class="admin_section">
  241. <h4>
  242. <a href="student.php"><img src="'.api_get_path(WEB_IMG_PATH).'students.gif">&nbsp;'.get_lang('Probationers').' ('.$nbStudents.')'.'</a>
  243. </h4>
  244. <table class="data_table">
  245. <tr>
  246. <td>
  247. '.get_lang('InactivesStudents').'
  248. </td>
  249. <td align="right">
  250. '.$nb_inactive_students.'
  251. </td>
  252. </tr>
  253. <tr>
  254. <td>
  255. '.get_lang('AverageTimeSpentOnThePlatform').'
  256. </td>
  257. <td align="right">
  258. '.api_time_to_hms($avgTimeSpent).'
  259. </td>
  260. </tr>
  261. <tr>
  262. <td>
  263. '.get_lang('AverageCoursePerStudent').'
  264. </td>
  265. <td align="right">
  266. '.$avgCoursesPerStudent.'
  267. </td>
  268. </tr>
  269. <tr>
  270. <td>
  271. '.get_lang('AverageProgressInLearnpath').'
  272. </td>
  273. <td align="right">
  274. '.round($avgTotalProgress,2).' %
  275. </td>
  276. </tr>
  277. <tr>
  278. <td>
  279. '.get_lang('AverageResultsToTheExercices').'
  280. </td>
  281. <td align="right">
  282. '.round($avgResultsToExercises,2).' %
  283. </td>
  284. </tr>
  285. <tr>
  286. <td>
  287. '.get_lang('AveragePostsInForum').'
  288. </td>
  289. <td align="right">
  290. '.round($nb_posts,2).'
  291. </td>
  292. </tr>
  293. <tr>
  294. <td>
  295. '.get_lang('AverageAssignments').'
  296. </td>
  297. <td align="right">
  298. '.round($nb_assignments,2).'
  299. </td>
  300. </tr>
  301. </table>
  302. <a href="student.php">'.get_lang('SeeStudentList').'</a>
  303. </div>';
  304. }
  305. }
  306. if($view == 'coach')
  307. {
  308. /****************************************
  309. * Infos about sessions of the coach
  310. ****************************************/
  311. $a_sessions = Tracking :: get_sessions_coached_by_user($_user['user_id']);
  312. $nbSessions = count($a_sessions);
  313. $nb_sessions_past = $nb_sessions_future = $nb_sessions_current = 0;
  314. $a_courses = array();
  315. foreach($a_sessions as $a_session)
  316. {
  317. if($a_session['date_start'] == '0000-00-00')
  318. {
  319. $nb_sessions_current ++;
  320. }
  321. else
  322. {
  323. $date_start = explode('-',$a_session['date_start']);
  324. $time_start = mktime(0,0,0,$date_start[1],$date_start[2],$date_start[0]);
  325. $date_end = explode('-',$a_session['date_end']);
  326. $time_end = mktime(0,0,0,$date_end[1],$date_end[2],$date_end[0]);
  327. if($time_start < time() && time() < $time_end)
  328. {
  329. $nb_sessions_current++;
  330. }
  331. else if(time() < $time_start)
  332. {
  333. $nb_sessions_future++;
  334. }
  335. else if(time() > $time_end)
  336. {
  337. $nb_sessions_past++;
  338. }
  339. }
  340. $a_courses = array_merge($a_courses, Tracking::get_courses_list_from_session($a_session['id']));
  341. }
  342. $nb_courses_per_session = round(count($a_courses)/$nbSessions,2);
  343. //csv part
  344. if($export_csv)
  345. {
  346. $csv_content[] = array( get_lang('Sessions'));
  347. $csv_content[] = array( get_lang('NbActiveSessions').';'.$nb_sessions_current);
  348. $csv_content[] = array( get_lang('NbPastSessions').';'.$nb_sessions_past);
  349. $csv_content[] = array( get_lang('NbFutureSessions').';'.$nb_sessions_future);
  350. $csv_content[] = array( get_lang('NbStudentPerSession').';'.round($nbStudents/$nbSessions,2));
  351. $csv_content[] = array( get_lang('NbCoursesPerSession').';'.$nb_courses_per_session);
  352. $csv_content[] = array();
  353. }
  354. // html part
  355. else
  356. {
  357. echo '
  358. <div class="admin_section">
  359. <h4>
  360. <a href="session.php"><img src="'.api_get_path(WEB_IMG_PATH).'sessions.gif">&nbsp;'.get_lang('Sessions').' ('.$nbSessions.')'.'</a>
  361. </h4>
  362. <table class="data_table">
  363. <tr>
  364. <td>
  365. '.get_lang('NbActiveSessions').'
  366. </td>
  367. <td align="right">
  368. '.$nb_sessions_current.'
  369. </td>
  370. </tr>
  371. <tr>
  372. <td>
  373. '.get_lang('NbPastSessions').'
  374. </td>
  375. <td align="right">
  376. '.$nb_sessions_past.'
  377. </td>
  378. </tr>
  379. <tr>
  380. <td>
  381. '.get_lang('NbFutureSessions').'
  382. </td>
  383. <td align="right">
  384. '.$nb_sessions_future.'
  385. </td>
  386. </tr>
  387. <tr>
  388. <td>
  389. '.get_lang('NbStudentPerSession').'
  390. </td>
  391. <td align="right">
  392. '.round($nbStudents/$nbSessions,2).'
  393. </td>
  394. </tr>
  395. <tr>
  396. <td>
  397. '.get_lang('NbCoursesPerSession').'
  398. </td>
  399. <td align="right">
  400. '.$nb_courses_per_session.'
  401. </td>
  402. </tr>
  403. </table>
  404. <a href="session.php">'.get_lang('SeeSessionList').'</a>
  405. </div>';
  406. }
  407. }
  408. echo '<div class="clear">&nbsp;</div>';
  409. if(api_is_allowed_to_create_course() && $view=='teacher')
  410. {
  411. if($nb_teacher_courses)
  412. {
  413. $table = new SortableTable('tracking_list_course', 'count_teacher_courses');
  414. $parameters['view'] = 'teacher';
  415. $table->set_additional_parameters($parameters);
  416. $table -> set_header(0, get_lang('CourseTitle'), false, 'align="center"');
  417. $table -> set_header(1, get_lang('NbStudents'), false);
  418. $table -> set_header(2, get_lang('AvgTimeSpentInTheCourse'), false);
  419. $table -> set_header(3, get_lang('AvgStudentsProgress'), false);
  420. $table -> set_header(4, get_lang('AvgStudentsScore'), false);
  421. $table -> set_header(5, get_lang('AvgMessages'), false);
  422. $table -> set_header(6, get_lang('AvgAssignments'), false);
  423. $table -> set_header(7, get_lang('Details'), false);
  424. $csv_content[] = array(
  425. get_lang('CourseTitle'),
  426. get_lang('NbStudents'),
  427. get_lang('AvgTimeSpentInTheCourse'),
  428. get_lang('AvgStudentsProgress'),
  429. get_lang('AvgStudentsScore'),
  430. get_lang('AvgMessages'),
  431. get_lang('AvgAssignments')
  432. );
  433. $a_course_students = array();
  434. foreach($a_courses as $course)
  435. {
  436. $course_code = $course['course_code'];
  437. $avg_assignments_in_course = $avg_messages_in_course = $nb_students_in_course = $avg_progress_in_course = $avg_score_in_course = $avg_time_spent_in_course = 0;
  438. // students directly subscribed to the course
  439. $sql = "SELECT user_id FROM $tbl_course_user as course_rel_user WHERE course_rel_user.status='5' AND course_rel_user.course_code='$course_code'";
  440. $rs = api_sql_query($sql, __FILE__, __LINE__);
  441. while($row = Database::fetch_array($rs))
  442. {
  443. $nb_students_in_course++;
  444. // tracking datas
  445. $avg_progress_in_course += Tracking :: get_avg_student_progress ($row['user_id'], $course_code);
  446. $avg_score_in_course += Tracking :: get_avg_student_score ($row['user_id'], $course_code);
  447. $avg_time_spent_in_course += Tracking :: get_time_spent_on_the_course ($row['user_id'], $course_code);
  448. $avg_messages_in_course += Tracking :: count_student_messages ($row['user_id'], $course_code);
  449. $avg_assignments_in_course += Tracking :: count_student_assignments ($row['user_id'], $course_code);
  450. $a_course_students[] = $row['user_id'];
  451. }
  452. // students subscribed to the course through a session
  453. if(api_get_setting('use_session_mode') == 'true')
  454. {
  455. $sql = 'SELECT id_user as user_id
  456. FROM '.$tbl_session_course_user.'
  457. WHERE course_code="'.addslashes($course_code).'" ORDER BY course_code';
  458. $rs = api_sql_query($sql, __FILE__, __LINE__);
  459. while($row = Database::fetch_array($rs))
  460. {
  461. if(!in_array($row['user_id'], $a_course_students))
  462. {
  463. $nb_students_in_course++;
  464. // tracking datas
  465. $avg_progress_in_course += Tracking :: get_avg_student_progress ($row['user_id'], $course_code);
  466. $avg_score_in_course += Tracking :: get_avg_student_score ($row['user_id'], $course_code);
  467. $avg_time_spent_in_course += Tracking :: get_time_spent_on_the_course ($row['user_id'], $course_code);
  468. $avg_messages_in_course += Tracking :: count_student_messages ($row['user_id'], $course_code);
  469. $avg_assignments_in_course += Tracking :: count_student_assignments ($row['user_id'], $course_code);
  470. $a_course_students[] = $row['user_id'];
  471. }
  472. }
  473. }
  474. if($nb_students_in_course>0)
  475. {
  476. $avg_time_spent_in_course = api_time_to_hms($avg_time_spent_in_course / $nb_students_in_course);
  477. $avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course,2).' %';
  478. $avg_score_in_course = round($avg_score_in_course / $nb_students_in_course,2).' %';
  479. $avg_messages_in_course = round($avg_messages_in_course / $nb_students_in_course,2);
  480. $avg_assignments_in_course = round($avg_assignments_in_course / $nb_students_in_course,2);
  481. }
  482. $table_row = array();
  483. $table_row[] = $course['title'];
  484. $table_row[] = $nb_students_in_course;
  485. $table_row[] = $avg_time_spent_in_course;
  486. $table_row[] = $avg_progress_in_course;
  487. $table_row[] = $avg_score_in_course;
  488. $table_row[] = $avg_messages_in_course;
  489. $table_row[] = $avg_assignments_in_course;
  490. $table_row[] = '<a href="../tracking/courseLog.php?cidReq='.$course_code.'&studentlist=true"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  491. $csv_content[] = array(
  492. $course['title'],
  493. $nb_students_in_course,
  494. $avg_time_spent_in_course,
  495. $avg_progress_in_course,
  496. $avg_score_in_course,
  497. $avg_messages_in_course,
  498. $avg_assignments_in_course,
  499. );
  500. $table -> addRow($table_row, 'align="right"');
  501. $a_course_students = array();
  502. }
  503. $table -> updateColAttributes(0,array('align'=>'left'));
  504. $table -> updateColAttributes(7,array('align'=>'center'));
  505. $table -> display();
  506. }
  507. }
  508. if(api_is_platform_admin() && $view=='admin'){
  509. $tracking_column = isset($_GET['tracking_list_coaches_column']) ? $_GET['tracking_list_coaches_column'] : 0;
  510. $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';
  511. //prepare array for column order - when impossible, use lastname
  512. $order = array(0=>'firstname',1=>'lastname',2=>'lastname',3=>'login_date',4=>'lastname',5=>'lastname');
  513. $table = new SortableTable('tracking_list_coaches', 'count_coaches');
  514. $parameters['view'] = 'admin';
  515. $table->set_additional_parameters($parameters);
  516. $table -> set_header(0, get_lang('FirstName'), true, 'align="center"');
  517. $table -> set_header(1, get_lang('LastName'), true, 'align="center"');
  518. $table -> set_header(2, get_lang('TimeSpentOnThePlatform'), false);
  519. $table -> set_header(3, get_lang('LastConnexion'), true, 'align="center"');
  520. $table -> set_header(4, get_lang('NbStudents'), false);
  521. $table -> set_header(5, get_lang('CountCours'), false);
  522. $table -> set_header(6, get_lang('NumberOfSessions'), false);
  523. $table -> set_header(7, get_lang('Sessions'), false,'align="center"');
  524. $csv_content[] = array(
  525. get_lang('FirstName'),
  526. get_lang('LastName'),
  527. get_lang('TimeSpentOnThePlatform'),
  528. get_lang('LastConnexion'),
  529. get_lang('NbStudents'),
  530. get_lang('CountCours'),
  531. get_lang('NumberOfSessions')
  532. );
  533. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  534. $sqlCoachs = " SELECT DISTINCT id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
  535. FROM $tbl_user, $tbl_session_course, $tbl_track_login
  536. WHERE id_coach=user_id AND login_user_id=user_id
  537. GROUP BY user_id " ;
  538. // ORDER BY login_date ".$tracking_direction;
  539. if(!empty($order[$tracking_column]))
  540. {
  541. $sqlCoachs .= "ORDER BY ".$order[$tracking_column]." ".$tracking_direction;
  542. }
  543. $result_coaches=api_sql_query($sqlCoachs, __FILE__, __LINE__);
  544. $total_no_coachs = Database::num_rows($result_coaches);
  545. $global_coachs=array();
  546. while($a_coach=Database::fetch_array($result_coaches)){
  547. $global_coachs[$a_coach['user_id']] = $a_coach;
  548. }
  549. $sql_session_coach = 'SELECT session.id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
  550. FROM '.$tbl_user.','.$tbl_sessions.' as session,'.$tbl_track_login.'
  551. WHERE id_coach=user_id AND login_user_id=user_id
  552. GROUP BY user_id
  553. ORDER BY login_date '.$tracking_direction;
  554. $result_sessions_coach=api_sql_query($sql_session_coach, __FILE__, __LINE__);
  555. $total_no_coachs += Database::num_rows($result_sessions_coach);
  556. while($a_coach=Database::fetch_array($result_sessions_coach)){
  557. $global_coachs[$a_coach['user_id']] = $a_coach;
  558. }
  559. $all_datas=array();
  560. foreach($global_coachs as $id_coach => $a_coachs){
  561. $time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($a_coachs['user_id']));
  562. $last_connection = Tracking :: get_last_connection_date($a_coachs['user_id']);
  563. $nb_students = count(Tracking :: get_student_followed_by_coach($a_coachs['user_id']));
  564. $nb_courses = count(Tracking :: get_courses_followed_by_coach($a_coachs['user_id']));
  565. $nb_sessions = count(Tracking :: get_sessions_coached_by_user($a_coachs['user_id']));
  566. $table_row = array();
  567. $table_row[] = $a_coachs['firstname'];
  568. $table_row[] = $a_coachs['lastname'];
  569. $table_row[] = $time_on_platform;
  570. $table_row[] = $last_connection;
  571. $table_row[] = $nb_students;
  572. $table_row[] = $nb_courses;
  573. $table_row[] = $nb_sessions;
  574. $table_row[] = '<a href="session.php?id_coach='.$a_coachs['user_id'].'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  575. $all_datas[] = $table_row;
  576. $csv_content[] = array(
  577. $a_coachs['firstname'],
  578. $a_coachs['lastname'],
  579. $time_on_platform,
  580. $last_connection,
  581. $nb_courses,
  582. $nb_sessions
  583. );
  584. }
  585. if($tracking_column != 3){
  586. usort($all_datas, 'sort_users');
  587. if($tracking_direction == 'DESC')
  588. rsort($all_datas);
  589. }
  590. if($export_csv && $tracking_column != 3)
  591. {
  592. usort($csv_content, 'sort_users');
  593. }
  594. foreach($all_datas as $row)
  595. {
  596. $table -> addRow($row,'align="right"');
  597. }
  598. $table -> updateColAttributes(0,array('align'=>'left'));
  599. $table -> updateColAttributes(1,array('align'=>'left'));
  600. $table -> updateColAttributes(3,array('align'=>'left'));
  601. $table -> updateColAttributes(7,array('align'=>'center'));
  602. $table -> display();
  603. }
  604. // send the csv file if asked
  605. if($export_csv)
  606. {
  607. ob_end_clean();
  608. Export :: export_table_csv($csv_content, 'reporting_index');
  609. }
  610. /*
  611. ==============================================================================
  612. FOOTER
  613. ==============================================================================
  614. */
  615. if(!$export_csv)
  616. {
  617. Display::display_footer();
  618. }
  619. ?>