total_time.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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 = array();
  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 = empty($columnsToHideFromSetting) ? array(0, 8, 9, 10, 11) : $columnsToHideFromSetting;
  78. $columnsToHide = json_encode($columnsToHide);
  79. $csv_content = array();
  80. // Database table definitions.
  81. //@todo remove this calls
  82. $TABLETRACK_DOWNLOADS = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  83. $TABLETRACK_EXERCISES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  84. $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  85. $TABLECOURSE = Database::get_main_table(TABLE_MAIN_COURSE);
  86. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  87. $TABLEQUIZ = Database::get_course_table(TABLE_QUIZ_TEST);
  88. $sessionId = api_get_session_id();
  89. // Breadcrumbs.
  90. if (isset($_GET['origin']) && $_GET['origin'] == 'resume_session') {
  91. $interbreadcrumb[] = array(
  92. 'url' => '../admin/index.php',
  93. 'name' => get_lang('PlatformAdmin')
  94. );
  95. $interbreadcrumb[] = array(
  96. 'url' => '../session/session_list.php',
  97. 'name' => get_lang('SessionList')
  98. );
  99. $interbreadcrumb[] = array(
  100. 'url' => '../session/resume_session.php?id_session='.$sessionId,
  101. 'name' => get_lang('SessionOverview')
  102. );
  103. }
  104. $view = isset($_REQUEST['view']) ? $_REQUEST['view'] : '';
  105. $nameTools = get_lang('Tracking');
  106. // getting all the students of the course
  107. if (empty($session_id)) {
  108. // Registered students in a course outside session.
  109. $a_students = CourseManager::get_student_list_from_course_code(
  110. api_get_course_id()
  111. );
  112. } else {
  113. // Registered students in session.
  114. $a_students = CourseManager::get_student_list_from_course_code(
  115. api_get_course_id(),
  116. true,
  117. $sessionId
  118. );
  119. }
  120. $nbStudents = count($a_students);
  121. // Display the header.
  122. Display::display_header($nameTools, 'Tracking');
  123. /* MAIN CODE */
  124. $actionsLeft = Display::return_icon(
  125. 'user_na.png',
  126. get_lang('StudentsTracking'),
  127. array(),
  128. ICON_SIZE_MEDIUM
  129. );
  130. $actionsLeft .= Display::url(
  131. Display::return_icon('group.png', get_lang('GroupReporting'), array(), ICON_SIZE_MEDIUM),
  132. 'course_log_groups.php?'.api_get_cidreq()
  133. );
  134. $actionsLeft .= Display::url(
  135. Display::return_icon('course.png', get_lang('CourseTracking'), array(), ICON_SIZE_MEDIUM),
  136. 'course_log_tools.php?'.api_get_cidreq()
  137. );
  138. $actionsLeft .= Display::url(
  139. Display::return_icon('tools.png', get_lang('ResourcesTracking'), array(), ICON_SIZE_MEDIUM),
  140. 'course_log_resources.php?'.api_get_cidreq()
  141. );
  142. $actionsLeft .= Display::url(
  143. Display::return_icon('quiz.png', get_lang('ExamTracking'), array(), ICON_SIZE_MEDIUM),
  144. api_get_path(WEB_CODE_PATH).'tracking/exams.php?'.api_get_cidreq()
  145. );
  146. if (!empty($sessionId)) {
  147. $actionsLeft .= Display::url(
  148. Display::return_icon('attendance_list.png', get_lang('Logins'), '', ICON_SIZE_MEDIUM),
  149. api_get_path(WEB_CODE_PATH).'attendance/index.php?'.api_get_cidreq().'&action=calendar_logins'
  150. );
  151. }
  152. $actionsRight = '<div class="pull-right">';
  153. $actionsRight .= '<a href="javascript: void(0);" onclick="javascript: window.print();">'.
  154. Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_MEDIUM).'</a>';
  155. $users_tracking_per_page = '';
  156. if (isset($_GET['users_tracking_per_page'])) {
  157. $users_tracking_per_page = '&users_tracking_per_page='.intval($_GET['users_tracking_per_page']);
  158. }
  159. $actionsRight .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&export=csv&'.$users_tracking_per_page.'">
  160. '.Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), '', ICON_SIZE_MEDIUM).'</a>';
  161. $actionsRight .= '</div>';
  162. // Create a search-box.
  163. $form_search = new FormValidator(
  164. 'search_simple',
  165. 'GET',
  166. api_get_path(WEB_CODE_PATH).'tracking/total_time.php?'.api_get_cidreq(),
  167. '',
  168. array(),
  169. FormValidator::LAYOUT_INLINE
  170. );
  171. $form_search->addElement('hidden', 'from', Security::remove_XSS($from));
  172. $form_search->addElement('hidden', 'session_id', $sessionId);
  173. $form_search->addElement('hidden', 'id_session', $sessionId);
  174. $form_search->addElement('text', 'user_keyword');
  175. $form_search->addButtonSearch(get_lang('SearchUsers'));
  176. echo Display::toolbarAction(
  177. 'toolbar-courselog',
  178. [$actionsLeft, $form_search->returnForm(), $actionsRight]
  179. );
  180. $course_name = get_lang('Course').' '.$courseInfo['name'];
  181. if ($session_id) {
  182. $titleSession = Display::return_icon(
  183. 'session.png',
  184. get_lang('Session'),
  185. array(),
  186. ICON_SIZE_SMALL
  187. ).' '.api_get_session_name($session_id);
  188. $titleCourse = Display::return_icon(
  189. 'course.png',
  190. get_lang('Course'),
  191. array(),
  192. ICON_SIZE_SMALL
  193. ).' '.$course_name;
  194. } else {
  195. $titleSession = Display::return_icon(
  196. 'course.png',
  197. get_lang('Course'),
  198. array(),
  199. ICON_SIZE_SMALL
  200. ).' '.$courseInfo['name'];
  201. }
  202. $teacherList = CourseManager::getTeacherListFromCourseCodeToString(
  203. $courseInfo['code'],
  204. ',',
  205. false,
  206. true
  207. );
  208. $coaches = null;
  209. if (!empty($session_id)) {
  210. $coaches = CourseManager::get_coachs_from_course_to_string(
  211. $session_id,
  212. $courseInfo['real_id'],
  213. ',',
  214. false,
  215. true
  216. );
  217. }
  218. $html = '';
  219. if (!empty($teacherList)) {
  220. $html .= Display::page_subheader2(get_lang('Teachers'));
  221. $html .= $teacherList;
  222. }
  223. if (!empty($coaches)) {
  224. $html .= Display::page_subheader2(get_lang('Coaches'));
  225. $html .= $coaches;
  226. }
  227. if (api_is_platform_admin(true) ||
  228. api_is_session_general_coach()
  229. ) {
  230. $sessionList = SessionManager::get_session_by_course($courseInfo['real_id']);
  231. if (!empty($sessionList)) {
  232. $html .= Display::page_subheader2(get_lang('SessionList'));
  233. $icon = Display::return_icon(
  234. 'session.png',
  235. null,
  236. null,
  237. ICON_SIZE_TINY
  238. );
  239. $html .= '<ul class="session-list">';
  240. foreach ($sessionList as $session) {
  241. $url = api_get_path(WEB_CODE_PATH).'mySpace/course.php?session_id='
  242. .$session['id'].'&cidReq='.$courseInfo['code'];
  243. $html .= Display::tag('li', $icon.' '.Display::url($session['name'], $url));
  244. }
  245. $html .= '</ul>';
  246. }
  247. }
  248. $html .= Display::page_subheader2(get_lang('StudentList'));
  249. // PERSON_NAME_DATA_EXPORT is buggy
  250. $is_western_name_order = api_is_western_name_order();
  251. if (count($a_students) > 0) {
  252. $all_datas = array();
  253. $course_code = $_course['id'];
  254. $user_ids = array_keys($a_students);
  255. $table = new SortableTable(
  256. 'users_tracking',
  257. array('TrackingCourseLog', 'get_number_of_users'),
  258. array('TrackingCourseLog', 'getTotalTimeReport'),
  259. (api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2
  260. );
  261. $parameters['cidReq'] = Security::remove_XSS($_GET['cidReq']);
  262. $parameters['id_session'] = $session_id;
  263. $parameters['from'] = isset($_GET['myspace']) ? Security::remove_XSS($_GET['myspace']) : null;
  264. $table->set_additional_parameters($parameters);
  265. $headers = array();
  266. // tab of header texts
  267. $table->set_header(0, get_lang('OfficialCode'), true);
  268. $headers['official_code'] = get_lang('OfficialCode');
  269. if ($is_western_name_order) {
  270. $table->set_header(1, get_lang('FirstName'), true);
  271. $headers['firstname'] = get_lang('FirstName');
  272. $table->set_header(2, get_lang('LastName'), true);
  273. $headers['lastname'] = get_lang('LastName');
  274. } else {
  275. $table->set_header(1, get_lang('LastName'), true);
  276. $headers['lastname'] = get_lang('LastName');
  277. $table->set_header(2, get_lang('FirstName'), true);
  278. $headers['firstname'] = get_lang('FirstName');
  279. }
  280. $table->set_header(3, get_lang('Login'), false);
  281. $headers['login'] = get_lang('Login');
  282. $table->set_header(4, get_lang('TrainingTime').'&nbsp;'.
  283. Display::return_icon('info3.gif', get_lang('CourseTimeInfo'), array('align' => 'absmiddle', 'hspace' => '3px')), false, array('style' => 'width:110px;'));
  284. $headers['training_time'] = get_lang('TrainingTime');
  285. $table->set_header(5, get_lang('TotalLPTime').'&nbsp;'.
  286. Display::return_icon('info3.gif', get_lang('TotalLPTime'), array('align' => 'absmiddle', 'hspace' => '3px')), false, array('style' => 'width:110px;'));
  287. $headers['total_time_lp'] = get_lang('TotalLPTime');
  288. $table->set_header(6, get_lang('FirstLoginInCourse'), false);
  289. $headers['first_login'] = get_lang('FirstLoginInCourse');
  290. $table->set_header(7, get_lang('LatestLoginInCourse'), false);
  291. $headers['latest_login'] = get_lang('LatestLoginInCourse');
  292. // Display the table
  293. $html .= "<div id='reporting_table'>";
  294. $html .= $table->return_table();
  295. $html .= "</div>";
  296. } else {
  297. $html .= Display::return_message(get_lang('NoUsersInCourse'), 'warning', true);
  298. }
  299. echo Display::panel($html, $titleSession);
  300. Display::display_footer();