SF.net SVN: postfixadmin:[1364] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2012-04-09 20:01:46
|
Revision: 1364 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=1364&view=rev Author: christian_boltz Date: 2012-04-09 20:01:40 +0000 (Mon, 09 Apr 2012) Log Message: ----------- PFAHandler: - set(): call $this->_missing_$fieldname() if a field is not set on $new - new function set_default_value() - typically called from _missing_$fieldname to set the default from $struct AliasHandler: - set default values on $new: - on_vacation and active from $struct default - localpart and domain based on address scripts/shells/alias.php: - convert AddTask to *Handler syntax. It was broken before, see https://sourceforge.net/tracker/?func=detail&aid=3232719&group_id=191583&atid=937964 Modified Paths: -------------- trunk/model/AliasHandler.php trunk/model/PFAHandler.php trunk/scripts/shells/alias.php Modified: trunk/model/AliasHandler.php =================================================================== --- trunk/model/AliasHandler.php 2012-04-09 17:56:21 UTC (rev 1363) +++ trunk/model/AliasHandler.php 2012-04-09 20:01:40 UTC (rev 1364) @@ -286,7 +286,24 @@ } } + protected function _missing_on_vacation($field) { return $this->set_default_value($field); } + protected function _missing_active ($field) { return $this->set_default_value($field); } + protected function _missing_localpart ($field) { + if (isset($this->RAWvalues['address'])) { + $parts = explode('@', $this->RAWvalues['address']); + if (count($parts) == 2) $this->RAWvalues['localpart'] = $parts[0]; + } + } + + protected function _missing_domain ($field) { + if (isset($this->RAWvalues['address'])) { + $parts = explode('@', $this->RAWvalues['address']); + if (count($parts) == 2) $this->RAWvalues['domain'] = $parts[1]; + } + } + + /** * Returns the vacation alias for this user. * i.e. if this user's username was ro...@ex..., and the autoreply domain was set to Modified: trunk/model/PFAHandler.php =================================================================== --- trunk/model/PFAHandler.php 2012-04-09 17:56:21 UTC (rev 1363) +++ trunk/model/PFAHandler.php 2012-04-09 20:01:40 UTC (rev 1364) @@ -98,6 +98,19 @@ $this->RAWvalues = $values; # allows comparison of two fields before the second field is checked # Warning: $this->RAWvalues contains unchecked input data - use it carefully! + if ($this->new) { + foreach($this->struct as $key=>$row) { + if ($row['editable'] && !isset($values[$key]) ) { + $func="_missing_".$key; # call $this->_missing_$fieldname() + if (method_exists($this, $func) ) { + $this->{$func}($key); # function can set $this->RAWvalues[$key] (or do nothing if it can't set a useful value) + } + } + } + $values = $this->RAWvalues; + } + + # base validation $this->values = array(); $this->values_valid = false; @@ -362,6 +375,18 @@ return false; } + /** + * set field to default value + * typically called from _missing_$fieldname() + * @param string $field - fieldname + */ + protected function set_default_value($field) { + if (isset($this->struct[$field]['default'])) { + $this->RAWvalues[$field] = $this->struct[$field]['default']; + } + } + + /************************************************************************** * functions for basic input validation */ Modified: trunk/scripts/shells/alias.php =================================================================== --- trunk/scripts/shells/alias.php 2012-04-09 17:56:21 UTC (rev 1363) +++ trunk/scripts/shells/alias.php 2012-04-09 20:01:40 UTC (rev 1364) @@ -105,9 +105,13 @@ $handler = new AliasHandler(1); $handler->init($address); - $return = $handler->add($goto); - if($return == 1) { + $values = array( + 'goto' => explode(',', $goto), + ); + if (!$handler->set($values)) { + $this->error("Error:", join("\n", $handler->errormsg)); + } elseif (!$handler->store()) { $this->error("Error:", join("\n", $handler->errormsg)); } else { $this->out(""); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |