index.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <?php
  2. /**
  3. * @todo use constant for $this_section
  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 (api_get_path(LIBRARY_PATH).'tracking.lib.php');
  10. require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
  11. require_once(api_get_path(LIBRARY_PATH).'export.lib.inc.php');
  12. ob_start();
  13. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  14. $csv_content = array();
  15. $nameTools= get_lang("MySpace");
  16. $this_section = "session_my_space";
  17. api_block_anonymous_users();
  18. if(!$export_csv)
  19. {
  20. Display :: display_header($nameTools);
  21. }
  22. // Database table definitions
  23. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  24. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  25. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  26. $tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
  27. $tbl_sessions = Database :: get_main_table(TABLE_MAIN_SESSION);
  28. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  29. $tbl_session_user = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
  30. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  31. $tbl_admin = Database :: get_main_table(TABLE_MAIN_ADMIN);
  32. /********************
  33. * FUNCTIONS
  34. ********************/
  35. function count_teacher_courses()
  36. {
  37. global $nb_teacher_courses;
  38. return $nb_teacher_courses;
  39. }
  40. /**************************
  41. * MAIN CODE
  42. ***************************/
  43. $isCoach = api_is_coach();
  44. echo '<div align="right">
  45. <a href="#" onclick="window.print()"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>
  46. <a href="'.$_SERVER['PHP_SELF'].'?export=csv"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>
  47. </div>';
  48. if($isCoach)
  49. {
  50. /****************************************
  51. * Infos about students of the coach
  52. ****************************************/
  53. $a_students = Tracking :: get_student_followed_by_coach($_user['user_id']);
  54. $a_courses = Tracking :: get_courses_followed_by_coach($_user['user_id']);
  55. $nbStudents = count($a_students);
  56. $totalTimeSpent = 0;
  57. $totalCourses = 0;
  58. $avgTotalProgress = 0;
  59. $avgResultsToExercises = 0;
  60. $nb_inactive_students = 0;
  61. $nb_posts = $nb_assignments = 0;
  62. foreach($a_students as $student_id)
  63. {
  64. // inactive students
  65. if($last_connection_date = Tracking :: get_last_connection_date($student_id))
  66. {
  67. list($last_connection_date, $last_connection_hour) = explode(' ',$last_connection_date);
  68. $last_connection_date = explode('-',$last_connection_date);
  69. $last_connection_hour = explode(':',$last_connection_hour);
  70. $last_connection_time = mktime($last_connection_hour[0],$last_connection_hour[1],$last_connection_hour[2],$last_connection_date[1],$last_connection_date[2],$last_connection_date[0]);
  71. if(time()-(3600*24*7) > $last_connection_time)
  72. {
  73. $nb_inactive_students++;
  74. }
  75. }
  76. else
  77. {
  78. $nb_inactive_students++;
  79. }
  80. $totalTimeSpent += Tracking :: get_time_spent_on_the_platform($student_id);
  81. $totalCourses += Tracking :: count_course_per_student($student_id);
  82. $avgStudentProgress = $avgStudentScore = 0;
  83. $nb_courses_student = 0;
  84. foreach($a_courses as $course_code)
  85. {
  86. if(CourseManager :: is_user_subscribed_in_course($student_id, $course_code, true))
  87. {
  88. $nb_courses_student++;
  89. $nb_posts += Tracking :: count_student_messages($student_id,$course_code);
  90. $nb_assignments += Tracking :: count_student_assignments($student_id,$course_code);
  91. $avgStudentProgress += Tracking :: get_avg_student_progress($student_id,$course_code);
  92. $avgStudentScore += Tracking :: get_avg_student_score($student_id,$course_code);
  93. }
  94. }
  95. // average progress of the student
  96. $avgStudentProgress = $avgStudentProgress / $nb_courses_student;
  97. $avgTotalProgress += $avgStudentProgress;
  98. // average test results of the student
  99. $avgStudentScore = $avgStudentScore / $nb_courses_student;
  100. $avgResultsToExercises += $avgStudentScore;
  101. }
  102. // average progress
  103. $avgTotalProgress = $avgTotalProgress/$nbStudents;
  104. // average results to the tests
  105. $avgResultsToExercises = $avgResultsToExercises/$nbStudents;
  106. // average courses by student
  107. $avgCoursesPerStudent = round($totalCourses / $nbStudents,2);
  108. // average time spent on the platform
  109. $avgTimeSpent = $totalTimeSpent / $nbStudents;
  110. // average assignments
  111. $nb_assignments = $nb_assignments / $nbStudents;
  112. // average posts
  113. $nb_posts = $nb_posts / $nbStudents;
  114. //csv part
  115. if($export_csv)
  116. {
  117. $csv_content[] = array( get_lang('Probationers'));
  118. $csv_content[] = array( get_lang('InactivesStudents'),$nb_inactive_students );
  119. $csv_content[] = array( get_lang('AverageTimeSpentOnThePlatform'),$avgTimeSpent);
  120. $csv_content[] = array( get_lang('AverageCoursePerStudent'),$avgCoursesPerStudent);
  121. $csv_content[] = array( get_lang('AverageProgressInLearnpath'),$avgTotalProgress);
  122. $csv_content[] = array( get_lang('AverageResultsToTheExercices'),$avgResultsToExercises);
  123. $csv_content[] = array( get_lang('AveragePostsInForum'),$nb_posts);
  124. $csv_content[] = array( get_lang('AverageAssignments'),$nb_assignments);
  125. $csv_content[] = array();
  126. }
  127. // html part
  128. else
  129. {
  130. echo '
  131. <div class="admin_section">
  132. <h4>
  133. <a href="student.php"><img src="'.api_get_path(WEB_IMG_PATH).'students.gif">&nbsp;'.get_lang('Probationers').' ('.$nbStudents.')'.'</a>
  134. </h4>
  135. <table class="data_table">
  136. <tr>
  137. <td>
  138. '.get_lang('InactivesStudents').'
  139. </td>
  140. <td align="right">
  141. '.$nb_inactive_students.'
  142. </td>
  143. </tr>
  144. <tr>
  145. <td>
  146. '.get_lang('AverageTimeSpentOnThePlatform').'
  147. </td>
  148. <td align="right">
  149. '.api_time_to_hms($avgTimeSpent).'
  150. </td>
  151. </tr>
  152. <tr>
  153. <td>
  154. '.get_lang('AverageCoursePerStudent').'
  155. </td>
  156. <td align="right">
  157. '.$avgCoursesPerStudent.'
  158. </td>
  159. </tr>
  160. <tr>
  161. <td>
  162. '.get_lang('AverageProgressInLearnpath').'
  163. </td>
  164. <td align="right">
  165. '.round($avgTotalProgress,2).' %
  166. </td>
  167. </tr>
  168. <tr>
  169. <td>
  170. '.get_lang('AverageResultsToTheExercices').'
  171. </td>
  172. <td align="right">
  173. '.round($avgResultsToExercises,2).' %
  174. </td>
  175. </tr>
  176. <tr>
  177. <td>
  178. '.get_lang('AveragePostsInForum').'
  179. </td>
  180. <td align="right">
  181. '.round($nb_posts,2).'
  182. </td>
  183. </tr>
  184. <tr>
  185. <td>
  186. '.get_lang('AverageAssignments').'
  187. </td>
  188. <td align="right">
  189. '.round($nb_assignments,2).'
  190. </td>
  191. </tr>
  192. </table>
  193. <a href="student.php">'.get_lang('SeeStudentList').'</a>
  194. </div>';
  195. }
  196. /****************************************
  197. * Infos about sessions of the coach
  198. ****************************************/
  199. $a_sessions = Tracking :: get_sessions_coached_by_user($_user['user_id']);
  200. $nbSessions = count($a_sessions);
  201. $nb_sessions_past = $nb_sessions_future = $nb_sessions_current = 0;
  202. $a_courses = array();
  203. foreach($a_sessions as $a_session)
  204. {
  205. if($a_session['date_start'] == '0000-00-00')
  206. {
  207. $nb_sessions_current ++;
  208. }
  209. else
  210. {
  211. $date_start = explode('-',$a_session['date_start']);
  212. $time_start = mktime(0,0,0,$date_start[1],$date_start[2],$date_start[0]);
  213. $date_end = explode('-',$a_session['date_end']);
  214. $time_end = mktime(0,0,0,$date_end[1],$date_end[2],$date_end[0]);
  215. if($time_start < time() && time() < $time_end)
  216. {
  217. $nb_sessions_current++;
  218. }
  219. else if(time() < $time_start)
  220. {
  221. $nb_sessions_future++;
  222. }
  223. else if(time() > $time_end)
  224. {
  225. $nb_sessions_past++;
  226. }
  227. }
  228. $a_courses = array_merge($a_courses, Tracking::get_courses_list_from_session($a_session['id']));
  229. }
  230. $nb_courses_per_session = round(count($a_courses)/$nbSessions,2);
  231. //csv part
  232. if($export_csv)
  233. {
  234. $csv_content[] = array( get_lang('Sessions'));
  235. $csv_content[] = array( get_lang('NbActiveSessions').';'.$nb_sessions_current);
  236. $csv_content[] = array( get_lang('NbPastSessions').';'.$nb_sessions_past);
  237. $csv_content[] = array( get_lang('NbFutureSessions').';'.$nb_sessions_future);
  238. $csv_content[] = array( get_lang('NbStudentPerSession').';'.round($nbStudents/$nbSessions,2));
  239. $csv_content[] = array( get_lang('NbCoursesPerSession').';'.$nb_courses_per_session);
  240. $csv_content[] = array();
  241. }
  242. // html part
  243. else
  244. {
  245. echo '
  246. <div class="admin_section">
  247. <h4>
  248. <a href="session.php"><img src="'.api_get_path(WEB_IMG_PATH).'sessions.gif">&nbsp;'.get_lang('Sessions').' ('.$nbSessions.')'.'</a>
  249. </h4>
  250. <table class="data_table">
  251. <tr>
  252. <td>
  253. '.get_lang('NbActiveSessions').'
  254. </td>
  255. <td align="right">
  256. '.$nb_sessions_current.'
  257. </td>
  258. </tr>
  259. <tr>
  260. <td>
  261. '.get_lang('NbPastSessions').'
  262. </td>
  263. <td align="right">
  264. '.$nb_sessions_past.'
  265. </td>
  266. </tr>
  267. <tr>
  268. <td>
  269. '.get_lang('NbFutureSessions').'
  270. </td>
  271. <td align="right">
  272. '.$nb_sessions_future.'
  273. </td>
  274. </tr>
  275. <tr>
  276. <td>
  277. '.get_lang('NbStudentPerSession').'
  278. </td>
  279. <td align="right">
  280. '.round($nbStudents/$nbSessions,2).'
  281. </td>
  282. </tr>
  283. <tr>
  284. <td>
  285. '.get_lang('NbCoursesPerSession').'
  286. </td>
  287. <td align="right">
  288. '.$nb_courses_per_session.'
  289. </td>
  290. </tr>
  291. </table>
  292. <a href="session.php">'.get_lang('SeeSessionList').'</a>
  293. </div>';
  294. }
  295. }
  296. echo '<div class="clear">&nbsp;</div>';
  297. $sqlNbCours = " SELECT course_rel_user.course_code, course.title
  298. FROM $tbl_course_user as course_rel_user
  299. INNER JOIN $tbl_course as course
  300. ON course.code = course_rel_user.course_code
  301. WHERE course_rel_user.user_id='".$_user['user_id']."' AND course_rel_user.status='1'
  302. ";
  303. $resultNbCours = api_sql_query($sqlNbCours, __FILE__, __LINE__);
  304. $a_courses = api_store_result($resultNbCours);
  305. $nb_teacher_courses = count($a_courses);
  306. if($nb_teacher_courses)
  307. {
  308. $table = new SortableTable('tracking_list_course', 'count_teacher_courses');
  309. $table -> set_header(0, get_lang('CourseTitle'), false);
  310. $table -> set_header(1, get_lang('NbStudents'), false);
  311. $table -> set_header(2, get_lang('TimeSpentInTheCourse'), false);
  312. $table -> set_header(3, get_lang('AvgStudentsProgress'), false);
  313. $table -> set_header(4, get_lang('AvgStudentsScore'), false);
  314. $table -> set_header(5, get_lang('AvgMessages'), false);
  315. $table -> set_header(6, get_lang('AvgAssignments'), false);
  316. $table -> set_header(7, get_lang('Details'), false);
  317. $csv_content[] = array(
  318. get_lang('CourseTitle'),
  319. get_lang('NbStudents'),
  320. get_lang('TimeSpentInTheCourse'),
  321. get_lang('AvgStudentsProgress'),
  322. get_lang('AvgStudentsScore'),
  323. get_lang('AvgMessages'),
  324. get_lang('AvgAssignments')
  325. );
  326. $a_students = array();
  327. foreach($a_courses as $course)
  328. {
  329. $course_code = $course['course_code'];
  330. $avg_assignments_in_course = $avg_messages_in_course = $nb_students_in_course = $avg_progress_in_course = $avg_score_in_course = $avg_time_spent_in_course = 0;
  331. // students directly subscribed to the course
  332. $sql = "SELECT user_id FROM $tbl_course_user as course_rel_user WHERE course_rel_user.status='5' AND course_rel_user.course_code='$course_code'";
  333. $rs = api_sql_query($sql, __FILE__, __LINE__);
  334. while($row = mysql_fetch_array($rs))
  335. {
  336. $nb_students_in_course++;
  337. // tracking datas
  338. $avg_progress_in_course += Tracking :: get_avg_student_progress ($row['user_id'], $course_code);
  339. $avg_score_in_course += Tracking :: get_avg_student_score ($row['user_id'], $course_code);
  340. $avg_time_spent_in_course += Tracking :: get_time_spent_on_the_course ($row['user_id'], $course_code);
  341. $avg_messages_in_course += Tracking :: count_student_messages ($row['user_id'], $course_code);
  342. $avg_assignments_in_course += Tracking :: count_student_assignments ($row['user_id'], $course_code);
  343. $a_students[] = $row['user_id'];
  344. }
  345. // students subscribed to the course throw a session
  346. if(api_get_setting('use_session_mode') == 'true')
  347. {
  348. $sql = 'SELECT id_user as user_id
  349. FROM '.$tbl_session_course_user.'
  350. WHERE course_code="'.addslashes($course_code).'"';
  351. $rs = api_sql_query($sql, __FILE__, __LINE__);
  352. while($row = mysql_fetch_array($rs))
  353. {
  354. if(!in_array($row['user_id'], $a_students))
  355. {
  356. $nb_students_in_course++;
  357. // tracking datas
  358. $avg_progress_in_course += Tracking :: get_avg_student_progress ($row['user_id'], $course_code);
  359. $avg_score_in_course += Tracking :: get_avg_student_score ($row['user_id'], $course_code);
  360. $avg_time_spent_in_course += Tracking :: get_time_spent_on_the_course ($row['user_id'], $course_code);
  361. $avg_messages_in_course += Tracking :: count_student_messages ($row['user_id'], $course_code);
  362. $avg_assignments_in_course += Tracking :: count_student_assignments ($row['user_id'], $course_code);
  363. $a_students[] = $row['user_id'];
  364. }
  365. }
  366. }
  367. if($nb_students_in_course>0)
  368. {
  369. $avg_time_spent_in_course = api_time_to_hms($avg_time_spent_in_course / $nb_students_in_course);
  370. $avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course,2).' %';
  371. $avg_score_in_course = round($avg_score_in_course / $nb_students_in_course,2).' %';
  372. $avg_messages_in_course = round($avg_messages_in_course / $nb_students_in_course,2);
  373. $avg_assignments_in_course = round($avg_assignments_in_course / $nb_students_in_course,2);
  374. }
  375. $table_row = array();
  376. $table_row[] = $course['title'];
  377. $table_row[] = $nb_students_in_course;
  378. $table_row[] = $avg_time_spent_in_course;
  379. $table_row[] = $avg_progress_in_course;
  380. $table_row[] = $avg_score_in_course;
  381. $table_row[] = $avg_messages_in_course;
  382. $table_row[] = $avg_assignments_in_course;
  383. $table_row[] = '<a href="../tracking/courseLog.php?cidReq='.$course_code.'&studentlist=true"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  384. $csv_content[] = array(
  385. $course['title'],
  386. $nb_students_in_course,
  387. $avg_time_spent_in_course,
  388. $avg_progress_in_course,
  389. $avg_score_in_course,
  390. $avg_messages_in_course,
  391. $avg_assignments_in_course,
  392. );
  393. $table -> addRow($table_row, 'align="left"');
  394. }
  395. $table -> setColAttributes(7,array('align'=>'center'));
  396. $table -> display();
  397. }
  398. // send the csv file if asked
  399. if($export_csv)
  400. {
  401. ob_end_clean();
  402. Export :: export_table_csv($csv_content, 'reporting_index');
  403. }
  404. /*
  405. ==============================================================================
  406. FOOTER
  407. ==============================================================================
  408. */
  409. if(!$export_csv)
  410. {
  411. Display::display_footer();
  412. }
  413. ?>