index.php 16 KB

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