Changeset 501 for trunk/Common/Form/Form.php
- Timestamp:
- Mar 10, 2013, 8:15:46 PM (12 years ago)
- Location:
- trunk/Common/Form
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/Form/Form.php
r500 r501 1 1 <?php 2 2 3 include_once(dirname(__FILE__).'/../ form_classes.php');4 include_once(dirname(__FILE__).'/ Database.php');3 include_once(dirname(__FILE__).'/../Database.php'); 4 include_once(dirname(__FILE__).'/Types/Type.php'); 5 5 6 6 class Form 7 7 { 8 var $Definition = array(); 9 var $Values = array(); 10 var $OnSubmit = ''; 11 12 function __construct($ClassName) 13 { 14 global $FormClasses; 15 16 $this->Definition = &$FormClasses[$ClassName]; 17 } 8 var $FormManager; 9 var $Definition; 10 var $Values; 11 var $OnSubmit; 12 var $Database; 13 14 function __construct($FormManager) 15 { 16 $this->FormManager = &$FormManager; 17 $this->Database = $FormManager->Database; 18 $this->Definition = array(); 19 $this->Values = array(); 20 $this->OnSubmit = ''; 21 } 22 23 function SetClass($Name) 24 { 25 $this->Definition = &$this->FormManager->Classes[$Name]; 26 } 18 27 19 28 function ShowViewForm() 20 29 { 21 global $Database, $FormTypes, $System;22 23 30 $Table = array( 24 31 //'Header' => array('Položka', 'Hodnota'), … … 26 33 ); 27 34 foreach($this->Definition['Items'] as $Index => $Item) 28 if(!array_key_exists($Item['Type'], $FormTypes) or 29 (array_key_exists($Item['Type'], $FormTypes) and ($FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 30 { 31 if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default']; 32 if(array_key_exists($Item['Type'], $FormTypes)) 33 { 34 if(!array_key_exists($Item['Type'], $System->Type->TypeDefinitionList)) 35 $System->Type->RegisterType($Item['Type'], '', $FormTypes[$Item['Type']]); 36 if($FormTypes[$Item['Type']]['Type'] == 'Reference') 37 $UseType = 'OneToMany'; 38 else if($FormTypes[$Item['Type']]['Type'] == 'Enumeration') 35 if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 36 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 37 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 38 { 39 if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default']; 40 if(array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 41 { 42 if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 43 $this->FormManager->Type->RegisterType($Item['Type'], '', $this->FormManager->FormTypes[$Item['Type']]); 44 if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference') 45 $UseType = 'OneToMany'; 46 else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration') 39 47 $UseType = 'Enumeration'; 40 48 } else $UseType = $Item['Type']; 41 $Edit = $ System->Type->ExecuteTypeEvent($UseType, 'OnView',49 $Edit = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnView', 42 50 array('Value' => $this->Values[$Index], 'Name' => $Index, 43 51 'Type' => $Item['Type'], 'Values' => $this->Values)); 44 52 if(array_key_exists('Suffix', $Item)) $Edit .= ' '.$Item['Suffix']; 45 if(!$ System->Type->IsHidden($UseType))53 if(!$this->FormManager->Type->IsHidden($UseType)) 46 54 array_push($Table['Rows'], array($Item['Caption'].':', $Edit)); 47 55 } … … 62 70 function ShowEditBlock($Context = '') 63 71 { 64 global $Database, $FormTypes, $System;65 66 72 $Hidden = ''; 67 73 $IsHidden = false; … … 75 81 if(!array_key_exists('ReadOnly', $Item)) $Item['ReadOnly'] = false; 76 82 if($Item['ReadOnly'] == false) 77 if(!array_key_exists($Item['Type'], $FormTypes) or 78 (array_key_exists($Item['Type'], $FormTypes) and ($FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 83 if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 84 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 85 ($$this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 79 86 { 80 87 if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default']; … … 84 91 else unset($Parameters['Null']); 85 92 86 if(array_key_exists($Item['Type'], $ FormTypes))87 { 88 if(!array_key_exists($Item['Type'], $ System->Type->TypeDefinitionList))89 $ System->Type->RegisterType($Item['Type'], '',90 $ FormTypes[$Item['Type']]);91 if($ FormTypes[$Item['Type']]['Type'] == 'Reference')93 if(array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 94 { 95 if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 96 $this->FormManager->Type->RegisterType($Item['Type'], '', 97 $this->FormManager->FormTypes[$Item['Type']]); 98 if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference') 92 99 { 93 100 $UseType = 'OneToMany'; 94 } else if($ FormTypes[$Item['Type']]['Type'] == 'Enumeration')95 $UseType = 'Enumeration'; 96 } else $UseType = $Item['Type']; 97 $Edit = $ System->Type->ExecuteTypeEvent($UseType, 'OnEdit', $Parameters);101 } else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration') 102 $UseType = 'Enumeration'; 103 } else $UseType = $Item['Type']; 104 $Edit = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnEdit', $Parameters); 98 105 if(array_key_exists('Suffix', $Item)) $Edit .= $Item['Suffix']; 99 106 100 if(!$ System->Type->IsHidden($UseType))107 if(!$this->FormManager->Type->IsHidden($UseType)) 101 108 array_push($Table['Rows'], array($Item['Caption'].':', $Edit)); 102 109 else $Hidden .= $Edit; … … 110 117 function LoadValuesFromDatabase($Id) 111 118 { 112 global $Database, $FormTypes, $System; 113 114 $DbResult = $Database->query('SELECT T.* FROM '.$this->Definition['Table'].' AS T WHERE T.Id='.$Id); 119 $DbResult = $this->Database->query('SELECT T.* FROM '.$this->Definition['Table'].' AS T WHERE T.Id='.$Id); 115 120 $DbRow = $DbResult->fetch_array(); 116 121 foreach($this->Definition['Items'] as $Index => $Item) 117 if(!array_key_exists($Item['Type'], $FormTypes) or 118 (array_key_exists($Item['Type'], $FormTypes) and ($FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 119 { 120 if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default']; 121 if(array_key_exists($Item['Type'], $FormTypes)) 122 { 123 if(!array_key_exists($Item['Type'], $System->Type->TypeDefinitionList)) 124 $System->Type->RegisterType($Item['Type'], '', 125 $FormTypes[$Item['Type']]); 126 if($FormTypes[$Item['Type']]['Type'] == 'Reference') 127 $UseType = 'OneToMany'; 128 else if($FormTypes[$Item['Type']]['Type'] == 'Enumeration') 129 $UseType = 'Enumeration'; 130 } else $UseType = $Item['Type']; 131 $this->Values[$Index] = $System->Type->ExecuteTypeEvent($UseType, 'OnLoadDb', 122 if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 123 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 124 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 125 { 126 if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default']; 127 if(array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 128 { 129 if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 130 $this->FormManager->Type->RegisterType($Item['Type'], '', 131 $this->FormManager->FormTypes[$Item['Type']]); 132 if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference') 133 $UseType = 'OneToMany'; 134 else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration') 135 $UseType = 'Enumeration'; 136 } else $UseType = $Item['Type']; 137 $this->Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoadDb', 132 138 array('Value' => $DbRow[$Index], 'Name' => $Index, 133 139 'Type' => $Item['Type'], 'Values' => $this->Values)); … … 139 145 function SaveValuesToDatabase($Id) 140 146 { 141 global $Database, $FormTypes, $System;142 143 147 $Values = array(); 144 148 foreach($this->Definition['Items'] as $Index => $Item) … … 146 150 if(!array_key_exists('ReadOnly', $Item)) $Item['ReadOnly'] = false; 147 151 if($Item['ReadOnly'] == false) 148 if(!array_key_exists($Item['Type'], $FormTypes) or 149 (array_key_exists($Item['Type'], $FormTypes) and ($FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 152 if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 153 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 154 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 150 155 { 151 156 if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default']; … … 153 158 'Type' => $Item['Type'], 'Values' => $this->Values); 154 159 155 if(array_key_exists($Item['Type'], $ FormTypes))156 { 157 if(!array_key_exists($Item['Type'], $ System->Type->TypeDefinitionList))158 $ System->Type->RegisterType($Item['Type'], '',159 $ FormTypes[$Item['Type']]);160 if($ FormTypes[$Item['Type']]['Type'] == 'Reference')160 if(array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 161 { 162 if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 163 $this->FormManager->Type->RegisterType($Item['Type'], '', 164 $this->FormManager->FormTypes[$Item['Type']]); 165 if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference') 161 166 { 162 167 $UseType = 'OneToMany'; 163 168 } 164 else if($ FormTypes[$Item['Type']]['Type'] == 'Enumeration')165 $UseType = 'Enumeration'; 166 } else $UseType = $Item['Type']; 167 $Values[$Index] = $ System->Type->ExecuteTypeEvent($UseType, 'OnSaveDb', $Parameters);169 else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration') 170 $UseType = 'Enumeration'; 171 } else $UseType = $Item['Type']; 172 $Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnSaveDb', $Parameters); 168 173 if(($Item['Type'] == 'Password') and ($Values[$Index] == '')) unset($Values[$Index]); 169 174 … … 174 179 { 175 180 $Values['Id'] = $Id; 176 $DbResult = $ Database->insert($this->Definition['Table'], $Values);181 $DbResult = $this->Database->insert($this->Definition['Table'], $Values); 177 182 } else 178 $DbResult = $ Database->update($this->Definition['Table'], 'Id='.$Id, $Values);183 $DbResult = $this->Database->update($this->Definition['Table'], 'Id='.$Id, $Values); 179 184 //echo($Database->LastQuery); 180 185 } … … 187 192 function LoadValuesFromFormBlock($Context = '') 188 193 { 189 global $Database, $FormTypes, $System;190 191 194 if($Context != '') $Context = $Context.'-'; 192 195 $Values = array(); 193 196 foreach($this->Definition['Items'] as $Index => $Item) 194 if((!array_key_exists($Item['Type'], $ FormTypes) or195 (array_key_exists($Item['Type'], $ FormTypes) and196 ($ FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) and197 if((!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 198 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 199 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) and 197 200 (!array_key_exists('ReadOnly', $Item) or 198 201 (array_key_exists('ReadOnly', $Item) and … … 200 203 { 201 204 //if(array_key_exists($Context.$Index, $_POST)) 202 if(array_key_exists($Item['Type'], $ FormTypes))203 { 204 if(!array_key_exists($Item['Type'], $ System->Type->TypeDefinitionList))205 $ System->Type->RegisterType($Item['Type'], '',206 $ FormTypes[$Item['Type']]);207 if($ FormTypes[$Item['Type']]['Type'] == 'Reference')208 $UseType = 'OneToMany'; 209 else if($ FormTypes[$Item['Type']]['Type'] == 'Enumeration')210 $UseType = 'Enumeration'; 211 } else $UseType = $Item['Type']; 212 $Values[$Index] = $ System->Type->ExecuteTypeEvent($UseType, 'OnLoad',205 if(array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 206 { 207 if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 208 $this->FormManager->Type->RegisterType($Item['Type'], '', 209 $this->FormManager->FormTypes[$Item['Type']]); 210 if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference') 211 $UseType = 'OneToMany'; 212 else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration') 213 $UseType = 'Enumeration'; 214 } else $UseType = $Item['Type']; 215 $Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoad', 213 216 array('Name' => $Index, 'Type' => $Item['Type'], 'Values' => $this->Values)); 214 217 } … … 246 249 } 247 250 248 function ShowEditTable($ClassName, $Values) 249 { 251 class FormManager 252 { 253 var $Classes; 254 var $FormTypes; 255 var $Database; 256 var $Type; 257 258 function __construct($Database) 259 { 260 $this->Database = &$Database; 261 $this->Classes = array(); 262 $this->FormTypes = array(); 263 $this->Type = new Type($this); 264 } 265 266 function RegisterClass($Name, $Class) 267 { 268 $this->Classes[$Name] = $Class; 269 } 270 271 function UnregisterClass($Name) 272 { 273 unset($this->Classes[$Name]); 274 } 250 275 } 251 276
Note:
See TracChangeset
for help on using the changeset viewer.