2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * The purpose of this feature is to quickly remove all user related data from a course
19 * in order to make it available for a new semester. This feature can handle the removal
20 * of general course data like students, teachers, logs, events and groups as well as module
21 * specific data. Each module must be modified to take advantage of this new feature.
22 * The feature will also reset the start date of the course if necessary.
24 * @package core_course
25 * @copyright Mark Flach and moodle.com
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29 require('../config.php');
30 require_once('reset_form.php');
31 require_once($CFG->dirroot
. '/backup/util/interfaces/checksumable.class.php');
32 require_once($CFG->dirroot
. '/backup/backup.class.php');
33 require_once($CFG->dirroot
. '/backup/util/helper/backup_helper.class.php');
35 $id = required_param('id', PARAM_INT
);
37 if (!$course = $DB->get_record('course', ['id' => $id])) {
38 throw new \
moodle_exception('invalidcourseid');
41 $PAGE->set_url('/course/reset.php', ['id' => $id]);
42 $PAGE->set_pagelayout('standard');
44 require_login($course);
45 require_capability('moodle/course:reset', context_course
::instance($course->id
));
47 $strreset = get_string('reset');
48 $strresetcourse = get_string('resetcourse');
49 $strremove = get_string('remove');
51 $PAGE->set_title($course->fullname
.': '.$strresetcourse);
52 $PAGE->set_heading($course->fullname
);
53 $PAGE->set_secondary_active_tab('coursereuse');
55 $mform = new course_reset_form();
57 if ($mform->is_cancelled()) {
58 redirect($CFG->wwwroot
. '/course/view.php?id='.$id);
60 } else if ($data = $mform->get_data()) { // No magic quotes.
62 if (isset($data->selectdefault
)) {
64 $mform = new course_reset_form();
65 $mform->load_defaults();
67 } else if (isset($data->deselectall
)) {
69 $mform = new course_reset_form();
72 echo $OUTPUT->header();
73 \backup_helper
::print_coursereuse_selector('reset');
75 $data->reset_start_date_old
= $course->startdate
;
76 $data->reset_end_date_old
= $course->enddate
;
77 $status = reset_course_userdata($data);
80 foreach ($status as $item) {
82 $line[] = $item['component'];
83 $line[] = $item['item'];
84 if ($item['error'] === false) {
85 $line[] = get_string('statusdone');
87 $line[] = html_writer
::div(
88 $OUTPUT->pix_icon('i/invalid', get_string('error')) . $item['error'],
94 $table = new html_table();
95 $table->head
= [get_string('resetcomponent'), get_string('resettask'), get_string('resetstatus')];
96 $table->size
= ['20%', '40%', '40%'];
97 $table->align
= ['left', 'left', 'left'];
98 $table->width
= '80%';
100 echo html_writer
::table($table);
102 echo $OUTPUT->continue_button('view.php?id=' . $course->id
); // Back to course page.
103 echo $OUTPUT->footer();
107 $mform = new course_reset_form();
108 $mform->load_defaults();
111 $PAGE->requires
->js_call_amd('core_course/resetcourse', 'init');
112 echo $OUTPUT->header();
113 \backup_helper
::print_coursereuse_selector('reset');
115 echo $OUTPUT->box(get_string('resetinfo'));
116 echo $OUTPUT->box(get_string('resetinfoselect'));
119 echo $OUTPUT->footer();