Changeset 424 for branches/Modular


Ignore:
Timestamp:
Oct 10, 2012, 9:29:20 AM (12 years ago)
Author:
chronos
Message:
  • Upraveno: Modulární systém přepracován tak, že základní modul System je zodpovědný za udržování stavu instalování modulů v databázi a je instalován samostatně jako první modul. Následně lze instalovat moduly dle závislostí.
Location:
branches/Modular
Files:
4 added
32 edited

Legend:

Unmodified
Added
Removed
  • branches/Modular/.htaccess

    r404 r424  
    1111RewriteCond  %{REQUEST_FILENAME}  !-f
    1212RewriteCond  %{REQUEST_FILENAME}  !-d
    13 #RewriteRule   ^(.*)$ centrala/index.php?$1
    14 RewriteRule   ^(.*)$ dev/centrala/branches/Modular/index.php?$1
     13RewriteRule   ^(.*)$ centrala_modular/index.php?$1
     14#RewriteRule   ^(.*)$ dev/centrala/branches/Modular/index.php?$1
    1515
    1616# Pretty urls
  • branches/Modular/Common/Database.php

    r401 r424  
    7070      $this->Error = $E->getMessage();
    7171      if(($this->Error != '') and ($this->ShowSQLError == true))
    72         echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>');
     72        //echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>');
     73        throw new Exception($this->Error);
    7374    }
    7475    return($Result); 
     
    8283  function delete($Table, $Condition)
    8384  {
    84     $this->PDO->query('DELETE FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition); 
     85    $this->query('DELETE FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition); 
    8586  }
    8687 
     
    9798    $Name = substr($Name, 1);
    9899    $Values = substr($Values, 1);
    99     $this->PDO->query('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');
     100    $this->query('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');
    100101    $this->insert_id = $this->PDO->lastInsertId();
    101102  }
     
    110111    }
    111112    $Values = substr($Values, 2); 
    112     $this->PDO->query('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')');
     113    $this->query('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')');
    113114  }
    114115 
     
    126127    $Values = substr($Values, 1);
    127128    //echo('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES ('.$Values.')<br />');
    128     $this->PDO->query('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');
     129    $this->query('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');
    129130    //echo($this->error().'<br>');
    130131  }
     
    132133  function charset($Charset)
    133134  {
    134     $this->PDO->query('SET NAMES "'.$Charset.'"');
     135    $this->query('SET NAMES "'.$Charset.'"');
    135136  }
    136137 
  • branches/Modular/Common/Global.php

    r405 r424  
    2727include_once('Localization.php');
    2828include_once('Navigation.php');
    29  
     29include_once('Modules/System/System.php');
     30 
    3031
    3132class System extends ModularSystem
     
    5051    global $Config;
    5152   
    52     return($Config['Web']['RootFolder'].$Target);
     53    return($this->RootFolder.$Target);
    5354  }     
    5455}
     56
     57$System = NULL;
    5558
    5659function GlobalInit()
     
    7982  $System->Localization->Load();
    8083  $System->Navigation = new Navigation();
     84
     85  //if(!$System->IsInstalled()) die('System not installed.');
     86  $ModuleSystem = new ModuleSystem($System->Database, $System);
     87  $System->RegisterModule($ModuleSystem);
     88  if($System->Modules['System']->IsInstalled()) $System->Modules['System']->Start(); 
    8189}
    8290
  • branches/Modular/Common/Module.php

    r405 r424  
    1414  var $Models = array();
    1515  var $SupportedModels = array();
     16  /** @var Database */
    1617  var $Database;
    1718  var $Installed;
    18   var $Initialized;
    19   var $System;
     19  var $Running;
     20  /** @var ModularSystem */
     21  var $ModularSystem;
     22 
    2023 
    2124  function __construct($Database, $System)
     
    2326    $this->Database = &$Database;   
    2427    $this->System = &$System;   
    25     $this->Initialized = false;
     28    $this->Running = false;
    2629    $this->Installed = false;
    2730  }
     
    2932  function Install()
    3033  {
    31     if($this->Installed) return;
     34    if($this->IsInstalled()) return;
    3235    DebugLog('Installing module '.$this->Name.'...');
    3336    $this->Installed = true;
     
    3538    // Install dependencies first
    3639    foreach($this->Dependencies as $Dependency) 
    37       $this->System->Modules[$Dependency]->Install();
    38 
    39     $this->LoadModels();
    40     foreach($this->Models as $Index => $Module)
    41     {
    42       $this->Models[$Index]->Install();
    43     }
    44     $this->Database->query('UPDATE SystemModule SET Installed=1 WHERE Name="'.$this->Name.'"');
     40      $this->ModularSystem->Modules[$Dependency]->Install();
     41    $this->DoChange();
    4542  }
    4643 
    4744  function UnInstall()
    4845  {
     46    if($this->IsInstalled() == false) return;
    4947    DebugLog('Uninstalling module '.$this->Name.'...');
     48    if($this->Running) $this->Stop();
    5049    $this->Installed = false;
    5150   
     
    5554        if(($Dependency == $this->Name) and ($Module->Installed)) $this->System->Modules[$Module->Name]->UnInstall();
    5655       
     56    $this->DoChange();
     57  }
     58 
     59  function IsInstalled()
     60  {
     61    return($this->Installed);
     62  }
     63 
     64  function Start()
     65  {
     66    if($this->Running) return;
     67    if($this->IsInstalled() == false) return;
     68    $this->Running = true;
     69    foreach($this->Dependencies as $Dependency) 
     70      $this->System->Modules[$Dependency]->Start();
    5771    $this->LoadModels();
    58     foreach(array_reverse($this->Models, true) as $Index => $Model)
    59     {
    60       $this->Models[$Index]->UnInstall();
    61     }
    62     $this->Database->query('UPDATE SystemModule SET Installed=0 WHERE Name="'.$this->Name.'"');
    63   }
    64  
    65   function Init()
    66   {
    67     if($this->Initialized) return;
    68     $this->Initialized = true;
    69     foreach($this->Dependencies as $Dependency) 
    70       $this->System->Modules[$Dependency]->Init();
     72    $this->DoChange();
    7173  }
    7274 
     75  function Stop()
     76  {
     77    if(!$this->Running) return;
     78    $this->Running = false;
     79    foreach($this->System->Modules as $Module) 
     80      foreach($Module->Dependencies as $Dependency)
     81        if(($Dependency == $this->Name) and ($Module->Running))
     82          $this->System->Modules[$Module->Name]->Stop();
     83    $this->DoChange();
     84  }
     85 
     86  private function DoChange()
     87  {
     88    if($this->ModularSystem->OnModuleChange)
     89      call_user_func_array($this->ModularSystem->OnModuleChange, array($this));
     90  }
     91 
     92  function RegisterModel($ModelName)
     93  {
     94    $this->SupportedModels[] = $ModelName;
     95  }
     96 
     97  function UnregisterModel($ModelName)
     98  {
     99    unset($this->SupportedModels[$ModelName]); 
     100  }
     101
    73102  function LoadModels()
    74103  {
     
    85114class ModularSystem
    86115{
     116  /** @var Database */
    87117  var $Database;
    88118  var $Modules = array();
    89119  var $Models = array();
    90120  var $Menu = array();
     121  var $OnModuleChange;
    91122 
    92123  function __construct($Database)
     
    95126  }
    96127 
    97   function ModulePresent($Name)
    98   {
    99     return(array_key_exists($Name, $this->Modules));
    100   }
    101 
    102   function LoadModules($Installed = true)
    103   {
    104     //DebugLog('Loading modules...');
    105     $this->Modules = array();
    106     $Query = 'SELECT `Id`, `Name`,`Installed` FROM `SystemModule`';
    107     if($Installed) $Query .= ' WHERE `Installed`=1';
    108       else $Query .= ''; // WHERE `Installed`=0';
    109     $DbResult = $this->Database->query($Query);
    110     while($Module = $DbResult->fetch_array())
    111     {
    112       //echo($Module['Name'].',');
    113       include_once('Modules/'.$Module['Name'].'/'.$Module['Name'].'.php');
    114       $ModuleClassName = 'Module'.$Module['Name'];
    115       $NewModule = new $ModuleClassName($this->Database, $this);     
    116       $NewModule->Id = $Module['Id'];
    117       $NewModule->Installed = $Module['Installed'];
    118       $this->Modules[$Module['Name']] = $NewModule;
    119     }     
    120   }
    121  
    122   function Init()
     128  function StartAll()
    123129  {
    124130    $this->LoadModules();
     
    126132    {
    127133      //DebugLog('Init module '.$Module->Name);
    128       $this->Modules[$Index]->Init();
    129     }
    130   }
    131  
     134      $this->Modules[$Index]->Start();
     135    }
     136  }
     137 
     138  function StopAll()
     139  {
     140    foreach($this->Modules as $Index => $Module)
     141    {
     142      //DebugLog('Init module '.$Module->Name);
     143      $this->Modules[$Index]->Stop();
     144    }
     145  }
     146
    132147  function Install()
    133148  {
    134149    //DebugLog('Installing modular system core...');
    135     $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemVersion` (
    136   `Id` int(11) NOT NULL AUTO_INCREMENT,
    137   `Version` varchar(255) COLLATE utf8_czech_ci NOT NULL,
    138   `Description` datetime NOT NULL,
    139   PRIMARY KEY (`Id`)
    140 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
    141     $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModule` (
    142   `Id` int(11) NOT NULL AUTO_INCREMENT,
    143   `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL,
    144   `Creator` varchar(255) COLLATE utf8_czech_ci NOT NULL,
    145   `Version` varchar(255) COLLATE utf8_czech_ci NOT NULL,
    146   `License` varchar(255) COLLATE utf8_czech_ci NOT NULL,
    147   `Installed` int(11) NOT NULL,
    148   `Description` text COLLATE utf8_czech_ci NOT NULL,
    149   PRIMARY KEY (`Id`)
    150 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
    151    
    152     $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModuleDependency` (
    153   `Id` int(11) NOT NULL AUTO_INCREMENT,
    154   `Module` int(11) NOT NULL,
    155   `DependencyModule` int(11) NOT NULL,
    156   PRIMARY KEY (`Id`),
    157   KEY (`Module`),
    158   KEY (`DependencyModule`),
    159   UNIQUE (`Module` , `DependencyModule`)
    160 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
    161     $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD CONSTRAINT `SystemModuleDependency_ibfk_1` FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)');
    162     $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD CONSTRAINT `SystemModuleDependency_ibfk_2` FOREIGN KEY ( `DependencyModule` ) REFERENCES `SystemModule` (`Id`)');
    163    
    164     $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModel` (
    165   `Id` int(11) NOT NULL AUTO_INCREMENT,
    166   `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL,
    167   `Module` int(11) NOT NULL,
    168   KEY (`Module`),
    169   PRIMARY KEY (`Id`)
    170 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
    171     $this->Database->query('ALTER TABLE `SystemModel` ADD CONSTRAINT `SystemModel_ibfk_1` FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)');
    172    
    173     $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModelProperty` (
    174   `Id` int(11) NOT NULL AUTO_INCREMENT,
    175   `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL,
    176   `Type` varchar(255) COLLATE utf8_czech_ci NOT NULL,
    177   `Model` int(11) NOT NULL,
    178   KEY (`Model`),
    179   PRIMARY KEY (`Id`)
    180 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
    181     $this->Database->query('ALTER TABLE `SystemModelProperty` ADD CONSTRAINT `SystemModelProperty_ibfk_1` FOREIGN KEY ( `Model` ) REFERENCES `SystemModel` (`Id`)');
    182150   
    183151    $this->ReloadList();
     
    190158  }
    191159 
    192   function UnInstall()
     160  function UnInstallAll()
    193161  {
    194162    DebugLog('Uninstalling modular system core...');
    195     foreach(array_reverse($this->Modules, true) as $Index => $Module)
    196       $this->Modules[$Index]->UnInstall();
    197    
    198     // Delete tables with reverse order
    199     $this->Database->query('ALTER TABLE `SystemModelProperty` DROP FOREIGN KEY `SystemModelProperty_ibfk_1`');
    200     $this->Database->query('DROP TABLE IF EXISTS `SystemModelProperty`');
    201     $this->Database->query('ALTER TABLE `SystemModel` DROP FOREIGN KEY `SystemModel_ibfk_1`');
    202     $this->Database->query('DROP TABLE IF EXISTS `SystemModel`');
    203     $this->Database->query('ALTER TABLE `SystemModuleDependency` DROP FOREIGN KEY `SystemModuleDependency_ibfk_1`');
    204     $this->Database->query('ALTER TABLE `SystemModuleDependency` DROP FOREIGN KEY `SystemModuleDependency_ibfk_2`');
    205     $this->Database->query('DROP TABLE IF EXISTS `SystemModuleDependency`');
    206     $this->Database->query('DROP TABLE IF EXISTS `SystemModule`');
    207     $this->Database->query('DROP TABLE IF EXISTS `SystemVersion`');
    208   }
    209  
    210   function IsInstalled()
    211   {
    212     $DbResult = $this->Database->query('SELECT table_name FROM information_schema.tables
    213 WHERE table_schema = "'.$this->Database->Database.'" AND table_name = "SystemVersion";');   
    214     if($DbResult->num_rows > 0) return(true);
    215       else return(false);
    216   }
    217  
    218   function ReloadList()
    219   {
    220     // Load list of modules from database
    221     $Modules = array();
    222     $DbResult = $this->Database->query('SELECT * FROM `SystemModule`');
    223     while($DbRow = $DbResult->fetch_assoc())
    224       $Modules[$DbRow['Name']] = $DbRow;
    225    
     163    foreach($this->Modules as $Index => $Module)
     164    {
     165      //DebugLog('Init module '.$Module->Name);
     166      $this->Modules[$Index]->Uninstall();
     167    }
     168  }
     169 
     170  /* @return Module */
     171  function SearchModuleById($Id)
     172  {
     173    foreach($this->Modules as $Module)
     174    {
     175      //DebugLog($Module->Name.' '.$Module->Id);
     176      if($Module->Id == $Id) return($Module->Name);
     177    }       
     178    return('');
     179  }
     180
     181  function ModulePresent($Name)
     182  {
     183    return(array_key_exists($Name, $this->Modules));
     184  }
     185 
     186  function RegisterModule(Module $Module)
     187  {
     188    $this->Modules[$Module->Name] = &$Module; 
     189    $Module->ModularSystem = $this;
     190    $Module->OnChange = &$this->OnModuleChange;
     191  }
     192 
     193  function UnregisterModule($Module)
     194  {
     195    unset($this->Modules[array_search($Module, $this->Modules)]); 
     196  }
     197 
     198  function ReloadFromDisk()
     199  {   
    226200    // Load list of modules on disk
    227201    $ModulesOnDisk = array();
     
    235209    // Add new
    236210    foreach($ModulesOnDisk as $ModuleName)
    237     if(!array_key_exists($ModuleName, $Modules))
    238     {
    239       DebugLog('Adding module '.$ModuleName.' to list');
     211    if(!array_key_exists($ModuleName, $this->Modules))
     212    {
     213      //DebugLog('Adding module '.$ModuleName.' to list');
    240214      include_once('Modules/'.$ModuleName.'/'.$ModuleName.'.php');
    241215      $ModuleClassName = 'Module'.$ModuleName;
    242216      if(class_exists($ModuleClassName))
    243217      {
    244         $Module = new $ModuleClassName($this->Database, $this);
    245         $this->Database->insert('SystemModule', array('Name' => $Module->Name,
    246           'Version' => $Module->Version, 'Creator' => $Module->Creator,
    247           'Description' => $Module->Description, 'License' => $Module->License,
    248           'Installed' => 0));
    249         unset($Module);
     218        $NewModule = new $ModuleClassName($this->Database, $this);
     219        $this->RegisterModule($NewModule);
    250220      } else throw new Exception('Missing class '.$ModuleClassName.' in module '.$ModuleName);
    251     }
     221    }   
    252222   
    253     // Remove missing
    254     foreach($Modules as $Module)
    255     if(($Module['Installed'] == 0) and !in_array($Module['Name'], $ModulesOnDisk))
    256     {
    257       DebugLog('Removing module '.$Module['Name'].' from list');
    258       $this->Database->query('DELETE FROM `SystemModule` WHERE `Id` = '.$Module['Id']);
    259     }
    260    
    261     // Reload dependencies
    262     $this->LoadModules(false);
    263223    foreach($this->Modules as $Module)
    264     {
    265       foreach($Module->Dependencies as $Dependency)
    266       {
    267         $this->Database->insert('SystemModuleDependency', array('Module' => $Module->Id,
    268           'DependencyModule' => $this->Modules[$Dependency]->Id));
    269       }
    270     }
    271   }
    272  
    273   function SearchModuleById($Id)
    274   {
    275     foreach($this->Modules as $Module)
    276     {
    277       DebugLog($Module->Name.' '.$Module->Id);
    278       if($Module->Id == $Id) return($Module->Name);
    279     }       
    280     return('');
    281   }
     224    if(array_key_exists($Module->Name, $ModulesOnDisk))
     225    {
     226      $this->ModularSystem->UnregisterModule($Module);
     227    }
     228  } 
    282229}
    283230
  • branches/Modular/Common/Page.php

    r404 r424  
    55class Page
    66{
     7  /** @var Database */
    78  var $Database;
     9  /** @var System */
    810  var $System;
    911  var $Config;
     
    1416  var $NavigationPath = array();
    1517
    16    function __construct()
     18  public static function Cast(Page &$Object = NULL)
     19  {
     20    return $Object;
     21  }
     22 
     23  function __construct()
    1724  {
    1825    global $Config;
     
    5562    <div id="Title">'.$Title.'</div>
    5663    <div class="Navigation"><span class="MenuItem"><strong>Navigace :: </strong> '.$Navigation.'</span><div class="MenuItem2">';
    57     if(array_key_exists('User', $this->System->Modules))
     64    if(array_key_exists('User', $this->System->Modules) and $this->System->Modules['User']->Installed)
    5865    {
    5966      if($this->System->Modules['User']->Models['User']->User['Id'] == $this->System->Modules['User']->Models['User']->AnonymousUserId)
  • branches/Modular/Install.php

    r403 r424  
    22
    33include_once('Common/Global.php');
     4/* @var $System System */
     5$System = NULL;
    46GlobalInit();
     7
     8function ModuleTable()
     9{
     10  global $System;
     11 
     12  $Output = '<table border="1" style="border: 1px" class="WideTable">'.
     13  '<tr><th>Name</th><th>Installed</th><th>Version</th><th>Dependency</th><th>Actions</th></tr>';
     14  foreach($System->Modules as $Module)
     15  {
     16    if($Module->Installed) $Actions = '<a href="?a=uninstall&m='.$Module->Name.'">Odinstalovat</td>';
     17      else $Actions = '<a href="?a=install&m='.$Module->Name.'">Instalovat</td>';
     18    if($Module->Installed) $Installed = 'Ano';
     19      else $Installed = 'Ne';
     20    $Deps = implode(', ', $Module->Dependencies);
     21    if($Deps == '') $Deps = '&nbsp;';
     22    $Output .= '<tr><td>'.$Module->Name.'</td><td>'.$Installed.'</td><td>'.
     23      $Module->Version.'</td><td>'.$Deps.'</td><td>'.$Actions.'</td></tr>';
     24  }
     25  $Output .= '</table>';
     26  return($Output);
     27}
    528
    629function ShowDefault()
     
    831  global $System;
    932 
    10   if($System->IsInstalled())
    11   {
    12     echo('System je již nainstalován.<br/>');
    13     echo('<a href="?a=uninstall">Odinstalovat systém</a>');
     33  if($System->Modules['System']->IsInstalled())
     34  {   
     35    $Output = ModuleTable();
     36    $Output .= '<a href="?a=uninstall">Odinstalovat systém</a>';
     37    $Output .= ' <a href="?a=reload">Aktualizovat seznam z disku</a>';
    1438  } else
    1539  {
    16     echo('System ještě není instalován.<br/>');
    17     echo('<a href="?a=install">Instalovat systém</a>');
    18   }
     40    $Output = 'System ještě není instalován.<br/>';
     41    $Output .= '<a href="?a=install">Instalovat systém</a>';
     42  }   
     43  echo($Output);
    1944}
    2045
     46if($System->Modules['System']->IsInstalled())
     47  $System->Modules['System']->LoadFromDatabase();
     48
     49if($Config['Web']['SystemAdministration'] == true)
     50{
    2151if(array_key_exists('a', $_GET))
    2252{
    2353  if($_GET['a'] == 'install')
    2454  {     
    25     $System->Install();
    26     $System->Init(); 
     55    if(array_key_exists('m', $_GET))
     56    {
     57      $Module = $System->Modules[$_GET['m']];
     58      $Module->Install();
     59    } else
     60    {
     61      $System->Modules['System']->Install();
     62      $System->ReloadFromDisk();
     63      $System->Modules['System']->SaveToDatabase();
     64    }
    2765    ShowDefault();
    2866  }
    2967  else if($_GET['a'] == 'uninstall')
    3068  {
    31     $System->Init(); 
    32     $System->Uninstall();
     69    if(array_key_exists('m', $_GET))
     70    {
     71      $Module = $System->Modules[$_GET['m']];
     72      $Module->Uninstall();
     73      //$System->Modules['System']->SaveToDatabase();
     74    } else
     75    {
     76      $System->Modules['System']->Uninstall();
     77    }
     78    ShowDefault();
     79  } else if($_GET['a'] == 'reload')
     80  {
     81    $System->ReloadFromDisk();
     82    $System->Modules['System']->SaveToDatabase();
    3383    ShowDefault();
    3484  }
    3585  else ShowDefault();
    3686} else ShowDefault();
     87} else echo('Access denied');
    3788
    3889?>
  • branches/Modular/Modules/Chat/Chat.php

    r385 r424  
    9999  }
    100100 
    101   function Init()
     101  function Start()
    102102  {
     103    parent::Start();
    103104    $this->System->Pages['chat'] = 'ChatHistory';
    104105  } 
  • branches/Modular/Modules/EmailQueue/EmailQueue.php

    r378 r424  
    4040  }
    4141
    42   function Init()
     42  function Start()
    4343  {
     44    parent::Start();
     45  }
     46
     47  function Stop()
     48  {
     49    parent::Start();
    4450  }
    4551
  • branches/Modular/Modules/Finance/Finance.php

    r405 r424  
    294294  }
    295295 
    296   function Init()
    297   {
     296  function Start()
     297  {
     298    parent::Start();
    298299    $this->System->Pages['finance'] = 'FinancePage';
    299300    $this->LoadMonthParameters(0);
  • branches/Modular/Modules/FrontPage/FrontPage.php

    r386 r424  
    369369  }
    370370 
    371   function Init()
    372   {
     371  function Start()
     372  {
     373    parent::Start();
    373374    $this->System->Pages[''] = 'IndexPage';
    374375  }
  • branches/Modular/Modules/Hosting/Hosting.php

    r403 r424  
    3737  }
    3838 
    39   function Init()
     39  function Start()
    4040  {
     41    parent::Start();
    4142    $this->System->Pages['hosting'] = 'PageHosting';     
    4243  } 
  • branches/Modular/Modules/Log/Log.php

    r383 r424  
    105105  }
    106106
    107   function Init()
     107  function Start()
    108108  {
     109    parent::Start();
    109110    $this->System->Pages['log'] = 'LogShow';
    110111  }
  • branches/Modular/Modules/Map/Map.php

    r378 r424  
    151151  }
    152152 
    153   function Init()
     153  function Start()
    154154  {
     155    parent::Start();
    155156    $this->System->Pages['map'] = 'NetworkMap';     
    156157  } 
  • branches/Modular/Modules/Meals/Meals.php

    r378 r424  
    229229  }
    230230
    231   function Init()
    232   {
     231  function Start()
     232  {
     233    parent::Start();
    233234    $this->System->Pages['jidelna'] = 'EatingPlace';
    234235  }
  • branches/Modular/Modules/Member/Member.php

    r398 r424  
    9494  }
    9595
    96   function Init()
     96  function Start()
    9797  {
     98    parent::Start();
    9899  }
    99100}
  • branches/Modular/Modules/Network/Network.php

    r386 r424  
    265265  }
    266266 
    267   function Init()
    268   {
     267  function Start()
     268  {
     269    parent::Start();
    269270    $this->System->Pages['sit'] = 'NetworkPage';
    270271  }
  • branches/Modular/Modules/NetworkConfig/NetworkConfig.php

    r383 r424  
    4242  }
    4343
    44   function Init()
     44  function Start()
    4545  {
     46    parent::Start();
    4647  }
    4748}
  • branches/Modular/Modules/NetworkConfigLinux/NetworkConfigLinux.php

    r382 r424  
    2525  }
    2626
    27   function Init()
     27  function Start()
    2828  {
     29    parent::Start();
    2930  }
    3031}
  • branches/Modular/Modules/NetworkConfigRouterOS/NetworkConfigRouterOS.php

    r383 r424  
    6464  }
    6565
    66   function Init()
     66  function Start()
    6767  {
     68    parent::Start();
    6869  }
    6970}
  • branches/Modular/Modules/NetworkShare/NetworkShare.php

    r378 r424  
    5656  }
    5757
    58   function Init()
     58  function Start()
    5959  {
     60    parent::Start();
    6061    $this->System->Pages['sdileni'] = 'SharePage';
    6162  }
  • branches/Modular/Modules/NetworkTopology/NetworkTopology.php

    r378 r424  
    154154  }
    155155
    156   function Init()
     156  function Start()
    157157  {
     158    parent::Start();
    158159    $this->System->Pages['topologie'] = 'NetworkTopologyPage';
    159160  }
  • branches/Modular/Modules/News/News.php

    r383 r424  
    115115  } 
    116116 
    117   function Init()
    118   {
     117  function Start()
     118  {
     119    parent::Start();
    119120    $this->System->Pages['aktuality'] = 'NewsPage';
    120121  }
  • branches/Modular/Modules/OpeningHours/OpeningHours.php

    r378 r424  
    252252  }
    253253 
    254   function Init()
    255   {
     254  function Start()
     255  {
     256    parent::Start();
    256257    $this->System->Pages['otviraci-doby'] = 'SubjectOpenTimePage';
    257258  }
  • branches/Modular/Modules/Project/Project.php

    r385 r424  
    7373  } 
    7474 
    75   function Init()
     75  function Start()
    7676  {
     77    parent::Start();
    7778    $this->System->Pages['projekt'] = 'ProjectPage';
    7879  }
  • branches/Modular/Modules/Subject/Subject.php

    r378 r424  
    4545  }
    4646
    47   function Init()
     47  function Start()
    4848  {
     49    parent::Start();
    4950  }
    5051}
  • branches/Modular/Modules/System/System.php

    r405 r424  
    109109  function Install()
    110110  {
    111     // Do nothing, already installed by ModuleManager
    112111  }
    113112 
    114113  function UnInstall()
    115114  {
    116     // Do nothing, managed by ModuleManager
    117   } 
     115  }   
    118116}
    119117
     
    135133  function Install()
    136134  {
     135    if($this->IsInstalled()) return;
    137136    parent::Install();
     137    $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemVersion` (
     138  `Id` int(11) NOT NULL AUTO_INCREMENT,
     139  `Version` varchar(255) COLLATE utf8_czech_ci NOT NULL,
     140  `Description` datetime NOT NULL,
     141  PRIMARY KEY (`Id`)
     142) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
     143    $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModule` (
     144  `Id` int(11) NOT NULL AUTO_INCREMENT,
     145  `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL,
     146  `Creator` varchar(255) COLLATE utf8_czech_ci NOT NULL,
     147  `Version` varchar(255) COLLATE utf8_czech_ci NOT NULL,
     148  `License` varchar(255) COLLATE utf8_czech_ci NOT NULL,
     149  `Installed` int(11) NOT NULL,
     150  `Description` text COLLATE utf8_czech_ci NOT NULL,
     151  PRIMARY KEY (`Id`)
     152) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
     153   
     154    $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModuleDependency` (
     155  `Id` int(11) NOT NULL AUTO_INCREMENT,
     156  `Module` int(11) NOT NULL,
     157  `DependencyModule` int(11) NOT NULL,
     158  PRIMARY KEY (`Id`),
     159  KEY (`Module`),
     160  KEY (`DependencyModule`),
     161  UNIQUE (`Module` , `DependencyModule`)
     162) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
     163    $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD CONSTRAINT `SystemModuleDependency_ibfk_1` FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)');
     164    $this->Database->query('ALTER TABLE `SystemModuleDependency` ADD CONSTRAINT `SystemModuleDependency_ibfk_2` FOREIGN KEY ( `DependencyModule` ) REFERENCES `SystemModule` (`Id`)');
     165   
     166    $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModel` (
     167  `Id` int(11) NOT NULL AUTO_INCREMENT,
     168  `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL,
     169  `Module` int(11) NOT NULL,
     170  KEY (`Module`),
     171  PRIMARY KEY (`Id`)
     172) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
     173    $this->Database->query('ALTER TABLE `SystemModel` ADD CONSTRAINT `SystemModel_ibfk_1` FOREIGN KEY ( `Module` ) REFERENCES `SystemModule` (`Id`)');
     174   
     175    $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModelProperty` (
     176  `Id` int(11) NOT NULL AUTO_INCREMENT,
     177  `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL,
     178  `Type` varchar(255) COLLATE utf8_czech_ci NOT NULL,
     179  `Model` int(11) NOT NULL,
     180  KEY (`Model`),
     181  PRIMARY KEY (`Id`)
     182) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;');
     183    $this->Database->query('ALTER TABLE `SystemModelProperty` ADD CONSTRAINT `SystemModelProperty_ibfk_1` FOREIGN KEY ( `Model` ) REFERENCES `SystemModel` (`Id`)');
    138184  }
    139185 
     
    141187  {
    142188    parent::UnInstall();
    143   }
    144 
    145   function Init()
    146   {
    147     $this->System->Pages['modules'] = 'PageModules';
    148   }
     189    if(!$this->IsInstalled()) return;
     190   
     191    // Delete tables with reverse order
     192    $this->Database->query('ALTER TABLE `SystemModelProperty` DROP FOREIGN KEY `SystemModelProperty_ibfk_1`');
     193    $this->Database->query('DROP TABLE IF EXISTS `SystemModelProperty`');
     194    $this->Database->query('ALTER TABLE `SystemModel` DROP FOREIGN KEY `SystemModel_ibfk_1`');
     195    $this->Database->query('DROP TABLE IF EXISTS `SystemModel`');
     196    $this->Database->query('ALTER TABLE `SystemModuleDependency` DROP FOREIGN KEY `SystemModuleDependency_ibfk_1`');
     197    $this->Database->query('ALTER TABLE `SystemModuleDependency` DROP FOREIGN KEY `SystemModuleDependency_ibfk_2`');
     198    $this->Database->query('DROP TABLE IF EXISTS `SystemModuleDependency`');
     199    $this->Database->query('DROP TABLE IF EXISTS `SystemModule`');
     200    $this->Database->query('DROP TABLE IF EXISTS `SystemVersion`');
     201  }
     202
     203  function Start()
     204  {
     205    parent::Start();
     206    $this->System->Pages['module'] = 'PageModules';
     207    $this->ModularSystem->OnModuleChange = array($this, 'ModuleChange');
     208    $this->LoadFromDatabase();
     209  }
     210 
     211  function Stop()
     212  {
     213    parent::Stop();
     214  }
     215 
     216  function IsInstalled()
     217  {
     218    $DbResult = $this->Database->query('SELECT table_name FROM information_schema.tables
     219WHERE table_schema = "'.$this->Database->Database.'" AND table_name = "SystemVersion";');   
     220    if($DbResult->num_rows > 0) return(true);
     221      else return(false);
     222  }
     223 
     224  function ModuleChange($Module)
     225  {
     226    if($this->IsInstalled())
     227    {
     228      if($Module->Installed)
     229      $this->Database->query('UPDATE `SystemModule` SET `Installed`=1 WHERE `Name`="'.$Module->Name.'"');
     230        else $this->Database->query('UPDATE `SystemModule` SET `Installed`=0 WHERE `Name`="'.$Module->Name.'"');
     231    }
     232  }
     233 
     234  function LoadFromDatabase()
     235  {
     236    //DebugLog('Loading modules...');
     237    $this->Modules = array();
     238    $Query = 'SELECT `Id`, `Name`,`Installed` FROM `SystemModule`';
     239    $DbResult = $this->Database->query($Query);
     240    while($Module = $DbResult->fetch_array())
     241    {
     242      //echo($Module['Name'].',');
     243      include_once('Modules/'.$Module['Name'].'/'.$Module['Name'].'.php');
     244      $ModuleClassName = 'Module'.$Module['Name'];
     245      $NewModule = new $ModuleClassName($this->Database, $this);     
     246      $NewModule->Id = $Module['Id'];
     247      $NewModule->Installed = $Module['Installed'];     
     248      $this->ModularSystem->RegisterModule($NewModule);
     249    }     
     250  }
     251 
     252  function SaveToDatabase()
     253  {
     254    $Modules = array();
     255    $DbResult = $this->Database->query('SELECT * FROM `SystemModule`');
     256    while($DbRow = $DbResult->fetch_assoc())
     257      $Modules[$DbRow['Name']] = $DbRow;
     258
     259    // Add missing
     260    foreach($this->ModularSystem->Modules as $Module)   
     261    {     
     262      if(!array_key_exists($Module->Name, $Modules))
     263      $this->Database->insert('SystemModule', array('Name' => $Module->Name,
     264        'Version' => $Module->Version, 'Creator' => $Module->Creator,
     265        'Description' => $Module->Description, 'License' => $Module->License,
     266        'Installed' => $Module->Installed));
     267     else $this->Database->update('SystemModule', 'Name = "'.$Module->Name.'"', array(
     268        'Version' => $Module->Version, 'Creator' => $Module->Creator,
     269        'Description' => $Module->Description, 'License' => $Module->License,
     270        'Installed' => $Module->Installed));
     271    }
     272   
     273    // Remove exceeding
     274    foreach($Modules as $Module)   
     275    if(!$this->ModularSystem->ModulePresent($Module['Name']))
     276    {
     277      DebugLog('Removing module '.$Module['Name'].' from list');
     278      $this->Database->query('DELETE FROM `SystemModule` WHERE `Id` = '.$Module['Id']);
     279    }   
     280   
     281    // Reload dependencies
     282    $DbDependency = array();
     283    $DbResult = $this->Database->query('SELECT * FROM `SystemModuleDependency`');
     284    while($DbRow = $DbResult->fetch_assoc())
     285      $DbDependency[$DbRow['Module']][] = $DbRow['DependencyModule'];
     286   
     287    foreach($this->ModularSystem->Modules as $Module)
     288    {
     289      // Add missing
     290      foreach($Module->Dependencies as $Dependency)
     291      {
     292        if(!array_key_exists($Module->Id, $DbDependency) or
     293        !in_array($this->ModularSystem->Modules[$Dependency]->Id, $DbDependency[$Module->Id]))
     294        $this->Database->insert('SystemModuleDependency', array('Module' => $Module->Id,
     295          'DependencyModule' => $this->ModularSystem->Modules[$Dependency]->Id));       
     296      }
     297     
     298      // Remove exceeding
     299      if(array_key_exists($Module->Id, $DbDependency))
     300      foreach($DbDependency[$Module->Id] as $Dep)
     301      {
     302        $DepModName = $this->ModularSystem->SearchModuleById($Dep);
     303        if(!in_array($DepModName, $Module->Dependencies))
     304        $this->Database->query('DELETE FROM `SystemModuleDependency` WHERE `Module` = '.
     305          $Module->Id.' AND DependencyModule='.$Dep);
     306      }     
     307    }   
     308  }
    149309}
    150310
  • branches/Modular/Modules/TV/TV.php

    r378 r424  
    132132  }
    133133 
    134   function Init()
     134  function Start()
    135135  {
     136    parent::Start();
    136137    $this->System->Pages['tv'] = 'TVChannelsPage';
    137138  }
  • branches/Modular/Modules/TimeMeasure/TimeMeasure.php

    r378 r424  
    4646  }
    4747
    48   function Init()
     48  function Start()
    4949  {
     50    parent::Start();
    5051  }
    5152}
  • branches/Modular/Modules/User/User.php

    r405 r424  
    378378  }
    379379 
    380   function Init()
     380  function Start()
    381381  {     
     382    parent::Start();
    382383    $this->System->Modules['User']->Models['User'] = new User($this->Database, $this->System);
    383384    $thus->System->Modules['User']->Models['User']->AnonymousUserId = ANONYMOUS_ID;
  • branches/Modular/Modules/WebCam/WebCam.php

    r378 r424  
    5757  }
    5858 
    59   function Init()
     59  function Start()
    6060  {
     61    parent::Start();
    6162    $this->System->Pages['webcam'] = 'WebcamPage';     
    6263  } 
  • branches/Modular/config.sample.php

    r405 r424  
    1616  'Web' => array
    1717  (
    18     'Locale' => 'csCZ',
     18    'Locale' => 'en',
    1919    'Style' => 'simple',
    2020    'FormatHTML' => false,
     
    2222    'Host' => 'localhost',
    2323    'RootFolder' => '',
    24     'Description' => 'Komunitní počítačová síť',
    25     'Title' => 'Síť',
     24    'Description' => 'Community network',
     25    'Title' => 'Network',
    2626    'Admin' => 'Admin',
    2727    'AdminEmail' => 'admin@localhost',
     
    3131    'ShowRuntimeInfo' => false,
    3232    'ShowDebug' => $IsDeveloper,
    33     'ErrorLogFile' => '/var/www/html/dev/centrala/www/php_script_error.log',   
     33    'SystemAdministration' => $IsDeveloper,       
     34    'ErrorLogFile' => 'php_script_error.log',   
    3435    'WebcamPassword' => '',
    3536    'WebcamRefresh' => 5,
  • branches/Modular/index.php

    r405 r424  
    22
    33include_once('Common/Global.php');
     4/* @var $System System */
     5$System = NULL;
    46GlobalInit();
    5 if(!$System->IsInstalled()) die('System not installed.');
    6 $System->Init(); 
    77$System->PathItems = ProcessURL();
    88//print_r($_GET);
     
    1616  $PageClass = $System->Pages[$Page];
    1717} else $PageClass = 'MissingPage';
    18 $PageObject = new $PageClass();
     18$PageObject = Page::Cast(new $PageClass());
    1919$PageObject->Database = &$Database;
    2020$PageObject->System = &$System;
Note: See TracChangeset for help on using the changeset viewer.