Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
/error/ -> index.php (source)

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 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   * 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  require('../config.php'); // phpcs:ignore
  31  
  32  $context = context_system::instance();
  33  $title = get_string('pagenotexisttitle', 'error');
  34  $PAGE->set_url('/error/index.php');
  35  $PAGE->set_context($context);
  36  $PAGE->set_title($title);
  37  $PAGE->set_heading($title);
  38  $PAGE->navbar->add($title);
  39  
  40  // This allows the webserver to dictate wether the http status should remain
  41  // what it would have been, or force it to be a 404. Under other conditions
  42  // it could most often be a 403, 405 or a 50x error.
  43  $code = optional_param('code', 0, PARAM_INT);
  44  if ($code == 404) {
  45      header("HTTP/1.0 404 Not Found");
  46  }
  47  
  48  $canmessage = has_capability('moodle/site:senderrormessage', $context);
  49  
  50  $supportuser = core_user::get_support_user();
  51  
  52  // We can only message support if both the user has the capability
  53  // and the support user is a real user.
  54  if ($canmessage) {
  55      $canmessage = core_user::is_real_user($supportuser->id);
  56  }
  57  
  58  $mform = new \core\form\error_feedback($CFG->wwwroot . '/error/index.php');
  59  
  60  if ($data = $mform->get_data()) {
  61  
  62      if (!$canmessage) {
  63          redirect($CFG->wwwroot);
  64      }
  65  
  66      // Send the message and redirect.
  67      $message = new \core\message\message();
  68      $message->courseid         = SITEID;
  69      $message->component        = 'moodle';
  70      $message->name             = 'errors';
  71      $message->userfrom          = $USER;
  72      $message->userto            = core_user::get_support_user();
  73      $message->subject           = 'Error: '. $data->referer .' -> '. $data->requested;
  74      $message->fullmessage       = $data->text;
  75      $message->fullmessageformat = FORMAT_PLAIN;
  76      $message->fullmessagehtml   = '';
  77      $message->smallmessage      = '';
  78      $message->contexturl = $data->requested;
  79      message_send($message);
  80  
  81      redirect($CFG->wwwroot, get_string('sendmessagesent', 'error', $data->requested), 5);
  82      exit;
  83  }
  84  
  85  echo $OUTPUT->header();
  86  echo $OUTPUT->notification(get_string('pagenotexist', 'error', s($ME)), 'error');
  87  echo $OUTPUT->supportemail(['class' => 'text-center d-block mb-3 font-weight-bold']);
  88  
  89  if ($canmessage) {
  90      echo \html_writer::tag('h4', get_string('sendmessage', 'error'));
  91      $mform->display();
  92  } else {
  93      echo $OUTPUT->continue_button($CFG->wwwroot);
  94  }
  95  
  96  echo $OUTPUT->footer();