teachers.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Teacher 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. $nameTools = get_lang('Teachers');
  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. $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  26. $active = isset($_GET['active']) ? intval($_GET['active']) : 1;
  27. $sleepingDays = isset($_GET['sleeping_days']) ? intval($_GET['sleeping_days']) : null;
  28. $lastConnectionDate = null;
  29. if (!empty($sleepingDays)) {
  30. $lastConnectionDate = api_get_utc_datetime(strtotime($sleepingDays.' days ago'));
  31. }
  32. $count = SessionManager::getCountUserTracking(
  33. $keyword,
  34. $active,
  35. $lastConnectionDate,
  36. null,
  37. null,
  38. COURSEMANAGER
  39. );
  40. return $count;
  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. $lastConnectionDate = null;
  48. if (!empty($sleepingDays)) {
  49. $lastConnectionDate = api_get_utc_datetime(strtotime($sleepingDays.' days ago'));
  50. }
  51. $is_western_name_order = api_is_western_name_order();
  52. $coach_id = api_get_user_id();
  53. $drhLoaded = false;
  54. if (api_is_drh()) {
  55. if (api_drh_can_access_all_session_content()) {
  56. $students = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
  57. 'drh_all',
  58. api_get_user_id(),
  59. false,
  60. $from,
  61. $limit,
  62. $column,
  63. $direction,
  64. $keyword,
  65. $active,
  66. $lastConnectionDate,
  67. null,
  68. null,
  69. COURSEMANAGER
  70. );
  71. $drhLoaded = true;
  72. }
  73. }
  74. if ($drhLoaded == false) {
  75. $students = UserManager::getUsersFollowedByUser(
  76. api_get_user_id(),
  77. COURSEMANAGER,
  78. false,
  79. false,
  80. false,
  81. $from,
  82. $limit,
  83. $column,
  84. $direction,
  85. $active,
  86. $lastConnectionDate,
  87. COURSEMANAGER,
  88. $keyword
  89. );
  90. }
  91. $all_datas = array();
  92. foreach ($students as $student_data) {
  93. $student_id = $student_data['user_id'];
  94. if (isset($_GET['id_session'])) {
  95. $courses = Tracking :: get_course_list_in_session_from_student($student_id, $_GET['id_session']);
  96. }
  97. $avg_time_spent = $avg_student_score = $avg_student_progress = $total_assignments = $total_messages = 0;
  98. $nb_courses_student = 0;
  99. if (!empty($courses)) {
  100. foreach ($courses as $course_code) {
  101. $courseInfo = api_get_course_info($course_code);
  102. $courseId = $courseInfo['real_id'];
  103. if (CourseManager :: is_user_subscribed_in_course($student_id, $course_code, true)) {
  104. $avg_time_spent += Tracking :: get_time_spent_on_the_course($student_id, $courseId, $_GET['id_session']);
  105. $my_average = Tracking :: get_avg_student_score($student_id, $course_code);
  106. if (is_numeric($my_average)) {
  107. $avg_student_score += $my_average;
  108. }
  109. $avg_student_progress += Tracking :: get_avg_student_progress($student_id, $course_code);
  110. $total_assignments += Tracking :: count_student_assignments($student_id, $course_code);
  111. $total_messages += Tracking :: count_student_messages($student_id, $course_code);
  112. $nb_courses_student++;
  113. }
  114. }
  115. }
  116. if ($nb_courses_student > 0) {
  117. $avg_time_spent = $avg_time_spent / $nb_courses_student;
  118. $avg_student_score = $avg_student_score / $nb_courses_student;
  119. $avg_student_progress = $avg_student_progress / $nb_courses_student;
  120. } else {
  121. $avg_time_spent = null;
  122. $avg_student_score = null;
  123. $avg_student_progress = null;
  124. }
  125. $row = array();
  126. if ($is_western_name_order) {
  127. $row[] = $student_data['firstname'];
  128. $row[] = $student_data['lastname'];
  129. } else {
  130. $row[] = $student_data['lastname'];
  131. $row[] = $student_data['firstname'];
  132. }
  133. $string_date = Tracking :: get_last_connection_date($student_id, true);
  134. $first_date = Tracking :: get_first_connection_date($student_id);
  135. $row[] = $first_date;
  136. $row[] = $string_date;
  137. if (isset($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
  138. $detailsLink = '<a href="myStudents.php?student='.$student_id.'&id_coach='.$coach_id.'&id_session='.$_GET['id_session'].'">
  139. '.Display::return_icon('2rightarrow.png', get_lang('Details')).'</a>';
  140. } else {
  141. $detailsLink = '<a href="myStudents.php?student='.$student_id.'">
  142. '.Display::return_icon('2rightarrow.png', get_lang('Details')).'</a>';
  143. }
  144. $row[] = $detailsLink;
  145. $all_datas[] = $row;
  146. }
  147. return $all_datas;
  148. }
  149. if ($export_csv) {
  150. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  151. } else {
  152. $is_western_name_order = api_is_western_name_order();
  153. }
  154. $sort_by_first_name = api_sort_by_first_name();
  155. $actionsLeft = '';
  156. if (api_is_drh()) {
  157. $menu_items = array(
  158. Display::url(Display::return_icon('stats.png', get_lang('MyStats'), '', ICON_SIZE_MEDIUM), api_get_path(WEB_CODE_PATH)."auth/my_progress.php" ),
  159. Display::url(Display::return_icon('user.png', get_lang('Students'), array(), ICON_SIZE_MEDIUM), 'student.php'),
  160. Display::url(Display::return_icon('teacher_na.png', get_lang('Trainers'), array(), ICON_SIZE_MEDIUM), 'teachers.php'),
  161. Display::url(Display::return_icon('course.png', get_lang('Courses'), array(), ICON_SIZE_MEDIUM), 'course.php'),
  162. Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_MEDIUM), 'session.php'),
  163. );
  164. $nb_menu_items = count($menu_items);
  165. if ($nb_menu_items > 1) {
  166. foreach ($menu_items as $key => $item) {
  167. $actionsLeft .= $item;
  168. }
  169. }
  170. }
  171. $actionsRight = '';
  172. $actionsRight .= Display::url(
  173. Display::return_icon('printer.png', get_lang('Print'), array(), ICON_SIZE_MEDIUM),
  174. 'javascript: void(0);',
  175. array('onclick'=>'javascript: window.print();')
  176. );
  177. $actionsRight .= Display::url(
  178. Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), array(), ICON_SIZE_MEDIUM),
  179. api_get_self().'?export=csv&keyword='.$keyword
  180. );
  181. $toolbar = Display::toolbarAction('toolbar-teachers', $content = array( 0 => $actionsLeft, 1 => $actionsRight ));
  182. $table = new SortableTable(
  183. 'tracking_teachers',
  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. );
  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/teachers.php');
  223. $form = Tracking::setUserSearchForm($form);
  224. $form->setDefaults($params);
  225. if ($export_csv) {
  226. // send the csv file if asked
  227. $content = $table->return_table();
  228. foreach ($content as &$row) {
  229. unset($row[4]);
  230. }
  231. $csv_content = array_merge($csv_header, $content);
  232. ob_end_clean();
  233. Export :: arrayToCsv($csv_content, 'reporting_teacher_list');
  234. exit;
  235. } else {
  236. Display::display_header($nameTools);
  237. echo $toolbar;
  238. $page_title = get_lang('Teachers');
  239. echo Display::page_subheader($page_title);
  240. if (isset($active)) {
  241. if ($active) {
  242. $activeLabel = get_lang('ActiveUsers');
  243. } else {
  244. $activeLabel = get_lang('InactiveUsers');
  245. }
  246. echo Display::page_subheader2($activeLabel);
  247. }
  248. $form->display();
  249. $table->display();
  250. }
  251. Display :: display_footer();