total_time.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. $this_section = SECTION_COURSES;
  17. if ($from == 'myspace') {
  18. $from_myspace = true;
  19. $this_section = 'session_my_space';
  20. }
  21. // Access restrictions.
  22. $is_allowedToTrack = Tracking::isAllowToTrack($session_id);
  23. if (!$is_allowedToTrack) {
  24. api_not_allowed(true);
  25. exit;
  26. }
  27. // If the user is a HR director (drh)
  28. if (api_is_drh()) {
  29. // Blocking course for drh
  30. if (api_drh_can_access_all_session_content()) {
  31. // If the drh has been configured to be allowed to see all session content,
  32. // give him access to the session courses
  33. $coursesFromSession = SessionManager::getAllCoursesFollowedByUser(
  34. api_get_user_id(),
  35. null
  36. );
  37. $coursesFromSessionCodeList = [];
  38. if (!empty($coursesFromSession)) {
  39. foreach ($coursesFromSession as $course) {
  40. $coursesFromSessionCodeList[$course['code']] = $course['code'];
  41. }
  42. }
  43. $coursesFollowedList = CourseManager::get_courses_followed_by_drh(api_get_user_id());
  44. if (!empty($coursesFollowedList)) {
  45. $coursesFollowedList = array_keys($coursesFollowedList);
  46. }
  47. if (!in_array($courseCode, $coursesFollowedList)) {
  48. if (!in_array($courseCode, $coursesFromSessionCodeList)) {
  49. api_not_allowed();
  50. }
  51. }
  52. } else {
  53. // If the drh has *not* been configured to be allowed to see all session content,
  54. // then check if he has also been given access to the corresponding courses
  55. $coursesFollowedList = CourseManager::get_courses_followed_by_drh(api_get_user_id());
  56. $coursesFollowedList = array_keys($coursesFollowedList);
  57. if (!in_array(api_get_course_id(), $coursesFollowedList)) {
  58. api_not_allowed(true);
  59. exit;
  60. }
  61. }
  62. }
  63. if ($export_csv) {
  64. if (!empty($session_id)) {
  65. Session::write('id_session', $session_id);
  66. }
  67. ob_start();
  68. }
  69. $columnsToHideFromSetting = api_get_configuration_value('course_log_hide_columns');
  70. $columnsToHide = empty($columnsToHideFromSetting) ? [0, 8, 9, 10, 11] : $columnsToHideFromSetting;
  71. $columnsToHide = json_encode($columnsToHide);
  72. $csv_content = [];
  73. // Database table definitions.
  74. //@todo remove this calls
  75. $TABLETRACK_EXERCISES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  76. $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  77. $TABLECOURSE = Database::get_main_table(TABLE_MAIN_COURSE);
  78. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  79. $TABLEQUIZ = Database::get_course_table(TABLE_QUIZ_TEST);
  80. $sessionId = api_get_session_id();
  81. // Breadcrumbs.
  82. if (isset($_GET['origin']) && $_GET['origin'] == 'resume_session') {
  83. $interbreadcrumb[] = [
  84. 'url' => '../admin/index.php',
  85. 'name' => get_lang('Administration'),
  86. ];
  87. $interbreadcrumb[] = [
  88. 'url' => '../session/session_list.php',
  89. 'name' => get_lang('Session list'),
  90. ];
  91. $interbreadcrumb[] = [
  92. 'url' => '../session/resume_session.php?id_session='.$sessionId,
  93. 'name' => get_lang('Session overview'),
  94. ];
  95. }
  96. $view = isset($_REQUEST['view']) ? $_REQUEST['view'] : '';
  97. $nameTools = get_lang('Reporting');
  98. // getting all the students of the course
  99. if (empty($session_id)) {
  100. // Registered students in a course outside session.
  101. $a_students = CourseManager::get_student_list_from_course_code(
  102. api_get_course_id()
  103. );
  104. } else {
  105. // Registered students in session.
  106. $a_students = CourseManager::get_student_list_from_course_code(
  107. api_get_course_id(),
  108. true,
  109. $sessionId
  110. );
  111. }
  112. $nbStudents = count($a_students);
  113. // Display the header.
  114. Display::display_header($nameTools, 'Tracking');
  115. /* MAIN CODE */
  116. $actionsLeft = Display::return_icon(
  117. 'user_na.png',
  118. get_lang('StudentsReporting'),
  119. [],
  120. ICON_SIZE_MEDIUM
  121. );
  122. $actionsLeft .= Display::url(
  123. Display::return_icon('group.png', get_lang('Group reporting'), [], ICON_SIZE_MEDIUM),
  124. 'course_log_groups.php?'.api_get_cidreq()
  125. );
  126. $actionsLeft .= Display::url(
  127. Display::return_icon('course.png', get_lang('CourseReporting'), [], ICON_SIZE_MEDIUM),
  128. 'course_log_tools.php?'.api_get_cidreq()
  129. );
  130. $actionsLeft .= Display::url(
  131. Display::return_icon('tools.png', get_lang('ResourcesReporting'), [], ICON_SIZE_MEDIUM),
  132. 'course_log_resources.php?'.api_get_cidreq()
  133. );
  134. $actionsLeft .= Display::url(
  135. Display::return_icon('quiz.png', get_lang('ExamReporting'), [], ICON_SIZE_MEDIUM),
  136. api_get_path(WEB_CODE_PATH).'tracking/exams.php?'.api_get_cidreq()
  137. );
  138. if (!empty($sessionId)) {
  139. $actionsLeft .= Display::url(
  140. Display::return_icon('attendance_list.png', get_lang('Logins'), '', ICON_SIZE_MEDIUM),
  141. api_get_path(WEB_CODE_PATH).'attendance/index.php?'.api_get_cidreq().'&action=calendar_logins'
  142. );
  143. }
  144. $actionsRight = '<div class="pull-right">';
  145. $actionsRight .= '<a href="javascript: void(0);" onclick="javascript: window.print();">'.
  146. Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_MEDIUM).'</a>';
  147. $users_tracking_per_page = '';
  148. if (isset($_GET['users_tracking_per_page'])) {
  149. $users_tracking_per_page = '&users_tracking_per_page='.intval($_GET['users_tracking_per_page']);
  150. }
  151. $actionsRight .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&export=csv&'.$users_tracking_per_page.'">
  152. '.Display::return_icon('export_csv.png', get_lang('CSV export'), '', ICON_SIZE_MEDIUM).'</a>';
  153. $actionsRight .= '</div>';
  154. // Create a search-box.
  155. $form_search = new FormValidator(
  156. 'search_simple',
  157. 'GET',
  158. api_get_path(WEB_CODE_PATH).'tracking/total_time.php?'.api_get_cidreq(),
  159. '',
  160. [],
  161. FormValidator::LAYOUT_INLINE
  162. );
  163. $form_search->addElement('hidden', 'from', Security::remove_XSS($from));
  164. $form_search->addElement('hidden', 'session_id', $sessionId);
  165. $form_search->addElement('hidden', 'id_session', $sessionId);
  166. $form_search->addElement('text', 'user_keyword');
  167. $form_search->addButtonSearch(get_lang('Search users'));
  168. echo Display::toolbarAction(
  169. 'toolbar-courselog',
  170. [$actionsLeft, $form_search->returnForm(), $actionsRight]
  171. );
  172. $course_name = get_lang('Course').' '.$courseInfo['name'];
  173. if ($session_id) {
  174. $titleSession = Display::return_icon(
  175. 'session.png',
  176. get_lang('Session'),
  177. [],
  178. ICON_SIZE_SMALL
  179. ).' '.api_get_session_name($session_id);
  180. $titleCourse = Display::return_icon(
  181. 'course.png',
  182. get_lang('Course'),
  183. [],
  184. ICON_SIZE_SMALL
  185. ).' '.$course_name;
  186. } else {
  187. $titleSession = Display::return_icon(
  188. 'course.png',
  189. get_lang('Course'),
  190. [],
  191. ICON_SIZE_SMALL
  192. ).' '.$courseInfo['name'];
  193. }
  194. $teacherList = CourseManager::getTeacherListFromCourseCodeToString(
  195. $courseInfo['code'],
  196. ',',
  197. false,
  198. true
  199. );
  200. $coaches = null;
  201. if (!empty($session_id)) {
  202. $coaches = CourseManager::get_coachs_from_course_to_string(
  203. $session_id,
  204. $courseInfo['real_id'],
  205. ',',
  206. false,
  207. true
  208. );
  209. }
  210. $html = '';
  211. if (!empty($teacherList)) {
  212. $html .= Display::page_subheader2(get_lang('Trainers'));
  213. $html .= $teacherList;
  214. }
  215. if (!empty($coaches)) {
  216. $html .= Display::page_subheader2(get_lang('Coaches'));
  217. $html .= $coaches;
  218. }
  219. if (api_is_platform_admin(true) ||
  220. api_is_session_general_coach()
  221. ) {
  222. $sessionList = SessionManager::get_session_by_course($courseInfo['real_id']);
  223. if (!empty($sessionList)) {
  224. $html .= Display::page_subheader2(get_lang('Session list'));
  225. $icon = Display::return_icon(
  226. 'session.png',
  227. null,
  228. null,
  229. ICON_SIZE_TINY
  230. );
  231. $html .= '<ul class="session-list">';
  232. foreach ($sessionList as $session) {
  233. $url = api_get_path(WEB_CODE_PATH).'mySpace/course.php?session_id='
  234. .$session['id'].'&cidReq='.$courseInfo['code'];
  235. $html .= Display::tag('li', $icon.' '.Display::url($session['name'], $url));
  236. }
  237. $html .= '</ul>';
  238. }
  239. }
  240. $html .= Display::page_subheader2(get_lang('Learners list'));
  241. // PERSON_NAME_DATA_EXPORT is buggy
  242. $is_western_name_order = api_is_western_name_order();
  243. if (count($a_students) > 0) {
  244. $all_datas = [];
  245. $course_code = $_course['id'];
  246. $user_ids = array_keys($a_students);
  247. $table = new SortableTable(
  248. 'users_tracking',
  249. ['TrackingCourseLog', 'get_number_of_users'],
  250. ['TrackingCourseLog', 'getTotalTimeReport'],
  251. (api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2
  252. );
  253. $parameters['cidReq'] = Security::remove_XSS($_GET['cidReq']);
  254. $parameters['id_session'] = $session_id;
  255. $parameters['from'] = isset($_GET['myspace']) ? Security::remove_XSS($_GET['myspace']) : null;
  256. $table->set_additional_parameters($parameters);
  257. $headers = [];
  258. // tab of header texts
  259. $table->set_header(0, get_lang('Code'), true);
  260. $headers['official_code'] = get_lang('Code');
  261. if ($is_western_name_order) {
  262. $table->set_header(1, get_lang('First name'), true);
  263. $headers['firstname'] = get_lang('First name');
  264. $table->set_header(2, get_lang('Last name'), true);
  265. $headers['lastname'] = get_lang('Last name');
  266. } else {
  267. $table->set_header(1, get_lang('Last name'), true);
  268. $headers['lastname'] = get_lang('Last name');
  269. $table->set_header(2, get_lang('First name'), true);
  270. $headers['firstname'] = get_lang('First name');
  271. }
  272. $table->set_header(3, get_lang('Login'), false);
  273. $headers['login'] = get_lang('Login');
  274. $table->set_header(4, get_lang('Time').'&nbsp;'.
  275. Display::return_icon('info3.gif', get_lang('Time spent in the course'), ['align' => 'absmiddle', 'hspace' => '3px']),
  276. false,
  277. ['style' => 'width:110px;']
  278. );
  279. $headers['training_time'] = get_lang('Time');
  280. $table->set_header(5, get_lang('Total learnpath time').'&nbsp;'.
  281. Display::return_icon('info3.gif', get_lang('Total learnpath time'), ['align' => 'absmiddle', 'hspace' => '3px']),
  282. false,
  283. ['style' => 'width:110px;']
  284. );
  285. $headers['total_time_lp'] = get_lang('Total learnpath time');
  286. $table->set_header(6, get_lang('First access to course'), false);
  287. $headers['first_login'] = get_lang('First access to course');
  288. $table->set_header(7, get_lang('Latest access in course'), false);
  289. $headers['latest_login'] = get_lang('Latest access in course');
  290. // Display the table
  291. $html .= "<div id='reporting_table'>";
  292. $html .= $table->return_table();
  293. $html .= "</div>";
  294. } else {
  295. $html .= Display::return_message(get_lang('No users in course'), 'warning', true);
  296. }
  297. echo Display::panel($html, $titleSession);
  298. Display::display_footer();