forked from weex/phpBMS
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsearch.php
342 lines (258 loc) · 12.6 KB
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<?php
/*
$Rev$ | $LastChangedBy$
$LastChangedDate$
+-------------------------------------------------------------------------+
| Copyright (c) 2004 - 2010, Kreotek LLC |
| All rights reserved. |
+-------------------------------------------------------------------------+
| |
| Redistribution and use in source and binary forms, with or without |
| modification, are permitted provided that the following conditions are |
| met: |
| |
| - Redistributions of source code must retain the above copyright |
| notice, this list of conditions and the following disclaimer. |
| |
| - Redistributions in binary form must reproduce the above copyright |
| notice, this list of conditions and the following disclaimer in the |
| documentation and/or other materials provided with the distribution. |
| |
| - Neither the name of Kreotek LLC nor the names of its contributore may |
| be used to endorse or promote products derived from this software |
| without specific prior written permission. |
| |
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| |
+-------------------------------------------------------------------------+
*/
require_once("include/session.php");
require_once("include/search_class.php");
if(!isset($_GET["id"]))
$error = new appError(100,"Passed Parameter not present.");
$_GET["id"] = mysqli_real_escape_string($db->db_link,$_GET["id"]);
$displayTable= new displaySearchTable($db);
//initialize the object
$displayTable->initialize($_GET["id"]);
if (isset($passedjoinclause)) $_SESSION["passedjoinclause"] = $passedjoinclause;
if (isset($passedjoinwhere)) $_SESSION["passedjoinwhere"] = $passedjoinwhere;
//process commands...
if(!isset($_POST["othercommands"])) $_POST["othercommands"]="";
if(!isset($_POST["relationship"])) $_POST["relationship"]="";
if(!isset($_POST["advancedsearch"])) $_POST["advancedsearch"]="";
if(!isset($_POST["advancedsort"])) $_POST["advancedsort"]="";
if(isset($_POST["doprint"]))
if($_POST["doprint"] == "print")
$_POST["command"]="print";
if(isset($_POST["deleteCommand"]))
if($_POST["deleteCommand"]) $_POST["command"]=$_POST["deleteCommand"];
if($_POST["othercommands"]) $_POST["command"]="other";
if($_POST["relationship"]) $_POST["command"]="relate records";
if($_POST["advancedsearch"]) $_POST["command"]="advanced search";
if($_POST["advancedsort"]) $_POST["command"]="advanced sort";
if(isset($_POST["command"])){
switch($_POST["command"]){
//command switches go here
case "print":
// run the print routine
//=====================================================================================================
$displayTable->querytype="print";
if($_POST["theids"] === "")
$_POST["theids"]="-100";
$theids=explode(",",$_POST["theids"]);
$_SESSION["printing"]["tableid"] = $displayTable->thetabledef["uuid"];
$_SESSION["printing"]["maintable"] = $displayTable->thetabledef["maintable"];
$_SESSION["printing"]["theids"]=$theids;
goURL("print.php");
break;
case "delete":
//=====================================================================================================
$_POST["othercommands"] = -1;
case "other":
// process table specific commands (passed by settings)
//=====================================================================================================
$displayTable->recordoffset=0;
$theids=explode(",",$_POST["theids"]);
//grab the method name
if(((int) $_POST["othercommands"]) === -1){
$functionname = "delete_record";
} else {
$querystatement = "
SELECT
name,
roleid
FROM
tableoptions
WHERE id = ".((int) $_POST["othercommands"]);
$queryresult = $db->query($querystatement);
$therecord = $db->fetchArray($queryresult);
$functionname = $therecord["name"];
if(!hasRights($therecord["roleid"]))
goURL(APP_PATH."noaccess.php");
}//endif
/**
* If the command is a push command, include tables.php
*/
if(strpos($functionname, ":") !== false)
include("include/tables.php");
//try to include table specific functions
if(file_exists("modules/".$displayTable->thetabledef["name"]."/include/".$displayTable->thetabledef["maintable"].".php"))
include("modules/".$displayTable->thetabledef["name"]."/include/".$displayTable->thetabledef["maintable"].".php");
//next, see if the searchclass exists
if(class_exists($displayTable->thetabledef["maintable"]."SearchFunctions")){
$classname = $displayTable->thetabledef["maintable"]."SearchFunctions";
$searchFunctions = new $classname($db,$displayTable->thetabledef["uuid"],$theids);
} else
$searchFunctions = new searchFunctions($db,$displayTable->thetabledef["uuid"],$theids);
if(!preg_match("/\:/", $functionname)){
if(method_exists($searchFunctions,$functionname))
$statusmessage = $searchFunctions->$functionname();
else
$statusmessage = "Function ".$functionname." not defined";
}else{
if(moduleExists("mod:b2d42220-443b-fe74-dbdb-ed2c0968c38c", $phpbms->modules))
$statusmessage = $searchFunctions->runPush($therecord["name"]);
}//end if
break;
case "search":
$displayTable->recordoffset=0;
$displayTable->buildSearch($_POST);
break;
case "reset":
$displayTable->recordoffset=0;
$displayTable->resetQuery();
break;
case "omit":
// omit selected from current query
//=====================================================================================================
$displayTable->recordoffset = 0;
$tempwhere = "";
$theids = explode(",",$_POST["theids"]);
foreach($theids as $theid)
$tempwhere.=" OR ".$displayTable->thetabledef["maintable"].".id=".((int) $theid);
$tempwhere = substr($tempwhere,3);
$displayTable->querywhereclause="(".$displayTable->querywhereclause.") AND NOT (".$tempwhere.")";
break;
case "keep":
// keep only those ids
//=====================================================================================================
$displayTable->recordoffset = 0;
$tempwhere = "";
$theids = explode(",",$_POST["theids"]);
foreach($theids as $theid)
$tempwhere.=" or ".$displayTable->thetabledef["maintable"].".id=".((int) $theid);
$tempwhere=substr($tempwhere,3);
$displayTable->querywhereclause = $tempwhere;
break;
case "advanced search":
if(!hasRights($displayTable->thetabledef["advsearchroleid"]))
goURL(APP_PATH."noaccess.php");
$displayTable->recordoffset=0;
$displayTable->querywhereclause=stripslashes($_POST["advancedsearch"]);
$displayTable->querytype="advanced search";
break;
case "run search":
/**
* Run a loaded search
*/
if(!hasRights($displayTable->thetabledef["advsearchroleid"])){
/**
* Need to load search from id, because the
* person does not have rights to override loaded
* searches
*/
$querystatement="
SELECT
sqlclause
FROM
usersearches
WHERE id=".((int) $_POST["LSList"]);
$queryresult = $db->query($querystatement);
$therecord = $db->fetchArray($queryresult);
$_POST["LSSQL"] = $therecord["sqlclause"];
}//endif
$displayTable->recordoffset=0;
$displayTable->querywhereclause=stripslashes($_POST["LSSQL"]);
$displayTable->querytype="advanced search";
break;
break;
case "advanced sort":
$displayTable->showGroupings = 0;
$displayTable->recordoffset = 0;
$displayTable->querysortorder = $_POST["advancedsort"];
break;
case "relate records":
include("include/relationships.php");
$theids = explode(",",$_POST["theids"]);
$relationship = new relationship($db, $_POST["relationship"]);
$newURL = $relationship->execute($theids);
$_SESSION["temp_relateto"] = $displayTable->thetabledef["displayname"];
$displayTable->querytype="relate";
goURL($newURL);
break;
}//end switch
}//end if
//on the fly sorting... this needs to be done after command processing or the querystatement will not work.
if(!isset($_POST["newsort"])) $_POST["newsort"]="";
if(!isset($_POST["desc"])) $_POST["desc"]="";
if($_POST["newsort"]!="") {
//$displayTable->setSort($_POST["newsort"]);
$displayTable->recordoffset=0;
$displayTable->showGroupings = false;
foreach ($displayTable->thecolumns as $therow){
if ($_POST["newsort"]==$therow["name"]) $therow["sortorder"]? $displayTable->querysortorder=$therow["sortorder"] : $displayTable->querysortorder=$therow["column"];
}
$_POST["startnum"]=1;
} elseif($_POST["desc"]!="") {
$displayTable->showGroupings = false;
$displayTable->querysortorder.=" DESC";
$displayTable->recordoffset=0;
}
if($displayTable->querytype!="print" and $displayTable->querytype!="relate" and $displayTable->querytype!="new" and $displayTable->querytype!="edit") {
//Check for passed join clause from relationships
//==============================================================
if(isset($_SESSION["passedjoinclause"])) {
$displayTable->recordoffset=0;
$displayTable->queryjoinclause=$_SESSION["passedjoinclause"];
session_unregister("passedjoinclause");
}
//Check for passed whereclause
//==============================================================
if(isset($_SESSION["passedjoinwhere"])) {
$displayTable->recordoffset=0;
//gettin kinda ugly here... maybe there's a better solution somewhere?
$displayTable->querywhereclause=$_SESSION["passedjoinwhere"];
session_unregister("passedjoinwhere");
//keeping settings
$displayTable->querytype="related records from ".$_SESSION["temp_relateto"];
session_unregister("temp_relateto");
}
//record offset?
if(isset($_POST["offset"])) if($_POST["offset"]!="") $displayTable->recordoffset=$_POST["offset"];
$displayTable->issueQuery();
$pageTitle = $displayTable->thetabledef["displayname"];
$phpbms->cssIncludes[] = "pages/search.css";
$phpbms->jsIncludes[] = "common/javascript/queryfunctions.js";
include("header.php");
?><div class="bodyline">
<h1 id="srchScreen<?php echo $displayTable->thetabledef["id"] ?>"><?php echo $displayTable->thetabledef["displayname"] ?></h1>
<?php
//Search//select
$displayTable->displaySearch();
$displayTable->displayQueryButtons();
$displayTable->displayResultTable();
$displayTable->showRelationships();
$displayTable->saveQueryParameters();
?>
</div>
<?php include("footer.php");}?>