thomascube
2005-11-18 fbf77b4493f1b77c99751d8a86365c712ae3fb1b
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']);
fd8c50 66                  
T 67     if (empty($CONFIG['log_dir']))
68       $CONFIG['log_dir'] = $INSTALL_PATH.'logs';
69       
70     if ($fp = fopen($CONFIG['log_dir'].'/errors', 'a'))
71     
4e17e6 72       {
T 73       fwrite($fp, $log_entry);
74       fclose($fp);
75       }
76     }
77
78 /*
79   // resport the bug to the global bug reporting system
80   if ($CONFIG['debug_level'] & 2)
81     {
82     $delm = '%AC';
83     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',
84                  $arg_arr['type'],
85                  $GLOBALS['HTTP_HOST'],
86                  $GLOBALS['SERVER_ADDR'],
87                  $GLOBALS['REMOTE_ADDR'],
88                  rawurlencode($GLOBALS['HTTP_USER_AGENT']),
89                     $GLOBALS['SERVER_PORT']==43 ? 'https' : 'http',
90                     $GLOBALS['HTTP_HOST'].$GLOBALS['REQUEST_URI'],
91                     $arg_arr['file'], $delm,
92                  $arg_arr['line'], $delm,
93                  rawurlencode($arg_arr['message'])));
94     }
95 */
96
97   // show error if debug_mode is on
98   if ($CONFIG['debug_level'] & 4)
99     {
100     print "<b>$program Error in $arg_arr[file] ($arg_arr[line]):</b>&nbsp;";
101     print nl2br($arg_arr['message']);
102     print '<br />';
103     flush();
104     }
105   }
106
107
108 ?>