[2] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare - eventlog * |
---|
| 4 | * http://www.egroupware.org * |
---|
| 5 | * This application written by jerry westrick <jerry@westrick.com> * |
---|
| 6 | * -------------------------------------------- * |
---|
| 7 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 8 | * under the terms of the GNU General Public License as published by the * |
---|
| 9 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 10 | * option) any later version. * |
---|
| 11 | \**************************************************************************/ |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | class error |
---|
| 15 | { |
---|
| 16 | /***************************\ |
---|
| 17 | * Instance Variables... * |
---|
| 18 | \***************************/ |
---|
| 19 | var $severity = 'E'; |
---|
| 20 | var $code = 'Unknown'; |
---|
| 21 | var $msg = 'Unknown error'; |
---|
| 22 | var $parms = array(); |
---|
| 23 | var $ismsg = 0; |
---|
| 24 | var $timestamp; |
---|
| 25 | var $fname; |
---|
| 26 | var $line; |
---|
| 27 | var $app; |
---|
| 28 | |
---|
| 29 | var $public_functions = array(); |
---|
| 30 | |
---|
| 31 | // Translate Message into Language |
---|
| 32 | function langmsg() |
---|
| 33 | { |
---|
| 34 | return lang($this->msg,$this->parms); |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | function error($parms) |
---|
| 38 | { |
---|
| 39 | if ($parms == '') |
---|
| 40 | { |
---|
| 41 | return; |
---|
| 42 | } |
---|
| 43 | $etext = $parms['text']; |
---|
| 44 | $parray = Array(); |
---|
[7655] | 45 | for($counter=1;$counter<=10;++$counter) |
---|
[2] | 46 | { |
---|
| 47 | $str = 'p_'.$counter; |
---|
| 48 | if(isset($parms[$str]) && !empty($parms[$str])) |
---|
| 49 | { |
---|
| 50 | $parray[$counter] = $parms[$str]; |
---|
| 51 | } |
---|
| 52 | else |
---|
| 53 | { |
---|
| 54 | $str = 'p'.$counter; |
---|
| 55 | if(isset($parms[$str]) && !empty($parms[$str])) |
---|
| 56 | { |
---|
| 57 | $parray[$counter] = $parms[$str]; |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | } |
---|
| 61 | $fname = $parms['file']; |
---|
| 62 | $line = $parms['line']; |
---|
[5281] | 63 | if (preg_match('/([DIWEF])-([[:alnum:]]*)\, (.*)/i',$etext,$match)) |
---|
[2] | 64 | { |
---|
| 65 | $this->severity = strtoupper($match[1]); |
---|
| 66 | $this->code = $match[2]; |
---|
| 67 | $this->msg = trim($match[3]); |
---|
| 68 | } |
---|
| 69 | else |
---|
| 70 | { |
---|
| 71 | $this->msg = trim($etext); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | @reset($parray); |
---|
| 75 | while( list($key,$val) = each( $parray ) ) |
---|
| 76 | { |
---|
| 77 | $this->msg = preg_replace( "/%$key/", "'".$val."'", $this->msg ); |
---|
| 78 | } |
---|
| 79 | @reset($parray); |
---|
| 80 | |
---|
| 81 | $this->timestamp = time(); |
---|
| 82 | $this->parms = $parray; |
---|
| 83 | $this->ismsg = $parms['ismsg']; |
---|
| 84 | $this->fname = $fname; |
---|
| 85 | $this->line = $line; |
---|
| 86 | $this->app = $GLOBALS['phpgw_info']['flags']['currentapp']; |
---|
| 87 | |
---|
| 88 | if (!$this->fname or !$this->line) |
---|
| 89 | { |
---|
| 90 | $GLOBALS['phpgw']->log->error(array( |
---|
| 91 | 'text'=>'W-PGMERR, Programmer failed to pass __FILE__ and/or __LINE__ in next log message', |
---|
| 92 | 'file'=>__FILE__,'line'=>__LINE__ |
---|
| 93 | )); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | $GLOBALS['phpgw']->log->errorstack[] = $this; |
---|
| 97 | if ($this->severity == 'F') |
---|
| 98 | { |
---|
| 99 | // This is it... Don't return |
---|
| 100 | // do rollback! |
---|
| 101 | // Hmmm this only works if UI!!!! |
---|
| 102 | // What Do we do if it's a SOAP/XML? |
---|
| 103 | echo "<Center>"; |
---|
| 104 | echo "<h1>Fatal Error</h1>"; |
---|
| 105 | echo "<h2>Error Stack</h2>"; |
---|
| 106 | echo $GLOBALS['phpgw']->log->astable(); |
---|
| 107 | echo "</center>"; |
---|
| 108 | // Commit stack to log |
---|
| 109 | $GLOBALS['phpgw']->log->commit(); |
---|
| 110 | $GLOBALS['phpgw']->common->phpgw_exit(True); |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | } |
---|