exercise_report.php 25 KB

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