Projekt

Obecné

Profil

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

    
3
	/**
4
	 * Manage tablespaces in a database cluster
5
	 *
6
	 * $Id: tablespaces.php,v 1.9 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
	 * Function to allow altering of a tablespace
18
	 */
19
	function doAlter($msg = '') {
20
		global $data, $misc;
21
		global $PHP_SELF, $lang;
22
		
23
		$misc->printTrail('tablespace');
24
		$misc->printTitle($lang['stralter'],'pg.tablespace.alter');
25
		$misc->printMsg($msg);
26

    
27
		// Fetch tablespace info		
28
		$tablespace = $data->getTablespace($_REQUEST['tablespace']);
29
		// Fetch all users		
30
		$users = $data->getUsers();
31
		
32
		if ($tablespace->recordCount() > 0) {
33
			
34
			if (!isset($_POST['name'])) $_POST['name'] = $tablespace->f['spcname'];
35
			if (!isset($_POST['owner'])) $_POST['owner'] = $tablespace->f['spcowner'];
36
			
37
			echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
38
			echo $misc->form;
39
			echo "<table>\n";
40
			echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n";
41
			echo "<td class=\"data1\">";
42
			echo "<input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", 
43
				htmlspecialchars($_POST['name']), "\" /></td></tr>\n";
44
			echo "<tr><th class=\"data left required\">{$lang['strowner']}</th>\n";
45
			echo "<td class=\"data1\"><select name=\"owner\">";
46
			while (!$users->EOF) {
47
				$uname = $users->f['usename'];
48
				echo "<option value=\"", htmlspecialchars($uname), "\"",
49
					($uname == $_POST['owner']) ? ' selected="selected"' : '', ">", htmlspecialchars($uname), "</option>\n";
50
				$users->moveNext();
51
			}
52
			echo "</select></td></tr>\n";				
53
			echo "</table>\n";
54
			echo "<p><input type=\"hidden\" name=\"action\" value=\"save_edit\" />\n";
55
			echo "<input type=\"hidden\" name=\"tablespace\" value=\"", htmlspecialchars($_REQUEST['tablespace']), "\" />\n";
56
			echo "<input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n";
57
			echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
58
			echo "</form>\n";
59
		}
60
		else echo "<p>{$lang['strnodata']}</p>\n";
61
	}
62

    
63
	/** 
64
	 * Function to save after altering a tablespace
65
	 */
66
	function doSaveAlter() {
67
		global $data, $lang;
68

    
69
		// Check data
70
		if (trim($_POST['name']) == '')
71
			doAlter($lang['strtablespaceneedsname']);
72
		else {
73
			$status = $data->alterTablespace($_POST['tablespace'], $_POST['name'], $_POST['owner']);
74
			if ($status == 0) {
75
				// If tablespace has been renamed, need to change to the new name
76
				if ($_POST['tablespace'] != $_POST['name']) {
77
					// Jump them to the new table name
78
					$_REQUEST['tablespace'] = $_POST['name'];
79
				}
80
				doDefault($lang['strtablespacealtered']);
81
			}
82
			else
83
				doAlter($lang['strtablespacealteredbad']);
84
		}
85
	}
86

    
87
	/**
88
	 * Show confirmation of drop and perform actual drop
89
	 */
90
	function doDrop($confirm) {
91
		global $data, $misc;
92
		global $PHP_SELF, $lang;
93

    
94
		if ($confirm) {
95
			$misc->printTrail('tablespace');
96
			$misc->printTitle($lang['strdrop'],'pg.tablespace.drop');
97
			
98
			echo "<p>", sprintf($lang['strconfdroptablespace'], $misc->printVal($_REQUEST['tablespace'])), "</p>\n";	
99
			
100
			echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
101
			echo $misc->form;
102
			echo "<input type=\"hidden\" name=\"action\" value=\"drop\" />\n";
103
			echo "<input type=\"hidden\" name=\"tablespace\" value=\"", htmlspecialchars($_REQUEST['tablespace']), "\" />\n";
104
			echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
105
			echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
106
			echo "</form>\n";
107
		}
108
		else {
109
			$status = $data->droptablespace($_REQUEST['tablespace']);
110
			if ($status == 0)
111
				doDefault($lang['strtablespacedropped']);
112
			else
113
				doDefault($lang['strtablespacedroppedbad']);
114
		}		
115
	}
116
	
117
	/**
118
	 * Displays a screen where they can enter a new tablespace
119
	 */
120
	function doCreate($msg = '') {
121
		global $data, $misc, $spcname;
122
		global $PHP_SELF, $lang;
123
		
124
		$server_info = $misc->getServerInfo();
125
		
126
		if (!isset($_POST['formSpcname'])) $_POST['formSpcname'] = '';
127
		if (!isset($_POST['formOwner'])) $_POST['formOwner'] = $server_info['username'];
128
		if (!isset($_POST['formLoc'])) $_POST['formLoc'] = '';
129

    
130
		// Fetch all users
131
		$users = $data->getUsers();
132
		
133
		$misc->printTrail('server');
134
		$misc->printTitle($lang['strcreatetablespace'],'pg.tablespace.create');
135
		$misc->printMsg($msg);
136

    
137
		echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
138
		echo $misc->form;
139
		echo "<table>\n";
140
		echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n";
141
		echo "\t\t<td class=\"data1\"><input size=\"32\" name=\"formSpcname\" maxlength=\"{$data->_maxNameLen}\" value=\"", htmlspecialchars($_POST['formSpcname']), "\" /></td>\n\t</tr>\n";
142
		echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strowner']}</th>\n";
143
		echo "\t\t<td class=\"data1\"><select name=\"formOwner\">\n";
144
		while (!$users->EOF) {
145
			$uname = $users->f['usename'];
146
			echo "\t\t\t<option value=\"", htmlspecialchars($uname), "\"",
147
				($uname == $_POST['formOwner']) ? ' selected="selected"' : '', ">", htmlspecialchars($uname), "</option>\n";
148
			$users->moveNext();
149
		}
150
		echo "\t\t</select></td>\n\t</tr>\n";				
151
		echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strlocation']}</th>\n";
152
		echo "\t\t<td class=\"data1\"><input size=\"32\" name=\"formLoc\" value=\"", htmlspecialchars($_POST['formLoc']), "\" /></td>\n\t</tr>\n";
153
		echo "</table>\n";
154
		echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create\" />\n";
155
		echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n";
156
		echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
157
		echo "</form>\n";
158
	}
159
	
160
	/**
161
	 * Actually creates the new tablespace in the cluster
162
	 */
163
	function doSaveCreate() {
164
		global $data;
165
		global $lang;
166

    
167
		// Check data
168
		if (trim($_POST['formSpcname']) == '')
169
			doCreate($lang['strtablespaceneedsname']);
170
		elseif (trim($_POST['formLoc']) == '')
171
			doCreate($lang['strtablespaceneedsloc']);
172
		else {		
173
			$status = $data->createTablespace($_POST['formSpcname'], $_POST['formOwner'], $_POST['formLoc']);
174
			if ($status == 0)
175
				doDefault($lang['strtablespacecreated']);
176
			else
177
				doCreate($lang['strtablespacecreatedbad']);
178
		}
179
	}	
180

    
181
	/**
182
	 * Show default list of tablespaces in the cluster
183
	 */
184
	function doDefault($msg = '') {
185
		global $data, $misc;
186
		global $PHP_SELF, $lang;
187
		
188
		$misc->printTrail('server');
189
		$misc->printTabs('server','tablespaces');
190
		$misc->printMsg($msg);
191
		
192
		$tablespaces = $data->getTablespaces();
193

    
194
		$columns = array(
195
			'database' => array(
196
				'title' => $lang['strname'],
197
				'field' => 'spcname'
198
			),
199
			'owner' => array(
200
				'title' => $lang['strowner'],
201
				'field' => 'spcowner'
202
			),
203
			'location' => array(
204
				'title' => $lang['strlocation'],
205
				'field' => 'spclocation'
206
			),
207
			'actions' => array(
208
				'title' => $lang['stractions']
209
			)
210
		);
211
		
212
		$actions = array(
213
			'alter' => array(
214
				'title' => $lang['stralter'],
215
				'url'   => "{$PHP_SELF}?action=edit&amp;{$misc->href}&amp;",
216
				'vars'  => array('tablespace' => 'spcname')
217
			),
218
			'drop' => array(
219
				'title' => $lang['strdrop'],
220
				'url'   => "{$PHP_SELF}?action=confirm_drop&amp;{$misc->href}&amp;",
221
				'vars'  => array('tablespace' => 'spcname')
222
			),
223
			'privileges' => array(
224
				'title' => $lang['strprivileges'],
225
				'url'   => "privileges.php?subject=tablespace&amp;{$misc->href}&amp;",
226
				'vars'  => array('tablespace' => 'spcname')
227
			)
228
		);
229
				
230
		$misc->printTable($tablespaces, $columns, $actions, $lang['strnotablespaces']);
231
		
232
		echo "<p><a class=\"navlink\" href=\"{$PHP_SELF}?action=create&amp;{$misc->href}\">{$lang['strcreatetablespace']}</a></p>\n";
233

    
234
	}
235

    
236
	$misc->printHeader($lang['strtablespaces']);
237
	$misc->printBody();
238

    
239
	switch ($action) {
240
		case 'save_create':
241
			if (isset($_REQUEST['cancel'])) doDefault();
242
			else doSaveCreate();
243
			break;
244
		case 'create':			
245
			doCreate();
246
			break;
247
		case 'drop':
248
			if (isset($_REQUEST['cancel'])) doDefault();
249
			else doDrop(false);
250
			break;
251
		case 'confirm_drop':
252
			doDrop(true);
253
			break;
254
		case 'save_edit':
255
			if (isset($_REQUEST['cancel'])) doDefault();
256
			else doSaveAlter();
257
			break;
258
		case 'edit':
259
			doAlter();
260
			break;
261
		default:
262
			doDefault();
263
			break;
264
	}	
265

    
266
	$misc->printFooter();
267

    
268
?>
(47-47/53)