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