diff --git a/create-domain.php b/create-domain.php index 034e2a85..cfd3aea9 100644 --- a/create-domain.php +++ b/create-domain.php @@ -58,8 +58,8 @@ foreach($form_fields as $key => $field) { if ($_SERVER['REQUEST_METHOD'] == "POST") { - $handler = new DomainHandler($values['domain'], 1); - if (!$handler->result()) { + $handler = new DomainHandler(1); + if (!$handler->init($values['domain'])) { $error = 1; $pAdminCreate_domain_domain_text_error = join("
", $handler->errormsg); } diff --git a/model/DomainHandler.php b/model/DomainHandler.php index 413dc452..25a606df 100644 --- a/model/DomainHandler.php +++ b/model/DomainHandler.php @@ -16,35 +16,44 @@ class DomainHandler extends PFAHandler { public $errormsg = array(); - # error messages used in __construct() and view() + # error messages used in init() and view() protected $error_already_exists = 'pAdminCreate_domain_domain_text_error'; protected $error_does_not_exist = 'domain_does_not_exist'; /** - * @param string $username + * Constructor: fill $struct etc. + * @param string $new */ - public function __construct($username, $new = 0) { - $this->username = strtolower($username); # TODO: find a better place for strtolower() to avoid a special constructor in DomainHandler (or agree that $username should be lowercase in all *Handler classes ;-) + public function __construct($new = 0) { if ($new) $this->new = 1; - $this->initStruct(); + } + + /** + * initialize with $username and check if it is valid + * @param string $username + */ + public function init($username) { + $this->username = strtolower($username); $exists = $this->view(false); - $this->return = false; # be pessimistic by default - if ($new) { + if ($this->new) { if ($exists) { $this->errormsg[] = Lang::read($this->error_already_exists); + return false; } elseif (!$this->validate_id() ) { # errormsg filled by validate_id() + return false; } else { - $this->return = true; + return true; } } else { # edit mode if (!$exists) { $this->errormsg[] = Lang::read($this->error_does_not_exist); + return false; } else { - $this->return = true; + return true; } } } diff --git a/scripts/shells/domain.php b/scripts/shells/domain.php index 130ff88e..0d7a5071 100644 --- a/scripts/shells/domain.php +++ b/scripts/shells/domain.php @@ -110,7 +110,7 @@ class AddTask extends Shell { $question = "Domain Quota (in MB):"; $d = $this->in($question); - $handler = new DomainHandler($domain); + $handler = new DomainHandler(); $transports = $handler->getTransports(); $qt[] = 'Choose transport option'; foreach ($transports AS $key => $val) { @@ -141,8 +141,8 @@ class AddTask extends Shell { function __handle($domain, $desc, $a, $m, $t, $q, $d, $default, $backup) { - $handler = new DomainHandler($domain, 1); - if (!$handler->result()) { + $handler = new DomainHandler(1); + if (!$handler->init($domain)) { $this->error("Error:",join("\n", $handler->errormsg)); return; } @@ -269,8 +269,8 @@ class DeleteTask extends Shell { * @access private */ function __handle($address) { - $handler = new DomainHandler($address); - if (!$handler->result()) { + $handler = new DomainHandler(); + if (!$handler->init($address)) { $this->error("Error:",join("\n", $handler->errormsg)); return; } @@ -345,8 +345,8 @@ class ViewTask extends Shell { function __handle($domain) { - $handler = new DomainHandler($domain); - if (!$handler->result()) { + $handler = new DomainHandler(); + if (!$handler->init($domain)) { $this->error("Error:",join("\n", $handler->errormsg)); return; }