index.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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(Display::return_icon('user_na.png', get_lang('Students'), array(), ICON_SIZE_MEDIUM), '#');
  90. $menu_items[] = Display::url(Display::return_icon('teacher.png', get_lang('Trainers'), array(), ICON_SIZE_MEDIUM), 'teachers.php');
  91. $menu_items[] = Display::url(Display::return_icon('course.png', get_lang('Courses'), array(), ICON_SIZE_MEDIUM), 'course.php');
  92. $menu_items[] = Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_MEDIUM), 'session.php');
  93. $menu_items[] = Display::url(Display::return_icon('empty_evaluation.png', get_lang('CompanyReport'), array(), ICON_SIZE_MEDIUM), 'company_reports.php');
  94. $menu_items[] = Display::url(Display::return_icon('evaluation_rate.png', get_lang('CompanyReportResumed'), array(), ICON_SIZE_MEDIUM), 'company_reports_resumed.php');
  95. }
  96. echo '<div id="actions" class="actions">';
  97. echo '<span style="float:right">';
  98. if ($display == 'useroverview' || $display == 'sessionoverview' || $display == 'courseoverview') {
  99. echo '<a href="'.api_get_self().'?display='.$display.'&export=csv&view='.$view.'">';
  100. echo Display::return_icon("export_csv.png", get_lang('ExportAsCSV'), array(), 32);
  101. echo '</a>';
  102. }
  103. echo '<a href="javascript: void(0);" onclick="javascript: window.print()">'.
  104. Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_MEDIUM).'</a>';
  105. echo '</span>';
  106. if (!empty($session_id) &&
  107. !in_array($display, array('accessoverview','lpprogressoverview','progressoverview','exerciseprogress', 'surveyoverview'))
  108. ) {
  109. echo '<a href="index.php">'.Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
  110. if (!api_is_platform_admin()) {
  111. if (api_get_setting('add_users_by_coach') == 'true') {
  112. if ($is_coach) {
  113. echo "<div align=\"right\">";
  114. echo '<a href="user_import.php?id_session='.$session_id.'&action=export&amp;type=xml">'.
  115. Display::return_icon('excel.gif', get_lang('ImportUserList')).'&nbsp;'.get_lang('ImportUserList').'</a>';
  116. echo "</div><br />";
  117. }
  118. }
  119. } else {
  120. echo "<div align=\"right\">";
  121. echo '<a href="user_import.php?id_session='.$session_id.'&action=export&amp;type=xml">'.
  122. Display::return_icon('excel.gif', get_lang('ImportUserList')).'&nbsp;'.get_lang('ImportUserList').'</a>';
  123. echo "</div><br />";
  124. }
  125. } else {
  126. echo Display::url(
  127. Display::return_icon('stats.png', get_lang('MyStats'),'',ICON_SIZE_MEDIUM),
  128. api_get_path(WEB_CODE_PATH)."auth/my_progress.php"
  129. );
  130. echo Display::url(
  131. Display::return_icon("certificate_list.png", get_lang("GradebookSeeListOfStudentsCertificates"), array(), ICON_SIZE_MEDIUM),
  132. api_get_path(WEB_CODE_PATH) . "gradebook/certificate_report.php"
  133. );
  134. }
  135. // Actions menu
  136. $nb_menu_items = count($menu_items);
  137. if (empty($session_id) ||
  138. in_array($display, array('accessoverview','lpprogressoverview', 'progressoverview', 'exerciseprogress', 'surveyoverview'))
  139. ) {
  140. if ($nb_menu_items > 1) {
  141. foreach ($menu_items as $key => $item) {
  142. echo $item;
  143. }
  144. }
  145. }
  146. echo '</div>';
  147. $userId = api_get_user_id();
  148. $stats = Tracking::getStats($userId);
  149. $students = $stats['students'];
  150. $teachers = $stats['teachers'];
  151. $humanResourcesUsers = $stats['drh'];
  152. $assignedCourses = $stats['assignedCourses'];
  153. $courses = $stats['courses'];
  154. $sessions = $stats['sessions'];
  155. $sessionIdList = array();
  156. if (!empty($sessions)) {
  157. foreach ($sessions as $session) {
  158. $sessionIdList[] = $session['id'];
  159. }
  160. }
  161. // Courses for the user
  162. $countAssignedCourses = count($assignedCourses);
  163. $count_courses = count($courses);
  164. // Sessions for the user
  165. $count_sessions = count($sessions);
  166. $total_time_spent = 0;
  167. $total_courses = 0;
  168. $avg_total_progress = 0;
  169. $avg_results_to_exercises = 0;
  170. $nb_inactive_students = 0;
  171. $nb_posts = $nb_assignments = 0;
  172. $inactiveTime = time() - (3600 * 24 * 7);
  173. $nb_students = 0;
  174. $numberTeachers = 0;
  175. $countHumanResourcesUsers = 0;
  176. $daysAgo = 7;
  177. $studentIds = array();
  178. if (!empty($students)) {
  179. // Students
  180. $nb_students = count($students);
  181. $progress = Tracking::get_avg_student_progress($studentIds);
  182. $countAssignments = Tracking::count_student_assignments($studentIds);
  183. $studentIds = array_values($students);
  184. $countHumanResourcesUsers = count($humanResourcesUsers);
  185. // average progress
  186. $avg_total_progress = $progress / $nb_students;
  187. // average assignments
  188. $nb_assignments = $countAssignments / $nb_students;
  189. $avg_courses_per_student = $count_courses / $nb_students;
  190. }
  191. if (!empty($teachers)) {
  192. $numberTeachers = count($teachers);
  193. }
  194. // Inactive students
  195. //$countInactiveUsers = Tracking::getInactiveUsers($studentIds, $daysAgo);
  196. $totalTimeSpent = Tracking::get_time_spent_on_the_platform($studentIds);
  197. $posts = Tracking::count_student_messages($studentIds);
  198. $averageScore = Tracking::getAverageStudentScore($studentIds);
  199. $avg_results_to_exercises = $averageScore;
  200. // average posts
  201. $nb_posts = $posts;
  202. $avg_time_spent = $totalTimeSpent;
  203. $linkAddUser = null;
  204. $linkCourseDetailsAsTeacher = null;
  205. $linkAddCourse = null;
  206. $linkAddSession = null;
  207. if (api_is_platform_admin()) {
  208. $linkAddUser = ' '.Display::url(
  209. Display::return_icon('2rightarrow.gif', get_lang('Add')),
  210. api_get_path(WEB_CODE_PATH).'admin/dashboard_add_users_to_user.php?user='.api_get_user_id(),
  211. array('class' => '')
  212. );
  213. $linkCourseDetailsAsTeacher = ' '.Display::url(
  214. Display::return_icon('2rightarrow.gif', get_lang('Details')),
  215. api_get_path(WEB_CODE_PATH).'mySpace/course.php',
  216. array('class' => '')
  217. );
  218. $linkAddCourse = ' '.Display::url(
  219. Display::return_icon('2rightarrow.gif', get_lang('Details')),
  220. api_get_path(WEB_CODE_PATH).'mySpace/course.php?follow',
  221. array('class' => '')
  222. );
  223. $linkAddSession = ' '.Display::url(
  224. Display::return_icon('2rightarrow.gif', get_lang('Add')),
  225. api_get_path(WEB_CODE_PATH).'admin/dashboard_add_sessions_to_user.php?user='.api_get_user_id(),
  226. array('class' => '')
  227. );
  228. }
  229. echo Display::page_subheader(get_lang('Overview'));
  230. echo '<div class="report_section">
  231. <table class="table table-bordered table-striped">
  232. <tr>
  233. <td>'.Display::url(
  234. get_lang('FollowedStudents'),
  235. api_get_path(WEB_CODE_PATH).'mySpace/student.php'
  236. ).'</td>
  237. <td align="right">'.$nb_students.'</td>
  238. </tr>
  239. <tr>
  240. <td>'.Display::url(
  241. get_lang('FollowedTeachers'),
  242. api_get_path(WEB_CODE_PATH).'mySpace/teachers.php'
  243. ).
  244. '</td>
  245. <td align="right">'.$numberTeachers.'</td>
  246. </tr>
  247. <tr>
  248. <td>'.Display::url(
  249. get_lang('FollowedHumanResources'),
  250. api_get_path(WEB_CODE_PATH).'mySpace/users.php?status='.DRH
  251. ).
  252. '</td>
  253. <td align="right">'.$countHumanResourcesUsers.'</td>
  254. </tr>
  255. <tr>
  256. <td>'.Display::url(
  257. get_lang('FollowedUsers'),
  258. api_get_path(WEB_CODE_PATH).'mySpace/users.php'
  259. ).
  260. '</td>
  261. <td align="right">'.($nb_students + $numberTeachers + $countHumanResourcesUsers).$linkAddUser.'</td>
  262. </tr>
  263. <tr>
  264. <td>'.Display::url(
  265. get_lang('AssignedCourses'),
  266. api_get_path(WEB_CODE_PATH).'mySpace/course.php'
  267. ).
  268. '</td>
  269. <td align="right">'.$count_courses.$linkCourseDetailsAsTeacher.'</td>
  270. </tr>
  271. <tr>
  272. <td>'.Display::url(
  273. get_lang('FollowedCourses'),
  274. api_get_path(WEB_CODE_PATH).'mySpace/course.php?follow'
  275. ).
  276. '</td>
  277. <td align="right">'.$countAssignedCourses.$linkAddCourse.'</td>
  278. </tr>
  279. <tr>
  280. <td>'.Display::url(
  281. get_lang('FollowedSessions'),
  282. api_get_path(WEB_CODE_PATH).'mySpace/session.php'
  283. ).
  284. '</td>
  285. <td align="right">'.$count_sessions.$linkAddSession.'</td>
  286. </tr>
  287. </table>';
  288. echo '</div>';
  289. echo Display::page_subheader(get_lang('Students').' ('.$nb_students.')');
  290. if ($export_csv) {
  291. //csv part
  292. $csv_content[] = array(get_lang('Students'));
  293. $csv_content[] = array(get_lang('InactivesStudents'), $nb_inactive_students);
  294. $csv_content[] = array(get_lang('AverageTimeSpentOnThePlatform'), $avg_time_spent);
  295. $csv_content[] = array(get_lang('AverageCoursePerStudent'), $avg_courses_per_student);
  296. $csv_content[] = array(get_lang('AverageProgressInLearnpath'), is_null($avg_total_progress) ? null : round($avg_total_progress, 2).'%');
  297. $csv_content[] = array(get_lang('AverageResultsToTheExercices'), is_null($avg_results_to_exercises) ? null : round($avg_results_to_exercises, 2).'%');
  298. $csv_content[] = array(get_lang('AveragePostsInForum'), $nb_posts);
  299. $csv_content[] = array(get_lang('AverageAssignments'), $nb_assignments);
  300. $csv_content[] = array();
  301. } else {
  302. $lastConnectionDate = api_get_utc_datetime(strtotime('15 days ago'));
  303. $countActiveUsers = SessionManager::getCountUserTracking(null, 1, null, array(), array());
  304. $countSleepingTeachers = SessionManager::getTeacherTracking(
  305. api_get_user_id(),
  306. 1,
  307. $lastConnectionDate,
  308. true,
  309. $sessionIdList
  310. );
  311. $countSleepingStudents = SessionManager::getCountUserTracking(
  312. null,
  313. 1,
  314. $lastConnectionDate,
  315. $sessionIdList,
  316. $studentIds
  317. );
  318. $form = new FormValidator('search_user', 'get', api_get_path(WEB_CODE_PATH).'mySpace/student.php');
  319. $form = Tracking::setUserSearchForm($form);
  320. $form->display();
  321. // html part
  322. echo '<div class="report_section">
  323. <table class="table table-bordered table-striped">
  324. <tr>
  325. <td>'.get_lang('AverageCoursePerStudent').'</td>
  326. <td align="right">'.(is_null($avg_courses_per_student) ? '' : round($avg_courses_per_student, 2)).'</td>
  327. </tr>
  328. <tr>
  329. <td>'.get_lang('InactivesStudents').'</td>
  330. <td align="right">'.$nb_inactive_students.'</td>
  331. </tr>
  332. <tr>
  333. <td>'.get_lang('AverageTimeSpentOnThePlatform').'</td>
  334. <td align="right">'.(is_null($avg_time_spent) ? '' : api_time_to_hms($avg_time_spent)).'</td>
  335. </tr>
  336. <tr>
  337. <td>'.get_lang('AverageProgressInLearnpath').'</td>
  338. <td align="right">'.(is_null($avg_total_progress) ? '' : round($avg_total_progress, 2).'%').'</td>
  339. </tr>
  340. <tr>
  341. <td>'.get_lang('AvgCourseScore').'</td>
  342. <td align="right">'.(is_null($avg_results_to_exercises) ? '' : round($avg_results_to_exercises, 2).'%').'</td>
  343. </tr>
  344. <tr>
  345. <td>'.get_lang('AveragePostsInForum').'</td>
  346. <td align="right">'.(is_null($nb_posts) ? '' : round($nb_posts, 2)).'</td>
  347. </tr>
  348. <tr>
  349. <td>'.get_lang('AverageAssignments').'</td>
  350. <td align="right">'.(is_null($nb_assignments) ? '' : round($nb_assignments, 2)).'</td>
  351. </tr>
  352. </table>
  353. </div>';
  354. }
  355. // Send the csv file if asked
  356. if ($export_csv) {
  357. ob_end_clean();
  358. Export :: arrayToCsv($csv_content, 'reporting_index');
  359. exit;
  360. }
  361. if (!$export_csv) {
  362. Display::display_footer();
  363. }