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)


git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1356 a1433add-5e2c-0410-b055-b7f2511e0802
pull/2/head
Christian Boltz 12 years ago
parent 54deb1fb23
commit e4d5d4574e

@ -80,9 +80,7 @@ if ($edit != "") {
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') {

@ -195,8 +195,12 @@ class AliasHandler extends PFAHandler {
$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 @@ class AliasHandler extends PFAHandler {
$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 @@ class AliasHandler extends PFAHandler {
$db_result[$key]['goto_mailbox'] = 0;
}
}
#print_r($db_result); exit;
return $db_result;
}

@ -5,6 +5,7 @@ class VacationHandler {
protected $username = null;
function __construct($username) {
$this->username = $username;
$this->id = $username;
}
/**
@ -13,19 +14,7 @@ class VacationHandler {
* @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 @@ class VacationHandler {
# 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 @@ class VacationHandler {
* 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,13 +119,40 @@ class VacationHandler {
}
# 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;
}
/**

Loading…
Cancel
Save