| 1 | <?php | 
|---|
| 2 |  | 
|---|
| 3 | include_once('Types.php'); | 
|---|
| 4 | include_once('Classes.php'); | 
|---|
| 5 | include_once('Packages/Common/Common.php'); | 
|---|
| 6 |  | 
|---|
| 7 | function HumanDate(int $Time): string | 
|---|
| 8 | { | 
|---|
| 9 | return date('j.n.Y', $Time); | 
|---|
| 10 | } | 
|---|
| 11 |  | 
|---|
| 12 | function GetMicrotime(): string | 
|---|
| 13 | { | 
|---|
| 14 | list($Usec, $Sec) = explode(" ", microtime()); | 
|---|
| 15 | return (float)$Usec + (float)$Sec; | 
|---|
| 16 | } | 
|---|
| 17 |  | 
|---|
| 18 | function MakeLink(string $Target, string $Title): string | 
|---|
| 19 | { | 
|---|
| 20 | return '<a href="'.$Target.'">'.$Title.'</a>'; | 
|---|
| 21 | } | 
|---|
| 22 |  | 
|---|
| 23 | function Table(array $Table): string | 
|---|
| 24 | { | 
|---|
| 25 | $Result = '<table cellspacing="0" class="BasicTable">'; | 
|---|
| 26 | $Result .= '<tr>'; | 
|---|
| 27 | foreach ($Table['Header'] as $Item) | 
|---|
| 28 | $Result .= '<th>'.$Item.'</th>'; | 
|---|
| 29 | $Result .= '</tr>'; | 
|---|
| 30 | foreach ($Table['Rows'] as $Row) | 
|---|
| 31 | { | 
|---|
| 32 | $Result .= '<tr>'; | 
|---|
| 33 | foreach ($Row as $Item) | 
|---|
| 34 | $Result .= '<td>'.$Item.'</td>'; | 
|---|
| 35 | $Result .= '</tr>'; | 
|---|
| 36 | } | 
|---|
| 37 | $Result .= '</table>'; | 
|---|
| 38 | return $Result; | 
|---|
| 39 | } | 
|---|
| 40 |  | 
|---|
| 41 | function ShowEditTable(string $ClassName, array $Values): string | 
|---|
| 42 | { | 
|---|
| 43 | global $Classes, $Types; | 
|---|
| 44 | $Class = $Classes[$ClassName]; | 
|---|
| 45 | $Table = array( | 
|---|
| 46 | 'Header' => array('Položka', 'Hodnota'), | 
|---|
| 47 | 'Rows' => array(), | 
|---|
| 48 | ); | 
|---|
| 49 |  | 
|---|
| 50 | foreach ($Class as $Index => $Item) | 
|---|
| 51 | { | 
|---|
| 52 | if (!array_key_exists($Index, $Values)) $Values[$Index] = $Item['Default']; | 
|---|
| 53 | switch ($Item['Type']) | 
|---|
| 54 | { | 
|---|
| 55 | case 'Boolean': | 
|---|
| 56 | if ($Values[$Index] == 0) $Checked = ''; else $Checked = ' checked="yes"'; | 
|---|
| 57 | $Edit = '<input type="checkbox" name="'.$Index.'"'.$Checked.'>'; | 
|---|
| 58 | break; | 
|---|
| 59 | case 'String': | 
|---|
| 60 | $Edit = '<input type="text" name="'.$Index.'" value="'.$Values[$Index].'">'; | 
|---|
| 61 | break; | 
|---|
| 62 | case 'Integer': | 
|---|
| 63 | $Edit = '<input type="text" name="'.$Index.'" value="'.$Values[$Index].'">'; | 
|---|
| 64 | break; | 
|---|
| 65 | default: | 
|---|
| 66 | $Edit = 'Neznámý typ'; | 
|---|
| 67 | } | 
|---|
| 68 | array_push($Table['Rows'], array($Item['Caption'], $Edit)); | 
|---|
| 69 | } | 
|---|
| 70 | $Output = '<h3>Tabulka '.$ClassName.'</h3>'.Table($Table).MakeLink('?Operation=Add2', 'Přidat'); | 
|---|
| 71 | return $Output; | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | function ProcessURL(): array | 
|---|
| 75 | { | 
|---|
| 76 | if (array_key_exists('REDIRECT_QUERY_STRING', $_SERVER)) | 
|---|
| 77 | $PathString = $_SERVER['REDIRECT_QUERY_STRING']; | 
|---|
| 78 | else $PathString = ''; | 
|---|
| 79 | if (substr($PathString, -1, 1) == '/') $PathString = substr($PathString, 0, -1); | 
|---|
| 80 | $PathItems = explode('/', $PathString); | 
|---|
| 81 | if (array_key_exists('REQUEST_URI', $_SERVER) and (strpos($_SERVER['REQUEST_URI'], '?') !== false)) | 
|---|
| 82 | $_SERVER['QUERY_STRING'] = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], '?') + 1); | 
|---|
| 83 | else $_SERVER['QUERY_STRING'] = ''; | 
|---|
| 84 | parse_str($_SERVER['QUERY_STRING'], $_GET); | 
|---|
| 85 | return $PathItems; | 
|---|
| 86 | } | 
|---|
| 87 |  | 
|---|
| 88 | function GetQueryStringArray(string $QueryString): array | 
|---|
| 89 | { | 
|---|
| 90 | $Result = array(); | 
|---|
| 91 | $Parts = explode('&', $QueryString); | 
|---|
| 92 | foreach ($Parts as $Part) | 
|---|
| 93 | { | 
|---|
| 94 | if ($Part != '') | 
|---|
| 95 | { | 
|---|
| 96 | if (!strpos($Part, '=')) $Part .= '='; | 
|---|
| 97 | $Item = explode('=', $Part); | 
|---|
| 98 | $Result[$Item[0]] = $Item[1]; | 
|---|
| 99 | } | 
|---|
| 100 | } | 
|---|
| 101 | return $Result; | 
|---|
| 102 | } | 
|---|
| 103 |  | 
|---|
| 104 | function SetQueryStringArray(array $QueryStringArray): string | 
|---|
| 105 | { | 
|---|
| 106 | $Parts = array(); | 
|---|
| 107 | foreach ($QueryStringArray as $Index => $Item) | 
|---|
| 108 | { | 
|---|
| 109 | $Parts[] = $Index.'='.$Item; | 
|---|
| 110 | } | 
|---|
| 111 | return implode('&', $Parts); | 
|---|
| 112 | } | 
|---|