From aefceabe78e9f5b02d5f5014334125b1d945fac7 Mon Sep 17 00:00:00 2001 From: dongsheng Date: Tue, 1 Apr 2008 06:19:10 +0000 Subject: [PATCH] MDL-14085, Make print_error() autonomous, merged from MOODLE_19_STABLE --- lib/weblib.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/lib/weblib.php b/lib/weblib.php index d5f8aa57ae..f29466c52d 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -5668,7 +5668,7 @@ function print_scale_menu_helpbutton($courseid, $scale, $return=false) { */ function print_error ($errorcode, $module='', $link='', $a=NULL) { - global $CFG; + global $CFG, $SESSION, $THEME; if (empty($module) || $module == 'moodle' || $module == 'core') { $module = 'error'; @@ -5677,6 +5677,15 @@ function print_error ($errorcode, $module='', $link='', $a=NULL) { $modulelink = $module; } + if (empty($link) and !defined('ADMIN_EXT_HEADER_PRINTED')) { + if ( !empty($SESSION->fromurl) ) { + $link = $SESSION->fromurl; + unset($SESSION->fromurl); + } else { + $link = $CFG->wwwroot .'/'; + } + } + if (!empty($CFG->errordocroot)) { $errordocroot = $CFG->errordocroot; } else if (!empty($CFG->docroot)) { @@ -5685,11 +5694,46 @@ function print_error ($errorcode, $module='', $link='', $a=NULL) { $errordocroot = 'http://docs.moodle.org'; } - $message = '

'.get_string($errorcode, $module, $a).'

'. + $message = clean_text('

'.get_string($errorcode, $module, $a).'

'. '

'. ''. - get_string('moreinformation').'

'; - error($message, $link); + get_string('moreinformation').'

'); + + if (defined('FULLME') && FULLME == 'cron') { + // Errors in cron should be mtrace'd. + mtrace($message); + die; + } + + if (! defined('HEADER_PRINTED')) { + //header not yet printed + @header('HTTP/1.0 404 Not Found'); + print_header(get_string('error')); + } else { + print_container_end_all(false, $THEME->open_header_containers); + } + + echo '
'; + + print_simple_box($message, '', '', '', '', 'errorbox'); + + debugging('Stack trace:', DEBUG_DEVELOPER); + + // in case we are logging upgrade in admin/index.php stop it + if (function_exists('upgrade_log_finish')) { + upgrade_log_finish(); + } + + if (!empty($link)) { + print_continue($link); + } + + print_footer(); + + for ($i=0;$i<512;$i++) { // Padding to help IE work with 404 + echo ' '; + } + die; } /** -- 2.39.5