Code

Updated language detection code
[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,$error_collector_mailto,$config;
25   /* Return if error reporting is set to zero */
26   if (error_reporting() == 0){
27     return;
28   }
30   /* Workaround for buggy imap_open error outputs */
31   if (preg_match('/imap_open/', $errstr)){
32     return;
33   }
35   /* FIXME: Workaround for PHP5 error message flooding. The new OOM
36      code want's us to use public/protected/private instead of flat
37      var declarations. For now I can't workaround this - let's ignore
38      the messages till the next major release which may drop support
39      for PHP4. */
40   if (preg_match('/var: Deprecated./', $errstr)){
41     return;
42   }
44   /* FIXME: Same as above. Compatibility does error flooding.*/
45   if (preg_match('/zend.ze1_compatibility_mode/', $errstr)){
46     return;
47   }
49   /* Hide ldap size limit messages */
50   if (preg_match('/ldap_error/', $errstr)){
51     if (preg_match('/sizelimit/', $errstr)){
52       return;
53     }
54   }
56   if((isset($config->data))){ 
57     if((isset($config->data['MAIN']['DISPLAYERRORS']))&&(!preg_match("/^true$/i",$config->data['MAIN']['DISPLAYERRORS']))){
59       /* Write to syslog */
60       gosa_log ("PHP error: $errstr ($errfile, line $errline)");
61       return;
62     }
63   }
66   /* Create header as needed */
67   if ($error_collector == ""){
69     /* Mailto body header */ 
70     $error_collector_mailto .=prepare4mailbody(
71                                 "Oups. Seems like you've catched some kind of bug inside GOsa/PHP. You may want to help ".
72                                 "us to improve the software stability. If so, please provide some more information below.".
73                                 "\n\n".
74                                 "*** GOsa bug report ***".
75                                 "\nGOsa Version: ".get_gosa_version().
76                                 "\nDate: ".date("d.m.Y").
77                                 "\nTime: ".date("H:i:s").
78                                 "\nUser-Agent: ".$_SERVER['HTTP_USER_AGENT']." ".
79                                 "(Javascript is ".( (isset($_SESSION['js']) && $_SESSION['js']==FALSE) ? "inactive" : "active" ).")".
80                                 "\n\n".
81                                 "Please describe what you did to produce this error as detailed as possible. Can you ".
82                                 "reproduce this bug using the demo on http://www.gosa-project.org ?".
83                                 "\n\n".
84                                 "*** PHP runtime information ***".
85                                 "\nPHP Version: ".phpversion().
86                                 "\nRunning on: ".php_uname().
87                                 "\nLoaded Extensions: ".print_array(get_loaded_extensions()).
88                                 "\nLDAP Module Version: ".get_module_setting('ldap','RCS Version').
89                                 "\n\n".
90                                 "*** PHP error information ***\n\n");
92     if (isset($_SESSION['js']) && $_SESSION['js']==FALSE){
93       $error_collector= "<div>";
94     } else {
95       $error_collector= "
96         <table summary=\"\" width=\"100%\" style='background-color:#E0E0E0;border-bottom:1px solid black;z-index:150;'>
97           <tr>
98             <td>
99               <img alt=\"\" align=\"middle\" src='".get_template_path('images/warning.png')."'>&nbsp;
100               <font style='font-size:14px;font-weight:bold'>".
101                 _("Generating this page caused the PHP interpreter to raise some errors!")."
102               </font>
103             </td>
104             <td align=right>
105               <a href=\"mailto:gosa-bugs@oss.gonicus.de?subject=GOsa%20bugreport&amp;body=%BUGBODY%\">
106                 <img border='0' src='images/mailto.png' title='"._("Send bug report to the GOsa Team")."' class='center' alt=''>&nbsp;"._("Send bugreport")."
107               </a>
108             </td>
109             <td align=right>
110               <button onClick='toggle(\"errorbox\")'>".
111                 _("Toggle information")."
112               </button>
113             </td>
114           </tr>
115         </table>
116         <div id='errorbox' style='position:absolute; z-index:150; visibility: hidden'>";
117     }
118   }
119  
120   /* Create error header */
121   $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>";
122   
123   $error_collector_mailto .= prepare4mailbody("=== Error === \n");
124   $error_collector_mailto .= prepare4mailbody("PHP error: $errstr ($errfile, line $errline)\n");
125   $error_collector_mailto .= prepare4mailbody("=== /Error === \n\n");
127   /* Extract traceback data - if available */
128   if (function_exists('debug_backtrace')){
129     $trace= debug_backtrace();
131     $error_collector_mailto .= prepare4mailbody("=== Trace ===");
133     /* Generate trace history */
134     for ($index= 0; $index<count($trace); $index++){
137       $ct= $trace[$index];
138       $loc= "";
139       if (isset($ct['class'])){
140         $loc.= _("class")." ".$ct['class'];
141         if (isset($ct['function'])){
142           $loc.= " / ";
143         }
144       }
145       if (isset($ct['function'])){
146         $loc.= _("function")." ".$ct['function'];
147       }
148       if (isset($ct['type'])){
149         switch ($ct['type']){
150           case "::":
151             $type= _("static");
152           break;
154           case "->":
155             $type= _("method");
156           break;
157         }
158       } else {
159         $type= "-";
160       }
161       $args= "";
162       if (isset($ct['args'])){
163         foreach ($ct['args'] as $arg){
165           /* Avoid convertig object to string errors */ 
166           if(is_object($arg)){
167             $arg = "CLASS:&nbsp;".get_class($arg);
168           }
170           $args.= htmlentities("\"$arg\", ");
171         }
172       }
173       $args= preg_replace("/, $/", "", $args);
174       if ($args == ""){
175         $args= "-";
176       }
177       if(isset($ct['file'])) {
178         $file= $ct['file'];
179       }else{
180         $file="";
181       }
182       if(isset($ct['line'])) {
183         $line= $ct['line'];
184       }else{
185         $line="";
186       }
187       $color= ($index&1)?'#404040':'606060';
188       $error_collector.= "<tr style='background-color:$color'><td style='padding-left:20px' width=\"30%\">"._("Trace")."[$index]: $loc</td>";
189       $error_collector.= "<td>"._("File").": $file ("._('Line')." $line)</td><td width=\"10%\">"._("Type").": $type</td></tr>";
190       $error_collector.= "<tr style='background-color:$color'><td colspan=3 style='padding-left:20px;'>"._("Arguments").": $args</td></tr>";
192       /* Add trace part to mailto body */
193       $error_collector_mailto .= prepare4mailbody(
194                                    "\nTrace[".$index."]:".$loc.
195                                    "\nFile : ".$file.
196                                    "\nLine : ".$line.
197                                    "\nType : ".$type.
198                                    "\n  ".$args.
199                                    "\n");
200       }
201   }
202   $error_collector_mailto .= prepare4mailbody("=== /Trace === \n");
204   /* Close error table */
205   $error_collector.= "</table>";
207   /* Flush in case of fatal errors */
208   if (preg_match('/^fatal/i', $errstr)){
209     echo $error_collector."</div>";
210     flush();
211     exit;
212   }
216 function dummy_error_handler()
221 /* Get base dir for reference */
222 $BASE_DIR= dirname(dirname(__FILE__));
223 $ROOT_DIR= $BASE_DIR."/html";
224 error_reporting (E_ALL);
226 /* Register error handler */
227 $error_collector= "";
228 $error_collector_mailto= "";
229 set_error_handler('gosaRaiseError');
231 $variables_order= "ES";
232 ini_set("register_globals",0);
233 ini_set("track_vars",1);
234 ini_set("display_errors",1);
235 ini_set("report_memleaks",1);
236 ini_set("include_path",".:$BASE_DIR/include");
238 /* Do smarty setup */
239 require("smarty/Smarty.class.php");
240 $smarty = new Smarty;
241 $smarty->template_dir = $BASE_DIR.'/ihtml/';
242 $smarty->caching= false;
243 $smarty->php_handling= SMARTY_PHP_REMOVE;
245 /* Set timezone */
246 if (function_exists("date_default_timezone_set")){
247   date_default_timezone_set("GMT");
250 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
251 ?>