Code

added migration classes for RDN properties
[gosa.git] / gosa-core / include / php_setup.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 define ("LOCALE_DIR", dirname(dirname(__FILE__))."/locale/compiled");
25 function gosaRaiseError($errno, $errstr, $errfile, $errline)
26 {
27   global $error_collector,$config, $error_collector_mailto;
29   // To avoid recursion - restore original error handler.
30   restore_error_handler();
32   /* Return if error reporting is set to zero 
33    * Also exclude statements prefixed with @ - Comment out the block below to see suppressed errors. 
34    * e.g. @call_function_but_hide_errors()
35    */
36   if (error_reporting() == 0){
37     set_error_handler('gosaRaiseError', E_WARNING |  E_NOTICE | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_STRICT) ;
38     return;
39   }
41   /* Workaround for buggy imap_open error outputs */
42   if (preg_match('/imap_open/', $errstr)){
43     set_error_handler('gosaRaiseError', E_WARNING |  E_NOTICE | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_STRICT) ;
44     return;
45   }
47   /* Hide ldap size limit messages */
48   if (preg_match('/ldap_error/', $errstr)){
49     if (preg_match('/sizelimit/', $errstr)){
50       set_error_handler('gosaRaiseError', E_WARNING |  E_NOTICE | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_STRICT) ;
51       return;
52     }
53   }
55   /* Error messages are hidden in GOsa, so we only send them to the logging class and abort here */
56   if(isset($config->data) && $config->get_cfg_value("core","displayErrors") != "true"){
58     /* Write to syslog */
59     if(class_exists("log") && !preg_match("/No such object/",$errstr)){
60       new log("view","error","",array(),"PHP error: $errstr ($errfile, line $errline)");
61     }
63     set_error_handler('gosaRaiseError', E_WARNING |  E_NOTICE | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_STRICT) ;
64     return;
65   }
66  
67   /* Send all errors to logging class, except "Ldap : No such object" messages*/
68   if(class_exists("log") && !preg_match("/No such object/",$errstr)){
69     new log("debug","all",$errfile,array(),"Type:".$errno.", Message:".$errstr.", File:".$errfile.", Line: ".$errline);
70   }
72   /* Create header as needed */
73   if ($error_collector == ""){
75     /* Mailto body header */
76     if(function_exists("prepare4mailbody")){
77       $version= "unknown";
78       if(function_exists("get_gosa_version")){
79               $version= get_gosa_version();
80       }
81       $error_collector_mailto .=prepare4mailbody(
82                                 "Oups. Seems like you've catched some kind of bug inside GOsa/PHP. You may want to help ".
83                                 "us to improve the software stability. If so, please provide some more information below.".
84                                 "\n\n".
85                                 "*** GOsa bug report ***".
86                                 "\nGOsa Version: $version".
87                                 "\n\n".
88                                 "Please describe what you did to produce this error as detailed as possible. Can you ".
89                                 "reproduce this bug using the demo on http://www.gosa-project.org ?".
90                                 "\n\n".
91                                 "*** PHP error information ***\n\n");
92       }
93     
94     if (session::is_set('js') && session::get('js')==FALSE){
95       $error_collector= "<div>";
96     } else {
97         $error_collector= "
98         <table summary=\"\" class='error-collector'>
99           <tr>
100            <td style='width:32px'>".image('images/toolbar-warning.png')."</td>
101            <td><span>"._("Generating this page caused the PHP interpreter to raise some errors!")."</span></td>
102            <td align='right'>
103             <a href=\"mailto:gosa-bugs@oss.gonicus.de?subject=GOsa%20bugreport&amp;body=%BUGBODY%\">
104                 ".image('images/mailto.png')."&nbsp;"._("Send bugreport")."
105             </a>
106            </td>
107            <td align='right'>
108             <button onClick=\"$('errorbox').toggle();\">"._("Toggle details")."</button>
109             </td>
110           </tr>
111         </table>
112         <div id='errorbox' style='position:absolute; z-index:150; display: none;'>";
113     }
114   }
115  
116   /* Create error header */
117   $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>";
119   $error_collector_mailto .= prepare4mailbody("=== Error === \n");
120   $error_collector_mailto .= prepare4mailbody("PHP error: $errstr ($errfile, line $errline)\n");
121   $error_collector_mailto .= prepare4mailbody("=== /Error === \n\n");
122   
123   /* Extract traceback data - if available */
124   if (function_exists('debug_backtrace')){
125     $trace= debug_backtrace();
127     $error_collector_mailto .= prepare4mailbody("=== Trace ===");
129     /* Generate trace history */
130     for ($index= 0, $c= count($trace); $index<$c; $index++){
133       $ct= $trace[$index];
134       $loc= "";
135       if (isset($ct['class'])){
136         $loc.= _("class")." ".$ct['class'];
137         if (isset($ct['function'])){
138           $loc.= " / ";
139         }
140       }
141       if (isset($ct['function'])){
142         $loc.= _("function")." ".$ct['function'];
143       }
144       if (isset($ct['type'])){
145         switch ($ct['type']){
146           case "::":
147             $type= _("static");
148           break;
150           case "->":
151             $type= _("method");
152           break;
153         }
154       } else {
155         $type= "-";
156       }
157       $args= "";
158       if (isset($ct['args'])){
159         foreach ($ct['args'] as $arg){
160        
161           /* Avoid convertig object to string errors */ 
162           if(is_object($arg)){
163             $arg = "CLASS:&nbsp;".get_class($arg);
164           }
165   
166           $args.= htmlentities("\"$arg\", ");
167         }
168       }
169       $args= preg_replace("/, $/", "", $args);
170       if ($args == ""){
171         $args= "-";
172       }
173       if(isset($ct['file'])) {
174         $file= $ct['file'];
175       }else{
176         $file="";
177       }
178       if(isset($ct['line'])) {
179         $line= $ct['line'];
180       }else{
181         $line="";
182       }
183       $color= ($index&1)?'#404040':'606060';
184       $error_collector.= "<tr style='background-color:$color'><td style='padding-left:20px' width=\"30%\">"._("Traceback")."[$index]: $loc</td>";
185       $error_collector.= "<td>"._("File").": $file ("._('Line')." $line)</td><td width=\"10%\">"._("Type").": $type</td></tr>";
186       $error_collector.= "<tr style='background-color:$color'><td colspan=3 style='padding-left:20px;'>"._("Arguments").": $args</td></tr>";
188       /* Add trace part to mailto body */
189       $error_collector_mailto .= prepare4mailbody(
190                                    "\nTrace[".$index."]:".$loc.
191                                    "\nFile : ".$file.
192                                    "\nLine : ".$line.
193                                    "\nType : ".$type.
194                                    "\n  ".$args.
195                                    "\n");
197     }
198   }
200   $error_collector_mailto .= prepare4mailbody("=== /Trace === \n");
202   /* Close error table */
203   $error_collector.= "</table>";
205   /* Flush in case of fatal errors */
206   set_error_handler('gosaRaiseError', E_WARNING |  E_NOTICE | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_STRICT) ;
207   if (preg_match('/^fatal/i', $errstr)){
208     echo $error_collector."</div>";
209     flush();
210     exit;
211   }
215 function prepare4mailbody($string)
217   $string = html_entity_decode($string);
219   $from = array(
220                 "/%/",
221                 "/ /",
222                 "/\n/",
223                 "/\r/",
224                 "/!/",
225                 "/#/",
226                 "/\*/",
227                 "/\//",
228                 "/</",
229                 "/>/",
230                 "/\?/",
231                 "/\"/");
233   $to = array(
234                 "%25",
235                 "%20",
236                 "%0A",
237                 "%0D",
238                 "%21",
239                 "%23",
240                 "%2A",
241                 "%2F",
242                 "%3C",
243                 "%3E",
244                 "%3F",
245                 "%22");
247   $string = preg_replace($from,$to,$string);
249   return($string);
253 function dummy_error_handler()
257 /* Bail out for incompatible/old PHP versions */
258 if (!version_compare(phpversion(),"5.2.0",">=")){
259   echo "PHP version needs to be 5.2.0 or above to run GOsa. Aborted.";
260   exit();
263 /* Set timezone */
264 date_default_timezone_set("GMT");
266 /* Get base dir for reference */
267 $BASE_DIR= dirname(dirname(__FILE__));
268 $ROOT_DIR= $BASE_DIR."/html";
269 error_reporting (E_ALL | E_STRICT);
271 /* Register error handler */
272 $error_collector= "";
273 $error_collector_mailto= "";
275 #set_error_handler('gosaRaiseError', E_WARNING |  E_NOTICE | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_STRICT) ;
277 $variables_order= "ES";
278 ini_set("register_globals",0);
279 ini_set("track_vars",1);
280 ini_set("display_errors",1);
281 ini_set("report_memleaks",1);
282 ini_set("include_path",".:$BASE_DIR/include:$BASE_DIR/include/utils/excel:/usr/share/php");
284 /* Do smarty setup */
285 require("smarty/Smarty.class.php");
286 $smarty = new Smarty;
287 $smarty->template_dir = $BASE_DIR.'/ihtml/';
288 $smarty->caching= false;
289 $smarty->php_handling= SMARTY_PHP_REMOVE;
291 /* Global FPDF define */
292 define('FPDF_FONTPATH', '/usr/share/php/fpdf/font/');
295 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
296 ?>