exercise_report.php 27 KB

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