SF.net SVN: postfixadmin:[981] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <va...@us...> - 2011-03-06 02:14:16
|
Revision: 981 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=981&view=rev Author: valkum Date: 2011-03-06 02:14:10 +0000 (Sun, 06 Mar 2011) Log Message: ----------- *fixed db_insert - duplicate $timestamp *fixed VacationHandler.php *changed edit-vacation to us VacationHandler *added todopoint to upgrade.php *fixed problem in AliasHandler Modified Paths: -------------- trunk/edit-vacation.php trunk/functions.inc.php trunk/model/AliasHandler.php trunk/model/VacationHandler.php trunk/upgrade.php Modified: trunk/edit-vacation.php =================================================================== --- trunk/edit-vacation.php 2011-03-03 20:57:08 UTC (rev 980) +++ trunk/edit-vacation.php 2011-03-06 02:14:10 UTC (rev 981) @@ -55,7 +55,7 @@ $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'] == "POST") { - + $tSubject = safepost('fSubject'); $fSubject = escape_string ($tSubject); $tBody = safepost('fBody'); @@ -114,38 +114,10 @@ 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 @@ //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; + } + } } Modified: trunk/functions.inc.php =================================================================== --- trunk/functions.inc.php 2011-03-03 20:57:08 UTC (rev 980) +++ trunk/functions.inc.php 2011-03-06 02:14:10 UTC (rev 981) @@ -1743,7 +1743,7 @@ */ 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 ); } /** Modified: trunk/model/AliasHandler.php =================================================================== --- trunk/model/AliasHandler.php 2011-03-03 20:57:08 UTC (rev 980) +++ trunk/model/AliasHandler.php 2011-03-06 02:14:10 UTC (rev 981) @@ -3,13 +3,19 @@ /** * 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 @@ } /** - * @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; Modified: trunk/model/VacationHandler.php =================================================================== --- trunk/model/VacationHandler.php 2011-03-03 20:57:08 UTC (rev 980) +++ trunk/model/VacationHandler.php 2011-03-06 02:14:10 UTC (rev 981) @@ -14,27 +14,29 @@ */ 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 @@ $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); Modified: trunk/upgrade.php =================================================================== --- trunk/upgrade.php 2011-03-03 20:57:08 UTC (rev 980) +++ trunk/upgrade.php 2011-03-06 02:14:10 UTC (rev 981) @@ -1305,3 +1305,4 @@ # 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 \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |