| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | $Rev$ | $LastChangedBy$ |
|---|
| 4 | $LastChangedDate$ |
|---|
| 5 | +-------------------------------------------------------------------------+ |
|---|
| 6 | | Copyright (c) 2004 - 2007, Kreotek LLC | |
|---|
| 7 | | All rights reserved. | |
|---|
| 8 | +-------------------------------------------------------------------------+ |
|---|
| 9 | | | |
|---|
| 10 | | Redistribution and use in source and binary forms, with or without | |
|---|
| 11 | | modification, are permitted provided that the following conditions are | |
|---|
| 12 | | met: | |
|---|
| 13 | | | |
|---|
| 14 | | - Redistributions of source code must retain the above copyright | |
|---|
| 15 | | notice, this list of conditions and the following disclaimer. | |
|---|
| 16 | | | |
|---|
| 17 | | - Redistributions in binary form must reproduce the above copyright | |
|---|
| 18 | | notice, this list of conditions and the following disclaimer in the | |
|---|
| 19 | | documentation and/or other materials provided with the distribution. | |
|---|
| 20 | | | |
|---|
| 21 | | - Neither the name of Kreotek LLC nor the names of its contributore may | |
|---|
| 22 | | be used to endorse or promote products derived from this software | |
|---|
| 23 | | without specific prior written permission. | |
|---|
| 24 | | | |
|---|
| 25 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
|---|
| 26 | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
|---|
| 27 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | |
|---|
| 28 | | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
|---|
| 29 | | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
|---|
| 30 | | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
|---|
| 31 | | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
|---|
| 32 | | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
|---|
| 33 | | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
|---|
| 34 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
|---|
| 35 | | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
|---|
| 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 | }//end if |
|---|
| 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 | }// end while |
|---|
| 82 | }//end if |
|---|
| 83 | ?> |
|---|
| 84 | </select> |
|---|
| 85 | <?php |
|---|
| 86 | }//end function |
|---|
| 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 | //First, grab table name from id |
|---|
| 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 | //Grab query for all columns |
|---|
| 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 | }//end switch |
|---|
| 189 | } |
|---|
| 190 | ?> |
|---|