From a633bd371c4bb23939f026659b4c41994e5fadd6 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Sat, 19 Jan 2008 16:48:15 +0000 Subject: [PATCH] vacation: maintain away message after coming back for next time git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@297 a1433add-5e2c-0410-b055-b7f2511e0802 --- edit-vacation.php | 29 ++++++++++++++++++----------- users/vacation.php | 25 +++++++++++++------------ 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/edit-vacation.php b/edit-vacation.php index d42dcb29..087952a2 100644 --- a/edit-vacation.php +++ b/edit-vacation.php @@ -84,10 +84,10 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") 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 ($_SERVER['REQUEST_METHOD'] == "POST") //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 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") $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) { diff --git a/users/vacation.php b/users/vacation.php index f73e9875..15aee615 100644 --- a/users/vacation.php +++ b/users/vacation.php @@ -84,17 +84,11 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") // 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 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") $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;