users.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  16. $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  17. $active = isset($_GET['active']) ? intval($_GET['active']) : 1;
  18. $sleepingDays = isset($_GET['sleeping_days']) ? intval($_GET['sleeping_days']) : null;
  19. $status = isset($_GET['status']) ? Security::remove_XSS($_GET['status']) : 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. $sleepingDays = isset($_GET['sleeping_days']) ? intval($_GET['sleeping_days']) : null;
  32. $active = isset($_GET['active']) ? $_GET['active'] : 1;
  33. $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  34. $status = isset($_GET['status']) ? Security::remove_XSS($_GET['status']) : null;
  35. $lastConnectionDate = null;
  36. if (!empty($sleepingDays)) {
  37. $lastConnectionDate = api_get_utc_datetime(strtotime($sleepingDays.' days ago'));
  38. }
  39. return SessionManager::getCountUserTracking(
  40. $keyword,
  41. $active,
  42. $lastConnectionDate,
  43. null,
  44. null,
  45. $status
  46. );
  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. $status = isset($_GET['status']) ? Security::remove_XSS($_GET['status']) : null;
  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. $column = 'u.user_id';
  61. $drhLoaded = false;
  62. if (api_is_drh()) {
  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. $status
  78. );
  79. $drhLoaded = true;
  80. }
  81. }
  82. if ($drhLoaded == false) {
  83. $students = UserManager::getUsersFollowedByUser(
  84. api_get_user_id(),
  85. $status,
  86. false,
  87. false,
  88. false,
  89. $from,
  90. $limit,
  91. $column,
  92. $direction,
  93. $active,
  94. $lastConnectionDate,
  95. COURSEMANAGER
  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. if (CourseManager :: is_user_subscribed_in_course($student_id, $course_code, true)) {
  109. $avg_time_spent += Tracking :: get_time_spent_on_the_course($student_id, $course_code, $_GET['id_session']);
  110. $my_average = Tracking :: get_avg_student_score($student_id, $course_code);
  111. if (is_numeric($my_average)) {
  112. $avg_student_score += $my_average;
  113. }
  114. $avg_student_progress += Tracking :: get_avg_student_progress($student_id, $course_code);
  115. $total_assignments += Tracking :: count_student_assignments($student_id, $course_code);
  116. $total_messages += Tracking :: count_student_messages($student_id, $course_code);
  117. $nb_courses_student++;
  118. }
  119. }
  120. }
  121. if ($nb_courses_student > 0) {
  122. $avg_time_spent = $avg_time_spent / $nb_courses_student;
  123. $avg_student_score = $avg_student_score / $nb_courses_student;
  124. $avg_student_progress = $avg_student_progress / $nb_courses_student;
  125. } else {
  126. $avg_time_spent = null;
  127. $avg_student_score = null;
  128. $avg_student_progress = null;
  129. }
  130. $row = array();
  131. if ($is_western_name_order) {
  132. $row[] = $student_data['firstname'];
  133. $row[] = $student_data['lastname'];
  134. } else {
  135. $row[] = $student_data['lastname'];
  136. $row[] = $student_data['firstname'];
  137. }
  138. $string_date = Tracking :: get_last_connection_date($student_id, true);
  139. $first_date = Tracking :: get_first_connection_date($student_id);
  140. $row[] = $first_date;
  141. $row[] = $string_date;
  142. if (isset($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
  143. $detailsLink = '<a href="myStudents.php?student='.$student_id.'&id_coach='.$coach_id.'&id_session='.$_GET['id_session'].'">
  144. <img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  145. } else {
  146. $detailsLink = '<a href="myStudents.php?student='.$student_id.'">
  147. <img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  148. }
  149. $row[] = $detailsLink;
  150. $all_datas[] = $row;
  151. }
  152. return $all_datas;
  153. }
  154. if ($export_csv) {
  155. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  156. } else {
  157. $is_western_name_order = api_is_western_name_order();
  158. }
  159. $sort_by_first_name = api_sort_by_first_name();
  160. $actions .= '<div class="actions">';
  161. if (api_is_drh()) {
  162. $menu_items = array(
  163. Display::url(Display::return_icon('stats.png', get_lang('MyStats'), '', ICON_SIZE_MEDIUM), api_get_path(WEB_CODE_PATH)."auth/my_progress.php" ),
  164. Display::url(Display::return_icon('user_na.png', get_lang('Students'), array(), ICON_SIZE_MEDIUM), '#'),
  165. Display::url(Display::return_icon('teacher.png', get_lang('Trainers'), array(), ICON_SIZE_MEDIUM), 'teachers.php'),
  166. Display::url(Display::return_icon('course.png', get_lang('Courses'), array(), ICON_SIZE_MEDIUM), 'course.php'),
  167. Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_MEDIUM), 'session.php')
  168. );
  169. $nb_menu_items = count($menu_items);
  170. if ($nb_menu_items > 1) {
  171. foreach ($menu_items as $key => $item) {
  172. $actions .= $item;
  173. }
  174. }
  175. }
  176. $actions .= '<span style="float:right">';
  177. $actions .= Display::url(Display::return_icon('printer.png', get_lang('Print'), array(), ICON_SIZE_MEDIUM), 'javascript: void(0);', array('onclick'=>'javascript: window.print();'));
  178. $actions .= Display::url(Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), array(), ICON_SIZE_MEDIUM), api_get_self().'?export=csv&keyword='.$keyword);
  179. $actions .= '</span>';
  180. $actions .= '</div>';
  181. $table = new SortableTable(
  182. 'tracking_student',
  183. 'get_count_users',
  184. 'get_users',
  185. ($is_western_name_order xor $sort_by_first_name) ? 1 : 0,
  186. 10
  187. );
  188. $params = array(
  189. 'keyword' => $keyword,
  190. 'active' => $active,
  191. 'sleeping_days' => $sleepingDays,
  192. 'status' => $status
  193. );
  194. $table->set_additional_parameters($params);
  195. if ($is_western_name_order) {
  196. $table->set_header(0, get_lang('FirstName'), false);
  197. $table->set_header(1, get_lang('LastName'), false);
  198. } else {
  199. $table->set_header(0, get_lang('LastName'), false);
  200. $table->set_header(1, get_lang('FirstName'), false);
  201. }
  202. $table->set_header(2, get_lang('FirstLogin'), false);
  203. $table->set_header(3, get_lang('LastConnexion'), false);
  204. $table->set_header(4, get_lang('Details'), false);
  205. if ($export_csv) {
  206. if ($is_western_name_order) {
  207. $csv_header[] = array (
  208. get_lang('FirstName'),
  209. get_lang('LastName'),
  210. get_lang('FirstLogin'),
  211. get_lang('LastConnexion')
  212. );
  213. } else {
  214. $csv_header[] = array (
  215. get_lang('LastName'),
  216. get_lang('FirstName'),
  217. get_lang('FirstLogin'),
  218. get_lang('LastConnexion')
  219. );
  220. }
  221. }
  222. $form = new FormValidator('search_user', 'get', api_get_path(WEB_CODE_PATH).'mySpace/users.php');
  223. $form->addElement('text', 'keyword', get_lang('User'));
  224. $form->addElement('select', 'active', get_lang('Status'), array(1 => get_lang('Active'), 0 => get_lang('Inactive')));
  225. $form->addElement('select', 'status', get_lang('Status'), array(
  226. '' => '',
  227. STUDENT => get_lang('Student'),
  228. COURSEMANAGER => get_lang('Teacher'),
  229. DRH => get_lang('DRH'))
  230. );
  231. if (isset($_configuration['save_user_last_login']) &&
  232. $_configuration['save_user_last_login']
  233. ) {
  234. $form->addElement(
  235. 'select',
  236. 'sleeping_days',
  237. get_lang('InactiveDays'),
  238. array('', 1 => 1, 5 => 5, 15 => 15, 30 => 30, 60 => 60, 90 => 90, 120 => 120)
  239. );
  240. }
  241. $form->addElement('button', 'submit', get_lang('Search'));
  242. $form->setDefaults($params);
  243. // send the csv file if asked
  244. $content = $table->get_table_data();
  245. if ($export_csv) {
  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('Users');
  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();