student.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. api_block_anonymous_users();
  15. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  16. $session_id = isset($_GET['id_session']) ? intval($_GET['id_session']) : null;
  17. if ($export_csv) {
  18. ob_start();
  19. }
  20. $csv_content = array();
  21. if (isset($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
  22. $nameTools = get_lang("CoachStudents");
  23. $sql = 'SELECT lastname, firstname FROM '.Database::get_main_table(TABLE_MAIN_USER).' WHERE user_id='.intval($_GET['id_coach']);
  24. $rs = Database::query($sql);
  25. $coach_name = api_get_person_name(Database::result($rs, 0, 1), Database::result($rs, 0, 0));
  26. $page_title = get_lang('Students').' - '.$coach_name;
  27. } else {
  28. $nameTools = get_lang("Students");
  29. $page_title = get_lang('Students');
  30. }
  31. $this_section = SECTION_TRACKING;
  32. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
  33. if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && !isset($_GET["type"])) {
  34. $interbreadcrumb[] = array ("url" => "teachers.php", "name" => get_lang('Teachers'));
  35. }
  36. if (isset($_GET["user_id"]) && $_GET["user_id"]!="" && isset($_GET["type"]) && $_GET["type"] == "coach") {
  37. $interbreadcrumb[] = array ("url" => "coaches.php", "name" => get_lang('Tutors'));
  38. }
  39. Display :: display_header($nameTools);
  40. /*
  41. FUNCTION
  42. */
  43. function count_student_coached() {
  44. global $students;
  45. return count($students);
  46. }
  47. function sort_users($a, $b) {
  48. global $tracking_column;
  49. if ($a[$tracking_column] > $b[$tracking_column]) {
  50. return 1;
  51. } else {
  52. return -1;
  53. }
  54. }
  55. function rsort_users($a, $b) {
  56. global $tracking_column;
  57. if ($b[$tracking_column] > $a[$tracking_column]) {
  58. return 1;
  59. } else {
  60. return -1;
  61. }
  62. }
  63. /* MAIN CODE */
  64. //if ($isCoach || api_is_platform_admin() || api_is_drh()) {
  65. if (api_is_allowed_to_create_course() || api_is_drh()) {
  66. if ($export_csv) {
  67. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  68. } else {
  69. $is_western_name_order = api_is_western_name_order();
  70. }
  71. $sort_by_first_name = api_sort_by_first_name();
  72. if (api_is_drh()) {
  73. $menu_items = array();
  74. $menu_items[] = Display::url(Display::return_icon('stats.png', get_lang('MyStats'),'',ICON_SIZE_MEDIUM),api_get_path(WEB_CODE_PATH)."auth/my_progress.php" );
  75. $menu_items[] = Display::return_icon('user_na.png', get_lang('Students'), array(), 32);
  76. $menu_items[] = Display::url(Display::return_icon('teacher.png', get_lang('Trainers'), array(), 32), 'teachers.php');
  77. $menu_items[] = Display::url(Display::return_icon('course.png', get_lang('Courses'), array(), 32), 'course.php');
  78. $menu_items[] = Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), 32), 'session.php');
  79. echo '<div class="actions">';
  80. $nb_menu_items = count($menu_items);
  81. if ($nb_menu_items > 1) {
  82. foreach ($menu_items as $key => $item) {
  83. echo $item;
  84. }
  85. }
  86. //if (count($students) > 0) { //
  87. echo '<span style="float:right">';
  88. echo Display::url(Display::return_icon('printer.png', get_lang('Print'), array(), 32), 'javascript: void(0);', array('onclick'=>'javascript: window.print();'));
  89. echo Display::url(Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), array(), 32), api_get_self().'?export=csv');
  90. echo '</span>';
  91. //}
  92. echo '</div>';
  93. } else {
  94. echo '<div class="actions"><div style="float:right;">
  95. <a href="javascript: void(0);" onclick="javascript: window.print();"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>
  96. <a href="'.api_get_self().'?export=csv"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>
  97. </div></div>';
  98. }
  99. echo Display::page_subheader($page_title);
  100. if (isset($_GET['id_coach'])) {
  101. $coach_id = intval($_GET['id_coach']);
  102. } else {
  103. $coach_id = api_get_user_id();
  104. }
  105. if (api_is_drh()) {
  106. $page_title = get_lang('YourStudents');
  107. if (empty($session_id)) {
  108. if (isset($_GET['user_id'])) {
  109. $user_id = intval($_GET['user_id']);
  110. $user_info = api_get_user_info($user_id);
  111. $page_title = api_get_person_name($user_info['firstname'], $user_info['lastname']).' : '.get_lang('Students');
  112. $courses_by_teacher = CourseManager::get_course_list_of_user_as_course_admin($user_id);
  113. $students_by_course = array();
  114. if (!empty($courses_by_teacher)) {
  115. foreach ($courses_by_teacher as $course) {
  116. $students_by_course = array_keys(CourseManager::get_student_list_from_course_code($course['real_id']));
  117. if (count($students_by_course) > 0) {
  118. foreach ($students_by_course as $student_by_course) {
  119. $students[] = $student_by_course;
  120. }
  121. }
  122. }
  123. }
  124. if (!empty($students)) {
  125. $students = array_unique($students);
  126. }
  127. } else {
  128. $students = array_keys(UserManager::get_users_followed_by_drh(api_get_user_id() , STUDENT));
  129. }
  130. $courses_of_the_platform = CourseManager :: get_real_course_list();
  131. foreach ($courses_of_the_platform as $course) {
  132. $courses[$course['code']] = $course['code'];
  133. }
  134. }
  135. } else {
  136. if (empty($session_id)) {
  137. //Getting courses
  138. $courses = CourseManager::get_course_list_as_coach($coach_id, false);
  139. if (isset($courses[0])) {
  140. $courses = $courses[0];
  141. }
  142. //Getting students
  143. $students = CourseManager::get_user_list_from_courses_as_coach($coach_id);
  144. } else {
  145. $students = Tracking :: get_student_followed_by_coach_in_a_session($session_id, $coach_id);
  146. }
  147. }
  148. $tracking_column = isset($_GET['tracking_column']) ? $_GET['tracking_column'] : ($is_western_name_order xor $sort_by_first_name) ? 1 : 0;
  149. $tracking_direction = isset($_GET['tracking_direction']) ? $_GET['tracking_direction'] : 'DESC';
  150. if (count($students) > 0) {
  151. $table = new SortableTable('tracking_student', 'count_student_coached', null, ($is_western_name_order xor $sort_by_first_name) ? 1 : 0);
  152. if ($is_western_name_order) {
  153. $table -> set_header(0, get_lang('FirstName'), false);
  154. $table -> set_header(1, get_lang('LastName'), false);
  155. } else {
  156. $table -> set_header(0, get_lang('LastName'), false);
  157. $table -> set_header(1, get_lang('FirstName'), false);
  158. }
  159. /* $table -> set_header(2, get_lang('Time'), false);
  160. $table -> set_header(3, get_lang('Progress'), false);
  161. $table -> set_header(4, get_lang('Score'), false);
  162. $table -> set_header(5, get_lang('Student_publication'), false);
  163. $table -> set_header(6, get_lang('Messages'), false);*/
  164. $table -> set_header(2, get_lang('FirstLogin'), false);
  165. $table -> set_header(3, get_lang('LatestLogin'), false);
  166. $table -> set_header(4, get_lang('Details'), false);
  167. if ($export_csv) {
  168. if ($is_western_name_order) {
  169. $csv_header[] = array (
  170. get_lang('FirstName', ''),
  171. get_lang('LastName', ''),
  172. //get_lang('Time', ''),
  173. //get_lang('Progress', ''),
  174. //get_lang('Score', ''),
  175. //get_lang('Student_publication', ''),
  176. //get_lang('Messages', ''),
  177. get_lang('FirstLogin', ''),
  178. get_lang('LatestLogin', '')
  179. );
  180. } else {
  181. $csv_header[] = array (
  182. get_lang('LastName', ''),
  183. get_lang('FirstName', ''),
  184. //get_lang('Time', ''),
  185. //get_lang('Progress', ''),
  186. //get_lang('Score', ''),
  187. //get_lang('Student_publication', ''),
  188. //get_lang('Messages', ''),
  189. get_lang('FirstLogin', ''),
  190. get_lang('LatestLogin', '')
  191. );
  192. }
  193. }
  194. $all_datas = array();
  195. foreach ($students as $student_id) {
  196. $student_data = UserManager :: get_user_info_by_id($student_id);
  197. if (!empty($session_id)) {
  198. $courses = Tracking :: get_course_list_in_session_from_student($student_id, $session_id);
  199. }
  200. $avg_time_spent = $avg_student_score = $avg_student_progress = $total_assignments = $total_messages = 0;
  201. $nb_courses_student = 0;
  202. foreach ($courses as $courseId) {
  203. if (CourseManager :: is_user_subscribed_in_course($student_id, $courseId, true)) {
  204. $avg_time_spent += Tracking :: get_time_spent_on_the_course($student_id, $courseId, $session_id);
  205. $my_average = Tracking :: get_avg_student_score($student_id, $courseId);
  206. if (is_numeric($my_average)) {
  207. $avg_student_score += $my_average;
  208. }
  209. $avg_student_progress += Tracking :: get_avg_student_progress($student_id, $courseId);
  210. $total_assignments += Tracking :: count_student_assignments($student_id, $courseId);
  211. $total_messages += Tracking :: count_student_messages($student_id, $courseId);
  212. $nb_courses_student++;
  213. }
  214. }
  215. if ($nb_courses_student > 0) {
  216. $avg_time_spent = $avg_time_spent / $nb_courses_student;
  217. $avg_student_score = $avg_student_score / $nb_courses_student;
  218. $avg_student_progress = $avg_student_progress / $nb_courses_student;
  219. } else {
  220. $avg_time_spent = null;
  221. $avg_student_score = null;
  222. $avg_student_progress = null;
  223. }
  224. $row = array();
  225. if ($is_western_name_order) {
  226. $row[] = $student_data['firstname'];
  227. $row[] = $student_data['lastname'];
  228. } else {
  229. $row[] = $student_data['lastname'];
  230. $row[] = $student_data['firstname'];
  231. }
  232. $string_date = Tracking :: get_last_connection_date($student_id, true);
  233. $first_date = Tracking :: get_first_connection_date($student_id);
  234. $row[] = $first_date;
  235. $row[] = $string_date;
  236. if ($export_csv) {
  237. $row[count($row) - 1] = strip_tags($row[count($row) - 1]);
  238. $row[count($row) - 2] = strip_tags($row[count($row) - 2]);
  239. $csv_content[] = $row;
  240. }
  241. if (isset($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
  242. $row[] = '<a href="myStudents.php?student='.$student_id.'&id_coach='.$coach_id.'&id_session='.$session_id.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  243. } else {
  244. $row[] = '<a href="myStudents.php?student='.$student_id.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  245. }
  246. $all_datas[] = $row;
  247. }
  248. if ($tracking_direction == 'ASC') {
  249. usort($all_datas, 'rsort_users');
  250. } else {
  251. usort($all_datas, 'sort_users');
  252. }
  253. if ($export_csv) {
  254. usort($csv_content, 'sort_users');
  255. $csv_content = array_merge($csv_header, $csv_content);
  256. }
  257. foreach ($all_datas as $row) {
  258. $table -> addRow($row, 'align="right"');
  259. }
  260. $table -> display();
  261. } else {
  262. echo Display::display_warning_message(get_lang('NoStudent'));
  263. }
  264. // send the csv file if asked
  265. if ($export_csv) {
  266. ob_end_clean();
  267. Export :: export_table_csv($csv_content, 'reporting_student_list');
  268. exit;
  269. }
  270. }
  271. Display :: display_footer();