myStudents.php 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Implements the tracking of students in the Reporting pages
  5. * @package chamilo.mySpace
  6. */
  7. // name of the language file that needs to be included
  8. $language_file = array('registration', 'index', 'tracking', 'exercice', 'admin', 'gradebook', 'survey');
  9. $cidReset = true;
  10. require_once '../inc/global.inc.php';
  11. require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
  12. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  13. require_once api_get_path(SYS_CODE_PATH).'mySpace/myspace.lib.php';
  14. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/gradebookitem.class.php';
  15. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/evaluation.class.php';
  16. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/result.class.php';
  17. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/linkfactory.class.php';
  18. require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/be/category.class.php';
  19. require_once api_get_path(LIBRARY_PATH).'attendance.lib.php';
  20. require_once api_get_path(SYS_CODE_PATH).'survey/survey.lib.php';
  21. $htmlHeadXtra[] = '<script type="text/javascript">
  22. function show_image(image,width,height) {
  23. width = parseInt(width) + 20;
  24. height = parseInt(height) + 20;
  25. window_x = window.open(image,\'windowX\',\'width=\'+ width + \', height=\'+ height + \'\');
  26. }
  27. </script>';
  28. $export_csv = isset ($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  29. if ($export_csv) {
  30. ob_start();
  31. }
  32. $csv_content = array ();
  33. $from_myspace = false;
  34. if (isset ($_GET['from']) && $_GET['from'] == 'myspace') {
  35. $from_myspace = true;
  36. $this_section = SECTION_TRACKING;
  37. } else {
  38. $this_section = SECTION_COURSES;
  39. }
  40. $nameTools = get_lang('StudentDetails');
  41. $get_course_code = Security :: remove_XSS($_GET['course']);
  42. if (isset ($_GET['details'])) {
  43. if (!empty ($_GET['origin']) && $_GET['origin'] == 'user_course') {
  44. $course_info = CourseManager :: get_course_information($get_course_code);
  45. if (empty ($cidReq)) {
  46. $interbreadcrumb[] = array (
  47. "url" => api_get_path(WEB_COURSE_PATH) . $course_info['directory'],
  48. 'name' => $course_info['title']
  49. );
  50. }
  51. $interbreadcrumb[] = array (
  52. "url" => "../user/user.php?cidReq=" . $get_course_code,
  53. "name" => get_lang("Users")
  54. );
  55. } else
  56. if (!empty ($_GET['origin']) && $_GET['origin'] == 'tracking_course') {
  57. $course_info = CourseManager :: get_course_information($get_course_code);
  58. if (empty ($cidReq)) {
  59. //$interbreadcrumb[] = array ("url" => api_get_path(WEB_COURSE_PATH).$course_info['directory'], 'name' => $course_info['title']);
  60. }
  61. $interbreadcrumb[] = array (
  62. "url" => "../tracking/courseLog.php?cidReq=" . $get_course_code . '&studentlist=true&id_session=' . (empty ($_SESSION['id_session']) ? '' : $_SESSION['id_session']),
  63. "name" => get_lang("Tracking")
  64. );
  65. } else
  66. if (!empty ($_GET['origin']) && $_GET['origin'] == 'resume_session') {
  67. $interbreadcrumb[] = array (
  68. 'url' => '../admin/index.php',
  69. "name" => get_lang('PlatformAdmin')
  70. );
  71. $interbreadcrumb[] = array (
  72. 'url' => "../admin/session_list.php",
  73. "name" => get_lang('SessionList')
  74. );
  75. $interbreadcrumb[] = array (
  76. 'url' => "../admin/resume_session.php?id_session=" . Security :: remove_XSS($_GET['id_session']),
  77. "name" => get_lang('SessionOverview')
  78. );
  79. } else {
  80. $interbreadcrumb[] = array (
  81. "url" => "index.php",
  82. "name" => get_lang('MySpace')
  83. );
  84. if (isset ($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
  85. $interbreadcrumb[] = array (
  86. "url" => "student.php?id_coach=" . Security :: remove_XSS($_GET['id_coach']),
  87. "name" => get_lang("CoachStudents")
  88. );
  89. $interbreadcrumb[] = array (
  90. "url" => "myStudents.php?student=" . Security :: remove_XSS($_GET['student']) . '&id_coach=' . Security :: remove_XSS($_GET['id_coach']),
  91. "name" => get_lang("StudentDetails")
  92. );
  93. } else {
  94. $interbreadcrumb[] = array (
  95. "url" => "student.php",
  96. "name" => get_lang("MyStudents")
  97. );
  98. $interbreadcrumb[] = array (
  99. "url" => "myStudents.php?student=" . Security :: remove_XSS($_GET['student']),
  100. "name" => get_lang("StudentDetails")
  101. );
  102. }
  103. }
  104. $nameTools = get_lang("DetailsStudentInCourse");
  105. } else {
  106. if (!empty ($_GET['origin']) && $_GET['origin'] == 'resume_session') {
  107. $interbreadcrumb[] = array (
  108. 'url' => '../admin/index.php',
  109. "name" => get_lang('PlatformAdmin')
  110. );
  111. $interbreadcrumb[] = array (
  112. 'url' => "../admin/session_list.php",
  113. "name" => get_lang('SessionList')
  114. );
  115. $interbreadcrumb[] = array (
  116. 'url' => "../admin/resume_session.php?id_session=" . Security :: remove_XSS($_GET['id_session']),
  117. "name" => get_lang('SessionOverview')
  118. );
  119. } else {
  120. $interbreadcrumb[] = array (
  121. "url" => "index.php",
  122. "name" => get_lang('MySpace')
  123. );
  124. if (isset ($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
  125. if (isset ($_GET['id_session']) && intval($_GET['id_session']) != 0) {
  126. $interbreadcrumb[] = array (
  127. "url" => "student.php?id_coach=" . Security :: remove_XSS($_GET['id_coach']) . "&id_session=" . $_GET['id_session'],
  128. "name" => get_lang("CoachStudents")
  129. );
  130. } else {
  131. $interbreadcrumb[] = array (
  132. "url" => "student.php?id_coach=" . Security :: remove_XSS($_GET['id_coach']),
  133. "name" => get_lang("CoachStudents")
  134. );
  135. }
  136. } else {
  137. $interbreadcrumb[] = array (
  138. "url" => "student.php",
  139. "name" => get_lang("MyStudents")
  140. );
  141. }
  142. }
  143. }
  144. api_block_anonymous_users();
  145. if (!api_is_allowed_to_create_course() && !api_is_session_admin() && !api_is_drh()) {
  146. api_not_allowed(true);
  147. }
  148. /*
  149. * MAIN CODE
  150. */
  151. // Database Table Definitions
  152. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  153. $tbl_session_user = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
  154. $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  155. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  156. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  157. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  158. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  159. $tbl_stats_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  160. $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  161. $tbl_stats_exercices_attempts= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  162. if (isset($_GET['user_id']) && $_GET['user_id'] != "") {
  163. $user_id = intval($_GET['user_id']);
  164. } else {
  165. $user_id = $_user['user_id'];
  166. }
  167. $session_id = intval($_GET['id_session']);
  168. if (empty($session_id)) {
  169. $session_id = api_get_session_id();
  170. }
  171. $student_id = intval($_GET['student']);
  172. // Action behaviour
  173. $check= Security::check_token('get');
  174. if ($check) {
  175. switch ($_GET['action']) {
  176. case 'reset_lp' :
  177. $course = isset($_GET['course']) ?$_GET['course']:"";
  178. $lp_id = isset($_GET['lp_id']) ?intval($_GET['lp_id']):"";
  179. if (api_is_course_admin() && !empty($course) && !empty($lp_id) && !empty($student_id)) {
  180. $course_info = api_get_course_info($course);
  181. delete_student_lp_events($student_id, $lp_id, $course_info, $session_id);
  182. //@todo delete the stats.track_e_exercices records. First implement this http://support.chamilo.org/issues/1334
  183. Display::display_confirmation_message(get_lang('LPWasReset'));
  184. }
  185. break;
  186. default:
  187. break;
  188. }
  189. Security::clear_token();
  190. }
  191. // infos about user
  192. $info_user = UserManager::get_user_info_by_id($student_id);
  193. $courses_in_session = array();
  194. $courses = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());
  195. $courses_in_session_by_coach = array();
  196. $sessions_coached_by_user = Tracking::get_sessions_coached_by_user(api_get_user_id());
  197. //RRHH or session admin
  198. if (api_is_session_admin() || api_is_drh()) {
  199. $session_by_session_admin = SessionManager::get_sessions_followed_by_drh(api_get_user_id());
  200. if (!empty($session_by_session_admin)) {
  201. foreach ($session_by_session_admin as $session_coached_by_user) {
  202. $courses_followed_by_coach = Tracking :: get_courses_list_from_session($session_coached_by_user['id']);
  203. $courses_in_session_by_coach[$session_coached_by_user['id']] = $courses_followed_by_coach;
  204. }
  205. }
  206. }
  207. // Teacher or admin
  208. if (!empty($sessions_coached_by_user)) {
  209. foreach ($sessions_coached_by_user as $session_coached_by_user) {
  210. $sid = intval($session_coached_by_user['id']);
  211. $courses_followed_by_coach = Tracking :: get_courses_followed_by_coach(api_get_user_id(), $sid);
  212. $courses_in_session_by_coach[$sid] = $courses_followed_by_coach;
  213. }
  214. }
  215. $sql = 'SELECT course_code FROM ' . $tbl_course_user . ' WHERE relation_type<>'.COURSE_RELATION_TYPE_RRHH.' AND user_id=' . Database :: escape_string($info_user['user_id']);
  216. $rs = Database::query($sql);
  217. while ($row = Database :: fetch_array($rs)) {
  218. if (isset($courses[$row['course_code']])) {
  219. $courses_in_session[0][] = $row['course_code'];
  220. }
  221. }
  222. // Get the list of sessions where the user is subscribed as student
  223. $sql = 'SELECT id_session, course_code FROM ' . Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER) . ' WHERE id_user=' . intval($info_user['user_id']);
  224. $rs = Database::query($sql);
  225. $tmp_sessions = array();
  226. while ($row = Database :: fetch_array($rs)) {
  227. $tmp_sessions[] = $row['id_session'];
  228. if (isset($courses_in_session_by_coach[$row['id_session']])) {
  229. if (in_array($row['id_session'], $tmp_sessions)) {
  230. $courses_in_session[$row['id_session']][] = $row['course_code'];
  231. }
  232. }
  233. }
  234. if (empty($courses_in_session)) {
  235. echo '<div class="actions">';
  236. echo '<a href="javascript: window.back();" ">'.Display::return_icon('back.png', get_lang('Back'),'','32').'</a>';
  237. echo '</div>';
  238. Display::display_warning_message(get_lang('NoDataAvailable'));
  239. Display::display_footer();
  240. exit;
  241. }
  242. Display :: display_header($nameTools);
  243. if (!empty($student_id)) {
  244. if (api_is_drh() && !UserManager::is_user_followed_by_drh($student_id, api_get_user_id())) {
  245. api_not_allowed(false);
  246. }
  247. $info_user['name'] = api_get_person_name($info_user['firstname'], $info_user['lastname']);
  248. // Actions bar
  249. echo '<div class="actions">';
  250. echo '<a href="javascript: window.back();" ">'.Display::return_icon('back.png', get_lang('Back'),'','32').'</a>';
  251. echo '<a href="javascript: void(0);" onclick="javascript: window.print();">'.Display::return_icon('printer.png', get_lang('Print'),'','32').'</a>';
  252. echo '<a href="' . api_get_self() . '?' . Security :: remove_XSS($_SERVER['QUERY_STRING']) . '&export=csv">'.Display::return_icon('export_csv.png', get_lang('ExportAsCSV'),'','32').'</a> ';
  253. if (!empty ($info_user['email'])) {
  254. $send_mail = '<a href="mailto:'.$info_user['email'].'">'.Display :: return_icon('mail_send.png', get_lang('SendMail'),'','32').'</a>';
  255. } else {
  256. $send_mail = Display :: return_icon('mail_send_na.png', get_lang('SendMail'),'','32');
  257. }
  258. echo $send_mail;
  259. if (!empty($student_id) && !empty ($_GET['course'])) { //only show link to connection details if course and student were defined in the URL
  260. echo '<a href="access_details.php?student=' . $student_id . '&course=' . Security :: remove_XSS($_GET['course']) . '&amp;origin=' . Security :: remove_XSS($_GET['origin']) . '&amp;cidReq='.Security::remove_XSS($_GET['course']).'&amp;id_session='.$session_id.'">' . Display :: return_icon('statistics.png', get_lang('AccessDetails'),'','32').'</a>';
  261. }
  262. echo '</div>';
  263. // is the user online ?
  264. $student_online = intval($_GET['student']);
  265. $users_online = who_is_online(30);
  266. foreach ($users_online as $online) {
  267. if (in_array($_GET['student'], $online)) {
  268. $online = get_lang('Yes');
  269. break;
  270. } else {
  271. $online = get_lang('No');
  272. }
  273. }
  274. // get average of score and average of progress by student
  275. $avg_student_progress = $avg_student_score = $nb_courses = 0;
  276. $course_code = Security :: remove_XSS($_GET['course']);
  277. if (!CourseManager :: is_user_subscribed_in_course($info_user['user_id'], $course_code, true)) {
  278. unset($courses[$key]);
  279. } else {
  280. $nb_courses++;
  281. $avg_student_progress = Tracking::get_avg_student_progress($info_user['user_id'], $course_code, array(), $session_id);
  282. //the score inside the Reporting table
  283. $avg_student_score = Tracking::get_avg_student_score($info_user['user_id'], $course_code, array(), $session_id);
  284. //var_dump($avg_student_score);
  285. }
  286. $avg_student_progress = round($avg_student_progress, 2);
  287. // time spent on the course
  288. $time_spent_on_the_course = api_time_to_hms(Tracking :: get_time_spent_on_the_course($info_user['user_id'], $course_code, $session_id));
  289. // get information about connections on the platform by student
  290. $first_connection_date = Tracking :: get_first_connection_date($info_user['user_id']);
  291. if ($first_connection_date == '') {
  292. $first_connection_date = get_lang('NoConnexion');
  293. }
  294. $last_connection_date = Tracking :: get_last_connection_date($info_user['user_id'], true);
  295. if ($last_connection_date == '') {
  296. $last_connection_date = get_lang('NoConnexion');
  297. }
  298. // cvs informations
  299. $csv_content[] = array (
  300. get_lang('Informations', '')
  301. );
  302. $csv_content[] = array (
  303. get_lang('Name', ''),
  304. get_lang('Email', ''),
  305. get_lang('Tel', '')
  306. );
  307. $csv_content[] = array (
  308. $info_user['name'],
  309. $info_user['email'],
  310. $info_user['phone']
  311. );
  312. $csv_content[] = array ();
  313. // csv tracking
  314. $csv_content[] = array (
  315. get_lang('Tracking', '')
  316. );
  317. $csv_content[] = array (
  318. get_lang('FirstLogin', ''),
  319. get_lang('LatestLogin', ''),
  320. get_lang('TimeSpentInTheCourse', ''),
  321. get_lang('Progress', ''),
  322. get_lang('Score', '')
  323. );
  324. $csv_content[] = array (
  325. strip_tags($first_connection_date),
  326. strip_tags($last_connection_date),
  327. $time_spent_on_the_course,
  328. $avg_student_progress . '%',
  329. $avg_student_score
  330. );
  331. //Show title
  332. $info_course = CourseManager :: get_course_information($course_code);
  333. $coachs_name = '';
  334. $session_name = '';
  335. $nb_login = Tracking :: count_login_per_student($info_user['user_id'], $_GET['course']);
  336. //get coach and session_name if there is one and if session_mode is activated
  337. if (api_get_setting('use_session_mode') == 'true' && $session_id > 0) {
  338. $session_info = api_get_session_info($session_id);
  339. $course_coachs = api_get_coachs_from_course($session_id, $course_code);
  340. $nb_login = '';
  341. if (!empty($course_coachs)) {
  342. $info_tutor_name = array();
  343. foreach ($course_coachs as $course_coach) {
  344. $info_tutor_name[] = api_get_person_name($course_coach['firstname'], $course_coach['lastname']);
  345. }
  346. $info_course['tutor_name'] = implode(",",$info_tutor_name);
  347. } elseif ($session_coach_id != 0) {
  348. $session_coach_id = intval($session_info['id_coach']);
  349. $coach_info = UserManager::get_user_info_by_id($session_coach_id);
  350. $info_course['tutor_name'] = api_get_person_name($coach_info['firstname'], $coach_info['lastname']);
  351. }
  352. $coachs_name = $info_course['tutor_name'];
  353. $session_name = $session_info['name'];
  354. } // end
  355. $info_course = CourseManager :: get_course_information($get_course_code);
  356. $table_title = Display::return_icon('user.png', get_lang('User'), array(), 22).api_get_person_name($info_user['firstname'], $info_user['lastname']);
  357. echo '<h2>'.$table_title.'</h2>';
  358. ?>
  359. <table width="100%" border="0">
  360. <tr>
  361. <?php
  362. $image_array = UserManager :: get_user_picture_path_by_id($info_user['user_id'], 'web', false, true);
  363. echo '<td class="borderRight" width="10%" valign="top">';
  364. // get the path,width and height from original picture
  365. $image_file = $image_array['dir'] . $image_array['file'];
  366. $big_image = $image_array['dir'] . 'big_' . $image_array['file'];
  367. $big_image_size = api_getimagesize($big_image);
  368. $big_image_width = $big_image_size['width'];
  369. $big_image_height = $big_image_size['height'];
  370. $url_big_image = $big_image . '?rnd=' . time();
  371. $img_attributes = 'src="' . $image_file . '?rand=' . time() . '" ' .
  372. 'alt="' . api_get_person_name($info_user['firstname'], $info_user['lastname']) . '" ' .
  373. 'style="float:' . ($text_dir == 'rtl' ? 'right' : 'left') . '; padding:5px;" ';
  374. if ($image_array['file'] == 'unknown.jpg') {
  375. echo '<img ' . $img_attributes . ' />';
  376. } else {
  377. echo '<input type="image" ' . $img_attributes . ' onclick="javascript: return show_image(\'' . $url_big_image . '\',\'' . $big_image_width . '\',\'' . $big_image_height . '\');"/>';
  378. }
  379. echo '</td>';
  380. ?>
  381. <td width="40%" valign="top">
  382. <table width="100%" class="data_table">
  383. <tr>
  384. <th><?php echo get_lang('Information'); ?></th>
  385. </tr>
  386. <tr>
  387. <td><?php echo get_lang('Name') . ' : '.api_get_person_name($info_user['firstname'], $info_user['lastname']); ?></td>
  388. </tr>
  389. <tr>
  390. <td><?php echo get_lang('Email') . ' : ';
  391. if (!empty ($info_user['email'])) {
  392. echo '<a href="mailto:' . $info_user['email'] . '">' . $info_user['email'] . '</a>';
  393. } else {
  394. echo get_lang('NoEmail');
  395. } ?>
  396. </td>
  397. </tr>
  398. <tr>
  399. <td> <?php echo get_lang('Tel') . ' : ';
  400. if (!empty ($info_user['phone'])) {
  401. echo $info_user['phone'];
  402. } else {
  403. echo get_lang('NoTel');
  404. }
  405. ?>
  406. </td>
  407. </tr>
  408. <tr>
  409. <td> <?php echo get_lang('OfficialCode') . ' : ';
  410. if (!empty ($info_user['official_code'])) {
  411. echo $info_user['official_code'];
  412. } else {
  413. echo get_lang('NoOfficialCode');
  414. }
  415. ?>
  416. </td>
  417. </tr>
  418. <tr>
  419. <td><?php echo get_lang('OnLine') . ' : '.$online; ?> </td>
  420. </tr>
  421. <?php
  422. // Display timezone if the user selected one and if the admin allows the use of user's timezone
  423. $timezone = null;
  424. $timezone_user = UserManager::get_extra_user_data_by_field($info_user['user_id'],'timezone');
  425. $use_users_timezone = api_get_setting('use_users_timezone', 'timezones');
  426. if ($timezone_user['timezone'] != null && $use_users_timezone == 'true') {
  427. $timezone = $timezone_user['timezone'];
  428. }
  429. if ($timezone !== null) {
  430. ?>
  431. <tr>
  432. <td> <?php echo get_lang('Timezone') . ' : '.$timezone; ?> </td>
  433. </tr>
  434. <?php
  435. }
  436. ?>
  437. </table>
  438. </td>
  439. <td class="borderLeft" width="35%" valign="top">
  440. <table width="100%" class="data_table">
  441. <tr>
  442. <th colspan="2"><?php echo get_lang('Tracking'); ?></th>
  443. </tr>
  444. <tr><td align="right"><?php echo get_lang('FirstLogin') ?></td>
  445. <td align="left"><?php echo $first_connection_date ?></td>
  446. </tr>
  447. <tr>
  448. <td align="right"><?php echo get_lang('LatestLogin') ?></td>
  449. <td align="left"><?php echo $last_connection_date ?></td>
  450. </tr>
  451. <?php if (isset($_GET['details']) && $_GET['details'] == 'true') {?>
  452. <tr>
  453. <td align="right"><?php echo get_lang('TimeSpentInTheCourse') ?></td>
  454. <td align="left"><?php echo $time_spent_on_the_course ?></td>
  455. </tr>
  456. <tr>
  457. <td align="right"><?php echo get_lang('Progress').' '; Display :: display_icon('info3.gif', get_lang('ScormAndLPProgressTotalAverage'), array ('align' => 'absmiddle', 'hspace' => '3px'));?></td>
  458. <td align="left"><?php echo $avg_student_progress.'%' ?></td>
  459. </tr>
  460. <tr>
  461. <td align="right"><?php echo get_lang('Score').' '; Display :: display_icon('info3.gif', get_lang('ScormAndLPTestTotalAverage'), array ('align' => 'absmiddle', 'hspace' => '3px')); ?>
  462. </td>
  463. <td align="left"><?php if (is_numeric($avg_student_score)) { echo $avg_student_score.'%';} else { echo $avg_student_score ;} ?></td>
  464. </tr>
  465. <?php
  466. if (!empty($nb_login)) {
  467. echo '<tr><td align="right">'.get_lang('CountToolAccess').'</td>';
  468. echo '<td align="left">'.$nb_login.'</td>';
  469. echo '</tr>';
  470. }
  471. } ?>
  472. </table>
  473. </td>
  474. </tr>
  475. </table>
  476. <?php
  477. $table_title = '';
  478. if (!empty($session_id)) {
  479. $session_name = api_get_session_name($session_id);
  480. $table_title = ($session_name? Display::return_icon('session.png', get_lang('Session'), array(), 22).' '.$session_name.' ':'');
  481. }
  482. if (!empty($info_course['title'])) {
  483. $table_title .= ($info_course ? Display::return_icon('course.png', get_lang('Course'), array(), 22).' '.$info_course['title'].' ':'');
  484. }
  485. echo Display::tag('h2', $table_title);
  486. if (empty($_GET['details'])) {
  487. $csv_content[] = array ();
  488. $csv_content[] = array (
  489. get_lang('Session', ''),
  490. get_lang('Course', ''),
  491. get_lang('Time', ''),
  492. get_lang('Progress', ''),
  493. get_lang('Score', ''),
  494. get_lang('AttendancesFaults', ''),
  495. get_lang('Evaluations')
  496. );
  497. $attendance = new Attendance();
  498. foreach ($courses_in_session as $key => $courses) {
  499. $session_id = $key;
  500. $session_info = api_get_session_info($session_id);
  501. $session_name = $session_info['name'];
  502. $date_start = '';
  503. if (!empty($session_info['date_start']) && $session_info['date_start'] != '0000-00-00') {
  504. $date_start = api_format_date($session_info['date_start'], DATE_FORMAT_SHORT);
  505. }
  506. $date_end = '';
  507. if (!empty($session_info['date_end']) && $session_info['date_end'] != '0000-00-00') {
  508. $date_end = api_format_date($session_info['date_end'], DATE_FORMAT_SHORT);
  509. }
  510. if (!empty($date_start) && !empty($date_end)) {
  511. $date_session = get_lang('From') . ' ' . $date_start . ' ' . get_lang('Until') . ' ' . $date_end;
  512. }
  513. $title = '';
  514. if (empty($session_id)) {
  515. $title = Display::return_icon('course.png', get_lang('Courses'), array(), 22).' '.get_lang('Courses');
  516. } else {
  517. $title = Display::return_icon('session.png', get_lang('Session'), array(), 22).' '.$session_name.($date_session?' ('.$date_session.')':'');
  518. }
  519. // Courses
  520. echo '<h3>'.$title.'</h3>';
  521. echo '<table class="data_table">';
  522. echo '<tr>
  523. <th>'.get_lang('Course').'</th>
  524. <th>'.get_lang('Time').'</th>
  525. <th>'.get_lang('Progress').'</th>
  526. <th>'.get_lang('Score').'</th>
  527. <th>'.get_lang('AttendancesFaults').'</th>
  528. <th>'.get_lang('Evaluations').'</th>
  529. <th>'.get_lang('Details').'</th>
  530. </tr>';
  531. if (!empty($courses)) {
  532. foreach ($courses as $course_code) {
  533. if (CourseManager :: is_user_subscribed_in_course($student_id, $course_code, true)) {
  534. $course_info = CourseManager :: get_course_information($course_code);
  535. $time_spent_on_course = api_time_to_hms(Tracking :: get_time_spent_on_the_course($info_user['user_id'], $course_code, $session_id));
  536. // get average of faults in attendances by student
  537. $results_faults_avg = $attendance->get_faults_average_by_course($student_id, $course_code, $session_id);
  538. if (!empty($results_faults_avg['total'])) {
  539. if (api_is_drh()) {
  540. $attendances_faults_avg = '<a title="'.get_lang('GoAttendance').'" href="'.api_get_path(WEB_CODE_PATH).'attendance/index.php?cidReq='.$course_code.'&id_session='.$session_id.'&student_id='.$student_id.'">'.$results_faults_avg['faults'].'/'.$results_faults_avg['total'].' ('.$results_faults_avg['porcent'].'%)</a>';
  541. } else {
  542. $attendances_faults_avg = $results_faults_avg['faults'].'/'.$results_faults_avg['total'].' ('.$results_faults_avg['porcent'].'%)';
  543. }
  544. } else {
  545. $attendances_faults_avg = '0/0 (0%)';
  546. }
  547. // get evaluatios by student
  548. $cats = Category::load(null, null, $course_code, null, null, $session_id);
  549. $scoretotal = array();
  550. if (isset($cats) && isset($cats[0])) {
  551. if (!empty($session_id)) {
  552. $scoretotal= $cats[0]->calc_score($student_id, $course_code, $session_id);
  553. } else {
  554. $scoretotal= $cats[0]->calc_score($student_id, $course_code);
  555. }
  556. }
  557. $scoretotal_display = '0/0 (0%)';
  558. if (!empty($scoretotal)) {
  559. $scoretotal_display = round($scoretotal[0],1).'/'.round($scoretotal[1],1).' ('.round(($scoretotal[0] / $scoretotal[1]) * 100,2) . ' %)';
  560. }
  561. $progress = Tracking::get_avg_student_progress($info_user['user_id'], $course_code, null, $session_id);
  562. $score = Tracking :: get_avg_student_score($info_user['user_id'], $course_code, null, $session_id);
  563. $progress = empty($progress) ? '0%' : $progress.'%';
  564. $score = empty($score) ? '0%' : $score.'%';
  565. $csv_content[] = array (
  566. $session_name,
  567. $course_info['title'],
  568. $time_spent_on_course,
  569. $progress,
  570. $score,
  571. $attendances_faults_avg,
  572. $scoretotal_display
  573. );
  574. echo '<tr>
  575. <td align="right">'.$course_info['title'].'</td>
  576. <td align="right">'.$time_spent_on_course .'</td>
  577. <td align="right">'.$progress.'</td>
  578. <td align="right">'.$score.'</td>
  579. <td align="right">'.$attendances_faults_avg.'</td>
  580. <td align="right">'.$scoretotal_display.'</td>';
  581. if (isset ($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
  582. echo '<td align="center" width="10"><a href="'.api_get_self().'?student='.$info_user['user_id'].'&details=true&course='.$course_info['code'].'&id_coach='.Security::remove_XSS($_GET['id_coach']).'&origin='.Security::remove_XSS($_GET['origin']).'&id_session='.$session_id.'#infosStudent"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></td>';
  583. } else {
  584. echo '<td align="center" width="10"><a href="'.api_get_self().'?student='.$info_user['user_id'].'&details=true&course='.$course_info['code'].'&origin='.Security::remove_XSS($_GET['origin']).'&id_session='.$session_id.'#infosStudent"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></td>';
  585. }
  586. echo '</tr>';
  587. }
  588. }
  589. } else {
  590. echo "<tr><td colspan='5'>".get_lang('NoCourse')."</td></tr>";
  591. }
  592. echo '</table>';
  593. }
  594. } else {
  595. $csv_content[] = array ();
  596. $csv_content[] = array (str_replace('&nbsp;', '', $table_title));
  597. $headerLearnpath = array (
  598. get_lang('Learnpath'),
  599. get_lang('Time'),
  600. get_lang('Progress'),
  601. get_lang('LastConnexion')
  602. );
  603. $t_lp = Database :: get_course_table(TABLE_LP_MAIN);
  604. // csv export headers
  605. $csv_content[] = array ();
  606. $csv_content[] = array (
  607. get_lang('Learnpath', ''),
  608. get_lang('Time', ''),
  609. get_lang('AverageScore', ''),
  610. get_lang('LatestScore', ''),
  611. get_lang('Progress', ''),
  612. get_lang('LastConnexion', '')
  613. );
  614. if (empty($session_id)) {
  615. $sql_lp = " SELECT lp.name, lp.id FROM $t_lp lp WHERE session_id = 0 AND c_id = {$info_course['real_id']} ORDER BY lp.display_order";
  616. } else {
  617. $sql_lp = " SELECT lp.name, lp.id FROM $t_lp lp WHERE c_id = {$info_course['real_id']} ORDER BY lp.display_order";
  618. }
  619. $rs_lp = Database::query($sql_lp);
  620. $token = Security::get_token();
  621. if (Database :: num_rows($rs_lp) > 0) {
  622. ?>
  623. <!-- LPs-->
  624. <table class="data_table">
  625. <tr>
  626. <th><?php echo get_lang('Learnpaths');?></th>
  627. <th><?php echo get_lang('Time').' '; Display :: display_icon('info3.gif', get_lang('TotalTimeByCourse'), array ('align' => 'absmiddle', 'hspace' => '3px')); ?></th>
  628. <th><?php echo get_lang('AverageScore').' '; Display :: display_icon('info3.gif', get_lang('AverageIsCalculatedBasedInAllAttempts'), array ( 'align' => 'absmiddle', 'hspace' => '3px')); ?></th>
  629. <th><?php echo get_lang('LatestAttemptAverageScore').' '; Display :: display_icon('info3.gif', get_lang('AverageIsCalculatedBasedInTheLatestAttempts'), array ( 'align' => 'absmiddle', 'hspace' => '3px')); ?></th>
  630. <th><?php echo get_lang('Progress').' '; Display :: display_icon('info3.gif', get_lang('LPProgressScore'), array ('align' => 'absmiddle','hspace' => '3px')); ?></th>
  631. <th><?php echo get_lang('LastConnexion').' '; Display :: display_icon('info3.gif', get_lang('LastTimeTheCourseWasUsed'), array ('align' => 'absmiddle','hspace' => '3px')); ?></th>
  632. <?php
  633. echo '<th>'.get_lang('Details').'</th>';
  634. if (api_is_course_admin()) {
  635. echo '<th>'.get_lang('ResetLP').'</th>';
  636. }
  637. ?>
  638. </tr>
  639. <?php
  640. $i = 0;
  641. while ($learnpath = Database :: fetch_array($rs_lp)) {
  642. $lp_id = intval($learnpath['id']);
  643. $lp_name = $learnpath['name'];
  644. $any_result = false;
  645. // Get progress in lp
  646. $progress = Tracking::get_avg_student_progress($student_id, $course_code, array($lp_id), $session_id);
  647. if ($progress === null) {
  648. $progress = '0%';
  649. } else {
  650. $any_result = true;
  651. }
  652. // Get time in lp
  653. $total_time = Tracking::get_time_spent_in_lp($student_id, $course_code, array($lp_id),$session_id);
  654. if (!empty($total_time)) $any_result = true;
  655. // Get last connection time in lp
  656. $start_time = Tracking::get_last_connection_time_in_lp($student_id, $course_code, $lp_id, $session_id);
  657. if (!empty($start_time)) {
  658. $start_time = api_convert_and_format_date($start_time, DATE_TIME_FORMAT_LONG);
  659. } else {
  660. $start_time = '-';
  661. }
  662. if (!empty($total_time)) $any_result = true;
  663. // Quizz in lp
  664. $score = Tracking::get_avg_student_score($student_id, $course_code, array($lp_id),$session_id);
  665. // Latest exercise results in a LP
  666. $score_latest = Tracking :: get_avg_student_score($student_id, $course_code, array($lp_id),$session_id, false, true);
  667. if ($i % 2 == 0) $css_class = "row_even";
  668. else $css_class = "row_odd";
  669. $i++;
  670. // csv export content
  671. $csv_content[] = array (
  672. api_html_entity_decode(stripslashes($lp_name), ENT_QUOTES, $charset),
  673. api_time_to_hms($total_time),
  674. $score . '%',
  675. $score_latest . '%',
  676. $progress.'%',
  677. $start_time
  678. );
  679. echo '<tr class="'.$css_class.'">';
  680. echo Display::tag('td', stripslashes($lp_name));
  681. echo Display::tag('td', api_time_to_hms($total_time), array('align'=>'center'));
  682. if (!is_null($score)) {
  683. if (is_numeric($score)) {
  684. $score = $score.'%';
  685. }
  686. }
  687. echo Display::tag('td', $score, array('align'=>'center'));
  688. if (!is_null($score_latest)) {
  689. if (is_numeric($score_latest)) {
  690. $score_latest = $score_latest.'%';
  691. }
  692. }
  693. echo Display::tag('td', $score_latest, array('align'=>'center'));
  694. if (is_numeric($progress)) {
  695. $progress = $progress.'%';
  696. } else {
  697. $progress = '-';
  698. }
  699. echo Display::tag('td', $progress, array('align'=>'center'));
  700. //Do not change with api_convert_and_format_date, because this value came from the lp_item_view table
  701. //which implies several other changes not a priority right now
  702. echo Display::tag('td', $start_time, array('align'=>'center'));
  703. if ($any_result === true) {
  704. $from = '';
  705. if ($from_myspace) {
  706. $from ='&from=myspace';
  707. }
  708. $link = Display::url('<img src="../img/2rightarrow.gif" border="0" />','lp_tracking.php?course='.Security::remove_XSS($_GET['course']).$from.'&origin='.Security::remove_XSS($_GET['origin']).'&lp_id='.$learnpath['id'].'&student_id='.$info_user['user_id'].'&id_session='.$session_id);
  709. echo Display::tag('td', $link, array('align'=>'center'));
  710. }
  711. if (api_is_course_admin()) {
  712. echo '<td align="center">';
  713. if($any_result === true) {
  714. echo '<a href="myStudents.php?action=reset_lp&sec_token='.$token.'&course='.Security::remove_XSS($_GET['course']).'&details='.Security::remove_XSS($_GET['details']).'&origin='.Security::remove_XSS($_GET['origin']).'&lp_id='.$learnpath['id'].'&student='.$info_user['user_id'].'&details=true&id_session='.Security::remove_XSS($_GET['id_session']).'">';
  715. echo Display::return_icon('clean.png',get_lang('Clean'),'','22').'</a>';
  716. echo '</a>';
  717. }
  718. echo '</td>';
  719. echo '</tr>';
  720. }
  721. $data_learnpath[$i][] = $lp_name;
  722. $data_learnpath[$i][] = $progress . '%';
  723. }
  724. } else {
  725. //echo '<tr><td colspan="6">'.get_lang('NoLearnpath').'</td></tr>';
  726. }
  727. ?>
  728. </table>
  729. <!-- line about exercises -->
  730. <table class="data_table">
  731. <tr>
  732. <th><?php echo get_lang('Exercices'); ?></th>
  733. <th><?php echo get_lang('AverageScore').' '.Display :: return_icon('info3.gif', get_lang('AverageScore'), array('align' => 'absmiddle', 'hspace' => '3px')) ?></th>
  734. <th><?php echo get_lang('Attempts'); ?></th>
  735. <th><?php echo get_lang('LatestAttempt'); ?></th>
  736. <th><?php echo get_lang('AllAttempts'); ?></th>
  737. </tr>
  738. <?php
  739. $csv_content[] = array ();
  740. $csv_content[] = array (
  741. get_lang('Exercices'),
  742. get_lang('Score'),
  743. get_lang('Attempts')
  744. );
  745. $t_quiz = Database :: get_course_table(TABLE_QUIZ_TEST);
  746. $sql_exercices = "SELECT quiz.title, id FROM " . $t_quiz . " AS quiz
  747. WHERE quiz.c_id = ".$info_course['real_id']." AND
  748. active='1' AND
  749. quiz.session_id = $session_id
  750. ORDER BY quiz.title ASC ";
  751. $result_exercices = Database::query($sql_exercices);
  752. $i = 0;
  753. if (Database :: num_rows($result_exercices) > 0) {
  754. while ($exercices = Database :: fetch_array($result_exercices)) {
  755. $exercise_id = intval($exercices['id']);
  756. $count_attempts = Tracking::count_student_exercise_attempts($student_id, $course_code, $exercise_id, 0, 0, $session_id);
  757. $score_percentage = Tracking::get_avg_student_exercise_score($student_id, $course_code, $exercise_id, $session_id);
  758. $csv_content[] = array (
  759. $exercices['title'],
  760. $score_percentage . '%',
  761. $count_attempts
  762. );
  763. if ($i % 2) $css_class = 'row_odd';
  764. else $css_class = 'row_even';
  765. echo '<tr class="'.$css_class.'"><td>'.$exercices['title'].'</td>';
  766. echo '<td align="center">';
  767. if ($count_attempts > 0) {
  768. echo $score_percentage . '%';
  769. } else {
  770. echo '-';
  771. $score_percentage = 0;
  772. }
  773. echo '</td>';
  774. echo '<td align="center">'.$count_attempts.'</td>';
  775. echo '<td align="center">';
  776. $sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . '
  777. WHERE exe_exo_id="'.$exercise_id.'" AND
  778. exe_user_id="'.$student_id.'" AND
  779. exe_cours_id="'.$course_code.'" AND
  780. status = "" AND
  781. orig_lp_id = 0 AND
  782. orig_lp_item_id = 0
  783. ORDER BY exe_date DESC LIMIT 1';
  784. $result_last_attempt = Database::query($sql_last_attempt);
  785. if (Database :: num_rows($result_last_attempt) > 0) {
  786. $id_last_attempt = Database :: result($result_last_attempt, 0, 0);
  787. if ($count_attempts > 0)
  788. echo '<a href="../exercice/exercise_show.php?id=' . $id_last_attempt . '&cidReq='.$course_code.'&student='.$student_id.'&origin='.(empty($_GET['origin'])?'tracking':Security::remove_XSS($_GET['origin'])).'"> <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" border="0" /> </a>';
  789. }
  790. echo '</td>';
  791. echo '<td align="center">';
  792. $all_attempt_url = "../exercice/exercise_report.php?exerciseId=$exercise_id&cidReq=$course_code&filter_by_user=$student_id&id_session=$session_id";
  793. echo Display::url(Display::return_icon('test_results.png', get_lang('AllAttempts'), array(), 22), $all_attempt_url );
  794. echo '</td></tr>';
  795. $data_exercices[$i][] = $exercices['title'];
  796. $data_exercices[$i][] = $score_percentage . '%';
  797. $data_exercices[$i][] = $count_attempts;
  798. $i++;
  799. }
  800. } else {
  801. echo '<tr><td colspan="6">'.get_lang('NoExercise').'</td></tr>';
  802. }
  803. echo '</table>';
  804. //@when using sessions we do not show the survey list
  805. if (empty($session_id)) {
  806. $survey_list = survey_manager::get_surveys($course_code, $session_id);
  807. $survey_data = array();
  808. foreach($survey_list as $survey) {
  809. $user_list = survey_manager::get_people_who_filled_survey($survey['survey_id'], false, $info_course['real_id']);
  810. $survey_done = Display::return_icon("accept_na.png", get_lang('NoAnswer'), array(), 22);
  811. if (in_array($student_id, $user_list)) {
  812. $survey_done = Display::return_icon("accept.png", get_lang('Answered'), array(), 22);
  813. }
  814. $data = array('title' => $survey['title'], 'done' => $survey_done);
  815. $survey_data[] = $data;
  816. }
  817. if (!empty($survey_list)) {
  818. $table = new HTML_Table(array('class' => 'data_table'));
  819. $header_names = array(get_lang('Survey'), get_lang('Answered'));
  820. $row = 0;
  821. $column = 0;
  822. foreach ($header_names as $item) {
  823. $table->setHeaderContents($row, $column, $item);
  824. $column++;
  825. }
  826. $row = 1;
  827. if (!empty($survey_data)) {
  828. foreach ($survey_data as $data) {
  829. $column = 0;
  830. $table->setCellContents($row, $column, $data);
  831. //$table->setRowAttributes($row, 'style="text-align:center"');
  832. $class = 'class="row_odd"';
  833. if($row % 2) {
  834. $class = 'class="row_even"';
  835. }
  836. $table->setRowAttributes($row, $class, true);
  837. $column++;
  838. $row++;
  839. }
  840. }
  841. echo $table->toHtml();
  842. }
  843. }
  844. // line about other tools
  845. echo '<table class="data_table">';
  846. $csv_content[] = array ();
  847. $nb_assignments = Tracking::count_student_assignments($student_id, $course_code, $session_id);
  848. $messages = Tracking::count_student_messages($student_id, $course_code, $session_id);
  849. $links = Tracking::count_student_visited_links($student_id, $course_code, $session_id);
  850. $chat_last_connection = Tracking::chat_last_connection($student_id, $course_code, $session_id);
  851. $documents = Tracking::count_student_downloaded_documents($student_id, $course_code, $session_id);
  852. $uploaded_documents = Tracking::count_student_uploaded_documents($student_id, $course_code, $session_id);
  853. $csv_content[] = array (
  854. get_lang('Student_publication'),
  855. $nb_assignments
  856. );
  857. $csv_content[] = array (
  858. get_lang('Messages'),
  859. $messages
  860. );
  861. $csv_content[] = array (
  862. get_lang('LinksDetails'),
  863. $links
  864. );
  865. $csv_content[] = array (
  866. get_lang('DocumentsDetails'),
  867. $documents
  868. );
  869. $csv_content[] = array (
  870. get_lang('UploadedDocuments'),
  871. $uploaded_documents
  872. );
  873. $csv_content[] = array (
  874. get_lang('ChatLastConnection'),
  875. $chat_last_connection
  876. );
  877. ?>
  878. <tr>
  879. <th colspan="2"><?php echo get_lang('OtherTools'); ?></th>
  880. </tr>
  881. <tr><!-- assignments -->
  882. <td width="40%"><?php echo get_lang('Student_publication') ?></td>
  883. <td><?php echo $nb_assignments ?></td>
  884. </tr>
  885. <tr><!-- messages -->
  886. <td><?php echo get_lang('Messages') ?></td>
  887. <td><?php echo $messages ?></td>
  888. </tr>
  889. <tr><!-- links -->
  890. <td><?php echo get_lang('LinksDetails') ?></td>
  891. <td><?php echo $links ?></td>
  892. </tr>
  893. <tr><!-- downloaded documents -->
  894. <td><?php echo get_lang('DocumentsDetails') ?></td>
  895. <td><?php echo $documents ?></td>
  896. </tr>
  897. <tr><!-- uploaded documents -->
  898. <td><?php echo get_lang('UploadedDocuments') ?></td>
  899. <td><?php echo $uploaded_documents ?></td>
  900. </tr>
  901. <tr><!-- Chats -->
  902. <td><?php echo get_lang('ChatLastConnection') ?></td>
  903. <td><?php echo $chat_last_connection; ?></td>
  904. </tr>
  905. </table>
  906. </td>
  907. </tr>
  908. </table>
  909. <?php
  910. } //end details
  911. }
  912. if ($export_csv) {
  913. ob_end_clean();
  914. Export :: export_table_csv($csv_content, 'reporting_student');
  915. exit;
  916. }
  917. /* FOOTER */
  918. Display :: display_footer();