SF.net SVN: postfixadmin:[1356] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <chr...@us...> - 2012-04-09 00:34:32
|
Revision: 1356 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=1356&view=rev Author: christian_boltz Date: 2012-04-09 00:34:26 +0000 (Mon, 09 Apr 2012) Log Message: ----------- VacationHandler: - use new *Handler syntax to add/remove vacation alias (implemented as function updateAlias() to avoid code duplication) AliasHandler: - setmore(): only use $oldvalues if no new on_vacation value is given - setmore(): fix "undefined index" warning edit.php: - only set $values if a field is editable and displayed in the form - do not set default values in $values (without those changes, the vacation alias was always removed when editing an alias) Modified Paths: -------------- trunk/edit.php trunk/model/AliasHandler.php trunk/model/VacationHandler.php Modified: trunk/edit.php =================================================================== --- trunk/edit.php 2012-04-08 23:18:29 UTC (rev 1355) +++ trunk/edit.php 2012-04-09 00:34:26 UTC (rev 1356) @@ -80,9 +80,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { foreach($form_fields as $key => $field) { - if ($field['editable'] == 0) { - $values[$key] = $field['default']; - } else { + if ($field['editable'] && $field['display_in_form']) { if($field['type'] == 'bool') { $values[$key] = safepost($key, 0); # isset() for unchecked checkboxes is always false } elseif($field['type'] == 'txtl') { Modified: trunk/model/AliasHandler.php =================================================================== --- trunk/model/AliasHandler.php 2012-04-08 23:18:29 UTC (rev 1355) +++ trunk/model/AliasHandler.php 2012-04-09 00:34:26 UTC (rev 1356) @@ -195,8 +195,12 @@ $this->errormsg[] = $old_ah->errormsg[0]; } else { $oldvalues = $old_ah->result(); - - if ($oldvalues['on_vacation']) { + + if (!isset($values['on_vacation'])) { # no new value given? + $values['on_vacation'] = $oldvalues['on_vacation']; + } + + if ($values['on_vacation']) { $vh = new VacationHandler($this->id); $values['goto'][] = $vh->getVacationAlias(); } @@ -209,7 +213,7 @@ $values['goto'][] = $this->id; # if the alias points to the mailbox, don't display the "empty goto" error message - if ($this->errormsg['goto'] == Lang::read('pEdit_alias_goto_text_error1') ) { + if (isset($this->errormsg['goto']) && $this->errormsg['goto'] == Lang::read('pEdit_alias_goto_text_error1') ) { unset($this->errormsg['goto']); } } @@ -240,7 +244,7 @@ $db_result[$key]['goto_mailbox'] = 0; } } -#print_r($db_result); exit; + return $db_result; } Modified: trunk/model/VacationHandler.php =================================================================== --- trunk/model/VacationHandler.php 2012-04-08 23:18:29 UTC (rev 1355) +++ trunk/model/VacationHandler.php 2012-04-09 00:34:26 UTC (rev 1356) @@ -5,6 +5,7 @@ protected $username = null; function __construct($username) { $this->username = $username; + $this->id = $username; } /** @@ -13,19 +14,7 @@ * @return boolean true on success. */ function remove() { - $ah = new AliasHandler(); - $ah->init($this->username); - $result = $ah->get(true); - if($result === true) { // fetch all # TODO check $result, error handling - $aliases = $ah->return; - $new_aliases = array(); - /* go through the user's aliases and remove any that look like a vacation address */ - foreach($aliases as $alias) { # TODO replace with (to be written) array_remove() - if(!$ah->is_vacation_address($alias)) { - $new_aliases[] = $alias; - } - } - $ah->update($new_aliases, '', false); # TODO: supress logging in AliasHandler if called from VacationHandler (VacationHandler should log itsself) + if (!$this->updateAlias(0)) return false; // tidy up vacation table. $vacation_data = array( @@ -36,8 +25,6 @@ # TODO db_log() call (maybe except if called from set_away?) /* crap error handling; oh for exceptions... */ return true; - } - return false; } /** @@ -54,18 +41,21 @@ * Why do we bother storing true/false in the vacation table if the alias dictates it anyway? */ function check_vacation() { - $ah = new AliasHandler(); - $ah->init($this->username); - $success = $ah->get(true); # fetch all. - if (!$success) { - return false; # TODO: error handling? + $handler = new AliasHandler(); + + if (!$handler->init($this->id)) { + # print_r($handler->errormsg); # TODO: error handling + return false; } - $aliases = $ah->result(); - foreach($aliases as $alias) { - if($ah->is_vacation_address($alias)) { - return true; - } + + if (!$handler->view()) { + # print_r($handler->errormsg); # TODO: error handling + return false; } + + $result = $handler->result(); + + if ($result['on_vacation']) return true; return false; } @@ -129,15 +119,42 @@ } # TODO error check # TODO wrap whole function in db_begin / db_commit (or rollback)? - $ah = new AliasHandler(); - $ah->init($this->username); - $alias = $ah->get(true); - $aliases = $ah->return; - $vacation_address = $this->getVacationAlias(); - $aliases[] = $vacation_address; - return $ah->update($aliases, '', false); + + return $this->updateAlias(1); } + /** + * add/remove the vacation alias + * @param int $vacationActive + */ + protected function updateAlias($vacationActive) { + $handler = new AliasHandler(); + + if (!$handler->init($this->id)) { + # print_r($handler->errormsg); # TODO: error handling + return false; + } + + $values = array ( + 'on_vacation' => $vacationActive, + ); + + if (!$handler->set($values)) { + # print_r($handler->errormsg); # TODO: error handling + return false; + } + + # TODO: supress logging in AliasHandler if called from VacationHandler (VacationHandler should log itsself) + + if (!$handler->store()) { + print_r($handler->errormsg); # TODO: error handling + return false; + } + + # still here? then everything worked + return true; + } + /** * Returns the vacation alias for this user. * i.e. if this user's username was ro...@ex..., and the autoreply domain was set to This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |