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