index.php 23 KB

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