Code

Some backport from trunk
[gosa.git] / gosa-core / include / php_setup.inc
index f57c9b1820b58cb82a0c3b6cb7aa130fbd42a175..8dd1005e1c04af0183335feb96589254c94b2f1f 100644 (file)
@@ -29,7 +29,10 @@ function gosaRaiseError($errno, $errstr, $errfile, $errline)
   // To avoid recursion - restore original error handler.
   restore_error_handler();
 
-  /* Return if error reporting is set to zero */
+  /* Return if error reporting is set to zero 
+   * Also exclude statements prefixed with @ - Comment out the block below to see suppressed errors. 
+   * e.g. @call_function_but_hide_errors()
+   */
   if (error_reporting() == 0){
     set_error_handler('gosaRaiseError', E_WARNING |  E_NOTICE | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_STRICT) ;
     return;
@@ -50,7 +53,7 @@ function gosaRaiseError($errno, $errstr, $errfile, $errline)
   }
 
   /* Error messages are hidden in GOsa, so we only send them to the logging class and abort here */
-  if(isset($config->data) && $config->get_cfg_value("displayerrors") != "true"){
+  if(isset($config->data) && $config->get_cfg_value("core","displayErrors") != "true"){
 
     /* Write to syslog */
     if(class_exists("log") && !preg_match("/No such object/",$errstr)){
@@ -66,6 +69,12 @@ function gosaRaiseError($errno, $errstr, $errfile, $errline)
     new log("debug","all",$errfile,array(),"Type:".$errno.", Message:".$errstr.", File:".$errfile.", Line: ".$errline);
   }
 
+  // Log errors in usage DB
+  if(class_exists('stats') && !preg_match("/No such object/",$errstr)){
+      stats::log('error', $class = 'ERROR', $category = array(),  $action = __FUNCTION__, 
+              $amount = 1, $duration = 0, $errno);
+  }
+
   /* Create header as needed */
   if ($error_collector == ""){
 
@@ -87,28 +96,29 @@ function gosaRaiseError($errno, $errstr, $errfile, $errline)
                                 "\n\n".
                                 "*** PHP error information ***\n\n");
       }
-    
-    if (session::is_set('js') && session::get('js')==FALSE){
+   
+     
+    if (class_exists('session') && session::is_set('js') && session::get('js')==FALSE){
       $error_collector= "<div>";
     } else {
-      $error_collector= "
-        <table summary=\"\" width=\"100%\" style='background-color:#E0E0E0;border-bottom:1px solid black;z-index:150;'>
+
+        $warning_image = (is_callable('image')) ? 
+            image('images/toolbar-warning.png') : "<image src='images/toolbar-warning.png' border=0>";
+        $mailto_image = (is_callable('image')) ? 
+            image('images/mailto.png') : "<image src='images/mailto.png' border=0>";
+
+        $error_collector= "
+        <table summary=\"\" class='error-collector'>
           <tr>
-            <td>
-              <img alt=\"\" align=\"middle\" src='".get_template_path('images/warning.png')."'>&nbsp;
-              <font style='font-size:14px;font-weight:bold'>".
-                _("Generating this page caused the PHP interpreter to raise some errors!")."
-              </font>
-            </td>
-            <td align=right>
-              <a href=\"mailto:gosa-bugs@oss.gonicus.de?subject=GOsa%20bugreport&amp;body=%BUGBODY%\">
-                <img border='0' src='images/mailto.png' title='"._("Send bug report to the GOsa Team")."' class='center' alt=''>&nbsp;"._("Send bugreport")."
-              </a>
-            </td>
-            <td align=right>
-              <button onClick=\"$('errorbox').toggle();\">".
-                _("Toggle information")."
-              </button>
+           <td style='width:32px'>{$warning_image}</td>
+           <td><span>"._("Generating this page caused the PHP interpreter to raise some errors!")."</span></td>
+           <td align='right'>
+            <a href=\"mailto:gosa-bugs@oss.gonicus.de?subject=GOsa%20bugreport&amp;body=%BUGBODY%\">
+                {$mailto_image}&nbsp;"._("Send bug report")."
+            </a>
+           </td>
+           <td align='right'>
+            <button onClick=\"$('errorbox').toggle();\">"._("Toggle details")."</button>
             </td>
           </tr>
         </table>
@@ -184,7 +194,7 @@ function gosaRaiseError($errno, $errstr, $errfile, $errline)
         $line="";
       }
       $color= ($index&1)?'#404040':'606060';
-      $error_collector.= "<tr style='background-color:$color'><td style='padding-left:20px' width=\"30%\">"._("Trace")."[$index]: $loc</td>";
+      $error_collector.= "<tr style='background-color:$color'><td style='padding-left:20px' width=\"30%\">"._("Traceback")."[$index]: $loc</td>";
       $error_collector.= "<td>"._("File").": $file ("._('Line')." $line)</td><td width=\"10%\">"._("Type").": $type</td></tr>";
       $error_collector.= "<tr style='background-color:$color'><td colspan=3 style='padding-left:20px;'>"._("Arguments").": $args</td></tr>";
 
@@ -289,7 +299,14 @@ require("smarty/Smarty.class.php");
 $smarty = new Smarty;
 $smarty->template_dir = $BASE_DIR.'/ihtml/';
 $smarty->caching= false;
-$smarty->php_handling= SMARTY_PHP_REMOVE;
+
+// To be able to switch between smarty version 2/3                                                                      
+if(defined('SMARTY_PHP_REMOVE')){                                                                                       
+    $smarty->php_handling= SMARTY_PHP_REMOVE;                                                                           
+}else{                                                                                                                  
+    $smarty->php_handling= Smarty::PHP_REMOVE;                                                                          
+}                                                                                                                       
+
 
 /* Global FPDF define */
 define('FPDF_FONTPATH', '/usr/share/php/fpdf/font/');