student.php 11 KB

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