Changeset 69 for trunk/Application
- Timestamp:
- Feb 28, 2016, 10:54:30 AM (9 years ago)
- Location:
- trunk/Application
- Files:
-
- 3 added
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Application/Core.php
r68 r69 1 1 <?php 2 2 3 class Application 3 $ConfigFileName = dirname(__FILE__).'/../Config/Config.php'; 4 if(file_exists($ConfigFileName)) include_once($ConfigFileName); 5 6 include_once(dirname(__FILE__).'/../Global.php'); 7 include_once(dirname(__FILE__).'/Version.php'); 8 include_once(dirname(__FILE__).'/View.php'); 9 include_once(dirname(__FILE__).'/UpdateTrace.php'); 10 include_once(dirname(__FILE__).'/DefaultConfig.php'); 11 12 class Core extends Application 4 13 { 5 var $Database; 14 var $Pages; 15 var $ShowPage; 16 var $BaseURL; 6 17 7 function Start() 18 function __construct() 19 { 20 parent::__construct(); 21 $this->Pages = array(); 22 $this->ShowPage = true; 23 $this->BaseURL = $_SERVER['SCRIPT_NAME']; 24 if(substr($this->BaseURL, -10, 10) == '/index.php') 25 $this->BaseURL = substr($this->BaseURL, 0, -10); 26 } 27 28 function RunCommon() 8 29 { 9 30 global $Config, $DatabaseRevision; 10 11 $FileName = dirname(__FILE__).'/config.php';12 if(file_exists($FileName)) include_once($FileName);13 else {14 die('Configuration file "'.$FileName.'" not found.');15 }16 31 17 32 session_start(); … … 33 48 foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($Item); 34 49 35 // Check database persistence structure 36 $UpdateManager = new UpdateManager(); 37 $UpdateManager->Database = $this->Database; 38 $UpdateManager->Revision = $DatabaseRevision; 39 if(!$UpdateManager->IsInstalled()) die('Systém vyžaduje instalaci databáze.'); 40 if(!$UpdateManager->IsUpToDate()) die('Systém vyžaduje aktualizaci databáze.'); 50 $this->Config = &$Config; 41 51 52 // Register and start existing modules 53 $this->Setup = new Setup($this); 54 $this->Setup->Start(); 55 if($this->Setup->CheckState()) 56 { 57 $this->ModuleManager->Start(); 58 } 59 } 60 61 function Run() 62 { 63 $this->RunCommon(); 64 if($this->ShowPage) 65 { 66 $this->PathItems = ProcessURL(); 67 $this->ShowPage(); 68 } 69 } 70 71 function ShowPage() 72 { 73 $this->BaseView = new BaseView($this); 74 75 /* @var $Page Page */ 76 $ClassName = $this->SearchPage($this->PathItems, $this->Pages); 77 if($ClassName != '') 78 { 79 $Page = new $ClassName($this); 80 } else { 81 $Page = new PageMissing($this); 82 } 83 echo($this->BaseView->GetOutput($Page)); 84 } 85 86 function RegisterPage($Path, $Handler) 87 { 88 if(is_array($Path)) 89 { 90 $Page = &$this->Pages; 91 $LastKey = array_pop($Path); 92 foreach($Path as $PathItem) 93 { 94 $Page = &$Page[$PathItem]; 95 } 96 if(!is_array($Page)) $Page = array('' => $Page); 97 $Page[$LastKey] = $Handler; 98 } else $this->Pages[$Path] = $Handler; 99 } 100 101 function UnregisterPage($Path) 102 { 103 unset($this->Pages[$Path]); 104 } 105 106 function SearchPage($PathItems, $Pages) 107 { 108 if(count($PathItems) > 0) $PathItem = $PathItems[0]; 109 else $PathItem = ''; 110 if(array_key_exists($PathItem, $Pages)) 111 { 112 if(is_array($Pages[$PathItem])) 113 { 114 array_shift($PathItems); 115 return($this->SearchPage($PathItems, $Pages[$PathItem])); 116 } else return($Pages[$PathItem]); 117 } else return(''); 118 } 119 120 function Link($Target) 121 { 122 return($this->BaseURL.$Target); 42 123 } 43 124 } 125 126 class PageMissing extends Page 127 { 128 function __construct($System) 129 { 130 parent::__construct($System); 131 $this->ParentClass = ''; 132 $this->Title = T('Page not found'); 133 } 134 135 function Show() 136 { 137 Header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); 138 return('<h3 align="center">'.T('Required page not found')); 139 } 140 } -
trunk/Application/UpdateTrace.php
r68 r69 1 1 <?php 2 2 3 class UpdateTrace 3 function FullInstall($Manager) 4 4 { 5 var $Manager; 6 7 function FullInstall($Manager) 8 { 9 $this->Manager->Execute('CREATE TABLE IF NOT EXISTS `SystemVersion` ( 5 $Manager->Execute('CREATE TABLE IF NOT EXISTS `SystemVersion` ( 10 6 `Id` int(11) NOT NULL AUTO_INCREMENT, 11 7 `Revision` int(11) NOT NULL, 12 8 PRIMARY KEY (`Id`) 13 9 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;'); 14 $this->Manager->Execute('INSERT INTO `SystemVersion` (`Id`, `Version`) VALUES (NULL, 65);'); 15 } 10 $Manager->Execute('INSERT INTO `SystemVersion` (`Id`, `Revision`) VALUES (NULL, 65);'); 11 $Manager->Execute('CREATE TABLE IF NOT EXISTS `measure` ( 12 `Id` int(11) NOT NULL auto_increment, 13 `Name` varchar(255) collate utf8_general_ci NOT NULL, 14 `Description` varchar(255) collate utf8_general_ci NOT NULL, 15 `Divider` int(11) NOT NULL default 1, 16 `Unit` varchar(16) collate utf8_general_ci NOT NULL, 17 `Continuity` tinyint(1) NOT NULL default 0, 18 `Period` int(11) NOT NULL default 60, 19 `OldName` varchar(32) collate utf8_general_ci NOT NULL, 20 `PermissionView` varchar(255) collate utf8_general_ci NOT NULL default "all", 21 `PermissionAdd` varchar(255) collate utf8_general_ci NOT NULL default "localhost.localdomain", 22 `Info` varchar(255) collate utf8_general_ci NOT NULL, 23 `Enabled` int(11) NOT NULL default 1, 24 `Cumulative` int(11) NOT NULL default 0, 25 `DataTable` varchar(32) collate utf8_general_ci NOT NULL default "data", 26 `DataType` varchar(32) collate utf8_general_ci NOT NULL, 27 PRIMARY KEY (`Id`) 28 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;'); 29 } 16 30 17 function UpdateTo67($Manager) 18 { 19 $this->Manager->Execute('RENAME TABLE `measure` TO `Measure`;'); 20 $this->Manager->Execute('CREATE TABLE IF NOT EXISTS `Permission` ( 31 function UpdateTo67($Manager) 32 { 33 $Manager->Execute('RENAME TABLE `measure` TO `Measure`;'); 34 /* 35 $Manager->Execute('CREATE TABLE IF NOT EXISTS `Permission` ( 21 36 `Id` int(11) NOT NULL AUTO_INCREMENT, 22 37 `Measure` int(11) NOT NULL, … … 26 41 KEY `Measure` (`Measure`) 27 42 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;'); 28 $this->Manager->Execute('ALTER TABLE `Permission` ADD FOREIGN KEY (`Measure`) '.29 30 $DbResult = $this->Manager->Execute('SELECT `Id`, `PermissionAdd` FROM `Measure`');31 32 33 $this->Manager->Execute('INSERT INTO `Permission` (`Measure`, `Operation`) VALUES ('.43 $Manager->Execute('ALTER TABLE `Permission` ADD FOREIGN KEY (`Measure`) '. 44 'REFERENCES `Measure`(`Id`) ON DELETE RESTRICT ON UPDATE RESTRICT;'); 45 $DbResult = $Manager->Execute('SELECT `Id`, `PermissionAdd` FROM `Measure`'); 46 while($DbRow = $DbResult->fetch_assoc()) 47 { 48 $Manager->Execute('INSERT INTO `Permission` (`Measure`, `Operation`) VALUES ('. 34 49 $DbRow['Id'].', "add");'); 35 50 } 36 $DbResult = $this->Manager->Execute('SELECT `Id`, `PermissionView` FROM `Measure`');37 38 39 $ this->Manager->Execute('INSERT INTO `Permission` (`Measure`, `Operation`) VALUES ('.51 $DbResult = $Manager->Execute('SELECT `Id`, `PermissionView` FROM `Measure`'); 52 while($DbRow = $DbResult->fetch_assoc()) 53 { 54 $Manager->Execute('INSERT INTO `Permission` (`Measure`, `Operation`) VALUES ('. 40 55 $DbRow['Id'].', "view");'); 41 }42 //$this->Manager->Execute('');43 56 } 57 */ 58 } 44 59 45 function __construct() 60 class Updates 61 { 62 function Get() 46 63 { 47 $this->Updates =array(64 return(array( 48 65 65 => array('Revision' => 67, 'Function' => 'UpdateTo67'), 49 ) ;66 )); 50 67 } 51 68 } -
trunk/Application/Version.php
r68 r69 8 8 $Revision = 67; 9 9 $DatabaseRevision = 67; 10 $ReleaseTime = strtotime('2016-0 1-03');10 $ReleaseTime = strtotime('2016-02-28');
Note:
See TracChangeset
for help on using the changeset viewer.