exercise_report.php 26 KB

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