| 1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
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.
|
|
|
8 |
//
|
|
|
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.
|
|
|
13 |
//
|
|
|
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/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
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.
|
|
|
23 |
*
|
| 1441 |
ariadna |
24 |
* @package core_course
|
| 1 |
efrain |
25 |
* @copyright Mark Flach and moodle.com
|
| 1441 |
ariadna |
26 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| 1 |
efrain |
27 |
*/
|
|
|
28 |
|
|
|
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');
|
|
|
34 |
|
|
|
35 |
$id = required_param('id', PARAM_INT);
|
|
|
36 |
|
| 1441 |
ariadna |
37 |
if (!$course = $DB->get_record('course', ['id' => $id])) {
|
|
|
38 |
throw new \moodle_exception('invalidcourseid');
|
| 1 |
efrain |
39 |
}
|
|
|
40 |
|
| 1441 |
ariadna |
41 |
$PAGE->set_url('/course/reset.php', ['id' => $id]);
|
|
|
42 |
$PAGE->set_pagelayout('standard');
|
| 1 |
efrain |
43 |
|
|
|
44 |
require_login($course);
|
|
|
45 |
require_capability('moodle/course:reset', context_course::instance($course->id));
|
|
|
46 |
|
|
|
47 |
$strreset = get_string('reset');
|
|
|
48 |
$strresetcourse = get_string('resetcourse');
|
|
|
49 |
$strremove = get_string('remove');
|
|
|
50 |
|
|
|
51 |
$PAGE->set_title($course->fullname.': '.$strresetcourse);
|
|
|
52 |
$PAGE->set_heading($course->fullname);
|
|
|
53 |
$PAGE->set_secondary_active_tab('coursereuse');
|
|
|
54 |
|
|
|
55 |
$mform = new course_reset_form();
|
|
|
56 |
|
|
|
57 |
if ($mform->is_cancelled()) {
|
| 1441 |
ariadna |
58 |
redirect($CFG->wwwroot . '/course/view.php?id='.$id);
|
| 1 |
efrain |
59 |
|
| 1441 |
ariadna |
60 |
} else if ($data = $mform->get_data()) { // No magic quotes.
|
| 1 |
efrain |
61 |
|
|
|
62 |
if (isset($data->selectdefault)) {
|
| 1441 |
ariadna |
63 |
$_POST = [];
|
| 1 |
efrain |
64 |
$mform = new course_reset_form();
|
|
|
65 |
$mform->load_defaults();
|
|
|
66 |
|
|
|
67 |
} else if (isset($data->deselectall)) {
|
| 1441 |
ariadna |
68 |
$_POST = [];
|
| 1 |
efrain |
69 |
$mform = new course_reset_form();
|
|
|
70 |
|
|
|
71 |
} else {
|
|
|
72 |
echo $OUTPUT->header();
|
|
|
73 |
\backup_helper::print_coursereuse_selector('reset');
|
|
|
74 |
|
|
|
75 |
$data->reset_start_date_old = $course->startdate;
|
|
|
76 |
$data->reset_end_date_old = $course->enddate;
|
|
|
77 |
$status = reset_course_userdata($data);
|
|
|
78 |
|
| 1441 |
ariadna |
79 |
$data = [];
|
| 1 |
efrain |
80 |
foreach ($status as $item) {
|
| 1441 |
ariadna |
81 |
$line = [];
|
| 1 |
efrain |
82 |
$line[] = $item['component'];
|
|
|
83 |
$line[] = $item['item'];
|
| 1441 |
ariadna |
84 |
if ($item['error'] === false) {
|
|
|
85 |
$line[] = get_string('statusdone');
|
|
|
86 |
} else {
|
|
|
87 |
$line[] = html_writer::div(
|
|
|
88 |
$OUTPUT->pix_icon('i/invalid', get_string('error')) . $item['error'],
|
|
|
89 |
);
|
|
|
90 |
}
|
| 1 |
efrain |
91 |
$data[] = $line;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
$table = new html_table();
|
| 1441 |
ariadna |
95 |
$table->head = [get_string('resetcomponent'), get_string('resettask'), get_string('resetstatus')];
|
|
|
96 |
$table->size = ['20%', '40%', '40%'];
|
|
|
97 |
$table->align = ['left', 'left', 'left'];
|
| 1 |
efrain |
98 |
$table->width = '80%';
|
|
|
99 |
$table->data = $data;
|
|
|
100 |
echo html_writer::table($table);
|
|
|
101 |
|
| 1441 |
ariadna |
102 |
echo $OUTPUT->continue_button('view.php?id=' . $course->id); // Back to course page.
|
| 1 |
efrain |
103 |
echo $OUTPUT->footer();
|
|
|
104 |
exit;
|
|
|
105 |
}
|
| 1441 |
ariadna |
106 |
} else {
|
|
|
107 |
$mform = new course_reset_form();
|
|
|
108 |
$mform->load_defaults();
|
| 1 |
efrain |
109 |
}
|
|
|
110 |
|
| 1441 |
ariadna |
111 |
$PAGE->requires->js_call_amd('core_course/resetcourse', 'init');
|
| 1 |
efrain |
112 |
echo $OUTPUT->header();
|
|
|
113 |
\backup_helper::print_coursereuse_selector('reset');
|
|
|
114 |
|
|
|
115 |
echo $OUTPUT->box(get_string('resetinfo'));
|
| 1441 |
ariadna |
116 |
echo $OUTPUT->box(get_string('resetinfoselect'));
|
| 1 |
efrain |
117 |
|
|
|
118 |
$mform->display();
|
|
|
119 |
echo $OUTPUT->footer();
|