student.php 12 KB

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