| Total Complexity | 65 |
| Total Lines | 675 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like DomainsController 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 DomainsController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 16 | class DomainsController extends BaseController |
||
| 17 | { |
||
| 18 | public $controller_name = 'DomainsController'; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Default method to render the controller according to the action parameter. |
||
| 22 | */ |
||
| 23 | public function render() |
||
| 24 | { |
||
| 25 | if ('tree' == $this->action) { |
||
| 26 | return $this->doTree(); |
||
| 27 | } |
||
| 28 | |||
| 29 | $this->printHeader($this->lang['strdomains']); |
||
| 30 | $this->printBody(); |
||
| 31 | |||
| 32 | switch ($this->action) { |
||
| 33 | case 'add_check': |
||
| 34 | $this->addCheck(true); |
||
| 35 | |||
| 36 | break; |
||
| 37 | case 'save_add_check': |
||
| 38 | if (isset($_POST['cancel'])) { |
||
| 39 | $this->doProperties(); |
||
| 40 | } else { |
||
| 41 | $this->addCheck(false); |
||
| 42 | } |
||
| 43 | |||
| 44 | break; |
||
| 45 | case 'drop_con': |
||
| 46 | if (isset($_POST['drop'])) { |
||
| 47 | $this->doDropConstraint(false); |
||
| 48 | } else { |
||
| 49 | $this->doProperties(); |
||
| 50 | } |
||
| 51 | |||
| 52 | break; |
||
| 53 | case 'confirm_drop_con': |
||
| 54 | $this->doDropConstraint(true); |
||
| 55 | |||
| 56 | break; |
||
| 57 | case 'save_create': |
||
| 58 | if (isset($_POST['cancel'])) { |
||
| 59 | $this->doDefault(); |
||
| 60 | } else { |
||
| 61 | $this->doSaveCreate(); |
||
| 62 | } |
||
| 63 | |||
| 64 | break; |
||
| 65 | case 'create': |
||
| 66 | $this->doCreate(); |
||
| 67 | |||
| 68 | break; |
||
| 69 | case 'drop': |
||
| 70 | if (isset($_POST['drop'])) { |
||
| 71 | $this->doDrop(false); |
||
| 72 | } else { |
||
| 73 | $this->doDefault(); |
||
| 74 | } |
||
| 75 | |||
| 76 | break; |
||
| 77 | case 'confirm_drop': |
||
| 78 | $this->doDrop(true); |
||
| 79 | |||
| 80 | break; |
||
| 81 | case 'save_alter': |
||
| 82 | if (isset($_POST['alter'])) { |
||
| 83 | $this->doSaveAlter(); |
||
| 84 | } else { |
||
| 85 | $this->doProperties(); |
||
| 86 | } |
||
| 87 | |||
| 88 | break; |
||
| 89 | case 'alter': |
||
| 90 | $this->doAlter(); |
||
| 91 | |||
| 92 | break; |
||
| 93 | case 'properties': |
||
| 94 | $this->doProperties(); |
||
| 95 | |||
| 96 | break; |
||
| 97 | default: |
||
| 98 | $this->doDefault(); |
||
| 99 | |||
| 100 | break; |
||
| 101 | } |
||
| 102 | |||
| 103 | return $this->printFooter(); |
||
| 104 | } |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Show default list of domains in the database. |
||
| 108 | * |
||
| 109 | * @param mixed $msg |
||
| 110 | */ |
||
| 111 | public function doDefault($msg = '') |
||
| 112 | { |
||
| 113 | $data = $this->misc->getDatabaseAccessor(); |
||
| 114 | |||
| 115 | $this->printTrail('schema'); |
||
| 116 | $this->printTabs('schema', 'domains'); |
||
| 117 | $this->printMsg($msg); |
||
| 118 | |||
| 119 | $domains = $data->getDomains(); |
||
| 120 | |||
| 121 | $columns = [ |
||
| 122 | 'domain' => [ |
||
| 123 | 'title' => $this->lang['strdomain'], |
||
| 124 | 'field' => Decorator::field('domname'), |
||
| 125 | 'url' => "domains?action=properties&{$this->misc->href}&", |
||
| 126 | 'vars' => ['domain' => 'domname'], |
||
| 127 | ], |
||
| 128 | 'type' => [ |
||
| 129 | 'title' => $this->lang['strtype'], |
||
| 130 | 'field' => Decorator::field('domtype'), |
||
| 131 | ], |
||
| 132 | 'notnull' => [ |
||
| 133 | 'title' => $this->lang['strnotnull'], |
||
| 134 | 'field' => Decorator::field('domnotnull'), |
||
| 135 | 'type' => 'bool', |
||
| 136 | 'params' => ['true' => 'NOT NULL', 'false' => ''], |
||
| 137 | ], |
||
| 138 | 'default' => [ |
||
| 139 | 'title' => $this->lang['strdefault'], |
||
| 140 | 'field' => Decorator::field('domdef'), |
||
| 141 | ], |
||
| 142 | 'owner' => [ |
||
| 143 | 'title' => $this->lang['strowner'], |
||
| 144 | 'field' => Decorator::field('domowner'), |
||
| 145 | ], |
||
| 146 | 'actions' => [ |
||
| 147 | 'title' => $this->lang['stractions'], |
||
| 148 | ], |
||
| 149 | 'comment' => [ |
||
| 150 | 'title' => $this->lang['strcomment'], |
||
| 151 | 'field' => Decorator::field('domcomment'), |
||
| 152 | ], |
||
| 153 | ]; |
||
| 154 | |||
| 155 | $actions = [ |
||
| 156 | 'alter' => [ |
||
| 157 | 'content' => $this->lang['stralter'], |
||
| 158 | 'attr' => [ |
||
| 159 | 'href' => [ |
||
| 160 | 'url' => 'domains', |
||
| 161 | 'urlvars' => [ |
||
| 162 | 'action' => 'alter', |
||
| 163 | 'domain' => Decorator::field('domname'), |
||
| 164 | ], |
||
| 165 | ], |
||
| 166 | ], |
||
| 167 | ], |
||
| 168 | 'drop' => [ |
||
| 169 | 'content' => $this->lang['strdrop'], |
||
| 170 | 'attr' => [ |
||
| 171 | 'href' => [ |
||
| 172 | 'url' => 'domains', |
||
| 173 | 'urlvars' => [ |
||
| 174 | 'action' => 'confirm_drop', |
||
| 175 | 'domain' => Decorator::field('domname'), |
||
| 176 | ], |
||
| 177 | ], |
||
| 178 | ], |
||
| 179 | ], |
||
| 180 | ]; |
||
| 181 | |||
| 182 | if (!$data->hasAlterDomains()) { |
||
| 183 | unset($actions['alter']); |
||
| 184 | } |
||
| 185 | |||
| 186 | echo $this->printTable($domains, $columns, $actions, 'domains-domains', $this->lang['strnodomains']); |
||
| 187 | |||
| 188 | $navlinks = [ |
||
| 189 | 'create' => [ |
||
| 190 | 'attr' => [ |
||
| 191 | 'href' => [ |
||
| 192 | 'url' => 'domains', |
||
| 193 | 'urlvars' => [ |
||
| 194 | 'action' => 'create', |
||
| 195 | 'server' => $_REQUEST['server'], |
||
| 196 | 'database' => $_REQUEST['database'], |
||
| 197 | 'schema' => $_REQUEST['schema'], |
||
| 198 | ], |
||
| 199 | ], |
||
| 200 | ], |
||
| 201 | 'content' => $this->lang['strcreatedomain'], |
||
| 202 | ], |
||
| 203 | ]; |
||
| 204 | $this->printNavLinks($navlinks, 'domains-domains', get_defined_vars()); |
||
| 205 | } |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Generate XML for the browser tree. |
||
| 209 | */ |
||
| 210 | public function doTree() |
||
| 211 | { |
||
| 212 | $data = $this->misc->getDatabaseAccessor(); |
||
| 213 | |||
| 214 | $domains = $data->getDomains(); |
||
| 215 | |||
| 216 | $reqvars = $this->misc->getRequestVars('domain'); |
||
| 217 | |||
| 218 | $attrs = [ |
||
| 219 | 'text' => Decorator::field('domname'), |
||
| 220 | 'icon' => 'Domain', |
||
| 221 | 'toolTip' => Decorator::field('domcomment'), |
||
| 222 | 'action' => Decorator::actionurl( |
||
| 223 | 'domains', |
||
| 224 | $reqvars, |
||
| 225 | [ |
||
| 226 | 'action' => 'properties', |
||
| 227 | 'domain' => Decorator::field('domname'), |
||
| 228 | ] |
||
| 229 | ), |
||
| 230 | ]; |
||
| 231 | |||
| 232 | return $this->printTree($domains, $attrs, 'domains'); |
||
| 233 | } |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Function to save after altering a domain. |
||
| 237 | */ |
||
| 238 | public function doSaveAlter() |
||
| 239 | { |
||
| 240 | $data = $this->misc->getDatabaseAccessor(); |
||
| 241 | |||
| 242 | $status = $data->alterDomain( |
||
| 243 | $_POST['domain'], |
||
| 244 | $_POST['domdefault'], |
||
| 245 | isset($_POST['domnotnull']), |
||
| 246 | $_POST['domowner'] |
||
| 247 | ); |
||
| 248 | if (0 == $status) { |
||
| 249 | $this->doProperties($this->lang['strdomainaltered']); |
||
| 250 | } else { |
||
| 251 | $this->doAlter($this->lang['strdomainalteredbad']); |
||
| 252 | } |
||
| 253 | } |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Allow altering a domain. |
||
| 257 | * |
||
| 258 | * @param mixed $msg |
||
| 259 | */ |
||
| 260 | public function doAlter($msg = '') |
||
| 261 | { |
||
| 262 | $data = $this->misc->getDatabaseAccessor(); |
||
| 263 | |||
| 264 | $this->printTrail('domain'); |
||
| 265 | $this->printTitle($this->lang['stralter'], 'pg.domain.alter'); |
||
| 266 | $this->printMsg($msg); |
||
| 267 | |||
| 268 | // Fetch domain info |
||
| 269 | $domaindata = $data->getDomain($_REQUEST['domain']); |
||
| 270 | // Fetch all users |
||
| 271 | $users = $data->getUsers(); |
||
| 272 | |||
| 273 | if ($domaindata->recordCount() > 0) { |
||
| 274 | if (!isset($_POST['domname'])) { |
||
| 275 | $_POST['domtype'] = $domaindata->fields['domtype']; |
||
| 276 | $_POST['domdefault'] = $domaindata->fields['domdef']; |
||
| 277 | $domaindata->fields['domnotnull'] = $data->phpBool($domaindata->fields['domnotnull']); |
||
| 278 | if ($domaindata->fields['domnotnull']) { |
||
| 279 | $_POST['domnotnull'] = 'on'; |
||
| 280 | } |
||
| 281 | |||
| 282 | $_POST['domowner'] = $domaindata->fields['domowner']; |
||
| 283 | } |
||
| 284 | |||
| 285 | // Display domain info |
||
| 286 | echo '<form action="'.\SUBFOLDER."/src/views/domains\" method=\"post\">\n"; |
||
| 287 | echo "<table>\n"; |
||
| 288 | echo "<tr><th class=\"data left required\" style=\"width: 70px\">{$this->lang['strname']}</th>\n"; |
||
| 289 | echo '<td class="data1">', $this->misc->printVal($domaindata->fields['domname']), "</td></tr>\n"; |
||
| 290 | echo "<tr><th class=\"data left required\">{$this->lang['strtype']}</th>\n"; |
||
| 291 | echo '<td class="data1">', $this->misc->printVal($domaindata->fields['domtype']), "</td></tr>\n"; |
||
| 292 | echo "<tr><th class=\"data left\"><label for=\"domnotnull\">{$this->lang['strnotnull']}</label></th>\n"; |
||
| 293 | echo '<td class="data1"><input type="checkbox" id="domnotnull" name="domnotnull"', (isset($_POST['domnotnull']) ? ' checked="checked"' : ''), " /></td></tr>\n"; |
||
| 294 | echo "<tr><th class=\"data left\">{$this->lang['strdefault']}</th>\n"; |
||
| 295 | echo '<td class="data1"><input name="domdefault" size="32" value="', |
||
| 296 | htmlspecialchars($_POST['domdefault']), "\" /></td></tr>\n"; |
||
| 297 | echo "<tr><th class=\"data left required\">{$this->lang['strowner']}</th>\n"; |
||
| 298 | echo '<td class="data1"><select name="domowner">'; |
||
| 299 | while (!$users->EOF) { |
||
| 300 | $uname = $users->fields['usename']; |
||
| 301 | echo '<option value="', htmlspecialchars($uname), '"', |
||
| 302 | ($uname == $_POST['domowner']) ? ' selected="selected"' : '', '>', htmlspecialchars($uname), "</option>\n"; |
||
| 303 | $users->moveNext(); |
||
| 304 | } |
||
| 305 | echo "</select></td></tr>\n"; |
||
| 306 | echo "</table>\n"; |
||
| 307 | echo "<p><input type=\"hidden\" name=\"action\" value=\"save_alter\" />\n"; |
||
| 308 | echo '<input type="hidden" name="domain" value="', htmlspecialchars($_REQUEST['domain']), "\" />\n"; |
||
| 309 | echo $this->misc->form; |
||
| 310 | echo "<input type=\"submit\" name=\"alter\" value=\"{$this->lang['stralter']}\" />\n"; |
||
| 311 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
| 312 | echo "</form>\n"; |
||
| 313 | } else { |
||
| 314 | echo "<p>{$this->lang['strnodata']}</p>\n"; |
||
| 315 | } |
||
| 316 | } |
||
| 317 | |||
| 318 | /** |
||
| 319 | * Confirm and then actually add a CHECK constraint. |
||
| 320 | * |
||
| 321 | * @param mixed $confirm |
||
| 322 | * @param mixed $msg |
||
| 323 | */ |
||
| 324 | public function addCheck($confirm, $msg = '') |
||
| 325 | { |
||
| 326 | $data = $this->misc->getDatabaseAccessor(); |
||
| 327 | |||
| 328 | if (!isset($_POST['name'])) { |
||
| 329 | $_POST['name'] = ''; |
||
| 330 | } |
||
| 331 | |||
| 332 | if (!isset($_POST['definition'])) { |
||
| 333 | $_POST['definition'] = ''; |
||
| 334 | } |
||
| 335 | |||
| 336 | if ($confirm) { |
||
| 337 | $this->printTrail('domain'); |
||
| 338 | $this->printTitle($this->lang['straddcheck'], 'pg.constraint.check'); |
||
| 339 | $this->printMsg($msg); |
||
| 340 | |||
| 341 | echo '<form action="'.\SUBFOLDER."/src/views/domains\" method=\"post\">\n"; |
||
| 342 | echo "<table>\n"; |
||
| 343 | echo "<tr><th class=\"data\">{$this->lang['strname']}</th>\n"; |
||
| 344 | echo "<th class=\"data required\">{$this->lang['strdefinition']}</th></tr>\n"; |
||
| 345 | |||
| 346 | echo "<tr><td class=\"data1\"><input name=\"name\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 347 | htmlspecialchars($_POST['name']), "\" /></td>\n"; |
||
| 348 | |||
| 349 | echo '<td class="data1">(<input name="definition" size="32" value="', |
||
| 350 | htmlspecialchars($_POST['definition']), "\" />)</td></tr>\n"; |
||
| 351 | echo "</table>\n"; |
||
| 352 | |||
| 353 | echo "<p><input type=\"hidden\" name=\"action\" value=\"save_add_check\" />\n"; |
||
| 354 | echo '<input type="hidden" name="domain" value="', htmlspecialchars($_REQUEST['domain']), "\" />\n"; |
||
| 355 | echo $this->misc->form; |
||
| 356 | echo "<input type=\"submit\" name=\"add\" value=\"{$this->lang['stradd']}\" />\n"; |
||
| 357 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
| 358 | echo "</form>\n"; |
||
| 359 | } else { |
||
| 360 | if ('' == trim($_POST['definition'])) { |
||
| 361 | $this->addCheck(true, $this->lang['strcheckneedsdefinition']); |
||
| 362 | } else { |
||
| 363 | $status = $data->addDomainCheckConstraint( |
||
| 364 | $_POST['domain'], |
||
| 365 | $_POST['definition'], |
||
| 366 | $_POST['name'] |
||
| 367 | ); |
||
| 368 | if (0 == $status) { |
||
| 369 | $this->doProperties($this->lang['strcheckadded']); |
||
| 370 | } else { |
||
| 371 | $this->addCheck(true, $this->lang['strcheckaddedbad']); |
||
| 372 | } |
||
| 373 | } |
||
| 374 | } |
||
| 375 | } |
||
| 376 | |||
| 377 | /** |
||
| 378 | * Show confirmation of drop constraint and perform actual drop. |
||
| 379 | * |
||
| 380 | * @param mixed $confirm |
||
| 381 | * @param mixed $msg |
||
| 382 | */ |
||
| 383 | public function doDropConstraint($confirm, $msg = '') |
||
| 384 | { |
||
| 385 | $data = $this->misc->getDatabaseAccessor(); |
||
| 386 | |||
| 387 | if ($confirm) { |
||
| 388 | $this->printTrail('domain'); |
||
| 389 | $this->printTitle($this->lang['strdrop'], 'pg.constraint.drop'); |
||
| 390 | $this->printMsg($msg); |
||
| 391 | |||
| 392 | echo '<p>', sprintf( |
||
| 393 | $this->lang['strconfdropconstraint'], |
||
| 394 | $this->misc->printVal($_REQUEST['constraint']), |
||
| 395 | $this->misc->printVal($_REQUEST['domain']) |
||
| 396 | ), "</p>\n"; |
||
| 397 | echo '<form action="'.\SUBFOLDER."/src/views/domains\" method=\"post\">\n"; |
||
| 398 | echo "<input type=\"hidden\" name=\"action\" value=\"drop_con\" />\n"; |
||
| 399 | echo '<input type="hidden" name="domain" value="', htmlspecialchars($_REQUEST['domain']), "\" />\n"; |
||
| 400 | echo '<input type="hidden" name="constraint" value="', htmlspecialchars($_REQUEST['constraint']), "\" />\n"; |
||
| 401 | echo $this->misc->form; |
||
| 402 | echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$this->lang['strcascade']}</label></p>\n"; |
||
| 403 | echo "<input type=\"submit\" name=\"drop\" value=\"{$this->lang['strdrop']}\" />\n"; |
||
| 404 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" />\n"; |
||
| 405 | echo "</form>\n"; |
||
| 406 | } else { |
||
| 407 | $status = $data->dropDomainConstraint($_POST['domain'], $_POST['constraint'], isset($_POST['cascade'])); |
||
| 408 | if (0 == $status) { |
||
| 409 | $this->doProperties($this->lang['strconstraintdropped']); |
||
| 410 | } else { |
||
| 411 | $this->doDropConstraint(true, $this->lang['strconstraintdroppedbad']); |
||
| 412 | } |
||
| 413 | } |
||
| 414 | } |
||
| 415 | |||
| 416 | /** |
||
| 417 | * Show properties for a domain. Allow manipulating constraints as well. |
||
| 418 | * |
||
| 419 | * @param mixed $msg |
||
| 420 | */ |
||
| 421 | public function doProperties($msg = '') |
||
| 422 | { |
||
| 423 | $data = $this->misc->getDatabaseAccessor(); |
||
| 424 | |||
| 425 | $this->printTrail('domain'); |
||
| 426 | $this->printTitle($this->lang['strproperties'], 'pg.domain'); |
||
| 427 | $this->printMsg($msg); |
||
| 428 | |||
| 429 | $domaindata = $data->getDomain($_REQUEST['domain']); |
||
| 430 | |||
| 431 | if ($domaindata->recordCount() > 0) { |
||
| 432 | // Show comment if any |
||
| 433 | if (null !== $domaindata->fields['domcomment']) { |
||
| 434 | echo '<p class="comment">', $this->misc->printVal($domaindata->fields['domcomment']), "</p>\n"; |
||
| 435 | } |
||
| 436 | |||
| 437 | // Display domain info |
||
| 438 | $domaindata->fields['domnotnull'] = $data->phpBool($domaindata->fields['domnotnull']); |
||
| 439 | echo "<table>\n"; |
||
| 440 | echo "<tr><th class=\"data left\" style=\"width: 70px\">{$this->lang['strname']}</th>\n"; |
||
| 441 | echo '<td class="data1">', $this->misc->printVal($domaindata->fields['domname']), "</td></tr>\n"; |
||
| 442 | echo "<tr><th class=\"data left\">{$this->lang['strtype']}</th>\n"; |
||
| 443 | echo '<td class="data1">', $this->misc->printVal($domaindata->fields['domtype']), "</td></tr>\n"; |
||
| 444 | echo "<tr><th class=\"data left\">{$this->lang['strnotnull']}</th>\n"; |
||
| 445 | echo '<td class="data1">', ($domaindata->fields['domnotnull'] ? 'NOT NULL' : ''), "</td></tr>\n"; |
||
| 446 | echo "<tr><th class=\"data left\">{$this->lang['strdefault']}</th>\n"; |
||
| 447 | echo '<td class="data1">', $this->misc->printVal($domaindata->fields['domdef']), "</td></tr>\n"; |
||
| 448 | echo "<tr><th class=\"data left\">{$this->lang['strowner']}</th>\n"; |
||
| 449 | echo '<td class="data1">', $this->misc->printVal($domaindata->fields['domowner']), "</td></tr>\n"; |
||
| 450 | echo "</table>\n"; |
||
| 451 | |||
| 452 | // Display domain constraints |
||
| 453 | echo "<h3>{$this->lang['strconstraints']}</h3>\n"; |
||
| 454 | if ($data->hasDomainConstraints()) { |
||
| 455 | $domaincons = $data->getDomainConstraints($_REQUEST['domain']); |
||
| 456 | |||
| 457 | $columns = [ |
||
| 458 | 'name' => [ |
||
| 459 | 'title' => $this->lang['strname'], |
||
| 460 | 'field' => Decorator::field('conname'), |
||
| 461 | ], |
||
| 462 | 'definition' => [ |
||
| 463 | 'title' => $this->lang['strdefinition'], |
||
| 464 | 'field' => Decorator::field('consrc'), |
||
| 465 | ], |
||
| 466 | 'actions' => [ |
||
| 467 | 'title' => $this->lang['stractions'], |
||
| 468 | ], |
||
| 469 | ]; |
||
| 470 | |||
| 471 | $actions = [ |
||
| 472 | 'drop' => [ |
||
| 473 | 'content' => $this->lang['strdrop'], |
||
| 474 | 'attr' => [ |
||
| 475 | 'href' => [ |
||
| 476 | 'url' => 'domains', |
||
| 477 | 'urlvars' => [ |
||
| 478 | 'action' => 'confirm_drop_con', |
||
| 479 | 'domain' => $_REQUEST['domain'], |
||
| 480 | 'constraint' => Decorator::field('conname'), |
||
| 481 | 'type' => Decorator::field('contype'), |
||
| 482 | ], |
||
| 483 | ], |
||
| 484 | ], |
||
| 485 | ], |
||
| 486 | ]; |
||
| 487 | |||
| 488 | echo $this->printTable($domaincons, $columns, $actions, 'domains-properties', $this->lang['strnodata']); |
||
| 489 | } |
||
| 490 | } else { |
||
| 491 | echo "<p>{$this->lang['strnodata']}</p>\n"; |
||
| 492 | } |
||
| 493 | |||
| 494 | $navlinks = [ |
||
| 495 | 'drop' => [ |
||
| 496 | 'attr' => [ |
||
| 497 | 'href' => [ |
||
| 498 | 'url' => 'domains', |
||
| 499 | 'urlvars' => [ |
||
| 500 | 'action' => 'confirm_drop', |
||
| 501 | 'server' => $_REQUEST['server'], |
||
| 502 | 'database' => $_REQUEST['database'], |
||
| 503 | 'schema' => $_REQUEST['schema'], |
||
| 504 | 'domain' => $_REQUEST['domain'], |
||
| 505 | ], |
||
| 506 | ], |
||
| 507 | ], |
||
| 508 | 'content' => $this->lang['strdrop'], |
||
| 509 | ], |
||
| 510 | ]; |
||
| 511 | if ($data->hasAlterDomains()) { |
||
| 512 | $navlinks['addcheck'] = [ |
||
| 513 | 'attr' => [ |
||
| 514 | 'href' => [ |
||
| 515 | 'url' => 'domains', |
||
| 516 | 'urlvars' => [ |
||
| 517 | 'action' => 'add_check', |
||
| 518 | 'server' => $_REQUEST['server'], |
||
| 519 | 'database' => $_REQUEST['database'], |
||
| 520 | 'schema' => $_REQUEST['schema'], |
||
| 521 | 'domain' => $_REQUEST['domain'], |
||
| 522 | ], |
||
| 523 | ], |
||
| 524 | ], |
||
| 525 | 'content' => $this->lang['straddcheck'], |
||
| 526 | ]; |
||
| 527 | $navlinks['alter'] = [ |
||
| 528 | 'attr' => [ |
||
| 529 | 'href' => [ |
||
| 530 | 'url' => 'domains', |
||
| 531 | 'urlvars' => [ |
||
| 532 | 'action' => 'alter', |
||
| 533 | 'server' => $_REQUEST['server'], |
||
| 534 | 'database' => $_REQUEST['database'], |
||
| 535 | 'schema' => $_REQUEST['schema'], |
||
| 536 | 'domain' => $_REQUEST['domain'], |
||
| 537 | ], |
||
| 538 | ], |
||
| 539 | ], |
||
| 540 | 'content' => $this->lang['stralter'], |
||
| 541 | ]; |
||
| 542 | } |
||
| 543 | |||
| 544 | $this->printNavLinks($navlinks, 'domains-properties', get_defined_vars()); |
||
| 545 | } |
||
| 546 | |||
| 547 | /** |
||
| 548 | * Show confirmation of drop and perform actual drop. |
||
| 549 | * |
||
| 550 | * @param mixed $confirm |
||
| 551 | */ |
||
| 552 | public function doDrop($confirm) |
||
| 553 | { |
||
| 554 | $data = $this->misc->getDatabaseAccessor(); |
||
| 555 | |||
| 556 | if ($confirm) { |
||
| 557 | $this->printTrail('domain'); |
||
| 558 | $this->printTitle($this->lang['strdrop'], 'pg.domain.drop'); |
||
| 559 | |||
| 560 | echo '<p>', sprintf($this->lang['strconfdropdomain'], $this->misc->printVal($_REQUEST['domain'])), "</p>\n"; |
||
| 561 | echo '<form action="'.\SUBFOLDER."/src/views/domains\" method=\"post\">\n"; |
||
| 562 | echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /><label for=\"cascade\">{$this->lang['strcascade']}</label></p>\n"; |
||
| 563 | echo "<p><input type=\"hidden\" name=\"action\" value=\"drop\" />\n"; |
||
| 564 | echo '<input type="hidden" name="domain" value="', htmlspecialchars($_REQUEST['domain']), "\" />\n"; |
||
| 565 | echo $this->misc->form; |
||
| 566 | echo "<input type=\"submit\" name=\"drop\" value=\"{$this->lang['strdrop']}\" />\n"; |
||
| 567 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
| 568 | echo "</form>\n"; |
||
| 569 | } else { |
||
| 570 | $status = $data->dropDomain($_POST['domain'], isset($_POST['cascade'])); |
||
| 571 | if (0 == $status) { |
||
| 572 | $this->doDefault($this->lang['strdomaindropped']); |
||
| 573 | } else { |
||
| 574 | $this->doDefault($this->lang['strdomaindroppedbad']); |
||
| 575 | } |
||
| 576 | } |
||
| 577 | } |
||
| 578 | |||
| 579 | /** |
||
| 580 | * Displays a screen where they can enter a new domain. |
||
| 581 | * |
||
| 582 | * @param mixed $msg |
||
| 583 | */ |
||
| 584 | public function doCreate($msg = '') |
||
| 585 | { |
||
| 586 | $data = $this->misc->getDatabaseAccessor(); |
||
| 587 | |||
| 588 | if (!isset($_POST['domname'])) { |
||
| 589 | $_POST['domname'] = ''; |
||
| 590 | } |
||
| 591 | |||
| 592 | if (!isset($_POST['domtype'])) { |
||
| 593 | $_POST['domtype'] = ''; |
||
| 594 | } |
||
| 595 | |||
| 596 | if (!isset($_POST['domlength'])) { |
||
| 597 | $_POST['domlength'] = ''; |
||
| 598 | } |
||
| 599 | |||
| 600 | if (!isset($_POST['domarray'])) { |
||
| 601 | $_POST['domarray'] = ''; |
||
| 602 | } |
||
| 603 | |||
| 604 | if (!isset($_POST['domdefault'])) { |
||
| 605 | $_POST['domdefault'] = ''; |
||
| 606 | } |
||
| 607 | |||
| 608 | if (!isset($_POST['domcheck'])) { |
||
| 609 | $_POST['domcheck'] = ''; |
||
| 610 | } |
||
| 611 | |||
| 612 | $types = $data->getTypes(true); |
||
| 613 | |||
| 614 | $this->printTrail('schema'); |
||
| 615 | $this->printTitle($this->lang['strcreatedomain'], 'pg.domain.create'); |
||
| 616 | $this->printMsg($msg); |
||
| 617 | |||
| 618 | echo '<form action="'.\SUBFOLDER."/src/views/domains\" method=\"post\">\n"; |
||
| 619 | echo "<table>\n"; |
||
| 620 | echo "<tr><th class=\"data left required\" style=\"width: 70px\">{$this->lang['strname']}</th>\n"; |
||
| 621 | echo "<td class=\"data1\"><input name=\"domname\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 622 | htmlspecialchars($_POST['domname']), "\" /></td></tr>\n"; |
||
| 623 | echo "<tr><th class=\"data left required\">{$this->lang['strtype']}</th>\n"; |
||
| 624 | echo "<td class=\"data1\">\n"; |
||
| 625 | // Output return type list |
||
| 626 | echo "<select name=\"domtype\">\n"; |
||
| 627 | while (!$types->EOF) { |
||
| 628 | echo '<option value="', htmlspecialchars($types->fields['typname']), '"', |
||
| 629 | ($types->fields['typname'] == $_POST['domtype']) ? ' selected="selected"' : '', '>', |
||
| 630 | $this->misc->printVal($types->fields['typname']), "</option>\n"; |
||
| 631 | $types->moveNext(); |
||
| 632 | } |
||
| 633 | echo "</select>\n"; |
||
| 634 | |||
| 635 | // Type length |
||
| 636 | echo '<input type="text" size="4" name="domlength" value="', htmlspecialchars($_POST['domlength']), '" />'; |
||
| 637 | |||
| 638 | // Output array type selector |
||
| 639 | echo "<select name=\"domarray\">\n"; |
||
| 640 | echo '<option value=""', ('' == $_POST['domarray']) ? ' selected="selected"' : '', "></option>\n"; |
||
| 641 | echo '<option value="[]"', ('[]' == $_POST['domarray']) ? ' selected="selected"' : '', ">[ ]</option>\n"; |
||
| 642 | echo "</select></td></tr>\n"; |
||
| 643 | |||
| 644 | echo "<tr><th class=\"data left\"><label for=\"domnotnull\">{$this->lang['strnotnull']}</label></th>\n"; |
||
| 645 | echo '<td class="data1"><input type="checkbox" id="domnotnull" name="domnotnull"', |
||
| 646 | (isset($_POST['domnotnull']) ? ' checked="checked"' : ''), " /></td></tr>\n"; |
||
| 647 | echo "<tr><th class=\"data left\">{$this->lang['strdefault']}</th>\n"; |
||
| 648 | echo '<td class="data1"><input name="domdefault" size="32" value="', |
||
| 649 | htmlspecialchars($_POST['domdefault']), "\" /></td></tr>\n"; |
||
| 650 | if ($data->hasDomainConstraints()) { |
||
| 651 | echo "<tr><th class=\"data left\">{$this->lang['strconstraints']}</th>\n"; |
||
| 652 | echo '<td class="data1">CHECK (<input name="domcheck" size="32" value="', |
||
| 653 | htmlspecialchars($_POST['domcheck']), "\" />)</td></tr>\n"; |
||
| 654 | } |
||
| 655 | echo "</table>\n"; |
||
| 656 | echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create\" />\n"; |
||
| 657 | echo $this->misc->form; |
||
| 658 | echo "<input type=\"submit\" value=\"{$this->lang['strcreate']}\" />\n"; |
||
| 659 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
| 660 | echo "</form>\n"; |
||
| 661 | } |
||
| 662 | |||
| 663 | /** |
||
| 664 | * Actually creates the new domain in the database. |
||
| 665 | */ |
||
| 666 | public function doSaveCreate() |
||
| 691 | } |
||
| 692 | } |
||
| 693 | } |
||
| 694 | } |
||
| 695 |