Merge branch 'MDL-81399' of https://github.com/paulholden/moodle
[moodle.git] / enrol / renameroles.php
blob5c62c75baff97c3a93c1db99dd7301c359ed8643
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 * Customise the course role names.
20 * @package core_enrol
21 * @copyright 2023 Ferran Recio <ferran@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require('../config.php');
26 require_once("$CFG->dirroot/course/lib.php");
29 $id = required_param('id', PARAM_INT);
30 $action = optional_param('action', '', PARAM_ALPHANUMEXT);
31 $filter = optional_param('ifilter', 0, PARAM_INT);
33 $course = $DB->get_record('course', ['id' => $id], '*', MUST_EXIST);
34 $context = core\context\course::instance($course->id, MUST_EXIST);
36 require_login($course);
37 require_capability('moodle/course:renameroles', $context);
39 if ($course->id == SITEID) {
40 redirect("$CFG->wwwroot/");
43 $PAGE->set_pagelayout('admin');
44 $PAGE->set_url('/enrol/renameroles.php', ['id' => $course->id]);
45 $PAGE->set_pagelayout('standard');
46 $PAGE->set_title(get_string('rolerenaming'));
47 $PAGE->set_heading($course->fullname);
49 echo $OUTPUT->header();
50 echo $OUTPUT->render_participants_tertiary_nav($course);
52 echo $OUTPUT->paragraph(get_string('rolerenaming_help'));
54 $customdata = [
55 'id' => $course->id,
56 'roles' => role_get_names($context, ROLENAME_ORIGINAL),
58 $mform = new core_enrol\form\renameroles(null, $customdata);
59 if ($data = $mform->get_data()) {
60 save_local_role_names($course->id, (array)$data);
61 core\notification::add(get_string('rolerenaming_success'), core\notification::SUCCESS);
64 $mform->display();
66 echo $OUTPUT->footer();