student.php 12 KB

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