1 | <?php
|
---|
2 | {
|
---|
3 | function PrintForm($_GET)
|
---|
4 | {
|
---|
5 | if (empty($_GET["fTable"]))
|
---|
6 | {
|
---|
7 | printf("ERROR - No table selected.\n");
|
---|
8 | return;
|
---|
9 | }
|
---|
10 | }
|
---|
11 |
|
---|
12 | function PrintPage($html, $host, $user, $pw, $db, $limits, $rms)
|
---|
13 | {
|
---|
14 | if (empty($_GET["fTable"]))
|
---|
15 | {
|
---|
16 | printf("ERROR - No table selected.\n");
|
---|
17 | return;
|
---|
18 |
|
---|
19 | }
|
---|
20 |
|
---|
21 | $db_id = mysql_connect($host, $user, $pw);
|
---|
22 | if ($db_id==FALSE)
|
---|
23 | {
|
---|
24 | printf("mysql_connect returned the following error: %s\n", mysql_error());
|
---|
25 | die("");
|
---|
26 | }
|
---|
27 | mysql_select_db($db);
|
---|
28 |
|
---|
29 | $fromtable=$_GET["fTable"];
|
---|
30 | $query0 = "SELECT SQL_CALC_FOUND_ROWS * FROM " . $fromtable;
|
---|
31 | if (!empty($_GET["fSortBy"]))
|
---|
32 | {
|
---|
33 | $val=substr($_GET["fSortBy"], 0, -1);
|
---|
34 | $query0 .= " ORDER BY " . GetTable($fromtable,$val) . " ";
|
---|
35 | if (substr($_GET["fSortBy"], -1)=="-")
|
---|
36 | $query0 .= "DESC";
|
---|
37 | }
|
---|
38 |
|
---|
39 |
|
---|
40 | $result0 = mysql_query($query0, $db_id);
|
---|
41 | $result1 = mysql_query("SELECT FOUND_ROWS()", $db_id);
|
---|
42 |
|
---|
43 | if ($result0)
|
---|
44 | {
|
---|
45 | if ($html=="1")
|
---|
46 | {
|
---|
47 | $alias = array
|
---|
48 | (
|
---|
49 | );
|
---|
50 | $rightalign = array
|
---|
51 | (
|
---|
52 | );
|
---|
53 | PrintMagicTable($result0, $alias, $rightalign, "", "", "", $result1);
|
---|
54 | }
|
---|
55 | else
|
---|
56 | PrintText($result0);
|
---|
57 |
|
---|
58 | mysql_free_result($result0);
|
---|
59 | mysql_free_result($result1);
|
---|
60 | }
|
---|
61 | mysql_close($db_id);
|
---|
62 |
|
---|
63 | PrintSubmittedQuery($query0, $html, $db, "old");
|
---|
64 | }
|
---|
65 |
|
---|
66 | include ("include.php");
|
---|
67 | include ("db.php");
|
---|
68 | include ("magicdefs.php");
|
---|
69 |
|
---|
70 | ini_set("display_errors", "On");
|
---|
71 | ini_set("mysql.trace_mode", "On");
|
---|
72 |
|
---|
73 | if (!empty($_GET["fSendTxt"]))
|
---|
74 | {
|
---|
75 | header("Content-type: application/octet");
|
---|
76 | header("Content-Disposition: attachment; filename=query-result.txt");
|
---|
77 |
|
---|
78 | PrintPage("0", $host, $user, $pw, $db, "", "");
|
---|
79 | }
|
---|
80 | else
|
---|
81 | {
|
---|
82 | echo (file_get_contents("index-header.html"));
|
---|
83 |
|
---|
84 | $environment = sizeof($_GET);
|
---|
85 |
|
---|
86 | PrintForm($_GET);
|
---|
87 |
|
---|
88 | if ($environment==0)
|
---|
89 | printf("No query submitted yet.<BR>");
|
---|
90 | else
|
---|
91 | PrintPage("1", $host, $user, $pw, $db, "", "");
|
---|
92 |
|
---|
93 | echo (file_get_contents("index-footer.html"));
|
---|
94 | }
|
---|
95 |
|
---|
96 | ini_set("display_errors", "Off");
|
---|
97 | ini_set("mysql.trace_mode", "Off");
|
---|
98 | }
|
---|
99 | ?>
|
---|