index.php 29 KB

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