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