| 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 | | |
| | 66 | |
| | 67 | $uuid = getUuid($this->db, "tbld:5c9d645f-26ab-5003-b98e-89e9049f8ac3", $tabledefid); |
| | 68 | |
| | 69 | $insertstatement = " |
| | 70 | INSERT INTO |
| | 71 | usersearches |
| | 72 | ( |
| | 73 | userid, |
| | 74 | tabledefid, |
| | 75 | name, |
| | 76 | `type`, |
| | 77 | sqlclause |
| | 78 | ) VALUES ( |
| | 79 | '".mysql_real_escape_string($userid)."', |
| | 80 | '".mysql_real_escape_string($uuid)."', |
| | 81 | '".mysql_real_escape_string($name)."', |
| | 82 | 'SCH', |
| | 83 | '".addslashes($_SESSION["tableparams"][$tabledefid]["querywhereclause"])."' |
| | 84 | )"; |
| | 85 | |
| | 86 | $this->db->query($insertstatement); |
| | 87 | |
| | 88 | echo "search saved"; |
| | 89 | |
| | 90 | }//endfunction save |
| | 91 | |
| | 92 | |
| | 93 | /** |
| | 94 | * displays sql clause for saved search |
| | 95 | * |
| | 96 | * @param integer $id savedsearch id |
| | 97 | */ |
| 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 |
| | 99 | |
| | 100 | $querystatement=" |
| | 101 | SELECT |
| | 102 | sqlclause |
| | 103 | FROM |
| | 104 | usersearches |
| | 105 | WHERE id=".((int) $id); |
| | 106 | |
| | 107 | $queryresult = $this->db->query($querystatement); |
| | 108 | |
| | 109 | $therecord = $this->db->fetchArray($queryresult); |
| | 110 | |
| | 111 | echo $therecord["sqlclause"]; |
| | 112 | |
| 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 | | } |
| | 115 | |
| | 116 | /** |
| | 117 | * generates the select input of saved searches |
| | 118 | * |
| | 119 | * @param mysql query result $queryresult |
| | 120 | */ |
| | 121 | function showSavedSearchList($queryresult){ |
| | 122 | |
| | 123 | $numrows = $this->db->numRows($queryresult); |
| | 124 | |
| | 125 | ?> |
| | 126 | <select id="LSList" name="LSList" <?php if ($numrows<1) echo "disabled" ?> size="10" style="width:170px;height:160px;" onchange="LSsearchSelect(this,'<?php echo APP_PATH ?>')"> |
| | 127 | <?php if($numrows<1) {?> |
| | 128 | |
| | 129 | <option value="NA">No Saved Searches</option> |
| | 130 | |
| | 131 | <?php |
| | 132 | } else { |
| | 133 | |
| | 134 | $numglobal=0; |
| | 135 | |
| | 136 | while($therecord=$this->db->fetchArray($queryresult)) |
| | 137 | if($therecord["userid"]<1) $numglobal++; |
| | 138 | |
| | 139 | $this->db->seek($queryresult,0); |
| | 140 | |
| | 141 | if($numglobal>0){ ?> |
| | 142 | <option value="NA" style="font-style:italic;font-weight:bold"> -- global searches ---------</option> |
| | 143 | <?php |
| | 144 | }//end if |
| | 145 | |
| | 146 | $userqueryline = true; |
| | 147 | |
| | 148 | while($therecord=$this->db->fetchArray($queryresult)){ |
| | 149 | |
| | 150 | if ($therecord["userid"] != '' and $userqueryline) { |
| | 151 | |
| | 152 | $userqueryline = false; |
| | 153 | |
| | 154 | ?><option value="NA" style="font-style:italic;font-weight:bold"> -- user searches ---------</option><?php |
| | 155 | |
| | 156 | }//endif |
| | 157 | |
| | 158 | ?><option value="<?php echo $therecord["id"]?>"><?php echo $therecord["name"]?></option><?php |
| | 159 | |
| | 160 | }// end while |
| | 161 | |
| | 162 | }//end if |
| | 163 | ?> |
| | 164 | </select> |
| | 165 | <?php |
| | 166 | |
| | 167 | }//end function showSavedSearchList |
| | 168 | |
| | 169 | |
| | 170 | /** |
| | 171 | * displays the load box for saved searches |
| | 172 | * |
| | 173 | * @param integer $tabledefid id of tabledef |
| | 174 | * @param string $userid uuid of user |
| | 175 | * @param string $securitywhere additional security based where clause to pass |
| | 176 | */ |
| | 177 | function showLoad($tabledefid,$userid,$securitywhere){ |
| | 178 | |
| | 179 | $uuid = getUuid($this->db, "tbld:5c9d645f-26ab-5003-b98e-89e9049f8ac3", $tabledefid); |
| | 180 | |
| | 181 | $querystatement = " |
| | 182 | SELECT |
| | 183 | id, |
| | 184 | name, |
| | 185 | userid |
| | 186 | FROM |
| | 187 | usersearches |
| | 188 | WHERE |
| | 189 | tabledefid = '".$uuid."' |
| | 190 | AND type='SCH' |
| | 191 | AND ( |
| | 192 | (userid = '' ".$securitywhere.") |
| | 193 | OR userid = '".$userid."') |
| | 194 | ORDER BY |
| | 195 | userid, |
| | 196 | name"; |
| | 197 | |
| | 198 | $queryresult = $this->db->query($querystatement); |
| | 199 | |
| | 200 | if(!$queryresult) |
| | 201 | $error = new appError(500,"Cannot retrieve saved search infromation"); |
| | 202 | |
| | 203 | $querystatement=" |
| | 204 | SELECT |
| | 205 | advsearchroleid |
| | 206 | FROM |
| | 207 | tabledefs |
| | 208 | WHERE id= '".$tabledefid."'"; |
| | 209 | |
| | 210 | $tabledefresult = $this->db->query($querystatement); |
| | 211 | |
| | 212 | if(!$tabledefresult) |
| | 213 | $error = new appError(500,"Cannot retrieve table definition information."); |
| | 214 | |
| | 215 | $tableinfo=$this->db->fetchArray($tabledefresult); |
| | 216 | |
| | 217 | ?> |
| | 218 | <table border="0" cellpadding="0" cellspacing="0"> |
| | 219 | <tr> |
| | 220 | <td valign="top"> |
| | 221 | <p> |
| | 222 | <label for="LSList">saved searches</label><br /> |
| | 223 | <?php $this->showSavedSearchList($queryresult)?> |
| | 224 | </p> |
| | 225 | </td> |
| | 226 | <td valign="top" width="100%"> |
| | 227 | <p> |
| | 228 | <label for="LSSelectedSearch">name</label><br /> |
| | 229 | <input type="text" id="LSSelectedSearch" size="10" readonly="readonly" class="uneditable" /> |
| | 230 | </p> |
| | 231 | <p> |
| | 232 | <textarea id="LSSQL" rows="8" cols="10" <?php if(!hasRights($tableinfo["advsearchroleid"])) echo " readonly=\"readonly\""?>></textarea> |
| | 233 | </p> |
| | 234 | </td> |
| | 235 | <td valign="top"> |
| | 236 | <p><br/><input id="LSLoad" type="button" onclick="LSRunSearch()" class="Buttons" disabled="disabled" value="run search"/></p> |
| | 237 | <p><input id="LSDelete" type="button" onclick="LSDeleteSearch('<?php echo APP_PATH ?>')" class="Buttons" disabled="disabled" value="delete"/></p> |
| | 238 | <div id="LSResults"> </div> |
| | 239 | </td> |
| | 240 | </tr> |
| | 241 | </table> |
| | 242 | <?php |
| | 243 | |
| | 244 | }//end function showLoad |
| | 245 | |