index.php 16 KB

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