myStudents.php 70 KB

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