HuasoFoundries /
phpPgAdmin6
| 1 | <?php |
||
| 2 | |||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 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 SchemasController extends BaseController |
||
| 15 | { |
||
| 16 | public $controller_name = 'SchemasController'; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Default method to render the controller according to the action parameter. |
||
| 20 | */ |
||
| 21 | public function render() |
||
| 22 | { |
||
| 23 | $lang = $this->lang; |
||
| 24 | $action = $this->action; |
||
| 25 | |||
| 26 | if ('tree' == $action) { |
||
| 27 | return $this->doTree(); |
||
| 28 | } |
||
| 29 | if ('subtree' == $action) { |
||
| 30 | return $this->doSubTree(); |
||
| 31 | } |
||
| 32 | |||
| 33 | if (isset($_POST['cancel'])) { |
||
| 34 | $action = ''; |
||
| 35 | } |
||
| 36 | |||
| 37 | $header_template = 'header.twig'; |
||
| 38 | $footer_template = 'footer.twig'; |
||
| 39 | |||
| 40 | ob_start(); |
||
| 41 | switch ($action) { |
||
| 42 | case 'create': |
||
| 43 | if (isset($_POST['create'])) { |
||
| 44 | $this->doSaveCreate(); |
||
| 45 | } else { |
||
| 46 | $this->doCreate(); |
||
| 47 | } |
||
| 48 | |||
| 49 | break; |
||
| 50 | case 'alter': |
||
| 51 | if (isset($_POST['alter'])) { |
||
| 52 | $this->doSaveAlter(); |
||
| 53 | } else { |
||
| 54 | $this->doAlter(); |
||
| 55 | } |
||
| 56 | |||
| 57 | break; |
||
| 58 | case 'drop': |
||
| 59 | if (isset($_POST['drop'])) { |
||
| 60 | $this->doDrop(false); |
||
| 61 | } else { |
||
| 62 | $this->doDrop(true); |
||
| 63 | } |
||
| 64 | |||
| 65 | break; |
||
| 66 | case 'export': |
||
| 67 | $this->doExport(); |
||
| 68 | |||
| 69 | break; |
||
| 70 | default: |
||
| 71 | $header_template = 'header_datatables.twig'; |
||
| 72 | $this->doDefault(); |
||
| 73 | |||
| 74 | break; |
||
| 75 | } |
||
| 76 | |||
| 77 | $output = ob_get_clean(); |
||
| 78 | |||
| 79 | $this->printHeader($lang['strschemas'], null, true, $header_template); |
||
| 80 | $this->printBody(); |
||
| 81 | |||
| 82 | echo $output; |
||
| 83 | |||
| 84 | return $this->printFooter(); |
||
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Show default list of schemas in the database. |
||
| 89 | * |
||
| 90 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 91 | */ |
||
| 92 | public function doDefault($msg = '') |
||
| 93 | { |
||
| 94 | $lang = $this->lang; |
||
| 95 | $data = $this->misc->getDatabaseAccessor(); |
||
| 96 | |||
| 97 | $this->printTrail('database'); |
||
| 98 | $this->printTabs('database', 'schemas'); |
||
| 99 | $this->printMsg($msg); |
||
| 100 | |||
| 101 | // Check that the DB actually supports schemas |
||
| 102 | $schemas = $data->getSchemas(); |
||
| 103 | |||
| 104 | $columns = [ |
||
| 105 | 'schema' => [ |
||
| 106 | 'title' => $lang['strschema'], |
||
| 107 | 'field' => Decorator::field('nspname'), |
||
| 108 | 'url' => \SUBFOLDER . "/redirect/schema?{$this->misc->href}&", |
||
| 109 | 'vars' => ['schema' => 'nspname'], |
||
| 110 | ], |
||
| 111 | 'owner' => [ |
||
| 112 | 'title' => $lang['strowner'], |
||
| 113 | 'field' => Decorator::field('nspowner'), |
||
| 114 | ], |
||
| 115 | 'actions' => [ |
||
| 116 | 'title' => $lang['stractions'], |
||
| 117 | ], |
||
| 118 | 'comment' => [ |
||
| 119 | 'title' => $lang['strcomment'], |
||
| 120 | 'field' => Decorator::field('nspcomment'), |
||
| 121 | ], |
||
| 122 | ]; |
||
| 123 | |||
| 124 | $actions = [ |
||
| 125 | 'multiactions' => [ |
||
| 126 | 'keycols' => ['nsp' => 'nspname'], |
||
| 127 | 'url' => 'schemas.php', |
||
| 128 | ], |
||
| 129 | 'drop' => [ |
||
| 130 | 'content' => $lang['strdrop'], |
||
| 131 | 'attr' => [ |
||
| 132 | 'href' => [ |
||
| 133 | 'url' => 'schemas.php', |
||
| 134 | 'urlvars' => [ |
||
| 135 | 'action' => 'drop', |
||
| 136 | 'nsp' => Decorator::field('nspname'), |
||
| 137 | ], |
||
| 138 | ], |
||
| 139 | ], |
||
| 140 | 'multiaction' => 'drop', |
||
| 141 | ], |
||
| 142 | 'privileges' => [ |
||
| 143 | 'content' => $lang['strprivileges'], |
||
| 144 | 'attr' => [ |
||
| 145 | 'href' => [ |
||
| 146 | 'url' => 'privileges.php', |
||
| 147 | 'urlvars' => [ |
||
| 148 | 'subject' => 'schema', |
||
| 149 | 'schema' => Decorator::field('nspname'), |
||
| 150 | ], |
||
| 151 | ], |
||
| 152 | ], |
||
| 153 | ], |
||
| 154 | 'alter' => [ |
||
| 155 | 'content' => $lang['stralter'], |
||
| 156 | 'attr' => [ |
||
| 157 | 'href' => [ |
||
| 158 | 'url' => 'schemas.php', |
||
| 159 | 'urlvars' => [ |
||
| 160 | 'action' => 'alter', |
||
| 161 | 'schema' => Decorator::field('nspname'), |
||
| 162 | ], |
||
| 163 | ], |
||
| 164 | ], |
||
| 165 | ], |
||
| 166 | ]; |
||
| 167 | |||
| 168 | if (!$data->hasAlterSchema()) { |
||
| 169 | unset($actions['alter']); |
||
| 170 | } |
||
| 171 | |||
| 172 | echo $this->printTable($schemas, $columns, $actions, 'schemas-schemas', $lang['strnoschemas']); |
||
| 173 | |||
| 174 | $this->printNavLinks(['create' => [ |
||
| 175 | 'attr' => [ |
||
| 176 | 'href' => [ |
||
| 177 | 'url' => 'schemas.php', |
||
| 178 | 'urlvars' => [ |
||
| 179 | 'action' => 'create', |
||
| 180 | 'server' => $_REQUEST['server'], |
||
| 181 | 'database' => $_REQUEST['database'], |
||
| 182 | ], |
||
| 183 | ], |
||
| 184 | ], |
||
| 185 | 'content' => $lang['strcreateschema'], |
||
| 186 | ]], 'schemas-schemas', get_defined_vars()); |
||
| 187 | } |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Generate XML for the browser tree. |
||
| 191 | */ |
||
| 192 | public function doTree() |
||
| 193 | { |
||
| 194 | $lang = $this->lang; |
||
|
0 ignored issues
–
show
|
|||
| 195 | $data = $this->misc->getDatabaseAccessor(); |
||
| 196 | |||
| 197 | $schemas = $data->getSchemas(); |
||
| 198 | |||
| 199 | $reqvars = $this->misc->getRequestVars('schema'); |
||
| 200 | |||
| 201 | //$this->prtrace($reqvars); |
||
| 202 | |||
| 203 | $attrs = [ |
||
| 204 | 'text' => Decorator::field('nspname'), |
||
| 205 | 'icon' => 'Schema', |
||
| 206 | 'toolTip' => Decorator::field('nspcomment'), |
||
| 207 | 'action' => Decorator::redirecturl( |
||
| 208 | 'redirect.php', |
||
| 209 | $reqvars, |
||
| 210 | [ |
||
| 211 | 'subject' => 'schema', |
||
| 212 | 'schema' => Decorator::field('nspname'), |
||
| 213 | ] |
||
| 214 | ), |
||
| 215 | 'branch' => Decorator::url( |
||
| 216 | 'schemas.php', |
||
| 217 | $reqvars, |
||
| 218 | [ |
||
| 219 | 'action' => 'subtree', |
||
| 220 | 'schema' => Decorator::field('nspname'), |
||
| 221 | ] |
||
| 222 | ), |
||
| 223 | ]; |
||
| 224 | |||
| 225 | $this->printTree($schemas, $attrs, 'schemas'); |
||
| 226 | } |
||
| 227 | |||
| 228 | public function doSubTree() |
||
| 229 | { |
||
| 230 | $lang = $this->lang; |
||
|
0 ignored issues
–
show
|
|||
| 231 | |||
| 232 | $tabs = $this->misc->getNavTabs('schema'); |
||
| 233 | |||
| 234 | $items = $this->adjustTabsForTree($tabs); |
||
| 235 | |||
| 236 | $reqvars = $this->misc->getRequestVars('schema'); |
||
| 237 | |||
| 238 | //$this->prtrace($reqvars); |
||
| 239 | |||
| 240 | $attrs = [ |
||
| 241 | 'text' => Decorator::field('title'), |
||
| 242 | 'icon' => Decorator::field('icon'), |
||
| 243 | 'action' => Decorator::actionurl( |
||
| 244 | Decorator::field('url'), |
||
| 245 | $reqvars, |
||
| 246 | Decorator::field('urlvars', []) |
||
| 247 | ), |
||
| 248 | 'branch' => Decorator::url( |
||
| 249 | Decorator::field('url'), |
||
| 250 | $reqvars, |
||
| 251 | Decorator::field('urlvars'), |
||
| 252 | ['action' => 'tree'] |
||
| 253 | ), |
||
| 254 | ]; |
||
| 255 | |||
| 256 | $this->printTree($items, $attrs, 'schema'); |
||
| 257 | } |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Displays a screen where they can enter a new schema. |
||
| 261 | * |
||
| 262 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 263 | */ |
||
| 264 | public function doCreate($msg = '') |
||
| 265 | { |
||
| 266 | $lang = $this->lang; |
||
| 267 | $data = $this->misc->getDatabaseAccessor(); |
||
| 268 | |||
| 269 | $server_info = $this->misc->getServerInfo(); |
||
| 270 | |||
| 271 | if (!isset($_POST['formName'])) { |
||
| 272 | $_POST['formName'] = ''; |
||
| 273 | } |
||
| 274 | |||
| 275 | if (!isset($_POST['formAuth'])) { |
||
| 276 | $_POST['formAuth'] = $server_info['username']; |
||
| 277 | } |
||
| 278 | |||
| 279 | if (!isset($_POST['formSpc'])) { |
||
| 280 | $_POST['formSpc'] = ''; |
||
| 281 | } |
||
| 282 | |||
| 283 | if (!isset($_POST['formComment'])) { |
||
| 284 | $_POST['formComment'] = ''; |
||
| 285 | } |
||
| 286 | |||
| 287 | // Fetch all users from the database |
||
| 288 | $users = $data->getUsers(); |
||
| 289 | |||
| 290 | $this->printTrail('database'); |
||
| 291 | $this->printTitle($lang['strcreateschema'], 'pg.schema.create'); |
||
| 292 | $this->printMsg($msg); |
||
| 293 | |||
| 294 | echo '<form action="' . \SUBFOLDER . '/src/views/schemas.php" method="post">' . "\n"; |
||
| 295 | echo "<table style=\"width: 100%\">\n"; |
||
| 296 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n"; |
||
| 297 | echo "\t\t<td class=\"data1\"><input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 298 | htmlspecialchars($_POST['formName']), "\" /></td>\n\t</tr>\n"; |
||
| 299 | // Owner |
||
| 300 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strowner']}</th>\n"; |
||
| 301 | echo "\t\t<td class=\"data1\">\n\t\t\t<select name=\"formAuth\">\n"; |
||
| 302 | while (!$users->EOF) { |
||
| 303 | $uname = htmlspecialchars($users->fields['usename']); |
||
| 304 | echo "\t\t\t\t<option value=\"{$uname}\"", |
||
| 305 | ($uname == $_POST['formAuth']) ? ' selected="selected"' : '', ">{$uname}</option>\n"; |
||
| 306 | $users->moveNext(); |
||
| 307 | } |
||
| 308 | echo "\t\t\t</select>\n\t\t</td>\n\t</tr>\n"; |
||
| 309 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n"; |
||
| 310 | echo "\t\t<td class=\"data1\"><textarea name=\"formComment\" rows=\"3\" cols=\"32\">", |
||
| 311 | htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n"; |
||
| 312 | |||
| 313 | echo "</table>\n"; |
||
| 314 | echo "<p>\n"; |
||
| 315 | echo "<input type=\"hidden\" name=\"action\" value=\"create\" />\n"; |
||
| 316 | echo '<input type="hidden" name="database" value="', htmlspecialchars($_REQUEST['database']), "\" />\n"; |
||
| 317 | echo $this->misc->form; |
||
| 318 | echo "<input type=\"submit\" name=\"create\" value=\"{$lang['strcreate']}\" />\n"; |
||
| 319 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n"; |
||
| 320 | echo "</p>\n"; |
||
| 321 | echo "</form>\n"; |
||
| 322 | } |
||
| 323 | |||
| 324 | /** |
||
| 325 | * Actually creates the new schema in the database. |
||
| 326 | */ |
||
| 327 | public function doSaveCreate() |
||
| 328 | { |
||
| 329 | $lang = $this->lang; |
||
| 330 | $data = $this->misc->getDatabaseAccessor(); |
||
| 331 | |||
| 332 | // Check that they've given a name |
||
| 333 | if ('' == $_POST['formName']) { |
||
| 334 | $this->doCreate($lang['strschemaneedsname']); |
||
| 335 | } else { |
||
| 336 | $status = $data->createSchema($_POST['formName'], $_POST['formAuth'], $_POST['formComment']); |
||
| 337 | if (0 == $status) { |
||
| 338 | $this->misc->setReloadBrowser(true); |
||
| 339 | $this->doDefault($lang['strschemacreated']); |
||
| 340 | } else { |
||
| 341 | $this->doCreate($lang['strschemacreatedbad']); |
||
| 342 | } |
||
| 343 | } |
||
| 344 | } |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Display a form to permit editing schema properies. |
||
| 348 | * TODO: permit changing owner. |
||
| 349 | * |
||
| 350 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 351 | */ |
||
| 352 | public function doAlter($msg = '') |
||
| 353 | { |
||
| 354 | $lang = $this->lang; |
||
| 355 | $data = $this->misc->getDatabaseAccessor(); |
||
| 356 | |||
| 357 | $this->printTrail('schema'); |
||
| 358 | $this->printTitle($lang['stralter'], 'pg.schema.alter'); |
||
| 359 | $this->printMsg($msg); |
||
| 360 | |||
| 361 | $schema = $data->getSchemaByName($_REQUEST['schema']); |
||
| 362 | if ($schema->recordCount() > 0) { |
||
| 363 | if (!isset($_POST['comment'])) { |
||
| 364 | $_POST['comment'] = $schema->fields['nspcomment']; |
||
| 365 | } |
||
| 366 | |||
| 367 | if (!isset($_POST['schema'])) { |
||
| 368 | $_POST['schema'] = $_REQUEST['schema']; |
||
| 369 | } |
||
| 370 | |||
| 371 | if (!isset($_POST['name'])) { |
||
| 372 | $_POST['name'] = $_REQUEST['schema']; |
||
| 373 | } |
||
| 374 | |||
| 375 | if (!isset($_POST['owner'])) { |
||
| 376 | $_POST['owner'] = $schema->fields['ownername']; |
||
| 377 | } |
||
| 378 | |||
| 379 | echo '<form action="' . \SUBFOLDER . '/src/views/schemas.php" method="post">' . "\n"; |
||
| 380 | echo "<table>\n"; |
||
| 381 | |||
| 382 | echo "\t<tr>\n"; |
||
| 383 | echo "\t\t<th class=\"data left required\">{$lang['strname']}</th>\n"; |
||
| 384 | echo "\t\t<td class=\"data1\">"; |
||
| 385 | echo "\t\t\t<input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 386 | htmlspecialchars($_POST['name']), "\" />\n"; |
||
| 387 | echo "\t\t</td>\n"; |
||
| 388 | echo "\t</tr>\n"; |
||
| 389 | |||
| 390 | if ($data->hasAlterSchemaOwner()) { |
||
| 391 | $users = $data->getUsers(); |
||
| 392 | echo "<tr><th class=\"data left required\">{$lang['strowner']}</th>\n"; |
||
| 393 | echo '<td class="data2"><select name="owner">'; |
||
| 394 | while (!$users->EOF) { |
||
| 395 | $uname = $users->fields['usename']; |
||
| 396 | echo '<option value="', htmlspecialchars($uname), '"', |
||
| 397 | ($uname == $_POST['owner']) ? ' selected="selected"' : '', '>', htmlspecialchars($uname), "</option>\n"; |
||
| 398 | $users->moveNext(); |
||
| 399 | } |
||
| 400 | echo "</select></td></tr>\n"; |
||
| 401 | } else { |
||
| 402 | echo "<input name=\"owner\" value=\"{$_POST['owner']}\" type=\"hidden\" />"; |
||
| 403 | } |
||
| 404 | |||
| 405 | echo "\t<tr>\n"; |
||
| 406 | echo "\t\t<th class=\"data\">{$lang['strcomment']}</th>\n"; |
||
| 407 | echo "\t\t<td class=\"data1\"><textarea cols=\"32\" rows=\"3\" name=\"comment\">", htmlspecialchars($_POST['comment']), "</textarea></td>\n"; |
||
| 408 | echo "\t</tr>\n"; |
||
| 409 | echo "</table>\n"; |
||
| 410 | echo "<p><input type=\"hidden\" name=\"action\" value=\"alter\" />\n"; |
||
| 411 | echo '<input type="hidden" name="schema" value="', htmlspecialchars($_POST['schema']), "\" />\n"; |
||
| 412 | echo $this->misc->form; |
||
| 413 | echo "<input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n"; |
||
| 414 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 415 | echo "</form>\n"; |
||
| 416 | } else { |
||
| 417 | echo "<p>{$lang['strnodata']}</p>\n"; |
||
| 418 | } |
||
| 419 | } |
||
| 420 | |||
| 421 | /** |
||
| 422 | * Save the form submission containing changes to a schema. |
||
| 423 | * |
||
| 424 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 425 | */ |
||
| 426 | public function doSaveAlter($msg = '') |
||
| 427 | { |
||
| 428 | $lang = $this->lang; |
||
| 429 | $data = $this->misc->getDatabaseAccessor(); |
||
| 430 | |||
| 431 | $status = $data->updateSchema($_POST['schema'], $_POST['comment'], $_POST['name'], $_POST['owner']); |
||
| 432 | if (0 == $status) { |
||
| 433 | $this->misc->setReloadBrowser(true); |
||
| 434 | $this->doDefault($lang['strschemaaltered']); |
||
| 435 | } else { |
||
| 436 | $this->doAlter($lang['strschemaalteredbad']); |
||
| 437 | } |
||
| 438 | } |
||
| 439 | |||
| 440 | /** |
||
| 441 | * Show confirmation of drop and perform actual drop. |
||
| 442 | * |
||
| 443 | * @param mixed $confirm |
||
|
1 ignored issue
–
show
|
|||
| 444 | */ |
||
| 445 | public function doDrop($confirm) |
||
| 446 | { |
||
| 447 | $lang = $this->lang; |
||
| 448 | $data = $this->misc->getDatabaseAccessor(); |
||
| 449 | |||
| 450 | if (empty($_REQUEST['nsp']) && empty($_REQUEST['ma'])) { |
||
| 451 | return $this->doDefault($lang['strspecifyschematodrop']); |
||
| 452 | } |
||
| 453 | |||
| 454 | if ($confirm) { |
||
| 455 | $this->printTrail('schema'); |
||
| 456 | $this->printTitle($lang['strdrop'], 'pg.schema.drop'); |
||
| 457 | |||
| 458 | echo '<form action="' . \SUBFOLDER . '/src/views/schemas.php" method="post">' . "\n"; |
||
| 459 | //If multi drop |
||
| 460 | if (isset($_REQUEST['ma'])) { |
||
| 461 | foreach ($_REQUEST['ma'] as $v) { |
||
| 462 | $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
||
| 463 | echo '<p>', sprintf($lang['strconfdropschema'], $this->misc->printVal($a['nsp'])), "</p>\n"; |
||
| 464 | echo '<input type="hidden" name="nsp[]" value="', htmlspecialchars($a['nsp']), "\" />\n"; |
||
| 465 | } |
||
| 466 | } else { |
||
| 467 | echo '<p>', sprintf($lang['strconfdropschema'], $this->misc->printVal($_REQUEST['nsp'])), "</p>\n"; |
||
| 468 | echo '<input type="hidden" name="nsp" value="', htmlspecialchars($_REQUEST['nsp']), "\" />\n"; |
||
| 469 | } |
||
| 470 | |||
| 471 | echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$lang['strcascade']}</label></p>\n"; |
||
| 472 | echo "<p><input type=\"hidden\" name=\"action\" value=\"drop\" />\n"; |
||
| 473 | echo '<input type="hidden" name="database" value="', htmlspecialchars($_REQUEST['database']), "\" />\n"; |
||
| 474 | echo $this->misc->form; |
||
| 475 | echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n"; |
||
| 476 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 477 | echo "</form>\n"; |
||
| 478 | } else { |
||
| 479 | if (is_array($_POST['nsp'])) { |
||
| 480 | $msg = ''; |
||
| 481 | $status = $data->beginTransaction(); |
||
| 482 | if (0 == $status) { |
||
| 483 | foreach ($_POST['nsp'] as $s) { |
||
| 484 | $status = $data->dropSchema($s, isset($_POST['cascade'])); |
||
| 485 | if (0 == $status) { |
||
| 486 | $msg .= sprintf('%s: %s<br />', htmlentities($s, ENT_QUOTES, 'UTF-8'), $lang['strschemadropped']); |
||
| 487 | } else { |
||
| 488 | $data->endTransaction(); |
||
| 489 | $this->doDefault(sprintf('%s%s: %s<br />', $msg, htmlentities($s, ENT_QUOTES, 'UTF-8'), $lang['strschemadroppedbad'])); |
||
| 490 | |||
| 491 | return; |
||
| 492 | } |
||
| 493 | } |
||
| 494 | } |
||
| 495 | if (0 == $data->endTransaction()) { |
||
| 496 | // Everything went fine, back to the Default page.... |
||
| 497 | $this->misc->setReloadBrowser(true); |
||
| 498 | $this->doDefault($msg); |
||
| 499 | } else { |
||
| 500 | $this->doDefault($lang['strschemadroppedbad']); |
||
| 501 | } |
||
| 502 | } else { |
||
| 503 | $status = $data->dropSchema($_POST['nsp'], isset($_POST['cascade'])); |
||
| 504 | if (0 == $status) { |
||
| 505 | $this->misc->setReloadBrowser(true); |
||
| 506 | $this->doDefault($lang['strschemadropped']); |
||
| 507 | } else { |
||
| 508 | $this->doDefault($lang['strschemadroppedbad']); |
||
| 509 | } |
||
| 510 | } |
||
| 511 | } |
||
| 512 | } |
||
| 513 | |||
| 514 | /** |
||
| 515 | * Displays options for database download. |
||
| 516 | * |
||
| 517 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 518 | */ |
||
| 519 | public function doExport($msg = '') |
||
| 520 | { |
||
| 521 | $lang = $this->lang; |
||
| 522 | $data = $this->misc->getDatabaseAccessor(); |
||
| 523 | |||
| 524 | $this->printTrail('schema'); |
||
| 525 | $this->printTabs('schema', 'export'); |
||
| 526 | $this->printMsg($msg); |
||
| 527 | |||
| 528 | echo '<form action="' . \SUBFOLDER . '/src/views/dbexport.php" method="post">' . "\n"; |
||
| 529 | |||
| 530 | echo "<table>\n"; |
||
| 531 | echo "<tr><th class=\"data\">{$lang['strformat']}</th><th class=\"data\" colspan=\"2\">{$lang['stroptions']}</th></tr>\n"; |
||
| 532 | // Data only |
||
| 533 | echo '<tr><th class="data left" rowspan="2">'; |
||
| 534 | echo "<input type=\"radio\" id=\"what1\" name=\"what\" value=\"dataonly\" checked=\"checked\" /><label for=\"what1\">{$lang['strdataonly']}</label></th>\n"; |
||
| 535 | echo "<td>{$lang['strformat']}</td>\n"; |
||
| 536 | echo "<td><select name=\"d_format\">\n"; |
||
| 537 | echo "<option value=\"copy\">COPY</option>\n"; |
||
| 538 | echo "<option value=\"sql\">SQL</option>\n"; |
||
| 539 | echo "</select>\n</td>\n</tr>\n"; |
||
| 540 | echo "<tr><td><label for=\"d_oids\">{$lang['stroids']}</label></td><td><input type=\"checkbox\" id=\"d_oids\" name=\"d_oids\" /></td>\n</tr>\n"; |
||
| 541 | // Structure only |
||
| 542 | echo "<tr><th class=\"data left\"><input type=\"radio\" id=\"what2\" name=\"what\" value=\"structureonly\" /><label for=\"what2\">{$lang['strstructureonly']}</label></th>\n"; |
||
| 543 | echo "<td><label for=\"s_clean\">{$lang['strdrop']}</label></td><td><input type=\"checkbox\" id=\"s_clean\" name=\"s_clean\" /></td>\n</tr>\n"; |
||
| 544 | // Structure and data |
||
| 545 | echo '<tr><th class="data left" rowspan="3">'; |
||
| 546 | echo "<input type=\"radio\" id=\"what3\" name=\"what\" value=\"structureanddata\" /><label for=\"what3\">{$lang['strstructureanddata']}</label></th>\n"; |
||
| 547 | echo "<td>{$lang['strformat']}</td>\n"; |
||
| 548 | echo "<td><select name=\"sd_format\">\n"; |
||
| 549 | echo "<option value=\"copy\">COPY</option>\n"; |
||
| 550 | echo "<option value=\"sql\">SQL</option>\n"; |
||
| 551 | echo "</select>\n</td>\n</tr>\n"; |
||
| 552 | echo "<tr><td><label for=\"sd_clean\">{$lang['strdrop']}</label></td><td><input type=\"checkbox\" id=\"sd_clean\" name=\"sd_clean\" /></td>\n</tr>\n"; |
||
| 553 | echo "<tr><td><label for=\"sd_oids\">{$lang['stroids']}</label></td><td><input type=\"checkbox\" id=\"sd_oids\" name=\"sd_oids\" /></td>\n</tr>\n"; |
||
| 554 | echo "</table>\n"; |
||
| 555 | |||
| 556 | echo "<h3>{$lang['stroptions']}</h3>\n"; |
||
| 557 | echo "<p><input type=\"radio\" id=\"output1\" name=\"output\" value=\"show\" checked=\"checked\" /><label for=\"output1\">{$lang['strshow']}</label>\n"; |
||
| 558 | echo "<br/><input type=\"radio\" id=\"output2\" name=\"output\" value=\"download\" /><label for=\"output2\">{$lang['strdownload']}</label>\n"; |
||
| 559 | // MSIE cannot download gzip in SSL mode - it's just broken |
||
| 560 | if (!(strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && isset($_SERVER['HTTPS']))) { |
||
| 561 | echo "<br /><input type=\"radio\" id=\"output3\" name=\"output\" value=\"gzipped\" /><label for=\"output3\">{$lang['strdownloadgzipped']}</label>\n"; |
||
| 562 | } |
||
| 563 | echo "</p>\n"; |
||
| 564 | echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n"; |
||
| 565 | echo "<input type=\"hidden\" name=\"subject\" value=\"schema\" />\n"; |
||
| 566 | echo '<input type="hidden" name="database" value="', htmlspecialchars($_REQUEST['database']), "\" />\n"; |
||
| 567 | echo '<input type="hidden" name="schema" value="', htmlspecialchars($_REQUEST['schema']), "\" />\n"; |
||
| 568 | echo $this->misc->form; |
||
| 569 | echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n"; |
||
| 570 | echo "</form>\n"; |
||
| 571 | } |
||
| 572 | } |
||
| 573 |