Projekt

Obecné

Profil

Stáhnout (9.48 KB) Statistiky
| Větev: | Tag: | Revize:
1
<?php
2

    
3
	/**
4
	 * Manage schemas in a database
5
	 *
6
	 * $Id: schemas.php,v 1.4 2005/10/18 04:00:19 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
	 * Show default list of schemas in the database
18
	 */
19
	function doDefault($msg = '') {
20
		global $data, $misc, $conf;
21
		global $PHP_SELF, $lang;
22
		
23
		$misc->printTrail('database');
24
		$misc->printTabs('database','schemas');
25
		$misc->printMsg($msg);
26
		
27
		// Check that the DB actually supports schemas
28
		if ($data->hasSchemas()) {
29
			$schemas = $data->getSchemas();
30

    
31
			$columns = array(
32
				'schema' => array(
33
					'title' => $lang['strschema'],
34
					'field' => 'nspname',
35
				),
36
				'owner' => array(
37
					'title' => $lang['strowner'],
38
					'field' => 'nspowner',
39
				),
40
				'actions' => array(
41
					'title' => $lang['stractions'],
42
				),
43
				'comment' => array(
44
					'title' => $lang['strcomment'],
45
					'field' => 'nspcomment',
46
				),
47
			);
48
			
49
			$actions = array(
50
				'properties' => array(
51
					'title' => $lang['strproperties'],
52
					'url'   => "redirect.php?subject=schema&amp;{$misc->href}&amp;",
53
					'vars'  => array('schema' => 'nspname'),
54
				),
55
				'drop' => array(
56
					'title' => $lang['strdrop'],
57
					'url'   => "{$PHP_SELF}?action=drop&amp;{$misc->href}&amp;",
58
					'vars'  => array('schema' => 'nspname'),
59
				),
60
				'privileges' => array(
61
					'title' => $lang['strprivileges'],
62
					'url'   => "privileges.php?subject=schema&amp;{$misc->href}&amp;",
63
					'vars'  => array('schema' => 'nspname'),
64
				),
65
				'alter' => array(
66
					'title' => $lang['stralter'],
67
					'url'   => "{$PHP_SELF}?action=alter&amp;{$misc->href}&amp;",
68
					'vars'  => array('schema' => 'nspname'),
69
				),
70
			);
71
			
72
			$misc->printTable($schemas, $columns, $actions, $lang['strnoschemas']);
73

    
74
			echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create&amp;{$misc->href}\">{$lang['strcreateschema']}</a></p>\n";
75
		} else {
76
			// If the database does not support schemas...
77
			echo "<p>{$lang['strnoschemas']}</p>\n";
78
		}
79
	}
80

    
81
	/**
82
	 * Displays a screen where they can enter a new schema
83
	 */
84
	function doCreate($msg = '') {
85
		global $data, $misc;
86
		global $PHP_SELF, $lang;
87

    
88
		$server_info = $misc->getServerInfo();
89
		
90
		if (!isset($_POST['formName'])) $_POST['formName'] = '';
91
		if (!isset($_POST['formAuth'])) $_POST['formAuth'] = $server_info['username'];
92
		if (!isset($_POST['formSpc'])) $_POST['formSpc'] = '';
93
		if (!isset($_POST['formComment'])) $_POST['formComment'] = '';
94

    
95
		// Fetch all users from the database
96
		$users = $data->getUsers();
97

    
98
		$misc->printTrail('database');
99
		$misc->printTitle($lang['strcreateschema'],'pg.schema.create');
100
		$misc->printMsg($msg);
101
		
102
		echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
103
		echo $misc->form;
104
		echo "<table width=\"100%\">\n";
105
		echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n";
106
		echo "\t\t<td class=\"data1\"><input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
107
			htmlspecialchars($_POST['formName']), "\" /></td>\n\t</tr>\n";
108
		// Owner
109
		echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strowner']}</th>\n";
110
		echo "\t\t<td class=\"data1\">\n\t\t\t<select name=\"formAuth\">\n";
111
		while (!$users->EOF) {
112
			$uname = htmlspecialchars($users->f['usename']);
113
			echo "\t\t\t\t<option value=\"{$uname}\"",
114
				($uname == $_POST['formAuth']) ? ' selected="selected"' : '', ">{$uname}</option>\n";
115
			$users->moveNext();
116
		}
117
		echo "\t\t\t</select>\n\t\t</td>\n\t\n";		
118
		echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n";
119
		echo "\t\t<td class=\"data1\"><textarea name=\"formComment\" rows=\"3\" cols=\"32\" wrap=\"virtual\">", 
120
			htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n";
121
			
122
		echo "\t</tr>\n";
123
		echo "</table>\n";
124
		echo "<p>\n";
125
		echo "<input type=\"hidden\" name=\"action\" value=\"create\" />\n";
126
		echo "<input type=\"hidden\" name=\"database\" value=\"", htmlspecialchars($_REQUEST['database']), "\" />\n";
127
		echo "<input type=\"submit\" name=\"create\" value=\"{$lang['strcreate']}\" />\n";
128
		echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
129
		echo "</p>\n";
130
		echo "</form>\n";
131
	}
132

    
133
	/**
134
	 * Actually creates the new schema in the database
135
	 */
136
	function doSaveCreate() {
137
		global $data, $lang, $_reload_browser;
138

    
139
		// Check that they've given a name
140
		if ($_POST['formName'] == '') doCreate($lang['strschemaneedsname']);
141
		else {
142
			$status = $data->createSchema($_POST['formName'], $_POST['formAuth'], $_POST['formComment']);
143
			if ($status == 0) {
144
				$_reload_browser = true;
145
				doDefault($lang['strschemacreated']);
146
			}
147
			else
148
				doCreate($lang['strschemacreatedbad']);
149
		}
150
	}	
151
	
152
	/**
153
	 * Display a form to permit editing schema properies.
154
	 * TODO: permit changing name, owner
155
	 */
156
	function doAlter($msg = '') {
157
		global $data, $misc,$PHP_SELF, $lang;
158
		
159
		$misc->printTrail('schema');
160
		$misc->printTitle($lang['stralter'],'pg.schema.alter');
161
		$misc->printMsg($msg);
162

    
163
		$schema = $data->getSchemaByName($_REQUEST['schema']);
164
		if ($schema->recordCount() > 0) {
165
			if (!isset($_POST['comment'])) $_POST['comment'] = $schema->f['nspcomment'];
166
			if (!isset($_POST['schema'])) $_POST['schema'] = $_REQUEST['schema'];
167

    
168
			echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
169
			echo "<table>\n";
170
			echo "\t<tr>\n";
171
			echo "\t\t<th class=\"data\">{$lang['strcomment']}</th>\n";
172
			echo "\t\t<td class=\"data1\"><textarea cols=\"32\" rows=\"3\"name=\"comment\" wrap=\"virtual\">", htmlspecialchars($_POST['comment']), "</textarea></td>\n";
173
			echo "\t</tr>\n";
174
			echo "</table>\n";
175
			echo "<p><input type=\"hidden\" name=\"action\" value=\"alter\" />\n";
176
			echo "<input type=\"hidden\" name=\"schema\" value=\"", htmlspecialchars($_POST['schema']), "\" />\n";
177
			echo $misc->form;
178
			echo "<input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n";
179
			echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
180
			echo "</form>\n";
181
		} else {
182
			echo "<p>{$lang['strnodata']}</p>\n";
183
		}
184
	}
185

    
186
	/**
187
	 * Save the form submission containing changes to a schema
188
	 */
189
	function doSaveAlter($msg = '') {
190
		global $data, $misc,$PHP_SELF, $lang;
191
		
192
		$status = $data->updateSchema($_POST['schema'], $_POST['comment']);
193
		if ($status == 0)
194
			doDefault($lang['strschemaaltered']);
195
		else
196
			doAlter($lang['strschemaalteredbad']);
197
	}
198

    
199
	/**
200
	 * Show confirmation of drop and perform actual drop
201
	 */
202
	function doDrop($confirm) {
203
		global $PHP_SELF, $data, $data, $misc;
204
		global $lang, $_reload_browser;
205

    
206
		if ($confirm) {
207
			$misc->printTrail('schema');
208
			$misc->printTitle($lang['strdrop'],'pg.schema.drop');
209

    
210
			echo "<p>", sprintf($lang['strconfdropschema'], $misc->printVal($_REQUEST['schema'])), "</p>\n";
211

    
212
			echo "<form action=\"{$PHP_SELF}\" method=\"post\">\n";
213
			echo $misc->form;
214
			echo "<input type=\"hidden\" name=\"action\" value=\"drop\" />\n";
215
			echo "<input type=\"hidden\" name=\"database\" value=\"", htmlspecialchars($_REQUEST['database']), "\" />\n";
216
			echo "<input type=\"hidden\" name=\"schema\" value=\"", htmlspecialchars($_REQUEST['schema']), "\" />\n";
217
			// Show cascade drop option if supportd
218
			if ($data->hasDropBehavior()) {
219
				echo "<p><input type=\"checkbox\" name=\"cascade\" /> {$lang['strcascade']}</p>\n";
220
			}
221
			echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
222
			echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
223
			echo "</form>\n";
224
		}
225
		else {
226
			$status = $data->dropSchema($_POST['schema'], isset($_POST['cascade']));
227
			if ($status == 0) {
228
				$_reload_browser = true;
229
				doDefault($lang['strschemadropped']);
230
			}
231
			else
232
				doDefault($lang['strschemadroppedbad']);
233
		}
234
		
235
	}
236

    
237
	/**
238
	 * Generate XML for the browser tree.
239
	 */
240
	function doTree() {
241
		global $misc, $data, $lang, $PHP_SELF, $slony;
242
		
243
		$schemas = $data->getSchemas();
244
		
245
		$reqvars = $misc->getRequestVars('schema');
246
		
247
		$attrs = array(
248
			'text'   => field('nspname'),
249
			'icon'   => 'folder',
250
			'toolTip'=> field('nspcomment'),
251
			'action' => url('redirect.php',
252
							$reqvars,
253
							array(
254
								'subject' => 'schema',
255
								'schema'  => field('nspname')
256
							)
257
						),
258
			'branch' => url('schemas.php',
259
							$reqvars,
260
							array(
261
								'action'  => 'subtree',
262
								'schema'  => field('nspname')
263
							)
264
						),
265
		);
266
		
267
		$misc->printTreeXML($schemas, $attrs);
268
		
269
		exit;
270
	}
271
	
272
	function doSubTree() {
273
		global $misc, $data, $lang;
274
		
275
		$tabs = $misc->getNavTabs('schema');
276
		
277
		$items = $misc->adjustTabsForTree($tabs);
278
		
279
		$reqvars = $misc->getRequestVars('schema');
280
		
281
		$attrs = array(
282
			'text'   => noEscape(field('title')),
283
			'icon'   => field('icon', 'folder'),
284
			'action' => url(field('url'),
285
							$reqvars,
286
							field('urlvars', array())
287
						),
288
			'branch' => url(field('url'),
289
							$reqvars,
290
							field('urlvars'),
291
							array('action' => 'tree')
292
						)
293
		);
294
		
295
		$misc->printTreeXML($items, $attrs);
296
		exit;
297
	}
298
	
299
	if ($action == 'tree') doTree();
300
	if ($action == 'subtree') doSubTree();
301
	
302
	$misc->printHeader($lang['strschemas']);
303
	$misc->printBody();
304

    
305
	if (isset($_POST['cancel'])) $action = '';
306
	
307
	switch ($action) {
308
		case 'create':
309
			if (isset($_POST['create'])) doSaveCreate();
310
			else doCreate();
311
			break;
312
		case 'alter':
313
			if (isset($_POST['alter'])) doSaveAlter();
314
			else doAlter();
315
			break;
316
		case 'drop':
317
			if (isset($_POST['drop'])) doDrop(false);
318
			else doDrop(true);
319
			break;
320
		default:
321
			doDefault();
322
			break;
323
	}
324

    
325
	$misc->printFooter();
326

    
327
?>
(41-41/53)