commit | author | age
|
25ece9
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
436ed8
|
4 |
Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
25ece9
|
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 searchform_actions { |
b1a6a5
|
32 |
|
25ece9
|
33 |
var $id; |
T |
34 |
var $idx_key; |
|
35 |
var $DataRowColor; |
|
36 |
var $SQLExtWhere = ''; |
|
37 |
var $SQLOrderBy = ''; |
b1a6a5
|
38 |
|
25ece9
|
39 |
function onLoad() { |
T |
40 |
global $app, $conf, $list_def_file; |
b1a6a5
|
41 |
|
25ece9
|
42 |
if(!is_object($app->tpl)) $app->uses('tpl'); |
T |
43 |
if(!is_object($app->searchform)) $app->uses('searchform'); |
|
44 |
if(!is_object($app->tform)) $app->uses('tform'); |
b1a6a5
|
45 |
|
25ece9
|
46 |
// Load list definition |
T |
47 |
$app->searchform->loadListDef($list_def_file); |
b1a6a5
|
48 |
|
25ece9
|
49 |
// Delete the search form contents, if requested |
T |
50 |
if($_REQUEST["empty_searchfields"] == 'yes') { |
|
51 |
$list_name = $app->searchform->listDef["name"]; |
|
52 |
unset($_SESSION["search"][$list_name]); |
|
53 |
} |
b1a6a5
|
54 |
|
25ece9
|
55 |
// Save the search for later usage |
T |
56 |
if($_REQUEST["btn_submit_search_save"] && $_REQUEST["search_save_as"] != '') { |
|
57 |
$app->searchform->saveSearchSettings($_REQUEST["search_save_as"]); |
|
58 |
} |
b1a6a5
|
59 |
|
25ece9
|
60 |
// Set th returnto value for forms |
T |
61 |
$_SESSION["s"]["form"]["return_to_url"] = $app->searchform->listDef["file"]; |
b1a6a5
|
62 |
|
25ece9
|
63 |
if(!is_file('templates/'.$app->searchform->listDef["name"].'_search.htm')) { |
T |
64 |
$app->uses('searchform_tpl_generator'); |
|
65 |
$app->searchform_tpl_generator->buildHTML($app->searchform->listDef); |
|
66 |
} |
b1a6a5
|
67 |
|
25ece9
|
68 |
$app->tpl->newTemplate("searchpage.tpl.htm"); |
b1a6a5
|
69 |
$app->tpl->setInclude('content_tpl', 'templates/'.$app->searchform->listDef["name"].'_search.htm'); |
25ece9
|
70 |
|
T |
71 |
// Getting Datasets from DB |
|
72 |
$records = $app->db->queryAllRecords($this->getQueryString()); |
|
73 |
|
|
74 |
|
|
75 |
$this->DataRowColor = "#FFFFFF"; |
|
76 |
if(is_array($records)) { |
b1a6a5
|
77 |
$this->idx_key = $app->searchform->listDef["table_idx"]; |
25ece9
|
78 |
foreach($records as $rec) { |
T |
79 |
$records_new[] = $this->prepareDataRow($rec); |
|
80 |
} |
|
81 |
} |
|
82 |
|
b1a6a5
|
83 |
$app->tpl->setLoop('records', $records_new); |
MC |
84 |
|
25ece9
|
85 |
//print_r($records_new); |
T |
86 |
|
|
87 |
$this->onShow(); |
b1a6a5
|
88 |
|
MC |
89 |
|
25ece9
|
90 |
} |
b1a6a5
|
91 |
|
25ece9
|
92 |
function prepareDataRow($rec) { |
T |
93 |
global $app; |
b1a6a5
|
94 |
|
25ece9
|
95 |
$rec = $app->searchform->decode($rec); |
T |
96 |
|
|
97 |
// Alternating datarow colors |
|
98 |
$this->DataRowColor = ($this->DataRowColor == "#FFFFFF")?"#EEEEEE":"#FFFFFF"; |
|
99 |
$rec["bgcolor"] = $this->DataRowColor; |
b1a6a5
|
100 |
|
25ece9
|
101 |
// substitute value for select fields |
T |
102 |
foreach($app->searchform->listDef["item"] as $field) { |
|
103 |
$key = $field["field"]; |
|
104 |
if($field['formtype'] == "SELECT") { |
a791b4
|
105 |
if($rec[$key] == 'y' or $rec[$key] == 'n') { |
T |
106 |
// Set a additional image variable for bolean fields |
|
107 |
$rec['_'.$key.'_'] = ($rec[$key] == 'y')?'list_icon_true.png':'list_icon_false.png'; |
|
108 |
} |
|
109 |
// substitute value for select field |
25ece9
|
110 |
$rec[$key] = $field['value'][$rec[$key]]; |
T |
111 |
} |
|
112 |
} |
b1a6a5
|
113 |
|
25ece9
|
114 |
// The variable "id" contains always the index variable |
T |
115 |
$rec["id"] = $rec[$this->idx_key]; |
b1a6a5
|
116 |
|
25ece9
|
117 |
return $rec; |
T |
118 |
} |
b1a6a5
|
119 |
|
25ece9
|
120 |
function getQueryString() { |
T |
121 |
global $app; |
b1a6a5
|
122 |
|
25ece9
|
123 |
// Generate the search sql |
T |
124 |
if($app->searchform->listDef["auth"] != 'no') { |
|
125 |
if($_SESSION["s"]["user"]["typ"] == "admin") { |
|
126 |
$sql_where = ""; |
|
127 |
} else { |
|
128 |
$sql_where = $app->tform->getAuthSQL('r')." and"; |
|
129 |
} |
|
130 |
} |
b1a6a5
|
131 |
|
25ece9
|
132 |
if($this->SQLExtWhere != '') { |
T |
133 |
$sql_where .= " ".$this->SQLExtWhere." and"; |
|
134 |
} |
|
135 |
|
|
136 |
$sql_where = $app->searchform->getSearchSQL($sql_where); |
|
137 |
$app->tpl->setVar($app->searchform->searchValues); |
b1a6a5
|
138 |
|
25ece9
|
139 |
$order_by_sql = $this->SQLOrderBy; |
T |
140 |
|
|
141 |
// Generate SQL for paging |
|
142 |
$limit_sql = $app->searchform->getPagingSQL($sql_where); |
b1a6a5
|
143 |
$app->tpl->setVar("paging", $app->searchform->pagingHTML); |
25ece9
|
144 |
|
T |
145 |
return "SELECT * FROM ".$app->searchform->listDef["table"]." WHERE $sql_where $order_by_sql $limit_sql"; |
b1a6a5
|
146 |
|
25ece9
|
147 |
} |
b1a6a5
|
148 |
|
MC |
149 |
|
25ece9
|
150 |
function onShow() { |
T |
151 |
global $app; |
b1a6a5
|
152 |
|
25ece9
|
153 |
// Language File setzen |
d82bfb
|
154 |
$lng_file = ISPC_WEB_PATH.'/lang/lib/lang/'.$_SESSION['s']['language'].'_list.lng'; |
F |
155 |
if(!file_exists($lng_file)) $lng_file = ISPC_WEB_PATH.'/lang/lib/lang/en_'.'_list.lng'; |
b1a6a5
|
156 |
include $lng_file; |
25ece9
|
157 |
$lng_file = "lib/lang/".$_SESSION["s"]["language"]."_".$app->searchform->listDef['name']."_search.lng"; |
d82bfb
|
158 |
if(!file_exists($lng_file)) $lng_file = 'lib/lang/en_'.$app->searchform->listDef['name']."_search.lng"; |
b1a6a5
|
159 |
include $lng_file; |
25ece9
|
160 |
$app->tpl->setVar($wb); |
b1a6a5
|
161 |
$app->tpl->setVar("form_action", $app->searchform->listDef["file"]); |
MC |
162 |
|
25ece9
|
163 |
// Parse the templates and send output to the browser |
T |
164 |
$this->onShowEnd(); |
|
165 |
} |
b1a6a5
|
166 |
|
25ece9
|
167 |
function onShowEnd() { |
T |
168 |
global $app; |
|
169 |
|
|
170 |
if(count($_REQUEST) > 0) { |
b1a6a5
|
171 |
$app->tpl->setVar('searchresult_visible', 1); |
MC |
172 |
if($_REQUEST['searchresult_visible'] == 'no') $app->tpl->setVar('searchresult_visible', 0); |
|
173 |
|
25ece9
|
174 |
if($_REQUEST['searchform_visible'] == 'yes') { |
b1a6a5
|
175 |
$app->tpl->setVar('searchform_visible', 1); |
25ece9
|
176 |
} else { |
b1a6a5
|
177 |
$app->tpl->setVar('searchform_visible', 0); |
25ece9
|
178 |
} |
T |
179 |
} else { |
b1a6a5
|
180 |
$app->tpl->setVar('searchform_visible', 1); |
MC |
181 |
if($_REQUEST['searchform_visible'] == 'no') $app->tpl->setVar('searchform_visible', 0); |
|
182 |
|
25ece9
|
183 |
if($_REQUEST['searchresult_visible'] == 'yes') { |
b1a6a5
|
184 |
$app->tpl->setVar('searchresult_visible', 1); |
25ece9
|
185 |
} else { |
b1a6a5
|
186 |
$app->tpl->setVar('searchresult_visible', 0); |
25ece9
|
187 |
} |
T |
188 |
} |
b1a6a5
|
189 |
|
25ece9
|
190 |
// make columns visible |
b1a6a5
|
191 |
$visible_columns = explode(",", $app->searchform->listDef['default_columns']); |
25ece9
|
192 |
foreach($visible_columns as $col) { |
b1a6a5
|
193 |
$app->tpl->setVar($col.'_visible', 1); |
25ece9
|
194 |
} |
b1a6a5
|
195 |
|
25ece9
|
196 |
$app->tpl_defaults(); |
T |
197 |
$app->tpl->pparse(); |
|
198 |
} |
b1a6a5
|
199 |
|
25ece9
|
200 |
} |
T |
201 |
|
b1a6a5
|
202 |
?> |