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 | if ($html=="1")
|
---|
90 | PrintSubmittedQuery($query0, $db, "old");
|
---|
91 | }
|
---|
92 |
|
---|
93 | include ("include.php");
|
---|
94 | include ("db.php");
|
---|
95 |
|
---|
96 | ini_set("display_errors", "On");
|
---|
97 | ini_set("mysql.trace_mode", "On");
|
---|
98 |
|
---|
99 | if (!empty($_GET["fSendTxt"]))
|
---|
100 | {
|
---|
101 | header("Content-type: application/octet");
|
---|
102 | header("Content-Disposition: attachment; filename=query-result.txt");
|
---|
103 |
|
---|
104 | PrintPage("0", $host, $user, $pw, $db);
|
---|
105 | }
|
---|
106 | else
|
---|
107 | {
|
---|
108 | if (empty($_GET["fPrintTable"]))
|
---|
109 | echo (file_get_contents("index-header.html"));
|
---|
110 |
|
---|
111 | $environment = sizeof($_GET);
|
---|
112 |
|
---|
113 | if (empty($_GET["fPrintTable"]))
|
---|
114 | PrintForm($_GET);
|
---|
115 |
|
---|
116 | if ($environment==0)
|
---|
117 | printf("No query submitted yet.<BR>");
|
---|
118 | else
|
---|
119 | {
|
---|
120 | if (empty($_GET["fPrintTable"]))
|
---|
121 | PrintPage("1", $host, $user, $pw, $db);
|
---|
122 | else
|
---|
123 | PrintPage("2", $host, $user, $pw, $db);
|
---|
124 | }
|
---|
125 |
|
---|
126 | if (empty($_GET["fPrintTable"]))
|
---|
127 | echo (file_get_contents("index-footer.html"));
|
---|
128 | }
|
---|
129 |
|
---|
130 | ini_set("display_errors", "Off");
|
---|
131 | ini_set("mysql.trace_mode", "Off");
|
---|
132 | }
|
---|
133 | ?>
|
---|