myStudents.php 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CourseBundle\Entity\CLp;
  4. /**
  5. * Implements the tracking of students in the Reporting pages
  6. * @package chamilo.reporting
  7. */
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. api_block_anonymous_users();
  10. $export = isset($_GET['export']) ? $_GET['export'] : false;
  11. $sessionId = isset($_GET['id_session']) ? intval($_GET['id_session']) : 0;
  12. $origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : '';
  13. $course_code = isset($_GET['course']) ? Security::remove_XSS($_GET['course']) : '';
  14. $courseInfo = api_get_course_info($course_code);
  15. $student_id = intval($_GET['student']);
  16. $allowedToTrackUser = true;
  17. if (
  18. !api_is_session_admin() &&
  19. !api_is_drh() &&
  20. !api_is_student_boss() &&
  21. !api_is_platform_admin()
  22. ) {
  23. if (empty($sessionId)) {
  24. $isTeacher = false;
  25. // Check if is current teacher if set
  26. if (!empty($courseInfo)) {
  27. $isTeacher = CourseManager::is_course_teacher(
  28. api_get_user_id(),
  29. $courseInfo['code']
  30. );
  31. }
  32. if (!api_is_course_admin() && $isTeacher == false) {
  33. if (!empty($courseInfo)) {
  34. // Check if the user is tutor of the course
  35. $userCourseStatus = CourseManager::get_tutor_in_course_status(
  36. api_get_user_id(),
  37. $courseInfo['real_id']
  38. );
  39. if ($userCourseStatus != 1) {
  40. $allowedToTrackUser = false;
  41. }
  42. }
  43. }
  44. } else {
  45. $coach = api_is_coach($sessionId, $courseInfo['real_id']);
  46. if (!$coach) {
  47. $allowedToTrackUser = false;
  48. }
  49. }
  50. }
  51. if (!$allowedToTrackUser) {
  52. api_not_allowed(true);
  53. }
  54. $htmlHeadXtra[] = '<script>
  55. function show_image(image,width,height) {
  56. width = parseInt(width) + 20;
  57. height = parseInt(height) + 20;
  58. window_x = window.open(image,\'windowX\',\'width=\'+ width + \', height=\'+ height + \'\');
  59. }
  60. </script>';
  61. if ($export) {
  62. ob_start();
  63. }
  64. $csv_content = array();
  65. $from_myspace = false;
  66. if (isset($_GET['from']) && $_GET['from'] == 'myspace') {
  67. $from_myspace = true;
  68. $this_section = SECTION_TRACKING;
  69. } else {
  70. $this_section = SECTION_COURSES;
  71. }
  72. $nameTools = get_lang('StudentDetails');
  73. $em = Database::getManager();
  74. if (isset($_GET['details'])) {
  75. if ($origin === 'user_course') {
  76. if (empty($cidReq)) {
  77. $interbreadcrumb[] = array(
  78. "url" => api_get_path(WEB_COURSE_PATH).$courseInfo['directory'],
  79. 'name' => $courseInfo['title']
  80. );
  81. }
  82. $interbreadcrumb[] = array(
  83. "url" => "../user/user.php?cidReq=".$course_code,
  84. "name" => get_lang("Users")
  85. );
  86. } else {
  87. if ($origin === 'tracking_course') {
  88. $interbreadcrumb[] = array(
  89. "url" => "../tracking/courseLog.php?cidReq=".$course_code.'&id_session='.api_get_session_id(),
  90. "name" => get_lang("Tracking")
  91. );
  92. } else {
  93. if ($origin === 'resume_session') {
  94. $interbreadcrumb[] = array(
  95. 'url' => "../session/session_list.php",
  96. "name" => get_lang('SessionList')
  97. );
  98. $interbreadcrumb[] = array(
  99. 'url' => "../session/resume_session.php?id_session=".$sessionId,
  100. "name" => get_lang('SessionOverview')
  101. );
  102. } else {
  103. $interbreadcrumb[] = array(
  104. "url" => api_is_student_boss() ? "#" : "index.php",
  105. "name" => get_lang('MySpace')
  106. );
  107. if (isset($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
  108. $interbreadcrumb[] = array(
  109. "url" => "student.php?id_coach=".Security::remove_XSS($_GET['id_coach']),
  110. "name" => get_lang("CoachStudents")
  111. );
  112. $interbreadcrumb[] = array(
  113. "url" => "myStudents.php?student=".$student_id.'&id_coach='.Security::remove_XSS($_GET['id_coach']),
  114. "name" => get_lang("StudentDetails")
  115. );
  116. } else {
  117. $interbreadcrumb[] = array(
  118. "url" => "student.php",
  119. "name" => get_lang("MyStudents")
  120. );
  121. $interbreadcrumb[] = array(
  122. "url" => "myStudents.php?student=".$student_id,
  123. "name" => get_lang("StudentDetails")
  124. );
  125. }
  126. }
  127. }
  128. }
  129. $nameTools = get_lang("DetailsStudentInCourse");
  130. } else {
  131. if ($origin == 'resume_session') {
  132. $interbreadcrumb[] = array(
  133. 'url' => "../session/session_list.php",
  134. "name" => get_lang('SessionList')
  135. );
  136. if (!empty($sessionId)) {
  137. $interbreadcrumb[] = array(
  138. 'url' => "../session/resume_session.php?id_session=".$sessionId,
  139. "name" => get_lang('SessionOverview')
  140. );
  141. }
  142. } else {
  143. $interbreadcrumb[] = array(
  144. "url" => api_is_student_boss() ? "#" : "index.php",
  145. "name" => get_lang('MySpace')
  146. );
  147. if (isset($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
  148. if ($sessionId) {
  149. $interbreadcrumb[] = array(
  150. "url" => "student.php?id_coach=".Security::remove_XSS($_GET['id_coach'])."&id_session=".$sessionId,
  151. "name" => get_lang("CoachStudents")
  152. );
  153. } else {
  154. $interbreadcrumb[] = array(
  155. "url" => "student.php?id_coach=".Security::remove_XSS($_GET['id_coach']),
  156. "name" => get_lang("CoachStudents")
  157. );
  158. }
  159. } else {
  160. $interbreadcrumb[] = array(
  161. "url" => "student.php",
  162. "name" => get_lang("MyStudents")
  163. );
  164. }
  165. }
  166. }
  167. // Database Table Definitions
  168. $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  169. $tbl_stats_exercices = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  170. if (isset($_GET['user_id']) && $_GET['user_id'] != "") {
  171. $user_id = intval($_GET['user_id']);
  172. } else {
  173. $user_id = api_get_user_id();
  174. }
  175. // Action behaviour
  176. $action = isset($_GET['action']) ? $_GET['action'] : '';
  177. switch ($action) {
  178. case 'generate_certificate':
  179. // ofaj
  180. $certificate = new Certificate(0, $student_id);
  181. $certificate->generatePdfFromCustomCertificate();
  182. exit;
  183. break;
  184. case 'send_legal':
  185. $subject = get_lang('SendLegalSubject');
  186. $content = sprintf(
  187. get_lang('SendLegalDescriptionToUrlX'),
  188. api_get_path(WEB_PATH)
  189. );
  190. MessageManager::send_message_simple($student_id, $subject, $content);
  191. Display::addFlash(Display::return_message(get_lang('Sent')));
  192. break;
  193. case 'delete_legal':
  194. $extraFieldValue = new ExtraFieldValue('user');
  195. $value = $extraFieldValue->get_values_by_handler_and_field_variable(
  196. $student_id,
  197. 'legal_accept'
  198. );
  199. $result = $extraFieldValue->delete($value['id']);
  200. if ($result) {
  201. Display::addFlash(Display::return_message(get_lang('Deleted')));
  202. }
  203. break;
  204. case 'reset_lp':
  205. $lp_id = isset($_GET['lp_id']) ? intval($_GET['lp_id']) : '';
  206. if (api_is_allowed_to_edit() &&
  207. !empty($lp_id) &&
  208. !empty($student_id)
  209. ) {
  210. Event::delete_student_lp_events(
  211. $student_id,
  212. $lp_id,
  213. $courseInfo,
  214. $sessionId
  215. );
  216. // @todo delete the stats.track_e_exercises records.
  217. // First implement this http://support.chamilo.org/issues/1334
  218. $message = Display::return_message(
  219. get_lang('LPWasReset'),
  220. 'success'
  221. );
  222. }
  223. break;
  224. default:
  225. break;
  226. }
  227. // user info
  228. $user_info = api_get_user_info($student_id);
  229. $courses_in_session = array();
  230. //See #4676
  231. $drh_can_access_all_courses = false;
  232. if (api_is_drh() || api_is_platform_admin() || api_is_student_boss()) {
  233. $drh_can_access_all_courses = true;
  234. }
  235. $courses = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());
  236. $courses_in_session_by_coach = array();
  237. $sessions_coached_by_user = Tracking::get_sessions_coached_by_user(api_get_user_id());
  238. // RRHH or session admin
  239. if (api_is_session_admin() || api_is_drh()) {
  240. $courses = CourseManager::get_courses_followed_by_drh(api_get_user_id());
  241. $session_by_session_admin = SessionManager::get_sessions_followed_by_drh(api_get_user_id());
  242. if (!empty($session_by_session_admin)) {
  243. foreach ($session_by_session_admin as $session_coached_by_user) {
  244. $courses_followed_by_coach = Tracking :: get_courses_list_from_session($session_coached_by_user['id']);
  245. $courses_in_session_by_coach[$session_coached_by_user['id']] = $courses_followed_by_coach;
  246. }
  247. }
  248. }
  249. // Teacher or admin
  250. if (!empty($sessions_coached_by_user)) {
  251. foreach ($sessions_coached_by_user as $session_coached_by_user) {
  252. $sid = intval($session_coached_by_user['id']);
  253. $courses_followed_by_coach = Tracking :: get_courses_followed_by_coach(api_get_user_id(), $sid);
  254. $courses_in_session_by_coach[$sid] = $courses_followed_by_coach;
  255. }
  256. }
  257. $sql = "SELECT c_id
  258. FROM $tbl_course_user
  259. WHERE
  260. relation_type <> ".COURSE_RELATION_TYPE_RRHH." AND
  261. user_id = ".intval($user_info['user_id']);
  262. $rs = Database::query($sql);
  263. while ($row = Database :: fetch_array($rs)) {
  264. if ($drh_can_access_all_courses) {
  265. $courses_in_session[0][] = $row['c_id'];
  266. } else {
  267. if (isset($courses[$row['c_id']])) {
  268. $courses_in_session[0][] = $row['c_id'];
  269. }
  270. }
  271. }
  272. // Get the list of sessions where the user is subscribed as student
  273. $sql = 'SELECT session_id, c_id
  274. FROM '.Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER).'
  275. WHERE user_id=' . intval($user_info['user_id']);
  276. $rs = Database::query($sql);
  277. $tmp_sessions = array();
  278. while ($row = Database :: fetch_array($rs, 'ASSOC')) {
  279. $tmp_sessions[] = $row['session_id'];
  280. if ($drh_can_access_all_courses) {
  281. if (in_array($row['session_id'], $tmp_sessions)) {
  282. $courses_in_session[$row['session_id']][] = $row['c_id'];
  283. }
  284. } else {
  285. if (isset($courses_in_session_by_coach[$row['session_id']])) {
  286. if (in_array($row['session_id'], $tmp_sessions)) {
  287. $courses_in_session[$row['session_id']][] = $row['c_id'];
  288. }
  289. }
  290. }
  291. }
  292. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  293. api_get_user_id(),
  294. api_get_course_info()
  295. );
  296. if (api_is_drh() && !api_is_platform_admin()) {
  297. if (!empty($student_id)) {
  298. if (api_drh_can_access_all_session_content()) {
  299. //@todo securize drh with student id
  300. /*$users = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus('drh_all', api_get_user_id());
  301. $userList = array();
  302. foreach ($users as $user) {
  303. $userList[] = $user['user_id'];
  304. }
  305. if (!in_array($student_id, $userList)) {
  306. api_not_allowed(true);
  307. }*/
  308. } else {
  309. if (!($isDrhOfCourse)) {
  310. if (api_is_drh() &&
  311. !UserManager::is_user_followed_by_drh($student_id, api_get_user_id())
  312. ) {
  313. api_not_allowed(true);
  314. }
  315. }
  316. }
  317. }
  318. }
  319. Display :: display_header($nameTools);
  320. if (isset($message)) {
  321. echo $message;
  322. }
  323. $token = Security::get_token();
  324. $extraParam = '';
  325. if (api_is_student_boss()) {
  326. $extraParam = '&log_as_user='.$student_id;
  327. }
  328. if (!empty($student_id)) {
  329. // Actions bar
  330. echo '<div class="actions">';
  331. echo '<a href="javascript: window.history.go(-1);">'.
  332. Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
  333. echo '<a href="javascript: void(0);" onclick="javascript: window.print();">'.
  334. Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_MEDIUM).'</a>';
  335. echo '<a href="'.api_get_self().'?'.Security::remove_XSS($_SERVER['QUERY_STRING']).'&export=csv">'.
  336. Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), '', ICON_SIZE_MEDIUM).'</a> ';
  337. echo '<a href="'.api_get_self().'?'.Security::remove_XSS($_SERVER['QUERY_STRING']).'&export=xls">'.
  338. Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), '', ICON_SIZE_MEDIUM).'</a> ';
  339. if (!empty($user_info['email'])) {
  340. $send_mail = '<a href="mailto:'.$user_info['email'].'">'.
  341. Display::return_icon('mail_send.png', get_lang('SendMail'), '', ICON_SIZE_MEDIUM).'</a>';
  342. } else {
  343. $send_mail = Display::return_icon('mail_send_na.png', get_lang('SendMail'), '', ICON_SIZE_MEDIUM);
  344. }
  345. echo $send_mail;
  346. if (!empty($student_id) && !empty($course_code)) {
  347. // Only show link to connection details if course and student were defined in the URL
  348. echo '<a href="access_details.php?student='.$student_id.'&course='.$course_code.'&origin='.$origin.'&cidReq='.$course_code.'&id_session='.$sessionId.'">'.
  349. Display::return_icon('statistics.png', get_lang('AccessDetails'), '', ICON_SIZE_MEDIUM).'</a>';
  350. }
  351. if (api_can_login_as($student_id)) {
  352. echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_list.php?action=login_as&user_id='.$student_id.'&sec_token='.$token.'">'.
  353. Display::return_icon('login_as.png', get_lang('LoginAs'), null, ICON_SIZE_MEDIUM).'</a>&nbsp;&nbsp;';
  354. }
  355. if (api_is_platform_admin(false, true) || api_is_student_boss()) {
  356. echo Display::url(
  357. Display::return_icon(
  358. 'skill-badges.png',
  359. get_lang('AssignSkill'),
  360. null,
  361. ICON_SIZE_MEDIUM
  362. ),
  363. api_get_path(WEB_CODE_PATH).'badge/assign.php?'.http_build_query(['user' => $student_id])
  364. );
  365. }
  366. $permissions = StudentFollowUpPlugin::getPermissions(
  367. $student_id,
  368. api_get_user_id()
  369. );
  370. $isAllow = $permissions['is_allow'];
  371. if ($isAllow) {
  372. echo Display::url(
  373. Display::return_icon(
  374. 'blog.png',
  375. get_lang('Blog'),
  376. null,
  377. ICON_SIZE_MEDIUM
  378. ),
  379. api_get_path(WEB_PLUGIN_PATH).'studentfollowup/posts.php?student_id='.$student_id
  380. );
  381. }
  382. echo '</div>';
  383. // is the user online ?
  384. if (user_is_online($student_id)) {
  385. $online = get_lang('Yes');
  386. } else {
  387. $online = get_lang('No');
  388. }
  389. // get average of score and average of progress by student
  390. $avg_student_progress = $avg_student_score = 0;
  391. if (CourseManager::is_user_subscribed_in_course($user_info['user_id'], $course_code, true)) {
  392. $avg_student_progress = Tracking::get_avg_student_progress(
  393. $user_info['user_id'],
  394. $course_code,
  395. array(),
  396. $sessionId
  397. );
  398. // the score inside the Reporting table
  399. $avg_student_score = Tracking::get_avg_student_score(
  400. $user_info['user_id'],
  401. $course_code,
  402. array(),
  403. $sessionId
  404. );
  405. }
  406. $avg_student_progress = round($avg_student_progress, 2);
  407. $time_spent_on_the_course = 0;
  408. if (!empty($courseInfo)) {
  409. $time_spent_on_the_course = api_time_to_hms(
  410. Tracking:: get_time_spent_on_the_course(
  411. $user_info['user_id'],
  412. $courseInfo['real_id'],
  413. $sessionId
  414. )
  415. );
  416. }
  417. // get information about connections on the platform by student
  418. $first_connection_date = Tracking :: get_first_connection_date($user_info['user_id']);
  419. if ($first_connection_date == '') {
  420. $first_connection_date = get_lang('NoConnexion');
  421. }
  422. $last_connection_date = Tracking :: get_last_connection_date($user_info['user_id'], true);
  423. if ($last_connection_date == '') {
  424. $last_connection_date = get_lang('NoConnexion');
  425. }
  426. // cvs information
  427. $csv_content[] = array(
  428. get_lang('Information')
  429. );
  430. $csv_content[] = array(
  431. get_lang('Name'),
  432. get_lang('Email'),
  433. get_lang('Tel')
  434. );
  435. $csv_content[] = array(
  436. $user_info['complete_name'],
  437. $user_info['email'],
  438. $user_info['phone']
  439. );
  440. $csv_content[] = array();
  441. // csv tracking
  442. $csv_content[] = array(
  443. get_lang('Tracking')
  444. );
  445. $csv_content[] = array(
  446. get_lang('FirstLoginInPlatform'),
  447. get_lang('LatestLoginInPlatform'),
  448. get_lang('TimeSpentInTheCourse'),
  449. get_lang('Progress'),
  450. get_lang('Score')
  451. );
  452. $csv_content[] = array(
  453. strip_tags($first_connection_date),
  454. strip_tags($last_connection_date),
  455. $time_spent_on_the_course,
  456. $avg_student_progress.'%',
  457. $avg_student_score
  458. );
  459. $coachs_name = '';
  460. $session_name = '';
  461. $table_title = Display::return_icon(
  462. 'user.png',
  463. get_lang('User'),
  464. array(),
  465. ICON_SIZE_SMALL
  466. ).$user_info['complete_name'];
  467. echo Display::page_subheader($table_title);
  468. $userPicture = UserManager::getUserPicture($user_info['user_id']);
  469. $userGroupManager = new UserGroup();
  470. $userGroups = $userGroupManager->getNameListByUser(
  471. $user_info['user_id'],
  472. UserGroup::NORMAL_CLASS
  473. );
  474. ?>
  475. <img src="<?php echo $userPicture ?>">
  476. <div class="row">
  477. <div class="col-sm-6">
  478. <table class="table table-striped table-hover">
  479. <thead>
  480. <tr>
  481. <th><?php echo get_lang('Information'); ?></th>
  482. </tr>
  483. </thead>
  484. <tbody>
  485. <tr>
  486. <td><?php echo get_lang('Name').' : '.$user_info['complete_name']; ?></td>
  487. </tr>
  488. <tr>
  489. <td>
  490. <?php
  491. echo get_lang('Email').' : ';
  492. if (!empty($user_info['email'])) {
  493. echo '<a href="mailto:'.$user_info['email'].'">'.$user_info['email'].'</a>';
  494. } else {
  495. echo get_lang('NoEmail');
  496. } ?>
  497. </td>
  498. </tr>
  499. <tr>
  500. <td> <?php echo get_lang('Tel').' : ';
  501. if (!empty($user_info['phone'])) {
  502. echo $user_info['phone'];
  503. } else {
  504. echo get_lang('NoTel');
  505. }
  506. ?>
  507. </td>
  508. </tr>
  509. <tr>
  510. <td>
  511. <?php
  512. echo get_lang('OfficialCode').' : ';
  513. if (!empty($user_info['official_code'])) {
  514. echo $user_info['official_code'];
  515. } else {
  516. echo get_lang('NoOfficialCode');
  517. }
  518. ?>
  519. </td>
  520. </tr>
  521. <tr>
  522. <td><?php echo get_lang('OnLine').' : '.$online; ?> </td>
  523. </tr>
  524. <?php
  525. if (!empty($course_code)) {
  526. ?>
  527. <tr>
  528. <td>
  529. <a href="access_details.php?student=<?php echo $student_id; ?>&course=<?php echo $course_code; ?>&origin=<?php echo $origin; ?>&cidReq=<?php echo $course_code; ?>&id_session=<?php echo $sessionId; ?>"><?php echo get_lang('SeeAccesses'); ?></a>
  530. </td>
  531. </tr>
  532. <?php
  533. }
  534. // Display timezone if the user selected one and if the admin allows the use of user's timezone
  535. $timezone = null;
  536. $timezone_user = UserManager::get_extra_user_data_by_field(
  537. $user_info['user_id'],
  538. 'timezone'
  539. );
  540. $use_users_timezone = api_get_setting('use_users_timezone', 'timezones');
  541. if ($timezone_user['timezone'] != null && $use_users_timezone == 'true') {
  542. $timezone = $timezone_user['timezone'];
  543. }
  544. if ($timezone !== null) {
  545. ?>
  546. <tr>
  547. <td> <?php echo get_lang('Timezone').' : '.$timezone; ?> </td>
  548. </tr>
  549. <?php
  550. }
  551. ?>
  552. </tbody>
  553. </table>
  554. </div>
  555. <div class="col-sm-6">
  556. <table class="table table-striped table-hover">
  557. <thead>
  558. <tr>
  559. <th colspan="2" class="text-center"><?php echo get_lang('Tracking'); ?></th>
  560. </tr>
  561. </thead>
  562. <tbody>
  563. <tr><td align="right"><?php echo get_lang('FirstLoginInPlatform') ?></td>
  564. <td align="left"><?php echo $first_connection_date ?></td>
  565. </tr>
  566. <tr>
  567. <td align="right"><?php echo get_lang('LatestLoginInPlatform') ?></td>
  568. <td align="left"><?php echo $last_connection_date ?></td>
  569. </tr>
  570. <?php if (isset($_GET['details']) && $_GET['details'] == 'true') { ?>
  571. <tr>
  572. <td align="right"><?php echo get_lang('TimeSpentInTheCourse') ?></td>
  573. <td align="left"><?php echo $time_spent_on_the_course ?></td>
  574. </tr>
  575. <tr>
  576. <td align="right">
  577. <?php
  578. echo get_lang('Progress').' ';
  579. Display:: display_icon(
  580. 'info3.gif',
  581. get_lang('ScormAndLPProgressTotalAverage'),
  582. array('align' => 'absmiddle', 'hspace' => '3px')
  583. );
  584. ?>
  585. </td>
  586. <td align="left"><?php echo $avg_student_progress.'%' ?></td>
  587. </tr>
  588. <tr>
  589. <td align="right">
  590. <?php
  591. echo get_lang('Score').' ';
  592. Display:: display_icon(
  593. 'info3.gif',
  594. get_lang('ScormAndLPTestTotalAverage'),
  595. array('align' => 'absmiddle', 'hspace' => '3px')
  596. );
  597. ?>
  598. </td>
  599. <td align="left"><?php
  600. if (is_numeric($avg_student_score)) {
  601. echo $avg_student_score.'%';
  602. } else {
  603. echo $avg_student_score;
  604. }
  605. ?>
  606. </td>
  607. </tr>
  608. <?php
  609. }
  610. if (api_get_setting('allow_terms_conditions') === 'true') {
  611. $isBoss = UserManager::userIsBossOfStudent(api_get_user_id(), $student_id);
  612. if ($isBoss || api_is_platform_admin()) {
  613. $extraFieldValue = new ExtraFieldValue('user');
  614. $value = $extraFieldValue->get_values_by_handler_and_field_variable($student_id, 'legal_accept');
  615. $icon = Display::return_icon('accept_na.png');
  616. if (isset($value['value'])) {
  617. list($legalId, $legalLanguageId, $legalTime) = explode(':', $value['value']);
  618. $icon = Display::return_icon('accept.png').' '.api_get_local_time($legalTime);
  619. $icon .= ' '.Display::url(
  620. get_lang('DeleteLegal'),
  621. api_get_self().'?action=delete_legal&student='.$student_id.'&course='.$course_code,
  622. ['class' => 'btn btn-danger btn-xs']
  623. );
  624. } else {
  625. $icon .= ' '.Display::url(
  626. get_lang('SendLegal'),
  627. api_get_self().'?action=send_legal&student='.$student_id.'&course='.$course_code,
  628. ['class' => 'btn btn-primary btn-xs']
  629. );
  630. }
  631. echo '<tr>
  632. <td align="right">';
  633. echo get_lang('LegalAccepted').' </td> <td align="left">'.$icon;
  634. echo '</td></tr>';
  635. }
  636. }
  637. $icon = ' '.Display::url(
  638. get_lang('Generate'),
  639. api_get_self().'?action=generate_certificate&student='.$student_id.'&course='.$course_code,
  640. ['class' => 'btn btn-primary btn-xs']
  641. );
  642. echo '<tr>
  643. <td align="right">';
  644. echo get_lang('Certificate').' </td> <td align="left">'.$icon;
  645. echo '</td></tr>';
  646. ?>
  647. </tbody>
  648. </table>
  649. <?php if (!empty($userGroups)) { ?>
  650. <table class="table table-striped table-hover">
  651. <thead>
  652. <tr>
  653. <th><?php echo get_lang('Classes') ?></th>
  654. </tr>
  655. </thead>
  656. <tbody>
  657. <?php foreach ($userGroups as $class) { ?>
  658. <tr>
  659. <td><?php echo $class ?></td>
  660. </tr>
  661. <?php } ?>
  662. </tbody>
  663. </table>
  664. <?php } ?>
  665. </div>
  666. </div>
  667. <?php
  668. if (empty($_GET['details'])) {
  669. $csv_content[] = array();
  670. $csv_content[] = array(
  671. get_lang('Session'),
  672. get_lang('Course'),
  673. get_lang('Time'),
  674. get_lang('Progress'),
  675. get_lang('Score'),
  676. get_lang('AttendancesFaults'),
  677. get_lang('Evaluations')
  678. );
  679. $attendance = new Attendance();
  680. foreach ($courses_in_session as $sId => $courses) {
  681. $session_name = '';
  682. $access_start_date = '';
  683. $access_end_date = '';
  684. $date_session = '';
  685. $title = Display::return_icon(
  686. 'course.png',
  687. get_lang('Courses'),
  688. array(),
  689. ICON_SIZE_SMALL
  690. ).' '.get_lang('Courses');
  691. $session_info = api_get_session_info($sId);
  692. if ($session_info) {
  693. $session_name = $session_info['name'];
  694. if (!empty($session_info['access_start_date'])) {
  695. $access_start_date = api_format_date($session_info['access_start_date'], DATE_FORMAT_SHORT);
  696. }
  697. if (!empty($session_info['access_end_date'])) {
  698. $access_end_date = api_format_date($session_info['access_end_date'], DATE_FORMAT_SHORT);
  699. }
  700. if (!empty($access_start_date) && !empty($access_end_date)) {
  701. $date_session = get_lang('From').' '.$access_start_date.' '.get_lang('Until').' '.$access_end_date;
  702. }
  703. $title = Display::return_icon('session.png', get_lang('Session'), array(), ICON_SIZE_SMALL).' '.$session_name.($date_session ? ' ('.$date_session.')' : '');
  704. }
  705. // Courses
  706. echo '<h3>'.$title.'</h3>';
  707. echo '<div class="table-responsive">';
  708. echo '<table class="table table-striped table-hover courses-tracking">';
  709. echo '<thead>';
  710. echo '<tr>
  711. <th>'.get_lang('Course').'</th>
  712. <th>'.get_lang('Time').'</th>
  713. <th>'.get_lang('Progress').'</th>
  714. <th>'.get_lang('Score').'</th>
  715. <th>'.get_lang('AttendancesFaults').'</th>
  716. <th>'.get_lang('Evaluations').'</th>
  717. <th>'.get_lang('Details').'</th>
  718. </tr>';
  719. echo '</thead>';
  720. echo '<tbody>';
  721. if (!empty($courses)) {
  722. foreach ($courses as $courseId) {
  723. $courseInfoItem = api_get_course_info_by_id($courseId);
  724. $courseId = $courseInfoItem['real_id'];
  725. $courseCodeItem = $courseInfoItem['code'];
  726. $isSubscribed = CourseManager:: is_user_subscribed_in_course(
  727. $student_id,
  728. $courseCodeItem,
  729. true
  730. );
  731. if ($isSubscribed) {
  732. $time_spent_on_course = api_time_to_hms(
  733. Tracking :: get_time_spent_on_the_course($user_info['user_id'], $courseId, $sId)
  734. );
  735. // get average of faults in attendances by student
  736. $results_faults_avg = $attendance->get_faults_average_by_course(
  737. $student_id,
  738. $courseCodeItem,
  739. $sId
  740. );
  741. if (!empty($results_faults_avg['total'])) {
  742. if (api_is_drh()) {
  743. $attendances_faults_avg =
  744. '<a title="'.get_lang('GoAttendance').'" href="'.api_get_path(WEB_CODE_PATH).'attendance/index.php?cidReq='.$courseCodeItem.'&id_session='.$sId.'&student_id='.$student_id.'">'.
  745. $results_faults_avg['faults'].'/'.$results_faults_avg['total'].' ('.$results_faults_avg['porcent'].'%)</a>';
  746. } else {
  747. $attendances_faults_avg =
  748. $results_faults_avg['faults'].'/'.
  749. $results_faults_avg['total'].
  750. ' ('.$results_faults_avg['porcent'].'%)'
  751. ;
  752. }
  753. } else {
  754. $attendances_faults_avg = '0/0 (0%)';
  755. }
  756. // Get evaluations by student
  757. $cats = Category::load(
  758. null,
  759. null,
  760. $courseCodeItem,
  761. null,
  762. null,
  763. $sId
  764. );
  765. $scoretotal = array();
  766. if (isset($cats) && isset($cats[0])) {
  767. if (!empty($sId)) {
  768. $scoretotal = $cats[0]->calc_score($student_id, null, $courseCodeItem, $sId);
  769. } else {
  770. $scoretotal = $cats[0]->calc_score($student_id, null, $courseCodeItem);
  771. }
  772. }
  773. $scoretotal_display = '0/0 (0%)';
  774. if (!empty($scoretotal) && !empty($scoretotal[1])) {
  775. $scoretotal_display =
  776. round($scoretotal[0], 1).'/'.
  777. round($scoretotal[1], 1).
  778. ' ('.round(($scoretotal[0] / $scoretotal[1]) * 100, 2).' %)';
  779. }
  780. $progress = Tracking::get_avg_student_progress(
  781. $user_info['user_id'],
  782. $courseCodeItem,
  783. null,
  784. $sId
  785. );
  786. $score = Tracking:: get_avg_student_score(
  787. $user_info['user_id'],
  788. $courseCodeItem,
  789. null,
  790. $sId
  791. );
  792. $progress = empty($progress) ? '0%' : $progress.'%';
  793. $score = empty($score) ? '0%' : $score.'%';
  794. $csv_content[] = array(
  795. $session_name,
  796. $courseInfoItem['title'],
  797. $time_spent_on_course,
  798. $progress,
  799. $score,
  800. $attendances_faults_avg,
  801. $scoretotal_display
  802. );
  803. echo '<tr>
  804. <td ><a href="' .$courseInfoItem['course_public_url'].'?id_session='.$sId.'">'.
  805. $courseInfoItem['title'].'</a></td>
  806. <td >'.$time_spent_on_course.'</td>
  807. <td >'.$progress.'</td>
  808. <td >'.$score.'</td>
  809. <td >'.$attendances_faults_avg.'</td>
  810. <td >'.$scoretotal_display.'</td>';
  811. if (isset($_GET['id_coach']) && intval($_GET['id_coach']) != 0) {
  812. echo '<td width="10"><a href="'.api_get_self().'?student='.$user_info['user_id'].'&details=true&course='.$courseInfoItem['code'].'&id_coach='.Security::remove_XSS($_GET['id_coach']).'&origin='.$origin.'&id_session='.$sId.'#infosStudent">
  813. '.Display::return_icon('2rightarrow.png', get_lang('Details')).'</a></td>';
  814. } else {
  815. echo '<td width="10"><a href="'.api_get_self().'?student='.$user_info['user_id'].'&details=true&course='.$courseInfoItem['code'].'&origin='.$origin.'&id_session='.$sId.'#infosStudent">
  816. '.Display::return_icon('2rightarrow.png', get_lang('Details')).'</a></td>';
  817. }
  818. echo '</tr>';
  819. }
  820. }
  821. } else {
  822. echo "<tr><td colspan='5'>".get_lang('NoCourse')."</td></tr>";
  823. }
  824. echo '</tbody>';
  825. echo '</table>';
  826. echo '</div>';
  827. }
  828. } else {
  829. $trackingColumns = api_get_configuration_value('tracking_columns');
  830. $columnHeaders = [
  831. 'lp' => get_lang('LearningPath'),
  832. 'time' => get_lang('Time').
  833. Display::return_icon(
  834. 'info3.gif',
  835. get_lang('TotalTimeByCourse'),
  836. array('align' => 'absmiddle', 'hspace' => '3px')
  837. ),
  838. 'best_score' => get_lang('BestScore'),
  839. 'latest_attempt_avg_score' => get_lang('LatestAttemptAverageScore').
  840. Display::return_icon(
  841. 'info3.gif',
  842. get_lang('AverageIsCalculatedBasedInTheLatestAttempts'),
  843. array('align' => 'absmiddle', 'hspace' => '3px')
  844. ),
  845. 'progress'=> get_lang('Progress').
  846. Display::return_icon(
  847. 'info3.gif',
  848. get_lang('LPProgressScore'),
  849. array('align' => 'absmiddle', 'hspace' => '3px')
  850. ),
  851. 'last_connection' => get_lang('LastConnexion').
  852. Display::return_icon(
  853. 'info3.gif',
  854. get_lang('LastTimeTheCourseWasUsed'),
  855. array('align' => 'absmiddle', 'hspace' => '3px')
  856. )
  857. ];
  858. if ($user_info['status'] != INVITEE) {
  859. $csv_content[] = array();
  860. $csv_content[] = array(str_replace('&nbsp;', '', $table_title));
  861. $trackingColumns = api_get_configuration_value('tracking_columns');
  862. if (isset($trackingColumns['my_students_lp'])) {
  863. foreach ($columnHeaders as $key => $value) {
  864. if (!isset($trackingColumns['my_progress_lp'][$key]) ||
  865. $trackingColumns['my_students_lp'][$key] == false
  866. ) {
  867. unset($columnHeaders[$key]);
  868. }
  869. }
  870. }
  871. $headers = '';
  872. $columnHeadersToExport = [];
  873. // csv export headers
  874. foreach ($columnHeaders as $key => $columnName) {
  875. $columnHeadersToExport[] = strip_tags($columnName);
  876. $headers .= Display::tag(
  877. 'th',
  878. $columnName
  879. );
  880. }
  881. $csv_content[] = $columnHeadersToExport;
  882. $columnHeadersKeys = array_keys($columnHeaders);
  883. // @todo use LearnpathList class
  884. if (empty($sessionId)) {
  885. $dql = '
  886. SELECT lp FROM ChamiloCourseBundle:CLp lp
  887. WHERE
  888. (lp.sessionId = 0 OR lp.sessionId IS NULL) AND
  889. lp.cId = :course
  890. ORDER BY lp.displayOrder ASC
  891. ';
  892. $query = $em->createQuery($dql);
  893. $query->setParameters([
  894. 'course' => $courseInfo['real_id']
  895. ]);
  896. } else {
  897. $dql = '
  898. SELECT lp FROM ChamiloCourseBundle:CLp lp
  899. WHERE
  900. (lp.sessionId = :session OR lp.sessionId = 0 OR lp.sessionId IS NULL) AND
  901. lp.cId = :course
  902. ORDER BY lp.displayOrder ASC
  903. ';
  904. $query = $em->createQuery($dql);
  905. $query->setParameters([
  906. 'session' => $sessionId,
  907. 'course' => $courseInfo['real_id']
  908. ]);
  909. }
  910. $lps = $query->getResult();
  911. if (count($lps) > 0) {
  912. echo '<div class="table-responsive">';
  913. echo '<table class="table table-striped table-hover"><thead><tr>';
  914. echo $headers;
  915. echo '<th>'.get_lang('Details').'</th>';
  916. if (api_is_allowed_to_edit()) {
  917. echo '<th>'.get_lang('ResetLP').'</th>';
  918. }
  919. echo '</tr></thead><tbody>';
  920. $i = 0;
  921. /** @var CLp $learnpath */
  922. foreach ($lps as $learnpath) {
  923. $lp_id = $learnpath->getId();
  924. $lp_name = $learnpath->getName();
  925. $any_result = false;
  926. // Get progress in lp
  927. $progress = Tracking::get_avg_student_progress(
  928. $student_id,
  929. $course_code,
  930. array($lp_id),
  931. $sessionId
  932. );
  933. if ($progress === null) {
  934. $progress = '0%';
  935. } else {
  936. $any_result = true;
  937. }
  938. // Get time in lp
  939. $total_time = Tracking::get_time_spent_in_lp(
  940. $student_id,
  941. $course_code,
  942. array($lp_id),
  943. $sessionId
  944. );
  945. if (!empty($total_time)) {
  946. $any_result = true;
  947. }
  948. // Get last connection time in lp
  949. $start_time = Tracking::get_last_connection_time_in_lp(
  950. $student_id,
  951. $course_code,
  952. $lp_id,
  953. $sessionId
  954. );
  955. if (!empty($start_time)) {
  956. $start_time = api_convert_and_format_date($start_time, DATE_TIME_FORMAT_LONG);
  957. } else {
  958. $start_time = '-';
  959. }
  960. if (!empty($total_time)) {
  961. $any_result = true;
  962. }
  963. // Quiz in lp
  964. $score = Tracking::get_avg_student_score(
  965. $student_id,
  966. $course_code,
  967. array($lp_id),
  968. $sessionId
  969. );
  970. // Latest exercise results in a LP
  971. $score_latest = Tracking:: get_avg_student_score(
  972. $student_id,
  973. $course_code,
  974. array($lp_id),
  975. $sessionId,
  976. false,
  977. true
  978. );
  979. $bestScore = Tracking::get_avg_student_score(
  980. $student_id,
  981. $course_code,
  982. array($lp_id),
  983. $sessionId,
  984. false,
  985. false,
  986. true
  987. );
  988. if (empty($bestScore)) {
  989. $bestScore = '';
  990. } else {
  991. $bestScore = $bestScore.'%';
  992. }
  993. if ($i % 2 == 0) {
  994. $css_class = "row_even";
  995. } else {
  996. $css_class = "row_odd";
  997. }
  998. $i++;
  999. if (isset($score_latest) && !is_null($score_latest)) {
  1000. if (is_numeric($score_latest)) {
  1001. $score_latest = $score_latest.'%';
  1002. }
  1003. }
  1004. if (is_numeric($progress)) {
  1005. $progress = $progress.'%';
  1006. } else {
  1007. $progress = '-';
  1008. }
  1009. echo '<tr class="'.$css_class.'">';
  1010. $contentToExport = [];
  1011. if (in_array('lp', $columnHeadersKeys)) {
  1012. $contentToExport[] = api_html_entity_decode(stripslashes($lp_name), ENT_QUOTES, $charset);
  1013. echo Display::tag('td', stripslashes($lp_name));
  1014. }
  1015. if (in_array('time', $columnHeadersKeys)) {
  1016. $contentToExport[] = api_time_to_hms($total_time);
  1017. echo Display::tag('td', api_time_to_hms($total_time));
  1018. }
  1019. if (in_array('best_score', $columnHeadersKeys)) {
  1020. $contentToExport[] = $bestScore;
  1021. echo Display::tag('td', $bestScore);
  1022. }
  1023. if (in_array('latest_attempt_avg_score', $columnHeadersKeys)) {
  1024. $contentToExport[] = $score_latest;
  1025. echo Display::tag('td', $score_latest);
  1026. }
  1027. if (in_array('progress', $columnHeadersKeys)) {
  1028. $contentToExport[] = $progress;
  1029. echo Display::tag('td', $progress);
  1030. }
  1031. if (in_array('last_connection', $columnHeadersKeys)) {
  1032. //Do not change with api_convert_and_format_date, because this value came from the lp_item_view table
  1033. //which implies several other changes not a priority right now
  1034. $contentToExport[] = $start_time;
  1035. echo Display::tag('td', $start_time);
  1036. }
  1037. $csv_content[] = $contentToExport;
  1038. if ($any_result === true) {
  1039. $from = '';
  1040. if ($from_myspace) {
  1041. $from = '&from=myspace';
  1042. }
  1043. $link = Display::url(
  1044. Display::return_icon('2rightarrow.png', get_lang('Details')),
  1045. 'lp_tracking.php?cidReq='.$course_code.'&course='.$course_code.$from.'&origin='.$origin.'&lp_id='.$learnpath->getId().'&student_id='.$user_info['user_id'].'&id_session='.$sessionId
  1046. );
  1047. echo Display::tag('td', $link);
  1048. }
  1049. if (api_is_allowed_to_edit()) {
  1050. echo '<td>';
  1051. if ($any_result === true) {
  1052. $url = 'myStudents.php?action=reset_lp&sec_token='.$token.'&cidReq='.$course_code.'&course='.$course_code.'&details='.Security::remove_XSS($_GET['details']).'&origin='.$origin.'&lp_id='.$learnpath->getId().'&student='.$user_info['user_id'].'&details=true&id_session='.$sessionId;
  1053. echo Display::url(
  1054. Display::return_icon(
  1055. 'clean.png',
  1056. get_lang('Clean'),
  1057. '',
  1058. ICON_SIZE_SMALL
  1059. ),
  1060. $url,
  1061. ['onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToDelete')))."')) return false;"]
  1062. );
  1063. }
  1064. echo '</td>';
  1065. echo '</tr>';
  1066. }
  1067. }
  1068. ?>
  1069. </tbody>
  1070. </table>
  1071. </div>
  1072. <?php
  1073. }
  1074. } ?>
  1075. <!-- line about exercises -->
  1076. <?php if ($user_info['status'] != INVITEE) { ?>
  1077. <div class="table-responsive">
  1078. <table class="table table-striped table-hover">
  1079. <thead>
  1080. <tr>
  1081. <th><?php echo get_lang('Exercises'); ?></th>
  1082. <th><?php echo get_lang('LearningPath'); ?></th>
  1083. <th><?php echo get_lang('AvgCourseScore').' '.Display::return_icon('info3.gif', get_lang('AverageScore'), array('align' => 'absmiddle', 'hspace' => '3px')) ?></th>
  1084. <th><?php echo get_lang('Attempts'); ?></th>
  1085. <th><?php echo get_lang('LatestAttempt'); ?></th>
  1086. <th><?php echo get_lang('AllAttempts'); ?></th>
  1087. </tr>
  1088. </thead>
  1089. <tbody>
  1090. <?php
  1091. $csv_content[] = array();
  1092. $csv_content[] = array(
  1093. get_lang('Exercises'),
  1094. get_lang('LearningPath'),
  1095. get_lang('AvgCourseScore'),
  1096. get_lang('Attempts')
  1097. );
  1098. $t_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  1099. $sessionCondition = api_get_session_condition(
  1100. $sessionId,
  1101. true,
  1102. true,
  1103. 'quiz.session_id'
  1104. );
  1105. $sql = "SELECT quiz.title, id FROM ".$t_quiz." AS quiz
  1106. WHERE
  1107. quiz.c_id = ".$courseInfo['real_id']." AND
  1108. active IN (0, 1)
  1109. $sessionCondition
  1110. ORDER BY quiz.title ASC ";
  1111. $result_exercices = Database::query($sql);
  1112. $i = 0;
  1113. if (Database :: num_rows($result_exercices) > 0) {
  1114. while ($exercices = Database :: fetch_array($result_exercices)) {
  1115. $exercise_id = intval($exercices['id']);
  1116. $count_attempts = Tracking::count_student_exercise_attempts(
  1117. $student_id,
  1118. $courseInfo['real_id'],
  1119. $exercise_id,
  1120. 0,
  1121. 0,
  1122. $sessionId,
  1123. 2
  1124. );
  1125. $score_percentage = Tracking::get_avg_student_exercise_score(
  1126. $student_id,
  1127. $course_code,
  1128. $exercise_id,
  1129. $sessionId,
  1130. 1,
  1131. 0
  1132. );
  1133. if (!isset($score_percentage) && $count_attempts > 0) {
  1134. $scores_lp = Tracking::get_avg_student_exercise_score(
  1135. $student_id,
  1136. $course_code,
  1137. $exercise_id,
  1138. $sessionId,
  1139. 2,
  1140. 1
  1141. );
  1142. $score_percentage = $scores_lp[0];
  1143. $lp_name = $scores_lp[1];
  1144. } else {
  1145. $lp_name = '-';
  1146. }
  1147. $lp_name = !empty($lp_name) ? $lp_name : get_lang('NoLearnpath');
  1148. if ($i % 2) {
  1149. $css_class = 'row_odd';
  1150. } else {
  1151. $css_class = 'row_even';
  1152. }
  1153. echo '<tr class="'.$css_class.'"><td>'.$exercices['title'].'</td>';
  1154. echo '<td>';
  1155. if (!empty($lp_name)) {
  1156. echo $lp_name;
  1157. } else {
  1158. echo '-';
  1159. }
  1160. echo '</td>';
  1161. echo '<td>';
  1162. if ($count_attempts > 0) {
  1163. echo $score_percentage.'%';
  1164. } else {
  1165. echo '-';
  1166. $score_percentage = 0;
  1167. }
  1168. echo '</td>';
  1169. echo '<td>'.$count_attempts.'</td>';
  1170. echo '<td>';
  1171. $sql = 'SELECT exe_id FROM '.$tbl_stats_exercices.'
  1172. WHERE
  1173. exe_exo_id = "'.$exercise_id.'" AND
  1174. exe_user_id ="'.$student_id.'" AND
  1175. c_id = '.$courseInfo['real_id'].' AND
  1176. session_id = "'.$sessionId.'" AND
  1177. status = ""
  1178. ORDER BY exe_date DESC
  1179. LIMIT 1';
  1180. $result_last_attempt = Database::query($sql);
  1181. if (Database :: num_rows($result_last_attempt) > 0) {
  1182. $id_last_attempt = Database :: result($result_last_attempt, 0, 0);
  1183. if ($count_attempts > 0) {
  1184. echo '<a href="../exercise/exercise_show.php?id='.$id_last_attempt.'&cidReq='.$course_code.'&session_id='.$sessionId.'&student='.$student_id.'&origin='.(empty($origin) ? 'tracking' : $origin).'">
  1185. '.Display::return_icon('quiz.png').'
  1186. </a>';
  1187. }
  1188. }
  1189. echo '</td>';
  1190. echo '<td>';
  1191. if ($count_attempts > 0) {
  1192. $all_attempt_url = "../exercise/exercise_report.php?exerciseId=$exercise_id&cidReq=$course_code&filter_by_user=$student_id&id_session=$sessionId";
  1193. echo Display::url(
  1194. Display::return_icon(
  1195. 'test_results.png',
  1196. get_lang('AllAttempts'),
  1197. array(),
  1198. ICON_SIZE_SMALL
  1199. ),
  1200. $all_attempt_url
  1201. );
  1202. }
  1203. echo '</td>';
  1204. echo '</tr>';
  1205. $data_exercices[$i][] = $exercices['title'];
  1206. $data_exercices[$i][] = $score_percentage.'%';
  1207. $data_exercices[$i][] = $count_attempts;
  1208. $csv_content[] = array(
  1209. $exercices['title'],
  1210. $lp_name,
  1211. $score_percentage,
  1212. $count_attempts
  1213. );
  1214. $i++;
  1215. }
  1216. } else {
  1217. echo '<tr><td colspan="6">'.get_lang('NoExercise').'</td></tr>';
  1218. }
  1219. ?>
  1220. </tbody>
  1221. </table>
  1222. </div>
  1223. <?php
  1224. }
  1225. // @when using sessions we do not show the survey list
  1226. if (empty($sessionId)) {
  1227. $survey_list = SurveyManager::get_surveys($course_code, $sessionId);
  1228. $survey_data = array();
  1229. foreach ($survey_list as $survey) {
  1230. $user_list = SurveyManager::get_people_who_filled_survey($survey['survey_id'], false, $courseInfo['real_id']);
  1231. $survey_done = Display::return_icon("accept_na.png", get_lang('NoAnswer'), array(), ICON_SIZE_SMALL);
  1232. if (in_array($student_id, $user_list)) {
  1233. $survey_done = Display::return_icon("accept.png", get_lang('Answered'), array(), ICON_SIZE_SMALL);
  1234. }
  1235. $data = array('title' => $survey['title'], 'done' => $survey_done);
  1236. $survey_data[] = $data;
  1237. }
  1238. if (!empty($survey_list)) {
  1239. $table = new HTML_Table(array('class' => 'data_table'));
  1240. $header_names = array(get_lang('Survey'), get_lang('Answered'));
  1241. $row = 0;
  1242. $column = 0;
  1243. foreach ($header_names as $item) {
  1244. $table->setHeaderContents($row, $column, $item);
  1245. $column++;
  1246. }
  1247. $row = 1;
  1248. if (!empty($survey_data)) {
  1249. foreach ($survey_data as $data) {
  1250. $column = 0;
  1251. $table->setCellContents($row, $column, $data);
  1252. $class = 'class="row_odd"';
  1253. if ($row % 2) {
  1254. $class = 'class="row_even"';
  1255. }
  1256. $table->setRowAttributes($row, $class, true);
  1257. $column++;
  1258. $row++;
  1259. }
  1260. }
  1261. echo $table->toHtml();
  1262. }
  1263. }
  1264. require_once '../work/work.lib.php';
  1265. $userWorks = getWorkPerUser($student_id, $courseInfo['real_id'], $sessionId);
  1266. echo '
  1267. <div class="table-responsive">
  1268. <table class="table table-striped table-hover">
  1269. <thead>
  1270. <tr>
  1271. <th>' . get_lang('Tasks').'</th>
  1272. <th class="text-center">' . get_lang('DocumentNumber').'</th>
  1273. <th class="text-center">' . get_lang('Note').'</th>
  1274. <th class="text-center">' . get_lang('HandedOut').'</th>
  1275. <th class="text-center">' . get_lang('HandOutDateLimit').'</th>
  1276. <th class="text-center">' . get_lang('ConsideredWorkingTime').'</th>
  1277. </tr>
  1278. </thead>
  1279. <tbody>
  1280. ';
  1281. $workingTime = api_get_configuration_value('considered_working_time');
  1282. foreach ($userWorks as $work) {
  1283. $work = $work['work'];
  1284. foreach ($work->user_results as $key => $results) {
  1285. echo '<tr>';
  1286. echo '<td>'.$work->title.'</td>';
  1287. $documentNumber = $key + 1;
  1288. echo '<td class="text-center"><a href="'.api_get_path(WEB_CODE_PATH).'work/view.php?cidReq='.$course_code.'&id_session='.$sessionId.'&id='.$results['id'].'">('.$documentNumber.')</a></td>';
  1289. $qualification = !empty($results['qualification']) ? $results['qualification'] : '-';
  1290. echo '<td class="text-center">'.$qualification.'</td>';
  1291. echo '<td class="text-center">'.$results['formatted_date'].'</td>';
  1292. $assignment = get_work_assignment_by_id($work->id, $courseInfo['real_id']);
  1293. echo '<td class="text-center">';
  1294. if (!empty($assignment['expires_on'])) {
  1295. echo api_convert_and_format_date($assignment['expires_on']);
  1296. }
  1297. echo '</td>';
  1298. $fieldValue = new ExtraFieldValue('work');
  1299. $resultExtra = $fieldValue->getAllValuesForAnItem(
  1300. $work->iid,
  1301. true
  1302. );
  1303. foreach ($resultExtra as $field) {
  1304. $field = $field['value'];
  1305. if ($workingTime == $field->getField()->getVariable()) {
  1306. echo '<td class="text-center">'.$field->getValue().'</td>';
  1307. }
  1308. }
  1309. echo '</tr>';
  1310. }
  1311. }
  1312. echo '</tbody>
  1313. </table>
  1314. </div>
  1315. ';
  1316. // line about other tools
  1317. ?>
  1318. <div class="table-responsive">
  1319. <table class="table table-striped table-hover">
  1320. <thead>
  1321. <tr>
  1322. <th colspan="2"><?php echo get_lang('OtherTools'); ?></th>
  1323. </tr>
  1324. </thead>
  1325. <tbody>
  1326. <?php
  1327. $csv_content[] = array();
  1328. $nb_assignments = Tracking::count_student_assignments($student_id, $course_code, $sessionId);
  1329. $messages = Tracking::count_student_messages($student_id, $course_code, $sessionId);
  1330. $links = Tracking::count_student_visited_links($student_id, $courseInfo['real_id'], $sessionId);
  1331. $chat_last_connection = Tracking::chat_last_connection($student_id, $courseInfo['real_id'], $sessionId);
  1332. $documents = Tracking::count_student_downloaded_documents($student_id, $courseInfo['real_id'], $sessionId);
  1333. $uploaded_documents = Tracking::count_student_uploaded_documents($student_id, $course_code, $sessionId);
  1334. $csv_content[] = array(
  1335. get_lang('OtherTools')
  1336. );
  1337. $csv_content[] = array(
  1338. get_lang('Student_publication'),
  1339. $nb_assignments
  1340. );
  1341. $csv_content[] = array(
  1342. get_lang('Messages'),
  1343. $messages
  1344. );
  1345. $csv_content[] = array(
  1346. get_lang('LinksDetails'),
  1347. $links
  1348. );
  1349. $csv_content[] = array(
  1350. get_lang('DocumentsDetails'),
  1351. $documents
  1352. );
  1353. $csv_content[] = array(
  1354. get_lang('UploadedDocuments'),
  1355. $uploaded_documents
  1356. );
  1357. $csv_content[] = array(
  1358. get_lang('ChatLastConnection'),
  1359. $chat_last_connection
  1360. );
  1361. ?>
  1362. <tr><!-- assignments -->
  1363. <td width="40%"><?php echo get_lang('Student_publication') ?></td>
  1364. <td><?php echo $nb_assignments ?></td>
  1365. </tr>
  1366. <tr><!-- messages -->
  1367. <td><?php echo get_lang('Forum').' - '.get_lang('NumberOfPostsForThisUser') ?></td>
  1368. <td><?php echo $messages ?></td>
  1369. </tr>
  1370. <tr><!-- links -->
  1371. <td><?php echo get_lang('LinksDetails') ?></td>
  1372. <td><?php echo $links ?></td>
  1373. </tr>
  1374. <tr><!-- downloaded documents -->
  1375. <td><?php echo get_lang('DocumentsDetails') ?></td>
  1376. <td><?php echo $documents ?></td>
  1377. </tr>
  1378. <tr><!-- uploaded documents -->
  1379. <td><?php echo get_lang('UploadedDocuments') ?></td>
  1380. <td><?php echo $uploaded_documents ?></td>
  1381. </tr>
  1382. <tr><!-- Chats -->
  1383. <td><?php echo get_lang('ChatLastConnection') ?></td>
  1384. <td><?php echo $chat_last_connection; ?></td>
  1385. </tr>
  1386. </tbody>
  1387. </table>
  1388. </div>
  1389. <?php
  1390. } //end details
  1391. echo Tracking::displayUserSkills(
  1392. $user_info['user_id'],
  1393. $courseInfo ? $courseInfo['real_id'] : 0,
  1394. $sessionId
  1395. );
  1396. }
  1397. if ($export) {
  1398. ob_end_clean();
  1399. switch ($export) {
  1400. case 'csv':
  1401. Export::arrayToCsv($csv_content, 'reporting_student');
  1402. break;
  1403. case 'xls':
  1404. Export::arrayToXls($csv_content, 'reporting_student');
  1405. break;
  1406. }
  1407. exit;
  1408. }
  1409. Display :: display_footer();