users.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Student report
  5. * @package chamilo.reporting
  6. */
  7. /**
  8. * Code
  9. */
  10. $cidReset = true;
  11. require_once '../inc/global.inc.php';
  12. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  13. $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  14. $active = isset($_GET['active']) ? intval($_GET['active']) : 1;
  15. $sleepingDays = isset($_GET['sleeping_days']) ? intval($_GET['sleeping_days']) : null;
  16. $status = isset($_GET['status']) ? Security::remove_XSS($_GET['status']) : null;
  17. api_block_anonymous_users();
  18. $this_section = SECTION_TRACKING;
  19. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
  20. if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && !isset($_GET["type"])) {
  21. $interbreadcrumb[] = array ("url" => "teachers.php", "name" => get_lang('Teachers'));
  22. }
  23. if (isset($_GET["user_id"]) && $_GET["user_id"]!="" && isset($_GET["type"]) && $_GET["type"] == "coach") {
  24. $interbreadcrumb[] = array ("url" => "coaches.php", "name" => get_lang('Tutors'));
  25. }
  26. function get_count_users()
  27. {
  28. $sleepingDays = isset($_GET['sleeping_days']) ? intval($_GET['sleeping_days']) : null;
  29. $active = isset($_GET['active']) ? $_GET['active'] : 1;
  30. $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  31. $status = isset($_GET['status']) ? Security::remove_XSS($_GET['status']) : null;
  32. $lastConnectionDate = null;
  33. if (!empty($sleepingDays)) {
  34. $lastConnectionDate = api_get_utc_datetime(strtotime($sleepingDays.' days ago'));
  35. }
  36. return SessionManager::getCountUserTracking(
  37. $keyword,
  38. $active,
  39. $lastConnectionDate,
  40. null,
  41. null,
  42. $status
  43. );
  44. }
  45. function get_users($from, $limit, $column, $direction)
  46. {
  47. $active = isset($_GET['active']) ? $_GET['active'] : 1;
  48. $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  49. $sleepingDays = isset($_GET['sleeping_days']) ? intval($_GET['sleeping_days']) : null;
  50. $status = isset($_GET['status']) ? Security::remove_XSS($_GET['status']) : null;
  51. $lastConnectionDate = null;
  52. if (!empty($sleepingDays)) {
  53. $lastConnectionDate = api_get_utc_datetime(strtotime($sleepingDays.' days ago'));
  54. }
  55. $is_western_name_order = api_is_western_name_order();
  56. $coach_id = api_get_user_id();
  57. $column = 'u.user_id';
  58. $drhLoaded = false;
  59. if (api_is_drh()) {
  60. if (api_drh_can_access_all_session_content()) {
  61. $students = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
  62. 'drh_all',
  63. api_get_user_id(),
  64. false,
  65. $from,
  66. $limit,
  67. $column,
  68. $direction,
  69. $keyword,
  70. $active,
  71. $lastConnectionDate,
  72. null,
  73. null,
  74. $status
  75. );
  76. $drhLoaded = true;
  77. }
  78. }
  79. if ($drhLoaded == false) {
  80. $students = UserManager::getUsersFollowedByUser(
  81. api_get_user_id(),
  82. $status,
  83. false,
  84. false,
  85. false,
  86. $from,
  87. $limit,
  88. $column,
  89. $direction,
  90. $active,
  91. $lastConnectionDate,
  92. COURSEMANAGER,
  93. $keyword
  94. );
  95. }
  96. $all_datas = array();
  97. foreach ($students as $student_data) {
  98. $student_id = $student_data['user_id'];
  99. if (isset($_GET['id_session'])) {
  100. $courses = Tracking :: get_course_list_in_session_from_student($student_id, $_GET['id_session']);
  101. }
  102. $avg_time_spent = $avg_student_score = $avg_student_progress = $total_assignments = $total_messages = 0;
  103. $nb_courses_student = 0;
  104. if (!empty($courses)) {
  105. foreach ($courses as $course_code) {
  106. $courseInfo = api_get_course_info($course_code);
  107. $courseId = $courseInfo['real_id'];
  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, $courseId, $_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('select', 'status', get_lang('Status'), array(
  224. '' => '',
  225. STUDENT => get_lang('Student'),
  226. COURSEMANAGER => get_lang('Teacher'),
  227. DRH => get_lang('DRH'))
  228. );
  229. $form = Tracking::setUserSearchForm($form);
  230. $form->setDefaults($params);
  231. // send the csv file if asked
  232. $content = $table->get_table_data();
  233. if ($export_csv) {
  234. foreach ($content as &$row) {
  235. unset($row[4]);
  236. }
  237. $csv_content = array_merge($csv_header, $content);
  238. ob_end_clean();
  239. Export :: export_table_csv($csv_content, 'reporting_student_list');
  240. exit;
  241. } else {
  242. Display::display_header($nameTools);
  243. echo $actions;
  244. $page_title = get_lang('Users');
  245. echo Display::page_subheader($page_title);
  246. if (isset($active)) {
  247. if ($active) {
  248. $activeLabel = get_lang('ActiveUsers');
  249. } else {
  250. $activeLabel = get_lang('InactiveUsers');
  251. }
  252. echo Display::page_subheader2($activeLabel);
  253. }
  254. $form->display();
  255. $table->display();
  256. }
  257. Display :: display_footer();