student.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. /*
  3. * Created on 28 juil. 2006 by Elixir Interactive http://www.elixir-interactive.com
  4. */
  5. // name of the language file that needs to be included
  6. $language_file = array ('registration', 'index', 'tracking');
  7. $cidReset=true;
  8. require ('../inc/global.inc.php');
  9. require_once (api_get_path(LIBRARY_PATH).'tracking.lib.php');
  10. require_once (api_get_path(LIBRARY_PATH).'export.lib.inc.php');
  11. require_once (api_get_path(LIBRARY_PATH).'course.lib.php');
  12. require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
  13. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  14. if($export_csv)
  15. {
  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 = api_sql_query($sql, __FILE__, __LINE__);
  23. $coach_name = mysql_result($rs, 0, 0).' '.mysql_result($rs, 0, 1);
  24. $title = get_lang('Probationers').' - '.$coach_name;
  25. }
  26. else{
  27. $nameTools= get_lang("Students");
  28. $title = get_lang('Probationers');
  29. }
  30. $this_section = "session_my_space";
  31. api_block_anonymous_users();
  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. $isCoach = api_is_coach();
  40. Display :: display_header($nameTools);
  41. // Database Table Definitions
  42. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  43. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  44. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  45. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  46. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  47. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  48. $tbl_session_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
  49. /*
  50. ===============================================================================
  51. FUNCTION
  52. ===============================================================================
  53. */
  54. function count_student_coached()
  55. {
  56. global $a_students;
  57. return count($a_students);
  58. }
  59. function sort_users($a, $b)
  60. {
  61. global $tracking_column;
  62. if($a[$tracking_column] > $b[$tracking_column])
  63. return 1;
  64. else
  65. return -1;
  66. }
  67. /*
  68. ===============================================================================
  69. MAIN CODE
  70. ===============================================================================
  71. */
  72. if($isCoach || api_is_platform_admin())
  73. {
  74. echo '<div align="left" style="float:left"><h4>'.$title.'</h4></div>
  75. <div align="right">
  76. <a href="#" onclick="window.print()"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>
  77. <a href="'.api_get_self().'?export=csv"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>
  78. </div><div class="clear"></div>';
  79. if(isset($_GET['id_coach'])){
  80. $coach_id=intval($_GET['id_coach']);
  81. }
  82. else{
  83. $coach_id=$_user['user_id'];
  84. }
  85. if(!isset($_GET['id_session'])){
  86. $a_courses = Tracking :: get_courses_followed_by_coach($coach_id);
  87. $a_students = Tracking :: get_student_followed_by_coach($coach_id);
  88. }
  89. else{
  90. $a_students = Tracking :: get_student_followed_by_coach_in_a_session($_GET['id_session'], $coach_id);
  91. }
  92. $tracking_column = isset($_GET['tracking_column']) ? $_GET['tracking_column'] : 0;
  93. $tracking_direction = isset($_GET['tracking_direction']) ? $_GET['tracking_direction'] : DESC;
  94. if(count($a_students)>0)
  95. {
  96. $table = new SortableTable('tracking', 'count_student_coached');
  97. $table -> set_header(0, get_lang('LastName'), true, 'align="center');
  98. $table -> set_header(1, get_lang('FirstName'), true, 'align="center');
  99. $table -> set_header(2, get_lang('Time'),false);
  100. $table -> set_header(3, get_lang('Progress'),false);
  101. $table -> set_header(4, get_lang('Score'),false);
  102. $table -> set_header(5, get_lang('Student_publication'),false);
  103. $table -> set_header(6, get_lang('Messages'),false);
  104. $table -> set_header(7, get_lang('LatestLogin'), false);
  105. $table -> set_header(8, get_lang('Details'),false);
  106. if($export_csv)
  107. {
  108. $csv_content[] = array (
  109. get_lang('LastName'),
  110. get_lang('FirstName'),
  111. get_lang('Time'),
  112. get_lang('Progress'),
  113. get_lang('Score'),
  114. get_lang('Student_publication'),
  115. get_lang('Messages'),
  116. get_lang('LatestLogin')
  117. );
  118. }
  119. $all_datas = array();
  120. foreach($a_students as $student_id)
  121. {
  122. $student_datas = UserManager :: get_user_info_by_id($student_id);
  123. if(isset($_GET['id_session'])){
  124. $a_courses = Tracking :: get_course_list_in_session_from_student($student_id,$_GET['id_session']);
  125. }
  126. $avg_time_spent = $avg_student_score = $avg_student_progress = $total_assignments = $total_messages = 0 ;
  127. $nb_courses_student = 0;
  128. foreach($a_courses as $course_code)
  129. {
  130. if(CourseManager :: is_user_subscribed_in_course($student_id,$course_code, true))
  131. {
  132. $avg_time_spent += Tracking :: get_time_spent_on_the_platform($student_id, $course_code);
  133. $avg_student_score += Tracking :: get_avg_student_score($student_id, $course_code);
  134. $avg_student_progress += Tracking :: get_avg_student_progress($student_id, $course_code);
  135. $total_assignments += Tracking :: count_student_assignments($student_id, $course_code);
  136. $total_messages += Tracking :: count_student_messages($student_id, $course_code);
  137. $nb_courses_student++;
  138. }
  139. }
  140. $avg_time_spent = $avg_time_spent / $nb_courses_student;
  141. $avg_student_score = $avg_student_score / $nb_courses_student;
  142. $avg_student_progress = $avg_student_progress / $nb_courses_student;
  143. $row = array();
  144. $row[] = $student_datas['lastname'];
  145. $row[] = $student_datas['firstname'];
  146. $row[] = api_time_to_hms($avg_time_spent);
  147. $row[] = round($avg_student_progress,2).' %';
  148. $row[] = round($avg_student_score,2).' %';
  149. $row[] = $total_assignments;
  150. $row[] = $total_messages;
  151. $string_date=Tracking :: get_last_connection_date($student_id,true);
  152. $row[] = $string_date;
  153. if($export_csv)
  154. {
  155. $csv_content[] = $row;
  156. }
  157. if(isset($_GET['id_coach']) && intval($_GET['id_coach'])!=0){
  158. $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>';
  159. }
  160. else{
  161. $row[] = '<a href="myStudents.php?student='.$student_id.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  162. }
  163. $all_datas[] = $row;
  164. }
  165. usort($all_datas, 'sort_users');
  166. if($tracking_direction == 'ASC')
  167. rsort($all_datas);
  168. if($export_csv)
  169. {
  170. usort($csv_content, 'sort_users');
  171. }
  172. foreach($all_datas as $row)
  173. {
  174. $table -> addRow($row,'align="right"');
  175. }
  176. $table -> updateColAttributes(0,array('align'=>'left'));
  177. $table -> updateColAttributes(1,array('align'=>'left'));
  178. $table -> updateColAttributes(7,array('align'=>'left'));
  179. $table -> setColAttributes(8,array('align'=>'center'));
  180. $table -> display();
  181. }
  182. else
  183. {
  184. echo get_lang('NoStudent');
  185. }
  186. // send the csv file if asked
  187. if($export_csv)
  188. {
  189. ob_end_clean();
  190. Export :: export_table_csv($csv_content, 'reporting_student_list');
  191. }
  192. }
  193. /*
  194. ==============================================================================
  195. FOOTER
  196. ==============================================================================
  197. */
  198. Display :: display_footer();
  199. ?>