Changeset 341
- Timestamp:
- Jan 17, 2012, 8:40:51 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 5 added
- 2 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Module.php
r340 r341 1 1 <?php 2 3 include_once(dirname(__FILE__).'/../Model.php'); 2 4 3 5 class Module … … 9 11 var $Description; 10 12 var $Dependencies; 13 var $Models; 14 var $Database; 15 var $Installed; 16 17 function __construct($Database) 18 { 19 $this->Database = &$Database; 20 } 11 21 12 22 function Install() 13 { 23 { 24 DebugLog('Installing module '.$this->Name.'...'); 25 parent::Install(); 26 foreach($this->Models as $ModelName) 27 { 28 $Model = new $ModelName(); 29 $Query = 'CREATE TABLE IF NOT EXISTS `'.$ModelName.'` ( 30 `Id` int(11) NOT NULL AUTO_INCREMENT,'; 31 foreach($Model->Properties as $Property) 32 { 33 if($Property['Type'] == PropertyDateTime) 34 $Query .= '`'.$Property['Name'].'` DATETIME NOT NULL,'; 35 else if($Property['Type'] == PropertyString) 36 $Query .= '`'.$Property['Name'].'` VARCHAR(255) COLLATE utf8_general_ci NOT NULL,'; 37 else if($Property['Type'] == PropertyText) 38 $Query .= '`'.$Property['Name'].'` TEXT COLLATE utf8_general_ci NOT NULL,'; 39 else if($Property['Type'] == PropertyInteger) 40 $Query .= '`'.$Property['Name'].'` INT(11) NOT NULL,'; 41 else if($Property['Type'] == PropertyFloat) 42 $Query .= '`'.$Property['Name'].'` FLOAT NOT NULL,'; 43 else if($Property['Type'] == PropertyOneToMany) 44 $Query .= '`'.$Property['Name'].'` INT(255) NOT NULL,'. 45 'KEY `'.$Property['Name'].'` (`'.$Property['Name'].'`),'; 46 else if($Property['Type'] == PropertyManyToOne) 47 $Query .= ''; 48 else if($Property['Type'] == PropertyManyToMany) 49 ; // Create many-to-many table 50 //$Query .= '`'.$Property['Name'].'` INT(255) NOT NULL,'. 51 // 'KEY `'.$Property['Name'].'` (`'.$Property['Name'].'`),'; 52 } 53 $Query .= 'PRIMARY KEY (`Id`),'. 54 ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci AUTO_INCREMENT=1 ;'; 55 $this->Database->query($Query); 56 } 57 unset($Model); 14 58 } 15 59 16 60 function UnInstall() 17 61 { 62 DebugLog('Uninstalling module '.$this->Name.'...'); 63 parent::UnInstall(); 64 foreach($this->Models as $ModelName) 65 { 66 $Model = new $ModelName(); 67 if($Model['Type'] == PropertyManyToMany) 68 ; // Delete many-to-many table 69 $this->Database->query('DROP TABLE IF EXISTS `'.$ModelName.'`'); 70 unset($Model); 71 } 72 } 73 } 74 75 class ModularSystem 76 { 77 var $Database; 78 var $Modules = array(); 79 80 function __construct($Database) 81 { 82 $this->Database = &$Database; 83 $DbResult = $this->Database->query('SELECT * FROM Module WHERE Installed=1'); 84 while($Module = $DbResult->fetch_array()) 85 { 86 include_once('Modules/'.$File.'/'.$File.'.php'); 87 $this->Modules[] = new $Module['Name']($this->Database); 88 } 89 } 90 91 function Install() 92 { 93 DebugLog('Installing modular system core...'); 94 $this->Database->query('CREATE TABLE IF NOT EXISTS `Module` ( 95 `Id` int(11) NOT NULL AUTO_INCREMENT, 96 `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL, 97 `Creator` varchar(255) COLLATE utf8_czech_ci NOT NULL, 98 `Version` varchar(255) COLLATE utf8_czech_ci NOT NULL, 99 `License` varchar(255) COLLATE utf8_czech_ci NOT NULL, 100 `Installed` int(11) NOT NULL, 101 PRIMARY KEY (`Id`) 102 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1 ;'); 103 foreach($this->Modules as $Module) 104 { 105 $Module->Install(); 106 } 107 } 108 109 function UnInstall() 110 { 111 DebugLog('Uninstalling modular system core...'); 112 foreach($this->Modules as $Module) 113 $Module->UnInstall(); 114 $this->Database->query('DROP TABLE IF EXISTS `Module`'); 115 } 116 117 function ReloadList() 118 { 119 // Load list of modules from database 120 $Modules = array(); 121 $DbResult = $this->Database->query('SELECT * FROM Module'); 122 while($DbRow = $DbResult->fetch_assoc()) 123 $Modules[$DbRow['Name']] = $DbRow; 124 125 // Load list of modules on disk 126 $ModulesOnDisk = array(); 127 $Files = scandir('Modules'); 128 foreach($Files as $File) 129 if(is_dir('Modules/'.$File) and ($File != '.') and ($File != '..')) 130 { 131 DebugLog($File.','); 132 $ModulesOnDisk[] = $File; 133 } 134 135 // Add new 136 foreach($ModulesOnDisk as $ModuleName) 137 if(!array_key_exists($ModuleName, $Modules)) 138 { 139 DebugLog('Adding module '.$ModuleName.' to list'); 140 include_once('Modules/'.$ModuleName.'/'.$ModuleName.'.php'); 141 $ModuleClassName = 'Module'.$ModuleName; 142 if(class_exists($ModuleClassName)) 143 { 144 $Module = new $ModuleClassName($this->Database); 145 $this->Database->insert('Module', array('Name' => $Module->Name, 146 'Version' => $Module->Version, 'Creator' => $Module->Creator, 147 'Description' => $Module->Description, 'License' => $Module->License, 148 'Installed' => 0)); 149 unset($Module); 150 } else throw new Exception('Missing class '.$ModuleClassName.' in module '.$ModuleName); 151 } 152 153 // Remove missing 154 foreach($Modules as $Module) 155 if($Module['Installed'] == 0) 156 { 157 DebugLog('Removing module '.$ModuleName.' from list'); 158 $this->Database->query('DELETE FROM Module WHERE Id = '.$Module['Id']); 159 } 18 160 } 19 161 } -
trunk/Modules/Project/Project.php
r340 r341 2 2 3 3 include_once(dirname(__FILE__).'/../Module.php'); 4 include_once(dirname(__FILE__).'/../../Model.php'); 4 5 5 class Project extends Module 6 class Project extends Model 7 { 8 function __construct($Database) 9 { 10 parent::__construct($Database); 11 $this->Name = 'Project'; 12 $this->AddPropertyDateTime('TimeSchedule'); 13 $this->AddPropertyOneToMany('UserAssignedTo', 'User'); 14 $this->AddPropertyManyToOne('Comments', 'ProjectComment', 'Project'); 15 $this->AddPropertyText('Description'); 16 } 17 } 18 19 class ProjectComment extends Model 6 20 { 7 21 function __construct() 8 22 { 23 parent::__construct(); 24 $this->Name = 'ProjectComment'; 25 $this->AddPropertyOneToMany('Project', 'Project'); 26 $this->AddPropertyText('Text'); 27 } 28 } 29 30 class ModuleProject extends Module 31 { 32 function __construct($Database) 33 { 34 parent::__construct($Database); 9 35 $this->Name = 'Project'; 10 36 $this->Version = '1.0'; … … 13 39 $this->Description = 'Project and task management'; 14 40 $this->Dependencies = array('User'); 41 $this->Models = array('Project', 'ProjectComment'); 15 42 } 16 43 17 44 function Install() 18 45 { 19 $Query = 'CREATE TABLE IF NOT EXISTS `Project` (20 `Id` int(11) NOT NULL AUTO_INCREMENT,21 `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL,22 `TimeCreate` datetime NOT NULL,23 `UserCreate` int(11) NOT NULL,24 `Description` text COLLATE utf8_czech_ci NOT NULL,25 `UserAssignedTo` int(11) DEFAULT NULL,26 `TimeSchedule` datetime DEFAULT NULL,27 PRIMARY KEY (`Id`),28 KEY `UserCreate` (`UserCreate`),29 KEY `UserAssignedTo` (`UserAssignedTo`)30 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1 ;31 32 CREATE TABLE IF NOT EXISTS `ProjectComment` (33 `Id` int(11) NOT NULL AUTO_INCREMENT,34 `Project` int(11) NOT NULL,35 `Text` text COLLATE utf8_czech_ci NOT NULL,36 `TimeCreate` datetime NOT NULL,37 `UserCreate` int(11) NOT NULL,38 PRIMARY KEY (`Id`),39 KEY `Project` (`Project`),40 KEY `UserCreate` (`UserCreate`)41 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1 ;';42 46 } 43 47 … … 50 54 } 51 55 56 52 57 ?> -
trunk/Modules/User/user.php
r340 r341 266 266 } 267 267 268 class ModuleUser extends Module 269 { 270 function __construct($Database) 271 { 272 parent::__construct($Database); 273 $this->Name = 'User'; 274 $this->Version = '1.0'; 275 $this->Creator = 'Chronos'; 276 $this->License = 'GNU/GPL'; 277 $this->Description = 'User management'; 278 $this->Dependencies = array(); 279 //$this->Models = array('User', 'UserOnline'); 280 } 281 } 282 283 268 284 ?> -
trunk/global.php
r340 r341 7 7 8 8 include_once('database.php'); 9 //include('error.php');10 include_once(' code.php');9 include_once('Common/Error.php'); 10 include_once('Common/Code.php'); 11 11 include_once('module.php'); 12 12 include_once('forms.php'); … … 19 19 include_once('finance/finance.php'); 20 20 include_once('Modules/Module.php'); 21 include_once('Model.php'); 21 22 include_once('Modules/User/user.php'); 22 23 include_once('Modules/Project/Project.php'); … … 221 222 $System->AddModule(new Bill()); 222 223 $System->AddModule(new Finance()); 223 $System->Modules['Finance']->LoadMonthParameters(0); 224 $System->Modules['Finance']->LoadMonthParameters(0); 225 226 $System->ModularSystem = new ModularSystem($Database); 227 $System->ModularSystem->ReloadList(); 224 228 } 225 229 … … 521 525 } 522 526 527 function DebugLog($Text) 528 { 529 global $Config; 530 531 if($Config['Web']['ShowDebug']) 532 { 533 if(isset($_SERVER['REMOTE_ADDR'])) $Ending = '<br/>'."\n"; 534 else $Ending = "\n"; 535 echo($Text.$Ending); 536 } 537 } 538 523 539 GlobalInit(); 524 540
Note:
See TracChangeset
for help on using the changeset viewer.