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 if(@class_exists("log")){
26 new log("debug","all",$errfile,array(),"Type:".$errno.", Message:".$errstr.", File:".$errfile.", Line: ".$errline);
27 }
29 /* Return if error reporting is set to zero */
30 if (error_reporting() == 0){
31 return;
32 }
34 /* Workaround for buggy imap_open error outputs */
35 if (preg_match('/imap_open/', $errstr)){
36 return;
37 }
39 /* FIXME: Workaround for PHP5 error message flooding. The new OOM
40 code want's us to use public/protected/private instead of flat
41 var declarations. For now I can't workaround this - let's ignore
42 the messages till the next major release which may drop support
43 for PHP4. */
44 if (preg_match('/var: Deprecated./', $errstr)){
45 return;
46 }
48 /* FIXME: Same as above. Compatibility does error flooding.*/
49 if (preg_match('/zend.ze1_compatibility_mode/', $errstr)){
50 return;
51 }
53 /* Hide ldap size limit messages */
54 if (preg_match('/ldap_error/', $errstr)){
55 if (preg_match('/sizelimit/', $errstr)){
56 return;
57 }
58 }
60 if((isset($config->data))){
61 if((isset($config->data['MAIN']['DISPLAYERRORS']))&&(!preg_match("/^true$/i",$config->data['MAIN']['DISPLAYERRORS']))){
63 /* Write to syslog */
64 new log("view","error","",array(),"PHP error: $errstr ($errfile, line $errline)");
65 return;
66 }
67 }
70 /* Create header as needed */
71 if ($error_collector == ""){
72 if (isset($_SESSION['js']) && $_SESSION['js']==FALSE){
73 $error_collector= "<div>";
74 } else {
75 $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')."'> <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'>";
76 }
77 }
79 /* Create error header */
80 $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>";
82 /* Extract traceback data - if available */
83 if (function_exists('debug_backtrace')){
84 $trace= debug_backtrace();
86 /* Generate trace history */
87 for ($index= 0; $index<count($trace); $index++){
88 $ct= $trace[$index];
89 $loc= "";
90 if (isset($ct['class'])){
91 $loc.= _("class")." ".$ct['class'];
92 if (isset($ct['function'])){
93 $loc.= " / ";
94 }
95 }
96 if (isset($ct['function'])){
97 $loc.= _("function")." ".$ct['function'];
98 }
99 if (isset($ct['type'])){
100 switch ($ct['type']){
101 case "::":
102 $type= _("static");
103 break;
105 case "->":
106 $type= _("method");
107 break;
108 }
109 } else {
110 $type= "-";
111 }
112 $args= "";
113 if (isset($ct['args'])){
114 foreach ($ct['args'] as $arg){
116 /* Avoid convertig object to string errors */
117 if(is_object($arg)){
118 $arg = "CLASS: ".get_class($arg);
119 }
121 $args.= htmlentities("\"$arg\", ");
122 }
123 }
124 $args= preg_replace("/, $/", "", $args);
125 if ($args == ""){
126 $args= "-";
127 }
128 if(isset($ct['file'])) {
129 $file= $ct['file'];
130 }else{
131 $file="";
132 }
133 if(isset($ct['line'])) {
134 $line= $ct['line'];
135 }else{
136 $line="";
137 }
138 $color= ($index&1)?'#404040':'606060';
139 $error_collector.= "<tr style='background-color:$color'><td style='padding-left:20px' width=\"30%\">"._("Trace")."[$index]: $loc</td>";
140 $error_collector.= "<td>"._("File").": $file ("._('Line')." $line)</td><td width=\"10%\">"._("Type").": $type</td></tr>";
141 $error_collector.= "<tr style='background-color:$color'><td colspan=3 style='padding-left:20px;'>"._("Arguments").": $args</td></tr>";
142 }
143 }
145 /* Close error table */
146 $error_collector.= "</table>";
148 /* Flush in case of fatal errors */
149 if (preg_match('/^fatal/i', $errstr)){
150 echo $error_collector."</div>";
151 flush();
152 exit;
153 }
154 }
157 function dummy_error_handler()
158 {
159 }
162 /* Get base dir for reference */
163 $BASE_DIR= dirname(dirname(__FILE__));
164 $ROOT_DIR= $BASE_DIR."/html";
165 error_reporting (E_ALL);
167 /* Register error handler */
168 $error_collector= "";
169 set_error_handler('gosaRaiseError');
171 $variables_order= "ES";
172 ini_set("register_globals",0);
173 ini_set("track_vars",1);
174 ini_set("display_errors",1);
175 ini_set("report_memleaks",1);
176 ini_set("include_path",".:$BASE_DIR/include");
178 /* Do smarty setup */
179 require("smarty/Smarty.class.php");
180 $smarty = new Smarty;
181 $smarty->template_dir = $BASE_DIR.'/ihtml/';
182 $smarty->caching= false;
183 $smarty->php_handling= SMARTY_PHP_REMOVE;
185 /* Set timezone */
186 if (function_exists("date_default_timezone_set")){
187 date_default_timezone_set("GMT");
188 }
190 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
191 ?>