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