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 ($_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'><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:0; visibility: hidden'>";
72 }
73 }
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>";
78 /* Extract traceback data - if available */
79 if (function_exists('debug_backtrace')){
80 $trace= debug_backtrace();
82 /* Generate trace history */
83 for ($index= 1; $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 $file= $ct['file'];
119 $line= $ct['line'];
120 $color= ($index&1)?'#404040':'606060';
121 $error_collector.= "<tr style='background-color:$color'><td style='padding-left:20px' width=\"30%\">"._("Trace")."[$index]: $loc</td>";
122 $error_collector.= "<td>"._("File").": $file ("._('Line')." $line)</td><td width=\"10%\">"._("Type").": $type</td></tr>";
123 $error_collector.= "<tr style='background-color:$color'><td colspan=3 style='padding-left:20px;'>"._("Arguments").": $args</td></tr>";
124 }
125 }
127 /* Close error table */
128 $error_collector.= "</table>";
130 /* Flush in case of fatal errors */
131 if (preg_match('/^fatal/i', $errstr)){
132 echo $error_collector."</div>";
133 flush();
134 exit;
135 }
136 }
139 function dummy_error_handler()
140 {
141 }
144 /* Get base dir for reference */
145 $BASE_DIR= dirname(dirname(__FILE__));
146 $ROOT_DIR= $BASE_DIR."/html";
147 error_reporting (E_ALL);
149 /* Register error handler */
150 $error_collector= "";
151 set_error_handler('gosaRaiseError');
153 $variables_order= "ES";
154 ini_set("register_globals",0);
155 ini_set("track_vars",1);
156 ini_set("display_errors",1);
157 ini_set("report_memleaks",1);
158 ini_set("include_path",".:$BASE_DIR/include");
160 /* Do smarty setup */
161 require("smarty/Smarty.class.php");
162 $smarty = new Smarty;
163 $smarty->template_dir = $BASE_DIR.'/ihtml/';
164 $smarty->caching= false;
165 $smarty->php_handling= SMARTY_PHP_REMOVE;
167 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
168 ?>