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) || preg_match("/Declaration of.*should be compatible/",$errstr)){
49 return;
50 }
52 /* Hide ldap size limit messages */
53 if (preg_match('/ldap_error/', $errstr)){
54 if (preg_match('/sizelimit/', $errstr)){
55 return;
56 }
57 }
59 if((isset($config->data))){
60 if((isset($config->data['MAIN']['DISPLAYERRORS']))&&(!preg_match("/^true$/i",$config->data['MAIN']['DISPLAYERRORS']))){
62 /* Write to syslog */
63 new log("view","error","",array(),"PHP error: $errstr ($errfile, line $errline)");
64 return;
65 }
66 }
69 /* Create header as needed */
70 if ($error_collector == ""){
72 /* Mailto body header */
73 if(function_exists("prepare4mailbody")){
74 $error_collector_mailto .=prepare4mailbody(
75 "Oups. Seems like you've catched some kind of bug inside GOsa/PHP. You may want to help ".
76 "us to improve the software stability. If so, please provide some more information below.".
77 "\n\n".
78 "*** GOsa bug report ***".
79 "\nGOsa Version: ".get_gosa_version().
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 error information ***\n\n");
85 }
87 if (isset($_SESSION['js']) && $_SESSION['js']==FALSE){
88 $error_collector= "<div>";
89 } else {
90 $error_collector= "
91 <table summary=\"\" width=\"100%\" style='background-color:#E0E0E0;border-bottom:1px solid black;z-index:150;'>
92 <tr>
93 <td>
94 <img alt=\"\" align=\"middle\" src='".get_template_path('images/warning.png')."'>
95 <font style='font-size:14px;font-weight:bold'>".
96 _("Generating this page caused the PHP interpreter to raise some errors!")."
97 </font>
98 </td>
99 <td align=right>
100 <a href=\"mailto:gosa-bugs@oss.gonicus.de?subject=GOsa%20bugreport&body=%BUGBODY%\">
101 <img border='0' src='images/mailto.png' title='"._("Send bug report to the GOsa Team")."' class='center' alt=''> "._("Send bugreport")."
102 </a>
103 </td>
104 <td align=right>
105 <button onClick='toggle(\"errorbox\")'>".
106 _("Toggle information")."
107 </button>
108 </td>
109 </tr>
110 </table>
111 <div id='errorbox' style='position:absolute; z-index:150; visibility: hidden'>";
112 }
113 }
115 /* Create error header */
116 $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>";
118 $error_collector_mailto .= prepare4mailbody("=== Error === \n");
119 $error_collector_mailto .= prepare4mailbody("PHP error: $errstr ($errfile, line $errline)\n");
120 $error_collector_mailto .= prepare4mailbody("=== /Error === \n\n");
122 /* Extract traceback data - if available */
123 if (function_exists('debug_backtrace')){
124 $trace= debug_backtrace();
126 $error_collector_mailto .= prepare4mailbody("=== Trace ===");
128 /* Generate trace history */
129 for ($index= 0; $index<count($trace); $index++){
132 $ct= $trace[$index];
133 $loc= "";
134 if (isset($ct['class'])){
135 $loc.= _("class")." ".$ct['class'];
136 if (isset($ct['function'])){
137 $loc.= " / ";
138 }
139 }
140 if (isset($ct['function'])){
141 $loc.= _("function")." ".$ct['function'];
142 }
143 if (isset($ct['type'])){
144 switch ($ct['type']){
145 case "::":
146 $type= _("static");
147 break;
149 case "->":
150 $type= _("method");
151 break;
152 }
153 } else {
154 $type= "-";
155 }
156 $args= "";
157 if (isset($ct['args'])){
158 foreach ($ct['args'] as $arg){
160 /* Avoid convertig object to string errors */
161 if(is_object($arg)){
162 $arg = "CLASS: ".get_class($arg);
163 }
165 $args.= htmlentities("\"$arg\", ");
166 }
167 }
168 $args= preg_replace("/, $/", "", $args);
169 if ($args == ""){
170 $args= "-";
171 }
172 if(isset($ct['file'])) {
173 $file= $ct['file'];
174 }else{
175 $file="";
176 }
177 if(isset($ct['line'])) {
178 $line= $ct['line'];
179 }else{
180 $line="";
181 }
182 $color= ($index&1)?'#404040':'606060';
183 $error_collector.= "<tr style='background-color:$color'><td style='padding-left:20px' width=\"30%\">"._("Trace")."[$index]: $loc</td>";
184 $error_collector.= "<td>"._("File").": $file ("._('Line')." $line)</td><td width=\"10%\">"._("Type").": $type</td></tr>";
185 $error_collector.= "<tr style='background-color:$color'><td colspan=3 style='padding-left:20px;'>"._("Arguments").": $args</td></tr>";
187 /* Add trace part to mailto body */
188 $error_collector_mailto .= prepare4mailbody(
189 "\nTrace[".$index."]:".$loc.
190 "\nFile : ".$file.
191 "\nLine : ".$line.
192 "\nType : ".$type.
193 "\n ".$args.
194 "\n");
196 }
197 }
199 $error_collector_mailto .= prepare4mailbody("=== /Trace === \n");
201 /* Close error table */
202 $error_collector.= "</table>";
204 /* Flush in case of fatal errors */
205 if (preg_match('/^fatal/i', $errstr)){
206 echo $error_collector."</div>";
207 flush();
208 exit;
209 }
210 }
213 function dummy_error_handler()
214 {
215 }
218 /* Set timezone */
219 date_default_timezone_set("GMT");
221 /* Get base dir for reference */
222 $BASE_DIR= dirname(dirname(__FILE__));
223 $ROOT_DIR= $BASE_DIR."/html";
224 error_reporting (E_ALL | E_STRICT);
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:$BASE_DIR/include/php_writeexcel");
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 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
246 ?>