exercise_report.php 25 KB

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