Changeset 873 for trunk/Common/Form/Form.php
- Timestamp:
- Apr 6, 2020, 11:17:40 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Common/Form/Form.php
r872 r873 67 67 { 68 68 $Item = $this->Definition['Items'][$Index]; 69 if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))70 { 71 if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))69 if (array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 70 { 71 if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 72 72 $this->FormManager->Type->RegisterType($Item['Type'], '', $this->FormManager->FormTypes[$Item['Type']]); 73 if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')73 if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference') 74 74 $UseType = 'OneToMany'; 75 else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')75 else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration') 76 76 $UseType = 'Enumeration'; 77 77 } else $UseType = $Item['Type']; … … 88 88 'Rows' => array(), 89 89 ); 90 foreach ($this->Definition['Items'] as $Index => $Item)91 if (!array_key_exists('Hidden', $Item) or ($Item['Hidden'] == false))92 if (!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or90 foreach ($this->Definition['Items'] as $Index => $Item) 91 if (!array_key_exists('Hidden', $Item) or ($Item['Hidden'] == false)) 92 if (!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 93 93 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 94 94 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 95 95 { 96 if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))97 { 98 if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))96 if (array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 97 { 98 if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 99 99 $this->FormManager->Type->RegisterType($Item['Type'], '', $this->FormManager->FormTypes[$Item['Type']]); 100 if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')100 if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference') 101 101 $UseType = 'OneToMany'; 102 else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')102 else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration') 103 103 $UseType = 'Enumeration'; 104 104 } else $UseType = $Item['Type']; … … 107 107 'Type' => $Item['Type'], 'Values' => $this->Values, 108 108 'Filter' => $this->ValuesFilter[$Index])); 109 if (array_key_exists('Suffix', $Item)) $Edit .= ' '.$Item['Suffix'];110 if (!$this->FormManager->Type->IsHidden($UseType))109 if (array_key_exists('Suffix', $Item)) $Edit .= ' '.$Item['Suffix']; 110 if (!$this->FormManager->Type->IsHidden($UseType)) 111 111 array_push($Table['Rows'], array($Item['Caption'].':', $Edit)); 112 112 } 113 113 $Output = '<fieldset><legend>'.$this->Definition['Title'].'</legend>'.Table($Table). 114 114 '</fieldset>'; 115 return ($Output);115 return ($Output); 116 116 } 117 117 118 118 function ShowEditForm() 119 119 { 120 if (!array_key_exists('SubmitText', $this->Definition)) $this->Definition['SubmitText'] = 'Uložit';120 if (!array_key_exists('SubmitText', $this->Definition)) $this->Definition['SubmitText'] = 'Uložit'; 121 121 $Output = '<form enctype="multipart/form-data" class="Form" action="'.$this->OnSubmit.'" method="post">'.$this->ShowEditBlock(). 122 122 '<div><input name="submit" type="submit" value="'.$this->Definition['SubmitText'].'" /> '. 123 123 '<input type="button" value="Zrušit" onclick="location.href=\'?\'"/></div></form>'; 124 return ($Output);124 return ($Output); 125 125 } 126 126 … … 184 184 function LoadValuesFromDatabase($Id) 185 185 { 186 foreach ($this->Definition['Items'] as $Index => $Item)187 if (!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or186 foreach ($this->Definition['Items'] as $Index => $Item) 187 if (!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 188 188 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 189 189 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 190 190 { 191 if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))192 { 193 if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))191 if (array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 192 { 193 if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 194 194 $this->FormManager->Type->RegisterType($Item['Type'], '', 195 195 $this->FormManager->FormTypes[$Item['Type']]); 196 if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')196 if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference') 197 197 $UseType = 'OneToMany'; 198 else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')198 else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration') 199 199 $UseType = 'Enumeration'; 200 200 } else $UseType = $Item['Type']; 201 if (!array_key_exists('SQL', $Item)) $Item['SQL'] = '';201 if (!array_key_exists('SQL', $Item)) $Item['SQL'] = ''; 202 202 else $Item['SQL'] = str_replace('#Id', $Id, $Item['SQL']); 203 203 $Columns[] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnFilterNameQuery', … … 205 205 } 206 206 $Columns = implode(',', $Columns); 207 if (array_key_exists('SQL', $this->Definition))207 if (array_key_exists('SQL', $this->Definition)) 208 208 $SourceTable = '('.$this->Definition['SQL'].') AS `TX`'; 209 209 else $SourceTable = '`'.$this->Definition['Table'].'` AS `TX`'; 210 210 $DbResult = $this->Database->query('SELECT '.$Columns.' FROM '.$SourceTable.' WHERE `TX`.`Id`='.$Id); 211 211 $DbRow = $DbResult->fetch_array(); 212 foreach ($this->Definition['Items'] as $Index => $Item)213 if (!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or212 foreach ($this->Definition['Items'] as $Index => $Item) 213 if (!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 214 214 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 215 215 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) 216 216 { 217 if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))218 { 219 if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))217 if (array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 218 { 219 if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 220 220 $this->FormManager->Type->RegisterType($Item['Type'], '', 221 221 $this->FormManager->FormTypes[$Item['Type']]); 222 if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')222 if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference') 223 223 $UseType = 'OneToMany'; 224 else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')224 else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration') 225 225 $UseType = 'Enumeration'; 226 226 } else $UseType = $Item['Type']; … … 235 235 { 236 236 $Values = array(); 237 foreach ($this->Definition['Items'] as $Index => $Item)238 { 239 if (array_key_exists($Index, $this->Values))240 if (!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or237 foreach ($this->Definition['Items'] as $Index => $Item) 238 { 239 if (array_key_exists($Index, $this->Values)) 240 if (!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 241 241 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 242 242 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) … … 245 245 'Type' => $Item['Type'], 'Values' => $this->Values); 246 246 247 if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))248 { 249 if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))247 if (array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 248 { 249 if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 250 250 $this->FormManager->Type->RegisterType($Item['Type'], '', 251 251 $this->FormManager->FormTypes[$Item['Type']]); 252 if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')252 if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference') 253 253 { 254 254 $UseType = 'OneToMany'; 255 255 } 256 else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')256 else if ($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration') 257 257 $UseType = 'Enumeration'; 258 258 } else $UseType = $Item['Type']; 259 259 $Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnSaveDb', $Parameters); 260 if (($Item['Type'] == 'Password') and ($Values[$Index] == '')) unset($Values[$Index]);261 } 262 } 263 if ($Id == 0)260 if (($Item['Type'] == 'Password') and ($Values[$Index] == '')) unset($Values[$Index]); 261 } 262 } 263 if ($Id == 0) 264 264 { 265 265 $Values['Id'] = $Id; … … 316 316 } 317 317 } 318 return ($Values);318 return ($Values); 319 319 } 320 320 … … 322 322 { 323 323 $Valid = true; 324 foreach ($this->Definition['Items'] as $Index => $Item)325 if ((!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or324 foreach ($this->Definition['Items'] as $Index => $Item) 325 if ((!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or 326 326 (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and 327 327 ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) and … … 330 330 ($Item['ReadOnly'] != true)))) 331 331 { 332 //if (array_key_exists($Context.$Index, $_POST))333 if (array_key_exists($Item['Type'], $this->FormManager->FormTypes))334 { 335 if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))332 //if (array_key_exists($Context.$Index, $_POST)) 333 if (array_key_exists($Item['Type'], $this->FormManager->FormTypes)) 334 { 335 if (!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList)) 336 336 $this->FormManager->Type->RegisterType($Item['Type'], '', 337 337 $this->FormManager->FormTypes[$Item['Type']]); 338 338 $CustomType = $this->FormManager->FormTypes[$Item['Type']]['Type']; 339 if ($CustomType == 'Reference')339 if ($CustomType == 'Reference') 340 340 $UseType = 'OneToMany'; 341 else if ($CustomType == 'Enumeration')341 else if ($CustomType == 'Enumeration') 342 342 $UseType = 'Enumeration'; 343 343 } else $UseType = $Item['Type']; 344 344 345 345 $Parameters = array('Value' => $this->Values[$Index]); 346 if (array_key_exists('Null', $Item)) $Parameters['Null'] = $Item['Null'];346 if (array_key_exists('Null', $Item)) $Parameters['Null'] = $Item['Null']; 347 347 else $Parameters['Null'] = false; 348 if (!$this->FormManager->Type->ExecuteTypeEvent($UseType, 'Validate',348 if (!$this->FormManager->Type->ExecuteTypeEvent($UseType, 'Validate', 349 349 $Parameters)) { 350 350 $this->ValuesValidate[$Index] = true; … … 352 352 } 353 353 } 354 if ($Valid == false) throw new Exception('not validated');355 return ($Valid);354 if ($Valid == false) throw new Exception('not validated'); 355 return ($Valid); 356 356 } 357 357 } … … 360 360 function MakeLink($Target, $Title) 361 361 { 362 return ('<a href="'.$Target.'">'.$Title.'</a>');362 return ('<a href="'.$Target.'">'.$Title.'</a>'); 363 363 } 364 364 … … 366 366 { 367 367 $Result = '<table class="BasicTable">'; 368 if (array_key_exists('Header', $Table))368 if (array_key_exists('Header', $Table)) 369 369 { 370 370 $Result .= '<tr>'; 371 foreach ($Table['Header'] as $Item)371 foreach ($Table['Header'] as $Item) 372 372 $Result .= '<th>'.$Item.'</th>'; 373 373 $Result .= '</tr>'; 374 374 } 375 foreach ($Table['Rows'] as $Row)375 foreach ($Table['Rows'] as $Row) 376 376 { 377 377 $Result .= '<tr>'; 378 foreach ($Row as $Index => $Item)379 { 380 if ($Index == 0) $Class = ' class="Header"'; else $Class = '';378 foreach ($Row as $Index => $Item) 379 { 380 if ($Index == 0) $Class = ' class="Header"'; else $Class = ''; 381 381 $Result .= '<td'.$Class.' style="width: '.(floor(100 / count($Row))).'%">'.$Item.'</td>'; 382 382 } … … 384 384 } 385 385 $Result .= '</table>'; 386 return ($Result);386 return ($Result); 387 387 } 388 388 … … 432 432 $this->Database->query('DELETE FROM DataType'); 433 433 434 foreach ($this->Type->TypeDefinitionList as $Name => $Type)434 foreach ($this->Type->TypeDefinitionList as $Name => $Type) 435 435 { 436 436 $DbResult = $this->Database->select('DataType', 'Id', 'Name="'.$Name.'"'); 437 if ($DbResult->num_rows == 0)437 if ($DbResult->num_rows == 0) 438 438 { 439 439 $this->Database->insert('DataType', array('Name' => $Name, … … 447 447 } 448 448 449 foreach ($this->Classes as $Class)450 if (!array_key_exists('SQL', $Class) and ($Class['Table'] != ''))449 foreach ($this->Classes as $Class) 450 if (!array_key_exists('SQL', $Class) and ($Class['Table'] != '')) 451 451 { 452 452 $DbResult = $this->Database->query('SELECT * FROM information_schema.tables WHERE table_schema = "centrala_big" 453 453 AND table_name = "'.$Class['Table'].'" LIMIT 1'); 454 if ($DbResult->num_rows == 0) continue;454 if ($DbResult->num_rows == 0) continue; 455 455 456 456 echo($Class['Table'].'<br>'); 457 457 $Module = 1; 458 458 $DbResult = $this->Database->select('Model', 'Id', 'Name="'.$Class['Table'].'"'); 459 if ($DbResult->num_rows == 0)459 if ($DbResult->num_rows == 0) 460 460 { 461 461 $this->Database->insert('Model', array('Name' => $Class['Table'], 'Title' => $Class['Title'], 'Module' => $Module)); … … 469 469 } 470 470 471 foreach ($Class['Items'] as $Name => $Field)471 foreach ($Class['Items'] as $Name => $Field) 472 472 { 473 473 echo($Name.', '); 474 474 $DbResult = $this->Database->select('DataType', 'Id', 'Name="'.$Field['Type'].'"'); 475 if ($DbResult->num_rows > 0)475 if ($DbResult->num_rows > 0) 476 476 { 477 477 $DbRow = $DbResult->fetch_assoc(); … … 482 482 // Search parent type 483 483 $DbResult = $this->Database->select('DataType', 'Id', 'Name="'.$Type['Type'].'"'); 484 if ($DbResult->num_rows > 0)484 if ($DbResult->num_rows > 0) 485 485 { 486 486 $DbRow = $DbResult->fetch_assoc(); … … 494 494 495 495 $DbResult = $this->Database->select('ModelField', 'Id', '(Name="'.$Name.'") AND (Model='.$Model.')'); 496 if ($DbResult->num_rows == 0)496 if ($DbResult->num_rows == 0) 497 497 { 498 498 $this->Database->insert('ModelField', array('Name' => $Name,
Note:
See TracChangeset
for help on using the changeset viewer.