1 | <?php
|
---|
2 |
|
---|
3 | include_once('database.php');
|
---|
4 |
|
---|
5 | class Form
|
---|
6 | {
|
---|
7 | var $Definition = array();
|
---|
8 | var $Values = array();
|
---|
9 | var $OnSubmit = '';
|
---|
10 |
|
---|
11 | function ShowEditForm()
|
---|
12 | {
|
---|
13 | $Output = '<center><form enctype="multipart/form-data" action="'.$this->OnSubmit.'" method="post"><div align="center">';
|
---|
14 | $Table = $this->ShowEditBlock();
|
---|
15 | $Output .= $this->Definition['Title'].Table($Table).$this->ShowHiddenBlock().'<input type="submit" value="'.$this->Definition['SubmitButtonText'].'"></div></form>';
|
---|
16 | return($Output);
|
---|
17 | }
|
---|
18 |
|
---|
19 | function ShowEditBlock($Context = '')
|
---|
20 | {
|
---|
21 | global $Database;
|
---|
22 |
|
---|
23 | $Table = array(
|
---|
24 | 'Header' => array('Položka', 'Hodnota'),
|
---|
25 | 'Rows' => array(),
|
---|
26 | );
|
---|
27 | if($Context != '') $Context = $Context.'-';
|
---|
28 | foreach($this->Definition['Items'] as $Index => $Item)
|
---|
29 | {
|
---|
30 | if($Item['Type'] != TypeHiddenId)
|
---|
31 | {
|
---|
32 | if(!array_key_exists($Index, $this->Values) and isset($Item['Value'])) $this->Values[$Index] = $Item['Value'];
|
---|
33 | $Edit = ExecuteTypeEvent($Item['Type'], 'OnEdit', $Item);
|
---|
34 | array_push($Table['Rows'], array($Item['Caption'], $Edit));
|
---|
35 | }
|
---|
36 | }
|
---|
37 | return($Table);
|
---|
38 | }
|
---|
39 |
|
---|
40 | function ShowHiddenBlock($Context = '')
|
---|
41 | {
|
---|
42 | global $Database;
|
---|
43 |
|
---|
44 | $Output = '';
|
---|
45 | if($Context != '') $Context = $Context.'-';
|
---|
46 | foreach($this->Definition['Items'] as $Item)
|
---|
47 | {
|
---|
48 | if($Item['Type'] == TypeHiddenId)
|
---|
49 | {
|
---|
50 | if(!array_key_exists($Item['Name'], $this->Values) and isset($Item['Value'])) $this->Values[$Item['Name']] = $Item['Value'];
|
---|
51 | $Edit = ExecuteTypeEvent($Item['Type'], 'OnEdit', $Item);
|
---|
52 | $Output .= $Edit;
|
---|
53 | }
|
---|
54 | }
|
---|
55 | return($Output);
|
---|
56 | }
|
---|
57 |
|
---|
58 | function ShowReadOnlyForm()
|
---|
59 | {
|
---|
60 | $Output = '<center><div align="center">';
|
---|
61 | $Table = $this->ShowReadOnlyBlock();
|
---|
62 | $Output .= $this->Definition['Title'].Table($Table).'</div></form>';
|
---|
63 | return($Output);
|
---|
64 | }
|
---|
65 |
|
---|
66 | function ShowReadOnlyBlock($Context = '')
|
---|
67 | {
|
---|
68 | global $Database;
|
---|
69 |
|
---|
70 | $Table = array(
|
---|
71 | 'Header' => array('Položka', 'Hodnota'),
|
---|
72 | 'Rows' => array(),
|
---|
73 | );
|
---|
74 | if($Context != '') $Context = $Context.'-';
|
---|
75 | foreach($this->Definition['Items'] as $Item)
|
---|
76 | {
|
---|
77 | if(!array_key_exists($Item['Name'], $this->Values) and isset($Item['Value'])) $this->Values[$Item['Name']] = $Item['Value'];
|
---|
78 | $Edit = ExecuteTypeEvent($Item['Type'], 'OnView', $Item);
|
---|
79 | array_push($Table['Rows'], array($Item['Caption'], $Edit));
|
---|
80 | }
|
---|
81 | return($Table);
|
---|
82 | }
|
---|
83 |
|
---|
84 | function LoadValuesFromDatabase($Id)
|
---|
85 | {
|
---|
86 | global $Database;
|
---|
87 |
|
---|
88 | $DbResult = $Database->query('SELECT * FROM '.$this->Definition['Table'].' WHERE Id='.$Id);
|
---|
89 | $DbRow = $DbResult->fetch_assoc();
|
---|
90 | foreach($this->Definition['Items'] as $Item)
|
---|
91 | {
|
---|
92 | $this->Values[$Item['Name']] = $DbRow[$Item['Name']];
|
---|
93 | switch($Item['Type'])
|
---|
94 | {
|
---|
95 | case 'Password':
|
---|
96 | if($Item['Type'] == 'Password') $this->Values[$Item['Name']] = ''; // Dont show password
|
---|
97 | break;
|
---|
98 | case 'Time':
|
---|
99 | $this->Values[$Index] == MysqlDateTimeToTime($this->Values[$Item['Name']]);
|
---|
100 | break;
|
---|
101 | }
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | function SaveValuesToDatabase($Id)
|
---|
106 | {
|
---|
107 | global $Database;
|
---|
108 |
|
---|
109 | foreach($this->Definition['Items'] as $Item)
|
---|
110 | {
|
---|
111 | switch($Item['Type'])
|
---|
112 | {
|
---|
113 | case 'Password':
|
---|
114 | if($this->Values[$Item['Name']] == '') unset($this->Values[$Item['Name']]); // Do not modify empty passwords
|
---|
115 | else $this->Values[$Item['Name']] = sha1($this->Values[$Item['Name']]);
|
---|
116 | break;
|
---|
117 | case 'Time':
|
---|
118 | $this->Values[$Item['Name']] = TimeToMysqlDateTime($this->Values[$Item['Name']]);
|
---|
119 | break;
|
---|
120 | }
|
---|
121 | }
|
---|
122 | $this->Values['Id'] = $Id;
|
---|
123 | $DbResult = $Database->replace($this->Definition['Table'], $this->Values);
|
---|
124 | //echo($Database->LastQuery);
|
---|
125 | }
|
---|
126 |
|
---|
127 | function LoadValuesFromForm()
|
---|
128 | {
|
---|
129 | $this->Values = $this->LoadValuesFromFormBlock();
|
---|
130 | }
|
---|
131 |
|
---|
132 | function LoadValuesFromFormBlock($Context = '')
|
---|
133 | {
|
---|
134 | $Values = array();
|
---|
135 | foreach($this->Definition['Items'] as $Index => $Item)
|
---|
136 | {
|
---|
137 | $Values[$Item['Name']] = ExecuteTypeEvent($Item['Type'], 'OnLoad', $Item);
|
---|
138 | }
|
---|
139 | //print_r($this->Values);
|
---|
140 | return($Values);
|
---|
141 | }
|
---|
142 | }
|
---|
143 |
|
---|
144 | function MakeLink($Target, $Title)
|
---|
145 | {
|
---|
146 | return('<a href="'.$Target.'">'.$Title.'</a>');
|
---|
147 | }
|
---|
148 |
|
---|
149 | function Table($Table)
|
---|
150 | {
|
---|
151 | $Result = '<table class="WideTable">';
|
---|
152 | $Result .= '<tr>';
|
---|
153 | if(array_key_exists('Header', $Table))
|
---|
154 | {
|
---|
155 | foreach($Table['Header'] as $Item)
|
---|
156 | $Result .= '<th>'.$Item.'</th>';
|
---|
157 | $Result .= '</tr>';
|
---|
158 | }
|
---|
159 | foreach($Table['Rows'] as $Row)
|
---|
160 | {
|
---|
161 | $Result .= '<tr>';
|
---|
162 | foreach($Row as $Index => $Item)
|
---|
163 | {
|
---|
164 | if($Index == 0) $Class = ' class="Header"'; else $Class = '';
|
---|
165 | $Result .= '<td'.$Class.'>'.$Item.'</td>';
|
---|
166 | }
|
---|
167 | $Result .= '</tr>';
|
---|
168 | }
|
---|
169 | $Result .= '</table>';
|
---|
170 | return($Result);
|
---|
171 | }
|
---|
172 |
|
---|
173 | function ShowEditTable($ClassName, $Values)
|
---|
174 | {
|
---|
175 | }
|
---|
176 |
|
---|
177 | ?>
|
---|