| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 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 |
} |
|---|
| 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 |
} |
|---|
| 110 |
} |
|---|
| 111 |
?> |
|---|
| 112 |
</select> |
|---|
| 113 |
<?php |
|---|
| 114 |
} |
|---|
| 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 |
} |
|---|
| 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 |
} |
|---|
| 187 |
}?> |
|---|