| 1 |
<?php |
|---|
| 2 |
require("include/session.php"); |
|---|
| 3 |
|
|---|
| 4 |
function loadSavedSort($id){ |
|---|
| 5 |
global $dblink; |
|---|
| 6 |
|
|---|
| 7 |
$querystatement="SELECT sqlclause FROM usersearches |
|---|
| 8 |
WHERE id=".$id; |
|---|
| 9 |
$queryresult = mysql_query($querystatement,$dblink); |
|---|
| 10 |
if(!$queryresult) reportError(500,"Cannot load saved sort"); |
|---|
| 11 |
$therecord=mysql_fetch_array($queryresult); |
|---|
| 12 |
echo $therecord["sqlclause"]; |
|---|
| 13 |
} |
|---|
| 14 |
|
|---|
| 15 |
function deleteSavedSort($id){ |
|---|
| 16 |
global $dblink; |
|---|
| 17 |
|
|---|
| 18 |
$querystatement="DELETE FROM usersearches |
|---|
| 19 |
WHERE id=".$id; |
|---|
| 20 |
$queryresult = mysql_query($querystatement,$dblink); |
|---|
| 21 |
if(!$queryresult) reportError(500,"Cannot delete saved sort<br/>".$querystatement); |
|---|
| 22 |
echo "success"; |
|---|
| 23 |
} |
|---|
| 24 |
|
|---|
| 25 |
function displaySavedSortList($queryresult){ |
|---|
| 26 |
$numrows=mysql_num_rows($queryresult); |
|---|
| 27 |
?> |
|---|
| 28 |
<select id="sortSavedList" name="sortSavedList" <?php if ($numrows<1) echo "disabled" ?> size="10" style="width:99%" onChange="sortSavedSelect(this)" /> |
|---|
| 29 |
<?php if($numrows<1) {?> |
|---|
| 30 |
<option value="NA">No Saved Sorts</option> |
|---|
| 31 |
<?php |
|---|
| 32 |
} else { |
|---|
| 33 |
$numglobal=0; |
|---|
| 34 |
while($therecord=mysql_fetch_array($queryresult)) |
|---|
| 35 |
if($therecord["userid"]<1) $numglobal++; |
|---|
| 36 |
mysql_data_seek($queryresult,0); |
|---|
| 37 |
?> |
|---|
| 38 |
<?php if($numglobal>0){ ?> |
|---|
| 39 |
<option value="NA" style="font-style:italic;font-weight:bold"> -- global sorts ---------</option> |
|---|
| 40 |
<?PHP |
|---|
| 41 |
} |
|---|
| 42 |
$userqueryline=true; |
|---|
| 43 |
while($therecord=mysql_fetch_array($queryresult)){ |
|---|
| 44 |
if ($therecord["userid"]> 0 and $userqueryline) { |
|---|
| 45 |
$userqueryline=false; |
|---|
| 46 |
?><option value="NA" style="font-style:italic;font-weight:bold"> -- user sorts---------</option><?php |
|---|
| 47 |
} |
|---|
| 48 |
?><option value="<?php echo $therecord["id"]?>"><?php echo $therecord["name"]?></option><?php |
|---|
| 49 |
} |
|---|
| 50 |
} |
|---|
| 51 |
?> |
|---|
| 52 |
</select> |
|---|
| 53 |
<?php |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
function showSavedSorts($tabledefid,$basepath,$userid){ |
|---|
| 57 |
global $dblink; |
|---|
| 58 |
|
|---|
| 59 |
$querystatement="SELECT id,name,userid FROM usersearches |
|---|
| 60 |
WHERE tabledefid=".$tabledefid." AND type=\"SRT\" AND (userid=0 OR userid=\"".$userid."\") ORDER BY userid, name"; |
|---|
| 61 |
$queryresult = mysql_query($querystatement,$dblink); |
|---|
| 62 |
if(!$queryresult) reportError(500,"Cannot retrieve saved sort infromation"); |
|---|
| 63 |
?><label for="sortSavedList"> |
|---|
| 64 |
saved sorts<br /> |
|---|
| 65 |
<?php displaySavedSortList($queryresult,$basepath)?> |
|---|
| 66 |
</label> |
|---|
| 67 |
<div align="right"> |
|---|
| 68 |
<input type="button" class="Buttons" style="width:75px;" id="sortSavedDeleteButton" value="delete" disabled="true" onClick="sortSavedDelete('<?php echo $basepath ?>')"/> |
|---|
| 69 |
<input type="button" class="Buttons" style="width:75px;" id="sortSavedLoadButton" value="load" disabled="true" onClick="sortSavedLoad('<?php echo $basepath ?>')"/> |
|---|
| 70 |
<input type="button" class="Buttons" style="width:75px;" id="sortSavedCancelButton" value="cancel" onClick="closeModal()"/> |
|---|
| 71 |
</div> |
|---|
| 72 |
<?php |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
function saveSort($name,$sqlclause,$tabledefid,$userid){ |
|---|
| 76 |
global $dblink; |
|---|
| 77 |
|
|---|
| 78 |
$querystatement="insert into usersearches (userid,tabledefid,name,type,sqlclause) values ("; |
|---|
| 79 |
$querystatement.=$userid.", "; |
|---|
| 80 |
$querystatement.="\"".$tabledefid."\", "; |
|---|
| 81 |
$querystatement.="\"".$name."\", "; |
|---|
| 82 |
$querystatement.="\"SRT\", "; |
|---|
| 83 |
$querystatement.="\"".$sqlclause."\")"; |
|---|
| 84 |
$queryresult = mysql_query($querystatement,$dblink); |
|---|
| 85 |
if(!$queryresult) reportError(500,"Cannot Save Sort"); |
|---|
| 86 |
echo "success"; |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
function showSort($tabledefid,$basepath){ |
|---|
| 90 |
global $dblink; |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
$querystatement="SELECT querytable FROM tabledefs WHERE id=".$tabledefid; |
|---|
| 94 |
$queryresult = mysql_query($querystatement,$dblink); |
|---|
| 95 |
if(!$queryresult) reportError(500,"Cannot retrieve Table Information"); |
|---|
| 96 |
$thetabledef=mysql_fetch_array($queryresult); |
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
$querystatement="SELECT * FROM ".$thetabledef["querytable"]." LIMIT 1"; |
|---|
| 100 |
$queryresult = mysql_query($querystatement,$dblink); |
|---|
| 101 |
if(!$queryresult) reportError(500,"Cannot retrieve Table Information"); |
|---|
| 102 |
$numfields = mysql_num_fields($queryresult); |
|---|
| 103 |
for ($i=0;$i<$numfields;$i++) $fieldlist[]=mysql_field_table($queryresult,$i).".".mysql_field_name($queryresult,$i); |
|---|
| 104 |
?><table border="0" cellspacing="0" cellpadding="0"> |
|---|
| 105 |
<tr> |
|---|
| 106 |
<td valign=top width="99%"> |
|---|
| 107 |
<div id="theSorts" style="margin:0px;padding:0px;"> |
|---|
| 108 |
<div id="Sort1"> |
|---|
| 109 |
<select id="Sort1Field" onChange="updateSort()"> |
|---|
| 110 |
<?php |
|---|
| 111 |
foreach($fieldlist as $field){ |
|---|
| 112 |
echo "<option value=\"".$field."\" >".$field."</option>\n";}?> |
|---|
| 113 |
</select> |
|---|
| 114 |
<select id="Sort1Order" onChange="updateSort()"> |
|---|
| 115 |
<option value="ASC" selected="selected">Ascending</option> |
|---|
| 116 |
<option value="DESC">Descending</option> |
|---|
| 117 |
</select> |
|---|
| 118 |
<button type="button" id="Sort1Up" class="invisibleButtons" onClick="sortMove(this,'up')"><img src="<?php echo $_SESSION["app_path"] ?>common/stylesheet/<?php echo $_SESSION["stylesheet"] ?>/button-up-disabled.png" align="middle" alt="up" width="16" height="16" border="0" /></button> |
|---|
| 119 |
<button type="button" id="Sort1Down" class="invisibleButtons" onClick="sortMove(this,'down')"><img src="<?php echo $_SESSION["app_path"] ?>common/stylesheet/<?php echo $_SESSION["stylesheet"] ?>/button-down-disabled.png" align="middle" alt="dn" width="16" height="16" border="0" /></button> |
|---|
| 120 |
<button type="button" id="Sort1Minus" class="invisibleButtons" onClick="sortRemoveLine(this)"><img src="<?php echo $_SESSION["app_path"] ?>common/stylesheet/<?php echo $_SESSION["stylesheet"] ?>/button-minus-disabled.png" align="middle" alt="-" width="16" height="16" border="0" /></button> |
|---|
| 121 |
<button type="button" id="Sort1Plus" class="invisibleButtons" onClick="sortAddLine()"><img src="<?php echo $_SESSION["app_path"] ?>common/stylesheet/<?php echo $_SESSION["stylesheet"] ?>/button-plus.png" align="middle" alt="+" width="16" height="16" border="0" /></button> |
|---|
| 122 |
</div> |
|---|
| 123 |
</div> |
|---|
| 124 |
<div> |
|---|
| 125 |
sql order by clause<br/> |
|---|
| 126 |
<textarea id="sortSQL" style="width:98%;height:75px;" cols="57" rows="4" onKeyUp="sortEnableButtons(this)" ></textarea> |
|---|
| 127 |
</div> |
|---|
| 128 |
</td> |
|---|
| 129 |
<td valign=top><br/> |
|---|
| 130 |
<div><input id="sortRunSort" type="button" onClick="performAdvancedSort(this)" class="Buttons" disabled="true" value="run sort" style="width:90px;" /></div> |
|---|
| 131 |
<div><input id="sortLoadSort" type="button" onClick="sortAskLoad('<?php echo $_SESSION["app_path"]?>')" class="Buttons" value="load sort..." style="width:90px;" /></div> |
|---|
| 132 |
<div><input id="sortSaveSort" type="button" onClick="sortAskSaveName('<?php echo $_SESSION["app_path"]?>')" class="Buttons" disabled="true" value="save sort..." style="width:90px;" /></div> |
|---|
| 133 |
<div><input id="sortClearSort" type="button" onClick="clearSort()" class="Buttons" disabled="true" value="clear sort" style="width:90px;" /></div> |
|---|
| 134 |
</td> |
|---|
| 135 |
</tr> |
|---|
| 136 |
</table> |
|---|
| 137 |
<?php |
|---|
| 138 |
|
|---|
| 139 |
} |
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
if(isset($_GET["cmd"])){ |
|---|
| 143 |
switch($_GET["cmd"]){ |
|---|
| 144 |
case "show": |
|---|
| 145 |
showSort($_GET["tid"],$_GET["base"]); |
|---|
| 146 |
break; |
|---|
| 147 |
case "save": |
|---|
| 148 |
saveSort($_GET["name"],$_GET["clause"],$_GET["tid"],$_SESSION["userinfo"]["id"]); |
|---|
| 149 |
break; |
|---|
| 150 |
case "showSaved": |
|---|
| 151 |
showSavedSorts($_GET["tid"],$_GET["base"],$_SESSION["userinfo"]["id"]); |
|---|
| 152 |
break; |
|---|
| 153 |
case "deleteSaved": |
|---|
| 154 |
deleteSavedSort($_GET["id"]); |
|---|
| 155 |
break; |
|---|
| 156 |
case "loadSaved": |
|---|
| 157 |
loadSavedSort($_GET["id"]); |
|---|
| 158 |
break; |
|---|
| 159 |
} |
|---|
| 160 |
} |
|---|
| 161 |
?> |
|---|
| 162 |
|
|---|