[3] | 1 | <?php
|
---|
| 2 | include('database.php');
|
---|
| 3 | include('types.php');
|
---|
| 4 | include('lists.php');
|
---|
| 5 | include('common.php');
|
---|
| 6 |
|
---|
[4] | 7 | function ShowList($List, $Column = '', $ParentId = 0)
|
---|
[3] | 8 | {
|
---|
| 9 | global $Database, $Types, $Config;
|
---|
| 10 |
|
---|
[4] | 11 | $Output = '<div>'.$List['Title'].'</div><table class="WideTable"><tr>';
|
---|
[3] | 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 |
|
---|
[4] | 19 | if(($Column != '') and ($ParentId != 0))
|
---|
| 20 | $Where = $Column.'='.$ParentId;
|
---|
[3] | 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);
|
---|
[4] | 41 | //echo($Database->LastQuery);
|
---|
[3] | 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 | {
|
---|
[4] | 53 | $ItemType = explode(':', $Item['Type']);
|
---|
| 54 | $Type = $Types[$ItemType[0]];
|
---|
| 55 | if(count($ItemType) > 1) $Type['Parameter'] = $ItemType[1];
|
---|
[3] | 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 | }
|
---|
[4] | 62 | $Output .= '<td><a href="?Action=ViewItem&TableId='.$List['TableName'].'&ItemId='.$DbRow['Id'].'">Zobrazit</a> <a href="?Action=EditItem&TableId='.$List['TableName'].'&ItemId='.$DbRow['Id'].'">Editovat</a> <a href="?Action=DeleteItem&TableId='.$List['TableName'].'&ItemId='.$DbRow['Id'].'">Smazat</a></td></tr>';
|
---|
[3] | 63 | }
|
---|
| 64 | $Output .= '</table>';
|
---|
[4] | 65 | $Output .= PagesList($Page, $TotalItemCount);
|
---|
| 66 | $Output .= '<a href="?Action=AddItem&TableId='.$List['TableName'].'">Přidat</a>';
|
---|
[3] | 67 | return($Output);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | function ShowEditItem($List, $Id)
|
---|
| 71 | {
|
---|
| 72 | global $Database, $Types;
|
---|
| 73 |
|
---|
[4] | 74 | $Output = '<form action="?Action=EditItemFinish&ItemId='.$Id.'" method="post"><table class="WideTable">';
|
---|
[3] | 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 | {
|
---|
[4] | 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 | }
|
---|
[3] | 93 | }
|
---|
| 94 | }
|
---|
[4] | 95 | $Output .= '</table><input type="submit" value="Uložit"></form><a href="?">Zpět</a>';
|
---|
[3] | 96 | return($Output);
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | function ShowEditItemFinish($List, $Id)
|
---|
| 100 | {
|
---|
| 101 | global $Database, $Types;
|
---|
| 102 |
|
---|
| 103 | $Values = array();
|
---|
| 104 | foreach($List['Items'] as $Index => $Item)
|
---|
| 105 | {
|
---|
[4] | 106 | $ItemType = explode(':', $Item['Type']);
|
---|
| 107 | if($ItemType[0] != 'PointerOneToMany')
|
---|
| 108 | {
|
---|
| 109 | $Values[$Index] = $_POST[$Index];
|
---|
| 110 | }
|
---|
[3] | 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 |
|
---|
| 119 | function ShowAddItem($List)
|
---|
| 120 | {
|
---|
| 121 | global $Database, $Types;
|
---|
| 122 |
|
---|
[4] | 123 | $Output = '<form action="?Action=AddItemFinish" method="post"><table class="WideTable">';
|
---|
[3] | 124 | $Output .= '<tr><th>Jméno položky</th><th>Hodnota</th></tr>';
|
---|
| 125 |
|
---|
| 126 | foreach($List['Items'] as $Index => $Item)
|
---|
| 127 | {
|
---|
[4] | 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 | }
|
---|
[3] | 140 | }
|
---|
[4] | 141 | $Output .= '</table><input type="submit" value="Přidat"></form><a href="?">Zpět</a>';
|
---|
[3] | 142 | return($Output);
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | function ShowAddItemFinish($List)
|
---|
| 146 | {
|
---|
| 147 | global $Database, $Types;
|
---|
| 148 |
|
---|
| 149 | $Values = array();
|
---|
| 150 | foreach($List['Items'] as $Index => $Item)
|
---|
| 151 | {
|
---|
[4] | 152 | $ItemType = explode(':', $Item['Type']);
|
---|
| 153 | if($ItemType[0] != 'PointerOneToMany')
|
---|
| 154 | {
|
---|
| 155 | $Values[$Index] = $_POST[$Index];
|
---|
| 156 | }
|
---|
[3] | 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 |
|
---|
| 165 | function ShowViewItem($List, $Id)
|
---|
| 166 | {
|
---|
[4] | 167 | global $Database, $Types, $Lists;
|
---|
[3] | 168 |
|
---|
[4] | 169 | $Output = '';
|
---|
[3] | 170 | $DbResult = $Database->select($List['TableName'], '*', 'Id='.$Id);
|
---|
| 171 | while($DbRow = $DbResult->fetch_array())
|
---|
| 172 | {
|
---|
[4] | 173 | $Output = '<table class="WideTable">';
|
---|
| 174 | $Output .= '<tr><th>Jméno položky</th><th>Hodnota</th></tr>';
|
---|
[3] | 175 | foreach($List['Items'] as $Index => $Item)
|
---|
| 176 | {
|
---|
[4] | 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 | }
|
---|
[3] | 187 | }
|
---|
[4] | 188 | $Output .= '</table>';
|
---|
| 189 | $Output .= '<a href="?Action=EditItem&ItemId='.$DbRow['Id'].'">Editovat</a>';
|
---|
| 190 | $Output .= ' <a href="?Action=ShowList&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 | }
|
---|
[3] | 202 | }
|
---|
| 203 | return($Output);
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 | function 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 |
|
---|
| 215 | function 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 | {
|
---|
[4] | 223 | if(($List['System'] == $System) and ($List['VisibleInMenu'] == 1))
|
---|
| 224 | $Output .= '<a href="?Action=ShowList&TableId='.$Index.'">'.$List['Title'].'</a><br />';
|
---|
[3] | 225 | }
|
---|
| 226 | $Output .= '<br />';
|
---|
| 227 | return($Output);
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | function Output()
|
---|
| 231 | {
|
---|
| 232 | global $Lists;
|
---|
| 233 |
|
---|
[4] | 234 | $PermanentVar = array('TableId', 'ItemId', 'ParentTable', 'ParentColumn', 'Action');
|
---|
| 235 | foreach($PermanentVar as $Var)
|
---|
[3] | 236 | {
|
---|
[4] | 237 | if(array_key_exists($Var, $_GET)) $_SESSION[$Var] = $_GET[$Var];
|
---|
[3] | 238 | }
|
---|
| 239 |
|
---|
[4] | 240 | $Output = '';
|
---|
| 241 | if(array_key_exists('TableId', $_SESSION) and array_key_exists($_SESSION['TableId'], $Lists))
|
---|
[3] | 242 | {
|
---|
[4] | 243 | $List = $Lists[$_SESSION['TableId']];
|
---|
| 244 | if(array_key_exists('Action', $_SESSION))
|
---|
[3] | 245 | {
|
---|
[4] | 246 | switch($_SESSION['Action'])
|
---|
[3] | 247 | {
|
---|
[4] | 248 | case 'EditItem':
|
---|
| 249 | $Output = ShowEditItem($List, $_SESSION['ItemId']);
|
---|
[3] | 250 | break;
|
---|
[4] | 251 | case 'EditItemFinish':
|
---|
| 252 | $Output = ShowEditItemFinish($List, $_SESSION['ItemId']);
|
---|
[3] | 253 | break;
|
---|
[4] | 254 | case 'DeleteItem':
|
---|
| 255 | $Output = ShowDeleteItem($List, $_SESSION['ItemId']);
|
---|
[3] | 256 | break;
|
---|
[4] | 257 | case 'ViewItem':
|
---|
| 258 | $Output = ShowViewItem($List, $_SESSION['ItemId']);
|
---|
[3] | 259 | break;
|
---|
[4] | 260 | case 'AddItem':
|
---|
[3] | 261 | $Output = ShowAddItem($List);
|
---|
| 262 | break;
|
---|
[4] | 263 | case 'AddItemFinish':
|
---|
[3] | 264 | $Output = ShowAddItemFinish($List);
|
---|
| 265 | break;
|
---|
[4] | 266 | case 'ShowList':
|
---|
[3] | 267 | default:
|
---|
| 268 | $Output = ShowList($List);
|
---|
| 269 | }
|
---|
| 270 | } else $Output = ShowList($List);
|
---|
| 271 | }
|
---|
| 272 | return($Output);
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | function LoadListDefinition()
|
---|
| 276 | {
|
---|
| 277 | global $Database, $Lists;
|
---|
| 278 |
|
---|
[4] | 279 | $DbResult = $Database->select('SystemList', '*');
|
---|
[3] | 280 | while($DbRow = $DbResult->fetch_assoc())
|
---|
| 281 | {
|
---|
| 282 | $Items = array();
|
---|
[4] | 283 | $DbResult2 = $Database->select('SystemListItem', '`Name`, `TextBefore`, `TextAfter`, `Type`, `Default`, `Help`, `Required`, `Editable`, `VisibleInList`, `VisibleInPointer`', 'List='.$DbRow['Id']);
|
---|
[3] | 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'],
|
---|
[4] | 292 | 'VisibleInMenu' => $DbRow['VisibleInMenu'],
|
---|
[3] | 293 | 'Items' => $Items,
|
---|
| 294 | );
|
---|
[4] | 295 | $Lists[$List['TableName']] = $List;
|
---|
[3] | 296 | }
|
---|
| 297 | }
|
---|
[4] | 298 |
|
---|
[3] | 299 | ?>
|
---|