source: base.php@ 4

Last change on this file since 4 was 4, checked in by george, 17 years ago
  • Opraveno: Utřídění systému výběru operací, tabulek a položek pomocí URL.
  • Přidáno: Podpora pro položky ukazatelů typu jede-na-jednoho a jeden-na-mnoho. Přítom vazba mnoho-na-mnoho je provedena dvěma opačnými povely jeden-na-mnoho. Vytváření vztahů je zatím proveditelné ručně přes databázi.
  • Upraveno: Vystředění tabulek na střed a menší stylové úpravy.
  • Přidáno: Vlastnost VisibleInMenu pro tabulky, která určí zda zobrazit celkové výpisy tabulek na klavní stránce v menu.
  • Přidáno: Vlastnost VisibleInPointer u položek tabulky, která určí co se má použít pro zobrazení identifikace odkazovaných objektů ve vztahu mezi tabulkami.
  • Přidáno: Složka Sql a demo data.
File size: 9.9 KB
Line 
1<?php
2include('database.php');
3include('types.php');
4include('lists.php');
5include('common.php');
6
7function ShowList($List, $Column = '', $ParentId = 0)
8{
9 global $Database, $Types, $Config;
10
11 $Output = '<div>'.$List['Title'].'</div><table class="WideTable"><tr>';
12 foreach($List['Items'] as $Item)
13 {
14 if($Item['VisibleInList'] == 1)
15 $Output .= '<th><a href="?OrderColumn='.$Item['Name'].'">'.$Item['TextBefore'].'</a></th>';
16 }
17 $Output .= '<th>Akce</th></tr>';
18
19 if(($Column != '') and ($ParentId != 0))
20 $Where = $Column.'='.$ParentId;
21 else $Where = '1';
22
23 // Handle ordering
24 if(array_key_exists('OrderColumn', $_GET))
25 {
26 if($_SESSION['OrderColumn'] == $_GET['OrderColumn']) // Same column => reverse orded
27 $_SESSION['OrderDirection'] = ($_SESSION['OrderDirection'] + 1) % 2;
28 if($_SESSION['OrderTable'] != $List['TableName']) // Different table => set ascending order
29 $_SESSION['OrderDirection'] = 0;
30 $_SESSION['OrderColumn'] = $_GET['OrderColumn'];
31 $_SESSION['OrderTable'] = $List['TableName'];
32 }
33 if(array_key_exists('OrderColumn', $_SESSION) and ($_SESSION['OrderTable'] == $List['TableName']))
34 {
35 $OrderDirection = array('ASC', 'DESC');
36 $Where .= ' ORDER BY `'.$_SESSION['OrderColumn'].'` '.$OrderDirection[$_SESSION['OrderDirection']];
37 }
38
39 if(array_key_exists('Page', $_GET)) $Page = $_GET['Page']; else $Page = 0;
40 $DbResult = $Database->select($List['TableName'], 'COUNT(*)', $Where);
41 //echo($Database->LastQuery);
42 $DbRow = $DbResult->fetch_array();
43 $TotalItemCount = $DbRow[0];
44
45 $DbResult = $Database->select($List['TableName'], '*', $Where.' LIMIT '.($Page * $Config['Web']['ItemsPerPage']).', '.$Config['Web']['ItemsPerPage']);
46 while($DbRow = $DbResult->fetch_array())
47 {
48 $Output .= '<tr>';
49 foreach($List['Items'] as $Index => $Item)
50 {
51 if($Item['VisibleInList'] == 1)
52 {
53 $ItemType = explode(':', $Item['Type']);
54 $Type = $Types[$ItemType[0]];
55 if(count($ItemType) > 1) $Type['Parameter'] = $ItemType[1];
56 if(is_callable($Type['ViewHtml'])) $Value = $Type['ViewHtml']($Type, $DbRow[$Index], $List['TableName'], $DbRow['Id']);
57 else $Value = $Type['ViewHtml'];
58 $Value = str_replace('%value%', $DbRow[$Index], $Value);
59 $Output .= '<td>'.$Value.'</td>';
60 }
61 }
62 $Output .= '<td><a href="?Action=ViewItem&amp;TableId='.$List['TableName'].'&amp;ItemId='.$DbRow['Id'].'">Zobrazit</a> <a href="?Action=EditItem&amp;TableId='.$List['TableName'].'&amp;ItemId='.$DbRow['Id'].'">Editovat</a> <a href="?Action=DeleteItem&amp;TableId='.$List['TableName'].'&amp;ItemId='.$DbRow['Id'].'">Smazat</a></td></tr>';
63 }
64 $Output .= '</table>';
65 $Output .= PagesList($Page, $TotalItemCount);
66 $Output .= '<a href="?Action=AddItem&amp;TableId='.$List['TableName'].'">Přidat</a>';
67 return($Output);
68}
69
70function ShowEditItem($List, $Id)
71{
72 global $Database, $Types;
73
74 $Output = '<form action="?Action=EditItemFinish&amp;ItemId='.$Id.'" method="post"><table class="WideTable">';
75 $Output .= '<tr><th>Jméno položky</th><th>Hodnota</th></tr>';
76 $DbResult = $Database->select($List['TableName'], '*', 'Id='.$Id);
77 while($DbRow = $DbResult->fetch_array())
78 {
79 foreach($List['Items'] as $Index => $Item)
80 {
81 $ItemType = explode(':', $Item['Type']);
82 if($ItemType[0] != 'PointerOneToMany')
83 {
84 $Type = $Types[$ItemType[0]];
85 if(count($ItemType) > 1) $Type['Parameter'] = $ItemType[1];
86 if(is_callable($Type['EditHtml'])) $Value = $Type['EditHtml']($Type, $DbRow[$Index], $List['TableName'], $DbRow['Id']);
87 else $Value = $Type['EditHtml'];
88 $Value = str_replace('%value%', $DbRow[$Index], $Value);
89 $Value = str_replace('%name%', $Index, $Value);
90 if($Item['Required'] == 1) $Required = ' *'; else $Required = '';
91 $Output .= '<tr><td>'.$Item['TextBefore'].':'.$Required.'</td><td title="'.$Item['Help'].'">'.$Value.'</td></tr>';
92 }
93 }
94 }
95 $Output .= '</table><input type="submit" value="Uložit"></form><a href="?">Zpět</a>';
96 return($Output);
97}
98
99function ShowEditItemFinish($List, $Id)
100{
101 global $Database, $Types;
102
103 $Values = array();
104 foreach($List['Items'] as $Index => $Item)
105 {
106 $ItemType = explode(':', $Item['Type']);
107 if($ItemType[0] != 'PointerOneToMany')
108 {
109 $Values[$Index] = $_POST[$Index];
110 }
111 }
112 $Database->update($List['TableName'], 'Id='.$Id, $Values);
113 //echo($Database->LastQuery);
114 $Output = 'Změny uloženy.';
115 $Output .= ShowViewItem($List, $Id);
116 return($Output);
117}
118
119function ShowAddItem($List)
120{
121 global $Database, $Types;
122
123 $Output = '<form action="?Action=AddItemFinish" method="post"><table class="WideTable">';
124 $Output .= '<tr><th>Jméno položky</th><th>Hodnota</th></tr>';
125
126 foreach($List['Items'] as $Index => $Item)
127 {
128 $ItemType = explode(':', $Item['Type']);
129 if($ItemType[0] != 'PointerOneToMany')
130 {
131 $Type = $Types[$ItemType[0]];
132 if(count($ItemType) > 1) $Type['Parameter'] = $ItemType[1];
133 if(is_callable($Type['EditHtml'])) $Value = $Type['EditHtml']($Type, $Type['InitValue'], $List['TableName'], 0);
134 else $Value = $Type['EditHtml'];
135 $Value = str_replace('%value%', $Type['InitValue'], $Value);
136 $Value = str_replace('%name%', $Index, $Value);
137 if($Item['Required'] == 1) $Required = ' *'; else $Required = '';
138 $Output .= '<tr><td>'.$Item['TextBefore'].':'.$Required.'</td><td title="'.$Item['Help'].'">'.$Value.'</td></tr>';
139 }
140 }
141 $Output .= '</table><input type="submit" value="Přidat"></form><a href="?">Zpět</a>';
142 return($Output);
143}
144
145function ShowAddItemFinish($List)
146{
147 global $Database, $Types;
148
149 $Values = array();
150 foreach($List['Items'] as $Index => $Item)
151 {
152 $ItemType = explode(':', $Item['Type']);
153 if($ItemType[0] != 'PointerOneToMany')
154 {
155 $Values[$Index] = $_POST[$Index];
156 }
157 }
158 $Database->insert($List['TableName'], $Values);
159 //echo($Database->LastQuery);
160 $Output = 'Položka přidána';
161 $Output .= ShowViewItem($List, $Database->insert_id);
162 return($Output);
163}
164
165function ShowViewItem($List, $Id)
166{
167 global $Database, $Types, $Lists;
168
169 $Output = '';
170 $DbResult = $Database->select($List['TableName'], '*', 'Id='.$Id);
171 while($DbRow = $DbResult->fetch_array())
172 {
173 $Output = '<table class="WideTable">';
174 $Output .= '<tr><th>Jméno položky</th><th>Hodnota</th></tr>';
175 foreach($List['Items'] as $Index => $Item)
176 {
177 $ItemType = explode(':', $Item['Type']);
178 if($ItemType[0] != 'PointerOneToMany')
179 {
180 $Type = $Types[$ItemType[0]];
181 if(count($ItemType) > 1) $Type['Parameter'] = $ItemType[1];
182 if(is_callable($Type['ViewHtml'])) $Value = $Type['ViewHtml']($Type, $DbRow[$Index], $List['TableName'], $DbRow['Id']);
183 else $Value = $Type['ViewHtml'];
184 $Value = str_replace('%value%', $DbRow[$Index], $Value);
185 $Output .= '<tr><td>'.$Item['TextBefore'].':</td><td title="'.$Item['Help'].'">'.$Value.'</td></tr>';
186 }
187 }
188 $Output .= '</table>';
189 $Output .= '<a href="?Action=EditItem&amp;ItemId='.$DbRow['Id'].'">Editovat</a>';
190 $Output .= ' <a href="?Action=ShowList&amp;ItemId='.$DbRow['Id'].'">Seznam</a>';
191 $Output .= '<div class="line"></div>';
192
193 foreach($List['Items'] as $Index => $Item)
194 {
195 $ItemType = explode(':', $Item['Type']);
196 if($ItemType[0] == 'PointerOneToMany')
197 {
198 $SubList = $Lists[$ItemType[1]];
199 $Output .= ShowList($SubList, $ItemType[2], $DbRow['Id']).'<br /><br />';
200 }
201 }
202 }
203 return($Output);
204}
205
206function ShowDeleteItem($List, $Id)
207{
208 global $Database;
209
210 $Database->delete($List['TableName'], 'Id='.$Id);
211 $Output = 'Položka smazána.';
212 return($Output);
213}
214
215function TableList($System)
216{
217 global $Lists;
218
219 $Type = array('Uživatelské', 'Systémové');
220 $Output = '<strong>'.$Type[$System].' seznamy:</strong><br />';
221 foreach($Lists as $Index => $List)
222 {
223 if(($List['System'] == $System) and ($List['VisibleInMenu'] == 1))
224 $Output .= '<a href="?Action=ShowList&amp;TableId='.$Index.'">'.$List['Title'].'</a><br />';
225 }
226 $Output .= '<br />';
227 return($Output);
228}
229
230function Output()
231{
232 global $Lists;
233
234 $PermanentVar = array('TableId', 'ItemId', 'ParentTable', 'ParentColumn', 'Action');
235 foreach($PermanentVar as $Var)
236 {
237 if(array_key_exists($Var, $_GET)) $_SESSION[$Var] = $_GET[$Var];
238 }
239
240 $Output = '';
241 if(array_key_exists('TableId', $_SESSION) and array_key_exists($_SESSION['TableId'], $Lists))
242 {
243 $List = $Lists[$_SESSION['TableId']];
244 if(array_key_exists('Action', $_SESSION))
245 {
246 switch($_SESSION['Action'])
247 {
248 case 'EditItem':
249 $Output = ShowEditItem($List, $_SESSION['ItemId']);
250 break;
251 case 'EditItemFinish':
252 $Output = ShowEditItemFinish($List, $_SESSION['ItemId']);
253 break;
254 case 'DeleteItem':
255 $Output = ShowDeleteItem($List, $_SESSION['ItemId']);
256 break;
257 case 'ViewItem':
258 $Output = ShowViewItem($List, $_SESSION['ItemId']);
259 break;
260 case 'AddItem':
261 $Output = ShowAddItem($List);
262 break;
263 case 'AddItemFinish':
264 $Output = ShowAddItemFinish($List);
265 break;
266 case 'ShowList':
267 default:
268 $Output = ShowList($List);
269 }
270 } else $Output = ShowList($List);
271 }
272 return($Output);
273}
274
275function LoadListDefinition()
276{
277 global $Database, $Lists;
278
279 $DbResult = $Database->select('SystemList', '*');
280 while($DbRow = $DbResult->fetch_assoc())
281 {
282 $Items = array();
283 $DbResult2 = $Database->select('SystemListItem', '`Name`, `TextBefore`, `TextAfter`, `Type`, `Default`, `Help`, `Required`, `Editable`, `VisibleInList`, `VisibleInPointer`', 'List='.$DbRow['Id']);
284 while($DbRow2 = $DbResult2->fetch_assoc())
285 {
286 $Items[$DbRow2['Name']] = $DbRow2;
287 }
288 $List = array(
289 'TableName' => $DbRow['TableName'],
290 'Title' => $DbRow['Title'],
291 'System' => $DbRow['System'],
292 'VisibleInMenu' => $DbRow['VisibleInMenu'],
293 'Items' => $Items,
294 );
295 $Lists[$List['TableName']] = $List;
296 }
297}
298
299?>
Note: See TracBrowser for help on using the repository browser.