index.php 30 KB

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