exercise_report.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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 __DIR__.'/../inc/global.inc.php';
  13. // Setting the tabs
  14. $this_section = SECTION_COURSES;
  15. $htmlHeadXtra[] = api_get_jqgrid_js();
  16. $filter_user = isset($_REQUEST['filter_by_user']) ? (int) $_REQUEST['filter_by_user'] : null;
  17. $isBossOfStudent = false;
  18. if (api_is_student_boss() && !empty($filter_user)) {
  19. // Check if boss has access to user info.
  20. if (UserManager::userIsBossOfStudent(api_get_user_id(), $filter_user)) {
  21. $isBossOfStudent = true;
  22. } else {
  23. api_not_allowed(true);
  24. }
  25. } else {
  26. api_protect_course_script(true, false, true);
  27. }
  28. // including additional libraries
  29. require_once 'hotpotatoes.lib.php';
  30. $_course = api_get_course_info();
  31. // document path
  32. $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
  33. $origin = isset($origin) ? $origin : null;
  34. $gradebook = isset($gradebook) ? $gradebook : null;
  35. $path = isset($_GET['path']) ? Security::remove_XSS($_GET['path']) : null;
  36. /* Constants and variables */
  37. $is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_drh() || api_is_student_boss();
  38. $is_tutor = api_is_allowed_to_edit(true);
  39. $TBL_TRACK_EXERCISES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  40. $TBL_TRACK_ATTEMPT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  41. $TBL_TRACK_ATTEMPT_RECORDING = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
  42. $TBL_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  43. $allowCoachFeedbackExercises = api_get_setting('allow_coach_feedback_exercises') === 'true';
  44. $course_id = api_get_course_int_id();
  45. $exercise_id = isset($_REQUEST['exerciseId']) ? intval($_REQUEST['exerciseId']) : null;
  46. $locked = api_resource_is_locked_by_gradebook($exercise_id, LINK_EXERCISE);
  47. if (empty($exercise_id)) {
  48. api_not_allowed(true);
  49. }
  50. if (!$is_allowedToEdit && !$allowCoachFeedbackExercises) {
  51. api_not_allowed(true);
  52. }
  53. if (!empty($exercise_id)) {
  54. $parameters['exerciseId'] = $exercise_id;
  55. }
  56. if (!empty($_GET['path'])) {
  57. $parameters['path'] = Security::remove_XSS($_GET['path']);
  58. }
  59. if (!empty($_REQUEST['export_report']) && $_REQUEST['export_report'] == '1') {
  60. if (api_is_platform_admin() || api_is_course_admin() ||
  61. api_is_course_tutor() || api_is_session_general_coach()
  62. ) {
  63. $loadExtraData = false;
  64. if (isset($_REQUEST['extra_data']) && $_REQUEST['extra_data'] == 1) {
  65. $loadExtraData = true;
  66. }
  67. $includeAllUsers = false;
  68. if (isset($_REQUEST['include_all_users']) &&
  69. $_REQUEST['include_all_users'] == 1
  70. ) {
  71. $includeAllUsers = true;
  72. }
  73. $onlyBestAttempts = false;
  74. if (isset($_REQUEST['only_best_attempts']) &&
  75. $_REQUEST['only_best_attempts'] == 1
  76. ) {
  77. $onlyBestAttempts = true;
  78. }
  79. require_once 'exercise_result.class.php';
  80. $export = new ExerciseResult();
  81. $export->setIncludeAllUsers($includeAllUsers);
  82. $export->setOnlyBestAttempts($onlyBestAttempts);
  83. switch ($_GET['export_format']) {
  84. case 'xls':
  85. $export->exportCompleteReportXLS(
  86. $documentPath,
  87. null,
  88. $loadExtraData,
  89. null,
  90. $_GET['exerciseId']
  91. );
  92. exit;
  93. break;
  94. case 'csv':
  95. default:
  96. $export->exportCompleteReportCSV(
  97. $documentPath,
  98. null,
  99. $loadExtraData,
  100. null,
  101. $_GET['exerciseId']
  102. );
  103. exit;
  104. break;
  105. }
  106. } else {
  107. api_not_allowed(true);
  108. }
  109. }
  110. //Send student email @todo move this code in a class, library
  111. if (isset($_REQUEST['comments']) &&
  112. $_REQUEST['comments'] == 'update' &&
  113. ($is_allowedToEdit || $is_tutor || $allowCoachFeedbackExercises)
  114. ) {
  115. // Filtered by post-condition
  116. $id = intval($_GET['exeid']);
  117. $track_exercise_info = ExerciseLib::get_exercise_track_exercise_info($id);
  118. if (empty($track_exercise_info)) {
  119. api_not_allowed();
  120. }
  121. $test = $track_exercise_info['title'];
  122. $student_id = $track_exercise_info['exe_user_id'];
  123. $session_id = $track_exercise_info['session_id'];
  124. $lp_id = $track_exercise_info['orig_lp_id'];
  125. $lp_item_view_id = $track_exercise_info['orig_lp_item_view_id'];
  126. $exerciseId = $track_exercise_info['exe_exo_id'];
  127. $course_info = api_get_course_info();
  128. $url = api_get_path(WEB_CODE_PATH).'exercise/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[] = isset($my_post_info[1]) ? $my_post_info[1] : null;
  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 = isset($_POST['marks_'.$array_content_id_exe[$i]]) ? $_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 = isset($_POST['notification_content']) ? $_POST['notification_content'] : '';
  190. MessageManager::send_message_simple(
  191. $student_id,
  192. $subject,
  193. $message,
  194. api_get_user_id()
  195. );
  196. if ($allowCoachFeedbackExercises) {
  197. Display::addFlash(
  198. Display::return_message(get_lang('MessageSent'))
  199. );
  200. header('Location: '.api_get_self().'?'.api_get_cidreq().'&exerciseId='.$exerciseId);
  201. exit;
  202. }
  203. }
  204. // Updating LP score here
  205. if (in_array($origin, array('tracking_course', 'user_course', 'correct_exercise_in_lp'))) {
  206. $sql = "UPDATE $TBL_LP_ITEM_VIEW
  207. 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: '.api_get_path(WEB_CODE_PATH).'exercise/exercise.php?course='.Security::remove_XSS($_GET['course']));
  213. exit;
  214. } else {
  215. // Redirect to the reporting
  216. header('Location: '.api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?origin='.$origin.'&student='.$student_id.'&details=true&course='.$course_id.'&session_id='.$session_id);
  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_session_general_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="exercise.php">'.
  250. Display::return_icon('back.png', get_lang('GoBackToQuestionList'), '', ICON_SIZE_MEDIUM).
  251. '</a>';
  252. }
  253. //Deleting an attempt
  254. if (($is_allowedToEdit || $is_tutor || api_is_coach()) &&
  255. isset($_GET['delete']) && $_GET['delete'] == 'delete' &&
  256. !empty($_GET['did']) && $locked == false
  257. ) {
  258. $exe_id = intval($_GET['did']);
  259. if (!empty($exe_id)) {
  260. $sql = 'DELETE FROM '.$TBL_TRACK_EXERCISES.' WHERE exe_id = '.$exe_id;
  261. Database::query($sql);
  262. $sql = 'DELETE FROM '.$TBL_TRACK_ATTEMPT.' WHERE exe_id = '.$exe_id;
  263. Database::query($sql);
  264. header('Location: exercise_report.php?'.api_get_cidreq().'&exerciseId='.$exercise_id);
  265. exit;
  266. }
  267. }
  268. if ($is_allowedToEdit || $is_tutor) {
  269. $interbreadcrumb[] = array("url" => "exercise.php?gradebook=$gradebook", "name" => get_lang('Exercises'));
  270. $objExerciseTmp = new Exercise();
  271. $nameTools = get_lang('StudentScore');
  272. if ($objExerciseTmp->read($exercise_id)) {
  273. $interbreadcrumb[] = array("url" => "admin.php?exerciseId=".$exercise_id, "name" => $objExerciseTmp->selectTitle(true));
  274. }
  275. } else {
  276. $interbreadcrumb[] = array("url" => "exercise.php?gradebook=$gradebook", "name" => get_lang('Exercises'));
  277. $objExerciseTmp = new Exercise();
  278. if ($objExerciseTmp->read($exercise_id)) {
  279. $nameTools = get_lang('Results').': '.$objExerciseTmp->selectTitle(true);
  280. }
  281. }
  282. if (($is_allowedToEdit || $is_tutor || api_is_coach()) &&
  283. isset($_GET['a']) && $_GET['a'] == 'close' &&
  284. !empty($_GET['id']) && $locked == false
  285. ) {
  286. // Close the user attempt otherwise left pending
  287. $exe_id = intval($_GET['id']);
  288. $sql = "UPDATE $TBL_TRACK_EXERCISES SET status = '' WHERE exe_id = $exe_id AND status = 'incomplete'";
  289. Database::query($sql);
  290. }
  291. Display :: display_header($nameTools);
  292. // Clean all results for this test before the selected date
  293. if (($is_allowedToEdit || $is_tutor || api_is_coach()) &&
  294. isset($_GET['delete_before_date']) && $locked == false
  295. ) {
  296. // ask for the date
  297. $check = Security::check_token('get');
  298. if ($check) {
  299. $objExerciseTmp = new Exercise();
  300. if ($objExerciseTmp->read($exercise_id)) {
  301. $count = $objExerciseTmp->clean_results(
  302. true,
  303. $_GET['delete_before_date'].' 23:59:59'
  304. );
  305. echo Display::return_message(sprintf(get_lang('XResultsCleaned'), $count), 'confirm');
  306. }
  307. }
  308. }
  309. // Security token to protect deletion
  310. $token = Security::get_token();
  311. $actions = Display::div($actions, array('class' => 'actions'));
  312. $extra = '<script>
  313. $(document).ready(function() {
  314. $( "#dialog:ui-dialog" ).dialog( "destroy" );
  315. $( "#dialog-confirm" ).dialog({
  316. autoOpen: false,
  317. show: "blind",
  318. resizable: false,
  319. height:300,
  320. modal: true
  321. });
  322. $("#export_opener").click(function() {
  323. var targetUrl = $(this).attr("href");
  324. $( "#dialog-confirm" ).dialog({
  325. width:400,
  326. height:300,
  327. buttons: {
  328. "'.addslashes(get_lang('Download')).'": function() {
  329. var export_format = $("input[name=export_format]:checked").val();
  330. var extra_data = $("input[name=load_extra_data]:checked").val();
  331. var includeAllUsers = $("input[name=include_all_users]:checked").val();
  332. var attempts = $("input[name=only_best_attempts]:checked").val();
  333. location.href = targetUrl+"&export_format="+export_format+"&extra_data="+extra_data+"&include_all_users="+includeAllUsers+"&only_best_attempts="+attempts;
  334. $( this ).dialog( "close" );
  335. }
  336. }
  337. });
  338. $( "#dialog-confirm" ).dialog("open");
  339. return false;
  340. });
  341. });
  342. </script>';
  343. $extra .= '<div id="dialog-confirm" title="'.get_lang("ConfirmYourChoice").'">';
  344. $form = new FormValidator('report', 'post', null, null, array('class' => 'form-vertical'));
  345. $form->addElement('radio', 'export_format', null, get_lang('ExportAsCSV'), 'csv', array('id' => 'export_format_csv_label'));
  346. $form->addElement('radio', 'export_format', null, get_lang('ExportAsXLS'), 'xls', array('id' => 'export_format_xls_label'));
  347. $form->addElement('checkbox', 'load_extra_data', null, get_lang('LoadExtraData'), '0', array('id' => 'export_format_xls_label'));
  348. $form->addElement('checkbox', 'include_all_users', null, get_lang('IncludeAllUsers'), '0');
  349. $form->addElement('checkbox', 'only_best_attempts', null, get_lang('OnlyBestAttempts'), '0');
  350. $form->setDefaults(array('export_format' => 'csv'));
  351. $extra .= $form->returnForm();
  352. $extra .= '</div>';
  353. if ($is_allowedToEdit) {
  354. echo $extra;
  355. }
  356. echo $actions;
  357. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_exercise_results&exerciseId='.$exercise_id.'&filter_by_user='.$filter_user.'&'.api_get_cidreq();
  358. $action_links = '';
  359. // Generating group list
  360. $group_list = GroupManager::get_group_list();
  361. $group_parameters = array(
  362. 'group_all:'.get_lang('All'),
  363. 'group_none:'.get_lang('None'),
  364. );
  365. foreach ($group_list as $group) {
  366. $group_parameters[] = $group['id'].':'.$group['name'];
  367. }
  368. if (!empty($group_parameters)) {
  369. $group_parameters = implode(';', $group_parameters);
  370. }
  371. $officialCodeInList = api_get_setting('show_official_code_exercise_result_list');
  372. if ($is_allowedToEdit || $is_tutor) {
  373. // The order is important you need to check the the $column variable in the model.ajax.php file
  374. $columns = array(
  375. get_lang('FirstName'),
  376. get_lang('LastName'),
  377. get_lang('LoginName'),
  378. get_lang('Group'),
  379. get_lang('Duration').' ('.get_lang('MinMinute').')',
  380. get_lang('StartDate'),
  381. get_lang('EndDate'),
  382. get_lang('Score'),
  383. get_lang('IP'),
  384. get_lang('Status'),
  385. get_lang('ToolLearnpath'),
  386. get_lang('Actions')
  387. );
  388. if ($officialCodeInList === 'true') {
  389. $columns = array_merge(array(get_lang('OfficialCode')), $columns);
  390. }
  391. //Column config
  392. $column_model = array(
  393. array('name' => 'firstname', 'index' => 'firstname', 'width' => '50', 'align' => 'left', 'search' => 'true'),
  394. array('name' => 'lastname', 'index' => 'lastname', 'width' => '50', 'align' => 'left', 'formatter' => 'action_formatter', 'search' => 'true'),
  395. array('name' => 'login', 'index' => 'username', 'width' => '40', 'align' => 'left', 'search' => 'true', 'hidden' => 'true'),
  396. array('name' => 'group_name', 'index' => 'group_id', 'width' => '40', 'align' => 'left', 'search' => 'true', 'stype' => 'select',
  397. //for the bottom bar
  398. 'searchoptions' => array(
  399. 'defaultValue' => 'group_all',
  400. 'value' => $group_parameters),
  401. //for the top bar
  402. 'editoptions' => array('value' => $group_parameters)),
  403. array('name' => 'duration', 'index' => 'exe_duration', 'width' => '30', 'align' => 'left', 'search' => 'true'),
  404. array('name' => 'start_date', 'index' => 'start_date', 'width' => '60', 'align' => 'left', 'search' => 'true'),
  405. array('name' => 'exe_date', 'index' => 'exe_date', 'width' => '60', 'align' => 'left', 'search' => 'true'),
  406. array('name' => 'score', 'index' => 'exe_result', 'width' => '50', 'align' => 'center', 'search' => 'true'),
  407. array('name' => 'ip', 'index' => 'user_ip', 'width' => '40', 'align' => 'center', 'search' => 'true'),
  408. array('name' => 'status', 'index' => 'revised', 'width' => '40', 'align' => 'left', 'search' => 'true', 'stype' => 'select',
  409. //for the bottom bar
  410. 'searchoptions' => array(
  411. 'defaultValue' => '',
  412. 'value' => ':'.get_lang('All').';1:'.get_lang('Validated').';0:'.get_lang('NotValidated')),
  413. //for the top bar
  414. 'editoptions' => array('value' => ':'.get_lang('All').';1:'.get_lang('Validated').';0:'.get_lang('NotValidated'))),
  415. array('name' => 'lp', 'index' => 'lp', 'width' => '60', 'align' => 'left', 'search' => 'false'),
  416. array('name' => 'actions', 'index' => 'actions', 'width' => '60', 'align' => 'left', 'search' => 'false')
  417. );
  418. if ($officialCodeInList == 'true') {
  419. $officialCodeRow = array('name' => 'official_code', 'index' => 'official_code', 'width' => '50', 'align' => 'left', 'search' => 'true');
  420. $column_model = array_merge(array($officialCodeRow), $column_model);
  421. }
  422. $action_links = '
  423. // add username as title in lastname filed - ref 4226
  424. function action_formatter(cellvalue, options, rowObject) {
  425. // rowObject is firstname,lastname,login,... get the third word
  426. var loginx = "'.api_htmlentities(sprintf(get_lang("LoginX"), ":::"), ENT_QUOTES).'";
  427. var tabLoginx = loginx.split(/:::/);
  428. // tabLoginx[0] is before and tabLoginx[1] is after :::
  429. // may be empty string but is defined
  430. return "<span title=\""+tabLoginx[0]+rowObject[2]+tabLoginx[1]+"\">"+cellvalue+"</span>";
  431. }';
  432. }
  433. //Autowidth
  434. $extra_params['autowidth'] = 'true';
  435. //height auto
  436. $extra_params['height'] = 'auto';
  437. ?>
  438. <script>
  439. function setSearchSelect(columnName) {
  440. $("#results").jqGrid(
  441. 'setColProp',
  442. columnName, {
  443. searchoptions:{
  444. dataInit:function(el) {
  445. $("option[value='1']",el).attr("selected", "selected");
  446. setTimeout(function(){
  447. $(el).trigger('change');
  448. },1000);
  449. }
  450. }
  451. }
  452. );
  453. }
  454. function exportExcel() {
  455. var mya=new Array();
  456. mya=$("#results").getDataIDs(); // Get All IDs
  457. var data=$("#results").getRowData(mya[0]); // Get First row to get the labels
  458. var colNames=new Array();
  459. var ii=0;
  460. for (var i in data){colNames[ii++]=i;} // capture col names
  461. var html="";
  462. for(i=0;i<mya.length;i++) {
  463. data=$("#results").getRowData(mya[i]); // get each row
  464. for(j=0;j<colNames.length;j++) {
  465. html=html+data[colNames[j]]+","; // output each column as tab delimited
  466. }
  467. html=html+"\n"; // output each row with end of line
  468. }
  469. html = html+"\n"; // end of line at the end
  470. var form = $("#export_report_form");
  471. $("#csvBuffer").attr('value', html);
  472. form.target='_blank';
  473. form.submit();
  474. }
  475. $(function() {
  476. <?php
  477. echo Display::grid_js(
  478. 'results',
  479. $url,
  480. $columns,
  481. $column_model,
  482. $extra_params,
  483. array(),
  484. $action_links,
  485. true
  486. );
  487. if ($is_allowedToEdit || $is_tutor) {
  488. ?>
  489. //setSearchSelect("status");
  490. //
  491. //view:true, del:false, add:false, edit:false, excel:true}
  492. $("#results").jqGrid('navGrid','#results_pager', {view:true, edit:false, add:false, del:false, excel:false},
  493. {height:280, reloadAfterSubmit:false}, // view options
  494. {height:280, reloadAfterSubmit:false}, // edit options
  495. {height:280, reloadAfterSubmit:false}, // add options
  496. {reloadAfterSubmit: false}, // del options
  497. {width:500} // search options
  498. );
  499. /*
  500. // add custom button to export the data to excel
  501. jQuery("#results").jqGrid('navButtonAdd','#results_pager',{
  502. caption:"",
  503. onClickButton : function () {
  504. //exportExcel();
  505. }
  506. });*/
  507. /*
  508. jQuery('#sessions').jqGrid('navButtonAdd','#sessions_pager',{id:'pager_csv',caption:'',title:'Export To CSV',onClickButton : function(e)
  509. {
  510. try {
  511. jQuery("#sessions").jqGrid('excelExport',{tag:'csv', url:'grid.php'});
  512. } catch (e) {
  513. window.location= 'grid.php?oper=csv';
  514. }
  515. },buttonicon:'ui-icon-document'})
  516. */
  517. //Adding search options
  518. var options = {
  519. 'stringResult': true,
  520. 'autosearch' : true,
  521. 'searchOnEnter':false
  522. }
  523. jQuery("#results").jqGrid('filterToolbar',options);
  524. var sgrid = $("#results")[0];
  525. sgrid.triggerToolbar();
  526. $('#results').on('click', 'a.exercise-recalculate', function (e) {
  527. e.preventDefault();
  528. if (!$(this).data('user') || !$(this).data('exercise') || !$(this).data('id')) {
  529. return;
  530. }
  531. var url = '<?php echo api_get_path(WEB_CODE_PATH) ?>exercise/recalculate.php?<?php echo api_get_cidreq() ?>';
  532. var recalculateXhr = $.post(url, $(this).data());
  533. $.when(recalculateXhr).done(function (response) {
  534. $('#results').trigger('reloadGrid');
  535. });
  536. });
  537. <?php } ?>
  538. });
  539. // datepicker functions
  540. var datapickerInputModified = false;
  541. /**
  542. * return true if the datepicker input has been modified
  543. */
  544. function datepicker_input_changed() {
  545. datapickerInputModified = true;
  546. }
  547. /**
  548. * disply the datepicker calendar on mouse over the input
  549. */
  550. function datepicker_input_mouseover() {
  551. $('#datepicker_start').datepicker( "show" );
  552. }
  553. /**
  554. * display or hide the datepicker input, calendar and button
  555. */
  556. function display_date_picker() {
  557. if (!$('#datepicker_span').is(":visible")) {
  558. $('#datepicker_span').show();
  559. $('#datepicker_start').datepicker( "show" );
  560. } else {
  561. $('#datepicker_start').datepicker( "hide" );
  562. $('#datepicker_span').hide();
  563. }
  564. }
  565. /**
  566. * confirm deletion
  567. */
  568. function submit_datepicker() {
  569. if (datapickerInputModified) {
  570. var dateTypeVar = $('#datepicker_start').datepicker('getDate');
  571. var dateForBDD = $.datepicker.formatDate('yy-mm-dd', dateTypeVar);
  572. // Format the date for confirm box
  573. var dateFormat = $( "#datepicker_start" ).datepicker( "option", "dateFormat" );
  574. var selectedDate = $.datepicker.formatDate(dateFormat, dateTypeVar);
  575. if (confirm("<?php echo convert_double_quote_to_single(get_lang('AreYouSureDeleteTestResultBeforeDateD')); ?>" + selectedDate)) {
  576. 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; ?>";
  577. }
  578. }
  579. }
  580. /**
  581. * initiate datepicker
  582. */
  583. $(function() {
  584. $( "#datepicker_start" ).datepicker({
  585. defaultDate: "",
  586. changeMonth: false,
  587. numberOfMonths: 1
  588. });
  589. });
  590. </script>
  591. <form id="export_report_form" method="post" action="exercise_report.php?<?php echo api_get_cidreq(); ?>">
  592. <input type="hidden" name="csvBuffer" id="csvBuffer" value="" />
  593. <input type="hidden" name="export_report" id="export_report" value="1" />
  594. <input type="hidden" name="exerciseId" id="exerciseId" value="<?php echo $exercise_id ?>" />
  595. </form>
  596. <?php
  597. echo Display::grid_html('results');
  598. Display :: display_footer();