teachers.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Teacher report.
  5. *
  6. * @package chamilo.reporting
  7. */
  8. $cidReset = true;
  9. require_once __DIR__.'/../inc/global.inc.php';
  10. api_block_anonymous_users();
  11. $allowToTrack = api_is_platform_admin(true, true) || api_is_teacher();
  12. if (!$allowToTrack) {
  13. api_not_allowed(true);
  14. }
  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. $nameTools = get_lang('Teachers');
  20. $this_section = SECTION_TRACKING;
  21. $interbreadcrumb[] = ["url" => "index.php", "name" => get_lang('MySpace')];
  22. if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && !isset($_GET["type"])) {
  23. $interbreadcrumb[] = ["url" => "teachers.php", "name" => get_lang('Teachers')];
  24. }
  25. if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && isset($_GET["type"]) && $_GET["type"] == "coach") {
  26. $interbreadcrumb[] = ["url" => "coaches.php", "name" => get_lang('Tutors')];
  27. }
  28. function get_count_users()
  29. {
  30. $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  31. $active = isset($_GET['active']) ? intval($_GET['active']) : 1;
  32. $sleepingDays = isset($_GET['sleeping_days']) ? intval($_GET['sleeping_days']) : null;
  33. $lastConnectionDate = null;
  34. if (!empty($sleepingDays)) {
  35. $lastConnectionDate = api_get_utc_datetime(strtotime($sleepingDays.' days ago'));
  36. }
  37. $count = SessionManager::getCountUserTracking(
  38. $keyword,
  39. $active,
  40. $lastConnectionDate,
  41. null,
  42. null,
  43. COURSEMANAGER
  44. );
  45. return $count;
  46. }
  47. function get_users($from, $limit, $column, $direction)
  48. {
  49. $active = isset($_GET['active']) ? $_GET['active'] : 1;
  50. $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  51. $sleepingDays = isset($_GET['sleeping_days']) ? intval($_GET['sleeping_days']) : null;
  52. $sessionId = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0;
  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. if (api_drh_can_access_all_session_content()) {
  62. $students = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
  63. 'drh_all',
  64. api_get_user_id(),
  65. false,
  66. $from,
  67. $limit,
  68. $column,
  69. $direction,
  70. $keyword,
  71. $active,
  72. $lastConnectionDate,
  73. null,
  74. null,
  75. COURSEMANAGER
  76. );
  77. $drhLoaded = true;
  78. }
  79. }
  80. if ($drhLoaded == false) {
  81. $students = UserManager::getUsersFollowedByUser(
  82. api_get_user_id(),
  83. COURSEMANAGER,
  84. false,
  85. false,
  86. false,
  87. $from,
  88. $limit,
  89. $column,
  90. $direction,
  91. $active,
  92. $lastConnectionDate,
  93. COURSEMANAGER,
  94. $keyword
  95. );
  96. }
  97. $all_datas = [];
  98. $url = api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php';
  99. foreach ($students as $student_data) {
  100. $student_id = $student_data['user_id'];
  101. $student_data = api_get_user_info($student_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 = 0;
  106. $nb_courses_student = 0;
  107. if (!empty($courses)) {
  108. foreach ($courses as $course_code) {
  109. $courseInfo = api_get_course_info($course_code);
  110. $courseId = $courseInfo['real_id'];
  111. if (CourseManager :: is_user_subscribed_in_course($student_id, $course_code, true)) {
  112. $avg_time_spent += Tracking::get_time_spent_on_the_course(
  113. $student_id,
  114. $courseId,
  115. $_GET['id_session']
  116. );
  117. $my_average = Tracking::get_avg_student_score($student_id, $course_code);
  118. if (is_numeric($my_average)) {
  119. $avg_student_score += $my_average;
  120. }
  121. $avg_student_progress += Tracking::get_avg_student_progress($student_id, $course_code);
  122. $nb_courses_student++;
  123. }
  124. }
  125. }
  126. if ($nb_courses_student > 0) {
  127. $avg_time_spent = $avg_time_spent / $nb_courses_student;
  128. $avg_student_score = $avg_student_score / $nb_courses_student;
  129. $avg_student_progress = $avg_student_progress / $nb_courses_student;
  130. } else {
  131. $avg_time_spent = null;
  132. $avg_student_score = null;
  133. $avg_student_progress = null;
  134. }
  135. $urlDetails = $url."?student=$student_id&origin=teacher_details";
  136. if (isset($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
  137. $urlDetails = $url."?student=$student_id&id_coach=$coach_id&id_session=$sessionId";
  138. }
  139. $row = [];
  140. if ($is_western_name_order) {
  141. $row[] = Display::url($student_data['firstname'], $urlDetails);
  142. $row[] = Display::url($student_data['lastname'], $urlDetails);
  143. } else {
  144. $row[] = $student_data['lastname'];
  145. $row[] = $student_data['firstname'];
  146. }
  147. $string_date = Tracking::get_last_connection_date($student_id, true);
  148. $first_date = Tracking::get_first_connection_date($student_id);
  149. $row[] = $first_date;
  150. $row[] = $string_date;
  151. $detailsLink = Display::url(
  152. Display::return_icon('2rightarrow.png', get_lang('Details').' '.$student_data['username']),
  153. $urlDetails,
  154. ['id' => 'details_'.$student_data['username']]
  155. );
  156. $row[] = $detailsLink;
  157. $all_datas[] = $row;
  158. }
  159. return $all_datas;
  160. }
  161. if ($export_csv) {
  162. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  163. } else {
  164. $is_western_name_order = api_is_western_name_order();
  165. }
  166. $sort_by_first_name = api_sort_by_first_name();
  167. $actionsLeft = '';
  168. if (api_is_drh()) {
  169. $menu_items = [
  170. Display::url(
  171. Display::return_icon('statistics.png', get_lang('MyStats'), '', ICON_SIZE_MEDIUM),
  172. api_get_path(WEB_CODE_PATH)."auth/my_progress.php"
  173. ),
  174. Display::url(Display::return_icon('user.png', get_lang('Students'), [], ICON_SIZE_MEDIUM), 'student.php'),
  175. Display::url(
  176. Display::return_icon('teacher_na.png', get_lang('Trainers'), [], ICON_SIZE_MEDIUM),
  177. 'teachers.php'
  178. ),
  179. Display::url(Display::return_icon('course.png', get_lang('Courses'), [], ICON_SIZE_MEDIUM), 'course.php'),
  180. Display::url(
  181. Display::return_icon('session.png', get_lang('Sessions'), [], ICON_SIZE_MEDIUM),
  182. 'session.php'
  183. ),
  184. ];
  185. $nb_menu_items = count($menu_items);
  186. if ($nb_menu_items > 1) {
  187. foreach ($menu_items as $key => $item) {
  188. $actionsLeft .= $item;
  189. }
  190. }
  191. }
  192. $actionsRight = '';
  193. $actionsRight .= Display::url(
  194. Display::return_icon('printer.png', get_lang('Print'), [], ICON_SIZE_MEDIUM),
  195. 'javascript: void(0);',
  196. ['onclick' => 'javascript: window.print();']
  197. );
  198. $actionsRight .= Display::url(
  199. Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), [], ICON_SIZE_MEDIUM),
  200. api_get_self().'?export=csv&keyword='.$keyword
  201. );
  202. $toolbar = Display::toolbarAction('toolbar-teachers', [$actionsLeft, $actionsRight]);
  203. $table = new SortableTable(
  204. 'tracking_teachers',
  205. 'get_count_users',
  206. 'get_users',
  207. ($is_western_name_order xor $sort_by_first_name) ? 1 : 0,
  208. 10
  209. );
  210. $params = [
  211. 'keyword' => $keyword,
  212. 'active' => $active,
  213. 'sleeping_days' => $sleepingDays,
  214. ];
  215. $table->set_additional_parameters($params);
  216. if ($is_western_name_order) {
  217. $table->set_header(0, get_lang('FirstName'), false);
  218. $table->set_header(1, get_lang('LastName'), false);
  219. } else {
  220. $table->set_header(0, get_lang('LastName'), false);
  221. $table->set_header(1, get_lang('FirstName'), false);
  222. }
  223. $table->set_header(2, get_lang('FirstLogin'), false);
  224. $table->set_header(3, get_lang('LastConnexion'), false);
  225. $table->set_header(4, get_lang('Details'), false);
  226. if ($export_csv) {
  227. if ($is_western_name_order) {
  228. $csv_header[] = [
  229. get_lang('FirstName'),
  230. get_lang('LastName'),
  231. get_lang('FirstLogin'),
  232. get_lang('LastConnexion'),
  233. ];
  234. } else {
  235. $csv_header[] = [
  236. get_lang('LastName'),
  237. get_lang('FirstName'),
  238. get_lang('FirstLogin'),
  239. get_lang('LastConnexion'),
  240. ];
  241. }
  242. }
  243. $form = new FormValidator('search_user', 'get', api_get_path(WEB_CODE_PATH).'mySpace/teachers.php');
  244. $form = Tracking::setUserSearchForm($form);
  245. $form->setDefaults($params);
  246. if ($export_csv) {
  247. // send the csv file if asked
  248. $content = $table->get_table_data();
  249. foreach ($content as &$row) {
  250. $row[3] = strip_tags($row[3]);
  251. unset($row[4]);
  252. }
  253. $csv_content = array_merge($csv_header, $content);
  254. ob_end_clean();
  255. Export :: arrayToCsv($csv_content, 'reporting_teacher_list');
  256. exit;
  257. } else {
  258. Display::display_header($nameTools);
  259. echo $toolbar;
  260. $page_title = get_lang('Teachers');
  261. echo Display::page_subheader($page_title);
  262. if (isset($active)) {
  263. if ($active) {
  264. $activeLabel = get_lang('ActiveUsers');
  265. } else {
  266. $activeLabel = get_lang('InactiveUsers');
  267. }
  268. echo Display::page_subheader2($activeLabel);
  269. }
  270. $form->display();
  271. $table->display();
  272. }
  273. Display :: display_footer();