Changeset 639 for trunk/Common/Form/Form.php
- Timestamp:
- Mar 16, 2014, 1:33:22 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/Form/Form.php
r606 r639 13 13 var $OnSubmit; 14 14 var $Database; 15 15 16 16 function __construct($FormManager) 17 { 17 { 18 18 $this->FormManager = &$FormManager; 19 19 $this->Database = $FormManager->Database; 20 20 $this->Definition = array(); 21 $this->Values = array(); 21 $this->Values = array(); 22 22 $this->ValuesFilter = array(); 23 $this->ValuesValidate = array(); 23 $this->ValuesValidate = array(); 24 24 $this->OnSubmit = ''; 25 25 } 26 26 27 function LoadDefaults() 28 { 29 foreach($this->Definition['Items'] as $Index => $Item) 30 if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 31 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 32 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 33 { 34 if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default']; 35 } 36 } 37 27 38 function SetClass($Name) 28 39 { 29 $this->Definition = &$this->FormManager->Classes[$Name]; 30 } 40 $this->Definition = &$this->FormManager->Classes[$Name]; 41 $this->LoadDefaults(); 42 } 31 43 32 44 function ShowViewForm() … … 37 49 ); 38 50 foreach($this->Definition['Items'] as $Index => $Item) 39 if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 40 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 41 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 42 { 43 if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default']; 44 if(array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 45 { 46 if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 51 if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 52 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 53 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 54 { 55 if(array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 56 { 57 if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 47 58 $this->FormManager->Type->RegisterType($Item['Type'], '', $this->FormManager->FormTypes[$Item['Type']]); 48 if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference') 49 $UseType = 'OneToMany'; 50 else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration') 51 $UseType = 'Enumeration'; 52 } else $UseType = $Item['Type']; 53 $Edit = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnView', 54 array('Value' => $this->Values[$Index], 'Name' => $Index, 55 'Type' => $Item['Type'], 'Values' => $this->Values, 59 if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference') 60 $UseType = 'OneToMany'; 61 else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration') 62 $UseType = 'Enumeration'; 63 } else $UseType = $Item['Type']; 64 $Edit = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnView', 65 array('Value' => $this->Values[$Index], 'Name' => $Index, 66 'Type' => $Item['Type'], 'Values' => $this->Values, 56 67 'Filter' => $this->ValuesFilter[$Index])); 57 68 if(array_key_exists('Suffix', $Item)) $Edit .= ' '.$Item['Suffix']; … … 61 72 $Output = '<fieldset><legend>'.$this->Definition['Title'].'</legend>'.Table($Table). 62 73 '</fieldset>'; 63 return($Output); 74 return($Output); 64 75 } 65 76 … … 86 97 if(!array_key_exists('ReadOnly', $Item)) $Item['ReadOnly'] = false; 87 98 if($Item['ReadOnly'] == false) 88 if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 89 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 90 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 91 { 92 if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default']; 93 $Parameters = array('Value' => $this->Values[$Index], 'Name' => $Index, 99 if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 100 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 101 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 102 { 103 $Parameters = array('Value' => $this->Values[$Index], 'Name' => $Index, 94 104 'Type' => $Item['Type'], 'Values' => $this->Values); 95 105 if(array_key_exists('Null', $Item)) $Parameters['Null'] = $Item['Null']; 96 106 else unset($Parameters['Null']); 97 98 if(array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 99 { 100 if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 101 $this->FormManager->Type->RegisterType($Item['Type'], '', 102 $this->FormManager->FormTypes[$Item['Type']]); 103 if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference') 107 if(array_key_exists('OnPreset', $Item)) $Parameters['OnPreset'] = $Item['OnPreset']; 108 else unset($Parameters['OnPreset']); 109 110 if(array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 111 { 112 if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 113 $this->FormManager->Type->RegisterType($Item['Type'], '', 114 $this->FormManager->FormTypes[$Item['Type']]); 115 if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference') 104 116 { 105 117 $UseType = 'OneToMany'; 106 } else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration') 118 } else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration') 107 119 $UseType = 'Enumeration'; 108 120 } else $UseType = $Item['Type']; … … 111 123 112 124 $Caption = $Item['Caption'].':'; 113 if(array_key_exists($Index, $this->ValuesValidate) and 125 if(array_key_exists($Index, $this->ValuesValidate) and 114 126 $this->ValuesValidate[$Index]) { 115 127 $Format = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'GetValidationFormat', array()); … … 124 136 $Output = '<fieldset><legend>'.$this->Definition['Title'].'</legend>'.Table($Table). 125 137 $Hidden.'</fieldset>'; 126 return($Output); 138 return($Output); 127 139 } 128 140 129 141 function LoadValuesFromDatabase($Id) 130 { 131 foreach($this->Definition['Items'] as $Index => $Item) 132 if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 133 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 134 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 135 { 136 if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default']; 137 if(array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 138 { 139 if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 140 $this->FormManager->Type->RegisterType($Item['Type'], '', 141 $this->FormManager->FormTypes[$Item['Type']]); 142 if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference') 143 $UseType = 'OneToMany'; 144 else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration') 142 { 143 foreach($this->Definition['Items'] as $Index => $Item) 144 if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 145 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 146 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 147 { 148 if(array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 149 { 150 if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 151 $this->FormManager->Type->RegisterType($Item['Type'], '', 152 $this->FormManager->FormTypes[$Item['Type']]); 153 if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference') 154 $UseType = 'OneToMany'; 155 else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration') 145 156 $UseType = 'Enumeration'; 146 157 } else $UseType = $Item['Type']; … … 154 165 $DbRow = $DbResult->fetch_array(); 155 166 foreach($this->Definition['Items'] as $Index => $Item) 156 if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 157 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 158 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 159 { 160 if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default']; 161 if(array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 162 { 163 if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 164 $this->FormManager->Type->RegisterType($Item['Type'], '', 165 $this->FormManager->FormTypes[$Item['Type']]); 166 if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference') 167 $UseType = 'OneToMany'; 168 else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration') 169 $UseType = 'Enumeration'; 170 } else $UseType = $Item['Type']; 171 $this->Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoadDb', 172 array('Value' => $DbRow[$Index], 'Name' => $Index, 167 if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 168 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 169 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 170 { 171 if(array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 172 { 173 if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 174 $this->FormManager->Type->RegisterType($Item['Type'], '', 175 $this->FormManager->FormTypes[$Item['Type']]); 176 if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference') 177 $UseType = 'OneToMany'; 178 else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration') 179 $UseType = 'Enumeration'; 180 } else $UseType = $Item['Type']; 181 $this->Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoadDb', 182 array('Value' => $DbRow[$Index], 'Name' => $Index, 173 183 'Type' => $Item['Type'], 'Values' => $this->Values)); 174 184 $this->ValuesFilter[$Index] = $DbRow[$Index.'_Filter']; … … 183 193 if(!array_key_exists('ReadOnly', $Item)) $Item['ReadOnly'] = false; 184 194 if($Item['ReadOnly'] == false) 185 if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 186 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 195 if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 196 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 187 197 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 188 198 { 189 if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default']; 190 $Parameters = array('Value' => $this->Values[$Index], 'Name' => $Index, 199 $Parameters = array('Value' => $this->Values[$Index], 'Name' => $Index, 191 200 'Type' => $Item['Type'], 'Values' => $this->Values); 192 193 if(array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 194 { 195 if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 196 $this->FormManager->Type->RegisterType($Item['Type'], '', 197 $this->FormManager->FormTypes[$Item['Type']]); 198 if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference') 201 202 if(array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 203 { 204 if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 205 $this->FormManager->Type->RegisterType($Item['Type'], '', 206 $this->FormManager->FormTypes[$Item['Type']]); 207 if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference') 199 208 { 200 209 $UseType = 'OneToMany'; 201 210 } 202 else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration') 211 else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration') 203 212 $UseType = 'Enumeration'; 204 213 } else $UseType = $Item['Type']; … … 225 234 $Values = array(); 226 235 foreach($this->Definition['Items'] as $Index => $Item) 227 if((!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 236 if((!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 228 237 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 229 238 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) and 230 (!array_key_exists('ReadOnly', $Item) or 239 (!array_key_exists('ReadOnly', $Item) or 231 240 (array_key_exists('ReadOnly', $Item) and 232 241 ($Item['ReadOnly'] != true)))) 233 { 242 { 234 243 //if(array_key_exists($Context.$Index, $_POST)) 235 244 if(array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 236 { 237 if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 238 $this->FormManager->Type->RegisterType($Item['Type'], '', 245 { 246 if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 247 $this->FormManager->Type->RegisterType($Item['Type'], '', 239 248 $this->FormManager->FormTypes[$Item['Type']]); 240 249 $CustomType = $this->FormManager->FormTypes[$Item['Type']]['Type']; 241 if($CustomType == 'Reference') 242 $UseType = 'OneToMany'; 243 else if($CustomType == 'Enumeration') 250 if($CustomType == 'Reference') 251 $UseType = 'OneToMany'; 252 else if($CustomType == 'Enumeration') 244 253 $UseType = 'Enumeration'; 245 254 } else $UseType = $Item['Type']; … … 247 256 if(array_key_exists('Null', $Item)) $Parameters['Null'] = $Item['Null']; 248 257 else unset($Parameters['Null']); 249 $Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoad', 258 $Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoad', 250 259 $Parameters); 251 260 } … … 257 266 $Valid = true; 258 267 foreach($this->Definition['Items'] as $Index => $Item) 259 if((!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 268 if((!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 260 269 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 261 270 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) and 262 (!array_key_exists('ReadOnly', $Item) or 271 (!array_key_exists('ReadOnly', $Item) or 263 272 (array_key_exists('ReadOnly', $Item) and 264 273 ($Item['ReadOnly'] != true)))) 265 { 274 { 266 275 //if(array_key_exists($Context.$Index, $_POST)) 267 276 if(array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 268 { 269 if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 270 $this->FormManager->Type->RegisterType($Item['Type'], '', 277 { 278 if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 279 $this->FormManager->Type->RegisterType($Item['Type'], '', 271 280 $this->FormManager->FormTypes[$Item['Type']]); 272 281 $CustomType = $this->FormManager->FormTypes[$Item['Type']]['Type']; 273 if($CustomType == 'Reference') 274 $UseType = 'OneToMany'; 275 else if($CustomType == 'Enumeration') 276 $UseType = 'Enumeration'; 277 } else $UseType = $Item['Type']; 278 282 if($CustomType == 'Reference') 283 $UseType = 'OneToMany'; 284 else if($CustomType == 'Enumeration') 285 $UseType = 'Enumeration'; 286 } else $UseType = $Item['Type']; 287 279 288 $Parameters = array('Value' => $this->Values[$Index]); 280 289 if(array_key_exists('Null', $Item)) $Parameters['Null'] = $Item['Null']; 281 290 else $Parameters['Null'] = false; 282 if(!$this->FormManager->Type->ExecuteTypeEvent($UseType, 'Validate', 291 if(!$this->FormManager->Type->ExecuteTypeEvent($UseType, 'Validate', 283 292 $Parameters)) { 284 293 $this->ValuesValidate[$Index] = true; … … 288 297 if($Valid == false) throw new Exception('not validated'); 289 298 return($Valid); 290 } 299 } 291 300 } 292 301 … … 294 303 function MakeLink($Target, $Title) 295 304 { 296 return('<a href="'.$Target.'">'.$Title.'</a>'); 305 return('<a href="'.$Target.'">'.$Title.'</a>'); 297 306 } 298 307 … … 329 338 var $RootURL; 330 339 var $ShowRelation; 331 340 332 341 function __construct($Database) 333 342 { … … 336 345 $this->FormTypes = array(); 337 346 $this->Type = new Type($this); 338 $this->ShowRelation = false; 339 } 340 347 $this->ShowRelation = false; 348 } 349 341 350 function RegisterClass($Name, $Class) 342 351 { 343 352 $this->Classes[$Name] = $Class; 344 353 } 345 354 346 355 function UnregisterClass($Name) 347 356 { … … 353 362 $this->FormTypes[$Name] = $Class; 354 363 } 355 364 356 365 function UnregisterFormType($Name) 357 366 {
Note:
See TracChangeset
for help on using the changeset viewer.