| Conditions | 67 |
| Total Lines | 463 |
| Code Lines | 269 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 110 | public function doBrowse($msg = '') |
||
| 111 | { |
||
| 112 | $conf = $this->conf; |
||
| 113 | $this->misc = $this->misc; |
||
| 114 | $lang = $this->lang; |
||
| 115 | $plugin_manager = $this->plugin_manager; |
||
| 116 | $data = $this->misc->getDatabaseAccessor(); |
||
| 117 | |||
| 118 | $save_history = false; |
||
| 119 | // If current page is not set, default to first page |
||
| 120 | if (!isset($_REQUEST['page'])) { |
||
| 121 | $_REQUEST['page'] = 1; |
||
| 122 | } |
||
| 123 | |||
| 124 | if (!isset($_REQUEST['nohistory'])) { |
||
| 125 | $save_history = true; |
||
| 126 | } |
||
| 127 | |||
| 128 | if (isset($_REQUEST['subject'])) { |
||
| 129 | $subject = $_REQUEST['subject']; |
||
| 130 | if (isset($_REQUEST[$subject])) { |
||
| 131 | $object = $_REQUEST[$subject]; |
||
| 132 | } |
||
| 133 | } else { |
||
| 134 | $subject = ''; |
||
| 135 | } |
||
| 136 | |||
| 137 | $this->printTrail(isset($subject) ? $subject : 'database'); |
||
| 138 | $this->printTabs($subject, 'browse'); |
||
| 139 | |||
| 140 | // This code is used when browsing FK in pure-xHTML (without js) |
||
| 141 | if (isset($_REQUEST['fkey'])) { |
||
| 142 | $ops = []; |
||
| 143 | foreach ($_REQUEST['fkey'] as $x => $y) { |
||
| 144 | $ops[$x] = '='; |
||
| 145 | } |
||
| 146 | $query = $data->getSelectSQL($_REQUEST['table'], [], $_REQUEST['fkey'], $ops); |
||
| 147 | $_REQUEST['query'] = $query; |
||
| 148 | } |
||
| 149 | |||
| 150 | if (isset($object)) { |
||
| 151 | if (isset($_REQUEST['query'])) { |
||
| 152 | $_SESSION['sqlquery'] = $_REQUEST['query']; |
||
| 153 | $this->printTitle($lang['strselect']); |
||
| 154 | $type = 'SELECT'; |
||
| 155 | } else { |
||
| 156 | $type = 'TABLE'; |
||
| 157 | } |
||
| 158 | } else { |
||
| 159 | $this->printTitle($lang['strqueryresults']); |
||
| 160 | // we comes from sql.php, $_SESSION['sqlquery'] has been set there |
||
| 161 | $type = 'QUERY'; |
||
| 162 | } |
||
| 163 | |||
| 164 | $this->printMsg($msg); |
||
| 165 | |||
| 166 | // If 'sortkey' is not set, default to '' |
||
| 167 | if (!isset($_REQUEST['sortkey'])) { |
||
| 168 | $_REQUEST['sortkey'] = ''; |
||
| 169 | } |
||
| 170 | |||
| 171 | // If 'sortdir' is not set, default to '' |
||
| 172 | if (!isset($_REQUEST['sortdir'])) { |
||
| 173 | $_REQUEST['sortdir'] = ''; |
||
| 174 | } |
||
| 175 | |||
| 176 | // If 'strings' is not set, default to collapsed |
||
| 177 | if (!isset($_REQUEST['strings'])) { |
||
| 178 | $_REQUEST['strings'] = 'collapsed'; |
||
| 179 | } |
||
| 180 | |||
| 181 | // Fetch unique row identifier, if this is a table browse request. |
||
| 182 | if (isset($object)) { |
||
| 183 | $key = $data->getRowIdentifier($object); |
||
| 184 | } else { |
||
| 185 | $key = []; |
||
| 186 | } |
||
| 187 | |||
| 188 | // Set the schema search path |
||
| 189 | if (isset($_REQUEST['search_path'])) { |
||
| 190 | if (0 != $data->setSearchPath(array_map('trim', explode(',', $_REQUEST['search_path'])))) { |
||
| 191 | return; |
||
| 192 | } |
||
| 193 | } |
||
| 194 | |||
| 195 | try { |
||
| 196 | // Retrieve page from query. $max_pages is returned by reference. |
||
| 197 | $resultset = $data->browseQuery( |
||
| 198 | $type, |
||
| 199 | isset($object) ? $object : null, |
||
| 200 | isset($_SESSION['sqlquery']) ? $_SESSION['sqlquery'] : null, |
||
| 201 | $_REQUEST['sortkey'], |
||
| 202 | $_REQUEST['sortdir'], |
||
| 203 | $_REQUEST['page'], |
||
| 204 | $this->conf['max_rows'], |
||
| 205 | $max_pages |
||
|
1 ignored issue
–
show
|
|||
| 206 | ); |
||
| 207 | } catch (\PHPPgAdmin\ADOdbException $e) { |
||
| 208 | return; |
||
| 209 | } |
||
| 210 | |||
| 211 | $fkey_information = $this->getFKInfo(); |
||
| 212 | |||
| 213 | // Build strings for GETs in array |
||
| 214 | $_gets = [ |
||
| 215 | 'server' => $_REQUEST['server'], |
||
| 216 | 'database' => $_REQUEST['database'], |
||
| 217 | ]; |
||
| 218 | |||
| 219 | if (isset($_REQUEST['schema'])) { |
||
| 220 | $_gets['schema'] = $_REQUEST['schema']; |
||
| 221 | } |
||
| 222 | |||
| 223 | if (isset($object)) { |
||
| 224 | $_gets[$subject] = $object; |
||
| 225 | } |
||
| 226 | |||
| 227 | if (isset($subject)) { |
||
| 228 | $_gets['subject'] = $subject; |
||
| 229 | } |
||
| 230 | |||
| 231 | if (isset($_REQUEST['query'])) { |
||
| 232 | $_gets['query'] = $_REQUEST['query']; |
||
| 233 | } |
||
| 234 | |||
| 235 | if (isset($_REQUEST['count'])) { |
||
| 236 | $_gets['count'] = $_REQUEST['count']; |
||
| 237 | } |
||
| 238 | |||
| 239 | if (isset($_REQUEST['return'])) { |
||
| 240 | $_gets['return'] = $_REQUEST['return']; |
||
| 241 | } |
||
| 242 | |||
| 243 | if (isset($_REQUEST['search_path'])) { |
||
| 244 | $_gets['search_path'] = $_REQUEST['search_path']; |
||
| 245 | } |
||
| 246 | |||
| 247 | if (isset($_REQUEST['table'])) { |
||
| 248 | $_gets['table'] = $_REQUEST['table']; |
||
| 249 | } |
||
| 250 | |||
| 251 | if (isset($_REQUEST['sortkey'])) { |
||
| 252 | $_gets['sortkey'] = $_REQUEST['sortkey']; |
||
| 253 | } |
||
| 254 | |||
| 255 | if (isset($_REQUEST['sortdir'])) { |
||
| 256 | $_gets['sortdir'] = $_REQUEST['sortdir']; |
||
| 257 | } |
||
| 258 | |||
| 259 | if (isset($_REQUEST['nohistory'])) { |
||
| 260 | $_gets['nohistory'] = $_REQUEST['nohistory']; |
||
| 261 | } |
||
| 262 | |||
| 263 | $_gets['strings'] = $_REQUEST['strings']; |
||
| 264 | |||
| 265 | if ($save_history && is_object($resultset) && ('QUERY' == $type)) { |
||
| 266 | //{ |
||
| 267 | $this->misc->saveScriptHistory($_REQUEST['query']); |
||
| 268 | } |
||
| 269 | |||
| 270 | if (isset($_REQUEST['query'])) { |
||
| 271 | $query = $_REQUEST['query']; |
||
| 272 | } else { |
||
| 273 | $query = "SELECT * FROM {$_REQUEST['schema']}"; |
||
| 274 | if ('matview' == $_REQUEST['subject']) { |
||
| 275 | $query = "{$query}.{$_REQUEST['matview']};"; |
||
| 276 | } elseif ('view' == $_REQUEST['subject']) { |
||
| 277 | $query = "{$query}.{$_REQUEST['view']};"; |
||
| 278 | } else { |
||
| 279 | $query = "{$query}.{$_REQUEST['table']};"; |
||
| 280 | } |
||
| 281 | } |
||
| 282 | //$query = isset($_REQUEST['query'])? $_REQUEST['query'] : "select * from {$_REQUEST['schema']}.{$_REQUEST['table']};"; |
||
| 283 | $this->prtrace($query); |
||
| 284 | //die(htmlspecialchars($query)); |
||
| 285 | |||
| 286 | echo '<form method="post" id="sqlform" action="' . $_SERVER['REQUEST_URI'] . '">'; |
||
| 287 | echo '<textarea width="90%" name="query" id="query" rows="5" cols="100" resizable="true">'; |
||
| 288 | |||
| 289 | echo htmlspecialchars($query); |
||
| 290 | echo '</textarea><br><input type="submit"/></form>'; |
||
| 291 | |||
| 292 | if (is_object($resultset) && $resultset->recordCount() > 0) { |
||
| 293 | // Show page navigation |
||
| 294 | $this->misc->printPages($_REQUEST['page'], $max_pages, $_gets); |
||
| 295 | |||
| 296 | echo "<table id=\"data\">\n<tr>"; |
||
| 297 | |||
| 298 | // Check that the key is actually in the result set. This can occur for select |
||
| 299 | // operations where the key fields aren't part of the select. XXX: We should |
||
| 300 | // be able to support this, somehow. |
||
| 301 | foreach ($key as $v) { |
||
| 302 | // If a key column is not found in the record set, then we |
||
| 303 | // can't use the key. |
||
| 304 | if (!in_array($v, array_keys($resultset->fields), true)) { |
||
| 305 | $key = []; |
||
| 306 | |||
| 307 | break; |
||
| 308 | } |
||
| 309 | } |
||
| 310 | |||
| 311 | $buttons = [ |
||
| 312 | 'edit' => [ |
||
| 313 | 'content' => $lang['stredit'], |
||
| 314 | 'attr' => [ |
||
| 315 | 'href' => [ |
||
| 316 | 'url' => 'display.php', |
||
| 317 | 'urlvars' => array_merge([ |
||
|
1 ignored issue
–
show
|
|||
| 318 | 'action' => 'confeditrow', |
||
| 319 | 'strings' => $_REQUEST['strings'], |
||
| 320 | 'page' => $_REQUEST['page'], |
||
| 321 | ], $_gets), |
||
|
1 ignored issue
–
show
|
|||
| 322 | ], |
||
| 323 | ], |
||
| 324 | ], |
||
| 325 | 'delete' => [ |
||
| 326 | 'content' => $lang['strdelete'], |
||
| 327 | 'attr' => [ |
||
| 328 | 'href' => [ |
||
| 329 | 'url' => 'display.php', |
||
| 330 | 'urlvars' => array_merge([ |
||
|
1 ignored issue
–
show
|
|||
| 331 | 'action' => 'confdelrow', |
||
| 332 | 'strings' => $_REQUEST['strings'], |
||
| 333 | 'page' => $_REQUEST['page'], |
||
| 334 | ], $_gets), |
||
|
1 ignored issue
–
show
|
|||
| 335 | ], |
||
| 336 | ], |
||
| 337 | ], |
||
| 338 | ]; |
||
| 339 | $actions = [ |
||
| 340 | 'actionbuttons' => &$buttons, |
||
| 341 | 'place' => 'display-browse', |
||
| 342 | ]; |
||
| 343 | $plugin_manager->do_hook('actionbuttons', $actions); |
||
| 344 | |||
| 345 | foreach (array_keys($actions['actionbuttons']) as $action) { |
||
| 346 | $actions['actionbuttons'][$action]['attr']['href']['urlvars'] = array_merge( |
||
| 347 | $actions['actionbuttons'][$action]['attr']['href']['urlvars'], |
||
| 348 | $_gets |
||
| 349 | ); |
||
| 350 | } |
||
| 351 | |||
| 352 | $edit_params = isset($actions['actionbuttons']['edit']) ? |
||
| 353 | $actions['actionbuttons']['edit'] : []; |
||
| 354 | $delete_params = isset($actions['actionbuttons']['delete']) ? |
||
| 355 | $actions['actionbuttons']['delete'] : []; |
||
| 356 | |||
| 357 | // Display edit and delete actions if we have a key |
||
| 358 | $colspan = count($buttons); |
||
| 359 | if ($colspan > 0 and count($key) > 0) { |
||
| 360 | echo "<th colspan=\"{$colspan}\" class=\"data\">{$lang['stractions']}</th>" . "\n"; |
||
| 361 | } |
||
| 362 | |||
| 363 | // we show OIDs only if we are in TABLE or SELECT type browsing |
||
| 364 | $this->printTableHeaderCells($resultset, $_gets, isset($object)); |
||
| 365 | |||
| 366 | echo '</tr>' . "\n"; |
||
| 367 | |||
| 368 | $i = 0; |
||
| 369 | reset($resultset->fields); |
||
| 370 | while (!$resultset->EOF) { |
||
| 371 | $id = (0 == ($i % 2) ? '1' : '2'); |
||
| 372 | echo "<tr class=\"data{$id}\">" . "\n"; |
||
| 373 | // Display edit and delete links if we have a key |
||
| 374 | if ($colspan > 0 and count($key) > 0) { |
||
| 375 | $keys_array = []; |
||
| 376 | $has_nulls = false; |
||
| 377 | foreach ($key as $v) { |
||
| 378 | if (null === $resultset->fields[$v]) { |
||
| 379 | $has_nulls = true; |
||
| 380 | |||
| 381 | break; |
||
| 382 | } |
||
| 383 | $keys_array["key[{$v}]"] = $resultset->fields[$v]; |
||
| 384 | } |
||
| 385 | if ($has_nulls) { |
||
| 386 | echo "<td colspan=\"{$colspan}\"> </td>" . "\n"; |
||
| 387 | } else { |
||
| 388 | if (isset($actions['actionbuttons']['edit'])) { |
||
| 389 | $actions['actionbuttons']['edit'] = $edit_params; |
||
| 390 | $actions['actionbuttons']['edit']['attr']['href']['urlvars'] = array_merge( |
||
| 391 | $actions['actionbuttons']['edit']['attr']['href']['urlvars'], |
||
| 392 | $keys_array |
||
| 393 | ); |
||
| 394 | } |
||
| 395 | |||
| 396 | if (isset($actions['actionbuttons']['delete'])) { |
||
| 397 | $actions['actionbuttons']['delete'] = $delete_params; |
||
| 398 | $actions['actionbuttons']['delete']['attr']['href']['urlvars'] = array_merge( |
||
| 399 | $actions['actionbuttons']['delete']['attr']['href']['urlvars'], |
||
| 400 | $keys_array |
||
| 401 | ); |
||
| 402 | } |
||
| 403 | |||
| 404 | foreach ($actions['actionbuttons'] as $action) { |
||
| 405 | echo "<td class=\"opbutton{$id}\">"; |
||
| 406 | $this->printLink($action, true, __METHOD__); |
||
| 407 | echo '</td>' . "\n"; |
||
| 408 | } |
||
| 409 | } |
||
| 410 | } |
||
| 411 | |||
| 412 | $this->printTableRowCells($resultset, $fkey_information, isset($object)); |
||
| 413 | |||
| 414 | echo '</tr>' . "\n"; |
||
| 415 | $resultset->moveNext(); |
||
| 416 | ++$i; |
||
| 417 | } |
||
| 418 | echo '</table>' . "\n"; |
||
| 419 | |||
| 420 | echo '<p>', $resultset->recordCount(), " {$lang['strrows']}</p>" . "\n"; |
||
| 421 | // Show page navigation |
||
| 422 | $this->misc->printPages($_REQUEST['page'], $max_pages, $_gets); |
||
| 423 | } else { |
||
| 424 | echo "<p>{$lang['strnodata']}</p>" . "\n"; |
||
| 425 | } |
||
| 426 | |||
| 427 | // Navigation links |
||
| 428 | $navlinks = []; |
||
| 429 | |||
| 430 | $fields = [ |
||
| 431 | 'server' => $_REQUEST['server'], |
||
| 432 | 'database' => $_REQUEST['database'], |
||
| 433 | ]; |
||
| 434 | |||
| 435 | if (isset($_REQUEST['schema'])) { |
||
| 436 | $fields['schema'] = $_REQUEST['schema']; |
||
| 437 | } |
||
| 438 | |||
| 439 | // Return |
||
| 440 | if (isset($_REQUEST['return'])) { |
||
| 441 | $urlvars = $this->misc->getSubjectParams($_REQUEST['return']); |
||
| 442 | |||
| 443 | $navlinks['back'] = [ |
||
| 444 | 'attr' => [ |
||
| 445 | 'href' => [ |
||
| 446 | 'url' => $urlvars['url'], |
||
| 447 | 'urlvars' => $urlvars['params'], |
||
| 448 | ], |
||
| 449 | ], |
||
| 450 | 'content' => $lang['strback'], |
||
| 451 | ]; |
||
| 452 | } |
||
| 453 | |||
| 454 | // Edit SQL link |
||
| 455 | if ('QUERY' == $type) { |
||
| 456 | $navlinks['edit'] = [ |
||
| 457 | 'attr' => [ |
||
| 458 | 'href' => [ |
||
| 459 | 'url' => 'database.php', |
||
| 460 | 'urlvars' => array_merge($fields, [ |
||
|
1 ignored issue
–
show
|
|||
| 461 | 'action' => 'sql', |
||
| 462 | 'paginate' => 'on', |
||
| 463 | ]), |
||
|
1 ignored issue
–
show
|
|||
| 464 | ], |
||
| 465 | ], |
||
| 466 | 'content' => $lang['streditsql'], |
||
| 467 | ]; |
||
| 468 | } |
||
| 469 | |||
| 470 | // Expand/Collapse |
||
| 471 | if ('expanded' == $_REQUEST['strings']) { |
||
| 472 | $navlinks['collapse'] = [ |
||
| 473 | 'attr' => [ |
||
| 474 | 'href' => [ |
||
| 475 | 'url' => 'display.php', |
||
| 476 | 'urlvars' => array_merge( |
||
| 477 | $_gets, |
||
| 478 | [ |
||
| 479 | 'strings' => 'collapsed', |
||
| 480 | 'page' => $_REQUEST['page'], |
||
| 481 | ] |
||
| 482 | ), |
||
| 483 | ], |
||
| 484 | ], |
||
| 485 | 'content' => $lang['strcollapse'], |
||
| 486 | ]; |
||
| 487 | } else { |
||
| 488 | $navlinks['collapse'] = [ |
||
| 489 | 'attr' => [ |
||
| 490 | 'href' => [ |
||
| 491 | 'url' => 'display.php', |
||
| 492 | 'urlvars' => array_merge( |
||
| 493 | $_gets, |
||
| 494 | [ |
||
| 495 | 'strings' => 'expanded', |
||
| 496 | 'page' => $_REQUEST['page'], |
||
| 497 | ] |
||
| 498 | ), |
||
| 499 | ], |
||
| 500 | ], |
||
| 501 | 'content' => $lang['strexpand'], |
||
| 502 | ]; |
||
| 503 | } |
||
| 504 | |||
| 505 | // Create view and download |
||
| 506 | if (isset($_REQUEST['query'], $resultset) && is_object($resultset) && $resultset->recordCount() > 0) { |
||
| 507 | // Report views don't set a schema, so we need to disable create view in that case |
||
| 508 | if (isset($_REQUEST['schema'])) { |
||
| 509 | $navlinks['createview'] = [ |
||
| 510 | 'attr' => [ |
||
| 511 | 'href' => [ |
||
| 512 | 'url' => 'views.php', |
||
| 513 | 'urlvars' => array_merge($fields, [ |
||
|
1 ignored issue
–
show
|
|||
| 514 | 'action' => 'create', |
||
| 515 | 'formDefinition' => $_REQUEST['query'], |
||
| 516 | ]), |
||
|
1 ignored issue
–
show
|
|||
| 517 | ], |
||
| 518 | ], |
||
| 519 | 'content' => $lang['strcreateview'], |
||
| 520 | ]; |
||
| 521 | } |
||
| 522 | |||
| 523 | $urlvars = []; |
||
| 524 | if (isset($_REQUEST['search_path'])) { |
||
| 525 | $urlvars['search_path'] = $_REQUEST['search_path']; |
||
| 526 | } |
||
| 527 | |||
| 528 | $navlinks['download'] = [ |
||
| 529 | 'attr' => [ |
||
| 530 | 'href' => [ |
||
| 531 | 'url' => 'dataexport.php', |
||
| 532 | 'urlvars' => array_merge($fields, $urlvars), |
||
| 533 | ], |
||
| 534 | ], |
||
| 535 | 'content' => $lang['strdownload'], |
||
| 536 | ]; |
||
| 537 | } |
||
| 538 | |||
| 539 | // Insert |
||
| 540 | if (isset($object) && (isset($subject) && 'table' == $subject)) { |
||
| 541 | $navlinks['insert'] = [ |
||
| 542 | 'attr' => [ |
||
| 543 | 'href' => [ |
||
| 544 | 'url' => 'tables.php', |
||
| 545 | 'urlvars' => array_merge($fields, [ |
||
|
1 ignored issue
–
show
|
|||
| 546 | 'action' => 'confinsertrow', |
||
| 547 | 'table' => $object, |
||
| 548 | ]), |
||
|
1 ignored issue
–
show
|
|||
| 549 | ], |
||
| 550 | ], |
||
| 551 | 'content' => $lang['strinsert'], |
||
| 552 | ]; |
||
| 553 | } |
||
| 554 | |||
| 555 | // Refresh |
||
| 556 | $navlinks['refresh'] = [ |
||
| 557 | 'attr' => [ |
||
| 558 | 'href' => [ |
||
| 559 | 'url' => 'display.php', |
||
| 560 | 'urlvars' => array_merge( |
||
| 561 | $_gets, |
||
| 562 | [ |
||
| 563 | 'strings' => $_REQUEST['strings'], |
||
| 564 | 'page' => $_REQUEST['page'], |
||
| 565 | ] |
||
| 566 | ), |
||
| 567 | ], |
||
| 568 | ], |
||
| 569 | 'content' => $lang['strrefresh'], |
||
| 570 | ]; |
||
| 571 | |||
| 572 | $this->printNavLinks($navlinks, 'display-browse', get_defined_vars()); |
||
| 573 | } |
||
| 1048 |