myStudents.php 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CourseBundle\Entity\CLpCategory;
  4. use ChamiloSession as Session;
  5. /**
  6. * Implements the tracking of students in the Reporting pages.
  7. *
  8. * @package chamilo.reporting
  9. */
  10. require_once __DIR__.'/../inc/global.inc.php';
  11. api_block_anonymous_users();
  12. $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_PUBLIC_PATH).'assets/jquery.easy-pie-chart/dist/jquery.easypiechart.js"></script>';
  13. $export = isset($_GET['export']) ? $_GET['export'] : false;
  14. $sessionId = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0;
  15. $origin = api_get_origin();
  16. $course_code = isset($_GET['course']) ? Security::remove_XSS($_GET['course']) : '';
  17. $courseInfo = api_get_course_info($course_code);
  18. $student_id = isset($_GET['student']) ? (int) $_GET['student'] : 0;
  19. $coachId = isset($_GET['id_coach']) ? (int) $_GET['id_coach'] : 0;
  20. $details = isset($_GET['details']) ? Security::remove_XSS($_GET['details']) : '';
  21. $currentUrl = api_get_self().'?student='.$student_id.'&course='.$course_code.'&id_session='.$sessionId
  22. .'&origin='.$origin.'&details='.$details;
  23. $allowMessages = api_get_configuration_value('private_messages_about_user');
  24. if (empty($student_id)) {
  25. api_not_allowed(true);
  26. }
  27. // user info
  28. $user_info = api_get_user_info($student_id);
  29. if (empty($user_info)) {
  30. api_not_allowed(true);
  31. }
  32. $allowToQualify = api_is_allowed_to_edit(null, true) ||
  33. api_is_course_tutor() ||
  34. api_is_session_admin() ||
  35. api_is_drh() ||
  36. api_is_student_boss();
  37. $allowedToTrackUser = true;
  38. if (!api_is_session_admin() &&
  39. !api_is_drh() &&
  40. !api_is_student_boss() &&
  41. !api_is_platform_admin()
  42. ) {
  43. if (empty($sessionId)) {
  44. $isTeacher = false;
  45. // Check if is current teacher if set
  46. if (!empty($courseInfo)) {
  47. $isTeacher = CourseManager::is_course_teacher(
  48. api_get_user_id(),
  49. $courseInfo['code']
  50. );
  51. }
  52. if (!api_is_course_admin() && $isTeacher == false) {
  53. if (!empty($courseInfo)) {
  54. // Check if the user is tutor of the course
  55. $userCourseStatus = CourseManager::get_tutor_in_course_status(
  56. api_get_user_id(),
  57. $courseInfo['real_id']
  58. );
  59. if ($userCourseStatus != 1) {
  60. $allowedToTrackUser = false;
  61. }
  62. }
  63. }
  64. } else {
  65. $coach = api_is_coach($sessionId, $courseInfo['real_id']);
  66. if (!$coach) {
  67. $allowedToTrackUser = false;
  68. }
  69. }
  70. }
  71. if (!$allowedToTrackUser) {
  72. api_not_allowed(true);
  73. }
  74. if (api_is_student()) {
  75. api_not_allowed(true);
  76. }
  77. if ($export) {
  78. ob_start();
  79. }
  80. $csv_content = [];
  81. $from_myspace = false;
  82. $this_section = SECTION_COURSES;
  83. if (isset($_GET['from']) && $_GET['from'] === 'myspace') {
  84. $from_myspace = true;
  85. $this_section = SECTION_TRACKING;
  86. }
  87. $nameTools = get_lang('StudentDetails');
  88. $em = Database::getManager();
  89. if (!empty($details)) {
  90. if ($origin === 'user_course') {
  91. if (empty($cidReq)) {
  92. $interbreadcrumb[] = [
  93. 'url' => api_get_path(WEB_COURSE_PATH).$courseInfo['directory'],
  94. 'name' => $courseInfo['title'],
  95. ];
  96. }
  97. $interbreadcrumb[] = [
  98. 'url' => '../user/user.php?cidReq='.$course_code,
  99. 'name' => get_lang('Users'),
  100. ];
  101. } else {
  102. if ($origin === 'tracking_course') {
  103. $interbreadcrumb[] = [
  104. 'url' => '../tracking/courseLog.php?cidReq='.$course_code.'&id_session='.api_get_session_id(),
  105. 'name' => get_lang('Tracking'),
  106. ];
  107. } else {
  108. if ($origin === 'resume_session') {
  109. $interbreadcrumb[] = [
  110. 'url' => "../session/session_list.php",
  111. 'name' => get_lang('SessionList'),
  112. ];
  113. $interbreadcrumb[] = [
  114. 'url' => '../session/resume_session.php?id_session='.$sessionId,
  115. 'name' => get_lang('SessionOverview'),
  116. ];
  117. } else {
  118. $interbreadcrumb[] = [
  119. 'url' => api_is_student_boss() ? '#' : 'index.php',
  120. 'name' => get_lang('MySpace'),
  121. ];
  122. if (!empty($coachId)) {
  123. $interbreadcrumb[] = [
  124. 'url' => 'student.php?id_coach='.$coachId,
  125. 'name' => get_lang('CoachStudents'),
  126. ];
  127. $interbreadcrumb[] = [
  128. 'url' => 'myStudents.php?student='.$student_id.'&id_coach='.$coachId,
  129. 'name' => get_lang('StudentDetails'),
  130. ];
  131. } else {
  132. $interbreadcrumb[] = [
  133. 'url' => 'student.php',
  134. 'name' => get_lang('MyStudents'),
  135. ];
  136. $interbreadcrumb[] = [
  137. 'url' => 'myStudents.php?student='.$student_id,
  138. 'name' => get_lang('StudentDetails'),
  139. ];
  140. }
  141. }
  142. }
  143. }
  144. $nameTools = get_lang('DetailsStudentInCourse');
  145. } else {
  146. if ($origin === 'resume_session') {
  147. $interbreadcrumb[] = [
  148. 'url' => '../session/session_list.php',
  149. 'name' => get_lang('SessionList'),
  150. ];
  151. if (!empty($sessionId)) {
  152. $interbreadcrumb[] = [
  153. 'url' => '../session/resume_session.php?id_session='.$sessionId,
  154. 'name' => get_lang('SessionOverview'),
  155. ];
  156. }
  157. } elseif ($origin === 'teacher_details') {
  158. $this_section = SECTION_TRACKING;
  159. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('MySpace')];
  160. $interbreadcrumb[] = ['url' => 'teachers.php', 'name' => get_lang('Teachers')];
  161. $nameTools = $user_info['complete_name'];
  162. } else {
  163. $interbreadcrumb[] = [
  164. 'url' => api_is_student_boss() ? '#' : 'index.php',
  165. 'name' => get_lang('MySpace'),
  166. ];
  167. if (!empty($coachId)) {
  168. if ($sessionId) {
  169. $interbreadcrumb[] = [
  170. 'url' => 'student.php?id_coach='.$coachId.'&id_session='.$sessionId,
  171. 'name' => get_lang('CoachStudents'),
  172. ];
  173. } else {
  174. $interbreadcrumb[] = [
  175. 'url' => 'student.php?id_coach='.$coachId,
  176. 'name' => get_lang('CoachStudents'),
  177. ];
  178. }
  179. } else {
  180. $interbreadcrumb[] = [
  181. 'url' => 'student.php',
  182. 'name' => get_lang('MyStudents'),
  183. ];
  184. }
  185. }
  186. }
  187. // Database Table Definitions
  188. $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  189. $tbl_stats_exercices = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  190. $user_id = isset($_GET['user_id']) && !empty($_GET['user_id']) ? (int) $_GET['user_id'] : api_get_user_id();
  191. $action = isset($_GET['action']) ? $_GET['action'] : '';
  192. switch ($action) {
  193. case 'export_to_pdf':
  194. $sessionToExport = $sId = isset($_GET['session_to_export']) ? (int) $_GET['session_to_export'] : 0;
  195. $sessionInfo = api_get_session_info($sessionToExport);
  196. if (empty($sessionInfo)) {
  197. api_not_allowed(true);
  198. }
  199. $courses = Tracking::get_courses_list_from_session($sessionToExport);
  200. $timeSpent = 0;
  201. $numberVisits = 0;
  202. $table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  203. $progress = 0;
  204. foreach ($courses as $course) {
  205. $courseId = $course['c_id'];
  206. $timeSpent += Tracking::get_time_spent_on_the_course($student_id, $courseId, $sessionToExport);
  207. $sql = 'SELECT DISTINCT count(course_access_id) as count
  208. FROM '.$table.'
  209. WHERE
  210. user_id = '.$student_id.' AND
  211. c_id = '.$courseId.' AND
  212. session_id = '.$sessionToExport.'
  213. ORDER BY login_course_date ASC';
  214. $result = Database::query($sql);
  215. $row = Database::fetch_array($result);
  216. $numberVisits += $row['count'];
  217. $progress += Tracking::get_avg_student_progress($student_id, $course['code'], [], $sessionToExport);
  218. }
  219. $average = round($progress / count($courses), 1);
  220. $average = empty($average) ? '0%' : $average.'%';
  221. $first = Tracking::get_first_connection_date($student_id);
  222. $last = Tracking::get_last_connection_date($student_id);
  223. $attendance = new Attendance();
  224. $table = new HTML_Table(['class' => 'data_table']);
  225. $column = 0;
  226. $row = 0;
  227. $headers = [
  228. get_lang('TimeSpent'),
  229. get_lang('NumberOfVisits'),
  230. get_lang('GlobalProgress'),
  231. get_lang('FirstLogin'),
  232. get_lang('LastConnexionDate'),
  233. ];
  234. foreach ($headers as $header) {
  235. $table->setHeaderContents($row, $column, $header);
  236. $column++;
  237. }
  238. $table->setCellContents(1, 0, api_time_to_hms($timeSpent));
  239. $table->setCellContents(1, 1, $numberVisits);
  240. $table->setCellContents(1, 2, $average);
  241. $table->setCellContents(1, 3, $first);
  242. $table->setCellContents(1, 4, $last);
  243. $courseTable = '';
  244. if (!empty($courses)) {
  245. $courseTable .= '<table class="data_table">';
  246. $courseTable .= '<thead>';
  247. $courseTable .= '<tr>
  248. <th>'.get_lang('FormationUnit').'</th>
  249. <th>'.get_lang('ConnectionTime').'</th>
  250. <th>'.get_lang('Progress').'</th>
  251. <th>'.get_lang('Score').'</th>
  252. </tr>';
  253. $courseTable .= '</thead>';
  254. $courseTable .= '<tbody>';
  255. $totalCourseTime = 0;
  256. $totalAttendance = [0, 0];
  257. $totalScore = 0;
  258. $totalProgress = 0;
  259. $gradeBookTotal = [0, 0];
  260. $totalEvaluations = '0/0 (0%)';
  261. $totalCourses = count($courses);
  262. $scoreDisplay = ScoreDisplay::instance();
  263. foreach ($courses as $course) {
  264. $courseId = $course['c_id'];
  265. $courseInfoItem = api_get_course_info_by_id($courseId);
  266. $courseId = $courseInfoItem['real_id'];
  267. $courseCodeItem = $courseInfoItem['code'];
  268. $isSubscribed = CourseManager::is_user_subscribed_in_course(
  269. $student_id,
  270. $courseCodeItem,
  271. true,
  272. $sId
  273. );
  274. if ($isSubscribed) {
  275. $timeInSeconds = Tracking::get_time_spent_on_the_course(
  276. $user_info['user_id'],
  277. $courseId,
  278. $sessionToExport
  279. );
  280. $totalCourseTime += $timeInSeconds;
  281. $time_spent_on_course = api_time_to_hms($timeInSeconds);
  282. $progress = Tracking::get_avg_student_progress(
  283. $user_info['user_id'],
  284. $courseCodeItem,
  285. [],
  286. $sId
  287. );
  288. $totalProgress += $progress;
  289. $bestScore = Tracking::get_avg_student_score(
  290. $user_info['user_id'],
  291. $courseCodeItem,
  292. [],
  293. $sId,
  294. false,
  295. false,
  296. true
  297. );
  298. if (is_numeric($bestScore)) {
  299. $totalScore += $bestScore;
  300. }
  301. $progress = empty($progress) ? '0%' : $progress.'%';
  302. $score = empty($bestScore) ? '0%' : $bestScore.'%';
  303. $courseTable .= '<tr>
  304. <td ><a href="'.$courseInfoItem['course_public_url'].'?id_session='.$sId.'">'.
  305. $courseInfoItem['title'].'</a></td>
  306. <td >'.$time_spent_on_course.'</td>
  307. <td >'.$progress.'</td>
  308. <td >'.$score.'</td>';
  309. $courseTable .= '</tr>';
  310. }
  311. }
  312. $totalAttendanceFormatted = $scoreDisplay->display_score($totalAttendance);
  313. $totalScoreFormatted = $scoreDisplay->display_score([$totalScore / $totalCourses, 100], SCORE_AVERAGE);
  314. $totalProgressFormatted = $scoreDisplay->display_score(
  315. [$totalProgress / $totalCourses, 100],
  316. SCORE_AVERAGE
  317. );
  318. $totalEvaluations = $scoreDisplay->display_score($gradeBookTotal);
  319. $totalTimeFormatted = api_time_to_hms($totalCourseTime);
  320. $courseTable .= '
  321. <tr>
  322. <th>'.get_lang('Total').'</th>
  323. <th>'.$totalTimeFormatted.'</th>
  324. <th>'.$totalProgressFormatted.'</th>
  325. <th>'.$totalScoreFormatted.'</th>
  326. </tr>';
  327. $courseTable .= '</tbody></table>';
  328. }
  329. $studentInfo = api_get_user_info($student_id);
  330. $tpl = new Template('', false, false, false, true, false, false);
  331. $tpl->assign('title', get_lang('AttestationOfAttendance'));
  332. $tpl->assign('session_title', $sessionInfo['name']);
  333. $tpl->assign('student', $studentInfo['complete_name']);
  334. $tpl->assign('table_progress', $table->toHtml());
  335. $tpl->assign('subtitle', sprintf(
  336. get_lang('InSessionXYouHadTheFollowingResults'),
  337. $sessionInfo['name']
  338. ));
  339. $tpl->assign('table_course', $courseTable);
  340. $content = $tpl->fetch($tpl->get_template('my_space/pdf_export_student.tpl'));
  341. $params = [
  342. 'pdf_title' => get_lang('Resume'),
  343. 'session_info' => $sessionInfo,
  344. 'course_info' => '',
  345. 'pdf_date' => '',
  346. 'student_info' => $studentInfo,
  347. 'show_grade_generated_date' => true,
  348. 'show_real_course_teachers' => false,
  349. 'show_teacher_as_myself' => false,
  350. 'orientation' => 'P',
  351. ];
  352. $pdf = new PDF('A4', $params['orientation'], $params);
  353. try {
  354. $pdf->setBackground($tpl->theme);
  355. @$pdf->content_to_pdf(
  356. $content,
  357. '',
  358. '',
  359. null,
  360. 'D',
  361. false,
  362. null,
  363. false,
  364. true,
  365. false
  366. );
  367. } catch (MpdfException $e) {
  368. error_log($e);
  369. }
  370. exit;
  371. break;
  372. case 'export_one_session_row':
  373. $sessionToExport = isset($_GET['session_to_export']) ? (int) $_GET['session_to_export'] : 0;
  374. $exportList = Session::read('export_course_list');
  375. if (isset($exportList[$sessionToExport])) {
  376. $dataToExport = $exportList[$sessionToExport];
  377. $title = '';
  378. if (!empty($sessionToExport)) {
  379. $sessionInfo = api_get_session_info($sessionToExport);
  380. $title .= '_'.$sessionInfo['name'];
  381. }
  382. $fileName = 'report'.$title.'_'.$user_info['complete_name'];
  383. switch ($export) {
  384. case 'csv':
  385. Export::arrayToCsv($dataToExport, $fileName);
  386. break;
  387. case 'xls':
  388. Export::arrayToXls($dataToExport, $fileName);
  389. break;
  390. }
  391. } else {
  392. api_not_allowed(true);
  393. }
  394. break;
  395. case 'send_message':
  396. if ($allowMessages === true) {
  397. $subject = isset($_POST['subject']) ? $_POST['subject'] : '';
  398. $message = isset($_POST['message']) ? $_POST['message'] : '';
  399. $currentUserInfo = api_get_user_info();
  400. MessageManager::sendMessageAboutUser(
  401. $user_info,
  402. $currentUserInfo,
  403. $subject,
  404. $message
  405. );
  406. // Send also message to all student bosses
  407. $bossList = UserManager::getStudentBossList($student_id);
  408. if (!empty($bossList)) {
  409. $url = api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$student_id;
  410. $link = Display::url($url, $url);
  411. foreach ($bossList as $boss) {
  412. MessageManager::send_message_simple(
  413. $boss['boss_id'],
  414. sprintf(get_lang('BossAlertMsgSentToUserXTitle'), $user_info['complete_name']),
  415. sprintf(
  416. get_lang('BossAlertUserXSentMessageToUserYWithLinkZ'),
  417. $currentUserInfo['complete_name'],
  418. $user_info['complete_name'],
  419. $link
  420. )
  421. );
  422. }
  423. }
  424. Display::addFlash(Display::return_message(get_lang('MessageSent')));
  425. header('Location: '.$currentUrl);
  426. exit;
  427. }
  428. break;
  429. case 'generate_certificate':
  430. // Delete old certificate
  431. $myCertificate = GradebookUtils::get_certificate_by_user_id(
  432. 0,
  433. $student_id
  434. );
  435. if ($myCertificate) {
  436. $certificate = new Certificate($myCertificate['id'], $student_id);
  437. $certificate->delete(true);
  438. }
  439. // Create new one
  440. $certificate = new Certificate(0, $student_id);
  441. $certificate->generatePdfFromCustomCertificate();
  442. exit;
  443. break;
  444. case 'send_legal':
  445. $isBoss = UserManager::userIsBossOfStudent(api_get_user_id(), $student_id);
  446. // @ofaj
  447. if ($isBoss || api_is_platform_admin()) {
  448. LegalManager::sendLegal($student_id);
  449. /*
  450. $currentUserInfo = api_get_user_info();
  451. $subject = get_lang('SendLegalSubject');
  452. $linkLegal = api_get_path(WEB_PATH)."courses/FORUMDAIDE/index.php";
  453. $content = sprintf(
  454. get_lang('SendTermsDescriptionToUrlX'),
  455. $user_info['complete_name'],
  456. "<a href=\"".$linkLegal."\">".$linkLegal."</a>",
  457. $currentUserInfo['complete_name']
  458. );
  459. MessageManager::send_message_simple($student_id, $subject, $content);
  460. Display::addFlash(Display::return_message(get_lang('Sent')));
  461. */
  462. }
  463. break;
  464. case 'delete_legal':
  465. $isBoss = UserManager::userIsBossOfStudent(api_get_user_id(), $student_id);
  466. if ($isBoss || api_is_platform_admin()) {
  467. $extraFieldValue = new ExtraFieldValue('user');
  468. $value = $extraFieldValue->get_values_by_handler_and_field_variable(
  469. $student_id,
  470. 'legal_accept'
  471. );
  472. $result = $extraFieldValue->delete($value['id']);
  473. if ($result) {
  474. Display::addFlash(Display::return_message(get_lang('Deleted')));
  475. }
  476. }
  477. break;
  478. case 'reset_lp':
  479. $lp_id = isset($_GET['lp_id']) ? (int) $_GET['lp_id'] : '';
  480. $check = true;
  481. if (!empty($lp_id) &&
  482. !empty($student_id) &&
  483. api_is_allowed_to_edit() &&
  484. Security::check_token('get')
  485. ) {
  486. Event::delete_student_lp_events(
  487. $student_id,
  488. $lp_id,
  489. $courseInfo,
  490. $sessionId
  491. );
  492. // @todo delete the stats.track_e_exercises records.
  493. // First implement this http://support.chamilo.org/issues/1334
  494. Display::addFlash(Display::return_message(get_lang('LPWasReset'), 'success'));
  495. Security::clear_token();
  496. }
  497. break;
  498. default:
  499. break;
  500. }
  501. $courses_in_session = [];
  502. // See #4676
  503. $drh_can_access_all_courses = false;
  504. if (api_is_drh() || api_is_platform_admin() || api_is_student_boss()) {
  505. $drh_can_access_all_courses = true;
  506. }
  507. $courses = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());
  508. $courses_in_session_by_coach = [];
  509. $sessions_coached_by_user = Tracking::get_sessions_coached_by_user(api_get_user_id());
  510. // RRHH or session admin
  511. if (api_is_session_admin() || api_is_drh()) {
  512. $courses = CourseManager::get_courses_followed_by_drh(api_get_user_id());
  513. if (!empty($courses)) {
  514. $courses = array_column($courses, 'real_id');
  515. }
  516. $session_by_session_admin = SessionManager::get_sessions_followed_by_drh(api_get_user_id());
  517. if (!empty($session_by_session_admin)) {
  518. foreach ($session_by_session_admin as $session_coached_by_user) {
  519. $courses_followed_by_coach = Tracking::get_courses_list_from_session(
  520. $session_coached_by_user['id']
  521. );
  522. $courses_in_session_by_coach[$session_coached_by_user['id']] = $courses_followed_by_coach;
  523. }
  524. }
  525. }
  526. // Teacher or admin
  527. if (!empty($sessions_coached_by_user)) {
  528. foreach ($sessions_coached_by_user as $session_coached_by_user) {
  529. $sid = (int) $session_coached_by_user['id'];
  530. $courses_followed_by_coach = Tracking::get_courses_followed_by_coach(api_get_user_id(), $sid);
  531. $courses_in_session_by_coach[$sid] = $courses_followed_by_coach;
  532. }
  533. }
  534. $sql = "SELECT c_id
  535. FROM $tbl_course_user
  536. WHERE
  537. relation_type <> ".COURSE_RELATION_TYPE_RRHH." AND
  538. user_id = ".$student_id;
  539. $rs = Database::query($sql);
  540. while ($row = Database::fetch_array($rs)) {
  541. if ($drh_can_access_all_courses) {
  542. $courses_in_session[0][] = $row['c_id'];
  543. } else {
  544. if (isset($courses[$row['c_id']])) {
  545. $courses_in_session[0][] = $row['c_id'];
  546. }
  547. }
  548. }
  549. // Get the list of sessions where the user is subscribed as student
  550. $sql = 'SELECT session_id, c_id
  551. FROM '.Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER).'
  552. WHERE user_id='.$student_id;
  553. $rs = Database::query($sql);
  554. $tmp_sessions = [];
  555. while ($row = Database::fetch_array($rs, 'ASSOC')) {
  556. $tmp_sessions[] = $row['session_id'];
  557. if ($drh_can_access_all_courses) {
  558. if (in_array($row['session_id'], $tmp_sessions)) {
  559. $courses_in_session[$row['session_id']][] = $row['c_id'];
  560. }
  561. } else {
  562. if (isset($courses_in_session_by_coach[$row['session_id']])) {
  563. if (in_array($row['session_id'], $tmp_sessions)) {
  564. $courses_in_session[$row['session_id']][] = $row['c_id'];
  565. }
  566. }
  567. }
  568. }
  569. $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
  570. api_get_user_id(),
  571. $courseInfo
  572. );
  573. if (api_is_drh() && !api_is_platform_admin()) {
  574. if (!empty($student_id)) {
  575. if (api_drh_can_access_all_session_content()) {
  576. } else {
  577. if (!$isDrhOfCourse) {
  578. if (api_is_drh() &&
  579. !UserManager::is_user_followed_by_drh($student_id, api_get_user_id())
  580. ) {
  581. api_not_allowed(true);
  582. }
  583. }
  584. }
  585. }
  586. }
  587. $pluginCalendar = api_get_plugin_setting('learning_calendar', 'enabled') === 'true';
  588. if ($pluginCalendar) {
  589. $plugin = LearningCalendarPlugin::create();
  590. $plugin->setJavaScript($htmlHeadXtra);
  591. }
  592. Display::display_header($nameTools);
  593. $token = Security::get_token();
  594. // Actions bar
  595. echo '<div class="actions">';
  596. echo '<a href="javascript: window.history.go(-1);">'
  597. .Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
  598. echo '<a href="javascript: void(0);" onclick="javascript: window.print();">'
  599. .Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_MEDIUM).'</a>';
  600. echo '<a href="'.api_get_self().'?'.Security::remove_XSS($_SERVER['QUERY_STRING']).'&export=csv">'
  601. .Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), '', ICON_SIZE_MEDIUM).'</a> ';
  602. echo '<a href="'.api_get_self().'?'.Security::remove_XSS($_SERVER['QUERY_STRING']).'&export=xls">'
  603. .Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), '', ICON_SIZE_MEDIUM).'</a> ';
  604. echo Display::url(
  605. Display::return_icon('export.png', get_lang('Export'), '', ICON_SIZE_MEDIUM),
  606. api_get_path(WEB_CODE_PATH).'mySpace/access_details_session.php?user_id='.$student_id
  607. );
  608. if (!empty($user_info['email'])) {
  609. $send_mail = '<a href="mailto:'.$user_info['email'].'">'.
  610. Display::return_icon('mail_send.png', get_lang('SendMail'), '', ICON_SIZE_MEDIUM).'</a>';
  611. } else {
  612. $send_mail = Display::return_icon('mail_send_na.png', get_lang('SendMail'), '', ICON_SIZE_MEDIUM);
  613. }
  614. echo $send_mail;
  615. if (!empty($student_id) && !empty($course_code)) {
  616. // Only show link to connection details if course and student were defined in the URL
  617. echo '<a href="access_details.php?student='.$student_id.'&course='.$course_code.'&origin='.$origin.'&cidReq='
  618. .$course_code.'&id_session='.$sessionId.'">'
  619. .Display::return_icon('statistics.png', get_lang('AccessDetails'), '', ICON_SIZE_MEDIUM)
  620. .'</a>';
  621. }
  622. $notebookTeacherEnable = api_get_plugin_setting('notebookteacher', 'enable_plugin_notebookteacher') === 'true';
  623. if ($notebookTeacherEnable && !empty($student_id) && !empty($course_code)) {
  624. // link notebookteacher
  625. $optionsLink = 'student_id='.$student_id.'&origin='.$origin.'&cidReq='.$course_code.'&id_session='.$sessionId;
  626. echo '<a href="'.api_get_path(WEB_PLUGIN_PATH).'notebookteacher/src/index.php?'.$optionsLink.'">'
  627. .Display::return_icon('notebookteacher.png', get_lang('Notebook'), '', ICON_SIZE_MEDIUM)
  628. .'</a>';
  629. }
  630. if (api_can_login_as($student_id)) {
  631. echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_list.php?action=login_as&user_id='.$student_id
  632. .'&sec_token='.$token.'">'
  633. .Display::return_icon('login_as.png', get_lang('LoginAs'), null, ICON_SIZE_MEDIUM).'</a>&nbsp;&nbsp;';
  634. }
  635. if (Skill::isAllowed($student_id, false)) {
  636. echo Display::url(
  637. Display::return_icon(
  638. 'skill-badges.png',
  639. get_lang('AssignSkill'),
  640. null,
  641. ICON_SIZE_MEDIUM
  642. ),
  643. api_get_path(WEB_CODE_PATH).'badge/assign.php?'.http_build_query(['user' => $student_id])
  644. );
  645. }
  646. $permissions = StudentFollowUpPlugin::getPermissions(
  647. $student_id,
  648. api_get_user_id()
  649. );
  650. $isAllow = $permissions['is_allow'];
  651. if ($isAllow) {
  652. echo Display::url(
  653. Display::return_icon(
  654. 'blog.png',
  655. get_lang('Blog'),
  656. null,
  657. ICON_SIZE_MEDIUM
  658. ),
  659. api_get_path(WEB_PLUGIN_PATH).'studentfollowup/posts.php?student_id='.$student_id
  660. );
  661. }
  662. echo '</div>';
  663. // is the user online ?
  664. $online = get_lang('No');
  665. if (user_is_online($student_id)) {
  666. $online = get_lang('Yes');
  667. }
  668. // get average of score and average of progress by student
  669. $avg_student_progress = $avg_student_score = 0;
  670. if (empty($sessionId)) {
  671. $isSubscribedToCourse = CourseManager::is_user_subscribed_in_course($user_info['user_id'], $course_code);
  672. } else {
  673. $isSubscribedToCourse = CourseManager::is_user_subscribed_in_course(
  674. $user_info['user_id'],
  675. $course_code,
  676. true,
  677. $sessionId
  678. );
  679. }
  680. if ($isSubscribedToCourse) {
  681. $avg_student_progress = Tracking::get_avg_student_progress(
  682. $user_info['user_id'],
  683. $course_code,
  684. [],
  685. $sessionId
  686. );
  687. // the score inside the Reporting table
  688. $avg_student_score = Tracking::get_avg_student_score(
  689. $user_info['user_id'],
  690. $course_code,
  691. [],
  692. $sessionId
  693. );
  694. }
  695. $avg_student_progress = round($avg_student_progress, 2);
  696. $time_spent_on_the_course = 0;
  697. if (!empty($courseInfo)) {
  698. $time_spent_on_the_course = api_time_to_hms(
  699. Tracking::get_time_spent_on_the_course(
  700. $user_info['user_id'],
  701. $courseInfo['real_id'],
  702. $sessionId
  703. )
  704. );
  705. }
  706. // get information about connections on the platform by student
  707. $first_connection_date = Tracking::get_first_connection_date($user_info['user_id']);
  708. if ($first_connection_date == '') {
  709. $first_connection_date = get_lang('NoConnexion');
  710. }
  711. $last_connection_date = Tracking::get_last_connection_date(
  712. $user_info['user_id'],
  713. true
  714. );
  715. if ($last_connection_date == '') {
  716. $last_connection_date = get_lang('NoConnexion');
  717. }
  718. // cvs information
  719. $csv_content[] = [
  720. get_lang('Information'),
  721. ];
  722. $csv_content[] = [
  723. get_lang('Name'),
  724. get_lang('Email'),
  725. get_lang('Tel'),
  726. ];
  727. $csv_content[] = [
  728. $user_info['complete_name'],
  729. $user_info['email'],
  730. $user_info['phone'],
  731. ];
  732. $csv_content[] = [];
  733. // csv tracking
  734. $csv_content[] = [
  735. get_lang('Tracking'),
  736. ];
  737. $csv_content[] = [
  738. get_lang('FirstLoginInPlatform'),
  739. get_lang('LatestLoginInPlatform'),
  740. get_lang('TimeSpentInTheCourse'),
  741. get_lang('Progress'),
  742. get_lang('Score'),
  743. ];
  744. $csv_content[] = [
  745. strip_tags($first_connection_date),
  746. strip_tags($last_connection_date),
  747. $time_spent_on_the_course,
  748. $avg_student_progress.'%',
  749. $avg_student_score,
  750. ];
  751. $coachs_name = '';
  752. $session_name = '';
  753. $table_title = Display::return_icon('user.png', get_lang('User')).$user_info['complete_name'];
  754. echo Display::page_subheader($table_title);
  755. $userPicture = UserManager::getUserPicture($user_info['user_id'], USER_IMAGE_SIZE_BIG);
  756. $userGroupManager = new UserGroup();
  757. $userGroups = $userGroupManager->getNameListByUser(
  758. $user_info['user_id'],
  759. UserGroup::NORMAL_CLASS
  760. );
  761. ?>
  762. <div class="row">
  763. <div class="col-sm-2">
  764. <img src="<?php echo $userPicture; ?>" class="thumbnail img-responsive">
  765. </div>
  766. <div class="col-sm-5">
  767. <table class="table table-striped table-hover">
  768. <thead>
  769. <tr>
  770. <th colspan="2"><?php echo get_lang('Information'); ?></th>
  771. </tr>
  772. </thead>
  773. <tbody>
  774. <tr>
  775. <td><?php echo get_lang('Name'); ?></td>
  776. <td><?php echo $user_info['complete_name_with_message_link']; ?></td>
  777. </tr>
  778. <tr>
  779. <td><?php echo get_lang('Email'); ?></td>
  780. <td>
  781. <?php
  782. echo !empty($user_info['email'])
  783. ? '<a href="mailto:'.$user_info['email'].'">'.$user_info['email'].'</a>'
  784. : get_lang('NoEmail');
  785. ?>
  786. </td>
  787. </tr>
  788. <tr>
  789. <td><?php echo get_lang('Tel'); ?></td>
  790. <td><?php echo !empty($user_info['phone']) ? $user_info['phone'] : get_lang('NoTel'); ?></td>
  791. </tr>
  792. <tr>
  793. <td><?php echo get_lang('OfficialCode'); ?></td>
  794. <td><?php
  795. echo !empty($user_info['official_code'])
  796. ? $user_info['official_code']
  797. : get_lang('NoOfficialCode');
  798. ?></td>
  799. </tr>
  800. <tr>
  801. <td><?php echo get_lang('OnLine'); ?></td>
  802. <td><?php echo $online; ?></td>
  803. </tr>
  804. <?php
  805. if (!empty($course_code)) {
  806. ?>
  807. <tr>
  808. <td colspan="2">
  809. <?php
  810. echo Display::url(
  811. get_lang('SeeAccesses'),
  812. 'access_details.php?'
  813. .http_build_query(
  814. [
  815. 'student' => $student_id,
  816. 'course' => $course_code,
  817. 'origin' => $origin,
  818. 'cidReq' => $course_code,
  819. 'id_session' => $sessionId,
  820. ]
  821. ),
  822. ['class' => 'btn btn-default']
  823. ); ?>
  824. </td>
  825. </tr>
  826. <?php
  827. }
  828. // Ofaj
  829. $bossList = Usermanager::getStudentBossList($student_id);
  830. echo '<tr><td>';
  831. echo get_lang('StudentBoss').' : ';
  832. foreach ($bossList as $boss) {
  833. $bossInfo = api_get_user_info($boss['boss_id']);
  834. if ($bossInfo) {
  835. echo $bossInfo['complete_name_with_username'].'<br />';
  836. }
  837. }
  838. echo '</td></tr>';
  839. echo '<tr><td>';
  840. echo get_lang('Language').' : ';
  841. $languageId = api_get_language_id($user_info['language']);
  842. if ($languageId) {
  843. $languageInfo = api_get_language_info($languageId);
  844. echo $languageInfo['original_name'];
  845. }
  846. echo '</td></tr>';
  847. $startDate = UserManager::get_extra_user_data_by_field(
  848. $user_info['user_id'],
  849. 'datedebutstage'
  850. );
  851. $endDate = UserManager::get_extra_user_data_by_field(
  852. $user_info['user_id'],
  853. 'datefinstage'
  854. );
  855. $extraField = new ExtraField('user');
  856. $extraFieldInfoStart = $extraField->get_handler_field_info_by_field_variable(
  857. 'datedebutstage'
  858. );
  859. $extraFieldInfoEnd = $extraField->get_handler_field_info_by_field_variable(
  860. 'datefinstage'
  861. );
  862. echo '<tr><td>';
  863. echo $extraFieldInfoStart['display_text'].' : ';
  864. if (isset($startDate['datedebutstage'])) {
  865. echo $startDate['datedebutstage'];
  866. }
  867. echo '</td></tr>';
  868. echo '<tr><td>';
  869. echo $extraFieldInfoEnd['display_text'].' : ';
  870. if (isset($endDate['datefinstage'])) {
  871. echo $endDate['datefinstage'];
  872. }
  873. echo '</td></tr>';
  874. /** @var ExtraFieldSavedSearch $saved */
  875. $search = [
  876. 'user' => $student_id,
  877. ];
  878. $items = $em->getRepository('ChamiloCoreBundle:ExtraFieldSavedSearch')->findBy($search);
  879. $listVariables = [
  880. 'ecouter',
  881. 'lire',
  882. 'ecrire',
  883. 's_exprimer_oralement_en_continu',
  884. 'participer_a_une_conversation',
  885. ];
  886. $extraField = new ExtraField('session');
  887. if ($items) {
  888. /** @var ExtraFieldSavedSearch $item */
  889. foreach ($items as $item) {
  890. $variable = $item->getField()->getVariable();
  891. if (in_array($variable, $listVariables)) {
  892. $extraFieldInfo = $extraField->get_handler_field_info_by_field_variable($variable);
  893. if ($extraFieldInfo) {
  894. echo '<tr><td>';
  895. $options = $extraFieldInfo['options'];
  896. $optionValues = array_column($options, 'display_text', 'option_value');
  897. //var_dump($optionValues);
  898. echo $extraFieldInfo['display_text'].' : ';
  899. $answers = $item->getValue();
  900. $list = [];
  901. if (is_array($answers)) {
  902. foreach ($answers as $answer) {
  903. $list[] = $optionValues[$answer];
  904. }
  905. } else {
  906. foreach ($options as $option) {
  907. $answers = trim($answers, '.');
  908. $answers = str_replace('-', '_', $answers);
  909. if ($option['option_value'] != api_underscore_to_camel_case($answers)) {
  910. continue;
  911. }
  912. $list[] = $option['display_text'];
  913. }
  914. }
  915. echo '<ul><li>';
  916. echo implode('</li><li>', $list);
  917. echo '</li></ul>';
  918. echo '</td></tr>';
  919. }
  920. }
  921. }
  922. }
  923. // Display timezone if the user selected one and if the admin allows the use of user's timezone
  924. $timezone = null;
  925. $timezone_user = UserManager::get_extra_user_data_by_field(
  926. $user_info['user_id'],
  927. 'timezone'
  928. );
  929. $use_users_timezone = api_get_setting('use_users_timezone', 'timezones');
  930. if ($timezone_user['timezone'] != null &&
  931. $use_users_timezone == 'true'
  932. ) {
  933. $timezone = $timezone_user['timezone'];
  934. }
  935. if ($timezone !== null) {
  936. ?>
  937. <tr>
  938. <td> <?php echo get_lang('Timezone').' : '.$timezone; ?> </td>
  939. </tr>
  940. <?php
  941. }
  942. ?>
  943. </tbody>
  944. </table>
  945. </div>
  946. <div class="col-sm-5">
  947. <table class="table table-striped table-hover">
  948. <thead>
  949. <tr>
  950. <th colspan="2" class="text-center"><?php echo get_lang('Tracking'); ?></th>
  951. </tr>
  952. </thead>
  953. <tbody>
  954. <tr>
  955. <td align="right"><?php echo get_lang('FirstLoginInPlatform'); ?></td>
  956. <td align="left"><?php echo $first_connection_date; ?></td>
  957. </tr>
  958. <tr>
  959. <td align="right"><?php echo get_lang('LatestLoginInPlatform'); ?></td>
  960. <td align="left"><?php echo $last_connection_date; ?></td>
  961. </tr>
  962. <?php
  963. if ($details == 'true') {
  964. ?>
  965. <tr>
  966. <td align="right"><?php echo get_lang('TimeSpentInTheCourse'); ?></td>
  967. <td align="left"><?php echo $time_spent_on_the_course; ?></td>
  968. </tr>
  969. <tr>
  970. <td align="right">
  971. <?php
  972. echo get_lang('Progress').' ';
  973. Display::display_icon(
  974. 'info3.gif',
  975. get_lang('ScormAndLPProgressTotalAverage'),
  976. ['align' => 'absmiddle', 'hspace' => '3px']
  977. ); ?>
  978. </td>
  979. <td align="left"><?php echo $avg_student_progress.'%'; ?></td>
  980. </tr>
  981. <tr>
  982. <td align="right">
  983. <?php
  984. echo get_lang('Score').' ';
  985. Display::display_icon(
  986. 'info3.gif',
  987. get_lang('ScormAndLPTestTotalAverage'),
  988. ['align' => 'absmiddle', 'hspace' => '3px']
  989. ); ?>
  990. </td>
  991. <td align="left">
  992. <?php
  993. if (is_numeric($avg_student_score)) {
  994. echo $avg_student_score.'%';
  995. } else {
  996. echo $avg_student_score;
  997. } ?>
  998. </td>
  999. </tr>
  1000. <?php
  1001. }
  1002. if (api_get_setting('allow_terms_conditions') === 'true') {
  1003. $isBoss = UserManager::userIsBossOfStudent(api_get_user_id(), $student_id);
  1004. if ($isBoss || api_is_platform_admin()) {
  1005. $extraFieldValue = new ExtraFieldValue('user');
  1006. $value = $extraFieldValue->get_values_by_handler_and_field_variable(
  1007. $student_id,
  1008. 'legal_accept'
  1009. );
  1010. $icon = Display::return_icon('accept_na.png');
  1011. if (isset($value['value']) && !empty($value['value'])) {
  1012. list($legalId, $legalLanguageId, $legalTime) = explode(':', $value['value']);
  1013. $icon = Display::return_icon('accept.png').' '.api_get_local_time($legalTime);
  1014. $icon .= ' '.Display::url(
  1015. get_lang('DeleteLegal'),
  1016. api_get_self().'?action=delete_legal&student='.$student_id.'&course='.$course_code,
  1017. ['class' => 'btn btn-danger btn-xs']
  1018. );
  1019. } else {
  1020. $icon .= ' '.Display::url(
  1021. get_lang('SendLegal'),
  1022. api_get_self().'?action=send_legal&student='.$student_id.'&course='.$course_code,
  1023. ['class' => 'btn btn-primary btn-xs']
  1024. );
  1025. }
  1026. echo '<tr>
  1027. <td align="right">';
  1028. echo get_lang('LegalAccepted').' </td> <td align="left">'.$icon;
  1029. echo '</td></tr>';
  1030. }
  1031. }
  1032. $icon = ' '.Display::url(
  1033. get_lang('Generate'),
  1034. api_get_self().'?action=generate_certificate&student='.$student_id.'&cidReq='.$course_code.'&course='.$course_code,
  1035. ['class' => 'btn btn-primary btn-xs']
  1036. );
  1037. echo '<tr>
  1038. <td align="right">';
  1039. echo get_lang('Certificate').' </td> <td align="left">'.$icon;
  1040. echo '</td></tr>';
  1041. ?>
  1042. </tbody>
  1043. </table>
  1044. <?php if (!empty($userGroups)) {
  1045. ?>
  1046. <table class="table table-striped table-hover">
  1047. <thead>
  1048. <tr>
  1049. <th><?php echo get_lang('Classes'); ?></th>
  1050. </tr>
  1051. </thead>
  1052. <tbody>
  1053. <?php foreach ($userGroups as $class) {
  1054. ?>
  1055. <tr>
  1056. <td><?php echo $class; ?></td>
  1057. </tr>
  1058. <?php
  1059. } ?>
  1060. </tbody>
  1061. </table>
  1062. <?php
  1063. } ?>
  1064. </div>
  1065. </div>
  1066. <?php
  1067. $exportCourseList = [];
  1068. $lpIdList = [];
  1069. if (empty($details)) {
  1070. $csv_content[] = [];
  1071. $csv_content[] = [
  1072. get_lang('Session'),
  1073. get_lang('Course'),
  1074. get_lang('Time'),
  1075. get_lang('Progress'),
  1076. get_lang('Score'),
  1077. get_lang('AttendancesFaults'),
  1078. get_lang('Evaluations'),
  1079. ];
  1080. $attendance = new Attendance();
  1081. foreach ($courses_in_session as $sId => $courses) {
  1082. $session_name = '';
  1083. $access_start_date = '';
  1084. $access_end_date = '';
  1085. $date_session = '';
  1086. $title = Display::return_icon('course.png', get_lang('Courses')).' '.get_lang('Courses');
  1087. $session_info = api_get_session_info($sId);
  1088. if ($session_info) {
  1089. $session_name = $session_info['name'];
  1090. if (!empty($session_info['access_start_date'])) {
  1091. $access_start_date = api_format_date($session_info['access_start_date'], DATE_FORMAT_SHORT);
  1092. }
  1093. if (!empty($session_info['access_end_date'])) {
  1094. $access_end_date = api_format_date($session_info['access_end_date'], DATE_FORMAT_SHORT);
  1095. }
  1096. if (!empty($access_start_date) && !empty($access_end_date)) {
  1097. $date_session = get_lang('From').' '.$access_start_date.' '.get_lang('Until').' '.$access_end_date;
  1098. }
  1099. $title = Display::return_icon('session.png', get_lang('Session'))
  1100. .' '.$session_name.($date_session ? ' ('.$date_session.')' : '');
  1101. }
  1102. // Courses
  1103. echo '<h3>'.$title.'</h3>';
  1104. echo '<div class="table-responsive">';
  1105. echo '<table class="table table-striped table-hover courses-tracking">';
  1106. echo '<thead>';
  1107. echo '<tr>
  1108. <th>'.get_lang('Course').'</th>
  1109. <th>'.get_lang('Time').'</th>
  1110. <th>'.get_lang('Progress').'</th>
  1111. <th>'.get_lang('Score').'</th>
  1112. <th>'.get_lang('AttendancesFaults').'</th>
  1113. <th>'.get_lang('Evaluations').'</th>
  1114. <th>'.get_lang('Details').'</th>
  1115. </tr>';
  1116. echo '</thead>';
  1117. echo '<tbody>';
  1118. $csvRow = [
  1119. '',
  1120. get_lang('Course'),
  1121. get_lang('Time'),
  1122. get_lang('Progress'),
  1123. get_lang('Score'),
  1124. get_lang('AttendancesFaults'),
  1125. get_lang('Evaluations'),
  1126. get_lang('Details'),
  1127. ];
  1128. $exportCourseList[$sId][] = $csvRow;
  1129. if (!empty($courses)) {
  1130. $totalCourseTime = 0;
  1131. $totalAttendance = [0, 0];
  1132. $totalScore = 0;
  1133. $totalProgress = 0;
  1134. $gradeBookTotal = [0, 0];
  1135. $totalEvaluations = '0/0 (0%)';
  1136. $totalCourses = count($courses);
  1137. $scoreDisplay = ScoreDisplay::instance();
  1138. foreach ($courses as $courseId) {
  1139. $courseInfoItem = api_get_course_info_by_id($courseId);
  1140. $courseId = $courseInfoItem['real_id'];
  1141. $courseCodeItem = $courseInfoItem['code'];
  1142. if (empty($session_info)) {
  1143. $isSubscribed = CourseManager::is_user_subscribed_in_course(
  1144. $student_id,
  1145. $courseCodeItem,
  1146. false
  1147. );
  1148. } else {
  1149. $isSubscribed = CourseManager::is_user_subscribed_in_course(
  1150. $student_id,
  1151. $courseCodeItem,
  1152. true,
  1153. $sId
  1154. );
  1155. }
  1156. if ($isSubscribed) {
  1157. $timeInSeconds = Tracking::get_time_spent_on_the_course(
  1158. $user_info['user_id'],
  1159. $courseId,
  1160. $sId
  1161. );
  1162. $totalCourseTime += $timeInSeconds;
  1163. $time_spent_on_course = api_time_to_hms($timeInSeconds);
  1164. // get average of faults in attendances by student
  1165. $results_faults_avg = $attendance->get_faults_average_by_course(
  1166. $student_id,
  1167. $courseCodeItem,
  1168. $sId
  1169. );
  1170. $attendances_faults_avg = '0/0 (0%)';
  1171. if (!empty($results_faults_avg['total'])) {
  1172. if (api_is_drh()) {
  1173. $attendances_faults_avg = '<a title="'.get_lang('GoAttendance').'" href="'.api_get_path(WEB_CODE_PATH)
  1174. .'attendance/index.php?cidReq='.$courseCodeItem.'&id_session='.$sId.'&student_id='
  1175. .$student_id.'">'
  1176. .$results_faults_avg['faults'].'/'.$results_faults_avg['total'].' ('
  1177. .$results_faults_avg['porcent'].'%)</a>';
  1178. } else {
  1179. $attendances_faults_avg = $results_faults_avg['faults'].'/'
  1180. .$results_faults_avg['total']
  1181. .' ('.$results_faults_avg['porcent'].'%)';
  1182. }
  1183. $totalAttendance[0] += $results_faults_avg['faults'];
  1184. $totalAttendance[1] += $results_faults_avg['total'];
  1185. }
  1186. // Get evaluations by student
  1187. $cats = Category::load(
  1188. null,
  1189. null,
  1190. $courseCodeItem,
  1191. null,
  1192. null,
  1193. $sId
  1194. );
  1195. $scoretotal = [];
  1196. if (isset($cats) && isset($cats[0])) {
  1197. if (!empty($sId)) {
  1198. $scoretotal = $cats[0]->calc_score($student_id, null, $courseCodeItem, $sId);
  1199. } else {
  1200. $scoretotal = $cats[0]->calc_score($student_id, null, $courseCodeItem);
  1201. }
  1202. }
  1203. $scoretotal_display = '0/0 (0%)';
  1204. if (!empty($scoretotal) && !empty($scoretotal[1])) {
  1205. $scoretotal_display =
  1206. round($scoretotal[0], 1).'/'.
  1207. round($scoretotal[1], 1).
  1208. ' ('.round(($scoretotal[0] / $scoretotal[1]) * 100, 2).' %)';
  1209. $gradeBookTotal[0] += $scoretotal[0];
  1210. $gradeBookTotal[1] += $scoretotal[1];
  1211. }
  1212. $progress = Tracking::get_avg_student_progress(
  1213. $user_info['user_id'],
  1214. $courseCodeItem,
  1215. [],
  1216. $sId
  1217. );
  1218. $totalProgress += $progress;
  1219. $score = Tracking::get_avg_student_score(
  1220. $user_info['user_id'],
  1221. $courseCodeItem,
  1222. [],
  1223. $sId
  1224. );
  1225. if (is_numeric($score)) {
  1226. $totalScore += $score;
  1227. }
  1228. $progress = empty($progress) ? '0%' : $progress.'%';
  1229. $score = empty($score) ? '0%' : $score.'%';
  1230. $csvRow = [
  1231. $session_name,
  1232. $courseInfoItem['title'],
  1233. $time_spent_on_course,
  1234. $progress,
  1235. $score,
  1236. $attendances_faults_avg,
  1237. $scoretotal_display,
  1238. ];
  1239. $csv_content[] = $csvRow;
  1240. $exportCourseList[$sId][] = $csvRow;
  1241. echo '<tr>
  1242. <td ><a href="'.$courseInfoItem['course_public_url'].'?id_session='.$sId.'">'.
  1243. $courseInfoItem['title'].'</a></td>
  1244. <td >'.$time_spent_on_course.'</td>
  1245. <td >'.$progress.'</td>
  1246. <td >'.$score.'</td>
  1247. <td >'.$attendances_faults_avg.'</td>
  1248. <td >'.$scoretotal_display.'</td>';
  1249. if (!empty($coachId)) {
  1250. echo '<td width="10"><a href="'.api_get_self().'?student='.$user_info['user_id']
  1251. .'&details=true&course='.$courseInfoItem['code'].'&id_coach='.$coachId.'&origin='.$origin
  1252. .'&id_session='.$sId.'#infosStudent">'
  1253. .Display::return_icon('2rightarrow.png', get_lang('Details')).'</a></td>';
  1254. } else {
  1255. echo '<td width="10"><a href="'.api_get_self().'?student='.$user_info['user_id']
  1256. .'&details=true&course='.$courseInfoItem['code'].'&origin='.$origin.'&id_session='.$sId.'#infosStudent">'
  1257. .Display::return_icon('2rightarrow.png', get_lang('Details')).'</a></td>';
  1258. }
  1259. echo '</tr>';
  1260. }
  1261. }
  1262. $totalAttendanceFormatted = $scoreDisplay->display_score($totalAttendance);
  1263. $totalScoreFormatted = $scoreDisplay->display_score([$totalScore / $totalCourses, 100], SCORE_AVERAGE);
  1264. $totalProgressFormatted = $scoreDisplay->display_score(
  1265. [$totalProgress / $totalCourses, 100],
  1266. SCORE_AVERAGE
  1267. );
  1268. $totalEvaluations = $scoreDisplay->display_score($gradeBookTotal);
  1269. $totalTimeFormatted = api_time_to_hms($totalCourseTime);
  1270. echo '<tr>
  1271. <th>'.get_lang('Total').'</th>
  1272. <th>'.$totalTimeFormatted.'</th>
  1273. <th>'.$totalProgressFormatted.'</th>
  1274. <th>'.$totalScoreFormatted.'</th>
  1275. <th>'.$totalAttendanceFormatted.'</th>
  1276. <th>'.$totalEvaluations.'</th>
  1277. <th></th>
  1278. </tr>';
  1279. $csvRow = [
  1280. get_lang('Total'),
  1281. '',
  1282. $totalTimeFormatted,
  1283. $totalProgressFormatted,
  1284. $totalScoreFormatted,
  1285. $totalAttendanceFormatted,
  1286. $totalEvaluations,
  1287. '',
  1288. ];
  1289. $csv_content[] = $csvRow;
  1290. $exportCourseList[$sId][] = $csvRow;
  1291. $sessionAction = Display::url(
  1292. Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), [], ICON_SIZE_MEDIUM),
  1293. $currentUrl
  1294. .'&'
  1295. .http_build_query(
  1296. ['action' => 'export_one_session_row', 'export' => 'csv', 'session_to_export' => $sId]
  1297. )
  1298. );
  1299. $sessionAction .= Display::url(
  1300. Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), [], ICON_SIZE_MEDIUM),
  1301. $currentUrl
  1302. .'&'
  1303. .http_build_query(
  1304. ['action' => 'export_one_session_row', 'export' => 'xls', 'session_to_export' => $sId]
  1305. )
  1306. );
  1307. if (!empty($sId)) {
  1308. $sessionAction .= Display::url(
  1309. Display::return_icon('pdf.png', get_lang('ExportToPDF'), [], ICON_SIZE_MEDIUM),
  1310. $currentUrl
  1311. .'&'
  1312. .http_build_query(
  1313. ['action' => 'export_to_pdf', 'session_to_export' => $sId]
  1314. )
  1315. );
  1316. }
  1317. echo $sessionAction;
  1318. } else {
  1319. echo "<tr><td colspan='5'>".get_lang('NoCourse')."</td></tr>";
  1320. }
  1321. Session::write('export_course_list', $exportCourseList);
  1322. echo '</tbody>';
  1323. echo '</table>';
  1324. echo '</div>';
  1325. }
  1326. } else {
  1327. $trackingColumns = api_get_configuration_value('tracking_columns');
  1328. $columnHeaders = [
  1329. 'lp' => get_lang('LearningPath'),
  1330. 'time' => get_lang('Time').
  1331. Display::return_icon(
  1332. 'info3.gif',
  1333. get_lang('TotalTimeByCourse'),
  1334. ['align' => 'absmiddle', 'hspace' => '3px']
  1335. ),
  1336. 'best_score' => get_lang('BestScore'),
  1337. 'latest_attempt_avg_score' => get_lang('LatestAttemptAverageScore').
  1338. Display::return_icon(
  1339. 'info3.gif',
  1340. get_lang('AverageIsCalculatedBasedInTheLatestAttempts'),
  1341. ['align' => 'absmiddle', 'hspace' => '3px']
  1342. ),
  1343. 'progress' => get_lang('Progress').
  1344. Display::return_icon(
  1345. 'info3.gif',
  1346. get_lang('LPProgressScore'),
  1347. ['align' => 'absmiddle', 'hspace' => '3px']
  1348. ),
  1349. 'last_connection' => get_lang('LastConnexion').
  1350. Display::return_icon(
  1351. 'info3.gif',
  1352. get_lang('LastTimeTheCourseWasUsed'),
  1353. ['align' => 'absmiddle', 'hspace' => '3px']
  1354. ),
  1355. ];
  1356. $timeCourse = null;
  1357. if (Tracking::minimumTimeAvailable($sessionId, $courseInfo['real_id'])) {
  1358. $timeCourse = Tracking::getCalculateTime($student_id, $courseInfo['real_id'], $sessionId);
  1359. }
  1360. if ($user_info['status'] != INVITEE) {
  1361. $csv_content[] = [];
  1362. $csv_content[] = [str_replace('&nbsp;', '', strip_tags($userInfo['complete_name']))];
  1363. $trackingColumns = api_get_configuration_value('tracking_columns');
  1364. if (isset($trackingColumns['my_students_lp'])) {
  1365. foreach ($columnHeaders as $key => $value) {
  1366. if (!isset($trackingColumns['my_progress_lp'][$key]) ||
  1367. $trackingColumns['my_students_lp'][$key] == false
  1368. ) {
  1369. unset($columnHeaders[$key]);
  1370. }
  1371. }
  1372. }
  1373. $headers = '';
  1374. $columnHeadersToExport = [];
  1375. // csv export headers
  1376. foreach ($columnHeaders as $key => $columnName) {
  1377. $columnHeadersToExport[] = strip_tags($columnName);
  1378. $headers .= Display::tag(
  1379. 'th',
  1380. $columnName
  1381. );
  1382. }
  1383. $csv_content[] = $columnHeadersToExport;
  1384. $columnHeadersKeys = array_keys($columnHeaders);
  1385. $categoriesTempList = learnpath::getCategories($courseInfo['real_id']);
  1386. $categoryTest = new CLpCategory();
  1387. $categoryTest->setId(0);
  1388. $categoryTest->setName(get_lang('WithOutCategory'));
  1389. $categoryTest->setPosition(0);
  1390. $categories = [
  1391. $categoryTest,
  1392. ];
  1393. if (!empty($categoriesTempList)) {
  1394. $categories = array_merge($categories, $categoriesTempList);
  1395. }
  1396. $userEntity = api_get_user_entity(api_get_user_id());
  1397. /** @var CLpCategory $item */
  1398. foreach ($categories as $item) {
  1399. $categoryId = $item->getId();
  1400. if (!learnpath::categoryIsVisibleForStudent($item, $userEntity, $courseInfo['real_id'], $sessionId)) {
  1401. continue;
  1402. }
  1403. $list = new LearnpathList(
  1404. api_get_user_id(),
  1405. $courseInfo,
  1406. $sessionId,
  1407. null,
  1408. false,
  1409. $categoryId,
  1410. false,
  1411. true
  1412. );
  1413. $flat_list = $list->get_flat_list();
  1414. $i = 0;
  1415. if (count($categories) > 1) {
  1416. echo Display::page_subheader2($item->getName());
  1417. }
  1418. echo '<div class="table-responsive">';
  1419. echo '<table class="table table-striped table-hover"><thead><tr>';
  1420. echo $headers;
  1421. echo '<th>'.get_lang('Details').'</th>';
  1422. if (api_is_allowed_to_edit()) {
  1423. echo '<th>'.get_lang('ResetLP').'</th>';
  1424. }
  1425. echo '</tr></thead><tbody>';
  1426. foreach ($flat_list as $learnpath) {
  1427. $lpIdList[] = $learnpath['iid'];
  1428. $lp_id = $learnpath['lp_old_id'];
  1429. $lp_name = $learnpath['lp_name'];
  1430. $any_result = false;
  1431. // Get progress in lp
  1432. $progress = Tracking::get_avg_student_progress(
  1433. $student_id,
  1434. $course_code,
  1435. [$lp_id],
  1436. $sessionId
  1437. );
  1438. if ($progress === null) {
  1439. $progress = '0%';
  1440. } else {
  1441. $any_result = true;
  1442. }
  1443. // Get time in lp
  1444. if (!empty($timeCourse)) {
  1445. $lpTime = isset($timeCourse[TOOL_LEARNPATH]) ? $timeCourse[TOOL_LEARNPATH] : 0;
  1446. $total_time = isset($lpTime[$lp_id]) ? (int) $lpTime[$lp_id] : 0;
  1447. } else {
  1448. $total_time = Tracking::get_time_spent_in_lp(
  1449. $student_id,
  1450. $course_code,
  1451. [$lp_id],
  1452. $sessionId
  1453. );
  1454. }
  1455. if (!empty($total_time)) {
  1456. $any_result = true;
  1457. }
  1458. // Get last connection time in lp
  1459. $start_time = Tracking::get_last_connection_time_in_lp(
  1460. $student_id,
  1461. $course_code,
  1462. $lp_id,
  1463. $sessionId
  1464. );
  1465. if (!empty($start_time)) {
  1466. $start_time = api_convert_and_format_date($start_time, DATE_TIME_FORMAT_LONG);
  1467. } else {
  1468. $start_time = '-';
  1469. }
  1470. if (!empty($total_time)) {
  1471. $any_result = true;
  1472. }
  1473. // Quiz in lp
  1474. $score = Tracking::get_avg_student_score(
  1475. $student_id,
  1476. $course_code,
  1477. [$lp_id],
  1478. $sessionId
  1479. );
  1480. // Latest exercise results in a LP
  1481. $score_latest = Tracking::get_avg_student_score(
  1482. $student_id,
  1483. $course_code,
  1484. [$lp_id],
  1485. $sessionId,
  1486. false,
  1487. true
  1488. );
  1489. $bestScore = Tracking::get_avg_student_score(
  1490. $student_id,
  1491. $course_code,
  1492. [$lp_id],
  1493. $sessionId,
  1494. false,
  1495. false,
  1496. true
  1497. );
  1498. if (empty($bestScore)) {
  1499. $bestScore = '';
  1500. } else {
  1501. $bestScore = $bestScore.'%';
  1502. }
  1503. if ($i % 2 == 0) {
  1504. $css_class = 'row_even';
  1505. } else {
  1506. $css_class = 'row_odd';
  1507. }
  1508. $i++;
  1509. if (isset($score_latest) && !is_null($score_latest)) {
  1510. if (is_numeric($score_latest)) {
  1511. $score_latest = $score_latest.'%';
  1512. }
  1513. }
  1514. if (is_numeric($progress)) {
  1515. $progress = $progress.'%';
  1516. } else {
  1517. $progress = '-';
  1518. }
  1519. echo '<tr class="'.$css_class.'">';
  1520. $contentToExport = [];
  1521. if (in_array('lp', $columnHeadersKeys)) {
  1522. $contentToExport[] = api_html_entity_decode(
  1523. stripslashes($lp_name),
  1524. ENT_QUOTES,
  1525. $charset
  1526. );
  1527. echo Display::tag('td', stripslashes($lp_name));
  1528. }
  1529. if (in_array('time', $columnHeadersKeys)) {
  1530. $contentToExport[] = api_time_to_hms($total_time);
  1531. echo Display::tag('td', api_time_to_hms($total_time));
  1532. }
  1533. if (in_array('best_score', $columnHeadersKeys)) {
  1534. $contentToExport[] = $bestScore;
  1535. echo Display::tag('td', $bestScore);
  1536. }
  1537. if (in_array('latest_attempt_avg_score', $columnHeadersKeys)) {
  1538. $contentToExport[] = $score_latest;
  1539. echo Display::tag('td', $score_latest);
  1540. }
  1541. if (in_array('progress', $columnHeadersKeys)) {
  1542. $contentToExport[] = $progress;
  1543. echo Display::tag('td', $progress);
  1544. }
  1545. if (in_array('last_connection', $columnHeadersKeys)) {
  1546. // Do not change with api_convert_and_format_date, because this value came from the lp_item_view table
  1547. // which implies several other changes not a priority right now
  1548. $contentToExport[] = $start_time;
  1549. echo Display::tag('td', $start_time);
  1550. }
  1551. $csv_content[] = $contentToExport;
  1552. if ($any_result === true) {
  1553. $from = '';
  1554. if ($from_myspace) {
  1555. $from = '&from=myspace';
  1556. }
  1557. $link = Display::url(
  1558. Display::return_icon('2rightarrow.png', get_lang('Details')),
  1559. 'lp_tracking.php?cidReq='.$course_code.'&course='.$course_code.$from.'&origin='.$origin
  1560. .'&lp_id='.$lp_id.'&student_id='.$user_info['user_id'].'&id_session='.$sessionId
  1561. );
  1562. echo Display::tag('td', $link);
  1563. }
  1564. if (api_is_allowed_to_edit()) {
  1565. echo '<td>';
  1566. if ($any_result === true) {
  1567. $url = 'myStudents.php?action=reset_lp&sec_token='.$token.'&cidReq='.$course_code.'&course='
  1568. .$course_code.'&details='.$details.'&origin='.$origin.'&lp_id='.$lp_id.'&student='
  1569. .$user_info['user_id'].'&details=true&id_session='.$sessionId;
  1570. echo Display::url(
  1571. Display::return_icon('clean.png', get_lang('Clean')),
  1572. $url,
  1573. [
  1574. 'onclick' => "javascript:if(!confirm('"
  1575. .addslashes(
  1576. api_htmlentities(get_lang('AreYouSureToDelete'))
  1577. )
  1578. ."')) return false;",
  1579. ]
  1580. );
  1581. }
  1582. echo '</td>';
  1583. echo '</tr>';
  1584. }
  1585. }
  1586. echo '</tbody></table></div>';
  1587. }
  1588. }
  1589. if ($user_info['status'] != INVITEE) {
  1590. echo '<div class="table-responsive">
  1591. <table class="table table-striped table-hover">
  1592. <thead>
  1593. <tr>';
  1594. echo '<th>'.get_lang('Exercises').'</th>';
  1595. echo '<th>'.get_lang('LearningPath').'</th>';
  1596. echo '<th>'.get_lang('AvgCourseScore').' '.
  1597. Display::return_icon(
  1598. 'info3.gif',
  1599. get_lang('AverageScore'),
  1600. ['align' => 'absmiddle', 'hspace' => '3px']
  1601. ).'</th>';
  1602. echo '<th>'.get_lang('Attempts').'</th>';
  1603. echo '<th>'.get_lang('LatestAttempt').'</th>';
  1604. echo '<th>'.get_lang('AllAttempts').'</th>';
  1605. echo '</tr></thead><tbody>';
  1606. $csv_content[] = [];
  1607. $csv_content[] = [
  1608. get_lang('Exercises'),
  1609. get_lang('LearningPath'),
  1610. get_lang('AvgCourseScore'),
  1611. get_lang('Attempts'),
  1612. ];
  1613. $t_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  1614. $sessionCondition = api_get_session_condition(
  1615. $sessionId,
  1616. true,
  1617. true,
  1618. 'quiz.session_id'
  1619. );
  1620. $sql = "SELECT quiz.title, id
  1621. FROM $t_quiz AS quiz
  1622. WHERE
  1623. quiz.c_id = ".$courseInfo['real_id']." AND
  1624. active IN (0, 1)
  1625. $sessionCondition
  1626. ORDER BY quiz.title ASC ";
  1627. $result_exercices = Database::query($sql);
  1628. $i = 0;
  1629. if (Database::num_rows($result_exercices) > 0) {
  1630. while ($exercices = Database::fetch_array($result_exercices)) {
  1631. $exercise_id = (int) $exercices['id'];
  1632. $count_attempts = Tracking::count_student_exercise_attempts(
  1633. $student_id,
  1634. $courseInfo['real_id'],
  1635. $exercise_id,
  1636. 0,
  1637. 0,
  1638. $sessionId,
  1639. 2
  1640. );
  1641. $score_percentage = Tracking::get_avg_student_exercise_score(
  1642. $student_id,
  1643. $course_code,
  1644. $exercise_id,
  1645. $sessionId,
  1646. 1,
  1647. 0
  1648. );
  1649. if (!isset($score_percentage) && $count_attempts > 0) {
  1650. $scores_lp = Tracking::get_avg_student_exercise_score(
  1651. $student_id,
  1652. $course_code,
  1653. $exercise_id,
  1654. $sessionId,
  1655. 2,
  1656. 1
  1657. );
  1658. $score_percentage = $scores_lp[0];
  1659. $lp_name = $scores_lp[1];
  1660. } else {
  1661. $lp_name = '-';
  1662. }
  1663. $lp_name = !empty($lp_name) ? $lp_name : get_lang('NoLearnpath');
  1664. $css_class = 'row_even';
  1665. if ($i % 2) {
  1666. $css_class = 'row_odd';
  1667. }
  1668. echo '<tr class="'.$css_class.'"><td>'.$exercices['title'].'</td>';
  1669. echo '<td>';
  1670. if (!empty($lp_name)) {
  1671. echo $lp_name;
  1672. } else {
  1673. echo '-';
  1674. }
  1675. echo '</td>';
  1676. echo '<td>';
  1677. if ($count_attempts > 0) {
  1678. echo $score_percentage.'%';
  1679. } else {
  1680. echo '-';
  1681. $score_percentage = 0;
  1682. }
  1683. echo '</td>';
  1684. echo '<td>'.$count_attempts.'</td>';
  1685. echo '<td>';
  1686. $sql = 'SELECT exe_id FROM '.$tbl_stats_exercices.'
  1687. WHERE
  1688. exe_exo_id = "'.$exercise_id.'" AND
  1689. exe_user_id ="'.$student_id.'" AND
  1690. c_id = '.$courseInfo['real_id'].' AND
  1691. session_id = "'.$sessionId.'" AND
  1692. status = ""
  1693. ORDER BY exe_date DESC
  1694. LIMIT 1';
  1695. $result_last_attempt = Database::query($sql);
  1696. if (Database::num_rows($result_last_attempt) > 0) {
  1697. $id_last_attempt = Database::result($result_last_attempt, 0, 0);
  1698. if ($count_attempts > 0) {
  1699. $qualifyLink = '';
  1700. if ($allowToQualify) {
  1701. $qualifyLink = '&action=qualify';
  1702. }
  1703. $attemptLink = '../exercise/exercise_show.php?id='.$id_last_attempt.'&cidReq='.$course_code
  1704. .'&id_session='.$sessionId.'&session_id='.$sessionId.'&student='.$student_id.'&origin='
  1705. .(empty($origin) ? 'tracking' : $origin).$qualifyLink;
  1706. echo Display::url(
  1707. Display::return_icon('quiz.png', get_lang('Exercise')),
  1708. $attemptLink
  1709. );
  1710. }
  1711. }
  1712. echo '</td>';
  1713. echo '<td>';
  1714. if ($count_attempts > 0) {
  1715. $all_attempt_url = "../exercise/exercise_report.php?exerciseId=$exercise_id&"
  1716. ."cidReq=$course_code&filter_by_user=$student_id&id_session=$sessionId";
  1717. echo Display::url(
  1718. Display::return_icon(
  1719. 'test_results.png',
  1720. get_lang('AllAttempts'),
  1721. [],
  1722. ICON_SIZE_SMALL
  1723. ),
  1724. $all_attempt_url
  1725. );
  1726. }
  1727. echo '</td>';
  1728. echo '</tr>';
  1729. $data_exercices[$i][] = $exercices['title'];
  1730. $data_exercices[$i][] = $score_percentage.'%';
  1731. $data_exercices[$i][] = $count_attempts;
  1732. $csv_content[] = [
  1733. $exercices['title'],
  1734. $lp_name,
  1735. $score_percentage,
  1736. $count_attempts,
  1737. ];
  1738. $i++;
  1739. }
  1740. } else {
  1741. echo '<tr><td colspan="6">'.get_lang('NoExercise').'</td></tr>';
  1742. }
  1743. echo '</tbody></table></div>';
  1744. }
  1745. // @when using sessions we do not show the survey list
  1746. if (empty($sessionId)) {
  1747. $survey_list = SurveyManager::get_surveys($course_code, $sessionId);
  1748. if (!empty($survey_list)) {
  1749. $survey_data = [];
  1750. foreach ($survey_list as $survey) {
  1751. $user_list = SurveyManager::get_people_who_filled_survey(
  1752. $survey['survey_id'],
  1753. false,
  1754. $courseInfo['real_id']
  1755. );
  1756. $survey_done = Display::return_icon(
  1757. "accept_na.png",
  1758. get_lang('NoAnswer'),
  1759. [],
  1760. ICON_SIZE_SMALL
  1761. );
  1762. if (in_array($student_id, $user_list)) {
  1763. $survey_done = Display::return_icon(
  1764. "accept.png",
  1765. get_lang('Answered'),
  1766. [],
  1767. ICON_SIZE_SMALL
  1768. );
  1769. }
  1770. $data = ['title' => $survey['title'], 'done' => $survey_done];
  1771. $survey_data[] = $data;
  1772. }
  1773. if (!empty($survey_data)) {
  1774. $table = new HTML_Table(['class' => 'data_table']);
  1775. $header_names = [get_lang('Survey'), get_lang('Answered')];
  1776. $row = 0;
  1777. $column = 0;
  1778. foreach ($header_names as $item) {
  1779. $table->setHeaderContents($row, $column, $item);
  1780. $column++;
  1781. }
  1782. $row = 1;
  1783. foreach ($survey_data as $data) {
  1784. $column = 0;
  1785. $table->setCellContents($row, $column, $data);
  1786. $class = 'class="row_odd"';
  1787. if ($row % 2) {
  1788. $class = 'class="row_even"';
  1789. }
  1790. $table->setRowAttributes($row, $class, true);
  1791. $column++;
  1792. $row++;
  1793. }
  1794. echo $table->toHtml();
  1795. }
  1796. }
  1797. }
  1798. require_once '../work/work.lib.php';
  1799. $userWorks = getWorkPerUser($student_id, $courseInfo['real_id'], $sessionId);
  1800. echo '
  1801. <div class="table-responsive">
  1802. <table class="table table-striped table-hover">
  1803. <thead>
  1804. <tr>
  1805. <th>'.get_lang('Tasks').'</th>
  1806. <th class="text-center">'.get_lang('DocumentNumber').'</th>
  1807. <th class="text-center">'.get_lang('Note').'</th>
  1808. <th class="text-center">'.get_lang('HandedOut').'</th>
  1809. <th class="text-center">'.get_lang('HandOutDateLimit').'</th>
  1810. <th class="text-center">'.get_lang('ConsideredWorkingTime').'</th>
  1811. </tr>
  1812. </thead>
  1813. <tbody>
  1814. ';
  1815. $workingTime = api_get_configuration_value('considered_working_time');
  1816. foreach ($userWorks as $work) {
  1817. $work = $work['work'];
  1818. foreach ($work->user_results as $key => $results) {
  1819. echo '<tr>';
  1820. echo '<td>'.$work->title.'</td>';
  1821. $documentNumber = $key + 1;
  1822. $url = api_get_path(WEB_CODE_PATH).'work/view.php?cidReq='.$course_code.'&id_session='.$sessionId.'&id='
  1823. .$results['id'];
  1824. echo '<td class="text-center"><a href="'.$url.'">('.$documentNumber.')</a></td>';
  1825. $qualification = !empty($results['qualification']) ? $results['qualification'] : '-';
  1826. echo '<td class="text-center">'.$qualification.'</td>';
  1827. echo '<td class="text-center">'.$results['formatted_date'].'</td>';
  1828. $assignment = get_work_assignment_by_id($work->id, $courseInfo['real_id']);
  1829. echo '<td class="text-center">';
  1830. if (!empty($assignment['expires_on'])) {
  1831. echo api_convert_and_format_date($assignment['expires_on']);
  1832. }
  1833. echo '</td>';
  1834. $fieldValue = new ExtraFieldValue('work');
  1835. $resultExtra = $fieldValue->getAllValuesForAnItem(
  1836. $work->iid,
  1837. true
  1838. );
  1839. foreach ($resultExtra as $field) {
  1840. $field = $field['value'];
  1841. if ($workingTime == $field->getField()->getVariable()) {
  1842. echo '<td class="text-center">'.$field->getValue().'</td>';
  1843. }
  1844. }
  1845. echo '</tr>';
  1846. }
  1847. }
  1848. echo '</tbody>
  1849. </table>
  1850. </div>
  1851. ';
  1852. echo '<div class="table-responsive">
  1853. <table class="table table-striped table-hover">
  1854. <thead>
  1855. <tr>
  1856. <th colspan="2">'.get_lang('OtherTools').'</th>
  1857. </tr>
  1858. </thead>
  1859. <tbody>
  1860. ';
  1861. $csv_content[] = [];
  1862. $nb_assignments = Tracking::count_student_assignments($student_id, $course_code, $sessionId);
  1863. $messages = Tracking::count_student_messages($student_id, $course_code, $sessionId);
  1864. $links = Tracking::count_student_visited_links($student_id, $courseInfo['real_id'], $sessionId);
  1865. $chat_last_connection = Tracking::chat_last_connection($student_id, $courseInfo['real_id'], $sessionId);
  1866. $documents = Tracking::count_student_downloaded_documents($student_id, $courseInfo['real_id'], $sessionId);
  1867. $uploaded_documents = Tracking::count_student_uploaded_documents($student_id, $course_code, $sessionId);
  1868. $csv_content[] = [
  1869. get_lang('OtherTools'),
  1870. ];
  1871. $csv_content[] = [
  1872. get_lang('Student_publication'),
  1873. $nb_assignments,
  1874. ];
  1875. $csv_content[] = [
  1876. get_lang('Messages'),
  1877. $messages,
  1878. ];
  1879. $csv_content[] = [
  1880. get_lang('LinksDetails'),
  1881. $links,
  1882. ];
  1883. $csv_content[] = [
  1884. get_lang('DocumentsDetails'),
  1885. $documents,
  1886. ];
  1887. $csv_content[] = [
  1888. get_lang('UploadedDocuments'),
  1889. $uploaded_documents,
  1890. ];
  1891. $csv_content[] = [
  1892. get_lang('ChatLastConnection'),
  1893. $chat_last_connection,
  1894. ]; ?>
  1895. <tr><!-- assignments -->
  1896. <td width="40%"><?php echo get_lang('Student_publication'); ?></td>
  1897. <td><?php echo $nb_assignments; ?></td>
  1898. </tr>
  1899. <tr><!-- messages -->
  1900. <td><?php echo get_lang('Forum').' - '.get_lang('NumberOfPostsForThisUser'); ?></td>
  1901. <td><?php echo $messages; ?></td>
  1902. </tr>
  1903. <tr><!-- links -->
  1904. <td><?php echo get_lang('LinksDetails'); ?></td>
  1905. <td><?php echo $links; ?></td>
  1906. </tr>
  1907. <tr><!-- downloaded documents -->
  1908. <td><?php echo get_lang('DocumentsDetails'); ?></td>
  1909. <td><?php echo $documents; ?></td>
  1910. </tr>
  1911. <tr><!-- uploaded documents -->
  1912. <td><?php echo get_lang('UploadedDocuments'); ?></td>
  1913. <td><?php echo $uploaded_documents; ?></td>
  1914. </tr>
  1915. <tr><!-- Chats -->
  1916. <td><?php echo get_lang('ChatLastConnection'); ?></td>
  1917. <td><?php echo $chat_last_connection; ?></td>
  1918. </tr>
  1919. </tbody>
  1920. </table>
  1921. </div>
  1922. <?php
  1923. } //end details
  1924. $allowAll = api_get_configuration_value('allow_teacher_access_student_skills');
  1925. if ($allowAll) {
  1926. // Show all skills
  1927. echo Tracking::displayUserSkills(
  1928. $user_info['user_id'],
  1929. 0,
  1930. 0,
  1931. true
  1932. );
  1933. } else {
  1934. // Default behaviour - Show all skills depending the course and session id
  1935. echo Tracking::displayUserSkills(
  1936. $user_info['user_id'],
  1937. $courseInfo ? $courseInfo['real_id'] : 0,
  1938. $sessionId
  1939. );
  1940. }
  1941. if ($allowMessages === true) {
  1942. // Messages
  1943. echo Display::page_subheader2(get_lang('Messages'));
  1944. echo MessageManager::getMessagesAboutUserToString($user_info);
  1945. echo Display::url(
  1946. get_lang('NewMessage'),
  1947. 'javascript: void(0);',
  1948. [
  1949. 'onClick' => "$('#compose_message').show();",
  1950. 'class' => 'btn btn-default',
  1951. ]
  1952. );
  1953. $form = new FormValidator(
  1954. 'messages',
  1955. 'post',
  1956. $currentUrl.'&action=send_message'
  1957. );
  1958. $form->addHtml('<div id="compose_message" style="display:none;">');
  1959. $form->addText('subject', get_lang('Subject'));
  1960. $form->addHtmlEditor('message', get_lang('Message'));
  1961. $form->addButtonSend(get_lang('Send'));
  1962. $form->addHidden('sec_token', $token);
  1963. $form->addHtml('</div>');
  1964. $form->display();
  1965. }
  1966. $allow = api_get_configuration_value('allow_user_message_tracking');
  1967. if ($allow && (api_is_drh() || api_is_platform_admin())) {
  1968. $users = MessageManager::getUsersThatHadConversationWithUser($student_id);
  1969. echo Display::page_subheader2(get_lang('MessageTracking'));
  1970. $table = new HTML_Table(['class' => 'table']);
  1971. $column = 0;
  1972. $row = 0;
  1973. $headers = [
  1974. get_lang('User'),
  1975. ];
  1976. foreach ($headers as $header) {
  1977. $table->setHeaderContents($row, $column, $header);
  1978. $column++;
  1979. }
  1980. $column = 0;
  1981. $row++;
  1982. foreach ($users as $userFollowed) {
  1983. $followedUserId = $userFollowed['user_id'];
  1984. $url = api_get_path(WEB_CODE_PATH).'tracking/messages.php?from_user='.$student_id.'&to_user='.$followedUserId;
  1985. $link = Display::url(
  1986. $userFollowed['complete_name'],
  1987. $url
  1988. );
  1989. $table->setCellContents($row, $column, $link);
  1990. $row++;
  1991. }
  1992. $table->display();
  1993. }
  1994. if ($pluginCalendar) {
  1995. echo $plugin->getUserStatsPanel($student_id, $courses_in_session);
  1996. }
  1997. if ($export) {
  1998. ob_end_clean();
  1999. switch ($export) {
  2000. case 'csv':
  2001. Export::arrayToCsv($csv_content, 'reporting_student');
  2002. break;
  2003. case 'xls':
  2004. Export::arrayToXls($csv_content, 'reporting_student');
  2005. break;
  2006. }
  2007. exit;
  2008. }
  2009. Display::display_footer();