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