| Total Complexity | 151 |
| Total Lines | 1233 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like TablesController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use TablesController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 16 | class TablesController extends BaseController |
||
| 17 | { |
||
| 18 | use \PHPPgAdmin\Traits\AdminTrait; |
||
| 19 | public $table_place = 'tables-tables'; |
||
| 20 | public $controller_title = 'strtables'; |
||
| 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 | if ('subtree' == $this->action) { |
||
| 31 | return $this->doSubTree(); |
||
| 32 | } |
||
| 33 | if ('json' == $this->action) { |
||
| 34 | return $this->displayJson(); |
||
| 35 | } |
||
| 36 | |||
| 37 | $header_template = 'header.twig'; |
||
| 38 | $footer_template = 'footer.twig'; |
||
|
|
|||
| 39 | |||
| 40 | ob_start(); |
||
| 41 | |||
| 42 | switch ($this->action) { |
||
| 43 | case 'create': |
||
| 44 | |||
| 45 | if (isset($_POST['cancel'])) { |
||
| 46 | $this->doDefault(); |
||
| 47 | } else { |
||
| 48 | $header_template = 'header_select2.twig'; |
||
| 49 | $this->doCreate(); |
||
| 50 | } |
||
| 51 | |||
| 52 | break; |
||
| 53 | case 'createlike': |
||
| 54 | $header_template = 'header_select2.twig'; |
||
| 55 | $this->doCreateLike(false); |
||
| 56 | |||
| 57 | break; |
||
| 58 | case 'confcreatelike': |
||
| 59 | if (isset($_POST['cancel'])) { |
||
| 60 | $header_template = 'header_datatables.twig'; |
||
| 61 | $this->doDefault(); |
||
| 62 | } else { |
||
| 63 | //$header_template = 'header_select2.twig'; |
||
| 64 | $this->doCreateLike(true); |
||
| 65 | } |
||
| 66 | |||
| 67 | break; |
||
| 68 | case 'selectrows': |
||
| 69 | if (!isset($_POST['cancel'])) { |
||
| 70 | $this->doSelectRows(false); |
||
| 71 | } else { |
||
| 72 | $header_template = 'header_datatables.twig'; |
||
| 73 | $this->doDefault(); |
||
| 74 | } |
||
| 75 | |||
| 76 | break; |
||
| 77 | case 'confselectrows': |
||
| 78 | $this->doSelectRows(true); |
||
| 79 | |||
| 80 | break; |
||
| 81 | case 'insertrow': |
||
| 82 | if (!isset($_POST['cancel'])) { |
||
| 83 | $this->doInsertRow(); |
||
| 84 | } else { |
||
| 85 | $header_template = 'header_datatables.twig'; |
||
| 86 | $this->doDefault(); |
||
| 87 | } |
||
| 88 | |||
| 89 | break; |
||
| 90 | case 'confinsertrow': |
||
| 91 | $this->formInsertRow(); |
||
| 92 | |||
| 93 | break; |
||
| 94 | case 'empty': |
||
| 95 | if (isset($_POST['empty'])) { |
||
| 96 | $this->doEmpty(false); |
||
| 97 | } else { |
||
| 98 | $header_template = 'header_datatables.twig'; |
||
| 99 | $this->doDefault(); |
||
| 100 | } |
||
| 101 | |||
| 102 | break; |
||
| 103 | case 'confirm_empty': |
||
| 104 | $this->doEmpty(true); |
||
| 105 | |||
| 106 | break; |
||
| 107 | case 'drop': |
||
| 108 | if (isset($_POST['drop'])) { |
||
| 109 | $this->doDrop(false); |
||
| 110 | } else { |
||
| 111 | $header_template = 'header_datatables.twig'; |
||
| 112 | $this->doDefault(); |
||
| 113 | } |
||
| 114 | |||
| 115 | break; |
||
| 116 | case 'confirm_drop': |
||
| 117 | $this->doDrop(true); |
||
| 118 | |||
| 119 | break; |
||
| 120 | default: |
||
| 121 | if (false === $this->adminActions($this->action, 'table')) { |
||
| 122 | $header_template = 'header_datatables.twig'; |
||
| 123 | $this->doDefault(); |
||
| 124 | } |
||
| 125 | |||
| 126 | break; |
||
| 127 | } |
||
| 128 | |||
| 129 | $output = ob_get_clean(); |
||
| 130 | |||
| 131 | $this->printHeader($this->headerTitle(), null, true, $header_template); |
||
| 132 | $this->printBody(); |
||
| 133 | |||
| 134 | echo $output; |
||
| 135 | |||
| 136 | return $this->printFooter(); |
||
| 137 | } |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Show default list of tables in the database. |
||
| 141 | * |
||
| 142 | * @param mixed $msg |
||
| 143 | */ |
||
| 144 | public function doDefault($msg = '') |
||
| 145 | { |
||
| 146 | $data = $this->misc->getDatabaseAccessor(); |
||
| 147 | |||
| 148 | $this->printTrail('schema'); |
||
| 149 | $this->printTabs('schema', 'tables'); |
||
| 150 | $this->printMsg($msg); |
||
| 151 | |||
| 152 | $tables = $data->getTables(); |
||
| 153 | |||
| 154 | $columns = [ |
||
| 155 | 'table' => [ |
||
| 156 | 'title' => $this->lang['strtable'], |
||
| 157 | 'field' => Decorator::field('relname'), |
||
| 158 | 'url' => \SUBFOLDER."/redirect/table?{$this->misc->href}&", |
||
| 159 | 'vars' => ['table' => 'relname'], |
||
| 160 | ], |
||
| 161 | 'owner' => [ |
||
| 162 | 'title' => $this->lang['strowner'], |
||
| 163 | 'field' => Decorator::field('relowner'), |
||
| 164 | ], |
||
| 165 | 'tablespace' => [ |
||
| 166 | 'title' => $this->lang['strtablespace'], |
||
| 167 | 'field' => Decorator::field('tablespace'), |
||
| 168 | ], |
||
| 169 | 'tuples' => [ |
||
| 170 | 'title' => $this->lang['strestimatedrowcount'], |
||
| 171 | 'field' => Decorator::field('reltuples'), |
||
| 172 | 'type' => 'numeric', |
||
| 173 | ], |
||
| 174 | 'table_size' => [ |
||
| 175 | 'title' => $this->lang['strsize'], |
||
| 176 | 'field' => Decorator::field('table_size'), |
||
| 177 | ], |
||
| 178 | 'actions' => [ |
||
| 179 | 'title' => $this->lang['stractions'], |
||
| 180 | ], |
||
| 181 | 'comment' => [ |
||
| 182 | 'title' => $this->lang['strcomment'], |
||
| 183 | 'field' => Decorator::field('relcomment'), |
||
| 184 | ], |
||
| 185 | ]; |
||
| 186 | |||
| 187 | $actions = [ |
||
| 188 | 'multiactions' => [ |
||
| 189 | 'keycols' => ['table' => 'relname'], |
||
| 190 | 'url' => 'tables', |
||
| 191 | 'default' => 'analyze', |
||
| 192 | ], |
||
| 193 | 'browse' => [ |
||
| 194 | 'content' => $this->lang['strbrowse'], |
||
| 195 | 'attr' => [ |
||
| 196 | 'href' => [ |
||
| 197 | 'url' => 'display', |
||
| 198 | 'urlvars' => [ |
||
| 199 | 'subject' => 'table', |
||
| 200 | 'return' => 'table', |
||
| 201 | 'table' => Decorator::field('relname'), |
||
| 202 | ], |
||
| 203 | ], |
||
| 204 | ], |
||
| 205 | ], |
||
| 206 | 'select' => [ |
||
| 207 | 'content' => $this->lang['strselect'], |
||
| 208 | 'attr' => [ |
||
| 209 | 'href' => [ |
||
| 210 | 'url' => 'tables', |
||
| 211 | 'urlvars' => [ |
||
| 212 | 'action' => 'confselectrows', |
||
| 213 | 'table' => Decorator::field('relname'), |
||
| 214 | ], |
||
| 215 | ], |
||
| 216 | ], |
||
| 217 | ], |
||
| 218 | 'insert' => [ |
||
| 219 | 'content' => $this->lang['strinsert'], |
||
| 220 | 'attr' => [ |
||
| 221 | 'href' => [ |
||
| 222 | 'url' => 'tables', |
||
| 223 | 'urlvars' => [ |
||
| 224 | 'action' => 'confinsertrow', |
||
| 225 | 'table' => Decorator::field('relname'), |
||
| 226 | ], |
||
| 227 | ], |
||
| 228 | ], |
||
| 229 | ], |
||
| 230 | 'empty' => [ |
||
| 231 | 'multiaction' => 'confirm_empty', |
||
| 232 | 'content' => $this->lang['strempty'], |
||
| 233 | 'attr' => [ |
||
| 234 | 'href' => [ |
||
| 235 | 'url' => 'tables', |
||
| 236 | 'urlvars' => [ |
||
| 237 | 'action' => 'confirm_empty', |
||
| 238 | 'table' => Decorator::field('relname'), |
||
| 239 | ], |
||
| 240 | ], |
||
| 241 | ], |
||
| 242 | ], |
||
| 243 | 'alter' => [ |
||
| 244 | 'content' => $this->lang['stralter'], |
||
| 245 | 'attr' => [ |
||
| 246 | 'href' => [ |
||
| 247 | 'url' => 'tblproperties', |
||
| 248 | 'urlvars' => [ |
||
| 249 | 'action' => 'confirm_alter', |
||
| 250 | 'table' => Decorator::field('relname'), |
||
| 251 | ], |
||
| 252 | ], |
||
| 253 | ], |
||
| 254 | ], |
||
| 255 | 'drop' => [ |
||
| 256 | 'multiaction' => 'confirm_drop', |
||
| 257 | 'content' => $this->lang['strdrop'], |
||
| 258 | 'attr' => [ |
||
| 259 | 'href' => [ |
||
| 260 | 'url' => 'tables', |
||
| 261 | 'urlvars' => [ |
||
| 262 | 'action' => 'confirm_drop', |
||
| 263 | 'table' => Decorator::field('relname'), |
||
| 264 | ], |
||
| 265 | ], |
||
| 266 | ], |
||
| 267 | ], |
||
| 268 | 'vacuum' => [ |
||
| 269 | 'multiaction' => 'confirm_vacuum', |
||
| 270 | 'content' => $this->lang['strvacuum'], |
||
| 271 | 'attr' => [ |
||
| 272 | 'href' => [ |
||
| 273 | 'url' => 'tables', |
||
| 274 | 'urlvars' => [ |
||
| 275 | 'action' => 'confirm_vacuum', |
||
| 276 | 'table' => Decorator::field('relname'), |
||
| 277 | ], |
||
| 278 | ], |
||
| 279 | ], |
||
| 280 | ], |
||
| 281 | 'analyze' => [ |
||
| 282 | 'multiaction' => 'confirm_analyze', |
||
| 283 | 'content' => $this->lang['stranalyze'], |
||
| 284 | 'attr' => [ |
||
| 285 | 'href' => [ |
||
| 286 | 'url' => 'tables', |
||
| 287 | 'urlvars' => [ |
||
| 288 | 'action' => 'confirm_analyze', |
||
| 289 | 'table' => Decorator::field('relname'), |
||
| 290 | ], |
||
| 291 | ], |
||
| 292 | ], |
||
| 293 | ], |
||
| 294 | 'reindex' => [ |
||
| 295 | 'multiaction' => 'confirm_reindex', |
||
| 296 | 'content' => $this->lang['strreindex'], |
||
| 297 | 'attr' => [ |
||
| 298 | 'href' => [ |
||
| 299 | 'url' => 'tables', |
||
| 300 | 'urlvars' => [ |
||
| 301 | 'action' => 'confirm_reindex', |
||
| 302 | 'table' => Decorator::field('relname'), |
||
| 303 | ], |
||
| 304 | ], |
||
| 305 | ], |
||
| 306 | ], |
||
| 307 | //'cluster' TODO ? |
||
| 308 | ]; |
||
| 309 | |||
| 310 | if (!$data->hasTablespaces()) { |
||
| 311 | unset($columns['tablespace']); |
||
| 312 | } |
||
| 313 | |||
| 314 | //\Kint::dump($tables); |
||
| 315 | |||
| 316 | echo $this->printTable($tables, $columns, $actions, $this->table_place, $this->lang['strnotables']); |
||
| 317 | |||
| 318 | $navlinks = [ |
||
| 319 | 'create' => [ |
||
| 320 | 'attr' => [ |
||
| 321 | 'href' => [ |
||
| 322 | 'url' => 'tables', |
||
| 323 | 'urlvars' => [ |
||
| 324 | 'action' => 'create', |
||
| 325 | 'server' => $_REQUEST['server'], |
||
| 326 | 'database' => $_REQUEST['database'], |
||
| 327 | 'schema' => $_REQUEST['schema'], |
||
| 328 | ], |
||
| 329 | ], |
||
| 330 | ], |
||
| 331 | 'content' => $this->lang['strcreatetable'], |
||
| 332 | ], |
||
| 333 | ]; |
||
| 334 | |||
| 335 | if (($tables->recordCount() > 0) && $data->hasCreateTableLike()) { |
||
| 336 | $navlinks['createlike'] = [ |
||
| 337 | 'attr' => [ |
||
| 338 | 'href' => [ |
||
| 339 | 'url' => 'tables', |
||
| 340 | 'urlvars' => [ |
||
| 341 | 'action' => 'createlike', |
||
| 342 | 'server' => $_REQUEST['server'], |
||
| 343 | 'database' => $_REQUEST['database'], |
||
| 344 | 'schema' => $_REQUEST['schema'], |
||
| 345 | ], |
||
| 346 | ], |
||
| 347 | ], |
||
| 348 | 'content' => $this->lang['strcreatetablelike'], |
||
| 349 | ]; |
||
| 350 | } |
||
| 351 | $this->printNavLinks($navlinks, 'tables-tables', get_defined_vars()); |
||
| 352 | } |
||
| 353 | |||
| 354 | public function displayJson() |
||
| 355 | { |
||
| 356 | $data = $this->misc->getDatabaseAccessor(); |
||
| 357 | |||
| 358 | $tables = $data->getTables(); |
||
| 359 | |||
| 360 | $all_tables = $tables->getAll(); |
||
| 361 | |||
| 362 | return $this |
||
| 363 | ->container |
||
| 364 | ->responseobj |
||
| 365 | ->withStatus(200) |
||
| 366 | ->withJson($all_tables); |
||
| 367 | } |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Generate XML for the browser tree. |
||
| 371 | */ |
||
| 372 | public function doTree() |
||
| 373 | { |
||
| 374 | $data = $this->misc->getDatabaseAccessor(); |
||
| 375 | |||
| 376 | //\PC::debug($this->misc->getDatabase(), 'getDatabase'); |
||
| 377 | |||
| 378 | $tables = $data->getTables(); |
||
| 379 | |||
| 380 | $reqvars = $this->misc->getRequestVars('table'); |
||
| 381 | |||
| 382 | $attrs = [ |
||
| 383 | 'text' => Decorator::field('relname'), |
||
| 384 | 'icon' => 'Table', |
||
| 385 | 'iconAction' => Decorator::url('display', $reqvars, ['table' => Decorator::field('relname')]), |
||
| 386 | 'toolTip' => Decorator::field('relcomment'), |
||
| 387 | 'action' => Decorator::redirecturl('redirect', $reqvars, ['table' => Decorator::field('relname')]), |
||
| 388 | 'branch' => Decorator::url('tables', $reqvars, ['action' => 'subtree', 'table' => Decorator::field('relname')]), |
||
| 389 | ]; |
||
| 390 | |||
| 391 | return $this->printTree($tables, $attrs, 'tables'); |
||
| 392 | } |
||
| 393 | |||
| 394 | public function doSubTree() |
||
| 426 | } |
||
| 427 | |||
| 428 | /** |
||
| 429 | * Displays a screen where they can enter a new table. |
||
| 430 | * |
||
| 431 | * @param mixed $msg |
||
| 432 | */ |
||
| 433 | public function doCreate($msg = '') |
||
| 434 | { |
||
| 435 | $data = $this->misc->getDatabaseAccessor(); |
||
| 436 | |||
| 437 | if (!isset($_REQUEST['stage'])) { |
||
| 438 | $_REQUEST['stage'] = 1; |
||
| 439 | $default_with_oids = $data->getDefaultWithOid(); |
||
| 440 | if ('off' == $default_with_oids) { |
||
| 441 | $_REQUEST['withoutoids'] = 'on'; |
||
| 442 | } |
||
| 443 | } |
||
| 444 | |||
| 445 | $this->coalesceArr($_REQUEST, 'name', ''); |
||
| 446 | |||
| 447 | $this->coalesceArr($_REQUEST, 'fields', ''); |
||
| 448 | |||
| 449 | $this->coalesceArr($_REQUEST, 'tblcomment', ''); |
||
| 450 | |||
| 451 | $this->coalesceArr($_REQUEST, 'spcname', ''); |
||
| 452 | |||
| 453 | switch ($_REQUEST['stage']) { |
||
| 454 | case 1: |
||
| 455 | // You are presented with a form in which you describe the table, pick the tablespace and state how many fields it will have |
||
| 456 | // Fetch all tablespaces from the database |
||
| 457 | if ($data->hasTablespaces()) { |
||
| 458 | $tablespaces = $data->getTablespaces(); |
||
| 459 | } |
||
| 460 | |||
| 461 | $this->printTrail('schema'); |
||
| 462 | $this->printTitle($this->lang['strcreatetable'], 'pg.table.create'); |
||
| 463 | $this->printMsg($msg); |
||
| 464 | |||
| 465 | echo '<form action="'.\SUBFOLDER.'/src/views/'.$this->script.'" method="post">'; |
||
| 466 | echo "\n"; |
||
| 467 | echo "<table>\n"; |
||
| 468 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strname']}</th>\n"; |
||
| 469 | echo "\t\t<td class=\"data\"><input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 470 | htmlspecialchars($_REQUEST['name']), "\" /></td>\n\t</tr>\n"; |
||
| 471 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strnumcols']}</th>\n"; |
||
| 472 | echo "\t\t<td class=\"data\"><input name=\"fields\" size=\"5\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 473 | htmlspecialchars($_REQUEST['fields']), "\" /></td>\n\t</tr>\n"; |
||
| 474 | echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['stroptions']}</th>\n"; |
||
| 475 | echo "\t\t<td class=\"data\"><label for=\"withoutoids\"><input type=\"checkbox\" id=\"withoutoids\" name=\"withoutoids\"", isset($_REQUEST['withoutoids']) ? ' checked="checked"' : '', " />WITHOUT OIDS</label></td>\n\t</tr>\n"; |
||
| 476 | |||
| 477 | // Tablespace (if there are any) |
||
| 478 | if ($data->hasTablespaces() && $tablespaces->recordCount() > 0) { |
||
| 479 | echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strtablespace']}</th>\n"; |
||
| 480 | echo "\t\t<td class=\"data1\">\n\t\t\t<select name=\"spcname\">\n"; |
||
| 481 | // Always offer the default (empty) option |
||
| 482 | echo "\t\t\t\t<option value=\"\"", |
||
| 483 | ('' == $_REQUEST['spcname']) ? ' selected="selected"' : '', "></option>\n"; |
||
| 484 | // Display all other tablespaces |
||
| 485 | while (!$tablespaces->EOF) { |
||
| 486 | $spcname = htmlspecialchars($tablespaces->fields['spcname']); |
||
| 487 | echo "\t\t\t\t<option value=\"{$spcname}\"", |
||
| 488 | ($tablespaces->fields['spcname'] == $_REQUEST['spcname']) ? ' selected="selected"' : '', ">{$spcname}</option>\n"; |
||
| 489 | $tablespaces->moveNext(); |
||
| 490 | } |
||
| 491 | echo "\t\t\t</select>\n\t\t</td>\n\t</tr>\n"; |
||
| 492 | } |
||
| 493 | |||
| 494 | echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strcomment']}</th>\n"; |
||
| 495 | echo "\t\t<td><textarea name=\"tblcomment\" rows=\"3\" cols=\"32\">", |
||
| 496 | htmlspecialchars($_REQUEST['tblcomment']), "</textarea></td>\n\t</tr>\n"; |
||
| 497 | |||
| 498 | echo "</table>\n"; |
||
| 499 | echo "<p><input type=\"hidden\" name=\"action\" value=\"create\" />\n"; |
||
| 500 | echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n"; |
||
| 501 | echo $this->misc->form; |
||
| 502 | echo "<input type=\"submit\" value=\"{$this->lang['strnext']}\" />\n"; |
||
| 503 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
| 504 | echo "</form>\n"; |
||
| 505 | |||
| 506 | break; |
||
| 507 | case 2: |
||
| 508 | |||
| 509 | // Check inputs |
||
| 510 | $fields = trim($_REQUEST['fields']); |
||
| 511 | if ('' == trim($_REQUEST['name'])) { |
||
| 512 | $_REQUEST['stage'] = 1; |
||
| 513 | $this->doCreate($this->lang['strtableneedsname']); |
||
| 514 | |||
| 515 | return; |
||
| 516 | } |
||
| 517 | if ('' == $fields || !is_numeric($fields) || $fields != (int) $fields || $fields < 1) { |
||
| 518 | $_REQUEST['stage'] = 1; |
||
| 519 | $this->doCreate($this->lang['strtableneedscols']); |
||
| 520 | |||
| 521 | return; |
||
| 522 | } |
||
| 523 | |||
| 524 | $types = $data->getTypes(true, false, true); |
||
| 525 | $types_for_js = []; |
||
| 526 | |||
| 527 | $this->printTrail('schema'); |
||
| 528 | $this->printTitle($this->lang['strcreatetable'], 'pg.table.create'); |
||
| 529 | $this->printMsg($msg); |
||
| 530 | |||
| 531 | echo '<script src="'.\SUBFOLDER.'/assets/js/tables.js" type="text/javascript"></script>'; |
||
| 532 | echo '<form action="'.\SUBFOLDER."/src/views/tables\" method=\"post\">\n"; |
||
| 533 | |||
| 534 | // Output table header |
||
| 535 | echo "<table>\n"; |
||
| 536 | echo "\t<tr><th colspan=\"2\" class=\"data required\">{$this->lang['strcolumn']}</th><th colspan=\"2\" class=\"data required\">{$this->lang['strtype']}</th>"; |
||
| 537 | echo "<th class=\"data\">{$this->lang['strlength']}</th><th class=\"data\">{$this->lang['strnotnull']}</th>"; |
||
| 538 | echo "<th class=\"data\">{$this->lang['struniquekey']}</th><th class=\"data\">{$this->lang['strprimarykey']}</th>"; |
||
| 539 | echo "<th class=\"data\">{$this->lang['strdefault']}</th><th class=\"data\">{$this->lang['strcomment']}</th></tr>\n"; |
||
| 540 | |||
| 541 | for ($i = 0; $i < $_REQUEST['fields']; ++$i) { |
||
| 542 | if (!isset($_REQUEST['field'][$i])) { |
||
| 543 | $_REQUEST['field'][$i] = ''; |
||
| 544 | } |
||
| 545 | |||
| 546 | if (!isset($_REQUEST['length'][$i])) { |
||
| 547 | $_REQUEST['length'][$i] = ''; |
||
| 548 | } |
||
| 549 | |||
| 550 | if (!isset($_REQUEST['default'][$i])) { |
||
| 551 | $_REQUEST['default'][$i] = ''; |
||
| 552 | } |
||
| 553 | |||
| 554 | if (!isset($_REQUEST['colcomment'][$i])) { |
||
| 555 | $_REQUEST['colcomment'][$i] = ''; |
||
| 556 | } |
||
| 557 | |||
| 558 | echo "\t<tr>\n\t\t<td>", $i + 1, ". </td>\n"; |
||
| 559 | echo "\t\t<td><input name=\"field[{$i}]\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 560 | htmlspecialchars($_REQUEST['field'][$i]), "\" /></td>\n"; |
||
| 561 | echo "\t\t<td>\n\t\t\t<select name=\"type[{$i}]\" class=\"select2\" id=\"types{$i}\" onchange=\"checkLengths(this.options[this.selectedIndex].value,{$i});\">\n"; |
||
| 562 | // Output any "magic" types |
||
| 563 | foreach ($data->extraTypes as $v) { |
||
| 564 | $types_for_js[strtolower($v)] = 1; |
||
| 565 | echo "\t\t\t\t<option value=\"", htmlspecialchars($v), '"', |
||
| 566 | (isset($_REQUEST['type'][$i]) && $_REQUEST['type'][$i] == $v) ? ' selected="selected"' : '', '>', |
||
| 567 | $this->misc->printVal($v), "</option>\n"; |
||
| 568 | } |
||
| 569 | $types->moveFirst(); |
||
| 570 | while (!$types->EOF) { |
||
| 571 | $typname = $types->fields['typname']; |
||
| 572 | $types_for_js[$typname] = 1; |
||
| 573 | echo "\t\t\t\t<option value=\"", htmlspecialchars($typname), '"', |
||
| 574 | (isset($_REQUEST['type'][$i]) && $_REQUEST['type'][$i] == $typname) ? ' selected="selected"' : '', '>', |
||
| 575 | $this->misc->printVal($typname), "</option>\n"; |
||
| 576 | $types->moveNext(); |
||
| 577 | } |
||
| 578 | echo "\t\t\t</select>\n\t\t\n"; |
||
| 579 | if (0 == $i) { |
||
| 580 | // only define js types array once |
||
| 581 | $predefined_size_types = array_intersect($data->predefined_size_types, array_keys($types_for_js)); |
||
| 582 | $escaped_predef_types = []; // the JS escaped array elements |
||
| 583 | foreach ($predefined_size_types as $value) { |
||
| 584 | $escaped_predef_types[] = "'{$value}'"; |
||
| 585 | } |
||
| 586 | echo '<script type="text/javascript">predefined_lengths = new Array('.implode(',', $escaped_predef_types).");</script>\n\t</td>"; |
||
| 587 | } |
||
| 588 | |||
| 589 | // Output array type selector |
||
| 590 | echo "\t\t<td>\n\t\t\t<select name=\"array[{$i}]\">\n"; |
||
| 591 | echo "\t\t\t\t<option value=\"\"", (isset($_REQUEST['array'][$i]) && $_REQUEST['array'][$i] == '') ? ' selected="selected"' : '', "></option>\n"; |
||
| 592 | echo "\t\t\t\t<option value=\"[]\"", (isset($_REQUEST['array'][$i]) && $_REQUEST['array'][$i] == '[]') ? ' selected="selected"' : '', ">[ ]</option>\n"; |
||
| 593 | echo "\t\t\t</select>\n\t\t</td>\n"; |
||
| 594 | |||
| 595 | echo "\t\t<td><input name=\"length[{$i}]\" id=\"lengths{$i}\" size=\"10\" value=\"", |
||
| 596 | htmlspecialchars($_REQUEST['length'][$i]), "\" /></td>\n"; |
||
| 597 | echo "\t\t<td><input type=\"checkbox\" name=\"notnull[{$i}]\"", (isset($_REQUEST['notnull'][$i])) ? ' checked="checked"' : '', " /></td>\n"; |
||
| 598 | echo "\t\t<td style=\"text-align: center\"><input type=\"checkbox\" name=\"uniquekey[{$i}]\"" |
||
| 599 | .(isset($_REQUEST['uniquekey'][$i]) ? ' checked="checked"' : '')." /></td>\n"; |
||
| 600 | echo "\t\t<td style=\"text-align: center\"><input type=\"checkbox\" name=\"primarykey[{$i}]\" " |
||
| 601 | .(isset($_REQUEST['primarykey'][$i]) ? ' checked="checked"' : '') |
||
| 602 | ." /></td>\n"; |
||
| 603 | echo "\t\t<td><input name=\"default[{$i}]\" size=\"20\" value=\"", |
||
| 604 | htmlspecialchars($_REQUEST['default'][$i]), "\" /></td>\n"; |
||
| 605 | echo "\t\t<td><input name=\"colcomment[{$i}]\" size=\"40\" value=\"", |
||
| 606 | htmlspecialchars($_REQUEST['colcomment'][$i]), "\" /> |
||
| 607 | <script type=\"text/javascript\">checkLengths(document.getElementById('types{$i}').value,{$i});</script> |
||
| 608 | </td>\n\t</tr>\n"; |
||
| 609 | } |
||
| 610 | echo "</table>\n"; |
||
| 611 | echo "<p><input type=\"hidden\" name=\"action\" value=\"create\" />\n"; |
||
| 612 | echo "<input type=\"hidden\" name=\"stage\" value=\"3\" />\n"; |
||
| 613 | echo $this->misc->form; |
||
| 614 | echo '<input type="hidden" name="name" value="', htmlspecialchars($_REQUEST['name']), "\" />\n"; |
||
| 615 | echo '<input type="hidden" name="fields" value="', htmlspecialchars($_REQUEST['fields']), "\" />\n"; |
||
| 616 | if (isset($_REQUEST['withoutoids'])) { |
||
| 617 | echo "<input type=\"hidden\" name=\"withoutoids\" value=\"true\" />\n"; |
||
| 618 | } |
||
| 619 | echo '<input type="hidden" name="tblcomment" value="', htmlspecialchars($_REQUEST['tblcomment']), "\" />\n"; |
||
| 620 | if (isset($_REQUEST['spcname'])) { |
||
| 621 | echo '<input type="hidden" name="spcname" value="', htmlspecialchars($_REQUEST['spcname']), "\" />\n"; |
||
| 622 | } |
||
| 623 | echo "<input type=\"submit\" value=\"{$this->lang['strcreate']}\" />\n"; |
||
| 624 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
| 625 | echo "</form>\n"; |
||
| 626 | |||
| 627 | break; |
||
| 628 | case 3: |
||
| 629 | |||
| 630 | $this->coalesceArr($_REQUEST, 'notnull', []); |
||
| 631 | |||
| 632 | $this->coalesceArr($_REQUEST, 'uniquekey', []); |
||
| 633 | |||
| 634 | $this->coalesceArr($_REQUEST, 'primarykey', []); |
||
| 635 | |||
| 636 | $this->coalesceArr($_REQUEST, 'length', []); |
||
| 637 | |||
| 638 | // Default tablespace to null if it isn't set |
||
| 639 | $this->coalesceArr($_REQUEST, 'spcname', null); |
||
| 640 | |||
| 641 | // Check inputs |
||
| 642 | $fields = trim($_REQUEST['fields']); |
||
| 643 | if ('' == trim($_REQUEST['name'])) { |
||
| 644 | $_REQUEST['stage'] = 1; |
||
| 645 | $this->doCreate($this->lang['strtableneedsname']); |
||
| 646 | |||
| 647 | return; |
||
| 648 | } |
||
| 649 | if ('' == $fields || !is_numeric($fields) || $fields != (int) $fields || $fields <= 0) { |
||
| 650 | $_REQUEST['stage'] = 1; |
||
| 651 | $this->doCreate($this->lang['strtableneedscols']); |
||
| 652 | |||
| 653 | return; |
||
| 654 | } |
||
| 655 | |||
| 656 | $status = $data->createTable( |
||
| 657 | $_REQUEST['name'], |
||
| 658 | $_REQUEST['fields'], |
||
| 659 | $_REQUEST['field'], |
||
| 660 | $_REQUEST['type'], |
||
| 661 | $_REQUEST['array'], |
||
| 662 | $_REQUEST['length'], |
||
| 663 | $_REQUEST['notnull'], |
||
| 664 | $_REQUEST['default'], |
||
| 665 | isset($_REQUEST['withoutoids']), |
||
| 666 | $_REQUEST['colcomment'], |
||
| 667 | $_REQUEST['tblcomment'], |
||
| 668 | $_REQUEST['spcname'], |
||
| 669 | $_REQUEST['uniquekey'], |
||
| 670 | $_REQUEST['primarykey'] |
||
| 671 | ); |
||
| 672 | |||
| 673 | if (0 == $status) { |
||
| 674 | $this->misc->setReloadBrowser(true); |
||
| 675 | |||
| 676 | return $this->doDefault($this->lang['strtablecreated']); |
||
| 677 | } |
||
| 678 | if ($status == -1) { |
||
| 679 | $_REQUEST['stage'] = 2; |
||
| 680 | $this->doCreate($this->lang['strtableneedsfield']); |
||
| 681 | |||
| 682 | return; |
||
| 683 | } |
||
| 684 | $_REQUEST['stage'] = 2; |
||
| 685 | $this->doCreate($this->lang['strtablecreatedbad']); |
||
| 686 | |||
| 687 | return; |
||
| 688 | break; |
||
| 689 | default: |
||
| 690 | echo "<p>{$this->lang['strinvalidparam']}</p>\n"; |
||
| 691 | } |
||
| 692 | } |
||
| 693 | |||
| 694 | /** |
||
| 695 | * Dsiplay a screen where user can create a table from an existing one. |
||
| 696 | * We don't have to check if pg supports schema cause create table like |
||
| 697 | * is available under pg 7.4+ which has schema. |
||
| 698 | * |
||
| 699 | * @param mixed $confirm |
||
| 700 | * @param mixed $msg |
||
| 701 | */ |
||
| 702 | public function doCreateLike($confirm, $msg = '') |
||
| 808 | } |
||
| 809 | } |
||
| 810 | |||
| 811 | /** |
||
| 812 | * Ask for select parameters and perform select. |
||
| 813 | * |
||
| 814 | * @param mixed $confirm |
||
| 815 | * @param mixed $msg |
||
| 816 | */ |
||
| 817 | public function doSelectRows($confirm, $msg = '') |
||
| 935 | } |
||
| 936 | } |
||
| 937 | |||
| 938 | /** |
||
| 939 | * Ask for insert parameters and then actually insert row. |
||
| 940 | * |
||
| 941 | * @param mixed $msg |
||
| 942 | */ |
||
| 943 | public function formInsertRow($msg = '') |
||
| 944 | { |
||
| 945 | $data = $this->misc->getDatabaseAccessor(); |
||
| 946 | |||
| 947 | $this->printTrail('table'); |
||
| 948 | $this->printTabs('table', 'insert'); |
||
| 949 | |||
| 950 | $this->printMsg($msg); |
||
| 951 | |||
| 952 | $attrs = $data->getTableAttributes($_REQUEST['table']); |
||
| 953 | |||
| 954 | if (('disable' != $this->conf['autocomplete'])) { |
||
| 955 | $fksprops = $this->misc->getAutocompleteFKProperties($_REQUEST['table']); |
||
| 956 | if (false !== $fksprops) { |
||
| 957 | echo $fksprops['code']; |
||
| 958 | } |
||
| 959 | } else { |
||
| 960 | $fksprops = false; |
||
| 961 | } |
||
| 962 | $this->coalesceArr($_REQUEST, 'values', []); |
||
| 963 | $this->coalesceArr($_REQUEST, 'nulls', []); |
||
| 964 | $this->coalesceArr($_REQUEST, 'format', []); |
||
| 965 | |||
| 966 | echo '<form action="'.\SUBFOLDER."/src/views/tables\" method=\"post\" id=\"ac_form\">\n"; |
||
| 967 | if ($attrs->recordCount() > 0) { |
||
| 968 | echo "<table>\n"; |
||
| 969 | |||
| 970 | // Output table header |
||
| 971 | echo "<tr><th class=\"data\">{$this->lang['strcolumn']}</th><th class=\"data\">{$this->lang['strtype']}</th>"; |
||
| 972 | echo "<th class=\"data\">{$this->lang['strformat']}</th>"; |
||
| 973 | echo "<th class=\"data\">{$this->lang['strnull']}</th><th class=\"data\">{$this->lang['strvalue']}</th></tr>"; |
||
| 974 | |||
| 975 | $i = 0; |
||
| 976 | $fields = []; |
||
| 977 | while (!$attrs->EOF) { |
||
| 978 | $fields[$attrs->fields['attnum']] = $attrs->fields['attname']; |
||
| 979 | $attrs->fields['attnotnull'] = $data->phpBool($attrs->fields['attnotnull']); |
||
| 980 | // Set up default value if there isn't one already |
||
| 981 | if (!isset($_REQUEST['values'][$attrs->fields['attnum']])) { |
||
| 982 | $_REQUEST['values'][$attrs->fields['attnum']] = $attrs->fields['adsrc']; |
||
| 983 | if ($attrs->fields['adsrc'] === null && !$attrs->fields['attnotnull']) { |
||
| 984 | $_REQUEST['nulls'][$attrs->fields['attnum']] = true; |
||
| 985 | } |
||
| 986 | } |
||
| 987 | |||
| 988 | // Default format to 'VALUE' if there is no default, |
||
| 989 | // otherwise default to 'EXPRESSION' |
||
| 990 | if (!isset($_REQUEST['format'][$attrs->fields['attnum']])) { |
||
| 991 | $_REQUEST['format'][$attrs->fields['attnum']] = (null === $attrs->fields['adsrc']) ? 'VALUE' : 'EXPRESSION'; |
||
| 992 | } |
||
| 993 | |||
| 994 | // Continue drawing row |
||
| 995 | $id = (0 == ($i % 2) ? '1' : '2'); |
||
| 996 | echo "<tr class=\"data{$id}\">\n"; |
||
| 997 | echo '<td style="white-space:nowrap;">', $this->misc->printVal($attrs->fields['attname']), '</td>'; |
||
| 998 | echo "<td style=\"white-space:nowrap;\">\n"; |
||
| 999 | echo $this->misc->printVal($data->formatType($attrs->fields['type'], $attrs->fields['atttypmod'])); |
||
| 1000 | echo "<input type=\"hidden\" name=\"types[{$attrs->fields['attnum']}]\" value=\"", |
||
| 1001 | htmlspecialchars($attrs->fields['type']), '" /></td>'; |
||
| 1002 | echo "<td style=\"white-space:nowrap;\">\n"; |
||
| 1003 | echo "<select name=\"format[{$attrs->fields['attnum']}]\">\n"; |
||
| 1004 | echo '<option value="VALUE"', ($_REQUEST['format'][$attrs->fields['attnum']] == 'VALUE') ? ' selected="selected"' : '', ">{$this->lang['strvalue']}</option>\n"; |
||
| 1005 | echo '<option value="EXPRESSION"', ($_REQUEST['format'][$attrs->fields['attnum']] == 'EXPRESSION') ? ' selected="selected"' : '', ">{$this->lang['strexpression']}</option>\n"; |
||
| 1006 | echo "</select>\n</td>\n"; |
||
| 1007 | echo '<td style="white-space:nowrap;">'; |
||
| 1008 | // Output null box if the column allows nulls (doesn't look at CHECKs or ASSERTIONS) |
||
| 1009 | if (!$attrs->fields['attnotnull']) { |
||
| 1010 | echo "<label><span><input type=\"checkbox\" class=\"nullcheckbox\" name=\"nulls[{$attrs->fields['attnum']}]\""; |
||
| 1011 | echo isset($_REQUEST['nulls'][$attrs->fields['attnum']]) ? ' checked="checked"' : ''; |
||
| 1012 | echo ' /></span></label>'; |
||
| 1013 | } |
||
| 1014 | echo '</td>'; |
||
| 1015 | |||
| 1016 | echo "<td id=\"row_att_{$attrs->fields['attnum']}\" style=\"white-space:nowrap;\">"; |
||
| 1017 | |||
| 1018 | if ((false !== $fksprops) && isset($fksprops['byfield'][$attrs->fields['attnum']])) { |
||
| 1019 | echo $data->printField( |
||
| 1020 | "values[{$attrs->fields['attnum']}]", |
||
| 1021 | $_REQUEST['values'][$attrs->fields['attnum']], |
||
| 1022 | 'fktype' /*force FK*/, |
||
| 1023 | [ |
||
| 1024 | 'id' => "attr_{$attrs->fields['attnum']}", |
||
| 1025 | 'autocomplete' => 'off', |
||
| 1026 | 'class' => 'insert_row_input', |
||
| 1027 | ] |
||
| 1028 | ); |
||
| 1029 | } else { |
||
| 1030 | echo $data->printField("values[{$attrs->fields['attnum']}]", $_REQUEST['values'][$attrs->fields['attnum']], $attrs->fields['type'], ['class' => 'insert_row_input']); |
||
| 1031 | } |
||
| 1032 | echo "</td>\n"; |
||
| 1033 | echo "</tr>\n"; |
||
| 1034 | ++$i; |
||
| 1035 | $attrs->moveNext(); |
||
| 1036 | } |
||
| 1037 | echo "</table>\n"; |
||
| 1038 | |||
| 1039 | if (!isset($_SESSION['counter'])) { |
||
| 1040 | $_SESSION['counter'] = 0; |
||
| 1041 | } |
||
| 1042 | |||
| 1043 | echo "<input type=\"hidden\" name=\"action\" value=\"insertrow\" />\n"; |
||
| 1044 | echo '<input type="hidden" name="fields" value="', htmlentities(serialize($fields), ENT_QUOTES, 'UTF-8'), "\" />\n"; |
||
| 1045 | echo '<input type="hidden" name="protection_counter" value="'.$_SESSION['counter']."\" />\n"; |
||
| 1046 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), "\" />\n"; |
||
| 1047 | echo "<p><input type=\"submit\" name=\"insert\" value=\"{$this->lang['strinsert']}\" />\n"; |
||
| 1048 | echo "<input type=\"submit\" name=\"insertandrepeat\" accesskey=\"r\" value=\"{$this->lang['strinsertandrepeat']}\" />\n"; |
||
| 1049 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />\n"; |
||
| 1050 | |||
| 1051 | if (false !== $fksprops) { |
||
| 1052 | if ('default off' != $this->conf['autocomplete']) { |
||
| 1053 | echo "<input type=\"checkbox\" id=\"no_ac\" value=\"1\" checked=\"checked\" /><label for=\"no_ac\">{$this->lang['strac']}</label>\n"; |
||
| 1054 | } else { |
||
| 1055 | echo "<input type=\"checkbox\" id=\"no_ac\" value=\"0\" /><label for=\"no_ac\">{$this->lang['strac']}</label>\n"; |
||
| 1056 | } |
||
| 1057 | } |
||
| 1058 | echo "</p>\n"; |
||
| 1059 | } else { |
||
| 1060 | echo "<p>{$this->lang['strnofieldsforinsert']}</p>\n"; |
||
| 1061 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />\n"; |
||
| 1062 | } |
||
| 1063 | echo $this->misc->form; |
||
| 1064 | echo "</form>\n"; |
||
| 1065 | echo '<script src="'.\SUBFOLDER.'/assets/js/insert_or_edit_row.js" type="text/javascript"></script>'; |
||
| 1066 | } |
||
| 1067 | |||
| 1068 | /** |
||
| 1069 | * Performs insertion of row according to request parameters. |
||
| 1070 | */ |
||
| 1071 | public function doInsertRow() |
||
| 1072 | { |
||
| 1073 | $data = $this->misc->getDatabaseAccessor(); |
||
| 1074 | |||
| 1075 | $this->coalesceArr($_POST, 'values', []); |
||
| 1076 | |||
| 1077 | $this->coalesceArr($_POST, 'nulls', []); |
||
| 1078 | |||
| 1079 | $_POST['fields'] = unserialize(htmlspecialchars_decode($_POST['fields'], ENT_QUOTES)); |
||
| 1080 | |||
| 1081 | if ($_SESSION['counter']++ == $_POST['protection_counter']) { |
||
| 1082 | $status = $data->insertRow($_POST['table'], $_POST['fields'], $_POST['values'], $_POST['nulls'], $_POST['format'], $_POST['types']); |
||
| 1083 | if (0 == $status) { |
||
| 1084 | if (isset($_POST['insert'])) { |
||
| 1085 | return $this->doDefault($this->lang['strrowinserted']); |
||
| 1086 | } |
||
| 1087 | $_REQUEST['values'] = []; |
||
| 1088 | $_REQUEST['nulls'] = []; |
||
| 1089 | |||
| 1090 | return $this->formInsertRow($this->lang['strrowinserted']); |
||
| 1091 | } |
||
| 1092 | |||
| 1093 | return $this->formInsertRow($this->lang['strrowinsertedbad']); |
||
| 1094 | } |
||
| 1095 | |||
| 1096 | return $this->formInsertRow($this->lang['strrowduplicate']); |
||
| 1097 | } |
||
| 1098 | |||
| 1099 | /** |
||
| 1100 | * Show confirmation of empty and perform actual empty. |
||
| 1101 | * |
||
| 1102 | * @param mixed $confirm |
||
| 1103 | */ |
||
| 1104 | public function doEmpty($confirm) |
||
| 1105 | { |
||
| 1106 | $data = $this->misc->getDatabaseAccessor(); |
||
| 1107 | |||
| 1108 | if (empty($_REQUEST['table']) && empty($_REQUEST['ma'])) { |
||
| 1109 | return $this->doDefault($this->lang['strspecifytabletoempty']); |
||
| 1110 | } |
||
| 1111 | |||
| 1112 | if ($confirm) { |
||
| 1113 | if (isset($_REQUEST['ma'])) { |
||
| 1114 | $this->printTrail('schema'); |
||
| 1115 | $this->printTitle($this->lang['strempty'], 'pg.table.empty'); |
||
| 1116 | |||
| 1117 | echo '<form action="'.\SUBFOLDER."/src/views/tables\" method=\"post\">\n"; |
||
| 1118 | foreach ($_REQUEST['ma'] as $v) { |
||
| 1119 | $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
||
| 1120 | echo '<p>'.sprintf($this->lang['strconfemptytable'], $this->misc->printVal($a['table'])); |
||
| 1121 | |||
| 1122 | echo "</p>\n"; |
||
| 1123 | printf('<input type="hidden" name="table[]" value="%s" />', htmlspecialchars($a['table'])); |
||
| 1124 | } // END mutli empty |
||
| 1125 | } else { |
||
| 1126 | $this->printTrail('table'); |
||
| 1127 | $this->printTitle($this->lang['strempty'], 'pg.table.empty'); |
||
| 1128 | |||
| 1129 | echo '<p>', sprintf($this->lang['strconfemptytable'], $this->misc->printVal($_REQUEST['table'])), "</p>\n"; |
||
| 1130 | |||
| 1131 | echo '<form action="'.\SUBFOLDER."/src/views/tables\" method=\"post\">\n"; |
||
| 1132 | |||
| 1133 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), "\" />\n"; |
||
| 1134 | // END not mutli empty |
||
| 1135 | } |
||
| 1136 | echo "<input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$this->lang['strcascade']}</label>"; |
||
| 1137 | echo "<input type=\"hidden\" name=\"action\" value=\"empty\" />\n"; |
||
| 1138 | echo $this->misc->form; |
||
| 1139 | echo "<input type=\"submit\" name=\"empty\" value=\"{$this->lang['strempty']}\" /> <input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />\n"; |
||
| 1140 | echo "</form>\n"; // END if confirm |
||
| 1141 | } else { |
||
| 1142 | // Do Empty |
||
| 1143 | $msg = ''; |
||
| 1144 | if (is_array($_REQUEST['table'])) { |
||
| 1145 | foreach ($_REQUEST['table'] as $t) { |
||
| 1146 | list($status, $sql) = $data->emptyTable($t, isset($_POST['cascade'])); |
||
| 1147 | if (0 == $status) { |
||
| 1148 | $msg .= sprintf('%s<br />', $sql); |
||
| 1149 | $msg .= sprintf('%s: %s<br />', htmlentities($t, ENT_QUOTES, 'UTF-8'), $this->lang['strtableemptied']); |
||
| 1150 | } else { |
||
| 1151 | $this->doDefault(sprintf('%s%s: %s<br />', $msg, htmlentities($t, ENT_QUOTES, 'UTF-8'), $this->lang['strtableemptiedbad'])); |
||
| 1152 | |||
| 1153 | return; |
||
| 1154 | } |
||
| 1155 | } |
||
| 1156 | $this->doDefault($msg); // END mutli empty |
||
| 1157 | } else { |
||
| 1158 | list($status, $sql) = $data->emptyTable($_POST['table'], isset($_POST['cascade'])); |
||
| 1159 | if (0 == $status) { |
||
| 1160 | $msg .= sprintf('%s<br />', $sql); |
||
| 1161 | $msg .= sprintf('%s: %s<br />', htmlentities($_POST['table'], ENT_QUOTES, 'UTF-8'), $this->lang['strtableemptied']); |
||
| 1162 | |||
| 1163 | return $this->doDefault($msg); |
||
| 1164 | } |
||
| 1165 | |||
| 1166 | return $this->doDefault($sql.'<br>'.$this->lang['strtableemptiedbad']); |
||
| 1167 | // END not mutli empty |
||
| 1168 | } |
||
| 1169 | // END do Empty |
||
| 1170 | } |
||
| 1171 | } |
||
| 1172 | |||
| 1173 | /** |
||
| 1174 | * Show confirmation of drop and perform actual drop. |
||
| 1175 | * |
||
| 1176 | * @param mixed $confirm |
||
| 1177 | */ |
||
| 1178 | public function doDrop($confirm) |
||
| 1249 | // END DROP |
||
| 1250 | } |
||
| 1251 | } |
||
| 1252 | |||
| 1255 |