users.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  10. $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  11. $active = isset($_GET['active']) ? intval($_GET['active']) : 1;
  12. $sleepingDays = isset($_GET['sleeping_days']) ? intval($_GET['sleeping_days']) : null;
  13. $status = isset($_GET['status']) ? Security::remove_XSS($_GET['status']) : null;
  14. api_block_anonymous_users();
  15. $this_section = SECTION_TRACKING;
  16. $interbreadcrumb[] = array ("url" => "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. $sleepingDays = isset($_GET['sleeping_days']) ? intval($_GET['sleeping_days']) : null;
  26. $active = isset($_GET['active']) ? $_GET['active'] : 1;
  27. $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  28. $status = isset($_GET['status']) ? Security::remove_XSS($_GET['status']) : null;
  29. $lastConnectionDate = null;
  30. if (!empty($sleepingDays)) {
  31. $lastConnectionDate = api_get_utc_datetime(strtotime($sleepingDays.' days ago'));
  32. }
  33. return SessionManager::getCountUserTracking(
  34. $keyword,
  35. $active,
  36. $lastConnectionDate,
  37. null,
  38. null,
  39. $status
  40. );
  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. $status = isset($_GET['status']) ? Security::remove_XSS($_GET['status']) : null;
  48. $lastConnectionDate = null;
  49. if (!empty($sleepingDays)) {
  50. $lastConnectionDate = api_get_utc_datetime(strtotime($sleepingDays.' days ago'));
  51. }
  52. $is_western_name_order = api_is_western_name_order();
  53. $coach_id = api_get_user_id();
  54. $column = 'u.user_id';
  55. $drhLoaded = false;
  56. if (api_is_drh()) {
  57. if (api_drh_can_access_all_session_content()) {
  58. $students = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
  59. 'drh_all',
  60. api_get_user_id(),
  61. false,
  62. $from,
  63. $limit,
  64. $column,
  65. $direction,
  66. $keyword,
  67. $active,
  68. $lastConnectionDate,
  69. null,
  70. null,
  71. $status
  72. );
  73. $drhLoaded = true;
  74. }
  75. }
  76. if ($drhLoaded == false) {
  77. $students = UserManager::getUsersFollowedByUser(
  78. api_get_user_id(),
  79. $status,
  80. false,
  81. false,
  82. false,
  83. $from,
  84. $limit,
  85. $column,
  86. $direction,
  87. $active,
  88. $lastConnectionDate,
  89. COURSEMANAGER,
  90. $keyword
  91. );
  92. }
  93. $all_datas = array();
  94. foreach ($students as $student_data) {
  95. $student_id = $student_data['user_id'];
  96. if (isset($_GET['id_session'])) {
  97. $courses = Tracking :: get_course_list_in_session_from_student($student_id, $_GET['id_session']);
  98. }
  99. $avg_time_spent = $avg_student_score = $avg_student_progress = $total_assignments = $total_messages = 0;
  100. $nb_courses_student = 0;
  101. if (!empty($courses)) {
  102. foreach ($courses as $course_code) {
  103. $courseInfo = api_get_course_info($course_code);
  104. $courseId = $courseInfo['real_id'];
  105. if (CourseManager :: is_user_subscribed_in_course($student_id, $course_code, true)) {
  106. $avg_time_spent += Tracking :: get_time_spent_on_the_course($student_id, $courseId, $_GET['id_session']);
  107. $my_average = Tracking :: get_avg_student_score($student_id, $course_code);
  108. if (is_numeric($my_average)) {
  109. $avg_student_score += $my_average;
  110. }
  111. $avg_student_progress += Tracking :: get_avg_student_progress($student_id, $course_code);
  112. $total_assignments += Tracking :: count_student_assignments($student_id, $course_code);
  113. $total_messages += Tracking :: count_student_messages($student_id, $course_code);
  114. $nb_courses_student++;
  115. }
  116. }
  117. }
  118. if ($nb_courses_student > 0) {
  119. $avg_time_spent = $avg_time_spent / $nb_courses_student;
  120. $avg_student_score = $avg_student_score / $nb_courses_student;
  121. $avg_student_progress = $avg_student_progress / $nb_courses_student;
  122. } else {
  123. $avg_time_spent = null;
  124. $avg_student_score = null;
  125. $avg_student_progress = null;
  126. }
  127. $row = array();
  128. if ($is_western_name_order) {
  129. $row[] = $student_data['firstname'];
  130. $row[] = $student_data['lastname'];
  131. } else {
  132. $row[] = $student_data['lastname'];
  133. $row[] = $student_data['firstname'];
  134. }
  135. $string_date = Tracking :: get_last_connection_date($student_id, true);
  136. $first_date = Tracking :: get_first_connection_date($student_id);
  137. $row[] = $first_date;
  138. $row[] = $string_date;
  139. if (isset($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
  140. $detailsLink = '<a href="myStudents.php?student='.$student_id.'&id_coach='.$coach_id.'&id_session='.$_GET['id_session'].'">
  141. <img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  142. } else {
  143. $detailsLink = '<a href="myStudents.php?student='.$student_id.'">
  144. <img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  145. }
  146. $row[] = $detailsLink;
  147. $all_datas[] = $row;
  148. }
  149. return $all_datas;
  150. }
  151. if ($export_csv) {
  152. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  153. } else {
  154. $is_western_name_order = api_is_western_name_order();
  155. }
  156. $sort_by_first_name = api_sort_by_first_name();
  157. $actionsLeft = '';
  158. if (api_is_drh()) {
  159. $menu_items = array(
  160. Display::url(Display::return_icon('stats.png', get_lang('MyStats'), '', ICON_SIZE_MEDIUM), api_get_path(WEB_CODE_PATH)."auth/my_progress.php" ),
  161. Display::url(Display::return_icon('user_na.png', get_lang('Students'), array(), ICON_SIZE_MEDIUM), '#'),
  162. Display::url(Display::return_icon('teacher.png', get_lang('Trainers'), array(), ICON_SIZE_MEDIUM), 'teachers.php'),
  163. Display::url(Display::return_icon('course.png', get_lang('Courses'), array(), ICON_SIZE_MEDIUM), 'course.php'),
  164. Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_MEDIUM), 'session.php')
  165. );
  166. $nb_menu_items = count($menu_items);
  167. if ($nb_menu_items > 1) {
  168. foreach ($menu_items as $key => $item) {
  169. $actionsLeft .= $item;
  170. }
  171. }
  172. }
  173. $actionsRight = Display::url(Display::return_icon('printer.png', get_lang('Print'), array(), ICON_SIZE_MEDIUM), 'javascript: void(0);', array('onclick'=>'javascript: window.print();'));
  174. $actionsRight .= Display::url(Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), array(), ICON_SIZE_MEDIUM), api_get_self().'?export=csv&keyword='.$keyword);
  175. $toolbar = Display::toolbarAction('toolbar-user', $content = array( 0 => $actionsLeft, 1 => $actionsRight ));
  176. $table = new SortableTable(
  177. 'tracking_student',
  178. 'get_count_users',
  179. 'get_users',
  180. ($is_western_name_order xor $sort_by_first_name) ? 1 : 0,
  181. 10
  182. );
  183. $params = array(
  184. 'keyword' => $keyword,
  185. 'active' => $active,
  186. 'sleeping_days' => $sleepingDays,
  187. 'status' => $status
  188. );
  189. $table->set_additional_parameters($params);
  190. if ($is_western_name_order) {
  191. $table->set_header(0, get_lang('FirstName'), false);
  192. $table->set_header(1, get_lang('LastName'), false);
  193. } else {
  194. $table->set_header(0, get_lang('LastName'), false);
  195. $table->set_header(1, get_lang('FirstName'), false);
  196. }
  197. $table->set_header(2, get_lang('FirstLogin'), false);
  198. $table->set_header(3, get_lang('LastConnexion'), false);
  199. $table->set_header(4, get_lang('Details'), false);
  200. if ($export_csv) {
  201. if ($is_western_name_order) {
  202. $csv_header[] = array (
  203. get_lang('FirstName'),
  204. get_lang('LastName'),
  205. get_lang('FirstLogin'),
  206. get_lang('LastConnexion')
  207. );
  208. } else {
  209. $csv_header[] = array (
  210. get_lang('LastName'),
  211. get_lang('FirstName'),
  212. get_lang('FirstLogin'),
  213. get_lang('LastConnexion')
  214. );
  215. }
  216. }
  217. $form = new FormValidator('search_user', 'get', api_get_path(WEB_CODE_PATH).'mySpace/users.php');
  218. $form->addElement('select', 'status', get_lang('Status'), array(
  219. '' => '',
  220. STUDENT => get_lang('Student'),
  221. COURSEMANAGER => get_lang('Teacher'),
  222. DRH => get_lang('DRH'))
  223. );
  224. $form = Tracking::setUserSearchForm($form);
  225. $form->setDefaults($params);
  226. // send the csv file if asked
  227. $content = $table->get_table_data();
  228. if ($export_csv) {
  229. foreach ($content as &$row) {
  230. unset($row[4]);
  231. }
  232. $csv_content = array_merge($csv_header, $content);
  233. ob_end_clean();
  234. Export :: arrayToCsv($csv_content, 'reporting_student_list');
  235. exit;
  236. } else {
  237. Display::display_header(get_lang('Users'));
  238. echo $toolbar;
  239. $page_title = get_lang('Users');
  240. echo Display::page_subheader($page_title);
  241. if (isset($active)) {
  242. if ($active) {
  243. $activeLabel = get_lang('ActiveUsers');
  244. } else {
  245. $activeLabel = get_lang('InactiveUsers');
  246. }
  247. echo Display::page_subheader2($activeLabel);
  248. }
  249. $form->display();
  250. $table->display();
  251. }
  252. Display :: display_footer();