index.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Homepage for the MySpace directory.
  5. *
  6. * @package chamilo.reporting
  7. */
  8. // resetting the course id
  9. $cidReset = true;
  10. require_once __DIR__.'/../inc/global.inc.php';
  11. // Access control
  12. api_block_anonymous_users();
  13. $htmlHeadXtra[] = api_get_jqgrid_js();
  14. $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_PUBLIC_PATH).'assets/jquery.easy-pie-chart/dist/jquery.easypiechart.js"></script>';
  15. $this_section = SECTION_TRACKING;
  16. ob_start();
  17. $nameTools = get_lang('Reporting');
  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 = [];
  21. $user_id = api_get_user_id();
  22. $session_id = isset($_GET['session_id']) ? (int) $_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. $skipData = api_get_configuration_value('tracking_skip_generic_data');
  28. $logInfo = [
  29. 'tool' => SECTION_TRACKING,
  30. 'tool_id' => 0,
  31. 'tool_id_detail' => 0,
  32. ];
  33. Event::registerLog($logInfo);
  34. $allowToTrack = api_is_platform_admin(true, true) || api_is_teacher();
  35. if (!$allowToTrack) {
  36. api_not_allowed(true);
  37. }
  38. if ($is_session_admin) {
  39. header('location:session.php');
  40. exit;
  41. }
  42. // Get views
  43. $views = ['admin', 'teacher', 'coach', 'drh'];
  44. $view = 'teacher';
  45. if (isset($_GET['view']) && in_array($_GET['view'], $views)) {
  46. $view = $_GET['view'];
  47. }
  48. $menu_items = [];
  49. $pluginCalendar = api_get_plugin_setting('learning_calendar', 'enabled') === 'true';
  50. $calendarMenuAdded = false;
  51. if ($is_platform_admin) {
  52. if ($view == 'admin') {
  53. $menu_items[] = Display::url(
  54. Display::return_icon('teacher.png', get_lang('Trainer View'), [], ICON_SIZE_MEDIUM),
  55. api_get_self().'?view=teacher'
  56. );
  57. $menu_items[] = Display::url(
  58. Display::return_icon('star_na.png', get_lang('Admin view'), [], 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('Exam tracking'), [], 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('Current courses report'), [], 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(
  72. 'teacher_na.png',
  73. get_lang('Trainer View'),
  74. [],
  75. ICON_SIZE_MEDIUM
  76. ),
  77. ''
  78. );
  79. $menu_items[] = Display::url(
  80. Display::return_icon('star.png', get_lang('Admin view'), [], ICON_SIZE_MEDIUM),
  81. //api_get_path(WEB_CODE_PATH).'tracking/course_session_report.php?view=admin'
  82. api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php'
  83. );
  84. $menu_items[] = Display::url(
  85. Display::return_icon('quiz.png', get_lang('Exam tracking'), [], ICON_SIZE_MEDIUM),
  86. api_get_path(WEB_CODE_PATH).'tracking/exams.php'
  87. );
  88. $menu_items[] = Display::url(
  89. Display::return_icon('statistics.png', get_lang('Current courses report'), [], ICON_SIZE_MEDIUM),
  90. api_get_path(WEB_CODE_PATH).'mySpace/current_courses.php'
  91. );
  92. if ($pluginCalendar) {
  93. $lpCalendar = LearningCalendarPlugin::create();
  94. $menu_items[] = Display::url(
  95. Display::return_icon('agenda.png', $lpCalendar->get_lang('Learning calendar'), [], ICON_SIZE_MEDIUM),
  96. api_get_path(WEB_PLUGIN_PATH).'learning_calendar/start.php'
  97. );
  98. $calendarMenuAdded = true;
  99. }
  100. }
  101. }
  102. if ($is_drh) {
  103. $view = 'drh';
  104. $menu_items[] = Display::url(
  105. Display::return_icon('user_na.png', get_lang('Learners'), [], ICON_SIZE_MEDIUM),
  106. '#'
  107. );
  108. $menu_items[] = Display::url(
  109. Display::return_icon('teacher.png', get_lang('Teachers'), [], ICON_SIZE_MEDIUM),
  110. 'teachers.php'
  111. );
  112. $menu_items[] = Display::url(
  113. Display::return_icon('course.png', get_lang('Courses'), [], ICON_SIZE_MEDIUM),
  114. 'course.php'
  115. );
  116. $menu_items[] = Display::url(
  117. Display::return_icon('session.png', get_lang('Course sessions'), [], ICON_SIZE_MEDIUM),
  118. 'session.php'
  119. );
  120. $menu_items[] = Display::url(
  121. Display::return_icon('empty_evaluation.png', get_lang('Corporate report'), [], ICON_SIZE_MEDIUM),
  122. 'company_reports.php'
  123. );
  124. $menu_items[] = Display::url(
  125. Display::return_icon('evaluation_rate.png', get_lang('Corporate reportResumed'), [], ICON_SIZE_MEDIUM),
  126. 'company_reports_resumed.php'
  127. );
  128. }
  129. $actionsRight = '';
  130. $actionsLeft = '';
  131. if ($display == 'useroverview' || $display == 'sessionoverview' || $display == 'courseoverview') {
  132. $actionsRight .= Display::url(
  133. Display::return_icon(
  134. 'export_csv.png',
  135. get_lang('CSV export'),
  136. null,
  137. ICON_SIZE_MEDIUM
  138. ),
  139. api_get_self().'?display='.$display.'&export=csv&view='.$view
  140. );
  141. }
  142. $actionsRight .= Display::url(
  143. Display::return_icon(
  144. 'printer.png',
  145. get_lang('Print'),
  146. null,
  147. ICON_SIZE_MEDIUM
  148. ),
  149. 'javascript: void(0);',
  150. ['onclick' => 'javascript: window.print()']
  151. );
  152. if (!empty($session_id) &&
  153. !in_array(
  154. $display,
  155. ['accessoverview', 'lpprogressoverview', 'progressoverview', 'exerciseprogress', 'surveyoverview']
  156. )
  157. ) {
  158. $actionsLeft .= Display::url(
  159. Display::return_icon(
  160. 'back.png',
  161. get_lang('Back'),
  162. null,
  163. ICON_SIZE_MEDIUM
  164. ),
  165. 'index.php'
  166. );
  167. if (!api_is_platform_admin()) {
  168. if (api_get_setting('add_users_by_coach') == 'true') {
  169. if ($is_coach) {
  170. $actionsLeft .= Display::url(
  171. Display::return_icon(
  172. 'excel.png',
  173. get_lang('Import list of users'),
  174. null,
  175. ICON_SIZE_MEDIUM
  176. ),
  177. 'user_import.php?id_session='.$session_id.'&action=export&amp;type=xml'
  178. );
  179. }
  180. }
  181. } else {
  182. Display::url(
  183. Display::return_icon(
  184. 'excel.png',
  185. get_lang('Import list of users'),
  186. null,
  187. ICON_SIZE_MEDIUM
  188. ),
  189. 'user_import.php?id_session='.$session_id.'&action=export&amp;type=xml'
  190. );
  191. }
  192. } else {
  193. $actionsLeft .= Display::url(
  194. Display::return_icon(
  195. 'statistics.png',
  196. get_lang('View my progress'),
  197. null,
  198. ICON_SIZE_MEDIUM
  199. ),
  200. api_get_path(WEB_CODE_PATH).'auth/my_progress.php'
  201. );
  202. if ($pluginCalendar && api_is_teacher() && $calendarMenuAdded === false) {
  203. $lpCalendar = LearningCalendarPlugin::create();
  204. $actionsLeft .= Display::url(
  205. Display::return_icon('agenda.png', $lpCalendar->get_lang('Learning calendar'), [], ICON_SIZE_MEDIUM),
  206. api_get_path(WEB_PLUGIN_PATH).'learning_calendar/start.php'
  207. );
  208. }
  209. if (api_is_platform_admin(true) || api_is_student_boss()) {
  210. $actionsLeft .= Display::url(
  211. Display::return_icon(
  212. "certificate_list.png",
  213. get_lang('GradebookSeeListOfLearnersCertificates'),
  214. null,
  215. ICON_SIZE_MEDIUM
  216. ),
  217. api_get_path(WEB_CODE_PATH).'gradebook/certificate_report.php'
  218. );
  219. }
  220. }
  221. // Actions menu
  222. $nb_menu_items = count($menu_items);
  223. if (empty($session_id) ||
  224. in_array(
  225. $display,
  226. ['accessoverview', 'lpprogressoverview', 'progressoverview', 'exerciseprogress', 'surveyoverview']
  227. )
  228. ) {
  229. if ($nb_menu_items > 1) {
  230. foreach ($menu_items as $key => $item) {
  231. $actionsLeft .= $item;
  232. }
  233. }
  234. }
  235. $userId = api_get_user_id();
  236. $stats = Tracking::getStats($userId, true);
  237. $numberStudents = $stats['student_count'];
  238. $students = $stats['student_list'];
  239. $numberStudentBosses = $stats['student_bosses'];
  240. $numberTeachers = $stats['teachers'];
  241. $countHumanResourcesUsers = $stats['drh'];
  242. $countAssignedCourses = $stats['assigned_courses'];
  243. $countCourses = $stats['courses'];
  244. $sessions = $stats['session_list'];
  245. $sessionIdList = [];
  246. if (!empty($sessions)) {
  247. foreach ($sessions as $session) {
  248. $sessionIdList[] = $session['id'];
  249. }
  250. }
  251. // Sessions for the user
  252. $countSessions = count($sessions);
  253. $total_time_spent = 0;
  254. $total_courses = 0;
  255. $avgTotalProgress = 0;
  256. $nb_inactive_students = 0;
  257. $numberAssignments = 0;
  258. $inactiveTime = time() - (3600 * 24 * 7);
  259. $daysAgo = 7;
  260. $studentIds = [];
  261. $avg_courses_per_student = 0;
  262. $view = new Template($nameTools);
  263. $view->assign('students', $numberStudents);
  264. $view->assign('studentbosses', $numberStudentBosses);
  265. $view->assign('numberTeachers', $numberTeachers);
  266. $view->assign('humanresources', $countHumanResourcesUsers);
  267. $view->assign(
  268. 'total_user',
  269. $numberStudents + $numberStudentBosses + $numberTeachers + $countHumanResourcesUsers
  270. );
  271. $view->assign('studentboss', STUDENT_BOSS);
  272. $view->assign('drh', DRH);
  273. $view->assign('stats', $stats);
  274. $form = new FormValidator(
  275. 'search_user',
  276. 'get',
  277. api_get_path(WEB_CODE_PATH).'mySpace/student.php'
  278. );
  279. $form = Tracking::setUserSearchForm($form);
  280. $totalTimeSpent = null;
  281. $averageScore = null;
  282. $posts = null;
  283. if ($skipData === false) {
  284. if (!empty($students)) {
  285. // Students
  286. $studentIds = array_values($students);
  287. $progress = Tracking::get_avg_student_progress($studentIds);
  288. $countAssignments = Tracking::count_student_assignments($studentIds);
  289. // average progress
  290. $avgTotalProgress = $progress / $numberStudents;
  291. // average assignments
  292. $numberAssignments = $countAssignments / $numberStudents;
  293. $avg_courses_per_student = $countCourses / $numberStudents;
  294. $totalTimeSpent = Tracking::get_time_spent_on_the_platform($studentIds);
  295. $posts = Tracking::count_student_messages($studentIds);
  296. $averageScore = Tracking::getAverageStudentScore($studentIds);
  297. }
  298. if ($export_csv) {
  299. //csv part
  300. $csv_content[] = [get_lang('Learners')];
  301. $csv_content[] = [get_lang('InactivesLearners'), $nb_inactive_students];
  302. $csv_content[] = [get_lang('Time spent on portal'), $totalTimeSpent];
  303. $csv_content[] = [get_lang('Average number of courses to which my learners are subscribed'), round($avg_courses_per_student, 3)];
  304. $csv_content[] = [
  305. get_lang('Progress in courses'),
  306. is_null($avgTotalProgress)
  307. ? null
  308. : round($avgTotalProgress, 2).'%',
  309. ];
  310. $csv_content[] = [
  311. get_lang('Tests score'),
  312. is_null($averageScore)
  313. ? null
  314. : round($averageScore, 2).'%',
  315. ];
  316. $csv_content[] = [get_lang('Posts in forum'), $posts];
  317. $csv_content[] = [get_lang('Average assignments per learner'), $numberAssignments];
  318. $csv_content[] = [];
  319. } else {
  320. $lastConnectionDate = api_get_utc_datetime(strtotime('15 days ago'));
  321. $countActiveUsers = SessionManager::getCountUserTracking(
  322. null,
  323. 1,
  324. null,
  325. [],
  326. []
  327. );
  328. $countSleepingTeachers = SessionManager::getTeacherTracking(
  329. api_get_user_id(),
  330. 1,
  331. $lastConnectionDate,
  332. true,
  333. $sessionIdList
  334. );
  335. $countSleepingStudents = SessionManager::getCountUserTracking(
  336. null,
  337. 1,
  338. $lastConnectionDate,
  339. $sessionIdList,
  340. $studentIds
  341. );
  342. $report['AverageCoursePerStudent'] = is_null($avg_courses_per_student)
  343. ? ''
  344. : round($avg_courses_per_student, 3);
  345. $report['InactivesStudents'] = $nb_inactive_students;
  346. $report['AverageTimeSpentOnThePlatform'] = is_null($totalTimeSpent)
  347. ? '00:00:00'
  348. : api_time_to_hms($totalTimeSpent);
  349. $report['AverageProgressInLearnpath'] = is_null($avgTotalProgress)
  350. ? ''
  351. : round($avgTotalProgress, 2).'%';
  352. $report['AvgCourseScore'] = is_null($averageScore) ? '0' : round($averageScore, 2).'%';
  353. $report['AveragePostsInForum'] = is_null($posts) ? '0' : round($posts, 2);
  354. $report['AverageAssignments'] = is_null($numberAssignments) ? '' : round($numberAssignments, 2);
  355. $view->assign('report', $report);
  356. }
  357. }
  358. $view->assign('header', $nameTools);
  359. $view->assign('form', $form->returnForm());
  360. $view->assign('actions', Display::toolbarAction('toolbar', [$actionsLeft, $actionsRight]));
  361. $view->assign('title', get_lang('Students').' ('.$numberStudents.')');
  362. $template = $view->get_template('my_space/index.tpl');
  363. $content = $view->fetch($template);
  364. $view->assign('content', $content);
  365. $view->display_one_col_template();
  366. // Send the csv file if asked
  367. if ($export_csv) {
  368. ob_end_clean();
  369. Export:: arrayToCsv($csv_content, 'reporting_index');
  370. exit;
  371. }