| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | $Rev$ | $LastChangedBy$ |
|---|
| 4 | $LastChangedDate$ |
|---|
| 5 | +-------------------------------------------------------------------------+ |
|---|
| 6 | | Copyright (c) 2004 - 2007, 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"])) $error = new appError(100,"Passed Parameter not present."); |
|---|
| 43 | $_GET["id"]= (integer) $_GET["id"]; |
|---|
| 44 | |
|---|
| 45 | $displayTable= new displaySearchTable($db); |
|---|
| 46 | |
|---|
| 47 | //initialize the object |
|---|
| 48 | $displayTable->initialize($_GET["id"]); |
|---|
| 49 | |
|---|
| 50 | session_register("passedjoinclause"); |
|---|
| 51 | session_register("passedjoinwhere"); |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | //process commands... |
|---|
| 55 | if(!isset($_POST["othercommands"])) $_POST["othercommands"]=""; |
|---|
| 56 | if(!isset($_POST["relationship"])) $_POST["relationship"]=""; |
|---|
| 57 | if(!isset($_POST["advancedsearch"])) $_POST["advancedsearch"]=""; |
|---|
| 58 | if(!isset($_POST["advancedsort"])) $_POST["advancedsort"]=""; |
|---|
| 59 | |
|---|
| 60 | if(isset($_POST["doprint"])) |
|---|
| 61 | if($_POST["doprint"] == "print") |
|---|
| 62 | $_POST["command"]="print"; |
|---|
| 63 | |
|---|
| 64 | if(isset($_POST["deleteCommand"])) |
|---|
| 65 | if($_POST["deleteCommand"]) $_POST["command"]=$_POST["deleteCommand"]; |
|---|
| 66 | if($_POST["othercommands"]) $_POST["command"]="other"; |
|---|
| 67 | if($_POST["relationship"]) $_POST["command"]="relate records"; |
|---|
| 68 | if($_POST["advancedsearch"]) $_POST["command"]="advanced search"; |
|---|
| 69 | if($_POST["advancedsort"]) $_POST["command"]="advanced sort"; |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | if(isset($_POST["command"])){ |
|---|
| 73 | |
|---|
| 74 | switch($_POST["command"]){ |
|---|
| 75 | //command switches go here |
|---|
| 76 | case "print": |
|---|
| 77 | // run the print routine |
|---|
| 78 | //===================================================================================================== |
|---|
| 79 | $displayTable->querytype="print"; |
|---|
| 80 | |
|---|
| 81 | if($_POST["theids"] === "") |
|---|
| 82 | $_POST["theids"]="-100"; |
|---|
| 83 | |
|---|
| 84 | $theids=explode(",",$_POST["theids"]); |
|---|
| 85 | $_SESSION["printing"]["tableid"]=$displayTable->thetabledef["id"]; |
|---|
| 86 | $_SESSION["printing"]["maintable"]=$displayTable->thetabledef["maintable"]; |
|---|
| 87 | $_SESSION["printing"]["theids"]=$theids; |
|---|
| 88 | goURL("print.php"); |
|---|
| 89 | break; |
|---|
| 90 | case "delete": |
|---|
| 91 | //===================================================================================================== |
|---|
| 92 | |
|---|
| 93 | $_POST["othercommands"] = -1; |
|---|
| 94 | |
|---|
| 95 | case "other": |
|---|
| 96 | $displayTable->recordoffset=0; |
|---|
| 97 | // process table specific commands (passed by settings) |
|---|
| 98 | //===================================================================================================== |
|---|
| 99 | $theids=explode(",",$_POST["theids"]); |
|---|
| 100 | |
|---|
| 101 | //try to include table specific functions |
|---|
| 102 | if(file_exists("modules/".$displayTable->thetabledef["name"]."/include/".$displayTable->thetabledef["maintable"].".php")) |
|---|
| 103 | include("modules/".$displayTable->thetabledef["name"]."/include/".$displayTable->thetabledef["maintable"].".php"); |
|---|
| 104 | |
|---|
| 105 | //next, see if the searchclass exists |
|---|
| 106 | if(class_exists($displayTable->thetabledef["maintable"]."SearchFunctions")){ |
|---|
| 107 | $classname = $displayTable->thetabledef["maintable"]."SearchFunctions"; |
|---|
| 108 | $searchFunctions = new $classname($db,$displayTable->thetabledef["id"],$theids); |
|---|
| 109 | } else |
|---|
| 110 | $searchFunctions = new searchFunctions($db,$displayTable->thetabledef["id"],$theids); |
|---|
| 111 | |
|---|
| 112 | //grab the method name |
|---|
| 113 | if(((int) $_POST["othercommands"]) === -1) |
|---|
| 114 | $functionname = "delete_record"; |
|---|
| 115 | else { |
|---|
| 116 | $querystatement = "SELECT name FROM tableoptions WHERE id=".((int) $_POST["othercommands"]); |
|---|
| 117 | $queryresult = $db->query($querystatement); |
|---|
| 118 | $therecord = $db->fetchArray($queryresult); |
|---|
| 119 | $functionname = $therecord["name"]; |
|---|
| 120 | } |
|---|
| 121 | |
|---|
| 122 | if(method_exists($searchFunctions,$functionname)) |
|---|
| 123 | $statusmessage = $searchFunctions->$functionname(); |
|---|
| 124 | else |
|---|
| 125 | $statusmessage = "Function ".$functionname." not defined"; |
|---|
| 126 | |
|---|
| 127 | break; |
|---|
| 128 | case "search": |
|---|
| 129 | $displayTable->recordoffset=0; |
|---|
| 130 | $displayTable->buildSearch($_POST); |
|---|
| 131 | break; |
|---|
| 132 | case "reset": |
|---|
| 133 | $displayTable->recordoffset=0; |
|---|
| 134 | $displayTable->resetQuery(); |
|---|
| 135 | break; |
|---|
| 136 | case "omit": |
|---|
| 137 | // omit selected from current query |
|---|
| 138 | //===================================================================================================== |
|---|
| 139 | $displayTable->recordoffset=0; |
|---|
| 140 | $tempwhere=""; |
|---|
| 141 | $theids=explode(",",$_POST["theids"]); |
|---|
| 142 | foreach($theids as $theid){ |
|---|
| 143 | $tempwhere.=" or ".$displayTable->thetabledef["maintable"].".id=".$theid; |
|---|
| 144 | } |
|---|
| 145 | $tempwhere=substr($tempwhere,3); |
|---|
| 146 | $displayTable->querywhereclause="(".$displayTable->querywhereclause.") and not (".$tempwhere.")"; |
|---|
| 147 | break; |
|---|
| 148 | case "keep": |
|---|
| 149 | // keep only those ids |
|---|
| 150 | //===================================================================================================== |
|---|
| 151 | $displayTable->recordoffset=0; |
|---|
| 152 | $tempwhere=""; |
|---|
| 153 | $theids=explode(",",$_POST["theids"]); |
|---|
| 154 | foreach($theids as $theid){ |
|---|
| 155 | $tempwhere.=" or ".$displayTable->thetabledef["maintable"].".id=".$theid; |
|---|
| 156 | } |
|---|
| 157 | $tempwhere=substr($tempwhere,3); |
|---|
| 158 | $displayTable->querywhereclause=$tempwhere; |
|---|
| 159 | break; |
|---|
| 160 | case "advanced search": |
|---|
| 161 | $displayTable->recordoffset=0; |
|---|
| 162 | $displayTable->querywhereclause=stripslashes($_POST["advancedsearch"]); |
|---|
| 163 | $displayTable->querytype="advanced search"; |
|---|
| 164 | break; |
|---|
| 165 | case "advanced sort": |
|---|
| 166 | $displayTable->showGroupings = 0; |
|---|
| 167 | $displayTable->recordoffset = 0; |
|---|
| 168 | $displayTable->querysortorder=$_POST["advancedsort"]; |
|---|
| 169 | break; |
|---|
| 170 | case "relate records": |
|---|
| 171 | include("include/relationships.php"); |
|---|
| 172 | $theids=explode(",",$_POST["theids"]); |
|---|
| 173 | $goto=perform_relationship($_POST["relationship"],$theids); |
|---|
| 174 | $_SESSION["temp_relateto"]=$displayTable->thetabledef["maintable"]; |
|---|
| 175 | $displayTable->querytype="relate"; |
|---|
| 176 | |
|---|
| 177 | goURL($goto); |
|---|
| 178 | break; |
|---|
| 179 | |
|---|
| 180 | }//end switch |
|---|
| 181 | }//end if |
|---|
| 182 | |
|---|
| 183 | //on the fly sorting... this needs to be done after command processing or the querystatement will not work. |
|---|
| 184 | if(!isset($_POST["newsort"])) $_POST["newsort"]=""; |
|---|
| 185 | if(!isset($_POST["desc"])) $_POST["desc"]=""; |
|---|
| 186 | |
|---|
| 187 | if($_POST["newsort"]!="") { |
|---|
| 188 | //$displayTable->setSort($_POST["newsort"]); |
|---|
| 189 | $displayTable->recordoffset=0; |
|---|
| 190 | $displayTable->showGroupings = false; |
|---|
| 191 | foreach ($displayTable->thecolumns as $therow){ |
|---|
| 192 | if ($_POST["newsort"]==$therow["name"]) $therow["sortorder"]? $displayTable->querysortorder=$therow["sortorder"] : $displayTable->querysortorder=$therow["column"]; |
|---|
| 193 | } |
|---|
| 194 | $_POST["startnum"]=1; |
|---|
| 195 | } elseif($_POST["desc"]!="") { |
|---|
| 196 | |
|---|
| 197 | $displayTable->showGroupings = false; |
|---|
| 198 | $displayTable->querysortorder.=" DESC"; |
|---|
| 199 | $displayTable->recordoffset=0; |
|---|
| 200 | |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | if($displayTable->querytype!="print" and $displayTable->querytype!="relate" and $displayTable->querytype!="new" and $displayTable->querytype!="edit") { |
|---|
| 204 | |
|---|
| 205 | //Check for passed join clause from relationships |
|---|
| 206 | //============================================================== |
|---|
| 207 | if(isset($_SESSION["passedjoinclause"])) { |
|---|
| 208 | $displayTable->recordoffset=0; |
|---|
| 209 | $displayTable->queryjoinclause=$_SESSION["passedjoinclause"]; |
|---|
| 210 | session_unregister("passedjoinclause"); |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | //Check for passed whereclause |
|---|
| 214 | //============================================================== |
|---|
| 215 | if(isset($_SESSION["passedjoinwhere"])) { |
|---|
| 216 | $displayTable->recordoffset=0; |
|---|
| 217 | //gettin kinda ugly here... maybe there's a better solution somewhere? |
|---|
| 218 | $displayTable->querywhereclause=$_SESSION["passedjoinwhere"]; |
|---|
| 219 | session_unregister("passedjoinwhere"); |
|---|
| 220 | |
|---|
| 221 | //keeping settings |
|---|
| 222 | $displayTable->querytype="related records from ".$_SESSION["temp_relateto"]; |
|---|
| 223 | session_unregister("temp_relateto"); |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | //record offset? |
|---|
| 227 | if(isset($_POST["offset"])) if($_POST["offset"]!="") $displayTable->recordoffset=$_POST["offset"]; |
|---|
| 228 | |
|---|
| 229 | $displayTable->issueQuery(); |
|---|
| 230 | |
|---|
| 231 | $pageTitle = $displayTable->thetabledef["displayname"]; |
|---|
| 232 | |
|---|
| 233 | $phpbms->cssIncludes[] = "pages/search.css"; |
|---|
| 234 | |
|---|
| 235 | $phpbms->jsIncludes[] = "common/javascript/queryfunctions.js"; |
|---|
| 236 | |
|---|
| 237 | include("header.php"); |
|---|
| 238 | |
|---|
| 239 | ?><div class="bodyline"> |
|---|
| 240 | <h1 id="srchScreen<?php echo $displayTable->thetabledef["id"] ?>"><?php echo $displayTable->thetabledef["displayname"] ?></h1> |
|---|
| 241 | <?php |
|---|
| 242 | //Search//select |
|---|
| 243 | $displayTable->displaySearch(); |
|---|
| 244 | $displayTable->displayQueryButtons(); |
|---|
| 245 | |
|---|
| 246 | $displayTable->displayResultTable(); |
|---|
| 247 | |
|---|
| 248 | $displayTable->displayRelationships(); |
|---|
| 249 | |
|---|
| 250 | $displayTable->saveQueryParameters(); |
|---|
| 251 | ?> |
|---|
| 252 | </div> |
|---|
| 253 | <?php include("footer.php");}?> |
|---|