| Total Complexity | 112 |
| Total Lines | 888 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like ViewsController 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 ViewsController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class ViewsController extends BaseController |
||
| 15 | { |
||
| 16 | public $script = 'views.php'; |
||
| 17 | public $controller_name = 'ViewsController'; |
||
| 18 | public $table_place = 'views-views'; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Default method to render the controller according to the action parameter. |
||
| 22 | */ |
||
| 23 | public function render() |
||
| 104 | } |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Show default list of views in the database. |
||
| 108 | * |
||
| 109 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 110 | */ |
||
| 111 | public function doDefault($msg = '') |
||
| 112 | { |
||
| 113 | $lang = $this->lang; |
||
| 114 | $data = $this->misc->getDatabaseAccessor(); |
||
| 115 | |||
| 116 | $this->printTrail('schema'); |
||
| 117 | $this->printTabs('schema', 'views'); |
||
| 118 | $this->printMsg($msg); |
||
| 119 | |||
| 120 | $views = $data->getViews(); |
||
| 121 | |||
| 122 | $columns = [ |
||
| 123 | 'view' => [ |
||
| 124 | 'title' => $lang['strview'], |
||
| 125 | 'field' => Decorator::field('relname'), |
||
| 126 | 'url' => \SUBFOLDER . "/redirect/view?{$this->misc->href}&", |
||
| 127 | 'vars' => ['view' => 'relname'], |
||
| 128 | ], |
||
| 129 | 'owner' => [ |
||
| 130 | 'title' => $lang['strowner'], |
||
| 131 | 'field' => Decorator::field('relowner'), |
||
| 132 | ], |
||
| 133 | 'actions' => [ |
||
| 134 | 'title' => $lang['stractions'], |
||
| 135 | ], |
||
| 136 | 'comment' => [ |
||
| 137 | 'title' => $lang['strcomment'], |
||
| 138 | 'field' => Decorator::field('relcomment'), |
||
| 139 | ], |
||
| 140 | ]; |
||
| 141 | |||
| 142 | $actions = [ |
||
| 143 | 'multiactions' => [ |
||
| 144 | 'keycols' => ['view' => 'relname'], |
||
| 145 | 'url' => 'views.php', |
||
| 146 | ], |
||
| 147 | 'browse' => [ |
||
| 148 | 'content' => $lang['strbrowse'], |
||
| 149 | 'attr' => [ |
||
| 150 | 'href' => [ |
||
| 151 | 'url' => 'display.php', |
||
| 152 | 'urlvars' => [ |
||
| 153 | 'action' => 'confselectrows', |
||
| 154 | 'subject' => 'view', |
||
| 155 | 'return' => 'schema', |
||
| 156 | 'view' => Decorator::field('relname'), |
||
| 157 | ], |
||
| 158 | ], |
||
| 159 | ], |
||
| 160 | ], |
||
| 161 | 'select' => [ |
||
| 162 | 'content' => $lang['strselect'], |
||
| 163 | 'attr' => [ |
||
| 164 | 'href' => [ |
||
| 165 | 'url' => 'views.php', |
||
| 166 | 'urlvars' => [ |
||
| 167 | 'action' => 'confselectrows', |
||
| 168 | 'view' => Decorator::field('relname'), |
||
| 169 | ], |
||
| 170 | ], |
||
| 171 | ], |
||
| 172 | ], |
||
| 173 | |||
| 174 | // Insert is possible if the relevant rule for the view has been created. |
||
| 175 | // 'insert' => array( |
||
| 176 | // 'title' => $lang['strinsert'], |
||
| 177 | // 'url' => "views.php?action=confinsertrow&{$this->misc->href}&", |
||
| 178 | // 'vars' => array('view' => 'relname'), |
||
| 179 | // ), |
||
| 180 | |||
| 181 | 'alter' => [ |
||
| 182 | 'content' => $lang['stralter'], |
||
| 183 | 'attr' => [ |
||
| 184 | 'href' => [ |
||
| 185 | 'url' => 'viewproperties.php', |
||
| 186 | 'urlvars' => [ |
||
| 187 | 'action' => 'confirm_alter', |
||
| 188 | 'view' => Decorator::field('relname'), |
||
| 189 | ], |
||
| 190 | ], |
||
| 191 | ], |
||
| 192 | ], |
||
| 193 | 'drop' => [ |
||
| 194 | 'multiaction' => 'confirm_drop', |
||
| 195 | 'content' => $lang['strdrop'], |
||
| 196 | 'attr' => [ |
||
| 197 | 'href' => [ |
||
| 198 | 'url' => 'views.php', |
||
| 199 | 'urlvars' => [ |
||
| 200 | 'action' => 'confirm_drop', |
||
| 201 | 'view' => Decorator::field('relname'), |
||
| 202 | ], |
||
| 203 | ], |
||
| 204 | ], |
||
| 205 | ], |
||
| 206 | ]; |
||
| 207 | |||
| 208 | echo $this->printTable($views, $columns, $actions, $this->table_place, $lang['strnoviews']); |
||
| 209 | |||
| 210 | $navlinks = [ |
||
| 211 | 'create' => [ |
||
| 212 | 'attr' => [ |
||
| 213 | 'href' => [ |
||
| 214 | 'url' => 'views.php', |
||
| 215 | 'urlvars' => [ |
||
| 216 | 'action' => 'create', |
||
| 217 | 'server' => $_REQUEST['server'], |
||
| 218 | 'database' => $_REQUEST['database'], |
||
| 219 | 'schema' => $_REQUEST['schema'], |
||
| 220 | ], |
||
| 221 | ], |
||
| 222 | ], |
||
| 223 | 'content' => $lang['strcreateview'], |
||
| 224 | ], |
||
| 225 | 'createwiz' => [ |
||
| 226 | 'attr' => [ |
||
| 227 | 'href' => [ |
||
| 228 | 'url' => 'views.php', |
||
| 229 | 'urlvars' => [ |
||
| 230 | 'action' => 'wiz_create', |
||
| 231 | 'server' => $_REQUEST['server'], |
||
| 232 | 'database' => $_REQUEST['database'], |
||
| 233 | 'schema' => $_REQUEST['schema'], |
||
| 234 | ], |
||
| 235 | ], |
||
| 236 | ], |
||
| 237 | 'content' => $lang['strcreateviewwiz'], |
||
| 238 | ], |
||
| 239 | ]; |
||
| 240 | $this->printNavLinks($navlinks, $this->table_place, get_defined_vars()); |
||
| 241 | } |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Generate XML for the browser tree. |
||
| 245 | */ |
||
| 246 | public function doTree() |
||
| 247 | { |
||
| 248 | $lang = $this->lang; |
||
| 249 | $data = $this->misc->getDatabaseAccessor(); |
||
| 250 | |||
| 251 | $views = $data->getViews(); |
||
| 252 | |||
| 253 | $reqvars = $this->misc->getRequestVars('view'); |
||
| 254 | |||
| 255 | $attrs = [ |
||
| 256 | 'text' => Decorator::field('relname'), |
||
| 257 | 'icon' => 'View', |
||
| 258 | 'iconAction' => Decorator::url('display.php', $reqvars, ['view' => Decorator::field('relname')]), |
||
| 259 | 'toolTip' => Decorator::field('relcomment'), |
||
| 260 | 'action' => Decorator::redirecturl('redirect.php', $reqvars, ['view' => Decorator::field('relname')]), |
||
| 261 | 'branch' => Decorator::url('views.php', $reqvars, ['action' => 'subtree', 'view' => Decorator::field('relname')]), |
||
| 262 | ]; |
||
| 263 | |||
| 264 | return $this->printTree($views, $attrs, 'views'); |
||
| 265 | } |
||
| 266 | |||
| 267 | public function doSubTree() |
||
|
1 ignored issue
–
show
|
|||
| 268 | { |
||
| 269 | $lang = $this->lang; |
||
| 270 | $data = $this->misc->getDatabaseAccessor(); |
||
| 271 | |||
| 272 | $tabs = $this->misc->getNavTabs('view'); |
||
| 273 | $items = $this->adjustTabsForTree($tabs); |
||
| 274 | $reqvars = $this->misc->getRequestVars('view'); |
||
| 275 | |||
| 276 | $attrs = [ |
||
| 277 | 'text' => Decorator::field('title'), |
||
| 278 | 'icon' => Decorator::field('icon'), |
||
| 279 | 'action' => Decorator::actionurl(Decorator::field('url'), $reqvars, Decorator::field('urlvars'), ['view' => $_REQUEST['view']]), |
||
| 280 | 'branch' => Decorator::ifempty( |
||
| 281 | Decorator::field('branch'), |
||
| 282 | '', |
||
| 283 | Decorator::url( |
||
| 284 | Decorator::field('url'), |
||
| 285 | Decorator::field('urlvars'), |
||
| 286 | $reqvars, |
||
| 287 | [ |
||
| 288 | 'action' => 'tree', |
||
| 289 | 'view' => $_REQUEST['view'], |
||
| 290 | ] |
||
| 291 | ) |
||
| 292 | ), |
||
| 293 | ]; |
||
| 294 | |||
| 295 | return $this->printTree($items, $attrs, 'view'); |
||
| 296 | } |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Ask for select parameters and perform select. |
||
| 300 | * |
||
| 301 | * @param mixed $confirm |
||
|
1 ignored issue
–
show
|
|||
| 302 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 303 | */ |
||
| 304 | public function doSelectRows($confirm, $msg = '') |
||
| 305 | { |
||
| 306 | $lang = $this->lang; |
||
| 307 | $data = $this->misc->getDatabaseAccessor(); |
||
| 308 | |||
| 309 | if ($confirm) { |
||
| 310 | $this->printTrail('view'); |
||
| 311 | $this->printTabs('view', 'select'); |
||
| 312 | $this->printMsg($msg); |
||
| 313 | |||
| 314 | $attrs = $data->getTableAttributes($_REQUEST['view']); |
||
| 315 | |||
| 316 | echo '<form action="' . \SUBFOLDER . '/src/views/' . $this->script . '" method="post" id="selectform">'; |
||
| 317 | echo "\n"; |
||
| 318 | |||
| 319 | if ($attrs->recordCount() > 0) { |
||
| 320 | // JavaScript for select all feature |
||
| 321 | echo "<script type=\"text/javascript\">\n"; |
||
| 322 | echo "//<![CDATA[\n"; |
||
| 323 | echo " function selectAll() {\n"; |
||
| 324 | echo " for (var i=0; i<document.getElementById('selectform').elements.length; i++) {\n"; |
||
| 325 | echo " var e = document.getElementById('selectform').elements[i];\n"; |
||
| 326 | echo " if (e.name.indexOf('show') == 0) { \n "; |
||
| 327 | echo " e.checked = document.getElementById('selectform').selectall.checked;\n"; |
||
| 328 | echo " }\n"; |
||
| 329 | echo " }\n"; |
||
| 330 | echo " }\n"; |
||
| 331 | echo "//]]>\n"; |
||
| 332 | echo "</script>\n"; |
||
| 333 | |||
| 334 | echo "<table>\n"; |
||
| 335 | |||
| 336 | // Output table header |
||
| 337 | echo "<tr><th class=\"data\">{$lang['strshow']}</th><th class=\"data\">{$lang['strcolumn']}</th>"; |
||
| 338 | echo "<th class=\"data\">{$lang['strtype']}</th><th class=\"data\">{$lang['stroperator']}</th>"; |
||
| 339 | echo "<th class=\"data\">{$lang['strvalue']}</th></tr>"; |
||
| 340 | |||
| 341 | $i = 0; |
||
| 342 | while (!$attrs->EOF) { |
||
| 343 | $attrs->fields['attnotnull'] = $data->phpBool($attrs->fields['attnotnull']); |
||
| 344 | // Set up default value if there isn't one already |
||
| 345 | if (!isset($_REQUEST['values'][$attrs->fields['attname']])) { |
||
| 346 | $_REQUEST['values'][$attrs->fields['attname']] = null; |
||
| 347 | } |
||
| 348 | |||
| 349 | if (!isset($_REQUEST['ops'][$attrs->fields['attname']])) { |
||
| 350 | $_REQUEST['ops'][$attrs->fields['attname']] = null; |
||
| 351 | } |
||
| 352 | |||
| 353 | // Continue drawing row |
||
| 354 | $id = (0 == ($i % 2) ? '1' : '2'); |
||
| 355 | echo "<tr class=\"data{$id}\">\n"; |
||
| 356 | echo '<td style="white-space:nowrap;">'; |
||
| 357 | echo '<input type="checkbox" name="show[', htmlspecialchars($attrs->fields['attname']), ']"', |
||
| 358 | isset($_REQUEST['show'][$attrs->fields['attname']]) ? ' checked="checked"' : '', ' /></td>'; |
||
| 359 | echo '<td style="white-space:nowrap;">', $this->misc->printVal($attrs->fields['attname']), '</td>'; |
||
| 360 | echo '<td style="white-space:nowrap;">', $this->misc->printVal($data->formatType($attrs->fields['type'], $attrs->fields['atttypmod'])), '</td>'; |
||
| 361 | echo '<td style="white-space:nowrap;">'; |
||
| 362 | echo "<select name=\"ops[{$attrs->fields['attname']}]\">\n"; |
||
| 363 | foreach (array_keys($data->selectOps) as $v) { |
||
| 364 | echo '<option value="', htmlspecialchars($v), '"', ($_REQUEST['ops'][$attrs->fields['attname']] == $v) ? ' selected="selected"' : '', |
||
| 365 | '>', htmlspecialchars($v), "</option>\n"; |
||
| 366 | } |
||
| 367 | echo "</select></td>\n"; |
||
| 368 | echo '<td style="white-space:nowrap;">', $data->printField( |
||
| 369 | "values[{$attrs->fields['attname']}]", |
||
| 370 | $_REQUEST['values'][$attrs->fields['attname']], |
||
| 371 | $attrs->fields['type'] |
||
| 372 | ), '</td>'; |
||
| 373 | echo "</tr>\n"; |
||
| 374 | ++$i; |
||
| 375 | $attrs->moveNext(); |
||
| 376 | } |
||
| 377 | // Select all checkbox |
||
| 378 | echo "<tr><td colspan=\"5\"><input type=\"checkbox\" id=\"selectall\" name=\"selectall\" accesskey=\"a\" onclick=\"javascript:selectAll()\" /><label for=\"selectall\">{$lang['strselectallfields']}</label></td></tr>"; |
||
| 379 | echo "</table>\n"; |
||
| 380 | } else { |
||
| 381 | echo "<p>{$lang['strinvalidparam']}</p>\n"; |
||
| 382 | } |
||
| 383 | |||
| 384 | echo "<p><input type=\"hidden\" name=\"action\" value=\"selectrows\" />\n"; |
||
| 385 | echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST['view']), "\" />\n"; |
||
| 386 | echo "<input type=\"hidden\" name=\"subject\" value=\"view\" />\n"; |
||
| 387 | echo $this->misc->form; |
||
| 388 | echo "<input type=\"submit\" name=\"select\" accesskey=\"r\" value=\"{$lang['strselect']}\" />\n"; |
||
| 389 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 390 | echo "</form>\n"; |
||
| 391 | |||
| 392 | return; |
||
| 393 | } |
||
| 394 | if (!isset($_POST['show'])) { |
||
| 395 | $_POST['show'] = []; |
||
| 396 | } |
||
| 397 | |||
| 398 | if (!isset($_POST['values'])) { |
||
| 399 | $_POST['values'] = []; |
||
| 400 | } |
||
| 401 | |||
| 402 | if (!isset($_POST['nulls'])) { |
||
| 403 | $_POST['nulls'] = []; |
||
| 404 | } |
||
| 405 | |||
| 406 | // Verify that they haven't supplied a value for unary operators |
||
| 407 | foreach ($_POST['ops'] as $k => $v) { |
||
| 408 | if ('p' == $data->selectOps[$v] && $_POST['values'][$k] != '') { |
||
| 409 | $this->doSelectRows(true, $lang['strselectunary']); |
||
| 410 | |||
| 411 | return; |
||
| 412 | } |
||
| 413 | } |
||
| 414 | |||
| 415 | if (0 == sizeof($_POST['show'])) { |
||
| 416 | return $this->doSelectRows(true, $lang['strselectneedscol']); |
||
| 417 | } |
||
| 418 | // Generate query SQL |
||
| 419 | $query = $data->getSelectSQL($_REQUEST['view'], array_keys($_POST['show']), $_POST['values'], $_POST['ops']); |
||
| 420 | |||
| 421 | $_REQUEST['query'] = $query; |
||
| 422 | $_REQUEST['return'] = 'schema'; |
||
| 423 | |||
| 424 | $this->setNoOutput(true); |
||
| 425 | |||
| 426 | $display_controller = new DisplayController($this->getContainer()); |
||
| 427 | |||
| 428 | return $display_controller->render(); |
||
| 429 | } |
||
| 430 | |||
| 431 | /** |
||
| 432 | * Show confirmation of drop and perform actual drop. |
||
| 433 | * |
||
| 434 | * @param mixed $confirm |
||
|
1 ignored issue
–
show
|
|||
| 435 | */ |
||
| 436 | public function doDrop($confirm) |
||
| 501 | } |
||
| 502 | } |
||
| 503 | } |
||
| 504 | } |
||
| 505 | |||
| 506 | /** |
||
| 507 | * Sets up choices for table linkage, and which fields to select for the view we're creating. |
||
| 508 | * |
||
| 509 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 510 | */ |
||
| 511 | public function doSetParamsCreate($msg = '') |
||
| 512 | { |
||
| 513 | $lang = $this->lang; |
||
| 514 | $data = $this->misc->getDatabaseAccessor(); |
||
| 515 | |||
| 516 | // Check that they've chosen tables for the view definition |
||
| 517 | if (!isset($_POST['formTables'])) { |
||
| 518 | $this->doWizardCreate($lang['strviewneedsdef']); |
||
| 519 | } else { |
||
| 520 | // Initialise variables |
||
| 521 | if (!isset($_REQUEST['formView'])) { |
||
| 522 | $_REQUEST['formView'] = ''; |
||
| 523 | } |
||
| 524 | |||
| 525 | if (!isset($_REQUEST['formComment'])) { |
||
| 526 | $_REQUEST['formComment'] = ''; |
||
| 527 | } |
||
| 528 | |||
| 529 | $this->printTrail('schema'); |
||
| 530 | $this->printTitle($lang['strcreateviewwiz'], 'pg.view.create'); |
||
| 531 | $this->printMsg($msg); |
||
| 532 | |||
| 533 | $tblCount = sizeof($_POST['formTables']); |
||
| 534 | //unserialize our schema/table information and store in arrSelTables |
||
| 535 | for ($i = 0; $i < $tblCount; ++$i) { |
||
| 536 | $arrSelTables[] = unserialize($_POST['formTables'][$i]); |
||
| 537 | } |
||
| 538 | |||
| 539 | $linkCount = $tblCount; |
||
| 540 | |||
| 541 | //get linking keys |
||
| 542 | $rsLinkKeys = $data->getLinkingKeys($arrSelTables); |
||
| 543 | $linkCount = $rsLinkKeys->recordCount() > $tblCount ? $rsLinkKeys->recordCount() : $tblCount; |
||
| 544 | |||
| 545 | $arrFields = []; //array that will hold all our table/field names |
||
| 546 | |||
| 547 | //if we have schemas we need to specify the correct schema for each table we're retrieiving |
||
| 548 | //with getTableAttributes |
||
| 549 | $curSchema = $data->_schema; |
||
| 550 | for ($i = 0; $i < $tblCount; ++$i) { |
||
| 551 | if ($arrSelTables[$i]['schemaname'] != $data->_schema) { |
||
| 552 | $data->setSchema($arrSelTables[$i]['schemaname']); |
||
| 553 | } |
||
| 554 | |||
| 555 | $attrs = $data->getTableAttributes($arrSelTables[$i]['tablename']); |
||
| 556 | while (!$attrs->EOF) { |
||
| 557 | $arrFields["{$arrSelTables[$i]['schemaname']}.{$arrSelTables[$i]['tablename']}.{$attrs->fields['attname']}"] = serialize( |
||
| 558 | [ |
||
| 559 | 'schemaname' => $arrSelTables[$i]['schemaname'], |
||
| 560 | 'tablename' => $arrSelTables[$i]['tablename'], |
||
| 561 | 'fieldname' => $attrs->fields['attname']] |
||
| 562 | ); |
||
| 563 | $attrs->moveNext(); |
||
| 564 | } |
||
| 565 | |||
| 566 | $data->setSchema($curSchema); |
||
| 567 | } |
||
| 568 | asort($arrFields); |
||
| 569 | |||
| 570 | echo '<form action="' . \SUBFOLDER . "/src/views/views.php\" method=\"post\">\n"; |
||
| 571 | echo "<table>\n"; |
||
| 572 | echo "<tr><th class=\"data\">{$lang['strviewname']}</th></tr>"; |
||
| 573 | echo "<tr>\n<td class=\"data1\">\n"; |
||
| 574 | // View name |
||
| 575 | echo '<input name="formView" value="', htmlspecialchars($_REQUEST['formView']), "\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" />\n"; |
||
| 576 | echo "</td>\n</tr>\n"; |
||
| 577 | echo "<tr><th class=\"data\">{$lang['strcomment']}</th></tr>"; |
||
| 578 | echo "<tr>\n<td class=\"data1\">\n"; |
||
| 579 | // View comments |
||
| 580 | echo '<textarea name="formComment" rows="3" cols="32">', |
||
| 581 | htmlspecialchars($_REQUEST['formComment']), "</textarea>\n"; |
||
| 582 | echo "</td>\n</tr>\n"; |
||
| 583 | echo "</table>\n"; |
||
| 584 | |||
| 585 | // Output selector for fields to be retrieved from view |
||
| 586 | echo "<table>\n"; |
||
| 587 | echo "<tr><th class=\"data\">{$lang['strcolumns']}</th></tr>"; |
||
| 588 | echo "<tr>\n<td class=\"data1\">\n"; |
||
| 589 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrFields, 'formFields[]', false, '', true); |
||
| 590 | echo "</td>\n</tr>"; |
||
| 591 | echo "<tr><td><input type=\"radio\" name=\"dblFldMeth\" id=\"dblFldMeth1\" value=\"rename\" /><label for=\"dblFldMeth1\">{$lang['strrenamedupfields']}</label>"; |
||
| 592 | echo "<br /><input type=\"radio\" name=\"dblFldMeth\" id=\"dblFldMeth2\" value=\"drop\" /><label for=\"dblFldMeth2\">{$lang['strdropdupfields']}</label>"; |
||
| 593 | echo "<br /><input type=\"radio\" name=\"dblFldMeth\" id=\"dblFldMeth3\" value=\"\" checked=\"checked\" /><label for=\"dblFldMeth3\">{$lang['strerrordupfields']}</label></td></tr></table><br />"; |
||
| 594 | |||
| 595 | // Output the Linking keys combo boxes |
||
| 596 | echo "<table>\n"; |
||
| 597 | echo "<tr><th class=\"data\">{$lang['strviewlink']}</th></tr>"; |
||
| 598 | $rowClass = 'data1'; |
||
| 599 | for ($i = 0; $i < $linkCount; ++$i) { |
||
| 600 | // Initialise variables |
||
| 601 | if (!isset($formLink[$i]['operator'])) { |
||
| 602 | $formLink[$i]['operator'] = 'INNER JOIN'; |
||
| 603 | } |
||
| 604 | |||
| 605 | echo "<tr>\n<td class=\"${rowClass}\">\n"; |
||
| 606 | |||
| 607 | if (!$rsLinkKeys->EOF) { |
||
| 608 | $curLeftLink = htmlspecialchars(serialize(['schemaname' => $rsLinkKeys->fields['p_schema'], 'tablename' => $rsLinkKeys->fields['p_table'], 'fieldname' => $rsLinkKeys->fields['p_field']])); |
||
| 609 | $curRightLink = htmlspecialchars(serialize(['schemaname' => $rsLinkKeys->fields['f_schema'], 'tablename' => $rsLinkKeys->fields['f_table'], 'fieldname' => $rsLinkKeys->fields['f_field']])); |
||
| 610 | $rsLinkKeys->moveNext(); |
||
| 611 | } else { |
||
| 612 | $curLeftLink = ''; |
||
| 613 | $curRightLink = ''; |
||
| 614 | } |
||
| 615 | |||
| 616 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrFields, "formLink[${i}][leftlink]", true, $curLeftLink, false); |
||
| 617 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($data->joinOps, "formLink[${i}][operator]", true, $formLink[$i]['operator']); |
||
| 618 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrFields, "formLink[${i}][rightlink]", true, $curRightLink, false); |
||
| 619 | echo "</td>\n</tr>\n"; |
||
| 620 | $rowClass = 'data1' == $rowClass ? 'data2' : 'data1'; |
||
| 621 | } |
||
| 622 | echo "</table>\n<br />\n"; |
||
| 623 | |||
| 624 | // Build list of available operators (infix only) |
||
| 625 | $arrOperators = []; |
||
| 626 | foreach ($data->selectOps as $k => $v) { |
||
| 627 | if ('i' == $v) { |
||
| 628 | $arrOperators[$k] = $k; |
||
| 629 | } |
||
| 630 | } |
||
| 631 | |||
| 632 | // Output additional conditions, note that this portion of the wizard treats the right hand side as literal values |
||
| 633 | //(not as database objects) so field names will be treated as strings, use the above linking keys section to perform joins |
||
| 634 | echo "<table>\n"; |
||
| 635 | echo "<tr><th class=\"data\">{$lang['strviewconditions']}</th></tr>"; |
||
| 636 | $rowClass = 'data1'; |
||
| 637 | for ($i = 0; $i < $linkCount; ++$i) { |
||
| 638 | echo "<tr>\n<td class=\"${rowClass}\">\n"; |
||
| 639 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrFields, "formCondition[${i}][field]"); |
||
| 640 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrOperators, "formCondition[${i}][operator]", false, false); |
||
| 641 | echo "<input type=\"text\" name=\"formCondition[${i}][txt]\" />\n"; |
||
| 642 | echo "</td>\n</tr>\n"; |
||
| 643 | $rowClass = 'data1' == $rowClass ? 'data2' : 'data1'; |
||
| 644 | } |
||
| 645 | echo "</table>\n"; |
||
| 646 | echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create_wiz\" />\n"; |
||
| 647 | |||
| 648 | foreach ($arrSelTables as $curTable) { |
||
| 649 | echo '<input type="hidden" name="formTables[]" value="' . htmlspecialchars(serialize($curTable)) . "\" />\n"; |
||
| 650 | } |
||
| 651 | |||
| 652 | echo $this->misc->form; |
||
| 653 | echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n"; |
||
| 654 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 655 | echo "</form>\n"; |
||
| 656 | } |
||
| 657 | } |
||
| 658 | |||
| 659 | /** |
||
| 660 | * Display a wizard where they can enter a new view. |
||
| 661 | * |
||
| 662 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 663 | */ |
||
| 664 | public function doWizardCreate($msg = '') |
||
| 665 | { |
||
| 666 | $lang = $this->lang; |
||
| 667 | $data = $this->misc->getDatabaseAccessor(); |
||
| 668 | |||
| 669 | $tables = $data->getTables(true); |
||
| 670 | |||
| 671 | $this->printTrail('schema'); |
||
| 672 | $this->printTitle($lang['strcreateviewwiz'], 'pg.view.create'); |
||
| 673 | $this->printMsg($msg); |
||
| 674 | |||
| 675 | echo '<form action="' . \SUBFOLDER . "/src/views/views.php\" method=\"post\">\n"; |
||
| 676 | echo "<table>\n"; |
||
| 677 | echo "<tr><th class=\"data\">{$lang['strtables']}</th></tr>"; |
||
| 678 | echo "<tr>\n<td class=\"data1\">\n"; |
||
| 679 | |||
| 680 | $arrTables = []; |
||
| 681 | while (!$tables->EOF) { |
||
| 682 | $arrTmp = []; |
||
| 683 | $arrTmp['schemaname'] = $tables->fields['nspname']; |
||
| 684 | $arrTmp['tablename'] = $tables->fields['relname']; |
||
| 685 | $arrTables[$tables->fields['nspname'] . '.' . $tables->fields['relname']] = serialize($arrTmp); |
||
| 686 | $tables->moveNext(); |
||
| 687 | } |
||
| 688 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($arrTables, 'formTables[]', false, '', true); |
||
| 689 | |||
| 690 | echo "</td>\n</tr>\n"; |
||
| 691 | echo "</table>\n"; |
||
| 692 | echo "<p><input type=\"hidden\" name=\"action\" value=\"set_params_create\" />\n"; |
||
| 693 | echo $this->misc->form; |
||
| 694 | echo "<input type=\"submit\" value=\"{$lang['strnext']}\" />\n"; |
||
| 695 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 696 | echo "</form>\n"; |
||
| 697 | } |
||
| 698 | |||
| 699 | /** |
||
| 700 | * Displays a screen where they can enter a new view. |
||
| 701 | * |
||
| 702 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 703 | */ |
||
| 704 | public function doCreate($msg = '') |
||
| 705 | { |
||
| 706 | $lang = $this->lang; |
||
| 707 | $data = $this->misc->getDatabaseAccessor(); |
||
| 708 | |||
| 709 | if (!isset($_REQUEST['formView'])) { |
||
| 710 | $_REQUEST['formView'] = ''; |
||
| 711 | } |
||
| 712 | |||
| 713 | if (!isset($_REQUEST['formDefinition'])) { |
||
| 714 | if (isset($_SESSION['sqlquery'])) { |
||
| 715 | $_REQUEST['formDefinition'] = $_SESSION['sqlquery']; |
||
| 716 | } else { |
||
| 717 | $_REQUEST['formDefinition'] = 'SELECT '; |
||
| 718 | } |
||
| 719 | } |
||
| 720 | if (!isset($_REQUEST['formComment'])) { |
||
| 721 | $_REQUEST['formComment'] = ''; |
||
| 722 | } |
||
| 723 | |||
| 724 | $this->printTrail('schema'); |
||
| 725 | $this->printTitle($lang['strcreateview'], 'pg.view.create'); |
||
| 726 | $this->printMsg($msg); |
||
| 727 | |||
| 728 | echo '<form action="' . \SUBFOLDER . "/src/views/views.php\" method=\"post\">\n"; |
||
| 729 | echo "<table style=\"width: 100%\">\n"; |
||
| 730 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n"; |
||
| 731 | echo "\t<td class=\"data1\"><input name=\"formView\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 732 | htmlspecialchars($_REQUEST['formView']), "\" /></td>\n\t</tr>\n"; |
||
| 733 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strdefinition']}</th>\n"; |
||
| 734 | echo "\t<td class=\"data1\"><textarea style=\"width:100%;\" rows=\"10\" cols=\"50\" name=\"formDefinition\">", |
||
| 735 | htmlspecialchars($_REQUEST['formDefinition']), "</textarea></td>\n\t</tr>\n"; |
||
| 736 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n"; |
||
| 737 | echo "\t\t<td class=\"data1\"><textarea name=\"formComment\" rows=\"3\" cols=\"32\">", |
||
| 738 | htmlspecialchars($_REQUEST['formComment']), "</textarea></td>\n\t</tr>\n"; |
||
| 739 | echo "</table>\n"; |
||
| 740 | echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create\" />\n"; |
||
| 741 | echo $this->misc->form; |
||
| 742 | echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n"; |
||
| 743 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 744 | echo "</form>\n"; |
||
| 745 | } |
||
| 746 | |||
| 747 | /** |
||
| 748 | * Actually creates the new view in the database. |
||
| 749 | */ |
||
| 750 | public function doSaveCreate() |
||
| 751 | { |
||
| 752 | $lang = $this->lang; |
||
| 753 | $data = $this->misc->getDatabaseAccessor(); |
||
| 754 | |||
| 755 | // Check that they've given a name and a definition |
||
| 756 | if ('' == $_POST['formView']) { |
||
| 757 | $this->doCreate($lang['strviewneedsname']); |
||
| 758 | } elseif ('' == $_POST['formDefinition']) { |
||
| 759 | $this->doCreate($lang['strviewneedsdef']); |
||
| 760 | } else { |
||
| 761 | $status = $data->createView($_POST['formView'], $_POST['formDefinition'], false, $_POST['formComment']); |
||
| 762 | if (0 == $status) { |
||
| 763 | $this->misc->setReloadBrowser(true); |
||
| 764 | $this->doDefault($lang['strviewcreated']); |
||
| 765 | } else { |
||
| 766 | $this->doCreate($lang['strviewcreatedbad']); |
||
| 767 | } |
||
| 768 | } |
||
| 769 | } |
||
| 770 | |||
| 771 | /** |
||
| 772 | * Actually creates the new wizard view in the database. |
||
| 773 | */ |
||
| 774 | public function doSaveCreateWiz() |
||
| 902 | } |
||
| 903 | } |
||
| 904 | } |
||
| 905 | } |
||
| 906 |