Changeset 373
- Timestamp:
- Jan 19, 2012, 9:43:36 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 12 added
- 2 deleted
- 14 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/.htaccess
r349 r373 5 5 6 6 RewriteEngine On 7 RewriteBase /7 #RewriteBase / 8 8 9 9 # Pretty urls on localhost with alias … … 11 11 RewriteCond %{REQUEST_FILENAME} !-f 12 12 RewriteCond %{REQUEST_FILENAME} !-d 13 RewriteRule ^(.*)$ centrala/index.php?$1 13 #RewriteRule ^(.*)$ centrala/index.php?$1 14 RewriteRule ^(.*)$ index.php?$1 14 15 15 16 # Pretty urls -
trunk/Common/Global.php
r372 r373 8 8 include_once('Database.php'); 9 9 include_once('Error.php'); 10 include_once(' Code.php');10 include_once('UTF8.php'); 11 11 include_once('File.php'); 12 12 include_once('Page.php'); 13 include_once('Mail.php'); 14 include_once('PrefixMultiplier.php'); 13 15 include_once('Module.php'); 14 16 include_once('Model.php'); 17 include_once('XML.php'); 18 include_once('HTML.php'); 19 include_once('XHTML.php'); 20 include_once('PageList.php'); 21 include_once('TableHeader.php'); 15 22 include_once('View.php'); 16 17 $PrefixMultipliers = array 18 ( 19 'Binary' => array 20 ( 21 'BaseIndex' => 0, 22 'Definition' => array 23 ( 24 array('', '', pow(2, 0)), 25 array('Ki', 'kibi', pow(2, 10)), 26 array('Mi', 'mebi', pow(2, 20)), 27 array('Gi', 'gibi', pow(2, 30)), 28 array('Ti', 'tebi', pow(2, 40)), 29 array('Pi', 'pebi', pow(2, 50)), 30 array('Ei', 'exbi', pow(2, 60)), 31 array('Zi', 'zebi', pow(2, 70)), 32 array('Yi', 'yobi', pow(2, 80)), 33 ), 34 ), 35 'Decimal' => array 36 ( 37 'BaseIndex' => 8, 38 'Definition' => array 39 ( 40 array('y', 'yocto', pow(10, -24)), 41 array('z', 'zepto', pow(10, -21)), 42 array('a', 'atto', pow(10, -18)), 43 array('f', 'femto', pow(10, -15)), 44 array('p', 'piko', pow(10, -12)), 45 array('n', 'nano', pow(10, -9)), 46 array('u', 'mikro', pow(10, -6)), 47 array('m', 'mili', pow(10, -3)), 48 array('', '', pow(10, 0)), 49 array('k', 'kilo', pow(10, 3)), 50 array('M', 'mega', pow(10, 6)), 51 array('G', 'giga', pow(10, 9)), 52 array('T', 'tera', pow(10, 12)), 53 array('P', 'peta', pow(10, 15)), 54 array('E', 'exa', pow(10, 18)), 55 array('Z', 'zetta', pow(10, 21)), 56 array('Y', 'yotta', pow(10, 24)), 57 ), 58 ), 59 'Time' => array 60 ( 61 'BaseIndex' => 8, 62 'Definition' => array 63 ( 64 array('ys', 'yoctosekunda', pow(10, -24)), 65 array('zs', 'zeptosekunda', pow(10, -21)), 66 array('as', 'attosekunda', pow(10, -18)), 67 array('fs', 'femtosekunda', pow(10, -15)), 68 array('ps', 'pikosekunda', pow(10, -12)), 69 array('ns', 'nanosekunda', pow(10, -9)), 70 array('us', 'mikrosekunda', pow(10, -6)), 71 array('ms', 'milisekunda', pow(10, -3)), 72 array('s', 'sekunda', 1), 73 array('minut', 'minuta', 60), 74 array('hodin', 'hodina', 60 * 60) , 75 array('dnů', 'den', 24 * 60 * 60), 76 array('týdnů', 'týden', 7 * 24 * 60 * 60), 77 array('měsíců', 'měsíc', 30 * 24 * 60 * 60), 78 array('roků', 'rok', 364 * 24 * 60 * 60), 79 array('desetiletí', 'desetiletí', 10 * 364 * 24 * 60 * 60), 80 array('stalatí', 'staletí', 100 * 364 * 24 * 60 * 60), 81 array('tisíciletí', 'tisiciletí', 10000 * 364 * 24 * 60 * 60), 82 ), 83 ), 84 ); 23 include_once('ViewList.php'); 24 include_once('ViewForm.php'); 25 85 26 86 27 class System extends ModularSystem … … 88 29 var $Pages = array(); 89 30 90 function AddModule($Module)91 {92 global $Database;93 94 //echo('Přidávám modul '.get_class($Module).'<br />');95 $Module->System = &$this;96 $Module->Database = &$Database;97 $this->Modules[get_class($Module)] = $Module;98 }99 100 function AddEmailToQueue($Address, $Subject, $Content, $Headers = '')101 {102 $this->Database->insert('EmailQueue', array('Address' => $Address, 'Subject' => $Subject, 'Content' => $Content, 'Time' => 'NOW()', 'Headers' => $Headers));103 }104 105 function MailUTF8($To, $Subject = '(No subject)', $Message = '', $Header = '')106 {107 $Header = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n".$Header;108 mail($To, '=?UTF-8?B?'.base64_encode($Subject).'?=', $Message, $Header);109 //echo('mail('.$To.', =?UTF-8?B?'.base64_encode($Subject).'?=, '.$Message.', '.$Header.')<br/>');110 }111 112 function ProcessEmailQueue()113 {114 $Output = '';115 $DbResult = $this->Database->select('EmailQueue', '*', 'Archive=0');116 while($DbRow = $DbResult->fetch_assoc())117 {118 $this->MailUTF8($DbRow['Address'], $DbRow['Subject'], $DbRow['Content'], $DbRow['Headers']);119 //echo('mail('.$DbRow['Address'].', '.$DbRow['Subject'].', '.$DbRow['Content'].', FromUTF8('.$DbRow['Headers'].', \'iso2\'));');120 $this->Database->update('EmailQueue', 'Id='.$DbRow['Id'], array('Archive' => 1));121 $this->Modules['Log']->NewRecord('System', 'SendEmail', $DbRow['Id']);122 $Output .= 'To: '.$DbRow['Address'].' Subject: '.$DbRow['Subject'].'<br />';123 }124 return($Output);125 }126 127 31 function HumanDate($Time) 128 32 { 129 33 return(date('j.n.Y', $Time)); 130 }131 132 function TruncateDigits($Value, $Digits = 4)133 {134 for($II = 2; $II > -6; $II--)135 {136 if($Value >= pow(10, $II))137 {138 if($Digits < ($II + 1)) $RealDigits = $II + 1; else $RealDigits = $Digits;139 $Value = round($Value / pow(10, $II - $RealDigits + 1)) * pow(10, $II - $RealDigits + 1);140 break;141 }142 }143 return($Value);144 }145 146 function AddPrefixMultipliers($Value, $Unit, $Digits = 4, $PrefixType = 'Decimal')147 {148 global $PrefixMultipliers;149 150 $Negative = ($Value < 0);151 $Value = abs($Value);152 if(($Unit == '') and ($PrefixType != 'Time'))153 return($this->TruncateDigits($Value, $Digits));154 155 $I = $PrefixMultipliers[$PrefixType]['BaseIndex'];156 if($Value == 0) return($Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit);157 158 if($Value > 1)159 {160 while((($I + 1) <= count($PrefixMultipliers[$PrefixType]['Definition'])) and (($Value / $PrefixMultipliers[$PrefixType]['Definition'][$I + 1][2]) > 1))161 $I = $I + 1;162 } else163 if($Value < 1)164 {165 while((($I - 1) >= 0) and (($Value / $PrefixMultipliers[$PrefixType]['Definition'][$I][2]) < 1))166 $I = $I - 1;167 }168 $Value = $Value / $PrefixMultipliers[$PrefixType]['Definition'][$I][2];169 170 // Truncate digits count171 $Value = $this->TruncateDigits($Value, $Digits);172 if($Negative) $Value = -$Value;173 return($Value.' '.$PrefixMultipliers[$PrefixType]['Definition'][$I][0].$Unit);174 34 } 175 35 -
trunk/Common/Model.php
r370 r373 147 147 function Install() 148 148 { 149 $this->Database->insert('SystemModel', array('Name' => $this->Name, 'Module' => $this->Module->Id)); 150 $this->Id = $this->Database->insert_id; 151 149 152 $Query = 'CREATE TABLE IF NOT EXISTS `'.$this->Name.'` ('. 150 153 '`Id` int(11) NOT NULL AUTO_INCREMENT,'; 151 154 foreach($this->Properties as $Property) 152 155 { 156 $this->Database->insert('SystemModelProperty', array('Name' => $Property['Name'], 157 'Model' => $this->Id, 'Type' => $Property['Type'])); 153 158 if($Property['Type'] == PropertyDateTime) 154 159 $Query .= '`'.$Property['Name'].'` DATETIME NOT NULL,'; … … 159 164 else if($Property['Type'] == PropertyString) 160 165 $Query .= '`'.$Property['Name'].'` VARCHAR(255) COLLATE utf8_general_ci NOT NULL,'; 161 else if($Property['Type'] == PropertyText) 166 else if($Property['Type'] == PropertyText8) 167 $Query .= '`'.$Property['Name'].'` TINYTEXT COLLATE utf8_general_ci NOT NULL,'; 168 else if($Property['Type'] == PropertyText16) 162 169 $Query .= '`'.$Property['Name'].'` TEXT COLLATE utf8_general_ci NOT NULL,'; 163 else if($Property['Type'] == PropertyInteger) 170 else if($Property['Type'] == PropertyText24) 171 $Query .= '`'.$Property['Name'].'` MEDIUMTEXT COLLATE utf8_general_ci NOT NULL,'; 172 else if($Property['Type'] == PropertyText32) 173 $Query .= '`'.$Property['Name'].'` LONGTEXT COLLATE utf8_general_ci NOT NULL,'; 174 else if($Property['Type'] == PropertyInteger8) 175 $Query .= '`'.$Property['Name'].'` TINYINT(4) NOT NULL,'; 176 else if($Property['Type'] == PropertyInteger16) 177 $Query .= '`'.$Property['Name'].'` SMALLINT(6) NOT NULL,'; 178 else if($Property['Type'] == PropertyInteger24) 179 $Query .= '`'.$Property['Name'].'` MEDIUMINT(9) NOT NULL,'; 180 else if($Property['Type'] == PropertyInteger32) 164 181 $Query .= '`'.$Property['Name'].'` INT(11) NOT NULL,'; 182 else if($Property['Type'] == PropertyInteger64) 183 $Query .= '`'.$Property['Name'].'` BIGINT(20) NOT NULL,'; 165 184 else if($Property['Type'] == PropertyBoolean) 166 $Query .= '`'.$Property['Name'].'` INT(11)NOT NULL,';185 $Query .= '`'.$Property['Name'].'` BOOLEAN NOT NULL,'; 167 186 else if($Property['Type'] == PropertyFloat) 168 187 $Query .= '`'.$Property['Name'].'` FLOAT NOT NULL,'; 188 else if($Property['Type'] == PropertyDouble) 189 $Query .= '`'.$Property['Name'].'` DOUBLE NOT NULL,'; 169 190 else if($Property['Type'] == PropertyOneToMany) 170 191 $Query .= '`'.$Property['Name'].'` INT(255) NOT NULL,'. -
trunk/Common/Module.php
r366 r373 28 28 { 29 29 $Model = new $ModelName($this->Database, $this->System); 30 $Model->Module = &$this; 30 31 $Model->Install(); 31 32 unset($Model); 32 33 } 33 $this->Database->query('UPDATE Module SET Installed=1 WHERE Name="'.$this->Name.'"');34 $this->Database->query('UPDATE SystemModule SET Installed=1 WHERE Name="'.$this->Name.'"'); 34 35 } 35 36 … … 43 44 unset($Model); 44 45 } 45 $this->Database->query('UPDATE Module SET Installed=0 WHERE Name="'.$this->Name.'"');46 $this->Database->query('UPDATE SystemModule SET Installed=0 WHERE Name="'.$this->Name.'"'); 46 47 } 47 48 … … 69 70 function Init($Installed = true) 70 71 { 71 $Query = 'SELECT Name FROM `Module`';72 $Query = 'SELECT `Id`, `Name` FROM `SystemModule`'; 72 73 if($Installed) $Query .= ' WHERE `Installed`=1'; 73 74 else $Query .= ' WHERE `Installed`=0'; … … 78 79 $ModuleClassName = 'Module'.$Module['Name']; 79 80 $this->Modules[$Module['Name']] = new $ModuleClassName($this->Database, $this); 81 $this->Modules[$Module['Name']]->Id = $Module['Id']; 80 82 $this->Modules[$Module['Name']]->Init(); 81 83 } … … 85 87 { 86 88 //DebugLog('Installing modular system core...'); 87 $this->Database->query('CREATE TABLE IF NOT EXISTS ` Module` (89 $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModule` ( 88 90 `Id` int(11) NOT NULL AUTO_INCREMENT, 89 91 `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL, … … 94 96 `Description` text COLLATE utf8_czech_ci NOT NULL, 95 97 `Dependecies` varchar(255) COLLATE utf8_czech_ci NOT NULL, 98 PRIMARY KEY (`Id`) 99 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;'); 100 $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModel` ( 101 `Id` int(11) NOT NULL AUTO_INCREMENT, 102 `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL, 103 `Module` int(11) NOT NULL, 104 KEY (`Module`), 105 PRIMARY KEY (`Id`) 106 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;'); 107 $this->Database->query('CREATE TABLE IF NOT EXISTS `SystemModelProperty` ( 108 `Id` int(11) NOT NULL AUTO_INCREMENT, 109 `Name` varchar(255) COLLATE utf8_czech_ci NOT NULL, 110 `Type` varchar(255) COLLATE utf8_czech_ci NOT NULL, 111 `Model` int(11) NOT NULL, 112 KEY (`Model`), 96 113 PRIMARY KEY (`Id`) 97 114 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1;'); … … 109 126 foreach($this->Modules as $Index => $Module) 110 127 $this->Modules[$Index]->UnInstall(); 111 $this->Database->query('DROP TABLE IF EXISTS `Module`'); 128 129 // Delete tables with reverse order 130 $this->Database->query('DROP TABLE IF EXISTS `SystemModelProperty`'); 131 $this->Database->query('DROP TABLE IF EXISTS `SystemModel`'); 132 $this->Database->query('DROP TABLE IF EXISTS `SystemModule`'); 112 133 } 113 134 … … 116 137 // Load list of modules from database 117 138 $Modules = array(); 118 $DbResult = $this->Database->query('SELECT * FROM ` Module`');139 $DbResult = $this->Database->query('SELECT * FROM `SystemModule`'); 119 140 while($DbRow = $DbResult->fetch_assoc()) 120 141 $Modules[$DbRow['Name']] = $DbRow; … … 139 160 { 140 161 $Module = new $ModuleClassName($this->Database, $this); 141 $this->Database->insert(' Module', array('Name' => $Module->Name,162 $this->Database->insert('SystemModule', array('Name' => $Module->Name, 142 163 'Version' => $Module->Version, 'Creator' => $Module->Creator, 143 164 'Description' => $Module->Description, 'License' => $Module->License, … … 152 173 { 153 174 DebugLog('Removing module '.$Module['Name'].' from list'); 154 $this->Database->query('DELETE FROM ` Module` WHERE `Id` = '.$Module['Id']);175 $this->Database->query('DELETE FROM `SystemModule` WHERE `Id` = '.$Module['Id']); 155 176 } 156 177 } -
trunk/Common/View.php
r372 r373 19 19 define('ViewItemTypeURL', 'URL'); 20 20 define('ViewItemTypeImage', 'Image'); 21 define('ViewItemTypeEnumeration', 'Enumeration'); 21 22 22 class View 23 class View 23 24 { 25 var $Database; 24 26 var $Name; 25 27 var $Title; 26 28 var $Items; 27 29 var $ModelName; 28 var $SubmitText; 29 var $Values = array(); 30 var $OnSubmit = ''; 31 var $Database; 32 30 33 31 function __construct($Database) 34 32 { … … 36 34 } 37 35 38 function AddItemOneToMany($Name, $Title, $TargetModel, $Default)39 {40 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeOneToMany, 'Default' => $Default,41 'TargetModel' => $TargetModel);42 }43 44 function AddItemManyToOne($Name, $Title, $TargetModel, $Default)45 {46 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeManyToOne, 'Default' => $Default,47 'TargetModel' => $TargetModel);48 }49 50 function AddItemInteger($Name, $Title, $Default)51 {52 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeInteger, 'Default' => $Default);53 }54 55 function AddItemFloat($Name, $Title, $Default)56 {57 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeFloat, 'Default' => $Default);58 }59 60 function AddItemText($Name, $Title, $Default)61 {62 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeText, 'Default' => $Default);63 }64 65 function AddItemString($Name, $Title, $Default)66 {67 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeString, 'Default' => $Default);68 }69 70 function AddItemBoolean($Name, $Title, $Default)71 {72 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeBoolean, 'Default' => $Default);73 }74 75 function AddItemDate($Name, $Title, $Default)76 {77 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeDate, 'Default' => $Default);78 }79 80 function AddItemTime($Name, $Title, $Default)81 {82 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeTime, 'Default' => $Default);83 }84 85 function AddItemDateTime($Name, $Title, $Default)86 {87 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeDateTime, 'Default' => $Default);88 }89 90 function AddItemIPv4($Name, $Title, $Default)91 {92 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeIPv4, 'Default' => $Default);93 }94 95 function AddItemIPv6($Name, $Title, $Default)96 {97 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeIPv6, 'Default' => $Default);98 }99 100 function AddItemMACAddress($Name, $Title, $Default)101 {102 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeMACAddress, 'Default' => $Default);103 }104 105 function AddItemFileName($Name, $Title, $Default)106 {107 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeFileName, 'Default' => $Default);108 }109 110 function AddItemURL($Name, $Title, $Default)111 {112 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeURL, 'Default' => $Default);113 }114 115 function AddItemPassword($Name, $Title, $Default)116 {117 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypePassword, 'Default' => $Default);118 }119 120 function AddItemImage($Name, $Title, $Default)121 {122 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeImage, 'Default' => $Default);123 }124 125 function ShowEditForm()126 {127 if($this->SubmitText == '') $this->SubmitText = 'Uložit';128 $Output = '<form class="Form" action="'.$this->OnSubmit.'" method="post">'.$this->ShowEditBlock().'<div><input type="submit" value="'.$this->SubmitText.'" /></div></form>';129 return($Output);130 }131 132 function ShowEditBlock($Context = '')133 {134 $Table = array(135 //'Header' => array('Položka', 'Hodnota'),136 'Rows' => array(),137 );138 if($Context != '') $Context = $Context.'-';139 foreach($this->Items as $Index => $Item)140 {141 if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default'];142 switch($Item['Type'])143 {144 case ViewItemTypeBoolean:145 if($this->Values[$Index] == 0) $Checked = ''; else $Checked = ' CHECKED';146 $Edit = '<input type="checkbox" name="'.$Context.$Index.'"'.$Checked.' />';147 break;148 case ViewItemTypeString:149 $Edit = '<input style="width: 98%;" type="text" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />';150 break;151 case ViewItemTypeText:152 $Edit = '<textarea style="width: 98%; height: 200px;" name="'.$Context.$Index.'">'.$this->Values[$Index].'</textarea>';153 break;154 case ViewItemTypePassword:155 $Edit = '<input style="width: 98%;" type="password" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />';156 break;157 case ViewItemTypeInteger:158 $Edit = '<input style="width: 98%;" type="text" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />';159 break;160 case ViewItemTypeFloat:161 $Edit = '<input style="width: 98%;" type="text" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />';162 break;163 case ViewItemTypeTime:164 if($this->Values[$Index] == 'Now') $this->Values[$Index] = date('j.n.Y');165 $Edit = '<input style="width: 98%;" type="text" name="'.$Context.$Index.'" value="'.$this->Values[$Index].'" />';166 break;167 case ViewItemTypeOneToMany:168 $Edit = '<select style="width: 100%;" name="'.$Context.$Index.'">';169 $DbResult = $this->Database->select($Item['TargetModel'], 'Id, Name', '1 ORDER BY Name');170 while($Row = $DbResult->fetch_assoc())171 {172 if($Row['Id'] == $this->Values[$Index]) $Selected = ' selected="selected"';173 else $Selected = '';174 $Edit .= '<option value="'.$Row['Id'].'"'.$Selected.'>'.$Row['Id'].': '.$Row['Name'].'</option>';175 }176 $Edit .= '</select>';177 break;178 case 'Array':179 $Form = new Form($Item['ItemClass']);180 $Edit = '<script type="text/javascript" id="syndication">'.181 "var Count = 0;".182 "function AddItem() {".183 "Count = Count + 1;".184 "var newcontent = document.createElement('div');".185 "newcontent.id = '".$Context.$Item['ItemClass']."-' + Count;".186 "newcontent.innerHTML = '<input type=\"hidden\" name=\"".$Context.$Item['ItemClass']."-' + Count + '\">".$Form->ShowEditBlock($Context.$Item['ItemClass']."-' + Count + '")."';".187 "var scr = document.getElementById('syndication');".188 "scr.parentNode.insertBefore(newcontent, scr); }".189 '</script>';190 $Edit .= '<form><input type="button" onclick="AddItem();" value="Přidat položku" /></form>';191 break;192 default:193 if(array_key_exists($Item['Type'], $FormTypes))194 {195 // Custom types196 switch($FormTypes[$Item['Type']]['Type'])197 {198 case 'Enumeration':199 $Edit = '<select style="width: 100%;" name="'.$Context.$Index.'">';200 foreach($FormTypes[$Item['Type']]['States'] as $StateIndex => $StateName)201 {202 if($this->Values[$Index] == $StateIndex) $Selected = 'selected="selected"';203 else $Selected = '';204 $Edit .= '<option value="'.$StateIndex.'"'.$Selected.'>'.$StateName.'</option>';205 }206 $Edit .= '</select>';207 break;208 default:209 $Edit = 'Neznámý typ';210 }211 } else $Edit = 'Neznámý typ';212 }213 array_push($Table['Rows'], array($Item['Title'].':', $Edit));214 }215 $Output = '<fieldset><legend>'.$this->Title.'</legend>'.Table($Table).216 '</fieldset>';217 return($Output);218 }219 220 function LoadValuesFromDatabase($Id)221 {222 $DbResult = $this->Database->query('SELECT T.* FROM '.$this->ModelName.' AS T WHERE T.Id='.$Id);223 $DbRow = $DbResult->fetch_array();224 foreach($this->Items as $Index => $Item)225 {226 $this->Values[$Index] = $DbRow[$Index];227 switch($Item['Type'])228 {229 case ViewItemTypePassword:230 if($Item['Type'] == ViewItemTypePassword) $this->Values[$Index] = ''; // Dont show password231 break;232 case ViewItemTypeTime:233 $this->Values[$Index] == MysqlDateTimeToTime($this->Values[$Index]);234 break;235 }236 }237 }238 239 function SaveValuesToDatabase($Id)240 {241 foreach($this->Items as $Index => $Item)242 {243 switch($Item['Type'])244 {245 case ViewItemTypePassword:246 if($this->Values[$Index] == '') unset($this->Values[$Index]); // Do not modify empty passwords247 else $this->Values[$Index] = sha1($this->Values[$Index]);248 break;249 case ViewItemTypeTime:250 $this->Values[$Index] = TimeToMysqlDateTime($this->Values[$Index]);251 break;252 }253 }254 if($Id == 0)255 {256 $this->Values['Id'] = $Id;257 $DbResult = $this->Database->replace($this->ModelName, $this->Values);258 } else259 $DbResult = $this->Database->update($this->ModelName, 'Id='.$Id, $this->Values);260 //echo($this->Database->LastQuery);261 }262 263 function LoadValuesFromForm()264 {265 $this->Values = $this->LoadValuesFromFormBlock();266 }267 268 function LoadValuesFromFormBlock($Context = '')269 {270 if($Context != '') $Context = $Context.'-';271 $Values = array();272 foreach($this->Items as $Index => $Item)273 {274 if(array_key_exists($Context.$Index, $_POST))275 switch($Item['Type'])276 {277 case ViewItemTypeBoolean:278 if(array_key_exists($Context.$Index, $_POST)) $Values[$Index] = 1;279 else $Values[$Index] = 0;280 break;281 case ViewItemTypeString:282 $Values[$Index] = $_POST[$Context.$Index];283 break;284 case ViewItemTypeText:285 $Values[$Index] = $_POST[$Context.$Index];286 break;287 case ViewItemTypePassword:288 $Values[$Index] = $_POST[$Context.$Index];289 break;290 case ViewItemTypeInteger:291 $Values[$Index] = $_POST[$Context.$Index];292 break;293 case ViewItemTypeFloat:294 $Values[$Index] = $_POST[$Context.$Index];295 break;296 case ViewItemTypeTime:297 $Values[$Index] = explode('.', $_POST[$Context.$Index]);298 $Values[$Index] = mktime(0, 0, 0, $Values[$Index][1], $Values[$Index][0], $Values[$Index][2]);299 break;300 case 'Array':301 $I = 1;302 //echo('Expect: '.$Context.$Item['ItemClass'].'-'.$I.'<br />');303 while(isset($_POST[$Context.$Item['ItemClass'].'-'.$I]))304 {305 $Form = new Form($Item['ItemClass']);306 $Values[$Index][] = $Form->LoadValuesFromFormBlock($Context.$Item['ItemClass'].'-'.$I);307 $I++;308 }309 break;310 default:311 if(array_key_exists($Item['Type'], $FormTypes))312 {313 // Custom types314 switch($FormTypes[$Item['Type']]['Type'])315 {316 case 'Enumeration':317 $Values[$Index] = $_POST[$Context.$Index];318 break;319 case 'Reference':320 $Values[$Index] = $_POST[$Context.$Index];321 break;322 default:323 }324 }325 }326 }327 return($Values);328 }329 }330 331 function MakeLink($Target, $Title)332 {333 return('<a href="'.$Target.'">'.$Title.'</a>');334 }335 336 function Table($Table)337 {338 $Result = '<table class="BasicTable">';339 if(array_key_exists('Header', $Table))340 {341 $Result .= '<tr>';342 foreach($Table['Header'] as $Item)343 $Result .= '<th>'.$Item.'</th>';344 $Result .= '</tr>';345 }346 foreach($Table['Rows'] as $Row)347 {348 $Result .= '<tr>';349 foreach($Row as $Index => $Item)350 {351 if($Index == 0) $Class = ' class="Header"'; else $Class = '';352 $Result .= '<td'.$Class.' style="width: '.(floor(100 / count($Row))).'%">'.$Item.'</td>';353 }354 $Result .= '</tr>';355 }356 $Result .= '</table>';357 return($Result);358 }359 360 function ShowEditTable($ClassName, $Values)361 {362 36 } 363 37 -
trunk/Common/ViewForm.php
r372 r373 1 1 <?php 2 2 3 define('ViewItemTypeDate', 'Date'); 4 define('ViewItemTypeTime', 'Time'); 5 define('ViewItemTypeDateTime', 'DateTime'); 6 define('ViewItemTypeText', 'Text'); 7 define('ViewItemTypeString', 'String'); 8 define('ViewItemTypeBoolean', 'Boolean'); 9 define('ViewItemTypeInteger', 'Integer'); 10 define('ViewItemTypeFloat', 'Float'); 11 define('ViewItemTypeOneToMany', 'OneToMany'); 12 define('ViewItemTypeManyToOne', 'ManyToOne'); 13 define('ViewItemTypeManyToMany', 'ManyToMany'); 14 define('ViewItemTypeIPv4', 'IPv4'); 15 define('ViewItemTypeIPv6', 'IPv6'); 16 define('ViewItemTypeMACAddrees', 'MACAddress'); 17 define('ViewItemTypeFileName', 'FileName'); 18 define('ViewItemTypePassword', 'Password'); 19 define('ViewItemTypeURL', 'URL'); 20 define('ViewItemTypeImage', 'Image'); 21 22 class View 3 class ViewForm extends View 23 4 { 24 var $Name;25 var $Title;26 var $Items;27 var $ModelName;28 5 var $SubmitText; 29 6 var $Values = array(); 30 7 var $OnSubmit = ''; 31 var $Database;32 8 33 9 function __construct($Database) … … 38 14 function AddItemOneToMany($Name, $Title, $TargetModel, $Default) 39 15 { 40 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeOneToMany, 'Default' => $Default, 16 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 17 'Type' => ViewItemTypeOneToMany, 'Default' => $Default, 41 18 'TargetModel' => $TargetModel); 42 19 } … … 44 21 function AddItemManyToOne($Name, $Title, $TargetModel, $Default) 45 22 { 46 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeManyToOne, 'Default' => $Default, 23 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 24 'Type' => ViewItemTypeManyToOne, 'Default' => $Default, 47 25 'TargetModel' => $TargetModel); 48 26 } … … 50 28 function AddItemInteger($Name, $Title, $Default) 51 29 { 52 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeInteger, 'Default' => $Default); 30 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 31 'Type' => ViewItemTypeInteger, 'Default' => $Default); 53 32 } 54 33 55 34 function AddItemFloat($Name, $Title, $Default) 56 35 { 57 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeFloat, 'Default' => $Default); 36 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 37 'Type' => ViewItemTypeFloat, 'Default' => $Default); 58 38 } 59 39 60 40 function AddItemText($Name, $Title, $Default) 61 41 { 62 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeText, 'Default' => $Default); 42 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 43 'Type' => ViewItemTypeText, 'Default' => $Default); 63 44 } 64 45 65 46 function AddItemString($Name, $Title, $Default) 66 47 { 67 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeString, 'Default' => $Default); 48 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 49 'Type' => ViewItemTypeString, 'Default' => $Default); 68 50 } 69 51 70 52 function AddItemBoolean($Name, $Title, $Default) 71 53 { 72 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeBoolean, 'Default' => $Default); 54 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 55 'Type' => ViewItemTypeBoolean, 'Default' => $Default); 73 56 } 74 57 75 58 function AddItemDate($Name, $Title, $Default) 76 59 { 77 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeDate, 'Default' => $Default); 60 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 61 'Type' => ViewItemTypeDate, 'Default' => $Default); 78 62 } 79 63 80 64 function AddItemTime($Name, $Title, $Default) 81 65 { 82 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeTime, 'Default' => $Default); 66 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 67 'Type' => ViewItemTypeTime, 'Default' => $Default); 83 68 } 84 69 85 70 function AddItemDateTime($Name, $Title, $Default) 86 71 { 87 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeDateTime, 'Default' => $Default); 72 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 73 'Type' => ViewItemTypeDateTime, 'Default' => $Default); 88 74 } 89 75 90 76 function AddItemIPv4($Name, $Title, $Default) 91 77 { 92 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeIPv4, 'Default' => $Default); 78 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 79 'Type' => ViewItemTypeIPv4, 'Default' => $Default); 93 80 } 94 81 95 82 function AddItemIPv6($Name, $Title, $Default) 96 83 { 97 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeIPv6, 'Default' => $Default); 84 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 85 'Type' => ViewItemTypeIPv6, 'Default' => $Default); 98 86 } 99 87 100 88 function AddItemMACAddress($Name, $Title, $Default) 101 89 { 102 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeMACAddress, 'Default' => $Default); 90 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 91 'Type' => ViewItemTypeMACAddress, 'Default' => $Default); 103 92 } 104 93 105 94 function AddItemFileName($Name, $Title, $Default) 106 95 { 107 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeFileName, 'Default' => $Default); 96 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 97 'Type' => ViewItemTypeFileName, 'Default' => $Default); 108 98 } 109 99 110 100 function AddItemURL($Name, $Title, $Default) 111 101 { 112 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeURL, 'Default' => $Default); 102 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 103 'Type' => ViewItemTypeURL, 'Default' => $Default); 113 104 } 114 105 115 106 function AddItemPassword($Name, $Title, $Default) 116 107 { 117 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypePassword, 'Default' => $Default); 108 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 109 'Type' => ViewItemTypePassword, 'Default' => $Default); 118 110 } 119 111 120 112 function AddItemImage($Name, $Title, $Default) 121 113 { 122 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 'Type' => ViewItemTypeImage, 'Default' => $Default); 114 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 115 'Type' => ViewItemTypeImage, 'Default' => $Default); 123 116 } 124 117 118 function AddItemEnumeration($Name, $Title, $Default, $States) 119 { 120 $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title, 121 'Type' => ViewItemTypeEnumeration, 'Default' => $Default, 'States' => $States); 122 } 123 125 124 function ShowEditForm() 126 125 { … … 173 172 else $Selected = ''; 174 173 $Edit .= '<option value="'.$Row['Id'].'"'.$Selected.'>'.$Row['Id'].': '.$Row['Name'].'</option>'; 174 } 175 $Edit .= '</select>'; 176 break; 177 case ViewItemTypeEnumeration: 178 $Edit = '<select style="width: 100%;" name="'.$Context.$Index.'">'; 179 foreach($Item['States'] as $StateIndex => $StateName) 180 { 181 if($this->Values[$Index] == $StateIndex) $Selected = 'selected="selected"'; 182 else $Selected = ''; 183 $Edit .= '<option value="'.$StateIndex.'"'.$Selected.'>'.$StateName.'</option>'; 175 184 } 176 185 $Edit .= '</select>'; … … 191 200 break; 192 201 default: 193 if(array_key_exists($Item['Type'], $FormTypes)) 194 { 195 // Custom types 196 switch($FormTypes[$Item['Type']]['Type']) 197 { 198 case 'Enumeration': 199 $Edit = '<select style="width: 100%;" name="'.$Context.$Index.'">'; 200 foreach($FormTypes[$Item['Type']]['States'] as $StateIndex => $StateName) 201 { 202 if($this->Values[$Index] == $StateIndex) $Selected = 'selected="selected"'; 203 else $Selected = ''; 204 $Edit .= '<option value="'.$StateIndex.'"'.$Selected.'>'.$StateName.'</option>'; 205 } 206 $Edit .= '</select>'; 207 break; 208 default: 209 $Edit = 'Neznámý typ'; 210 } 211 } else $Edit = 'Neznámý typ'; 202 $Edit = 'Neznámý typ'; 212 203 } 213 204 array_push($Table['Rows'], array($Item['Title'].':', $Edit)); … … 297 288 $Values[$Index] = explode('.', $_POST[$Context.$Index]); 298 289 $Values[$Index] = mktime(0, 0, 0, $Values[$Index][1], $Values[$Index][0], $Values[$Index][2]); 299 break; 290 break; 291 case ViewItemTypeOneToMany: 292 $Values[$Index] = $_POST[$Context.$Index]; 293 break; 294 case ViewItemTypeEnumeration: 295 $Values[$Index] = $_POST[$Context.$Index]; 296 break; 300 297 case 'Array': 301 298 $I = 1; … … 309 306 break; 310 307 default: 311 if(array_key_exists($Item['Type'], $FormTypes))312 {313 // Custom types314 switch($FormTypes[$Item['Type']]['Type'])315 {316 case 'Enumeration':317 $Values[$Index] = $_POST[$Context.$Index];318 break;319 case 'Reference':320 $Values[$Index] = $_POST[$Context.$Index];321 break;322 default:323 }324 }325 308 } 326 309 } -
trunk/Modules/Finance/Finance.php
r370 r373 166 166 } 167 167 168 class FinanceOperationView extends View 169 { 170 function __construct() 171 { 168 class FinanceOperationView extends ViewForm 169 { 170 function __construct($Database) 171 { 172 parent::__construct($Database); 172 173 $this->Name = 'FinanceOperation'; 173 174 $this->Title = 'Platba'; … … 183 184 } 184 185 185 class FinanceClaimsLiabilitiesView extends View 186 { 187 function __construct() 188 { 186 class FinanceClaimsLiabilitiesView extends ViewForm 187 { 188 function __construct($Database) 189 { 190 parent::__construct($Database); 189 191 $this->Name = 'FinanceClaimsLiabilities'; 190 192 $this->Title = 'Faktura'; -
trunk/Modules/Log/Log.php
r369 r373 1 1 <?php 2 2 3 include_once('Common/ rss_generator.php');3 include_once('Common/RSS.php'); 4 4 5 5 class LogShow extends Page -
trunk/Modules/Member/Member.php
r372 r373 1 1 <?php 2 2 3 class MemberOptionsView extends View 3 class MemberOptionsView extends ViewForm 4 4 { 5 5 function __construct($Database) … … 11 11 $this->AddItemString('AddressStreet', 'Ulice', ''); 12 12 $this->AddItemString('AddressTown', 'Město', ''); 13 $this->AddItemString(' PSC', 'PSČ', '');13 $this->AddItemString('AddressPSC', 'PSČ', ''); 14 14 $this->AddItemString('IC', 'IČ', ''); 15 15 $this->AddItemString('DIC', 'DIČ', ''); -
trunk/Modules/Network/Network.php
r372 r373 154 154 } 155 155 156 class EmailView extends View 156 class EmailView extends ViewForm 157 157 { 158 158 function __construct($Database) -
trunk/Modules/News/News.php
r370 r373 70 70 } 71 71 72 class NewsView extends View 73 { 74 function __construct() 75 { 72 class NewsView extends ViewForm 73 { 74 function __construct($Database) 75 { 76 parent::__construct($Database); 76 77 $this->Name = 'News'; 77 78 $this->Title = 'Nová aktualita'; 78 79 $this->SubmitText = 'Vložit'; 79 AddItemOneToMany('Category', 'Kategorie', 'NewsGroup', '0');80 AddItemString('Title', 'Nadpis', '');81 AddItemText('Content', 'Obsah', '');82 AddItemFileName('Enclosure1', 'Přílohy (Max. velikost souboru 1 MB)', '');83 AddItemFileName('Enclosure2', '', '');84 AddItemFileName('Enclosure3', '', '');80 $this->AddItemOneToMany('Category', 'Kategorie', 'NewsGroup', '0'); 81 $this->AddItemString('Title', 'Nadpis', ''); 82 $this->AddItemText('Content', 'Obsah', ''); 83 $this->AddItemFileName('Enclosure1', 'Přílohy (Max. velikost souboru 1 MB)', ''); 84 $this->AddItemFileName('Enclosure2', '', ''); 85 $this->AddItemFileName('Enclosure3', '', ''); 85 86 } 86 87 } -
trunk/Modules/News/NewsPage.php
r358 r373 1 1 <?php 2 2 3 include_once('Common/ rss_generator.php');3 include_once('Common/RSS.php'); 4 4 5 5 class NewsPage extends Page -
trunk/Modules/Subject/Subject.php
r371 r373 10 10 $this->AddPropertyString('AddressStreet'); 11 11 $this->AddPropertyString('AddressTown'); 12 $this->AddPropertyInteger(' PSC');12 $this->AddPropertyInteger('AddressPSC'); 13 13 $this->AddPropertyString('Country'); 14 14 $this->AddPropertyString('IC'); -
trunk/Modules/TimeMeasure/TimeMeasure.php
r370 r373 1 1 <?php 2 2 3 class MeasureView extends View 3 class MeasureView extends ViewForm 4 4 { 5 function __construct( )5 function __construct($Database) 6 6 { 7 parent::__construct($Database); 7 8 $this->Name = 'Measure'; 8 9 $this->Title = 'Časové měření'; -
trunk/Modules/User/User.php
r372 r373 321 321 } 322 322 323 class UserOptionsView extends View 323 class UserOptionsView extends ViewForm 324 324 { 325 325 function __construct($Database) … … 338 338 } 339 339 340 class UserRegisterView extends View 340 class UserRegisterView extends ViewForm 341 341 { 342 342 function __construct($Database) … … 357 357 } 358 358 359 class PasswordRecoveryView extends View 359 class PasswordRecoveryView extends ViewForm 360 360 { 361 361 function __construct($Database) … … 370 370 } 371 371 372 class UserLoginView extends View 372 class UserLoginView extends ViewForm 373 373 { 374 374 function __construct($Database)
Note:
See TracChangeset
for help on using the changeset viewer.