commit | author | age
|
fb02f0
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
436ed8
|
4 |
Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
fb02f0
|
5 |
All rights reserved. |
T |
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_actions { |
b1a6a5
|
32 |
|
fb02f0
|
33 |
private $id; |
T |
34 |
public $idx_key; |
|
35 |
public $DataRowColor; |
656a1c
|
36 |
public $SQLExtWhere = ''; |
F |
37 |
public $SQLOrderBy = ''; |
|
38 |
public $SQLExtSelect = ''; |
615a0a
|
39 |
private $sortKeys; |
b1a6a5
|
40 |
|
MC |
41 |
private function _sort($aOne, $aTwo) { |
|
42 |
if(!is_array($aOne) || !is_array($aTwo)) return 0; |
|
43 |
|
|
44 |
if(!is_array($this->sortKeys)) $this->sortKeys = array($this->sortKeys); |
|
45 |
foreach($this->sortKeys as $sKey => $sDir) { |
|
46 |
if(is_numeric($sKey)) { |
|
47 |
$sKey = $sDir; |
|
48 |
$sDir = 'ASC'; |
|
49 |
} |
|
50 |
$a = $aOne[$sKey]; |
|
51 |
$b = $aTwo[$sKey]; |
|
52 |
if(is_string($a)) $a = strtolower($a); |
|
53 |
if(is_string($b)) $b = strtolower($b); |
|
54 |
if($a < $b) return $sDir == 'DESC' ? 1 : -1; |
|
55 |
elseif($a > $b) return $sDir == 'DESC' ? -1 : 1; |
|
56 |
} |
|
57 |
return 0; |
|
58 |
} |
|
59 |
|
fb02f0
|
60 |
public function onLoad() |
b1a6a5
|
61 |
{ |
fb02f0
|
62 |
global $app, $conf, $list_def_file; |
b1a6a5
|
63 |
|
fb02f0
|
64 |
$app->uses('tpl,listform,tform'); |
b1a6a5
|
65 |
|
fb02f0
|
66 |
//* Clear session variable that is used when lists are embedded with the listview plugin |
T |
67 |
$_SESSION['s']['form']['return_to'] = ''; |
b1a6a5
|
68 |
|
fb02f0
|
69 |
// Load list definition |
T |
70 |
$app->listform->loadListDef($list_def_file); |
b1a6a5
|
71 |
|
fb02f0
|
72 |
if(!is_file('templates/'.$app->listform->listDef["name"].'_list.htm')) { |
T |
73 |
$app->uses('listform_tpl_generator'); |
|
74 |
$app->listform_tpl_generator->buildHTML($app->listform->listDef); |
|
75 |
} |
b1a6a5
|
76 |
|
fb02f0
|
77 |
$app->tpl->newTemplate("listpage.tpl.htm"); |
b1a6a5
|
78 |
$app->tpl->setInclude('content_tpl', 'templates/'.$app->listform->listDef["name"].'_list.htm'); |
MC |
79 |
|
8145fb
|
80 |
//* Manipulate order by for sorting / Every list has a stored value |
X |
81 |
//* Against notice error |
615a0a
|
82 |
if(!isset($_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'])){ |
b1a6a5
|
83 |
$_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'] = ''; |
8145fb
|
84 |
} |
b1a6a5
|
85 |
|
MC |
86 |
$php_sort = false; |
|
87 |
|
8145fb
|
88 |
if(!empty($_GET['orderby'])){ |
b1a6a5
|
89 |
$order = str_replace('tbl_col_', '', $_GET['orderby']); |
MC |
90 |
|
|
91 |
//* Check the css class submited value |
|
92 |
if (preg_match("/^[a-z\_]{1,}$/", $order)) { |
|
93 |
|
|
94 |
if(isset($app->listform->listDef['phpsort']) && is_array($app->listform->listDef['phpsort']) && in_array($order, $app->listform->listDef['phpsort'])) { |
|
95 |
$php_sort = true; |
|
96 |
} else { |
|
97 |
// prepend correct table |
|
98 |
$prepend_table = $app->listform->listDef['table']; |
|
99 |
if(trim($app->listform->listDef['additional_tables']) != '' && is_array($app->listform->listDef['item']) && count($app->listform->listDef['item']) > 0) { |
|
100 |
foreach($app->listform->listDef['item'] as $field) { |
|
101 |
if($field['field'] == $order && $field['table'] != ''){ |
|
102 |
$prepend_table = $field['table']; |
|
103 |
break; |
|
104 |
} |
|
105 |
} |
|
106 |
} |
|
107 |
$order = $prepend_table.'.'.$order; |
|
108 |
} |
|
109 |
|
|
110 |
if($_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'] == $order){ |
|
111 |
$_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'] = $order.' DESC'; |
|
112 |
} else { |
|
113 |
$_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'] = $order; |
|
114 |
} |
|
115 |
$_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order_in_php'] = $php_sort; |
|
116 |
} |
8145fb
|
117 |
} |
X |
118 |
|
|
119 |
// If a manuel oder by like customers isset the sorting will be infront |
615a0a
|
120 |
if(!empty($_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order']) && !$_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order_in_php']){ |
b1a6a5
|
121 |
if(empty($this->SQLOrderBy)){ |
MC |
122 |
$this->SQLOrderBy = "ORDER BY ".$_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order']; |
|
123 |
} else { |
|
124 |
$this->SQLOrderBy = str_replace("ORDER BY ", "ORDER BY ".$_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order'].', ', $this->SQLOrderBy); |
|
125 |
} |
8145fb
|
126 |
} |
b1a6a5
|
127 |
|
7d52e0
|
128 |
if($_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order_in_php']) $php_sort = true; |
b1a6a5
|
129 |
|
fb02f0
|
130 |
// Getting Datasets from DB |
202df8
|
131 |
$records = $app->db->queryAllRecords($this->getQueryString($php_sort)); |
fb02f0
|
132 |
|
T |
133 |
$this->DataRowColor = "#FFFFFF"; |
|
134 |
$records_new = ''; |
|
135 |
if(is_array($records)) { |
b1a6a5
|
136 |
$this->idx_key = $app->listform->listDef["table_idx"]; |
fb02f0
|
137 |
foreach($records as $rec) { |
T |
138 |
$records_new[] = $this->prepareDataRow($rec); |
|
139 |
} |
|
140 |
} |
b1a6a5
|
141 |
|
MC |
142 |
if(!empty($_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order']) && $_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order_in_php']) { |
|
143 |
$order_by = $_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order']; |
|
144 |
$order_dir = 'ASC'; |
|
145 |
if(substr($order_by, -5) === ' DESC') { |
|
146 |
$order_by = substr($order_by, 0, -5); |
|
147 |
$order_dir = 'DESC'; |
|
148 |
} |
|
149 |
$this->sortKeys = array($order_by => $order_dir); |
|
150 |
uasort($records_new, array($this, '_sort')); |
|
151 |
} |
|
152 |
if($php_sort) { |
202df8
|
153 |
$records_new = array_slice($records_new, $app->listform->getPagingValue('offset'), $app->listform->getPagingValue('records_per_page')); |
MC |
154 |
} |
b1a6a5
|
155 |
|
MC |
156 |
$app->tpl->setLoop('records', $records_new); |
fb02f0
|
157 |
|
T |
158 |
$this->onShow(); |
b1a6a5
|
159 |
|
MC |
160 |
|
fb02f0
|
161 |
} |
b1a6a5
|
162 |
|
fb02f0
|
163 |
public function prepareDataRow($rec) |
b1a6a5
|
164 |
{ |
fb02f0
|
165 |
global $app; |
b1a6a5
|
166 |
|
fb02f0
|
167 |
$rec = $app->listform->decode($rec); |
T |
168 |
|
|
169 |
//* Alternating datarow colors |
|
170 |
$this->DataRowColor = ($this->DataRowColor == '#FFFFFF') ? '#EEEEEE' : '#FFFFFF'; |
|
171 |
$rec['bgcolor'] = $this->DataRowColor; |
b1a6a5
|
172 |
|
fb02f0
|
173 |
//* substitute value for select fields |
8ab3cd
|
174 |
if(is_array($app->listform->listDef['item']) && count($app->listform->listDef['item']) > 0) { |
T |
175 |
foreach($app->listform->listDef['item'] as $field) { |
|
176 |
$key = $field['field']; |
|
177 |
if(isset($field['formtype']) && $field['formtype'] == 'SELECT') { |
|
178 |
if(strtolower($rec[$key]) == 'y' or strtolower($rec[$key]) == 'n') { |
|
179 |
// Set a additional image variable for bolean fields |
|
180 |
$rec['_'.$key.'_'] = (strtolower($rec[$key]) == 'y')?'x16/tick_circle.png':'x16/cross_circle.png'; |
|
181 |
} |
|
182 |
//* substitute value for select field |
|
183 |
$rec[$key] = @$field['value'][$rec[$key]]; |
fb02f0
|
184 |
} |
T |
185 |
} |
|
186 |
} |
b1a6a5
|
187 |
|
fb02f0
|
188 |
//* The variable "id" contains always the index variable |
T |
189 |
$rec['id'] = $rec[$this->idx_key]; |
|
190 |
return $rec; |
|
191 |
} |
b1a6a5
|
192 |
|
202df8
|
193 |
public function getQueryString($no_limit = false) { |
fb02f0
|
194 |
global $app; |
T |
195 |
$sql_where = ''; |
|
196 |
|
|
197 |
//* Generate the search sql |
|
198 |
if($app->listform->listDef['auth'] != 'no') { |
|
199 |
if($_SESSION['s']['user']['typ'] == "admin") { |
|
200 |
$sql_where = ''; |
|
201 |
} else { |
b1a6a5
|
202 |
$sql_where = $app->tform->getAuthSQL('r', $app->listform->listDef['table']).' and'; |
MC |
203 |
//$sql_where = $app->tform->getAuthSQL('r').' and'; |
fb02f0
|
204 |
} |
b1a6a5
|
205 |
} |
fb02f0
|
206 |
if($this->SQLExtWhere != '') { |
T |
207 |
$sql_where .= ' '.$this->SQLExtWhere.' and'; |
|
208 |
} |
b1a6a5
|
209 |
|
fb02f0
|
210 |
$sql_where = $app->listform->getSearchSQL($sql_where); |
615a0a
|
211 |
if($app->listform->listDef['join_sql']) $sql_where .= ' AND '.$app->listform->listDef['join_sql']; |
fb02f0
|
212 |
$app->tpl->setVar($app->listform->searchValues); |
b1a6a5
|
213 |
|
fb02f0
|
214 |
$order_by_sql = $this->SQLOrderBy; |
T |
215 |
|
|
216 |
//* Generate SQL for paging |
|
217 |
$limit_sql = $app->listform->getPagingSQL($sql_where); |
b1a6a5
|
218 |
$app->tpl->setVar('paging', $app->listform->pagingHTML); |
fb02f0
|
219 |
|
8145fb
|
220 |
$extselect = ''; |
X |
221 |
$join = ''; |
b1a6a5
|
222 |
|
8f9240
|
223 |
if($this->SQLExtSelect != '') { |
b1a6a5
|
224 |
if(substr($this->SQLExtSelect, 0, 1) != ',') $this->SQLExtSelect = ','.$this->SQLExtSelect; |
8f9240
|
225 |
$extselect .= $this->SQLExtSelect; |
F |
226 |
} |
b1a6a5
|
227 |
|
615a0a
|
228 |
$table_selects = array(); |
T |
229 |
$table_selects[] = trim($app->listform->listDef['table']).'.*'; |
|
230 |
$app->listform->listDef['additional_tables'] = trim($app->listform->listDef['additional_tables']); |
|
231 |
if($app->listform->listDef['additional_tables'] != ''){ |
|
232 |
$additional_tables = explode(',', $app->listform->listDef['additional_tables']); |
|
233 |
foreach($additional_tables as $additional_table){ |
|
234 |
$table_selects[] = trim($additional_table).'.*'; |
|
235 |
} |
|
236 |
} |
|
237 |
$select = implode(', ', $table_selects); |
8f9240
|
238 |
|
202df8
|
239 |
$sql = 'SELECT '.$select.$extselect.' FROM '.$app->listform->listDef['table'].($app->listform->listDef['additional_tables'] != ''? ','.$app->listform->listDef['additional_tables'] : '')."$join WHERE $sql_where $order_by_sql"; |
MC |
240 |
if($no_limit == false) $sql .= " $limit_sql"; |
615a0a
|
241 |
//echo $sql; |
T |
242 |
return $sql; |
fb02f0
|
243 |
} |
b1a6a5
|
244 |
|
MC |
245 |
|
d8b8b0
|
246 |
public function onShow() |
b1a6a5
|
247 |
{ |
fb02f0
|
248 |
global $app; |
b1a6a5
|
249 |
|
fb02f0
|
250 |
//* Set global Language File |
T |
251 |
$lng_file = ISPC_LIB_PATH.'/lang/'.$_SESSION['s']['language'].'.lng'; |
|
252 |
if(!file_exists($lng_file)) |
b1a6a5
|
253 |
$lng_file = ISPC_LIB_PATH.'/lang/en.lng'; |
MC |
254 |
include $lng_file; |
fb02f0
|
255 |
$app->tpl->setVar($wb); |
b1a6a5
|
256 |
|
8145fb
|
257 |
//* Limit each page |
b1a6a5
|
258 |
$limits = array('5'=>'5', '15'=>'15', '25'=>'25', '50'=>'50', '100'=>'100', '999999999' => 'all'); |
8145fb
|
259 |
|
X |
260 |
//* create options and set selected, if default -> 15 is selected |
b9ce1a
|
261 |
|
X |
262 |
$options = ''; |
8145fb
|
263 |
foreach($limits as $key => $val){ |
b1a6a5
|
264 |
$options .= '<option value="'.$key.'" '.(isset($_SESSION['search']['limit']) && $_SESSION['search']['limit'] == $key ? 'selected="selected"':'' ).(!isset($_SESSION['search']['limit']) && $key == '15' ? 'selected="selected"':'').'>'.$val.'</option>'; |
8145fb
|
265 |
} |
b1a6a5
|
266 |
$app->tpl->setVar('search_limit', '<select name="search_limit" class="search_limit">'.$options.'</select>'); |
MC |
267 |
|
|
268 |
$app->tpl->setVar('toolsarea_head_txt', $app->lng('toolsarea_head_txt')); |
fb02f0
|
269 |
$app->tpl->setVar($app->listform->wordbook); |
T |
270 |
$app->tpl->setVar('form_action', $app->listform->listDef['file']); |
b1a6a5
|
271 |
|
MC |
272 |
if(isset($_SESSION['show_info_msg'])) { |
|
273 |
$app->tpl->setVar('show_info_msg', $_SESSION['show_info_msg']); |
|
274 |
unset($_SESSION['show_info_msg']); |
|
275 |
} |
|
276 |
if(isset($_SESSION['show_error_msg'])) { |
|
277 |
$app->tpl->setVar('show_error_msg', $_SESSION['show_error_msg']); |
|
278 |
unset($_SESSION['show_error_msg']); |
|
279 |
} |
|
280 |
|
fb02f0
|
281 |
//* Parse the templates and send output to the browser |
T |
282 |
$this->onShowEnd(); |
|
283 |
} |
b1a6a5
|
284 |
|
6ac26d
|
285 |
public function onShowEnd() |
b1a6a5
|
286 |
{ |
fb02f0
|
287 |
global $app; |
T |
288 |
$app->tpl_defaults(); |
|
289 |
$app->tpl->pparse(); |
|
290 |
} |
b1a6a5
|
291 |
|
fb02f0
|
292 |
} |
T |
293 |
|
b1a6a5
|
294 |
?> |