myStudents.php 39 KB

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