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.
/message/ -> edit.php (source)

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 message preferences
  19   *
  20   * @package    core_message
  21   * @copyright  2008 Luis Rodrigues and Martin Dougiamas
  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('id', 0, PARAM_INT);    // User id.
  30  $currentuser = true;
  31  
  32  if (!$userid) {
  33      $userid = $USER->id;
  34  }
  35  
  36  $url = new moodle_url('/message/edit.php');
  37  $url->param('id', $userid);
  38  
  39  $PAGE->set_url($url);
  40  
  41  require_login();
  42  
  43  if (isguestuser()) {
  44      print_error('guestnoeditmessage', 'message');
  45  }
  46  
  47  if (!$user = $DB->get_record('user', array('id' => $userid))) {
  48      print_error('invaliduserid');
  49  }
  50  
  51  $systemcontext   = context_system::instance();
  52  $personalcontext = context_user::instance($user->id);
  53  
  54  $PAGE->set_context($personalcontext);
  55  $PAGE->set_pagelayout('admin');
  56  
  57  // check access control
  58  if ($user->id == $USER->id) {
  59      //editing own message profile
  60      require_capability('moodle/user:editownmessageprofile', $systemcontext);
  61  } else {
  62      $currentuser = false;
  63      // teachers, parents, etc.
  64      require_capability('moodle/user:editmessageprofile', $personalcontext);
  65      // no editing of guest user account
  66      if (isguestuser($user->id)) {
  67          print_error('guestnoeditmessageother', 'message');
  68      }
  69      // no editing of admins by non admins!
  70      if (is_siteadmin($user) and !is_siteadmin($USER)) {
  71          print_error('useradmineditadmin');
  72      }
  73      $PAGE->navbar->includesettingsbase = true;
  74      $PAGE->navigation->extend_for_user($user);
  75  }
  76  
  77  /// Display page header
  78  $strmessaging = get_string('messagepreferences', 'message');
  79  $PAGE->set_title($strmessaging);
  80  $PAGE->set_heading(fullname($user));
  81  
  82  echo $OUTPUT->header();
  83  if ($currentuser) {
  84      // Open the message drawer to show the settings.
  85      echo $OUTPUT->heading(get_string('messagepreferences', 'core_message'));
  86      $PAGE->requires->js_call_amd('core_message/message_drawer_helper', 'showSettings');
  87  } else {
  88      // Viewing another user's preferences so render the old page.
  89      $renderer = $PAGE->get_renderer('core', 'message');
  90      echo $renderer->render_user_message_preferences($user);
  91  }
  92  
  93  echo $OUTPUT->footer();
  94