Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.
   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.
  13  //
  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/>.
  16  
  17  /**
  18   * Customise the course role names.
  19   *
  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
  23   */
  24  
  25  require('../config.php');
  26  require_once("$CFG->dirroot/course/lib.php");
  27  
  28  
  29  $id = required_param('id', PARAM_INT);
  30  $action  = optional_param('action', '', PARAM_ALPHANUMEXT);
  31  $filter = optional_param('ifilter', 0, PARAM_INT);
  32  
  33  $course = $DB->get_record('course', ['id' => $id], '*', MUST_EXIST);
  34  $context = core\context\course::instance($course->id, MUST_EXIST);
  35  
  36  require_login($course);
  37  require_capability('moodle/course:renameroles', $context);
  38  
  39  if ($course->id == SITEID) {
  40      redirect("$CFG->wwwroot/");
  41  }
  42  
  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);
  48  
  49  echo $OUTPUT->header();
  50  echo $OUTPUT->render_participants_tertiary_nav($course);
  51  
  52  echo $OUTPUT->paragraph(get_string('rolerenaming_help'));
  53  
  54  $customdata = [
  55      'id' => $course->id,
  56      'roles' => role_get_names($context, ROLENAME_ORIGINAL),
  57  ];
  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);
  62  }
  63  
  64  $mform->display();
  65  
  66  echo $OUTPUT->footer();