| 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 |
function loadSavedSort($id,$db){ |
|---|
| 42 |
$querystatement="SELECT sqlclause FROM usersearches |
|---|
| 43 |
WHERE id=".((int) $id); |
|---|
| 44 |
$queryresult = $db->query($querystatement); |
|---|
| 45 |
|
|---|
| 46 |
$therecord=$db->fetchArray($queryresult); |
|---|
| 47 |
echo $therecord["sqlclause"]; |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
function deleteSavedSort($id,$db){ |
|---|
| 51 |
$querystatement="DELETE FROM usersearches |
|---|
| 52 |
WHERE id=".((int) $id); |
|---|
| 53 |
$queryresult = $db->query($querystatement); |
|---|
| 54 |
echo "success"; |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
function displaySavedSortList($queryresult,$db){ |
|---|
| 58 |
$numrows=$db->numRows($queryresult); |
|---|
| 59 |
?> |
|---|
| 60 |
<select id="sortSavedList" name="sortSavedList" <?php if ($numrows<1) echo "disabled" ?> size="10" style="width:99%" onchange="sortSavedSelect(this)" /> |
|---|
| 61 |
<?php if($numrows<1) {?> |
|---|
| 62 |
<option value="NA">No Saved Sorts</option> |
|---|
| 63 |
<?php |
|---|
| 64 |
} else { |
|---|
| 65 |
$numglobal=0; |
|---|
| 66 |
while($therecord=$db->fetchArray($queryresult)) |
|---|
| 67 |
if($therecord["userid"]<1) $numglobal++; |
|---|
| 68 |
$db->seek($queryresult,0); |
|---|
| 69 |
?> |
|---|
| 70 |
<?php if($numglobal>0){ ?> |
|---|
| 71 |
<option value="NA" style="font-style:italic;font-weight:bold"> -- global sorts ---------</option> |
|---|
| 72 |
<?php |
|---|
| 73 |
} |
|---|
| 74 |
$userqueryline=true; |
|---|
| 75 |
while($therecord=$db->fetchArray($queryresult)){ |
|---|
| 76 |
if ($therecord["userid"]> 0 and $userqueryline) { |
|---|
| 77 |
$userqueryline=false; |
|---|
| 78 |
?><option value="NA" style="font-style:italic;font-weight:bold"> -- user sorts---------</option><?php |
|---|
| 79 |
} |
|---|
| 80 |
?><option value="<?php echo $therecord["id"]?>"><?php echo $therecord["name"]?></option><?php |
|---|
| 81 |
} |
|---|
| 82 |
} |
|---|
| 83 |
?> |
|---|
| 84 |
</select> |
|---|
| 85 |
<?php |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
function showSavedSorts($tabledefid,$basepath,$userid,$db){ |
|---|
| 89 |
$querystatement="SELECT id,name,userid FROM usersearches |
|---|
| 90 |
WHERE tabledefid=".$tabledefid." AND type=\"SRT\" AND (userid=0 OR userid=\"".$userid."\") ORDER BY userid, name"; |
|---|
| 91 |
$queryresult = $db->query($querystatement); |
|---|
| 92 |
?><p><label for="sortSavedList">saved sorts</label><br /> |
|---|
| 93 |
<?php displaySavedSortList($queryresult,$db)?> |
|---|
| 94 |
|
|---|
| 95 |
</p> |
|---|
| 96 |
<p align="right" class="buttonsRight"> |
|---|
| 97 |
<input type="button" class="Buttons" style="width:75px;" id="sortSavedDeleteButton" value="delete" disabled="disabled" onclick="sortSavedDelete('<?php echo $basepath ?>')"/> |
|---|
| 98 |
<input type="button" class="Buttons" style="width:75px;" id="sortSavedLoadButton" value="load" disabled="disabled" onclick="sortSavedLoad('<?php echo $basepath ?>')"/> |
|---|
| 99 |
<input type="button" class="Buttons" style="width:75px;" id="sortSavedCancelButton" value="cancel" onclick="closeModal()"/> |
|---|
| 100 |
</p> |
|---|
| 101 |
<?php |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
function saveSort($name,$sqlclause,$tabledefid,$userid,$db){ |
|---|
| 105 |
$querystatement="insert into usersearches (userid,tabledefid,name,type,sqlclause) values ("; |
|---|
| 106 |
$querystatement.=$userid.", "; |
|---|
| 107 |
$querystatement.="\"".$tabledefid."\", "; |
|---|
| 108 |
$querystatement.="\"".$name."\", "; |
|---|
| 109 |
$querystatement.="\"SRT\", "; |
|---|
| 110 |
$querystatement.="\"".$sqlclause."\")"; |
|---|
| 111 |
|
|---|
| 112 |
$queryresult = $db->query($querystatement); |
|---|
| 113 |
|
|---|
| 114 |
echo "success"; |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
function showSort($tabledefid,$basepath,$db){ |
|---|
| 118 |
|
|---|
| 119 |
$querystatement="SELECT querytable FROM tabledefs WHERE id=".$tabledefid; |
|---|
| 120 |
$queryresult = $db->query($querystatement); |
|---|
| 121 |
if(!$queryresult) $error = new appError(500,"Cannot retrieve Table Information"); |
|---|
| 122 |
$thetabledef=$db->fetchArray($queryresult); |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
$querystatement="SELECT * FROM ".$thetabledef["querytable"]." LIMIT 1"; |
|---|
| 126 |
$queryresult = $db->query($querystatement); |
|---|
| 127 |
if(!$queryresult) $error = new appError(500,"Cannot retrieve Table Information"); |
|---|
| 128 |
$numfields = $db->numFields($queryresult); |
|---|
| 129 |
for ($i=0;$i<$numfields;$i++) $fieldlist[]=$db->fieldTable($queryresult,$i).".".$db->fieldName($queryresult,$i); |
|---|
| 130 |
?><table border="0" cellspacing="0" cellpadding="0"> |
|---|
| 131 |
<tr> |
|---|
| 132 |
<td valign=top width="99%"> |
|---|
| 133 |
<div id="theSorts"> |
|---|
| 134 |
<div id="Sort1"> |
|---|
| 135 |
<select id="Sort1Field" onchange="updateSort()"> |
|---|
| 136 |
<?php |
|---|
| 137 |
foreach($fieldlist as $field){ |
|---|
| 138 |
echo "<option value=\"".$field."\" >".$field."</option>\n";}?> |
|---|
| 139 |
</select> |
|---|
| 140 |
<select id="Sort1Order" onchange="updateSort()"> |
|---|
| 141 |
<option value="ASC" selected="selected">Ascending</option> |
|---|
| 142 |
<option value="DESC">Descending</option> |
|---|
| 143 |
</select> |
|---|
| 144 |
<button type="button" id="Sort1Up" class="graphicButtons buttonUpDisabled" onclick="sortMove(this,'up')"><span>up</span></button> |
|---|
| 145 |
<button type="button" id="Sort1Down" class="graphicButtons buttonDownDisabled" onclick="sortMove(this,'down')"><span>down</span></button> |
|---|
| 146 |
<button type="button" id="Sort1Minus" class="graphicButtons buttonMinusDisabled" onclick="sortRemoveLine(this)"><span>-</span></button> |
|---|
| 147 |
<button type="button" id="Sort1Plus" class="graphicButtons buttonPlus" onclick="sortAddLine()"><span>+</span></button> |
|---|
| 148 |
</div> |
|---|
| 149 |
</div> |
|---|
| 150 |
<p> |
|---|
| 151 |
sql order by clause<br/> |
|---|
| 152 |
<textarea id="sortSQL" style="width:98%;height:75px;" cols="57" rows="4" onkeyup="sortEnableButtons(this)" ></textarea> |
|---|
| 153 |
</p> |
|---|
| 154 |
</td> |
|---|
| 155 |
<td valign=top> |
|---|
| 156 |
<div style="float:right"> |
|---|
| 157 |
<br/> |
|---|
| 158 |
<p><input id="sortRunSort" type="button" onclick="performAdvancedSort(this)" class="Buttons" disabled="disabled" value="run sort" style="width:90px;" /></p> |
|---|
| 159 |
<p><input id="sortLoadSort" type="button" onclick="sortAskLoad('<?php echo APP_PATH?>')" class="Buttons" value="load sort..." style="width:90px;" /></p> |
|---|
| 160 |
<p><input id="sortSaveSort" type="button" onclick="sortAskSaveName('<?php echo APP_PATH?>')" class="Buttons" disabled="disabled" value="save sort..." style="width:90px;" /></p> |
|---|
| 161 |
<p><input id="sortClearSort" type="button" onclick="clearSort()" class="Buttons" disabled="disabled" value="clear sort" style="width:90px;" /></p> |
|---|
| 162 |
</div> |
|---|
| 163 |
</td> |
|---|
| 164 |
</tr> |
|---|
| 165 |
</table> |
|---|
| 166 |
<?php |
|---|
| 167 |
|
|---|
| 168 |
} |
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
if(isset($_GET["cmd"])){ |
|---|
| 172 |
switch($_GET["cmd"]){ |
|---|
| 173 |
case "show": |
|---|
| 174 |
showSort($_GET["tid"],$_GET["base"],$db); |
|---|
| 175 |
break; |
|---|
| 176 |
case "save": |
|---|
| 177 |
saveSort($_GET["name"],$_GET["clause"],$_GET["tid"],$_SESSION["userinfo"]["id"],$db); |
|---|
| 178 |
break; |
|---|
| 179 |
case "showSaved": |
|---|
| 180 |
showSavedSorts($_GET["tid"],$_GET["base"],$_SESSION["userinfo"]["id"],$db); |
|---|
| 181 |
break; |
|---|
| 182 |
case "deleteSaved": |
|---|
| 183 |
deleteSavedSort($_GET["id"],$db); |
|---|
| 184 |
break; |
|---|
| 185 |
case "loadSaved": |
|---|
| 186 |
loadSavedSort($_GET["id"],$db); |
|---|
| 187 |
break; |
|---|
| 188 |
} |
|---|
| 189 |
} |
|---|
| 190 |
?> |
|---|
| 191 |
|
|---|