index.php 15 KB

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