student.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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).'sortabletable.class.php';
  8. require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
  9. require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
  10. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  11. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  12. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  13. if ($export_csv) {
  14. ob_start();
  15. }
  16. $csv_content = array();
  17. if (isset($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
  18. $nameTools = get_lang("CoachStudents");
  19. $sql = 'SELECT lastname, firstname FROM '.Database::get_main_table(TABLE_MAIN_USER).' WHERE user_id='.intval($_GET['id_coach']);
  20. $rs = Database::query($sql);
  21. $coach_name = api_get_person_name(Database::result($rs, 0, 1), Database::result($rs, 0, 0));
  22. $title = get_lang('Probationers').' - '.$coach_name;
  23. } else {
  24. $nameTools = get_lang("Students");
  25. $title = get_lang('Probationers');
  26. }
  27. $this_section = SECTION_TRACKING;
  28. api_block_anonymous_users();
  29. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
  30. if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && !isset($_GET["type"])) {
  31. $interbreadcrumb[] = array ("url" => "teachers.php", "name" => get_lang('Teachers'));
  32. }
  33. if (isset($_GET["user_id"]) && $_GET["user_id"]!="" && isset($_GET["type"]) && $_GET["type"] == "coach") {
  34. $interbreadcrumb[] = array ("url" => "coaches.php", "name" => get_lang('Tutors'));
  35. }
  36. $isCoach = api_is_coach();
  37. Display :: display_header($nameTools);
  38. // Database Table Definitions
  39. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  40. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  41. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  42. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  43. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  44. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  45. $tbl_session_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
  46. /*
  47. ===============================================================================
  48. FUNCTION
  49. ===============================================================================
  50. */
  51. function count_student_coached() {
  52. global $students;
  53. return count($students);
  54. }
  55. function sort_users($a, $b) {
  56. global $tracking_column;
  57. if ($a[$tracking_column] > $b[$tracking_column]) {
  58. return 1;
  59. } else {
  60. return -1;
  61. }
  62. }
  63. function rsort_users($a, $b)
  64. {
  65. global $tracking_column;
  66. if ($b[$tracking_column] > $a[$tracking_column]) {
  67. return 1;
  68. } else {
  69. return -1;
  70. }
  71. }
  72. /*
  73. ===============================================================================
  74. MAIN CODE
  75. ===============================================================================
  76. */
  77. if ($isCoach || api_is_platform_admin() || api_is_drh()) {
  78. if ($export_csv) {
  79. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  80. } else {
  81. $is_western_name_order = api_is_western_name_order();
  82. }
  83. $sort_by_first_name = api_sort_by_first_name();
  84. if (api_is_drh() || $_GET['display'] == 'yourstudents') {
  85. $title = get_lang('YourStudents');
  86. if (!isset($_GET['id_session'])) {
  87. if (isset($_GET['user_id'])) {
  88. $user_id = intval($_GET['user_id']);
  89. $user_info = api_get_user_info($user_id);
  90. $title = api_get_person_name($user_info['firstname'], $user_info['lastname']).' : '.get_lang('Students');
  91. $courses_by_teacher = CourseManager::get_course_list_of_user_as_course_admin($user_id);
  92. $students_by_course = array();
  93. if (!empty($courses_by_teacher)) {
  94. foreach ($courses_by_teacher as $course) {
  95. $students_by_course = array_keys(CourseManager::get_student_list_from_course_code($course['course_code']));
  96. if (count($students_by_course) > 0) {
  97. foreach ($students_by_course as $student_by_course) {
  98. $students[] = $student_by_course;
  99. }
  100. }
  101. }
  102. }
  103. $students = array_unique($students);
  104. } else {
  105. $students = array_keys(UserManager::get_users_followed_by_drh($_user['user_id'], STUDENT));
  106. }
  107. $courses_of_the_platform = CourseManager :: get_real_course_list();
  108. foreach ($courses_of_the_platform as $course) {
  109. $courses[$course['code']] = $course['code'];
  110. }
  111. }
  112. $menu_items[] = '<a href="index.php?view=drh_students">'.get_lang('Students').'</a>';
  113. $menu_items[] = '<a href="teachers.php">'.get_lang('Trainers').'</a>';
  114. $menu_items[] = '<a href="course.php">'.get_lang('Courses').'</a>';
  115. $menu_items[] = '<a href="session.php">'.get_lang('Sessions').'</a>';
  116. echo '<div class="actions-title" style ="font-size:10pt;">';
  117. $nb_menu_items = count($menu_items);
  118. if ($nb_menu_items > 1) {
  119. foreach ($menu_items as $key => $item) {
  120. echo $item;
  121. if ($key != $nb_menu_items - 1) {
  122. echo '&nbsp;|&nbsp;';
  123. }
  124. }
  125. }
  126. if (count($students) > 0) {
  127. echo '&nbsp;&nbsp;<a href="javascript: void(0);" onclick="javascript: window.print()"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a> ';
  128. echo '<a href="'.api_get_self().'?export=csv"><img align="absbottom" src="../img/csv.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>';
  129. }
  130. echo '</div>';
  131. echo '<h4>'.$title.'</h4>';
  132. } else {
  133. echo '<div align="left" style="float:left"><h4>'.$title.'</h4></div>
  134. <div align="right">
  135. <a href="javascript: void(0);" onclick="javascript: window.print();"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>
  136. <a href="'.api_get_self().'?export=csv"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>
  137. </div><div class="clear"></div>';
  138. }
  139. if (isset($_GET['id_coach'])) {
  140. $coach_id = intval($_GET['id_coach']);
  141. } else {
  142. $coach_id = $_user['user_id'];
  143. }
  144. if (!isset($_GET['id_session'])) {
  145. if ($isCoach) {
  146. $courses = Tracking :: get_courses_followed_by_coach($coach_id);
  147. $students = Tracking :: get_student_followed_by_coach($coach_id);
  148. }
  149. } else {
  150. $students = Tracking :: get_student_followed_by_coach_in_a_session($_GET['id_session'], $coach_id);
  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, 'align="center');
  158. $table -> set_header(1, get_lang('LastName'), false, 'align="center');
  159. } else {
  160. $table -> set_header(0, get_lang('LastName'), false, 'align="center');
  161. $table -> set_header(1, get_lang('FirstName'), false, 'align="center');
  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(7, get_lang('FirstLogin'), false);
  169. $table -> set_header(8, get_lang('LatestLogin'), false);
  170. $table -> set_header(9, 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(isset($_GET['id_session'])) {
  202. $courses = Tracking :: get_course_list_in_session_from_student($student_id, $_GET['id_session']);
  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 $course_code) {
  207. if (CourseManager :: is_user_subscribed_in_course($student_id, $course_code, true)) {
  208. $avg_time_spent += Tracking :: get_time_spent_on_the_course($student_id, $course_code, $_GET['id_session']);
  209. $avg_student_score += Tracking :: get_avg_student_score($student_id, $course_code);
  210. $avg_student_progress += Tracking :: get_avg_student_progress($student_id, $course_code);
  211. $total_assignments += Tracking :: count_student_assignments($student_id, $course_code);
  212. $total_messages += Tracking :: count_student_messages($student_id, $course_code);
  213. $nb_courses_student++;
  214. }
  215. }
  216. if ($nb_courses_student > 0) {
  217. $avg_time_spent = $avg_time_spent / $nb_courses_student;
  218. $avg_student_score = $avg_student_score / $nb_courses_student;
  219. $avg_student_progress = $avg_student_progress / $nb_courses_student;
  220. } else {
  221. $avg_time_spent = null;
  222. $avg_student_score = null;
  223. $avg_student_progress = null;
  224. }
  225. $row = array();
  226. if ($is_western_name_order) {
  227. $row[] = $student_data['firstname'];
  228. $row[] = $student_data['lastname'];
  229. } else {
  230. $row[] = $student_data['lastname'];
  231. $row[] = $student_data['firstname'];
  232. }
  233. $row[] = api_time_to_hms($avg_time_spent);
  234. $row[] = is_null($avg_student_progress) ? null : round($avg_student_progress, 2).'%';
  235. $row[] = is_null($avg_student_score) ? null : round($avg_student_score, 2).'%';
  236. $row[] = $total_assignments;
  237. $row[] = $total_messages;
  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. $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='.$_GET['id_session'].'"><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 -> updateColAttributes(0, array('align' => 'left'));
  265. $table -> updateColAttributes(1, array('align' => 'left'));
  266. $table -> updateColAttributes(7, array('align' => 'left'));
  267. $table -> updateColAttributes(8, array('align' => 'left'));
  268. $table -> setColAttributes(9, array('align' => 'center'));
  269. $table -> display();
  270. } else {
  271. echo '<p>'.get_lang('NoStudent').'</p>';
  272. }
  273. // send the csv file if asked
  274. if ($export_csv) {
  275. ob_end_clean();
  276. Export :: export_table_csv($csv_content, 'reporting_student_list');
  277. exit;
  278. }
  279. }
  280. /*
  281. ==============================================================================
  282. FOOTER
  283. ==============================================================================
  284. */
  285. Display :: display_footer();