teachers.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Teacher 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. api_block_anonymous_users();
  19. $this_section = SECTION_TRACKING;
  20. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
  21. if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && !isset($_GET["type"])) {
  22. $interbreadcrumb[] = array ("url" => "teachers.php", "name" => get_lang('Teachers'));
  23. }
  24. if (isset($_GET["user_id"]) && $_GET["user_id"]!="" && isset($_GET["type"]) && $_GET["type"] == "coach") {
  25. $interbreadcrumb[] = array ("url" => "coaches.php", "name" => get_lang('Tutors'));
  26. }
  27. function get_count_users()
  28. {
  29. $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  30. $active = isset($_GET['active']) ? intval($_GET['active']) : 1;
  31. $sleepingDays = isset($_GET['sleeping_days']) ? intval($_GET['sleeping_days']) : null;
  32. $lastConnectionDate = null;
  33. if (!empty($sleepingDays)) {
  34. $lastConnectionDate = api_get_utc_datetime(strtotime($sleepingDays.' days ago'));
  35. }
  36. $count = SessionManager::getCountUserTracking(
  37. $keyword,
  38. $active,
  39. $lastConnectionDate,
  40. null,
  41. null,
  42. COURSEMANAGER
  43. );
  44. return $count;
  45. }
  46. function get_users($from, $limit, $column, $direction)
  47. {
  48. $active = isset($_GET['active']) ? $_GET['active'] : 1;
  49. $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  50. $sleepingDays = isset($_GET['sleeping_days']) ? intval($_GET['sleeping_days']) : 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. $drhLoaded = false;
  58. if (api_is_drh()) {
  59. if (api_drh_can_access_all_session_content()) {
  60. $students = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
  61. 'drh_all',
  62. api_get_user_id(),
  63. false,
  64. $from,
  65. $limit,
  66. $column,
  67. $direction,
  68. $keyword,
  69. $active,
  70. $lastConnectionDate,
  71. null,
  72. null,
  73. COURSEMANAGER
  74. );
  75. $drhLoaded = true;
  76. }
  77. }
  78. if ($drhLoaded == false) {
  79. $students = UserManager::getUsersFollowedByUser(
  80. api_get_user_id(),
  81. COURSEMANAGER,
  82. false,
  83. false,
  84. false,
  85. $from,
  86. $limit,
  87. $column,
  88. $direction,
  89. $active,
  90. $lastConnectionDate,
  91. COURSEMANAGER,
  92. $keyword
  93. );
  94. }
  95. $all_datas = array();
  96. foreach ($students as $student_data) {
  97. $student_id = $student_data['user_id'];
  98. if (isset($_GET['id_session'])) {
  99. $courses = Tracking :: get_course_list_in_session_from_student($student_id, $_GET['id_session']);
  100. }
  101. $avg_time_spent = $avg_student_score = $avg_student_progress = $total_assignments = $total_messages = 0;
  102. $nb_courses_student = 0;
  103. if (!empty($courses)) {
  104. foreach ($courses as $course_code) {
  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, $course_code, $_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. $actions .= '<div class="actions">';
  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.png', get_lang('Students'), array(), ICON_SIZE_MEDIUM), 'student.php'),
  162. Display::url(Display::return_icon('teacher_na.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. $actions .= $item;
  170. }
  171. }
  172. }
  173. $actions .= '<span style="float:right">';
  174. $actions .= Display::url(Display::return_icon('printer.png', get_lang('Print'), array(), ICON_SIZE_MEDIUM), 'javascript: void(0);', array('onclick'=>'javascript: window.print();'));
  175. $actions .= Display::url(Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), array(), ICON_SIZE_MEDIUM), api_get_self().'?export=csv&keyword='.$keyword);
  176. $actions .= '</span>';
  177. $actions .= '</div>';
  178. $table = new SortableTable(
  179. 'tracking_teachers',
  180. 'get_count_users',
  181. 'get_users',
  182. ($is_western_name_order xor $sort_by_first_name) ? 1 : 0,
  183. 10
  184. );
  185. $params = array(
  186. 'keyword' => $keyword,
  187. 'active' => $active,
  188. 'sleeping_days' => $sleepingDays
  189. );
  190. $table->set_additional_parameters($params);
  191. if ($is_western_name_order) {
  192. $table->set_header(0, get_lang('FirstName'), false);
  193. $table->set_header(1, get_lang('LastName'), false);
  194. } else {
  195. $table->set_header(0, get_lang('LastName'), false);
  196. $table->set_header(1, get_lang('FirstName'), false);
  197. }
  198. $table->set_header(2, get_lang('FirstLogin'), false);
  199. $table->set_header(3, get_lang('LastConnexion'), false);
  200. $table->set_header(4, get_lang('Details'), false);
  201. if ($export_csv) {
  202. if ($is_western_name_order) {
  203. $csv_header[] = array(
  204. get_lang('FirstName'),
  205. get_lang('LastName'),
  206. get_lang('FirstLogin'),
  207. get_lang('LastConnexion')
  208. );
  209. } else {
  210. $csv_header[] = array(
  211. get_lang('LastName'),
  212. get_lang('FirstName'),
  213. get_lang('FirstLogin'),
  214. get_lang('LastConnexion')
  215. );
  216. }
  217. }
  218. $form = new FormValidator('search_user', 'get', api_get_path(WEB_CODE_PATH).'mySpace/teachers.php');
  219. $form = Tracking::setUserSearchForm($form);
  220. $form->setDefaults($params);
  221. if ($export_csv) {
  222. // send the csv file if asked
  223. $content = $table->return_table();
  224. foreach ($content as &$row) {
  225. unset($row[4]);
  226. }
  227. $csv_content = array_merge($csv_header, $content);
  228. ob_end_clean();
  229. Export :: export_table_csv($csv_content, 'reporting_teacher_list');
  230. exit;
  231. } else {
  232. Display::display_header($nameTools);
  233. echo $actions;
  234. $page_title = get_lang('Teachers');
  235. echo Display::page_subheader($page_title);
  236. if (isset($active)) {
  237. if ($active) {
  238. $activeLabel = get_lang('ActiveUsers');
  239. } else {
  240. $activeLabel = get_lang('InactiveUsers');
  241. }
  242. echo Display::page_subheader2($activeLabel);
  243. }
  244. $form->display();
  245. $table->display();
  246. }
  247. Display :: display_footer();