student.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Student report
  5. * @package chamilo.reporting
  6. */
  7. $cidReset = true;
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. $nameTools = get_lang('Students');
  10. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  11. $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  12. $active = isset($_GET['active']) ? intval($_GET['active']) : 1;
  13. $sleepingDays = isset($_GET['sleeping_days']) ? intval($_GET['sleeping_days']) : null;
  14. api_block_anonymous_users();
  15. $this_section = SECTION_TRACKING;
  16. $interbreadcrumb[] = array(
  17. "url" => api_is_student_boss() ? "#" : "index.php",
  18. "name" => get_lang('MySpace')
  19. );
  20. if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && !isset($_GET["type"])) {
  21. $interbreadcrumb[] = array(
  22. "url" => "teachers.php",
  23. "name" => get_lang('Teachers')
  24. );
  25. }
  26. if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && isset($_GET["type"]) && $_GET["type"] == "coach") {
  27. $interbreadcrumb[] = array("url" => "coaches.php", "name" => get_lang('Tutors'));
  28. }
  29. function get_count_users()
  30. {
  31. $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  32. $active = isset($_GET['active']) ? (int) $_GET['active'] : 1;
  33. $sleepingDays = isset($_GET['sleeping_days']) ? (int) $_GET['sleeping_days'] : null;
  34. $lastConnectionDate = null;
  35. if (!empty($sleepingDays)) {
  36. $lastConnectionDate = api_get_utc_datetime(strtotime($sleepingDays.' days ago'));
  37. }
  38. $count = SessionManager::getCountUserTracking(
  39. $keyword,
  40. $active,
  41. $lastConnectionDate,
  42. null,
  43. null,
  44. api_is_student_boss() ? null : STUDENT
  45. );
  46. return $count;
  47. }
  48. function get_users($from, $limit, $column, $direction)
  49. {
  50. $active = isset($_GET['active']) ? $_GET['active'] : 1;
  51. $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  52. $sleepingDays = isset($_GET['sleeping_days']) ? (int) $_GET['sleeping_days'] : null;
  53. $sessionId = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0;
  54. $lastConnectionDate = null;
  55. if (!empty($sleepingDays)) {
  56. $lastConnectionDate = api_get_utc_datetime(strtotime($sleepingDays.' days ago'));
  57. }
  58. $is_western_name_order = api_is_western_name_order();
  59. $coach_id = api_get_user_id();
  60. $drhLoaded = false;
  61. if (api_is_drh()) {
  62. $column = 'u.user_id';
  63. if (api_drh_can_access_all_session_content()) {
  64. $students = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
  65. 'drh_all',
  66. api_get_user_id(),
  67. false,
  68. $from,
  69. $limit,
  70. $column,
  71. $direction,
  72. $keyword,
  73. $active,
  74. $lastConnectionDate,
  75. null,
  76. null,
  77. api_is_student_boss() ? null : STUDENT
  78. );
  79. $drhLoaded = true;
  80. }
  81. }
  82. if ($drhLoaded == false) {
  83. $students = UserManager::getUsersFollowedByUser(
  84. api_get_user_id(),
  85. api_is_student_boss() ? null : STUDENT,
  86. false,
  87. false,
  88. false,
  89. $from,
  90. $limit,
  91. $column,
  92. $direction,
  93. $active,
  94. $lastConnectionDate,
  95. api_is_student_boss() ? STUDENT_BOSS : COURSEMANAGER,
  96. $keyword
  97. );
  98. }
  99. $all_datas = array();
  100. foreach ($students as $student_data) {
  101. $student_id = $student_data['user_id'];
  102. if (isset($_GET['id_session'])) {
  103. $courses = Tracking :: get_course_list_in_session_from_student($student_id, $sessionId);
  104. }
  105. $avg_time_spent = $avg_student_score = $avg_student_progress = 0;
  106. $nb_courses_student = 0;
  107. if (!empty($courses)) {
  108. foreach ($courses as $course_code) {
  109. $courseInfo = api_get_course_info($course_code);
  110. $courseId = $courseInfo['real_id'];
  111. if (CourseManager :: is_user_subscribed_in_course($student_id, $course_code, true)) {
  112. $avg_time_spent += Tracking :: get_time_spent_on_the_course($student_id, $courseId, $sessionId);
  113. $my_average = Tracking :: get_avg_student_score($student_id, $course_code);
  114. if (is_numeric($my_average)) {
  115. $avg_student_score += $my_average;
  116. }
  117. $avg_student_progress += Tracking :: get_avg_student_progress($student_id, $course_code);
  118. $nb_courses_student++;
  119. }
  120. }
  121. }
  122. if ($nb_courses_student > 0) {
  123. $avg_time_spent = $avg_time_spent / $nb_courses_student;
  124. $avg_student_score = $avg_student_score / $nb_courses_student;
  125. $avg_student_progress = $avg_student_progress / $nb_courses_student;
  126. } else {
  127. $avg_time_spent = null;
  128. $avg_student_score = null;
  129. $avg_student_progress = null;
  130. }
  131. $row = array();
  132. if ($is_western_name_order) {
  133. $row[] = $student_data['firstname'];
  134. $row[] = $student_data['lastname'];
  135. } else {
  136. $row[] = $student_data['lastname'];
  137. $row[] = $student_data['firstname'];
  138. }
  139. $string_date = Tracking::get_last_connection_date($student_id, true);
  140. $first_date = Tracking::get_first_connection_date($student_id);
  141. $row[] = $first_date;
  142. $row[] = $string_date;
  143. if (isset($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
  144. $detailsLink = '<a href="myStudents.php?student='.$student_id.'&id_coach='.$coach_id.'&id_session='.$sessionId.'">
  145. '.Display::return_icon('2rightarrow.png').'</a>';
  146. } else {
  147. $detailsLink = '<a href="myStudents.php?student='.$student_id.'">
  148. '.Display::return_icon('2rightarrow.png').'</a>';
  149. }
  150. $lostPasswordLink = '';
  151. if (api_is_drh() || api_is_platform_admin()) {
  152. $lostPasswordLink = '&nbsp;'.Display::url(
  153. Display::return_icon('edit.png', get_lang('Edit')),
  154. api_get_path(WEB_CODE_PATH).'mySpace/user_edit.php?user_id='.$student_id
  155. );
  156. }
  157. $row[] = $lostPasswordLink.$detailsLink;
  158. $all_datas[] = $row;
  159. }
  160. return $all_datas;
  161. }
  162. if ($export_csv) {
  163. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  164. } else {
  165. $is_western_name_order = api_is_western_name_order();
  166. }
  167. $sort_by_first_name = api_sort_by_first_name();
  168. $actionsLeft = '';
  169. if (api_is_drh()) {
  170. $menu_items = array(
  171. Display::url(
  172. Display::return_icon('stats.png', get_lang('MyStats'), '', ICON_SIZE_MEDIUM),
  173. api_get_path(WEB_CODE_PATH)."auth/my_progress.php"
  174. ),
  175. Display::url(
  176. Display::return_icon('user_na.png', get_lang('Students'), array(), ICON_SIZE_MEDIUM),
  177. '#'
  178. ),
  179. Display::url(
  180. Display::return_icon('teacher.png', get_lang('Trainers'), array(), ICON_SIZE_MEDIUM),
  181. 'teachers.php'
  182. ),
  183. Display::url(
  184. Display::return_icon('course.png', get_lang('Courses'), array(), ICON_SIZE_MEDIUM),
  185. 'course.php'
  186. ),
  187. Display::url(
  188. Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_MEDIUM),
  189. 'session.php'
  190. ),
  191. Display::url(
  192. Display::return_icon('skills.png', get_lang('Skills'), array(), ICON_SIZE_MEDIUM),
  193. 'skills.php'
  194. )
  195. );
  196. $nb_menu_items = count($menu_items);
  197. if ($nb_menu_items > 1) {
  198. foreach ($menu_items as $key => $item) {
  199. $actionsLeft .= $item;
  200. }
  201. }
  202. } else if (api_is_student_boss()) {
  203. $actionsLeft .= Display::url(
  204. Display::return_icon('stats.png', get_lang('MyStats'), '', ICON_SIZE_MEDIUM),
  205. api_get_path(WEB_CODE_PATH)."auth/my_progress.php"
  206. );
  207. $actionsLeft .= Display::url(
  208. Display::return_icon('user_na.png', get_lang('Students'), array(), ICON_SIZE_MEDIUM),
  209. '#'
  210. );
  211. $actionsLeft .= Display::url(
  212. Display::return_icon("statistics.png", get_lang("CompanyReport"), array(), ICON_SIZE_MEDIUM),
  213. api_get_path(WEB_CODE_PATH)."mySpace/company_reports.php"
  214. );
  215. $actionsLeft .= Display::url(
  216. Display::return_icon(
  217. "certificate_list.png",
  218. get_lang("GradebookSeeListOfStudentsCertificates"),
  219. [],
  220. ICON_SIZE_MEDIUM
  221. ),
  222. api_get_path(WEB_CODE_PATH)."gradebook/certificate_report.php"
  223. );
  224. }
  225. $actionsRight = '';
  226. $actionsRight .= Display::url(
  227. Display::return_icon('printer.png', get_lang('Print'), array(), ICON_SIZE_MEDIUM),
  228. 'javascript: void(0);',
  229. array('onclick'=>'javascript: window.print();')
  230. );
  231. $actionsRight .= Display::url(
  232. Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), array(), ICON_SIZE_MEDIUM),
  233. api_get_self().'?export=csv&keyword='.$keyword
  234. );
  235. $toolbar = Display::toolbarAction('toolbar-student', [$actionsLeft, $actionsRight]);
  236. $table = new SortableTable(
  237. 'tracking_student',
  238. 'get_count_users',
  239. 'get_users',
  240. ($is_western_name_order xor $sort_by_first_name) ? 1 : 0,
  241. 10
  242. );
  243. $params = array(
  244. 'keyword' => $keyword,
  245. 'active' => $active,
  246. 'sleeping_days' => $sleepingDays
  247. );
  248. $table->set_additional_parameters($params);
  249. if ($is_western_name_order) {
  250. $table->set_header(0, get_lang('FirstName'), false);
  251. $table->set_header(1, get_lang('LastName'), false);
  252. } else {
  253. $table->set_header(0, get_lang('LastName'), false);
  254. $table->set_header(1, get_lang('FirstName'), false);
  255. }
  256. $table->set_header(2, get_lang('FirstLogin'), false);
  257. $table->set_header(3, get_lang('LastConnexion'), false);
  258. $table->set_header(4, get_lang('Details'), false);
  259. if ($export_csv) {
  260. if ($is_western_name_order) {
  261. $csv_header[] = array(
  262. get_lang('FirstName'),
  263. get_lang('LastName'),
  264. get_lang('FirstLogin'),
  265. get_lang('LastConnexion')
  266. );
  267. } else {
  268. $csv_header[] = array(
  269. get_lang('LastName'),
  270. get_lang('FirstName'),
  271. get_lang('FirstLogin'),
  272. get_lang('LastConnexion')
  273. );
  274. }
  275. }
  276. $form = new FormValidator(
  277. 'search_user',
  278. 'get',
  279. api_get_path(WEB_CODE_PATH).'mySpace/student.php'
  280. );
  281. $form = Tracking::setUserSearchForm($form);
  282. $form->setDefaults($params);
  283. if ($export_csv) {
  284. // send the csv file if asked
  285. $content = $table->get_table_data();
  286. foreach ($content as &$row) {
  287. unset($row[4]);
  288. }
  289. $csv_content = array_merge($csv_header, $content);
  290. ob_end_clean();
  291. Export :: arrayToCsv($csv_content, 'reporting_student_list');
  292. exit;
  293. } else {
  294. Display::display_header($nameTools);
  295. echo $toolbar;
  296. $page_title = get_lang('Students');
  297. echo Display::page_subheader($page_title);
  298. if (isset($active)) {
  299. if ($active) {
  300. $activeLabel = get_lang('ActiveUsers');
  301. } else {
  302. $activeLabel = get_lang('InactiveUsers');
  303. }
  304. echo Display::page_subheader2($activeLabel);
  305. }
  306. $form->display();
  307. $table->display();
  308. }
  309. Display :: display_footer();