Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

   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   * Edit user notification preferences
  19   *
  20   * @package    core_message
  21   * @copyright  2016 Ryan Wyllie <ryan@moodle.com>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once(__DIR__ . '/../config.php');
  26  require_once($CFG->dirroot . '/message/lib.php');
  27  require_once($CFG->dirroot . '/user/lib.php');
  28  
  29  $userid = optional_param('userid', $USER->id, PARAM_INT);    // User id.
  30  $url = new moodle_url('/message/notificationpreferences.php');
  31  $url->param('userid', $userid);
  32  
  33  $PAGE->set_url($url);
  34  
  35  require_login();
  36  
  37  if (isguestuser()) {
  38      print_error('guestnoeditmessage', 'message');
  39  }
  40  
  41  $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
  42  
  43  $systemcontext   = context_system::instance();
  44  $personalcontext = context_user::instance($user->id);
  45  
  46  $PAGE->set_context($personalcontext);
  47  $PAGE->set_pagelayout('admin');
  48  
  49  // Check access control.
  50  if ($user->id == $USER->id) {
  51      // Editing own message profile.
  52      require_capability('moodle/user:editownmessageprofile', $systemcontext);
  53  } else {
  54      // Teachers, parents, etc.
  55      require_capability('moodle/user:editmessageprofile', $personalcontext);
  56      // No editing of guest user account.
  57      if (isguestuser($user->id)) {
  58          print_error('guestnoeditmessageother', 'message');
  59      }
  60      // No editing of admins by non admins!
  61      if (is_siteadmin($user) and !is_siteadmin($USER)) {
  62          print_error('useradmineditadmin');
  63      }
  64      $PAGE->navbar->includesettingsbase = true;
  65      $PAGE->navigation->extend_for_user($user);
  66  }
  67  
  68  // Display page header.
  69  $strmessaging = get_string('notificationpreferences', 'message');
  70  $PAGE->set_title($strmessaging);
  71  $PAGE->set_heading(fullname($user));
  72  
  73  // Grab the renderer.
  74  $renderer = $PAGE->get_renderer('core', 'message');
  75  $messagingoptions = $renderer->render_user_notification_preferences($user);
  76  
  77  echo $OUTPUT->header();
  78  echo $messagingoptions;
  79  echo $OUTPUT->footer();
  80