| 1 |
<?php |
|---|
| 2 |
include("include/session.php"); |
|---|
| 3 |
include("include/advancedsearch_functions.php"); |
|---|
| 4 |
|
|---|
| 5 |
if(!isset($_GET["id"])) reportError(100,"Passed Variable Not Present"); |
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
$querystatement="SELECT id,displayname,maintable FROM tabledefs WHERE id=".$_GET["id"]; |
|---|
| 9 |
$queryresult = mysql_query($querystatement,$dblink); |
|---|
| 10 |
if(!$queryresult) reportError(500,"Cannot retrieve Table Information"); |
|---|
| 11 |
$thetabledef=mysql_fetch_array($queryresult); |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
$querystatement="SELECT * FROM ".$thetabledef["maintable"]." LIMIT 1"; |
|---|
| 15 |
$queryresult = mysql_query($querystatement,$dblink); |
|---|
| 16 |
if(!$queryresult) reportError(500,"Cannot retrieve Table Information"); |
|---|
| 17 |
$numfields = mysql_num_fields($queryresult); |
|---|
| 18 |
for ($i=0;$i<$numfields;$i++) $fieldlist[]=mysql_field_name($queryresult,$i); |
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
$loadedsearch=""; |
|---|
| 22 |
if(isset($_POST["command"])){ |
|---|
| 23 |
switch($_POST["command"]){ |
|---|
| 24 |
case "save search": |
|---|
| 25 |
save_search($_SESSION["userinfo"]["id"],$thetabledef["id"],$_POST["savename"],$_POST["constructedquery"]); |
|---|
| 26 |
break; |
|---|
| 27 |
|
|---|
| 28 |
case "delete search": |
|---|
| 29 |
delete_search($_SESSION["userinfo"]["id"],$_POST["loadsearch"]); |
|---|
| 30 |
break; |
|---|
| 31 |
|
|---|
| 32 |
case "load search": |
|---|
| 33 |
$loadedsearch=load_search($_POST["loadsearch"]); |
|---|
| 34 |
break; |
|---|
| 35 |
} |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
$savedsearches=get_saved_searches($_SESSION["userinfo"]["id"],$thetabledef["id"]); |
|---|
| 40 |
?> |
|---|
| 41 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" > |
|---|
| 42 |
<html> |
|---|
| 43 |
<head> |
|---|
| 44 |
<title><?php echo $thetabledef["displayname"]; ?> Advanced Search</title> |
|---|
| 45 |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
|---|
| 46 |
<link href="common/stylesheet/<?php echo $_SESSION["stylesheet"] ?>/base.css" rel="stylesheet" type="text/css"> |
|---|
| 47 |
<script language="JavaScript" src="common/javascript/advancedsearch.js"></script> |
|---|
| 48 |
</head> |
|---|
| 49 |
<body> |
|---|
| 50 |
<script>self.resizeTo(540,360)</script> |
|---|
| 51 |
<div class=bodyline> |
|---|
| 52 |
<div class=large><strong><?php echo $thetabledef["displayname"]; ?> Advanced Search</strong></div> |
|---|
| 53 |
<form action="<?php echo $_SERVER["PHP_SELF"]."?id=".$_GET["id"]?>" method="post" name="queryconstruct"> |
|---|
| 54 |
<input name="tablename" type="hidden" value="<?php echo $thetabledef["maintable"] ?>"> |
|---|
| 55 |
<div align="center"> |
|---|
| 56 |
<table border="0" cellpadding="0" cellspacing="0" class="querytable"> |
|---|
| 57 |
<tr> |
|---|
| 58 |
<td align="center" colspan=2 nowrap class="queryheader">and/or</td> |
|---|
| 59 |
<td class="queryheader">field</td> |
|---|
| 60 |
<td class="queryheader">operator</td> |
|---|
| 61 |
<td class="queryheader">argument</td> |
|---|
| 62 |
</tr> |
|---|
| 63 |
<tr> |
|---|
| 64 |
<?php |
|---|
| 65 |
|
|---|
| 66 |
for($i=1;$i<6;$i++) { ?> |
|---|
| 67 |
<td> |
|---|
| 68 |
<?php if($i!=1) { ?> |
|---|
| 69 |
<input name="line<?php echo $i ?>" type="checkbox" value="1" class=radiochecks onClick="unlockLine(<?PHP echo $i ?>,this)"> |
|---|
| 70 |
<?php } else echo " " ?> |
|---|
| 71 |
</td> |
|---|
| 72 |
<td align="left" class=small nowrap> |
|---|
| 73 |
<?php if($i!=1) { ?> |
|---|
| 74 |
<input name="andor<?php echo $i ?>" disabled=true id="andorand<?php echo $i ?>" type="radio" class="radiochecks" value="and" checked onChange="updatequery(this);">and <input onChange="updatequery(this);" name="andor<?php echo $i ?>" id="andoror<?php echo $i ?>" type="radio" class="radiochecks" value="or" disabled=true>or |
|---|
| 75 |
<?php } else echo " " ?> |
|---|
| 76 |
</td> |
|---|
| 77 |
<td> |
|---|
| 78 |
<select name="field<?php echo $i ?>" onChange="updatequery(this);" <?php if($i!=1) echo "disabled=true" ?>> |
|---|
| 79 |
<?php |
|---|
| 80 |
foreach($fieldlist as $field){ |
|---|
| 81 |
echo "<option value=\"".$field."\""; |
|---|
| 82 |
if($field=="id") echo "selected"; |
|---|
| 83 |
echo ">".$field."</option>\n"; |
|---|
| 84 |
} |
|---|
| 85 |
?> |
|---|
| 86 |
</select> |
|---|
| 87 |
</td> |
|---|
| 88 |
<td><select name="operator<?php echo $i ?>" id="operator<?php echo $i ?>" onChange="updatequery(this);" <?php if($i!=1) echo "disabled=true" ?>> |
|---|
| 89 |
<option value="=" selected>=</option> |
|---|
| 90 |
<option value="!=">!=</option> |
|---|
| 91 |
<option value=">">></option> |
|---|
| 92 |
<option value="<"><</option> |
|---|
| 93 |
<option value=">=">>=</option> |
|---|
| 94 |
<option value="<="><=</option> |
|---|
| 95 |
<option value="like">like</option> |
|---|
| 96 |
<option value="not like">not like</option> |
|---|
| 97 |
</select></td> |
|---|
| 98 |
<td width="100%"><input name="thetext<?php echo $i?>" id="thetext<?php echo $i?>" type="text" onKeyUp="updatequery(this);" size="32" maxlength="128" <?php if($i!=1) echo "disabled=true" ?> style="width:100%"></td> |
|---|
| 99 |
</tr> |
|---|
| 100 |
<?php } ?> |
|---|
| 101 |
</table></div> |
|---|
| 102 |
<div class="box"> |
|---|
| 103 |
<div style="float:left"> |
|---|
| 104 |
<input name="showsql" id="showsql"type="button" class="smallButtons" onClick="togglesql();" value="show SQL" style="margin-bottom:3px;width:100px;"><br> |
|---|
| 105 |
<input name="showtips" id="showtips" type="button" class="smallButtons" onClick="toggletips();" value="show tips" style="width:100px;"> |
|---|
| 106 |
</div> |
|---|
| 107 |
<div align="right"> |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
<input name="reset" type="reset" class="smallButtons" value="clear search criteria" style="margin-bottom:3px; width:120px;"><br> |
|---|
| 111 |
<input name="savedsearches" id="savedsearches" onClick="togglesavedsearches()" type="button" class="smallButtons" value="saved searches..." style="width:120px;"> |
|---|
| 112 |
</div> |
|---|
| 113 |
</div> |
|---|
| 114 |
<div class="box" id="tipsbox" style="display:none;"> |
|---|
| 115 |
<div> |
|---|
| 116 |
<strong>Tips</strong><br> |
|---|
| 117 |
<ul style="margin:0px;padding-left:20px;"> |
|---|
| 118 |
<li>Type dates using the format "YYYY-MM-DD"</li> |
|---|
| 119 |
<li>When using the "like" or "contains" operator use the "%" character as a wildcard</li> |
|---|
| 120 |
<li>Invalid searches will not return any records, but will indicate an error.</li> |
|---|
| 121 |
</ul> |
|---|
| 122 |
</div> |
|---|
| 123 |
</div> |
|---|
| 124 |
<div class=box id="sqlbox" style="display:none;"> |
|---|
| 125 |
<div>SQL<br> |
|---|
| 126 |
<textarea name="constructedquery" cols="85" rows="3" class=small style="width:100%"><?PHP echo $loadedsearch; ?></textarea> |
|---|
| 127 |
</div> |
|---|
| 128 |
</div> |
|---|
| 129 |
<div class=box id="savedsearchesbox" style="display:none;"> |
|---|
| 130 |
<div style="float:right;width:120px;"><br> |
|---|
| 131 |
<input name="command" type="submit" class="Buttons" value="load search" style="width:120px;margin-bottom:3px;" <?php if(!mysql_num_rows($savedsearches)) echo "disabled"?>><br> |
|---|
| 132 |
<input name="command" type="submit" class="Buttons" value="delete search" style="width:120px;" <?php if(!mysql_num_rows($savedsearches)) echo "disabled"?>> |
|---|
| 133 |
</div> |
|---|
| 134 |
<div style="margin-right:130px;"> |
|---|
| 135 |
saved searches<br> |
|---|
| 136 |
<?PHP display_saved_search_list($savedsearches); ?><br><br> |
|---|
| 137 |
</div> |
|---|
| 138 |
</div> |
|---|
| 139 |
<div class="recordbottom" align="right"> |
|---|
| 140 |
<input name="savename" type="hidden" size="32" maxlength="64" style=""> |
|---|
| 141 |
<input class=Buttons name="command" type="button" value="execute search" onClick="dosearch(this.form)" style="width:100px;"> |
|---|
| 142 |
<input name="command" type="submit" onClick="getname(this.form);" class="Buttons" value="save search" style="width:100px;"> |
|---|
| 143 |
<input class=Buttons name="cancel" type="button" onClick="window.close();" value="cancel" style="width:100px;"> |
|---|
| 144 |
</div> |
|---|
| 145 |
<?php if($loadedsearch){?> |
|---|
| 146 |
<script language="javascript">document["queryconstruct"]["showsql"].click();</script> |
|---|
| 147 |
<?php }?> |
|---|
| 148 |
</form> |
|---|
| 149 |
</div> |
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
</body> |
|---|
| 155 |
</html> |
|---|
| 156 |
|
|---|