SF.net SVN: postfixadmin:[1348] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2012-04-08 20:16:59
|
Revision: 1348 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=1348&view=rev Author: christian_boltz Date: 2012-04-08 20:16:53 +0000 (Sun, 08 Apr 2012) Log Message: ----------- AliasHandler: - setmore(): keep/(re-)add vacation and mailbox alias to goto - hide 'goto_mailbox' if the alias does not belong to a mailbox (done in initStruct for $new, otherwise in init()) edit.php: - set $form_fields and $id_field later (after $hander->init()) - needed for AliasHandler to decide if goto_mailbox should be displayed With this commit, AliasHandler is feature-complete for usage with edit.php. We even get a "deliver to local mailbox" checkbox :-) Modified Paths: -------------- trunk/edit.php trunk/model/AliasHandler.php Modified: trunk/edit.php =================================================================== --- trunk/edit.php 2012-04-08 17:41:02 UTC (rev 1347) +++ trunk/edit.php 2012-04-08 20:16:53 UTC (rev 1348) @@ -47,9 +47,6 @@ authentication_require_role($formconf['required_role']); -$form_fields = $handler->getStruct(); -$id_field = $handler->getId_field(); - if ($active != '0' && $active != '1') { $active = ''; # ignore invalid values } @@ -62,6 +59,9 @@ } } +$form_fields = $handler->getStruct(); +$id_field = $handler->getId_field(); + if ($edit != "") { $mode = 'edit'; if ($_SERVER['REQUEST_METHOD'] == "GET" && $active == '') { # read values from database (except if $active is set to save some CPU cycles) Modified: trunk/model/AliasHandler.php =================================================================== --- trunk/model/AliasHandler.php 2012-04-08 17:41:02 UTC (rev 1347) +++ trunk/model/AliasHandler.php 2012-04-08 20:16:53 UTC (rev 1348) @@ -20,6 +20,8 @@ $this->db_table = 'alias'; $this->id_field = 'address'; + $mbgoto = 1 - $this->new; + $this->struct=array( # field name allow display in... type $PALANG label $PALANG description default / ... # editing? form list @@ -42,7 +44,7 @@ ' FROM ' . table_by_key('mailbox') . ' WHERE username IS NOT NULL ' . ' ) AS __mailbox ON __mailbox_username = address' ), - 'goto_mailbox' => pacol( 1, 1, 1, 'bool', 'pEdit_alias_forward_and_store' , '' , 0, + 'goto_mailbox' => pacol( $mbgoto, $mbgoto,$mbgoto,'bool', 'pEdit_alias_forward_and_store' , '' , 0, /*options*/ '', /*not_in_db*/ 1 ), 'on_vacation' => pacol( 1, 0, 1, 'bool', 'pUsersMenu_vacation' , '' , 0 , @@ -96,7 +98,18 @@ $id = '@' . $domain; } - return parent::init($id); + $retval = parent::init($id); + + # hide 'goto_mailbox' for non-mailbox aliases + # parent::init called view() before, so we can rely on having $this->return filled + # (only validate_new_id() is called from parent::init and could in theory change $this->return) + if ($this->new || $this->return['is_mailbox'] == 0) { + $this->struct['goto_mailbox']['editable'] = 0; + $this->struct['goto_mailbox']['display_in_form'] = 0; + $this->struct['goto_mailbox']['display_in_list'] = 0; + } + + return $retval; } protected function validate_new_id() { @@ -164,6 +177,32 @@ } } + if (! $this->new) { # edit mode - preserve vacation and mailbox alias if they were included before + $old_ah = new AliasHandler(); + + if (!$old_ah->init($this->id)) { + $this->errormsg[] = $old_ah->errormsg[0]; + } elseif (!$old_ah->view()) { + $this->errormsg[] = $old_ah->errormsg[0]; + } else { + $oldvalues = $old_ah->result(); + + if ($oldvalues['on_vacation']) { + $vh = new VacationHandler($this->id); + $values['goto'][] = $vh->getVacationAlias(); + } + + if ($oldvalues['is_mailbox']) { # alias belongs to a mailbox - add/keep mailbox to/in goto + if (!isset($values['goto_mailbox'])) { # no new value given? + $values['goto_mailbox'] = $oldvalues['goto_mailbox']; + } + if ($values['goto_mailbox']) { + $values['goto'][] = $this->id; + } + } + } + } + $this->values['goto'] = join(',', $values['goto']); # TODO: add mailbox and vacation aliases } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |