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