index.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  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. $is_coach = api_is_coach($_GET['session_id']); // This is used?
  26. $session_id = isset($_GET['session_id']) ? intval($_GET['session_id']) : 0;
  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. $htmlHeadXtra[] = '<script>
  37. </script>';
  38. if (!$export_csv) {
  39. Display :: display_header($nameTools);
  40. } else {
  41. if ($_GET['view'] == 'admin') {
  42. if($display == 'useroverview') {
  43. MySpace::export_tracking_user_overview();
  44. exit;
  45. } else if($display == 'sessionoverview') {
  46. MySpace::export_tracking_session_overview();
  47. exit;
  48. } else if($display == 'courseoverview') {
  49. MySpace::export_tracking_course_overview();
  50. exit;
  51. }
  52. }
  53. }
  54. // Database table definitions
  55. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  56. $tbl_sessions = Database :: get_main_table(TABLE_MAIN_SESSION);
  57. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  58. /* * FUNCTIONS */
  59. function count_coaches() {
  60. global $total_no_coaches;
  61. return $total_no_coaches;
  62. }
  63. function sort_users($a, $b) {
  64. return api_strcmp(trim(api_strtolower($a[$_SESSION['tracking_column']])), trim(api_strtolower($b[$_SESSION['tracking_column']])));
  65. }
  66. function rsort_users($a, $b) {
  67. return api_strcmp(trim(api_strtolower($b[$_SESSION['tracking_column']])), trim(api_strtolower($a[$_SESSION['tracking_column']])));
  68. }
  69. function count_sessions_coached() {
  70. global $count_sessions;
  71. return $count_sessions;
  72. }
  73. function sort_sessions($a, $b) {
  74. global $tracking_column;
  75. if ($a[$tracking_column] > $b[$tracking_column]) {
  76. return 1;
  77. } else {
  78. return -1;
  79. }
  80. }
  81. function rsort_sessions($a, $b) {
  82. global $tracking_column;
  83. if ($b[$tracking_column] > $a[$tracking_column]) {
  84. return 1;
  85. } else {
  86. return -1;
  87. }
  88. }
  89. /* * MAIN CODE */
  90. if ($is_session_admin) {
  91. header('location:session.php');
  92. exit;
  93. }
  94. // Get views
  95. $views = array('admin', 'teacher', 'coach', 'drh');
  96. $view = 'teacher';
  97. if (isset($_GET['view']) && in_array($_GET['view'], $views)) {
  98. $view = $_GET['view'];
  99. }
  100. $menu_items = array();
  101. global $_configuration;
  102. if ($is_platform_admin) {
  103. if ($view == 'admin') {
  104. $title = get_lang('CoachList');
  105. $menu_items[] = Display::url(Display::return_icon('teacher.png', get_lang('TeacherInterface'), array(), 32), api_get_self().'?view=teacher');
  106. $menu_items[] = Display::url(Display::return_icon('star_na.png', get_lang('AdminInterface'), array(), 32), api_get_self().'?view=admin');
  107. $menu_items[] = Display::url(Display::return_icon('quiz.png', get_lang('ExamTracking'), array(), 32), api_get_path(WEB_CODE_PATH).'tracking/exams.php');
  108. $menu_items[] = Display::url(Display::return_icon('statistics.png', get_lang('CurrentCoursesReport'), array(), 32), api_get_path(WEB_CODE_PATH).'mySpace/current_courses.php');
  109. } else {
  110. $menu_items[] = Display::return_icon('teacher_na.png', get_lang('TeacherInterface'), array(), 32);
  111. $menu_items[] = Display::url(Display::return_icon('star.png', get_lang('AdminInterface'), array(), 32), api_get_self().'?view=admin');
  112. $menu_items[] = Display::url(Display::return_icon('quiz.png', get_lang('ExamTracking'), array(), 32), api_get_path(WEB_CODE_PATH).'tracking/exams.php');
  113. $menu_items[] = Display::url(Display::return_icon('statistics.png', get_lang('CurrentCoursesReport'), array(), 32), api_get_path(WEB_CODE_PATH).'mySpace/current_courses.php');
  114. }
  115. }
  116. if ($is_drh) {
  117. $view = 'drh';
  118. $menu_items[] = Display::return_icon('user_na.png', get_lang('Students'), array(), 32);
  119. $menu_items[] = Display::url(Display::return_icon('teacher.png', get_lang('Trainers'), array(), 32), 'teachers.php');
  120. $menu_items[] = Display::url(Display::return_icon('course.png', get_lang('Courses'), array(), 32), 'course.php');
  121. $menu_items[] = Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), 32), 'session.php');
  122. }
  123. echo '<div id="actions" class="actions">';
  124. echo '<span style="float:right">';
  125. if ($display == 'useroverview' || $display == 'sessionoverview' || $display == 'courseoverview') {
  126. echo '<a href="'.api_get_self().'?display='.$display.'&export=csv&view='.$view.'">';
  127. echo Display::return_icon("export_csv.png", get_lang('ExportAsCSV'),array(), 32);
  128. echo '</a>';
  129. }
  130. echo '<a href="javascript: void(0);" onclick="javascript: window.print()">'.Display::return_icon('printer.png', get_lang('Print'),'',ICON_SIZE_MEDIUM).'</a>';
  131. echo '</span>';
  132. if (!empty($session_id)) {
  133. echo '<a href="index.php">'.Display::return_icon('back.png', get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  134. } else {
  135. echo Display::url(Display::return_icon('stats.png', get_lang('MyStats'),'',ICON_SIZE_MEDIUM),api_get_path(WEB_CODE_PATH)."auth/my_progress.php" );
  136. }
  137. // Actions menu
  138. $nb_menu_items = count($menu_items);
  139. if (empty($session_id)) {
  140. if ($nb_menu_items > 1) {
  141. foreach ($menu_items as $key => $item) {
  142. echo $item;
  143. }
  144. }
  145. }
  146. echo '</div>';
  147. if (empty($session_id)) {
  148. //Getting courses followed by a coach (No session courses)
  149. $courses = CourseManager::get_course_list_as_coach($user_id, false);
  150. if (isset($courses[0])) {
  151. $courses = $courses[0];
  152. }
  153. //Getting students from courses and courses in sessions (To show the total students that the user follows)
  154. $students = CourseManager::get_user_list_from_courses_as_coach($user_id);
  155. // Sessions for the coach
  156. $sessions = SessionManager::get_sessions_coached_by_user($user_id);
  157. //If is drh
  158. if ($is_drh) {
  159. $students = array_keys(UserManager::get_users_followed_by_drh($user_id, STUDENT));
  160. $courses_of_the_platform = CourseManager :: get_courses_followed_by_drh($user_id);
  161. foreach ($courses_of_the_platform as $course) {
  162. $courses[$course['code']] = $course['code'];
  163. }
  164. $sessions = SessionManager::get_sessions_followed_by_drh($user_id);
  165. }
  166. //Courses for the user
  167. $count_courses = count($courses);
  168. //Sessions for the user
  169. $count_sessions = count($sessions);
  170. //Students
  171. $nb_students = count($students);
  172. $total_time_spent = 0;
  173. $total_courses = 0;
  174. $avg_total_progress = 0;
  175. $avg_results_to_exercises = 0;
  176. $nb_inactive_students = 0;
  177. $nb_posts = $nb_assignments = 0;
  178. if (!empty($students))
  179. foreach ($students as $student_id) {
  180. // inactive students
  181. $last_connection_date = Tracking :: get_last_connection_date($student_id, true, true);
  182. if ($last_connection_date !== false) {
  183. if (time() - (3600 * 24 * 7) > $last_connection_date) {
  184. $nb_inactive_students++;
  185. }
  186. } else {
  187. $nb_inactive_students++;
  188. }
  189. $total_time_spent += Tracking :: get_time_spent_on_the_platform($student_id);
  190. $total_courses += Tracking :: count_course_per_student($student_id);
  191. $avg_student_progress = 0;
  192. $avg_student_score = 0;
  193. $nb_courses_student = 0;
  194. foreach ($courses as $course_code) {
  195. if (CourseManager :: is_user_subscribed_in_course($student_id, $course_code, true)) {
  196. $nb_courses_student++;
  197. $nb_posts += Tracking :: count_student_messages($student_id, $course_code);
  198. $nb_assignments += Tracking :: count_student_assignments($student_id, $course_code);
  199. $avg_student_progress += Tracking :: get_avg_student_progress($student_id, $course_code);
  200. $myavg_temp = Tracking :: get_avg_student_score($student_id, $course_code);
  201. if (is_numeric($myavg_temp))
  202. $avg_student_score += $myavg_temp;
  203. if ($nb_posts !== null && $nb_assignments !== null && $avg_student_progress !== null && $avg_student_score !== null) {
  204. //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
  205. $nb_courses_student++;
  206. }
  207. }
  208. }
  209. // average progress of the student
  210. $avg_student_progress = $nb_courses_student ? $avg_student_progress / $nb_courses_student:0;
  211. $avg_total_progress += $avg_student_progress;
  212. // average test results of the student
  213. $avg_student_score = $avg_student_score ? $avg_student_score / $nb_courses_student:0;
  214. $avg_results_to_exercises += $avg_student_score;
  215. }
  216. if ($nb_students > 0 && $view != 'admin') {
  217. // average progress
  218. $avg_total_progress = $avg_total_progress / $nb_students;
  219. // average results to the tests
  220. $avg_results_to_exercises = $avg_results_to_exercises / $nb_students;
  221. // average courses by student
  222. $avg_courses_per_student = round($count_courses / $nb_students, 2);
  223. // average time spent on the platform
  224. $avg_time_spent = $total_time_spent / $nb_students;
  225. // average assignments
  226. $nb_assignments = $nb_assignments / $nb_students;
  227. // average posts
  228. $nb_posts = $nb_posts / $nb_students;
  229. echo Display::page_subheader('<img src="'.api_get_path(WEB_IMG_PATH).'teachers.gif">&nbsp;'.get_lang('Overview'));
  230. echo '<div class="report_section">
  231. <table class="table table-bordered">
  232. <tr>
  233. <td>'.get_lang('FollowedUsers').'</td>
  234. <td align="right">'.$nb_students.'</td>
  235. </tr>
  236. <tr>
  237. <td>'.get_lang('FollowedCourses').'</td>
  238. <td align="right">'.$count_courses.'</td>
  239. </tr>
  240. <tr>
  241. <td>'.get_lang('FollowedSessions').'</td>
  242. <td align="right">'.$count_sessions.'</td>
  243. </tr>
  244. </table>';
  245. echo '</div>';
  246. echo Display::page_subheader('<img src="'.api_get_path(WEB_IMG_PATH).'students.gif">&nbsp;'.get_lang('Students').' ('.$nb_students.')');
  247. if ($export_csv) {
  248. //csv part
  249. $csv_content[] = array(get_lang('Students', ''));
  250. $csv_content[] = array(get_lang('InactivesStudents', ''), $nb_inactive_students );
  251. $csv_content[] = array(get_lang('AverageTimeSpentOnThePlatform', ''), $avg_time_spent);
  252. $csv_content[] = array(get_lang('AverageCoursePerStudent', ''), $avg_courses_per_student);
  253. $csv_content[] = array(get_lang('AverageProgressInLearnpath', ''), is_null($avg_total_progress) ? null : round($avg_total_progress, 2).'%');
  254. $csv_content[] = array(get_lang('AverageResultsToTheExercices', ''), is_null($avg_results_to_exercises) ? null : round($avg_results_to_exercises, 2).'%');
  255. $csv_content[] = array(get_lang('AveragePostsInForum', ''), $nb_posts);
  256. $csv_content[] = array(get_lang('AverageAssignments', ''), $nb_assignments);
  257. $csv_content[] = array();
  258. } else {
  259. // html part
  260. echo '<div class="report_section">
  261. <table class="table table-bordered">
  262. <tr>
  263. <td>'.get_lang('AverageCoursePerStudent').'</td>
  264. <td align="right">'.(is_null($avg_courses_per_student) ? '' : $avg_courses_per_student).'</td>
  265. </tr>
  266. <tr>
  267. <td>'.get_lang('InactivesStudents').'</td>
  268. <td align="right">'.$nb_inactive_students.'</td>
  269. </tr>
  270. <tr>
  271. <td>'.get_lang('AverageTimeSpentOnThePlatform').'</td>
  272. <td align="right">'.(is_null($avg_time_spent) ? '' : api_time_to_hms($avg_time_spent)).'</td>
  273. </tr>
  274. <tr>
  275. <td>'.get_lang('AverageProgressInLearnpath').'</td>
  276. <td align="right">'.(is_null($avg_total_progress) ? '' : round($avg_total_progress, 2).'%').'</td>
  277. </tr>
  278. <tr>
  279. <td>'.get_lang('AvgCourseScore').'</td>
  280. <td align="right">'.(is_null($avg_results_to_exercises) ? '' : round($avg_results_to_exercises, 2).'%').'</td>
  281. </tr>
  282. <tr>
  283. <td>'.get_lang('AveragePostsInForum').'</td>
  284. <td align="right">'.(is_null($nb_posts) ? '' : round($nb_posts, 2)).'</td>
  285. </tr>
  286. <tr>
  287. <td>'.get_lang('AverageAssignments').'</td>
  288. <td align="right">'.(is_null($nb_assignments) ? '' : round($nb_assignments, 2)).'</td>
  289. </tr>
  290. </table>
  291. <a href="student.php">'.get_lang('SeeStudentList').'</a>
  292. </div><br />';
  293. }
  294. } else {
  295. $avg_total_progress = null;
  296. $avg_results_to_exercises = null;
  297. $avg_courses_per_student = null;
  298. $avg_time_spent = null;
  299. $nb_assignments = null;
  300. $nb_posts = null;
  301. }
  302. } else {
  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 && !isset($_GET['session_id'])) {
  372. $columns = array(
  373. get_lang('Title'),
  374. get_lang('SessionDisplayStartDate'),
  375. get_lang('SessionDisplayEndDate'),
  376. get_lang('NbStudentPerSession'),
  377. get_lang('NbCoursesPerSession'),
  378. get_lang('Details')
  379. );
  380. //'formatter'=>'action_formatter',
  381. $column_model = array (
  382. array('name'=>'name', 'index'=>'name', 'width'=>'120', 'align'=>'left', 'search' => 'true', 'searchoptions' => array()),
  383. array('name'=>'display_start_date', 'index'=>'display_start_date', 'width'=>'70', 'align'=>'left', 'search' => 'true', 'searchoptions' => array(), 'sorttype' => 'date'),
  384. array('name'=>'display_end_date', 'index'=>'display_end_date', 'width'=>'70', 'align'=>'left', 'search' => 'true', 'searchoptions' => array(), 'sorttype' => 'date'),
  385. array('name'=>'number_student_per_session', 'index'=>'number_student_per_session', 'width'=>'70', 'align'=>'left', 'search' => 'true', 'searchoptions' => array(), 'sorttype' => 'numeric'),
  386. array('name'=>'courses_per_session', 'index'=>'courses_per_session','width'=>'70', 'align'=>'left', 'search' => 'false', 'searchoptions' => array(), 'sorttype' => 'numeric'),
  387. array('name'=>'details', 'index'=>'details', 'width'=>'80', 'align'=>'left', 'sortable'=>'false', 'search' => 'false'),
  388. );
  389. //Autowidth
  390. $extra_params['autowidth'] = 'true';
  391. //height auto
  392. $extra_params['height'] = 'auto';
  393. $extra_params['sortname'] = 'display_start_date';
  394. $extra_params['sortorder'] = 'desc';
  395. //$extra_params['excel'] = 'excel';
  396. $extra_params['rowList'] = array(10, 20 ,30);
  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, array())."
  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_statistic_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 scu.status=2 AND login_user_id=user_id
  538. GROUP BY user_id ";
  539. if ($_configuration['multiple_access_urls']) {
  540. $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  541. $access_url_id = api_get_current_access_url_id();
  542. if ($access_url_id != -1) {
  543. $sqlCoachs = "SELECT DISTINCT scu.id_user as id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
  544. FROM $tbl_user, $tbl_session_course_user scu, $tbl_track_login , $tbl_session_rel_access_url session_rel_url
  545. 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
  546. GROUP BY user_id ";
  547. }
  548. }
  549. if (!empty($order[$tracking_column])) {
  550. $sqlCoachs .= "ORDER BY ".$order[$tracking_column]." ".$tracking_direction;
  551. }
  552. $result_coaches = Database::query($sqlCoachs);
  553. $total_no_coaches = Database::num_rows($result_coaches);
  554. $global_coaches = array();
  555. while ($coach = Database::fetch_array($result_coaches)) {
  556. $global_coaches[$coach['user_id']] = $coach;
  557. }
  558. $sql_session_coach = 'SELECT session.id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
  559. FROM '.$tbl_user.','.$tbl_sessions.' as session,'.$tbl_track_login.'
  560. WHERE id_coach=user_id AND login_user_id=user_id
  561. GROUP BY user_id
  562. ORDER BY login_date '.$tracking_direction;
  563. if ($_configuration['multiple_access_urls']) {
  564. $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  565. $access_url_id = api_get_current_access_url_id();
  566. if ($access_url_id != -1) {
  567. $sql_session_coach = 'SELECT session.id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
  568. FROM '.$tbl_user.','.$tbl_sessions.' as session,'.$tbl_track_login.' , '.$tbl_session_rel_access_url.' as session_rel_url
  569. 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
  570. GROUP BY user_id
  571. ORDER BY login_date '.$tracking_direction;
  572. }
  573. }
  574. $result_sessions_coach = Database::query($sql_session_coach);
  575. $total_no_coaches += Database::num_rows($result_sessions_coach);
  576. while ($coach = Database::fetch_array($result_sessions_coach)) {
  577. $global_coaches[$coach['user_id']] = $coach;
  578. }
  579. $all_datas = array();
  580. foreach ($global_coaches as $id_coach => $coaches) {
  581. $time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($coaches['user_id']));
  582. $last_connection = Tracking :: get_last_connection_date($coaches['user_id']);
  583. $nb_students = count(Tracking :: get_student_followed_by_coach($coaches['user_id']));
  584. $nb_courses = count(Tracking :: get_courses_followed_by_coach($coaches['user_id']));
  585. $nb_sessions = count(Tracking :: get_sessions_coached_by_user($coaches['user_id']));
  586. $table_row = array();
  587. if ($is_western_name_order) {
  588. $table_row[] = $coaches['firstname'];
  589. $table_row[] = $coaches['lastname'];
  590. } else {
  591. $table_row[] = $coaches['lastname'];
  592. $table_row[] = $coaches['firstname'];
  593. }
  594. $table_row[] = $time_on_platform;
  595. $table_row[] = $last_connection;
  596. $table_row[] = $nb_students;
  597. $table_row[] = $nb_courses;
  598. $table_row[] = $nb_sessions;
  599. $table_row[] = '<a href="session.php?id_coach='.$coaches['user_id'].'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  600. $all_datas[] = $table_row;
  601. if ($is_western_name_order) {
  602. $csv_content[] = array(
  603. api_html_entity_decode($coaches['firstname'], ENT_QUOTES, $charset),
  604. api_html_entity_decode($coaches['lastname'], ENT_QUOTES, $charset),
  605. $time_on_platform,
  606. $last_connection,
  607. $nb_students,
  608. $nb_courses,
  609. $nb_sessions
  610. );
  611. } else {
  612. $csv_content[] = array(
  613. api_html_entity_decode($coaches['lastname'], ENT_QUOTES, $charset),
  614. api_html_entity_decode($coaches['firstname'], ENT_QUOTES, $charset),
  615. $time_on_platform,
  616. $last_connection,
  617. $nb_students,
  618. $nb_courses,
  619. $nb_sessions
  620. );
  621. }
  622. }
  623. if ($tracking_column != 3) {
  624. if ($tracking_direction == 'DESC') {
  625. usort($all_datas, 'rsort_users');
  626. } else {
  627. usort($all_datas, 'sort_users');
  628. }
  629. }
  630. if ($export_csv && $tracking_column != 3) {
  631. usort($csv_content, 'sort_users');
  632. }
  633. if ($export_csv) {
  634. $csv_content = array_merge($csv_header, $csv_content);
  635. }
  636. foreach ($all_datas as $row) {
  637. $table -> addRow($row, 'align="right"');
  638. }
  639. /*
  640. $table -> updateColAttributes(0, array('align' => 'left'));
  641. $table -> updateColAttributes(1, array('align' => 'left'));
  642. $table -> updateColAttributes(3, array('align' => 'left'));
  643. $table -> updateColAttributes(7, array('align' => 'center'));*/
  644. $table -> display();
  645. }
  646. }
  647. // send the csv file if asked
  648. if ($export_csv) {
  649. ob_end_clean();
  650. Export :: export_table_csv($csv_content, 'reporting_index');
  651. exit;
  652. }
  653. //footer
  654. if (!$export_csv) {
  655. Display::display_footer();
  656. }
  657. /**
  658. * Get number of courses for sortable with pagination
  659. * @return int
  660. */
  661. function get_number_of_courses() {
  662. global $courses;
  663. return count($courses);
  664. }