d9cb06dc |
1 | <?php |
2 | |
3 | // This file is part of Moodle - http://moodle.org/ |
4 | // |
5 | // Moodle is free software: you can redistribute it and/or modify |
6 | // it under the terms of the GNU General Public License as published by |
7 | // the Free Software Foundation, either version 3 of the License, or |
8 | // (at your option) any later version. |
9 | // |
10 | // Moodle is distributed in the hope that it will be useful, |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | // GNU General Public License for more details. |
14 | // |
15 | // You should have received a copy of the GNU General Public License |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
17 | |
18 | /** |
19 | * The purpose of this feature is to quickly remove all user related data from a course |
20 | * in order to make it available for a new semester. This feature can handle the removal |
21 | * of general course data like students, teachers, logs, events and groups as well as module |
22 | * specific data. Each module must be modified to take advantage of this new feature. |
23 | * The feature will also reset the start date of the course if necessary. |
24 | * |
25 | * @copyright Mark Flach and moodle.com |
26 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
27 | * @package course |
28 | */ |
ffd0fbb7 |
29 | |
0b5a80a1 |
30 | require('../config.php'); |
31 | require_once('reset_form.php'); |
ffd0fbb7 |
32 | |
0b5a80a1 |
33 | $id = required_param('id', PARAM_INT); |
665f8762 |
34 | |
f400841b |
35 | if (!$course = $DB->get_record('course', array('id'=>$id))) { |
ba6018a9 |
36 | print_error("invalidcourseid"); |
0b5a80a1 |
37 | } |
ffd0fbb7 |
38 | |
a6855934 |
39 | $PAGE->set_url('/course/reset.php', array('id'=>$id)); |
d5814f4e |
40 | $PAGE->set_pagelayout('admin'); |
d9cb06dc |
41 | |
0b5a80a1 |
42 | require_login($course); |
4a1c6c58 |
43 | require_capability('moodle/course:reset', context_course::instance($course->id)); |
ffd0fbb7 |
44 | |
0b5a80a1 |
45 | $strreset = get_string('reset'); |
46 | $strresetcourse = get_string('resetcourse'); |
47 | $strremove = get_string('remove'); |
0be6f678 |
48 | |
0a122046 |
49 | $PAGE->navbar->add($strresetcourse); |
50 | $PAGE->set_title($course->fullname.': '.$strresetcourse); |
51 | $PAGE->set_heading($course->fullname.': '.$strresetcourse); |
0be6f678 |
52 | |
0b5a80a1 |
53 | $mform = new course_reset_form(); |
ffd0fbb7 |
54 | |
0b5a80a1 |
55 | if ($mform->is_cancelled()) { |
56 | redirect($CFG->wwwroot.'/course/view.php?id='.$id); |
ffd0fbb7 |
57 | |
294ce987 |
58 | } else if ($data = $mform->get_data()) { // no magic quotes |
ffd0fbb7 |
59 | |
0b5a80a1 |
60 | if (isset($data->selectdefault)) { |
61 | $_POST = array(); |
62 | $mform = new course_reset_form(); |
63 | $mform->load_defaults(); |
ffd0fbb7 |
64 | |
0b5a80a1 |
65 | } else if (isset($data->deselectall)) { |
66 | $_POST = array(); |
67 | $mform = new course_reset_form(); |
ffd0fbb7 |
68 | |
0b5a80a1 |
69 | } else { |
0a122046 |
70 | echo $OUTPUT->header(); |
7c5286cd |
71 | echo $OUTPUT->heading($strresetcourse); |
0b5a80a1 |
72 | |
73 | $data->reset_start_date_old = $course->startdate; |
8643c576 |
74 | $data->reset_end_date_old = $course->enddate; |
0b5a80a1 |
75 | $status = reset_course_userdata($data); |
76 | |
0e35ba6f |
77 | $data = array(); |
0b5a80a1 |
78 | foreach ($status as $item) { |
79 | $line = array(); |
80 | $line[] = $item['component']; |
81 | $line[] = $item['item']; |
82 | $line[] = ($item['error']===false) ? get_string('ok') : '<div class="notifyproblem">'.$item['error'].'</div>'; |
83 | $data[] = $line; |
ffd0fbb7 |
84 | } |
0b5a80a1 |
85 | |
b4531207 |
86 | $table = new html_table(); |
0b5a80a1 |
87 | $table->head = array(get_string('resetcomponent'), get_string('resettask'), get_string('resetstatus')); |
88 | $table->size = array('20%', '40%', '40%'); |
89 | $table->align = array('left', 'left', 'left'); |
90 | $table->width = '80%'; |
91 | $table->data = $data; |
16be8974 |
92 | echo html_writer::table($table); |
0b5a80a1 |
93 | |
e6db3026 |
94 | echo $OUTPUT->continue_button('view.php?id='.$course->id); // Back to course page |
d60c1124 |
95 | echo $OUTPUT->footer(); |
ffd0fbb7 |
96 | exit; |
97 | } |
0b5a80a1 |
98 | } |
ffd0fbb7 |
99 | |
0a122046 |
100 | echo $OUTPUT->header(); |
7c5286cd |
101 | echo $OUTPUT->heading($strresetcourse); |
ffd0fbb7 |
102 | |
e6db3026 |
103 | echo $OUTPUT->box(get_string('resetinfo')); |
ffd0fbb7 |
104 | |
0b5a80a1 |
105 | $mform->display(); |
d60c1124 |
106 | echo $OUTPUT->footer(); |
ffd0fbb7 |
107 | |
aa6c1ced |
108 | |