| 1 | <?php
 | 
|---|
| 2 | 
 | 
|---|
| 3 | class ModuleError extends Module
 | 
|---|
| 4 | {
 | 
|---|
| 5 |   public string $Encoding;
 | 
|---|
| 6 |   public ErrorHandler $ErrorHandler;
 | 
|---|
| 7 | 
 | 
|---|
| 8 |   function __construct(System $System)
 | 
|---|
| 9 |   {
 | 
|---|
| 10 |     parent::__construct($System);
 | 
|---|
| 11 |     $this->Name = 'Error';
 | 
|---|
| 12 |     $this->Version = '1.0';
 | 
|---|
| 13 |     $this->Creator = 'Chronos';
 | 
|---|
| 14 |     $this->License = 'GNU/GPLv3';
 | 
|---|
| 15 |     $this->Description = 'Error logging and reporting';
 | 
|---|
| 16 |     $this->Dependencies = array(ModuleLog::GetName());
 | 
|---|
| 17 | 
 | 
|---|
| 18 |     $this->ErrorHandler = new ErrorHandler();
 | 
|---|
| 19 |     $this->Encoding = 'utf-8';
 | 
|---|
| 20 |   }
 | 
|---|
| 21 | 
 | 
|---|
| 22 |   function DoStart(): void
 | 
|---|
| 23 |   {
 | 
|---|
| 24 |     $this->ErrorHandler->ShowError = Core::Cast($this->System)->Config['Web']['ShowPHPError'];
 | 
|---|
| 25 |     $this->ErrorHandler->OnError = array(array($this, 'DoOnError'));
 | 
|---|
| 26 |     $this->ErrorHandler->Start();
 | 
|---|
| 27 |   }
 | 
|---|
| 28 | 
 | 
|---|
| 29 |   function DoStop(): void
 | 
|---|
| 30 |   {
 | 
|---|
| 31 |     $this->ErrorHandler->Stop();
 | 
|---|
| 32 |   }
 | 
|---|
| 33 | 
 | 
|---|
| 34 |   function DoOnError(string $Error): void
 | 
|---|
| 35 |   {
 | 
|---|
| 36 |     ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('Error', 'Log', $Error);
 | 
|---|
| 37 | 
 | 
|---|
| 38 |     //if ($Config['Web']['ErrorLogFile'] != '')
 | 
|---|
| 39 |     // error_log($Error, 3, $Config['Web']['ErrorLogFile']);
 | 
|---|
| 40 |     // Pošli mi zprávu (pokud je to kritická chyba)
 | 
|---|
| 41 |     //mail($Config['Web']['AdminEmail'], $Config['Web']['Title'].' - Chybové hlášení', $Error);
 | 
|---|
| 42 |     // Show error message
 | 
|---|
| 43 |     if ($this->ErrorHandler->ShowError == true)
 | 
|---|
| 44 |     {
 | 
|---|
| 45 |       if (array_key_exists('REMOTE_ADDR', $_SERVER))
 | 
|---|
| 46 |       {
 | 
|---|
| 47 |         echo('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>'."\n".
 | 
|---|
| 48 |             '<meta http-equiv="Content-Language" content="cs">'."\n".
 | 
|---|
| 49 |             '<meta http-equiv="Content-Type" content="text/html; charset='.$this->Encoding.'"></head><body>'."\n".
 | 
|---|
| 50 |             'Došlo k vnitřní chybě!<br/> O chybě byl uvědoměn správce webu a chybu brzy odstraní.<br/><br/>');
 | 
|---|
| 51 |         echo('<pre>'.$Error.'</pre><br/>');     // V případě ladění chybu i zobraz
 | 
|---|
| 52 |         echo('</body></html>');
 | 
|---|
| 53 |       } else
 | 
|---|
| 54 |       {
 | 
|---|
| 55 |         echo($Error);
 | 
|---|
| 56 |       }
 | 
|---|
| 57 |     }
 | 
|---|
| 58 |   }
 | 
|---|
| 59 | }
 | 
|---|