HuasoFoundries /
phpPgAdmin6
| 1 | <?php |
||
| 2 | |||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 3 | /* |
||
| 4 | * PHPPgAdmin v6.0.0-beta.30 |
||
| 5 | */ |
||
| 6 | |||
| 7 | namespace PHPPgAdmin\Controller; |
||
| 8 | |||
| 9 | use PHPPgAdmin\Decorators\Decorator; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Base controller class. |
||
| 13 | */ |
||
| 14 | class MaterializedviewpropertiesController extends BaseController |
||
| 15 | { |
||
| 16 | public $controller_name = 'MaterializedviewpropertiesController'; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Default method to render the controller according to the action parameter. |
||
| 20 | */ |
||
| 21 | public function render() |
||
| 22 | { |
||
| 23 | $lang = $this->lang; |
||
| 24 | |||
| 25 | $action = $this->action; |
||
| 26 | if ('tree' == $action) { |
||
| 27 | return $this->doTree(); |
||
| 28 | } |
||
| 29 | |||
| 30 | $this->printHeader($lang['strviews'] . ' - ' . $_REQUEST['matview']); |
||
| 31 | $this->printBody(); |
||
| 32 | |||
| 33 | switch ($action) { |
||
| 34 | case 'save_edit': |
||
| 35 | if (isset($_POST['cancel'])) { |
||
| 36 | $this->doDefinition(); |
||
| 37 | } else { |
||
| 38 | $this->doSaveEdit(); |
||
| 39 | } |
||
| 40 | |||
| 41 | break; |
||
| 42 | case 'edit': |
||
| 43 | $this->doEdit(); |
||
| 44 | |||
| 45 | break; |
||
| 46 | case 'export': |
||
| 47 | $this->doExport(); |
||
| 48 | |||
| 49 | break; |
||
| 50 | case 'definition': |
||
| 51 | $this->doDefinition(); |
||
| 52 | |||
| 53 | break; |
||
| 54 | case 'properties': |
||
| 55 | if (isset($_POST['cancel'])) { |
||
| 56 | $this->doDefault(); |
||
| 57 | } else { |
||
| 58 | $this->doProperties(); |
||
| 59 | } |
||
| 60 | |||
| 61 | break; |
||
| 62 | case 'alter': |
||
| 63 | if (isset($_POST['alter'])) { |
||
| 64 | $this->doAlter(false); |
||
| 65 | } else { |
||
| 66 | $this->doDefault(); |
||
| 67 | } |
||
| 68 | |||
| 69 | break; |
||
| 70 | case 'confirm_alter': |
||
| 71 | doAlter(true); |
||
| 72 | |||
| 73 | break; |
||
| 74 | case 'drop': |
||
| 75 | if (isset($_POST['drop'])) { |
||
| 76 | $this->doDrop(false); |
||
| 77 | } else { |
||
| 78 | $this->doDefault(); |
||
| 79 | } |
||
| 80 | |||
| 81 | break; |
||
| 82 | case 'confirm_drop': |
||
| 83 | $this->doDrop(true); |
||
| 84 | |||
| 85 | break; |
||
| 86 | default: |
||
| 87 | $this->doDefault(); |
||
| 88 | |||
| 89 | break; |
||
| 90 | } |
||
| 91 | |||
| 92 | $this->printFooter(); |
||
| 93 | } |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Show view definition and virtual columns. |
||
| 97 | * |
||
| 98 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 99 | */ |
||
| 100 | public function doDefault($msg = '') |
||
| 101 | { |
||
| 102 | $lang = $this->lang; |
||
| 103 | $data = $this->misc->getDatabaseAccessor(); |
||
| 104 | |||
| 105 | $attPre = function (&$rowdata) use ($data) { |
||
| 106 | $rowdata->fields['+type'] = $data->formatType($rowdata->fields['type'], $rowdata->fields['atttypmod']); |
||
| 107 | }; |
||
| 108 | |||
| 109 | $this->printTrail('matview'); |
||
| 110 | $this->printTabs('matview', 'columns'); |
||
| 111 | $this->printMsg($msg); |
||
| 112 | |||
| 113 | // Get view |
||
| 114 | $vdata = $data->getView($_REQUEST['matview']); |
||
| 115 | // Get columns (using same method for getting a view) |
||
| 116 | $attrs = $data->getTableAttributes($_REQUEST['matview']); |
||
| 117 | |||
| 118 | // Show comment if any |
||
| 119 | if (null !== $vdata->fields['relcomment']) { |
||
| 120 | echo '<p class="comment">', $this->misc->printVal($vdata->fields['relcomment']), "</p>\n"; |
||
| 121 | } |
||
| 122 | |||
| 123 | $columns = [ |
||
| 124 | 'column' => [ |
||
| 125 | 'title' => $lang['strcolumn'], |
||
| 126 | 'field' => Decorator::field('attname'), |
||
| 127 | 'url' => "colproperties.php?subject=column&{$this->misc->href}&view=" . urlencode($_REQUEST['matview']) . '&', |
||
| 128 | 'vars' => ['column' => 'attname'], |
||
| 129 | ], |
||
| 130 | 'type' => [ |
||
| 131 | 'title' => $lang['strtype'], |
||
| 132 | 'field' => Decorator::field('+type'), |
||
| 133 | ], |
||
| 134 | 'default' => [ |
||
| 135 | 'title' => $lang['strdefault'], |
||
| 136 | 'field' => Decorator::field('adsrc'), |
||
| 137 | ], |
||
| 138 | 'actions' => [ |
||
| 139 | 'title' => $lang['stractions'], |
||
| 140 | ], |
||
| 141 | 'comment' => [ |
||
| 142 | 'title' => $lang['strcomment'], |
||
| 143 | 'field' => Decorator::field('comment'), |
||
| 144 | ], |
||
| 145 | ]; |
||
| 146 | |||
| 147 | $actions = [ |
||
| 148 | 'alter' => [ |
||
| 149 | 'content' => $lang['stralter'], |
||
| 150 | 'attr' => [ |
||
| 151 | 'href' => [ |
||
| 152 | 'url' => 'materializedviewproperties.php', |
||
| 153 | 'urlvars' => [ |
||
| 154 | 'action' => 'properties', |
||
| 155 | 'view' => $_REQUEST['matview'], |
||
| 156 | 'column' => Decorator::field('attname'), |
||
| 157 | ], |
||
| 158 | ], |
||
| 159 | ], |
||
| 160 | ], |
||
| 161 | ]; |
||
| 162 | |||
| 163 | echo $this->printTable($attrs, $columns, $actions, 'materializedviewproperties-materializedviewproperties', null, $attPre); |
||
| 164 | |||
| 165 | echo "<br />\n"; |
||
| 166 | |||
| 167 | $navlinks = [ |
||
| 168 | 'browse' => [ |
||
| 169 | 'attr' => [ |
||
| 170 | 'href' => [ |
||
| 171 | 'url' => 'display.php', |
||
| 172 | 'urlvars' => [ |
||
| 173 | 'server' => $_REQUEST['server'], |
||
| 174 | 'database' => $_REQUEST['database'], |
||
| 175 | 'schema' => $_REQUEST['schema'], |
||
| 176 | 'matview' => $_REQUEST['matview'], |
||
| 177 | 'subject' => 'matview', |
||
| 178 | 'return' => 'matview', |
||
| 179 | ], |
||
| 180 | ], |
||
| 181 | ], |
||
| 182 | 'content' => $lang['strbrowse'], |
||
| 183 | ], |
||
| 184 | 'select' => [ |
||
| 185 | 'attr' => [ |
||
| 186 | 'href' => [ |
||
| 187 | 'url' => 'materializedviews.php', |
||
| 188 | 'urlvars' => [ |
||
| 189 | 'action' => 'confselectrows', |
||
| 190 | 'server' => $_REQUEST['server'], |
||
| 191 | 'database' => $_REQUEST['database'], |
||
| 192 | 'schema' => $_REQUEST['schema'], |
||
| 193 | 'matview' => $_REQUEST['matview'], |
||
| 194 | ], |
||
| 195 | ], |
||
| 196 | ], |
||
| 197 | 'content' => $lang['strselect'], |
||
| 198 | ], |
||
| 199 | 'drop' => [ |
||
| 200 | 'attr' => [ |
||
| 201 | 'href' => [ |
||
| 202 | 'url' => 'materializedviews.php', |
||
| 203 | 'urlvars' => [ |
||
| 204 | 'action' => 'confirm_drop', |
||
| 205 | 'server' => $_REQUEST['server'], |
||
| 206 | 'database' => $_REQUEST['database'], |
||
| 207 | 'schema' => $_REQUEST['schema'], |
||
| 208 | 'matview' => $_REQUEST['matview'], |
||
| 209 | ], |
||
| 210 | ], |
||
| 211 | ], |
||
| 212 | 'content' => $lang['strdrop'], |
||
| 213 | ], |
||
| 214 | 'alter' => [ |
||
| 215 | 'attr' => [ |
||
| 216 | 'href' => [ |
||
| 217 | 'url' => 'materializedviewproperties.php', |
||
| 218 | 'urlvars' => [ |
||
| 219 | 'action' => 'confirm_alter', |
||
| 220 | 'server' => $_REQUEST['server'], |
||
| 221 | 'database' => $_REQUEST['database'], |
||
| 222 | 'schema' => $_REQUEST['schema'], |
||
| 223 | 'matview' => $_REQUEST['matview'], |
||
| 224 | ], |
||
| 225 | ], |
||
| 226 | ], |
||
| 227 | 'content' => $lang['stralter'], |
||
| 228 | ], |
||
| 229 | ]; |
||
| 230 | |||
| 231 | $this->printNavLinks($navlinks, 'materializedviewproperties-materializedviewproperties', get_defined_vars()); |
||
| 232 | } |
||
| 233 | |||
| 234 | public function doTree() |
||
| 235 | { |
||
| 236 | $lang = $this->lang; |
||
|
0 ignored issues
–
show
|
|||
| 237 | $data = $this->misc->getDatabaseAccessor(); |
||
| 238 | |||
| 239 | $reqvars = $this->misc->getRequestVars('column'); |
||
| 240 | $columns = $data->getTableAttributes($_REQUEST['matview']); |
||
| 241 | |||
| 242 | $attrs = [ |
||
| 243 | 'text' => Decorator::field('attname'), |
||
| 244 | 'action' => Decorator::actionurl( |
||
| 245 | 'colproperties.php', |
||
| 246 | $reqvars, |
||
| 247 | [ |
||
| 248 | 'view' => $_REQUEST['matview'], |
||
| 249 | 'column' => Decorator::field('attname'), |
||
| 250 | ] |
||
| 251 | ), |
||
| 252 | 'icon' => 'Column', |
||
| 253 | 'iconAction' => Decorator::url( |
||
| 254 | 'display.php', |
||
| 255 | $reqvars, |
||
| 256 | [ |
||
| 257 | 'view' => $_REQUEST['matview'], |
||
| 258 | 'column' => Decorator::field('attname'), |
||
| 259 | 'query' => Decorator::replace( |
||
| 260 | 'SELECT "%column%", count(*) AS "count" FROM %view% GROUP BY "%column%" ORDER BY "%column%"', |
||
| 261 | [ |
||
| 262 | '%column%' => Decorator::field('attname'), |
||
| 263 | '%view%' => $_REQUEST['matview'], |
||
| 264 | ] |
||
| 265 | ), |
||
| 266 | ] |
||
| 267 | ), |
||
| 268 | 'toolTip' => Decorator::field('comment'), |
||
| 269 | ]; |
||
| 270 | |||
| 271 | return $this->printTree($columns, $attrs, 'viewcolumns'); |
||
| 272 | } |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Function to save after editing a view. |
||
| 276 | */ |
||
| 277 | public function doSaveEdit() |
||
| 278 | { |
||
| 279 | $lang = $this->lang; |
||
| 280 | $data = $this->misc->getDatabaseAccessor(); |
||
| 281 | |||
| 282 | $status = $data->setView($_POST['view'], $_POST['formDefinition'], $_POST['formComment']); |
||
| 283 | if (0 == $status) { |
||
| 284 | $this->doDefinition($lang['strviewupdated']); |
||
| 285 | } else { |
||
| 286 | $this->doEdit($lang['strviewupdatedbad']); |
||
| 287 | } |
||
| 288 | } |
||
| 289 | |||
| 290 | /** |
||
| 291 | * Function to allow editing of a view. |
||
| 292 | * |
||
| 293 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 294 | */ |
||
| 295 | public function doEdit($msg = '') |
||
| 296 | { |
||
| 297 | $lang = $this->lang; |
||
| 298 | $data = $this->misc->getDatabaseAccessor(); |
||
| 299 | |||
| 300 | $this->printTrail('matview'); |
||
| 301 | $this->printTitle($lang['stredit'], 'pg.matview.alter'); |
||
| 302 | $this->printMsg($msg); |
||
| 303 | |||
| 304 | $viewdata = $data->getView($_REQUEST['matview']); |
||
| 305 | |||
| 306 | if ($viewdata->recordCount() > 0) { |
||
| 307 | if (!isset($_POST['formDefinition'])) { |
||
| 308 | $_POST['formDefinition'] = $viewdata->fields['vwdefinition']; |
||
| 309 | $_POST['formComment'] = $viewdata->fields['relcomment']; |
||
| 310 | } |
||
| 311 | |||
| 312 | echo '<form action="' . \SUBFOLDER . "/src/views/materializedviewproperties.php\" method=\"post\">\n"; |
||
| 313 | echo "<table style=\"width: 100%\">\n"; |
||
| 314 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strdefinition']}</th>\n"; |
||
| 315 | echo "\t\t<td class=\"data1\"><textarea style=\"width: 100%;\" rows=\"20\" cols=\"50\" name=\"formDefinition\">", |
||
| 316 | htmlspecialchars($_POST['formDefinition']), "</textarea></td>\n\t</tr>\n"; |
||
| 317 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n"; |
||
| 318 | echo "\t\t<td class=\"data1\"><textarea rows=\"3\" cols=\"32\" name=\"formComment\">", |
||
| 319 | htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n"; |
||
| 320 | echo "</table>\n"; |
||
| 321 | echo "<p><input type=\"hidden\" name=\"action\" value=\"save_edit\" />\n"; |
||
| 322 | echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST['matview']), "\" />\n"; |
||
| 323 | echo $this->misc->form; |
||
| 324 | echo "<input type=\"submit\" value=\"{$lang['stralter']}\" />\n"; |
||
| 325 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 326 | echo "</form>\n"; |
||
| 327 | } else { |
||
| 328 | echo "<p>{$lang['strnodata']}</p>\n"; |
||
| 329 | } |
||
| 330 | } |
||
| 331 | |||
| 332 | /** |
||
| 333 | * Allow the dumping of the data "in" a view |
||
| 334 | * NOTE:: PostgreSQL doesn't currently support dumping the data in a view |
||
| 335 | * so I have disabled the data related parts for now. In the future |
||
| 336 | * we should allow it conditionally if it becomes supported. This is |
||
| 337 | * a SMOP since it is based on pg_dump version not backend version. |
||
| 338 | * |
||
| 339 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 340 | */ |
||
| 341 | public function doExport($msg = '') |
||
| 342 | { |
||
| 343 | $lang = $this->lang; |
||
| 344 | |||
| 345 | $this->printTrail('matview'); |
||
| 346 | $this->printTabs('matview', 'export'); |
||
| 347 | $this->printMsg($msg); |
||
| 348 | |||
| 349 | echo '<form action="' . \SUBFOLDER . "/src/views/dataexport.php\" method=\"post\">\n"; |
||
| 350 | echo "<table>\n"; |
||
| 351 | echo "<tr><th class=\"data\">{$lang['strformat']}</th><th class=\"data\" colspan=\"2\">{$lang['stroptions']}</th></tr>\n"; |
||
| 352 | // Data only |
||
| 353 | echo "<!--\n"; |
||
| 354 | echo '<tr><th class="data left">'; |
||
| 355 | echo "<input type=\"radio\" id=\"what1\" name=\"what\" value=\"dataonly\" /><label for=\"what1\">{$lang['strdataonly']}</label></th>\n"; |
||
| 356 | echo "<td>{$lang['strformat']}</td>\n"; |
||
| 357 | echo "<td><select name=\"d_format\" >\n"; |
||
| 358 | echo "<option value=\"copy\">COPY</option>\n"; |
||
| 359 | echo "<option value=\"sql\">SQL</option>\n"; |
||
| 360 | echo "<option value=\"csv\">CSV</option>\n"; |
||
| 361 | echo "<option value=\"tab\">{$lang['strtabbed']}</option>\n"; |
||
| 362 | echo "<option value=\"html\">XHTML</option>\n"; |
||
| 363 | echo "<option value=\"xml\">XML</option>\n"; |
||
| 364 | echo "</select>\n</td>\n</tr>\n"; |
||
| 365 | echo "-->\n"; |
||
| 366 | |||
| 367 | // Structure only |
||
| 368 | echo "<tr><th class=\"data left\"><input type=\"radio\" id=\"what2\" name=\"what\" value=\"structureonly\" checked=\"checked\" /><label for=\"what2\">{$lang['strstructureonly']}</label></th>\n"; |
||
| 369 | echo "<td><label for=\"s_clean\">{$lang['strdrop']}</label></td><td><input type=\"checkbox\" id=\"s_clean\" name=\"s_clean\" /></td>\n</tr>\n"; |
||
| 370 | // Structure and data |
||
| 371 | echo "<!--\n"; |
||
| 372 | echo '<tr><th class="data left" rowspan="2">'; |
||
| 373 | echo "<input type=\"radio\" id=\"what3\" name=\"what\" value=\"structureanddata\" /><label for=\"what3\">{$lang['strstructureanddata']}</label></th>\n"; |
||
| 374 | echo "<td>{$lang['strformat']}</td>\n"; |
||
| 375 | echo "<td><select name=\"sd_format\">\n"; |
||
| 376 | echo "<option value=\"copy\">COPY</option>\n"; |
||
| 377 | echo "<option value=\"sql\">SQL</option>\n"; |
||
| 378 | echo "</select>\n</td>\n</tr>\n"; |
||
| 379 | echo "<td><label for=\"sd_clean\">{$lang['strdrop']}</label></td><td><input type=\"checkbox\" id=\"sd_clean\" name=\"sd_clean\" /></td>\n</tr>\n"; |
||
| 380 | echo "-->\n"; |
||
| 381 | echo "</table>\n"; |
||
| 382 | |||
| 383 | echo "<h3>{$lang['stroptions']}</h3>\n"; |
||
| 384 | echo "<p><input type=\"radio\" id=\"output1\" name=\"output\" value=\"show\" checked=\"checked\" /><label for=\"output1\">{$lang['strshow']}</label>\n"; |
||
| 385 | echo "<br/><input type=\"radio\" id=\"output2\" name=\"output\" value=\"download\" /><label for=\"output2\">{$lang['strdownload']}</label></p>\n"; |
||
| 386 | |||
| 387 | echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n"; |
||
| 388 | echo $this->misc->form; |
||
| 389 | echo "<input type=\"hidden\" name=\"subject\" value=\"view\" />\n"; |
||
| 390 | echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST['matview']), "\" />\n"; |
||
| 391 | echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n"; |
||
| 392 | echo "</form>\n"; |
||
| 393 | } |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Show definition for a view. |
||
| 397 | * |
||
| 398 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 399 | */ |
||
| 400 | public function doDefinition($msg = '') |
||
| 401 | { |
||
| 402 | $lang = $this->lang; |
||
| 403 | $data = $this->misc->getDatabaseAccessor(); |
||
| 404 | |||
| 405 | // Get view |
||
| 406 | $vdata = $data->getView($_REQUEST['matview']); |
||
| 407 | |||
| 408 | $this->printTrail('matview'); |
||
| 409 | $this->printTabs('matview', 'definition'); |
||
| 410 | $this->printMsg($msg); |
||
| 411 | |||
| 412 | if ($vdata->recordCount() > 0) { |
||
| 413 | // Show comment if any |
||
| 414 | if (null !== $vdata->fields['relcomment']) { |
||
| 415 | echo '<p class="comment">', $this->misc->printVal($vdata->fields['relcomment']), "</p>\n"; |
||
| 416 | } |
||
| 417 | |||
| 418 | echo "<table style=\"width: 100%\">\n"; |
||
| 419 | echo "<tr><th class=\"data\">{$lang['strdefinition']}</th></tr>\n"; |
||
| 420 | echo '<tr><td class="data1">', $this->misc->printVal($vdata->fields['vwdefinition']), "</td></tr>\n"; |
||
| 421 | echo "</table>\n"; |
||
| 422 | } else { |
||
| 423 | echo "<p>{$lang['strnodata']}</p>\n"; |
||
| 424 | } |
||
| 425 | |||
| 426 | $this->printNavLinks(['alter' => [ |
||
| 427 | 'attr' => [ |
||
| 428 | 'href' => [ |
||
| 429 | 'url' => 'materializedviewproperties.php', |
||
| 430 | 'urlvars' => [ |
||
| 431 | 'action' => 'edit', |
||
| 432 | 'server' => $_REQUEST['server'], |
||
| 433 | 'database' => $_REQUEST['database'], |
||
| 434 | 'schema' => $_REQUEST['schema'], |
||
| 435 | 'view' => $_REQUEST['matview'], |
||
| 436 | ], |
||
| 437 | ], |
||
| 438 | ], |
||
| 439 | 'content' => $lang['stralter'], |
||
| 440 | ]], 'materializedviewproperties-definition', get_defined_vars()); |
||
| 441 | } |
||
| 442 | |||
| 443 | /** |
||
| 444 | * Displays a screen where they can alter a column in a view. |
||
| 445 | * |
||
| 446 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 447 | */ |
||
| 448 | public function doProperties($msg = '') |
||
| 449 | { |
||
| 450 | $lang = $this->lang; |
||
| 451 | $data = $this->misc->getDatabaseAccessor(); |
||
| 452 | |||
| 453 | if (!isset($_REQUEST['stage'])) { |
||
| 454 | $_REQUEST['stage'] = 1; |
||
| 455 | } |
||
| 456 | |||
| 457 | switch ($_REQUEST['stage']) { |
||
| 458 | case 1: |
||
| 459 | |||
| 460 | $this->printTrail('column'); |
||
| 461 | $this->printTitle($lang['stralter'], 'pg.column.alter'); |
||
| 462 | $this->printMsg($msg); |
||
| 463 | |||
| 464 | echo '<form action="' . \SUBFOLDER . "/src/views/materializedviewproperties.php\" method=\"post\">\n"; |
||
| 465 | |||
| 466 | // Output view header |
||
| 467 | echo "<table>\n"; |
||
| 468 | echo "<tr><th class=\"data required\">{$lang['strname']}</th><th class=\"data required\">{$lang['strtype']}</th>"; |
||
| 469 | echo "<th class=\"data\">{$lang['strdefault']}</th><th class=\"data\">{$lang['strcomment']}</th></tr>"; |
||
| 470 | |||
| 471 | $column = $data->getTableAttributes($_REQUEST['matview'], $_REQUEST['column']); |
||
| 472 | |||
| 473 | if (!isset($_REQUEST['default'])) { |
||
| 474 | $_REQUEST['field'] = $column->fields['attname']; |
||
| 475 | $_REQUEST['default'] = $_REQUEST['olddefault'] = $column->fields['adsrc']; |
||
| 476 | $_REQUEST['comment'] = $column->fields['comment']; |
||
| 477 | } |
||
| 478 | |||
| 479 | echo '<tr><td><input name="field" size="32" value="', |
||
| 480 | htmlspecialchars($_REQUEST['field']), '" /></td>'; |
||
| 481 | |||
| 482 | echo '<td>', $this->misc->printVal($data->formatType($column->fields['type'], $column->fields['atttypmod'])), '</td>'; |
||
| 483 | echo '<td><input name="default" size="20" value="', |
||
| 484 | htmlspecialchars($_REQUEST['default']), '" /></td>'; |
||
| 485 | echo '<td><input name="comment" size="32" value="', |
||
| 486 | htmlspecialchars($_REQUEST['comment']), '" /></td>'; |
||
| 487 | |||
| 488 | echo "</table>\n"; |
||
| 489 | echo "<p><input type=\"hidden\" name=\"action\" value=\"properties\" />\n"; |
||
| 490 | echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n"; |
||
| 491 | echo $this->misc->form; |
||
| 492 | echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST['matview']), "\" />\n"; |
||
| 493 | echo '<input type="hidden" name="column" value="', htmlspecialchars($_REQUEST['column']), "\" />\n"; |
||
| 494 | echo '<input type="hidden" name="olddefault" value="', htmlspecialchars($_REQUEST['olddefault']), "\" />\n"; |
||
| 495 | echo "<input type=\"submit\" value=\"{$lang['stralter']}\" />\n"; |
||
| 496 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 497 | echo "</form>\n"; |
||
| 498 | |||
| 499 | break; |
||
| 500 | case 2: |
||
| 501 | |||
| 502 | // Check inputs |
||
| 503 | if ('' == trim($_REQUEST['field'])) { |
||
| 504 | $_REQUEST['stage'] = 1; |
||
| 505 | $this->doProperties($lang['strcolneedsname']); |
||
| 506 | |||
| 507 | return; |
||
| 508 | } |
||
| 509 | |||
| 510 | // Alter the view column |
||
| 511 | list($status, $sql) = $data->alterColumn( |
||
| 512 | $_REQUEST['matview'], |
||
| 513 | $_REQUEST['column'], |
||
| 514 | $_REQUEST['field'], |
||
| 515 | false, |
||
| 516 | false, |
||
| 517 | $_REQUEST['default'], |
||
| 518 | $_REQUEST['olddefault'], |
||
| 519 | '', |
||
| 520 | '', |
||
| 521 | '', |
||
| 522 | '', |
||
| 523 | $_REQUEST['comment'] |
||
| 524 | ); |
||
| 525 | if (0 == $status) { |
||
| 526 | $this->doDefault($lang['strcolumnaltered']); |
||
| 527 | } else { |
||
| 528 | $_REQUEST['stage'] = 1; |
||
| 529 | $this->doProperties($lang['strcolumnalteredbad']); |
||
| 530 | |||
| 531 | return; |
||
| 532 | } |
||
| 533 | |||
| 534 | break; |
||
| 535 | default: |
||
| 536 | echo "<p>{$lang['strinvalidparam']}</p>\n"; |
||
| 537 | } |
||
| 538 | } |
||
| 539 | |||
| 540 | public function doAlter($confirm = false, $msg = '') |
||
| 541 | { |
||
| 542 | $lang = $this->lang; |
||
| 543 | $data = $this->misc->getDatabaseAccessor(); |
||
| 544 | |||
| 545 | if ($confirm) { |
||
| 546 | $this->printTrail('matview'); |
||
| 547 | $this->printTitle($lang['stralter'], 'pg.matview.alter'); |
||
| 548 | $this->printMsg($msg); |
||
| 549 | |||
| 550 | // Fetch view info |
||
| 551 | $view = $data->getView($_REQUEST['matview']); |
||
| 552 | |||
| 553 | if ($view->recordCount() > 0) { |
||
| 554 | if (!isset($_POST['name'])) { |
||
| 555 | $_POST['name'] = $view->fields['relname']; |
||
| 556 | } |
||
| 557 | |||
| 558 | if (!isset($_POST['owner'])) { |
||
| 559 | $_POST['owner'] = $view->fields['relowner']; |
||
| 560 | } |
||
| 561 | |||
| 562 | if (!isset($_POST['newschema'])) { |
||
| 563 | $_POST['newschema'] = $view->fields['nspname']; |
||
| 564 | } |
||
| 565 | |||
| 566 | if (!isset($_POST['comment'])) { |
||
| 567 | $_POST['comment'] = $view->fields['relcomment']; |
||
| 568 | } |
||
| 569 | |||
| 570 | echo '<form action="' . \SUBFOLDER . "/src/views/materializedviewproperties.php\" method=\"post\">\n"; |
||
| 571 | echo "<table>\n"; |
||
| 572 | echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n"; |
||
| 573 | echo '<td class="data1">'; |
||
| 574 | echo "<input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 575 | htmlspecialchars($_POST['name']), "\" /></td></tr>\n"; |
||
| 576 | |||
| 577 | if ($data->isSuperUser()) { |
||
| 578 | // Fetch all users |
||
| 579 | $users = $data->getUsers(); |
||
| 580 | |||
| 581 | echo "<tr><th class=\"data left required\">{$lang['strowner']}</th>\n"; |
||
| 582 | echo '<td class="data1"><select name="owner">'; |
||
| 583 | while (!$users->EOF) { |
||
| 584 | $uname = $users->fields['usename']; |
||
| 585 | echo '<option value="', htmlspecialchars($uname), '"', |
||
| 586 | ($uname == $_POST['owner']) ? ' selected="selected"' : '', '>', htmlspecialchars($uname), "</option>\n"; |
||
| 587 | $users->moveNext(); |
||
| 588 | } |
||
| 589 | echo "</select></td></tr>\n"; |
||
| 590 | } |
||
| 591 | |||
| 592 | if ($data->hasAlterTableSchema()) { |
||
| 593 | $schemas = $data->getSchemas(); |
||
| 594 | echo "<tr><th class=\"data left required\">{$lang['strschema']}</th>\n"; |
||
| 595 | echo '<td class="data1"><select name="newschema">'; |
||
| 596 | while (!$schemas->EOF) { |
||
| 597 | $schema = $schemas->fields['nspname']; |
||
| 598 | echo '<option value="', htmlspecialchars($schema), '"', |
||
| 599 | ($schema == $_POST['newschema']) ? ' selected="selected"' : '', '>', htmlspecialchars($schema), "</option>\n"; |
||
| 600 | $schemas->moveNext(); |
||
| 601 | } |
||
| 602 | echo "</select></td></tr>\n"; |
||
| 603 | } |
||
| 604 | |||
| 605 | echo "<tr><th class=\"data left\">{$lang['strcomment']}</th>\n"; |
||
| 606 | echo '<td class="data1">'; |
||
| 607 | echo '<textarea rows="3" cols="32" name="comment">', |
||
| 608 | htmlspecialchars($_POST['comment']), "</textarea></td></tr>\n"; |
||
| 609 | echo "</table>\n"; |
||
| 610 | echo "<input type=\"hidden\" name=\"action\" value=\"alter\" />\n"; |
||
| 611 | echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST['matview']), "\" />\n"; |
||
| 612 | echo $this->misc->form; |
||
| 613 | echo "<p><input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n"; |
||
| 614 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 615 | echo "</form>\n"; |
||
| 616 | } else { |
||
| 617 | echo "<p>{$lang['strnodata']}</p>\n"; |
||
| 618 | } |
||
| 619 | } else { |
||
| 620 | // For databases that don't allow owner change |
||
| 621 | if (!isset($_POST['owner'])) { |
||
| 622 | $_POST['owner'] = ''; |
||
| 623 | } |
||
| 624 | |||
| 625 | if (!isset($_POST['newschema'])) { |
||
| 626 | $_POST['newschema'] = null; |
||
| 627 | } |
||
| 628 | |||
| 629 | $status = $data->alterView($_POST['view'], $_POST['name'], $_POST['owner'], $_POST['newschema'], $_POST['comment']); |
||
| 630 | if (0 == $status) { |
||
| 631 | // If view has been renamed, need to change to the new name and |
||
| 632 | // reload the browser frame. |
||
| 633 | if ($_POST['view'] != $_POST['name']) { |
||
| 634 | // Jump them to the new view name |
||
| 635 | $_REQUEST['matview'] = $_POST['name']; |
||
| 636 | // Force a browser reload |
||
| 637 | $this->misc->setReloadBrowser(true); |
||
| 638 | } |
||
| 639 | // If schema has changed, need to change to the new schema and reload the browser |
||
| 640 | if (!empty($_POST['newschema']) && ($_POST['newschema'] != $data->_schema)) { |
||
| 641 | // Jump them to the new sequence schema |
||
| 642 | $this->misc->setCurrentSchema($_POST['newschema']); |
||
| 643 | $this->misc->setReloadBrowser(true); |
||
| 644 | } |
||
| 645 | $this->doDefault($lang['strviewaltered']); |
||
| 646 | } else { |
||
| 647 | $this->doAlter(true, $lang['strviewalteredbad']); |
||
| 648 | } |
||
| 649 | } |
||
| 650 | } |
||
| 651 | } |
||
| 652 |