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