Code

Updated logview to display the target object too.
[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, $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   /* Hide ldap size limit messages */
44   if (preg_match('/ldap_error/', $errstr)){
45     if (preg_match('/sizelimit/', $errstr)){
46       return;
47     }
48   }
50   if((isset($config->data))){ 
51     if((isset($config->data['MAIN']['DISPLAYERRORS']))&&(!preg_match("/^true$/i",$config->data['MAIN']['DISPLAYERRORS']))){
53       /* Write to syslog */
54       new log("view","error","",array(),"PHP error: $errstr ($errfile, line $errline)");
55       return;
56     }
57   }
60   /* Create header as needed */
61   if ($error_collector == ""){
63     /* Mailto body header */
64     if(function_exists("prepare4mailbody")){
65       $error_collector_mailto .=prepare4mailbody(
66                                 "Oups. Seems like you've catched some kind of bug inside GOsa/PHP. You may want to help ".
67                                 "us to improve the software stability. If so, please provide some more information below.".
68                                 "\n\n".
69                                 "*** GOsa bug report ***".
70                                 "\nGOsa Version: ".get_gosa_version().
71                                 "\n\n".
72                                 "Please describe what you did to produce this error as detailed as possible. Can you ".
73                                 "reproduce this bug using the demo on http://www.gosa-project.org ?".
74                                 "\n\n".
75                                 "*** PHP error information ***\n\n");
76       }
77     
78     if (isset($_SESSION['js']) && $_SESSION['js']==FALSE){
79       $error_collector= "<div>";
80     } else {
81       $error_collector= "
82         <table summary=\"\" width=\"100%\" style='background-color:#E0E0E0;border-bottom:1px solid black;z-index:150;'>
83           <tr>
84             <td>
85               <img alt=\"\" align=\"middle\" src='".get_template_path('images/warning.png')."'>&nbsp;
86               <font style='font-size:14px;font-weight:bold'>".
87                 _("Generating this page caused the PHP interpreter to raise some errors!")."
88               </font>
89             </td>
90             <td align=right>
91               <a href=\"mailto:gosa-bugs@oss.gonicus.de?subject=GOsa%20bugreport&amp;body=%BUGBODY%\">
92                 <img border='0' src='images/mailto.png' title='"._("Send bug report to the GOsa Team")."' class='center' alt=''>&nbsp;"._("Send bugreport")."
93               </a>
94             </td>
95             <td align=right>
96               <button onClick='toggle(\"errorbox\")'>".
97                 _("Toggle information")."
98               </button>
99             </td>
100           </tr>
101         </table>
102         <div id='errorbox' style='position:absolute; z-index:150; visibility: hidden'>";
103     }
104   }
105  
106   /* Create error header */
107   $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>";
109   $error_collector_mailto .= prepare4mailbody("=== Error === \n");
110   $error_collector_mailto .= prepare4mailbody("PHP error: $errstr ($errfile, line $errline)\n");
111   $error_collector_mailto .= prepare4mailbody("=== /Error === \n\n");
112   
113   /* Extract traceback data - if available */
114   if (function_exists('debug_backtrace')){
115     $trace= debug_backtrace();
117     $error_collector_mailto .= prepare4mailbody("=== Trace ===");
119     /* Generate trace history */
120     for ($index= 0; $index<count($trace); $index++){
123       $ct= $trace[$index];
124       $loc= "";
125       if (isset($ct['class'])){
126         $loc.= _("class")." ".$ct['class'];
127         if (isset($ct['function'])){
128           $loc.= " / ";
129         }
130       }
131       if (isset($ct['function'])){
132         $loc.= _("function")." ".$ct['function'];
133       }
134       if (isset($ct['type'])){
135         switch ($ct['type']){
136           case "::":
137             $type= _("static");
138           break;
140           case "->":
141             $type= _("method");
142           break;
143         }
144       } else {
145         $type= "-";
146       }
147       $args= "";
148       if (isset($ct['args'])){
149         foreach ($ct['args'] as $arg){
150        
151           /* Avoid convertig object to string errors */ 
152           if(is_object($arg)){
153             $arg = "CLASS:&nbsp;".get_class($arg);
154           }
155   
156           $args.= htmlentities("\"$arg\", ");
157         }
158       }
159       $args= preg_replace("/, $/", "", $args);
160       if ($args == ""){
161         $args= "-";
162       }
163       if(isset($ct['file'])) {
164         $file= $ct['file'];
165       }else{
166         $file="";
167       }
168       if(isset($ct['line'])) {
169         $line= $ct['line'];
170       }else{
171         $line="";
172       }
173       $color= ($index&1)?'#404040':'606060';
174       $error_collector.= "<tr style='background-color:$color'><td style='padding-left:20px' width=\"30%\">"._("Trace")."[$index]: $loc</td>";
175       $error_collector.= "<td>"._("File").": $file ("._('Line')." $line)</td><td width=\"10%\">"._("Type").": $type</td></tr>";
176       $error_collector.= "<tr style='background-color:$color'><td colspan=3 style='padding-left:20px;'>"._("Arguments").": $args</td></tr>";
178       /* Add trace part to mailto body */
179       $error_collector_mailto .= prepare4mailbody(
180                                    "\nTrace[".$index."]:".$loc.
181                                    "\nFile : ".$file.
182                                    "\nLine : ".$line.
183                                    "\nType : ".$type.
184                                    "\n  ".$args.
185                                    "\n");
187     }
188   }
190   $error_collector_mailto .= prepare4mailbody("=== /Trace === \n");
192   /* Close error table */
193   $error_collector.= "</table>";
195   /* Flush in case of fatal errors */
196   if (preg_match('/^fatal/i', $errstr)){
197     echo $error_collector."</div>";
198     flush();
199     exit;
200   }
204 function dummy_error_handler()
209 /* Set timezone */
210 date_default_timezone_set("GMT");
212 /* Get base dir for reference */
213 $BASE_DIR= dirname(dirname(__FILE__));
214 $ROOT_DIR= $BASE_DIR."/html";
215 error_reporting (E_ALL | E_STRICT);
217 /* Register error handler */
218 $error_collector= "";
219 $error_collector_mailto= "";
220 set_error_handler('gosaRaiseError');
222 $variables_order= "ES";
223 ini_set("register_globals",0);
224 ini_set("track_vars",1);
225 ini_set("display_errors",1);
226 ini_set("report_memleaks",1);
227 ini_set("include_path",".:$BASE_DIR/include:$BASE_DIR/include/php_writeexcel");
229 /* Do smarty setup */
230 require("smarty/Smarty.class.php");
231 $smarty = new Smarty;
232 $smarty->template_dir = $BASE_DIR.'/ihtml/';
233 $smarty->caching= false;
234 $smarty->php_handling= SMARTY_PHP_REMOVE;
236 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
237 ?>