myStudents.php 71 KB

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