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;
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 /* Create header as needed */
57 if ($error_collector == ""){
58 if ($_SESSION['js']==FALSE){
59 $error_collector= "<div>";
60 } else {
61 $error_collector= "<table 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'>";
62 }
63 }
65 /* Create error header */
66 $error_collector.= "<table 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>";
68 /* Extract traceback data - if available */
69 if (function_exists('debug_backtrace')){
70 $trace= debug_backtrace();
72 /* Generate trace history */
73 for ($index= 1; $index<count($trace); $index++){
74 $ct= $trace[$index];
75 $loc= "";
76 if (isset($ct['class'])){
77 $loc.= _("class")." ".$ct['class'];
78 if (isset($ct['function'])){
79 $loc.= " / ";
80 }
81 }
82 if (isset($ct['function'])){
83 $loc.= _("function")." ".$ct['function'];
84 }
85 if (isset($ct['type'])){
86 switch ($ct['type']){
87 case "::":
88 $type= _("static");
89 break;
91 case "->":
92 $type= _("method");
93 break;
94 }
95 } else {
96 $type= "-";
97 }
98 $args= "";
99 foreach ($ct['args'] as $arg){
100 $args.= htmlentities("\"$arg\", ");
101 }
102 $args= preg_replace("/, $/", "", $args);
103 if ($args == ""){
104 $args= "-";
105 }
106 $file= $ct['file'];
107 $line= $ct['line'];
108 $color= ($index&1)?'#404040':'606060';
109 $error_collector.= "<tr style='background-color:$color'><td style='padding-left:20px' width=\"30%\">"._("Trace")."[$index]: $loc</td>";
110 $error_collector.= "<td>"._("File").": $file ("._('Line')." $line)</td><td width=\"10%\">"._("Type").": $type</td></tr>";
111 $error_collector.= "<tr style='background-color:$color'><td colspan=3 style='padding-left:20px;'>"._("Arguments").": $args</td></tr>";
112 }
113 }
115 /* Close error table */
116 $error_collector.= "</table>";
118 /* Write to syslog */
119 gosa_log ("PHP error: $errstr ($errfile, line $errline)");
121 /* Flush in case of fatal errors */
122 if (preg_match('/^fatal/i', $errstr)){
123 echo $error_collector."</div>";
124 flush();
125 exit;
126 }
127 }
130 function dummy_error_handler()
131 {
132 }
135 /* Get base dir for reference */
136 $BASE_DIR= dirname(dirname(__FILE__));
137 $ROOT_DIR= $BASE_DIR."/html";
138 error_reporting (E_ALL);
140 /* Register error handler */
141 $error_collector= "";
142 set_error_handler('gosaRaiseError');
144 $variables_order= "ES";
145 ini_set("register_globals",0);
146 ini_set("track_vars",1);
147 ini_set("display_errors",1);
148 ini_set("report_memleaks",1);
149 ini_set("include_path",".:$BASE_DIR/include");
151 /* Do smarty setup */
152 require("smarty/Smarty.class.php");
153 $smarty = new Smarty;
154 $smarty->template_dir = $BASE_DIR.'/ihtml/';
155 $smarty->caching= false;
156 $smarty->php_handling= SMARTY_PHP_REMOVE;
158 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
159 ?>