courseLog.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
  4. use ChamiloSession as Session;
  5. /**
  6. * @package chamilo.tracking
  7. */
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. $current_course_tool = TOOL_TRACKING;
  10. $courseId = api_get_course_id();
  11. $courseInfo = api_get_course_info($courseId);
  12. //keep course_code form as it is loaded (global) by the table's get_user_data
  13. $course_code = $courseCode = $courseInfo['code'];
  14. $session_id = $sessionId = api_get_session_id();
  15. $from_myspace = false;
  16. $from = isset($_GET['from']) ? $_GET['from'] : null;
  17. // Starting the output buffering when we are exporting the information.
  18. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  19. $htmlHeadXtra[] = api_get_js('chartjs/Chart.min.js');
  20. $htmlHeadXtra[] = ' ';
  21. $this_section = SECTION_COURSES;
  22. if ($from == 'myspace') {
  23. $from_myspace = true;
  24. $this_section = 'session_my_space';
  25. }
  26. // Access restrictions.
  27. $is_allowedToTrack = Tracking::isAllowToTrack($session_id);
  28. if (!$is_allowedToTrack) {
  29. api_not_allowed(true);
  30. }
  31. // If the user is a HR director (drh)
  32. if (api_is_drh()) {
  33. // Blocking course for drh
  34. if (api_drh_can_access_all_session_content()) {
  35. // If the drh has been configured to be allowed to see all session content, give him access to the session courses
  36. $coursesFromSession = SessionManager::getAllCoursesFollowedByUser(
  37. api_get_user_id(),
  38. null
  39. );
  40. $coursesFromSessionCodeList = [];
  41. if (!empty($coursesFromSession)) {
  42. foreach ($coursesFromSession as $course) {
  43. $coursesFromSessionCodeList[$course['code']] = $course['code'];
  44. }
  45. }
  46. $coursesFollowedList = CourseManager::get_courses_followed_by_drh(api_get_user_id());
  47. if (!empty($coursesFollowedList)) {
  48. $coursesFollowedList = array_keys($coursesFollowedList);
  49. }
  50. if (!in_array($courseCode, $coursesFollowedList)) {
  51. if (!in_array($courseCode, $coursesFromSessionCodeList)) {
  52. api_not_allowed();
  53. }
  54. }
  55. } else {
  56. // If the drh has *not* been configured to be allowed to see all session content,
  57. // then check if he has also been given access to the corresponding courses
  58. $coursesFollowedList = CourseManager::get_courses_followed_by_drh(api_get_user_id());
  59. $coursesFollowedList = array_keys($coursesFollowedList);
  60. if (!in_array($courseId, $coursesFollowedList)) {
  61. api_not_allowed(true);
  62. }
  63. }
  64. }
  65. if ($export_csv) {
  66. if (!empty($session_id)) {
  67. Session::write('id_session', $session_id);
  68. }
  69. ob_start();
  70. }
  71. $columnsToHideFromSetting = api_get_configuration_value('course_log_hide_columns');
  72. $columnsToHide = [0, 8, 9, 10, 11];
  73. if (!empty($columnsToHideFromSetting) && isset($columnsToHideFromSetting['columns'])) {
  74. $columnsToHide = $columnsToHideFromSetting['columns'];
  75. }
  76. $columnsToHide = json_encode($columnsToHide);
  77. $csv_content = [];
  78. // Scripts for reporting array hide/show columns
  79. $js = "<script>
  80. // hide column and display the button to unhide it
  81. function foldup(id) {
  82. $('#reporting_table .data_table tr td:nth-child(' + (id + 1) + ')').toggleClass('hide');
  83. $('#reporting_table .data_table tr th:nth-child(' + (id + 1) + ')').toggleClass('hide');
  84. $('div#unhideButtons a:nth-child(' + (id + 1) + ')').toggleClass('hide');
  85. }
  86. // add the red cross on top of each column
  87. function init_hide() {
  88. $('#reporting_table .data_table tr th').each(
  89. function(index) {
  90. $(this).prepend(
  91. '<div style=\"cursor:pointer\" onclick=\"foldup(' + index + ')\">".Display::return_icon(
  92. 'visible.png',
  93. get_lang('HideColumn'),
  94. ['align' => 'absmiddle', 'hspace' => '3px'],
  95. ICON_SIZE_SMALL
  96. )."</div>'
  97. );
  98. }
  99. );
  100. }
  101. // hide some column at startup
  102. // be sure that these columns always exists
  103. // see headers = array();
  104. // tab of header texts
  105. $(document).ready( function() {
  106. init_hide();
  107. var columnsToHide = ".$columnsToHide.";
  108. if (columnsToHide) {
  109. columnsToHide.forEach(function(id) {
  110. foldup(id);
  111. });
  112. }
  113. })
  114. </script>";
  115. $htmlHeadXtra[] = $js;
  116. // Database table definitions.
  117. //@todo remove this calls
  118. $TABLETRACK_DOWNLOADS = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  119. $TABLETRACK_EXERCISES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  120. $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  121. $TABLECOURSE = Database::get_main_table(TABLE_MAIN_COURSE);
  122. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  123. $TABLEQUIZ = Database::get_course_table(TABLE_QUIZ_TEST);
  124. // Breadcrumbs.
  125. if (isset($_GET['origin']) && $_GET['origin'] == 'resume_session') {
  126. $interbreadcrumb[] = [
  127. 'url' => '../admin/index.php',
  128. 'name' => get_lang('PlatformAdmin'),
  129. ];
  130. $interbreadcrumb[] = [
  131. 'url' => '../session/session_list.php',
  132. 'name' => get_lang('SessionList'),
  133. ];
  134. $interbreadcrumb[] = [
  135. 'url' => '../session/resume_session.php?id_session='.$sessionId,
  136. 'name' => get_lang('SessionOverview'),
  137. ];
  138. }
  139. $view = isset($_REQUEST['view']) ? $_REQUEST['view'] : '';
  140. $nameTools = get_lang('Tracking');
  141. //Template Tracking
  142. $tpl = new Template($nameTools);
  143. // getting all the students of the course
  144. if (empty($session_id)) {
  145. // Registered students in a course outside session.
  146. $a_students = CourseManager::get_student_list_from_course_code($courseId);
  147. } else {
  148. // Registered students in session.
  149. $a_students = CourseManager::get_student_list_from_course_code($courseId, true, $sessionId);
  150. }
  151. $nbStudents = count($a_students);
  152. $user_ids = array_keys($a_students);
  153. $extra_info = [];
  154. $userProfileInfo = [];
  155. // Getting all the additional information of an additional profile field.
  156. if (isset($_GET['additional_profile_field'])) {
  157. $user_array = [];
  158. foreach ($a_students as $key => $item) {
  159. $user_array[] = $key;
  160. }
  161. foreach ($_GET['additional_profile_field'] as $fieldId) {
  162. // Fetching only the user that are loaded NOT ALL user in the portal.
  163. $userProfileInfo[$fieldId] = TrackingCourseLog::getAdditionalProfileInformationOfFieldByUser(
  164. $fieldId,
  165. $user_array
  166. );
  167. $extra_info[$fieldId] = UserManager::get_extra_field_information(
  168. $fieldId
  169. );
  170. }
  171. }
  172. Session::write('additional_user_profile_info', $userProfileInfo);
  173. Session::write('extra_field_info', $extra_info);
  174. // Display the header.
  175. Display::display_header($nameTools, 'Tracking');
  176. /* MAIN CODE */
  177. $actionsLeft = TrackingCourseLog::actionsLeft('users', $sessionId);
  178. $actionsRight = '<div class="pull-right">';
  179. $actionsRight .= '<a href="javascript: void(0);" onclick="javascript: window.print();">'.
  180. Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_MEDIUM).'</a>';
  181. $addional_param = '';
  182. if (isset($_GET['additional_profile_field'])) {
  183. foreach ($_GET['additional_profile_field'] as $fieldId) {
  184. $addional_param .= '&additional_profile_field[]='.(int) $fieldId;
  185. }
  186. }
  187. $users_tracking_per_page = '';
  188. if (isset($_GET['users_tracking_per_page'])) {
  189. $users_tracking_per_page = '&users_tracking_per_page='.intval($_GET['users_tracking_per_page']);
  190. }
  191. $actionsRight .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&export=csv&'.$addional_param.$users_tracking_per_page.'">
  192. '.Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), '', ICON_SIZE_MEDIUM).'</a>';
  193. $actionsRight .= '</div>';
  194. // Create a search-box.
  195. $form_search = new FormValidator(
  196. 'search_simple',
  197. 'GET',
  198. api_get_path(WEB_CODE_PATH).'tracking/courseLog.php?'.api_get_cidreq(),
  199. '',
  200. [],
  201. FormValidator::LAYOUT_INLINE
  202. );
  203. $form_search->addHidden('from', Security::remove_XSS($from));
  204. $form_search->addHidden('session_id', $sessionId);
  205. $form_search->addHidden('id_session', $sessionId);
  206. $form_search->addElement('text', 'user_keyword');
  207. $form_search->addButtonSearch(get_lang('SearchUsers'));
  208. echo Display::toolbarAction(
  209. 'toolbar-courselog',
  210. [$actionsLeft, $form_search->returnForm(), $actionsRight]
  211. );
  212. $course_name = get_lang('Course').' '.$courseInfo['name'];
  213. if ($session_id) {
  214. $titleSession = Display::return_icon(
  215. 'session.png',
  216. get_lang('Session'),
  217. [],
  218. ICON_SIZE_SMALL
  219. ).' '.api_get_session_name($session_id);
  220. $titleCourse = Display::return_icon(
  221. 'course.png',
  222. get_lang('Course'),
  223. [],
  224. ICON_SIZE_SMALL
  225. ).' '.$course_name;
  226. } else {
  227. $titleSession = Display::return_icon(
  228. 'course.png',
  229. get_lang('Course'),
  230. [],
  231. ICON_SIZE_SMALL
  232. ).' '.$courseInfo['name'];
  233. }
  234. $teacherList = CourseManager::getTeacherListFromCourseCodeToString(
  235. $courseInfo['code'],
  236. ',',
  237. true,
  238. true
  239. );
  240. $coaches = null;
  241. if (!empty($session_id)) {
  242. $coaches = CourseManager::get_coachs_from_course_to_string(
  243. $session_id,
  244. $courseInfo['real_id'],
  245. ',',
  246. true,
  247. true
  248. );
  249. }
  250. $html = '';
  251. if (!empty($teacherList)) {
  252. $html .= Display::page_subheader2(get_lang('Teachers'));
  253. $html .= $teacherList;
  254. }
  255. if (!empty($coaches)) {
  256. $html .= Display::page_subheader2(get_lang('Coaches'));
  257. $html .= $coaches;
  258. }
  259. $showReporting = api_get_configuration_value('hide_reporting_session_list') === false;
  260. if ($showReporting) {
  261. $sessionList = SessionManager::get_session_by_course($courseInfo['real_id']);
  262. if (!empty($sessionList)) {
  263. $html .= Display::page_subheader2(get_lang('SessionList'));
  264. $icon = Display::return_icon(
  265. 'session.png',
  266. null,
  267. null,
  268. ICON_SIZE_TINY
  269. );
  270. $html .= '<ul class="session-list">';
  271. $urlWebCode = api_get_path(WEB_CODE_PATH);
  272. $isAdmin = api_is_platform_admin();
  273. foreach ($sessionList as $session) {
  274. if (!$isAdmin) {
  275. // Check session visibility
  276. $visibility = api_get_session_visibility($session['id'], api_get_course_int_id());
  277. if ($visibility == SESSION_INVISIBLE) {
  278. continue;
  279. }
  280. // Check if is coach
  281. $isCoach = api_is_coach($session['id'], api_get_course_int_id());
  282. if (!$isCoach) {
  283. continue;
  284. }
  285. }
  286. $url = $urlWebCode.'mySpace/course.php?session_id='.$session['id'].'&cidReq='.$courseInfo['code'];
  287. $html .= Display::tag('li', $icon.' '.Display::url($session['name'], $url));
  288. }
  289. $html .= '</ul>';
  290. }
  291. }
  292. //Load Orden
  293. $trackingColumn = isset($_GET['users_tracking_column']) ? $_GET['users_tracking_column'] : null;
  294. $trackingDirection = isset($_GET['users_tracking_direction']) ? $_GET['users_tracking_direction'] : null;
  295. // Show the charts part only if there are students subscribed to this course/session
  296. if ($nbStudents > 0) {
  297. $usersTracking = TrackingCourseLog::get_user_data(null, $nbStudents, $trackingColumn, $trackingDirection, false);
  298. $numberStudentsCompletedLP = 0;
  299. $averageStudentsTestScore = 0;
  300. $scoresDistribution = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
  301. $userScoreList = [];
  302. $listStudentIds = [];
  303. $timeStudent = [];
  304. $certificateCount = 0;
  305. $category = Category::load(
  306. null,
  307. null,
  308. $course_code,
  309. null,
  310. null,
  311. $session_id
  312. );
  313. foreach ($usersTracking as $userTracking) {
  314. $userInfo = api_get_user_info_from_username($userTracking[3]);
  315. if (empty($userInfo)) {
  316. continue;
  317. }
  318. $userId = $userInfo['user_id'];
  319. if ($userTracking[5] === '100%') {
  320. $numberStudentsCompletedLP++;
  321. }
  322. $averageStudentTestScore = substr($userTracking[7], 0, -1);
  323. $averageStudentsTestScore += $averageStudentTestScore;
  324. if ($averageStudentTestScore === '100') {
  325. $reducedAverage = 9;
  326. } else {
  327. $reducedAverage = floor($averageStudentTestScore / 10);
  328. }
  329. if (isset($scoresDistribution[$reducedAverage])) {
  330. $scoresDistribution[$reducedAverage]++;
  331. }
  332. $scoreStudent = substr($userTracking[5], 0, -1) + substr($userTracking[7], 0, -1);
  333. list($hours, $minutes, $seconds) = preg_split('/:/', $userTracking[4]);
  334. $minutes = round((3600 * $hours + 60 * $minutes + $seconds) / 60);
  335. $certificate = false;
  336. if (isset($category[0]) && $category[0]->is_certificate_available($userId)) {
  337. $certificate = true;
  338. $certificateCount++;
  339. }
  340. $listStudent = [
  341. 'id' => $userId,
  342. 'fullname' => $userInfo['complete_name'],
  343. 'score' => floor($scoreStudent / 2),
  344. 'total_time' => $minutes,
  345. 'avatar' => $userInfo['avatar'],
  346. 'certicate' => $certificate,
  347. ];
  348. $listStudentIds[] = $userId;
  349. $userScoreList[] = $listStudent;
  350. }
  351. uasort($userScoreList, 'sort_by_order');
  352. $averageStudentsTestScore = round($averageStudentsTestScore / $nbStudents);
  353. $colors = ChamiloApi::getColorPalette(true, true, 10);
  354. $tpl->assign('chart_colors', json_encode($colors));
  355. $tpl->assign('certificate_count', $certificateCount);
  356. $tpl->assign('score_distribution', json_encode($scoresDistribution));
  357. $tpl->assign('json_time_student', json_encode($userScoreList));
  358. $tpl->assign('students_test_score', $averageStudentsTestScore);
  359. $tpl->assign('students_completed_lp', $numberStudentsCompletedLP);
  360. $tpl->assign('number_students', $nbStudents);
  361. $tpl->assign('top_students', $userScoreList);
  362. $trackingSummaryLayout = $tpl->get_template('tracking/tracking_course_log.tpl');
  363. $content = $tpl->fetch($trackingSummaryLayout);
  364. echo $content;
  365. }
  366. $html .= Display::page_subheader2(get_lang('StudentList'));
  367. // PERSON_NAME_DATA_EXPORT is buggy
  368. $sortByFirstName = api_sort_by_first_name();
  369. if (count($a_students) > 0) {
  370. $getLangXDays = get_lang('XDays');
  371. $form = new FormValidator(
  372. 'reminder_form',
  373. 'get',
  374. api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.api_get_cidreq(),
  375. null,
  376. ['style' => 'margin-bottom: 10px'],
  377. FormValidator::LAYOUT_INLINE
  378. );
  379. $options = [
  380. 2 => sprintf($getLangXDays, 2),
  381. 3 => sprintf($getLangXDays, 3),
  382. 4 => sprintf($getLangXDays, 4),
  383. 5 => sprintf($getLangXDays, 5),
  384. 6 => sprintf($getLangXDays, 6),
  385. 7 => sprintf($getLangXDays, 7),
  386. 15 => sprintf($getLangXDays, 15),
  387. 30 => sprintf($getLangXDays, 30),
  388. 'never' => get_lang('Never'),
  389. ];
  390. $el = $form->addSelect(
  391. 'since',
  392. Display::returnFontAwesomeIcon('warning').get_lang('RemindInactivesLearnersSince'),
  393. $options,
  394. ['class' => 'col-sm-3']
  395. );
  396. $el->setSelected(7);
  397. $form->addElement('hidden', 'action', 'add');
  398. $form->addElement('hidden', 'remindallinactives', 'true');
  399. $form->addElement('hidden', 'cidReq', $courseInfo['code']);
  400. $form->addElement('hidden', 'id_session', api_get_session_id());
  401. $form->addButtonSend(get_lang('SendNotification'));
  402. $extra_field_select = TrackingCourseLog::display_additional_profile_fields();
  403. if (!empty($extra_field_select)) {
  404. $html .= $extra_field_select;
  405. }
  406. $html .= $form->returnForm();
  407. if ($export_csv) {
  408. $csv_content = [];
  409. //override the SortableTable "per page" limit if CSV
  410. $_GET['users_tracking_per_page'] = 1000000;
  411. }
  412. $all_datas = [];
  413. $course_code = $_course['id'];
  414. $table = new SortableTable(
  415. 'users_tracking',
  416. ['TrackingCourseLog', 'get_number_of_users'],
  417. function () use ($usersTracking) {
  418. return $usersTracking;
  419. },
  420. 1
  421. );
  422. $parameters['cidReq'] = isset($_GET['cidReq']) ? Security::remove_XSS($_GET['cidReq']) : '';
  423. $parameters['id_session'] = $session_id;
  424. $parameters['from'] = isset($_GET['myspace']) ? Security::remove_XSS($_GET['myspace']) : null;
  425. $table->set_additional_parameters($parameters);
  426. $headers = [];
  427. // tab of header texts
  428. $table->set_header(0, get_lang('OfficialCode'), true);
  429. $headers['official_code'] = get_lang('OfficialCode');
  430. if ($sortByFirstName) {
  431. $table->set_header(1, get_lang('FirstName'), true);
  432. $table->set_header(2, get_lang('LastName'), true);
  433. $headers['firstname'] = get_lang('FirstName');
  434. $headers['lastname'] = get_lang('LastName');
  435. } else {
  436. $table->set_header(1, get_lang('LastName'), true);
  437. $table->set_header(2, get_lang('FirstName'), true);
  438. $headers['lastname'] = get_lang('LastName');
  439. $headers['firstname'] = get_lang('FirstName');
  440. }
  441. $table->set_header(3, get_lang('Login'), false);
  442. $headers['login'] = get_lang('Login');
  443. $table->set_header(
  444. 4,
  445. get_lang('TrainingTime').'&nbsp;'.
  446. Display::return_icon('info3.gif', get_lang('CourseTimeInfo'), ['align' => 'absmiddle', 'hspace' => '3px']),
  447. false,
  448. ['style' => 'width:110px;']
  449. );
  450. $headers['training_time'] = get_lang('TrainingTime');
  451. $table->set_header(5, get_lang('CourseProgress').'&nbsp;'.
  452. Display::return_icon(
  453. 'info3.gif',
  454. get_lang('ScormAndLPProgressTotalAverage'),
  455. ['align' => 'absmiddle', 'hspace' => '3px']
  456. ),
  457. false,
  458. ['style' => 'width:110px;']
  459. );
  460. $headers['course_progress'] = get_lang('CourseProgress');
  461. $table->set_header(6, get_lang('ExerciseProgress').'&nbsp;'.
  462. Display::return_icon(
  463. 'info3.gif',
  464. get_lang('ExerciseProgressInfo'),
  465. ['align' => 'absmiddle', 'hspace' => '3px']
  466. ),
  467. false,
  468. ['style' => 'width:110px;']
  469. );
  470. $headers['exercise_progress'] = get_lang('ExerciseProgress');
  471. $table->set_header(7, get_lang('ExerciseAverage').'&nbsp;'.
  472. Display::return_icon('info3.gif', get_lang('ExerciseAverageInfo'), ['align' => 'absmiddle', 'hspace' => '3px']),
  473. false,
  474. ['style' => 'width:110px;']
  475. );
  476. $headers['exercise_average'] = get_lang('ExerciseAverage');
  477. $table->set_header(8, get_lang('Score').'&nbsp;'.
  478. Display::return_icon(
  479. 'info3.gif',
  480. get_lang('ScormAndLPTestTotalAverage'),
  481. ['align' => 'absmiddle', 'hspace' => '3px']
  482. ),
  483. false,
  484. ['style' => 'width:110px;']
  485. );
  486. $headers['score'] = get_lang('Score');
  487. $table->set_header(9, get_lang('Student_publication'), false);
  488. $headers['student_publication'] = get_lang('Student_publication');
  489. $table->set_header(10, get_lang('Messages'), false);
  490. $headers['messages'] = get_lang('Messages');
  491. $table->set_header(11, get_lang('Classes'));
  492. $headers['clasess'] = get_lang('Classes');
  493. if (empty($session_id)) {
  494. $table->set_header(12, get_lang('Survey'), false);
  495. $headers['survey'] = get_lang('Survey');
  496. $table->set_header(13, get_lang('FirstLoginInCourse'), false);
  497. $headers['first_login'] = get_lang('FirstLoginInCourse');
  498. $table->set_header(14, get_lang('LatestLoginInCourse'), false);
  499. $headers['latest_login'] = get_lang('LatestLoginInCourse');
  500. if (isset($_GET['additional_profile_field'])) {
  501. $counter = 15;
  502. foreach ($_GET['additional_profile_field'] as $fieldId) {
  503. $table->set_header($counter, $extra_info[$fieldId]['display_text'], false);
  504. $headers[$extra_info[$fieldId]['variable']] = $extra_info[$fieldId]['display_text'];
  505. $counter++;
  506. }
  507. $table->set_header($counter, get_lang('Details'), false);
  508. $headers['details'] = get_lang('Details');
  509. } else {
  510. $table->set_header(15, get_lang('Details'), false);
  511. $headers['details'] = get_lang('Details');
  512. }
  513. } else {
  514. $table->set_header(12, get_lang('FirstLoginInCourse'), false);
  515. $headers['first_login'] = get_lang('FirstLoginInCourse');
  516. $table->set_header(13, get_lang('LatestLoginInCourse'), false);
  517. $headers['latest_login'] = get_lang('LatestLoginInCourse');
  518. if (isset($_GET['additional_profile_field'])) {
  519. $counter = 15;
  520. foreach ($_GET['additional_profile_field'] as $fieldId) {
  521. $table->set_header($counter, $extra_info[$fieldId]['display_text'], false);
  522. $headers[$extra_info[$fieldId]['variable']] = $extra_info[$fieldId]['display_text'];
  523. $counter++;
  524. }
  525. } else {
  526. $table->set_header(14, get_lang('Details'), false);
  527. $headers['Details'] = get_lang('Details');
  528. }
  529. }
  530. // display buttons to un hide hidden columns
  531. $html .= '<div id="unhideButtons" class="btn-toolbar">';
  532. $index = 0;
  533. $getLangDisplayColumn = get_lang('DisplayColumn');
  534. foreach ($headers as $header) {
  535. $html .= Display::toolbarButton(
  536. $header,
  537. '#',
  538. 'arrow-right',
  539. 'default',
  540. [
  541. 'title' => htmlentities("$getLangDisplayColumn \"$header\"", ENT_QUOTES),
  542. 'class' => 'hide',
  543. 'onclick' => "foldup($index); return false;",
  544. ]
  545. );
  546. $index++;
  547. }
  548. $html .= "</div>";
  549. // Display the table
  550. $html .= "<div id='reporting_table'>";
  551. $html .= $table->return_table();
  552. $html .= "</div>";
  553. } else {
  554. $html .= Display::return_message(get_lang('NoUsersInCourse'), 'warning', true);
  555. }
  556. echo Display::panel($html, $titleSession);
  557. // Send the csv file if asked.
  558. if ($export_csv) {
  559. $csv_headers = [];
  560. $csv_headers[] = get_lang('OfficialCode');
  561. if ($sortByFirstName) {
  562. $csv_headers[] = get_lang('FirstName');
  563. $csv_headers[] = get_lang('LastName');
  564. } else {
  565. $csv_headers[] = get_lang('LastName');
  566. $csv_headers[] = get_lang('FirstName');
  567. }
  568. $csv_headers[] = get_lang('Login');
  569. $csv_headers[] = get_lang('TrainingTime');
  570. $csv_headers[] = get_lang('CourseProgress');
  571. $csv_headers[] = get_lang('ExerciseProgress');
  572. $csv_headers[] = get_lang('ExerciseAverage');
  573. $csv_headers[] = get_lang('Score');
  574. $csv_headers[] = get_lang('Student_publication');
  575. $csv_headers[] = get_lang('Messages');
  576. if (empty($session_id)) {
  577. $csv_headers[] = get_lang('Survey');
  578. }
  579. $csv_headers[] = get_lang('FirstLoginInCourse');
  580. $csv_headers[] = get_lang('LatestLoginInCourse');
  581. if (isset($_GET['additional_profile_field'])) {
  582. foreach ($_GET['additional_profile_field'] as $fieldId) {
  583. $csv_headers[] = $extra_info[$fieldId]['display_text'];
  584. }
  585. }
  586. ob_end_clean();
  587. $csvContentInSession = Session::read('csv_content');
  588. // Adding headers before the content.
  589. array_unshift($csvContentInSession, $csv_headers);
  590. if ($session_id) {
  591. $sessionData = [];
  592. $sessionInfo = api_get_session_info($session_id);
  593. $sessionDates = SessionManager::parseSessionDates($sessionInfo);
  594. array_unshift($csvContentInSession, [get_lang('Date'), $sessionDates['access']]);
  595. array_unshift($csvContentInSession, [get_lang('SessionName'), $sessionInfo['name']]);
  596. }
  597. Export::arrayToCsv($csvContentInSession, 'reporting_student_list');
  598. exit;
  599. }
  600. Display::display_footer();
  601. function sort_by_order($a, $b)
  602. {
  603. return $a['score'] <= $b['score'];
  604. }