| Total Complexity | 91 |
| Total Lines | 864 |
| Duplicated Lines | 8.22 % |
| Changes | 0 | ||
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like TblpropertiesController 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 TblpropertiesController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | class TblpropertiesController extends BaseController |
||
| 11 | { |
||
| 12 | public $_name = 'TblpropertiesController'; |
||
| 13 | |||
| 14 | public function render() |
||
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Show default list of columns in the table |
||
| 93 | */ |
||
| 94 | public function doDefault($msg = '') |
||
| 95 | { |
||
| 96 | $conf = $this->conf; |
||
| 97 | $misc = $this->misc; |
||
| 98 | $lang = $this->lang; |
||
| 99 | $data = $misc->getDatabaseAccessor(); |
||
| 100 | |||
| 101 | $attPre = function (&$rowdata, $actions) use ($data) { |
||
| 102 | $rowdata->fields['+type'] = $data->formatType($rowdata->fields['type'], $rowdata->fields['atttypmod']); |
||
| 103 | $attname = $rowdata->fields['attname']; |
||
| 104 | $table = $_REQUEST['table']; |
||
| 105 | $data->fieldClean($attname); |
||
| 106 | $data->fieldClean($table); |
||
| 107 | |||
| 108 | $actions['browse']['attr']['href']['urlvars']['query'] = "SELECT \"{$attname}\", count(*) AS \"count\" |
||
| 109 | FROM \"{$table}\" GROUP BY \"{$attname}\" ORDER BY \"{$attname}\""; |
||
| 110 | |||
| 111 | return $actions; |
||
| 112 | }; |
||
| 113 | |||
| 114 | $cstrRender = function ($s, $p) use ($misc, $data) { |
||
| 115 | $str = ''; |
||
| 116 | foreach ($p['keys'] as $k => $c) { |
||
| 117 | if (is_null($p['keys'][$k]['consrc'])) { |
||
| 118 | $atts = $data->getAttributeNames($_REQUEST['table'], explode(' ', $p['keys'][$k]['indkey'])); |
||
| 119 | $c['consrc'] = ($c['contype'] == 'u' ? 'UNIQUE (' : 'PRIMARY KEY (') . join(',', $atts) . ')'; |
||
| 120 | } |
||
| 121 | |||
| 122 | if ($c['p_field'] == $s) { |
||
| 123 | switch ($c['contype']) { |
||
| 124 | View Code Duplication | case 'p': |
|
| 125 | $str .= '<a href="constraints.php?' . $misc->href . '&table=' . urlencode($c['p_table']) . '&schema=' . urlencode($c['p_schema']) . '"><img src="' . |
||
| 126 | $misc->icon('PrimaryKey') . '" alt="[pk]" title="' . htmlentities($c['consrc'], ENT_QUOTES, 'UTF-8') . '" /></a>'; |
||
| 127 | break; |
||
| 128 | View Code Duplication | case 'f': |
|
| 129 | $str .= '<a href="tblproperties.php?' . $misc->href . '&table=' . urlencode($c['f_table']) . '&schema=' . urlencode($c['f_schema']) . '"><img src="' . |
||
| 130 | $misc->icon('ForeignKey') . '" alt="[fk]" title="' . htmlentities($c['consrc'], ENT_QUOTES, 'UTF-8') . '" /></a>'; |
||
| 131 | break; |
||
| 132 | View Code Duplication | case 'u': |
|
| 133 | $str .= '<a href="constraints.php?' . $misc->href . '&table=' . urlencode($c['p_table']) . '&schema=' . urlencode($c['p_schema']) . '"><img src="' . |
||
| 134 | $misc->icon('UniqueConstraint') . '" alt="[uniq]" title="' . htmlentities($c['consrc'], ENT_QUOTES, 'UTF-8') . '" /></a>'; |
||
| 135 | break; |
||
| 136 | View Code Duplication | case 'c': |
|
| 137 | $str .= '<a href="constraints.php?' . $misc->href . '&table=' . urlencode($c['p_table']) . '&schema=' . urlencode($c['p_schema']) . '"><img src="' . |
||
| 138 | $misc->icon('CheckConstraint') . '" alt="[check]" title="' . htmlentities($c['consrc'], ENT_QUOTES, 'UTF-8') . '" /></a>'; |
||
| 139 | } |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | return $str; |
||
| 144 | }; |
||
| 145 | |||
| 146 | $this->printTrail('table'); |
||
| 147 | $this->printTabs('table', 'columns'); |
||
| 148 | $this->printMsg($msg); |
||
| 149 | |||
| 150 | // Get table |
||
| 151 | $tdata = $data->getTable($_REQUEST['table']); |
||
| 152 | // Get columns |
||
| 153 | $attrs = $data->getTableAttributes($_REQUEST['table']); |
||
| 154 | // Get constraints keys |
||
| 155 | $ck = $data->getConstraintsWithFields($_REQUEST['table']); |
||
| 156 | |||
| 157 | // Show comment if any |
||
| 158 | if ($tdata->fields['relcomment'] !== null) { |
||
| 159 | echo '<p class="comment">', $misc->printVal($tdata->fields['relcomment']), "</p>\n"; |
||
| 160 | } |
||
| 161 | |||
| 162 | $columns = [ |
||
| 163 | 'column' => [ |
||
| 164 | 'title' => $lang['strcolumn'], |
||
| 165 | 'field' => Decorator::field('attname'), |
||
| 166 | 'url' => "colproperties.php?subject=column&{$misc->href}&table=" . urlencode($_REQUEST['table']) . '&', |
||
| 167 | 'vars' => ['column' => 'attname'], |
||
| 168 | ], |
||
| 169 | 'type' => [ |
||
| 170 | 'title' => $lang['strtype'], |
||
| 171 | 'field' => Decorator::field('+type'), |
||
| 172 | ], |
||
| 173 | 'notnull' => [ |
||
| 174 | 'title' => $lang['strnotnull'], |
||
| 175 | 'field' => Decorator::field('attnotnull'), |
||
| 176 | 'type' => 'bool', |
||
| 177 | 'params' => ['true' => 'NOT NULL', 'false' => ''], |
||
| 178 | ], |
||
| 179 | 'default' => [ |
||
| 180 | 'title' => $lang['strdefault'], |
||
| 181 | 'field' => Decorator::field('adsrc'), |
||
| 182 | ], |
||
| 183 | 'keyprop' => [ |
||
| 184 | 'title' => $lang['strconstraints'], |
||
| 185 | 'class' => 'constraint_cell', |
||
| 186 | 'field' => Decorator::field('attname'), |
||
| 187 | 'type' => 'callback', |
||
| 188 | 'params' => [ |
||
| 189 | 'function' => $cstrRender, |
||
| 190 | 'keys' => $ck->getArray(), |
||
| 191 | ], |
||
| 192 | ], |
||
| 193 | 'actions' => [ |
||
| 194 | 'title' => $lang['stractions'], |
||
| 195 | ], |
||
| 196 | 'comment' => [ |
||
| 197 | 'title' => $lang['strcomment'], |
||
| 198 | 'field' => Decorator::field('comment'), |
||
| 199 | ], |
||
| 200 | ]; |
||
| 201 | |||
| 202 | $actions = [ |
||
| 203 | 'browse' => [ |
||
| 204 | 'title' => $lang['strbrowse'], |
||
| 205 | 'url' => "display.php?{$misc->href}&subject=column&return=table&table=" . urlencode($_REQUEST['table']) . '&', |
||
| 206 | 'vars' => ['column' => 'attname'], |
||
| 207 | ], |
||
| 208 | 'alter' => [ |
||
| 209 | 'title' => $lang['stralter'], |
||
| 210 | 'url' => "colproperties.php?action=properties&{$misc->href}&table=" . urlencode($_REQUEST['table']) . '&', |
||
| 211 | 'vars' => ['column' => 'attname'], |
||
| 212 | ], |
||
| 213 | 'privileges' => [ |
||
| 214 | 'title' => $lang['strprivileges'], |
||
| 215 | 'url' => "privileges.php?subject=column&{$misc->href}&table=" . urlencode($_REQUEST['table']) . '&', |
||
| 216 | 'vars' => ['column' => 'attname'], |
||
| 217 | ], |
||
| 218 | 'drop' => [ |
||
| 219 | 'title' => $lang['strdrop'], |
||
| 220 | 'url' => "tblproperties.php?action=confirm_drop&{$misc->href}&table=" . urlencode($_REQUEST['table']) . '&', |
||
| 221 | 'vars' => ['column' => 'attname'], |
||
| 222 | ], |
||
| 223 | ]; |
||
| 224 | |||
| 225 | $actions = [ |
||
| 226 | 'browse' => [ |
||
| 227 | 'content' => $lang['strbrowse'], |
||
| 228 | 'attr' => [ |
||
| 229 | 'href' => [ |
||
| 230 | 'url' => 'display.php', |
||
| 231 | 'urlvars' => [ |
||
| 232 | 'table' => $_REQUEST['table'], |
||
| 233 | 'subject' => 'column', |
||
| 234 | 'return' => 'table', |
||
| 235 | 'column' => Decorator::field('attname'), |
||
| 236 | ], |
||
| 237 | ], |
||
| 238 | ], |
||
| 239 | ], |
||
| 240 | 'alter' => [ |
||
| 241 | 'content' => $lang['stralter'], |
||
| 242 | 'attr' => [ |
||
| 243 | 'href' => [ |
||
| 244 | 'url' => 'colproperties.php', |
||
| 245 | 'urlvars' => [ |
||
| 246 | 'subject' => 'column', |
||
| 247 | 'action' => 'properties', |
||
| 248 | 'table' => $_REQUEST['table'], |
||
| 249 | 'column' => Decorator::field('attname'), |
||
| 250 | ], |
||
| 251 | ], |
||
| 252 | ], |
||
| 253 | ], |
||
| 254 | 'privileges' => [ |
||
| 255 | 'content' => $lang['strprivileges'], |
||
| 256 | 'attr' => [ |
||
| 257 | 'href' => [ |
||
| 258 | 'url' => 'privileges.php', |
||
| 259 | 'urlvars' => [ |
||
| 260 | 'subject' => 'column', |
||
| 261 | 'table' => $_REQUEST['table'], |
||
| 262 | 'column' => Decorator::field('attname'), |
||
| 263 | ], |
||
| 264 | ], |
||
| 265 | ], |
||
| 266 | ], |
||
| 267 | 'drop' => [ |
||
| 268 | 'content' => $lang['strdrop'], |
||
| 269 | 'attr' => [ |
||
| 270 | 'href' => [ |
||
| 271 | 'url' => 'tblproperties.php', |
||
| 272 | 'urlvars' => [ |
||
| 273 | 'subject' => 'column', |
||
| 274 | 'action' => 'confirm_drop', |
||
| 275 | 'table' => $_REQUEST['table'], |
||
| 276 | 'column' => Decorator::field('attname'), |
||
| 277 | ], |
||
| 278 | ], |
||
| 279 | ], |
||
| 280 | ], |
||
| 281 | ]; |
||
| 282 | |||
| 283 | echo $this->printTable($attrs, $columns, $actions, 'tblproperties-tblproperties', null, $attPre); |
||
| 284 | |||
| 285 | $navlinks = [ |
||
| 286 | 'browse' => [ |
||
| 287 | 'attr' => [ |
||
| 288 | 'href' => [ |
||
| 289 | 'url' => 'display.php', |
||
| 290 | 'urlvars' => [ |
||
| 291 | 'server' => $_REQUEST['server'], |
||
| 292 | 'database' => $_REQUEST['database'], |
||
| 293 | 'schema' => $_REQUEST['schema'], |
||
| 294 | 'table' => $_REQUEST['table'], |
||
| 295 | 'subject' => 'table', |
||
| 296 | 'return' => 'table', |
||
| 297 | ], |
||
| 298 | ], |
||
| 299 | ], |
||
| 300 | 'content' => $lang['strbrowse'], |
||
| 301 | ], |
||
| 302 | 'select' => [ |
||
| 303 | 'attr' => [ |
||
| 304 | 'href' => [ |
||
| 305 | 'url' => 'tables.php', |
||
| 306 | 'urlvars' => [ |
||
| 307 | 'action' => 'confselectrows', |
||
| 308 | 'server' => $_REQUEST['server'], |
||
| 309 | 'database' => $_REQUEST['database'], |
||
| 310 | 'schema' => $_REQUEST['schema'], |
||
| 311 | 'table' => $_REQUEST['table'], |
||
| 312 | ], |
||
| 313 | ], |
||
| 314 | ], |
||
| 315 | 'content' => $lang['strselect'], |
||
| 316 | ], |
||
| 317 | 'insert' => [ |
||
| 318 | 'attr' => [ |
||
| 319 | 'href' => [ |
||
| 320 | 'url' => 'tables.php', |
||
| 321 | 'urlvars' => [ |
||
| 322 | 'action' => 'confinsertrow', |
||
| 323 | 'server' => $_REQUEST['server'], |
||
| 324 | 'database' => $_REQUEST['database'], |
||
| 325 | 'schema' => $_REQUEST['schema'], |
||
| 326 | 'table' => $_REQUEST['table'], |
||
| 327 | ], |
||
| 328 | ], |
||
| 329 | ], |
||
| 330 | 'content' => $lang['strinsert'], |
||
| 331 | ], |
||
| 332 | 'empty' => [ |
||
| 333 | 'attr' => [ |
||
| 334 | 'href' => [ |
||
| 335 | 'url' => 'tables.php', |
||
| 336 | 'urlvars' => [ |
||
| 337 | 'action' => 'confirm_empty', |
||
| 338 | 'server' => $_REQUEST['server'], |
||
| 339 | 'database' => $_REQUEST['database'], |
||
| 340 | 'schema' => $_REQUEST['schema'], |
||
| 341 | 'table' => $_REQUEST['table'], |
||
| 342 | ], |
||
| 343 | ], |
||
| 344 | ], |
||
| 345 | 'content' => $lang['strempty'], |
||
| 346 | ], |
||
| 347 | 'drop' => [ |
||
| 348 | 'attr' => [ |
||
| 349 | 'href' => [ |
||
| 350 | 'url' => 'tables.php', |
||
| 351 | 'urlvars' => [ |
||
| 352 | 'action' => 'confirm_drop', |
||
| 353 | 'server' => $_REQUEST['server'], |
||
| 354 | 'database' => $_REQUEST['database'], |
||
| 355 | 'schema' => $_REQUEST['schema'], |
||
| 356 | 'table' => $_REQUEST['table'], |
||
| 357 | ], |
||
| 358 | ], |
||
| 359 | ], |
||
| 360 | 'content' => $lang['strdrop'], |
||
| 361 | ], |
||
| 362 | 'addcolumn' => [ |
||
| 363 | 'attr' => [ |
||
| 364 | 'href' => [ |
||
| 365 | 'url' => 'tblproperties.php', |
||
| 366 | 'urlvars' => [ |
||
| 367 | 'action' => 'add_column', |
||
| 368 | 'server' => $_REQUEST['server'], |
||
| 369 | 'database' => $_REQUEST['database'], |
||
| 370 | 'schema' => $_REQUEST['schema'], |
||
| 371 | 'table' => $_REQUEST['table'], |
||
| 372 | ], |
||
| 373 | ], |
||
| 374 | ], |
||
| 375 | 'content' => $lang['straddcolumn'], |
||
| 376 | ], |
||
| 377 | 'alter' => [ |
||
| 378 | 'attr' => [ |
||
| 379 | 'href' => [ |
||
| 380 | 'url' => 'tblproperties.php', |
||
| 381 | 'urlvars' => [ |
||
| 382 | 'action' => 'confirm_alter', |
||
| 383 | 'server' => $_REQUEST['server'], |
||
| 384 | 'database' => $_REQUEST['database'], |
||
| 385 | 'schema' => $_REQUEST['schema'], |
||
| 386 | 'table' => $_REQUEST['table'], |
||
| 387 | ], |
||
| 388 | ], |
||
| 389 | ], |
||
| 390 | 'content' => $lang['stralter'], |
||
| 391 | ], |
||
| 392 | ]; |
||
| 393 | $this->printNavLinks($navlinks, 'tblproperties-tblproperties', get_defined_vars()); |
||
| 394 | } |
||
| 395 | |||
| 396 | public function doTree() |
||
| 397 | { |
||
| 398 | $conf = $this->conf; |
||
| 399 | $misc = $this->misc; |
||
| 400 | $lang = $this->lang; |
||
| 401 | $data = $misc->getDatabaseAccessor(); |
||
| 402 | |||
| 403 | $columns = $data->getTableAttributes($_REQUEST['table']); |
||
| 404 | $reqvars = $misc->getRequestVars('column'); |
||
| 405 | |||
| 406 | $attrs = [ |
||
| 407 | 'text' => Decorator::field('attname'), |
||
| 408 | 'action' => Decorator::actionurl('colproperties.php', |
||
| 409 | $reqvars, |
||
| 410 | [ |
||
| 411 | 'table' => $_REQUEST['table'], |
||
| 412 | 'column' => Decorator::field('attname'), |
||
| 413 | ] |
||
| 414 | ), |
||
| 415 | 'icon' => 'Column', |
||
| 416 | 'iconAction' => Decorator::url('display.php', |
||
| 417 | $reqvars, |
||
| 418 | [ |
||
| 419 | 'table' => $_REQUEST['table'], |
||
| 420 | 'column' => Decorator::field('attname'), |
||
| 421 | 'query' => Decorator::replace( |
||
| 422 | 'SELECT "%column%", count(*) AS "count" FROM "%table%" GROUP BY "%column%" ORDER BY "%column%"', |
||
| 423 | [ |
||
| 424 | '%column%' => Decorator::field('attname'), |
||
| 425 | '%table%' => $_REQUEST['table'], |
||
| 426 | ] |
||
| 427 | ), |
||
| 428 | ] |
||
| 429 | ), |
||
| 430 | 'toolTip' => Decorator::field('comment'), |
||
| 431 | ]; |
||
| 432 | |||
| 433 | return $this->printTree($columns, $attrs, 'tblcolumns'); |
||
| 434 | } |
||
| 435 | |||
| 436 | public function doSaveAlter() |
||
| 437 | { |
||
| 438 | $conf = $this->conf; |
||
| 439 | $misc = $this->misc; |
||
| 440 | $lang = $this->lang; |
||
| 441 | $data = $misc->getDatabaseAccessor(); |
||
| 442 | |||
| 443 | // For databases that don't allow owner change |
||
| 444 | if (!isset($_POST['owner'])) { |
||
| 445 | $_POST['owner'] = ''; |
||
| 446 | } |
||
| 447 | |||
| 448 | // Default tablespace to null if it isn't set |
||
| 449 | if (!isset($_POST['tablespace'])) { |
||
| 450 | $_POST['tablespace'] = null; |
||
| 451 | } |
||
| 452 | |||
| 453 | if (!isset($_POST['newschema'])) { |
||
| 454 | $_POST['newschema'] = null; |
||
| 455 | } |
||
| 456 | |||
| 457 | $status = $data->alterTable($_POST['table'], $_POST['name'], $_POST['owner'], $_POST['newschema'], $_POST['comment'], $_POST['tablespace']); |
||
| 458 | if ($status == 0) { |
||
| 459 | // If table has been renamed, need to change to the new name and |
||
| 460 | // reload the browser frame. |
||
| 461 | if ($_POST['table'] != $_POST['name']) { |
||
| 462 | // Jump them to the new table name |
||
| 463 | $_REQUEST['table'] = $_POST['name']; |
||
| 464 | // Force a browser reload |
||
| 465 | $misc->setReloadBrowser(true); |
||
| 466 | } |
||
| 467 | // If schema has changed, need to change to the new schema and reload the browser |
||
| 468 | if (!empty($_POST['newschema']) && ($_POST['newschema'] != $data->_schema)) { |
||
| 469 | // Jump them to the new sequence schema |
||
| 470 | $misc->setCurrentSchema($_POST['newschema']); |
||
| 471 | $misc->setReloadBrowser(true); |
||
| 472 | } |
||
| 473 | $this->doDefault($lang['strtablealtered']); |
||
| 474 | } else { |
||
| 475 | $this->doAlter($lang['strtablealteredbad']); |
||
| 476 | } |
||
| 477 | } |
||
| 478 | |||
| 479 | /** |
||
| 480 | * Function to allow altering of a table |
||
| 481 | */ |
||
| 482 | public function doAlter($msg = '') |
||
| 483 | { |
||
| 484 | $conf = $this->conf; |
||
| 485 | $misc = $this->misc; |
||
| 486 | $lang = $this->lang; |
||
| 487 | $data = $misc->getDatabaseAccessor(); |
||
| 488 | |||
| 489 | $this->printTrail('table'); |
||
| 490 | $this->printTitle($lang['stralter'], 'pg.table.alter'); |
||
| 491 | $this->printMsg($msg); |
||
| 492 | |||
| 493 | // Fetch table info |
||
| 494 | $table = $data->getTable($_REQUEST['table']); |
||
| 495 | // Fetch all users |
||
| 496 | $users = $data->getUsers(); |
||
| 497 | // Fetch all tablespaces from the database |
||
| 498 | if ($data->hasTablespaces()) { |
||
| 499 | $tablespaces = $data->getTablespaces(true); |
||
| 500 | } |
||
| 501 | |||
| 502 | if ($table->recordCount() > 0) { |
||
| 503 | if (!isset($_POST['name'])) { |
||
| 504 | $_POST['name'] = $table->fields['relname']; |
||
| 505 | } |
||
| 506 | |||
| 507 | if (!isset($_POST['owner'])) { |
||
| 508 | $_POST['owner'] = $table->fields['relowner']; |
||
| 509 | } |
||
| 510 | |||
| 511 | if (!isset($_POST['newschema'])) { |
||
| 512 | $_POST['newschema'] = $table->fields['nspname']; |
||
| 513 | } |
||
| 514 | |||
| 515 | if (!isset($_POST['comment'])) { |
||
| 516 | $_POST['comment'] = $table->fields['relcomment']; |
||
| 517 | } |
||
| 518 | |||
| 519 | if ($data->hasTablespaces() && !isset($_POST['tablespace'])) { |
||
| 520 | $_POST['tablespace'] = $table->fields['tablespace']; |
||
| 521 | } |
||
| 522 | |||
| 523 | echo '<form action="' . SUBFOLDER . "/src/views/tblproperties.php\" method=\"post\">\n"; |
||
| 524 | echo "<table>\n"; |
||
| 525 | echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n"; |
||
| 526 | echo '<td class="data1">'; |
||
| 527 | echo "<input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 528 | htmlspecialchars($_POST['name'], ENT_QUOTES), "\" /></td></tr>\n"; |
||
| 529 | |||
| 530 | View Code Duplication | if ($data->isSuperUser()) { |
|
| 531 | echo "<tr><th class=\"data left required\">{$lang['strowner']}</th>\n"; |
||
| 532 | echo '<td class="data1"><select name="owner">'; |
||
| 533 | while (!$users->EOF) { |
||
| 534 | $uname = $users->fields['usename']; |
||
| 535 | echo '<option value="', htmlspecialchars($uname), '"', |
||
| 536 | ($uname == $_POST['owner']) ? ' selected="selected"' : '', '>', htmlspecialchars($uname), "</option>\n"; |
||
| 537 | $users->moveNext(); |
||
| 538 | } |
||
| 539 | echo "</select></td></tr>\n"; |
||
| 540 | } |
||
| 541 | |||
| 542 | if ($data->hasAlterTableSchema()) { |
||
| 543 | $schemas = $data->getSchemas(); |
||
| 544 | echo "<tr><th class=\"data left required\">{$lang['strschema']}</th>\n"; |
||
| 545 | echo '<td class="data1"><select name="newschema">'; |
||
| 546 | while (!$schemas->EOF) { |
||
| 547 | $schema = $schemas->fields['nspname']; |
||
| 548 | echo '<option value="', htmlspecialchars($schema), '"', |
||
| 549 | ($schema == $_POST['newschema']) ? ' selected="selected"' : '', '>', htmlspecialchars($schema), "</option>\n"; |
||
| 550 | $schemas->moveNext(); |
||
| 551 | } |
||
| 552 | echo "</select></td></tr>\n"; |
||
| 553 | } |
||
| 554 | |||
| 555 | // Tablespace (if there are any) |
||
| 556 | View Code Duplication | if ($data->hasTablespaces() && $tablespaces->recordCount() > 0) { |
|
| 557 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strtablespace']}</th>\n"; |
||
| 558 | echo "\t\t<td class=\"data1\">\n\t\t\t<select name=\"tablespace\">\n"; |
||
| 559 | // Always offer the default (empty) option |
||
| 560 | echo "\t\t\t\t<option value=\"\"", |
||
| 561 | ($_POST['tablespace'] == '') ? ' selected="selected"' : '', "></option>\n"; |
||
| 562 | // Display all other tablespaces |
||
| 563 | while (!$tablespaces->EOF) { |
||
| 564 | $spcname = htmlspecialchars($tablespaces->fields['spcname']); |
||
| 565 | echo "\t\t\t\t<option value=\"{$spcname}\"", |
||
| 566 | ($spcname == $_POST['tablespace']) ? ' selected="selected"' : '', ">{$spcname}</option>\n"; |
||
| 567 | $tablespaces->moveNext(); |
||
| 568 | } |
||
| 569 | echo "\t\t\t</select>\n\t\t</td>\n\t</tr>\n"; |
||
| 570 | } |
||
| 571 | |||
| 572 | echo "<tr><th class=\"data left\">{$lang['strcomment']}</th>\n"; |
||
| 573 | echo '<td class="data1">'; |
||
| 574 | echo '<textarea rows="3" cols="32" name="comment">', |
||
| 575 | htmlspecialchars($_POST['comment']), "</textarea></td></tr>\n"; |
||
| 576 | echo "</table>\n"; |
||
| 577 | echo "<p><input type=\"hidden\" name=\"action\" value=\"alter\" />\n"; |
||
| 578 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), "\" />\n"; |
||
| 579 | echo $misc->form; |
||
| 580 | echo "<input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n"; |
||
| 581 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 582 | echo "</form>\n"; |
||
| 583 | } else { |
||
| 584 | echo "<p>{$lang['strnodata']}</p>\n"; |
||
| 585 | } |
||
| 586 | } |
||
| 587 | |||
| 588 | public function doExport($msg = '') |
||
| 647 | } |
||
| 648 | |||
| 649 | public function doImport($msg = '') |
||
| 692 | } |
||
| 693 | } |
||
| 694 | |||
| 695 | /** |
||
| 696 | * Displays a screen where they can add a column |
||
| 697 | */ |
||
| 698 | public function doAddColumn($msg = '') |
||
| 699 | { |
||
| 700 | $conf = $this->conf; |
||
| 701 | $misc = $this->misc; |
||
| 702 | $lang = $this->lang; |
||
| 703 | $data = $misc->getDatabaseAccessor(); |
||
| 704 | |||
| 705 | if (!isset($_REQUEST['stage'])) { |
||
| 706 | $_REQUEST['stage'] = 1; |
||
| 707 | } |
||
| 708 | |||
| 709 | switch ($_REQUEST['stage']) { |
||
| 710 | case 1: |
||
| 711 | // Set variable defaults |
||
| 712 | if (!isset($_POST['field'])) { |
||
| 713 | $_POST['field'] = ''; |
||
| 714 | } |
||
| 715 | |||
| 716 | if (!isset($_POST['type'])) { |
||
| 717 | $_POST['type'] = ''; |
||
| 718 | } |
||
| 719 | |||
| 720 | if (!isset($_POST['array'])) { |
||
| 721 | $_POST['array'] = ''; |
||
| 722 | } |
||
| 723 | |||
| 724 | if (!isset($_POST['length'])) { |
||
| 725 | $_POST['length'] = ''; |
||
| 726 | } |
||
| 727 | |||
| 728 | if (!isset($_POST['default'])) { |
||
| 729 | $_POST['default'] = ''; |
||
| 730 | } |
||
| 731 | |||
| 732 | if (!isset($_POST['comment'])) { |
||
| 733 | $_POST['comment'] = ''; |
||
| 734 | } |
||
| 735 | |||
| 736 | // Fetch all available types |
||
| 737 | $types = $data->getTypes(true, false, true); |
||
| 738 | $types_for_js = []; |
||
| 739 | |||
| 740 | $this->printTrail('table'); |
||
| 741 | $this->printTitle($lang['straddcolumn'], 'pg.column.add'); |
||
| 742 | $this->printMsg($msg); |
||
| 743 | |||
| 744 | echo '<script src="' . SUBFOLDER . '/js/tables.js" type="text/javascript"></script>'; |
||
| 745 | echo '<form action="' . SUBFOLDER . "/src/views/tblproperties.php\" method=\"post\">\n"; |
||
| 746 | |||
| 747 | // Output table header |
||
| 748 | echo "<table>\n"; |
||
| 749 | echo "<tr><th class=\"data required\">{$lang['strname']}</th>\n<th colspan=\"2\" class=\"data required\">{$lang['strtype']}</th>\n"; |
||
| 750 | echo "<th class=\"data\">{$lang['strlength']}</th>\n"; |
||
| 751 | if ($data->hasCreateFieldWithConstraints()) { |
||
| 752 | echo "<th class=\"data\">{$lang['strnotnull']}</th>\n<th class=\"data\">{$lang['strdefault']}</th>\n"; |
||
| 753 | } |
||
| 754 | |||
| 755 | echo "<th class=\"data\">{$lang['strcomment']}</th></tr>\n"; |
||
| 756 | |||
| 757 | echo "<tr><td><input name=\"field\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 758 | htmlspecialchars($_POST['field']), "\" /></td>\n"; |
||
| 759 | echo "<td><select class=\"select2\" name=\"type\" id=\"type\" onchange=\"checkLengths(document.getElementById('type').value,'');\">\n"; |
||
| 760 | // Output any "magic" types. This came in with the alter column type so we'll check that |
||
| 761 | if ($data->hasMagicTypes()) { |
||
| 762 | foreach ($data->extraTypes as $v) { |
||
| 763 | $types_for_js[] = strtolower($v); |
||
| 764 | echo "\t<option value=\"", htmlspecialchars($v), '"', |
||
| 765 | ($v == $_POST['type']) ? ' selected="selected"' : '', '>', |
||
| 766 | $misc->printVal($v), "</option>\n"; |
||
| 767 | } |
||
| 768 | } |
||
| 769 | while (!$types->EOF) { |
||
| 770 | $typname = $types->fields['typname']; |
||
| 771 | $types_for_js[] = $typname; |
||
| 772 | echo "\t<option value=\"", htmlspecialchars($typname), '"', ($typname == $_POST['type']) ? ' selected="selected"' : '', '>', |
||
| 773 | $misc->printVal($typname), "</option>\n"; |
||
| 774 | $types->moveNext(); |
||
| 775 | } |
||
| 776 | echo "</select></td>\n"; |
||
| 777 | |||
| 778 | // Output array type selector |
||
| 779 | echo "<td><select name=\"array\">\n"; |
||
| 780 | echo "\t<option value=\"\"", ($_POST['array'] == '') ? ' selected="selected"' : '', "></option>\n"; |
||
| 781 | echo "\t<option value=\"[]\"", ($_POST['array'] == '[]') ? ' selected="selected"' : '', ">[ ]</option>\n"; |
||
| 782 | echo "</select></td>\n"; |
||
| 783 | $predefined_size_types = array_intersect($data->predefined_size_types, $types_for_js); |
||
| 784 | $escaped_predef_types = []; // the JS escaped array elements |
||
| 785 | foreach ($predefined_size_types as $value) { |
||
| 786 | $escaped_predef_types[] = "'{$value}'"; |
||
| 787 | } |
||
| 788 | |||
| 789 | echo '<td><input name="length" id="lengths" size="8" value="', |
||
| 790 | htmlspecialchars($_POST['length']), "\" /></td>\n"; |
||
| 791 | // Support for adding column with not null and default |
||
| 792 | if ($data->hasCreateFieldWithConstraints()) { |
||
| 793 | echo '<td><input type="checkbox" name="notnull"', |
||
| 794 | (isset($_REQUEST['notnull'])) ? ' checked="checked"' : '', " /></td>\n"; |
||
| 795 | echo '<td><input name="default" size="20" value="', |
||
| 796 | htmlspecialchars($_POST['default']), "\" /></td>\n"; |
||
| 797 | } |
||
| 798 | echo '<td><input name="comment" size="40" value="', |
||
| 799 | htmlspecialchars($_POST['comment']), "\" /></td></tr>\n"; |
||
| 800 | echo "</table>\n"; |
||
| 801 | echo "<p><input type=\"hidden\" name=\"action\" value=\"add_column\" />\n"; |
||
| 802 | echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n"; |
||
| 803 | echo $misc->form; |
||
| 804 | echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), "\" />\n"; |
||
| 805 | if (!$data->hasCreateFieldWithConstraints()) { |
||
| 806 | echo "<input type=\"hidden\" name=\"default\" value=\"\" />\n"; |
||
| 807 | } |
||
| 808 | echo "<input type=\"submit\" value=\"{$lang['stradd']}\" />\n"; |
||
| 809 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 810 | echo "</form>\n"; |
||
| 811 | echo '<script type="text/javascript">predefined_lengths = new Array(' . implode(',', $escaped_predef_types) . ");checkLengths(document.getElementById('type').value,'');</script>\n"; |
||
| 812 | break; |
||
| 813 | case 2: |
||
| 814 | // Check inputs |
||
| 815 | if (trim($_POST['field']) == '') { |
||
| 816 | $_REQUEST['stage'] = 1; |
||
| 817 | $this->doAddColumn($lang['strcolneedsname']); |
||
| 818 | return; |
||
| 819 | } |
||
| 820 | if (!isset($_POST['length'])) { |
||
| 821 | $_POST['length'] = ''; |
||
| 822 | } |
||
| 823 | |||
| 824 | $status = $data->addColumn($_POST['table'], $_POST['field'], |
||
| 825 | $_POST['type'], $_POST['array'] != '', $_POST['length'], isset($_POST['notnull']), |
||
| 826 | $_POST['default'], $_POST['comment']); |
||
| 827 | if ($status == 0) { |
||
| 828 | $misc->setReloadBrowser(true); |
||
| 829 | $this->doDefault($lang['strcolumnadded']); |
||
| 830 | } else { |
||
| 831 | $_REQUEST['stage'] = 1; |
||
| 832 | $this->doAddColumn($lang['strcolumnaddedbad']); |
||
| 833 | return; |
||
| 834 | } |
||
| 835 | break; |
||
| 836 | default: |
||
| 837 | echo "<p>{$lang['strinvalidparam']}</p>\n"; |
||
| 838 | } |
||
| 839 | } |
||
| 840 | |||
| 841 | /** |
||
| 842 | * Show confirmation of drop column and perform actual drop |
||
| 843 | */ |
||
| 844 | View Code Duplication | public function doDrop($confirm) |
|
| 874 | } |
||
| 875 | } |
||
| 878 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: