Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
/error/ -> index.php (source)

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]

   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   * Moodle 404 Error page
  19   *
  20   * This is for 404 error pages served by the webserver and then passed
  21   * to Moodle to be rendered using the site theme.
  22   *
  23   * ErrorDocument 404 /error/index.php
  24   *
  25   * @package    core
  26   * @copyright  2020 Brendan Heywood <brendan@catalyst-au.net>
  27   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  28   */
  29  
  30  // @codingStandardsIgnoreStart
  31  require('../config.php');
  32  // @codingStandardsIgnoreEnd
  33  
  34  $context = context_system::instance();
  35  $title = get_string('pagenotexisttitle', 'error');
  36  $PAGE->set_url('/error/index.php');
  37  $PAGE->set_context($context);
  38  $PAGE->set_title($title);
  39  $PAGE->set_heading($title);
  40  $PAGE->navbar->add($title);
  41  
  42  $canmessage = has_capability('moodle/site:senderrormessage', $context);
  43  
  44  $supportuser = core_user::get_support_user();
  45  
  46  // We can only message support if both the user has the capability
  47  // and the support user is a real user.
  48  if ($canmessage) {
  49      $canmessage = core_user::is_real_user($supportuser->id);
  50  }
  51  
  52  $mform = new \core\form\error_feedback($CFG->wwwroot . '/error/index.php');
  53  
  54  if ($data = $mform->get_data()) {
  55  
  56      if (!$canmessage) {
  57          redirect($CFG->wwwroot);
  58      }
  59  
  60      // Send the message and redirect.
  61      $message = new \core\message\message();
  62      $message->courseid         = SITEID;
  63      $message->component        = 'moodle';
  64      $message->name             = 'errors';
  65      $message->userfrom          = $USER;
  66      $message->userto            = core_user::get_support_user();
  67      $message->subject           = 'Error: '. $data->referer .' -> '. $data->requested;
  68      $message->fullmessage       = $data->text;
  69      $message->fullmessageformat = FORMAT_PLAIN;
  70      $message->fullmessagehtml   = '';
  71      $message->smallmessage      = '';
  72      $message->contexturl = $data->requested;
  73      message_send($message);
  74  
  75      redirect($CFG->wwwroot, get_string('sendmessagesent', 'error', $data->requested), 5);
  76      exit;
  77  }
  78  
  79  echo $OUTPUT->header();
  80  echo $OUTPUT->notification(get_string('pagenotexist', 'error', s($ME)), 'error');
  81  
  82  if (!empty($CFG->supportpage)) {
  83      echo \html_writer::tag('h4', get_string('supportpage', 'admin'));
  84      $link = \html_writer::link($CFG->supportpage, $CFG->supportpage);
  85      echo \html_writer::tag('p', $link);
  86  }
  87  if (!empty($CFG->supportemail)) {
  88      echo \html_writer::tag('h4', get_string('supportemail', 'admin'));
  89      $link = \html_writer::link('mailto:' . $CFG->supportemail, $CFG->supportemail);
  90      echo \html_writer::tag('p', $link);
  91  }
  92  
  93  if ($canmessage) {
  94      echo \html_writer::tag('h4', get_string('sendmessage', 'error'));
  95      $mform->display();
  96  } else {
  97      echo $OUTPUT->continue_button($CFG->wwwroot);
  98  }
  99  
 100  echo $OUTPUT->footer();
 101