courseLog.php 23 KB

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