Projekt

Obecné

Profil

Stáhnout (24.9 KB) Statistiky
| Větev: | Tag: | Revize:
1 6daefa8c Petr Lukašík
<?php
2
3
	/**
4
	 * List tables in a database
5
	 *
6
	 * $Id: tblproperties.php,v 1.67 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
	 * Function to save after altering a table
17
	 */
18
	function doSaveAlter() {
19
		global $data, $lang, $_reload_browser;
20
21
		// For databases that don't allow owner change
22
		if (!isset($_POST['owner'])) $_POST['owner'] = '';
23
		// Default tablespace to null if it isn't set
24
		if (!isset($_POST['tablespace'])) $_POST['tablespace'] = null;
25
		
26
		$status = $data->alterTable($_POST['table'], $_POST['name'], $_POST['owner'], $_POST['comment'], $_POST['tablespace']);
27
		if ($status == 0) {
28
			// If table has been renamed, need to change to the new name and
29
			// reload the browser frame.
30
			if ($_POST['table'] != $_POST['name']) {
31
				// Jump them to the new table name
32
				$_REQUEST['table'] = $_POST['name'];
33
				// Force a browser reload
34
				$_reload_browser = true;
35
			}
36
			doDefault($lang['strtablealtered']);
37
		}
38
		else
39
			doAlter($lang['strtablealteredbad']);
40
	}
41
42
	/**
43
	 * Function to allow altering of a table
44
	 */
45
	function doAlter($msg = '') {
46
		global $data, $misc;
47
		global $PHP_SELF, $lang;
48
		
49
		$misc->printTrail('table');
50
		$misc->printTitle($lang['stralter'], 'pg.table.alter');
51
		$misc->printMsg($msg);
52
53
		// Fetch table info		
54
		$table = $data->getTable($_REQUEST['table']);
55
		// Fetch all users
56
		$users = $data->getUsers();
57
		// Fetch all tablespaces from the database
58
		if ($data->hasTablespaces()) $tablespaces = $data->getTablespaces(true);
59
		
60
		if ($table->recordCount() > 0) {
61
			
62
			if (!isset($_POST['name'])) $_POST['name'] = $table->f['relname'];
63
			if (!isset($_POST['owner'])) $_POST['owner'] = $table->f['relowner'];
64
			if (!isset($_POST['comment'])) $_POST['comment'] = $table->f['relcomment'];
65
			if ($data->hasTablespaces() && !isset($_POST['tablespace'])) $_POST['tablespace'] = $table->f['tablespace'];
66
			
67
			echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
68
			echo "<table>\n";
69
			echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n";
70
			echo "<td class=\"data1\">";
71
			echo "<input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", 
72
				htmlspecialchars($_POST['name']), "\" /></td></tr>\n";
73
			
74
			$server_info = $misc->getServerInfo();
75
			if ($data->hasAlterTableOwner() && $data->isSuperUser($server_info['username'])) {
76
				echo "<tr><th class=\"data left required\">{$lang['strowner']}</th>\n";
77
				echo "<td class=\"data1\"><select name=\"owner\">";
78
				while (!$users->EOF) {
79
					$uname = $users->f['usename'];
80
					echo "<option value=\"", htmlspecialchars($uname), "\"",
81
						($uname == $_POST['owner']) ? ' selected="selected"' : '', ">", htmlspecialchars($uname), "</option>\n";
82
					$users->moveNext();
83
				}
84
				echo "</select></td></tr>\n";				
85
			}
86
87
			// Tablespace (if there are any)
88
			if ($data->hasTablespaces() && $tablespaces->recordCount() > 0) {
89
				echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strtablespace']}</th>\n";
90
				echo "\t\t<td class=\"data1\">\n\t\t\t<select name=\"tablespace\">\n";
91
				// Always offer the default (empty) option
92
				echo "\t\t\t\t<option value=\"\"",
93
					($_POST['tablespace'] == '') ? ' selected="selected"' : '', "></option>\n";
94
				// Display all other tablespaces
95
				while (!$tablespaces->EOF) {
96
					$spcname = htmlspecialchars($tablespaces->f['spcname']);
97
					echo "\t\t\t\t<option value=\"{$spcname}\"",
98
						($spcname == $_POST['tablespace']) ? ' selected="selected"' : '', ">{$spcname}</option>\n";
99
					$tablespaces->moveNext();
100
				}
101
				echo "\t\t\t</select>\n\t\t</td>\n\t</tr>\n";
102
			}
103
			
104
			echo "<tr><th class=\"data left\">{$lang['strcomment']}</th>\n";
105
			echo "<td class=\"data1\">";
106
			echo "<textarea rows=\"3\" cols=\"32\" name=\"comment\" wrap=\"virtual\">",
107
				htmlspecialchars($_POST['comment']), "</textarea></td></tr>\n";
108
			echo "</table>\n";
109
			echo "<p><input type=\"hidden\" name=\"action\" value=\"alter\" />\n";
110
			echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
111
			echo $misc->form;
112
			echo "<input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n";
113
			echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
114
			echo "</form>\n";
115
		}
116
		else echo "<p>{$lang['strnodata']}</p>\n";
117
	}
118
	
119
	function doExport($msg = '') {
120
		global $data, $misc;
121
		global $PHP_SELF, $lang;
122
123
		// Determine whether or not the table has an object ID
124
		$hasID = $data->hasObjectID($_REQUEST['table']);
125
		
126
		$misc->printTrail('table');
127
		$misc->printTabs('table','export');
128
		$misc->printMsg($msg);
129
130
		echo "<form action=\"dataexport.php\" method=\"post\">\n";
131
		echo "<table>\n";
132
		echo "<tr><th class=\"data\">{$lang['strformat']}</th><th class=\"data\" colspan=\"2\">{$lang['stroptions']}</th></tr>\n";
133
		// Data only
134
		echo "<tr><th class=\"data left\" rowspan=\"", ($hasID) ? 2 : 1, "\">";
135
		echo "<input type=\"radio\" name=\"what\" value=\"dataonly\" checked=\"checked\" />{$lang['strdataonly']}</th>\n";
136
		echo "<td>{$lang['strformat']}</td>\n";
137
		echo "<td><select name=\"d_format\">\n";
138
		echo "<option value=\"copy\">COPY</option>\n";
139
		echo "<option value=\"sql\">SQL</option>\n";
140
		echo "<option value=\"csv\">CSV</option>\n";
141
		echo "<option value=\"tab\">{$lang['strtabbed']}</option>\n";
142
		echo "<option value=\"html\">XHTML</option>\n";
143
		echo "<option value=\"xml\">XML</option>\n";
144
		echo "</select>\n</td>\n</tr>\n";
145
		if ($hasID) {
146
			echo "<tr><td>{$lang['stroids']}</td><td><input type=\"checkbox\" name=\"d_oids\" /></td>\n</tr>\n";
147
		}
148
		// Structure only
149
		echo "<tr><th class=\"data left\"><input type=\"radio\" name=\"what\" value=\"structureonly\" />{$lang['strstructureonly']}</th>\n";
150
		echo "<td>{$lang['strdrop']}</td><td><input type=\"checkbox\" name=\"s_clean\" /></td>\n</tr>\n";
151
		// Structure and data
152
		echo "<tr><th class=\"data left\" rowspan=\"", ($hasID) ? 3 : 2, "\">";
153
		echo "<input type=\"radio\" name=\"what\" value=\"structureanddata\" />{$lang['strstructureanddata']}</th>\n";
154
		echo "<td>{$lang['strformat']}</td>\n";
155
		echo "<td><select name=\"sd_format\">\n";
156
		echo "<option value=\"copy\">COPY</option>\n";
157
		echo "<option value=\"sql\">SQL</option>\n";
158
		echo "</select>\n</td>\n</tr>\n";
159
		echo "<tr><td>{$lang['strdrop']}</td><td><input type=\"checkbox\" name=\"sd_clean\" /></td>\n</tr>\n";
160
		if ($hasID) {
161
			echo "<tr><td>{$lang['stroids']}</td><td><input type=\"checkbox\" name=\"sd_oids\" /></td>\n</tr>\n";
162
		}
163
		echo "</table>\n";
164
		
165
		echo "<h3>{$lang['stroptions']}</h3>\n";
166
		echo "<p><input type=\"radio\" name=\"output\" value=\"show\" checked=\"checked\" />{$lang['strshow']}\n";
167
		echo "<br/><input type=\"radio\" name=\"output\" value=\"download\" />{$lang['strdownload']}</p>\n";
168
169
		echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n";
170
		echo $misc->form;
171
		echo "<input type=\"hidden\" name=\"subject\" value=\"table\" />\n";
172
		echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
173
		echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n";
174
		echo "</form>\n";
175
	}
176
	
177
	function doImport($msg = '') {
178
		global $data, $misc;
179
		global $PHP_SELF, $lang;
180
181
		$misc->printTrail('table');
182
		$misc->printTabs('table','import');
183
		$misc->printMsg($msg);
184
185
		// Check that file uploads are enabled
186
		if (ini_get('file_uploads')) {
187
			// Don't show upload option if max size of uploads is zero
188
			$max_size = $misc->inisizeToBytes(ini_get('upload_max_filesize'));
189
			if (is_double($max_size) && $max_size > 0) {
190
				echo "<form action=\"dataimport.php\" method=\"post\" enctype=\"multipart/form-data\">\n";
191
				echo "<table>\n";
192
				echo "<tr><th class=\"data left required\">{$lang['strformat']}</th>";
193
				echo "<td><select name=\"format\">\n";
194
				echo "<option value=\"auto\">{$lang['strauto']}</option>\n";
195
				echo "<option value=\"csv\">CSV</option>\n";
196
				echo "<option value=\"tab\">{$lang['strtabbed']}</option>\n";
197
				if (function_exists('xml_parser_create')) {
198
					echo "<option value=\"xml\">XML</option>\n";
199
				}
200
				echo "</select>\n</td>\n</tr>\n";
201
				echo "<tr><th class=\"data left required\">{$lang['strallowednulls']}</th>";
202
				echo "<td><select multiple size=\"3\" name=\"allowednulls[]\">\n";
203
				echo "<option value=\"default\" selected=\"selected\">{$lang['strbackslashn']}</option>\n";
204
				echo "<option value=\"null\">{$lang['strnull']}</option>\n";
205
				echo "<option value=\"emptystring\">{$lang['stremptystring'] }</option>\n";
206
				echo "</select>\n</td>\n</tr>\n";
207
				echo "<tr><th class=\"data left required\">{$lang['strfile']}</th>";
208
				echo "<td><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"{$max_size}\" />\n";
209
				echo "<input type=\"file\" name=\"source\" />\n";
210
				echo "</table>\n";
211
				echo "<p><input type=\"hidden\" name=\"action\" value=\"import\" />\n";
212
				echo $misc->form;
213
				echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
214
				echo "<input type=\"submit\" value=\"{$lang['strimport']}\" /></p>\n";
215
				echo "</form>\n";
216
			}
217
		}
218
		else echo "<p>{$lang['strnouploads']}</p>\n";		
219
	}	
220
221
	/**
222
	 * Displays a screen where they can add a column
223
	 */
224
	function doAddColumn($msg = '') {
225
		global $data, $misc;
226
		global $PHP_SELF, $lang;
227
228
		if (!isset($_REQUEST['stage'])) $_REQUEST['stage'] = 1;
229
230
		switch ($_REQUEST['stage']) {
231
			case 1:
232
				global $lang;
233
234
				// Set variable defaults
235
				if (!isset($_POST['field'])) $_POST['field'] = '';
236
				if (!isset($_POST['type'])) $_POST['type'] = '';
237
				if (!isset($_POST['array'])) $_POST['array'] = '';
238
				if (!isset($_POST['length'])) $_POST['length'] = '';
239
				if (!isset($_POST['default'])) $_POST['default'] = '';
240
				if (!isset($_POST['comment'])) $_POST['comment'] = '';
241
242
				// Fetch all available types
243
				$types = $data->getTypes(true, false, true);
244
245
				$misc->printTrail('table');
246
				$misc->printTitle($lang['straddcolumn'], 'pg.column.add');
247
				$misc->printMsg($msg);
248
249
				echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
250
251
				// Output table header
252
				echo "<table>\n<tr>";
253
				echo "<tr><th class=\"data required\">{$lang['strcolumn']}</th><th colspan=\"2\" class=\"data required\">{$lang['strtype']}</th>";
254
				echo "<th class=\"data\">{$lang['strlength']}</th>";
255
				if ($data->hasAlterColumnType()) echo "<th class=\"data\">{$lang['strnotnull']}</th><th class=\"data\">{$lang['strdefault']}</th>";
256
				echo "<th class=\"data\">{$lang['strcomment']}</th></tr>";
257
258
				echo "<tr><td><input name=\"field\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"",
259
					htmlspecialchars($_POST['field']), "\" /></td>";
260
				echo "<td><select name=\"type\">\n";				
261
				// Output any "magic" types.  This came in with the alter column type so we'll check that
262
				if ($data->hasAlterColumnType()) {
263
					foreach ($data->extraTypes as $v) {
264
						echo "<option value=\"", htmlspecialchars($v), "\"",
265
						($v == $_POST['type']) ? ' selected="selected"' : '', ">",
266
							$misc->printVal($v), "</option>\n";
267
					}
268
				}
269
				while (!$types->EOF) {
270
					$typname = $types->f['typname'];
271
					echo "<option value=\"", htmlspecialchars($typname), "\"", ($typname == $_POST['type']) ? ' selected="selected"' : '', ">",
272
						$misc->printVal($typname), "</option>\n";
273
					$types->moveNext();
274
				}
275
				echo "</select></td>";
276
				
277
				// Output array type selector
278
				echo "<td><select name=\"array\">\n";
279
				echo "<option value=\"\"", ($_POST['array'] == '') ? ' selected="selected"' : '', "></option>\n";
280
				echo "<option value=\"[]\"", ($_POST['array'] == '[]') ? ' selected="selected"' : '', ">[ ]</option>\n";
281
				echo "</select></td>\n";
282
283
				echo "<td><input name=\"length\" size=\"8\" value=\"",
284
					htmlspecialchars($_POST['length']), "\" /></td>";
285
				// Support for adding column with not null and default
286
				if ($data->hasAlterColumnType()) {					
287
					echo "<td><input type=\"checkbox\" name=\"notnull\"", 
288
						(isset($_REQUEST['notnull'])) ? ' checked="checked"' : '', " /></td>\n";
289
					echo "<td><input name=\"default\" size=\"20\" value=\"",
290
						htmlspecialchars($_POST['default']), "\" /></td>";
291
				}
292
				else {
293
					echo "<input type=\"hidden\" name=\"default\" value=\"\" />\n";	
294
				}
295
				echo "<td><input name=\"comment\" size=\"40\" value=\"",
296
					htmlspecialchars($_POST['comment']), "\" /></td></tr>";
297
				echo "</table>\n";
298
				echo "<input type=\"hidden\" name=\"action\" value=\"add_column\" />\n";
299
				echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n";
300
				echo $misc->form;
301
				echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\">\n";
302
				echo "<p><input type=\"submit\" value=\"{$lang['stradd']}\" />\n";
303
				echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
304
				echo "</form>\n";
305
306
				break;
307
			case 2:
308
				global $data, $lang;
309
310
				// Check inputs
311
				if (trim($_POST['field']) == '') {
312
					$_REQUEST['stage'] = 1;
313
					doAddColumn($lang['strcolneedsname']);
314
					return;
315
				}
316
317
				$status = $data->addColumn($_POST['table'], $_POST['field'],
318
							   $_POST['type'], $_POST['array'] != '', $_POST['length'], isset($_POST['notnull']),
319
							   $_POST['default'], $_POST['comment']);
320
				if ($status == 0)
321
					doDefault($lang['strcolumnadded']);
322
				else {
323
					$_REQUEST['stage'] = 1;
324
					doAddColumn($lang['strcolumnaddedbad']);
325
					return;
326
				}
327
				break;
328
			default:
329
				echo "<p>{$lang['strinvalidparam']}</p>\n";
330
		}
331
	}
332
333
	/**
334
	 * Displays a screen where they can alter a column
335
	 */
336
	function doProperties($msg = '') {
337
		global $data, $misc;
338
		global $PHP_SELF, $lang;
339
340
		if (!isset($_REQUEST['stage'])) $_REQUEST['stage'] = 1;
341
342
		switch ($_REQUEST['stage']) {
343
			case 1:
344
				global $lang;
345
346
				$misc->printTrail('column');
347
				$misc->printTitle($lang['straltercolumn'], 'pg.column.alter'); 
348
				$misc->printMsg($msg);
349
350
				echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
351
352
				// Output table header
353
				echo "<table>\n<tr>";
354
				echo "<tr><th class=\"data required\">{$lang['strname']}</th>";
355
				if ($data->hasAlterColumnType()) {
356
					echo "<th class=\"data required\" colspan=\"2\">{$lang['strtype']}</th>";
357
					echo "<th class=\"data\">{$lang['strlength']}</th>";
358
				}
359
				else {
360
					echo "<th class=\"data required\">{$lang['strtype']}</th>";					
361
				}
362
				echo "<th class=\"data\">{$lang['strnotnull']}</th><th class=\"data\">{$lang['strdefault']}</th><th class=\"data\">{$lang['strcomment']}</th></tr>";
363
364
				$column = $data->getTableAttributes($_REQUEST['table'], $_REQUEST['column']);
365
				$column->f['attnotnull'] = $data->phpBool($column->f['attnotnull']);
366
367
				// Upon first drawing the screen, load the existing column information
368
				// from the database.
369
				if (!isset($_REQUEST['default'])) {
370
					$_REQUEST['field'] = $column->f['attname'];
371
					$_REQUEST['type'] = $column->f['base_type'];
372
					// Check to see if its' an array type...
373
					// XXX: HACKY
374
					if (substr($column->f['base_type'], strlen($column->f['base_type']) - 2) == '[]') {
375
						$_REQUEST['type'] = substr($column->f['base_type'], 0, strlen($column->f['base_type']) - 2);
376
						$_REQUEST['array'] = '[]';
377
					}
378
					else {
379
						$_REQUEST['type'] = $column->f['base_type'];
380
						$_REQUEST['array'] = '';
381
					}
382
					// To figure out the length, look in the brackets :(
383
					// XXX: HACKY
384
					if ($column->f['type'] != $column->f['base_type'] && ereg('\\(([0-9, ]*)\\)', $column->f['type'], $bits)) {
385
						$_REQUEST['length'] = $bits[1];
386
					}
387
					else
388
						$_REQUEST['length'] = '';
389
					$_REQUEST['default'] = $_REQUEST['olddefault'] = $column->f['adsrc'];
390
					if ($column->f['attnotnull']) $_REQUEST['notnull'] = 'YES';
391
					$_REQUEST['comment'] = $column->f['comment'];
392
				}				
393
394
				// Column name
395
				echo "<tr><td><input name=\"field\" size=\"32\" value=\"",
396
					htmlspecialchars($_REQUEST['field']), "\" /></td>";
397
					
398
				// Column type
399
				if ($data->hasAlterColumnType()) {
400
					// Fetch all available types
401
					$types = $data->getTypes(true, false, true);
402
					
403
					echo "<td><select name=\"type\">\n";				
404
					// Output any "magic" types.  This came in with Alter Column Type so we don't need to check that
405
					foreach ($data->extraTypes as $v) {
406
						echo "<option value=\"", htmlspecialchars($v), "\"",
407
						($v == $_REQUEST['type']) ? ' selected="selected"' : '', ">",
408
							$misc->printVal($v), "</option>\n";
409
					}
410
					while (!$types->EOF) {
411
						$typname = $types->f['typname'];
412
						echo "<option value=\"", htmlspecialchars($typname), "\"", ($typname == $_REQUEST['type']) ? ' selected="selected"' : '', ">",
413
							$misc->printVal($typname), "</option>\n";
414
						$types->moveNext();
415
					}
416
					echo "</select></td>";
417
					
418
					// Output array type selector
419
					echo "<td><select name=\"array\">\n";
420
					echo "<option value=\"\"", ($_REQUEST['array'] == '') ? ' selected="selected"' : '', "></option>\n";
421
					echo "<option value=\"[]\"", ($_REQUEST['array'] == '[]') ? ' selected="selected"' : '', ">[ ]</option>\n";
422
					echo "</select></td>\n";
423
	
424
					echo "<td><input name=\"length\" size=\"8\" value=\"",
425
						htmlspecialchars($_REQUEST['length']), "\" /></td>";
426
				} else {
427
					// Otherwise draw the read-only type name
428
					echo "<td>", $misc->printVal($data->formatType($column->f['type'], $column->f['atttypmod'])), "</td>";
429
				}
430
				
431
				echo "<td><input type=\"checkbox\" name=\"notnull\"", (isset($_REQUEST['notnull'])) ? ' checked="checked"' : '', " /></td>\n";
432
				echo "<td><input name=\"default\" size=\"20\" value=\"", 
433
					htmlspecialchars($_REQUEST['default']), "\" /></td>";
434
				echo "<td><input name=\"comment\" size=\"20\" value=\"", 
435
					htmlspecialchars($_REQUEST['comment']), "\" /></td>";
436
				
437
				echo "</table>\n";
438
				echo "<p><input type=\"hidden\" name=\"action\" value=\"properties\" />\n";
439
				echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n";
440
				echo $misc->form;
441
				echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
442
				echo "<input type=\"hidden\" name=\"column\" value=\"", htmlspecialchars($_REQUEST['column']), "\" />\n";
443
				echo "<input type=\"hidden\" name=\"olddefault\" value=\"", htmlspecialchars($_REQUEST['olddefault']), "\" />\n";
444
				if ($column->f['attnotnull']) echo "<input type=\"hidden\" name=\"oldnotnull\" value=\"on\" />\n";
445
				echo "<input type=\"hidden\" name=\"oldtype\" value=\"", htmlspecialchars($data->formatType($column->f['type'], $column->f['atttypmod'])), "\" />\n";
446
				// Add hidden variables to suppress error notices if we don't support altering column type
447
				if (!$data->hasAlterColumnType()) {
448
					echo "<input type=\"hidden\" name=\"type\" value=\"", htmlspecialchars($_REQUEST['type']), "\" />\n";				
449
					echo "<input type=\"hidden\" name=\"length\" value=\"", htmlspecialchars($_REQUEST['length']), "\" />\n";				
450
					echo "<input type=\"hidden\" name=\"array\" value=\"", htmlspecialchars($_REQUEST['array']), "\" />\n";				
451
				}
452
				echo "<input type=\"submit\" value=\"{$lang['stralter']}\" />\n";
453
				echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
454
				echo "</form>\n";
455
								
456
				break;
457
			case 2:
458
				global $data, $lang;
459
460
				// Check inputs
461
				if (trim($_REQUEST['field']) == '') {
462
					$_REQUEST['stage'] = 1;
463
					doProperties($lang['strcolneedsname']);
464
					return;
465
				}
466
467
				$status = $data->alterColumn($_REQUEST['table'], $_REQUEST['column'], $_REQUEST['field'], 
468
							     isset($_REQUEST['notnull']), isset($_REQUEST['oldnotnull']), 
469
							     $_REQUEST['default'], $_REQUEST['olddefault'],
470
							     $_REQUEST['type'], $_REQUEST['length'], $_REQUEST['array'], $_REQUEST['oldtype'],
471
							     $_REQUEST['comment']);
472
				if ($status == 0)
473
					doDefault($lang['strcolumnaltered']);
474
				else {
475
					$_REQUEST['stage'] = 1;
476
					doProperties($lang['strcolumnalteredbad']);
477
					return;
478
				}
479
				break;
480
			default:
481
				echo "<p>{$lang['strinvalidparam']}</p>\n";
482
		}
483
	}
484
485
	/**
486
	 * Show confirmation of drop column and perform actual drop
487
	 */
488
	function doDrop($confirm) {
489
		global $data, $database, $misc;
490
		global $PHP_SELF, $lang;
491
492
		if ($confirm) {
493
			$misc->printTrail('column');
494
			$misc->printTitle($lang['strdrop'], 'pg.column.drop');
495
496
            echo "<p>", sprintf($lang['strconfdropcolumn'], $misc->printVal($_REQUEST['column']),
497
                    $misc->printVal($_REQUEST['table'])), "</p>\n";
498
								
499
500
			echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
501
			echo "<input type=\"hidden\" name=\"action\" value=\"drop\" />\n";
502
			echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
503
			echo "<input type=\"hidden\" name=\"column\" value=\"", htmlspecialchars($_REQUEST['column']), "\" />\n";
504
			echo $misc->form;
505
			// Show cascade drop option if supportd
506
			if ($data->hasDropBehavior()) {
507
				echo "<p><input type=\"checkbox\" name=\"cascade\"> {$lang['strcascade']}</p>\n";
508
			}
509
			echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
510
			echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
511
			echo "</form>\n";
512
		}
513
		else {
514
			$status = $data->dropColumn($_POST['table'], $_POST['column'], isset($_POST['cascade']));
515
			if ($status == 0)
516
				doDefault($lang['strcolumndropped']);
517
			else
518
				doDefault($lang['strcolumndroppedbad']);
519
		}
520
		
521
	}
522
523
	/**
524
	 * Show default list of columns in the table
525
	 */
526
	function doDefault($msg = '') {
527
		global $data, $conf, $misc;
528
		global $PHP_SELF, $lang;
529
530
		function attPre(&$rowdata) {
531
			global $data;
532
			$rowdata->f['+type'] = $data->formatType($rowdata->f['type'], $rowdata->f['atttypmod']);
533
		}
534
		
535
		$misc->printTrail('table');
536
		$misc->printTabs('table','columns');
537
		$misc->printMsg($msg);
538
539
		// Get table
540
		$tdata = $data->getTable($_REQUEST['table']);
541
		// Get columns
542
		$attrs = $data->getTableAttributes($_REQUEST['table']);		
543
544
		// Show comment if any
545
		if ($tdata->f['relcomment'] !== null)
546
			echo "<p class=\"comment\">", $misc->printVal($tdata->f['relcomment']), "</p>\n";
547
548
		$columns = array(
549
			'column' => array(
550
				'title' => $lang['strcolumn'],
551
				'field' => 'attname',
552
			),
553
			'type' => array(
554
				'title' => $lang['strtype'],
555
				'field' => '+type',
556
			),
557
			'notnull' => array(
558
				'title' => $lang['strnotnull'],
559
				'field' => 'attnotnull',
560
				'type'  => 'bool',
561
				'params'=> array('true' => 'NOT NULL', 'false' => ''),
562
			),
563
			'default' => array(
564
				'title' => $lang['strdefault'],
565
				'field' => 'adsrc',
566
			),
567
			'actions' => array(
568
				'title' => $lang['stractions'],
569
			),
570
			'comment' => array(
571
				'title' => $lang['strcomment'],
572
				'field' => 'comment',
573
			),
574
		);
575
		
576
		$actions = array(
577
			'alter' => array(
578
				'title' => $lang['stralter'],
579
				'url'   => "{$PHP_SELF}?action=properties&amp;{$misc->href}&amp;table=".urlencode($_REQUEST['table'])."&amp;",
580
				'vars'  => array('column' => 'attname'),
581
			),
582
			'drop' => array(
583
				'title' => $lang['strdrop'],
584
				'url'   => "{$PHP_SELF}?action=confirm_drop&amp;{$misc->href}&amp;table=".urlencode($_REQUEST['table'])."&amp;",
585
				'vars'  => array('column' => 'attname'),
586
			),
587
		);
588
		
589
		if (!$data->hasDropColumn()) unset($actions['drop']);
590
		
591
		$misc->printTable($attrs, $columns, $actions, null, 'attPre');
592
		
593
		echo "<br />\n";
594
595
		echo "<ul>\n";
596
		$return_url = urlencode("tblproperties.php?{$misc->href}&table={$_REQUEST['table']}");
597
		echo "\t<li><a href=\"display.php?{$misc->href}&amp;table=", urlencode($_REQUEST['table']), "&amp;subject=table&amp;return_url={$return_url}&amp;return_desc=",
598
			urlencode($lang['strback']), "\">{$lang['strbrowse']}</a></li>\n";
599
		echo "\t<li><a href=\"tables.php?action=confselectrows&amp;{$misc->href}&amp;table=", urlencode($_REQUEST['table']),"\">{$lang['strselect']}</a></li>\n";
600
		echo "\t<li><a href=\"tables.php?action=confinsertrow&amp;{$misc->href}&amp;table=", urlencode($_REQUEST['table']),"\">{$lang['strinsert']}</a></li>\n";
601
		echo "\t<li><a href=\"tables.php?action=confirm_empty&amp;{$misc->href}&amp;table=", urlencode($_REQUEST['table']),"\">{$lang['strempty']}</a></li>\n";
602
		echo "\t<li><a href=\"tables.php?action=confirm_drop&amp;{$misc->href}&amp;table=", urlencode($_REQUEST['table']),"\">{$lang['strdrop']}</a></li>\n";
603
		echo "\t<li><a href=\"{$PHP_SELF}?action=add_column&amp;{$misc->href}&amp;table=", urlencode($_REQUEST['table']),"\">{$lang['straddcolumn']}</a></li>\n";
604
		echo "\t<li><a href=\"{$PHP_SELF}?action=confirm_alter&amp;{$misc->href}&amp;table=", urlencode($_REQUEST['table']),"\">{$lang['stralter']}</a></li>\n";
605
		echo "</ul>\n";
606
	}
607
608
	$misc->printHeader($lang['strtables'] . ' - ' . $_REQUEST['table']);
609
	$misc->printBody();
610
611
	switch ($action) {
612
		case 'alter':
613
			if (isset($_POST['alter'])) doSaveAlter();
614
			else doDefault();
615
			break;
616
		case 'confirm_alter':
617
			doAlter();
618
			break;
619
		case 'import':
620
			doImport();
621
			break;
622
		case 'export':
623
			doExport();
624
			break;
625
		case 'add_column':
626
			if (isset($_POST['cancel'])) doDefault();
627
			else doAddColumn();
628
			break;
629
		case 'properties':
630
			if (isset($_POST['cancel'])) doDefault();
631
			else doProperties();
632
			break;
633
		case 'drop':
634
			if (isset($_POST['drop'])) doDrop(false);
635
			else doDefault();
636
			break;
637
		case 'confirm_drop':
638
			doDrop(true);
639
			break;
640
		default:
641
			doDefault();
642
			break;
643
	}
644
	
645
	$misc->printFooter();
646
647
?>