| Total Complexity | 107 |
| Total Lines | 820 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like TypesController 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 TypesController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 16 | class TypesController extends BaseController |
||
| 17 | { |
||
| 18 | public $controller_name = 'TypesController'; |
||
| 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['strtypes']); |
||
| 30 | $this->printBody(); |
||
| 31 | |||
| 32 | switch ($this->action) { |
||
| 33 | case 'create_comp': |
||
| 34 | if (isset($_POST['cancel'])) { |
||
| 35 | $this->doDefault(); |
||
| 36 | } else { |
||
| 37 | $this->doCreateComposite(); |
||
| 38 | } |
||
| 39 | |||
| 40 | break; |
||
| 41 | case 'create_enum': |
||
| 42 | if (isset($_POST['cancel'])) { |
||
| 43 | $this->doDefault(); |
||
| 44 | } else { |
||
| 45 | $this->doCreateEnum(); |
||
| 46 | } |
||
| 47 | |||
| 48 | break; |
||
| 49 | case 'save_create': |
||
| 50 | if (isset($_POST['cancel'])) { |
||
| 51 | $this->doDefault(); |
||
| 52 | } else { |
||
| 53 | $this->doSaveCreate(); |
||
| 54 | } |
||
| 55 | |||
| 56 | break; |
||
| 57 | case 'create': |
||
| 58 | $this->doCreate(); |
||
| 59 | |||
| 60 | break; |
||
| 61 | case 'drop': |
||
| 62 | if (isset($_POST['cancel'])) { |
||
| 63 | $this->doDefault(); |
||
| 64 | } else { |
||
| 65 | $this->doDrop(false); |
||
| 66 | } |
||
| 67 | |||
| 68 | break; |
||
| 69 | case 'confirm_drop': |
||
| 70 | $this->doDrop(true); |
||
| 71 | |||
| 72 | break; |
||
| 73 | case 'properties': |
||
| 74 | $this->doProperties(); |
||
| 75 | |||
| 76 | break; |
||
| 77 | default: |
||
| 78 | $this->doDefault(); |
||
| 79 | |||
| 80 | break; |
||
| 81 | } |
||
| 82 | |||
| 83 | return $this->printFooter(); |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Show default list of types in the database. |
||
| 88 | * |
||
| 89 | * @param mixed $msg |
||
| 90 | */ |
||
| 91 | public function doDefault($msg = '') |
||
| 92 | { |
||
| 93 | $data = $this->misc->getDatabaseAccessor(); |
||
| 94 | |||
| 95 | $this->printTrail('schema'); |
||
| 96 | $this->printTabs('schema', 'types'); |
||
| 97 | $this->printMsg($msg); |
||
| 98 | |||
| 99 | $types = $data->getTypes(); |
||
| 100 | |||
| 101 | $columns = [ |
||
| 102 | 'type' => [ |
||
| 103 | 'title' => $this->lang['strtype'], |
||
| 104 | 'field' => Decorator::field('typname'), |
||
| 105 | 'url' => "types?action=properties&{$this->misc->href}&", |
||
| 106 | 'vars' => ['type' => 'basename'], |
||
| 107 | ], |
||
| 108 | 'owner' => [ |
||
| 109 | 'title' => $this->lang['strowner'], |
||
| 110 | 'field' => Decorator::field('typowner'), |
||
| 111 | ], |
||
| 112 | 'flavour' => [ |
||
| 113 | 'title' => $this->lang['strflavor'], |
||
| 114 | 'field' => Decorator::field('typtype'), |
||
| 115 | 'type' => 'verbatim', |
||
| 116 | 'params' => [ |
||
| 117 | 'map' => [ |
||
| 118 | 'b' => $this->lang['strbasetype'], |
||
| 119 | 'c' => $this->lang['strcompositetype'], |
||
| 120 | 'd' => $this->lang['strdomain'], |
||
| 121 | 'p' => $this->lang['strpseudotype'], |
||
| 122 | 'e' => $this->lang['strenum'], |
||
| 123 | ], |
||
| 124 | 'align' => 'center', |
||
| 125 | ], |
||
| 126 | ], |
||
| 127 | 'actions' => [ |
||
| 128 | 'title' => $this->lang['stractions'], |
||
| 129 | ], |
||
| 130 | 'comment' => [ |
||
| 131 | 'title' => $this->lang['strcomment'], |
||
| 132 | 'field' => Decorator::field('typcomment'), |
||
| 133 | ], |
||
| 134 | ]; |
||
| 135 | |||
| 136 | if (!isset($types->fields['typtype'])) { |
||
| 137 | unset($columns['flavour']); |
||
| 138 | } |
||
| 139 | |||
| 140 | $actions = [ |
||
| 141 | 'drop' => [ |
||
| 142 | 'content' => $this->lang['strdrop'], |
||
| 143 | 'attr' => [ |
||
| 144 | 'href' => [ |
||
| 145 | 'url' => 'types', |
||
| 146 | 'urlvars' => [ |
||
| 147 | 'action' => 'confirm_drop', |
||
| 148 | 'type' => Decorator::field('basename'), |
||
| 149 | ], |
||
| 150 | ], |
||
| 151 | ], |
||
| 152 | ], |
||
| 153 | ]; |
||
| 154 | |||
| 155 | echo $this->printTable($types, $columns, $actions, 'types-types', $this->lang['strnotypes']); |
||
| 156 | |||
| 157 | $navlinks = [ |
||
| 158 | 'create' => [ |
||
| 159 | 'attr' => [ |
||
| 160 | 'href' => [ |
||
| 161 | 'url' => 'types', |
||
| 162 | 'urlvars' => [ |
||
| 163 | 'action' => 'create', |
||
| 164 | 'server' => $_REQUEST['server'], |
||
| 165 | 'database' => $_REQUEST['database'], |
||
| 166 | 'schema' => $_REQUEST['schema'], |
||
| 167 | ], |
||
| 168 | ], |
||
| 169 | ], |
||
| 170 | 'content' => $this->lang['strcreatetype'], |
||
| 171 | ], |
||
| 172 | 'createcomp' => [ |
||
| 173 | 'attr' => [ |
||
| 174 | 'href' => [ |
||
| 175 | 'url' => 'types', |
||
| 176 | 'urlvars' => [ |
||
| 177 | 'action' => 'create_comp', |
||
| 178 | 'server' => $_REQUEST['server'], |
||
| 179 | 'database' => $_REQUEST['database'], |
||
| 180 | 'schema' => $_REQUEST['schema'], |
||
| 181 | ], |
||
| 182 | ], |
||
| 183 | ], |
||
| 184 | 'content' => $this->lang['strcreatecomptype'], |
||
| 185 | ], |
||
| 186 | 'createenum' => [ |
||
| 187 | 'attr' => [ |
||
| 188 | 'href' => [ |
||
| 189 | 'url' => 'types', |
||
| 190 | 'urlvars' => [ |
||
| 191 | 'action' => 'create_enum', |
||
| 192 | 'server' => $_REQUEST['server'], |
||
| 193 | 'database' => $_REQUEST['database'], |
||
| 194 | 'schema' => $_REQUEST['schema'], |
||
| 195 | ], |
||
| 196 | ], |
||
| 197 | ], |
||
| 198 | 'content' => $this->lang['strcreateenumtype'], |
||
| 199 | ], |
||
| 200 | ]; |
||
| 201 | |||
| 202 | if (!$data->hasEnumTypes()) { |
||
| 203 | unset($navlinks['enum']); |
||
| 204 | } |
||
| 205 | |||
| 206 | $this->printNavLinks($navlinks, 'types-types', get_defined_vars()); |
||
| 207 | } |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Generate XML for the browser tree. |
||
| 211 | */ |
||
| 212 | public function doTree() |
||
| 213 | { |
||
| 214 | $data = $this->misc->getDatabaseAccessor(); |
||
| 215 | |||
| 216 | $types = $data->getTypes(); |
||
| 217 | |||
| 218 | $reqvars = $this->misc->getRequestVars('type'); |
||
| 219 | |||
| 220 | $attrs = [ |
||
| 221 | 'text' => Decorator::field('typname'), |
||
| 222 | 'icon' => 'Type', |
||
| 223 | 'toolTip' => Decorator::field('typcomment'), |
||
| 224 | 'action' => Decorator::actionurl( |
||
| 225 | 'types', |
||
| 226 | $reqvars, |
||
| 227 | [ |
||
| 228 | 'action' => 'properties', |
||
| 229 | 'type' => Decorator::field('basename'), |
||
| 230 | ] |
||
| 231 | ), |
||
| 232 | ]; |
||
| 233 | |||
| 234 | return $this->printTree($types, $attrs, 'types'); |
||
| 235 | } |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Show read only properties for a type. |
||
| 239 | * |
||
| 240 | * @param mixed $msg |
||
| 241 | */ |
||
| 242 | public function doProperties($msg = '') |
||
| 243 | { |
||
| 244 | $data = $this->misc->getDatabaseAccessor(); |
||
| 245 | // Get type (using base name) |
||
| 246 | $typedata = $data->getType($_REQUEST['type']); |
||
| 247 | |||
| 248 | $this->printTrail('type'); |
||
| 249 | $this->printTitle($this->lang['strproperties'], 'pg.type'); |
||
| 250 | $this->printMsg($msg); |
||
| 251 | |||
| 252 | $attPre = function (&$rowdata) use ($data) { |
||
| 253 | $rowdata->fields['+type'] = $data->formatType($rowdata->fields['type'], $rowdata->fields['atttypmod']); |
||
| 254 | }; |
||
| 255 | |||
| 256 | if ($typedata->recordCount() > 0) { |
||
| 257 | $vals = false; |
||
| 258 | switch ($typedata->fields['typtype']) { |
||
| 259 | case 'c': |
||
| 260 | $attrs = $data->getTableAttributes($_REQUEST['type']); |
||
| 261 | |||
| 262 | $columns = [ |
||
| 263 | 'field' => [ |
||
| 264 | 'title' => $this->lang['strfield'], |
||
| 265 | 'field' => Decorator::field('attname'), |
||
| 266 | ], |
||
| 267 | 'type' => [ |
||
| 268 | 'title' => $this->lang['strtype'], |
||
| 269 | 'field' => Decorator::field('+type'), |
||
| 270 | ], |
||
| 271 | 'comment' => [ |
||
| 272 | 'title' => $this->lang['strcomment'], |
||
| 273 | 'field' => Decorator::field('comment'), |
||
| 274 | ], |
||
| 275 | ]; |
||
| 276 | |||
| 277 | $actions = []; |
||
| 278 | |||
| 279 | echo $this->printTable($attrs, $columns, $actions, 'types-properties', null, $attPre); |
||
| 280 | |||
| 281 | break; |
||
| 282 | case 'e': |
||
| 283 | $vals = $data->getEnumValues($typedata->fields['typname']); |
||
| 284 | // no break |
||
| 285 | default: |
||
| 286 | $byval = $data->phpBool($typedata->fields['typbyval']); |
||
| 287 | echo "<table>\n"; |
||
| 288 | echo "<tr><th class=\"data left\">{$this->lang['strname']}</th>\n"; |
||
| 289 | echo '<td class="data1">', $this->misc->printVal($typedata->fields['typname']), "</td></tr>\n"; |
||
| 290 | echo "<tr><th class=\"data left\">{$this->lang['strinputfn']}</th>\n"; |
||
| 291 | echo '<td class="data1">', $this->misc->printVal($typedata->fields['typin']), "</td></tr>\n"; |
||
| 292 | echo "<tr><th class=\"data left\">{$this->lang['stroutputfn']}</th>\n"; |
||
| 293 | echo '<td class="data1">', $this->misc->printVal($typedata->fields['typout']), "</td></tr>\n"; |
||
| 294 | echo "<tr><th class=\"data left\">{$this->lang['strlength']}</th>\n"; |
||
| 295 | echo '<td class="data1">', $this->misc->printVal($typedata->fields['typlen']), "</td></tr>\n"; |
||
| 296 | echo "<tr><th class=\"data left\">{$this->lang['strpassbyval']}</th>\n"; |
||
| 297 | echo '<td class="data1">', ($byval) ? $this->lang['stryes'] : $this->lang['strno'], "</td></tr>\n"; |
||
| 298 | echo "<tr><th class=\"data left\">{$this->lang['stralignment']}</th>\n"; |
||
| 299 | echo '<td class="data1">', $this->misc->printVal($typedata->fields['typalign']), "</td></tr>\n"; |
||
| 300 | if ($data->hasEnumTypes() && $vals) { |
||
| 301 | $vals = $vals->getArray(); |
||
| 302 | $nbVals = count($vals); |
||
| 303 | echo "<tr>\n\t<th class=\"data left\" rowspan=\"${nbVals}\">{$this->lang['strenumvalues']}</th>\n"; |
||
| 304 | echo "<td class=\"data2\">{$vals[0]['enumval']}</td></tr>\n"; |
||
| 305 | for ($i = 1; $i < $nbVals; ++$i) { |
||
| 306 | echo '<td class="data', 2 - ($i % 2), "\">{$vals[$i]['enumval']}</td></tr>\n"; |
||
| 307 | } |
||
| 308 | } |
||
| 309 | echo "</table>\n"; |
||
| 310 | } |
||
| 311 | |||
| 312 | $this->printNavLinks(['showall' => [ |
||
|
1 ignored issue
–
show
|
|||
| 313 | 'attr' => [ |
||
| 314 | 'href' => [ |
||
| 315 | 'url' => 'types', |
||
| 316 | 'urlvars' => [ |
||
| 317 | 'server' => $_REQUEST['server'], |
||
| 318 | 'database' => $_REQUEST['database'], |
||
| 319 | 'schema' => $_REQUEST['schema'], |
||
| 320 | ], |
||
| 321 | ], |
||
| 322 | ], |
||
| 323 | 'content' => $this->lang['strshowalltypes'], |
||
| 324 | ]], 'types-properties', get_defined_vars()); |
||
|
1 ignored issue
–
show
|
|||
| 325 | } else { |
||
| 326 | $this->doDefault($this->lang['strinvalidparam']); |
||
| 327 | } |
||
| 328 | } |
||
| 329 | |||
| 330 | /** |
||
| 331 | * Show confirmation of drop and perform actual drop. |
||
| 332 | * |
||
| 333 | * @param mixed $confirm |
||
| 334 | */ |
||
| 335 | public function doDrop($confirm) |
||
| 336 | { |
||
| 337 | $data = $this->misc->getDatabaseAccessor(); |
||
| 338 | |||
| 339 | if ($confirm) { |
||
| 340 | $this->printTrail('type'); |
||
| 341 | $this->printTitle($this->lang['strdrop'], 'pg.type.drop'); |
||
| 342 | |||
| 343 | echo '<p>', sprintf($this->lang['strconfdroptype'], $this->misc->printVal($_REQUEST['type'])), "</p>\n"; |
||
| 344 | |||
| 345 | echo '<form action="'.\SUBFOLDER."/src/views/types\" method=\"post\">\n"; |
||
| 346 | echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$this->lang['strcascade']}</label></p>\n"; |
||
| 347 | echo "<p><input type=\"hidden\" name=\"action\" value=\"drop\" />\n"; |
||
| 348 | echo '<input type="hidden" name="type" value="', htmlspecialchars($_REQUEST['type']), "\" />\n"; |
||
| 349 | echo $this->misc->form; |
||
| 350 | echo "<input type=\"submit\" name=\"drop\" value=\"{$this->lang['strdrop']}\" />\n"; |
||
| 351 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
| 352 | echo "</form>\n"; |
||
| 353 | } else { |
||
| 354 | $status = $data->dropType($_POST['type'], isset($_POST['cascade'])); |
||
| 355 | if (0 == $status) { |
||
| 356 | $this->doDefault($this->lang['strtypedropped']); |
||
| 357 | } else { |
||
| 358 | $this->doDefault($this->lang['strtypedroppedbad']); |
||
| 359 | } |
||
| 360 | } |
||
| 361 | } |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Displays a screen where they can enter a new composite type. |
||
| 365 | * |
||
| 366 | * @param mixed $msg |
||
| 367 | */ |
||
| 368 | public function doCreateComposite($msg = '') |
||
| 369 | { |
||
| 370 | $data = $this->misc->getDatabaseAccessor(); |
||
| 371 | |||
| 372 | if (!isset($_REQUEST['stage'])) { |
||
| 373 | $_REQUEST['stage'] = 1; |
||
| 374 | } |
||
| 375 | |||
| 376 | if (!isset($_REQUEST['name'])) { |
||
| 377 | $_REQUEST['name'] = ''; |
||
| 378 | } |
||
| 379 | |||
| 380 | if (!isset($_REQUEST['fields'])) { |
||
| 381 | $_REQUEST['fields'] = ''; |
||
| 382 | } |
||
| 383 | |||
| 384 | if (!isset($_REQUEST['typcomment'])) { |
||
| 385 | $_REQUEST['typcomment'] = ''; |
||
| 386 | } |
||
| 387 | |||
| 388 | switch ($_REQUEST['stage']) { |
||
| 389 | case 1: |
||
| 390 | $this->printTrail('type'); |
||
| 391 | $this->printTitle($this->lang['strcreatecomptype'], 'pg.type.create'); |
||
| 392 | $this->printMsg($msg); |
||
| 393 | |||
| 394 | echo '<form action="'.\SUBFOLDER."/src/views/types\" method=\"post\">\n"; |
||
| 395 | echo "<table>\n"; |
||
| 396 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strname']}</th>\n"; |
||
| 397 | echo "\t\t<td class=\"data\"><input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 398 | htmlspecialchars($_REQUEST['name']), "\" /></td>\n\t</tr>\n"; |
||
| 399 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strnumfields']}</th>\n"; |
||
| 400 | echo "\t\t<td class=\"data\"><input name=\"fields\" size=\"5\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 401 | htmlspecialchars($_REQUEST['fields']), "\" /></td>\n\t</tr>\n"; |
||
| 402 | |||
| 403 | echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strcomment']}</th>\n"; |
||
| 404 | echo "\t\t<td><textarea name=\"typcomment\" rows=\"3\" cols=\"32\">", |
||
| 405 | htmlspecialchars($_REQUEST['typcomment']), "</textarea></td>\n\t</tr>\n"; |
||
| 406 | |||
| 407 | echo "</table>\n"; |
||
| 408 | echo "<p><input type=\"hidden\" name=\"action\" value=\"create_comp\" />\n"; |
||
| 409 | echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n"; |
||
| 410 | echo $this->misc->form; |
||
| 411 | echo "<input type=\"submit\" value=\"{$this->lang['strnext']}\" />\n"; |
||
| 412 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
| 413 | echo "</form>\n"; |
||
| 414 | |||
| 415 | break; |
||
| 416 | case 2: |
||
| 417 | |||
| 418 | // Check inputs |
||
| 419 | $fields = trim($_REQUEST['fields']); |
||
| 420 | if ('' == trim($_REQUEST['name'])) { |
||
| 421 | $_REQUEST['stage'] = 1; |
||
| 422 | $this->doCreateComposite($this->lang['strtypeneedsname']); |
||
| 423 | |||
| 424 | return; |
||
| 425 | } |
||
| 426 | if ('' == $fields || !is_numeric($fields) || $fields != (int) $fields || $fields < 1) { |
||
| 427 | $_REQUEST['stage'] = 1; |
||
| 428 | $this->doCreateComposite($this->lang['strtypeneedscols']); |
||
| 429 | |||
| 430 | return; |
||
| 431 | } |
||
| 432 | |||
| 433 | $types = $data->getTypes(true, false, true); |
||
| 434 | |||
| 435 | $this->printTrail('schema'); |
||
| 436 | $this->printTitle($this->lang['strcreatecomptype'], 'pg.type.create'); |
||
| 437 | $this->printMsg($msg); |
||
| 438 | |||
| 439 | echo '<form action="'.\SUBFOLDER."/src/views/types\" method=\"post\">\n"; |
||
| 440 | |||
| 441 | // Output table header |
||
| 442 | echo "<table>\n"; |
||
| 443 | echo "\t<tr><th colspan=\"2\" class=\"data required\">{$this->lang['strfield']}</th><th colspan=\"2\" class=\"data required\">{$this->lang['strtype']}</th>"; |
||
| 444 | echo "<th class=\"data\">{$this->lang['strlength']}</th><th class=\"data\">{$this->lang['strcomment']}</th></tr>\n"; |
||
| 445 | |||
| 446 | for ($i = 0; $i < $_REQUEST['fields']; ++$i) { |
||
| 447 | if (!isset($_REQUEST['field'][$i])) { |
||
| 448 | $_REQUEST['field'][$i] = ''; |
||
| 449 | } |
||
| 450 | |||
| 451 | if (!isset($_REQUEST['length'][$i])) { |
||
| 452 | $_REQUEST['length'][$i] = ''; |
||
| 453 | } |
||
| 454 | |||
| 455 | if (!isset($_REQUEST['colcomment'][$i])) { |
||
| 456 | $_REQUEST['colcomment'][$i] = ''; |
||
| 457 | } |
||
| 458 | |||
| 459 | echo "\t<tr>\n\t\t<td>", $i + 1, ". </td>\n"; |
||
| 460 | echo "\t\t<td><input name=\"field[{$i}]\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 461 | htmlspecialchars($_REQUEST['field'][$i]), "\" /></td>\n"; |
||
| 462 | echo "\t\t<td>\n\t\t\t<select name=\"type[{$i}]\">\n"; |
||
| 463 | $types->moveFirst(); |
||
| 464 | while (!$types->EOF) { |
||
| 465 | $typname = $types->fields['typname']; |
||
| 466 | echo "\t\t\t\t<option value=\"", htmlspecialchars($typname), '"', |
||
| 467 | (isset($_REQUEST['type'][$i]) && $_REQUEST['type'][$i] == $typname) ? ' selected="selected"' : '', '>', |
||
| 468 | $this->misc->printVal($typname), "</option>\n"; |
||
| 469 | $types->moveNext(); |
||
| 470 | } |
||
| 471 | echo "\t\t\t</select>\n\t\t</td>\n"; |
||
| 472 | |||
| 473 | // Output array type selector |
||
| 474 | echo "\t\t<td>\n\t\t\t<select name=\"array[{$i}]\">\n"; |
||
| 475 | echo "\t\t\t\t<option value=\"\"", (isset($_REQUEST['array'][$i]) && $_REQUEST['array'][$i] == '') ? ' selected="selected"' : '', "></option>\n"; |
||
| 476 | echo "\t\t\t\t<option value=\"[]\"", (isset($_REQUEST['array'][$i]) && $_REQUEST['array'][$i] == '[]') ? ' selected="selected"' : '', ">[ ]</option>\n"; |
||
| 477 | echo "\t\t\t</select>\n\t\t</td>\n"; |
||
| 478 | |||
| 479 | echo "\t\t<td><input name=\"length[{$i}]\" size=\"10\" value=\"", |
||
| 480 | htmlspecialchars($_REQUEST['length'][$i]), "\" /></td>\n"; |
||
| 481 | echo "\t\t<td><input name=\"colcomment[{$i}]\" size=\"40\" value=\"", |
||
| 482 | htmlspecialchars($_REQUEST['colcomment'][$i]), "\" /></td>\n\t</tr>\n"; |
||
| 483 | } |
||
| 484 | echo "</table>\n"; |
||
| 485 | echo "<p><input type=\"hidden\" name=\"action\" value=\"create_comp\" />\n"; |
||
| 486 | echo "<input type=\"hidden\" name=\"stage\" value=\"3\" />\n"; |
||
| 487 | echo $this->misc->form; |
||
| 488 | echo '<input type="hidden" name="name" value="', htmlspecialchars($_REQUEST['name']), "\" />\n"; |
||
| 489 | echo '<input type="hidden" name="fields" value="', htmlspecialchars($_REQUEST['fields']), "\" />\n"; |
||
| 490 | echo '<input type="hidden" name="typcomment" value="', htmlspecialchars($_REQUEST['typcomment']), "\" />\n"; |
||
| 491 | echo "<input type=\"submit\" value=\"{$this->lang['strcreate']}\" />\n"; |
||
| 492 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
| 493 | echo "</form>\n"; |
||
| 494 | |||
| 495 | break; |
||
| 496 | case 3: |
||
| 497 | |||
| 498 | // Check inputs |
||
| 499 | $fields = trim($_REQUEST['fields']); |
||
| 500 | if ('' == trim($_REQUEST['name'])) { |
||
| 501 | $_REQUEST['stage'] = 1; |
||
| 502 | $this->doCreateComposite($this->lang['strtypeneedsname']); |
||
| 503 | |||
| 504 | return; |
||
| 505 | } |
||
| 506 | if ('' == $fields || !is_numeric($fields) || $fields != (int) $fields || $fields <= 0) { |
||
| 507 | $_REQUEST['stage'] = 1; |
||
| 508 | $this->doCreateComposite($this->lang['strtypeneedscols']); |
||
| 509 | |||
| 510 | return; |
||
| 511 | } |
||
| 512 | |||
| 513 | $status = $data->createCompositeType( |
||
| 514 | $_REQUEST['name'], |
||
| 515 | $_REQUEST['fields'], |
||
| 516 | $_REQUEST['field'], |
||
| 517 | $_REQUEST['type'], |
||
| 518 | $_REQUEST['array'], |
||
| 519 | $_REQUEST['length'], |
||
| 520 | $_REQUEST['colcomment'], |
||
| 521 | $_REQUEST['typcomment'] |
||
| 522 | ); |
||
| 523 | |||
| 524 | if (0 == $status) { |
||
| 525 | $this->doDefault($this->lang['strtypecreated']); |
||
| 526 | } elseif ($status == -1) { |
||
| 527 | $_REQUEST['stage'] = 2; |
||
| 528 | $this->doCreateComposite($this->lang['strtypeneedsfield']); |
||
| 529 | |||
| 530 | return; |
||
| 531 | } else { |
||
| 532 | $_REQUEST['stage'] = 2; |
||
| 533 | $this->doCreateComposite($this->lang['strtypecreatedbad']); |
||
| 534 | |||
| 535 | return; |
||
| 536 | } |
||
| 537 | |||
| 538 | break; |
||
| 539 | default: |
||
| 540 | echo "<p>{$this->lang['strinvalidparam']}</p>\n"; |
||
| 541 | } |
||
| 542 | } |
||
| 543 | |||
| 544 | /** |
||
| 545 | * Displays a screen where they can enter a new enum type. |
||
| 546 | * |
||
| 547 | * @param mixed $msg |
||
| 548 | */ |
||
| 549 | public function doCreateEnum($msg = '') |
||
| 550 | { |
||
| 551 | $data = $this->misc->getDatabaseAccessor(); |
||
| 552 | |||
| 553 | if (!isset($_REQUEST['stage'])) { |
||
| 554 | $_REQUEST['stage'] = 1; |
||
| 555 | } |
||
| 556 | |||
| 557 | if (!isset($_REQUEST['name'])) { |
||
| 558 | $_REQUEST['name'] = ''; |
||
| 559 | } |
||
| 560 | |||
| 561 | if (!isset($_REQUEST['values'])) { |
||
| 562 | $_REQUEST['values'] = ''; |
||
| 563 | } |
||
| 564 | |||
| 565 | if (!isset($_REQUEST['typcomment'])) { |
||
| 566 | $_REQUEST['typcomment'] = ''; |
||
| 567 | } |
||
| 568 | |||
| 569 | switch ($_REQUEST['stage']) { |
||
| 570 | case 1: |
||
| 571 | $this->printTrail('type'); |
||
| 572 | $this->printTitle($this->lang['strcreateenumtype'], 'pg.type.create'); |
||
| 573 | $this->printMsg($msg); |
||
| 574 | |||
| 575 | echo '<form action="'.\SUBFOLDER."/src/views/types\" method=\"post\">\n"; |
||
| 576 | echo "<table>\n"; |
||
| 577 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strname']}</th>\n"; |
||
| 578 | echo "\t\t<td class=\"data\"><input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 579 | htmlspecialchars($_REQUEST['name']), "\" /></td>\n\t</tr>\n"; |
||
| 580 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$this->lang['strnumvalues']}</th>\n"; |
||
| 581 | echo "\t\t<td class=\"data\"><input name=\"values\" size=\"5\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 582 | htmlspecialchars($_REQUEST['values']), "\" /></td>\n\t</tr>\n"; |
||
| 583 | |||
| 584 | echo "\t<tr>\n\t\t<th class=\"data left\">{$this->lang['strcomment']}</th>\n"; |
||
| 585 | echo "\t\t<td><textarea name=\"typcomment\" rows=\"3\" cols=\"32\">", |
||
| 586 | htmlspecialchars($_REQUEST['typcomment']), "</textarea></td>\n\t</tr>\n"; |
||
| 587 | |||
| 588 | echo "</table>\n"; |
||
| 589 | echo "<p><input type=\"hidden\" name=\"action\" value=\"create_enum\" />\n"; |
||
| 590 | echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n"; |
||
| 591 | echo $this->misc->form; |
||
| 592 | echo "<input type=\"submit\" value=\"{$this->lang['strnext']}\" />\n"; |
||
| 593 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
| 594 | echo "</form>\n"; |
||
| 595 | |||
| 596 | break; |
||
| 597 | case 2: |
||
| 598 | |||
| 599 | // Check inputs |
||
| 600 | $values = trim($_REQUEST['values']); |
||
| 601 | if ('' == trim($_REQUEST['name'])) { |
||
| 602 | $_REQUEST['stage'] = 1; |
||
| 603 | $this->doCreateEnum($this->lang['strtypeneedsname']); |
||
| 604 | |||
| 605 | return; |
||
| 606 | } |
||
| 607 | if ('' == $values || !is_numeric($values) || $values != (int) $values || $values < 1) { |
||
| 608 | $_REQUEST['stage'] = 1; |
||
| 609 | $this->doCreateEnum($this->lang['strtypeneedsvals']); |
||
| 610 | |||
| 611 | return; |
||
| 612 | } |
||
| 613 | |||
| 614 | $this->printTrail('schema'); |
||
| 615 | $this->printTitle($this->lang['strcreateenumtype'], 'pg.type.create'); |
||
| 616 | $this->printMsg($msg); |
||
| 617 | |||
| 618 | echo '<form action="'.\SUBFOLDER."/src/views/types\" method=\"post\">\n"; |
||
| 619 | |||
| 620 | // Output table header |
||
| 621 | echo "<table>\n"; |
||
| 622 | echo "\t<tr><th colspan=\"2\" class=\"data required\">{$this->lang['strvalue']}</th></tr>\n"; |
||
| 623 | |||
| 624 | for ($i = 0; $i < $_REQUEST['values']; ++$i) { |
||
| 625 | if (!isset($_REQUEST['value'][$i])) { |
||
| 626 | $_REQUEST['value'][$i] = ''; |
||
| 627 | } |
||
| 628 | |||
| 629 | echo "\t<tr>\n\t\t<td>", $i + 1, ". </td>\n"; |
||
| 630 | echo "\t\t<td><input name=\"value[{$i}]\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 631 | htmlspecialchars($_REQUEST['value'][$i]), "\" /></td>\n\t</tr>\n"; |
||
| 632 | } |
||
| 633 | echo "</table>\n"; |
||
| 634 | echo "<p><input type=\"hidden\" name=\"action\" value=\"create_enum\" />\n"; |
||
| 635 | echo "<input type=\"hidden\" name=\"stage\" value=\"3\" />\n"; |
||
| 636 | echo $this->misc->form; |
||
| 637 | echo '<input type="hidden" name="name" value="', htmlspecialchars($_REQUEST['name']), "\" />\n"; |
||
| 638 | echo '<input type="hidden" name="values" value="', htmlspecialchars($_REQUEST['values']), "\" />\n"; |
||
| 639 | echo '<input type="hidden" name="typcomment" value="', htmlspecialchars($_REQUEST['typcomment']), "\" />\n"; |
||
| 640 | echo "<input type=\"submit\" value=\"{$this->lang['strcreate']}\" />\n"; |
||
| 641 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$this->lang['strcancel']}\" /></p>\n"; |
||
| 642 | echo "</form>\n"; |
||
| 643 | |||
| 644 | break; |
||
| 645 | case 3: |
||
| 646 | |||
| 647 | // Check inputs |
||
| 648 | $values = trim($_REQUEST['values']); |
||
| 649 | if ('' == trim($_REQUEST['name'])) { |
||
| 650 | $_REQUEST['stage'] = 1; |
||
| 651 | $this->doCreateEnum($this->lang['strtypeneedsname']); |
||
| 652 | |||
| 653 | return; |
||
| 654 | } |
||
| 655 | if ('' == $values || !is_numeric($values) || $values != (int) $values || $values <= 0) { |
||
| 656 | $_REQUEST['stage'] = 1; |
||
| 657 | $this->doCreateEnum($this->lang['strtypeneedsvals']); |
||
| 658 | |||
| 659 | return; |
||
| 660 | } |
||
| 661 | |||
| 662 | $status = $data->createEnumType($_REQUEST['name'], $_REQUEST['value'], $_REQUEST['typcomment']); |
||
| 663 | |||
| 664 | if (0 == $status) { |
||
| 665 | $this->doDefault($this->lang['strtypecreated']); |
||
| 666 | } elseif ($status == -1) { |
||
| 667 | $_REQUEST['stage'] = 2; |
||
| 668 | $this->doCreateEnum($this->lang['strtypeneedsvalue']); |
||
| 669 | |||
| 670 | return; |
||
| 671 | } else { |
||
| 672 | $_REQUEST['stage'] = 2; |
||
| 673 | $this->doCreateEnum($this->lang['strtypecreatedbad']); |
||
| 674 | |||
| 675 | return; |
||
| 676 | } |
||
| 677 | |||
| 678 | break; |
||
| 679 | default: |
||
| 680 | echo "<p>{$this->lang['strinvalidparam']}</p>\n"; |
||
| 681 | } |
||
| 682 | } |
||
| 683 | |||
| 684 | /** |
||
| 685 | * Displays a screen where they can enter a new type. |
||
| 686 | * |
||
| 687 | * @param mixed $msg |
||
| 688 | */ |
||
| 689 | public function doCreate($msg = '') |
||
| 803 | } |
||
| 804 | |||
| 805 | /** |
||
| 806 | * Actually creates the new type in the database. |
||
| 807 | */ |
||
| 808 | public function doSaveCreate() |
||
| 836 | } |
||
| 837 | } |
||
| 838 | } |
||
| 840 |