Merge branch 'MDL-81456-main' of https://github.com/andrewnicols/moodle
[moodle.git] / backup / view.php
blob1ff7af82d879be6213037e055ecb7a3a67dd0e2f
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 * Page to view the course reuse actions.
20 * @package core_backup
21 * @copyright 2023 Sara Arjona <sara@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once(__DIR__ . '/../config.php');
27 // Course id.
28 $courseid = required_param('id', PARAM_INT);
30 $PAGE->set_url(new moodle_url('/backup/view.php', ['id' => $courseid]));
32 // Basic access checks.
33 if (!$course = $DB->get_record('course', ['id' => $courseid])) {
34 throw new \moodle_exception('invalidcourseid');
36 require_login($course);
38 $title = get_string('coursereuse');
39 // Only append the course name if the course ID is not the site ID.
40 if ($courseid != SITEID) {
41 $title .= moodle_page::TITLE_SEPARATOR . $course->fullname;
43 // Otherwise, output the page with a notification stating that there are no available course reuse actions.
44 $PAGE->set_title($title);
45 $PAGE->set_pagelayout('incourse');
46 $PAGE->set_heading($course->fullname);
47 $PAGE->set_pagetype('course-view-' . $course->format);
48 $PAGE->add_body_class('limitedwidth');
50 echo $OUTPUT->header();
51 echo $OUTPUT->heading(get_string('coursereuse'));
53 // Check if there is at least one displayable course reuse action.
54 $hasactions = false;
55 if ($coursereusenode = $PAGE->settingsnav->find('coursereuse', \navigation_node::TYPE_CONTAINER)) {
56 foreach ($coursereusenode->children as $child) {
57 if ($child->display) {
58 $hasactions = true;
59 break;
64 if ($hasactions) {
65 echo $OUTPUT->render_from_template('core/report_link_page', ['node' => $coursereusenode]);
66 } else {
67 throw new \moodle_exception(
68 'accessdenied',
69 'admin',
70 new moodle_url('/course/view.php', ['id' => $courseid])
73 echo $OUTPUT->footer();