navigation  interaction  search

 other resources

root/tags/phpbms-0.61/search.php

Revision 51 (checked in by brieb, 3 years ago)

- Added license to the top of every page with code.

Line 
1 <?php
2 /*
3  +-------------------------------------------------------------------------+
4  | Copyright (c) 2005, Kreotek LLC                                         |
5  | All rights reserved.                                                    |
6  +-------------------------------------------------------------------------+
7  |                                                                         |
8  | Redistribution and use in source and binary forms, with or without      |
9  | modification, are permitted provided that the following conditions are  |
10  | met:                                                                    |
11  |                                                                         |
12  | - Redistributions of source code must retain the above copyright        |
13  |   notice, this list of conditions and the following disclaimer.         |
14  |                                                                         |
15  | - Redistributions in binary form must reproduce the above copyright     |
16  |   notice, this list of conditions and the following disclaimer in the   |
17  |   documentation and/or other materials provided with the distribution.  |
18  |                                                                         |
19  | - Neither the name of Kreotek LLC nor the names of its contributore may |
20  |   be used to endorse or promote products derived from this software     |
21  |   without specific prior written permission.                            |
22  |                                                                         |
23  | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS     |
24  | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT       |
25  | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
26  | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT      |
27  | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,   |
28  | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT        |
29  | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,   |
30  | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY   |
31  | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT     |
32  | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE   |
33  | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.    |
34  |                                                                         |
35  +-------------------------------------------------------------------------+
36 */
37     require_once("include/session.php");
38     require_once("include/search_class.php");
39     require_once("include/common_functions.php");   
40     
41     if(!isset($_GET["id"])) reportError(100,"Passed Parameter not present.");
42     $_GET["id"]= (integer) $_GET["id"];
43     
44     $displayTable= new displaySearchTable;   
45
46     //initialize the object
47     $displayTable->initialize($_GET["id"]);   
48
49     session_register("passedjoinclause");
50     session_register("passedjoinwhere");
51     
52
53     //process commands...
54     if(!isset($_POST["othercommands"])) $_POST["othercommands"]="";
55     if(!isset($_POST["relationship"])) $_POST["relationship"]="";
56     if(!isset($_POST["advancedsearch"])) $_POST["advancedsearch"]="";
57     if(!isset($_POST["advancedsort"])) $_POST["advancedsort"]="";
58             
59     if(isset($_POST["doprint"])) $_POST["command"]="print";
60     if(isset($_POST["deleteCommand"]))
61         if($_POST["deleteCommand"]) $_POST["command"]=$_POST["deleteCommand"];
62     if($_POST["othercommands"]) $_POST["command"]="other";
63     if($_POST["relationship"]) $_POST["command"]="relate records";
64     if($_POST["advancedsearch"]) $_POST["command"]="advanced search";
65     if($_POST["advancedsort"]) $_POST["command"]="advanced sort";
66     
67
68     if(isset($_POST["command"])){
69         
70         switch($_POST["command"]){
71             //command switches go here
72         case "print":
73             // run the print routine
74             //=====================================================================================================
75             $displayTable->querytype="print";
76             $theids=explode(",",$_POST["theids"]);
77             $_SESSION["printing"]["tableid"]=$displayTable->thetabledef["id"];
78             $_SESSION["printing"]["maintable"]=$displayTable->thetabledef["maintable"];
79             $_SESSION["printing"]["theids"]=$theids;
80             header("Location: print.php");
81         break;
82         case "other":
83             $displayTable->recordoffset=0;       
84             // process table specific commands (passed by settings)       
85             //=====================================================================================================
86             $theids=explode(",",$_POST["theids"]);
87             eval("\$tempmessage=".$_POST["othercommands"]."(\$theids);");
88             if($tempmessage) $statusmessage=$tempmessage;           
89         break;
90         case "search":
91             $displayTable->recordoffset=0;       
92             $displayTable->buildSearch($_POST);       
93         break;       
94         case "reset":       
95             $displayTable->recordoffset=0;       
96             $displayTable->resetQuery();
97         break;
98         case "omit":
99             // omit selected from current query
100             //=====================================================================================================
101             $displayTable->recordoffset=0;       
102             $tempwhere="";
103             $theids=explode(",",$_POST["theids"]);
104             foreach($theids as $theid){
105                 $tempwhere.=" or ".$displayTable->thetabledef["maintable"].".id=".$theid;
106             }
107             $tempwhere=substr($tempwhere,3);
108             $displayTable->querywhereclause="(".$displayTable->querywhereclause.") and not (".$tempwhere.")";           
109         break;
110         case "keep":
111             // keep only those ids
112             //=====================================================================================================
113             $displayTable->recordoffset=0;       
114             $tempwhere="";
115             $theids=explode(",",$_POST["theids"]);
116             foreach($theids as $theid){
117                 $tempwhere.=" or ".$displayTable->thetabledef["maintable"].".id=".$theid;
118             }
119             $tempwhere=substr($tempwhere,3);
120             $displayTable->querywhereclause=$tempwhere;
121         break;
122         case "delete":
123             //=====================================================================================================
124             $theids=explode(",",$_POST["theids"]);
125             $tempmessage=delete_record($theids);
126             if($tempmessage) $statusmessage=$tempmessage;
127         break;
128         case "advanced search":
129             $displayTable->recordoffset=0;       
130             $displayTable->querywhereclause=stripslashes($_POST["advancedsearch"]);           
131             $displayTable->querytype="advanced search";
132         break;
133         case "advanced sort":
134             $displayTable->recordoffset=0;       
135             $displayTable->querysortorder=$_POST["advancedsort"];
136         break;
137         case "relate records":
138             include("include/relationships.php");
139             $theids=explode(",",$_POST["theids"]);
140             $goto=perform_relationship($_POST["relationship"],$theids);           
141             $_SESSION["temp_relateto"]=$displayTable->thetabledef["maintable"];
142             $displayTable->querytype="relate";
143
144             header("Location: ".$goto);
145         break;       
146             
147         }//end switch
148     }//end if
149     
150     //on the fly sorting... this needs to be done after command processing or the querystatement will not work.
151     if(!isset($_POST["newsort"])) $_POST["newsort"]="";
152     if(!isset($_POST["desc"])) $_POST["desc"]="";
153     
154     if($_POST["newsort"]!="") {
155         //$displayTable->setSort($_POST["newsort"]);
156         $displayTable->recordoffset=0;       
157         foreach ($displayTable->thecolumns as $therow){
158             if ($_POST["newsort"]==$therow["name"]) $therow["sortorder"]? $displayTable->querysortorder=$therow["sortorder"] : $displayTable->querysortorder=$therow["column"];
159         }
160         $_POST["startnum"]=1;       
161     } elseif($_POST["desc"]!="") {
162          $displayTable->querysortorder.=" DESC";
163          $displayTable->recordoffset=0;       
164     }
165     
166 if($displayTable->querytype!="print" and $displayTable->querytype!="relate" and $displayTable->querytype!="new" and $displayTable->querytype!="edit") {
167     
168     //Check for passed join clause from relationships
169     //==============================================================
170     if(isset($_SESSION["passedjoinclause"])) {
171         $displayTable->recordoffset=0;
172         $displayTable->queryjoinclause=$_SESSION["passedjoinclause"];
173         session_unregister("passedjoinclause");           
174     }
175
176     //Check for passed whereclause
177     //==============================================================
178     if(isset($_SESSION["passedjoinwhere"])) {
179         $displayTable->recordoffset=0;
180         //gettin kinda ugly here... maybe there's a better solution somewhere?
181         $displayTable->querywhereclause=$_SESSION["passedjoinwhere"];
182         session_unregister("passedjoinwhere");
183     
184         //keeping settings
185         $displayTable->querytype="related records from ".$_SESSION["temp_relateto"];   
186         session_unregister("temp_relateto");
187     }
188     
189     //record offset?
190     if(isset($_POST["offset"])) if($_POST["offset"]!="") $displayTable->recordoffset=$_POST["offset"];
191     
192     
193     $displayTable->issueQuery();
194 ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
195 <html>
196 <head>
197 <title><?php echo $displayTable->thetabledef["displayname"] ?></title>
198 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
199 <link href="<?php echo $_SESSION["app_path"] ?>common/stylesheet/<?php echo $_SESSION["stylesheet"] ?>/base.css" rel="stylesheet" type="text/css">
200 <!-- These Javscript files and scripts are required for the query_searchdisplay and query_function files to
201      work properly -->
202 <script language="JavaScript" src="common/javascript/common.js" type="text/javascript" ></script>
203 <script language="JavaScript" src="common/javascript/queryfunctions.js" type="text/javascript" ></script>
204 </head>
205 <body><?php include("menu.php");?><?php if(isset($has_header)) display_header();?><div class="bodyline">
206     <h1 id="srchScreen<?php echo $displayTable->thetabledef["id"] ?>"><?php echo $displayTable->thetabledef["displayname"] ?></h1>
207     <div>
208 <?PHP 
209         //Search//select
210             $displayTable->displaySearch();
211             $displayTable->displayQueryButtons();
212             $displayTable->displayQueryHeader();
213             if($displayTable->numrows>0){
214                 $displayTable->displayQueryResults();
215                 $displayTable->displayQueryFooter();
216             }
217             else
218                 $displayTable->displayNoResults();               
219             
220             $displayTable->displayRelationships();
221             $displayTable->saveQueryParameters();
222     ?></div>
223 </div>
224 <?php include("footer.php")?>
225 </body>
226 </html><?php }// end relate/print if?>
Note: See TracBrowser for help on using the browser.
Copyright © 2006-2007 Kreotek, LLC. All Rights reserved.