Changeset 516
- Timestamp:
- Apr 9, 2013, 11:36:09 PM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/Global.php
r513 r516 12 12 include_once(dirname(__FILE__).'/Version.php'); 13 13 include_once(dirname(__FILE__).'/Update.php'); 14 include_once(dirname(__FILE__).'/VarDumper.php'); 14 15 include_once(dirname(__FILE__).'/Module.php'); 15 16 include_once(dirname(__FILE__).'/AppModule.php'); 16 17 include_once(dirname(__FILE__).'/Database.php'); 17 include_once(dirname(__FILE__).'/Error.php');18 18 include_once(dirname(__FILE__).'/Code.php'); 19 19 include_once(dirname(__FILE__).'/Mail.php'); … … 28 28 29 29 // Application modules 30 include_once(dirname(__FILE__).'/../Modules/Error/Error.php'); 30 31 include_once(dirname(__FILE__).'/../Modules/File/File.php'); 31 32 include_once(dirname(__FILE__).'/../Modules/Meteostation/Meteostation.php'); … … 174 175 175 176 $System = new System(); 176 $System->Config = $Config;177 $System->Config = &$Config; 177 178 $System->Database->Connect($Config['Database']['Host'], $Config['Database']['User'], $Config['Database']['Password'], $Config['Database']['Database']); 178 179 $System->Database->Prefix = $Config['Database']['Prefix']; … … 190 191 // Init old modules 191 192 $System->AddModule(new Log()); 192 $System->AddModule(new ErrorHandler());193 $System->Modules['ErrorHandler']->ShowErrors = $Config['Web']['ShowPHPError'];194 $System->Modules['ErrorHandler']->Init();195 193 $System->AddModule(new User()); 196 194 if(isset($_SERVER['REMOTE_ADDR'])) $System->Modules['User']->Check(); … … 200 198 $System->Modules['Finance']->DirectoryId = $Config['Finance']['DirectoryId']; 201 199 $System->Modules['Finance']->LoadMonthParameters(0); 200 $System->Modules['Log']->Database->LastQuery = 'ssd'; 202 201 RegisterFormClasses($System->FormManager); 203 202 203 204 204 // Register new modules 205 $System->ModuleManager->RegisterModule(new ModuleError($System)); 205 206 $System->ModuleManager->RegisterModule(new ModuleFile($System)); 206 207 $System->ModuleManager->RegisterModule(new ModuleMeteostation($System)); -
trunk/Common/Version.php
r515 r516 1 1 <?php 2 2 3 $Revision = 51 5; // Subversion revision3 $Revision = 516; // Subversion revision 4 4 $DatabaseRevision = 515; 5 5 $ReleaseTime = '2013-04-08'; -
trunk/Modules/Error/Error.php
r511 r516 1 1 <?php 2 2 3 class ErrorHandler extendsModule3 class ModuleError extends AppModule 4 4 { 5 5 var $Encoding; … … 7 7 var $UserErrors; 8 8 9 function __construct( )9 function __construct($System) 10 10 { 11 parent::__construct($System); 12 $this->Name = 'Error'; 13 $this->Version = '1.0'; 14 $this->Creator = 'Chronos'; 15 $this->License = 'GNU/GPLv3'; 16 $this->Description = 'Error logging and reporting'; 17 $this->Dependencies = array('Log'); 18 11 19 $this->Encoding = 'utf-8'; 12 20 $this->ShowError = false; … … 14 22 } 15 23 16 function In it()24 function Install() 17 25 { 18 set_error_handler(array($this, 'Handle')); 26 parent::Install(); 27 } 28 29 function UnInstall() 30 { 31 parent::UnInstall(); 32 } 33 34 function Start() 35 { 36 parent::Start(); 37 $this->ShowError = $this->System->Config['Web']['ShowPHPError']; 38 set_error_handler(array($this, 'ErrorHandler')); 39 set_exception_handler(array($this, 'ExceptionHandler')); 19 40 } 20 41 21 function Handle($Number, $Message, $FileName, $LineNumber, $Variables)42 function Stop() 22 43 { 23 $Date = date('Y-m-d H:i:s'); // časové razítko položky 44 restore_error_handler(); 45 restore_exception_handler(); 46 parent::Stop(); 47 } 48 49 function ErrorHandler($Number, $Message, $FileName, $LineNumber, $Variables) 50 { 24 51 $ErrorType = array 25 52 ( … … 39 66 if(($this->UserErrors & $Number)) 40 67 { 41 $Error = '# '.$Date."\n";42 68 $Backtrace = debug_backtrace(); 43 69 $Backtrace[0]['function'] = $Message; … … 45 71 $Backtrace[0]['file'] = $FileName; 46 72 $Backtrace[0]['line'] = $LineNumber; 47 //$First = array_shift($Backtrace); 73 $this->Report($Backtrace); 74 if((E_ERROR | E_PARSE) & $Number) die(); 75 } 76 } 77 78 function ExceptionHandler(Exception $Exception) 79 { 80 $Backtrace = $Exception->getTrace(); 81 array_unshift($Backtrace, array( 82 'function' => $Exception->getMessage(), 83 'file' => $Exception->getFile(), 84 'line' => $Exception->getLine(), 85 )); 86 $this->Report($Backtrace); 87 die(); 88 } 89 90 function Report($Backtrace) 91 { 92 $Date = date('Y-m-d H:i:s'); 93 $Error = '# '.$Date."\n"; 94 foreach($Backtrace as $Item) 95 { 96 if(!array_key_exists('line', $Item)) $Item['line'] = ''; 97 if(!array_key_exists('file', $Item)) $Item['file'] = ''; 48 98 49 //array_unshift($Backtrace, $First); 50 //array_shift($Backtrace); 51 foreach($Backtrace as $Item) 52 { 53 $Error .= ' '.$Item['file'].'('.$Item['line'].")\t".$Item['function']; 54 $Arguments = ''; 55 if(array_key_exists('args', $Item) and is_array($Item['args'])) 99 $Error .= ' '.$Item['file'].'('.$Item['line'].")\t".$Item['function']; 100 $Arguments = ''; 101 if(array_key_exists('args', $Item) and is_array($Item['args'])) 56 102 foreach($Item['args'] as $Item) 57 103 { 58 if(is_object($Item)) ; 104 if(is_object($Item)) ; 59 105 else if(is_array($Item)) $Arguments .= "'".serialize($Item)."',"; 60 106 else $Arguments .= "'".$Item."',"; 61 107 } 62 108 if(strlen($Arguments) > 0) $Error .= '('.substr($Arguments, 0, -1).')'; 63 $Error .= "\n"; 64 65 109 $Error .= "\n"; 110 } 111 $Error .= "\n"; 66 112 67 $this->System->Modules['Log']->NewRecord('Error', 'Log', $Error);113 $this->System->Modules['Log']->NewRecord('Error', 'Log', $Error); 68 114 69 //if($Config['Web']['ErrorLogFile'] != '') 70 // error_log($Error, 3, $Config['Web']['ErrorLogFile']); 71 // Pošli mi zprávu (pokud je to kritická chyba) 72 //mail($Config['Web']['AdminEmail'], $Config['Web']['Title'].' - Chybové hlášení', $Error); 73 // Show error message 74 if($this->ShowError == true) 75 { 76 echo('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>'."\n". 77 '<meta http-equiv="Content-Language" content="cs">'."\n". 78 '<meta http-equiv="Content-Type" content="text/html; charset='.$this->Encoding.'"></head><body>'."\n". 79 'Došlo k vnitřní chybě!<br/> O chybě byl uvědoměn správce webu a chybu brzy odstraní.<br/><br/>'); 80 echo('<pre>'.$Error.'</pre><br/>'); // V případě ladění chybu i zobraz 81 echo('</body></html>'); 82 } 83 if((E_ERROR | E_PARSE) & $Number) die(); 84 } 115 //if($Config['Web']['ErrorLogFile'] != '') 116 // error_log($Error, 3, $Config['Web']['ErrorLogFile']); 117 // Pošli mi zprávu (pokud je to kritická chyba) 118 //mail($Config['Web']['AdminEmail'], $Config['Web']['Title'].' - Chybové hlášení', $Error); 119 // Show error message 120 if($this->ShowError == true) 121 { 122 echo('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>'."\n". 123 '<meta http-equiv="Content-Language" content="cs">'."\n". 124 '<meta http-equiv="Content-Type" content="text/html; charset='.$this->Encoding.'"></head><body>'."\n". 125 'Došlo k vnitřní chybě!<br/> O chybě byl uvědoměn správce webu a chybu brzy odstraní.<br/><br/>'); 126 echo('<pre>'.$Error.'</pre><br/>'); // V případě ladění chybu i zobraz 127 echo('</body></html>'); 128 } 85 129 } 86 130 }
Note:
See TracChangeset
for help on using the changeset viewer.