Ignore:
Timestamp:
Apr 20, 2013, 8:51:15 PM (11 years ago)
Author:
chronos
Message:
  • Upraveno: Definice třída User přesunuta do modulu User. Existuje aplikační modul System->ModuleManager->ModulesUser a samotná instance třídy System->User.
  • Upraveno: Zbylá inicializace starého modulového systému třídy Module přesunuta do startovní části aplikačních modulů.
  • Upraveno: Třída System přesunuta ze souboru Common/Global do samostatného souboru Common/System.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Common/Global.php

    r522 r524  
    1515include_once(dirname(__FILE__).'/Database.php');
    1616include_once(dirname(__FILE__).'/Code.php');
     17include_once(dirname(__FILE__).'/System.php');
    1718include_once(dirname(__FILE__).'/Mail.php');
    18 include_once(dirname(__FILE__).'/Log.php');
    19 include_once(dirname(__FILE__).'/User.php');
    2019include_once(dirname(__FILE__).'/Page.php');
    2120include_once(dirname(__FILE__).'/Form/Form.php');
     
    2322 
    2423// Application modules
     24include_once(dirname(__FILE__).'/../Modules/System/System.php');
    2525include_once(dirname(__FILE__).'/../Modules/Error/Error.php');
     26include_once(dirname(__FILE__).'/../Modules/Log/Log.php');
    2627include_once(dirname(__FILE__).'/../Modules/File/File.php');
    2728include_once(dirname(__FILE__).'/../Modules/Meteostation/Meteostation.php');
     
    4546include_once(dirname(__FILE__).'/../Modules/NetworkConfigRouterOS/NetworkConfigRouterOS.php');
    4647
    47 class System extends Module
    48 {
    49   var $Modules;
    50   /** @var Type */
    51   var $Type;
    52   var $Pages;
    53   /** @var AppModuleManager */
    54   var $ModuleManager;
    55   var $PathItems;
    56   var $RootURLFolder;
    57 
    58   function __construct()
    59   {
    60     parent::__construct();
    61     $this->Modules = array();
    62     $this->Pages = array();
    63     $this->ModuleManager = new AppModuleManager();
    64     $this->Database = new Database();
    65     $this->FormManager = new FormManager($this->Database);
    66   } 
    67  
    68   function RegisterPage($Path, $Handler)
    69   {
    70     if(is_array($Path))
    71     {
    72       $Page = &$this->Pages;
    73       $LastKey = array_pop($Path);
    74       foreach($Path as $PathItem)
    75       {
    76         $Page = &$Page[$PathItem];       
    77       }
    78       if(!is_array($Page)) $Page = array('' => $Page);
    79       $Page[$LastKey] = $Handler;
    80     } else $this->Pages[$Path] = $Handler;
    81   }
    82  
    83   function SearchPage($PathItems, $Pages)
    84   {
    85     if(count($PathItems) > 0) $PathItem = $PathItems[0];
    86       else $PathItem = '';
    87     if(array_key_exists($PathItem, $Pages))
    88     {
    89       if(is_array($Pages[$PathItem]))
    90       {
    91         array_shift($PathItems);
    92         return($this->SearchPage($PathItems, $Pages[$PathItem]));
    93       } else return($Pages[$PathItem]);
    94     } else return('');
    95   }
    96  
    97   function PageNotFound()
    98   {
    99     return('Page '.implode('/', $this->PathItems).' not found.');
    100   }
    101  
    102   function ShowPage()
    103   {
    104     /* @var $Page Page */
    105     $ClassName = $this->SearchPage($this->PathItems, $this->Pages);     
    106     if($ClassName != '')
    107     {
    108       $Page = new $ClassName();
    109       $Page->System = &$this;
    110       $Page->Database = &$this->Database;
    111       $Page->GetOutput();
    112     } else echo($this->PageNotFound());
    113   }
    114  
    115   function ModulePresent($Name)
    116   {
    117     return(array_key_exists($Name, $this->Modules));
    118   }
    119 
    120   function AddModule($Module)
    121   {
    122     //echo('Přidávám modul '.get_class($Module).'<br />');
    123     $Module->System = &$this;
    124     $Module->Database = &$this->Database;
    125     $this->Modules[get_class($Module)] = $Module;
    126   }
    127  
    128   function AddEmailToQueue($To, $Subject, $Content, $From, $AttachmentFileId = '')
    129   {
    130     $Values = array('To' => $To,
    131       'Subject' => $Subject, 'Content' => $Content, 'Time' => 'NOW()',
    132       'From' => $From);
    133     if($AttachmentFileId != '') $Values['AttachmentFile'] = $AttachmentFileId;
    134     $this->Database->insert('EmailQueue', $Values);
    135   }
    136  
    137   function ProcessEmailQueue()
    138   {
    139     $Output = '';
    140     $DbResult = $this->Database->select('EmailQueue', '*', 'Archive=0');
    141     while($DbRow = $DbResult->fetch_assoc())
    142     {     
    143       $Mail = new Mail();
    144       $Mail->AddToCombined($DbRow['To']);
    145       $Mail->Subject = $DbRow['Subject'];
    146       $Mail->From = $DbRow['From'];
    147       $Mail->AddBody(strip_tags($DbRow['Content']), 'text/plain');
    148       $Mail->AddBody($DbRow['Content'], 'text/html');
    149       if($DbRow['AttachmentFile'] != '')
    150       {
    151         $DbResult2 = $this->Database->select('File', '*', 'Id='.$DbRow['AttachmentFile']);
    152         while($File = $DbResult2->fetch_assoc())
    153           $Mail->AttachFile($this->Config['Web']['FileRootFolder'].$File['DrivePath'], $File['MimeType']);
    154       }
    155       $Mail->Send();
    156       $this->Database->update('EmailQueue', 'Id='.$DbRow['Id'], array('Archive' => 1));
    157       $this->Modules['Log']->NewRecord('System', 'SendEmail', $DbRow['Id']);
    158       $Output .= 'To: '.$DbRow['To'].'  Subject: '.$DbRow['Subject'].'<br />';
    159     }   
    160     return($Output);
    161   }
    162  
    163   function HumanDate($Time)
    164   {
    165     return(date('j.n.Y', $Time));
    166   }
    167  
    168   function Link($Target)
    169   {
    170     return($this->RootURLFolder.$Target);
    171   }   
    172 }
    173 
    17448function GlobalInit()
    17549{
     
    20478  if(!$UpdateManager->IsUpToDate()) die('Systém vyžaduje aktualizaci databáze.');
    20579 
    206   // Init old modules
    207   $System->AddModule(new Log());
    208   $System->AddModule(new User());
    209   if(isset($_SERVER['REMOTE_ADDR'])) $System->Modules['User']->Check();
    210   $System->AddModule(new Bill());
    211   $System->AddModule(new Finance());
    212   $System->Modules['Finance']->MainSubject = $Config['Finance']['MainSubjectId'];
    213   $System->Modules['Finance']->DirectoryId = $Config['Finance']['DirectoryId'];
    214   $System->Modules['Finance']->LoadMonthParameters(0);
    215   $System->Modules['Log']->Database->LastQuery = 'ssd';
    216   RegisterFormClasses($System->FormManager);
    217  
     80  $Database = $System->Database;
     81  RegisterFormClasses($System->FormManager); 
    21882 
    21983  // Register new modules
    22084  $System->ModuleManager->RegisterModule(new ModuleError($System));
     85  $System->ModuleManager->RegisterModule(new ModuleSystem($System));
     86  $System->ModuleManager->RegisterModule(new ModuleLog($System));
    22187  $System->ModuleManager->RegisterModule(new ModuleFile($System));
    22288  $System->ModuleManager->RegisterModule(new ModuleMeteostation($System));
     
    236102  $System->ModuleManager->RegisterModule(new ModuleMeals($System));
    237103  $System->ModuleManager->RegisterModule(new ModuleNetworkTopology($System));
     104  $System->ModuleManager->RegisterModule(new ModuleNetworkConfig($System));
     105  $System->ModuleManager->RegisterModule(new ModuleNetworkConfigRouterOS($System));
     106  $System->ModuleManager->RegisterModule(new ModuleNetworkConfigLinux($System));
    238107  $System->ModuleManager->StartAll();
    239108}
Note: See TracChangeset for help on using the changeset viewer.