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. // 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. $keyword
  97. );
  98. }
  99. $all_datas = array();
  100. foreach ($students as $student_data) {
  101. $student_id = $student_data['user_id'];
  102. if (isset($_GET['id_session'])) {
  103. $courses = Tracking :: get_course_list_in_session_from_student($student_id, $_GET['id_session']);
  104. }
  105. $avg_time_spent = $avg_student_score = $avg_student_progress = $total_assignments = $total_messages = 0;
  106. $nb_courses_student = 0;
  107. if (!empty($courses)) {
  108. foreach ($courses as $course_code) {
  109. if (CourseManager :: is_user_subscribed_in_course($student_id, $course_code, true)) {
  110. $avg_time_spent += Tracking :: get_time_spent_on_the_course($student_id, $course_code, $_GET['id_session']);
  111. $my_average = Tracking :: get_avg_student_score($student_id, $course_code);
  112. if (is_numeric($my_average)) {
  113. $avg_student_score += $my_average;
  114. }
  115. $avg_student_progress += Tracking :: get_avg_student_progress($student_id, $course_code);
  116. $total_assignments += Tracking :: count_student_assignments($student_id, $course_code);
  117. $total_messages += Tracking :: count_student_messages($student_id, $course_code);
  118. $nb_courses_student++;
  119. }
  120. }
  121. }
  122. if ($nb_courses_student > 0) {
  123. $avg_time_spent = $avg_time_spent / $nb_courses_student;
  124. $avg_student_score = $avg_student_score / $nb_courses_student;
  125. $avg_student_progress = $avg_student_progress / $nb_courses_student;
  126. } else {
  127. $avg_time_spent = null;
  128. $avg_student_score = null;
  129. $avg_student_progress = null;
  130. }
  131. $row = array();
  132. if ($is_western_name_order) {
  133. $row[] = $student_data['firstname'];
  134. $row[] = $student_data['lastname'];
  135. } else {
  136. $row[] = $student_data['lastname'];
  137. $row[] = $student_data['firstname'];
  138. }
  139. $string_date = Tracking :: get_last_connection_date($student_id, true);
  140. $first_date = Tracking :: get_first_connection_date($student_id);
  141. $row[] = $first_date;
  142. $row[] = $string_date;
  143. if (isset($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
  144. $detailsLink = '<a href="myStudents.php?student='.$student_id.'&id_coach='.$coach_id.'&id_session='.$_GET['id_session'].'">
  145. <img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  146. } else {
  147. $detailsLink = '<a href="myStudents.php?student='.$student_id.'">
  148. <img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  149. }
  150. $row[] = $detailsLink;
  151. $all_datas[] = $row;
  152. }
  153. return $all_datas;
  154. }
  155. if ($export_csv) {
  156. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  157. } else {
  158. $is_western_name_order = api_is_western_name_order();
  159. }
  160. $sort_by_first_name = api_sort_by_first_name();
  161. $actions .= '<div class="actions">';
  162. if (api_is_drh()) {
  163. $menu_items = array(
  164. Display::url(Display::return_icon('stats.png', get_lang('MyStats'), '', ICON_SIZE_MEDIUM), api_get_path(WEB_CODE_PATH)."auth/my_progress.php" ),
  165. Display::url(Display::return_icon('user_na.png', get_lang('Students'), array(), ICON_SIZE_MEDIUM), '#'),
  166. Display::url(Display::return_icon('teacher.png', get_lang('Trainers'), array(), ICON_SIZE_MEDIUM), 'teachers.php'),
  167. Display::url(Display::return_icon('course.png', get_lang('Courses'), array(), ICON_SIZE_MEDIUM), 'course.php'),
  168. Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_MEDIUM), 'session.php')
  169. );
  170. $nb_menu_items = count($menu_items);
  171. if ($nb_menu_items > 1) {
  172. foreach ($menu_items as $key => $item) {
  173. $actions .= $item;
  174. }
  175. }
  176. }
  177. $actions .= '<span style="float:right">';
  178. $actions .= Display::url(Display::return_icon('printer.png', get_lang('Print'), array(), ICON_SIZE_MEDIUM), 'javascript: void(0);', array('onclick'=>'javascript: window.print();'));
  179. $actions .= Display::url(Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), array(), ICON_SIZE_MEDIUM), api_get_self().'?export=csv&keyword='.$keyword);
  180. $actions .= '</span>';
  181. $actions .= '</div>';
  182. $table = new SortableTable(
  183. 'tracking_student',
  184. 'get_count_users',
  185. 'get_users',
  186. ($is_western_name_order xor $sort_by_first_name) ? 1 : 0,
  187. 10
  188. );
  189. $params = array(
  190. 'keyword' => $keyword,
  191. 'active' => $active,
  192. 'sleeping_days' => $sleepingDays,
  193. 'status' => $status
  194. );
  195. $table->set_additional_parameters($params);
  196. if ($is_western_name_order) {
  197. $table->set_header(0, get_lang('FirstName'), false);
  198. $table->set_header(1, get_lang('LastName'), false);
  199. } else {
  200. $table->set_header(0, get_lang('LastName'), false);
  201. $table->set_header(1, get_lang('FirstName'), false);
  202. }
  203. $table->set_header(2, get_lang('FirstLogin'), false);
  204. $table->set_header(3, get_lang('LastConnexion'), false);
  205. $table->set_header(4, get_lang('Details'), false);
  206. if ($export_csv) {
  207. if ($is_western_name_order) {
  208. $csv_header[] = array (
  209. get_lang('FirstName'),
  210. get_lang('LastName'),
  211. get_lang('FirstLogin'),
  212. get_lang('LastConnexion')
  213. );
  214. } else {
  215. $csv_header[] = array (
  216. get_lang('LastName'),
  217. get_lang('FirstName'),
  218. get_lang('FirstLogin'),
  219. get_lang('LastConnexion')
  220. );
  221. }
  222. }
  223. $form = new FormValidator('search_user', 'get', api_get_path(WEB_CODE_PATH).'mySpace/users.php');
  224. $form->addElement('select', 'status', get_lang('Status'), array(
  225. '' => '',
  226. STUDENT => get_lang('Student'),
  227. COURSEMANAGER => get_lang('Teacher'),
  228. DRH => get_lang('DRH'))
  229. );
  230. $form = Tracking::setUserSearchForm($form);
  231. $form->setDefaults($params);
  232. // send the csv file if asked
  233. $content = $table->get_table_data();
  234. if ($export_csv) {
  235. foreach ($content as &$row) {
  236. unset($row[4]);
  237. }
  238. $csv_content = array_merge($csv_header, $content);
  239. ob_end_clean();
  240. Export :: export_table_csv($csv_content, 'reporting_student_list');
  241. exit;
  242. } else {
  243. Display::display_header($nameTools);
  244. echo $actions;
  245. $page_title = get_lang('Users');
  246. echo Display::page_subheader($page_title);
  247. if (isset($active)) {
  248. if ($active) {
  249. $activeLabel = get_lang('ActiveUsers');
  250. } else {
  251. $activeLabel = get_lang('InactiveUsers');
  252. }
  253. echo Display::page_subheader2($activeLabel);
  254. }
  255. $form->display();
  256. $table->display();
  257. }
  258. Display :: display_footer();