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