index.php 16 KB

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