myStudents.php 38 KB

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