myStudents.php 73 KB

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