*fixed db_insert - duplicate $timestamp

*fixed VacationHandler.php
*changed edit-vacation to us VacationHandler
*added todopoint to upgrade.php
*fixed problem in AliasHandler


git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@981 a1433add-5e2c-0410-b055-b7f2511e0802
pull/2/head
Valkum 14 years ago
parent 8560012db8
commit 179f195bf1

@ -55,7 +55,7 @@ else {
$fUsername = $SESSID_USERNAME;
$fDomain = $USERID_DOMAIN;
}
$vh = new VacationHandler($fUsername);
$vacation_domain = $CONF['vacation_domain'];
$vacation_goto = preg_replace('/@/', '#', $fUsername);
$vacation_goto = $vacation_goto . '@' . $vacation_domain;
@ -85,7 +85,7 @@ if ($_SERVER['REQUEST_METHOD'] == "GET")
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$tSubject = safepost('fSubject');
$fSubject = escape_string ($tSubject);
$tBody = safepost('fBody');
@ -114,38 +114,10 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
if ($tBody == '') { $tBody = html_entity_decode($PALANG['pUsersVacation_body_text'], ENT_QUOTES, 'UTF-8'); }
//if change, remove old one, then perhaps set new one
if (!empty ($fBack) || !empty ($fChange))
if (!empty ($fBack))
{
//if we find an existing vacation entry, disable it
$result = db_query("SELECT * FROM $table_vacation WHERE email='$fUsername'");
if ($result['rows'] == 1)
{
$db_false = db_get_boolean(false);
// retain vacation message if possible - i.e disable vacation away-ness.
$result = db_query ("UPDATE $table_vacation SET active = '$db_false' WHERE email='$fUsername'");
$result = db_query("DELETE FROM $table_vacation_notification WHERE on_vacation='$fUsername'");
$result = db_query ("SELECT * FROM $table_alias WHERE address='$fUsername'");
if ($result['rows'] == 1)
{
$row = db_array ($result['result']);
$goto = $row['goto'];
//only one of these will do something, first handles address at beginning and middle, second at end
$goto= preg_replace ( "/$vacation_goto,/", '', $goto);
$goto= preg_replace ( "/,$vacation_goto/", '', $goto);
$goto= preg_replace ( "/$vacation_goto/", '', $goto);
if($goto == '') {
$sql = "DELETE FROM $table_alias WHERE address = '$fUsername'";
}
else {
$sql = "UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$fUsername'";
}
$result = db_query($sql);
if ($result['rows'] != 1)
{
$error = 1;
}
}
if(!$vh->remove()) {
$error = 1;
}
}
@ -153,42 +125,10 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
//Set the vacation data for $fUsername
if (!empty ($fChange))
{
$goto = '';
$result = db_query ("SELECT * FROM $table_alias WHERE address='$fUsername'");
if ($result['rows'] == 1)
{
$row = db_array ($result['result']);
$goto = $row['goto'];
}
$Active = db_get_boolean(True);
$notActive = db_get_boolean(False);
// I don't think we need to care if the vacation entry is inactive or active.. as long as we don't try and
// insert a duplicate
$result = db_query("SELECT * FROM $table_vacation WHERE email = '$fUsername'");
if($result['rows'] == 1) {
$result = db_query("UPDATE $table_vacation SET active = '$Active', subject = '$fSubject', body = '$fBody', created = NOW(), activefrom = '$tActiveFrom', activeuntil = '$tActiveUntil' WHERE email = '$fUsername'");
}
else {
$result = db_query ("INSERT INTO $table_vacation (email,subject,body,domain,created,active, activefrom, activeuntil) VALUES ('$fUsername','$fSubject','$fBody','$fDomain',NOW(),$Active, '$tActiveFrom', '$tActiveUntil')");
}
if ($result['rows'] != 1)
{
$error = 1;
}
if($goto == '') {
$goto = $vacation_goto;
$sql = "INSERT INTO $table_alias (goto, address, domain, modified, activefrom, activeuntil) VALUES ('$goto', '$fUsername', '$fDomain', NOW(), '$tActiveFrom', '$tActiveUntil')";
}
else {
$goto = $goto . "," . $vacation_goto;
$sql = "UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$fUsername'";
}
$result = db_query ($sql);
if ($result['rows'] != 1)
{
$error = 1;
}
if(!$vh->set_away($fSubject, $fBody, $tActiveFrom, $tActiveUntil)) {
$error = 1;
}
}
}

@ -1743,7 +1743,7 @@ function db_insert ($table, $values, $timestamp = array('created', 'modified') )
*/
function db_update ($table, $where_col, $where_value, $values, $timestamp = array('modified') ) {
$where = $where_col . " = '" . escape_string($where_value) . "'";
return db_update_q ($table, $where, $values, $timestamp = array('modified') );
return db_update_q ($table, $where, $values, $timestamp );
}
/**

@ -3,12 +3,18 @@
/**
* Handlers User level alias actions - e.g. add alias, get aliases, update etc.
* @property $username name of alias
* @property $return return of methods
*/
class AliasHandler {
private $username = null;
/**
*
* @public
*/
public $return = null;
/**
* @param string $username
@ -18,15 +24,15 @@ class AliasHandler {
}
/**
* @return array - list of email addresses the user's mail is forwarded to.
* @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) {
$username = escape_string($this->username);
$E_username = escape_string($this->username);
$table_alias = table_by_key('alias');
$sql = "SELECT * FROM $table_alias WHERE address='$username'";
$sql = "SELECT * FROM $table_alias WHERE address='$E_username'";
$result = db_query($sql);
if($result['rows'] != 1) {
return false;

@ -14,27 +14,29 @@ class VacationHandler {
*/
function remove() {
$ah = new AliasHandler($this->username);
$result = $ah->get(true); // fetch all # TODO check $result, error handling
$aliases = $ah->result;
$new_aliases = array();
$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()
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);
}
$ah->update($new_aliases, '', false);
// tidy up vacation table.
$vacation_data = array(
// tidy up vacation table.
$vacation_data = array(
'active' => db_get_boolean(false),
);
$result = db_update('vacation', 'email', $this->username, $vacation_data);
$result = db_delete('vacation_notification', 'on_vacation', $this->username);
);
$result = db_update('vacation', 'email', $this->username, $vacation_data, array());
$result = db_delete('vacation_notification', 'on_vacation', $this->username, array());
# TODO db_log() call (maybe except if called from set_away?)
/* crap error handling; oh for exceptions... */
return true;
/* crap error handling; oh for exceptions... */
return true;
}
return false;
}
/**
@ -115,14 +117,14 @@ class VacationHandler {
$table_vacation = table_by_key('vacation');
$result = db_query("SELECT * FROM $table_vacation WHERE email = '$E_username'");
if($result['rows'] == 1) {
$result = db_update('vacation', 'email', $this->username, $vacation_data);
$result = db_update('vacation', 'email', $this->username, $vacation_data, array());
} else {
$result = db_insert('vacation', $vacation_data);
$result = db_insert('vacation', $vacation_data, array());
}
# TODO error check
# TODO wrap whole function in db_begin / db_commit (or rollback)?
$ah = new AliasHandler($this->username);
$aliases = $ah->get(true);
$alias = $ah->get(true);
$vacation_address = $this->getVacationAlias();
$aliases[] = $vacation_address;
return $ah->update($aliases, '', false);

@ -1305,3 +1305,4 @@ function upgrade_968_pgsql() {
# including vacation.activefrom/activeuntil (might have a different default as leftover from upgrade_727_mysql)
# including vacation.modified - should be {DATE}, not {DATECURRENT}
# https://sourceforge.net/tracker/?func=detail&aid=1699218&group_id=191583&atid=937964
@todo vacation.email has 2 indizes
Loading…
Cancel
Save