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)
<?php
> // This file is part of Moodle - http://moodle.org/ > // require('../config.php'); > // Moodle is free software: you can redistribute it and/or modify > // it under the terms of the GNU General Public License as published by // Form submitted, do not check referer (original page unknown). > // the Free Software Foundation, either version 3 of the License, or if ($form = data_submitted()) { > // (at your option) any later version. // Only deal with real users. > // if (!isloggedin()) { > // Moodle is distributed in the hope that it will be useful, redirect($CFG->wwwroot); > // but WITHOUT ANY WARRANTY; without even the implied warranty of } > // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > // GNU General Public License for more details. // Send the message and redirect. > // $eventdata = new \core\message\message(); > // You should have received a copy of the GNU General Public License $eventdata->courseid = SITEID; > // along with Moodle. If not, see <http://www.gnu.org/licenses/>. $eventdata->component = 'moodle'; > $eventdata->name = 'errors'; > /** $eventdata->userfrom = $USER; > * Moodle 404 Error page $eventdata->userto = core_user::get_support_user(); > * $eventdata->subject = 'Error: '. $form->referer .' -> '. $form->requested; > * This is for 404 error pages served by the webserver and then passed $eventdata->fullmessage = $form->text; > * to Moodle to be rendered using the site theme. $eventdata->fullmessageformat = FORMAT_PLAIN; > * $eventdata->fullmessagehtml = ''; > * ErrorDocument 404 /error/index.php $eventdata->smallmessage = ''; > * message_send($eventdata); > * @package core > * @copyright 2020 Brendan Heywood <brendan@catalyst-au.net> redirect($CFG->wwwroot .'/course/', 'Message sent, thanks', 3); > * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later exit; > */ } > > require('../config.php'); // phpcs:ignore $site = get_site(); > $redirecturl = empty($_SERVER['REDIRECT_URL']) ? '' : $_SERVER['REDIRECT_URL']; > $context = context_system::instance(); $httpreferer = get_local_referer(false); > $title = get_string('pagenotexisttitle', 'error'); $requesturi = empty($_SERVER['REQUEST_URI']) ? '' : $_SERVER['REQUEST_URI']; > $PAGE->set_url('/error/index.php'); > $PAGE->set_context($context); header("HTTP/1.0 404 Not Found"); > $PAGE->set_title($title); header("Status: 404 Not Found"); > $PAGE->set_heading($title); > $PAGE->navbar->add($title); $PAGE->set_url('/error/'); > $PAGE->set_context(context_system::instance()); > // This allows the webserver to dictate wether the http status should remain $PAGE->set_title($site->fullname .':Error'); > // what it would have been, or force it to be a 404. Under other conditions $PAGE->set_heading($site->fullname .': Error 404'); > // it could most often be a 403, 405 or a 50x error. $PAGE->navbar->add('Error 404 - File not Found'); > $code = optional_param('code', 0, PARAM_INT); echo $OUTPUT->header(); > if ($code == 404) { echo $OUTPUT->box(get_string('pagenotexist', 'error'). '<br />'.s($requesturi), 'generalbox boxaligncenter'); > header("HTTP/1.0 404 Not Found"); > } if (isloggedin()) { > ?> > $canmessage = has_capability('moodle/site:senderrormessage', $context); <p><?php echo get_string('pleasereport', 'error'); ?> > <p><form action="<?php echo $CFG->wwwroot ?>/error/index.php" method="post"> > $supportuser = core_user::get_support_user(); <textarea rows="3" cols="50" name="text" id="text" spellcheck="true"></textarea><br /> > <input type="hidden" name="referer" value="<?php p($httpreferer) ?>"> > // We can only message support if both the user has the capability <input type="hidden" name="requested" value="<?php p($requesturi) ?>"> > // and the support user is a real user. <input type="submit" value="<?php echo get_string('sendmessage', 'error'); ?>"> > if ($canmessage) { </form> > $canmessage = core_user::is_real_user($supportuser->id); <?php > }
< require('../config.php');
> $mform = new \core\form\error_feedback($CFG->wwwroot . '/error/index.php');
< // Form submitted, do not check referer (original page unknown). < if ($form = data_submitted()) { < // Only deal with real users. < if (!isloggedin()) {
> if ($data = $mform->get_data()) { > > if (!$canmessage) {
< $eventdata = new \core\message\message(); < $eventdata->courseid = SITEID; < $eventdata->component = 'moodle'; < $eventdata->name = 'errors'; < $eventdata->userfrom = $USER; < $eventdata->userto = core_user::get_support_user(); < $eventdata->subject = 'Error: '. $form->referer .' -> '. $form->requested; < $eventdata->fullmessage = $form->text; < $eventdata->fullmessageformat = FORMAT_PLAIN; < $eventdata->fullmessagehtml = ''; < $eventdata->smallmessage = ''; < message_send($eventdata);
> $message = new \core\message\message(); > $message->courseid = SITEID; > $message->component = 'moodle'; > $message->name = 'errors'; > $message->userfrom = $USER; > $message->userto = core_user::get_support_user(); > $message->subject = 'Error: '. $data->referer .' -> '. $data->requested; > $message->fullmessage = $data->text; > $message->fullmessageformat = FORMAT_PLAIN; > $message->fullmessagehtml = ''; > $message->smallmessage = ''; > $message->contexturl = $data->requested; > message_send($message);
< redirect($CFG->wwwroot .'/course/', 'Message sent, thanks', 3);
> redirect($CFG->wwwroot, get_string('sendmessagesent', 'error', $data->requested), 5);
< $site = get_site(); < $redirecturl = empty($_SERVER['REDIRECT_URL']) ? '' : $_SERVER['REDIRECT_URL']; < $httpreferer = get_local_referer(false); < $requesturi = empty($_SERVER['REQUEST_URI']) ? '' : $_SERVER['REQUEST_URI']; < < header("HTTP/1.0 404 Not Found"); < header("Status: 404 Not Found"); < < $PAGE->set_url('/error/'); < $PAGE->set_context(context_system::instance()); < $PAGE->set_title($site->fullname .':Error'); < $PAGE->set_heading($site->fullname .': Error 404'); < $PAGE->navbar->add('Error 404 - File not Found');
< echo $OUTPUT->box(get_string('pagenotexist', 'error'). '<br />'.s($requesturi), 'generalbox boxaligncenter');
> echo $OUTPUT->notification(get_string('pagenotexist', 'error', s($ME)), 'error'); > echo $OUTPUT->supportemail(['class' => 'text-center d-block mb-3 font-weight-bold']);
< if (isloggedin()) { < ?> < <p><?php echo get_string('pleasereport', 'error'); ?> < <p><form action="<?php echo $CFG->wwwroot ?>/error/index.php" method="post"> < <textarea rows="3" cols="50" name="text" id="text" spellcheck="true"></textarea><br /> < <input type="hidden" name="referer" value="<?php p($httpreferer) ?>"> < <input type="hidden" name="requested" value="<?php p($requesturi) ?>"> < <input type="submit" value="<?php echo get_string('sendmessage', 'error'); ?>"> < </form> < <?php
> if ($canmessage) { > echo \html_writer::tag('h4', get_string('sendmessage', 'error')); > $mform->display();
>
< ?>