MDL-70595 core: Updated security.txt expiry
[moodle.git] / backup / copy.php
blob6243090dbe5365929904470572eecdad77af7529
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.
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/>.
17 /**
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');
28 defined('MOODLE_INTERNAL') || die();
30 $courseid = required_param('id', PARAM_INT);
31 $returnto = optional_param('returnto', 'course', PARAM_ALPHANUM); // Generic navigation return page switch.
32 $returnurl = optional_param('returnurl', '', PARAM_LOCALURL); // A return URL. returnto must also be set to 'url'.
34 $url = new moodle_url('/backup/copy.php', array('id' => $courseid));
35 $course = get_course($courseid);
36 $coursecontext = context_course::instance($course->id);
38 // Security and access checks.
39 require_login($course, false);
40 $copycaps = \core_course\management\helper::get_course_copy_capabilities();
41 require_all_capabilities($copycaps, $coursecontext);
43 if ($returnurl != '') {
44 $returnurl = new moodle_url($returnurl);
45 } else if ($returnto == 'catmanage') {
46 // Redirect to category management page.
47 $returnurl = new moodle_url('/course/management.php', array('categoryid' => $course->category));
48 } else {
49 // Redirect back to course page if we came from there.
50 $returnurl = new moodle_url('/course/view.php', array('id' => $courseid));
53 // Setup the page.
54 $title = get_string('copycoursetitle', 'backup', $course->shortname);
55 $heading = get_string('copycourseheading', 'backup');
56 $PAGE->set_url($url);
57 $PAGE->set_pagelayout('admin');
58 $PAGE->set_title($title);
59 $PAGE->set_heading($heading);
61 // Get data ready for mform.
62 $mform = new \core_backup\output\copy_form(
63 $url,
64 array('course' => $course, 'returnto' => $returnto, 'returnurl' => $returnurl));
66 if ($mform->is_cancelled()) {
67 // The form has been cancelled, take them back to what ever the return to is.
68 redirect($returnurl);
70 } else if ($mdata = $mform->get_data()) {
72 // Process the form and create the copy task.
73 $backupcopy = new \core_backup\copy\copy($mdata);
74 $backupcopy->create_copy();
76 if (!empty($mdata->submitdisplay)) {
77 // Redirect to the copy progress overview.
78 $progressurl = new moodle_url('/backup/copyprogress.php', array('id' => $courseid));
79 redirect($progressurl);
80 } else {
81 // Redirect to the course view page.
82 $coursesurl = new moodle_url('/course/view.php', array('id' => $courseid));
83 redirect($coursesurl);
86 } else {
87 // This branch is executed if the form is submitted but the data doesn't validate,
88 // or on the first display of the form.
90 // Build the page output.
91 echo $OUTPUT->header();
92 echo $OUTPUT->heading($title);
93 $mform->display();
94 echo $OUTPUT->footer();