| 1 | <?php | 
|---|
| 2 | { | 
|---|
| 3 | function CreateQuery($_GET, $alias) | 
|---|
| 4 | { | 
|---|
| 5 |  | 
|---|
| 6 | $query0 = "SELECT "; | 
|---|
| 7 | if ($_GET["fLinks"]=="Off" || !empty($_GET["fSendTxt"])) | 
|---|
| 8 | $query0 .= " fSourceName as 'Source' "; | 
|---|
| 9 | else | 
|---|
| 10 | { | 
|---|
| 11 | $query0 .= " CONCAT('<A&ws;HREF=\"sequinfo.php?', "; | 
|---|
| 12 | $query0 .= " 'fRunStart=On', '&fZenithDistanceMin=On', '&fNumEvents=On', '&fRunTime%2F60=On', '&fSequenceLast=On', "; | 
|---|
| 13 | $query0 .= " '&fSequenceFileWrittenStatus=0', '&fAllFilesAvail=On', '&fAllFilesAvailStatus=0', '&fCallisto=On', '&fCallistoStatus=0', '&fStar=On', '&fStarStatus=0', '&fFillCallistoStatus=0', '&fFillStarStatus=0', "; | 
|---|
| 14 | $query0 .= " '&fSourceName=On', '&fSourceKEY=', fSourceKEY, "; //'&fRunMin=0', '&fRunMax=1000000', "; | 
|---|
| 15 | $query0 .= " '&fNumResults=500\">', fSourcename, '</A>') "; | 
|---|
| 16 | $query0 .= " as 'Source' "; | 
|---|
| 17 | } | 
|---|
| 18 | $query0 .= " , fSourceKEY as 'KEY', fTest as 'Test' "; | 
|---|
| 19 | $query0 .= " FROM Source "; | 
|---|
| 20 |  | 
|---|
| 21 | if (empty($_GET["fTest"])) | 
|---|
| 22 | $query0 .= " WHERE fTest='no'"; | 
|---|
| 23 |  | 
|---|
| 24 | if ($_GET["fOff"]=="Off") | 
|---|
| 25 | { | 
|---|
| 26 | if (strpos($query0, " WHERE ")==FALSE) | 
|---|
| 27 | $query0 .= " WHERE "; | 
|---|
| 28 | else | 
|---|
| 29 | $query0 .= " AND "; | 
|---|
| 30 |  | 
|---|
| 31 | $query0 .= " NOT (fSourceName like '%Off%')"; | 
|---|
| 32 | } | 
|---|
| 33 |  | 
|---|
| 34 | if (!empty($_GET["fSortBy"])) | 
|---|
| 35 | { | 
|---|
| 36 | $query0 .= " ORDER BY " . substr($_GET["fSortBy"], 0, -1) . " "; | 
|---|
| 37 | if (substr($_GET["fSortBy"], -1)=="-") | 
|---|
| 38 | $query0 .= "DESC"; | 
|---|
| 39 | } | 
|---|
| 40 | else | 
|---|
| 41 | $query0 .= " ORDER BY fSourceKEY "; | 
|---|
| 42 |  | 
|---|
| 43 | return $query0; | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 | function InitGet($_GET) | 
|---|
| 47 | { | 
|---|
| 48 |  | 
|---|
| 49 | if (empty($_GET["fOff"])) | 
|---|
| 50 | $_GET["fOff"]="Off"; | 
|---|
| 51 |  | 
|---|
| 52 | if (empty($_GET["fLinks"])) | 
|---|
| 53 | $_GET["fLinks"]="On"; | 
|---|
| 54 |  | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|
| 57 | function PrintForm($_GET) | 
|---|
| 58 | { | 
|---|
| 59 | printf("<center>\n"); | 
|---|
| 60 | printf("<form action=\"sources.php\" METHOD=\"GET\">\n"); | 
|---|
| 61 | printf(" <p><table>\n"); | 
|---|
| 62 | printf("  <tr>\n"); | 
|---|
| 63 |  | 
|---|
| 64 | CheckBox("fOff",   "incl. offsources"); | 
|---|
| 65 | CheckBox("fTest",  "incl. test-sources"); | 
|---|
| 66 | CheckBox("fLinks", "links"); | 
|---|
| 67 |  | 
|---|
| 68 | printf(" </table></p>\n"); | 
|---|
| 69 |  | 
|---|
| 70 |  | 
|---|
| 71 | ini_set("mysql.trace_mode", "Off"); | 
|---|
| 72 | ini_set("display_errors", "Off"); | 
|---|
| 73 |  | 
|---|
| 74 | printf("<input class='Width' type='submit' value='Query Table'>   \n"); | 
|---|
| 75 | printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"sources.php\"'>   \n"); | 
|---|
| 76 | if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE) | 
|---|
| 77 | printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'>   \n", $_SERVER["REQUEST_URI"]); | 
|---|
| 78 | printf("</form>\n"); | 
|---|
| 79 | printf("</center>\n"); | 
|---|
| 80 | printf("</td>\n"); | 
|---|
| 81 | printf("</tr>\n"); | 
|---|
| 82 | printf("<tr class='Block'>\n"); | 
|---|
| 83 | printf("<td>\n"); | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign) | 
|---|
| 87 | { | 
|---|
| 88 | $db_id = mysql_connect($host, $user, $pw); | 
|---|
| 89 | if ($db_id==FALSE) | 
|---|
| 90 | { | 
|---|
| 91 | printf("mysql_connect returned the following error: %s\n", mysql_error()); | 
|---|
| 92 | die(""); | 
|---|
| 93 | } | 
|---|
| 94 | mysql_select_db($db); | 
|---|
| 95 |  | 
|---|
| 96 | $query0 = CreateQuery($_GET, $alias); | 
|---|
| 97 |  | 
|---|
| 98 | $result0 = mysql_query($query0, $db_id); | 
|---|
| 99 |  | 
|---|
| 100 | if ($result0) | 
|---|
| 101 | { | 
|---|
| 102 | if ($html=="1") | 
|---|
| 103 | PrintMagicTable($result0, $alias, $rightalign, "", "", $_GET); | 
|---|
| 104 | else | 
|---|
| 105 | PrintText($result0); | 
|---|
| 106 |  | 
|---|
| 107 | mysql_free_result($result0); | 
|---|
| 108 | } | 
|---|
| 109 | mysql_close($db_id); | 
|---|
| 110 |  | 
|---|
| 111 | PrintSubmittedQuery($query0, $html, $db, "old"); | 
|---|
| 112 | } | 
|---|
| 113 |  | 
|---|
| 114 | include ("include.php"); | 
|---|
| 115 | include ("db.php"); | 
|---|
| 116 | include ("magicdefs.php"); | 
|---|
| 117 |  | 
|---|
| 118 | ini_set("display_errors", "On"); | 
|---|
| 119 | ini_set("mysql.trace_mode", "On"); | 
|---|
| 120 |  | 
|---|
| 121 | if (!empty($_GET["fSendTxt"])) | 
|---|
| 122 | { | 
|---|
| 123 | header("Content-type: application/octet"); | 
|---|
| 124 | header("Content-Disposition: attachment; filename=query-result.txt"); | 
|---|
| 125 |  | 
|---|
| 126 | PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign); | 
|---|
| 127 | } | 
|---|
| 128 | else | 
|---|
| 129 | { | 
|---|
| 130 | echo (file_get_contents("index-header.html")); | 
|---|
| 131 |  | 
|---|
| 132 | $environment = sizeof($_GET); | 
|---|
| 133 |  | 
|---|
| 134 | InitGet($_GET); | 
|---|
| 135 | PrintForm($_GET); | 
|---|
| 136 |  | 
|---|
| 137 | if ($environment==0) | 
|---|
| 138 | printf("No query submitted yet.<BR>"); | 
|---|
| 139 | else | 
|---|
| 140 | PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign); | 
|---|
| 141 |  | 
|---|
| 142 | echo (file_get_contents("index-footer.html")); | 
|---|
| 143 | } | 
|---|
| 144 |  | 
|---|
| 145 | ini_set("display_errors", "Off"); | 
|---|
| 146 | ini_set("mysql.trace_mode", "Off"); | 
|---|
| 147 | } | 
|---|
| 148 | ?> | 
|---|