@ -22,126 +22,140 @@
// fAway
// fAway
// fBack
// fBack
//
//
require ("../variables.inc.php");
require ("../config.inc.php");
require ("../functions.inc.php");
include ("../languages/" . check_language () . ".lang");
$USERID_USERNAME = check_user_session ();
require_once('../common.php');
(($CONF['vacation'] == 'NO') ? header("Location: " . $CONF['postfix_admin_url'] . "/users/main.php") & & exit : '1');
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);
$tmp = preg_split ('/@/', $USERID_USERNAME);
$USERID_DOMAIN = $tmp[1];
$USERID_DOMAIN = $tmp[1];
if ($_SERVER['REQUEST_METHOD'] == "GET")
if ($_SERVER['REQUEST_METHOD'] == "GET")
{
{
$result = db_query("SELECT * FROM $table_vacation WHERE email='$USERID_USERNAME'");
$result = db_query("SELECT * FROM $table_vacation WHERE email='$USERID_USERNAME'");
if ($result['rows'] == 1)
if ($result['rows'] == 1)
{
{
$row = db_array($result['result']);
$row = db_array($result['result']);
$tMessage = $PALANG['pUsersVacation_welcome_text'];
$tMessage = $PALANG['pUsersVacation_welcome_text'];
$tSubject = $row['subject'];
$tSubject = $row['subject'];
$tBody = $row['body'];
$tBody = $row['body'];
}
}
if ($tSubject == '') { $tSubject = $PALANG['pUsersVacation_subject_text']; }
if ($tBody == '') { $tBody = $PALANG['pUsersVacation_body_text']; }
if ($tSubject == '') { $tSubject = $PALANG['pUsersVacation_subject_text']; }
if ($tBody == '') { $tBody = $PALANG['pUsersVacation_body_text']; }
$template = "users_vacation.tpl";
$template = "users_vacation.tpl";
include ("../templates/header.tpl");
include ("../templates/users_menu.tpl");
include ("../templates/header.tpl");
include ("../templates/users_vacation.tpl");
include ("../templates/users_menu.tpl");
include ("../templates/footer.tpl");
include ("../templates/users_vacation.tpl");
include ("../templates/footer.tpl");
}
}
if ($_SERVER['REQUEST_METHOD'] == "POST")
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
{
$vacation_domain = $CONF['vacation_domain'];
if(isset($_POST['fCancel'])) {
header("Location: main.php");
if (isset ($_POST['fSubject'])) $fSubject = escape_string ($_POST['fSubject']);
exit(0);
if (isset ($_POST['fBody'])) $fBody = escape_string ($_POST['fBody']);
}
if (isset ($_POST['fAway'])) $fAway = escape_string ($_POST['fAway']);
if (isset ($_POST['fBack'])) $fBack = escape_string ($_POST['fBack']);
// We store goto addresses in the form of roger#example.com@autoreply.example.com
$vacation_domain = $CONF['vacation_domain'];
//set a default, reset fields for coming back selection
$vacation_goto = preg_replace('/@/', '#', $USERID_USERNAME);
if ($tSubject == '') { $tSubject = $PALANG['pUsersVacation_subject_text']; }
$vacation_goto = "{$vacation_goto}@{$vacation_domain}";
if ($tBody == '') { $tBody = $PALANG['pUsersVacation_body_text']; }
if (isset ($_POST['fSubject'])) $fSubject = escape_string ($_POST['fSubject']);
if (!empty ($fBack) || !empty ($fAway))
if (isset ($_POST['fBody'])) $fBody = escape_string ($_POST['fBody']);
{
if (isset ($_POST['fAway'])) $fAway = escape_string ($_POST['fAway']);
$result = db_query ("DELETE FROM $table_vacation WHERE email='$USERID_USERNAME'");
if (isset ($_POST['fBack'])) $fBack = escape_string ($_POST['fBack']);
if ($result['rows'] != 1)
{
//set a default, reset fields for coming back selection
$error = 1;
if ($tSubject == '') { $tSubject = $PALANG['pUsersVacation_subject_text']; }
$tMessage = $PALANG['pUsersVacation_result_error'];
if ($tBody == '') { $tBody = $PALANG['pUsersVacation_body_text']; }
}
else
// if they've set themselves away OR back, delete any record of vacation emails etc
{
if (!empty ($fBack) || !empty ($fAway))
$tMessage = $PALANG['pUsersVacation_result_succes'];
{
}
$result = db_query ("DELETE FROM $table_vacation WHERE email='$USERID_USERNAME'");
if ($result['rows'] != 1)
$result = db_query ("SELECT * FROM $table_alias WHERE address='$USERID_USERNAME'");
{
if ($result['rows'] == 1)
$error = 1;
{
$tMessage = $PALANG['pUsersVacation_result_error'];
$row = db_array ($result['result']);
}
$tGoto = $row['goto'];
else
{
//only one of these will do something, first handles address at beginning and middle, second at end
$tMessage = $PALANG['pUsersVacation_result_succes'];
$goto= preg_replace ( "/$USERID_USERNAME@$vacation_domain,/", '', $tGoto);
}
$goto= preg_replace ( "/,$USERID_USERNAME@$vacation_domain/", '', $goto);
$result = db_query ("SELECT * FROM $table_alias WHERE address='$USERID_USERNAME'");
}
if ($result['rows'] == 1)
{
$result = db_query ("UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$USERID_USERNAME'");
$row = db_array ($result['result']);
if ($result['rows'] != 1)
$tGoto = $row['goto'];
{
$error = 1;
//only one of these will do something, first handles address at beginning and middle, second at end
$tMessage = $PALANG['pUsersVacation_result_error'];
$goto= preg_replace ( "/$vacation_goto,/", '', $tGoto);
}
$goto= preg_replace ( "/,$vacation_goto/", '', $tGoto);
else
{
}
$tMessage = $PALANG['pUsersVacation_result_succes'];
}
$result = db_query ("UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$USERID_USERNAME'");
if ($result['rows'] != 1)
}
{
$error = 1;
if (!empty ($fAway))
$tMessage = $PALANG['pUsersVacation_result_error'];
{
}
$result = db_query ("SELECT * FROM $table_alias WHERE address='$USERID_USERNAME'");
else
if ($result['rows'] == 1)
{
{
$tMessage = $PALANG['pUsersVacation_result_succes'];
$row = db_array ($result['result']);
}
$tGoto = $row['goto'];
}
}
($CONF['database_type']=='pgsql') ? $Active='true' : $Active=1;
// the user is going away - set the goto alias and vacation table as necessary.
$result = db_query ("INSERT INTO $table_vacation (email,subject,body,domain,created,active) VALUES ('$USERID_USERNAME','$fSubject','$fBody','$USERID_DOMAIN',NOW(),$Active)");
if (!empty ($fAway))
if ($result['rows'] != 1)
{
{
// Can we ever have no alias records for a user?
$error = 1;
$result = db_query ("SELECT * FROM $table_alias WHERE address='$USERID_USERNAME'");
$tMessage = $PALANG['pUsersVacation_result_error'];
if ($result['rows'] == 1)
}
{
$row = db_array ($result['result']);
$goto = $tGoto . "," . "$USERID_USERNAME@$vacation_domain";
$tGoto = $row['goto'];
}
$result = db_query ("UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$USERID_USERNAME'");
if ($result['rows'] != 1)
($CONF['database_type']=='pgsql') ? $Active='true' : $Active=1;
{
$result = db_query ("INSERT INTO $table_vacation (email,subject,body,domain,created,active) VALUES ('$USERID_USERNAME','$fSubject','$fBody','$USERID_DOMAIN',NOW(),$Active)");
$error = 1;
if ($result['rows'] != 1)
$tMessage = $PALANG['pUsersVacation_result_error'];
{
}
$error = 1;
else
$tMessage = $PALANG['pUsersVacation_result_error'];
{
}
header ("Location: main.php");
// add the goto record back in...
exit;
$goto = $tGoto . "," . $vacation_goto;
}
}
$result = db_query ("UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$USERID_USERNAME'");
if ($result['rows'] != 1)
include ("../templates/header.tpl");
{
include ("../templates/users_menu.tpl");
$error = 1;
include ("../templates/users_vacation.tpl");
$tMessage = $PALANG['pUsersVacation_result_error'];
include ("../templates/footer.tpl");
}
else
{
header ("Location: main.php");
exit;
}
}
include ("../templates/header.tpl");
include ("../templates/users_menu.tpl");
include ("../templates/users_vacation.tpl");
include ("../templates/footer.tpl");
}
}
?>
?>