| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | include_once(dirname(__FILE__).'/HTML.php');
|
|---|
| 4 |
|
|---|
| 5 | class Form extends HTML
|
|---|
| 6 | {
|
|---|
| 7 | var $Definition = array();
|
|---|
| 8 | var $Values = array();
|
|---|
| 9 | var $OnSubmit = '';
|
|---|
| 10 |
|
|---|
| 11 | function __construct($System, $FormClass)
|
|---|
| 12 | {
|
|---|
| 13 | $this->System = $System;
|
|---|
| 14 | $this->Definition = $FormClass;
|
|---|
| 15 | foreach($this->Definition['Items'] as $Index => $Item)
|
|---|
| 16 | {
|
|---|
| 17 | $this->Values[$Index] = '';
|
|---|
| 18 | }
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | function ShowTable()
|
|---|
| 22 | {
|
|---|
| 23 | $Output = $this->ShowTableBlock();
|
|---|
| 24 | return($Output);
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | function ShowTableBlock($Context = '')
|
|---|
| 28 | {
|
|---|
| 29 | $Table = array(
|
|---|
| 30 | 'Header' => array('Položka', 'Hodnota'),
|
|---|
| 31 | 'Rows' => array(),
|
|---|
| 32 | );
|
|---|
| 33 | if($Context != '') $Context = $Context.'-';
|
|---|
| 34 | foreach($this->Definition['Items'] as $Index => $Item)
|
|---|
| 35 | {
|
|---|
| 36 | if($Item['Type'] != 'Hidden')
|
|---|
| 37 | {
|
|---|
| 38 | if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default'];
|
|---|
| 39 | $Edit = $this->System->Type->ExecuteTypeEvent($Item['Type'], 'OnView',
|
|---|
| 40 | array('Name' => $Index, 'Value' => $this->Values[$Index], 'Type' => $Item['Type']));
|
|---|
| 41 | array_push($Table['Rows'], array($Item['Caption'], $Edit));
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
| 44 | $Output = '<div style="text-align: center">'.$this->Definition['Title'].'</div>'.$this->Table($Table, 'WideTable');
|
|---|
| 45 | return($Output);
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | function ShowEditForm()
|
|---|
| 49 | {
|
|---|
| 50 | if(!array_key_exists('SubmitText', $this->Definition)) $this->Definition['SubmitText'] = 'Uložit';
|
|---|
| 51 | $Output = '<form class="Form" action="'.$this->OnSubmit.'" method="post">'.$this->ShowEditBlock().'<div><input type="submit" value="'.$this->Definition['SubmitText'].'" /></div></form>';
|
|---|
| 52 | return($Output);
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | function ShowEditBlock($Context = '')
|
|---|
| 56 | {
|
|---|
| 57 | $Table = array(
|
|---|
| 58 | //'Header' => array('Položka', 'Hodnota'),
|
|---|
| 59 | 'Rows' => array(),
|
|---|
| 60 | );
|
|---|
| 61 | if($Context != '') $Context = $Context.'-';
|
|---|
| 62 | foreach($this->Definition['Items'] as $Index => $Item)
|
|---|
| 63 | {
|
|---|
| 64 | if($Item['Type'] != 'Hidden')
|
|---|
| 65 | {
|
|---|
| 66 | if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default'];
|
|---|
| 67 | $Edit = $this->System->Type->ExecuteTypeEvent($Item['Type'], 'OnEdit', array('Name' => $Index, 'Value' => $this->Values[$Index], 'Type' => $Item['Type']));
|
|---|
| 68 | array_push($Table['Rows'], array($Item['Caption'].':', $Edit));
|
|---|
| 69 | }
|
|---|
| 70 | }
|
|---|
| 71 | $Output = '<fieldset><legend>'.$this->Definition['Title'].'</legend>'.$this->Table($Table, 'BasicTable').
|
|---|
| 72 | '</fieldset>';
|
|---|
| 73 | foreach($this->Definition['Items'] as $Index => $Item)
|
|---|
| 74 | if($Item['Type'] == 'Hidden') $Output .= $this->System->Type->ExecuteTypeEvent($Item['Type'], 'OnEdit', array('Name' => $Index, 'Value' => $this->Values[$Index], 'Type' => $Item['Type']));
|
|---|
| 75 | return($Output);
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | function LoadValuesFromDatabase($Id)
|
|---|
| 79 | {
|
|---|
| 80 | $DbResult = $this->System->Database->query('SELECT T.* FROM '.$this->Definition['Table'].' AS T WHERE T.Id='.$Id);
|
|---|
| 81 | if($DbResult->num_rows > 0) $DbRow = $DbResult->fetch_assoc();
|
|---|
| 82 | foreach($this->Definition['Items'] as $Index => $Item)
|
|---|
| 83 | {
|
|---|
| 84 | if($Item['Type'] != 'Hidden')
|
|---|
| 85 | if($DbResult->num_rows > 0) $this->Values[$Index] = $DbRow[$Index];
|
|---|
| 86 | else $this->Values[$Index] = '';
|
|---|
| 87 | }
|
|---|
| 88 | $this->Definition['Items']['Id'] = array('Type' => 'Hidden', 'Caption' => 'Id', 'Default' => 0);
|
|---|
| 89 | $this->Values['Id'] = $Id;
|
|---|
| 90 | return($DbResult->num_rows > 0);
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | function SaveValuesToDatabase($Id)
|
|---|
| 94 | {
|
|---|
| 95 | if($Id == 0)
|
|---|
| 96 | {
|
|---|
| 97 | $this->Values['Id'] = $Id;
|
|---|
| 98 | $DbResult = $this->System->Database->replace($this->Definition['Table'], $this->Values);
|
|---|
| 99 | } else
|
|---|
| 100 | $DbResult = $this->System->Database->update($this->Definition['Table'], 'Id='.$Id, $this->Values);
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | function LoadValuesFromForm()
|
|---|
| 104 | {
|
|---|
| 105 | $this->Values = $this->LoadValuesFromFormBlock();
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | function LoadValuesFromFormBlock($Context = '')
|
|---|
| 109 | {
|
|---|
| 110 | if($Context != '') $Context = $Context.'-';
|
|---|
| 111 | $Values = array();
|
|---|
| 112 | foreach($this->Definition['Items'] as $Index => $Item)
|
|---|
| 113 | {
|
|---|
| 114 | if(array_key_exists($Context.$Index, $_POST))
|
|---|
| 115 | $Values[$Index] = $this->System->Type->ExecuteTypeEvent($Item['Type'], 'OnLoad',
|
|---|
| 116 | array('Name' => $Index, 'Type' => $Item['Type']));
|
|---|
| 117 | }
|
|---|
| 118 | return($Values);
|
|---|
| 119 | }
|
|---|
| 120 | }
|
|---|