]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14085, Make print_error() autonomous, merged from MOODLE_19_STABLE
authordongsheng <dongsheng>
Tue, 1 Apr 2008 06:19:10 +0000 (06:19 +0000)
committerdongsheng <dongsheng>
Tue, 1 Apr 2008 06:19:10 +0000 (06:19 +0000)
lib/weblib.php

index d5f8aa57ae68e909a770ed3b3033dc9627c2622b..f29466c52d96e85022737817ccf89b82744c3aaa 100644 (file)
@@ -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 = '<p class="errormessage">'.get_string($errorcode, $module, $a).'</p>'.
+    $message = clean_text('<p class="errormessage">'.get_string($errorcode, $module, $a).'</p>'.
                '<p class="errorcode">'.
                '<a href="'.$errordocroot.'/en/error/'.$modulelink.'/'.$errorcode.'">'.
-                 get_string('moreinformation').'</a></p>';
-    error($message, $link);
+                 get_string('moreinformation').'</a></p>');
+
+    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 '<br />';
+
+    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;
 }
 
 /**