SF.net SVN: postfixadmin:[1310] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2011-12-26 20:54:47
|
Revision: 1310 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=1310&view=rev Author: christian_boltz Date: 2011-12-26 20:54:40 +0000 (Mon, 26 Dec 2011) Log Message: ----------- AliasHandler.php: - add initStruct() (not the final version, but works for now) - add initMsg() - replace $this->username with $this->id everywhere - drop __construct() - default __construct will be used now users/edit-alias.php, xmlrpc.php, VacationHandler.php, scripts/shells/alias.php: - use default init sequence for AliasHandler (new, then ->init()) Modified Paths: -------------- trunk/model/AliasHandler.php trunk/model/VacationHandler.php trunk/scripts/shells/alias.php trunk/users/edit-alias.php trunk/xmlrpc.php Modified: trunk/model/AliasHandler.php =================================================================== --- trunk/model/AliasHandler.php 2011-12-26 18:27:25 UTC (rev 1309) +++ trunk/model/AliasHandler.php 2011-12-26 20:54:40 UTC (rev 1310) @@ -16,20 +16,43 @@ */ public $return = null; - /** - * @param string $username - */ - public function __construct($username) { - $this->username = strtolower($username); + protected function initStruct() { + $this->db_table = 'alias'; + $this->id_field = 'address'; + + $this->struct=array( + # field name allow display in... type $PALANG label $PALANG description default / options / ... + # editing? form list + 'address' => pacol( $this->new, 1, 1, 'mail', 'pCreate_alias_domain_alias' , 'pCreate_alias_domain_alias_text' ), + 'goto' => pacol( 1, 1, 1, 'mail', 'pCreate_alias_domain_target' , 'pCreate_alias_domain_target_text' ), + 'domain' => pacol( $this->new, 0, 0, 'text', '' , '' ), + 'active' => pacol( 1, 1, 1, 'bool', 'pAdminEdit_domain_active' , '' , 1 ), + 'created' => pacol( 0, 0, 1, 'ts', 'created' , '' ), + 'modified' => pacol( 0, 0, 1, 'ts', 'pAdminList_domain_modified' , '' ), + ); } + protected function initMsg() { + $this->msg['error_already_exists'] = 'pCreate_alias_address_text_error2'; + $this->msg['error_does_not_exist'] = 'pCreate_alias_address_text_error1'; # TODO: better error message + if ($this->new) { + $this->msg['logname'] = 'create_alias'; + $this->msg['store_error'] = 'pCreate_alias_result_error'; + } else { + $this->msg['logname'] = 'edit_alias'; + $this->msg['store_error'] = 'pEdit_alias_result_error'; + } + } + + + /** * @return bool true if succeed * (may be an empty list, especially if $CONF['alias_control'] is turned off...) * @param boolean - by default we don't return special addresses (e.g. vacation and mailbox alias); pass in true here if you wish to. */ public function get($all=false) { - $E_username = escape_string($this->username); + $E_username = escape_string($this->id); $table_alias = table_by_key('alias'); $sql = "SELECT * FROM $table_alias WHERE address='$E_username'"; @@ -71,7 +94,7 @@ public function is_mailbox_alias($address) { global $CONF; - if($address != $this->username) { # avoid false positives if $address is a mailbox + if($address != $this->id) { # avoid false positives if $address is a mailbox return false; } @@ -120,7 +143,7 @@ } $addresses = array_unique($addresses); - list (/*NULL*/, $domain) = explode('@', $this->username); + list (/*NULL*/, $domain) = explode('@', $this->id); if ( ! $this->get(true) ) die("Alias not existing?"); # TODO: better error behaviour @@ -142,7 +165,7 @@ if($flags == 'remote_only') { foreach($addresses as $address) { # TODO: write a remove_from_array function, see http://tech.petegraham.co.uk/2007/03/22/php-remove-values-from-array/ // strip out our username... if it's in the list given. - if($address != $this->username) { + if($address != $this->id) { $new_list[] = $address; } } @@ -150,8 +173,8 @@ } if($flags == 'forward_and_store') { - if(!in_array($this->username, $addresses)) { - $addresses[] = $this->username; + if(!in_array($this->id, $addresses)) { + $addresses[] = $this->id; } } $new_list = array(); @@ -161,15 +184,15 @@ } } $addresses = array_unique($new_list); - $E_username = escape_string($this->username); + $E_username = escape_string($this->id); $goto = implode(',', $addresses); if(sizeof($addresses) == 0) { - # $result = db_delete('alias', 'address', $this->username); # '"DELETE FROM $table_alias WHERE address = '$username'"; # TODO: should never happen and causes broken behaviour - error_log("Alias set to empty / Attemp to delete: " . $this->username); # TODO: more/better error handling - maybe just return false? + # $result = db_delete('alias', 'address', $this->id); # '"DELETE FROM $table_alias WHERE address = '$username'"; # TODO: should never happen and causes broken behaviour + error_log("Alias set to empty / Attemp to delete: " . $this->id); # TODO: more/better error handling - maybe just return false? } if($this->hasAliasRecord() == false) { # TODO should never happen in update() - see also the comments on handling DELETE above $alias_data = array( - 'address' => $this->username, + 'address' => $this->id, 'goto' => $goto, 'domain' => $domain, 'active' => db_get_boolean(True), @@ -179,7 +202,7 @@ $alias_data = array( 'goto' => $goto, ); - $result = db_update('alias', 'address', $this->username, $alias_data); + $result = db_update('alias', 'address', $this->id, $alias_data); } if($result != 1) { return false; @@ -195,7 +218,7 @@ */ public function hasStoreAndForward() { $result = $this->get(true); # TODO: error checking? - if(in_array($this->username, $this->return)) { + if(in_array($this->id, $this->return)) { return true; } return false; @@ -205,7 +228,7 @@ * @return boolean true if the user has an alias record (i.e row in alias table); else false. */ public function hasAliasRecord() { - $username = escape_string($this->username); + $username = escape_string($this->id); $table_alias = table_by_key('alias'); $sql = "SELECT * FROM $table_alias WHERE address = '$username'"; $result = db_query($sql); @@ -224,15 +247,15 @@ return false; } - if ($this->is_mailbox_alias($this->username) ) { + if ($this->is_mailbox_alias($this->id) ) { $this->errormsg[] = 'This alias belongs to a mailbox and can\'t be deleted.'; # TODO: make translatable return false; } - $result = db_delete('alias', 'address', $this->username); + $result = db_delete('alias', 'address', $this->id); if( $result == 1 ) { - list(/*NULL*/,$domain) = explode('@', $this->username); - db_log ($domain, 'delete_alias', $this->username); + list(/*NULL*/,$domain) = explode('@', $this->id); + db_log ($domain, 'delete_alias', $this->id); return true; } } Modified: trunk/model/VacationHandler.php =================================================================== --- trunk/model/VacationHandler.php 2011-12-26 18:27:25 UTC (rev 1309) +++ trunk/model/VacationHandler.php 2011-12-26 20:54:40 UTC (rev 1310) @@ -13,7 +13,8 @@ * @return boolean true on success. */ function remove() { - $ah = new AliasHandler($this->username); + $ah = new AliasHandler(); + $ah->init($this->username); $result = $ah->get(true); if($result === true) { // fetch all # TODO check $result, error handling $aliases = $ah->return; @@ -53,7 +54,8 @@ * Why do we bother storing true/false in the vacation table if the alias dictates it anyway? */ function check_vacation() { - $ah = new AliasHandler($this->username); + $ah = new AliasHandler(); + $ah->init($this->username); $success = $ah->get(true); # fetch all. if (!$success) { return false; # TODO: error handling? @@ -127,7 +129,8 @@ } # TODO error check # TODO wrap whole function in db_begin / db_commit (or rollback)? - $ah = new AliasHandler($this->username); + $ah = new AliasHandler(); + $ah->init($this->username); $alias = $ah->get(true); $aliases = $ah->return; $vacation_address = $this->getVacationAlias(); Modified: trunk/scripts/shells/alias.php =================================================================== --- trunk/scripts/shells/alias.php 2011-12-26 18:27:25 UTC (rev 1309) +++ trunk/scripts/shells/alias.php 2011-12-26 20:54:40 UTC (rev 1310) @@ -103,7 +103,8 @@ */ function __handle($address, $goto) { - $handler = new AliasHandler($address); + $handler = new AliasHandler(1); + $handler->init($address); $return = $handler->add($goto); if($return == 1) { @@ -227,7 +228,8 @@ ### (and will probably cause some error messages that I added today ;-) ### Implemented check it please! - $handler = new AliasHandler($address); + $handler = new AliasHandler(); + $handler->init($address); $status = $handler->delete(); if ($status == true) { $this->out("Mailbox of '$address' was deleted."); @@ -296,7 +298,8 @@ function __handle($address) { - $handler = new AliasHandler($address); + $handler = new AliasHandler(); + $handler->init($address); $status = $handler->get(); # TODO: set the "all" flag? if ( ! $status) { $this->error("Error: Not Found", "The requested alias was not found!"); @@ -343,3 +346,5 @@ } } + +/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ Modified: trunk/users/edit-alias.php =================================================================== --- trunk/users/edit-alias.php 2011-12-26 18:27:25 UTC (rev 1309) +++ trunk/users/edit-alias.php 2011-12-26 20:54:40 UTC (rev 1310) @@ -37,7 +37,9 @@ $tmp = preg_split ('/@/', $USERID_USERNAME); $USERID_DOMAIN = $tmp[1]; -$ah = new AliasHandler($USERID_USERNAME); +$ah = new AliasHandler(); +$ah->init($USERID_USERNAME); + $smarty->assign ('USERID_USERNAME', $USERID_USERNAME); Modified: trunk/xmlrpc.php =================================================================== --- trunk/xmlrpc.php 2011-12-26 18:27:25 UTC (rev 1309) +++ trunk/xmlrpc.php 2011-12-26 20:54:40 UTC (rev 1310) @@ -139,7 +139,8 @@ * @return array - array of aliases this user has. Array may be empty. */ public function get() { - $ah = new AliasHandler($_SESSION['username']); + $ah = new AliasHandler(); + $ah->init($_SESSION['username']); /* I see no point in returning special addresses to the user. */ $ah->get(false); return $ah->result; @@ -151,7 +152,8 @@ * @return boolean true */ public function update($addresses, $flags) { - $ah = new AliasHandler($_SESSION['username']); + $ah = new AliasHandler(); + $ah->init($_SESSION['username']); /** * if the user is on vacation, they should use VacationProxy stuff to remove it * and we'll never return the vacation address from here anyway @@ -164,7 +166,8 @@ * (i.e. their email address is also in the alias table). IF it returns false, then it's 'remote_only' */ public function hasStoreAndForward() { - $ah = new AliasHandler($_SESSION['username']); + $ah = new AliasHandler(); + $ah->init($_SESSION['username']); return $ah->hasStoreAndForward(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |