exercise_report.php 26 KB

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