myStudents.php 71 KB

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