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 * This script is used to configure and execute the course copy proccess.
20 * @package core_backup
21 * @copyright 2020 onward The Moodle Users Association <https://moodleassociation.org/>
22 * @author Matt Porritt <mattp@catalyst-au.net>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once('../config.php');
27 require_once($CFG->dirroot
. '/backup/util/includes/backup_includes.php');
29 defined('MOODLE_INTERNAL') ||
die();
31 $courseid = required_param('id', PARAM_INT
);
32 $returnto = optional_param('returnto', 'course', PARAM_ALPHANUM
); // Generic navigation return page switch.
33 $returnurl = optional_param('returnurl', '', PARAM_LOCALURL
); // A return URL. returnto must also be set to 'url'.
35 $url = new moodle_url('/backup/copy.php', array('id' => $courseid));
36 $course = get_course($courseid);
37 $coursecontext = context_course
::instance($course->id
);
39 // Security and access checks.
40 require_login($course, false);
41 $copycaps = \core_course\management\helper
::get_course_copy_capabilities();
42 require_all_capabilities($copycaps, $coursecontext);
44 if ($returnurl != '') {
45 $returnurl = new moodle_url($returnurl);
46 } else if ($returnto == 'catmanage') {
47 // Redirect to category management page.
48 $returnurl = new moodle_url('/course/management.php', array('categoryid' => $course->category
));
50 // Redirect back to course page if we came from there.
51 $returnurl = new moodle_url('/course/view.php', array('id' => $courseid));
55 $title = get_string('copycoursetitle', 'backup', $course->shortname
);
56 $heading = get_string('copycourseheading', 'backup');
58 $PAGE->set_pagelayout('admin');
59 $PAGE->set_title($title);
60 $PAGE->set_heading($heading);
61 $PAGE->set_secondary_active_tab('coursereuse');
63 // Get data ready for mform.
64 $mform = new \core_backup\output\
copy_form(
66 array('course' => $course, 'returnto' => $returnto, 'returnurl' => $returnurl));
68 if ($mform->is_cancelled()) {
69 // The form has been cancelled, take them back to what ever the return to is.
72 } else if ($mdata = $mform->get_data()) {
74 // Process the form and create the copy task.
75 $copydata = \copy_helper
::process_formdata($mdata);
76 \copy_helper
::create_copy($copydata);
78 if (!empty($mdata->submitdisplay
)) {
79 // Redirect to the copy progress overview.
80 $progressurl = new moodle_url('/backup/copyprogress.php', array('id' => $courseid));
81 redirect($progressurl);
83 // Redirect to the course view page.
84 $coursesurl = new moodle_url('/course/view.php', array('id' => $courseid));
85 redirect($coursesurl);
89 // This branch is executed if the form is submitted but the data doesn't validate,
90 // or on the first display of the form.
92 // Build the page output.
93 echo $OUTPUT->header();
94 echo $OUTPUT->heading($title);
96 echo $OUTPUT->footer();