|
| 1 | +<?php |
| 2 | +/* For licensing terms, see /license.txt */ |
| 3 | +/** |
| 4 | + * This script exports the PDF reports from a test for several students at once. |
| 5 | + * This script is the teacher view of a similar script (for admins) at main/admin/export_exercise_results.php |
| 6 | + */ |
| 7 | +require_once __DIR__.'/../../inc/global.inc.php'; |
| 8 | + |
| 9 | +// Setting the section (for the tabs). |
| 10 | +$this_section = SECTION_COURSES; |
| 11 | + |
| 12 | +api_protect_course_script(true); |
| 13 | +if (!api_is_allowed_to_edit()) { |
| 14 | + api_not_allowed(true); |
| 15 | +} |
| 16 | + |
| 17 | +$sessionId = api_get_session_id(); |
| 18 | +$courseId = api_get_course_int_id(); |
| 19 | +$exerciseId = isset($_REQUEST['exerciseId']) ? (int) $_REQUEST['exerciseId'] : null; |
| 20 | +$exerciseIdChanged = isset($_GET['exercise_id_changed']) ? (int) $_GET['exercise_id_changed'] : null; |
| 21 | + |
| 22 | +$courseInfo = []; |
| 23 | +if (empty($courseId)) { |
| 24 | + $exerciseId = 0; |
| 25 | +} else { |
| 26 | + $courseInfo = api_get_course_info_by_id($courseId); |
| 27 | +} |
| 28 | + |
| 29 | +$interbreadcrumb[] = ['url' => '../exercise.php?'.api_get_cidreq(), 'name' => get_lang('Exercises')]; |
| 30 | + |
| 31 | +$confirmYourChoice = addslashes(get_lang('ConfirmYourChoice')); |
| 32 | +$htmlHeadXtra[] = " |
| 33 | +<script> |
| 34 | + function submit_form(obj) { |
| 35 | + document.export_all_results_form.submit(); |
| 36 | + } |
| 37 | +
|
| 38 | + function mark_exercise_id_changed() { |
| 39 | + $('#exercise_id_changed').val('0'); |
| 40 | + } |
| 41 | +
|
| 42 | + function confirm_your_choice() { |
| 43 | + return confirm('$confirmYourChoice'); |
| 44 | + } |
| 45 | +</script>"; |
| 46 | + |
| 47 | +// Get exercise list for this course |
| 48 | +$exerciseList = ExerciseLib::get_all_exercises_for_course_id( |
| 49 | + $courseInfo, |
| 50 | + $sessionId, |
| 51 | + $courseId, |
| 52 | + false |
| 53 | +); |
| 54 | + |
| 55 | +$exerciseSelectList = []; |
| 56 | +$exerciseSelectList = [0 => get_lang('All')]; |
| 57 | +if (is_array($exerciseList)) { |
| 58 | + foreach ($exerciseList as $row) { |
| 59 | + $exerciseTitle = $row['title']; |
| 60 | + $exerciseSelectList[$row['iid']] = $exerciseTitle; |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +$url = api_get_self().'?'.api_get_cidreq().'&'.http_build_query( |
| 65 | + [ |
| 66 | + 'session_id' => $sessionId, |
| 67 | + 'exerciseId' => $exerciseId, |
| 68 | + 'exercise_id_changed' => $exerciseIdChanged, |
| 69 | + ] |
| 70 | + ); |
| 71 | + |
| 72 | +// Form |
| 73 | +$form = new FormValidator('export_all_results_form', 'GET', $url); |
| 74 | +$form->addHeader(get_lang('ExportExerciseAllResults')); |
| 75 | +$form |
| 76 | + ->addSelect( |
| 77 | + 'exerciseId', |
| 78 | + get_lang('Exercise'), |
| 79 | + $exerciseSelectList |
| 80 | + ) |
| 81 | + ->setSelected($exerciseId); |
| 82 | + |
| 83 | +$form->addDateTimePicker('start_date', get_lang('StartDate')); |
| 84 | +$form->addDateTimePicker('end_date', get_lang('EndDate')); |
| 85 | +$form->addRule('start_date', get_lang('InvalidDate'), 'datetime'); |
| 86 | +$form->addRule('end_date', get_lang('InvalidDate'), 'datetime'); |
| 87 | + |
| 88 | +$form->addRule( |
| 89 | + ['start_date', 'end_date'], |
| 90 | + get_lang('StartDateShouldBeBeforeEndDate'), |
| 91 | + 'date_compare', |
| 92 | + 'lte' |
| 93 | +); |
| 94 | + |
| 95 | +$form->addHidden('exercise_id_changed', '0'); |
| 96 | +$form->addButtonExport(get_lang('Export'), 'name'); |
| 97 | + |
| 98 | +if ($form->validate()) { |
| 99 | + $values = $form->getSubmitValues(); |
| 100 | + |
| 101 | + $exerciseId = (int) $values['exerciseId']; |
| 102 | + $filterDates = [ |
| 103 | + 'start_date' => (!empty($values['start_date']) ? $values['start_date'] : ''), |
| 104 | + 'end_date' => (!empty($values['end_date']) ? $values['end_date'] : ''), |
| 105 | + ]; |
| 106 | + if ($exerciseId === 0) { |
| 107 | + ExerciseLib::exportAllExercisesResultsZip($sessionId, $courseId, $filterDates); |
| 108 | + } else { |
| 109 | + ExerciseLib::exportExerciseAllResultsZip($sessionId, $courseId, $exerciseId, $filterDates); |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +Display::display_header(get_lang('ExportExerciseAllResults')); |
| 114 | + |
| 115 | + |
| 116 | +echo $form->display(); |
| 117 | + |
| 118 | +Display::display_footer(); |
0 commit comments