commit | author | age
|
fb02f0
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
|
5 |
All rights reserved. |
|
6 |
|
|
7 |
Redistribution and use in source and binary forms, with or without modification, |
|
8 |
are permitted provided that the following conditions are met: |
|
9 |
|
|
10 |
* Redistributions of source code must retain the above copyright notice, |
|
11 |
this list of conditions and the following disclaimer. |
|
12 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
13 |
this list of conditions and the following disclaimer in the documentation |
|
14 |
and/or other materials provided with the distribution. |
|
15 |
* Neither the name of ISPConfig nor the names of its contributors |
|
16 |
may be used to endorse or promote products derived from this software without |
|
17 |
specific prior written permission. |
|
18 |
|
|
19 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
20 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
21 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
22 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
23 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
24 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
26 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
27 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
28 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 |
*/ |
|
30 |
|
|
31 |
class listform { |
|
32 |
|
7fe908
|
33 |
private $debug = 0; |
MC |
34 |
private $errorMessage; |
|
35 |
public $listDef; |
|
36 |
public $searchValues; |
|
37 |
public $pagingHTML; |
|
38 |
private $pagingValues; |
|
39 |
private $searchChanged = 0; |
|
40 |
private $module; |
fb02f0
|
41 |
public $wordbook; |
T |
42 |
|
7fe908
|
43 |
public function loadListDef($file, $module = '') |
MC |
44 |
{ |
|
45 |
global $app, $conf; |
|
46 |
if(!is_file($file)){ |
|
47 |
die("List-Definition: $file not found."); |
fb02f0
|
48 |
} |
7fe908
|
49 |
require_once $file; |
MC |
50 |
$this->listDef = $liste; |
|
51 |
$this->module = $module; |
|
52 |
|
|
53 |
//* Fill datasources |
|
54 |
if(@is_array($this->listDef['item'])) { |
|
55 |
foreach($this->listDef['item'] as $key => $field) { |
|
56 |
if(@is_array($field['datasource'])) { |
|
57 |
$this->listDef['item'][$key]['value'] = $this->getDatasourceData($field); |
|
58 |
} |
|
59 |
} |
|
60 |
} |
|
61 |
|
fb02f0
|
62 |
//* Set local Language File |
5ded80
|
63 |
$lng_file = 'lib/lang/'.$_SESSION['s']['language'].'_'.$this->listDef['name'].'_list.lng'; |
F |
64 |
if(!file_exists($lng_file)) $lng_file = 'lib/lang/en_'.$this->listDef['name'].'_list.lng'; |
7fe908
|
65 |
include $lng_file; |
MC |
66 |
|
fb02f0
|
67 |
$this->wordbook = $wb; |
7fe908
|
68 |
|
MC |
69 |
return true; |
|
70 |
} |
|
71 |
|
fb02f0
|
72 |
/** |
7fe908
|
73 |
* Get the key => value array of a form filed from a datasource definitiom |
MC |
74 |
* |
|
75 |
* @param field = array with field definition |
|
76 |
* @param record = Dataset as array |
|
77 |
* @return array key => value array for the value field of a form |
|
78 |
*/ |
fb02f0
|
79 |
|
T |
80 |
|
7fe908
|
81 |
private function getDatasourceData($field) |
MC |
82 |
{ |
|
83 |
global $app; |
|
84 |
$values = array(); |
|
85 |
|
|
86 |
if($field['datasource']['type'] == 'SQL') { |
|
87 |
|
|
88 |
//** Preparing SQL string. We will replace some common placeholders |
|
89 |
$querystring = $field['datasource']['querystring']; |
|
90 |
$querystring = str_replace('{USERID}', $_SESSION['s']['user']['userid'], $querystring); |
|
91 |
$querystring = str_replace('{GROUPID}', $_SESSION['s']['user']['default_group'], $querystring); |
|
92 |
$querystring = str_replace('{GROUPS}', $_SESSION['s']['user']['groups'], $querystring); |
|
93 |
//TODO: |
|
94 |
//$table_idx = $this->formDef['db_table_idx']; |
|
95 |
//$querystring = str_replace("{RECORDID}",$record[$table_idx],$querystring); |
fb02f0
|
96 |
$app->uses('tform'); |
7fe908
|
97 |
$querystring = str_replace("{AUTHSQL}", $app->tform->getAuthSQL('r'), $querystring); |
MC |
98 |
$querystring = str_replace("{AUTHSQL-A}", $app->tform->getAuthSQL('r', 'a'), $querystring); |
|
99 |
$querystring = str_replace("{AUTHSQL-B}", $app->tform->getAuthSQL('r', 'b'), $querystring); |
53f0d2
|
100 |
$querystring = preg_replace_callback('@{AUTHSQL::(.+?)}@', create_function('$matches','global $app; $tmp = $app->tform->getAuthSQL("r", $matches[1]); return $tmp;'), $querystring); |
fb02f0
|
101 |
|
7fe908
|
102 |
//* Getting the records |
MC |
103 |
$tmp_records = $app->db->queryAllRecords($querystring); |
|
104 |
if($app->db->errorMessage != '') die($app->db->errorMessage); |
|
105 |
if(is_array($tmp_records)) { |
|
106 |
$key_field = $field['datasource']['keyfield']; |
|
107 |
$value_field = $field['datasource']['valuefield']; |
|
108 |
foreach($tmp_records as $tmp_rec) { |
|
109 |
$tmp_id = $tmp_rec[$key_field]; |
|
110 |
$values[$tmp_id] = $tmp_rec[$value_field]; |
|
111 |
} |
|
112 |
} |
|
113 |
} |
fb02f0
|
114 |
|
7fe908
|
115 |
if($field['datasource']['type'] == 'CUSTOM') { |
MC |
116 |
//* Calls a custom class to validate this record |
|
117 |
if($field['datasource']['class'] != '' and $field['datasource']['function'] != '') { |
|
118 |
$datasource_class = $field['datasource']['class']; |
|
119 |
$datasource_function = $field['datasource']['function']; |
|
120 |
$app->uses($datasource_class); |
fb02f0
|
121 |
$record = array(); |
7fe908
|
122 |
$values = $app->$datasource_class->$datasource_function($field, $record); |
MC |
123 |
} else { |
|
124 |
$this->errorMessage .= "Custom datasource class or function is empty<br />\r\n"; |
|
125 |
} |
|
126 |
} |
a9b325
|
127 |
|
MC |
128 |
if($api == false && isset($field['filters']) && is_array($field['filters'])) { |
|
129 |
$new_values = array(); |
|
130 |
foreach($values as $index => $value) { |
|
131 |
$new_index = $app->tform->filterField($index, $index, $field['filters'], 'SHOW'); |
|
132 |
$new_values[$new_index] = $app->tform->filterField($index, (isset($values[$index]))?$values[$index]:'', $field['filters'], 'SHOW'); |
|
133 |
} |
|
134 |
$values = $new_values; |
|
135 |
unset($new_values); |
|
136 |
unset($new_index); |
|
137 |
} |
7fe908
|
138 |
return $values; |
MC |
139 |
} |
fb02f0
|
140 |
|
7fe908
|
141 |
public function getSearchSQL($sql_where = '') |
MC |
142 |
{ |
|
143 |
global $app, $db; |
fb02f0
|
144 |
|
7fe908
|
145 |
//* Get config variable |
MC |
146 |
$list_name = $this->listDef['name']; |
|
147 |
$search_prefix = $this->listDef['search_prefix']; |
|
148 |
|
a59ad3
|
149 |
if(isset($_REQUEST['Filter']) && !isset($_SESSION['search'][$list_name])) { |
T |
150 |
//* Jump back to page 1 of the list when a new search gets started. |
|
151 |
$_SESSION['search'][$list_name]['page'] = 0; |
|
152 |
} |
fb02f0
|
153 |
|
7fe908
|
154 |
//* store retrieval query |
MC |
155 |
if(@is_array($this->listDef['item'])) { |
|
156 |
foreach($this->listDef['item'] as $i) { |
|
157 |
$field = $i['field']; |
fb02f0
|
158 |
|
7fe908
|
159 |
//* The search string has been changed |
MC |
160 |
if(isset($_REQUEST[$search_prefix.$field]) && isset($_SESSION['search'][$list_name][$search_prefix.$field]) && $_REQUEST[$search_prefix.$field] != $_SESSION['search'][$list_name][$search_prefix.$field]){ |
|
161 |
$this->searchChanged = 1; |
fb02f0
|
162 |
|
7fe908
|
163 |
//* Jump back to page 1 of the list when search has changed. |
MC |
164 |
$_SESSION['search'][$list_name]['page'] = 0; |
|
165 |
} |
|
166 |
|
|
167 |
//* Store field in session |
|
168 |
if(isset($_REQUEST[$search_prefix.$field]) && !stristr($_REQUEST[$search_prefix.$field], "'")){ |
|
169 |
$_SESSION['search'][$list_name][$search_prefix.$field] = $_REQUEST[$search_prefix.$field]; |
86985d
|
170 |
if(preg_match("/['\\\\]/", $_SESSION['search'][$list_name][$search_prefix.$field])) $_SESSION['search'][$list_name][$search_prefix.$field] = ''; |
T |
171 |
} |
fb02f0
|
172 |
|
7fe908
|
173 |
if(isset($i['formtype']) && $i['formtype'] == 'SELECT'){ |
MC |
174 |
if(is_array($i['value'])) { |
|
175 |
$out = '<option value=""></option>'; |
|
176 |
foreach($i['value'] as $k => $v) { |
|
177 |
// TODO: this could be more elegant |
|
178 |
$selected = (isset($_SESSION['search'][$list_name][$search_prefix.$field]) |
|
179 |
&& $k == $_SESSION['search'][$list_name][$search_prefix.$field] |
|
180 |
&& $_SESSION['search'][$list_name][$search_prefix.$field] != '') |
|
181 |
? ' SELECTED' : ''; |
|
182 |
$out .= "<option value='$k'$selected>$v</option>\r\n"; |
|
183 |
} |
|
184 |
} |
|
185 |
$this->searchValues[$search_prefix.$field] = $out; |
|
186 |
} else { |
|
187 |
if(isset($_SESSION['search'][$list_name][$search_prefix.$field])){ |
|
188 |
$this->searchValues[$search_prefix.$field] = htmlspecialchars($_SESSION['search'][$list_name][$search_prefix.$field]); |
|
189 |
} |
|
190 |
} |
|
191 |
} |
|
192 |
} |
|
193 |
//* Store variables in object | $this->searchValues = $_SESSION["search"][$list_name]; |
|
194 |
if(@is_array($this->listDef['item'])) { |
|
195 |
foreach($this->listDef['item'] as $i) { |
|
196 |
$field = $i['field']; |
615a0a
|
197 |
$table = $i['table']; |
7fe908
|
198 |
|
2d2fd1
|
199 |
$searchval = $_SESSION['search'][$list_name][$search_prefix.$field]; |
e9d5c9
|
200 |
// IDN |
MC |
201 |
if($searchval != ''){ |
|
202 |
foreach($i['filters'] as $searchval_filter) { |
|
203 |
if($searchval_filter['event'] == 'SHOW') { |
|
204 |
switch ($searchval_filter['type']) { |
|
205 |
case 'IDNTOUTF8': |
|
206 |
$searchval = $app->functions->idn_encode($searchval); |
|
207 |
//echo $searchval; |
|
208 |
break; |
|
209 |
} |
|
210 |
} |
|
211 |
} |
|
212 |
} |
|
213 |
|
2d2fd1
|
214 |
// format user date format to MySQL date format 0000-00-00 |
FT |
215 |
if($i['datatype'] == 'DATE' && $this->lng('conf_format_dateshort') != 'Y-m-d'){ |
|
216 |
$dateformat = preg_replace("@[^Ymd]@", "", $this->lng('conf_format_dateshort')); |
|
217 |
$yearpos = strpos($dateformat, 'Y') + 1; |
|
218 |
$monthpos = strpos($dateformat, 'm') + 1; |
|
219 |
$daypos = strpos($dateformat, 'd') + 1; |
7fe908
|
220 |
|
MC |
221 |
$full_date_trans = array ('Y' => '((?:19|20)\d\d)', |
|
222 |
'm' => '(0[1-9]|1[012])', |
|
223 |
'd' => '(0[1-9]|[12][0-9]|3[01])' |
|
224 |
); |
|
225 |
// d.m.Y Y/m/d |
2d2fd1
|
226 |
$full_date_regex = strtr(preg_replace("@[^Ymd]@", "[^0-9]", $this->lng('conf_format_dateshort')), $full_date_trans); |
FT |
227 |
//echo $full_date_regex; |
7fe908
|
228 |
|
2d2fd1
|
229 |
if (preg_match("@^\d+$@", $_SESSION['search'][$list_name][$search_prefix.$field])) { // we just have digits |
FT |
230 |
$searchval = $_SESSION['search'][$list_name][$search_prefix.$field]; |
|
231 |
} elseif(preg_match("@^[^0-9]?\d+[^0-9]?$@", $_SESSION['search'][$list_name][$search_prefix.$field])){ // 10. or .10. |
|
232 |
$searchval = preg_replace("@[^0-9]@", "", $_SESSION['search'][$list_name][$search_prefix.$field]); |
|
233 |
} elseif(preg_match("@^[^0-9]?(\d{1,2})[^0-9]((?:19|20)\d\d)$@", $_SESSION['search'][$list_name][$search_prefix.$field], $matches)){ // 10.2013 |
|
234 |
$month = $matches[1]; |
|
235 |
$year = $matches[2]; |
|
236 |
$searchval = $year.'-'.$month; |
|
237 |
} elseif(preg_match("@^((?:19|20)\d\d)[^0-9](\d{1,2})[^0-9]?$@", $_SESSION['search'][$list_name][$search_prefix.$field], $matches)){ // 2013-10 |
|
238 |
$month = $matches[2]; |
|
239 |
$year = $matches[1]; |
|
240 |
$searchval = $year.'-'.$month; |
|
241 |
} elseif(preg_match("@^[^0-9]?(\d{1,2})[^0-9](\d{1,2})[^0-9]?$@", $_SESSION['search'][$list_name][$search_prefix.$field], $matches)){ // 04.10. |
|
242 |
if($monthpos < $daypos){ |
7fe908
|
243 |
$month = $matches[1]; |
MC |
244 |
$day = $matches[2]; |
2d2fd1
|
245 |
} else { |
FT |
246 |
$month = $matches[2]; |
|
247 |
$day = $matches[1]; |
|
248 |
} |
|
249 |
$searchval = $month.'-'.$day; |
|
250 |
} elseif (preg_match("@^".$full_date_regex."$@", $_SESSION['search'][$list_name][$search_prefix.$field], $matches)) { |
|
251 |
//print_r($matches); |
|
252 |
$day = $matches[$daypos]; |
|
253 |
$month = $matches[$monthpos]; |
|
254 |
$year = $matches[$yearpos]; |
|
255 |
$searchval = $year.'-'.$month.'-'.$day; |
|
256 |
} |
|
257 |
} |
7fe908
|
258 |
|
MC |
259 |
// if($_REQUEST[$search_prefix.$field] != '') $sql_where .= " $field ".$i["op"]." '".$i["prefix"].$_REQUEST[$search_prefix.$field].$i["suffix"]."' and"; |
|
260 |
if(isset($searchval) && $searchval != ''){ |
|
261 |
$sql_where .= " ".($table != ''? $table.'.' : $this->listDef['table'].'.')."$field ".$i['op']." '".$app->db->quote($i['prefix'].$searchval.$i['suffix'])."' and"; |
|
262 |
} |
|
263 |
} |
|
264 |
} |
|
265 |
return ( $sql_where != '' ) ? $sql_where = substr($sql_where, 0, -3) : '1'; |
|
266 |
} |
|
267 |
|
202df8
|
268 |
public function getPagingValue($key) { |
MC |
269 |
if(!is_array($this->pagingValues)) return null; |
|
270 |
if(!array_key_exists($key, $this->pagingValues)) return null; |
|
271 |
return $this->pagingValues[$key]; |
|
272 |
} |
7fe908
|
273 |
|
2af58c
|
274 |
/* TODO: maybe rewrite sql */ |
7fe908
|
275 |
public function getPagingSQL($sql_where = '1') |
MC |
276 |
{ |
|
277 |
global $app, $conf; |
e03212
|
278 |
|
TB |
279 |
$old_search_limit = intval($_SESSION['search']['limit']); |
7fe908
|
280 |
|
7b47c0
|
281 |
//* Add Global Limit from selectbox |
7fe908
|
282 |
if(!empty($_POST['search_limit']) and $app->functions->intval($_POST['search_limit']) > 0){ |
65ea2e
|
283 |
$_SESSION['search']['limit'] = $app->functions->intval($_POST['search_limit']); |
26c0fc
|
284 |
} |
7fe908
|
285 |
|
992797
|
286 |
//if(preg_match('{^[0-9]$}',$_SESSION['search']['limit'])){ |
7fe908
|
287 |
// $_SESSION['search']['limit'] = 15; |
992797
|
288 |
//} |
MC |
289 |
if(intval($_SESSION['search']['limit']) < 1) $_SESSION['search']['limit'] = 15; |
fb02f0
|
290 |
|
7fe908
|
291 |
//* Get Config variables |
MC |
292 |
$list_name = $this->listDef['name']; |
|
293 |
$search_prefix = $this->listDef['search_prefix']; |
|
294 |
$records_per_page = (empty($_SESSION['search']['limit']) ? $app->functions->intval($this->listDef['records_per_page']) : $app->functions->intval($_SESSION['search']['limit'])) ; |
|
295 |
$table = $this->listDef['table']; |
fb02f0
|
296 |
|
7fe908
|
297 |
//* set PAGE to zero, if in session not set |
MC |
298 |
if(!isset($_SESSION['search'][$list_name]['page']) || $_SESSION['search'][$list_name]['page'] == ''){ |
|
299 |
$_SESSION['search'][$list_name]['page'] = 0; |
|
300 |
} |
fb02f0
|
301 |
|
7fe908
|
302 |
//* set PAGE to worth request variable "PAGE" - ? setze page auf wert der request variablen "page" |
MC |
303 |
if(isset($_REQUEST["page"])) $_SESSION["search"][$list_name]["page"] = $app->functions->intval($_REQUEST["page"]); |
e03212
|
304 |
|
TB |
305 |
//* Set search to changed when search limit has been changed. |
|
306 |
if(intval($_SESSION['search']['limit']) != $old_search_limit) $this->searchChanged = 1; |
fb02f0
|
307 |
|
7fe908
|
308 |
//* PAGE to 0 set, if look for themselves ? page auf 0 setzen, wenn suche sich ge�ndert hat. |
MC |
309 |
if($this->searchChanged == 1) $_SESSION['search'][$list_name]['page'] = 0; |
fb02f0
|
310 |
|
7fe908
|
311 |
$sql_von = $app->functions->intval($_SESSION['search'][$list_name]['page'] * $records_per_page); |
2af58c
|
312 |
$record_count = $app->db->queryOneRecord("SELECT count(*) AS anzahl FROM ??".($app->listform->listDef['additional_tables'] != ''? ','.$app->listform->listDef['additional_tables'] : '')." WHERE $sql_where", $table); |
7fe908
|
313 |
$pages = $app->functions->intval(($record_count['anzahl'] - 1) / $records_per_page); |
fb02f0
|
314 |
|
T |
315 |
|
7fe908
|
316 |
$vars['list_file'] = $_SESSION['s']['module']['name'].'/'.$this->listDef['file']; |
MC |
317 |
$vars['page'] = $_SESSION['search'][$list_name]['page']; |
|
318 |
$vars['last_page'] = $_SESSION['search'][$list_name]['page'] - 1; |
|
319 |
$vars['next_page'] = $_SESSION['search'][$list_name]['page'] + 1; |
|
320 |
$vars['pages'] = $pages; |
|
321 |
$vars['max_pages'] = $pages + 1; |
|
322 |
$vars['records_gesamt'] = $record_count['anzahl']; |
|
323 |
$vars['page_params'] = (isset($this->listDef['page_params'])) ? $this->listDef['page_params'] : ''; |
|
324 |
$vars['offset'] = $sql_von; |
|
325 |
$vars['records_per_page'] = $records_per_page; |
|
326 |
//$vars['module'] = $_SESSION['s']['module']['name']; |
fb02f0
|
327 |
|
7fe908
|
328 |
if($_SESSION['search'][$list_name]['page'] > 0) $vars['show_page_back'] = 1; |
MC |
329 |
if($_SESSION['search'][$list_name]['page'] <= $vars['pages'] - 1) $vars['show_page_next'] = 1; |
fb02f0
|
330 |
|
7fe908
|
331 |
$this->pagingValues = $vars; |
MC |
332 |
$this->pagingHTML = $this->getPagingHTML($vars); |
fb02f0
|
333 |
|
7fe908
|
334 |
//* Return limit sql |
MC |
335 |
return "LIMIT $sql_von, $records_per_page"; |
|
336 |
} |
fb02f0
|
337 |
|
7fe908
|
338 |
public function getPagingHTML($vars) |
MC |
339 |
{ |
|
340 |
global $app; |
|
341 |
|
|
342 |
// we want to show at max 17 page numbers (8 left, current, 8 right) |
|
343 |
$show_pages_count = 17; |
|
344 |
|
|
345 |
$show_pages = array(0); // first page |
|
346 |
if($vars['pages'] > 0) $show_pages[] = $vars['pages']; // last page |
|
347 |
for($p = $vars['page'] - 2; $p <= $vars['page'] + 2; $p++) { // surrounding pages |
|
348 |
if($p > 0 && $p < $vars['pages']) $show_pages[] = $p; |
|
349 |
} |
|
350 |
|
|
351 |
$l_start = $vars['page'] - 13; |
|
352 |
$l_start -= ($l_start % 10) + 1; |
|
353 |
$h_end = $vars['page'] + 23; |
|
354 |
$h_end -= ($h_end % 10) + 1; |
|
355 |
for($p = $l_start; $p <= $h_end; $p += 10) { // surrounding pages |
|
356 |
if($p > 0 && $p < $vars['pages'] && !in_array($p, $show_pages, true) && count($show_pages) < $show_pages_count) $show_pages[] = $p; |
|
357 |
} |
|
358 |
|
|
359 |
$l_start = $vars['page'] - 503; |
|
360 |
$l_start -= ($l_start % 100) + 1; |
|
361 |
$h_end = $vars['page'] + 603; |
|
362 |
$h_end -= ($h_end % 100) + 1; |
|
363 |
for($p = $l_start; $p <= $h_end; $p += 100) { // surrounding pages |
|
364 |
if($p > 0 && $p < $vars['pages'] && !in_array($p, $show_pages, true) && count($show_pages) < $show_pages_count) $show_pages[] = $p; |
|
365 |
} |
|
366 |
|
|
367 |
$l_start = $vars['page'] - 203; |
|
368 |
$l_start -= ($l_start % 25) + 1; |
|
369 |
$h_end = $vars['page'] + 228; |
|
370 |
$h_end -= ($h_end % 25) + 1; |
|
371 |
for($p = $l_start; $p <= $h_end; $p += 25) { // surrounding pages |
|
372 |
if($p > 0 && $p < $vars['pages'] && abs($p - $vars['page']) > 30 && !in_array($p, $show_pages, true) && count($show_pages) < $show_pages_count) $show_pages[] = $p; |
|
373 |
} |
|
374 |
|
|
375 |
sort($show_pages); |
|
376 |
$show_pages = array_unique($show_pages); |
8ceb08
|
377 |
|
MC |
378 |
$content = '<nav> |
|
379 |
<ul class="pagination">'; |
|
380 |
|
7fe908
|
381 |
//* Show Back |
MC |
382 |
if(isset($vars['show_page_back']) && $vars['show_page_back'] == 1){ |
9021d7
|
383 |
$content .= '<li><a href="#" data-load-content="'.$vars['list_file'].'?page=0'.$vars['page_params'].'" aria-label="First"> |
8ceb08
|
384 |
<span aria-hidden="true">«</span></a></li>'; |
9021d7
|
385 |
$content .= '<li><a href="#" data-load-content='.$vars['list_file'].'?page='.$vars['last_page'].$vars['page_params'].'" aria-label="Previous"> |
8ceb08
|
386 |
<span aria-hidden="true">‹</span></a></li>'; |
7fe908
|
387 |
} |
MC |
388 |
$prev = -1; |
|
389 |
foreach($show_pages as $p) { |
8ceb08
|
390 |
if($prev != -1 && $p > $prev + 1) $content .= '<li class="disabled"><a href="#">…</a></li>'; |
9021d7
|
391 |
$content .= '<li' . ($p == $vars['page'] ? ' class="active"' : '') . '><a href="#" data-load-content="'.$vars['list_file'].'?page='.$p.$vars['page_params'].'">'. ($p+1) .'</a></li>'; |
7fe908
|
392 |
$prev = $p; |
MC |
393 |
} |
|
394 |
//.$vars['next_page'].' '.$this->lng('page_of_txt').' '.$vars['max_pages'].' '; |
|
395 |
//* Show Next |
|
396 |
if(isset($vars['show_page_next']) && $vars['show_page_next'] == 1){ |
9021d7
|
397 |
$content .= '<li><a href="#" data-load-content="'.$vars['list_file'].'?page='.$vars['next_page'].$vars['page_params'].'" aria-label="Next"> |
8ceb08
|
398 |
<span aria-hidden="true">›</span></a></li>'; |
9021d7
|
399 |
$content .= '<li><a href="#" data-load-content="'.$vars['list_file'].'?page='.$vars['pages'].$vars['page_params'].'" aria-label="Last"> |
8ceb08
|
400 |
<span aria-hidden="true">»</span></a></li>'; |
7fe908
|
401 |
} |
8ceb08
|
402 |
$content .= '</ul></nav>'; |
MC |
403 |
|
7fe908
|
404 |
return $content; |
MC |
405 |
} |
|
406 |
|
fb02f0
|
407 |
public function getPagingHTMLasTXT($vars) |
7fe908
|
408 |
{ |
MC |
409 |
global $app; |
|
410 |
$content = '[<a href="'.$vars['list_file'].'?page=0'.$vars['page_params'].'">|<< </a>]'; |
|
411 |
if($vars['show_page_back'] == 1){ |
|
412 |
$content .= '[<< <a href="'.$vars['list_file'].'?page='.$vars['last_page'].$vars['page_params'].'">'.$app->lng('page_back_txt').'</a>] '; |
|
413 |
} |
|
414 |
$content .= ' '.$this->lng('page_txt').' '.$vars['next_page'].' '.$this->lng('page_of_txt').' '.$vars['max_pages'].' '; |
|
415 |
if($vars['show_page_next'] == 1){ |
|
416 |
$content .= '[<a href="'.$vars['list_file'].'?page='.$vars['next_page'].$vars['page_params'].'">'.$app->lng('page_next_txt').' >></a>] '; |
|
417 |
} |
|
418 |
$content .= '[<a href="'.$vars['list_file'].'?page='.$vars['pages'].$vars['page_params'].'"> >>|</a>]'; |
|
419 |
return $content; |
|
420 |
} |
fb02f0
|
421 |
|
7fe908
|
422 |
public function getSortSQL() |
MC |
423 |
{ |
|
424 |
global $app, $conf; |
|
425 |
//* Get config vars |
|
426 |
$sort_field = $this->listDef['sort_field']; |
|
427 |
$sort_direction = $this->listDef['sort_direction']; |
|
428 |
return ($sort_field != '' && $sort_direction != '') ? "ORDER BY $sort_field $sort_direction" : ''; |
|
429 |
} |
fb02f0
|
430 |
|
7fe908
|
431 |
public function decode($record) |
MC |
432 |
{ |
|
433 |
global $conf, $app; |
|
434 |
if(is_array($record) && count($record) > 0 && is_array($this->listDef['item'])) { |
|
435 |
foreach($this->listDef['item'] as $field){ |
|
436 |
$key = $field['field']; |
|
437 |
//* Apply filter to record value. |
|
438 |
if(isset($field['filters']) && is_array($field['filters'])) { |
|
439 |
$app->uses('tform'); |
|
440 |
$record[$key] = $app->tform->filterField($key, (isset($record[$key]))?$record[$key]:'', $field['filters'], 'SHOW'); |
fb02f0
|
441 |
} |
7fe908
|
442 |
if(isset($record[$key])) { |
MC |
443 |
switch ($field['datatype']){ |
|
444 |
case 'VARCHAR': |
|
445 |
case 'TEXT': |
|
446 |
$record[$key] = htmlentities(stripslashes($record[$key]), ENT_QUOTES, $conf["html_content_encoding"]); |
|
447 |
break; |
fb02f0
|
448 |
|
57540e
|
449 |
case 'DATETSTAMP': |
7fe908
|
450 |
if ($record[$key] > 0) { |
MC |
451 |
// is value int? |
|
452 |
if (preg_match("/^[0-9]+[\.]?[0-9]*$/", $record[$key], $p)) { |
|
453 |
$record[$key] = date($this->lng('conf_format_dateshort'), $record[$key]); |
|
454 |
} else { |
|
455 |
$record[$key] = date($this->lng('conf_format_dateshort'), strtotime($record[$key])); |
|
456 |
} |
|
457 |
} |
|
458 |
break; |
615a0a
|
459 |
case 'DATETIMETSTAMP': |
7fe908
|
460 |
if ($record[$key] > 0) { |
MC |
461 |
// is value int? |
|
462 |
if (preg_match("/^[0-9]+[\.]?[0-9]*$/", $record[$key], $p)) { |
|
463 |
$record[$key] = date($this->lng('conf_format_datetime'), $record[$key]); |
|
464 |
} else { |
|
465 |
$record[$key] = date($this->lng('conf_format_datetime'), strtotime($record[$key])); |
|
466 |
} |
|
467 |
} |
|
468 |
break; |
|
469 |
case 'DATE': |
|
470 |
if ($record[$key] > 0) { |
|
471 |
// is value int? |
|
472 |
if (preg_match("/^[0-9]+[\.]?[0-9]*$/", $record[$key], $p)) { |
|
473 |
$record[$key] = date($this->lng('conf_format_dateshort'), $record[$key]); |
|
474 |
} else { |
|
475 |
$record[$key] = date($this->lng('conf_format_dateshort'), strtotime($record[$key])); |
|
476 |
} |
|
477 |
} |
|
478 |
break; |
e11f5d
|
479 |
|
7fe908
|
480 |
case 'DATETIME': |
MC |
481 |
if ($record[$key] > 0) { |
|
482 |
// is value int? |
|
483 |
if (preg_match("/^[0-9]+[\.]?[0-9]*$/", $record[$key], $p)) { |
|
484 |
$record[$key] = date($this->lng('conf_format_datetime'), $record[$key]); |
|
485 |
} else { |
|
486 |
$record[$key] = date($this->lng('conf_format_datetime'), strtotime($record[$key])); |
|
487 |
} |
|
488 |
} |
|
489 |
break; |
fb02f0
|
490 |
|
7fe908
|
491 |
case 'INTEGER': |
MC |
492 |
$record[$key] = $app->functions->intval($record[$key]); |
|
493 |
break; |
fb02f0
|
494 |
|
7fe908
|
495 |
case 'DOUBLE': |
MC |
496 |
$record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf["html_content_encoding"]); |
|
497 |
break; |
fb02f0
|
498 |
|
7fe908
|
499 |
case 'CURRENCY': |
MC |
500 |
$record[$key] = $app->functions->currency_format($record[$key]); |
|
501 |
break; |
|
502 |
|
|
503 |
default: |
|
504 |
$record[$key] = htmlentities(stripslashes($record[$key]), ENT_QUOTES, $conf["html_content_encoding"]); |
|
505 |
} |
|
506 |
} |
|
507 |
} |
|
508 |
} |
|
509 |
return $record; |
|
510 |
} |
2af58c
|
511 |
|
MC |
512 |
/* TODO: check double quoting of SQL */ |
7fe908
|
513 |
public function encode($record) |
MC |
514 |
{ |
|
515 |
global $app; |
|
516 |
if(is_array($record)) { |
|
517 |
foreach($this->listDef['item'] as $field){ |
|
518 |
$key = $field['field']; |
|
519 |
switch($field['datatype']){ |
|
520 |
|
|
521 |
case 'VARCHAR': |
|
522 |
case 'TEXT': |
|
523 |
if(!is_array($record[$key])) { |
|
524 |
$record[$key] = $app->db->quote($record[$key]); |
|
525 |
} else { |
|
526 |
$record[$key] = implode($this->tableDef[$key]['separator'], $record[$key]); |
|
527 |
} |
|
528 |
break; |
|
529 |
|
|
530 |
case 'DATETSTAMP': |
|
531 |
if($record[$key] > 0) { |
|
532 |
$record[$key] = date('Y-m-d', strtotime($record[$key])); |
|
533 |
} |
|
534 |
break; |
|
535 |
|
|
536 |
case 'DATETIMETSTAMP': |
|
537 |
if($record[$key] > 0) { |
|
538 |
$record[$key] = date('Y-m-d H:i:s', strtotime($record[$key])); |
|
539 |
} |
|
540 |
break; |
|
541 |
|
|
542 |
case 'DATE': |
|
543 |
if($record[$key] != '' && $record[$key] != '0000-00-00') { |
|
544 |
$record[$key] = $record[$key]; |
|
545 |
} |
|
546 |
break; |
|
547 |
|
|
548 |
case 'DATETIME': |
|
549 |
if($record[$key] > 0) { |
|
550 |
$record[$key] = date('Y-m-d H:i:s', strtotime($record[$key])); |
|
551 |
} |
|
552 |
break; |
|
553 |
|
|
554 |
case 'INTEGER': |
|
555 |
$record[$key] = $app->functions->intval($record[$key]); |
|
556 |
break; |
|
557 |
|
|
558 |
case 'DOUBLE': |
|
559 |
$record[$key] = $app->db->quote($record[$key]); |
|
560 |
break; |
|
561 |
|
|
562 |
case 'CURRENCY': |
|
563 |
$record[$key] = str_replace(',', '.', $record[$key]); |
|
564 |
break; |
|
565 |
} |
|
566 |
} |
|
567 |
} |
|
568 |
return $record; |
|
569 |
} |
|
570 |
|
fb02f0
|
571 |
function lng($msg) { |
T |
572 |
global $app; |
7fe908
|
573 |
|
fb02f0
|
574 |
if(isset($this->wordbook[$msg])) { |
T |
575 |
return $this->wordbook[$msg]; |
|
576 |
} else { |
|
577 |
return $app->lng($msg); |
7fe908
|
578 |
} |
fb02f0
|
579 |
} |
7fe908
|
580 |
|
ae69e6
|
581 |
function escapeArrayValues($search_values) { |
7fe908
|
582 |
global $conf; |
MC |
583 |
|
ae69e6
|
584 |
$out = array(); |
T |
585 |
if(is_array($search_values)) { |
|
586 |
foreach($search_values as $key => $val) { |
7fe908
|
587 |
$out[$key] = htmlentities($val, ENT_QUOTES, $conf["html_content_encoding"]); |
ae69e6
|
588 |
} |
T |
589 |
} |
7fe908
|
590 |
|
ae69e6
|
591 |
return $out; |
7fe908
|
592 |
|
ae69e6
|
593 |
} |
fb02f0
|
594 |
|
T |
595 |
} |
|
596 |
|
7fe908
|
597 |
?> |