index.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Homepage for the MySpace directory
  5. * @package chamilo.reporting
  6. */
  7. // resetting the course id
  8. $cidReset = true;
  9. $htmlHeadXtra[] = api_get_jqgrid_js();
  10. // the section (for the tabs)
  11. $this_section = SECTION_TRACKING;
  12. ob_start();
  13. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  14. $display = isset($_GET['display']) ? Security::remove_XSS($_GET['display']) : null;
  15. $csv_content = array();
  16. $nameTools = get_lang('MySpace');
  17. $user_id = api_get_user_id();
  18. $session_id = isset($_GET['session_id']) ? intval($_GET['session_id']) : 0;
  19. $is_coach = api_is_coach($session_id);
  20. $is_platform_admin = api_is_platform_admin();
  21. $is_drh = api_is_drh();
  22. $is_session_admin = api_is_session_admin();
  23. $count_sessions = 0;
  24. $count_courses = 0;
  25. $title = null;
  26. // Access control
  27. api_block_anonymous_users();
  28. if (!$export_csv) {
  29. Display :: display_header($nameTools);
  30. }
  31. // Database table definitions
  32. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  33. $tbl_sessions = Database::get_main_table(TABLE_MAIN_SESSION);
  34. $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  35. /* MAIN CODE */
  36. if ($is_session_admin) {
  37. header('location:session.php');
  38. exit;
  39. }
  40. // Get views
  41. $views = array('admin', 'teacher', 'coach', 'drh');
  42. $view = 'teacher';
  43. if (isset($_GET['view']) && in_array($_GET['view'], $views)) {
  44. $view = $_GET['view'];
  45. }
  46. $menu_items = array();
  47. if ($is_platform_admin) {
  48. if ($view == 'admin') {
  49. $title = get_lang('CoachList');
  50. $menu_items[] = Display::url(
  51. Display::return_icon('teacher.png', get_lang('TeacherInterface'), array(), ICON_SIZE_MEDIUM),
  52. api_get_self().'?view=teacher'
  53. );
  54. $menu_items[] = Display::url(
  55. Display::return_icon('star_na.png', get_lang('AdminInterface'), array(), ICON_SIZE_MEDIUM),
  56. api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php'
  57. );
  58. $menu_items[] = Display::url(
  59. Display::return_icon('quiz.png', get_lang('ExamTracking'), array(), ICON_SIZE_MEDIUM),
  60. api_get_path(WEB_CODE_PATH).'tracking/exams.php'
  61. );
  62. $menu_items[] = Display::url(
  63. Display::return_icon('statistics.png', get_lang('CurrentCoursesReport'), array(), ICON_SIZE_MEDIUM),
  64. api_get_path(WEB_CODE_PATH).'mySpace/current_courses.php'
  65. );
  66. } else {
  67. $menu_items[] = Display::url(
  68. Display::return_icon('teacher_na.png', get_lang('TeacherInterface'), array(), ICON_SIZE_MEDIUM), '');
  69. $menu_items[] = Display::url(
  70. Display::return_icon('star.png', get_lang('AdminInterface'), array(), ICON_SIZE_MEDIUM),
  71. //api_get_path(WEB_CODE_PATH).'tracking/course_session_report.php?view=admin'
  72. api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php'
  73. );
  74. $menu_items[] = Display::url(
  75. Display::return_icon('quiz.png', get_lang('ExamTracking'), array(), ICON_SIZE_MEDIUM),
  76. api_get_path(WEB_CODE_PATH).'tracking/exams.php'
  77. );
  78. $menu_items[] = Display::url(
  79. Display::return_icon('statistics.png', get_lang('CurrentCoursesReport'), array(), ICON_SIZE_MEDIUM),
  80. api_get_path(WEB_CODE_PATH).'mySpace/current_courses.php'
  81. );
  82. }
  83. }
  84. if ($is_drh) {
  85. $view = 'drh';
  86. $menu_items[] = Display::url(
  87. Display::return_icon('user_na.png', get_lang('Students'), array(), ICON_SIZE_MEDIUM),
  88. '#'
  89. );
  90. $menu_items[] = Display::url(
  91. Display::return_icon('teacher.png', get_lang('Trainers'), array(), ICON_SIZE_MEDIUM),
  92. 'teachers.php'
  93. );
  94. $menu_items[] = Display::url(
  95. Display::return_icon('course.png', get_lang('Courses'), array(), ICON_SIZE_MEDIUM),
  96. 'course.php'
  97. );
  98. $menu_items[] = Display::url(
  99. Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_MEDIUM),
  100. 'session.php'
  101. );
  102. $menu_items[] = Display::url(
  103. Display::return_icon('empty_evaluation.png', get_lang('CompanyReport'), array(), ICON_SIZE_MEDIUM),
  104. 'company_reports.php'
  105. );
  106. $menu_items[] = Display::url(
  107. Display::return_icon('evaluation_rate.png', get_lang('CompanyReportResumed'), array(), ICON_SIZE_MEDIUM),
  108. 'company_reports_resumed.php'
  109. );
  110. }
  111. echo '<div id="actions" class="actions">';
  112. echo '<span style="float:right">';
  113. if ($display == 'useroverview' || $display == 'sessionoverview' || $display == 'courseoverview') {
  114. echo '<a href="'.api_get_self().'?display='.$display.'&export=csv&view='.$view.'">';
  115. echo Display::return_icon("export_csv.png", get_lang('ExportAsCSV'), array(), 32);
  116. echo '</a>';
  117. }
  118. echo '<a href="javascript: void(0);" onclick="javascript: window.print()">'.
  119. Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_MEDIUM).'</a>';
  120. echo '</span>';
  121. if (!empty($session_id) &&
  122. !in_array($display, array('accessoverview','lpprogressoverview','progressoverview','exerciseprogress', 'surveyoverview'))
  123. ) {
  124. echo '<a href="index.php">'.Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
  125. if (!api_is_platform_admin()) {
  126. if (api_get_setting('session.add_users_by_coach') == 'true') {
  127. if ($is_coach) {
  128. echo "<div align=\"right\">";
  129. echo '<a href="user_import.php?id_session='.$session_id.'&action=export&amp;type=xml">'.
  130. Display::return_icon('excel.gif', get_lang('ImportUserList')).'&nbsp;'.get_lang('ImportUserList').'</a>';
  131. echo "</div><br />";
  132. }
  133. }
  134. } else {
  135. echo "<div align=\"right\">";
  136. echo '<a href="user_import.php?id_session='.$session_id.'&action=export&amp;type=xml">'.
  137. Display::return_icon('excel.gif', get_lang('ImportUserList')).'&nbsp;'.get_lang('ImportUserList').'</a>';
  138. echo "</div><br />";
  139. }
  140. } else {
  141. echo Display::url(
  142. Display::return_icon('stats.png', get_lang('MyStats'),'',ICON_SIZE_MEDIUM),
  143. api_get_path(WEB_CODE_PATH)."auth/my_progress.php"
  144. );
  145. echo Display::url(
  146. Display::return_icon("certificate_list.png", get_lang("GradebookSeeListOfStudentsCertificates"), array(), ICON_SIZE_MEDIUM),
  147. api_get_path(WEB_CODE_PATH) . "gradebook/certificate_report.php"
  148. );
  149. }
  150. // Actions menu
  151. $nb_menu_items = count($menu_items);
  152. if (empty($session_id) ||
  153. in_array($display, array('accessoverview','lpprogressoverview', 'progressoverview', 'exerciseprogress', 'surveyoverview'))
  154. ) {
  155. if ($nb_menu_items > 1) {
  156. foreach ($menu_items as $key => $item) {
  157. echo $item;
  158. }
  159. }
  160. }
  161. echo '</div>';
  162. $userId = api_get_user_id();
  163. $stats = Tracking::getStats($userId);
  164. $students = $stats['students'];
  165. $studentBosses = $stats['studentBosses'];
  166. $teachers = $stats['teachers'];
  167. $humanResourcesUsers = $stats['drh'];
  168. $assignedCourses = $stats['assignedCourses'];
  169. $courses = $stats['courses'];
  170. $sessions = $stats['sessions'];
  171. $sessionIdList = array();
  172. if (!empty($sessions)) {
  173. foreach ($sessions as $session) {
  174. $sessionIdList[] = $session['id'];
  175. }
  176. }
  177. // Courses for the user
  178. $countAssignedCourses = count($assignedCourses);
  179. $count_courses = count($courses);
  180. // Sessions for the user
  181. $count_sessions = count($sessions);
  182. $total_time_spent = 0;
  183. $total_courses = 0;
  184. $avg_total_progress = 0;
  185. $avg_results_to_exercises = 0;
  186. $nb_inactive_students = 0;
  187. $nb_posts = $nb_assignments = 0;
  188. $inactiveTime = time() - (3600 * 24 * 7);
  189. $nb_students = 0;
  190. $numberTeachers = 0;
  191. $numberStudentBosses = 0;
  192. $countHumanResourcesUsers = 0;
  193. $daysAgo = 7;
  194. $studentIds = array();
  195. $avg_courses_per_student = null;
  196. if (!empty($students)) {
  197. // Students
  198. $nb_students = count($students);
  199. $progress = Tracking::get_avg_student_progress($studentIds);
  200. $countAssignments = Tracking::count_student_assignments($studentIds);
  201. $studentIds = array_values($students);
  202. // average progress
  203. $avg_total_progress = $progress / $nb_students;
  204. // average assignments
  205. $nb_assignments = $countAssignments / $nb_students;
  206. $avg_courses_per_student = $count_courses / $nb_students;
  207. }
  208. if (!empty($studentBosses)) {
  209. $numberStudentBosses = count($studentBosses);
  210. }
  211. if (!empty($humanResourcesUsers)) {
  212. $countHumanResourcesUsers = count($humanResourcesUsers);
  213. }
  214. if (!empty($teachers)) {
  215. $numberTeachers = count($teachers);
  216. }
  217. // Inactive students
  218. //$countInactiveUsers = Tracking::getInactiveUsers($studentIds, $daysAgo);
  219. $totalTimeSpent = Tracking::get_time_spent_on_the_platform($studentIds);
  220. $posts = Tracking::count_student_messages($studentIds);
  221. $averageScore = Tracking::getAverageStudentScore($studentIds);
  222. $avg_results_to_exercises = $averageScore;
  223. // average posts
  224. $nb_posts = $posts;
  225. $avg_time_spent = $totalTimeSpent;
  226. $linkAddUser = null;
  227. $linkCourseDetailsAsTeacher = null;
  228. $linkAddCourse = null;
  229. $linkAddSession = null;
  230. if (api_is_platform_admin()) {
  231. $linkAddUser = ' '.Display::url(
  232. Display::return_icon('2rightarrow.png', get_lang('Add')),
  233. api_get_path(WEB_CODE_PATH).'admin/dashboard_add_users_to_user.php?user='.api_get_user_id(),
  234. array('class' => '')
  235. );
  236. $linkCourseDetailsAsTeacher = ' '.Display::url(
  237. Display::return_icon('2rightarrow.png', get_lang('Details')),
  238. api_get_path(WEB_CODE_PATH).'mySpace/course.php',
  239. array('class' => '')
  240. );
  241. $linkAddCourse = ' '.Display::url(
  242. Display::return_icon('2rightarrow.png', get_lang('Details')),
  243. api_get_path(WEB_CODE_PATH).'mySpace/course.php?follow',
  244. array('class' => '')
  245. );
  246. $linkAddSession = ' '.Display::url(
  247. Display::return_icon('2rightarrow.png', get_lang('Add')),
  248. api_get_path(WEB_CODE_PATH).'admin/dashboard_add_sessions_to_user.php?user='.api_get_user_id(),
  249. array('class' => '')
  250. );
  251. }
  252. echo Display::page_subheader(get_lang('Overview'));
  253. echo '<div class="report_section">
  254. <table class="table table-bordered table-striped">
  255. <tr>
  256. <td>'.Display::url(
  257. get_lang('FollowedStudents'),
  258. api_get_path(WEB_CODE_PATH).'mySpace/student.php'
  259. ).'</td>
  260. <td align="right">'.$nb_students.'</td>
  261. </tr>
  262. <tr>
  263. <td>'.Display::url(
  264. get_lang('FollowedStudentBosses'),
  265. api_get_path(WEB_CODE_PATH).'mySpace/users.php?status='.STUDENT_BOSS
  266. ).'</td>
  267. <td align="right">'.$numberStudentBosses.'</td>
  268. </tr>
  269. <tr>
  270. <td>'.Display::url(
  271. get_lang('FollowedTeachers'),
  272. api_get_path(WEB_CODE_PATH).'mySpace/teachers.php'
  273. ).
  274. '</td>
  275. <td align="right">'.$numberTeachers.'</td>
  276. </tr>
  277. <tr>
  278. <td>'.Display::url(
  279. get_lang('FollowedHumanResources'),
  280. api_get_path(WEB_CODE_PATH).'mySpace/users.php?status='.DRH
  281. ).
  282. '</td>
  283. <td align="right">'.$countHumanResourcesUsers.'</td>
  284. </tr>
  285. <tr>
  286. <td>'.Display::url(
  287. get_lang('FollowedUsers'),
  288. api_get_path(WEB_CODE_PATH).'mySpace/users.php'
  289. ).
  290. '</td>
  291. <td align="right">'.($nb_students + $numberStudentBosses + $numberTeachers + $countHumanResourcesUsers).$linkAddUser.'</td>
  292. </tr>
  293. <tr>
  294. <td>'.Display::url(
  295. get_lang('AssignedCourses'),
  296. api_get_path(WEB_CODE_PATH).'mySpace/course.php'
  297. ).
  298. '</td>
  299. <td align="right">'.$count_courses.$linkCourseDetailsAsTeacher.'</td>
  300. </tr>
  301. <tr>
  302. <td>'.Display::url(
  303. get_lang('FollowedCourses'),
  304. api_get_path(WEB_CODE_PATH).'mySpace/course.php?follow'
  305. ).
  306. '</td>
  307. <td align="right">'.$countAssignedCourses.$linkAddCourse.'</td>
  308. </tr>
  309. <tr>
  310. <td>'.Display::url(
  311. get_lang('FollowedSessions'),
  312. api_get_path(WEB_CODE_PATH).'mySpace/session.php'
  313. ).
  314. '</td>
  315. <td align="right">'.$count_sessions.$linkAddSession.'</td>
  316. </tr>
  317. </table>';
  318. echo '</div>';
  319. echo Display::page_subheader(get_lang('Students').' ('.$nb_students.')');
  320. if ($export_csv) {
  321. //csv part
  322. $csv_content[] = array(get_lang('Students'));
  323. $csv_content[] = array(get_lang('InactivesStudents'), $nb_inactive_students);
  324. $csv_content[] = array(get_lang('AverageTimeSpentOnThePlatform'), $avg_time_spent);
  325. $csv_content[] = array(get_lang('AverageCoursePerStudent'), $avg_courses_per_student);
  326. $csv_content[] = array(get_lang('AverageProgressInLearnpath'), is_null($avg_total_progress) ? null : round($avg_total_progress, 2).'%');
  327. $csv_content[] = array(get_lang('AverageResultsToTheExercices'), is_null($avg_results_to_exercises) ? null : round($avg_results_to_exercises, 2).'%');
  328. $csv_content[] = array(get_lang('AveragePostsInForum'), $nb_posts);
  329. $csv_content[] = array(get_lang('AverageAssignments'), $nb_assignments);
  330. $csv_content[] = array();
  331. } else {
  332. $lastConnectionDate = api_get_utc_datetime(strtotime('15 days ago'));
  333. $countActiveUsers = SessionManager::getCountUserTracking(null, 1, null, array(), array());
  334. $countSleepingTeachers = SessionManager::getTeacherTracking(
  335. api_get_user_id(),
  336. 1,
  337. $lastConnectionDate,
  338. true,
  339. $sessionIdList
  340. );
  341. $countSleepingStudents = SessionManager::getCountUserTracking(
  342. null,
  343. 1,
  344. $lastConnectionDate,
  345. $sessionIdList,
  346. $studentIds
  347. );
  348. $form = new FormValidator('search_user', 'get', api_get_path(WEB_CODE_PATH).'mySpace/student.php');
  349. $form = Tracking::setUserSearchForm($form);
  350. $form->display();
  351. // html part
  352. echo '<div class="report_section">
  353. <table class="table table-bordered table-striped">
  354. <tr>
  355. <td>'.get_lang('AverageCoursePerStudent').'</td>
  356. <td align="right">'.(is_null($avg_courses_per_student) ? '' : round($avg_courses_per_student, 2)).'</td>
  357. </tr>
  358. <tr>
  359. <td>'.get_lang('InactivesStudents').'</td>
  360. <td align="right">'.$nb_inactive_students.'</td>
  361. </tr>
  362. <tr>
  363. <td>'.get_lang('AverageTimeSpentOnThePlatform').'</td>
  364. <td align="right">'.(is_null($avg_time_spent) ? '' : api_time_to_hms($avg_time_spent)).'</td>
  365. </tr>
  366. <tr>
  367. <td>'.get_lang('AverageProgressInLearnpath').'</td>
  368. <td align="right">'.(is_null($avg_total_progress) ? '' : round($avg_total_progress, 2).'%').'</td>
  369. </tr>
  370. <tr>
  371. <td>'.get_lang('AvgCourseScore').'</td>
  372. <td align="right">'.(is_null($avg_results_to_exercises) ? '' : round($avg_results_to_exercises, 2).'%').'</td>
  373. </tr>
  374. <tr>
  375. <td>'.get_lang('AveragePostsInForum').'</td>
  376. <td align="right">'.(is_null($nb_posts) ? '' : round($nb_posts, 2)).'</td>
  377. </tr>
  378. <tr>
  379. <td>'.get_lang('AverageAssignments').'</td>
  380. <td align="right">'.(is_null($nb_assignments) ? '' : round($nb_assignments, 2)).'</td>
  381. </tr>
  382. </table>
  383. </div>';
  384. }
  385. // Send the csv file if asked
  386. if ($export_csv) {
  387. ob_end_clean();
  388. Export :: arrayToCsv($csv_content, 'reporting_index');
  389. exit;
  390. }
  391. if (!$export_csv) {
  392. Display::display_footer();
  393. }