SF.net SVN: postfixadmin: [297] trunk
Brought to you by:
christian_boltz,
gingerdog
From: <Gin...@us...> - 2008-01-19 16:48:09
|
Revision: 297 http://postfixadmin.svn.sourceforge.net/postfixadmin/?rev=297&view=rev Author: GingerDog Date: 2008-01-19 08:48:15 -0800 (Sat, 19 Jan 2008) Log Message: ----------- vacation: maintain away message after coming back for next time Modified Paths: -------------- trunk/edit-vacation.php trunk/users/vacation.php Modified: trunk/edit-vacation.php =================================================================== --- trunk/edit-vacation.php 2008-01-19 16:47:27 UTC (rev 296) +++ trunk/edit-vacation.php 2008-01-19 16:48:15 UTC (rev 297) @@ -84,10 +84,10 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") { - $tSubject = safepost('fSubject'); - $fSubject = escape_string ( $tSubject); - $tBody = safepost('fBody'); - $fBody = escape_string ( $tBody); + $tSubject = safepost('fSubject'); + $fSubject = escape_string ($tSubject); + $tBody = safepost('fBody'); + $fBody = escape_string ($tBody); $fChange = escape_string (safepost('fChange')); $fBack = escape_string (safepost('fBack')); @@ -111,15 +111,13 @@ //if change, remove old one, then perhaps set new one if (!empty ($fBack) || !empty ($fChange)) { - //if we find an existing vacation entry, delete it + //if we find an existing vacation entry, disable it $result = db_query("SELECT * FROM $table_vacation WHERE email='$fUsername'"); if ($result['rows'] == 1) { - $result = db_query ("DELETE FROM $table_vacation WHERE email='$fUsername'"); - if ($result['rows'] != 1) - { - $error = 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 ("SELECT * FROM $table_alias WHERE address='$fUsername'"); if ($result['rows'] == 1) @@ -157,7 +155,16 @@ $goto = $row['goto']; } $Active = db_get_boolean(True); - $result = db_query ("INSERT INTO $table_vacation (email,subject,body,domain,created,active) VALUES ('$fUsername','$fSubject','$fBody','$fDomain',NOW(),$Active)"); + $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, created = NOW() WHERE email = '$fUsername'"); + } + else { + $result = db_query ("INSERT INTO $table_vacation (email,subject,body,domain,created,active) VALUES ('$fUsername','$fSubject','$fBody','$fDomain',NOW(),$Active)"); + } if ($result['rows'] != 1) { Modified: trunk/users/vacation.php =================================================================== --- trunk/users/vacation.php 2008-01-19 16:47:27 UTC (rev 296) +++ trunk/users/vacation.php 2008-01-19 16:48:15 UTC (rev 297) @@ -84,17 +84,11 @@ // if they've set themselves away OR back, delete any record of vacation emails. if (!empty ($fBack) || !empty ($fAway)) { - $result = db_query ("DELETE FROM $table_vacation WHERE email='$USERID_USERNAME'"); - $result2 = db_query ("DELETE FROM $table_vacation_notification WHERE on_vacation='$USERID_USERNAME'"); - if ($result['rows'] != 1) - { - $error = 1; - $tMessage = $PALANG['pUsersVacation_result_error']; - } - else - { - $tMessage = $PALANG['pUsersVacation_result_success']; - } + $notActive = db_get_boolean(False); + // this isn't very good, as $result['rows'] would be 0 if the user had not used vacation stuff before. + $result = db_query("UPDATE $table_vacation SET active = $notActive WHERE email='$USERID_USERNAME'"); + $result = db_query("DELETE FROM $table_vacation_notification WHERE on_vacation='$USERID_USERNAME'"); + $tMessage = $PALANG['pUsersVacation_result_error']; // We need to see whether there is already an alias record for the user, or not. // If not, we create one, else update the existing one. @@ -146,7 +140,14 @@ $tGoto = $row['goto']; } $Active = db_get_boolean(True); - $result = db_query ("INSERT INTO $table_vacation (email,subject,body,domain,created,active) VALUES ('$USERID_USERNAME','$fSubject','$fBody','$USERID_DOMAIN',NOW(),$Active)"); + $result = db_query("SELECT * FROM $table_vacation WHERE email = '$USERID_USERNAME'"); + if($result['rows'] == 1) { + $result = db_query("UPDATE $table_vacation SET active = $Active, body = '$fBody', subject = '$fSubject', created = NOW() WHERE email = '$USERID_USERNAME'"); + } + else { + $result = db_query ("INSERT INTO $table_vacation (email,subject,body,domain,created,active) VALUES ('$USERID_USERNAME','$fSubject','$fBody','$USERID_DOMAIN',NOW(),$Active)"); + } + if ($result['rows'] != 1) { $error = 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |