myStudents.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  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],2).'/'.round($scoretotal[1],2).'('.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 . ' WHERE exe_exo_id="'.$exercise_id.'" AND exe_user_id="'.$student_id.'" AND exe_cours_id="'.$course_code.'" AND orig_lp_id = 0 AND orig_lp_item_id = 0 ORDER BY exe_date DESC LIMIT 1';
  777. $result_last_attempt = Database::query($sql_last_attempt);
  778. if (Database :: num_rows($result_last_attempt) > 0) {
  779. $id_last_attempt = Database :: result($result_last_attempt, 0, 0);
  780. if ($count_attempts > 0)
  781. 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>';
  782. }
  783. echo '</td>';
  784. echo '<td align="center">';
  785. $all_attempt_url = "../exercice/exercise_report.php?exerciseId=$exercise_id&cidReq=$course_code&filter_by_user=$student_id&id_session=$session_id";
  786. echo Display::url(Display::return_icon('test_results.png', get_lang('AllAttempts'), array(), 22), $all_attempt_url );
  787. echo '</td></tr>';
  788. $data_exercices[$i][] = $exercices['title'];
  789. $data_exercices[$i][] = $score_percentage . '%';
  790. $data_exercices[$i][] = $count_attempts;
  791. $i++;
  792. }
  793. } else {
  794. echo '<tr><td colspan="6">'.get_lang('NoExercise').'</td></tr>';
  795. }
  796. echo '</table>';
  797. //@when using sessions we do not show the survey list
  798. if (empty($session_id)) {
  799. $survey_list = survey_manager::get_surveys($course_code, $session_id);
  800. $survey_data = array();
  801. foreach($survey_list as $survey) {
  802. $user_list = survey_manager::get_people_who_filled_survey($survey['survey_id'], false, $info_course['real_id']);
  803. $survey_done = Display::return_icon("accept_na.png", get_lang('NoAnswer'), array(), 22);
  804. if (in_array($student_id, $user_list)) {
  805. $survey_done = Display::return_icon("accept.png", get_lang('Answered'), array(), 22);
  806. }
  807. $data = array('title' => $survey['title'], 'done' => $survey_done);
  808. $survey_data[] = $data;
  809. }
  810. if (!empty($survey_list)) {
  811. $table = new HTML_Table(array('class' => 'data_table'));
  812. $header_names = array(get_lang('Survey'), get_lang('Answered'));
  813. $row = 0;
  814. $column = 0;
  815. foreach ($header_names as $item) {
  816. $table->setHeaderContents($row, $column, $item);
  817. $column++;
  818. }
  819. $row = 1;
  820. if (!empty($survey_data)) {
  821. foreach ($survey_data as $data) {
  822. $column = 0;
  823. $table->setCellContents($row, $column, $data);
  824. //$table->setRowAttributes($row, 'style="text-align:center"');
  825. $class = 'class="row_odd"';
  826. if($row % 2) {
  827. $class = 'class="row_even"';
  828. }
  829. $table->setRowAttributes($row, $class, true);
  830. $column++;
  831. $row++;
  832. }
  833. }
  834. echo $table->toHtml();
  835. }
  836. }
  837. // line about other tools
  838. echo '<table class="data_table">';
  839. $csv_content[] = array ();
  840. $nb_assignments = Tracking::count_student_assignments($student_id, $course_code, $session_id);
  841. $messages = Tracking::count_student_messages($student_id, $course_code, $session_id);
  842. $links = Tracking::count_student_visited_links($student_id, $course_code, $session_id);
  843. $chat_last_connection = Tracking::chat_last_connection($student_id, $course_code, $session_id);
  844. $documents = Tracking::count_student_downloaded_documents($student_id, $course_code, $session_id);
  845. $uploaded_documents = Tracking::count_student_uploaded_documents($student_id, $course_code, $session_id);
  846. $csv_content[] = array (
  847. get_lang('Student_publication'),
  848. $nb_assignments
  849. );
  850. $csv_content[] = array (
  851. get_lang('Messages'),
  852. $messages
  853. );
  854. $csv_content[] = array (
  855. get_lang('LinksDetails'),
  856. $links
  857. );
  858. $csv_content[] = array (
  859. get_lang('DocumentsDetails'),
  860. $documents
  861. );
  862. $csv_content[] = array (
  863. get_lang('UploadedDocuments'),
  864. $uploaded_documents
  865. );
  866. $csv_content[] = array (
  867. get_lang('ChatLastConnection'),
  868. $chat_last_connection
  869. );
  870. ?>
  871. <tr>
  872. <th colspan="2"><?php echo get_lang('OtherTools'); ?></th>
  873. </tr>
  874. <tr><!-- assignments -->
  875. <td width="40%"><?php echo get_lang('Student_publication') ?></td>
  876. <td><?php echo $nb_assignments ?></td>
  877. </tr>
  878. <tr><!-- messages -->
  879. <td><?php echo get_lang('Messages') ?></td>
  880. <td><?php echo $messages ?></td>
  881. </tr>
  882. <tr><!-- links -->
  883. <td><?php echo get_lang('LinksDetails') ?></td>
  884. <td><?php echo $links ?></td>
  885. </tr>
  886. <tr><!-- downloaded documents -->
  887. <td><?php echo get_lang('DocumentsDetails') ?></td>
  888. <td><?php echo $documents ?></td>
  889. </tr>
  890. <tr><!-- uploaded documents -->
  891. <td><?php echo get_lang('UploadedDocuments') ?></td>
  892. <td><?php echo $uploaded_documents ?></td>
  893. </tr>
  894. <tr><!-- Chats -->
  895. <td><?php echo get_lang('ChatLastConnection') ?></td>
  896. <td><?php echo $chat_last_connection; ?></td>
  897. </tr>
  898. </table>
  899. </td>
  900. </tr>
  901. </table>
  902. <?php
  903. } //end details
  904. }
  905. if ($export_csv) {
  906. ob_end_clean();
  907. Export :: export_table_csv($csv_content, 'reporting_student');
  908. exit;
  909. }
  910. /* FOOTER */
  911. Display :: display_footer();