1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* Alternative SQL editing window
|
5
|
*
|
6
|
* $Id: sqledit.php,v 1.29 2005/10/18 03:45:16 chriskl Exp $
|
7
|
*/
|
8
|
|
9
|
// Include application functions
|
10
|
include_once('./libraries/lib.inc.php');
|
11
|
|
12
|
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
|
13
|
if (!isset($msg)) $msg = '';
|
14
|
$PHP_SELF = $_SERVER['PHP_SELF'];
|
15
|
|
16
|
/**
|
17
|
* Private function to display server and list of databases
|
18
|
*/
|
19
|
function _printConnection() {
|
20
|
global $data, $lang, $conf, $action, $misc;
|
21
|
|
22
|
// The javascript action on the select box reloads the
|
23
|
// popup whenever the server or database is changed.
|
24
|
// This ensures that the correct page encoding is used.
|
25
|
$onchange = "onchange=\"location.href='sqledit.php?action=" .
|
26
|
urlencode($action) . "&server=' + encodeURI(server.options[server.selectedIndex].value) + '&database=' + encodeURI(database.options[database.selectedIndex].value) + ";
|
27
|
|
28
|
// The exact URL to reload to is different between SQL and Find mode, however.
|
29
|
if ($action == 'find') {
|
30
|
$onchange .= "'&term=' + encodeURI(term.value) + '&filter=' + encodeURI(filter.value) + '&" . SID . "'\">\n";
|
31
|
} else {
|
32
|
$onchange .= "'&query=' + encodeURI(query.value) ";
|
33
|
if ($data->hasSchemas()) $onchange .= "+ '&search_path=' + encodeURI(search_path.value) ";
|
34
|
$onchange .= "+ (paginate.checked ? '&paginate=on' : '') + '&" . SID . "'\"";
|
35
|
}
|
36
|
|
37
|
echo "<table width=\"100%\"><tr><td>\n";
|
38
|
echo "<label>";
|
39
|
$misc->printHelp($lang['strserver'], 'pg.server');
|
40
|
echo "</label>";
|
41
|
echo ": <select name=\"server\" {$onchange}>\n";
|
42
|
|
43
|
$servers = $misc->getServers();
|
44
|
foreach($servers as $info) {
|
45
|
if (empty($info['username'])) continue;
|
46
|
echo "<option value=\"", htmlspecialchars($info['id']), "\"",
|
47
|
((isset($_REQUEST['server']) && $info['id'] == $_REQUEST['server'])) ? ' selected="selected"' : '', ">",
|
48
|
htmlspecialchars("{$info['desc']} ({$info['id']})"), "</option>\n";
|
49
|
}
|
50
|
echo "</select>\n</td><td align=\"right\">\n";
|
51
|
|
52
|
// Get the list of all databases
|
53
|
$databases = $data->getDatabases();
|
54
|
|
55
|
if ($databases->recordCount() > 0) {
|
56
|
// The javascript action on the select box reloads
|
57
|
// the popup whenever the database is changed.
|
58
|
// This ensures that the correct page encoding is used.
|
59
|
|
60
|
echo "<label>";
|
61
|
$misc->printHelp($lang['strdatabase'], 'pg.database');
|
62
|
echo ": <select name=\"database\" {$onchange}>\n";
|
63
|
|
64
|
while (!$databases->EOF) {
|
65
|
$dbname = $databases->f['datname'];
|
66
|
echo "<option value=\"", htmlspecialchars($dbname), "\"",
|
67
|
((isset($_REQUEST['database']) && $dbname == $_REQUEST['database'])) ? ' selected="selected"' : '', ">",
|
68
|
htmlspecialchars($dbname), "</option>\n";
|
69
|
$databases->moveNext();
|
70
|
}
|
71
|
echo "</select></label>\n";
|
72
|
}
|
73
|
else {
|
74
|
$server_info = $misc->getServerInfo();
|
75
|
echo "<input type=\"hidden\" name=\"database\" value=\"",
|
76
|
htmlspecialchars($server_info['defaultdb']), "\" />\n";
|
77
|
}
|
78
|
|
79
|
echo "</td></tr></table>\n";
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* Searches for a named database object
|
84
|
*/
|
85
|
function doFind() {
|
86
|
global $PHP_SELF, $data, $misc;
|
87
|
global $lang, $conf;
|
88
|
|
89
|
if (!isset($_GET['term'])) $_GET['term'] = '';
|
90
|
if (!isset($_GET['filter'])) $_GET['filter'] = '';
|
91
|
|
92
|
$misc->printHeader($lang['strfind']);
|
93
|
|
94
|
// Bring to the front always
|
95
|
echo "<body onload=\"window.focus();\">\n";
|
96
|
|
97
|
$misc->printTabs($misc->getNavTabs('popup'), 'find');
|
98
|
|
99
|
echo "<form action=\"database.php\" method=\"get\" target=\"detail\">\n<p>";
|
100
|
_printConnection();
|
101
|
echo "</p><p><input name=\"term\" value=\"", htmlspecialchars($_GET['term']),
|
102
|
"\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" />\n";
|
103
|
|
104
|
// Output list of filters. This is complex due to all the 'has' and 'conf' feature possibilities
|
105
|
echo "<select name=\"filter\">\n";
|
106
|
echo "\t<option value=\"\"", ($_GET['filter'] == '') ? ' selected="selected"' : '', ">{$lang['strallobjects']}</option>\n";
|
107
|
if ($data->hasSchemas())
|
108
|
echo "\t<option value=\"SCHEMA\"", ($_GET['filter'] == 'SCHEMA') ? ' selected="selected"' : '', ">{$lang['strschemas']}</option>\n";
|
109
|
echo "\t<option value=\"TABLE\"", ($_GET['filter'] == 'TABLE') ? ' selected="selected"' : '', ">{$lang['strtables']}</option>\n";
|
110
|
echo "\t<option value=\"VIEW\"", ($_GET['filter'] == 'VIEW') ? ' selected="selected"' : '', ">{$lang['strviews']}</option>\n";
|
111
|
echo "\t<option value=\"SEQUENCE\"", ($_GET['filter'] == 'SEQUENCE') ? ' selected="selected"' : '', ">{$lang['strsequences']}</option>\n";
|
112
|
echo "\t<option value=\"COLUMN\"", ($_GET['filter'] == 'COLUMN') ? ' selected="selected"' : '', ">{$lang['strcolumns']}</option>\n";
|
113
|
echo "\t<option value=\"RULE\"", ($_GET['filter'] == 'RULE') ? ' selected="selected"' : '', ">{$lang['strrules']}</option>\n";
|
114
|
echo "\t<option value=\"INDEX\"", ($_GET['filter'] == 'INDEX') ? ' selected="selected"' : '', ">{$lang['strindexes']}</option>\n";
|
115
|
echo "\t<option value=\"TRIGGER\"", ($_GET['filter'] == 'TRIGGER') ? ' selected="selected"' : '', ">{$lang['strtriggers']}</option>\n";
|
116
|
echo "\t<option value=\"CONSTRAINT\"", ($_GET['filter'] == 'CONSTRAINT') ? ' selected="selected"' : '', ">{$lang['strconstraints']}</option>\n";
|
117
|
echo "\t<option value=\"FUNCTION\"", ($_GET['filter'] == 'FUNCTION') ? ' selected="selected"' : '', ">{$lang['strfunctions']}</option>\n";
|
118
|
if ($data->hasDomains())
|
119
|
echo "\t<option value=\"DOMAIN\"", ($_GET['filter'] == 'DOMAIN') ? ' selected="selected"' : '', ">{$lang['strdomains']}</option>\n";
|
120
|
if ($conf['show_advanced']) {
|
121
|
echo "\t<option value=\"AGGREGATE\"", ($_GET['filter'] == 'AGGREGATE') ? ' selected="selected"' : '', ">{$lang['straggregates']}</option>\n";
|
122
|
echo "\t<option value=\"TYPE\"", ($_GET['filter'] == 'TYPE') ? ' selected="selected"' : '', ">{$lang['strtypes']}</option>\n";
|
123
|
echo "\t<option value=\"OPERATOR\"", ($_GET['filter'] == 'OPERATOR') ? ' selected="selected"' : '', ">{$lang['stroperators']}</option>\n";
|
124
|
echo "\t<option value=\"OPCLASS\"", ($_GET['filter'] == 'OPCLASS') ? ' selected="selected"' : '', ">{$lang['stropclasses']}</option>\n";
|
125
|
if ($data->hasConversions())
|
126
|
echo "\t<option value=\"CONVERSION\"", ($_GET['filter'] == 'CONVERSION') ? ' selected="selected"' : '', ">{$lang['strconversions']}</option>\n";
|
127
|
echo "\t<option value=\"LANGUAGE\"", ($_GET['filter'] == 'LANGUAGE') ? ' selected="selected"' : '', ">{$lang['strlanguages']}</option>\n";
|
128
|
}
|
129
|
echo "</select>\n";
|
130
|
|
131
|
echo "<input type=\"submit\" value=\"{$lang['strfind']}\" />\n";
|
132
|
echo "<input type=\"hidden\" name=\"action\" value=\"find\" /></p>\n";
|
133
|
echo "</form>\n";
|
134
|
|
135
|
// Default focus
|
136
|
$misc->setFocus('forms[0].term');
|
137
|
}
|
138
|
|
139
|
/**
|
140
|
* Allow execution of arbitrary SQL statements on a database
|
141
|
*/
|
142
|
function doDefault() {
|
143
|
global $PHP_SELF, $data, $misc;
|
144
|
global $lang, $conf;
|
145
|
|
146
|
if (!isset($_REQUEST['query'])) $_REQUEST['query'] = '';
|
147
|
|
148
|
$misc->printHeader($lang['strsql']);
|
149
|
|
150
|
// Bring to the front always
|
151
|
echo "<body onload=\"window.focus();\">\n";
|
152
|
|
153
|
$misc->printTabs($misc->getNavTabs('popup'), 'sql');
|
154
|
|
155
|
echo "<form action=\"sql.php\" method=\"post\" target=\"detail\">\n<p>";
|
156
|
_printConnection();
|
157
|
echo "</p>\n";
|
158
|
if ($data->hasSchemas()) {
|
159
|
if (!isset($_REQUEST['search_path']))
|
160
|
$_REQUEST['search_path'] = implode(',',$data->getSearchPath());
|
161
|
|
162
|
echo "<p><label>";
|
163
|
$misc->printHelp($lang['strsearchpath'], 'pg.schema.search_path');
|
164
|
echo ": <input type=\"text\" name=\"search_path\" size=\"50\" value=\"",
|
165
|
htmlspecialchars($_REQUEST['search_path']), "\" /></label></p>\n";
|
166
|
}
|
167
|
|
168
|
echo "<textarea style=\"width: 100%;\" rows=\"10\" cols=\"50\" name=\"query\">",
|
169
|
htmlspecialchars($_REQUEST['query']), "</textarea>\n";
|
170
|
echo "<label><input type=\"checkbox\" name=\"paginate\"", (isset($_REQUEST['paginate']) ? ' checked="checked"' : ''), " /> {$lang['strpaginate']}</label>\n";
|
171
|
|
172
|
echo "<p><input type=\"submit\" value=\"{$lang['strrun']}\" />\n";
|
173
|
if ($data->hasFullExplain()) {
|
174
|
echo "<input type=\"submit\" name=\"explain\" value=\"{$lang['strexplain']}\" />\n";
|
175
|
echo "<input type=\"submit\" name=\"explain_analyze\" value=\"{$lang['strexplainanalyze']}\" />\n";
|
176
|
}
|
177
|
echo "<input type=\"reset\" value=\"{$lang['strreset']}\" /></p>\n";
|
178
|
echo "</form>\n";
|
179
|
|
180
|
// Default focus
|
181
|
$misc->setFocus('forms[0].query');
|
182
|
}
|
183
|
|
184
|
switch ($action) {
|
185
|
case 'find':
|
186
|
doFind();
|
187
|
break;
|
188
|
case 'sql':
|
189
|
default:
|
190
|
doDefault();
|
191
|
break;
|
192
|
}
|
193
|
|
194
|
// Set the name of the window
|
195
|
$misc->setWindowName('sqledit');
|
196
|
|
197
|
$misc->printFooter();
|
198
|
|
199
|
?>
|