courseLog.php 23 KB

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