1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PHPPgAdmin\Controller; |
4
|
|
|
|
5
|
|
|
use PHPPgAdmin\Decorators\Decorator; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Base controller class. |
9
|
|
|
*/ |
10
|
|
|
class AlldbController extends BaseController |
11
|
|
|
{ |
12
|
|
|
public $_name = 'AlldbController'; |
13
|
|
|
public $table_place = 'alldb-databases'; |
14
|
|
|
|
15
|
|
|
public function render() |
16
|
|
|
{ |
17
|
|
|
$conf = $this->conf; |
|
|
|
|
18
|
|
|
$misc = $this->misc; |
|
|
|
|
19
|
|
|
$lang = $this->lang; |
20
|
|
|
$action = $this->action; |
21
|
|
|
|
22
|
|
|
if ($action == 'tree') { |
23
|
|
|
return $this->doTree(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
$this->printHeader($lang['strdatabases']); |
27
|
|
|
$this->printBody(); |
28
|
|
|
|
29
|
|
|
switch ($action) { |
30
|
|
|
case 'export': |
31
|
|
|
$this->doExport(); |
32
|
|
|
break; |
33
|
|
|
case 'save_create': |
34
|
|
|
if (isset($_POST['cancel'])) { |
35
|
|
|
$this->doDefault(); |
36
|
|
|
} else { |
37
|
|
|
$this->doSaveCreate(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
break; |
41
|
|
|
case 'create': |
42
|
|
|
$this->doCreate(); |
43
|
|
|
break; |
44
|
|
|
case 'drop': |
45
|
|
|
if (isset($_REQUEST['drop'])) { |
46
|
|
|
$this->doDrop(false); |
47
|
|
|
} else { |
48
|
|
|
$this->doDefault(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
break; |
52
|
|
|
case 'confirm_drop': |
53
|
|
|
doDrop(true); |
|
|
|
|
54
|
|
|
break; |
55
|
|
|
case 'alter': |
56
|
|
|
if (isset($_POST['oldname']) && isset($_POST['newname']) && !isset($_POST['cancel'])) { |
57
|
|
|
$this->doAlter(false); |
58
|
|
|
} else { |
59
|
|
|
$this->doDefault(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
break; |
63
|
|
|
case 'confirm_alter': |
64
|
|
|
$this->doAlter(true); |
65
|
|
|
break; |
66
|
|
|
default: |
67
|
|
|
$this->doDefault(); |
68
|
|
|
|
69
|
|
|
break; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $this->printFooter(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Show default list of databases in the server. |
77
|
|
|
*/ |
78
|
|
|
public function doDefault($msg = '') |
79
|
|
|
{ |
80
|
|
|
$conf = $this->conf; |
81
|
|
|
$misc = $this->misc; |
82
|
|
|
$lang = $this->lang; |
83
|
|
|
|
84
|
|
|
$this->printTrail('server'); |
85
|
|
|
$this->printTabs('server', 'databases'); |
86
|
|
|
$this->printMsg($msg); |
87
|
|
|
$data = $misc->getDatabaseAccessor(); |
88
|
|
|
$databases = $data->getDatabases(); |
89
|
|
|
|
90
|
|
|
$columns = [ |
91
|
|
|
'database' => [ |
92
|
|
|
'title' => $lang['strdatabase'], |
93
|
|
|
'field' => Decorator::field('datname'), |
94
|
|
|
'url' => SUBFOLDER."/redirect/database?{$misc->href}&", |
95
|
|
|
'vars' => ['database' => 'datname'], |
96
|
|
|
], |
97
|
|
|
'owner' => [ |
98
|
|
|
'title' => $lang['strowner'], |
99
|
|
|
'field' => Decorator::field('datowner'), |
100
|
|
|
], |
101
|
|
|
'encoding' => [ |
102
|
|
|
'title' => $lang['strencoding'], |
103
|
|
|
'field' => Decorator::field('datencoding'), |
104
|
|
|
], |
105
|
|
|
'lc_collate' => [ |
106
|
|
|
'title' => $lang['strcollation'], |
107
|
|
|
'field' => Decorator::field('datcollate'), |
108
|
|
|
], |
109
|
|
|
'lc_ctype' => [ |
110
|
|
|
'title' => $lang['strctype'], |
111
|
|
|
'field' => Decorator::field('datctype'), |
112
|
|
|
], |
113
|
|
|
'tablespace' => [ |
114
|
|
|
'title' => $lang['strtablespace'], |
115
|
|
|
'field' => Decorator::field('tablespace'), |
116
|
|
|
], |
117
|
|
|
'dbsize' => [ |
118
|
|
|
'title' => $lang['strsize'], |
119
|
|
|
'field' => Decorator::field('dbsize'), |
120
|
|
|
'type' => 'prettysize', |
121
|
|
|
], |
122
|
|
|
'actions' => [ |
123
|
|
|
'title' => $lang['stractions'], |
124
|
|
|
], |
125
|
|
|
'comment' => [ |
126
|
|
|
'title' => $lang['strcomment'], |
127
|
|
|
'field' => Decorator::field('datcomment'), |
128
|
|
|
], |
129
|
|
|
]; |
130
|
|
|
|
131
|
|
|
$actions = [ |
132
|
|
|
'multiactions' => [ |
133
|
|
|
'keycols' => ['database' => 'datname'], |
134
|
|
|
'url' => 'alldb.php', |
135
|
|
|
'default' => null, |
136
|
|
|
], |
137
|
|
|
'drop' => [ |
138
|
|
|
'content' => $lang['strdrop'], |
139
|
|
|
'attr' => [ |
140
|
|
|
'href' => [ |
141
|
|
|
'url' => 'alldb.php', |
142
|
|
|
'urlvars' => [ |
143
|
|
|
'subject' => 'database', |
144
|
|
|
'action' => 'confirm_drop', |
145
|
|
|
'dropdatabase' => Decorator::field('datname'), |
146
|
|
|
], |
147
|
|
|
], |
148
|
|
|
], |
149
|
|
|
'multiaction' => 'confirm_drop', |
150
|
|
|
], |
151
|
|
|
'privileges' => [ |
152
|
|
|
'content' => $lang['strprivileges'], |
153
|
|
|
'attr' => [ |
154
|
|
|
'href' => [ |
155
|
|
|
'url' => 'privileges.php', |
156
|
|
|
'urlvars' => [ |
157
|
|
|
'subject' => 'database', |
158
|
|
|
'database' => Decorator::field('datname'), |
159
|
|
|
], |
160
|
|
|
], |
161
|
|
|
], |
162
|
|
|
], |
163
|
|
|
]; |
164
|
|
|
if ($data->hasAlterDatabase()) { |
165
|
|
|
$actions['alter'] = [ |
166
|
|
|
'content' => $lang['stralter'], |
167
|
|
|
'attr' => [ |
168
|
|
|
'href' => [ |
169
|
|
|
'url' => 'alldb.php', |
170
|
|
|
'urlvars' => [ |
171
|
|
|
'subject' => 'database', |
172
|
|
|
'action' => 'confirm_alter', |
173
|
|
|
'alterdatabase' => Decorator::field('datname'), |
174
|
|
|
], |
175
|
|
|
], |
176
|
|
|
], |
177
|
|
|
]; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
if (!$data->hasTablespaces()) { |
181
|
|
|
unset($columns['tablespace']); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
if (!$data->hasServerAdminFuncs()) { |
185
|
|
|
unset($columns['dbsize']); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
if (!$data->hasDatabaseCollation()) { |
189
|
|
|
unset($columns['lc_collate'], $columns['lc_ctype']); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
if (!isset($data->privlist['database'])) { |
193
|
|
|
unset($actions['privileges']); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
echo $this->printTable($databases, $columns, $actions, $this->table_place, $lang['strnodatabases']); |
197
|
|
|
|
198
|
|
|
$navlinks = [ |
199
|
|
|
'create' => [ |
200
|
|
|
'attr' => [ |
201
|
|
|
'href' => [ |
202
|
|
|
'url' => 'alldb.php', |
203
|
|
|
'urlvars' => [ |
204
|
|
|
'action' => 'create', |
205
|
|
|
'server' => $_REQUEST['server'], |
206
|
|
|
], |
207
|
|
|
], |
208
|
|
|
], |
209
|
|
|
'content' => $lang['strcreatedatabase'], |
210
|
|
|
], |
211
|
|
|
]; |
212
|
|
|
$this->printNavLinks($navlinks, $this->table_place, get_defined_vars()); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
View Code Duplication |
public function doTree() |
|
|
|
|
216
|
|
|
{ |
217
|
|
|
$conf = $this->conf; |
|
|
|
|
218
|
|
|
$misc = $this->misc; |
219
|
|
|
$lang = $this->lang; |
|
|
|
|
220
|
|
|
$data = $misc->getDatabaseAccessor(); |
221
|
|
|
|
222
|
|
|
$databases = $data->getDatabases(); |
223
|
|
|
|
224
|
|
|
$reqvars = $misc->getRequestVars('database'); |
225
|
|
|
|
226
|
|
|
//$this->prtrace($reqvars); |
227
|
|
|
|
228
|
|
|
$attrs = [ |
229
|
|
|
'text' => Decorator::field('datname'), |
230
|
|
|
'icon' => 'Database', |
231
|
|
|
'toolTip' => Decorator::field('datcomment'), |
232
|
|
|
'action' => Decorator::redirecturl('redirect.php', $reqvars, ['database' => Decorator::field('datname')]), |
233
|
|
|
'branch' => Decorator::url('/src/views/database', $reqvars, ['action' => 'tree', 'database' => Decorator::field('datname')]), |
234
|
|
|
|
235
|
|
|
]; |
236
|
|
|
|
237
|
|
|
return $this->printTree($databases, $attrs, 'databases'); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Display a form for alter and perform actual alter. |
242
|
|
|
*/ |
243
|
|
|
public function doAlter($confirm) |
244
|
|
|
{ |
245
|
|
|
$conf = $this->conf; |
|
|
|
|
246
|
|
|
$misc = $this->misc; |
247
|
|
|
$lang = $this->lang; |
248
|
|
|
$data = $misc->getDatabaseAccessor(); |
249
|
|
|
|
250
|
|
|
if ($confirm) { |
251
|
|
|
$this->printTrail('database'); |
252
|
|
|
$this->printTitle($lang['stralter'], 'pg.database.alter'); |
253
|
|
|
|
254
|
|
|
echo '<form action="'.SUBFOLDER."/src/views/alldb.php\" method=\"post\">\n"; |
255
|
|
|
echo "<table>\n"; |
256
|
|
|
echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n"; |
257
|
|
|
echo '<td class="data1">'; |
258
|
|
|
echo "<input name=\"newname\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
259
|
|
|
htmlspecialchars($_REQUEST['alterdatabase']), "\" /></td></tr>\n"; |
260
|
|
|
|
261
|
|
|
if ($data->hasAlterDatabaseOwner() && $data->isSuperUser()) { |
262
|
|
|
// Fetch all users |
263
|
|
|
|
264
|
|
|
$rs = $data->getDatabaseOwner($_REQUEST['alterdatabase']); |
265
|
|
|
$owner = isset($rs->fields['usename']) ? $rs->fields['usename'] : ''; |
266
|
|
|
$users = $data->getUsers(); |
267
|
|
|
|
268
|
|
|
echo "<tr><th class=\"data left required\">{$lang['strowner']}</th>\n"; |
269
|
|
|
echo '<td class="data1"><select name="owner">'; |
270
|
|
|
while (!$users->EOF) { |
271
|
|
|
$uname = $users->fields['usename']; |
272
|
|
|
echo '<option value="', htmlspecialchars($uname), '"', |
273
|
|
|
($uname == $owner) ? ' selected="selected"' : '', '>', htmlspecialchars($uname), "</option>\n"; |
274
|
|
|
$users->moveNext(); |
275
|
|
|
} |
276
|
|
|
echo "</select></td></tr>\n"; |
277
|
|
|
} |
278
|
|
|
if ($data->hasSharedComments()) { |
279
|
|
|
$rs = $data->getDatabaseComment($_REQUEST['alterdatabase']); |
280
|
|
|
$comment = isset($rs->fields['description']) ? $rs->fields['description'] : ''; |
281
|
|
|
echo "<tr><th class=\"data left\">{$lang['strcomment']}</th>\n"; |
282
|
|
|
echo '<td class="data1">'; |
283
|
|
|
echo '<textarea rows="3" cols="32" name="dbcomment">', |
284
|
|
|
htmlspecialchars($comment), "</textarea></td></tr>\n"; |
285
|
|
|
} |
286
|
|
|
echo "</table>\n"; |
287
|
|
|
echo "<input type=\"hidden\" name=\"action\" value=\"alter\" />\n"; |
288
|
|
|
echo $misc->form; |
289
|
|
|
echo '<input type="hidden" name="oldname" value="', |
290
|
|
|
htmlspecialchars($_REQUEST['alterdatabase']), "\" />\n"; |
291
|
|
|
echo "<input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n"; |
292
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n"; |
293
|
|
|
echo "</form>\n"; |
294
|
|
|
} else { |
295
|
|
|
if (!isset($_POST['owner'])) { |
296
|
|
|
$_POST['owner'] = ''; |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
if (!isset($_POST['dbcomment'])) { |
300
|
|
|
$_POST['dbcomment'] = ''; |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
if ($data->alterDatabase($_POST['oldname'], $_POST['newname'], $_POST['owner'], $_POST['dbcomment']) == 0) { |
304
|
|
|
$this->misc->setReloadBrowser(true); |
305
|
|
|
$this->doDefault($lang['strdatabasealtered']); |
306
|
|
|
} else { |
307
|
|
|
$this->doDefault($lang['strdatabasealteredbad']); |
308
|
|
|
} |
309
|
|
|
} |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* Show confirmation of drop and perform actual drop. |
314
|
|
|
*/ |
315
|
|
|
public function doDrop($confirm) |
316
|
|
|
{ |
317
|
|
|
$conf = $this->conf; |
|
|
|
|
318
|
|
|
$misc = $this->misc; |
319
|
|
|
$lang = $this->lang; |
320
|
|
|
$data = $misc->getDatabaseAccessor(); |
321
|
|
|
|
322
|
|
|
if (empty($_REQUEST['dropdatabase']) && empty($_REQUEST['ma'])) { |
323
|
|
|
$this->doDefault($lang['strspecifydatabasetodrop']); |
324
|
|
|
exit(); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
if ($confirm) { |
328
|
|
|
$this->printTrail('database'); |
329
|
|
|
$this->printTitle($lang['strdrop'], 'pg.database.drop'); |
330
|
|
|
|
331
|
|
|
echo '<form action="'.SUBFOLDER."/src/views/alldb.php\" method=\"post\">\n"; |
332
|
|
|
//If multi drop |
333
|
|
|
if (isset($_REQUEST['ma'])) { |
334
|
|
|
foreach ($_REQUEST['ma'] as $v) { |
335
|
|
|
$a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
|
|
|
|
336
|
|
|
echo '<p>', sprintf($lang['strconfdropdatabase'], $misc->printVal($a['database'])), "</p>\n"; |
337
|
|
|
printf('<input type="hidden" name="dropdatabase[]" value="%s" />', htmlspecialchars($a['database'])); |
338
|
|
|
} |
339
|
|
|
} else { |
340
|
|
|
echo '<p>', sprintf($lang['strconfdropdatabase'], $misc->printVal($_REQUEST['dropdatabase'])), "</p>\n"; |
341
|
|
|
echo '<input type="hidden" name="dropdatabase" value="', htmlspecialchars($_REQUEST['dropdatabase']), "\" />\n"; |
342
|
|
|
} // END if multi drop |
343
|
|
|
|
344
|
|
|
echo "<input type=\"hidden\" name=\"action\" value=\"drop\" />\n"; |
345
|
|
|
echo $misc->form; |
346
|
|
|
echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n"; |
347
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n"; |
348
|
|
|
echo "</form>\n"; |
349
|
|
|
} // END confirm |
350
|
|
|
else { |
351
|
|
|
//If multi drop |
352
|
|
|
if (is_array($_REQUEST['dropdatabase'])) { |
353
|
|
|
$msg = ''; |
354
|
|
|
foreach ($_REQUEST['dropdatabase'] as $d) { |
355
|
|
|
$status = $data->dropDatabase($d); |
356
|
|
|
if ($status == 0) { |
357
|
|
|
$msg .= sprintf('%s: %s<br />', htmlentities($d, ENT_QUOTES, 'UTF-8'), $lang['strdatabasedropped']); |
358
|
|
|
} else { |
359
|
|
|
$this->doDefault(sprintf('%s%s: %s<br />', $msg, htmlentities($d, ENT_QUOTES, 'UTF-8'), $lang['strdatabasedroppedbad'])); |
360
|
|
|
|
361
|
|
|
return; |
362
|
|
|
} |
363
|
|
|
} // Everything went fine, back to Default page... |
364
|
|
|
$this->setReloadDropDatabase(true); |
365
|
|
|
$this->doDefault($msg); |
366
|
|
|
} else { |
367
|
|
|
$status = $data->dropDatabase($_POST['dropdatabase']); |
368
|
|
|
if ($status == 0) { |
369
|
|
|
$this->setReloadDropDatabase(true); |
370
|
|
|
$this->doDefault($lang['strdatabasedropped']); |
371
|
|
|
} else { |
372
|
|
|
$this->doDefault($lang['strdatabasedroppedbad']); |
373
|
|
|
} |
374
|
|
|
} |
375
|
|
|
} //END DROP |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
// END FUNCTION |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* Displays a screen where they can enter a new database. |
382
|
|
|
*/ |
383
|
|
|
public function doCreate($msg = '') |
384
|
|
|
{ |
385
|
|
|
$conf = $this->conf; |
|
|
|
|
386
|
|
|
$misc = $this->misc; |
387
|
|
|
$lang = $this->lang; |
388
|
|
|
$data = $misc->getDatabaseAccessor(); |
389
|
|
|
|
390
|
|
|
$this->printTrail('server'); |
391
|
|
|
$this->printTitle($lang['strcreatedatabase'], 'pg.database.create'); |
392
|
|
|
$this->printMsg($msg); |
393
|
|
|
|
394
|
|
|
if (!isset($_POST['formName'])) { |
395
|
|
|
$_POST['formName'] = ''; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
// Default encoding is that in language file |
399
|
|
|
if (!isset($_POST['formEncoding'])) { |
400
|
|
|
$_POST['formEncoding'] = ''; |
401
|
|
|
} |
402
|
|
|
if (!isset($_POST['formTemplate'])) { |
403
|
|
|
$_POST['formTemplate'] = 'template1'; |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
if (!isset($_POST['formSpc'])) { |
407
|
|
|
$_POST['formSpc'] = ''; |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
if (!isset($_POST['formComment'])) { |
411
|
|
|
$_POST['formComment'] = ''; |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
// Fetch a list of databases in the cluster |
415
|
|
|
$templatedbs = $data->getDatabases(false); |
416
|
|
|
|
417
|
|
|
// Fetch all tablespaces from the database |
418
|
|
|
if ($data->hasTablespaces()) { |
419
|
|
|
$tablespaces = $data->getTablespaces(); |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
echo '<form action="'.SUBFOLDER."/src/views/alldb.php\" method=\"post\">\n"; |
423
|
|
|
echo "<table>\n"; |
424
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n"; |
425
|
|
|
echo "\t\t<td class=\"data1\"><input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
426
|
|
|
htmlspecialchars($_POST['formName']), "\" /></td>\n\t</tr>\n"; |
427
|
|
|
|
428
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strtemplatedb']}</th>\n"; |
429
|
|
|
echo "\t\t<td class=\"data1\">\n"; |
430
|
|
|
echo "\t\t\t<select name=\"formTemplate\">\n"; |
431
|
|
|
// Always offer template0 and template1 |
432
|
|
|
echo "\t\t\t\t<option value=\"template0\"", |
433
|
|
|
($_POST['formTemplate'] == 'template0') ? ' selected="selected"' : '', ">template0</option>\n"; |
434
|
|
|
echo "\t\t\t\t<option value=\"template1\"", |
435
|
|
|
($_POST['formTemplate'] == 'template1') ? ' selected="selected"' : '', ">template1</option>\n"; |
436
|
|
|
while (!$templatedbs->EOF) { |
437
|
|
|
$dbname = htmlspecialchars($templatedbs->fields['datname']); |
438
|
|
|
if ($dbname != 'template1') { |
439
|
|
|
// filter out for $conf[show_system] users so we dont get duplicates |
440
|
|
|
echo "\t\t\t\t<option value=\"{$dbname}\"", |
441
|
|
|
($dbname == $_POST['formTemplate']) ? ' selected="selected"' : '', ">{$dbname}</option>\n"; |
442
|
|
|
} |
443
|
|
|
$templatedbs->moveNext(); |
444
|
|
|
} |
445
|
|
|
echo "\t\t\t</select>\n"; |
446
|
|
|
echo "\t\t</td>\n\t</tr>\n"; |
447
|
|
|
|
448
|
|
|
// ENCODING |
449
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strencoding']}</th>\n"; |
450
|
|
|
echo "\t\t<td class=\"data1\">\n"; |
451
|
|
|
echo "\t\t\t<select name=\"formEncoding\">\n"; |
452
|
|
|
echo "\t\t\t\t<option value=\"\"></option>\n"; |
453
|
|
|
while (list($key) = each($data->codemap)) { |
454
|
|
|
echo "\t\t\t\t<option value=\"", htmlspecialchars($key), '"', |
455
|
|
|
($key == $_POST['formEncoding']) ? ' selected="selected"' : '', '>', |
456
|
|
|
$misc->printVal($key), "</option>\n"; |
457
|
|
|
} |
458
|
|
|
echo "\t\t\t</select>\n"; |
459
|
|
|
echo "\t\t</td>\n\t</tr>\n"; |
460
|
|
|
|
461
|
|
|
if ($data->hasDatabaseCollation()) { |
462
|
|
|
if (!isset($_POST['formCollate'])) { |
463
|
|
|
$_POST['formCollate'] = ''; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
if (!isset($_POST['formCType'])) { |
467
|
|
|
$_POST['formCType'] = ''; |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
// LC_COLLATE |
471
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcollation']}</th>\n"; |
472
|
|
|
echo "\t\t<td class=\"data1\">\n"; |
473
|
|
|
echo "\t\t\t<input name=\"formCollate\" value=\"", htmlspecialchars($_POST['formCollate']), "\" />\n"; |
474
|
|
|
echo "\t\t</td>\n\t</tr>\n"; |
475
|
|
|
|
476
|
|
|
// LC_CTYPE |
477
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strctype']}</th>\n"; |
478
|
|
|
echo "\t\t<td class=\"data1\">\n"; |
479
|
|
|
echo "\t\t\t<input name=\"formCType\" value=\"", htmlspecialchars($_POST['formCType']), "\" />\n"; |
480
|
|
|
echo "\t\t</td>\n\t</tr>\n"; |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
// Tablespace (if there are any) |
484
|
|
View Code Duplication |
if ($data->hasTablespaces() && $tablespaces->recordCount() > 0) { |
|
|
|
|
485
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strtablespace']}</th>\n"; |
486
|
|
|
echo "\t\t<td class=\"data1\">\n\t\t\t<select name=\"formSpc\">\n"; |
487
|
|
|
// Always offer the default (empty) option |
488
|
|
|
echo "\t\t\t\t<option value=\"\"", |
489
|
|
|
($_POST['formSpc'] == '') ? ' selected="selected"' : '', "></option>\n"; |
490
|
|
|
// Display all other tablespaces |
491
|
|
|
while (!$tablespaces->EOF) { |
492
|
|
|
$spcname = htmlspecialchars($tablespaces->fields['spcname']); |
493
|
|
|
echo "\t\t\t\t<option value=\"{$spcname}\"", |
494
|
|
|
($spcname == $_POST['formSpc']) ? ' selected="selected"' : '', ">{$spcname}</option>\n"; |
495
|
|
|
$tablespaces->moveNext(); |
496
|
|
|
} |
497
|
|
|
echo "\t\t\t</select>\n\t\t</td>\n\t</tr>\n"; |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
// Comments (if available) |
501
|
|
View Code Duplication |
if ($data->hasSharedComments()) { |
|
|
|
|
502
|
|
|
echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n"; |
503
|
|
|
echo "\t\t<td><textarea name=\"formComment\" rows=\"3\" cols=\"32\">", |
504
|
|
|
htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n"; |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
echo "</table>\n"; |
508
|
|
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create\" />\n"; |
509
|
|
|
echo $misc->form; |
510
|
|
|
echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n"; |
511
|
|
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
512
|
|
|
echo "</form>\n"; |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
/** |
516
|
|
|
* Actually creates the new view in the database. |
517
|
|
|
*/ |
518
|
|
|
public function doSaveCreate() |
519
|
|
|
{ |
520
|
|
|
$conf = $this->conf; |
|
|
|
|
521
|
|
|
$misc = $this->misc; |
522
|
|
|
$lang = $this->lang; |
523
|
|
|
$data = $misc->getDatabaseAccessor(); |
524
|
|
|
|
525
|
|
|
// Default tablespace to null if it isn't set |
526
|
|
|
if (!isset($_POST['formSpc'])) { |
527
|
|
|
$_POST['formSpc'] = null; |
528
|
|
|
} |
529
|
|
|
|
530
|
|
|
// Default comment to blank if it isn't set |
531
|
|
|
if (!isset($_POST['formComment'])) { |
532
|
|
|
$_POST['formComment'] = null; |
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
// Default collate to blank if it isn't set |
536
|
|
|
if (!isset($_POST['formCollate'])) { |
537
|
|
|
$_POST['formCollate'] = null; |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
// Default ctype to blank if it isn't set |
541
|
|
|
if (!isset($_POST['formCType'])) { |
542
|
|
|
$_POST['formCType'] = null; |
543
|
|
|
} |
544
|
|
|
|
545
|
|
|
// Check that they've given a name and a definition |
546
|
|
|
if ($_POST['formName'] == '') { |
547
|
|
|
$this->doCreate($lang['strdatabaseneedsname']); |
548
|
|
|
} else { |
549
|
|
|
$status = $data->createDatabase($_POST['formName'], $_POST['formEncoding'], $_POST['formSpc'], |
550
|
|
|
$_POST['formComment'], $_POST['formTemplate'], $_POST['formCollate'], $_POST['formCType']); |
551
|
|
|
if ($status == 0) { |
552
|
|
|
$this->misc->setReloadBrowser(true); |
553
|
|
|
$this->doDefault($lang['strdatabasecreated']); |
554
|
|
|
} else { |
555
|
|
|
$this->doCreate($lang['strdatabasecreatedbad']); |
556
|
|
|
} |
557
|
|
|
} |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
/** |
561
|
|
|
* Displays options for cluster download. |
562
|
|
|
*/ |
563
|
|
|
public function doExport($msg = '') |
564
|
|
|
{ |
565
|
|
|
$conf = $this->conf; |
|
|
|
|
566
|
|
|
$misc = $this->misc; |
567
|
|
|
$lang = $this->lang; |
568
|
|
|
$data = $misc->getDatabaseAccessor(); |
|
|
|
|
569
|
|
|
|
570
|
|
|
$this->printTrail('server'); |
571
|
|
|
$this->printTabs('server', 'export'); |
572
|
|
|
$this->printMsg($msg); |
573
|
|
|
|
574
|
|
|
echo '<form action="'.SUBFOLDER."/src/views/dbexport.php\" method=\"post\">\n"; |
575
|
|
|
echo "<table>\n"; |
576
|
|
|
echo "<tr><th class=\"data\">{$lang['strformat']}</th><th class=\"data\">{$lang['stroptions']}</th></tr>\n"; |
577
|
|
|
// Data only |
578
|
|
|
echo '<tr><th class="data left" rowspan="2">'; |
579
|
|
|
echo "<input type=\"radio\" id=\"what1\" name=\"what\" value=\"dataonly\" checked=\"checked\" /><label for=\"what1\">{$lang['strdataonly']}</label></th>\n"; |
580
|
|
|
echo "<td>{$lang['strformat']}\n"; |
581
|
|
|
echo "<select name=\"d_format\">\n"; |
582
|
|
|
echo "<option value=\"copy\">COPY</option>\n"; |
583
|
|
|
echo "<option value=\"sql\">SQL</option>\n"; |
584
|
|
|
echo "</select>\n</td>\n</tr>\n"; |
585
|
|
|
echo "<tr><td><input type=\"checkbox\" id=\"d_oids\" name=\"d_oids\" /><label for=\"d_oids\">{$lang['stroids']}</label></td>\n</tr>\n"; |
586
|
|
|
// Structure only |
587
|
|
|
echo "<tr><th class=\"data left\"><input type=\"radio\" id=\"what2\" name=\"what\" value=\"structureonly\" /><label for=\"what2\">{$lang['strstructureonly']}</label></th>\n"; |
588
|
|
|
echo "<td><input type=\"checkbox\" id=\"s_clean\" name=\"s_clean\" /><label for=\"s_clean\">{$lang['strdrop']}</label></td>\n</tr>\n"; |
589
|
|
|
// Structure and data |
590
|
|
|
echo '<tr><th class="data left" rowspan="3">'; |
591
|
|
|
echo "<input type=\"radio\" id=\"what3\" name=\"what\" value=\"structureanddata\" /><label for=\"what3\">{$lang['strstructureanddata']}</label></th>\n"; |
592
|
|
|
echo "<td>{$lang['strformat']}\n"; |
593
|
|
|
echo "<select name=\"sd_format\">\n"; |
594
|
|
|
echo "<option value=\"copy\">COPY</option>\n"; |
595
|
|
|
echo "<option value=\"sql\">SQL</option>\n"; |
596
|
|
|
echo "</select>\n</td>\n</tr>\n"; |
597
|
|
|
echo "<tr><td><input type=\"checkbox\" id=\"sd_clean\" name=\"sd_clean\" /><label for=\"sd_clean\">{$lang['strdrop']}</label></td>\n</tr>\n"; |
598
|
|
|
echo "<tr><td><input type=\"checkbox\" id=\"sd_oids\" name=\"sd_oids\" /><label for=\"sd_oids\">{$lang['stroids']}</label></td>\n</tr>\n"; |
599
|
|
|
echo "</table>\n"; |
600
|
|
|
|
601
|
|
|
echo "<h3>{$lang['stroptions']}</h3>\n"; |
602
|
|
|
echo "<p><input type=\"radio\" id=\"output1\" name=\"output\" value=\"show\" checked=\"checked\" /><label for=\"output1\">{$lang['strshow']}</label>\n"; |
603
|
|
|
echo "<br/><input type=\"radio\" id=\"output2\" name=\"output\" value=\"download\" /><label for=\"output2\">{$lang['strdownload']}</label></p>\n"; |
604
|
|
|
|
605
|
|
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n"; |
606
|
|
|
echo "<input type=\"hidden\" name=\"subject\" value=\"server\" />\n"; |
607
|
|
|
echo $misc->form; |
608
|
|
|
echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n"; |
609
|
|
|
echo "</form>\n"; |
610
|
|
|
} |
611
|
|
|
} |
612
|
|
|
|