DomainHandler.php:

- rename $this->username to $this->id
- rename function validate_id() to validate_new_id()


git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1253 a1433add-5e2c-0410-b055-b7f2511e0802
pull/2/head
Christian Boltz 13 years ago
parent 7ac37cfbff
commit 7a236d401c

@ -6,7 +6,7 @@
*/ */
class DomainHandler extends PFAHandler { class DomainHandler extends PFAHandler {
protected $username = null; # actually it's the domain - variable name kept for consistence with the other classes protected $id = null;
protected $db_table = null; protected $db_table = null;
protected $id_field = null; protected $id_field = null;
protected $struct = array(); protected $struct = array();
@ -31,11 +31,11 @@ class DomainHandler extends PFAHandler {
} }
/** /**
* initialize with $username and check if it is valid * initialize with $id and check if it is valid
* @param string $username * @param string $id
*/ */
public function init($username) { public function init($id) {
$this->username = strtolower($username); $this->id = strtolower($id);
$exists = $this->view(false); $exists = $this->view(false);
@ -43,8 +43,8 @@ class DomainHandler extends PFAHandler {
if ($exists) { if ($exists) {
$this->errormsg[$this->id_field] = Lang::read($this->msg['error_already_exists']); $this->errormsg[$this->id_field] = Lang::read($this->msg['error_already_exists']);
return false; return false;
} elseif (!$this->validate_id() ) { } elseif (!$this->validate_new_id() ) {
# errormsg filled by validate_id() # errormsg filled by validate_new_id()
return false; return false;
} else { } else {
return true; return true;
@ -59,8 +59,8 @@ class DomainHandler extends PFAHandler {
} }
} }
protected function validate_id() { protected function validate_new_id() {
$valid = check_domain($this->username); $valid = check_domain($this->id);
if ($valid) { if ($valid) {
return true; return true;
@ -168,7 +168,7 @@ class DomainHandler extends PFAHandler {
# TODO: make this a generic function for add and edit # TODO: make this a generic function for add and edit
if ($this->new == 1) { if ($this->new == 1) {
$values[$this->id_field] = $this->username; $values[$this->id_field] = $this->id;
} }
# base validation # base validation
@ -243,17 +243,17 @@ class DomainHandler extends PFAHandler {
if ($this->new) { if ($this->new) {
$result = db_insert($this->db_table, $db_values); $result = db_insert($this->db_table, $db_values);
} else { } else {
$result = db_update($this->db_table, $this->id_field, $this->username, $db_values); $result = db_update($this->db_table, $this->id_field, $this->id, $db_values);
} }
if ($result != 1) { if ($result != 1) {
$this->errormsg[] = Lang::read($this->msg['store_error']) . "\n(" . $this->username . ")\n"; # TODO: change message + use sprintf $this->errormsg[] = Lang::read($this->msg['store_error']) . "\n(" . $this->id . ")\n"; # TODO: change message + use sprintf
return false; return false;
} }
$result = $this->storemore(); $result = $this->storemore();
if ($result) { if ($result) {
db_log ($this->username, $this->msg['logname'], ""); db_log ($this->id, $this->msg['logname'], "");
} }
return $result; return $result;
} }
@ -265,25 +265,25 @@ class DomainHandler extends PFAHandler {
protected function storemore() { protected function storemore() {
if ($this->new && $this->values['default_aliases']) { if ($this->new && $this->values['default_aliases']) {
foreach (Config::read('default_aliases') as $address=>$goto) { foreach (Config::read('default_aliases') as $address=>$goto) {
$address = $address . "@" . $this->username; $address = $address . "@" . $this->id;
# TODO: use AliasHandler->add instead of writing directly to the alias table # TODO: use AliasHandler->add instead of writing directly to the alias table
$arr = array( $arr = array(
'address' => $address, 'address' => $address,
'goto' => $goto, 'goto' => $goto,
'domain' => $this->username, 'domain' => $this->id,
); );
$result = db_insert ('alias', $arr); $result = db_insert ('alias', $arr);
# TODO: error checking # TODO: error checking
} }
} }
if ($this->new) { if ($this->new) {
$tMessage = Lang::read('pAdminCreate_domain_result_success') . " (" . $this->username . ")"; # TODO: tMessage is not used/returned anywhere $tMessage = Lang::read('pAdminCreate_domain_result_success') . " (" . $this->id . ")"; # TODO: tMessage is not used/returned anywhere
} else { } else {
# TODO: success message for edit # TODO: success message for edit
} }
if ($this->new) { if ($this->new) {
if (!domain_postcreation($this->username)) { if (!domain_postcreation($this->id)) {
$this->errormsg[] = Lang::read('pAdminCreate_domain_error'); $this->errormsg[] = Lang::read('pAdminCreate_domain_error');
} }
} else { } else {
@ -363,7 +363,7 @@ class DomainHandler extends PFAHandler {
* The data is stored in $this->return (as associative array of column => value) * The data is stored in $this->return (as associative array of column => value)
*/ */
public function view($errors=true) { public function view($errors=true) {
$result = $this->read_from_db(array($this->id_field => $this->username) ); $result = $this->read_from_db(array($this->id_field => $this->id) );
if (count($result) == 1) { if (count($result) == 1) {
$this->return = $result[0]; $this->return = $result[0];
return true; return true;
@ -408,10 +408,10 @@ class DomainHandler extends PFAHandler {
# TODO: recursively delete mailboxes, aliases, alias_domains, fetchmail entries etc. before deleting the domain # TODO: recursively delete mailboxes, aliases, alias_domains, fetchmail entries etc. before deleting the domain
# TODO: move the needed code from delete.php here # TODO: move the needed code from delete.php here
$result = db_delete($this->db_table, $this->id_field, $this->username); $result = db_delete($this->db_table, $this->id_field, $this->id);
if ( $result == 1 ) { if ( $result == 1 ) {
list(/*NULL*/,$domain) = explode('@', $this->username); list(/*NULL*/,$domain) = explode('@', $this->id);
db_log ($domain, 'delete_domain', $this->username); # TODO delete_domain is not a valid db_log keyword yet because we don't yet log add/delete domain db_log ($domain, 'delete_domain', $this->id); # TODO delete_domain is not a valid db_log keyword yet because we don't yet log add/delete domain
return true; return true;
} }
} }

Loading…
Cancel
Save