removing trailing ?> from function scripts
[squirrelmail.git] / class / error.class.php
index cef939bdad5f3b0875d93753ab16387822c8d51d..0f9f13c8ad300bd646159467e129b5558eae20d2 100644 (file)
@@ -43,6 +43,7 @@ class ErrorHandler {
         $this->TemplateName = $sTemplateFile;
         $this->Template =& $oTemplate;
         $this->aErrors = array();
+        $this->header_sent = false;
     }
 
     /**
@@ -53,6 +54,28 @@ class ErrorHandler {
         $this->TemplateFile = $sTemplateFile;
     }
 
+    /**
+     * Sets if the page header is already sent
+     * @since 1.5.1
+     */
+    function HeaderSent() {
+        $this->header_sent = true;
+    }
+
+    /**
+     * Store errors generated in a previous script but couldn't be displayed
+     * due to a header redirect. This requires storing of aDelayedErrors in the session
+     * @param array $aDelayedErrors array with errors stored in the $this->aErrors format.
+     * @since 1.5.1
+     */
+    function AssignDelayedErrors(&$aDelayedErrors) {
+        $aErrors = array_merge($this->aErrors,$aDelayedErrors);
+        $this->aErrors = $aErrors;
+        $this->Template->assign('aErrors',$this->aErrors);
+        $aDelayedErrors = false;
+    }
+
+
     /**
      * Custom Error handler (set with set_error_handler() )
      * @private
@@ -172,6 +195,10 @@ class ErrorHandler {
 
         // Show the error immediate in case of fatal errors
         if ($iType == SQM_ERROR) {
+            if (!$this->header_sent) {
+                // TODO replace this with template that can be assigned
+                displayHtmlHeader(_("Error"),'',false);
+            }
             $this->DisplayErrors();
             exit(_("Terminating SquirrelMail due to a fatal error"));
         }
@@ -205,7 +232,7 @@ function SquirrelMailErrorhandler($iErrNo, $sErrStr, $sErrFile, $iErrLine, $aCon
 
 /**
  * Triggers an imap error. Utility function for sqm_trigger_error()
- * @param  integer $iErrNo error number defined in errors.php
+ * @param  string $sErrNo error string defined in errors.php
  * @param  string $sRequest imap request string
  * @param  string $sResponse tagged imap response
  * @param  string $sMessage tagged imap response message
@@ -214,39 +241,43 @@ function SquirrelMailErrorhandler($iErrNo, $sErrStr, $sErrFile, $iErrLine, $aCon
  * @author  Marc Groot Koerkamp
  * @since 1.5.1
  */
-function sqm_trigger_imap_error($iErrNo,$sRequest,$sResponse, $sMessage, $aExtra=array()) {
+function sqm_trigger_imap_error($sErrNo,$sRequest,$sResponse, $sMessage, $aExtra=array()) {
     $aError = array(
                     'REQUEST' => $sRequest,
                     'RESPONSE' => $sResponse,
                     'MESSAGE' => $sMessage);
     $aError = array_merge($aExtra,$aError);
-    sqm_trigger_error($iErrNo,$aError);
+    sqm_trigger_error($sErrNo,$aError);
 }
 
 /**
  * Trigger an error.
- * @param  integer $iErrNo error number defined in errors.php
+ * @param  string $sErrNo error string defined in errors.php
  * @param  array   $aExtra optional associative array with extra error info
  * @return void
  * @author  Marc Groot Koerkamp
  * @since 1.5.1
  */
-function sqm_trigger_error($iErrNo,$aExtra=array()) {
-    // Include the error definition file.
-    include_once(SM_PATH.'include/errors.php');
+function sqm_trigger_error($sErrNo,$aExtra=array()) {
+    static $aErrors;
+    if (!isset($aErrors)) {
+        // Include the error definition file.
+        include_once(SM_PATH.'include/errors.php');
+    }
+
     $iPhpErr = E_USER_NOTICE;
-    if (is_array($aErrors) && isset($aErrors[$iErrNo]['level'])) {
+    if (is_array($aErrors) && isset($aErrors[$sErrNo]['level'])) {
         if (is_array($aExtra) && count($aExtra)) {
-            $aErrors[$iErrNo]['extra'] = $aExtra;
+            $aErrors[$sErrNo]['extra'] = $aExtra;
         }
         // because trigger_error can only handle a string argument for the error description
         // we serialize the result.
-        $sErrString = serialize($aErrors[$iErrNo]);
-        $iPhpErr = $aErrors[$iErrNo]['level'];
+        $sErrString = serialize($aErrors[$sErrNo]);
+        $iPhpErr = $aErrors[$sErrNo]['level'];
     } else {
-        $sErrString = "Error number <$iErrNo> does not exist, fix the code or update the errors.php file";
+        sm_print_r($aErrors);
+        $sErrString = "Error <$sErrNo> does not exist, fix the code or update the errors.php file";
         $iPhpErr = E_USER_ERROR;
     }
     trigger_error($sErrString, $iPhpErr);
 }
-?>
\ No newline at end of file