exercise_report.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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_id = $track_exercise_info['orig_lp_item_id'];
  118. $lp_item_view_id = $track_exercise_info['orig_lp_item_view_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').' <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_path(WEB_PATH));
  211. exit;
  212. }
  213. }
  214. //Updating LP score here
  215. if (in_array($origin, array('tracking_course', 'user_course', 'correct_exercise_in_lp'))) {
  216. $sql = "UPDATE $TBL_LP_ITEM_VIEW SET score = '".floatval($tot)."'
  217. WHERE c_id = ".$course_id." AND id = ".$lp_item_view_id;
  218. Database::query($sql);
  219. if ($origin == 'tracking_course') {
  220. //Redirect to the course detail in lp
  221. header('location: exercise.php?course='.Security :: remove_XSS($_GET['course']));
  222. exit;
  223. } else {
  224. //Redirect to the reporting
  225. header('location: ../mySpace/myStudents.php?origin='.$origin.'&student='.$student_id.'&details=true&course='.$course_id.'&session_id='.$session_id);
  226. exit;
  227. }
  228. }
  229. }
  230. $actions = null;
  231. if ($is_allowedToEdit && $origin != 'learnpath') {
  232. // the form
  233. if (api_is_platform_admin() || api_is_course_admin() ||
  234. api_is_course_tutor() || api_is_course_coach()
  235. ) {
  236. $actions .= '<a href="admin.php?exerciseId='.intval($_GET['exerciseId']).'">'.Display :: return_icon('back.png', get_lang('GoBackToQuestionList'), '', ICON_SIZE_MEDIUM).'</a>';
  237. $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>';
  238. $actions .='<a href="stats.php?'.api_get_cidreq().'&exerciseId='.$exercise_id.'">'.Display :: return_icon('statistics.png', get_lang('ReportByQuestion'), '', ICON_SIZE_MEDIUM).'</a>';
  239. $actions .= '<a id="export_opener" href="'.api_get_self().'?export_report=1&exerciseId='.intval($_GET['exerciseId']).'" >'.
  240. Display::return_icon('save.png', get_lang('Export'), '', ICON_SIZE_MEDIUM).'</a>';
  241. // clean result before a selected date icon
  242. $actions .= Display::url(
  243. Display::return_icon('clean_before_date.png', get_lang('CleanStudentsResultsBeforeDate'), '', ICON_SIZE_MEDIUM),
  244. '#',
  245. array('onclick' => "javascript:display_date_picker()")
  246. );
  247. // clean result before a selected date datepicker popup
  248. $actions .= Display::span(
  249. Display::input('input', 'datepicker_start', get_lang('SelectADateOnTheCalendar'),
  250. array('onmouseover'=>'datepicker_input_mouseover()', 'id'=>'datepicker_start', 'onchange'=>'datepicker_input_changed()', 'readonly'=>'readonly')
  251. ).
  252. Display::button('delete', get_lang('Delete'),
  253. array('onclick'=>'submit_datepicker()')),
  254. array('style'=>'display:none', 'id'=>'datepicker_span')
  255. );
  256. }
  257. } else {
  258. $actions .= '<a href="exercise.php">'.Display :: return_icon('back.png', get_lang('GoBackToQuestionList'), '', ICON_SIZE_MEDIUM).'</a>';
  259. }
  260. //Deleting an attempt
  261. if (($is_allowedToEdit || $is_tutor || api_is_coach()) &&
  262. isset($_GET['delete']) && $_GET['delete'] == 'delete' &&
  263. !empty($_GET['did']) && $locked == false
  264. ) {
  265. $exe_id = intval($_GET['did']);
  266. if (!empty($exe_id)) {
  267. $sql = 'DELETE FROM '.$TBL_TRACK_EXERCISES.' WHERE exe_id = '.$exe_id;
  268. Database::query($sql);
  269. $sql = 'DELETE FROM '.$TBL_TRACK_ATTEMPT.' WHERE exe_id = '.$exe_id;
  270. Database::query($sql);
  271. header('Location: exercise_report.php?'.api_get_cidreq().'&exerciseId='.$exercise_id);
  272. exit;
  273. }
  274. }
  275. if ($is_allowedToEdit || $is_tutor) {
  276. $nameTools = get_lang('StudentScore');
  277. $interbreadcrumb[] = array("url" => "exercise.php?gradebook=$gradebook", "name" => get_lang('Exercises'));
  278. $objExerciseTmp = new Exercise();
  279. if ($objExerciseTmp->read($exercise_id)) {
  280. $interbreadcrumb[] = array("url" => "admin.php?exerciseId=".$exercise_id, "name" => $objExerciseTmp->name);
  281. }
  282. } else {
  283. $interbreadcrumb[] = array("url" => "exercise.php?gradebook=$gradebook", "name" => get_lang('Exercises'));
  284. $objExerciseTmp = new Exercise();
  285. if ($objExerciseTmp->read($exercise_id)) {
  286. $nameTools = get_lang('Results').': '.$objExerciseTmp->name;
  287. }
  288. }
  289. Display :: display_header($nameTools);
  290. // Clean all results for this test before the selected date
  291. if (($is_allowedToEdit || $is_tutor || api_is_coach()) && isset($_GET['delete_before_date']) && $locked == false) {
  292. // ask for the date
  293. $check = Security::check_token('get');
  294. if ($check) {
  295. $objExerciseTmp = new Exercise();
  296. if ($objExerciseTmp->read($exercise_id)) {
  297. $count = $objExerciseTmp->clean_results(
  298. true,
  299. $_GET['delete_before_date'].' 23:59:59'
  300. );
  301. Display::display_confirmation_message(sprintf(get_lang('XResultsCleaned'), $count));
  302. }
  303. }
  304. }
  305. // Security token to protect deletion
  306. $token = Security::get_token();
  307. $actions = Display::div($actions, array('class' => 'actions'));
  308. $extra = '<script>
  309. $(document).ready(function() {
  310. $( "#dialog:ui-dialog" ).dialog( "destroy" );
  311. $( "#dialog-confirm" ).dialog({
  312. autoOpen: false,
  313. show: "blind",
  314. resizable: false,
  315. height:300,
  316. modal: true
  317. });
  318. $("#export_opener").click(function() {
  319. var targetUrl = $(this).attr("href");
  320. $( "#dialog-confirm" ).dialog({
  321. width:400,
  322. height:300,
  323. buttons: {
  324. "'.addslashes(get_lang('Download')).'": function() {
  325. var export_format = $("input[name=export_format]:checked").val();
  326. var extra_data = $("input[name=load_extra_data]:checked").val();
  327. var includeAllUsers = $("input[name=include_all_users]:checked").val();
  328. var attempts = $("input[name=only_best_attempts]:checked").val();
  329. location.href = targetUrl+"&export_format="+export_format+"&extra_data="+extra_data+"&include_all_users="+includeAllUsers+"&only_best_attempts="+attempts;
  330. $( this ).dialog( "close" );
  331. }
  332. }
  333. });
  334. $( "#dialog-confirm" ).dialog("open");
  335. return false;
  336. });
  337. });
  338. </script>';
  339. $extra .= '<div id="dialog-confirm" title="'.get_lang("ConfirmYourChoice").'">';
  340. $form = new FormValidator('report', 'post', null, null, array('class' => 'form-vertical'));
  341. $form->addElement('radio', 'export_format', null, get_lang('ExportAsCSV'), 'csv', array('id' => 'export_format_csv_label'));
  342. $form->addElement('radio', 'export_format', null, get_lang('ExportAsXLS'), 'xls', array('id' => 'export_format_xls_label'));
  343. $form->addElement('checkbox', 'load_extra_data', null, get_lang('LoadExtraData'), '0', array('id' => 'export_format_xls_label'));
  344. $form->addElement('checkbox', 'include_all_users', null, get_lang('IncludeAllUsers'), '0');
  345. $form->addElement('checkbox', 'only_best_attempts', null, get_lang('OnlyBestAttempts'), '0');
  346. $form->setDefaults(array('export_format' => 'csv'));
  347. $extra .= $form->return_form();
  348. $extra .= '</div>';
  349. if ($is_allowedToEdit)
  350. echo $extra;
  351. echo $actions;
  352. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_exercise_results&exerciseId='.$exercise_id.'&filter_by_user='.$filter_user;
  353. $action_links = '';
  354. //Generating group list
  355. $group_list = GroupManager::get_group_list();
  356. $group_parameters = array('group_all:'.get_lang('All'), 'group_none:'.get_lang('None'));
  357. foreach ($group_list as $group) {
  358. $group_parameters[] = $group['id'].':'.$group['name'];
  359. }
  360. if (!empty($group_parameters)) {
  361. $group_parameters = implode(';', $group_parameters);
  362. }
  363. $officialCodeInList = api_get_setting('show_official_code_exercise_result_list');
  364. if ($is_allowedToEdit || $is_tutor) {
  365. // The order is important you need to check the the $column variable in the model.ajax.php file
  366. $columns = array(
  367. get_lang('FirstName'),
  368. get_lang('LastName'),
  369. get_lang('LoginName'),
  370. get_lang('Group'),
  371. get_lang('Duration').' ('.get_lang('MinMinute').')',
  372. get_lang('StartDate'),
  373. get_lang('EndDate'),
  374. get_lang('Score'),
  375. get_lang('IP'),
  376. get_lang('Status'),
  377. get_lang('ToolLearnpath'),
  378. get_lang('Actions')
  379. );
  380. if ($officialCodeInList === 'true') {
  381. $columns = array_merge(array(get_lang('OfficialCode')), $columns);
  382. }
  383. //Column config
  384. $column_model = array(
  385. array('name' => 'firstname', 'index' => 'firstname', 'width' => '50', 'align' => 'left', 'search' => 'true'),
  386. array('name' => 'lastname', 'index' => 'lastname', 'width' => '50', 'align' => 'left', 'formatter' => 'action_formatter', 'search' => 'true'),
  387. array('name' => 'login', 'index' => 'username', 'width' => '40', 'align' => 'left', 'search' => 'true', 'hidden' => 'true'),
  388. array('name' => 'group_name', 'index' => 'group_id', 'width' => '40', 'align' => 'left', 'search' => 'true', 'stype' => 'select',
  389. //for the bottom bar
  390. 'searchoptions' => array(
  391. 'defaultValue' => 'group_all',
  392. 'value' => $group_parameters),
  393. //for the top bar
  394. 'editoptions' => array('value' => $group_parameters)),
  395. array('name' => 'duration', 'index' => 'exe_duration', 'width' => '30', 'align' => 'left', 'search' => 'true'),
  396. array('name' => 'start_date', 'index' => 'start_date', 'width' => '60', 'align' => 'left', 'search' => 'true'),
  397. array('name' => 'exe_date', 'index' => 'exe_date', 'width' => '60', 'align' => 'left', 'search' => 'true'),
  398. array('name' => 'score', 'index' => 'exe_result', 'width' => '50', 'align' => 'left', 'search' => 'true'),
  399. array('name' => 'ip', 'index' => 'user_ip', 'width' => '40', 'align' => 'center', 'search' => 'true'),
  400. array('name' => 'status', 'index' => 'revised', 'width' => '40', 'align' => 'left', 'search' => 'true', 'stype' => 'select',
  401. //for the bottom bar
  402. 'searchoptions' => array(
  403. 'defaultValue' => '',
  404. 'value' => ':'.get_lang('All').';1:'.get_lang('Validated').';0:'.get_lang('NotValidated')),
  405. //for the top bar
  406. 'editoptions' => array('value' => ':'.get_lang('All').';1:'.get_lang('Validated').';0:'.get_lang('NotValidated'))),
  407. array('name' => 'lp', 'index' => 'lp', 'width' => '60', 'align' => 'left', 'search' => 'false'),
  408. array('name' => 'actions', 'index' => 'actions', 'width' => '60', 'align' => 'left', 'search' => 'false')
  409. );
  410. if ($officialCodeInList == 'true') {
  411. $officialCodeRow = array('name' => 'official_code', 'index' => 'official_code', 'width' => '50', 'align' => 'left', 'search' => 'true');
  412. $column_model = array_merge(array($officialCodeRow), $column_model);
  413. }
  414. $action_links = '
  415. // add username as title in lastname filed - ref 4226
  416. function action_formatter(cellvalue, options, rowObject) {
  417. // rowObject is firstname,lastname,login,... get the third word
  418. var loginx = "'.api_htmlentities(sprintf(get_lang("LoginX"), ":::"), ENT_QUOTES).'";
  419. var tabLoginx = loginx.split(/:::/);
  420. // tabLoginx[0] is before and tabLoginx[1] is after :::
  421. // may be empty string but is defined
  422. return "<span title=\""+tabLoginx[0]+rowObject[2]+tabLoginx[1]+"\">"+cellvalue+"</span>";
  423. }';
  424. }
  425. //Autowidth
  426. $extra_params['autowidth'] = 'true';
  427. //height auto
  428. $extra_params['height'] = 'auto';
  429. ?>
  430. <script>
  431. function setSearchSelect(columnName) {
  432. $("#results").jqGrid(
  433. 'setColProp',
  434. columnName, {
  435. searchoptions:{
  436. dataInit:function(el) {
  437. $("option[value='1']",el).attr("selected", "selected");
  438. setTimeout(function(){
  439. $(el).trigger('change');
  440. },1000);
  441. }
  442. }
  443. }
  444. );
  445. }
  446. function exportExcel() {
  447. var mya=new Array();
  448. mya=$("#results").getDataIDs(); // Get All IDs
  449. var data=$("#results").getRowData(mya[0]); // Get First row to get the labels
  450. var colNames=new Array();
  451. var ii=0;
  452. for (var i in data){colNames[ii++]=i;} // capture col names
  453. var html="";
  454. for(i=0;i<mya.length;i++) {
  455. data=$("#results").getRowData(mya[i]); // get each row
  456. for(j=0;j<colNames.length;j++) {
  457. html=html+data[colNames[j]]+","; // output each column as tab delimited
  458. }
  459. html=html+"\n"; // output each row with end of line
  460. }
  461. html = html+"\n"; // end of line at the end
  462. var form = $("#export_report_form");
  463. $("#csvBuffer").attr('value', html);
  464. form.target='_blank';
  465. form.submit();
  466. }
  467. $(function() {
  468. <?php
  469. echo Display::grid_js('results', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  470. if ($is_allowedToEdit || $is_tutor) {
  471. ?>
  472. //setSearchSelect("status");
  473. //
  474. //view:true, del:false, add:false, edit:false, excel:true}
  475. $("#results").jqGrid('navGrid','#results_pager', {view:true, edit:false, add:false, del:false, excel:false},
  476. {height:280, reloadAfterSubmit:false}, // view options
  477. {height:280, reloadAfterSubmit:false}, // edit options
  478. {height:280, reloadAfterSubmit:false}, // add options
  479. {reloadAfterSubmit: false}, // del options
  480. {width:500} // search options
  481. );
  482. /*
  483. // add custom button to export the data to excel
  484. jQuery("#results").jqGrid('navButtonAdd','#results_pager',{
  485. caption:"",
  486. onClickButton : function () {
  487. //exportExcel();
  488. }
  489. });*/
  490. /*
  491. jQuery('#sessions').jqGrid('navButtonAdd','#sessions_pager',{id:'pager_csv',caption:'',title:'Export To CSV',onClickButton : function(e)
  492. {
  493. try {
  494. jQuery("#sessions").jqGrid('excelExport',{tag:'csv', url:'grid.php'});
  495. } catch (e) {
  496. window.location= 'grid.php?oper=csv';
  497. }
  498. },buttonicon:'ui-icon-document'})
  499. */
  500. //Adding search options
  501. var options = {
  502. 'stringResult': true,
  503. 'autosearch' : true,
  504. 'searchOnEnter':false
  505. }
  506. jQuery("#results").jqGrid('filterToolbar',options);
  507. var sgrid = $("#results")[0];
  508. sgrid.triggerToolbar();
  509. <?php } ?>
  510. });
  511. // datepicker functions
  512. var datapickerInputModified = false;
  513. /**
  514. * return true if the datepicker input has been modified
  515. */
  516. function datepicker_input_changed() {
  517. datapickerInputModified = true;
  518. }
  519. /**
  520. * disply the datepicker calendar on mouse over the input
  521. */
  522. function datepicker_input_mouseover() {
  523. $('#datepicker_start').datepicker( "show" );
  524. }
  525. /**
  526. * display or hide the datepicker input, calendar and button
  527. */
  528. function display_date_picker() {
  529. if (!$('#datepicker_span').is(":visible")) {
  530. $('#datepicker_span').show();
  531. $('#datepicker_start').datepicker( "show" );
  532. } else {
  533. $('#datepicker_start').datepicker( "hide" );
  534. $('#datepicker_span').hide();
  535. }
  536. }
  537. /**
  538. * confirm deletion
  539. */
  540. function submit_datepicker() {
  541. if (datapickerInputModified) {
  542. var dateTypeVar = $('#datepicker_start').datepicker('getDate');
  543. var dateForBDD = $.datepicker.formatDate('yy-mm-dd', dateTypeVar);
  544. // Format the date for confirm box
  545. var dateFormat = $( "#datepicker_start" ).datepicker( "option", "dateFormat" );
  546. var selectedDate = $.datepicker.formatDate(dateFormat, dateTypeVar);
  547. if (confirm("<?php echo convert_double_quote_to_single(get_lang('AreYouSureDeleteTestResultBeforeDateD')); ?>" + selectedDate)) {
  548. 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; ?>";
  549. }
  550. }
  551. }
  552. /**
  553. * initiate datepicker
  554. */
  555. $(function() {
  556. $( "#datepicker_start" ).datepicker({
  557. defaultDate: "",
  558. changeMonth: false,
  559. numberOfMonths: 1
  560. });
  561. });
  562. </script>
  563. <form id="export_report_form" method="post" action="exercise_report.php?<?php echo api_get_cidreq(); ?>">
  564. <input type="hidden" name="csvBuffer" id="csvBuffer" value="" />
  565. <input type="hidden" name="export_report" id="export_report" value="1" />
  566. <input type="hidden" name="exerciseId" id="exerciseId" value="<?php echo $exercise_id ?>" />
  567. </form>
  568. <?php
  569. echo Display::grid_html('results');
  570. Display :: display_footer();