MDL-80880 quiz: change display of previous attempts summary
[moodle.git] / course / reset.php
blobfc042ed6a8666f8616cc5d8108fa4e49ebb4e0c7
1 <?php
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.
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/>.
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.
25 * @copyright Mark Flach and moodle.com
26 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 * @package course
30 require('../config.php');
31 require_once('reset_form.php');
32 require_once($CFG->dirroot . '/backup/util/interfaces/checksumable.class.php');
33 require_once($CFG->dirroot . '/backup/backup.class.php');
34 require_once($CFG->dirroot . '/backup/util/helper/backup_helper.class.php');
36 $id = required_param('id', PARAM_INT);
38 if (!$course = $DB->get_record('course', array('id'=>$id))) {
39 throw new \moodle_exception("invalidcourseid");
42 $PAGE->set_url('/course/reset.php', array('id'=>$id));
43 $PAGE->set_pagelayout('admin');
45 require_login($course);
46 require_capability('moodle/course:reset', context_course::instance($course->id));
48 $strreset = get_string('reset');
49 $strresetcourse = get_string('resetcourse');
50 $strremove = get_string('remove');
52 $PAGE->set_title($course->fullname.': '.$strresetcourse);
53 $PAGE->set_heading($course->fullname);
54 $PAGE->set_secondary_active_tab('coursereuse');
56 $mform = new course_reset_form();
58 if ($mform->is_cancelled()) {
59 redirect($CFG->wwwroot.'/course/view.php?id='.$id);
61 } else if ($data = $mform->get_data()) { // no magic quotes
63 if (isset($data->selectdefault)) {
64 $_POST = array();
65 $mform = new course_reset_form();
66 $mform->load_defaults();
68 } else if (isset($data->deselectall)) {
69 $_POST = array();
70 $mform = new course_reset_form();
72 } else {
73 echo $OUTPUT->header();
74 \backup_helper::print_coursereuse_selector('reset');
76 $data->reset_start_date_old = $course->startdate;
77 $data->reset_end_date_old = $course->enddate;
78 $status = reset_course_userdata($data);
80 $data = array();
81 foreach ($status as $item) {
82 $line = array();
83 $line[] = $item['component'];
84 $line[] = $item['item'];
85 $line[] = ($item['error'] === false) ? get_string('statusok') : '<div class="notifyproblem">'.$item['error'].'</div>';
86 $data[] = $line;
89 $table = new html_table();
90 $table->head = array(get_string('resetcomponent'), get_string('resettask'), get_string('resetstatus'));
91 $table->size = array('20%', '40%', '40%');
92 $table->align = array('left', 'left', 'left');
93 $table->width = '80%';
94 $table->data = $data;
95 echo html_writer::table($table);
97 echo $OUTPUT->continue_button('view.php?id='.$course->id); // Back to course page
98 echo $OUTPUT->footer();
99 exit;
103 echo $OUTPUT->header();
104 \backup_helper::print_coursereuse_selector('reset');
106 echo $OUTPUT->box(get_string('resetinfo'));
108 $mform->display();
109 echo $OUTPUT->footer();