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 |
} |
|
127 |
return $values; |
|
128 |
} |
fb02f0
|
129 |
|
7fe908
|
130 |
public function getSearchSQL($sql_where = '') |
MC |
131 |
{ |
|
132 |
global $app, $db; |
fb02f0
|
133 |
|
7fe908
|
134 |
//* Get config variable |
MC |
135 |
$list_name = $this->listDef['name']; |
|
136 |
$search_prefix = $this->listDef['search_prefix']; |
|
137 |
|
a59ad3
|
138 |
if(isset($_REQUEST['Filter']) && !isset($_SESSION['search'][$list_name])) { |
T |
139 |
//* Jump back to page 1 of the list when a new search gets started. |
|
140 |
$_SESSION['search'][$list_name]['page'] = 0; |
|
141 |
} |
fb02f0
|
142 |
|
7fe908
|
143 |
//* store retrieval query |
MC |
144 |
if(@is_array($this->listDef['item'])) { |
|
145 |
foreach($this->listDef['item'] as $i) { |
|
146 |
$field = $i['field']; |
fb02f0
|
147 |
|
7fe908
|
148 |
//* The search string has been changed |
MC |
149 |
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]){ |
|
150 |
$this->searchChanged = 1; |
fb02f0
|
151 |
|
7fe908
|
152 |
//* Jump back to page 1 of the list when search has changed. |
MC |
153 |
$_SESSION['search'][$list_name]['page'] = 0; |
|
154 |
} |
|
155 |
|
|
156 |
//* Store field in session |
|
157 |
if(isset($_REQUEST[$search_prefix.$field]) && !stristr($_REQUEST[$search_prefix.$field], "'")){ |
|
158 |
$_SESSION['search'][$list_name][$search_prefix.$field] = $_REQUEST[$search_prefix.$field]; |
86985d
|
159 |
if(preg_match("/['\\\\]/", $_SESSION['search'][$list_name][$search_prefix.$field])) $_SESSION['search'][$list_name][$search_prefix.$field] = ''; |
T |
160 |
} |
fb02f0
|
161 |
|
7fe908
|
162 |
if(isset($i['formtype']) && $i['formtype'] == 'SELECT'){ |
MC |
163 |
if(is_array($i['value'])) { |
|
164 |
$out = '<option value=""></option>'; |
|
165 |
foreach($i['value'] as $k => $v) { |
|
166 |
// TODO: this could be more elegant |
|
167 |
$selected = (isset($_SESSION['search'][$list_name][$search_prefix.$field]) |
|
168 |
&& $k == $_SESSION['search'][$list_name][$search_prefix.$field] |
|
169 |
&& $_SESSION['search'][$list_name][$search_prefix.$field] != '') |
|
170 |
? ' SELECTED' : ''; |
|
171 |
$out .= "<option value='$k'$selected>$v</option>\r\n"; |
|
172 |
} |
|
173 |
} |
|
174 |
$this->searchValues[$search_prefix.$field] = $out; |
|
175 |
} else { |
|
176 |
if(isset($_SESSION['search'][$list_name][$search_prefix.$field])){ |
|
177 |
$this->searchValues[$search_prefix.$field] = htmlspecialchars($_SESSION['search'][$list_name][$search_prefix.$field]); |
|
178 |
} |
|
179 |
} |
|
180 |
} |
|
181 |
} |
|
182 |
//* Store variables in object | $this->searchValues = $_SESSION["search"][$list_name]; |
|
183 |
if(@is_array($this->listDef['item'])) { |
|
184 |
foreach($this->listDef['item'] as $i) { |
|
185 |
$field = $i['field']; |
615a0a
|
186 |
$table = $i['table']; |
7fe908
|
187 |
|
2d2fd1
|
188 |
$searchval = $_SESSION['search'][$list_name][$search_prefix.$field]; |
FT |
189 |
// format user date format to MySQL date format 0000-00-00 |
|
190 |
if($i['datatype'] == 'DATE' && $this->lng('conf_format_dateshort') != 'Y-m-d'){ |
|
191 |
$dateformat = preg_replace("@[^Ymd]@", "", $this->lng('conf_format_dateshort')); |
|
192 |
$yearpos = strpos($dateformat, 'Y') + 1; |
|
193 |
$monthpos = strpos($dateformat, 'm') + 1; |
|
194 |
$daypos = strpos($dateformat, 'd') + 1; |
7fe908
|
195 |
|
MC |
196 |
$full_date_trans = array ('Y' => '((?:19|20)\d\d)', |
|
197 |
'm' => '(0[1-9]|1[012])', |
|
198 |
'd' => '(0[1-9]|[12][0-9]|3[01])' |
|
199 |
); |
|
200 |
// d.m.Y Y/m/d |
2d2fd1
|
201 |
$full_date_regex = strtr(preg_replace("@[^Ymd]@", "[^0-9]", $this->lng('conf_format_dateshort')), $full_date_trans); |
FT |
202 |
//echo $full_date_regex; |
7fe908
|
203 |
|
2d2fd1
|
204 |
if (preg_match("@^\d+$@", $_SESSION['search'][$list_name][$search_prefix.$field])) { // we just have digits |
FT |
205 |
$searchval = $_SESSION['search'][$list_name][$search_prefix.$field]; |
|
206 |
} elseif(preg_match("@^[^0-9]?\d+[^0-9]?$@", $_SESSION['search'][$list_name][$search_prefix.$field])){ // 10. or .10. |
|
207 |
$searchval = preg_replace("@[^0-9]@", "", $_SESSION['search'][$list_name][$search_prefix.$field]); |
|
208 |
} elseif(preg_match("@^[^0-9]?(\d{1,2})[^0-9]((?:19|20)\d\d)$@", $_SESSION['search'][$list_name][$search_prefix.$field], $matches)){ // 10.2013 |
|
209 |
$month = $matches[1]; |
|
210 |
$year = $matches[2]; |
|
211 |
$searchval = $year.'-'.$month; |
|
212 |
} elseif(preg_match("@^((?:19|20)\d\d)[^0-9](\d{1,2})[^0-9]?$@", $_SESSION['search'][$list_name][$search_prefix.$field], $matches)){ // 2013-10 |
|
213 |
$month = $matches[2]; |
|
214 |
$year = $matches[1]; |
|
215 |
$searchval = $year.'-'.$month; |
|
216 |
} 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. |
|
217 |
if($monthpos < $daypos){ |
7fe908
|
218 |
$month = $matches[1]; |
MC |
219 |
$day = $matches[2]; |
2d2fd1
|
220 |
} else { |
FT |
221 |
$month = $matches[2]; |
|
222 |
$day = $matches[1]; |
|
223 |
} |
|
224 |
$searchval = $month.'-'.$day; |
|
225 |
} elseif (preg_match("@^".$full_date_regex."$@", $_SESSION['search'][$list_name][$search_prefix.$field], $matches)) { |
|
226 |
//print_r($matches); |
|
227 |
$day = $matches[$daypos]; |
|
228 |
$month = $matches[$monthpos]; |
|
229 |
$year = $matches[$yearpos]; |
|
230 |
$searchval = $year.'-'.$month.'-'.$day; |
|
231 |
} |
|
232 |
} |
7fe908
|
233 |
|
MC |
234 |
// if($_REQUEST[$search_prefix.$field] != '') $sql_where .= " $field ".$i["op"]." '".$i["prefix"].$_REQUEST[$search_prefix.$field].$i["suffix"]."' and"; |
|
235 |
if(isset($searchval) && $searchval != ''){ |
|
236 |
$sql_where .= " ".($table != ''? $table.'.' : $this->listDef['table'].'.')."$field ".$i['op']." '".$app->db->quote($i['prefix'].$searchval.$i['suffix'])."' and"; |
|
237 |
} |
|
238 |
} |
|
239 |
} |
|
240 |
return ( $sql_where != '' ) ? $sql_where = substr($sql_where, 0, -3) : '1'; |
|
241 |
} |
|
242 |
|
202df8
|
243 |
public function getPagingValue($key) { |
MC |
244 |
if(!is_array($this->pagingValues)) return null; |
|
245 |
if(!array_key_exists($key, $this->pagingValues)) return null; |
|
246 |
return $this->pagingValues[$key]; |
|
247 |
} |
7fe908
|
248 |
|
MC |
249 |
public function getPagingSQL($sql_where = '1') |
|
250 |
{ |
|
251 |
global $app, $conf; |
e03212
|
252 |
|
TB |
253 |
$old_search_limit = intval($_SESSION['search']['limit']); |
7fe908
|
254 |
|
7b47c0
|
255 |
//* Add Global Limit from selectbox |
7fe908
|
256 |
if(!empty($_POST['search_limit']) and $app->functions->intval($_POST['search_limit']) > 0){ |
65ea2e
|
257 |
$_SESSION['search']['limit'] = $app->functions->intval($_POST['search_limit']); |
26c0fc
|
258 |
} |
7fe908
|
259 |
|
992797
|
260 |
//if(preg_match('{^[0-9]$}',$_SESSION['search']['limit'])){ |
7fe908
|
261 |
// $_SESSION['search']['limit'] = 15; |
992797
|
262 |
//} |
MC |
263 |
if(intval($_SESSION['search']['limit']) < 1) $_SESSION['search']['limit'] = 15; |
fb02f0
|
264 |
|
7fe908
|
265 |
//* Get Config variables |
MC |
266 |
$list_name = $this->listDef['name']; |
|
267 |
$search_prefix = $this->listDef['search_prefix']; |
|
268 |
$records_per_page = (empty($_SESSION['search']['limit']) ? $app->functions->intval($this->listDef['records_per_page']) : $app->functions->intval($_SESSION['search']['limit'])) ; |
|
269 |
$table = $this->listDef['table']; |
fb02f0
|
270 |
|
7fe908
|
271 |
//* set PAGE to zero, if in session not set |
MC |
272 |
if(!isset($_SESSION['search'][$list_name]['page']) || $_SESSION['search'][$list_name]['page'] == ''){ |
|
273 |
$_SESSION['search'][$list_name]['page'] = 0; |
|
274 |
} |
fb02f0
|
275 |
|
7fe908
|
276 |
//* set PAGE to worth request variable "PAGE" - ? setze page auf wert der request variablen "page" |
MC |
277 |
if(isset($_REQUEST["page"])) $_SESSION["search"][$list_name]["page"] = $app->functions->intval($_REQUEST["page"]); |
e03212
|
278 |
|
TB |
279 |
//* Set search to changed when search limit has been changed. |
|
280 |
if(intval($_SESSION['search']['limit']) != $old_search_limit) $this->searchChanged = 1; |
fb02f0
|
281 |
|
7fe908
|
282 |
//* PAGE to 0 set, if look for themselves ? page auf 0 setzen, wenn suche sich ge�ndert hat. |
MC |
283 |
if($this->searchChanged == 1) $_SESSION['search'][$list_name]['page'] = 0; |
fb02f0
|
284 |
|
7fe908
|
285 |
$sql_von = $app->functions->intval($_SESSION['search'][$list_name]['page'] * $records_per_page); |
MC |
286 |
$record_count = $app->db->queryOneRecord("SELECT count(*) AS anzahl FROM $table".($app->listform->listDef['additional_tables'] != ''? ','.$app->listform->listDef['additional_tables'] : '')." WHERE $sql_where"); |
|
287 |
$pages = $app->functions->intval(($record_count['anzahl'] - 1) / $records_per_page); |
fb02f0
|
288 |
|
T |
289 |
|
7fe908
|
290 |
$vars['list_file'] = $_SESSION['s']['module']['name'].'/'.$this->listDef['file']; |
MC |
291 |
$vars['page'] = $_SESSION['search'][$list_name]['page']; |
|
292 |
$vars['last_page'] = $_SESSION['search'][$list_name]['page'] - 1; |
|
293 |
$vars['next_page'] = $_SESSION['search'][$list_name]['page'] + 1; |
|
294 |
$vars['pages'] = $pages; |
|
295 |
$vars['max_pages'] = $pages + 1; |
|
296 |
$vars['records_gesamt'] = $record_count['anzahl']; |
|
297 |
$vars['page_params'] = (isset($this->listDef['page_params'])) ? $this->listDef['page_params'] : ''; |
|
298 |
$vars['offset'] = $sql_von; |
|
299 |
$vars['records_per_page'] = $records_per_page; |
|
300 |
//$vars['module'] = $_SESSION['s']['module']['name']; |
fb02f0
|
301 |
|
7fe908
|
302 |
if($_SESSION['search'][$list_name]['page'] > 0) $vars['show_page_back'] = 1; |
MC |
303 |
if($_SESSION['search'][$list_name]['page'] <= $vars['pages'] - 1) $vars['show_page_next'] = 1; |
fb02f0
|
304 |
|
7fe908
|
305 |
$this->pagingValues = $vars; |
MC |
306 |
$this->pagingHTML = $this->getPagingHTML($vars); |
fb02f0
|
307 |
|
7fe908
|
308 |
//* Return limit sql |
MC |
309 |
return "LIMIT $sql_von, $records_per_page"; |
|
310 |
} |
fb02f0
|
311 |
|
7fe908
|
312 |
public function getPagingHTML($vars) |
MC |
313 |
{ |
|
314 |
global $app; |
|
315 |
|
|
316 |
// we want to show at max 17 page numbers (8 left, current, 8 right) |
|
317 |
$show_pages_count = 17; |
|
318 |
|
|
319 |
$show_pages = array(0); // first page |
|
320 |
if($vars['pages'] > 0) $show_pages[] = $vars['pages']; // last page |
|
321 |
for($p = $vars['page'] - 2; $p <= $vars['page'] + 2; $p++) { // surrounding pages |
|
322 |
if($p > 0 && $p < $vars['pages']) $show_pages[] = $p; |
|
323 |
} |
|
324 |
|
|
325 |
$l_start = $vars['page'] - 13; |
|
326 |
$l_start -= ($l_start % 10) + 1; |
|
327 |
$h_end = $vars['page'] + 23; |
|
328 |
$h_end -= ($h_end % 10) + 1; |
|
329 |
for($p = $l_start; $p <= $h_end; $p += 10) { // surrounding pages |
|
330 |
if($p > 0 && $p < $vars['pages'] && !in_array($p, $show_pages, true) && count($show_pages) < $show_pages_count) $show_pages[] = $p; |
|
331 |
} |
|
332 |
|
|
333 |
$l_start = $vars['page'] - 503; |
|
334 |
$l_start -= ($l_start % 100) + 1; |
|
335 |
$h_end = $vars['page'] + 603; |
|
336 |
$h_end -= ($h_end % 100) + 1; |
|
337 |
for($p = $l_start; $p <= $h_end; $p += 100) { // surrounding pages |
|
338 |
if($p > 0 && $p < $vars['pages'] && !in_array($p, $show_pages, true) && count($show_pages) < $show_pages_count) $show_pages[] = $p; |
|
339 |
} |
|
340 |
|
|
341 |
$l_start = $vars['page'] - 203; |
|
342 |
$l_start -= ($l_start % 25) + 1; |
|
343 |
$h_end = $vars['page'] + 228; |
|
344 |
$h_end -= ($h_end % 25) + 1; |
|
345 |
for($p = $l_start; $p <= $h_end; $p += 25) { // surrounding pages |
|
346 |
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; |
|
347 |
} |
|
348 |
|
|
349 |
sort($show_pages); |
|
350 |
$show_pages = array_unique($show_pages); |
|
351 |
|
|
352 |
//* Show Back |
|
353 |
if(isset($vars['show_page_back']) && $vars['show_page_back'] == 1){ |
|
354 |
$content = '<a class="btn-page first-page" href="'."javascript:loadContent('".$vars['list_file'].'?page=0'.$vars['page_params']."');".'">' |
|
355 |
.'<img src="themes/'.$_SESSION['s']['theme'].'/icons/x16/arrow_stop_180.png"></a> '; |
|
356 |
$content .= '<a class="btn-page previous-page" href="'."javascript:loadContent('".$vars['list_file'].'?page='.$vars['last_page'].$vars['page_params']."');".'">' |
|
357 |
.'<img src="themes/'.$_SESSION['s']['theme'].'/icons/x16/arrow_180.png"></a> '; |
|
358 |
} |
|
359 |
$content .= ' '.$this->lng('page_txt').' '; |
|
360 |
$prev = -1; |
|
361 |
foreach($show_pages as $p) { |
|
362 |
if($prev != -1 && $p > $prev + 1) $content .= '<span class="page-spacer">...</span>'; |
|
363 |
$content .= '<a class="link-page' . ($p == $vars['page'] ? ' current-page' : '') . '" href="'."javascript:loadContent('".$vars['list_file'].'?page='.$p.$vars['page_params']."');".'">'. ($p+1) .'</a>'; |
|
364 |
$prev = $p; |
|
365 |
} |
|
366 |
//.$vars['next_page'].' '.$this->lng('page_of_txt').' '.$vars['max_pages'].' '; |
|
367 |
//* Show Next |
|
368 |
if(isset($vars['show_page_next']) && $vars['show_page_next'] == 1){ |
|
369 |
$content .= '<a class="btn-page next-page" href="'."javascript:loadContent('".$vars['list_file'].'?page='.$vars['next_page'].$vars['page_params']."');".'">' |
|
370 |
.'<img src="themes/'.$_SESSION['s']['theme'].'/icons/x16/arrow.png"></a> '; |
|
371 |
$content .= '<a class="btn-page last-page" href="'."javascript:loadContent('".$vars['list_file'].'?page='.$vars['pages'].$vars['page_params']."');".'">' |
|
372 |
.'<img src="themes/'.$_SESSION['s']['theme'].'/icons/x16/arrow_stop.png"></a>'; |
|
373 |
} |
|
374 |
return $content; |
|
375 |
} |
|
376 |
|
fb02f0
|
377 |
public function getPagingHTMLasTXT($vars) |
7fe908
|
378 |
{ |
MC |
379 |
global $app; |
|
380 |
$content = '[<a href="'.$vars['list_file'].'?page=0'.$vars['page_params'].'">|<< </a>]'; |
|
381 |
if($vars['show_page_back'] == 1){ |
|
382 |
$content .= '[<< <a href="'.$vars['list_file'].'?page='.$vars['last_page'].$vars['page_params'].'">'.$app->lng('page_back_txt').'</a>] '; |
|
383 |
} |
|
384 |
$content .= ' '.$this->lng('page_txt').' '.$vars['next_page'].' '.$this->lng('page_of_txt').' '.$vars['max_pages'].' '; |
|
385 |
if($vars['show_page_next'] == 1){ |
|
386 |
$content .= '[<a href="'.$vars['list_file'].'?page='.$vars['next_page'].$vars['page_params'].'">'.$app->lng('page_next_txt').' >></a>] '; |
|
387 |
} |
|
388 |
$content .= '[<a href="'.$vars['list_file'].'?page='.$vars['pages'].$vars['page_params'].'"> >>|</a>]'; |
|
389 |
return $content; |
|
390 |
} |
fb02f0
|
391 |
|
7fe908
|
392 |
public function getSortSQL() |
MC |
393 |
{ |
|
394 |
global $app, $conf; |
|
395 |
//* Get config vars |
|
396 |
$sort_field = $this->listDef['sort_field']; |
|
397 |
$sort_direction = $this->listDef['sort_direction']; |
|
398 |
return ($sort_field != '' && $sort_direction != '') ? "ORDER BY $sort_field $sort_direction" : ''; |
|
399 |
} |
fb02f0
|
400 |
|
7fe908
|
401 |
public function decode($record) |
MC |
402 |
{ |
|
403 |
global $conf, $app; |
|
404 |
if(is_array($record) && count($record) > 0 && is_array($this->listDef['item'])) { |
|
405 |
foreach($this->listDef['item'] as $field){ |
|
406 |
$key = $field['field']; |
|
407 |
//* Apply filter to record value. |
|
408 |
if(isset($field['filters']) && is_array($field['filters'])) { |
|
409 |
$app->uses('tform'); |
|
410 |
$record[$key] = $app->tform->filterField($key, (isset($record[$key]))?$record[$key]:'', $field['filters'], 'SHOW'); |
fb02f0
|
411 |
} |
7fe908
|
412 |
if(isset($record[$key])) { |
MC |
413 |
switch ($field['datatype']){ |
|
414 |
case 'VARCHAR': |
|
415 |
case 'TEXT': |
|
416 |
$record[$key] = htmlentities(stripslashes($record[$key]), ENT_QUOTES, $conf["html_content_encoding"]); |
|
417 |
break; |
fb02f0
|
418 |
|
57540e
|
419 |
case 'DATETSTAMP': |
7fe908
|
420 |
if ($record[$key] > 0) { |
MC |
421 |
// is value int? |
|
422 |
if (preg_match("/^[0-9]+[\.]?[0-9]*$/", $record[$key], $p)) { |
|
423 |
$record[$key] = date($this->lng('conf_format_dateshort'), $record[$key]); |
|
424 |
} else { |
|
425 |
$record[$key] = date($this->lng('conf_format_dateshort'), strtotime($record[$key])); |
|
426 |
} |
|
427 |
} |
|
428 |
break; |
615a0a
|
429 |
case 'DATETIMETSTAMP': |
7fe908
|
430 |
if ($record[$key] > 0) { |
MC |
431 |
// is value int? |
|
432 |
if (preg_match("/^[0-9]+[\.]?[0-9]*$/", $record[$key], $p)) { |
|
433 |
$record[$key] = date($this->lng('conf_format_datetime'), $record[$key]); |
|
434 |
} else { |
|
435 |
$record[$key] = date($this->lng('conf_format_datetime'), strtotime($record[$key])); |
|
436 |
} |
|
437 |
} |
|
438 |
break; |
|
439 |
case 'DATE': |
|
440 |
if ($record[$key] > 0) { |
|
441 |
// is value int? |
|
442 |
if (preg_match("/^[0-9]+[\.]?[0-9]*$/", $record[$key], $p)) { |
|
443 |
$record[$key] = date($this->lng('conf_format_dateshort'), $record[$key]); |
|
444 |
} else { |
|
445 |
$record[$key] = date($this->lng('conf_format_dateshort'), strtotime($record[$key])); |
|
446 |
} |
|
447 |
} |
|
448 |
break; |
e11f5d
|
449 |
|
7fe908
|
450 |
case 'DATETIME': |
MC |
451 |
if ($record[$key] > 0) { |
|
452 |
// is value int? |
|
453 |
if (preg_match("/^[0-9]+[\.]?[0-9]*$/", $record[$key], $p)) { |
|
454 |
$record[$key] = date($this->lng('conf_format_datetime'), $record[$key]); |
|
455 |
} else { |
|
456 |
$record[$key] = date($this->lng('conf_format_datetime'), strtotime($record[$key])); |
|
457 |
} |
|
458 |
} |
|
459 |
break; |
fb02f0
|
460 |
|
7fe908
|
461 |
case 'INTEGER': |
MC |
462 |
$record[$key] = $app->functions->intval($record[$key]); |
|
463 |
break; |
fb02f0
|
464 |
|
7fe908
|
465 |
case 'DOUBLE': |
MC |
466 |
$record[$key] = htmlentities($record[$key], ENT_QUOTES, $conf["html_content_encoding"]); |
|
467 |
break; |
fb02f0
|
468 |
|
7fe908
|
469 |
case 'CURRENCY': |
MC |
470 |
$record[$key] = $app->functions->currency_format($record[$key]); |
|
471 |
break; |
|
472 |
|
|
473 |
default: |
|
474 |
$record[$key] = htmlentities(stripslashes($record[$key]), ENT_QUOTES, $conf["html_content_encoding"]); |
|
475 |
} |
|
476 |
} |
|
477 |
} |
|
478 |
} |
|
479 |
return $record; |
|
480 |
} |
|
481 |
|
|
482 |
public function encode($record) |
|
483 |
{ |
|
484 |
global $app; |
|
485 |
if(is_array($record)) { |
|
486 |
foreach($this->listDef['item'] as $field){ |
|
487 |
$key = $field['field']; |
|
488 |
switch($field['datatype']){ |
|
489 |
|
|
490 |
case 'VARCHAR': |
|
491 |
case 'TEXT': |
|
492 |
if(!is_array($record[$key])) { |
|
493 |
$record[$key] = $app->db->quote($record[$key]); |
|
494 |
} else { |
|
495 |
$record[$key] = implode($this->tableDef[$key]['separator'], $record[$key]); |
|
496 |
} |
|
497 |
break; |
|
498 |
|
|
499 |
case 'DATETSTAMP': |
|
500 |
if($record[$key] > 0) { |
|
501 |
$record[$key] = date('Y-m-d', strtotime($record[$key])); |
|
502 |
} |
|
503 |
break; |
|
504 |
|
|
505 |
case 'DATETIMETSTAMP': |
|
506 |
if($record[$key] > 0) { |
|
507 |
$record[$key] = date('Y-m-d H:i:s', strtotime($record[$key])); |
|
508 |
} |
|
509 |
break; |
|
510 |
|
|
511 |
case 'DATE': |
|
512 |
if($record[$key] != '' && $record[$key] != '0000-00-00') { |
|
513 |
$record[$key] = $record[$key]; |
|
514 |
} |
|
515 |
break; |
|
516 |
|
|
517 |
case 'DATETIME': |
|
518 |
if($record[$key] > 0) { |
|
519 |
$record[$key] = date('Y-m-d H:i:s', strtotime($record[$key])); |
|
520 |
} |
|
521 |
break; |
|
522 |
|
|
523 |
case 'INTEGER': |
|
524 |
$record[$key] = $app->functions->intval($record[$key]); |
|
525 |
break; |
|
526 |
|
|
527 |
case 'DOUBLE': |
|
528 |
$record[$key] = $app->db->quote($record[$key]); |
|
529 |
break; |
|
530 |
|
|
531 |
case 'CURRENCY': |
|
532 |
$record[$key] = str_replace(',', '.', $record[$key]); |
|
533 |
break; |
|
534 |
} |
|
535 |
} |
|
536 |
} |
|
537 |
return $record; |
|
538 |
} |
|
539 |
|
fb02f0
|
540 |
function lng($msg) { |
T |
541 |
global $app; |
7fe908
|
542 |
|
fb02f0
|
543 |
if(isset($this->wordbook[$msg])) { |
T |
544 |
return $this->wordbook[$msg]; |
|
545 |
} else { |
|
546 |
return $app->lng($msg); |
7fe908
|
547 |
} |
fb02f0
|
548 |
} |
7fe908
|
549 |
|
ae69e6
|
550 |
function escapeArrayValues($search_values) { |
7fe908
|
551 |
global $conf; |
MC |
552 |
|
ae69e6
|
553 |
$out = array(); |
T |
554 |
if(is_array($search_values)) { |
|
555 |
foreach($search_values as $key => $val) { |
7fe908
|
556 |
$out[$key] = htmlentities($val, ENT_QUOTES, $conf["html_content_encoding"]); |
ae69e6
|
557 |
} |
T |
558 |
} |
7fe908
|
559 |
|
ae69e6
|
560 |
return $out; |
7fe908
|
561 |
|
ae69e6
|
562 |
} |
fb02f0
|
563 |
|
T |
564 |
} |
|
565 |
|
7fe908
|
566 |
?> |