student.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <?php
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /*
  4. * Created on 28 juil. 2006 by Elixir Interactive http://www.elixir-interactive.com
  5. */
  6. // name of the language file that needs to be included
  7. $language_file = array ('registration', 'index', 'tracking');
  8. $cidReset = true;
  9. require '../inc/global.inc.php';
  10. require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
  11. require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
  12. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  13. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  14. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  15. if ($export_csv) {
  16. ob_start();
  17. }
  18. $csv_content = array();
  19. if (isset($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
  20. $nameTools = get_lang("CoachStudents");
  21. $sql = 'SELECT lastname, firstname FROM '.Database::get_main_table(TABLE_MAIN_USER).' WHERE user_id='.intval($_GET['id_coach']);
  22. $rs = Database::query($sql, __FILE__, __LINE__);
  23. $coach_name = api_get_person_name(Database::result($rs, 0, 1), Database::result($rs, 0, 0));
  24. $title = get_lang('Probationers').' - '.$coach_name;
  25. } else {
  26. $nameTools = get_lang("Students");
  27. $title = get_lang('Probationers');
  28. }
  29. $this_section = "session_my_space";
  30. api_block_anonymous_users();
  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. $isCoach = api_is_coach();
  39. Display :: display_header($nameTools);
  40. // Database Table Definitions
  41. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  42. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  43. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  44. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  45. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  46. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  47. $tbl_session_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
  48. /*
  49. ===============================================================================
  50. FUNCTION
  51. ===============================================================================
  52. */
  53. function count_student_coached() {
  54. global $students;
  55. return count($students);
  56. }
  57. function sort_users($a, $b) {
  58. global $tracking_column;
  59. if ($a[$tracking_column] > $b[$tracking_column]) {
  60. return 1;
  61. } else {
  62. return -1;
  63. }
  64. }
  65. function rsort_users($a, $b)
  66. {
  67. global $tracking_column;
  68. if ($b[$tracking_column] > $a[$tracking_column]) {
  69. return 1;
  70. } else {
  71. return -1;
  72. }
  73. }
  74. /*
  75. ===============================================================================
  76. MAIN CODE
  77. ===============================================================================
  78. */
  79. if ($isCoach || api_is_platform_admin() || $_user['status'] == DRH) {
  80. if ($export_csv) {
  81. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  82. } else {
  83. $is_western_name_order = api_is_western_name_order();
  84. }
  85. $sort_by_first_name = api_sort_by_first_name();
  86. echo '<div align="left" style="float:left"><h4>'.$title.'</h4></div>
  87. <div align="right">
  88. <a href="javascript: void(0);" onclick="javascript: window.print();"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>
  89. <a href="'.api_get_self().'?export=csv"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>
  90. </div><div class="clear"></div>';
  91. if (isset($_GET['id_coach'])) {
  92. $coach_id = intval($_GET['id_coach']);
  93. } else {
  94. $coach_id = $_user['user_id'];
  95. }
  96. if (!isset($_GET['id_session'])) {
  97. if ($isCoach) {
  98. $courses = Tracking :: get_courses_followed_by_coach($coach_id);
  99. $students = Tracking :: get_student_followed_by_coach($coach_id);
  100. }
  101. elseif ($_user['status'] == DRH) {
  102. $students = Tracking :: get_student_followed_by_drh($_user['user_id']);
  103. $courses_of_the_platform = CourseManager :: get_real_course_list();
  104. foreach ($courses_of_the_platform as $course) {
  105. $courses[$course['code']] = $course['code'];
  106. }
  107. }
  108. } else {
  109. $students = Tracking :: get_student_followed_by_coach_in_a_session($_GET['id_session'], $coach_id);
  110. }
  111. $tracking_column = isset($_GET['tracking_column']) ? $_GET['tracking_column'] : ($is_western_name_order xor $sort_by_first_name) ? 1 : 0;
  112. $tracking_direction = isset($_GET['tracking_direction']) ? $_GET['tracking_direction'] : DESC;
  113. if (count($students) > 0) {
  114. $table = new SortableTable('tracking_student', 'count_student_coached', null, ($is_western_name_order xor $sort_by_first_name) ? 1 : 0);
  115. if ($is_western_name_order) {
  116. $table -> set_header(0, get_lang('FirstName'), true, 'align="center');
  117. $table -> set_header(1, get_lang('LastName'), true, 'align="center');
  118. } else {
  119. $table -> set_header(0, get_lang('LastName'), true, 'align="center');
  120. $table -> set_header(1, get_lang('FirstName'), true, 'align="center');
  121. }
  122. $table -> set_header(2, get_lang('Time'), false);
  123. $table -> set_header(3, get_lang('Progress'), false);
  124. $table -> set_header(4, get_lang('Score'), false);
  125. $table -> set_header(5, get_lang('Student_publication'), false);
  126. $table -> set_header(6, get_lang('Messages'), false);
  127. $table -> set_header(7, get_lang('FirstLogin'), false);
  128. $table -> set_header(8, get_lang('LatestLogin'), false);
  129. $table -> set_header(9, get_lang('Details'), false);
  130. if ($export_csv) {
  131. if ($is_western_name_order) {
  132. $csv_header[] = array (
  133. get_lang('FirstName', ''),
  134. get_lang('LastName', ''),
  135. get_lang('Time', ''),
  136. get_lang('Progress', ''),
  137. get_lang('Score', ''),
  138. get_lang('Student_publication', ''),
  139. get_lang('Messages', ''),
  140. get_lang('FirstLogin', ''),
  141. get_lang('LatestLogin', '')
  142. );
  143. } else {
  144. $csv_header[] = array (
  145. get_lang('LastName', ''),
  146. get_lang('FirstName', ''),
  147. get_lang('Time', ''),
  148. get_lang('Progress', ''),
  149. get_lang('Score', ''),
  150. get_lang('Student_publication', ''),
  151. get_lang('Messages', ''),
  152. get_lang('FirstLogin', ''),
  153. get_lang('LatestLogin', '')
  154. );
  155. }
  156. }
  157. $all_datas = array();
  158. foreach ($students as $student_id) {
  159. $student_data = UserManager :: get_user_info_by_id($student_id);
  160. if(isset($_GET['id_session'])) {
  161. $courses = Tracking :: get_course_list_in_session_from_student($student_id, $_GET['id_session']);
  162. }
  163. $avg_time_spent = $avg_student_score = $avg_student_progress = $total_assignments = $total_messages = 0;
  164. $nb_courses_student = 0;
  165. foreach ($courses as $course_code) {
  166. if (CourseManager :: is_user_subscribed_in_course($student_id, $course_code, true)) {
  167. $avg_time_spent += Tracking :: get_time_spent_on_the_platform($student_id, $course_code);
  168. $avg_student_score += Tracking :: get_avg_student_score($student_id, $course_code);
  169. $avg_student_progress += Tracking :: get_avg_student_progress($student_id, $course_code);
  170. $total_assignments += Tracking :: count_student_assignments($student_id, $course_code);
  171. $total_messages += Tracking :: count_student_messages($student_id, $course_code);
  172. $nb_courses_student++;
  173. }
  174. }
  175. if ($nb_courses_student > 0) {
  176. $avg_time_spent = $avg_time_spent / $nb_courses_student;
  177. $avg_student_score = $avg_student_score / $nb_courses_student;
  178. $avg_student_progress = $avg_student_progress / $nb_courses_student;
  179. } else {
  180. $avg_time_spent = null;
  181. $avg_student_score = null;
  182. $avg_student_progress = null;
  183. }
  184. $row = array();
  185. if ($is_western_name_order) {
  186. $row[] = $student_data['firstname'];
  187. $row[] = $student_data['lastname'];
  188. } else {
  189. $row[] = $student_data['lastname'];
  190. $row[] = $student_data['firstname'];
  191. }
  192. $row[] = api_time_to_hms($avg_time_spent);
  193. $row[] = is_null($avg_student_progress) ? null : round($avg_student_progress, 2).'%';
  194. $row[] = is_null($avg_student_score) ? null : round($avg_student_score, 2).'%';
  195. $row[] = $total_assignments;
  196. $row[] = $total_messages;
  197. $string_date = Tracking :: get_last_connection_date($student_id, true);
  198. $first_date = Tracking :: get_first_connection_date($student_id);
  199. $row[] = $first_date;
  200. $row[] = $string_date;
  201. if ($export_csv) {
  202. $csv_content[] = $row;
  203. }
  204. if (isset($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
  205. $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>';
  206. } else {
  207. $row[] = '<a href="myStudents.php?student='.$student_id.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  208. }
  209. $all_datas[] = $row;
  210. }
  211. if ($tracking_direction == 'ASC') {
  212. usort($all_datas, 'rsort_users');
  213. } else {
  214. usort($all_datas, 'sort_users');
  215. }
  216. if ($export_csv) {
  217. usort($csv_content, 'sort_users');
  218. $csv_content = array_merge($csv_header, $csv_content);
  219. }
  220. foreach ($all_datas as $row) {
  221. $table -> addRow($row, 'align="right"');
  222. }
  223. $table -> updateColAttributes(0, array('align' => 'left'));
  224. $table -> updateColAttributes(1, array('align' => 'left'));
  225. $table -> updateColAttributes(7, array('align' => 'left'));
  226. $table -> updateColAttributes(8, array('align' => 'left'));
  227. $table -> setColAttributes(9, array('align' => 'center'));
  228. $table -> display();
  229. } else {
  230. echo get_lang('NoStudent');
  231. }
  232. // send the csv file if asked
  233. if ($export_csv) {
  234. ob_end_clean();
  235. Export :: export_table_csv($csv_content, 'reporting_student_list');
  236. exit;
  237. }
  238. }
  239. /*
  240. ==============================================================================
  241. FOOTER
  242. ==============================================================================
  243. */
  244. Display :: display_footer();