phpBMS

root/trunk/phpbms/search.php

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