1 | <?php
|
---|
2 | {
|
---|
3 | function PrintForm($_GET)
|
---|
4 | {
|
---|
5 | if (empty($_GET["fDate"]))
|
---|
6 | $_GET["fDate"]=date("Y-m-d");
|
---|
7 |
|
---|
8 | printf("<center>\n");
|
---|
9 | printf("<form action=\"queryrbk.php\" METHOD=\"GET\">\n");
|
---|
10 |
|
---|
11 | printf("Date (yyyy-mm-dd) <input name=\"fDate\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"");
|
---|
12 | printf("%s\"> \n", $_GET["fDate"]);
|
---|
13 |
|
---|
14 | printf("Search <A HREF=\"regexp.html\">regexp:</A> <input name=\"fRegexp\" type=\"text\" size=\"32\" maxlength=\"128\" value=\"");
|
---|
15 | if (!empty($_GET["fRegexp"]))
|
---|
16 | printf("%s", $_GET["fRegexp"]);
|
---|
17 | printf("\"> \n<P>\n");
|
---|
18 |
|
---|
19 | ini_set("mysql.trace_mode", "Off");
|
---|
20 | ini_set("display_errors", "Off");
|
---|
21 |
|
---|
22 | printf("Night (yyyy-mm-dd) <input name=\"fNight\" type=\"text\" size=\"10\" maxlength=\"10\" value=\"");
|
---|
23 | printf("%s\"> \n", $_GET["fNight"]);
|
---|
24 |
|
---|
25 |
|
---|
26 | printf("<input class='Width' type='submit' value='Query Table'> \n");
|
---|
27 | printf("<input class='Width' type='button' value='Reset' onClick='self.location.href=\"queryrbk.php\"'> \n");
|
---|
28 | if (strchr($_SERVER["REQUEST_URI"], '?')!=FALSE)
|
---|
29 | {
|
---|
30 | printf("<input class='Width' type='button' value='Get .txt' onClick='self.location.href=\"%s&fSendTxt=1\"'> \n", $_SERVER["REQUEST_URI"]);
|
---|
31 | printf("<input class='Width' type='button' value='Print' onClick='self.location.href=\"%s&fPrintTable=1\"'> \n", htmlspecialchars($_SERVER["REQUEST_URI"]));
|
---|
32 | }
|
---|
33 |
|
---|
34 | printf("</form>\n");
|
---|
35 | printf("</center>\n");
|
---|
36 | printf("</td>\n");
|
---|
37 | printf("</tr>\n");
|
---|
38 | printf("<tr class='Block'>\n");
|
---|
39 | printf("<td>\n");
|
---|
40 | }
|
---|
41 |
|
---|
42 | function PrintPage($html, $host, $user, $pw, $db)
|
---|
43 | {
|
---|
44 | $db_id = mysql_connect($host, $user, $pw);
|
---|
45 | if ($db_id==FALSE)
|
---|
46 | {
|
---|
47 | printf("mysql_connect returned the following error: %s\n", mysql_error());
|
---|
48 | die("");
|
---|
49 | }
|
---|
50 | mysql_select_db($db);
|
---|
51 |
|
---|
52 | $query0 = "SELECT SQL_CALC_FOUND_ROWS fRunBookDate AS Date, fRunBookText AS Entry ";
|
---|
53 | $query0 .= "FROM " . $db . ".RunBook ";
|
---|
54 | $query0 .= "WHERE fRunBookDate REGEXP '^" . $_GET["fDate"] . "' ";
|
---|
55 |
|
---|
56 | if (!empty($_GET["fRegexp"]))
|
---|
57 | $query0 .= "AND fRunBookText REGEXP '" . $_GET["fRegexp"] . "' ";
|
---|
58 |
|
---|
59 | if (!empty($_GET["fNight"]))
|
---|
60 | $query0 .= "AND fRunBookDate < '" . $_GET["fNight"] . " 13:00:00' AND fRunBookDate > ADDDATE( '" . $_GET["fNight"] . " 13:00:00', INTERVAL -1 DAY) ";
|
---|
61 |
|
---|
62 | $query0 .= "ORDER BY fRunBookDate";
|
---|
63 |
|
---|
64 | $result0 = mysql_query($query0, $db_id);
|
---|
65 | $result1 = mysql_query("SELECT FOUND_ROWS()", $db_id);
|
---|
66 |
|
---|
67 | if ($result0)
|
---|
68 | {
|
---|
69 | if ($html=="1" || $html=="2")
|
---|
70 | {
|
---|
71 | $alias = array
|
---|
72 | (
|
---|
73 | "fRunBookDate" => "Date",
|
---|
74 | "fRunBookText" => "Entry"
|
---|
75 | );
|
---|
76 | $rightalign = array
|
---|
77 | (
|
---|
78 | );
|
---|
79 | PrintMagicTable($result0, $alias, $rightalign, "", "", "", $result1);
|
---|
80 | }
|
---|
81 | else
|
---|
82 | PrintText($result0);
|
---|
83 |
|
---|
84 | mysql_free_result($result0);
|
---|
85 | mysql_free_result($result1);
|
---|
86 | }
|
---|
87 | mysql_close($db_id);
|
---|
88 |
|
---|
89 | PrintSubmittedQuery($query0, $html, $db, "old");
|
---|
90 | }
|
---|
91 |
|
---|
92 | include ("include.php");
|
---|
93 | include ("db.php");
|
---|
94 |
|
---|
95 | ini_set("display_errors", "On");
|
---|
96 | ini_set("mysql.trace_mode", "On");
|
---|
97 |
|
---|
98 | if (!empty($_GET["fSendTxt"]))
|
---|
99 | {
|
---|
100 | header("Content-type: application/octet");
|
---|
101 | header("Content-Disposition: attachment; filename=query-result.txt");
|
---|
102 |
|
---|
103 | PrintPage("0", $host, $user, $pw, $db);
|
---|
104 | }
|
---|
105 | else
|
---|
106 | {
|
---|
107 | if (empty($_GET["fPrintTable"]))
|
---|
108 | echo (file_get_contents("index-header.html"));
|
---|
109 |
|
---|
110 | $environment = sizeof($_GET);
|
---|
111 |
|
---|
112 | if (empty($_GET["fPrintTable"]))
|
---|
113 | PrintForm($_GET);
|
---|
114 |
|
---|
115 | if ($environment==0)
|
---|
116 | printf("No query submitted yet.<BR>");
|
---|
117 | else
|
---|
118 | {
|
---|
119 | if (empty($_GET["fPrintTable"]))
|
---|
120 | PrintPage("1", $host, $user, $pw, $db);
|
---|
121 | else
|
---|
122 | PrintPage("2", $host, $user, $pw, $db);
|
---|
123 | }
|
---|
124 |
|
---|
125 | if (empty($_GET["fPrintTable"]))
|
---|
126 | echo (file_get_contents("index-footer.html"));
|
---|
127 | }
|
---|
128 |
|
---|
129 | ini_set("display_errors", "Off");
|
---|
130 | ini_set("mysql.trace_mode", "Off");
|
---|
131 | }
|
---|
132 | ?>
|
---|