Code

Added external resolution hook to environment
[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;
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 == ""){
68     if (isset($_SESSION['js']) && $_SESSION['js']==FALSE){
69       $error_collector= "<div>";
70     } else {
71       $error_collector= "<table summary=\"\" width=\"100%\" style='background-color:#E0E0E0;border-bottom:1px solid black';z-index:150;><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><button onClick='toggle(\"errorbox\")'>"._("Toggle information")."</button></td></tr></table><div id='errorbox' style='position:absolute; z-index:150; visibility: hidden'>";
72     }
73   }
74  
75   /* Create error header */
76   $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>";
77   
78   /* Extract traceback data - if available */
79   if (function_exists('debug_backtrace')){
80     $trace= debug_backtrace();
82     /* Generate trace history */
83     for ($index= 0; $index<count($trace); $index++){
84       $ct= $trace[$index];
85       $loc= "";
86       if (isset($ct['class'])){
87         $loc.= _("class")." ".$ct['class'];
88         if (isset($ct['function'])){
89           $loc.= " / ";
90         }
91       }
92       if (isset($ct['function'])){
93         $loc.= _("function")." ".$ct['function'];
94       }
95       if (isset($ct['type'])){
96         switch ($ct['type']){
97           case "::":
98             $type= _("static");
99           break;
101           case "->":
102             $type= _("method");
103           break;
104         }
105       } else {
106         $type= "-";
107       }
108       $args= "";
109       if (isset($ct['args'])){
110         foreach ($ct['args'] as $arg){
111           $args.= htmlentities("\"$arg\", ");
112         }
113       }
114       $args= preg_replace("/, $/", "", $args);
115       if ($args == ""){
116         $args= "-";
117       }
118       if(isset($ct['file'])) {
119         $file= $ct['file'];
120       }else{
121         $file="";
122       }
123       if(isset($ct['line'])) {
124         $line= $ct['line'];
125       }else{
126         $line="";
127       }
128       $color= ($index&1)?'#404040':'606060';
129       $error_collector.= "<tr style='background-color:$color'><td style='padding-left:20px' width=\"30%\">"._("Trace")."[$index]: $loc</td>";
130       $error_collector.= "<td>"._("File").": $file ("._('Line')." $line)</td><td width=\"10%\">"._("Type").": $type</td></tr>";
131       $error_collector.= "<tr style='background-color:$color'><td colspan=3 style='padding-left:20px;'>"._("Arguments").": $args</td></tr>";
132     }
133   }
135   /* Close error table */
136   $error_collector.= "</table>";
138   /* Flush in case of fatal errors */
139   if (preg_match('/^fatal/i', $errstr)){
140     echo $error_collector."</div>";
141     flush();
142     exit;
143   }
147 function dummy_error_handler()
152 /* Get base dir for reference */
153 $BASE_DIR= dirname(dirname(__FILE__));
154 $ROOT_DIR= $BASE_DIR."/html";
155 error_reporting (E_ALL);
157 /* Register error handler */
158 $error_collector= "";
159 set_error_handler('gosaRaiseError');
161 $variables_order= "ES";
162 ini_set("register_globals",0);
163 ini_set("track_vars",1);
164 ini_set("display_errors",1);
165 ini_set("report_memleaks",1);
166 ini_set("include_path",".:$BASE_DIR/include");
168 /* Do smarty setup */
169 require("smarty/Smarty.class.php");
170 $smarty = new Smarty;
171 $smarty->template_dir = $BASE_DIR.'/ihtml/';
172 $smarty->caching= false;
173 $smarty->php_handling= SMARTY_PHP_REMOVE;
175 /* Set timezone */
176 if (function_exists("date_default_timezone_set")){
177   date_default_timezone_set("GMT");
180 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
181 ?>