@ -22,19 +22,23 @@
// fAway
// fBack
//
require ("../variables.inc.php");
require ("../config.inc.php");
require ("../functions.inc.php");
include ("../languages/" . check_language () . ".lang");
$USERID_USERNAME = check_user_session ();
(($CONF['vacation'] == 'NO') ? header("Location: " . $CONF['postfix_admin_url'] . "/users/main.php") & & exit : '1');
require_once('../common.php');
authentication_require_role('user');
$USERID_USERNAME = authentication_get_username();
// is vacation support enabled in $CONF ?
if($CONF['vacation'] == 'NO') {
header("Location: " . $CONF['postfix_admin_url'] . "/users/main.php");
exit(0);
}
$tmp = preg_split ('/@/', $USERID_USERNAME);
$USERID_DOMAIN = $tmp[1];
if ($_SERVER['REQUEST_METHOD'] == "GET")
{
$result = db_query("SELECT * FROM $table_vacation WHERE email='$USERID_USERNAME'");
if ($result['rows'] == 1)
{
@ -42,7 +46,6 @@ if ($_SERVER['REQUEST_METHOD'] == "GET")
$tMessage = $PALANG['pUsersVacation_welcome_text'];
$tSubject = $row['subject'];
$tBody = $row['body'];
}
if ($tSubject == '') { $tSubject = $PALANG['pUsersVacation_subject_text']; }
@ -58,7 +61,15 @@ if ($_SERVER['REQUEST_METHOD'] == "GET")
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
if(isset($_POST['fCancel'])) {
header("Location: main.php");
exit(0);
}
// We store goto addresses in the form of roger#example.com@autoreply.example.com
$vacation_domain = $CONF['vacation_domain'];
$vacation_goto = preg_replace('/@/', '#', $USERID_USERNAME);
$vacation_goto = "{$vacation_goto}@{$vacation_domain}";
if (isset ($_POST['fSubject'])) $fSubject = escape_string ($_POST['fSubject']);
if (isset ($_POST['fBody'])) $fBody = escape_string ($_POST['fBody']);
@ -69,6 +80,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
if ($tSubject == '') { $tSubject = $PALANG['pUsersVacation_subject_text']; }
if ($tBody == '') { $tBody = $PALANG['pUsersVacation_body_text']; }
// if they've set themselves away OR back, delete any record of vacation emails etc
if (!empty ($fBack) || !empty ($fAway))
{
$result = db_query ("DELETE FROM $table_vacation WHERE email='$USERID_USERNAME'");
@ -89,8 +101,8 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
$tGoto = $row['goto'];
//only one of these will do something, first handles address at beginning and middle, second at end
$goto= preg_replace ( "/$USERID_USERNAME@$vacation_domain ,/", '', $tGoto);
$goto= preg_replace ( "/,$USERID_USERNAME@$vacation_domain/", '', $g oto);
$goto= preg_replace ( "/$vacation_goto ,/", '', $tGoto);
$goto= preg_replace ( "/,$vacation_goto/", '', $tG oto);
}
@ -107,8 +119,10 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
}
// the user is going away - set the goto alias and vacation table as necessary.
if (!empty ($fAway))
{
// Can we ever have no alias records for a user?
$result = db_query ("SELECT * FROM $table_alias WHERE address='$USERID_USERNAME'");
if ($result['rows'] == 1)
{
@ -123,8 +137,8 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
$error = 1;
$tMessage = $PALANG['pUsersVacation_result_error'];
}
$goto = $tGoto . "," . "$USERID_USERNAME@$vacation_domain" ;
// add the goto record back in...
$goto = $tGoto . "," . $vacation_goto ;
$result = db_query ("UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$USERID_USERNAME'");
if ($result['rows'] != 1)