student.php 11 KB

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