exercise_report.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Exercise list: This script shows the list of exercises for administrators and students.
  5. *
  6. * @package chamilo.exercise
  7. *
  8. * @author Julio Montoya <gugli100@gmail.com> jqgrid integration
  9. * Modified by hubert.borderiou (question category)
  10. *
  11. * @todo fix excel export
  12. */
  13. require_once __DIR__.'/../inc/global.inc.php';
  14. // Setting the tabs
  15. $this_section = SECTION_COURSES;
  16. $htmlHeadXtra[] = api_get_jqgrid_js();
  17. $filter_user = isset($_REQUEST['filter_by_user']) ? (int) $_REQUEST['filter_by_user'] : null;
  18. $isBossOfStudent = false;
  19. if (api_is_student_boss() && !empty($filter_user)) {
  20. // Check if boss has access to user info.
  21. if (UserManager::userIsBossOfStudent(api_get_user_id(), $filter_user)) {
  22. $isBossOfStudent = true;
  23. } else {
  24. api_not_allowed(true);
  25. }
  26. } else {
  27. api_protect_course_script(true, false, true);
  28. }
  29. $limitTeacherAccess = api_get_configuration_value('limit_exercise_teacher_access');
  30. if ($limitTeacherAccess && !api_is_platform_admin()) {
  31. api_not_allowed(true);
  32. }
  33. // including additional libraries
  34. require_once 'hotpotatoes.lib.php';
  35. $_course = api_get_course_info();
  36. // document path
  37. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
  38. $origin = api_get_origin();
  39. $path = isset($_GET['path']) ? Security::remove_XSS($_GET['path']) : null;
  40. /* Constants and variables */
  41. $is_allowedToEdit = api_is_allowed_to_edit(null, true) ||
  42. api_is_drh() ||
  43. api_is_student_boss() ||
  44. api_is_session_admin();
  45. $is_tutor = api_is_allowed_to_edit(true);
  46. $TBL_TRACK_EXERCISES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  47. $TBL_TRACK_ATTEMPT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  48. $TBL_TRACK_ATTEMPT_RECORDING = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
  49. $TBL_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  50. $allowCoachFeedbackExercises = api_get_setting('allow_coach_feedback_exercises') === 'true';
  51. $course_id = api_get_course_int_id();
  52. $exercise_id = isset($_REQUEST['exerciseId']) ? (int) $_REQUEST['exerciseId'] : 0;
  53. $locked = api_resource_is_locked_by_gradebook($exercise_id, LINK_EXERCISE);
  54. $sessionId = api_get_session_id();
  55. if (empty($exercise_id)) {
  56. api_not_allowed(true);
  57. }
  58. $blockPage = true;
  59. if (empty($sessionId)) {
  60. if ($is_allowedToEdit) {
  61. $blockPage = false;
  62. }
  63. } else {
  64. if ($allowCoachFeedbackExercises && api_is_coach($sessionId, $course_id)) {
  65. $blockPage = false;
  66. } else {
  67. if ($is_allowedToEdit) {
  68. $blockPage = false;
  69. }
  70. }
  71. }
  72. if ($blockPage) {
  73. api_not_allowed(true);
  74. }
  75. if (!empty($exercise_id)) {
  76. $parameters['exerciseId'] = $exercise_id;
  77. }
  78. if (!empty($_GET['path'])) {
  79. $parameters['path'] = Security::remove_XSS($_GET['path']);
  80. }
  81. if (!empty($_REQUEST['export_report']) && $_REQUEST['export_report'] == '1') {
  82. if (api_is_platform_admin() || api_is_course_admin() ||
  83. api_is_course_tutor() || api_is_session_general_coach()
  84. ) {
  85. $loadExtraData = false;
  86. if (isset($_REQUEST['extra_data']) && $_REQUEST['extra_data'] == 1) {
  87. $loadExtraData = true;
  88. }
  89. $includeAllUsers = false;
  90. if (isset($_REQUEST['include_all_users']) &&
  91. $_REQUEST['include_all_users'] == 1
  92. ) {
  93. $includeAllUsers = true;
  94. }
  95. $onlyBestAttempts = false;
  96. if (isset($_REQUEST['only_best_attempts']) &&
  97. $_REQUEST['only_best_attempts'] == 1
  98. ) {
  99. $onlyBestAttempts = true;
  100. }
  101. require_once 'exercise_result.class.php';
  102. $export = new ExerciseResult();
  103. $export->setIncludeAllUsers($includeAllUsers);
  104. $export->setOnlyBestAttempts($onlyBestAttempts);
  105. switch ($_GET['export_format']) {
  106. case 'xls':
  107. $export->exportCompleteReportXLS(
  108. $documentPath,
  109. null,
  110. $loadExtraData,
  111. null,
  112. $_GET['exerciseId']
  113. );
  114. exit;
  115. break;
  116. case 'csv':
  117. default:
  118. $export->exportCompleteReportCSV(
  119. $documentPath,
  120. null,
  121. $loadExtraData,
  122. null,
  123. $_GET['exerciseId']
  124. );
  125. exit;
  126. break;
  127. }
  128. } else {
  129. api_not_allowed(true);
  130. }
  131. }
  132. $objExerciseTmp = new Exercise();
  133. $exerciseExists = $objExerciseTmp->read($exercise_id);
  134. $courseInfo = api_get_course_info();
  135. //Send student email @todo move this code in a class, library
  136. if (isset($_REQUEST['comments']) &&
  137. $_REQUEST['comments'] == 'update' &&
  138. ($is_allowedToEdit || $is_tutor || $allowCoachFeedbackExercises)
  139. ) {
  140. // Filtered by post-condition
  141. $id = intval($_GET['exeid']);
  142. $track_exercise_info = ExerciseLib::get_exercise_track_exercise_info($id);
  143. if (empty($track_exercise_info)) {
  144. api_not_allowed();
  145. }
  146. $test = $track_exercise_info['title'];
  147. $student_id = $track_exercise_info['exe_user_id'];
  148. $session_id = $track_exercise_info['session_id'];
  149. $lp_id = $track_exercise_info['orig_lp_id'];
  150. $lpItemId = $track_exercise_info['orig_lp_item_id'];
  151. $lp_item_view_id = $track_exercise_info['orig_lp_item_view_id'];
  152. $exerciseId = $track_exercise_info['exe_exo_id'];
  153. $exeWeighting = $track_exercise_info['exe_weighting'];
  154. $url = api_get_path(WEB_CODE_PATH).'exercise/result.php?id='.$track_exercise_info['exe_id'].'&'.api_get_cidreq().'&show_headers=1&id_session='.$session_id;
  155. $my_post_info = [];
  156. $post_content_id = [];
  157. $comments_exist = false;
  158. foreach ($_POST as $key_index => $key_value) {
  159. $my_post_info = explode('_', $key_index);
  160. $post_content_id[] = isset($my_post_info[1]) ? $my_post_info[1] : null;
  161. if ($my_post_info[0] == 'comments') {
  162. $comments_exist = true;
  163. }
  164. }
  165. $loop_in_track = $comments_exist === true ? (count($_POST) / 2) : count($_POST);
  166. $array_content_id_exe = [];
  167. if ($comments_exist === true) {
  168. $array_content_id_exe = array_slice($post_content_id, $loop_in_track);
  169. } else {
  170. $array_content_id_exe = $post_content_id;
  171. }
  172. for ($i = 0; $i < $loop_in_track; $i++) {
  173. $my_marks = isset($_POST['marks_'.$array_content_id_exe[$i]]) ? $_POST['marks_'.$array_content_id_exe[$i]] : '';
  174. $my_comments = '';
  175. if (isset($_POST['comments_'.$array_content_id_exe[$i]])) {
  176. $my_comments = $_POST['comments_'.$array_content_id_exe[$i]];
  177. }
  178. $my_questionid = intval($array_content_id_exe[$i]);
  179. $params = [
  180. 'marks' => $my_marks,
  181. 'teacher_comment' => $my_comments,
  182. ];
  183. Database::update(
  184. $TBL_TRACK_ATTEMPT,
  185. $params,
  186. ['question_id = ? AND exe_id = ?' => [$my_questionid, $id]]
  187. );
  188. $params = [
  189. 'exe_id' => $id,
  190. 'question_id' => $my_questionid,
  191. 'marks' => $my_marks,
  192. 'insert_date' => api_get_utc_datetime(),
  193. 'author' => api_get_user_id(),
  194. 'teacher_comment' => $my_comments,
  195. ];
  196. Database::insert($TBL_TRACK_ATTEMPT_RECORDING, $params);
  197. }
  198. $useEvaluationPlugin = false;
  199. $pluginEvaluation = QuestionOptionsEvaluationPlugin::create();
  200. if ('true' === $pluginEvaluation->get(QuestionOptionsEvaluationPlugin::SETTING_ENABLE)) {
  201. $formula = $pluginEvaluation->getFormulaForExercise($exerciseId);
  202. if (!empty($formula)) {
  203. $useEvaluationPlugin = true;
  204. }
  205. }
  206. if (!$useEvaluationPlugin) {
  207. $qry = 'SELECT DISTINCT question_id, marks
  208. FROM '.$TBL_TRACK_ATTEMPT.' WHERE exe_id = '.$id.'
  209. GROUP BY question_id';
  210. $res = Database::query($qry);
  211. $tot = 0;
  212. while ($row = Database :: fetch_array($res, 'ASSOC')) {
  213. $tot += $row['marks'];
  214. }
  215. } else {
  216. $tot = $pluginEvaluation->getResultWithFormula($id, $formula);
  217. }
  218. $sql = "UPDATE $TBL_TRACK_EXERCISES
  219. SET exe_result = '".floatval($tot)."'
  220. WHERE exe_id = ".$id;
  221. Database::query($sql);
  222. if (isset($_POST['send_notification'])) {
  223. //@todo move this somewhere else
  224. $subject = get_lang('ExamSheetVCC');
  225. $message = isset($_POST['notification_content']) ? $_POST['notification_content'] : '';
  226. MessageManager::send_message_simple(
  227. $student_id,
  228. $subject,
  229. $message,
  230. api_get_user_id()
  231. );
  232. if ($allowCoachFeedbackExercises) {
  233. Display::addFlash(
  234. Display::return_message(get_lang('MessageSent'))
  235. );
  236. }
  237. }
  238. // Updating LP score here
  239. if (!empty($lp_id) && !empty($lpItemId)) {
  240. $statusCondition = '';
  241. $item = new learnpathItem($lpItemId, api_get_user_id(), api_get_course_int_id());
  242. if ($item) {
  243. $prereqId = $item->get_prereq_string();
  244. $minScore = $item->getPrerequisiteMinScore();
  245. $maxScore = $item->getPrerequisiteMaxScore();
  246. $passed = false;
  247. $lp = new learnpath(api_get_course_id(), $lp_id, $student_id);
  248. $prereqCheck = $lp->prerequisites_match($lpItemId);
  249. if ($prereqCheck) {
  250. $passed = true;
  251. }
  252. /*$minScore = $item->getPrerequisiteMinScore();
  253. $maxScore = $item->getPrerequisiteMaxScore();
  254. $passed = false;
  255. // Check lp item min/max
  256. if (isset($minScore) && isset($maxScore)) {
  257. if ($tot >= $minScore && $tot <= $maxScore) {
  258. $passed = true;
  259. }
  260. }*/
  261. if ($passed == false) {
  262. if (!empty($objExerciseTmp->pass_percentage)) {
  263. $passed = ExerciseLib::isSuccessExerciseResult(
  264. $tot,
  265. $exeWeighting,
  266. $objExerciseTmp->pass_percentage
  267. );
  268. } else {
  269. $passed = false;
  270. }
  271. }
  272. if ($passed) {
  273. $statusCondition = ', status = "completed" ';
  274. } else {
  275. $statusCondition = ', status = "failed" ';
  276. }
  277. Display::addFlash(Display::return_message(get_lang('LearnpathUpdated')));
  278. }
  279. $sql = "UPDATE $TBL_LP_ITEM_VIEW
  280. SET score = '".floatval($tot)."'
  281. $statusCondition
  282. WHERE c_id = ".$course_id." AND id = ".$lp_item_view_id;
  283. Database::query($sql);
  284. if (empty($origin)) {
  285. header('Location: '.api_get_path(WEB_CODE_PATH).'exercise/exercise_report.php?exerciseId='.$exercise_id.'&'.api_get_cidreq());
  286. exit;
  287. }
  288. if ($origin == 'tracking_course') {
  289. //Redirect to the course detail in lp
  290. header('Location: '.api_get_path(WEB_CODE_PATH).'exercise/exercise.php?course='.Security::remove_XSS($_GET['course']));
  291. exit;
  292. } else {
  293. // Redirect to the reporting
  294. header(
  295. 'Location: '.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?origin='.$origin.'&student='.$student_id.'&details=true&course='.api_get_course_id(
  296. ).'&session_id='.$session_id
  297. );
  298. exit;
  299. }
  300. }
  301. }
  302. $actions = null;
  303. if ($is_allowedToEdit && $origin != 'learnpath') {
  304. // the form
  305. if (api_is_platform_admin() || api_is_course_admin() ||
  306. api_is_course_tutor() || api_is_session_general_coach()
  307. ) {
  308. $actions .= '<a href="exercise.php?'.api_get_cidreq().'">'.
  309. Display::return_icon('back.png', get_lang('GoBackToQuestionList'), '', ICON_SIZE_MEDIUM).'</a>';
  310. $actions .= '<a href="live_stats.php?'.api_get_cidreq().'&exerciseId='.$exercise_id.'">'.
  311. Display::return_icon('activity_monitor.png', get_lang('LiveResults'), '', ICON_SIZE_MEDIUM).'</a>';
  312. $actions .= '<a href="stats.php?'.api_get_cidreq().'&exerciseId='.$exercise_id.'">'.
  313. Display::return_icon('statistics.png', get_lang('ReportByQuestion'), '', ICON_SIZE_MEDIUM).'</a>';
  314. $actions .= '<a id="export_opener" href="'.api_get_self().'?export_report=1&exerciseId='.intval($_GET['exerciseId']).'" >'.
  315. Display::return_icon('save.png', get_lang('Export'), '', ICON_SIZE_MEDIUM).'</a>';
  316. // clean result before a selected date icon
  317. $actions .= Display::url(
  318. Display::return_icon(
  319. 'clean_before_date.png',
  320. get_lang('CleanStudentsResultsBeforeDate'),
  321. '',
  322. ICON_SIZE_MEDIUM
  323. ),
  324. '#',
  325. ['onclick' => "javascript:display_date_picker()"]
  326. );
  327. // clean result before a selected date datepicker popup
  328. $actions .= Display::span(
  329. Display::input(
  330. 'input',
  331. 'datepicker_start',
  332. get_lang('SelectADateOnTheCalendar'),
  333. [
  334. 'onmouseover' => 'datepicker_input_mouseover()',
  335. 'id' => 'datepicker_start',
  336. 'onchange' => 'datepicker_input_changed()',
  337. 'readonly' => 'readonly',
  338. ]
  339. ).
  340. Display::button(
  341. 'delete',
  342. get_lang('Delete'),
  343. ['onclick' => 'submit_datepicker()']
  344. ),
  345. ['style' => 'display:none', 'id' => 'datepicker_span']
  346. );
  347. }
  348. } else {
  349. $actions .= '<a href="exercise.php">'.
  350. Display::return_icon(
  351. 'back.png',
  352. get_lang('GoBackToQuestionList'),
  353. '',
  354. ICON_SIZE_MEDIUM
  355. ).
  356. '</a>';
  357. }
  358. // Deleting an attempt
  359. if (($is_allowedToEdit || $is_tutor || api_is_coach()) &&
  360. isset($_GET['delete']) && $_GET['delete'] == 'delete' &&
  361. !empty($_GET['did']) && $locked == false
  362. ) {
  363. $exe_id = intval($_GET['did']);
  364. if (!empty($exe_id)) {
  365. $sql = 'DELETE FROM '.$TBL_TRACK_EXERCISES.' WHERE exe_id = '.$exe_id;
  366. Database::query($sql);
  367. $sql = 'DELETE FROM '.$TBL_TRACK_ATTEMPT.' WHERE exe_id = '.$exe_id;
  368. Database::query($sql);
  369. Event::addEvent(
  370. LOG_EXERCISE_ATTEMPT_DELETE,
  371. LOG_EXERCISE_ATTEMPT,
  372. $exe_id,
  373. api_get_utc_datetime()
  374. );
  375. header('Location: exercise_report.php?'.api_get_cidreq().'&exerciseId='.$exercise_id);
  376. exit;
  377. }
  378. }
  379. if ($is_allowedToEdit || $is_tutor) {
  380. $interbreadcrumb[] = [
  381. "url" => "exercise.php?".api_get_cidreq(),
  382. "name" => get_lang('Exercises'),
  383. ];
  384. $nameTools = get_lang('StudentScore');
  385. if ($exerciseExists) {
  386. $interbreadcrumb[] = [
  387. "url" => '#',
  388. "name" => $objExerciseTmp->selectTitle(true),
  389. ];
  390. }
  391. } else {
  392. $interbreadcrumb[] = [
  393. "url" => "exercise.php?".api_get_cidreq(),
  394. "name" => get_lang('Exercises'),
  395. ];
  396. if ($exerciseExists) {
  397. $nameTools = get_lang('Results').': '.$objExerciseTmp->selectTitle(true);
  398. }
  399. }
  400. if (($is_allowedToEdit || $is_tutor || api_is_coach()) &&
  401. isset($_GET['a']) && $_GET['a'] == 'close' &&
  402. !empty($_GET['id']) && $locked == false
  403. ) {
  404. // Close the user attempt otherwise left pending
  405. $exe_id = intval($_GET['id']);
  406. $sql = "UPDATE $TBL_TRACK_EXERCISES SET status = ''
  407. WHERE exe_id = $exe_id AND status = 'incomplete'";
  408. Database::query($sql);
  409. }
  410. Display :: display_header($nameTools);
  411. // Clean all results for this test before the selected date
  412. if (($is_allowedToEdit || $is_tutor || api_is_coach()) &&
  413. isset($_GET['delete_before_date']) && $locked == false
  414. ) {
  415. // ask for the date
  416. $check = Security::check_token('get');
  417. if ($check) {
  418. $objExerciseTmp = new Exercise();
  419. if ($objExerciseTmp->read($exercise_id)) {
  420. $count = $objExerciseTmp->cleanResults(
  421. true,
  422. $_GET['delete_before_date'].' 23:59:59'
  423. );
  424. echo Display::return_message(
  425. sprintf(get_lang('XResultsCleaned'), $count),
  426. 'confirm'
  427. );
  428. }
  429. }
  430. }
  431. // Security token to protect deletion
  432. $token = Security::get_token();
  433. $actions = Display::div($actions, ['class' => 'actions']);
  434. $extra = '<script>
  435. $(function() {
  436. $( "#dialog:ui-dialog" ).dialog( "destroy" );
  437. $( "#dialog-confirm" ).dialog({
  438. autoOpen: false,
  439. show: "blind",
  440. resizable: false,
  441. height:300,
  442. modal: true
  443. });
  444. $("#export_opener").click(function() {
  445. var targetUrl = $(this).attr("href");
  446. $( "#dialog-confirm" ).dialog({
  447. width:400,
  448. height:300,
  449. buttons: {
  450. "'.addslashes(get_lang('Download')).'": function() {
  451. var export_format = $("input[name=export_format]:checked").val();
  452. var extra_data = $("input[name=load_extra_data]:checked").val();
  453. var includeAllUsers = $("input[name=include_all_users]:checked").val();
  454. var attempts = $("input[name=only_best_attempts]:checked").val();
  455. location.href = targetUrl+"&export_format="+export_format+"&extra_data="+extra_data+"&include_all_users="+includeAllUsers+"&only_best_attempts="+attempts;
  456. $( this ).dialog( "close" );
  457. }
  458. }
  459. });
  460. $( "#dialog-confirm" ).dialog("open");
  461. return false;
  462. });
  463. });
  464. </script>';
  465. $extra .= '<div id="dialog-confirm" title="'.get_lang("ConfirmYourChoice").'">';
  466. $form = new FormValidator(
  467. 'report',
  468. 'post',
  469. null,
  470. null,
  471. ['class' => 'form-vertical']
  472. );
  473. $form->addElement(
  474. 'radio',
  475. 'export_format',
  476. null,
  477. get_lang('ExportAsCSV'),
  478. 'csv',
  479. ['id' => 'export_format_csv_label']
  480. );
  481. $form->addElement(
  482. 'radio',
  483. 'export_format',
  484. null,
  485. get_lang('ExportAsXLS'),
  486. 'xls',
  487. ['id' => 'export_format_xls_label']
  488. );
  489. $form->addElement(
  490. 'checkbox',
  491. 'load_extra_data',
  492. null,
  493. get_lang('LoadExtraData'),
  494. '0',
  495. ['id' => 'export_format_xls_label']
  496. );
  497. $form->addElement(
  498. 'checkbox',
  499. 'include_all_users',
  500. null,
  501. get_lang('IncludeAllUsers'),
  502. '0'
  503. );
  504. $form->addElement(
  505. 'checkbox',
  506. 'only_best_attempts',
  507. null,
  508. get_lang('OnlyBestAttempts'),
  509. '0'
  510. );
  511. $form->setDefaults(['export_format' => 'csv']);
  512. $extra .= $form->returnForm();
  513. $extra .= '</div>';
  514. if ($is_allowedToEdit) {
  515. echo $extra;
  516. }
  517. echo $actions;
  518. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_exercise_results&exerciseId='.$exercise_id.'&filter_by_user='.$filter_user.'&'.api_get_cidreq();
  519. $action_links = '';
  520. // Generating group list
  521. $group_list = GroupManager::get_group_list();
  522. $group_parameters = [
  523. 'group_all:'.get_lang('All'),
  524. 'group_none:'.get_lang('None'),
  525. ];
  526. foreach ($group_list as $group) {
  527. $group_parameters[] = $group['id'].':'.$group['name'];
  528. }
  529. if (!empty($group_parameters)) {
  530. $group_parameters = implode(';', $group_parameters);
  531. }
  532. $officialCodeInList = api_get_setting('show_official_code_exercise_result_list');
  533. if ($is_allowedToEdit || $is_tutor) {
  534. // The order is important you need to check the the $column variable in the model.ajax.php file
  535. $columns = [
  536. get_lang('FirstName'),
  537. get_lang('LastName'),
  538. get_lang('LoginName'),
  539. get_lang('Group'),
  540. get_lang('Duration').' ('.get_lang('MinMinute').')',
  541. get_lang('StartDate'),
  542. get_lang('EndDate'),
  543. get_lang('Score'),
  544. get_lang('IP'),
  545. get_lang('Status'),
  546. get_lang('ToolLearnpath'),
  547. get_lang('Actions'),
  548. ];
  549. if ($officialCodeInList === 'true') {
  550. $columns = array_merge([get_lang('OfficialCode')], $columns);
  551. }
  552. //Column config
  553. $column_model = [
  554. ['name' => 'firstname', 'index' => 'firstname', 'width' => '50', 'align' => 'left', 'search' => 'true'],
  555. ['name' => 'lastname', 'index' => 'lastname', 'width' => '50', 'align' => 'left', 'formatter' => 'action_formatter', 'search' => 'true'],
  556. [
  557. 'name' => 'login',
  558. 'index' => 'username',
  559. 'width' => '40',
  560. 'align' => 'left',
  561. 'search' => 'true',
  562. 'hidden' => api_get_configuration_value('exercise_attempts_report_show_username') ? 'false' : 'true',
  563. ],
  564. ['name' => 'group_name', 'index' => 'group_id', 'width' => '40', 'align' => 'left', 'search' => 'true', 'stype' => 'select',
  565. //for the bottom bar
  566. 'searchoptions' => [
  567. 'defaultValue' => 'group_all',
  568. 'value' => $group_parameters, ],
  569. //for the top bar
  570. 'editoptions' => ['value' => $group_parameters], ],
  571. ['name' => 'duration', 'index' => 'exe_duration', 'width' => '30', 'align' => 'left', 'search' => 'true'],
  572. ['name' => 'start_date', 'index' => 'start_date', 'width' => '60', 'align' => 'left', 'search' => 'true'],
  573. ['name' => 'exe_date', 'index' => 'exe_date', 'width' => '60', 'align' => 'left', 'search' => 'true'],
  574. ['name' => 'score', 'index' => 'exe_result', 'width' => '50', 'align' => 'center', 'search' => 'true'],
  575. ['name' => 'ip', 'index' => 'user_ip', 'width' => '40', 'align' => 'center', 'search' => 'true'],
  576. ['name' => 'status', 'index' => 'revised', 'width' => '40', 'align' => 'left', 'search' => 'true', 'stype' => 'select',
  577. //for the bottom bar
  578. 'searchoptions' => [
  579. 'defaultValue' => '',
  580. 'value' => ':'.get_lang('All').';1:'.get_lang('Validated').';0:'.get_lang('NotValidated'), ],
  581. //for the top bar
  582. 'editoptions' => ['value' => ':'.get_lang('All').';1:'.get_lang('Validated').';0:'.get_lang('NotValidated')], ],
  583. ['name' => 'lp', 'index' => 'orig_lp_id', 'width' => '60', 'align' => 'left', 'search' => 'false'],
  584. ['name' => 'actions', 'index' => 'actions', 'width' => '60', 'align' => 'left', 'search' => 'false', 'sortable' => 'false'],
  585. ];
  586. if ($officialCodeInList == 'true') {
  587. $officialCodeRow = ['name' => 'official_code', 'index' => 'official_code', 'width' => '50', 'align' => 'left', 'search' => 'true'];
  588. $column_model = array_merge([$officialCodeRow], $column_model);
  589. }
  590. $action_links = '
  591. // add username as title in lastname filed - ref 4226
  592. function action_formatter(cellvalue, options, rowObject) {
  593. // rowObject is firstname,lastname,login,... get the third word
  594. var loginx = "'.api_htmlentities(sprintf(get_lang("LoginX"), ":::"), ENT_QUOTES).'";
  595. var tabLoginx = loginx.split(/:::/);
  596. // tabLoginx[0] is before and tabLoginx[1] is after :::
  597. // may be empty string but is defined
  598. return "<span title=\""+tabLoginx[0]+rowObject[2]+tabLoginx[1]+"\">"+cellvalue+"</span>";
  599. }';
  600. }
  601. //Autowidth
  602. $extra_params['autowidth'] = 'true';
  603. //height auto
  604. $extra_params['height'] = 'auto';
  605. ?>
  606. <script>
  607. function setSearchSelect(columnName) {
  608. $("#results").jqGrid(
  609. 'setColProp',
  610. columnName, {
  611. searchoptions:{
  612. dataInit:function(el) {
  613. $("option[value='1']",el).attr("selected", "selected");
  614. setTimeout(function(){
  615. $(el).trigger('change');
  616. },1000);
  617. }
  618. }
  619. }
  620. );
  621. }
  622. function exportExcel()
  623. {
  624. var mya=new Array();
  625. mya=$("#results").getDataIDs(); // Get All IDs
  626. var data=$("#results").getRowData(mya[0]); // Get First row to get the labels
  627. var colNames=new Array();
  628. var ii=0;
  629. for (var i in data){colNames[ii++]=i;} // capture col names
  630. var html="";
  631. for(i=0;i<mya.length;i++) {
  632. data=$("#results").getRowData(mya[i]); // get each row
  633. for(j=0;j<colNames.length;j++) {
  634. html=html+data[colNames[j]]+","; // output each column as tab delimited
  635. }
  636. html=html+"\n"; // output each row with end of line
  637. }
  638. html = html+"\n"; // end of line at the end
  639. var form = $("#export_report_form");
  640. $("#csvBuffer").attr('value', html);
  641. form.target='_blank';
  642. form.submit();
  643. }
  644. $(function() {
  645. <?php
  646. echo Display::grid_js(
  647. 'results',
  648. $url,
  649. $columns,
  650. $column_model,
  651. $extra_params,
  652. [],
  653. $action_links,
  654. true
  655. );
  656. if ($is_allowedToEdit || $is_tutor) {
  657. ?>
  658. //setSearchSelect("status");
  659. //
  660. //view:true, del:false, add:false, edit:false, excel:true}
  661. $("#results").jqGrid('navGrid','#results_pager', {view:true, edit:false, add:false, del:false, excel:false},
  662. {height:280, reloadAfterSubmit:false}, // view options
  663. {height:280, reloadAfterSubmit:false}, // edit options
  664. {height:280, reloadAfterSubmit:false}, // add options
  665. {reloadAfterSubmit: false}, // del options
  666. {width:500} // search options
  667. );
  668. /*
  669. // add custom button to export the data to excel
  670. jQuery("#results").jqGrid('navButtonAdd','#results_pager',{
  671. caption:"",
  672. onClickButton : function () {
  673. //exportExcel();
  674. }
  675. });*/
  676. /*
  677. jQuery('#sessions').jqGrid('navButtonAdd','#sessions_pager',{id:'pager_csv',caption:'',title:'Export To CSV',onClickButton : function(e)
  678. {
  679. try {
  680. jQuery("#sessions").jqGrid('excelExport',{tag:'csv', url:'grid.php'});
  681. } catch (e) {
  682. window.location= 'grid.php?oper=csv';
  683. }
  684. },buttonicon:'ui-icon-document'})
  685. */
  686. //Adding search options
  687. var options = {
  688. 'stringResult': true,
  689. 'autosearch' : true,
  690. 'searchOnEnter':false
  691. }
  692. jQuery("#results").jqGrid('filterToolbar',options);
  693. var sgrid = $("#results")[0];
  694. sgrid.triggerToolbar();
  695. $('#results').on('click', 'a.exercise-recalculate', function (e) {
  696. e.preventDefault();
  697. if (!$(this).data('user') || !$(this).data('exercise') || !$(this).data('id')) {
  698. return;
  699. }
  700. var url = '<?php echo api_get_path(WEB_CODE_PATH); ?>exercise/recalculate.php?<?php echo api_get_cidreq(); ?>';
  701. var recalculateXhr = $.post(url, $(this).data());
  702. $.when(recalculateXhr).done(function (response) {
  703. $('#results').trigger('reloadGrid');
  704. });
  705. });
  706. <?php
  707. }
  708. ?>
  709. });
  710. // datepicker functions
  711. var datapickerInputModified = false;
  712. /**
  713. * return true if the datepicker input has been modified
  714. */
  715. function datepicker_input_changed() {
  716. datapickerInputModified = true;
  717. }
  718. /**
  719. * disply the datepicker calendar on mouse over the input
  720. */
  721. function datepicker_input_mouseover() {
  722. $('#datepicker_start').datepicker( "show" );
  723. }
  724. /**
  725. * display or hide the datepicker input, calendar and button
  726. */
  727. function display_date_picker() {
  728. if (!$('#datepicker_span').is(":visible")) {
  729. $('#datepicker_span').show();
  730. $('#datepicker_start').datepicker( "show" );
  731. } else {
  732. $('#datepicker_start').datepicker( "hide" );
  733. $('#datepicker_span').hide();
  734. }
  735. }
  736. /**
  737. * confirm deletion
  738. */
  739. function submit_datepicker() {
  740. if (datapickerInputModified) {
  741. var dateTypeVar = $('#datepicker_start').datepicker('getDate');
  742. var dateForBDD = $.datepicker.formatDate('yy-mm-dd', dateTypeVar);
  743. // Format the date for confirm box
  744. var dateFormat = $( "#datepicker_start" ).datepicker( "option", "dateFormat" );
  745. var selectedDate = $.datepicker.formatDate(dateFormat, dateTypeVar);
  746. if (confirm("<?php echo convert_double_quote_to_single(get_lang('AreYouSureDeleteTestResultBeforeDateD')).' '; ?>" + selectedDate)) {
  747. self.location.href = "exercise_report.php?<?php echo api_get_cidreq(); ?>&exerciseId=<?php echo $exercise_id; ?>&delete_before_date="+dateForBDD+"&sec_token=<?php echo $token; ?>";
  748. }
  749. }
  750. }
  751. /**
  752. * initiate datepicker
  753. */
  754. $(function() {
  755. $("#datepicker_start").datepicker({
  756. defaultDate: "",
  757. changeMonth: false,
  758. numberOfMonths: 1
  759. });
  760. });
  761. </script>
  762. <form id="export_report_form" method="post" action="exercise_report.php?<?php echo api_get_cidreq(); ?>">
  763. <input type="hidden" name="csvBuffer" id="csvBuffer" value="" />
  764. <input type="hidden" name="export_report" id="export_report" value="1" />
  765. <input type="hidden" name="exerciseId" id="exerciseId" value="<?php echo $exercise_id; ?>" />
  766. </form>
  767. <?php
  768. echo Display::grid_html('results');
  769. Display :: display_footer();