| 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("include/session.php"); |
|---|
| 40 | |
|---|
| 41 | class savedSearch{ |
|---|
| 42 | |
|---|
| 43 | var $db; |
|---|
| 44 | |
|---|
| 45 | function savedSearch($db){ |
|---|
| 46 | $this->db=$db; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | function delete($id){ |
|---|
| 50 | $querystatement="DELETE FROM usersearches |
|---|
| 51 | WHERE id=".((int) $id); |
|---|
| 52 | $queryresult = $this->db->query($querystatement); |
|---|
| 53 | |
|---|
| 54 | echo "success"; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | function save($name,$tabledefid,$userid){ |
|---|
| 59 | $querystatement="INSERT INTO usersearches (userid,tabledefid,name,type,sqlclause) values ("; |
|---|
| 60 | $querystatement.=((int) $userid).", "; |
|---|
| 61 | $querystatement.="\"".$tabledefid."\", "; |
|---|
| 62 | $querystatement.="\"".$name."\", "; |
|---|
| 63 | $querystatement.="\"SCH\", "; |
|---|
| 64 | $querystatement.="\"".addslashes($_SESSION["tableparams"][$tabledefid]["querywhereclause"])."\")"; |
|---|
| 65 | |
|---|
| 66 | $queryresult = $this->db->query($querystatement); |
|---|
| 67 | |
|---|
| 68 | echo "search saved"; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | function get($id){ |
|---|
| 72 | $querystatement="SELECT sqlclause FROM usersearches |
|---|
| 73 | WHERE id=".((int) $id); |
|---|
| 74 | $queryresult = $this->db->query($querystatement); |
|---|
| 75 | |
|---|
| 76 | $therecord=$this->db->fetchArray($queryresult); |
|---|
| 77 | |
|---|
| 78 | echo $therecord["sqlclause"]; |
|---|
| 79 | |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | function showSavedSearchList($queryresult,$basepath){ |
|---|
| 84 | |
|---|
| 85 | $numrows=$this->db->numRows($queryresult); |
|---|
| 86 | |
|---|
| 87 | ?> |
|---|
| 88 | <select id="LSList" name="LSList" <?php if ($numrows<1) echo "disabled" ?> size="10" style="width:170px;height:160px;" onchange="LSsearchSelect(this,'<?php echo $basepath ?>')"> |
|---|
| 89 | <?php if($numrows<1) {?> |
|---|
| 90 | <option value="NA">No Saved Searches</option> |
|---|
| 91 | <?php |
|---|
| 92 | } else { |
|---|
| 93 | $numglobal=0; |
|---|
| 94 | while($therecord=$this->db->fetchArray($queryresult)) |
|---|
| 95 | if($therecord["userid"]<1) $numglobal++; |
|---|
| 96 | $this->db->seek($queryresult,0); |
|---|
| 97 | ?> |
|---|
| 98 | <?php if($numglobal>0){ ?> |
|---|
| 99 | <option value="NA" style="font-style:italic;font-weight:bold"> -- global searches ---------</option> |
|---|
| 100 | <?php |
|---|
| 101 | }//end if |
|---|
| 102 | $userqueryline=true; |
|---|
| 103 | while($therecord=$this->db->fetchArray($queryresult)){ |
|---|
| 104 | if ($therecord["userid"]> 0 and $userqueryline) { |
|---|
| 105 | $userqueryline=false; |
|---|
| 106 | ?><option value="NA" style="font-style:italic;font-weight:bold"> -- user searches ---------</option><?php |
|---|
| 107 | } |
|---|
| 108 | ?><option value="<?php echo $therecord["id"]?>"><?php echo $therecord["name"]?></option><?php |
|---|
| 109 | }// end while |
|---|
| 110 | }//end if |
|---|
| 111 | ?> |
|---|
| 112 | </select> |
|---|
| 113 | <?php |
|---|
| 114 | }//end function |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | function showLoad($tabledefid,$basepath,$userid,$securitywhere){ |
|---|
| 118 | |
|---|
| 119 | $querystatement="SELECT id,name,userid FROM usersearches |
|---|
| 120 | WHERE tabledefid=".$tabledefid." AND type=\"SCH\" AND ((userid=0 ".$securitywhere.") OR userid=\"".$userid."\") ORDER BY userid, name"; |
|---|
| 121 | $queryresult = $this->db->query($querystatement); |
|---|
| 122 | if(!$queryresult) $error = new appError(500,"Cannot retrieve saved search infromation"); |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | $querystatement="SELECT advsearchroleid FROM tabledefs WHERE id=".$tabledefid ; |
|---|
| 126 | $tabledefresult = $this->db->query($querystatement); |
|---|
| 127 | if(!$tabledefresult) $error = new appError(500,"Cannot retrieve table definition information."); |
|---|
| 128 | $tableinfo=$this->db->fetchArray($tabledefresult); |
|---|
| 129 | |
|---|
| 130 | ?> |
|---|
| 131 | <table border="0" cellpadding="0" cellspacing="0"> |
|---|
| 132 | <tr> |
|---|
| 133 | <td valign="top"> |
|---|
| 134 | <p> |
|---|
| 135 | <label for="LSList">saved searches</label><br /> |
|---|
| 136 | <?php $this->showSavedSearchList($queryresult,$basepath)?> |
|---|
| 137 | </p> |
|---|
| 138 | </td> |
|---|
| 139 | <td valign="top" width="100%"> |
|---|
| 140 | <p> |
|---|
| 141 | <label for="LSSelectedSearch">name</label><br /> |
|---|
| 142 | <input type="text" id="LSSelectedSearch" size="10" readonly="readonly" class="uneditable" /> |
|---|
| 143 | </p> |
|---|
| 144 | <p> |
|---|
| 145 | <textarea id="LSSQL" rows="8" cols="10" <?php if(!hasRights($tableinfo["advsearchroleid"])) echo " readonly=\"readonly\""?>></textarea> |
|---|
| 146 | </p> |
|---|
| 147 | </td> |
|---|
| 148 | <td valign="top"> |
|---|
| 149 | <p><br/><input id="LSLoad" type="button" onclick="LSRunSearch()" class="Buttons" disabled="disabled" value="run search"/></p> |
|---|
| 150 | <p><input id="LSDelete" type="button" onclick="LSDeleteSearch('<?php echo $basepath ?>')" class="Buttons" disabled="disabled" value="delete"/></p> |
|---|
| 151 | <div id="LSResults"> </div> |
|---|
| 152 | </td> |
|---|
| 153 | </tr> |
|---|
| 154 | </table> |
|---|
| 155 | <?php |
|---|
| 156 | } |
|---|
| 157 | }//end class |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | if(isset($_GET["cmd"])){ |
|---|
| 167 | |
|---|
| 168 | $thesearch = new savedSearch($db); |
|---|
| 169 | |
|---|
| 170 | switch($_GET["cmd"]){ |
|---|
| 171 | case "show": |
|---|
| 172 | $securitywhere=""; |
|---|
| 173 | if ($_SESSION["userinfo"]["admin"]!=1 && count($_SESSION["userinfo"]["roles"])>0) |
|---|
| 174 | $securitywhere=" AND roleid IN (".implode(",",$_SESSION["userinfo"]["roles"]).",0)"; |
|---|
| 175 | $thesearch->showLoad($_GET["tid"],$_GET["base"],$_SESSION["userinfo"]["id"],$securitywhere); |
|---|
| 176 | break; |
|---|
| 177 | case "getsearch": |
|---|
| 178 | $thesearch->get($_GET["id"]); |
|---|
| 179 | break; |
|---|
| 180 | case "savesearch": |
|---|
| 181 | $thesearch->save($_GET["name"],$_GET["tid"],$_SESSION["userinfo"]["id"]); |
|---|
| 182 | break; |
|---|
| 183 | case "deletesearch": |
|---|
| 184 | $thesearch->delete($_GET["id"]); |
|---|
| 185 | break; |
|---|
| 186 | }//end switch |
|---|
| 187 | }?> |
|---|