thomascube
2005-11-08 583f1c8d80c42195d0ee41f30a885e13d777b79f
commit | author | age
4e17e6 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/include/bugs.inc                                              |
6  |                                                                       |
7  | This file is part of the BQube Webmail client                         |
8  | Copyright (C) 2005, BQube Dev - Switzerland                           |
30233b 9  | Licensed under the GNU GPL                                            |
4e17e6 10  |                                                                       |
T 11  | PURPOSE:                                                              |
12  |   Provide error handling and logging functions                        |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16  +-----------------------------------------------------------------------+
17
18  $Id$
19
20 */
21
22
23 // throw system error and show error page
24 function raise_error($arg=array(), $log=FALSE, $terminate=FALSE)
25   {
26   global $__page_content, $CONFIG, $OUTPUT, $ERROR_CODE, $ERROR_MESSAGE;
27   
28   /* $arg keys:
29        int     code
30        string  type (php, xpath, db, imap, javascript)
31        string  message
32        sring   file
33        int     line
34   */
35
36   // report bug (if not incompatible browser)
37   if ($log && $arg['type'] && $arg['message'])
38     log_bug($arg);
39
40   // display error page and terminate script
41   if ($terminate)
42     {
43     $ERROR_CODE = $arg['code'];
44     $ERROR_MESSAGE = $arg['message'];
45     include("program/steps/error.inc");
46     exit;
47     }
48   }
49
50
51 // report error
52 function log_bug($arg_arr)
53   {
54   global $CONFIG, $INSTALL_PATH;
55   $program = $arg_arr['type']=='xpath' ? 'XPath' : strtoupper($arg_arr['type']);
56
57   // write error to local log file
58   if ($CONFIG['debug_level'] & 1)
59     {
60     $log_entry = sprintf("[%s] %s Error: %s in %s on line %d\n",
61                  date("d-M-Y H:i:s O", mktime()),
62                  $program,
63                  $arg_arr['message'],
64                  $arg_arr['file'],
65                  $arg_arr['line']);
66
67     if ($fp = fopen($INSTALL_PATH.'logs/errors', 'a'))
68       {
69       fwrite($fp, $log_entry);
70       fclose($fp);
71       }
72     }
73
74 /*
75   // resport the bug to the global bug reporting system
76   if ($CONFIG['debug_level'] & 2)
77     {
78     $delm = '%AC';
79     http_request(sprintf('http://roundcube.net/log/bug.php?_type=%s&_domain=%s&_server_ip=%s&_client_ip=%s&_useragent=%s&_url=%s%%3A//%s&_errors=%s%s%s%s%s',
80                  $arg_arr['type'],
81                  $GLOBALS['HTTP_HOST'],
82                  $GLOBALS['SERVER_ADDR'],
83                  $GLOBALS['REMOTE_ADDR'],
84                  rawurlencode($GLOBALS['HTTP_USER_AGENT']),
85                     $GLOBALS['SERVER_PORT']==43 ? 'https' : 'http',
86                     $GLOBALS['HTTP_HOST'].$GLOBALS['REQUEST_URI'],
87                     $arg_arr['file'], $delm,
88                  $arg_arr['line'], $delm,
89                  rawurlencode($arg_arr['message'])));
90     }
91 */
92
93   // show error if debug_mode is on
94   if ($CONFIG['debug_level'] & 4)
95     {
96     print "<b>$program Error in $arg_arr[file] ($arg_arr[line]):</b>&nbsp;";
97     print nl2br($arg_arr['message']);
98     print '<br />';
99     flush();
100     }
101   }
102
103
104 ?>