exams.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Exams script
  5. * @package chamilo.tracking
  6. */
  7. ////require_once '../inc/global.inc.php';
  8. $toolTable = Database::get_course_table(TABLE_TOOL_LIST);
  9. $quizTable = Database::get_course_table(TABLE_QUIZ_TEST);
  10. $this_section = SECTION_TRACKING;
  11. $is_allowedToTrack = $is_courseAdmin || $is_platformAdmin || $is_courseCoach || $is_sessionAdmin;
  12. if (!$is_allowedToTrack) {
  13. api_not_allowed();
  14. }
  15. $exportToXLS = false;
  16. if (isset($_GET['export'])) {
  17. $exportToXLS = true;
  18. }
  19. if (api_is_platform_admin() && empty($_GET['cidReq'])) {
  20. $global = true;
  21. } else {
  22. $global = false;
  23. }
  24. $courseList = array();
  25. if ($global) {
  26. $temp = CourseManager::get_courses_list();
  27. foreach ($temp as $tempCourse) {
  28. $courseInfo = api_get_course_info($tempCourse['code']);
  29. $courseList[] = $courseInfo;
  30. }
  31. } else {
  32. $courseList = array(api_get_course_info());
  33. }
  34. $sessionId = api_get_session_id();
  35. if (empty($sessionId)) {
  36. $sessionCondition = ' AND session_id = 0';
  37. } else {
  38. $sessionCondition = api_get_session_condition($sessionId, true, true);
  39. }
  40. $form = new FormValidator('search_simple', 'POST', '', '', null, false);
  41. $form->addElement('text', 'score', get_lang('Percentage'));
  42. if ($global) {
  43. $form->addElement('hidden', 'view', 'admin');
  44. } else {
  45. // Get exam lists
  46. $courseId = api_get_course_int_id();
  47. $sql = "SELECT quiz.title, id FROM $quizTable AS quiz
  48. WHERE
  49. c_id = $courseId AND
  50. active = 1
  51. $sessionCondition
  52. ORDER BY quiz.title ASC";
  53. $result = Database::query($sql);
  54. $exerciseList = array(get_lang('All'));
  55. while ($row = Database::fetch_array($result)) {
  56. $exerciseList[$row['id']] = $row['title'];
  57. }
  58. $form->addElement('select', 'exercise_id', get_lang('Exercise'), $exerciseList);
  59. }
  60. $form->addButtonFilter(get_lang('Filter'));
  61. $filter_score = isset($_REQUEST['score']) ? intval($_REQUEST['score']) : 70;
  62. $exerciseId = isset($_REQUEST['exercise_id']) ? intval($_REQUEST['exercise_id']) : 0;
  63. $form->setDefaults(array('score' => $filter_score));
  64. if (!$exportToXLS) {
  65. Display :: display_header(get_lang('Reporting'));
  66. $actionsLeft = $actionsRight ='';
  67. if ($global) {
  68. $actionsLeft .= '<a href="'.api_get_path(WEB_CODE_PATH).'auth/my_progress.php">'.
  69. Display::return_icon('stats.png', get_lang('MyStats'), '', ICON_SIZE_MEDIUM);
  70. $actionsLeft .= '</a>';
  71. $courseLink = '';
  72. $courseInfo = api_get_course_info();
  73. if (!empty($courseInfo)) {
  74. $courseLink = api_get_cidreq();
  75. }
  76. $actionsRight .= '<a href="'.api_get_self().'?export=1&score='.$filter_score.'&exercise_id='.$exerciseId.'&'.$courseLink.'">'.
  77. Display::return_icon('export_excel.png',get_lang('ExportAsXLS'),'',ICON_SIZE_MEDIUM).'</a>';
  78. $actionsRight .= '<a href="javascript: void(0);" onclick="javascript: window.print()">'.
  79. Display::return_icon('printer.png',get_lang('Print'),'',ICON_SIZE_MEDIUM).'</a>';
  80. $menuItems[] = Display::url(
  81. Display::return_icon('teacher.png', get_lang('TeacherInterface'), array(), 32),
  82. api_get_path(WEB_CODE_PATH).'mySpace/?view=teacher'
  83. );
  84. if (api_is_platform_admin()) {
  85. $menuItems[] = Display::url(
  86. Display::return_icon('star.png', get_lang('AdminInterface'), array(), 32),
  87. api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php'
  88. );
  89. } else {
  90. $menuItems[] = Display::url(
  91. Display::return_icon('star.png', get_lang('CoachInterface'), array(), 32),
  92. api_get_path(WEB_CODE_PATH).'mySpace/index.php?view=coach'
  93. );
  94. }
  95. $menuItems[] = '<a href="#">'.Display::return_icon('quiz_na.png', get_lang('ExamTracking'), array(), 32).'</a>';
  96. $nb_menu_items = count($menuItems);
  97. if ($nb_menu_items > 1) {
  98. foreach ($menuItems as $key=> $item) {
  99. $actionsLeft .= $item;
  100. }
  101. }
  102. } else {
  103. $actionsLeft .= Display::url(
  104. Display::return_icon('user.png', get_lang('StudentsTracking'), array(), 32),
  105. 'courseLog.php?'.api_get_cidreq().'&studentlist=true'
  106. );
  107. $actionsLeft .= Display::url(
  108. Display::return_icon('course.png', get_lang('CourseTracking'), array(), 32),
  109. 'courseLog.php?'.api_get_cidreq().'&studentlist=false'
  110. );
  111. $actionsLeft .= Display::url(
  112. Display::return_icon('tools.png', get_lang('ResourcesTracking'), array(), 32),
  113. 'courseLog.php?'.api_get_cidreq().'&studentlist=resouces'
  114. );
  115. $actionsLeft .= Display::url(
  116. Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), array(), 32),
  117. api_get_self().'?'.api_get_cidreq().'&export=1&score='.$filter_score.'&exercise_id='.$exerciseId
  118. );
  119. }
  120. $toolbar = Display::toolbarAction('toolbar-exams', $content = array( 0 => $actionsLeft, 1 => $actionsRight ));
  121. echo $toolbar;
  122. $form->display();
  123. echo '<h3>'.sprintf(get_lang('FilteringWithScoreX'), $filter_score).'%</h3>';
  124. }
  125. $html = null;
  126. if ($global) {
  127. $html .= '<table class="data_table">';
  128. $html .= '<tr><th>'.get_lang('Courses').'</th>';
  129. $html .= '<th>'.get_lang('Quiz').'</th>';
  130. $html .= '<th>'.get_lang('ExamTaken').'</th>';
  131. $html .= '<th>'.get_lang('ExamNotTaken').'</th>';
  132. $html .= '<th>'.sprintf(get_lang('ExamPassX'), $filter_score).'%</th>';
  133. $html .= '<th>'.get_lang('ExamFail').'</th>';
  134. $html .= '<th>'.get_lang('TotalStudents').'</th>';
  135. $html .= '</tr>';
  136. } else {
  137. $html .= '<table class="data_table">';
  138. $html .= '<tr><th>'.get_lang('Quiz').'</th>';
  139. $html .= '<th>'.get_lang('User').'</th>';
  140. //$html .= '<th>'.sprintf(get_lang('ExamPassX'), $filter_score).'</th>';
  141. $html .= '<th>'.get_lang('Percentage').' %</th>';
  142. $html .= '<th>'.get_lang('Status').'</th>';
  143. $html .= '<th>'.get_lang('Attempts').'</th>';
  144. $html .= '</tr>';
  145. }
  146. $export_array_global = $export_array = array();
  147. $s_css_class = null;
  148. if (!empty($courseList) && is_array($courseList)) {
  149. foreach ($courseList as $courseInfo) {
  150. $sessionList = SessionManager::get_session_by_course($courseInfo['real_id']);
  151. $newSessionList = array();
  152. if (!empty($sessionList)) {
  153. foreach ($sessionList as $session) {
  154. $newSessionList[$session['id']] = $session['name'];
  155. }
  156. }
  157. $courseId = $courseInfo['real_id'];
  158. if ($global) {
  159. $sql = "SELECT count(id) as count
  160. FROM $quizTable AS quiz
  161. WHERE c_id = $courseId AND active = 1 AND (session_id = 0 OR session_id IS NULL)";
  162. $result = Database::query($sql);
  163. $countExercises = Database::store_result($result);
  164. $exerciseCount = $countExercises[0]['count'];
  165. $sql = "SELECT count(id) as count
  166. FROM $quizTable AS quiz
  167. WHERE c_id = $courseId AND active = 1 AND session_id <> 0";
  168. $result = Database::query($sql);
  169. $countExercises = Database::store_result($result);
  170. $exerciseSessionCount = $countExercises[0]['count'];
  171. $exerciseCount = $exerciseCount + $exerciseCount * count($newSessionList) + $exerciseSessionCount;
  172. // Add course and session list.
  173. if ($exerciseCount == 0) {
  174. $exerciseCount = 2;
  175. }
  176. $html .= "<tr>
  177. <td rowspan=$exerciseCount>";
  178. $html .= $courseInfo['title'];
  179. $html .= "</td>";
  180. }
  181. $sql = "SELECT visibility FROM $toolTable
  182. WHERE c_id = $courseId AND name = 'quiz'";
  183. $result = Database::query($sql);
  184. // If main tool is visible.
  185. if (Database::result($result, 0, 'visibility') == 1) {
  186. // Getting the exam list.
  187. if ($global) {
  188. $sql = "SELECT quiz.title, id, session_id
  189. FROM $quizTable AS quiz
  190. WHERE c_id = $courseId AND active = 1
  191. ORDER BY session_id, quiz.title ASC";
  192. } else {
  193. //$sessionCondition = api_get_session_condition($sessionId, true, false);
  194. if (!empty($exerciseId)) {
  195. $sql = "SELECT quiz.title, id, session_id
  196. FROM $quizTable AS quiz
  197. WHERE
  198. c_id = $courseId AND
  199. active = 1 AND
  200. id = $exerciseId
  201. $sessionCondition
  202. ORDER BY session_id, quiz.title ASC";
  203. } else {
  204. $sql = "SELECT quiz.title, id, session_id
  205. FROM $quizTable AS quiz
  206. WHERE
  207. c_id = $courseId AND
  208. active = 1
  209. $sessionCondition
  210. ORDER BY session_id, quiz.title ASC";
  211. }
  212. }
  213. $resultExercises = Database::query($sql);
  214. if (Database::num_rows($resultExercises) > 0) {
  215. $export_array_global = array();
  216. while ($exercise = Database::fetch_array($resultExercises, 'ASSOC')) {
  217. $exerciseSessionId = $exercise['session_id'];
  218. if (empty($exerciseSessionId)) {
  219. if ($global) {
  220. // If the exercise was created in the base course.
  221. // Load all sessions.
  222. foreach ($newSessionList as $currentSessionId => $sessionName) {
  223. $result = processStudentList(
  224. $filter_score,
  225. $global,
  226. $exercise,
  227. $courseInfo,
  228. $currentSessionId,
  229. $newSessionList
  230. );
  231. $html .= $result['html'];
  232. $export_array_global = array_merge($export_array_global, $result['export_array_global']);
  233. }
  234. // Load base course.
  235. $result = processStudentList(
  236. $filter_score,
  237. $global,
  238. $exercise,
  239. $courseInfo,
  240. 0,
  241. $newSessionList
  242. );
  243. $html .= $result['html'];
  244. $export_array_global = array_merge($export_array_global, $result['export_array_global']);
  245. } else {
  246. if (empty($sessionId)) {
  247. // Load base course.
  248. $result = processStudentList(
  249. $filter_score,
  250. $global,
  251. $exercise,
  252. $courseInfo,
  253. 0,
  254. $newSessionList
  255. );
  256. $html .= $result['html'];
  257. $export_array_global = array_merge(
  258. $export_array_global,
  259. $result['export_array_global']
  260. );
  261. } else {
  262. $result = processStudentList(
  263. $filter_score,
  264. $global,
  265. $exercise,
  266. $courseInfo,
  267. $sessionId,
  268. $newSessionList
  269. );
  270. $html .= $result['html'];
  271. $export_array_global = array_merge(
  272. $export_array_global,
  273. $result['export_array_global']
  274. );
  275. }
  276. }
  277. } else {
  278. // If the exercise only exists in this session.
  279. $result = processStudentList(
  280. $filter_score,
  281. $global,
  282. $exercise,
  283. $courseInfo,
  284. $exerciseSessionId,
  285. $newSessionList
  286. );
  287. $html .= $result['html'];
  288. $export_array_global = array_merge(
  289. $export_array_global,
  290. $result['export_array_global']
  291. );
  292. }
  293. }
  294. } else {
  295. $html .= "<tr>
  296. <td colspan='6'>
  297. ".get_lang('NoExercise')."
  298. </td>
  299. </tr>
  300. ";
  301. }
  302. } else {
  303. $html .= "<tr>
  304. <td colspan='6'>
  305. ".get_lang('NoExercise')."
  306. </td>
  307. </tr>
  308. ";
  309. }
  310. }
  311. }
  312. $html .= '</table>';
  313. if (!$exportToXLS) {
  314. echo $html;
  315. }
  316. $filename = 'exam-reporting-'.api_get_local_time().'.xlsx';
  317. if ($exportToXLS) {
  318. if ($global) {
  319. export_complete_report_xls($filename, $export_array_global);
  320. } else {
  321. export_complete_report_xls($filename, $export_array);
  322. }
  323. exit;
  324. }
  325. /**
  326. * @param $a
  327. * @param $b
  328. * @return int
  329. */
  330. function sort_user($a, $b) {
  331. if (is_numeric($a['score']) && is_numeric($b['score'])) {
  332. if ($a['score'] < $b['score']) {
  333. return 1;
  334. }
  335. return 0;
  336. }
  337. return 1;
  338. }
  339. /**
  340. * @param string $filename
  341. * @param array $array
  342. */
  343. function export_complete_report_xls($filename, $array)
  344. {
  345. global $global, $filter_score;
  346. $spreadsheet = new PHPExcel();
  347. $spreadsheet->setActiveSheetIndex(0);
  348. $worksheet = $spreadsheet->getActiveSheet();
  349. $line = 0;
  350. $column = 0; //skip the first column (row titles)
  351. if ($global) {
  352. $worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('Courses'));
  353. $column++;
  354. $worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('Exercises'));
  355. $column++;
  356. $worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('ExamTaken'));
  357. $column++;
  358. $worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('ExamNotTaken'));
  359. $column++;
  360. $worksheet->SetCellValueByColumnAndRow($line, $column, sprintf(get_lang('ExamPassX'), $filter_score) . '%');
  361. $column++;
  362. $worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('ExamFail'));
  363. $column++;
  364. $worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('TotalStudents'));
  365. $column++;
  366. $line++;
  367. foreach ($array as $row) {
  368. $column = 0;
  369. foreach ($row as $item) {
  370. $worksheet->SetCellValueByColumnAndRow($line, $column, html_entity_decode(strip_tags($item)));
  371. $column++;
  372. }
  373. $line++;
  374. }
  375. $line++;
  376. } else {
  377. $worksheet->SetCellValueByColumnAndRow($line,$column,get_lang('Exercises'));
  378. $column++;
  379. $worksheet->SetCellValueByColumnAndRow($line,$column,get_lang('User'));
  380. $column++;
  381. $worksheet->SetCellValueByColumnAndRow($line,$column,get_lang('Percentage'));
  382. $column++;
  383. $worksheet->SetCellValueByColumnAndRow($line,$column,get_lang('Status'));
  384. $column++;
  385. $worksheet->SetCellValueByColumnAndRow($line,$column,get_lang('Attempts'));
  386. $column++;
  387. $line++;
  388. foreach ($array as $row) {
  389. $column = 0;
  390. $worksheet->SetCellValueByColumnAndRow(
  391. $line,
  392. $column,
  393. html_entity_decode(strip_tags($row['exercise']))
  394. );
  395. $column++;
  396. foreach ($row['users'] as $key=>$user) {
  397. $column = 1;
  398. $worksheet->SetCellValueByColumnAndRow(
  399. $line,
  400. $column,
  401. html_entity_decode(strip_tags($user))
  402. );
  403. $column++;
  404. foreach ($row['results'][$key] as $result_item) {
  405. $worksheet->SetCellValueByColumnAndRow(
  406. $line,
  407. $column,
  408. html_entity_decode(strip_tags($result_item))
  409. );
  410. $column++;
  411. }
  412. $line++;
  413. }
  414. }
  415. $line++;
  416. }
  417. $file = api_get_path(SYS_ARCHIVE_PATH).api_replace_dangerous_char($filename);
  418. $writer = new PHPExcel_Writer_Excel2007($spreadsheet);
  419. $writer->save($file);
  420. DocumentManager::file_send_for_download($file, true, $filename);
  421. exit;
  422. }
  423. /**
  424. * @param $filter_score
  425. * @param $global
  426. * @param $exercise
  427. * @param $courseInfo
  428. * @param $sessionId
  429. * @param $newSessionList
  430. * @return array
  431. */
  432. function processStudentList($filter_score, $global, $exercise, $courseInfo, $sessionId, $newSessionList)
  433. {
  434. if (
  435. (isset($exercise['id']) && empty($exercise['id'])) ||
  436. !isset($exercise['id'])
  437. ) {
  438. return array(
  439. 'html' => '',
  440. 'export_array_global' => [],
  441. 'total_students' => 0
  442. );
  443. }
  444. $exerciseStatsTable = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  445. $courseId = api_get_course_int_id($courseInfo['code']);
  446. if (empty($sessionId)) {
  447. $students = CourseManager::get_student_list_from_course_code(
  448. $courseInfo['code'],
  449. false,
  450. 0,
  451. null,
  452. null,
  453. false
  454. );
  455. } else {
  456. $students = CourseManager::get_student_list_from_course_code(
  457. $courseInfo['code'],
  458. true,
  459. $sessionId,
  460. null,
  461. null,
  462. false
  463. );
  464. }
  465. $html = null;
  466. $totalStudents = count($students);
  467. if (!$global) {
  468. $html .= "<tr>";
  469. }
  470. if (!$global) {
  471. $html .= '<td rowspan="'.$totalStudents.'">';
  472. } else {
  473. $html .= '<td>';
  474. }
  475. $html .= $exercise['title'];
  476. if ($global && !empty($sessionId)) {
  477. $sessionName = isset($newSessionList[$sessionId]) ? $newSessionList[$sessionId] : null;
  478. $html .= Display::return_icon('star.png', get_lang('Session')).' ('.$sessionName.')';
  479. }
  480. $html .= '</td>';
  481. $globalRow = array(
  482. $courseInfo['title'],
  483. $exercise['title']
  484. );
  485. $total_with_parameter_score = 0;
  486. $taken = 0;
  487. $export_array_global = array();
  488. $studentResult = array();
  489. foreach ($students as $student) {
  490. $studentId = isset($student['user_id']) ? $student['user_id'] : $student['id_user'];
  491. $sql = "SELECT COUNT(ex.exe_id) as count
  492. FROM $exerciseStatsTable AS ex
  493. WHERE
  494. ex.c_id = $courseId AND
  495. ex.exe_exo_id = ".$exercise['id']." AND
  496. exe_user_id= $studentId AND
  497. session_id = $sessionId
  498. ";
  499. $result = Database::query($sql);
  500. $attempts = Database::fetch_array($result);
  501. $sql = "SELECT exe_id, exe_result, exe_weighting
  502. FROM $exerciseStatsTable
  503. WHERE
  504. exe_user_id = $studentId AND
  505. c_id = $courseId AND
  506. exe_exo_id = ".$exercise['id']." AND
  507. session_id = $sessionId
  508. ORDER BY exe_result DESC
  509. LIMIT 1";
  510. $result = Database::query($sql);
  511. $score = 0;
  512. $weighting = 0;
  513. while ($scoreInfo = Database::fetch_array($result)) {
  514. $score = $score + $scoreInfo['exe_result'];
  515. $weighting = $weighting + $scoreInfo['exe_weighting'];
  516. }
  517. $percentageScore = 0;
  518. if ($weighting != 0) {
  519. $percentageScore = round(($score*100)/$weighting);
  520. }
  521. if ($attempts['count'] > 0 ) {
  522. $taken++;
  523. }
  524. if ($percentageScore >= $filter_score) {
  525. $total_with_parameter_score++;
  526. }
  527. $tempArray = array();
  528. if (!$global) {
  529. $userInfo = api_get_user_info($studentId);
  530. // User
  531. $userRow = '<td>';
  532. $userRow .= $userInfo['complete_name'];
  533. $userRow .= '</td>';
  534. // Best result
  535. if (!empty($attempts['count'])) {
  536. $userRow .= '<td>';
  537. $userRow .= $percentageScore;
  538. $tempArray[] = $percentageScore;
  539. $userRow .= '</td>';
  540. if ($percentageScore >= $filter_score) {
  541. $userRow .= '<td style="background-color:#DFFFA8">';
  542. $userRow .= get_lang('PassExam').'</td>';
  543. $tempArray[] = get_lang('PassExam');
  544. } else {
  545. $userRow .= '<td style="background-color:#FC9A9E" >';
  546. $userRow .= get_lang('ExamFail').'</td>';
  547. $tempArray[] = get_lang('ExamFail');
  548. }
  549. $userRow .= '<td>';
  550. $userRow .= $attempts['count'];
  551. $tempArray[] = $attempts['count'];
  552. $userRow .= '</td>';
  553. } else {
  554. $score = '-';
  555. $userRow .= '<td>';
  556. $userRow .= '-';
  557. $tempArray[] = '-';
  558. $userRow .= '</td>';
  559. $userRow .= '<td style="background-color:#FCE89A">';
  560. $userRow .= get_lang('NoAttempt');
  561. $tempArray[] = get_lang('NoAttempt');
  562. $userRow .= '</td>';
  563. $userRow .= '<td>';
  564. $userRow .= 0;
  565. $tempArray[] = 0;
  566. $userRow .= '</td>';
  567. }
  568. $userRow .= '</tr>';
  569. $studentResult[$studentId] = array(
  570. 'html' => $userRow,
  571. 'score' => $score,
  572. 'array' => $tempArray,
  573. 'user' => $userInfo['complete_name']
  574. );
  575. }
  576. }
  577. $row_not_global['exercise'] = $exercise['title'];
  578. if (!$global) {
  579. if (!empty($studentResult)) {
  580. $studentResultEmpty = $studentResultContent = array();
  581. foreach ($studentResult as $row) {
  582. if ($row['score'] == '-') {
  583. $studentResultEmpty[] = $row;
  584. } else {
  585. $studentResultContent[] = $row;
  586. }
  587. }
  588. // Sort only users with content
  589. usort($studentResultContent, 'sort_user');
  590. $studentResult = array_merge($studentResultContent, $studentResultEmpty);
  591. foreach ($studentResult as $row) {
  592. $html .= $row['html'];
  593. $row_not_global['results'][] = $row['array'];
  594. $row_not_global['users'][] = $row['user'];
  595. }
  596. $export_array[] = $row_not_global;
  597. }
  598. }
  599. if ($global) {
  600. // Exam taken
  601. $html .= '<td>';
  602. $html .= $taken;
  603. $globalRow[]= $taken;
  604. $html .= '</td>';
  605. // Exam NOT taken
  606. $html .= '<td>';
  607. $html .= $not_taken = $totalStudents - $taken;
  608. $globalRow[]= $not_taken;
  609. $html .= '</td>';
  610. // Exam pass
  611. if (!empty($total_with_parameter_score)) {
  612. $html .= '<td style="background-color:#DFFFA8" >';
  613. } else {
  614. $html .= '<td style="background-color:#FCE89A" >';
  615. }
  616. $html .= $total_with_parameter_score;
  617. $globalRow[]= $total_with_parameter_score;
  618. $html .= '</td>';
  619. // Exam fail
  620. $html .= '<td>';
  621. $html .= $fail = $taken - $total_with_parameter_score;
  622. $globalRow[]= $fail;
  623. $html .= '</td>';
  624. $html .= '<td>';
  625. $html .= $totalStudents;
  626. $globalRow[]= $totalStudents;
  627. $html .= '</td>';
  628. $html .= '</tr>';
  629. $export_array_global[] = $globalRow;
  630. }
  631. return array(
  632. 'html' => $html,
  633. 'export_array_global' => $export_array_global,
  634. 'total_students' => $totalStudents
  635. );
  636. }
  637. Display :: display_footer();