exercise_report.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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. * @package chamilo.exercise
  6. * @author Julio Montoya <gugli100@gmail.com> jqgrid integration
  7. * Modified by hubert.borderiou (question category)
  8. *
  9. * @todo fix excel export
  10. *
  11. */
  12. //require_once '../inc/global.inc.php';
  13. // Setting the tabs
  14. $this_section = SECTION_COURSES;
  15. $htmlHeadXtra[] = api_get_jqgrid_js();
  16. // Access control
  17. api_protect_course_script(true, false, true);
  18. // including additional libraries
  19. require_once 'hotpotatoes.lib.php';
  20. $_course = api_get_course_info();
  21. // document path
  22. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
  23. $origin = isset($origin) ? $origin : null;
  24. $gradebook = isset($gradebook) ? $gradebook : null;
  25. $path = isset($_GET['path']) ? Security::remove_XSS($_GET['path']) : null;
  26. /* Constants and variables */
  27. $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_drh() || api_is_student_boss();
  28. $is_tutor = api_is_allowed_to_edit(true);
  29. $em = Database::getManager();
  30. $TBL_QUESTIONS = Database :: get_course_table(TABLE_QUIZ_QUESTION);
  31. $TBL_TRACK_EXERCISES = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  32. $TBL_TRACK_ATTEMPT_RECORDING = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
  33. $TBL_LP_ITEM_VIEW = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  34. $allowCoachFeedbackExercises = api_get_setting(
  35. 'exercise.allow_coach_feedback_exercises'
  36. ) === 'true';
  37. $course_id = api_get_course_int_id();
  38. $exercise_id = isset($_REQUEST['exerciseId']) ? intval($_REQUEST['exerciseId']) : null;
  39. $filter_user = isset($_REQUEST['filter_by_user']) ? intval($_REQUEST['filter_by_user']) : null;
  40. $locked = api_resource_is_locked_by_gradebook($exercise_id, LINK_EXERCISE);
  41. if (empty($exercise_id)) {
  42. api_not_allowed(true);
  43. }
  44. if (!$is_allowedToEdit && !$allowCoachFeedbackExercises) {
  45. api_not_allowed(true);
  46. }
  47. if (!empty($exercise_id)) {
  48. $parameters['exerciseId'] = $exercise_id;
  49. }
  50. if (!empty($_GET['path'])) {
  51. $parameters['path'] = Security::remove_XSS($_GET['path']);
  52. }
  53. if (!empty($_REQUEST['export_report']) && $_REQUEST['export_report'] == '1') {
  54. if (api_is_platform_admin() || api_is_course_admin() ||
  55. api_is_course_tutor() || api_is_course_coach()
  56. ) {
  57. $loadExtraData = false;
  58. if (isset($_REQUEST['extra_data']) && $_REQUEST['extra_data'] == 1) {
  59. $loadExtraData = true;
  60. }
  61. $includeAllUsers = false;
  62. if (isset($_REQUEST['include_all_users']) &&
  63. $_REQUEST['include_all_users'] == 1
  64. ) {
  65. $includeAllUsers = true;
  66. }
  67. $onlyBestAttempts = false;
  68. if (isset($_REQUEST['only_best_attempts']) &&
  69. $_REQUEST['only_best_attempts'] == 1
  70. ) {
  71. $onlyBestAttempts = true;
  72. }
  73. require_once 'exercise_result.class.php';
  74. $export = new ExerciseResult();
  75. $export->setIncludeAllUsers($includeAllUsers);
  76. $export->setOnlyBestAttempts($onlyBestAttempts);
  77. switch ($_GET['export_format']) {
  78. case 'xls':
  79. $export->exportCompleteReportXLS(
  80. $documentPath,
  81. null,
  82. $loadExtraData,
  83. null,
  84. $_GET['exerciseId']
  85. );
  86. exit;
  87. break;
  88. case 'csv':
  89. default:
  90. $export->exportCompleteReportCSV(
  91. $documentPath,
  92. null,
  93. $loadExtraData,
  94. null,
  95. $_GET['exerciseId']
  96. );
  97. exit;
  98. break;
  99. }
  100. } else {
  101. api_not_allowed(true);
  102. }
  103. }
  104. //Send student email @todo move this code in a class, library
  105. if (isset($_REQUEST['comments']) &&
  106. $_REQUEST['comments'] == 'update' &&
  107. ($is_allowedToEdit || $is_tutor || $allowCoachFeedbackExercises)
  108. ) {
  109. //filtered by post-condition
  110. $id = intval($_GET['exeid']);
  111. $track_exercise_info = ExerciseLib::get_exercise_track_exercise_info($id);
  112. if (empty($track_exercise_info)) {
  113. api_not_allowed();
  114. }
  115. $test = $track_exercise_info['title'];
  116. $student_id = $track_exercise_info['exe_user_id'];
  117. $session_id = $track_exercise_info['session_id'];
  118. $lp_id = $track_exercise_info['orig_lp_id'];
  119. $lp_item_view_id = $track_exercise_info['orig_lp_item_view_id'];
  120. $exerciseId = $track_exercise_info['exe_exo_id'];
  121. $course_info = api_get_course_info();
  122. // Teacher data
  123. $teacher_info = api_get_user_info(api_get_user_id());
  124. $from_name = api_get_person_name(
  125. $teacher_info['firstname'],
  126. $teacher_info['lastname'],
  127. null,
  128. PERSON_NAME_EMAIL_ADDRESS
  129. );
  130. $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;
  131. $my_post_info = array();
  132. $post_content_id = array();
  133. $comments_exist = false;
  134. foreach ($_POST as $key_index => $key_value) {
  135. $my_post_info = explode('_', $key_index);
  136. $post_content_id[] = $my_post_info[1];
  137. if ($my_post_info[0] == 'comments') {
  138. $comments_exist = true;
  139. }
  140. }
  141. $loop_in_track = $comments_exist === true ? (count($_POST) / 2) : count($_POST);
  142. $array_content_id_exe = array();
  143. if ($comments_exist === true) {
  144. $array_content_id_exe = array_slice($post_content_id, $loop_in_track);
  145. } else {
  146. $array_content_id_exe = $post_content_id;
  147. }
  148. for ($i = 0; $i < $loop_in_track; $i++) {
  149. $my_marks = isset($_POST['marks_'.$array_content_id_exe[$i]]) ? $_POST['marks_'.$array_content_id_exe[$i]] : '';
  150. $contain_comments = $_POST['comments_'.$array_content_id_exe[$i]];
  151. if (isset($contain_comments)) {
  152. $my_comments = $_POST['comments_'.$array_content_id_exe[$i]];
  153. } else {
  154. $my_comments = '';
  155. }
  156. $my_questionid = intval($array_content_id_exe[$i]);
  157. $em
  158. ->createQuery('
  159. UPDATE ChamiloCoreBundle:TrackEAttempt tea
  160. SET tea.marks = :marks, tea.teacherComment = :comment
  161. WHERE tea.questionId = :question AND tea.exeId = :exe
  162. ')
  163. ->execute([
  164. 'marks' => $my_marks,
  165. 'comment' => $my_comments,
  166. 'question' => $my_questionid,
  167. 'exeId' => $id
  168. ]);
  169. $params = [
  170. 'exe_id' => $id,
  171. 'question_id' => $my_questionid,
  172. 'marks' => $my_marks,
  173. 'insert_date' => api_get_utc_datetime(),
  174. 'author' => api_get_user_id(),
  175. 'teacher_comment' => $my_comments
  176. ];
  177. Database::insert($TBL_TRACK_ATTEMPT_RECORDING, $params);
  178. }
  179. $res = $em
  180. ->createQuery('
  181. SELECT DISTINCT tea.questionId, tea.marks
  182. FROM ChamiloCoreBundle:TrackeEAttempt tea
  183. WHERE tea.exeId = :exe
  184. GROUP BY tea.questionId
  185. ')
  186. ->setParameter('exe', $id)
  187. ->getResult();
  188. $tot = 0;
  189. foreach ($res as $row) {
  190. $tot += $row['marks'];
  191. }
  192. $sql = "UPDATE $TBL_TRACK_EXERCISES
  193. SET exe_result = '".floatval($tot)."'
  194. WHERE exe_id = ".$id;
  195. Database::query($sql);
  196. if (isset($_POST['send_notification'])) {
  197. //@todo move this somewhere else
  198. $subject = get_lang('ExamSheetVCC');
  199. $message = '<p>'.get_lang('DearStudentEmailIntroduction').'</p><p>'.get_lang('AttemptVCC');
  200. $message .= '<h3>'.get_lang('CourseName').'</h3><p>'.Security::remove_XSS($course_info['name']).'';
  201. $message .= '<h3>'.get_lang('Exercise').'</h3><p>'.Security::remove_XSS($test);
  202. // Only for exercises not in a LP
  203. if ($lp_id == 0) {
  204. $message .= '<p>'.get_lang('ClickLinkToViewComment').' <br /><a href="#url#">#url#</a><br />';
  205. }
  206. $message .= '<p>'.get_lang('Regards').'</p>';
  207. $message .= $from_name;
  208. $message = str_replace("#test#", Security::remove_XSS($test), $message);
  209. $message = str_replace("#url#", $url, $message);
  210. MessageManager::send_message_simple(
  211. $student_id,
  212. $subject,
  213. $message,
  214. api_get_user_id()
  215. );
  216. if ($allowCoachFeedbackExercises) {
  217. Display::addFlash(
  218. Display::return_message(get_lang('MessageSent'))
  219. );
  220. header('Location: ' . api_get_self().'?'.api_get_cidreq().'&exerciseId='.$exerciseId);
  221. exit;
  222. }
  223. }
  224. // Updating LP score here
  225. if (in_array($origin, array('tracking_course', 'user_course', 'correct_exercise_in_lp'))
  226. ) {
  227. $sql = "UPDATE $TBL_LP_ITEM_VIEW SET score = '".floatval($tot)."'
  228. WHERE c_id = ".$course_id." AND id = ".$lp_item_view_id;
  229. Database::query($sql);
  230. if ($origin == 'tracking_course') {
  231. //Redirect to the course detail in lp
  232. header('location: '.api_get_path(WEB_CODE_PATH).'exercise/exercise.php?course='.Security :: remove_XSS($_GET['course']));
  233. exit;
  234. } else {
  235. // Redirect to the reporting
  236. header('Location: '.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?origin='.$origin.'&student='.$student_id.'&details=true&course='.$course_id.'&session_id='.$session_id);
  237. exit;
  238. }
  239. }
  240. }
  241. $actions = null;
  242. if ($is_allowedToEdit && $origin != 'learnpath') {
  243. // the form
  244. if (api_is_platform_admin() || api_is_course_admin() ||
  245. api_is_course_tutor() || api_is_course_coach()
  246. ) {
  247. $actions .= '<a href="admin.php?exerciseId='.intval($_GET['exerciseId']).'">'.Display :: return_icon('back.png', get_lang('GoBackToQuestionList'), '', ICON_SIZE_MEDIUM).'</a>';
  248. $actions .='<a href="live_stats.php?'.api_get_cidreq().'&exerciseId='.$exercise_id.'">'.Display :: return_icon('activity_monitor.png', get_lang('LiveResults'), '', ICON_SIZE_MEDIUM).'</a>';
  249. $actions .='<a href="stats.php?'.api_get_cidreq().'&exerciseId='.$exercise_id.'">'.Display :: return_icon('statistics.png', get_lang('ReportByQuestion'), '', ICON_SIZE_MEDIUM).'</a>';
  250. $actions .= '<a id="export_opener" href="'.api_get_self().'?export_report=1&exerciseId='.intval($_GET['exerciseId']).'" >'.
  251. Display::return_icon('save.png', get_lang('Export'), '', ICON_SIZE_MEDIUM).'</a>';
  252. // clean result before a selected date icon
  253. $actions .= Display::url(
  254. Display::return_icon('clean_before_date.png', get_lang('CleanStudentsResultsBeforeDate'), '', ICON_SIZE_MEDIUM),
  255. '#',
  256. array('onclick' => "javascript:display_date_picker()")
  257. );
  258. // clean result before a selected date datepicker popup
  259. $actions .= Display::span(
  260. Display::input('input', 'datepicker_start', get_lang('SelectADateOnTheCalendar'),
  261. array('onmouseover'=>'datepicker_input_mouseover()', 'id'=>'datepicker_start', 'onchange'=>'datepicker_input_changed()', 'readonly'=>'readonly')
  262. ).
  263. Display::button('delete', get_lang('Delete'),
  264. array('onclick'=>'submit_datepicker()')),
  265. array('style'=>'display:none', 'id'=>'datepicker_span')
  266. );
  267. }
  268. } else {
  269. $actions .= '<a href="exercise.php">'.Display :: return_icon('back.png', get_lang('GoBackToQuestionList'), '', ICON_SIZE_MEDIUM).'</a>';
  270. }
  271. //Deleting an attempt
  272. if (($is_allowedToEdit || $is_tutor || api_is_coach()) &&
  273. isset($_GET['delete']) && $_GET['delete'] == 'delete' &&
  274. !empty($_GET['did']) && $locked == false
  275. ) {
  276. $exe_id = intval($_GET['did']);
  277. if (!empty($exe_id)) {
  278. $sql = 'DELETE FROM '.$TBL_TRACK_EXERCISES.' WHERE exe_id = '.$exe_id;
  279. Database::query($sql);
  280. $em
  281. ->createQuery('DELETE FROM ChamiloCoreBundle:TrackEAttempt tea WHERE tea.exeId = :exe')
  282. ->execute([
  283. 'exe' => $exe_id
  284. ]);
  285. header('Location: exercise_report.php?'.api_get_cidreq().'&exerciseId='.$exercise_id);
  286. exit;
  287. }
  288. }
  289. if ($is_allowedToEdit || $is_tutor) {
  290. $nameTools = get_lang('StudentScore');
  291. $interbreadcrumb[] = array(
  292. "url" => "exercise.php?".api_get_cidreq(),
  293. "name" => get_lang('Exercises'),
  294. );
  295. $objExerciseTmp = new Exercise();
  296. if ($objExerciseTmp->read($exercise_id)) {
  297. $interbreadcrumb[] = array(
  298. "url" => "admin.php?exerciseId=".$exercise_id."&".api_get_cidreq(),
  299. "name" => $objExerciseTmp->name,
  300. );
  301. }
  302. } else {
  303. $interbreadcrumb[] = array(
  304. "url" => "exercise.php?".api_get_cidreq(),
  305. "name" => get_lang('Exercises'),
  306. );
  307. $objExerciseTmp = new Exercise();
  308. if ($objExerciseTmp->read($exercise_id)) {
  309. $nameTools = get_lang('Results').': '.$objExerciseTmp->name;
  310. }
  311. }
  312. Display :: display_header($nameTools);
  313. // Clean all results for this test before the selected date
  314. if (($is_allowedToEdit || $is_tutor || api_is_coach()) && isset($_GET['delete_before_date']) && $locked == false) {
  315. // ask for the date
  316. $check = Security::check_token('get');
  317. if ($check) {
  318. $objExerciseTmp = new Exercise();
  319. if ($objExerciseTmp->read($exercise_id)) {
  320. $count = $objExerciseTmp->clean_results(
  321. true,
  322. $_GET['delete_before_date'].' 23:59:59'
  323. );
  324. Display::display_confirmation_message(sprintf(get_lang('XResultsCleaned'), $count));
  325. }
  326. }
  327. }
  328. // Security token to protect deletion
  329. $token = Security::get_token();
  330. $actions = Display::div($actions, array('class' => 'actions'));
  331. $extra = '<script>
  332. $(document).ready(function() {
  333. $( "#dialog:ui-dialog" ).dialog( "destroy" );
  334. $( "#dialog-confirm" ).dialog({
  335. autoOpen: false,
  336. show: "blind",
  337. resizable: false,
  338. height:300,
  339. modal: true
  340. });
  341. $("#export_opener").click(function() {
  342. var targetUrl = $(this).attr("href");
  343. $( "#dialog-confirm" ).dialog({
  344. width:400,
  345. height:300,
  346. buttons: {
  347. "'.addslashes(get_lang('Download')).'": function() {
  348. var export_format = $("input[name=export_format]:checked").val();
  349. var extra_data = $("input[name=load_extra_data]:checked").val();
  350. var includeAllUsers = $("input[name=include_all_users]:checked").val();
  351. var attempts = $("input[name=only_best_attempts]:checked").val();
  352. location.href = targetUrl+"&export_format="+export_format+"&extra_data="+extra_data+"&include_all_users="+includeAllUsers+"&only_best_attempts="+attempts;
  353. $( this ).dialog( "close" );
  354. }
  355. }
  356. });
  357. $( "#dialog-confirm" ).dialog("open");
  358. return false;
  359. });
  360. });
  361. </script>';
  362. $extra .= '<div id="dialog-confirm" title="'.get_lang("ConfirmYourChoice").'">';
  363. $form = new FormValidator('report', 'post', null, null, array('class' => 'form-vertical'));
  364. $form->addElement('radio', 'export_format', null, get_lang('ExportAsCSV'), 'csv', array('id' => 'export_format_csv_label'));
  365. $form->addElement('radio', 'export_format', null, get_lang('ExportAsXLS'), 'xls', array('id' => 'export_format_xls_label'));
  366. $form->addElement('checkbox', 'load_extra_data', null, get_lang('LoadExtraData'), '0', array('id' => 'export_format_xls_label'));
  367. $form->addElement('checkbox', 'include_all_users', null, get_lang('IncludeAllUsers'), '0');
  368. $form->addElement('checkbox', 'only_best_attempts', null, get_lang('OnlyBestAttempts'), '0');
  369. $form->setDefaults(array('export_format' => 'csv'));
  370. $extra .= $form->return_form();
  371. $extra .= '</div>';
  372. if ($is_allowedToEdit)
  373. echo $extra;
  374. echo $actions;
  375. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_exercise_results&exerciseId='.$exercise_id.'&filter_by_user='.$filter_user;
  376. $action_links = '';
  377. //Generating group list
  378. $group_list = GroupManager::get_group_list();
  379. $group_parameters = array('group_all:'.get_lang('All'), 'group_none:'.get_lang('None'));
  380. foreach ($group_list as $group) {
  381. $group_parameters[] = $group['id'].':'.$group['name'];
  382. }
  383. if (!empty($group_parameters)) {
  384. $group_parameters = implode(';', $group_parameters);
  385. }
  386. $officialCodeInList = api_get_setting(
  387. 'exercise.show_official_code_exercise_result_list'
  388. );
  389. if ($is_allowedToEdit || $is_tutor) {
  390. // The order is important you need to check the the $column variable in the model.ajax.php file
  391. $columns = array(
  392. get_lang('FirstName'),
  393. get_lang('LastName'),
  394. get_lang('LoginName'),
  395. get_lang('Group'),
  396. get_lang('Duration').' ('.get_lang('MinMinute').')',
  397. get_lang('StartDate'),
  398. get_lang('EndDate'),
  399. get_lang('Score'),
  400. get_lang('IP'),
  401. get_lang('Status'),
  402. get_lang('ToolLearnpath'),
  403. get_lang('Actions')
  404. );
  405. if ($officialCodeInList === 'true') {
  406. $columns = array_merge(array(get_lang('OfficialCode')), $columns);
  407. }
  408. //Column config
  409. $column_model = array(
  410. array('name' => 'firstname', 'index' => 'firstname', 'width' => '50', 'align' => 'left', 'search' => 'true'),
  411. array('name' => 'lastname', 'index' => 'lastname', 'width' => '50', 'align' => 'left', 'formatter' => 'action_formatter', 'search' => 'true'),
  412. array('name' => 'login', 'index' => 'username', 'width' => '40', 'align' => 'left', 'search' => 'true', 'hidden' => 'true'),
  413. array('name' => 'group_name', 'index' => 'group_id', 'width' => '40', 'align' => 'left', 'search' => 'true', 'stype' => 'select',
  414. //for the bottom bar
  415. 'searchoptions' => array(
  416. 'defaultValue' => 'group_all',
  417. 'value' => $group_parameters),
  418. //for the top bar
  419. 'editoptions' => array('value' => $group_parameters)),
  420. array('name' => 'duration', 'index' => 'exe_duration', 'width' => '30', 'align' => 'left', 'search' => 'true'),
  421. array('name' => 'start_date', 'index' => 'start_date', 'width' => '60', 'align' => 'left', 'search' => 'true'),
  422. array('name' => 'exe_date', 'index' => 'exe_date', 'width' => '60', 'align' => 'left', 'search' => 'true'),
  423. array('name' => 'score', 'index' => 'exe_result', 'width' => '50', 'align' => 'center', 'search' => 'true'),
  424. array('name' => 'ip', 'index' => 'user_ip', 'width' => '40', 'align' => 'center', 'search' => 'true'),
  425. array('name' => 'status', 'index' => 'revised', 'width' => '40', 'align' => 'left', 'search' => 'true', 'stype' => 'select',
  426. //for the bottom bar
  427. 'searchoptions' => array(
  428. 'defaultValue' => '',
  429. 'value' => ':'.get_lang('All').';1:'.get_lang('Validated').';0:'.get_lang('NotValidated')),
  430. //for the top bar
  431. 'editoptions' => array('value' => ':'.get_lang('All').';1:'.get_lang('Validated').';0:'.get_lang('NotValidated'))),
  432. array('name' => 'lp', 'index' => 'lp', 'width' => '60', 'align' => 'left', 'search' => 'false'),
  433. array('name' => 'actions', 'index' => 'actions', 'width' => '60', 'align' => 'left', 'search' => 'false')
  434. );
  435. if ($officialCodeInList == 'true') {
  436. $officialCodeRow = array('name' => 'official_code', 'index' => 'official_code', 'width' => '50', 'align' => 'left', 'search' => 'true');
  437. $column_model = array_merge(array($officialCodeRow), $column_model);
  438. }
  439. $action_links = '
  440. // add username as title in lastname filed - ref 4226
  441. function action_formatter(cellvalue, options, rowObject) {
  442. // rowObject is firstname,lastname,login,... get the third word
  443. var loginx = "'.api_htmlentities(sprintf(get_lang("LoginX"), ":::"), ENT_QUOTES).'";
  444. var tabLoginx = loginx.split(/:::/);
  445. // tabLoginx[0] is before and tabLoginx[1] is after :::
  446. // may be empty string but is defined
  447. return "<span title=\""+tabLoginx[0]+rowObject[2]+tabLoginx[1]+"\">"+cellvalue+"</span>";
  448. }';
  449. }
  450. //Autowidth
  451. $extra_params['autowidth'] = 'true';
  452. //height auto
  453. $extra_params['height'] = 'auto';
  454. ?>
  455. <script>
  456. function setSearchSelect(columnName) {
  457. $("#results").jqGrid(
  458. 'setColProp',
  459. columnName, {
  460. searchoptions:{
  461. dataInit:function(el) {
  462. $("option[value='1']",el).attr("selected", "selected");
  463. setTimeout(function(){
  464. $(el).trigger('change');
  465. },1000);
  466. }
  467. }
  468. }
  469. );
  470. }
  471. function exportExcel() {
  472. var mya=new Array();
  473. mya=$("#results").getDataIDs(); // Get All IDs
  474. var data=$("#results").getRowData(mya[0]); // Get First row to get the labels
  475. var colNames=new Array();
  476. var ii=0;
  477. for (var i in data){colNames[ii++]=i;} // capture col names
  478. var html="";
  479. for(i=0;i<mya.length;i++) {
  480. data=$("#results").getRowData(mya[i]); // get each row
  481. for(j=0;j<colNames.length;j++) {
  482. html=html+data[colNames[j]]+","; // output each column as tab delimited
  483. }
  484. html=html+"\n"; // output each row with end of line
  485. }
  486. html = html+"\n"; // end of line at the end
  487. var form = $("#export_report_form");
  488. $("#csvBuffer").attr('value', html);
  489. form.target='_blank';
  490. form.submit();
  491. }
  492. $(function() {
  493. <?php
  494. echo Display::grid_js('results', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  495. if ($is_allowedToEdit || $is_tutor) {
  496. ?>
  497. //setSearchSelect("status");
  498. //
  499. //view:true, del:false, add:false, edit:false, excel:true}
  500. $("#results").jqGrid('navGrid','#results_pager', {view:true, edit:false, add:false, del:false, excel:false},
  501. {height:280, reloadAfterSubmit:false}, // view options
  502. {height:280, reloadAfterSubmit:false}, // edit options
  503. {height:280, reloadAfterSubmit:false}, // add options
  504. {reloadAfterSubmit: false}, // del options
  505. {width:500} // search options
  506. );
  507. /*
  508. // add custom button to export the data to excel
  509. jQuery("#results").jqGrid('navButtonAdd','#results_pager',{
  510. caption:"",
  511. onClickButton : function () {
  512. //exportExcel();
  513. }
  514. });*/
  515. /*
  516. jQuery('#sessions').jqGrid('navButtonAdd','#sessions_pager',{id:'pager_csv',caption:'',title:'Export To CSV',onClickButton : function(e)
  517. {
  518. try {
  519. jQuery("#sessions").jqGrid('excelExport',{tag:'csv', url:'grid.php'});
  520. } catch (e) {
  521. window.location= 'grid.php?oper=csv';
  522. }
  523. },buttonicon:'ui-icon-document'})
  524. */
  525. //Adding search options
  526. var options = {
  527. 'stringResult': true,
  528. 'autosearch' : true,
  529. 'searchOnEnter':false
  530. }
  531. jQuery("#results").jqGrid('filterToolbar',options);
  532. var sgrid = $("#results")[0];
  533. sgrid.triggerToolbar();
  534. $('#results').on('click', 'a.exercise-recalculate', function (e) {
  535. e.preventDefault();
  536. if (!$(this).data('user') || !$(this).data('exercise') || !$(this).data('id')) {
  537. return;
  538. }
  539. var url = '<?php echo api_get_path(WEB_CODE_PATH) ?>exercise/recalculate.php?<?php echo api_get_cidreq() ?>';
  540. var recalculateXhr = $.post(url, $(this).data());
  541. $.when(recalculateXhr).done(function (response) {
  542. $('#results').trigger('reloadGrid');
  543. });
  544. });
  545. <?php } ?>
  546. });
  547. // datepicker functions
  548. var datapickerInputModified = false;
  549. /**
  550. * return true if the datepicker input has been modified
  551. */
  552. function datepicker_input_changed() {
  553. datapickerInputModified = true;
  554. }
  555. /**
  556. * disply the datepicker calendar on mouse over the input
  557. */
  558. function datepicker_input_mouseover() {
  559. $('#datepicker_start').datepicker( "show" );
  560. }
  561. /**
  562. * display or hide the datepicker input, calendar and button
  563. */
  564. function display_date_picker() {
  565. if (!$('#datepicker_span').is(":visible")) {
  566. $('#datepicker_span').show();
  567. $('#datepicker_start').datepicker( "show" );
  568. } else {
  569. $('#datepicker_start').datepicker( "hide" );
  570. $('#datepicker_span').hide();
  571. }
  572. }
  573. /**
  574. * confirm deletion
  575. */
  576. function submit_datepicker() {
  577. if (datapickerInputModified) {
  578. var dateTypeVar = $('#datepicker_start').datepicker('getDate');
  579. var dateForBDD = $.datepicker.formatDate('yy-mm-dd', dateTypeVar);
  580. // Format the date for confirm box
  581. var dateFormat = $( "#datepicker_start" ).datepicker( "option", "dateFormat" );
  582. var selectedDate = $.datepicker.formatDate(dateFormat, dateTypeVar);
  583. if (confirm("<?php echo convert_double_quote_to_single(get_lang('AreYouSureDeleteTestResultBeforeDateD')); ?>" + selectedDate)) {
  584. 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; ?>";
  585. }
  586. }
  587. }
  588. /**
  589. * initiate datepicker
  590. */
  591. $(function() {
  592. $( "#datepicker_start" ).datepicker({
  593. defaultDate: "",
  594. changeMonth: false,
  595. numberOfMonths: 1
  596. });
  597. });
  598. </script>
  599. <form id="export_report_form" method="post" action="exercise_report.php?<?php echo api_get_cidreq(); ?>">
  600. <input type="hidden" name="csvBuffer" id="csvBuffer" value="" />
  601. <input type="hidden" name="export_report" id="export_report" value="1" />
  602. <input type="hidden" name="exerciseId" id="exerciseId" value="<?php echo $exercise_id ?>" />
  603. </form>
  604. <?php
  605. echo Display::grid_html('results');
  606. Display :: display_footer();