index.php 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  1. <?php // $Id: index.php 16620 2008-10-25 20:03:54Z yannoo $
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  4. * @todo use constant for $this_section
  5. */
  6. // name of the language file that needs to be included
  7. $language_file = array ('registration', 'index', 'tracking');
  8. // resetting the course id
  9. $cidReset = true;
  10. // including the global Dokeos file
  11. require '../inc/global.inc.php';
  12. // including additional libraries
  13. require api_get_path(LIBRARY_PATH).'tracking.lib.php';
  14. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  15. require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
  16. // the section (for the tabs)
  17. $this_section = "session_my_space";
  18. ob_start();
  19. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  20. $csv_content = array();
  21. $nameTools = get_lang("MySpace");
  22. // access control
  23. api_block_anonymous_users();
  24. if (!$export_csv) {
  25. Display :: display_header($nameTools);
  26. } else {
  27. if ($_GET['view'] == 'admin' AND $_GET['display'] == 'useroverview') {
  28. export_tracking_user_overview();
  29. exit;
  30. }
  31. }
  32. // Database table definitions
  33. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  34. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  35. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  36. $tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
  37. $tbl_sessions = Database :: get_main_table(TABLE_MAIN_SESSION);
  38. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  39. $tbl_session_user = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
  40. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  41. $tbl_admin = Database :: get_main_table(TABLE_MAIN_ADMIN);
  42. /********************
  43. * FUNCTIONS
  44. ********************/
  45. function count_teacher_courses() {
  46. global $nb_teacher_courses;
  47. return $nb_teacher_courses;
  48. }
  49. function count_coaches() {
  50. global $total_no_coaches;
  51. return $total_no_coaches;
  52. }
  53. function sort_users($a, $b) {
  54. return api_strcmp(trim(api_strtolower($a[$_SESSION['tracking_column']])), trim(api_strtolower($b[$_SESSION['tracking_column']])));
  55. }
  56. function rsort_users($a, $b) {
  57. return api_strcmp(trim(api_strtolower($b[$_SESSION['tracking_column']])), trim(api_strtolower($a[$_SESSION['tracking_column']])));
  58. }
  59. /**************************
  60. * MAIN CODE
  61. ***************************/
  62. $is_coach = api_is_coach();
  63. $is_platform_admin = api_is_platform_admin();
  64. $view = isset($_GET['view']) ? $_GET['view'] : 'teacher';
  65. $menu_items = array();
  66. global $_configuration;
  67. if (api_is_allowed_to_create_course()) {
  68. $sql_nb_cours = "SELECT course_rel_user.course_code, course.title
  69. FROM $tbl_course_user as course_rel_user
  70. INNER JOIN $tbl_course as course
  71. ON course.code = course_rel_user.course_code
  72. WHERE course_rel_user.user_id='".$_user['user_id']."' AND course_rel_user.status='1'
  73. ORDER BY course.title";
  74. if ($_configuration['multiple_access_urls'] == true) {
  75. $tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  76. $access_url_id = api_get_current_access_url_id();
  77. if ($access_url_id != -1) {
  78. $sql_nb_cours = " SELECT course_rel_user.course_code, course.title
  79. FROM $tbl_course_user as course_rel_user
  80. INNER JOIN $tbl_course as course
  81. ON course.code = course_rel_user.course_code
  82. INNER JOIN $tbl_course_rel_access_url course_rel_url
  83. ON (course_rel_url.course_code= course.code)
  84. WHERE access_url_id = $access_url_id AND course_rel_user.user_id='".$_user['user_id']."' AND course_rel_user.status='1'
  85. ORDER BY course.title";
  86. }
  87. }
  88. $result_nb_cours = Database::query($sql_nb_cours, __FILE__, __LINE__);
  89. $courses = Database::store_result($result_nb_cours);
  90. $nb_teacher_courses = count($courses);
  91. if ($nb_teacher_courses) {
  92. if (!$is_coach && !$is_platform_admin) {
  93. $view = 'teacher';
  94. }
  95. if ($view == 'teacher') {
  96. $menu_items[] = get_lang('TeacherInterface');
  97. $title = get_lang('YourCourseList');
  98. } else {
  99. $menu_items[] = '<a href="'.api_get_self().'?view=teacher">'.get_lang('TeacherInterface').'</a>';
  100. }
  101. }
  102. }
  103. if ($is_coach) {
  104. if ($nb_teacher_courses == 0 && !$is_platform_admin) {
  105. $view = 'coach';
  106. }
  107. if ($view == 'coach') {
  108. $menu_items[] = get_lang('CoachInterface');
  109. $title = get_lang('YourStatistics');
  110. } else {
  111. $menu_items[] = '<a href="'.api_get_self().'?view=coach">'.get_lang('CoachInterface').'</a>';
  112. }
  113. }
  114. if ($is_platform_admin) {
  115. if (!$is_coach && $nb_teacher_courses == 0) {
  116. $view = 'admin';
  117. }
  118. if ($view == 'admin') {
  119. $menu_items[] = get_lang('AdminInterface');
  120. $title = get_lang('CoachList');
  121. } else {
  122. $menu_items[] = '<a href="'.api_get_self().'?view=admin">'.get_lang('AdminInterface').'</a>';
  123. }
  124. }
  125. if ($_user['status'] == DRH) {
  126. $view = 'drh';
  127. $title = get_lang('DrhInterface');
  128. $menu_items[] = '<a href="'.api_get_self().'?view=drh">'.get_lang('DrhInterface').'</a>';
  129. }
  130. echo '<div class="actions">';
  131. $nb_menu_items = count($menu_items);
  132. if ($nb_menu_items > 1) {
  133. foreach ($menu_items as $key => $item) {
  134. echo $item;
  135. if ($key != $nb_menu_items - 1) {
  136. echo ' | ';
  137. }
  138. }
  139. }
  140. echo '<a href="javascript: void(0);" onclick="javascript: window.print()"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a> ';
  141. echo (isset($_GET['display']) && $_GET['display'] == 'useroverview')? '' : '<a href="'.api_get_self().'?export=csv&view='.$view.'"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>';
  142. echo '</div>';
  143. echo '<h4>'.$title.'</h4>';
  144. if ($_user['status'] == DRH && $view == 'drh') {
  145. $students = Tracking :: get_student_followed_by_drh($_user['user_id']);
  146. $courses_of_the_platform = CourseManager :: get_real_course_list();
  147. foreach ($courses_of_the_platform as $course) {
  148. $courses[$course['code']] = $course['code'];
  149. }
  150. }
  151. if ($is_coach && $view == 'coach') {
  152. $students = Tracking :: get_student_followed_by_coach($_user['user_id']);
  153. $courses = Tracking :: get_courses_followed_by_coach($_user['user_id']);
  154. }
  155. if ($view == 'coach' || $view == 'drh') {
  156. $nb_students = count($students);
  157. $total_time_spent = 0;
  158. $total_courses = 0;
  159. $avg_total_progress = 0;
  160. $avg_results_to_exercises = 0;
  161. $nb_inactive_students = 0;
  162. $nb_posts = $nb_assignments = 0;
  163. foreach ($students as $student_id) {
  164. // inactive students
  165. $last_connection_date = Tracking :: get_last_connection_date($student_id, true, true);
  166. if ($last_connection_date != false) {
  167. /*
  168. list($last_connection_date, $last_connection_hour) = explode(' ', $last_connection_date);
  169. $last_connection_date = explode('-', $last_connection_date);
  170. $last_connection_hour = explode(':', $last_connection_hour);
  171. $last_connection_hour[0];
  172. $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]);
  173. */
  174. if (time() - (3600 * 24 * 7) > $last_connection_time) {
  175. $nb_inactive_students++;
  176. }
  177. } else {
  178. $nb_inactive_students++;
  179. }
  180. $total_time_spent += Tracking :: get_time_spent_on_the_platform($student_id);
  181. $total_courses += Tracking :: count_course_per_student($student_id);
  182. $avg_student_progress = $avg_student_score = 0;
  183. $nb_courses_student = 0;
  184. foreach ($courses as $course_code) {
  185. if (CourseManager :: is_user_subscribed_in_course($student_id, $course_code, true)) {
  186. $nb_courses_student++;
  187. $nb_posts += Tracking :: count_student_messages($student_id, $course_code);
  188. $nb_assignments += Tracking :: count_student_assignments($student_id, $course_code);
  189. $avg_student_progress += Tracking :: get_avg_student_progress($student_id, $course_code);
  190. $avg_student_score += Tracking :: get_avg_student_score($student_id, $course_code);
  191. if ($nb_posts !== null && $nb_assignments !== null && $avg_student_progress !== null && $avg_student_score !== null) {
  192. //if one of these scores is null, it means that we had a problem connecting to the right database, so don't count it in
  193. $nb_courses_student++;
  194. }
  195. }
  196. }
  197. // average progress of the student
  198. $avg_student_progress = $avg_student_progress / $nb_courses_student;
  199. $avg_total_progress += $avg_student_progress;
  200. // average test results of the student
  201. $avg_student_score = $avg_student_score / $nb_courses_student;
  202. $avg_results_to_exercises += $avg_student_score;
  203. }
  204. if ($nb_students > 0) {
  205. // average progress
  206. $avg_total_progress = $avg_total_progress / $nb_students;
  207. // average results to the tests
  208. $avg_results_to_exercises = $avg_results_to_exercises / $nb_students;
  209. // average courses by student
  210. $avg_courses_per_student = round($total_courses / $nb_students, 2);
  211. // average time spent on the platform
  212. $avg_time_spent = $total_time_spent / $nb_students;
  213. // average assignments
  214. $nb_assignments = $nb_assignments / $nb_students;
  215. // average posts
  216. $nb_posts = $nb_posts / $nb_students;
  217. } else {
  218. $avg_total_progress = null;
  219. $avg_results_to_exercises = null;
  220. $avg_courses_per_student = null;
  221. $avg_time_spent = null;
  222. $nb_assignments = null;
  223. $nb_posts = null;
  224. }
  225. if ($export_csv) {
  226. //csv part
  227. $csv_content[] = array(get_lang('Probationers', ''));
  228. $csv_content[] = array(get_lang('InactivesStudents', ''), $nb_inactive_students );
  229. $csv_content[] = array(get_lang('AverageTimeSpentOnThePlatform', ''), $avg_time_spent);
  230. $csv_content[] = array(get_lang('AverageCoursePerStudent', ''), $avg_courses_per_student);
  231. $csv_content[] = array(get_lang('AverageProgressInLearnpath', ''), is_null($avg_total_progress) ? null : round($avg_total_progress, 2).'%');
  232. $csv_content[] = array(get_lang('AverageResultsToTheExercices', ''), is_null($avg_results_to_exercises) ? null : round($avg_results_to_exercises, 2).'%');
  233. $csv_content[] = array(get_lang('AveragePostsInForum', ''), $nb_posts);
  234. $csv_content[] = array(get_lang('AverageAssignments', ''), $nb_assignments);
  235. $csv_content[] = array();
  236. } else {
  237. // html part
  238. echo '
  239. <div class="report_section">
  240. <h4>
  241. <a href="student.php"><img src="'.api_get_path(WEB_IMG_PATH).'students.gif">&nbsp;'.get_lang('Probationers').' ('.$nb_students.')'.'</a>
  242. </h4>
  243. <table class="data_table">
  244. <tr>
  245. <td>
  246. '.get_lang('InactivesStudents').'
  247. </td>
  248. <td align="right">
  249. '.$nb_inactive_students.'
  250. </td>
  251. </tr>
  252. <tr>
  253. <td>
  254. '.get_lang('AverageTimeSpentOnThePlatform').'
  255. </td>
  256. <td align="right">
  257. '.(is_null($avg_time_spent) ? '' : api_time_to_hms($avg_time_spent)).'
  258. </td>
  259. </tr>
  260. <tr>
  261. <td>
  262. '.get_lang('AverageCoursePerStudent').'
  263. </td>
  264. <td align="right">
  265. '.(is_null($avg_courses_per_student) ? '' : $avg_courses_per_student).'
  266. </td>
  267. </tr>
  268. <tr>
  269. <td>
  270. '.get_lang('AverageProgressInLearnpath').'
  271. </td>
  272. <td align="right">
  273. '.(is_null($avg_total_progress) ? '' : round($avg_total_progress, 2).'%').'
  274. </td>
  275. </tr>
  276. <tr>
  277. <td>
  278. '.get_lang('AverageResultsToTheExercices').'
  279. </td>
  280. <td align="right">
  281. '.(is_null($avg_results_to_exercises) ? '' : round($avg_results_to_exercises, 2).'%').'
  282. </td>
  283. </tr>
  284. <tr>
  285. <td>
  286. '.get_lang('AveragePostsInForum').'
  287. </td>
  288. <td align="right">
  289. '.(is_null($nb_posts) ? '' : round($nb_posts, 2)).'
  290. </td>
  291. </tr>
  292. <tr>
  293. <td>
  294. '.get_lang('AverageAssignments').'
  295. </td>
  296. <td align="right">
  297. '.(is_null($nb_assignments) ? '' : round($nb_assignments, 2)).'
  298. </td>
  299. </tr>
  300. </table>
  301. <a href="student.php">'.get_lang('SeeStudentList').'</a>
  302. </div>';
  303. }
  304. }
  305. if ($view == 'coach') {
  306. /****************************************
  307. * Infos about sessions of the coach
  308. ****************************************/
  309. $sessions = Tracking :: get_sessions_coached_by_user($_user['user_id']);
  310. $nb_sessions = count($sessions);
  311. $nb_sessions_past = $nb_sessions_future = $nb_sessions_current = 0;
  312. $courses = array();
  313. foreach ($sessions as $session) {
  314. if ($session['date_start'] == '0000-00-00') {
  315. $nb_sessions_current ++;
  316. } else {
  317. $date_start = explode('-', $session['date_start']);
  318. $time_start = mktime(0, 0, 0, $date_start[1], $date_start[2], $date_start[0]);
  319. $date_end = explode('-', $session['date_end']);
  320. $time_end = mktime(0, 0, 0, $date_end[1], $date_end[2], $date_end[0]);
  321. if ($time_start < time() && time() < $time_end) {
  322. $nb_sessions_current++;
  323. }
  324. elseif (time() < $time_start) {
  325. $nb_sessions_future++;
  326. }
  327. elseif (time() > $time_end) {
  328. $nb_sessions_past++;
  329. }
  330. }
  331. $courses = array_merge($courses, Tracking::get_courses_list_from_session($session['id']));
  332. }
  333. if ($nb_sessions > 0) {
  334. $nb_courses_per_session = round(count($courses) / $nb_sessions, 2);
  335. $nb_students_per_session = round($nb_students / $nb_sessions, 2);
  336. } else {
  337. $nb_courses_per_session = null;
  338. $nb_students_per_session = null;
  339. }
  340. if ($export_csv) {
  341. //csv part
  342. $csv_content[] = array(get_lang('Sessions', ''));
  343. $csv_content[] = array(get_lang('NbActiveSessions', '').';'.$nb_sessions_current);
  344. $csv_content[] = array(get_lang('NbPastSessions', '').';'.$nb_sessions_past);
  345. $csv_content[] = array(get_lang('NbFutureSessions', '').';'.$nb_sessions_future);
  346. $csv_content[] = array(get_lang('NbStudentPerSession', '').';'.$nb_students_per_session);
  347. $csv_content[] = array(get_lang('NbCoursesPerSession', '').';'.$nb_courses_per_session);
  348. $csv_content[] = array();
  349. } else {
  350. // html part
  351. echo '
  352. <div class="report_section">
  353. <h4>
  354. <a href="session.php"><img src="'.api_get_path(WEB_IMG_PATH).'sessions.gif">&nbsp;'.get_lang('Sessions').' ('.$nb_sessions.')'.'</a>
  355. </h4>
  356. <table class="data_table">
  357. <tr>
  358. <td>
  359. '.get_lang('NbActiveSessions').'
  360. </td>
  361. <td align="right">
  362. '.$nb_sessions_current.'
  363. </td>
  364. </tr>
  365. <tr>
  366. <td>
  367. '.get_lang('NbPastSessions').'
  368. </td>
  369. <td align="right">
  370. '.$nb_sessions_past.'
  371. </td>
  372. </tr>
  373. <tr>
  374. <td>
  375. '.get_lang('NbFutureSessions').'
  376. </td>
  377. <td align="right">
  378. '.$nb_sessions_future.'
  379. </td>
  380. </tr>
  381. <tr>
  382. <td>
  383. '.get_lang('NbStudentPerSession').'
  384. </td>
  385. <td align="right">
  386. '.(is_null($nb_students_per_session) ? '' : $nb_students_per_session).'
  387. </td>
  388. </tr>
  389. <tr>
  390. <td>
  391. '.get_lang('NbCoursesPerSession').'
  392. </td>
  393. <td align="right">
  394. '.(is_null($nb_courses_per_session) ? '' : $nb_courses_per_session).'
  395. </td>
  396. </tr>
  397. </table>
  398. <a href="session.php">'.get_lang('SeeSessionList').'</a>
  399. </div>';
  400. }
  401. }
  402. echo '<div class="clear">&nbsp;</div>';
  403. if (api_is_allowed_to_create_course() && $view == 'teacher') {
  404. if ($nb_teacher_courses) {
  405. $table = new SortableTable('tracking_list_course', 'count_teacher_courses');
  406. $parameters['view'] = 'teacher';
  407. $parameters['class'] = 'data_table';
  408. $table->set_additional_parameters($parameters);
  409. $table -> set_header(0, get_lang('CourseTitle'), false, 'align="center"');
  410. $table -> set_header(1, get_lang('NbStudents'), false);
  411. $table -> set_header(2, get_lang('AvgTimeSpentInTheCourse').Display :: return_icon('info3.gif', get_lang('TimeOfActiveByTraining'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
  412. $table -> set_header(3, get_lang('AvgStudentsProgress').Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
  413. $table -> set_header(4, get_lang('AvgCourseScore').Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
  414. $table -> set_header(5, get_lang('AvgExercisesScore').Display :: return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false);
  415. $table -> set_header(6, get_lang('AvgMessages'), false);
  416. $table -> set_header(7, get_lang('AvgAssignments'), false);
  417. $table -> set_header(8, get_lang('Details'), false);
  418. $csv_content[] = array (
  419. get_lang('CourseTitle', ''),
  420. get_lang('NbStudents', ''),
  421. get_lang('AvgTimeSpentInTheCourse', ''),
  422. get_lang('AvgStudentsProgress', ''),
  423. get_lang('AvgCourseScore', ''),
  424. get_lang('AvgExercisesScore', ''),
  425. get_lang('AvgMessages', ''),
  426. get_lang('AvgAssignments', '')
  427. );
  428. $a_course_students = array();
  429. foreach ($courses as $course) {
  430. $course_code = $course['course_code'];
  431. $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 = $avg_score_in_exercise = 0;
  432. // students directly subscribed to the course
  433. $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'";
  434. $rs = Database::query($sql, __FILE__, __LINE__);
  435. while ($row = Database::fetch_array($rs)) {
  436. $nb_students_in_course++;
  437. // tracking datas
  438. $avg_progress_in_course += Tracking :: get_avg_student_progress ($row['user_id'], $course_code);
  439. $avg_score_in_course += Tracking :: get_avg_student_score ($row['user_id'], $course_code);
  440. $avg_score_in_exercise += Tracking :: get_avg_student_exercise_score ($row['user_id'], $course_code);
  441. $avg_time_spent_in_course += Tracking :: get_time_spent_on_the_course ($row['user_id'], $course_code);
  442. $avg_messages_in_course += Tracking :: count_student_messages ($row['user_id'], $course_code);
  443. $avg_assignments_in_course += Tracking :: count_student_assignments ($row['user_id'], $course_code);
  444. $a_course_students[] = $row['user_id'];
  445. }
  446. // students subscribed to the course through a session
  447. if (api_get_setting('use_session_mode') == 'true') {
  448. $sql = 'SELECT id_user as user_id
  449. FROM '.$tbl_session_course_user.'
  450. WHERE course_code="'.addslashes($course_code).'" ORDER BY course_code';
  451. $rs = Database::query($sql, __FILE__, __LINE__);
  452. while ($row = Database::fetch_array($rs)) {
  453. if (!in_array($row['user_id'], $a_course_students)) {
  454. $nb_students_in_course++;
  455. // tracking datas
  456. $avg_progress_in_course += Tracking :: get_avg_student_progress ($row['user_id'], $course_code);
  457. $avg_score_in_course += Tracking :: get_avg_student_score ($row['user_id'], $course_code);
  458. $avg_score_in_exercise += Tracking :: get_avg_student_exercise_score ($row['user_id'], $course_code);
  459. $avg_time_spent_in_course += Tracking :: get_time_spent_on_the_course ($row['user_id'], $course_code);
  460. $avg_messages_in_course += Tracking :: count_student_messages ($row['user_id'], $course_code);
  461. $avg_assignments_in_course += Tracking :: count_student_assignments ($row['user_id'], $course_code);
  462. $a_course_students[] = $row['user_id'];
  463. }
  464. }
  465. }
  466. if ($nb_students_in_course > 0) {
  467. $avg_time_spent_in_course = api_time_to_hms($avg_time_spent_in_course / $nb_students_in_course);
  468. $avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course, 2);
  469. $avg_score_in_course = round($avg_score_in_course / $nb_students_in_course, 2);
  470. $avg_score_in_exercise = round($avg_score_in_exercise / $nb_students_in_course, 2);
  471. $avg_messages_in_course = round($avg_messages_in_course / $nb_students_in_course, 2);
  472. $avg_assignments_in_course = round($avg_assignments_in_course / $nb_students_in_course, 2);
  473. } else {
  474. $avg_time_spent_in_course = null;
  475. $avg_progress_in_course = null;
  476. $avg_score_in_course = null;
  477. $avg_score_in_exercise = null;
  478. $avg_messages_in_course = null;
  479. $avg_assignments_in_course = null;
  480. }
  481. $table_row = array();
  482. $table_row[] = $course['title'];
  483. $table_row[] = $nb_students_in_course;
  484. $table_row[] = $avg_time_spent_in_course;
  485. $table_row[] = is_null($avg_progress_in_course) ? '' : $avg_progress_in_course.'%';
  486. $table_row[] = is_null($avg_score_in_course) ? '' : $avg_score_in_course.'%';
  487. $table_row[] = is_null($avg_score_in_exercise) ? '' : $avg_score_in_exercise.'%';
  488. $table_row[] = $avg_messages_in_course;
  489. $table_row[] = $avg_assignments_in_course;
  490. //set the "from" value to know if I access the Reporting by the Dokeos tab or the course link
  491. $table_row[] = '<center><a href="../tracking/courseLog.php?cidReq='.$course_code.'&studentlist=true&from=myspace"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></center>';
  492. $csv_content[] = array(
  493. api_html_entity_decode($course['title'], ENT_QUOTES, $charset),
  494. $nb_students_in_course,
  495. $avg_time_spent_in_course,
  496. is_null($avg_progress_in_course) ? null : $avg_progress_in_course.'%',
  497. is_null($avg_score_in_course) ? null : $avg_score_in_course.'%',
  498. is_null($avg_score_in_exercise) ? null : $avg_score_in_exercise.'%',
  499. $avg_messages_in_course,
  500. $avg_assignments_in_course,
  501. );
  502. $table -> addRow($table_row, 'align="right"');
  503. $a_course_students = array();
  504. }
  505. $table -> updateColAttributes(0, array('align' => 'left'));
  506. $table -> updateColAttributes(7, array('align' => 'center'));
  507. $table -> display();
  508. }
  509. }
  510. if ($is_platform_admin && $view == 'admin') {
  511. echo '<a href="'.api_get_self().'?view=admin&amp;display=coaches">'.get_lang('DisplayCoaches').'</a> | ';
  512. echo '<a href="'.api_get_self().'?view=admin&amp;display=useroverview">'.get_lang('DisplayUserOverview').'</a>';
  513. if ($_GET['display'] == 'useroverview') {
  514. echo ' | <a href="'.api_get_self().'?view=admin&amp;display=useroverview&amp;export=options">'.get_lang('ExportUserOverviewOptions').'</a>';
  515. }
  516. if ($_GET['display'] === 'useroverview') {
  517. display_tracking_user_overview();
  518. } else {
  519. if ($export_csv) {
  520. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  521. } else {
  522. $is_western_name_order = api_is_western_name_order();
  523. }
  524. $sort_by_first_name = api_sort_by_first_name();
  525. $tracking_column = isset($_GET['tracking_list_coaches_column']) ? $_GET['tracking_list_coaches_column'] : ($is_western_name_order xor $sort_by_first_name) ? 1 : 0;
  526. $tracking_direction = (isset($_GET['tracking_list_coaches_direction']) && in_array(strtoupper($_GET['tracking_list_coaches_direction']), array('ASC', 'DESC', 'ASCENDING', 'DESCENDING', '0', '1'))) ? $_GET['tracking_list_coaches_direction'] : 'DESC';
  527. // Prepare array for column order - when impossible, use some of user names.
  528. if ($is_western_name_order) {
  529. $order = array(0 => 'firstname', 1 => 'lastname', 2 => ($sort_by_first_name ? 'firstname' : 'lastname'), 3 => 'login_date', 4 => ($sort_by_first_name ? 'firstname' : 'lastname'), 5 => ($sort_by_first_name ? 'firstname' : 'lastname'));
  530. } else {
  531. $order = array(0 => 'lastname', 1 => 'firstname', 2 => ($sort_by_first_name ? 'firstname' : 'lastname'), 3 => 'login_date', 4 => ($sort_by_first_name ? 'firstname' : 'lastname'), 5 => ($sort_by_first_name ? 'firstname' : 'lastname'));
  532. }
  533. $table = new SortableTable('tracking_list_coaches', 'count_coaches', null, ($is_western_name_order xor $sort_by_first_name) ? 1 : 0);
  534. $parameters['view'] = 'admin';
  535. $table->set_additional_parameters($parameters);
  536. if ($is_western_name_order) {
  537. $table -> set_header(0, get_lang('FirstName'), true, 'align="center"');
  538. $table -> set_header(1, get_lang('LastName'), true, 'align="center"');
  539. } else {
  540. $table -> set_header(0, get_lang('LastName'), true, 'align="center"');
  541. $table -> set_header(1, get_lang('FirstName'), true, 'align="center"');
  542. }
  543. $table -> set_header(2, get_lang('TimeSpentOnThePlatform'), false);
  544. $table -> set_header(3, get_lang('LastConnexion'), true, 'align="center"');
  545. $table -> set_header(4, get_lang('NbStudents'), false);
  546. $table -> set_header(5, get_lang('CountCours'), false);
  547. $table -> set_header(6, get_lang('NumberOfSessions'), false);
  548. $table -> set_header(7, get_lang('Sessions'), false, 'align="center"');
  549. if ($is_western_name_order) {
  550. $csv_header[] = array (
  551. get_lang('FirstName', ''),
  552. get_lang('LastName', ''),
  553. get_lang('TimeSpentOnThePlatform', ''),
  554. get_lang('LastConnexion', ''),
  555. get_lang('NbStudents', ''),
  556. get_lang('CountCours', ''),
  557. get_lang('NumberOfSessions', '')
  558. );
  559. } else {
  560. $csv_header[] = array (
  561. get_lang('LastName', ''),
  562. get_lang('FirstName', ''),
  563. get_lang('TimeSpentOnThePlatform', ''),
  564. get_lang('LastConnexion', ''),
  565. get_lang('NbStudents', ''),
  566. get_lang('CountCours', ''),
  567. get_lang('NumberOfSessions', '')
  568. );
  569. }
  570. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  571. $sqlCoachs = "SELECT DISTINCT scu.id_user as id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
  572. FROM $tbl_user, $tbl_session_course_user scu, $tbl_track_login
  573. WHERE scu.id_user=user_id AND scu.status=2 AND login_user_id=user_id
  574. GROUP BY user_id ";
  575. // ORDER BY login_date ".$tracking_direction;
  576. if ($_configuration['multiple_access_urls'] == true) {
  577. $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  578. $access_url_id = api_get_current_access_url_id();
  579. if ($access_url_id != -1) {
  580. $sqlCoachs = "SELECT DISTINCT scu.id_user as id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
  581. FROM $tbl_user, $tbl_session_course_user scu, $tbl_track_login , $tbl_session_rel_access_url session_rel_url
  582. WHERE scu.id_user=user_id AND scu.status=2 AND login_user_id=user_id AND access_url_id = $access_url_id AND session_rel_url.session_id=id_session
  583. GROUP BY user_id ";
  584. }
  585. }
  586. if (!empty($order[$tracking_column])) {
  587. $sqlCoachs .= "ORDER BY ".$order[$tracking_column]." ".$tracking_direction;
  588. }
  589. $result_coaches = Database::query($sqlCoachs, __FILE__, __LINE__);
  590. $total_no_coaches = Database::num_rows($result_coaches);
  591. $global_coaches = array();
  592. while ($coach = Database::fetch_array($result_coaches)) {
  593. $global_coaches[$coach['user_id']] = $coach;
  594. }
  595. $sql_session_coach = 'SELECT session.id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
  596. FROM '.$tbl_user.','.$tbl_sessions.' as session,'.$tbl_track_login.'
  597. WHERE id_coach=user_id AND login_user_id=user_id
  598. GROUP BY user_id
  599. ORDER BY login_date '.$tracking_direction;
  600. if ($_configuration['multiple_access_urls'] == true) {
  601. $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  602. $access_url_id = api_get_current_access_url_id();
  603. if ($access_url_id != -1) {
  604. $sql_session_coach = 'SELECT session.id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
  605. FROM '.$tbl_user.','.$tbl_sessions.' as session,'.$tbl_track_login.' , '.$tbl_session_rel_access_url.' as session_rel_url
  606. WHERE id_coach=user_id AND login_user_id=user_id AND access_url_id = '.$access_url_id.' AND session_rel_url.session_id=session.id
  607. GROUP BY user_id
  608. ORDER BY login_date '.$tracking_direction;
  609. }
  610. }
  611. $result_sessions_coach = Database::query($sql_session_coach, __FILE__, __LINE__);
  612. $total_no_coaches += Database::num_rows($result_sessions_coach);
  613. while ($coach = Database::fetch_array($result_sessions_coach)) {
  614. $global_coaches[$coach['user_id']] = $coach;
  615. }
  616. $all_datas = array();
  617. foreach ($global_coaches as $id_coach => $coaches) {
  618. $time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($coaches['user_id']));
  619. $last_connection = Tracking :: get_last_connection_date($coaches['user_id']);
  620. $nb_students = count(Tracking :: get_student_followed_by_coach($coaches['user_id']));
  621. $nb_courses = count(Tracking :: get_courses_followed_by_coach($coaches['user_id']));
  622. $nb_sessions = count(Tracking :: get_sessions_coached_by_user($coaches['user_id']));
  623. $table_row = array();
  624. if ($is_western_name_order) {
  625. $table_row[] = $coaches['firstname'];
  626. $table_row[] = $coaches['lastname'];
  627. } else {
  628. $table_row[] = $coaches['lastname'];
  629. $table_row[] = $coaches['firstname'];
  630. }
  631. $table_row[] = $time_on_platform;
  632. $table_row[] = $last_connection;
  633. $table_row[] = $nb_students;
  634. $table_row[] = $nb_courses;
  635. $table_row[] = $nb_sessions;
  636. $table_row[] = '<center><a href="session.php?id_coach='.$coaches['user_id'].'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></center>';
  637. $all_datas[] = $table_row;
  638. if ($is_western_name_order) {
  639. $csv_content[] = array(
  640. api_html_entity_decode($coaches['firstname'], ENT_QUOTES, $charset),
  641. api_html_entity_decode($coaches['lastname'], ENT_QUOTES, $charset),
  642. $time_on_platform,
  643. $last_connection,
  644. $nb_students,
  645. $nb_courses,
  646. $nb_sessions
  647. );
  648. } else {
  649. $csv_content[] = array(
  650. api_html_entity_decode($coaches['lastname'], ENT_QUOTES, $charset),
  651. api_html_entity_decode($coaches['firstname'], ENT_QUOTES, $charset),
  652. $time_on_platform,
  653. $last_connection,
  654. $nb_students,
  655. $nb_courses,
  656. $nb_sessions
  657. );
  658. }
  659. }
  660. if ($tracking_column != 3) {
  661. if ($tracking_direction == 'DESC') {
  662. usort($all_datas, 'rsort_users');
  663. } else {
  664. usort($all_datas, 'sort_users');
  665. }
  666. }
  667. if ($export_csv && $tracking_column != 3) {
  668. usort($csv_content, 'sort_users');
  669. }
  670. if ($export_csv) {
  671. $csv_content = array_merge($csv_header, $csv_content);
  672. }
  673. foreach ($all_datas as $row) {
  674. $table -> addRow($row, 'align="right"');
  675. }
  676. $table -> updateColAttributes(0, array('align' => 'left'));
  677. $table -> updateColAttributes(1, array('align' => 'left'));
  678. $table -> updateColAttributes(3, array('align' => 'left'));
  679. $table -> updateColAttributes(7, array('align' => 'center'));
  680. $table -> display();
  681. }
  682. }
  683. // send the csv file if asked
  684. if ($export_csv) {
  685. ob_end_clean();
  686. /*echo "<pre>";
  687. print_r($csv_content);
  688. echo "</pre>";*/
  689. Export :: export_table_csv($csv_content, 'reporting_index');
  690. }
  691. //footer
  692. if (!$export_csv) {
  693. Display::display_footer();
  694. }
  695. /**
  696. * This function exports the table that we see in display_tracking_user_overview()
  697. *
  698. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  699. * @version Dokeos 1.8.6
  700. * @since October 2008
  701. */
  702. function export_tracking_user_overview() {
  703. // database table definitions
  704. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  705. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  706. $sort_by_first_name = api_sort_by_first_name();
  707. // the values of the sortable table
  708. if ($_GET['tracking_user_overview_page_nr']) {
  709. $from = $_GET['tracking_user_overview_page_nr'];
  710. } else {
  711. $from = 0;
  712. }
  713. if ($_GET['tracking_user_overview_column']) {
  714. $orderby = $_GET['tracking_user_overview_column'];
  715. } else {
  716. $orderby = 0;
  717. }
  718. if ($is_western_name_order != api_is_western_name_order() && ($orderby == 1 || $orderby == 2)) {
  719. // Swapping the sorting column if name order for export is different than the common name order.
  720. $orderby = 3 - $orderby;
  721. }
  722. if ($_GET['tracking_user_overview_direction']) {
  723. $direction = $_GET['tracking_user_overview_direction'];
  724. } else {
  725. $direction = 'ASC';
  726. }
  727. $user_data = get_user_data_tracking_overview($from, 1000, $orderby, $direction);
  728. // the first line of the csv file with the column headers
  729. $csv_row = array();
  730. $csv_row[] = get_lang('OfficialCode');
  731. if ($is_western_name_order) {
  732. $csv_row[] = get_lang('FirstName', '');
  733. $csv_row[] = get_lang('LastName', '');
  734. } else {
  735. $csv_row[] = get_lang('LastName', '');
  736. $csv_row[] = get_lang('FirstName', '');
  737. }
  738. $csv_row[] = get_lang('LoginName');
  739. $csv_row[] = get_lang('CourseCode');
  740. // the additional user defined fields (only those that were selected to be exported)
  741. require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
  742. $fields = UserManager::get_extra_fields(0, 50, 5, 'ASC');
  743. if (is_array($_SESSION['additional_export_fields'])) {
  744. foreach ($_SESSION['additional_export_fields'] as $key => $extra_field_export) {
  745. $csv_row[] = $fields[$extra_field_export][3];
  746. $field_names_to_be_exported[] = 'extra_'.$fields[$extra_field_export][1];
  747. }
  748. }
  749. $csv_row[] = get_lang('AvgTimeSpentInTheCourse', '');
  750. $csv_row[] = get_lang('AvgStudentsProgress', '');
  751. $csv_row[] = get_lang('AvgCourseScore', '');
  752. $csv_row[] = get_lang('AvgExercisesScore', '');
  753. $csv_row[] = get_lang('AvgMessages', '');
  754. $csv_row[] = get_lang('AvgAssignments', '');
  755. $csv_row[] = get_lang('TotalExercisesScoreObtained', '');
  756. $csv_row[] = get_lang('TotalExercisesScorePossible', '');
  757. $csv_row[] = get_lang('TotalExercisesAnswered', '');
  758. $csv_row[] = get_lang('TotalExercisesScorePercentage', '');
  759. $csv_row[] = get_lang('FirstLogin', '');
  760. $csv_row[] = get_lang('LatestLogin', '');
  761. $csv_content[] = $csv_row;
  762. // the other lines (the data)
  763. foreach ($user_data as $key => $user) {
  764. // getting all the courses of the user
  765. $sql = "SELECT * FROM $tbl_course_user WHERE user_id = '".Database::escape_string($user[4])."'";
  766. $result = Database::query($sql, __FILE__, __LINE__);
  767. while ($row = Database::fetch_row($result)) {
  768. $csv_row = array();
  769. // user official code
  770. $csv_row[] = $user[0];
  771. // user first|last name
  772. $csv_row[] = $user[1];
  773. // user last|first name
  774. $csv_row[] = $user[2];
  775. // user login name
  776. $csv_row[] = $user[3];
  777. // course code
  778. $csv_row[] = $row[0];
  779. // the additional defined user fields
  780. $extra_fields = get_user_overview_export_extra_fields($user[4]);
  781. if (is_array($field_names_to_be_exported)) {
  782. foreach ($field_names_to_be_exported as $key => $extra_field_export) {
  783. $csv_row[] = $extra_fields[$extra_field_export];
  784. }
  785. }
  786. // time spent in the course
  787. $csv_row[] = api_time_to_hms(Tracking :: get_time_spent_on_the_course ($user[4], $row[0]));
  788. // student progress in course
  789. $csv_row[] = round(Tracking :: get_avg_student_progress ($user[4], $row[0]), 2);
  790. // student score
  791. $csv_row[] = round(Tracking :: get_avg_student_score ($user[4], $row[0]), 2);
  792. // student tes score
  793. $csv_row[] = round(Tracking :: get_avg_student_exercise_score ($user[4], $row[0]), 2);
  794. // student messages
  795. $csv_row[] = Tracking :: count_student_messages ($user[4], $row[0]);
  796. // student assignments
  797. $csv_row[] = Tracking :: count_student_assignments ($user[4], $row[0]);
  798. // student exercises results
  799. $exercises_results = exercises_results($user[4], $row[0]);
  800. $csv_row[] = $exercises_results['score_obtained'];
  801. $csv_row[] = $exercises_results['score_possible'];
  802. $csv_row[] = $exercises_results['questions_answered'];
  803. $csv_row[] = $exercises_results['percentage'];
  804. // first connection
  805. $csv_row[] = Tracking :: get_first_connection_date_on_the_course ($user[4], $row[0]);
  806. // last connection
  807. $csv_row[] = strip_tags(Tracking :: get_last_connection_date_on_the_course ($user[4], $row[0]));
  808. $csv_content[] = $csv_row;
  809. }
  810. }
  811. Export :: export_table_csv($csv_content, 'reporting_user_overview');
  812. }
  813. /**
  814. * Display a sortable table that contains an overview off all the reporting progress of all users and all courses the user is subscribed to
  815. *
  816. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  817. * @version Dokeos 1.8.6
  818. * @since October 2008
  819. */
  820. function display_tracking_user_overview() {
  821. display_user_overview_export_options();
  822. $t_head .= ' <table style="width: 100%;border:0;padding:0;border-collapse:collapse;table-layout: fixed">';
  823. $t_head .= ' <caption>'.get_lang('CourseInformation').'</caption>';
  824. $t_head .= '<tr>';
  825. $t_head .= ' <th width="155px" style="border-left:0;border-bottom:0"><span>'.get_lang('Course').'</span></th>';
  826. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgTimeSpentInTheCourse'), 6, true).'</span></th>';
  827. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgStudentsProgress'), 6, true).'</span></th>';
  828. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgCourseScore'), 6, true).'</span></th>';
  829. //$t_head .= ' <th><div style="width:40px">'.get_lang('AvgExercisesScore').'</div></th>';
  830. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgMessages'), 6, true).'</span></th>';
  831. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgAssignments'), 6, true).'</span></th>';
  832. $t_head .= ' <th width="105px" style="border-bottom:0"><span>'.get_lang('TotalExercisesScoreObtained').'</span></th>';
  833. //$t_head .= ' <th><div>'.get_lang('TotalExercisesScorePossible').'</div></th>';
  834. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('TotalExercisesAnswered'), 6, true).'</span></th>';
  835. //$t_head .= ' <th><div>'.get_lang('TotalExercisesScorePercentage').'</div></th>';
  836. //$t_head .= ' <th><div style="width:60px">'.get_lang('FirstLogin').'</div></th>';
  837. $t_head .= ' <th style="padding:0;border-bottom:0;border-right:0;"><span>'.get_lang('LatestLogin').'</span></th>';
  838. $t_head .= ' </tr></table>';
  839. $addparams = array('view' => 'admin', 'display' => 'useroverview');
  840. $table = new SortableTable('tracking_user_overview', 'get_number_of_users_tracking_overview', 'get_user_data_tracking_overview', 0);
  841. $table->additional_parameters = $addparams;
  842. $table->set_header(0, get_lang('OfficialCode'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  843. if (api_is_western_name_order()) {
  844. $table->set_header(1, get_lang('FirstName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  845. $table->set_header(2, get_lang('LastName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  846. } else {
  847. $table->set_header(1, get_lang('LastName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  848. $table->set_header(2, get_lang('FirstName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  849. }
  850. $table->set_header(3, get_lang('LoginName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  851. $table->set_header(4, $t_head, false, array('style' => 'width:90%;border:0;padding:0;font-size:7.5pt;'), array('style' => 'width:90%;padding:0;font-size:7.5pt;'));
  852. $table->set_column_filter(4, 'course_info_tracking_filter');
  853. $table->display();
  854. }
  855. /**
  856. * get the numer of users of the platform
  857. *
  858. * @return integer
  859. *
  860. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  861. * @version Dokeos 1.8.6
  862. * @since October 2008
  863. */
  864. function get_number_of_users_tracking_overview() {
  865. // database table definition
  866. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  867. // query
  868. $sql = 'SELECT user_id FROM '.$main_user_table;
  869. $result = Database::query($sql, __FILE__, __LINE__);
  870. // return the number of results
  871. return Database::num_rows($result);
  872. }
  873. /**
  874. * get all the data for the sortable table of the reporting progress of all users and all the courses the user is subscribed to.
  875. *
  876. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  877. * @version Dokeos 1.8.6
  878. * @since October 2008
  879. */
  880. function get_user_data_tracking_overview($from, $number_of_items, $column, $direction) {
  881. // database table definition
  882. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  883. global $export_csv;
  884. if ($export_csv) {
  885. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  886. } else {
  887. $is_western_name_order = api_is_western_name_order();
  888. }
  889. $sql = "SELECT
  890. official_code AS col0,
  891. ".($is_western_name_order ? "
  892. firstname AS col1,
  893. lastname AS col2,
  894. " : "
  895. lastname AS col1,
  896. firstname AS col2,
  897. ").
  898. "username AS col3,
  899. user_id AS col4
  900. FROM
  901. $main_user_table
  902. ";
  903. $sql .= " ORDER BY col$column $direction ";
  904. $sql .= " LIMIT $from,$number_of_items";
  905. $result = Database::query($sql, __FILE__, __LINE__);
  906. $return = array ();
  907. while ($user = Database::fetch_row($result)) {
  908. $return[] = $user;
  909. }
  910. return $return;
  911. }
  912. /**
  913. * Creates a small table in the last column of the table with the user overview
  914. *
  915. * @param integer $user_id the id of the user
  916. * @param array $url_params additonal url parameters
  917. * @param array $row the row information (the other columns)
  918. * @return html code
  919. *
  920. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  921. * @version Dokeos 1.8.6
  922. * @since October 2008
  923. */
  924. function course_info_tracking_filter($user_id, $url_params, $row) {
  925. // the table header
  926. $return .= '<table class="data_table" style="width: 100%;border:0;padding:0;border-collapse:collapse;table-layout: fixed">';
  927. /*$return .= ' <tr>';
  928. $return .= ' <th>'.get_lang('Course').'</th>';
  929. $return .= ' <th>'.get_lang('AvgTimeSpentInTheCourse').'</th>';
  930. $return .= ' <th>'.get_lang('AvgStudentsProgress').'</th>';
  931. $return .= ' <th>'.get_lang('AvgCourseScore').'</th>';
  932. $return .= ' <th>'.get_lang('AvgExercisesScore').'</th>';
  933. $return .= ' <th>'.get_lang('AvgMessages').'</th>';
  934. $return .= ' <th>'.get_lang('AvgAssignments').'</th>';
  935. $return .= ' <th>'.get_lang('TotalExercisesScoreObtained').'</th>';
  936. $return .= ' <th>'.get_lang('TotalExercisesScorePossible').'</th>';
  937. $return .= ' <th>'.get_lang('TotalExercisesAnswered').'</th>';
  938. $return .= ' <th>'.get_lang('TotalExercisesScorePercentage').'</th>';
  939. $return .= ' <th>'.get_lang('FirstLogin').'</th>';
  940. $return .= ' <th>'.get_lang('LatestLogin').'</th>';
  941. $return .= ' </tr>';*/
  942. // database table definition
  943. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  944. // getting all the courses of the user
  945. $sql = "SELECT * FROM $tbl_course_user WHERE user_id = '".Database::escape_string($user_id)."'";
  946. $result = Database::query($sql, __FILE__, __LINE__);
  947. while ($row = Database::fetch_row($result)) {
  948. $return .= '<tr>';
  949. // course code
  950. $return .= ' <td width="157px" >'.cut($row[0], 20, true).'</td>';
  951. // time spent in the course
  952. $return .= ' <td><div>'.api_time_to_hms(Tracking :: get_time_spent_on_the_course($user_id, $row[0])).'</div></td>';
  953. // student progress in course
  954. $return .= ' <td><div>'.round(Tracking :: get_avg_student_progress($user_id, $row[0]), 2).'</div></td>';
  955. // student score
  956. $return .= ' <td><div>'.round(Tracking :: get_avg_student_score($user_id, $row[0]), 2).'</div></td>';
  957. // student tes score
  958. //$return .= ' <td><div style="width:40px">'.round(Tracking :: get_avg_student_exercise_score ($user_id, $row[0]),2).'%</div></td>';
  959. // student messages
  960. $return .= ' <td><div>'.Tracking :: count_student_messages($user_id, $row[0]).'</div></td>';
  961. // student assignments
  962. $return .= ' <td><div>'.Tracking :: count_student_assignments($user_id, $row[0]).'</div></td>';
  963. // student exercises results (obtained score, maximum score, number of exercises answered, score percentage)
  964. $exercises_results = exercises_results($user_id, $row[0]);
  965. $return .= ' <td width="105px"><div>'.(is_null($exercises_results['percentage']) ? '' : $exercises_results['score_obtained'].'/'.$exercises_results['score_possible'].' ( '.$exercises_results['percentage'].'% )').'</div></td>';
  966. //$return .= ' <td><div>'.$exercises_results['score_possible'].'</div></td>';
  967. $return .= ' <td><div>'.$exercises_results['questions_answered'].'</div></td>';
  968. //$return .= ' <td><div>'.$exercises_results['percentage'].'% </div></td>';
  969. // first connection
  970. //$return .= ' <td width="60px">'.Tracking :: get_first_connection_date_on_the_course ($user_id, $row[0]).'</td>';
  971. // last connection
  972. $return .= ' <td><div>'.Tracking :: get_last_connection_date_on_the_course ($user_id, $row[0]).'</div></td>';
  973. $return .= '<tr>';
  974. }
  975. $return .= '</table>';
  976. return $return;
  977. }
  978. /**
  979. * Get general information about the exercise performance of the user
  980. * the total obtained score (all the score on all the questions)
  981. * the maximum score that could be obtained
  982. * the number of questions answered
  983. * the success percentage
  984. *
  985. * @param integer $user_id the id of the user
  986. * @param string $course_code the course code
  987. *
  988. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  989. * @version Dokeos 1.8.6
  990. * @since November 2008
  991. */
  992. function exercises_results($user_id, $course_code) {
  993. $questions_answered = 0;
  994. $sql = 'SELECT exe_result , exe_weighting
  995. FROM '.Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES)."
  996. WHERE exe_cours_id = '".Database::escape_string($course_code)."'
  997. AND exe_user_id = '".Database::escape_string($user_id)."'";
  998. $result = Database::query($sql, __FILE__, __LINE__);
  999. $score_obtained = 0;
  1000. $score_possible = 0;
  1001. $questions_answered = 0;
  1002. while ($row = Database::fetch_array($result)) {
  1003. $score_obtained += $row['exe_result'];
  1004. $score_possible += $row['exe_weighting'];
  1005. $questions_answered ++;
  1006. }
  1007. if ($score_possible != 0) {
  1008. $percentage = round(($score_obtained / $score_possible * 100), 2);
  1009. } else {
  1010. $percentage = null;
  1011. }
  1012. return array('score_obtained' => $score_obtained, 'score_possible' => $score_possible, 'questions_answered' => $questions_answered, 'percentage' => $percentage);
  1013. }
  1014. /**
  1015. * Displays a form with all the additionally defined user fields of the profile
  1016. * and give you the opportunity to include these in the CSV export
  1017. *
  1018. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  1019. * @version Dokeos 1.8.6
  1020. * @since November 2008
  1021. */
  1022. function display_user_overview_export_options() {
  1023. // include the user manager and formvalidator library
  1024. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  1025. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  1026. if ($_GET['export'] == 'options') {
  1027. // get all the defined extra fields
  1028. $extrafields = UserManager::get_extra_fields(0, 50, 5, 'ASC', false);
  1029. // creating the form with all the defined extra fields
  1030. $form = new FormValidator('exportextrafields', 'post', api_get_self()."?view=".Security::remove_XSS($_GET['view']).'&display='.Security::remove_XSS($_GET['display']).'&export='.Security::remove_XSS($_GET['export']));
  1031. foreach ($extrafields as $key => $extra) {
  1032. $form->addElement('checkbox', 'extra_export_field'.$extra[0], '', $extra[3]);
  1033. }
  1034. $form->addElement('style_submit_button','submit', get_lang('Ok'),'class="save"' );
  1035. // setting the default values for the form that contains all the extra fields
  1036. if (is_array($_SESSION['additional_export_fields'])) {
  1037. foreach ($_SESSION['additional_export_fields'] as $key => $value) {
  1038. $defaults['extra_export_field'.$value] = 1;
  1039. }
  1040. }
  1041. $form->setDefaults($defaults);
  1042. if ($form->validate()) {
  1043. // exporting the form values
  1044. $values = $form->exportValues();
  1045. // re-initialising the session that contains the additional fields that need to be exported
  1046. $_SESSION['additional_export_fields'] = array();
  1047. // adding the fields that are checked to the session
  1048. $message = '';
  1049. foreach ($values as $field_ids => $value) {
  1050. if ($value == 1 && strstr($field_ids,'extra_export_field')) {
  1051. $_SESSION['additional_export_fields'][] = str_replace('extra_export_field', '', $field_ids);
  1052. }
  1053. }
  1054. // adding the fields that will be also exported to a message string
  1055. if (is_array($_SESSION['additional_export_fields'])) {
  1056. foreach ($_SESSION['additional_export_fields'] as $key => $extra_field_export) {
  1057. $message .= '<li>'.$extrafields[$extra_field_export][3].'</li>';
  1058. }
  1059. }
  1060. // Displaying a feedback message
  1061. if (!empty($_SESSION['additional_export_fields'])) {
  1062. Display::display_confirmation_message(get_lang('FollowingFieldsWillAlsoBeExported').': <br /><ul>'.$message.'</ul>', false);
  1063. } else {
  1064. Display::display_confirmation_message(get_lang('NoAdditionalFieldsWillBeExported'), false);
  1065. }
  1066. $message = '';
  1067. } else {
  1068. $form->display();
  1069. }
  1070. } else {
  1071. if (!empty($_SESSION['additional_export_fields'])) {
  1072. // get all the defined extra fields
  1073. $extrafields = UserManager::get_extra_fields(0, 50, 5, 'ASC');
  1074. foreach ($_SESSION['additional_export_fields'] as $key => $extra_field_export) {
  1075. $message .= '<li>'.$extrafields[$extra_field_export][3].'</li>';
  1076. }
  1077. Display::display_normal_message(get_lang('FollowingFieldsWillAlsoBeExported').': <br /><ul>'.$message.'</ul>', false);
  1078. $message = '';
  1079. }
  1080. }
  1081. }
  1082. /**
  1083. * Get all information that the user with user_id = $user_data has
  1084. * entered in the additionally defined profile fields
  1085. *
  1086. * @param integer $user_id the id of the user
  1087. *
  1088. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  1089. * @version Dokeos 1.8.6
  1090. * @since November 2008
  1091. */
  1092. function get_user_overview_export_extra_fields($user_id) {
  1093. // include the user manager
  1094. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  1095. $extra_data = UserManager::get_extra_user_data($user_id, true);
  1096. return $extra_data;
  1097. }