myStudents.php 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CourseBundle\Entity\CLpCategory;
  4. use ChamiloSession as Session;
  5. if (!isset($_GET['course'])) {
  6. $cidReset = true;
  7. }
  8. /**
  9. * Implements the tracking of students in the Reporting pages.
  10. *
  11. * @package chamilo.reporting
  12. */
  13. require_once __DIR__.'/../inc/global.inc.php';
  14. api_block_anonymous_users();
  15. $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_PUBLIC_PATH).'assets/jquery.easy-pie-chart/dist/jquery.easypiechart.js"></script>';
  16. $export = isset($_GET['export']) ? $_GET['export'] : false;
  17. $sessionId = isset($_GET['id_session']) ? (int) $_GET['id_session'] : 0;
  18. $origin = api_get_origin();
  19. $course_code = isset($_GET['course']) ? Security::remove_XSS($_GET['course']) : '';
  20. $courseInfo = api_get_course_info($course_code);
  21. $student_id = isset($_GET['student']) ? (int) $_GET['student'] : 0;
  22. $coachId = isset($_GET['id_coach']) ? (int) $_GET['id_coach'] : 0;
  23. $details = isset($_GET['details']) ? Security::remove_XSS($_GET['details']) : '';
  24. $currentUrl = api_get_self().'?student='.$student_id.'&course='.$course_code.'&id_session='.$sessionId
  25. .'&origin='.$origin.'&details='.$details;
  26. $allowMessages = api_get_configuration_value('private_messages_about_user');
  27. if (empty($student_id)) {
  28. api_not_allowed(true);
  29. }
  30. // user info
  31. $user_info = api_get_user_info($student_id);
  32. if (empty($user_info)) {
  33. api_not_allowed(true);
  34. }
  35. $allowToQualify = api_is_allowed_to_edit(null, true) ||
  36. api_is_course_tutor() ||
  37. api_is_session_admin() ||
  38. api_is_drh() ||
  39. api_is_student_boss();
  40. $allowedToTrackUser = true;
  41. if (!api_is_session_admin() &&
  42. !api_is_drh() &&
  43. !api_is_student_boss() &&
  44. !api_is_platform_admin()
  45. ) {
  46. if (empty($sessionId)) {
  47. $isTeacher = false;
  48. // Check if is current teacher if set
  49. if (!empty($courseInfo)) {
  50. $isTeacher = CourseManager::is_course_teacher(
  51. api_get_user_id(),
  52. $courseInfo['code']
  53. );
  54. }
  55. if (!api_is_course_admin() && $isTeacher == false) {
  56. if (!empty($courseInfo)) {
  57. // Check if the user is tutor of the course
  58. $userCourseStatus = CourseManager::get_tutor_in_course_status(
  59. api_get_user_id(),
  60. $courseInfo['real_id']
  61. );
  62. if ($userCourseStatus != 1) {
  63. $allowedToTrackUser = false;
  64. }
  65. }
  66. }
  67. } else {
  68. $coach = api_is_coach($sessionId, $courseInfo['real_id']);
  69. if (!$coach) {
  70. $allowedToTrackUser = false;
  71. }
  72. }
  73. }
  74. if (!$allowedToTrackUser) {
  75. api_not_allowed(true);
  76. }
  77. if (api_is_student()) {
  78. api_not_allowed(true);
  79. }
  80. if ($export) {
  81. ob_start();
  82. }
  83. $csv_content = [];
  84. $from_myspace = false;
  85. $this_section = SECTION_COURSES;
  86. if (isset($_GET['from']) && $_GET['from'] === 'myspace') {
  87. $from_myspace = true;
  88. $this_section = SECTION_TRACKING;
  89. }
  90. $nameTools = get_lang('StudentDetails');
  91. if (!empty($details)) {
  92. if ($origin === 'user_course') {
  93. if (empty($cidReq)) {
  94. $interbreadcrumb[] = [
  95. 'url' => api_get_path(WEB_COURSE_PATH).$courseInfo['directory'],
  96. 'name' => $courseInfo['title'],
  97. ];
  98. }
  99. $interbreadcrumb[] = [
  100. 'url' => '../user/user.php?cidReq='.$course_code,
  101. 'name' => get_lang('Users'),
  102. ];
  103. } else {
  104. if ($origin === 'tracking_course') {
  105. $interbreadcrumb[] = [
  106. 'url' => '../tracking/courseLog.php?cidReq='.$course_code.'&id_session='.api_get_session_id(),
  107. 'name' => get_lang('Tracking'),
  108. ];
  109. } else {
  110. if ($origin === 'resume_session') {
  111. $interbreadcrumb[] = [
  112. 'url' => "../session/session_list.php",
  113. 'name' => get_lang('SessionList'),
  114. ];
  115. $interbreadcrumb[] = [
  116. 'url' => '../session/resume_session.php?id_session='.$sessionId,
  117. 'name' => get_lang('SessionOverview'),
  118. ];
  119. } else {
  120. $interbreadcrumb[] = [
  121. 'url' => api_is_student_boss() ? '#' : 'index.php',
  122. 'name' => get_lang('MySpace'),
  123. ];
  124. if (!empty($coachId)) {
  125. $interbreadcrumb[] = [
  126. 'url' => 'student.php?id_coach='.$coachId,
  127. 'name' => get_lang('CoachStudents'),
  128. ];
  129. $interbreadcrumb[] = [
  130. 'url' => 'myStudents.php?student='.$student_id.'&id_coach='.$coachId,
  131. 'name' => get_lang('StudentDetails'),
  132. ];
  133. } else {
  134. $interbreadcrumb[] = [
  135. 'url' => 'student.php',
  136. 'name' => get_lang('MyStudents'),
  137. ];
  138. $interbreadcrumb[] = [
  139. 'url' => 'myStudents.php?student='.$student_id,
  140. 'name' => get_lang('StudentDetails'),
  141. ];
  142. }
  143. }
  144. }
  145. }
  146. $nameTools = get_lang('DetailsStudentInCourse');
  147. } else {
  148. if ($origin === 'resume_session') {
  149. $interbreadcrumb[] = [
  150. 'url' => '../session/session_list.php',
  151. 'name' => get_lang('SessionList'),
  152. ];
  153. if (!empty($sessionId)) {
  154. $interbreadcrumb[] = [
  155. 'url' => '../session/resume_session.php?id_session='.$sessionId,
  156. 'name' => get_lang('SessionOverview'),
  157. ];
  158. }
  159. } elseif ($origin === 'teacher_details') {
  160. $this_section = SECTION_TRACKING;
  161. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('MySpace')];
  162. $interbreadcrumb[] = ['url' => 'teachers.php', 'name' => get_lang('Teachers')];
  163. $nameTools = $user_info['complete_name'];
  164. } else {
  165. $interbreadcrumb[] = [
  166. 'url' => api_is_student_boss() ? '#' : 'index.php',
  167. 'name' => get_lang('MySpace'),
  168. ];
  169. if (!empty($coachId)) {
  170. if ($sessionId) {
  171. $interbreadcrumb[] = [
  172. 'url' => 'student.php?id_coach='.$coachId.'&id_session='.$sessionId,
  173. 'name' => get_lang('CoachStudents'),
  174. ];
  175. } else {
  176. $interbreadcrumb[] = [
  177. 'url' => 'student.php?id_coach='.$coachId,
  178. 'name' => get_lang('CoachStudents'),
  179. ];
  180. }
  181. } else {
  182. $interbreadcrumb[] = [
  183. 'url' => 'student.php',
  184. 'name' => get_lang('MyStudents'),
  185. ];
  186. }
  187. }
  188. }
  189. // Database Table Definitions
  190. $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  191. $tbl_stats_exercices = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  192. $action = isset($_GET['action']) ? $_GET['action'] : '';
  193. switch ($action) {
  194. case 'export_to_pdf':
  195. $sessionToExport = $sId = isset($_GET['session_to_export']) ? (int) $_GET['session_to_export'] : 0;
  196. $sessionInfo = api_get_session_info($sessionToExport);
  197. if (empty($sessionInfo)) {
  198. api_not_allowed(true);
  199. }
  200. $courses = Tracking::get_courses_list_from_session($sessionToExport);
  201. $timeSpent = 0;
  202. $numberVisits = 0;
  203. $table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  204. $progress = 0;
  205. foreach ($courses as $course) {
  206. $courseId = $course['c_id'];
  207. $timeSpent += Tracking::get_time_spent_on_the_course($student_id, $courseId, $sessionToExport);
  208. $sql = 'SELECT DISTINCT count(course_access_id) as count
  209. FROM '.$table.'
  210. WHERE
  211. user_id = '.$student_id.' AND
  212. c_id = '.$courseId.' AND
  213. session_id = '.$sessionToExport.'
  214. ORDER BY login_course_date ASC';
  215. $result = Database::query($sql);
  216. $row = Database::fetch_array($result);
  217. $numberVisits += $row['count'];
  218. $progress += Tracking::get_avg_student_progress($student_id, $course['code'], [], $sessionToExport);
  219. }
  220. $average = round($progress / count($courses), 1);
  221. $average = empty($average) ? '0%' : $average.'%';
  222. $first = Tracking::get_first_connection_date($student_id);
  223. $last = Tracking::get_last_connection_date($student_id);
  224. $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() || api_is_session_admin()) {
  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('attendance.png', get_lang('AccessDetails'), '', 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. $totalCourses = count($courses);
  984. $scoreDisplay = ScoreDisplay::instance();
  985. foreach ($courses as $courseId) {
  986. $courseInfoItem = api_get_course_info_by_id($courseId);
  987. $courseId = $courseInfoItem['real_id'];
  988. $courseCodeItem = $courseInfoItem['code'];
  989. if (empty($session_info)) {
  990. $isSubscribed = CourseManager::is_user_subscribed_in_course(
  991. $student_id,
  992. $courseCodeItem
  993. );
  994. } else {
  995. $isSubscribed = CourseManager::is_user_subscribed_in_course(
  996. $student_id,
  997. $courseCodeItem,
  998. true,
  999. $sId
  1000. );
  1001. }
  1002. if ($isSubscribed) {
  1003. $timeInSeconds = Tracking::get_time_spent_on_the_course(
  1004. $user_info['user_id'],
  1005. $courseId,
  1006. $sId
  1007. );
  1008. $totalCourseTime += $timeInSeconds;
  1009. $time_spent_on_course = api_time_to_hms($timeInSeconds);
  1010. // get average of faults in attendances by student
  1011. $results_faults_avg = $attendance->get_faults_average_by_course(
  1012. $student_id,
  1013. $courseCodeItem,
  1014. $sId
  1015. );
  1016. $attendances_faults_avg = '0/0 (0%)';
  1017. if (!empty($results_faults_avg['total'])) {
  1018. if (api_is_drh()) {
  1019. $attendances_faults_avg = '<a title="'.get_lang('GoAttendance').'" href="'.api_get_path(WEB_CODE_PATH)
  1020. .'attendance/index.php?cidReq='.$courseCodeItem.'&id_session='.$sId.'&student_id='
  1021. .$student_id.'">'
  1022. .$results_faults_avg['faults'].'/'.$results_faults_avg['total'].' ('
  1023. .$results_faults_avg['porcent'].'%)</a>';
  1024. } else {
  1025. $attendances_faults_avg = $results_faults_avg['faults'].'/'
  1026. .$results_faults_avg['total']
  1027. .' ('.$results_faults_avg['porcent'].'%)';
  1028. }
  1029. $totalAttendance[0] += $results_faults_avg['faults'];
  1030. $totalAttendance[1] += $results_faults_avg['total'];
  1031. }
  1032. // Get evaluations by student
  1033. $cats = Category::load(
  1034. null,
  1035. null,
  1036. $courseCodeItem,
  1037. null,
  1038. null,
  1039. $sId
  1040. );
  1041. $scoretotal = [];
  1042. if (isset($cats) && isset($cats[0])) {
  1043. if (!empty($sId)) {
  1044. $scoretotal = $cats[0]->calc_score($student_id, null, $courseCodeItem, $sId);
  1045. } else {
  1046. $scoretotal = $cats[0]->calc_score($student_id, null, $courseCodeItem);
  1047. }
  1048. }
  1049. $scoretotal_display = '0/0 (0%)';
  1050. if (!empty($scoretotal) && !empty($scoretotal[1])) {
  1051. $scoretotal_display =
  1052. round($scoretotal[0], 1).'/'.
  1053. round($scoretotal[1], 1).
  1054. ' ('.round(($scoretotal[0] / $scoretotal[1]) * 100, 2).' %)';
  1055. $gradeBookTotal[0] += $scoretotal[0];
  1056. $gradeBookTotal[1] += $scoretotal[1];
  1057. }
  1058. $progress = Tracking::get_avg_student_progress(
  1059. $user_info['user_id'],
  1060. $courseCodeItem,
  1061. [],
  1062. $sId
  1063. );
  1064. $totalProgress += $progress;
  1065. $score = Tracking::get_avg_student_score(
  1066. $user_info['user_id'],
  1067. $courseCodeItem,
  1068. [],
  1069. $sId
  1070. );
  1071. if (is_numeric($score)) {
  1072. $totalScore += $score;
  1073. }
  1074. $progress = empty($progress) ? '0%' : $progress.'%';
  1075. $score = empty($score) ? '0%' : $score.'%';
  1076. $csvRow = [
  1077. $session_name,
  1078. $courseInfoItem['title'],
  1079. $time_spent_on_course,
  1080. $progress,
  1081. $score,
  1082. $attendances_faults_avg,
  1083. $scoretotal_display,
  1084. ];
  1085. $csv_content[] = $csvRow;
  1086. $exportCourseList[$sId][] = $csvRow;
  1087. echo '<tr>
  1088. <td ><a href="'.$courseInfoItem['course_public_url'].'?id_session='.$sId.'">'.
  1089. $courseInfoItem['title'].'</a></td>
  1090. <td >'.$time_spent_on_course.'</td>
  1091. <td >'.$progress.'</td>
  1092. <td >'.$score.'</td>
  1093. <td >'.$attendances_faults_avg.'</td>
  1094. <td >'.$scoretotal_display.'</td>';
  1095. if (!empty($coachId)) {
  1096. echo '<td width="10"><a href="'.api_get_self().'?student='.$user_info['user_id']
  1097. .'&details=true&course='.$courseInfoItem['code'].'&id_coach='.$coachId.'&origin='.$origin
  1098. .'&id_session='.$sId.'#infosStudent">'
  1099. .Display::return_icon('2rightarrow.png', get_lang('Details')).'</a></td>';
  1100. } else {
  1101. echo '<td width="10"><a href="'.api_get_self().'?student='.$user_info['user_id']
  1102. .'&details=true&course='.$courseInfoItem['code'].'&origin='.$origin.'&id_session='.$sId.'#infosStudent">'
  1103. .Display::return_icon('2rightarrow.png', get_lang('Details')).'</a></td>';
  1104. }
  1105. echo '</tr>';
  1106. }
  1107. }
  1108. $totalAttendanceFormatted = $scoreDisplay->display_score($totalAttendance);
  1109. $totalScoreFormatted = $scoreDisplay->display_score([$totalScore / $totalCourses, 100], SCORE_AVERAGE);
  1110. $totalProgressFormatted = $scoreDisplay->display_score(
  1111. [$totalProgress / $totalCourses, 100],
  1112. SCORE_AVERAGE
  1113. );
  1114. $totalEvaluations = $scoreDisplay->display_score($gradeBookTotal);
  1115. $totalTimeFormatted = api_time_to_hms($totalCourseTime);
  1116. echo '<tr>
  1117. <th>'.get_lang('Total').'</th>
  1118. <th>'.$totalTimeFormatted.'</th>
  1119. <th>'.$totalProgressFormatted.'</th>
  1120. <th>'.$totalScoreFormatted.'</th>
  1121. <th>'.$totalAttendanceFormatted.'</th>
  1122. <th>'.$totalEvaluations.'</th>
  1123. <th></th>
  1124. </tr>';
  1125. $csvRow = [
  1126. get_lang('Total'),
  1127. '',
  1128. $totalTimeFormatted,
  1129. $totalProgressFormatted,
  1130. $totalScoreFormatted,
  1131. $totalAttendanceFormatted,
  1132. $totalEvaluations,
  1133. '',
  1134. ];
  1135. $csv_content[] = $csvRow;
  1136. $exportCourseList[$sId][] = $csvRow;
  1137. $sessionAction = Display::url(
  1138. Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), [], ICON_SIZE_MEDIUM),
  1139. $currentUrl
  1140. .'&'
  1141. .http_build_query(
  1142. ['action' => 'export_one_session_row', 'export' => 'csv', 'session_to_export' => $sId]
  1143. )
  1144. );
  1145. $sessionAction .= Display::url(
  1146. Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), [], ICON_SIZE_MEDIUM),
  1147. $currentUrl
  1148. .'&'
  1149. .http_build_query(
  1150. ['action' => 'export_one_session_row', 'export' => 'xls', 'session_to_export' => $sId]
  1151. )
  1152. );
  1153. if (!empty($sId)) {
  1154. $sessionAction .= Display::url(
  1155. Display::return_icon('pdf.png', get_lang('ExportToPDF'), [], ICON_SIZE_MEDIUM),
  1156. $currentUrl
  1157. .'&'
  1158. .http_build_query(
  1159. ['action' => 'export_to_pdf', 'session_to_export' => $sId]
  1160. )
  1161. );
  1162. }
  1163. echo $sessionAction;
  1164. } else {
  1165. echo "<tr><td colspan='5'>".get_lang('NoCourse')."</td></tr>";
  1166. }
  1167. Session::write('export_course_list', $exportCourseList);
  1168. echo '</tbody>';
  1169. echo '</table>';
  1170. echo '</div>';
  1171. }
  1172. } else {
  1173. $columnHeaders = [
  1174. 'lp' => get_lang('LearningPath'),
  1175. 'time' => get_lang('Time').
  1176. Display::return_icon(
  1177. 'info3.gif',
  1178. get_lang('TotalTimeByCourse'),
  1179. ['align' => 'absmiddle', 'hspace' => '3px']
  1180. ),
  1181. 'best_score' => get_lang('BestScore'),
  1182. 'latest_attempt_avg_score' => get_lang('LatestAttemptAverageScore').
  1183. Display::return_icon(
  1184. 'info3.gif',
  1185. get_lang('AverageIsCalculatedBasedInTheLatestAttempts'),
  1186. ['align' => 'absmiddle', 'hspace' => '3px']
  1187. ),
  1188. 'progress' => get_lang('Progress').
  1189. Display::return_icon(
  1190. 'info3.gif',
  1191. get_lang('LPProgressScore'),
  1192. ['align' => 'absmiddle', 'hspace' => '3px']
  1193. ),
  1194. 'last_connection' => get_lang('LastConnexion').
  1195. Display::return_icon(
  1196. 'info3.gif',
  1197. get_lang('LastTimeTheCourseWasUsed'),
  1198. ['align' => 'absmiddle', 'hspace' => '3px']
  1199. ),
  1200. ];
  1201. $timeCourse = null;
  1202. if (Tracking::minimumTimeAvailable($sessionId, $courseInfo['real_id'])) {
  1203. $timeCourse = Tracking::getCalculateTime($student_id, $courseInfo['real_id'], $sessionId);
  1204. }
  1205. if ($user_info['status'] != INVITEE) {
  1206. $csv_content[] = [];
  1207. $csv_content[] = [str_replace('&nbsp;', '', strip_tags($userInfo['complete_name']))];
  1208. $trackingColumns = api_get_configuration_value('tracking_columns');
  1209. if (isset($trackingColumns['my_students_lp'])) {
  1210. foreach ($columnHeaders as $key => $value) {
  1211. if (!isset($trackingColumns['my_progress_lp'][$key]) ||
  1212. $trackingColumns['my_students_lp'][$key] == false
  1213. ) {
  1214. unset($columnHeaders[$key]);
  1215. }
  1216. }
  1217. }
  1218. $headers = '';
  1219. $columnHeadersToExport = [];
  1220. // csv export headers
  1221. foreach ($columnHeaders as $key => $columnName) {
  1222. $columnHeadersToExport[] = strip_tags($columnName);
  1223. $headers .= Display::tag(
  1224. 'th',
  1225. $columnName
  1226. );
  1227. }
  1228. $csv_content[] = $columnHeadersToExport;
  1229. $columnHeadersKeys = array_keys($columnHeaders);
  1230. $categoriesTempList = learnpath::getCategories($courseInfo['real_id']);
  1231. $categoryTest = new CLpCategory();
  1232. $categoryTest->setId(0);
  1233. $categoryTest->setName(get_lang('WithOutCategory'));
  1234. $categoryTest->setPosition(0);
  1235. $categories = [
  1236. $categoryTest,
  1237. ];
  1238. if (!empty($categoriesTempList)) {
  1239. $categories = array_merge($categories, $categoriesTempList);
  1240. }
  1241. $userEntity = api_get_user_entity(api_get_user_id());
  1242. /** @var CLpCategory $item */
  1243. foreach ($categories as $item) {
  1244. $categoryId = $item->getId();
  1245. if (!learnpath::categoryIsVisibleForStudent($item, $userEntity, $courseInfo['real_id'], $sessionId)) {
  1246. continue;
  1247. }
  1248. $list = new LearnpathList(
  1249. api_get_user_id(),
  1250. $courseInfo,
  1251. $sessionId,
  1252. null,
  1253. false,
  1254. $categoryId,
  1255. false,
  1256. true
  1257. );
  1258. $flat_list = $list->get_flat_list();
  1259. $i = 0;
  1260. if (count($categories) > 1) {
  1261. echo Display::page_subheader2($item->getName());
  1262. }
  1263. echo '<div class="table-responsive">';
  1264. echo '<table class="table table-striped table-hover"><thead><tr>';
  1265. echo $headers;
  1266. echo '<th>'.get_lang('Details').'</th>';
  1267. if (api_is_allowed_to_edit()) {
  1268. echo '<th>'.get_lang('ResetLP').'</th>';
  1269. }
  1270. echo '</tr></thead><tbody>';
  1271. foreach ($flat_list as $learnpath) {
  1272. $lpIdList[] = $learnpath['iid'];
  1273. $lp_id = $learnpath['lp_old_id'];
  1274. $lp_name = $learnpath['lp_name'];
  1275. $any_result = false;
  1276. // Get progress in lp
  1277. $progress = Tracking::get_avg_student_progress(
  1278. $student_id,
  1279. $course_code,
  1280. [$lp_id],
  1281. $sessionId
  1282. );
  1283. if ($progress === null) {
  1284. $progress = '0%';
  1285. } else {
  1286. $any_result = true;
  1287. }
  1288. // Get time in lp
  1289. if (!empty($timeCourse)) {
  1290. $lpTime = isset($timeCourse[TOOL_LEARNPATH]) ? $timeCourse[TOOL_LEARNPATH] : 0;
  1291. $total_time = isset($lpTime[$lp_id]) ? (int) $lpTime[$lp_id] : 0;
  1292. } else {
  1293. $total_time = Tracking::get_time_spent_in_lp(
  1294. $student_id,
  1295. $course_code,
  1296. [$lp_id],
  1297. $sessionId
  1298. );
  1299. }
  1300. if (!empty($total_time)) {
  1301. $any_result = true;
  1302. }
  1303. // Get last connection time in lp
  1304. $start_time = Tracking::get_last_connection_time_in_lp(
  1305. $student_id,
  1306. $course_code,
  1307. $lp_id,
  1308. $sessionId
  1309. );
  1310. if (!empty($start_time)) {
  1311. $start_time = api_convert_and_format_date($start_time, DATE_TIME_FORMAT_LONG);
  1312. } else {
  1313. $start_time = '-';
  1314. }
  1315. if (!empty($total_time)) {
  1316. $any_result = true;
  1317. }
  1318. // Quiz in lp
  1319. $score = Tracking::get_avg_student_score(
  1320. $student_id,
  1321. $course_code,
  1322. [$lp_id],
  1323. $sessionId
  1324. );
  1325. // Latest exercise results in a LP
  1326. $score_latest = Tracking::get_avg_student_score(
  1327. $student_id,
  1328. $course_code,
  1329. [$lp_id],
  1330. $sessionId,
  1331. false,
  1332. true
  1333. );
  1334. $bestScore = Tracking::get_avg_student_score(
  1335. $student_id,
  1336. $course_code,
  1337. [$lp_id],
  1338. $sessionId,
  1339. false,
  1340. false,
  1341. true
  1342. );
  1343. if (empty($bestScore)) {
  1344. $bestScore = '';
  1345. } else {
  1346. $bestScore = $bestScore.'%';
  1347. }
  1348. if ($i % 2 == 0) {
  1349. $css_class = 'row_even';
  1350. } else {
  1351. $css_class = 'row_odd';
  1352. }
  1353. $i++;
  1354. if (isset($score_latest) && !is_null($score_latest)) {
  1355. if (is_numeric($score_latest)) {
  1356. $score_latest = $score_latest.'%';
  1357. }
  1358. }
  1359. if (is_numeric($progress)) {
  1360. $progress = $progress.'%';
  1361. } else {
  1362. $progress = '-';
  1363. }
  1364. echo '<tr class="'.$css_class.'">';
  1365. $contentToExport = [];
  1366. if (in_array('lp', $columnHeadersKeys)) {
  1367. $contentToExport[] = api_html_entity_decode(
  1368. stripslashes($lp_name),
  1369. ENT_QUOTES,
  1370. $charset
  1371. );
  1372. echo Display::tag('td', stripslashes($lp_name));
  1373. }
  1374. if (in_array('time', $columnHeadersKeys)) {
  1375. $contentToExport[] = api_time_to_hms($total_time);
  1376. echo Display::tag('td', api_time_to_hms($total_time));
  1377. }
  1378. if (in_array('best_score', $columnHeadersKeys)) {
  1379. $contentToExport[] = $bestScore;
  1380. echo Display::tag('td', $bestScore);
  1381. }
  1382. if (in_array('latest_attempt_avg_score', $columnHeadersKeys)) {
  1383. $contentToExport[] = $score_latest;
  1384. echo Display::tag('td', $score_latest);
  1385. }
  1386. if (in_array('progress', $columnHeadersKeys)) {
  1387. $contentToExport[] = $progress;
  1388. echo Display::tag('td', $progress);
  1389. }
  1390. if (in_array('last_connection', $columnHeadersKeys)) {
  1391. // Do not change with api_convert_and_format_date, because this value came from the lp_item_view table
  1392. // which implies several other changes not a priority right now
  1393. $contentToExport[] = $start_time;
  1394. echo Display::tag('td', $start_time);
  1395. }
  1396. $csv_content[] = $contentToExport;
  1397. if ($any_result === true) {
  1398. $from = '';
  1399. if ($from_myspace) {
  1400. $from = '&from=myspace';
  1401. }
  1402. $link = Display::url(
  1403. Display::return_icon('2rightarrow.png', get_lang('Details')),
  1404. 'lp_tracking.php?cidReq='.$course_code.'&course='.$course_code.$from.'&origin='.$origin
  1405. .'&lp_id='.$lp_id.'&student_id='.$user_info['user_id'].'&id_session='.$sessionId
  1406. );
  1407. echo Display::tag('td', $link);
  1408. }
  1409. if (api_is_allowed_to_edit()) {
  1410. echo '<td>';
  1411. if ($any_result === true) {
  1412. $url = 'myStudents.php?action=reset_lp&sec_token='.$token.'&cidReq='.$course_code.'&course='
  1413. .$course_code.'&details='.$details.'&origin='.$origin.'&lp_id='.$lp_id.'&student='
  1414. .$user_info['user_id'].'&details=true&id_session='.$sessionId;
  1415. echo Display::url(
  1416. Display::return_icon('clean.png', get_lang('Clean')),
  1417. $url,
  1418. [
  1419. 'onclick' => "javascript:if(!confirm('"
  1420. .addslashes(
  1421. api_htmlentities(get_lang('AreYouSureToDelete'))
  1422. )
  1423. ."')) return false;",
  1424. ]
  1425. );
  1426. }
  1427. echo '</td>';
  1428. echo '</tr>';
  1429. }
  1430. }
  1431. echo '</tbody></table></div>';
  1432. }
  1433. }
  1434. if ($user_info['status'] != INVITEE) {
  1435. echo '<div class="table-responsive">
  1436. <table class="table table-striped table-hover">
  1437. <thead>
  1438. <tr>';
  1439. echo '<th>'.get_lang('Exercises').'</th>';
  1440. echo '<th>'.get_lang('LearningPath').'</th>';
  1441. echo '<th>'.get_lang('AvgCourseScore').' '.
  1442. Display::return_icon(
  1443. 'info3.gif',
  1444. get_lang('AverageScore'),
  1445. ['align' => 'absmiddle', 'hspace' => '3px']
  1446. ).'</th>';
  1447. echo '<th>'.get_lang('Attempts').'</th>';
  1448. echo '<th>'.get_lang('LatestAttempt').'</th>';
  1449. echo '<th>'.get_lang('AllAttempts').'</th>';
  1450. echo '</tr></thead><tbody>';
  1451. $csv_content[] = [];
  1452. $csv_content[] = [
  1453. get_lang('Exercises'),
  1454. get_lang('LearningPath'),
  1455. get_lang('AvgCourseScore'),
  1456. get_lang('Attempts'),
  1457. ];
  1458. $t_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
  1459. $sessionCondition = api_get_session_condition(
  1460. $sessionId,
  1461. true,
  1462. true,
  1463. 'quiz.session_id'
  1464. );
  1465. $sql = "SELECT quiz.title, id
  1466. FROM $t_quiz AS quiz
  1467. WHERE
  1468. quiz.c_id = ".$courseInfo['real_id']." AND
  1469. active IN (0, 1)
  1470. $sessionCondition
  1471. ORDER BY quiz.title ASC ";
  1472. $result_exercices = Database::query($sql);
  1473. $i = 0;
  1474. if (Database::num_rows($result_exercices) > 0) {
  1475. while ($exercices = Database::fetch_array($result_exercices)) {
  1476. $exercise_id = (int) $exercices['id'];
  1477. $count_attempts = Tracking::count_student_exercise_attempts(
  1478. $student_id,
  1479. $courseInfo['real_id'],
  1480. $exercise_id,
  1481. 0,
  1482. 0,
  1483. $sessionId,
  1484. 2
  1485. );
  1486. $score_percentage = Tracking::get_avg_student_exercise_score(
  1487. $student_id,
  1488. $course_code,
  1489. $exercise_id,
  1490. $sessionId,
  1491. 1,
  1492. 0
  1493. );
  1494. $lp_name = '-';
  1495. if (!isset($score_percentage) && $count_attempts > 0) {
  1496. $scores_lp = Tracking::get_avg_student_exercise_score(
  1497. $student_id,
  1498. $course_code,
  1499. $exercise_id,
  1500. $sessionId,
  1501. 2,
  1502. 1
  1503. );
  1504. $score_percentage = $scores_lp[0];
  1505. $lp_name = $scores_lp[1];
  1506. }
  1507. $lp_name = !empty($lp_name) ? $lp_name : get_lang('NoLearnpath');
  1508. $css_class = 'row_even';
  1509. if ($i % 2) {
  1510. $css_class = 'row_odd';
  1511. }
  1512. echo '<tr class="'.$css_class.'"><td>'.Exercise::get_formated_title_variable($exercices['title']).'</td>';
  1513. echo '<td>';
  1514. if (!empty($lp_name)) {
  1515. echo $lp_name;
  1516. } else {
  1517. echo '-';
  1518. }
  1519. echo '</td>';
  1520. echo '<td>';
  1521. if ($count_attempts > 0) {
  1522. echo $score_percentage.'%';
  1523. } else {
  1524. echo '-';
  1525. $score_percentage = 0;
  1526. }
  1527. echo '</td>';
  1528. echo '<td>'.$count_attempts.'</td>';
  1529. echo '<td>';
  1530. $sql = 'SELECT exe_id FROM '.$tbl_stats_exercices.'
  1531. WHERE
  1532. exe_exo_id = "'.$exercise_id.'" AND
  1533. exe_user_id ="'.$student_id.'" AND
  1534. c_id = '.$courseInfo['real_id'].' AND
  1535. session_id = "'.$sessionId.'" AND
  1536. status = ""
  1537. ORDER BY exe_date DESC
  1538. LIMIT 1';
  1539. $result_last_attempt = Database::query($sql);
  1540. if (Database::num_rows($result_last_attempt) > 0) {
  1541. $id_last_attempt = Database::result($result_last_attempt, 0, 0);
  1542. if ($count_attempts > 0) {
  1543. $qualifyLink = '';
  1544. if ($allowToQualify) {
  1545. $qualifyLink = '&action=qualify';
  1546. }
  1547. $attemptLink = '../exercise/exercise_show.php?id='.$id_last_attempt.'&cidReq='.$course_code
  1548. .'&id_session='.$sessionId.'&session_id='.$sessionId.'&student='.$student_id.'&origin='
  1549. .(empty($origin) ? 'tracking' : $origin).$qualifyLink;
  1550. echo Display::url(
  1551. Display::return_icon('quiz.png', get_lang('Exercise')),
  1552. $attemptLink
  1553. );
  1554. }
  1555. }
  1556. echo '</td>';
  1557. echo '<td>';
  1558. if ($count_attempts > 0) {
  1559. $all_attempt_url = "../exercise/exercise_report.php?exerciseId=$exercise_id&"
  1560. ."cidReq=$course_code&filter_by_user=$student_id&id_session=$sessionId";
  1561. echo Display::url(
  1562. Display::return_icon(
  1563. 'test_results.png',
  1564. get_lang('AllAttempts'),
  1565. [],
  1566. ICON_SIZE_SMALL
  1567. ),
  1568. $all_attempt_url
  1569. );
  1570. }
  1571. echo '</td>';
  1572. echo '</tr>';
  1573. $data_exercices[$i][] = $exercices['title'];
  1574. $data_exercices[$i][] = $score_percentage.'%';
  1575. $data_exercices[$i][] = $count_attempts;
  1576. $csv_content[] = [
  1577. $exercices['title'],
  1578. $lp_name,
  1579. $score_percentage,
  1580. $count_attempts,
  1581. ];
  1582. $i++;
  1583. }
  1584. } else {
  1585. echo '<tr><td colspan="6">'.get_lang('NoExercise').'</td></tr>';
  1586. }
  1587. echo '</tbody></table></div>';
  1588. }
  1589. // @when using sessions we do not show the survey list
  1590. if (empty($sessionId)) {
  1591. $survey_list = SurveyManager::get_surveys($course_code, $sessionId);
  1592. if (!empty($survey_list)) {
  1593. $survey_data = [];
  1594. foreach ($survey_list as $survey) {
  1595. $user_list = SurveyManager::get_people_who_filled_survey(
  1596. $survey['survey_id'],
  1597. false,
  1598. $courseInfo['real_id']
  1599. );
  1600. $survey_done = Display::return_icon(
  1601. "accept_na.png",
  1602. get_lang('NoAnswer'),
  1603. [],
  1604. ICON_SIZE_SMALL
  1605. );
  1606. if (in_array($student_id, $user_list)) {
  1607. $survey_done = Display::return_icon(
  1608. "accept.png",
  1609. get_lang('Answered'),
  1610. [],
  1611. ICON_SIZE_SMALL
  1612. );
  1613. }
  1614. $data = ['title' => $survey['title'], 'done' => $survey_done];
  1615. $survey_data[] = $data;
  1616. }
  1617. if (!empty($survey_data)) {
  1618. $table = new HTML_Table(['class' => 'data_table']);
  1619. $header_names = [get_lang('Survey'), get_lang('Answered')];
  1620. $row = 0;
  1621. $column = 0;
  1622. foreach ($header_names as $item) {
  1623. $table->setHeaderContents($row, $column, $item);
  1624. $column++;
  1625. }
  1626. $row = 1;
  1627. foreach ($survey_data as $data) {
  1628. $column = 0;
  1629. $table->setCellContents($row, $column, $data);
  1630. $class = 'class="row_odd"';
  1631. if ($row % 2) {
  1632. $class = 'class="row_even"';
  1633. }
  1634. $table->setRowAttributes($row, $class, true);
  1635. $column++;
  1636. $row++;
  1637. }
  1638. echo $table->toHtml();
  1639. }
  1640. }
  1641. }
  1642. require_once '../work/work.lib.php';
  1643. $userWorks = getWorkPerUser($student_id, $courseInfo['real_id'], $sessionId);
  1644. echo '
  1645. <div class="table-responsive">
  1646. <table class="table table-striped table-hover">
  1647. <thead>
  1648. <tr>
  1649. <th>'.get_lang('Tasks').'</th>
  1650. <th class="text-center">'.get_lang('DocumentNumber').'</th>
  1651. <th class="text-center">'.get_lang('Note').'</th>
  1652. <th class="text-center">'.get_lang('HandedOut').'</th>
  1653. <th class="text-center">'.get_lang('HandOutDateLimit').'</th>
  1654. <th class="text-center">'.get_lang('ConsideredWorkingTime').'</th>
  1655. </tr>
  1656. </thead>
  1657. <tbody>
  1658. ';
  1659. $workingTime = api_get_configuration_value('considered_working_time');
  1660. foreach ($userWorks as $work) {
  1661. $work = $work['work'];
  1662. foreach ($work->user_results as $key => $results) {
  1663. echo '<tr>';
  1664. echo '<td>'.$work->title.'</td>';
  1665. $documentNumber = $key + 1;
  1666. $url = api_get_path(WEB_CODE_PATH).'work/view.php?cidReq='.$course_code.'&id_session='.$sessionId.'&id='
  1667. .$results['id'];
  1668. echo '<td class="text-center"><a href="'.$url.'">('.$documentNumber.')</a></td>';
  1669. $qualification = !empty($results['qualification']) ? $results['qualification'] : '-';
  1670. echo '<td class="text-center">'.$qualification.'</td>';
  1671. echo '<td class="text-center">'.$results['formatted_date'].'</td>';
  1672. $assignment = get_work_assignment_by_id($work->id, $courseInfo['real_id']);
  1673. echo '<td class="text-center">';
  1674. if (!empty($assignment['expires_on'])) {
  1675. echo api_convert_and_format_date($assignment['expires_on']);
  1676. }
  1677. echo '</td>';
  1678. $fieldValue = new ExtraFieldValue('work');
  1679. $resultExtra = $fieldValue->getAllValuesForAnItem(
  1680. $work->iid,
  1681. true
  1682. );
  1683. foreach ($resultExtra as $field) {
  1684. $field = $field['value'];
  1685. if ($workingTime == $field->getField()->getVariable()) {
  1686. echo '<td class="text-center">'.$field->getValue().'</td>';
  1687. }
  1688. }
  1689. echo '</tr>';
  1690. }
  1691. }
  1692. echo '</tbody>
  1693. </table>
  1694. </div>
  1695. ';
  1696. $csv_content[] = [];
  1697. $csv_content[] = [
  1698. get_lang('OtherTools'),
  1699. ];
  1700. $csv_content[] = [
  1701. get_lang('Student_publication'),
  1702. $nb_assignments,
  1703. ];
  1704. $csv_content[] = [
  1705. get_lang('Messages'),
  1706. $messages,
  1707. ];
  1708. $csv_content[] = [
  1709. get_lang('LinksDetails'),
  1710. $links,
  1711. ];
  1712. $csv_content[] = [
  1713. get_lang('DocumentsDetails'),
  1714. $documents,
  1715. ];
  1716. $csv_content[] = [
  1717. get_lang('UploadedDocuments'),
  1718. $uploaded_documents,
  1719. ];
  1720. $csv_content[] = [
  1721. get_lang('ChatLastConnection'),
  1722. $chat_last_connection,
  1723. ];
  1724. } //end details
  1725. if ($allowMessages === true) {
  1726. // Messages
  1727. echo Display::page_subheader2(get_lang('Messages'));
  1728. echo MessageManager::getMessagesAboutUserToString($user_info);
  1729. echo Display::url(
  1730. get_lang('NewMessage'),
  1731. 'javascript: void(0);',
  1732. [
  1733. 'onClick' => "$('#compose_message').show();",
  1734. 'class' => 'btn btn-default',
  1735. ]
  1736. );
  1737. $form = new FormValidator(
  1738. 'messages',
  1739. 'post',
  1740. $currentUrl.'&action=send_message'
  1741. );
  1742. $form->addHtml('<div id="compose_message" style="display:none;">');
  1743. $form->addText('subject', get_lang('Subject'));
  1744. $form->addHtmlEditor('message', get_lang('Message'));
  1745. $form->addButtonSend(get_lang('Send'));
  1746. $form->addHidden('sec_token', $token);
  1747. $form->addHtml('</div>');
  1748. $form->display();
  1749. }
  1750. $allow = api_get_configuration_value('allow_user_message_tracking');
  1751. if ($allow && (api_is_drh() || api_is_platform_admin())) {
  1752. $users = MessageManager::getUsersThatHadConversationWithUser($student_id);
  1753. echo Display::page_subheader2(get_lang('MessageTracking'));
  1754. $table = new HTML_Table(['class' => 'table']);
  1755. $column = 0;
  1756. $row = 0;
  1757. $headers = [
  1758. get_lang('User'),
  1759. ];
  1760. foreach ($headers as $header) {
  1761. $table->setHeaderContents($row, $column, $header);
  1762. $column++;
  1763. }
  1764. $column = 0;
  1765. $row++;
  1766. foreach ($users as $userFollowed) {
  1767. $followedUserId = $userFollowed['user_id'];
  1768. $url = api_get_path(WEB_CODE_PATH).'tracking/messages.php?from_user='.$student_id.'&to_user='.$followedUserId;
  1769. $link = Display::url(
  1770. $userFollowed['complete_name'],
  1771. $url
  1772. );
  1773. $table->setCellContents($row, $column, $link);
  1774. $row++;
  1775. }
  1776. $table->display();
  1777. }
  1778. if ($pluginCalendar) {
  1779. echo $plugin->getUserStatsPanel($student_id, $courses_in_session);
  1780. }
  1781. if ($export) {
  1782. ob_end_clean();
  1783. switch ($export) {
  1784. case 'csv':
  1785. Export::arrayToCsv($csv_content, 'reporting_student');
  1786. break;
  1787. case 'xls':
  1788. Export::arrayToXls($csv_content, 'reporting_student');
  1789. break;
  1790. }
  1791. exit;
  1792. }
  1793. Display::display_footer();