myStudents.php 72 KB

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