1 | <?php
|
---|
2 |
|
---|
3 | function HumanDate($Time)
|
---|
4 | {
|
---|
5 | return date('j.n.Y', $Time);
|
---|
6 | }
|
---|
7 |
|
---|
8 | function HumanDateTime($Time)
|
---|
9 | {
|
---|
10 | return date('j.n.Y H:i:s', $Time);
|
---|
11 | }
|
---|
12 |
|
---|
13 | function Link2($URL)
|
---|
14 | {
|
---|
15 | global $Config;
|
---|
16 |
|
---|
17 | return $Config['BaseURL'].$URL;
|
---|
18 | }
|
---|
19 |
|
---|
20 | function GetRemoteAddress()
|
---|
21 | {
|
---|
22 | if (array_key_exists('REMOTE_ADDR', $_SERVER)) $IP = $_SERVER['REMOTE_ADDR'];
|
---|
23 | else $IP = '';
|
---|
24 | return $IP;
|
---|
25 | }
|
---|
26 |
|
---|
27 | function GetQueryStringArray($QueryString)
|
---|
28 | {
|
---|
29 | $Result = array();
|
---|
30 | $Parts = explode('&', $QueryString);
|
---|
31 | foreach ($Parts as $Part)
|
---|
32 | {
|
---|
33 | if ($Part != '')
|
---|
34 | {
|
---|
35 | if (!strpos($Part, '=')) $Part .= '=';
|
---|
36 | $Item = explode('=', $Part);
|
---|
37 | $Result[$Item[0]] = $Item[1];
|
---|
38 | }
|
---|
39 | }
|
---|
40 | return $Result;
|
---|
41 | }
|
---|
42 |
|
---|
43 | function SetQueryStringArray($QueryStringArray)
|
---|
44 | {
|
---|
45 | $Parts = array();
|
---|
46 | foreach ($QueryStringArray as $Index => $Item)
|
---|
47 | {
|
---|
48 | if ($Index != 'lvm') $Parts[] = $Index.'='.$Item;
|
---|
49 | }
|
---|
50 | return implode('&', $Parts);
|
---|
51 | }
|
---|
52 |
|
---|
53 | function GetPageList($TotalCount)
|
---|
54 | {
|
---|
55 | global $Config;
|
---|
56 |
|
---|
57 | $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
|
---|
58 |
|
---|
59 | $ItemPerPage = $Config['ItemsPerPage'];
|
---|
60 | $Around = round($Config['VisiblePagingItems'] / 2);
|
---|
61 | $Result = '';
|
---|
62 | $PageCount = floor($TotalCount / $ItemPerPage) + 1;
|
---|
63 |
|
---|
64 | if (!array_key_exists('Page', $_SESSION)) $_SESSION['Page'] = 0;
|
---|
65 | if (array_key_exists('page', $_GET)) $_SESSION['Page'] = $_GET['page'] * 1;
|
---|
66 | if ($_SESSION['Page'] < 0) $_SESSION['Page'] = 0;
|
---|
67 | if ($_SESSION['Page'] >= $PageCount) $_SESSION['Page'] = $PageCount - 1;
|
---|
68 | $CurrentPage = $_SESSION['Page'];
|
---|
69 |
|
---|
70 |
|
---|
71 | $Result .= 'Počet položek: <strong>'.$TotalCount.'</strong> Stránky: ';
|
---|
72 |
|
---|
73 | $Result = '';
|
---|
74 | if ($PageCount > 1)
|
---|
75 | {
|
---|
76 | if ($CurrentPage > 0)
|
---|
77 | {
|
---|
78 | $QueryItems['page'] = 0;
|
---|
79 | $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'"><<</a> ';
|
---|
80 | $QueryItems['page'] = ($CurrentPage - 1);
|
---|
81 | $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'"><</a> ';
|
---|
82 | }
|
---|
83 | $PagesMax = $PageCount - 1;
|
---|
84 | $PagesMin = 0;
|
---|
85 | if ($PagesMax > ($CurrentPage + $Around)) $PagesMax = $CurrentPage + $Around;
|
---|
86 | if ($PagesMin < ($CurrentPage - $Around))
|
---|
87 | {
|
---|
88 | $Result.= ' ... ';
|
---|
89 | $PagesMin = $CurrentPage - $Around;
|
---|
90 | }
|
---|
91 | for ($i = $PagesMin; $i <= $PagesMax; $i++)
|
---|
92 | {
|
---|
93 | if ($i == $CurrentPage) $Result.= '<strong>'.($i + 1).'</strong> ';
|
---|
94 | else {
|
---|
95 | $QueryItems['page'] = $i;
|
---|
96 | $Result .= '<a href="?'.SetQueryStringArray($QueryItems).'">'.($i + 1).'</a> ';
|
---|
97 | }
|
---|
98 | }
|
---|
99 | if ($PagesMax < ($PageCount - 1)) $Result .= ' ... ';
|
---|
100 | if ($CurrentPage < ($PageCount - 1))
|
---|
101 | {
|
---|
102 | $QueryItems['page'] = ($CurrentPage + 1);
|
---|
103 | $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">></a> ';
|
---|
104 | $QueryItems['page'] = ($PageCount - 1);
|
---|
105 | $Result.= '<a href="?'.SetQueryStringArray($QueryItems).'">>></a>';
|
---|
106 | }
|
---|
107 | }
|
---|
108 | $Result = '<div style="text-align: center">'.$Result.'</div>';
|
---|
109 | return array('SQLLimit' => ' LIMIT '.$CurrentPage * $ItemPerPage.', '.$ItemPerPage,
|
---|
110 | 'Page' => $CurrentPage,
|
---|
111 | 'Output' => $Result,
|
---|
112 | );
|
---|
113 | }
|
---|
114 |
|
---|
115 | $OrderDirSQL = array('ASC', 'DESC');
|
---|
116 | $OrderArrowImage = array('sort_asc.png', 'sort_desc.png');
|
---|
117 |
|
---|
118 | function GetOrderTableHeader($Columns, $DefaultColumn, $DefaultOrder = 0)
|
---|
119 | {
|
---|
120 | global $OrderDirSQL, $OrderArrowImage, $Config;
|
---|
121 |
|
---|
122 | if (array_key_exists('OrderCol', $_GET)) $_SESSION['OrderCol'] = $_GET['OrderCol'];
|
---|
123 | if (array_key_exists('OrderDir', $_GET) and (array_key_exists($_GET['OrderDir'], $OrderArrowImage)))
|
---|
124 | $_SESSION['OrderDir'] = $_GET['OrderDir'];
|
---|
125 | if (!array_key_exists('OrderCol', $_SESSION)) $_SESSION['OrderCol'] = $DefaultColumn;
|
---|
126 | if (!array_key_exists('OrderDir', $_SESSION)) $_SESSION['OrderDir'] = $DefaultOrder;
|
---|
127 |
|
---|
128 | // Check OrderCol
|
---|
129 | $Found = false;
|
---|
130 | foreach ($Columns as $Column)
|
---|
131 | {
|
---|
132 | if ($Column['Name'] == $_SESSION['OrderCol'])
|
---|
133 | {
|
---|
134 | $Found = true;
|
---|
135 | break;
|
---|
136 | }
|
---|
137 | }
|
---|
138 | if ($Found == false)
|
---|
139 | {
|
---|
140 | $_SESSION['OrderCol'] = $DefaultColumn;
|
---|
141 | $_SESSION['OrderDir'] = $DefaultOrder;
|
---|
142 | }
|
---|
143 | // Check OrderDir
|
---|
144 | if (($_SESSION['OrderDir'] != 0) and ($_SESSION['OrderDir'] != 1)) $_SESSION['OrderDir'] = 0;
|
---|
145 |
|
---|
146 | $Result = '';
|
---|
147 | $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
|
---|
148 | foreach ($Columns as $Index => $Column)
|
---|
149 | {
|
---|
150 | $QueryItems['OrderCol'] = $Column['Name'];
|
---|
151 | $QueryItems['OrderDir'] = 1 - $_SESSION['OrderDir'];
|
---|
152 | if ($Column['Name'] == $_SESSION['OrderCol']) $ArrowImage = '<img style="vertical-align: middle; border: 0px;" src="'.
|
---|
153 | Link2('/images/'.$OrderArrowImage[$_SESSION['OrderDir']]).'" alt="order arrow"/>';
|
---|
154 | else $ArrowImage = '';
|
---|
155 | if ($Column['Name'] == '') $Result .= '<th>'.$Column['Title'].'</th>';
|
---|
156 | else $Result .= '<th><a href="?'.SetQueryStringArray($QueryItems).'">'.$Column['Title'].$ArrowImage.'</a></th>';
|
---|
157 | }
|
---|
158 | return array(
|
---|
159 | 'SQL' => ' ORDER BY `'.$_SESSION['OrderCol'].'` '.$OrderDirSQL[$_SESSION['OrderDir']],
|
---|
160 | 'Output' => '<tr>'.$Result.'</tr>',
|
---|
161 | 'Column' => $_SESSION['OrderCol'],
|
---|
162 | 'Direction' => $_SESSION['OrderDir'],
|
---|
163 | );
|
---|
164 | }
|
---|