1 |
6daefa8c
|
Petr Lukašík
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* List tables in a database
|
5 |
|
|
*
|
6 |
|
|
* $Id: tables.php,v 1.74 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 |
|
|
$PHP_SELF = $_SERVER['PHP_SELF'];
|
14 |
|
|
|
15 |
|
|
/**
|
16 |
|
|
* Displays a screen where they can enter a new table
|
17 |
|
|
*/
|
18 |
|
|
function doCreate($msg = '') {
|
19 |
|
|
global $data, $misc;
|
20 |
|
|
global $PHP_SELF, $lang;
|
21 |
|
|
|
22 |
|
|
if (!isset($_REQUEST['stage'])) $_REQUEST['stage'] = 1;
|
23 |
|
|
if (!isset($_REQUEST['name'])) $_REQUEST['name'] = '';
|
24 |
|
|
if (!isset($_REQUEST['fields'])) $_REQUEST['fields'] = '';
|
25 |
|
|
if (!isset($_REQUEST['tblcomment'])) $_REQUEST['tblcomment'] = '';
|
26 |
|
|
if (!isset($_REQUEST['spcname'])) $_REQUEST['spcname'] = '';
|
27 |
|
|
|
28 |
|
|
switch ($_REQUEST['stage']) {
|
29 |
|
|
case 1:
|
30 |
|
|
// Fetch all tablespaces from the database
|
31 |
|
|
if ($data->hasTablespaces()) $tablespaces = $data->getTablespaces();
|
32 |
|
|
|
33 |
|
|
$misc->printTrail('schema');
|
34 |
|
|
$misc->printTitle($lang['strcreatetable'], 'pg.table.create');
|
35 |
|
|
$misc->printMsg($msg);
|
36 |
|
|
|
37 |
|
|
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
|
38 |
|
|
echo "<table>\n";
|
39 |
|
|
echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n";
|
40 |
|
|
echo "\t\t<td class=\"data\"><input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
|
41 |
|
|
htmlspecialchars($_REQUEST['name']), "\" /></td>\n\t</tr>\n";
|
42 |
|
|
echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strnumcols']}</th>\n";
|
43 |
|
|
echo "\t\t<td class=\"data\"><input name=\"fields\" size=\"5\" maxlength=\"{$data->_maxNameLen}\" value=\"",
|
44 |
|
|
htmlspecialchars($_REQUEST['fields']), "\" /></td>\n\t</tr>\n";
|
45 |
|
|
if ($data->hasWithoutOIDs()) {
|
46 |
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['stroptions']}</th>\n";
|
47 |
|
|
echo "\t\t<td class=\"data\"><input type=\"checkbox\" name=\"withoutoids\"",
|
48 |
|
|
(isset($_REQUEST['withoutoids']) ? ' checked="checked"' : ''), " />WITHOUT OIDS</td>\n\t</tr>\n";
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
// Tablespace (if there are any)
|
52 |
|
|
if ($data->hasTablespaces() && $tablespaces->recordCount() > 0) {
|
53 |
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strtablespace']}</th>\n";
|
54 |
|
|
echo "\t\t<td class=\"data1\">\n\t\t\t<select name=\"spcname\">\n";
|
55 |
|
|
// Always offer the default (empty) option
|
56 |
|
|
echo "\t\t\t\t<option value=\"\"",
|
57 |
|
|
($_REQUEST['spcname'] == '') ? ' selected="selected"' : '', "></option>\n";
|
58 |
|
|
// Display all other tablespaces
|
59 |
|
|
while (!$tablespaces->EOF) {
|
60 |
|
|
$spcname = htmlspecialchars($tablespaces->f['spcname']);
|
61 |
|
|
echo "\t\t\t\t<option value=\"{$spcname}\"",
|
62 |
|
|
($spcname == $_REQUEST['spcname']) ? ' selected="selected"' : '', ">{$spcname}</option>\n";
|
63 |
|
|
$tablespaces->moveNext();
|
64 |
|
|
}
|
65 |
|
|
echo "\t\t\t</select>\n\t\t</td>\n\t</tr>\n";
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n";
|
69 |
|
|
echo "\t\t<td><textarea name=\"tblcomment\" rows=\"3\" cols=\"32\" wrap=\"virtual\">",
|
70 |
|
|
htmlspecialchars($_REQUEST['tblcomment']), "</textarea></td>\n\t</tr>\n";
|
71 |
|
|
|
72 |
|
|
echo "</table>\n";
|
73 |
|
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"create\" />\n";
|
74 |
|
|
echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n";
|
75 |
|
|
echo $misc->form;
|
76 |
|
|
echo "<input type=\"submit\" value=\"{$lang['strnext']}\" />\n";
|
77 |
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
|
78 |
|
|
echo "</form>\n";
|
79 |
|
|
break;
|
80 |
|
|
case 2:
|
81 |
|
|
global $lang;
|
82 |
|
|
|
83 |
|
|
// Check inputs
|
84 |
|
|
$fields = trim($_REQUEST['fields']);
|
85 |
|
|
if (trim($_REQUEST['name']) == '') {
|
86 |
|
|
$_REQUEST['stage'] = 1;
|
87 |
|
|
doCreate($lang['strtableneedsname']);
|
88 |
|
|
return;
|
89 |
|
|
}
|
90 |
|
|
elseif ($fields == '' || !is_numeric($fields) || $fields != (int)$fields || $fields < 1) {
|
91 |
|
|
$_REQUEST['stage'] = 1;
|
92 |
|
|
doCreate($lang['strtableneedscols']);
|
93 |
|
|
return;
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
$types = $data->getTypes(true, false, true);
|
97 |
|
|
|
98 |
|
|
$misc->printTrail('schema');
|
99 |
|
|
$misc->printTitle($lang['strcreatetable'], 'pg.table.create');
|
100 |
|
|
$misc->printMsg($msg);
|
101 |
|
|
|
102 |
|
|
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
|
103 |
|
|
|
104 |
|
|
// Output table header
|
105 |
|
|
echo "<table>\n";
|
106 |
|
|
echo "\t<tr><th colspan=\"2\" class=\"data required\">{$lang['strcolumn']}</th><th colspan=\"2\" class=\"data required\">{$lang['strtype']}</th>";
|
107 |
|
|
echo "<th class=\"data\">{$lang['strlength']}</th><th class=\"data\">{$lang['strnotnull']}</th>";
|
108 |
|
|
echo "<th class=\"data\">{$lang['struniquekey']}</th><th class=\"data\">{$lang['strprimarykey']}</th>";
|
109 |
|
|
echo "<th class=\"data\">{$lang['strdefault']}</th><th class=\"data\">{$lang['strcomment']}</th></tr>\n";
|
110 |
|
|
|
111 |
|
|
for ($i = 0; $i < $_REQUEST['fields']; $i++) {
|
112 |
|
|
if (!isset($_REQUEST['field'][$i])) $_REQUEST['field'][$i] = '';
|
113 |
|
|
if (!isset($_REQUEST['length'][$i])) $_REQUEST['length'][$i] = '';
|
114 |
|
|
if (!isset($_REQUEST['default'][$i])) $_REQUEST['default'][$i] = '';
|
115 |
|
|
if (!isset($_REQUEST['colcomment'][$i])) $_REQUEST['colcomment'][$i] = '';
|
116 |
|
|
|
117 |
|
|
echo "\t<tr>\n\t\t<td>", $i + 1, ". </td>\n";
|
118 |
|
|
echo "\t\t<td><input name=\"field[{$i}]\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"",
|
119 |
|
|
htmlspecialchars($_REQUEST['field'][$i]), "\" /></td>\n";
|
120 |
|
|
echo "\t\t<td>\n\t\t\t<select name=\"type[{$i}]\">\n";
|
121 |
|
|
// Output any "magic" types
|
122 |
|
|
foreach ($data->extraTypes as $v) {
|
123 |
|
|
echo "\t\t\t\t<option value=\"", htmlspecialchars($v), "\"",
|
124 |
|
|
(isset($_REQUEST['type'][$i]) && $v == $_REQUEST['type'][$i]) ? ' selected="selected"' : '', ">",
|
125 |
|
|
$misc->printVal($v), "</option>\n";
|
126 |
|
|
}
|
127 |
|
|
$types->moveFirst();
|
128 |
|
|
while (!$types->EOF) {
|
129 |
|
|
$typname = $types->f['typname'];
|
130 |
|
|
echo "\t\t\t\t<option value=\"", htmlspecialchars($typname), "\"",
|
131 |
|
|
(isset($_REQUEST['type'][$i]) && $typname == $_REQUEST['type'][$i]) ? ' selected="selected"' : '', ">",
|
132 |
|
|
$misc->printVal($typname), "</option>\n";
|
133 |
|
|
$types->moveNext();
|
134 |
|
|
}
|
135 |
|
|
echo "\t\t\t</select>\n\t\t</td>\n";
|
136 |
|
|
|
137 |
|
|
// Output array type selector
|
138 |
|
|
echo "\t\t<td>\n\t\t\t<select name=\"array[{$i}]\">\n";
|
139 |
|
|
echo "\t\t\t\t<option value=\"\"", (isset($_REQUEST['array'][$i]) && $_REQUEST['array'][$i] == '') ? ' selected="selected"' : '', "></option>\n";
|
140 |
|
|
echo "\t\t\t\t<option value=\"[]\"", (isset($_REQUEST['array'][$i]) && $_REQUEST['array'][$i] == '[]') ? ' selected="selected"' : '', ">[ ]</option>\n";
|
141 |
|
|
echo "\t\t\t</select>\n\t\t</td>\n";
|
142 |
|
|
|
143 |
|
|
echo "\t\t<td><input name=\"length[{$i}]\" size=\"10\" value=\"",
|
144 |
|
|
htmlspecialchars($_REQUEST['length'][$i]), "\" /></td>\n";
|
145 |
|
|
echo "\t\t<td><input type=\"checkbox\" name=\"notnull[{$i}]\"", (isset($_REQUEST['notnull'][$i])) ? ' checked="checked"' : '', " /></td>\n";
|
146 |
|
|
echo "\t\t<td align=\"center\"><input type=\"checkbox\" name=\"uniquekey[{$i}]\""
|
147 |
|
|
.(isset($_REQUEST['uniquekey'][$i]) ? ' checked="checked"' :'')." /></td>\n";
|
148 |
|
|
echo "\t\t<td align=\"center\"><input type=\"checkbox\" name=\"primarykey[{$i}]\" "
|
149 |
|
|
.(isset($_REQUEST['primarykey'][$i]) ? ' checked="checked"' : '')
|
150 |
|
|
." /></td>\n";
|
151 |
|
|
echo "\t\t<td><input name=\"default[{$i}]\" size=\"20\" value=\"",
|
152 |
|
|
htmlspecialchars($_REQUEST['default'][$i]), "\" /></td>\n";
|
153 |
|
|
echo "\t\t<td><input name=\"colcomment[{$i}]\" size=\"40\" value=\"",
|
154 |
|
|
htmlspecialchars($_REQUEST['colcomment'][$i]), "\" /></td>\n\t</tr>\n";
|
155 |
|
|
}
|
156 |
|
|
echo "</table>\n";
|
157 |
|
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"create\" />\n";
|
158 |
|
|
echo "<input type=\"hidden\" name=\"stage\" value=\"3\" />\n";
|
159 |
|
|
echo $misc->form;
|
160 |
|
|
echo "<input type=\"hidden\" name=\"name\" value=\"", htmlspecialchars($_REQUEST['name']), "\" />\n";
|
161 |
|
|
echo "<input type=\"hidden\" name=\"fields\" value=\"", htmlspecialchars($_REQUEST['fields']), "\" />\n";
|
162 |
|
|
if (isset($_REQUEST['withoutoids'])) {
|
163 |
|
|
echo "<input type=\"hidden\" name=\"withoutoids\" value=\"true\" />\n";
|
164 |
|
|
}
|
165 |
|
|
echo "<input type=\"hidden\" name=\"tblcomment\" value=\"", htmlspecialchars($_REQUEST['tblcomment']), "\" />\n";
|
166 |
|
|
if (isset($_REQUEST['spcname'])) {
|
167 |
|
|
echo "<input type=\"hidden\" name=\"spcname\" value=\"", htmlspecialchars($_REQUEST['spcname']), "\" />\n";
|
168 |
|
|
}
|
169 |
|
|
echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n";
|
170 |
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
|
171 |
|
|
echo "</form>\n";
|
172 |
|
|
|
173 |
|
|
break;
|
174 |
|
|
case 3:
|
175 |
|
|
global $data, $lang, $_reload_browser;
|
176 |
|
|
|
177 |
|
|
if (!isset($_REQUEST['notnull'])) $_REQUEST['notnull'] = array();
|
178 |
|
|
if (!isset($_REQUEST['uniquekey'])) $_REQUEST['uniquekey'] = array();
|
179 |
|
|
if (!isset($_REQUEST['primarykey'])) $_REQUEST['primarykey'] = array();
|
180 |
|
|
// Default tablespace to null if it isn't set
|
181 |
|
|
if (!isset($_REQUEST['spcname'])) $_REQUEST['spcname'] = null;
|
182 |
|
|
|
183 |
|
|
// Check inputs
|
184 |
|
|
$fields = trim($_REQUEST['fields']);
|
185 |
|
|
if (trim($_REQUEST['name']) == '') {
|
186 |
|
|
$_REQUEST['stage'] = 1;
|
187 |
|
|
doCreate($lang['strtableneedsname']);
|
188 |
|
|
return;
|
189 |
|
|
}
|
190 |
|
|
elseif ($fields == '' || !is_numeric($fields) || $fields != (int)$fields || $fields <= 0) {
|
191 |
|
|
$_REQUEST['stage'] = 1;
|
192 |
|
|
doCreate($lang['strtableneedscols']);
|
193 |
|
|
return;
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
$status = $data->createTable($_REQUEST['name'], $_REQUEST['fields'], $_REQUEST['field'],
|
197 |
|
|
$_REQUEST['type'], $_REQUEST['array'], $_REQUEST['length'], $_REQUEST['notnull'], $_REQUEST['default'],
|
198 |
|
|
isset($_REQUEST['withoutoids']), $_REQUEST['colcomment'], $_REQUEST['tblcomment'], $_REQUEST['spcname'],
|
199 |
|
|
$_REQUEST['uniquekey'], $_REQUEST['primarykey']);
|
200 |
|
|
|
201 |
|
|
if ($status == 0) {
|
202 |
|
|
$_reload_browser = true;
|
203 |
|
|
doDefault($lang['strtablecreated']);
|
204 |
|
|
}
|
205 |
|
|
elseif ($status == -1) {
|
206 |
|
|
$_REQUEST['stage'] = 2;
|
207 |
|
|
doCreate($lang['strtableneedsfield']);
|
208 |
|
|
return;
|
209 |
|
|
}
|
210 |
|
|
else {
|
211 |
|
|
$_REQUEST['stage'] = 2;
|
212 |
|
|
doCreate($lang['strtablecreatedbad']);
|
213 |
|
|
return;
|
214 |
|
|
}
|
215 |
|
|
break;
|
216 |
|
|
default:
|
217 |
|
|
echo "<p>{$lang['strinvalidparam']}</p>\n";
|
218 |
|
|
}
|
219 |
|
|
}
|
220 |
|
|
|
221 |
|
|
/**
|
222 |
|
|
* Ask for select parameters and perform select
|
223 |
|
|
*/
|
224 |
|
|
function doSelectRows($confirm, $msg = '') {
|
225 |
|
|
global $data, $misc, $_no_output;
|
226 |
|
|
global $lang;
|
227 |
|
|
global $PHP_SELF;
|
228 |
|
|
|
229 |
|
|
if ($confirm) {
|
230 |
|
|
$misc->printTrail('table');
|
231 |
|
|
$misc->printTitle($lang['strselect'], 'pg.sql.select');
|
232 |
|
|
$misc->printMsg($msg);
|
233 |
|
|
|
234 |
|
|
$attrs = $data->getTableAttributes($_REQUEST['table']);
|
235 |
|
|
|
236 |
|
|
echo "<form action=\"$PHP_SELF\" method=\"post\" name=\"selectform\">\n";
|
237 |
|
|
if ($attrs->recordCount() > 0) {
|
238 |
|
|
// JavaScript for select all feature
|
239 |
|
|
echo "<script type=\"text/javascript\">\n";
|
240 |
|
|
echo "<!--\n";
|
241 |
|
|
echo " function selectAll() {\n";
|
242 |
|
|
echo " for (var i=0; i<document.selectform.elements.length; i++) {\n";
|
243 |
|
|
echo " var e = document.selectform.elements[i];\n";
|
244 |
|
|
echo " if (e.name.indexOf('show') == 0) e.checked = document.selectform.selectall.checked;\n";
|
245 |
|
|
echo " }\n";
|
246 |
|
|
echo " }\n";
|
247 |
|
|
echo "//-->\n";
|
248 |
|
|
echo "</script>\n";
|
249 |
|
|
|
250 |
|
|
echo "<table>\n<tr>";
|
251 |
|
|
|
252 |
|
|
// Output table header
|
253 |
|
|
echo "<tr><th class=\"data\">{$lang['strshow']}</th><th class=\"data\">{$lang['strcolumn']}</th>";
|
254 |
|
|
echo "<th class=\"data\">{$lang['strtype']}</th><th class=\"data\">{$lang['stroperator']}</th>";
|
255 |
|
|
echo "<th class=\"data\">{$lang['strvalue']}</th></tr>";
|
256 |
|
|
|
257 |
|
|
$i = 0;
|
258 |
|
|
while (!$attrs->EOF) {
|
259 |
|
|
$attrs->f['attnotnull'] = $data->phpBool($attrs->f['attnotnull']);
|
260 |
|
|
// Set up default value if there isn't one already
|
261 |
|
|
if (!isset($_REQUEST['values'][$attrs->f['attname']]))
|
262 |
|
|
$_REQUEST['values'][$attrs->f['attname']] = null;
|
263 |
|
|
if (!isset($_REQUEST['ops'][$attrs->f['attname']]))
|
264 |
|
|
$_REQUEST['ops'][$attrs->f['attname']] = null;
|
265 |
|
|
// Continue drawing row
|
266 |
|
|
$id = (($i % 2) == 0 ? '1' : '2');
|
267 |
|
|
echo "<tr>\n";
|
268 |
|
|
echo "<td class=\"data{$id}\" nowrap=\"nowrap\">";
|
269 |
|
|
echo "<input type=\"checkbox\" name=\"show[", htmlspecialchars($attrs->f['attname']), "]\"",
|
270 |
|
|
isset($_REQUEST['show'][$attrs->f['attname']]) ? ' checked="checked"' : '', " /></td>";
|
271 |
|
|
echo "<td class=\"data{$id}\" nowrap=\"nowrap\">", $misc->printVal($attrs->f['attname']), "</td>";
|
272 |
|
|
echo "<td class=\"data{$id}\" nowrap=\"nowrap\">", $misc->printVal($data->formatType($attrs->f['type'], $attrs->f['atttypmod'])), "</td>";
|
273 |
|
|
echo "<td class=\"data{$id}\" nowrap=\"nowrap\">";
|
274 |
|
|
echo "<select name=\"ops[{$attrs->f['attname']}]\">\n";
|
275 |
|
|
foreach (array_keys($data->selectOps) as $v) {
|
276 |
|
|
echo "<option value=\"", htmlspecialchars($v), "\"", ($v == $_REQUEST['ops'][$attrs->f['attname']]) ? ' selected="selected"' : '',
|
277 |
|
|
">", htmlspecialchars($v), "</option>\n";
|
278 |
|
|
}
|
279 |
|
|
echo "</select>\n";
|
280 |
|
|
echo "<td class=\"data{$id}\" nowrap=\"nowrap\">", $data->printField("values[{$attrs->f['attname']}]",
|
281 |
|
|
$_REQUEST['values'][$attrs->f['attname']], $attrs->f['type']), "</td>";
|
282 |
|
|
echo "</tr>\n";
|
283 |
|
|
$i++;
|
284 |
|
|
$attrs->moveNext();
|
285 |
|
|
}
|
286 |
|
|
// Select all checkbox
|
287 |
|
|
echo "<tr><td colspan=\"5\"><input type=\"checkbox\" name=\"selectall\" onClick=\"javascript:selectAll()\" />{$lang['strselectallfields']}</td>";
|
288 |
|
|
echo "</table></p>\n";
|
289 |
|
|
}
|
290 |
|
|
else echo "<p>{$lang['strinvalidparam']}</p>\n";
|
291 |
|
|
|
292 |
|
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"selectrows\" />\n";
|
293 |
|
|
echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
|
294 |
|
|
echo "<input type=\"hidden\" name=\"subject\" value=\"table\" />\n";
|
295 |
|
|
echo $misc->form;
|
296 |
|
|
echo "<input type=\"submit\" name=\"select\" value=\"{$lang['strselect']}\" />\n";
|
297 |
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
|
298 |
|
|
echo "</form>\n";
|
299 |
|
|
}
|
300 |
|
|
else {
|
301 |
|
|
if (!isset($_POST['show'])) $_POST['show'] = array();
|
302 |
|
|
if (!isset($_POST['values'])) $_POST['values'] = array();
|
303 |
|
|
if (!isset($_POST['nulls'])) $_POST['nulls'] = array();
|
304 |
|
|
|
305 |
|
|
// Verify that they haven't supplied a value for unary operators
|
306 |
|
|
foreach ($_POST['ops'] as $k => $v) {
|
307 |
|
|
if ($data->selectOps[$v] == 'p' && $_POST['values'][$k] != '') {
|
308 |
|
|
doSelectRows(true, $lang['strselectunary']);
|
309 |
|
|
return;
|
310 |
|
|
}
|
311 |
|
|
}
|
312 |
|
|
|
313 |
|
|
if (sizeof($_POST['show']) == 0)
|
314 |
|
|
doSelectRows(true, $lang['strselectneedscol']);
|
315 |
|
|
else {
|
316 |
|
|
// Generate query SQL
|
317 |
|
|
$query = $data->getSelectSQL($_REQUEST['table'], array_keys($_POST['show']),
|
318 |
|
|
$_POST['values'], $_POST['ops']);
|
319 |
|
|
$_REQUEST['query'] = $query;
|
320 |
|
|
$_REQUEST['return_url'] = "tables.php?action=confselectrows&{$misc->href}&table={$_REQUEST['table']}";
|
321 |
|
|
$_REQUEST['return_desc'] = $lang['strback'];
|
322 |
|
|
|
323 |
|
|
$_no_output = true;
|
324 |
|
|
include('./display.php');
|
325 |
|
|
exit;
|
326 |
|
|
}
|
327 |
|
|
}
|
328 |
|
|
|
329 |
|
|
}
|
330 |
|
|
|
331 |
|
|
/**
|
332 |
|
|
* Ask for insert parameters and then actually insert row
|
333 |
|
|
*/
|
334 |
|
|
function doInsertRow($confirm, $msg = '') {
|
335 |
|
|
global $data, $misc;
|
336 |
|
|
global $lang;
|
337 |
|
|
global $PHP_SELF;
|
338 |
|
|
|
339 |
|
|
if ($confirm) {
|
340 |
|
|
$misc->printTrail('table');
|
341 |
|
|
$misc->printTitle($lang['strinsertrow'], 'pg.sql.insert');
|
342 |
|
|
$misc->printMsg($msg);
|
343 |
|
|
|
344 |
|
|
$attrs = $data->getTableAttributes($_REQUEST['table']);
|
345 |
|
|
|
346 |
|
|
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
|
347 |
|
|
if ($attrs->recordCount() > 0) {
|
348 |
|
|
echo "<table>\n";
|
349 |
|
|
|
350 |
|
|
// Output table header
|
351 |
|
|
echo "<tr><th class=\"data\">{$lang['strcolumn']}</th><th class=\"data\">{$lang['strtype']}</th>";
|
352 |
|
|
echo "<th class=\"data\">{$lang['strformat']}</th>";
|
353 |
|
|
echo "<th class=\"data\">{$lang['strnull']}</th><th class=\"data\">{$lang['strvalue']}</th></tr>";
|
354 |
|
|
|
355 |
|
|
$i = 0;
|
356 |
|
|
while (!$attrs->EOF) {
|
357 |
|
|
$attrs->f['attnotnull'] = $data->phpBool($attrs->f['attnotnull']);
|
358 |
|
|
// Set up default value if there isn't one already
|
359 |
|
|
if (!isset($_REQUEST['values'][$attrs->f['attname']]))
|
360 |
|
|
$_REQUEST['values'][$attrs->f['attname']] = $attrs->f['adsrc'];
|
361 |
|
|
// Default format to 'VALUE' if there is no default,
|
362 |
|
|
// otherwise default to 'EXPRESSION'
|
363 |
|
|
if (!isset($_REQUEST['format'][$attrs->f['attname']]))
|
364 |
|
|
$_REQUEST['format'][$attrs->f['attname']] = ($attrs->f['adsrc'] === null) ? 'VALUE' : 'EXPRESSION';
|
365 |
|
|
// Continue drawing row
|
366 |
|
|
$id = (($i % 2) == 0 ? '1' : '2');
|
367 |
|
|
echo "<tr>\n";
|
368 |
|
|
echo "<td class=\"data{$id}\" nowrap=\"nowrap\">", $misc->printVal($attrs->f['attname']), "</td>";
|
369 |
|
|
echo "<td class=\"data{$id}\" nowrap=\"nowrap\">\n";
|
370 |
|
|
echo $misc->printVal($data->formatType($attrs->f['type'], $attrs->f['atttypmod']));
|
371 |
|
|
echo "<input type=\"hidden\" name=\"types[", htmlspecialchars($attrs->f['attname']), "]\" value=\"",
|
372 |
|
|
htmlspecialchars($attrs->f['type']), "\" /></td>";
|
373 |
|
|
echo "<td class=\"data{$id}\" nowrap=\"nowrap\">\n";
|
374 |
|
|
echo "<select name=\"format[", htmlspecialchars($attrs->f['attname']), "]\">\n";
|
375 |
|
|
echo "<option value=\"VALUE\"", ($_REQUEST['format'][$attrs->f['attname']] == 'VALUE') ? ' selected="selected"' : '', ">{$lang['strvalue']}</option>\n";
|
376 |
|
|
echo "<option value=\"EXPRESSION\"", ($_REQUEST['format'][$attrs->f['attname']] == 'EXPRESSION') ? ' selected="selected"' : '', ">{$lang['strexpression']}</option>\n";
|
377 |
|
|
echo "</select>\n</td>\n";
|
378 |
|
|
echo "<td class=\"data{$id}\" nowrap=\"nowrap\">";
|
379 |
|
|
// Output null box if the column allows nulls (doesn't look at CHECKs or ASSERTIONS)
|
380 |
|
|
if (!$attrs->f['attnotnull'])
|
381 |
|
|
echo "<input type=\"checkbox\" name=\"nulls[", htmlspecialchars($attrs->f['attname']), "]\"",
|
382 |
|
|
isset($_REQUEST['nulls'][$attrs->f['attname']]) ? ' checked="checked"' : '', " /></td>";
|
383 |
|
|
else
|
384 |
|
|
echo " </td>";
|
385 |
|
|
echo "<td class=\"data{$id}\" nowrap=\"nowrap\">", $data->printField("values[{$attrs->f['attname']}]",
|
386 |
|
|
$_REQUEST['values'][$attrs->f['attname']], $attrs->f['type']), "</td>";
|
387 |
|
|
echo "</tr>\n";
|
388 |
|
|
$i++;
|
389 |
|
|
$attrs->moveNext();
|
390 |
|
|
}
|
391 |
|
|
echo "</table></p>\n";
|
392 |
|
|
}
|
393 |
|
|
else echo "<p>{$lang['strnodata']}</p>\n";
|
394 |
|
|
|
395 |
|
|
if (!isset($_SESSION['counter'])) { $_SESSION['counter'] = 0; }
|
396 |
|
|
|
397 |
|
|
echo "<input type=\"hidden\" name=\"action\" value=\"insertrow\" />\n";
|
398 |
|
|
echo "<input type=\"hidden\" name=\"protection_counter\" value=\"".$_SESSION['counter']."\" />\n";
|
399 |
|
|
echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
|
400 |
|
|
echo $misc->form;
|
401 |
|
|
echo "<p><input type=\"submit\" name=\"insert\" value=\"{$lang['strinsert']}\" />\n";
|
402 |
|
|
echo "<input type=\"submit\" name=\"insertandrepeat\" value=\"{$lang['strinsertandrepeat']}\" />\n";
|
403 |
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
|
404 |
|
|
echo "</form>\n";
|
405 |
|
|
}
|
406 |
|
|
else {
|
407 |
|
|
if (!isset($_POST['values'])) $_POST['values'] = array();
|
408 |
|
|
if (!isset($_POST['nulls'])) $_POST['nulls'] = array();
|
409 |
|
|
|
410 |
|
|
if ($_SESSION['counter']++ == $_POST['protection_counter']) {
|
411 |
|
|
$status = $data->insertRow($_POST['table'], $_POST['values'],
|
412 |
|
|
$_POST['nulls'], $_POST['format'], $_POST['types']);
|
413 |
|
|
if ($status == 0) {
|
414 |
|
|
if (isset($_POST['insert']))
|
415 |
|
|
doDefault($lang['strrowinserted']);
|
416 |
|
|
else {
|
417 |
|
|
$_REQUEST['values'] = array();
|
418 |
|
|
$_REQUEST['nulls'] = array();
|
419 |
|
|
doInsertRow(true, $lang['strrowinserted']);
|
420 |
|
|
}
|
421 |
|
|
}
|
422 |
|
|
else
|
423 |
|
|
doInsertRow(true, $lang['strrowinsertedbad']);
|
424 |
|
|
} else
|
425 |
|
|
doInsertRow(true, $lang['strrowduplicate']);
|
426 |
|
|
}
|
427 |
|
|
|
428 |
|
|
}
|
429 |
|
|
|
430 |
|
|
/**
|
431 |
|
|
* Show confirmation of empty and perform actual empty
|
432 |
|
|
*/
|
433 |
|
|
function doEmpty($confirm) {
|
434 |
|
|
global $data, $misc;
|
435 |
|
|
global $lang;
|
436 |
|
|
global $PHP_SELF;
|
437 |
|
|
|
438 |
|
|
if ($confirm) {
|
439 |
|
|
$misc->printTrail('table');
|
440 |
|
|
$misc->printTitle($lang['strempty'],'pg.table.empty');
|
441 |
|
|
|
442 |
|
|
echo "<p>", sprintf($lang['strconfemptytable'], $misc->printVal($_REQUEST['table'])), "</p>\n";
|
443 |
|
|
|
444 |
|
|
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
|
445 |
|
|
echo "<input type=\"hidden\" name=\"action\" value=\"empty\" />\n";
|
446 |
|
|
echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
|
447 |
|
|
echo $misc->form;
|
448 |
|
|
echo "<input type=\"submit\" name=\"empty\" value=\"{$lang['strempty']}\" /> <input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
|
449 |
|
|
echo "</form>\n";
|
450 |
|
|
}
|
451 |
|
|
else {
|
452 |
|
|
$status = $data->emptyTable($_POST['table']);
|
453 |
|
|
if ($status == 0)
|
454 |
|
|
doDefault($lang['strtableemptied']);
|
455 |
|
|
else
|
456 |
|
|
doDefault($lang['strtableemptiedbad']);
|
457 |
|
|
}
|
458 |
|
|
|
459 |
|
|
}
|
460 |
|
|
|
461 |
|
|
/**
|
462 |
|
|
* Show confirmation of drop and perform actual drop
|
463 |
|
|
*/
|
464 |
|
|
function doDrop($confirm) {
|
465 |
|
|
global $data, $misc;
|
466 |
|
|
global $lang, $_reload_browser;
|
467 |
|
|
global $PHP_SELF;
|
468 |
|
|
|
469 |
|
|
if ($confirm) {
|
470 |
|
|
$misc->printTrail('table');
|
471 |
|
|
$misc->printTitle($lang['strdrop'], 'pg.table.drop');
|
472 |
|
|
|
473 |
|
|
echo "<p>", sprintf($lang['strconfdroptable'], $misc->printVal($_REQUEST['table'])), "</p>\n";
|
474 |
|
|
|
475 |
|
|
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
|
476 |
|
|
echo "<input type=\"hidden\" name=\"action\" value=\"drop\" />\n";
|
477 |
|
|
echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
|
478 |
|
|
echo $misc->form;
|
479 |
|
|
// Show cascade drop option if supportd
|
480 |
|
|
if ($data->hasDropBehavior()) {
|
481 |
|
|
echo "<p><input type=\"checkbox\" name=\"cascade\" /> {$lang['strcascade']}</p>\n";
|
482 |
|
|
}
|
483 |
|
|
echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
|
484 |
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
|
485 |
|
|
echo "</form>\n";
|
486 |
|
|
}
|
487 |
|
|
else {
|
488 |
|
|
$status = $data->dropTable($_POST['table'], isset($_POST['cascade']));
|
489 |
|
|
if ($status == 0) {
|
490 |
|
|
$_reload_browser = true;
|
491 |
|
|
doDefault($lang['strtabledropped']);
|
492 |
|
|
}
|
493 |
|
|
else
|
494 |
|
|
doDefault($lang['strtabledroppedbad']);
|
495 |
|
|
}
|
496 |
|
|
|
497 |
|
|
}
|
498 |
|
|
|
499 |
|
|
|
500 |
|
|
/**
|
501 |
|
|
* Show confirmation of vacuum and perform actual vacuum
|
502 |
|
|
*/
|
503 |
|
|
function doVacuum($confirm) {
|
504 |
|
|
global $data, $misc;
|
505 |
|
|
global $lang, $_reload_browser;
|
506 |
|
|
global $PHP_SELF;
|
507 |
|
|
|
508 |
|
|
if ($confirm) {
|
509 |
|
|
$misc->printTrail('table');
|
510 |
|
|
$misc->printTitle($lang['strvacuum'], 'pg.vacuum');
|
511 |
|
|
|
512 |
|
|
echo "<p>", sprintf($lang['strconfvacuumtable'], $misc->printVal($_REQUEST['table'])), "</p>\n";
|
513 |
|
|
|
514 |
|
|
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
|
515 |
|
|
echo "<input type=\"hidden\" name=\"action\" value=\"vacuum\" />\n";
|
516 |
|
|
echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
|
517 |
|
|
echo $misc->form;
|
518 |
|
|
// Show vacuum full option if supportd
|
519 |
|
|
if ($data->hasFullVacuum()) {
|
520 |
|
|
echo "<p><input type=\"checkbox\" name=\"vacuum_full\" /> {$lang['strfull']}</p>\n";
|
521 |
|
|
echo "<p><input type=\"checkbox\" name=\"vacuum_analyze\" /> {$lang['stranalyze']}</p>\n";
|
522 |
|
|
}
|
523 |
|
|
echo "<input type=\"submit\" name=\"vacuum\" value=\"{$lang['strvacuum']}\" />\n";
|
524 |
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
|
525 |
|
|
echo "</form>\n";
|
526 |
|
|
}
|
527 |
|
|
else {
|
528 |
|
|
$status = $data->vacuumDB($_POST['table'], isset($_REQUEST['vacuum_analyze']), isset($_REQUEST['vacuum_full']), '');
|
529 |
|
|
if ($status == 0) {
|
530 |
|
|
$_reload_browser = true;
|
531 |
|
|
doDefault($lang['strvacuumgood']);
|
532 |
|
|
}
|
533 |
|
|
else
|
534 |
|
|
doDefault($lang['strvacuumbad']);
|
535 |
|
|
}
|
536 |
|
|
|
537 |
|
|
}
|
538 |
|
|
|
539 |
|
|
/**
|
540 |
|
|
* Show default list of tables in the database
|
541 |
|
|
*/
|
542 |
|
|
function doDefault($msg = '') {
|
543 |
|
|
global $data, $conf, $misc, $data;
|
544 |
|
|
global $PHP_SELF, $lang;
|
545 |
|
|
|
546 |
|
|
$misc->printTrail('schema');
|
547 |
|
|
$misc->printTabs('schema','tables');
|
548 |
|
|
$misc->printMsg($msg);
|
549 |
|
|
|
550 |
|
|
$tables = $data->getTables();
|
551 |
|
|
|
552 |
|
|
$columns = array(
|
553 |
|
|
'table' => array(
|
554 |
|
|
'title' => $lang['strtable'],
|
555 |
|
|
'field' => 'relname',
|
556 |
|
|
),
|
557 |
|
|
'owner' => array(
|
558 |
|
|
'title' => $lang['strowner'],
|
559 |
|
|
'field' => 'relowner',
|
560 |
|
|
),
|
561 |
|
|
'tablespace' => array(
|
562 |
|
|
'title' => $lang['strtablespace'],
|
563 |
|
|
'field' => 'tablespace'
|
564 |
|
|
),
|
565 |
|
|
'tuples' => array(
|
566 |
|
|
'title' => $lang['strestimatedrowcount'],
|
567 |
|
|
'field' => 'reltuples',
|
568 |
|
|
'type' => 'numeric'
|
569 |
|
|
),
|
570 |
|
|
'actions' => array(
|
571 |
|
|
'title' => $lang['stractions'],
|
572 |
|
|
),
|
573 |
|
|
'comment' => array(
|
574 |
|
|
'title' => $lang['strcomment'],
|
575 |
|
|
'field' => 'relcomment',
|
576 |
|
|
),
|
577 |
|
|
);
|
578 |
|
|
|
579 |
|
|
$actions = array(
|
580 |
|
|
'properties' => array(
|
581 |
|
|
'title' => $lang['strproperties'],
|
582 |
|
|
'url' => "redirect.php?subject=table&{$misc->href}&",
|
583 |
|
|
'vars' => array('table' => 'relname'),
|
584 |
|
|
),
|
585 |
|
|
'browse' => array(
|
586 |
|
|
'title' => $lang['strbrowse'],
|
587 |
|
|
'url' => "display.php?{$misc->href}&subject=table&return_url=".urlencode("tables.php?{$misc->href}")."&return_desc=".urlencode($lang['strback'])."&",
|
588 |
|
|
'vars' => array('table' => 'relname'),
|
589 |
|
|
),
|
590 |
|
|
'select' => array(
|
591 |
|
|
'title' => $lang['strselect'],
|
592 |
|
|
'url' => "{$PHP_SELF}?action=confselectrows&{$misc->href}&",
|
593 |
|
|
'vars' => array('table' => 'relname'),
|
594 |
|
|
),
|
595 |
|
|
'insert' => array(
|
596 |
|
|
'title' => $lang['strinsert'],
|
597 |
|
|
'url' => "{$PHP_SELF}?action=confinsertrow&{$misc->href}&",
|
598 |
|
|
'vars' => array('table' => 'relname'),
|
599 |
|
|
),
|
600 |
|
|
'empty' => array(
|
601 |
|
|
'title' => $lang['strempty'],
|
602 |
|
|
'url' => "{$PHP_SELF}?action=confirm_empty&{$misc->href}&",
|
603 |
|
|
'vars' => array('table' => 'relname'),
|
604 |
|
|
),
|
605 |
|
|
'drop' => array(
|
606 |
|
|
'title' => $lang['strdrop'],
|
607 |
|
|
'url' => "{$PHP_SELF}?action=confirm_drop&{$misc->href}&",
|
608 |
|
|
'vars' => array('table' => 'relname'),
|
609 |
|
|
),
|
610 |
|
|
'vacuum' => array(
|
611 |
|
|
'title' => $lang['strvacuum'],
|
612 |
|
|
'url' => "{$PHP_SELF}?action=confirm_vacuum&{$misc->href}&",
|
613 |
|
|
'vars' => array('table' => 'relname'),
|
614 |
|
|
),
|
615 |
|
|
);
|
616 |
|
|
|
617 |
|
|
if (!$data->hasTablespaces()) unset($columns['tablespace']);
|
618 |
|
|
|
619 |
|
|
$misc->printTable($tables, $columns, $actions, $lang['strnotables']);
|
620 |
|
|
|
621 |
|
|
echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create&{$misc->href}\">{$lang['strcreatetable']}</a></p>\n";
|
622 |
|
|
}
|
623 |
|
|
|
624 |
|
|
/**
|
625 |
|
|
* Generate XML for the browser tree.
|
626 |
|
|
*/
|
627 |
|
|
function doTree() {
|
628 |
|
|
global $misc, $data;
|
629 |
|
|
|
630 |
|
|
$tables = $data->getTables();
|
631 |
|
|
|
632 |
|
|
$reqvars = $misc->getRequestVars('table');
|
633 |
|
|
|
634 |
|
|
$attrs = array(
|
635 |
|
|
'text' => field('relname'),
|
636 |
|
|
'icon' => 'tables',
|
637 |
|
|
'toolTip'=> field('relcomment'),
|
638 |
|
|
'action' => url('redirect.php',
|
639 |
|
|
$reqvars,
|
640 |
|
|
array('table' => field('relname'))
|
641 |
|
|
)
|
642 |
|
|
);
|
643 |
|
|
|
644 |
|
|
$misc->printTreeXML($tables, $attrs);
|
645 |
|
|
exit;
|
646 |
|
|
}
|
647 |
|
|
|
648 |
|
|
if ($action == 'tree') doTree();
|
649 |
|
|
|
650 |
|
|
$misc->printHeader($lang['strtables']);
|
651 |
|
|
$misc->printBody();
|
652 |
|
|
|
653 |
|
|
switch ($action) {
|
654 |
|
|
case 'create':
|
655 |
|
|
if (isset($_POST['cancel'])) doDefault();
|
656 |
|
|
else doCreate();
|
657 |
|
|
break;
|
658 |
|
|
case 'selectrows':
|
659 |
|
|
if (!isset($_POST['cancel'])) doSelectRows(false);
|
660 |
|
|
else doDefault();
|
661 |
|
|
break;
|
662 |
|
|
case 'confselectrows':
|
663 |
|
|
doSelectRows(true);
|
664 |
|
|
break;
|
665 |
|
|
case 'insertrow':
|
666 |
|
|
if (!isset($_POST['cancel'])) doInsertRow(false);
|
667 |
|
|
else doDefault();
|
668 |
|
|
break;
|
669 |
|
|
case 'confinsertrow':
|
670 |
|
|
doInsertRow(true);
|
671 |
|
|
break;
|
672 |
|
|
case 'empty':
|
673 |
|
|
if (isset($_POST['empty'])) doEmpty(false);
|
674 |
|
|
else doDefault();
|
675 |
|
|
break;
|
676 |
|
|
case 'confirm_empty':
|
677 |
|
|
doEmpty(true);
|
678 |
|
|
break;
|
679 |
|
|
case 'drop':
|
680 |
|
|
if (isset($_POST['drop'])) doDrop(false);
|
681 |
|
|
else doDefault();
|
682 |
|
|
break;
|
683 |
|
|
case 'confirm_drop':
|
684 |
|
|
doDrop(true);
|
685 |
|
|
break;
|
686 |
|
|
case 'vacuum':
|
687 |
|
|
if (isset($_POST['vacuum'])) doVacuum(false);
|
688 |
|
|
else doDefault();
|
689 |
|
|
break;
|
690 |
|
|
case 'confirm_vacuum':
|
691 |
|
|
doVacuum(true);
|
692 |
|
|
break;
|
693 |
|
|
default:
|
694 |
|
|
doDefault();
|
695 |
|
|
break;
|
696 |
|
|
}
|
697 |
|
|
|
698 |
|
|
$misc->printFooter();
|
699 |
|
|
|
700 |
|
|
?>
|