navigation  interaction  search

 other resources

root/tags/phpbms-0.51/search.php

Revision 1 (checked in by mipalmer, 2 years ago)

--

Line 
1 <?php
2     require_once("include/session.php");
3     require_once("include/search_class.php");
4     require_once("include/common_functions.php");   
5     
6     if(!isset($_GET["id"])) reportError(100,"Table ID Required");
7     
8     $displayTable= new displaySearchTable;   
9
10     //initialize the object
11     $displayTable->initialize($_GET["id"]);   
12
13     session_register("passedjoinclause");
14     session_register("passedjoinwhere");
15     
16
17     //process commands...
18     if(!isset($_POST["othercommands"])) $_POST["othercommands"]="";
19     if(!isset($_POST["relationship"])) $_POST["relationship"]="";
20     if(!isset($_POST["advancedsearch"])) $_POST["advancedsearch"]="";
21     if(!isset($_POST["advancedsort"])) $_POST["advancedsort"]="";
22             
23     if($_POST["othercommands"]) $_POST["command"]="other";
24     if($_POST["relationship"]) $_POST["command"]="relate records";
25     if($_POST["advancedsearch"]) $_POST["command"]="advanced search";
26     if($_POST["advancedsort"]) $_POST["command"]="advanced sort";
27     
28
29     if(isset($_POST["command"])){
30         
31         switch($_POST["command"]){
32             //command switches go here
33         case "print":
34             // run the print routine
35             //=====================================================================================================
36             $displayTable->querytype="print";
37             $theids=explode(",",$_POST["theids"]);
38             $_SESSION["printing"]["tableid"]=$displayTable->thetabledef["id"];
39             $_SESSION["printing"]["maintable"]=$displayTable->thetabledef["maintable"];
40             $_SESSION["printing"]["theids"]=$theids;
41             header("Location: print.php");
42         break;
43         case "other":
44             $displayTable->recordoffset=0;       
45             // process table specific commands (passed by settings)       
46             //=====================================================================================================
47             $theids=explode(",",$_POST["theids"]);
48             eval($_POST["othercommands"]."(\$theids);");
49         break;
50         case "Search":
51             $displayTable->recordoffset=0;       
52             $displayTable->buildSearch($_POST);       
53         break;       
54         case "Reset":       
55             $displayTable->recordoffset=0;       
56             $displayTable->resetQuery();
57         break;
58         case "omit":
59             // omit selected from current query
60             //=====================================================================================================
61             $displayTable->recordoffset=0;       
62             $tempwhere="";
63             $theids=explode(",",$_POST["theids"]);
64             foreach($theids as $theid){
65                 $tempwhere.=" or ".$displayTable->thetabledef["maintable"].".id=".$theid;
66             }
67             $tempwhere=substr($tempwhere,3);
68             $displayTable->querywhereclause="(".$displayTable->querywhereclause.") and not (".$tempwhere.")";           
69         break;
70         case "keep":
71             // keep only those ids
72             //=====================================================================================================
73             $displayTable->recordoffset=0;       
74             $tempwhere="";
75             $theids=explode(",",$_POST["theids"]);
76             foreach($theids as $theid){
77                 $tempwhere.=" or ".$displayTable->thetabledef["maintable"].".id=".$theid;
78             }
79             $tempwhere=substr($tempwhere,3);
80             $displayTable->querywhereclause=$tempwhere;
81         break;
82         case "new":
83             // relocate to new screen
84             //=====================================================================================================
85             header("Location: ".$displayTable->thetabledef["addfile"]);
86         break;
87         case $displayTable->thetabledef["deletebutton"]:
88             //=====================================================================================================
89             $theids=explode(",",$_POST["theids"]);
90             delete_record($theids);
91         break;
92         case "edit":
93             // relocate to edit screen
94             //=====================================================================================================
95             $theids=explode(",",$_POST["theids"]);
96             header("Location: ".$displayTable->thetabledef["editfile"]."?id=".$theids[0]);
97         break;
98         case "advanced search":
99             $displayTable->recordoffset=0;       
100             $displayTable->querywhereclause=stripslashes($_POST["advancedsearch"]);           
101             $displayTable->querytype="advanced search";
102         break;
103         case "advanced sort":
104             $displayTable->recordoffset=0;       
105             $displayTable->querysortorder=$_POST["advancedsort"];
106         break;
107         case "relate records":
108             include("include/relationships.php");
109             $theids=explode(",",$_POST["theids"]);
110             $goto=perform_relationship($_POST["relationship"],$theids);           
111             $_SESSION["temp_relateto"]=$displayTable->thetabledef["maintable"];
112             $displayTable->querytype="relate";
113
114             header("Location: ".$goto);
115         break;       
116             
117         }//end switch
118     }//end if
119     
120     //on the fly sorting... this needs to be done after command processing or the querystatement will not work.
121     if(!isset($_POST["newsort"])) $_POST["newsort"]="";
122     if(!isset($_POST["desc"])) $_POST["desc"]="";
123     
124     if($_POST["newsort"]!="") {
125         //$displayTable->setSort($_POST["newsort"]);
126         $displayTable->recordoffset=0;       
127         foreach ($displayTable->thecolumns as $therow){
128             if ($_POST["newsort"]==$therow["name"]) $therow["sortorder"]? $displayTable->querysortorder=$therow["sortorder"] : $displayTable->querysortorder=$therow["column"];
129         }
130         $_POST["startnum"]=1;       
131     } elseif($_POST["desc"]!="") {
132          $displayTable->querysortorder.=" DESC";
133          $displayTable->recordoffset=0;       
134     }
135     
136 if($displayTable->querytype!="print" and $displayTable->querytype!="relate" and $displayTable->querytype!="new" and $displayTable->querytype!="edit") {
137     
138     //Check for passed join clause from relationships
139     //==============================================================
140     if(isset($_SESSION["passedjoinclause"])) {
141         $displayTable->recordoffset=0;
142         $displayTable->queryjoinclause=$_SESSION["passedjoinclause"];
143         session_unregister("passedjoinclause");           
144     }
145
146     //Check for passed whereclause
147     //==============================================================
148     if(isset($_SESSION["passedjoinwhere"])) {
149         $displayTable->recordoffset=0;
150         //gettin kinda ugly here... maybe there's a better solution somewhere?
151         $displayTable->querywhereclause=$_SESSION["passedjoinwhere"];
152         session_unregister("passedjoinwhere");
153     
154         //keeping settings
155         $displayTable->querytype="related records from ".$_SESSION["temp_relateto"];   
156         session_unregister("temp_relateto");
157     }
158     
159     //record offset?
160     if(isset($_POST["offset"])) if($_POST["offset"]!="") $displayTable->recordoffset=$_POST["offset"];
161     
162     
163     $displayTable->issueQuery();
164 ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
165 <html>
166 <head>
167 <title><?php echo $displayTable->thetabledef["displayname"] ?></title>
168 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
169 <link href="common/stylesheet/<?php echo $_SESSION["stylesheet"] ?>/base.css" rel="stylesheet" type="text/css">
170 <!-- These Javscript files and scripts are required for the query_searchdisplay and query_function files to
171      work properly -->
172 <script language="JavaScript" src="common/javascript/queryfunctions.js" type="text/javascript" ></script>
173 </head>
174 <body>
175 <?php include("menu.php");?>
176 <?php
177     $table_class="bodyline";
178     if(isset($has_header)) {
179         display_header();
180         $table_class=$displayTable->isselect?"bodyline":"untabbedbox";
181     }
182     
183 ?>
184 <div class="<?php echo $table_class ?>">
185     <div class="searchtitle"><?php echo $displayTable->thetabledef["displayname"] ?></div>
186     <div>
187 <?PHP 
188         //Search//select
189             $displayTable->displaySearch();
190             $displayTable->displayQueryButtons();
191             $displayTable->displayQueryHeader();
192             if($displayTable->numrows>0){
193                 $displayTable->displayQueryResults();
194                 $displayTable->displayQueryFooter();
195             }
196             else
197                 $displayTable->displayNoResults();               
198             
199             $displayTable->displayRelationships();
200             $displayTable->saveQueryParameters();
201     ?></div>
202 </div>
203 </body>
204 </html><?php }// end relate/print if?>
Note: See TracBrowser for help on using the browser.
Copyright © 2006-2007 Kreotek, LLC. All Rights reserved.