student.php 11 KB

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