courseLog.php 19 KB

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