myStudents.php 39 KB

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