student.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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();">
  96. '.Display::return_icon('printmgr.gif', get_lang('Print')).'
  97. </a>
  98. <a href="'.api_get_self().'?export=csv">
  99. '.Display::return_icon('excel.gif', get_lang('ExportAsCSV')).'
  100. &nbsp;'.get_lang('ExportAsCSV').'</a>
  101. </div></div>';
  102. }
  103. echo Display::page_subheader($page_title);
  104. if (isset($_GET['id_coach'])) {
  105. $coach_id = intval($_GET['id_coach']);
  106. } else {
  107. $coach_id = api_get_user_id();
  108. }
  109. if (api_is_drh()) {
  110. $page_title = get_lang('YourStudents');
  111. if (empty($session_id)) {
  112. if (isset($_GET['user_id'])) {
  113. $user_id = intval($_GET['user_id']);
  114. $user_info = api_get_user_info($user_id);
  115. $page_title = api_get_person_name($user_info['firstname'], $user_info['lastname']).' : '.get_lang('Students');
  116. $courses_by_teacher = CourseManager::get_course_list_of_user_as_course_admin($user_id);
  117. $students_by_course = array();
  118. if (!empty($courses_by_teacher)) {
  119. foreach ($courses_by_teacher as $course) {
  120. $students_by_course = array_keys(CourseManager::get_student_list_from_course_code($course['real_id']));
  121. if (count($students_by_course) > 0) {
  122. foreach ($students_by_course as $student_by_course) {
  123. $students[] = $student_by_course;
  124. }
  125. }
  126. }
  127. }
  128. if (!empty($students)) {
  129. $students = array_unique($students);
  130. }
  131. } else {
  132. $students = array_keys(UserManager::get_users_followed_by_drh(api_get_user_id() , STUDENT));
  133. }
  134. $courses_of_the_platform = CourseManager :: get_real_course_list();
  135. foreach ($courses_of_the_platform as $course) {
  136. $courses[$course['code']] = $course['code'];
  137. }
  138. }
  139. } else {
  140. if (empty($session_id)) {
  141. //Getting courses
  142. $courses = CourseManager::get_course_list_as_coach($coach_id, false);
  143. if (isset($courses[0])) {
  144. $courses = $courses[0];
  145. }
  146. //Getting students
  147. $students = CourseManager::get_user_list_from_courses_as_coach($coach_id);
  148. } else {
  149. $students = Tracking :: get_student_followed_by_coach_in_a_session($session_id, $coach_id);
  150. }
  151. }
  152. $tracking_column = isset($_GET['tracking_column']) ? $_GET['tracking_column'] : ($is_western_name_order xor $sort_by_first_name) ? 1 : 0;
  153. $tracking_direction = isset($_GET['tracking_direction']) ? $_GET['tracking_direction'] : 'DESC';
  154. if (count($students) > 0) {
  155. $table = new SortableTable('tracking_student', 'count_student_coached', null, ($is_western_name_order xor $sort_by_first_name) ? 1 : 0);
  156. if ($is_western_name_order) {
  157. $table -> set_header(0, get_lang('FirstName'), false);
  158. $table -> set_header(1, get_lang('LastName'), false);
  159. } else {
  160. $table -> set_header(0, get_lang('LastName'), false);
  161. $table -> set_header(1, get_lang('FirstName'), false);
  162. }
  163. /* $table -> set_header(2, get_lang('Time'), false);
  164. $table -> set_header(3, get_lang('Progress'), false);
  165. $table -> set_header(4, get_lang('Score'), false);
  166. $table -> set_header(5, get_lang('Student_publication'), false);
  167. $table -> set_header(6, get_lang('Messages'), false);*/
  168. $table -> set_header(2, get_lang('FirstLogin'), false);
  169. $table -> set_header(3, get_lang('LatestLogin'), false);
  170. $table -> set_header(4, get_lang('Details'), false);
  171. if ($export_csv) {
  172. if ($is_western_name_order) {
  173. $csv_header[] = array (
  174. get_lang('FirstName', ''),
  175. get_lang('LastName', ''),
  176. //get_lang('Time', ''),
  177. //get_lang('Progress', ''),
  178. //get_lang('Score', ''),
  179. //get_lang('Student_publication', ''),
  180. //get_lang('Messages', ''),
  181. get_lang('FirstLogin', ''),
  182. get_lang('LatestLogin', '')
  183. );
  184. } else {
  185. $csv_header[] = array (
  186. get_lang('LastName', ''),
  187. get_lang('FirstName', ''),
  188. //get_lang('Time', ''),
  189. //get_lang('Progress', ''),
  190. //get_lang('Score', ''),
  191. //get_lang('Student_publication', ''),
  192. //get_lang('Messages', ''),
  193. get_lang('FirstLogin', ''),
  194. get_lang('LatestLogin', '')
  195. );
  196. }
  197. }
  198. $all_datas = array();
  199. foreach ($students as $student_id) {
  200. $student_data = UserManager :: get_user_info_by_id($student_id);
  201. if (!empty($session_id)) {
  202. $courses = Tracking :: get_course_list_in_session_from_student($student_id, $session_id);
  203. }
  204. $avg_time_spent = $avg_student_score = $avg_student_progress = $total_assignments = $total_messages = 0;
  205. $nb_courses_student = 0;
  206. foreach ($courses as $courseId) {
  207. if (CourseManager :: is_user_subscribed_in_course($student_id, $courseId, true)) {
  208. $avg_time_spent += Tracking :: get_time_spent_on_the_course($student_id, $courseId, $session_id);
  209. $my_average = Tracking :: get_avg_student_score($student_id, $courseId);
  210. if (is_numeric($my_average)) {
  211. $avg_student_score += $my_average;
  212. }
  213. $avg_student_progress += Tracking :: get_avg_student_progress($student_id, $courseId);
  214. $total_assignments += Tracking :: count_student_assignments($student_id, $courseId);
  215. $total_messages += Tracking :: count_student_messages($student_id, $courseId);
  216. $nb_courses_student++;
  217. }
  218. }
  219. if ($nb_courses_student > 0) {
  220. $avg_time_spent = $avg_time_spent / $nb_courses_student;
  221. $avg_student_score = $avg_student_score / $nb_courses_student;
  222. $avg_student_progress = $avg_student_progress / $nb_courses_student;
  223. } else {
  224. $avg_time_spent = null;
  225. $avg_student_score = null;
  226. $avg_student_progress = null;
  227. }
  228. $row = array();
  229. if ($is_western_name_order) {
  230. $row[] = $student_data['firstname'];
  231. $row[] = $student_data['lastname'];
  232. } else {
  233. $row[] = $student_data['lastname'];
  234. $row[] = $student_data['firstname'];
  235. }
  236. $string_date = Tracking :: get_last_connection_date($student_id, true);
  237. $first_date = Tracking :: get_first_connection_date($student_id);
  238. $row[] = $first_date;
  239. $row[] = $string_date;
  240. if ($export_csv) {
  241. $row[count($row) - 1] = strip_tags($row[count($row) - 1]);
  242. $row[count($row) - 2] = strip_tags($row[count($row) - 2]);
  243. $csv_content[] = $row;
  244. }
  245. if (isset($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
  246. $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>';
  247. } else {
  248. $row[] = '<a href="myStudents.php?student='.$student_id.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  249. }
  250. $all_datas[] = $row;
  251. }
  252. if ($tracking_direction == 'ASC') {
  253. usort($all_datas, 'rsort_users');
  254. } else {
  255. usort($all_datas, 'sort_users');
  256. }
  257. if ($export_csv) {
  258. usort($csv_content, 'sort_users');
  259. $csv_content = array_merge($csv_header, $csv_content);
  260. }
  261. foreach ($all_datas as $row) {
  262. $table -> addRow($row, 'align="right"');
  263. }
  264. $table -> display();
  265. } else {
  266. echo Display::display_warning_message(get_lang('NoStudent'));
  267. }
  268. // send the csv file if asked
  269. if ($export_csv) {
  270. ob_end_clean();
  271. Export :: export_table_csv($csv_content, 'reporting_student_list');
  272. exit;
  273. }
  274. }
  275. Display :: display_footer();