Code

Moved to E_STRICT
[gosa.git] / include / php_setup.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2003  Cajus Pollmeier
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
21 function gosaRaiseError($errno, $errstr, $errfile, $errline)
22 {
23   global $error_collector,$config, $error_collector_mailto;
25   if(@class_exists("log")){
26     new log("debug","all",$errfile,array(),"Type:".$errno.", Message:".$errstr.", File:".$errfile.", Line: ".$errline);
27   }
29   if(function_exists("gosa_log")){
30     gosa_log($errno." ".$errstr." ".$errfile." ".$errline);
31   }
33   /* Return if error reporting is set to zero */
34   if (error_reporting() == 0){
35     return;
36   }
38   /* Workaround for buggy imap_open error outputs */
39   if (preg_match('/imap_open/', $errstr)){
40     return;
41   }
43   /* FIXME: Workaround for PHP5 error message flooding. The new OOM
44      code want's us to use public/protected/private instead of flat
45      var declarations. For now I can't workaround this - let's ignore
46      the messages till the next major release which may drop support
47      for PHP4. */
48   if (preg_match('/var: Deprecated./', $errstr)){
49     return;
50   }
52   /* FIXME: Same as above. Compatibility does error flooding.*/
53   if (preg_match('/zend.ze1_compatibility_mode/', $errstr)){
54     return;
55   }
57   /* Hide ldap size limit messages */
58   if (preg_match('/ldap_error/', $errstr)){
59     if (preg_match('/sizelimit/', $errstr)){
60       return;
61     }
62   }
64   if((isset($config->data))){ 
65     if((isset($config->data['MAIN']['DISPLAYERRORS']))&&(!preg_match("/^true$/i",$config->data['MAIN']['DISPLAYERRORS']))){
67       /* Write to syslog */
68       new log("view","error","",array(),"PHP error: $errstr ($errfile, line $errline)");
69       return;
70     }
71   }
74   /* Create header as needed */
75   if ($error_collector == ""){
77     /* Mailto body header */
78     if(function_exists("prepare4mailbody")){
79       $error_collector_mailto .=prepare4mailbody(
80                                 "Oups. Seems like you've catched some kind of bug inside GOsa/PHP. You may want to help ".
81                                 "us to improve the software stability. If so, please provide some more information below.".
82                                 "\n\n".
83                                 "*** GOsa bug report ***".
84                                 "\nGOsa Version: ".get_gosa_version().
85                                 "\nDate: ".date("d.m.Y").
86                                 "\nTime: ".date("H:i:s").
87                                 "\n\n".
88                                 "Please describe what you did to produce this error as detailed as possible. Can you ".
89                                 "reproduce this bug using the demo on http://www.gosa-project.org ?".
90                                 "\n\n".
91                                 "*** PHP error information ***\n\n");
92       }
93     
94     if (isset($_SESSION['js']) && $_SESSION['js']==FALSE){
95       $error_collector= "<div>";
96     } else {
97       $error_collector= "
98         <table summary=\"\" width=\"100%\" style='background-color:#E0E0E0;border-bottom:1px solid black;z-index:150;'>
99           <tr>
100             <td>
101               <img alt=\"\" align=\"middle\" src='".get_template_path('images/warning.png')."'>&nbsp;
102               <font style='font-size:14px;font-weight:bold'>".
103                 _("Generating this page caused the PHP interpreter to raise some errors!")."
104               </font>
105             </td>
106             <td align=right>
107               <a href=\"mailto:gosa-bugs@oss.gonicus.de?subject=GOsa%20bugreport&amp;body=%BUGBODY%\">
108                 <img border='0' src='images/mailto.png' title='"._("Send bug report to the GOsa Team")."' class='center' alt=''>&nbsp;"._("Send bugreport")."
109               </a>
110             </td>
111             <td align=right>
112               <button onClick='toggle(\"errorbox\")'>".
113                 _("Toggle information")."
114               </button>
115             </td>
116           </tr>
117         </table>
118         <div id='errorbox' style='position:absolute; z-index:150; visibility: hidden'>";
119     }
120   }
121  
122   /* Create error header */
123   $error_collector.= "<table summary=\"\" width=\"100%\" cellspacing=0 style='background-color:#402005;color:white;border:2px solid red'><tr><td colspan=3><h1 style='color:white'>"._("PHP error")." \"$errstr\"</h1></td></tr>";
125   $error_collector_mailto .= prepare4mailbody("=== Error === \n");
126   $error_collector_mailto .= prepare4mailbody("PHP error: $errstr ($errfile, line $errline)\n");
127   $error_collector_mailto .= prepare4mailbody("=== /Error === \n\n");
128   
129   /* Extract traceback data - if available */
130   if (function_exists('debug_backtrace')){
131     $trace= debug_backtrace();
133     $error_collector_mailto .= prepare4mailbody("=== Trace ===");
135     /* Generate trace history */
136     for ($index= 0; $index<count($trace); $index++){
139       $ct= $trace[$index];
140       $loc= "";
141       if (isset($ct['class'])){
142         $loc.= _("class")." ".$ct['class'];
143         if (isset($ct['function'])){
144           $loc.= " / ";
145         }
146       }
147       if (isset($ct['function'])){
148         $loc.= _("function")." ".$ct['function'];
149       }
150       if (isset($ct['type'])){
151         switch ($ct['type']){
152           case "::":
153             $type= _("static");
154           break;
156           case "->":
157             $type= _("method");
158           break;
159         }
160       } else {
161         $type= "-";
162       }
163       $args= "";
164       if (isset($ct['args'])){
165         foreach ($ct['args'] as $arg){
166        
167           /* Avoid convertig object to string errors */ 
168           if(is_object($arg)){
169             $arg = "CLASS:&nbsp;".get_class($arg);
170           }
171   
172           $args.= htmlentities("\"$arg\", ");
173         }
174       }
175       $args= preg_replace("/, $/", "", $args);
176       if ($args == ""){
177         $args= "-";
178       }
179       if(isset($ct['file'])) {
180         $file= $ct['file'];
181       }else{
182         $file="";
183       }
184       if(isset($ct['line'])) {
185         $line= $ct['line'];
186       }else{
187         $line="";
188       }
189       $color= ($index&1)?'#404040':'606060';
190       $error_collector.= "<tr style='background-color:$color'><td style='padding-left:20px' width=\"30%\">"._("Trace")."[$index]: $loc</td>";
191       $error_collector.= "<td>"._("File").": $file ("._('Line')." $line)</td><td width=\"10%\">"._("Type").": $type</td></tr>";
192       $error_collector.= "<tr style='background-color:$color'><td colspan=3 style='padding-left:20px;'>"._("Arguments").": $args</td></tr>";
194       /* Add trace part to mailto body */
195       $error_collector_mailto .= prepare4mailbody(
196                                    "\nTrace[".$index."]:".$loc.
197                                    "\nFile : ".$file.
198                                    "\nLine : ".$line.
199                                    "\nType : ".$type.
200                                    "\n  ".$args.
201                                    "\n");
203     }
204   }
206   $error_collector_mailto .= prepare4mailbody("=== /Trace === \n");
208   /* Close error table */
209   $error_collector.= "</table>";
211   /* Flush in case of fatal errors */
212   if (preg_match('/^fatal/i', $errstr)){
213     echo $error_collector."</div>";
214     flush();
215     exit;
216   }
220 function dummy_error_handler()
225 /* Get base dir for reference */
226 $BASE_DIR= dirname(dirname(__FILE__));
227 $ROOT_DIR= $BASE_DIR."/html";
228 error_reporting (E_ALL | E_STRICT);
230 /* Register error handler */
231 $error_collector= "";
232 $error_collector_mailto= "";
233 set_error_handler('gosaRaiseError');
235 $variables_order= "ES";
236 ini_set("register_globals",0);
237 ini_set("track_vars",1);
238 ini_set("display_errors",1);
239 ini_set("report_memleaks",1);
240 ini_set("include_path",".:$BASE_DIR/include");
242 /* Do smarty setup */
243 require("smarty/Smarty.class.php");
244 $smarty = new Smarty;
245 $smarty->template_dir = $BASE_DIR.'/ihtml/';
246 $smarty->caching= false;
247 $smarty->php_handling= SMARTY_PHP_REMOVE;
249 /* Set timezone */
250 if (function_exists("date_default_timezone_set")){
251   date_default_timezone_set("GMT");
254 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
255 ?>