admin/*, users/* - code refactoring

git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@67 a1433add-5e2c-0410-b055-b7f2511e0802
postfixadmin-2.3
David Goodwin 17 years ago
parent 68511080ff
commit cf5b117aa5

@ -17,12 +17,11 @@
//
// -none-
//
require ("../config.inc.php");
require ("../functions.inc.php");
include ("../languages/" . check_language () . ".lang");
$SESSID_USERNAME = check_session ();
(!check_admin($SESSID_USERNAME) ? header("Location: " . $CONF['postfix_admin_url'] . "/main.php") && exit : '1');
require_once('../common.php');
authentication_require_role('global-admin');
(($CONF['backup'] == 'NO') ? header("Location: " . $CONF['postfix_admin_url'] . "/main.php") && exit : '1');
// TODO: make backup supported for postgres

@ -20,13 +20,12 @@
// b_message
//
//
require ("../variables.inc.php");
require ("../config.inc.php");
require ("../functions.inc.php");
include ("../languages/" . check_language () . ".lang");
$SESSID_USERNAME = check_session ();
(!check_admin($SESSID_USERNAME) ? header("Location: " . $CONF['postfix_admin_url'] . "/main.php") && exit : '1');
require_once('../common.php');
authentication_require_role('global-admin');
$SESSID_USERNAME = authentication_get_username();
if ($_SERVER['REQUEST_METHOD'] == "POST")
{

@ -23,13 +23,10 @@
// fPassword2
// fDomains
//
require ("../variables.inc.php");
require ("../config.inc.php");
require ("../functions.inc.php");
include ("../languages/" . check_language () . ".lang");
$SESSID_USERNAME = check_session ();
(!check_admin($SESSID_USERNAME) ? header("Location: " . $CONF['postfix_admin_url'] . "/main.php") && exit : '1');
require_once('../common.php');
authentication_require_role('global-admin');
$list_domains = list_domains ();
$tDomains = array();

@ -23,7 +23,6 @@
// fDomain
//
$incpath = '..';
require ("../create-alias.php");
?>

@ -28,13 +28,11 @@
// fMaxquota
// fDefaultaliases
//
require ("../variables.inc.php");
require ("../config.inc.php");
require ("../functions.inc.php");
include ("../languages/" . check_language () . ".lang");
$SESSID_USERNAME = check_session ();
(!check_admin($SESSID_USERNAME) ? header("Location: " . $CONF['postfix_admin_url'] . "/main.php") && exit : '1');
require_once('../common.php');
authentication_require_role('global-admin');
if ($_SERVER['REQUEST_METHOD'] == "GET")
{

@ -29,7 +29,6 @@
// fMail
//
$incpath = '..';
require ("../create-mailbox.php");
/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */

@ -20,13 +20,10 @@
// fDelete
// fDomain
//
require ("../variables.inc.php");
require ("../config.inc.php");
require ("../functions.inc.php");
include ("../languages/" . check_language () . ".lang");
$SESSID_USERNAME = check_session ();
(!check_admin($SESSID_USERNAME) ? header("Location: " . $CONF['postfix_admin_url'] . "/main.php") && exit : '1');
require_once('../common.php');
authentication_require_role('global-admin');
if ($_SERVER['REQUEST_METHOD'] == "GET")
{

@ -17,13 +17,10 @@
//
// fUsername
//
require ("../variables.inc.php");
require ("../config.inc.php");
require ("../functions.inc.php");
include ("../languages/" . check_language () . ".lang");
$SESSID_USERNAME = check_session ();
(!check_admin($SESSID_USERNAME) ? header("Location: " . $CONF['postfix_admin_url'] . "/main.php") && exit : '1');
require_once('../common.php');
authentication_require_role('global-admin');
if ($_SERVER['REQUEST_METHOD'] == "GET")
{

@ -17,13 +17,10 @@
//
// fDomain
//
require ("../variables.inc.php");
require ("../config.inc.php");
require ("../functions.inc.php");
include ("../languages/" . check_language () . ".lang");
$SESSID_USERNAME = check_session ();
(!check_admin($SESSID_USERNAME) ? header("Location: " . $CONF['postfix_admin_url'] . "/main.php") && exit : '1');
require_once('../common.php');
authentication_require_role('global-admin');
if ($_SERVER['REQUEST_METHOD'] == "GET")
{

@ -19,7 +19,6 @@
// fDomain
//
$incpath = "..";
require("../edit-active.php");
/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */

@ -25,13 +25,10 @@
// fMaxquota
// fActive
//
require ("../variables.inc.php");
require ("../config.inc.php");
require ("../functions.inc.php");
include ("../languages/" . check_language () . ".lang");
$SESSID_USERNAME = check_session ();
(!check_admin($SESSID_USERNAME) ? header("Location: " . $CONF['postfix_admin_url'] . "/main.php") && exit : '1');
require_once('../common.php');
authentication_require_role('global-admin');
if ($_SERVER['REQUEST_METHOD'] == "GET")
{

@ -21,7 +21,6 @@
// fGoto
//
$incpath = "..";
require("../edit-alias.php");
?>

@ -25,13 +25,10 @@
// fMaxquota
// fActive
//
require ("../variables.inc.php");
require ("../config.inc.php");
require ("../functions.inc.php");
include ("../languages/" . check_language () . ".lang");
$SESSID_USERNAME = check_session ();
(!check_admin($SESSID_USERNAME) ? header("Location: " . $CONF['postfix_admin_url'] . "/main.php") && exit : '1');
require_once('../common.php');
authentication_require_role('global-admin');
if ($_SERVER['REQUEST_METHOD'] == "GET")
{

@ -26,7 +26,6 @@
// fActive
//
$incpath = "..";
require("../edit-mailbox.php");
/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */

@ -27,7 +27,6 @@
//
//
$incpath = '..';
require ("../edit-vacation.php");
?>

@ -18,5 +18,5 @@
// -none-
//
header ("Location: list-admin.php");
exit;
exit(0);
?>

@ -17,13 +17,10 @@
//
// -none-
//
require ("../variables.inc.php");
require ("../config.inc.php");
require ("../functions.inc.php");
include ("../languages/" . check_language () . ".lang");
$SESSID_USERNAME = check_session ();
(!check_admin($SESSID_USERNAME) ? header("Location: " . $CONF['postfix_admin_url'] . "/main.php") && exit : '1');
require_once("../common.php");
authentication_require_role('global-admin');
$list_admins = list_admins ();
if ((is_array ($list_admins) and sizeof ($list_admins) > 0))

@ -17,13 +17,10 @@
//
// fUsername
//
require ("../variables.inc.php");
require ("../config.inc.php");
require ("../functions.inc.php");
include ("../languages/" . check_language () . ".lang");
$SESSID_USERNAME = check_session ();
(!check_admin($SESSID_USERNAME) ? header("Location: " . $CONF['postfix_admin_url'] . "/main.php") && exit : '1');
require_once('../common.php');
authentication_require_role('global-admin');
$list_admins = list_admins ();

@ -20,13 +20,10 @@
// fDomain
// fDisplay
//
require ("../variables.inc.php");
require ("../config.inc.php");
require ("../functions.inc.php");
include ("../languages/" . check_language () . ".lang");
$SESSID_USERNAME = check_session ();
(!check_admin($SESSID_USERNAME) ? header("Location: " . $CONF['postfix_admin_url'] . "/main.php") && exit : '1');
require_once('../common.php');
authentication_require_role('global-admin');
$list_domains = list_domains ();
@ -79,7 +76,6 @@ if ($CONF['vacation_control_admin'] == 'YES')
$query = ("SELECT $table_mailbox.*, $table_vacation.active AS v_active FROM $table_mailbox LEFT JOIN $table_vacation ON $table_mailbox.username=$table_vacation.email WHERE $table_mailbox.domain='$fDomain' ORDER BY $table_mailbox.username LIMIT $fDisplay, $page_size");
if ('pgsql'==$CONF['database_type'])
{
//FIXME: postgres query needs to be rewrited
$query = "SELECT *,extract(epoch from created) as uts_created,extract(epoch from modified) as uts_modified FROM $table_mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $page_size OFFSET $fDisplay";
}
}

@ -20,13 +20,10 @@
// fDomain
// fGo
//
require ("../variables.inc.php");
require ("../config.inc.php");
require ("../functions.inc.php");
include ("../languages/" . check_language () . ".lang");
$SESSID_USERNAME = check_session ();
(!check_admin($SESSID_USERNAME) ? header("Location: " . $CONF['postfix_admin_url'] . "/main.php") && exit : '1');
require_once('../common.php');
authentication_require_role('global-admin');
$tAlias = array();
$tMailbox = array();

@ -19,7 +19,6 @@
// fDomain
//
$incpath = "..";
require("../viewlog.php");
/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */

@ -20,107 +20,111 @@
// fDomain
// fGoto
//
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');
authentication_require_role('user');
$USERID_USERNAME = authentication_get_username();
$tmp = preg_split ('/@/', $USERID_USERNAME);
$USERID_DOMAIN = $tmp[1];
$vacation_domain = $CONF['vacation_domain'];
$vacation_goto = preg_replace('/@/', '#', $USERID_USERNAME) . '@' . $vacation_domain;
if ($_SERVER['REQUEST_METHOD'] == "GET")
{
$vacation_domain = $CONF['vacation_domain'];
$result = db_query ("SELECT * FROM $table_alias WHERE address='$USERID_USERNAME'");
if ($result['rows'] == 1)
{
$row = db_array ($result['result']);
$tGoto = $row['goto'];
}
else
{
$tMessage = $PALANG['pEdit_alias_address_error'];
}
include ("../templates/header.tpl");
include ("../templates/users_menu.tpl");
include ("../templates/users_edit-alias.tpl");
include ("../templates/footer.tpl");
$vacation_domain = $CONF['vacation_domain'];
$result = db_query ("SELECT * FROM $table_alias WHERE address='$USERID_USERNAME'");
if ($result['rows'] == 1)
{
$row = db_array ($result['result']);
$tGoto = $row['goto'];
}
else
{
$tMessage = $PALANG['pEdit_alias_address_error'];
}
include ("../templates/header.tpl");
include ("../templates/users_menu.tpl");
include ("../templates/users_edit-alias.tpl");
include ("../templates/footer.tpl");
}
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$vacation_domain = $CONF['vacation_domain'];
$pEdit_alias_goto = $PALANG['pEdit_alias_goto'];
if (isset ($_POST['fVacation'])) $fVacation = $_POST['fVacation'];
if (isset ($_POST['fGoto'])) $fGoto = escape_string ($_POST['fGoto']);
if (isset ($_POST['fForward_and_store'])) $fForward_and_store = escape_string ($_POST['fForward_and_store']);
$goto = strtolower ($fGoto);
$goto = preg_replace ('/\\\r\\\n/', ',', $goto);
$goto = preg_replace ('/\r\n/', ',', $goto);
$goto = preg_replace ('/[\s]+/i', '', $goto);
$goto = preg_replace ('/\,*$/', '', $goto);
( $fForward_and_store == "YES" ) ? $goto = $USERID_USERNAME . "," . $goto : '';
$goto = explode(",",$goto);
$goto = array_merge(array_unique($goto));
$goto = implode(",",$goto);
$array = preg_split ('/,/', $goto);
for ($i = 0; $i < sizeof ($array); $i++) {
if (in_array ("$array[$i]", $CONF['default_aliases'])) continue;
if (empty ($array[$i]) && $fForward_and_store == "NO")
{
$error = 1;
$tGoto = $goto;
$tMessage = $PALANG['pEdit_alias_goto_text_error1'];
}
if (empty ($array[$i])) continue;
if (!check_email ($array[$i]))
{
$error = 1;
$tGoto = $goto;
$tMessage = $PALANG['pEdit_alias_goto_text_error2'] . "$array[$i]</font>";
}
}
if ($error != 1)
{
if (empty ($goto))
{
$goto = $USERID_USERNAME;
}
/* else
{
$goto = $USERID_USERNAME . "," . $goto;
}*/
if ($fVacation == "YES")
{
$goto .= "," . $USERID_USERNAME . "@" . $vacation_domain;
}
$result = db_query ("UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$USERID_USERNAME'");
if ($result['rows'] != 1)
{
$tMessage = $PALANG['pEdit_alias_result_error'];
}
else
{
db_log ($USERID_USERNAME, $USERID_DOMAIN, "edit alias", "$USERID_USERNAME -> $goto");
header ("Location: main.php");
exit;
}
}
include ("../templates/header.tpl");
include ("../templates/users_menu.tpl");
include ("../templates/users_edit-alias.tpl");
include ("../templates/footer.tpl");
// user clicked on cancel button
if(isset($_POST['fCancel'])) {
header("Location: main.php");
exit(0);
}
$pEdit_alias_goto = $PALANG['pEdit_alias_goto'];
if (isset ($_POST['fVacation'])) $fVacation = $_POST['fVacation'];
if (isset ($_POST['fGoto'])) $fGoto = escape_string ($_POST['fGoto']);
if (isset ($_POST['fForward_and_store'])) $fForward_and_store = escape_string ($_POST['fForward_and_store']);
$goto = strtolower ($fGoto);
$goto = preg_replace ('/\\\r\\\n/', ',', $goto);
$goto = preg_replace ('/\r\n/', ',', $goto);
$goto = preg_replace ('/[\s]+/i', '', $goto);
$goto = preg_replace ('/\,*$/', '', $goto);
( $fForward_and_store == "YES" ) ? $goto = $USERID_USERNAME . "," . $goto : '';
$goto = explode(",",$goto);
$goto = array_merge(array_unique($goto));
$goto = implode(",",$goto);
$array = preg_split ('/,/', $goto);
for ($i = 0; $i < sizeof ($array); $i++) {
if (in_array ("$array[$i]", $CONF['default_aliases'])) continue;
if (empty ($array[$i]) && $fForward_and_store == "NO")
{
$error = 1;
$tGoto = $goto;
$tMessage = $PALANG['pEdit_alias_goto_text_error1'];
}
if (empty ($array[$i])) continue;
if (!check_email ($array[$i]))
{
$error = 1;
$tGoto = $goto;
$tMessage = $PALANG['pEdit_alias_goto_text_error2'] . "$array[$i]</font>";
}
}
if ($error != 1)
{
if (empty ($goto))
{
$goto = $USERID_USERNAME;
}
if ($fVacation == "YES")
{
$goto .= "," . $vacation_goto;
}
$result = db_query ("UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$USERID_USERNAME'");
if ($result['rows'] != 1)
{
$tMessage = $PALANG['pEdit_alias_result_error'];
}
else
{
db_log ($USERID_USERNAME, $USERID_DOMAIN, "edit alias", "$USERID_USERNAME -> $goto");
header ("Location: main.php");
exit;
}
}
include ("../templates/header.tpl");
include ("../templates/users_menu.tpl");
include ("../templates/users_edit-alias.tpl");
include ("../templates/footer.tpl");
}
?>

@ -19,11 +19,10 @@
// fUsername
// fPassword
//
require ("../variables.inc.php");
require ("../config.inc.php");
require ("../functions.inc.php");
include ("../languages/" . check_language () . ".lang");
require_once("../common.php");
if ($_SERVER['REQUEST_METHOD'] == "GET")
{
include ("../templates/header.tpl");
@ -68,10 +67,11 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
if ($error != 1)
{
session_start();
session_register("userid");
$_SESSION['userid']['username'] = $fUsername;
session_regenerate_id();
$_SESSION['sessid'] = array();
$_SESSION['sessid']['roles'] = array();
$_SESSION['sessid']['roles'][] = 'user';
$_SESSION['sessid']['username'] = $fUsername;
header("Location: main.php");
exit;
}

@ -17,10 +17,8 @@
//
// -none-
//
require ("../config.inc.php");
require ("../functions.inc.php");
$USERID_USERNAME = check_user_session ();
require_once('../common.php');
session_unset ();
session_destroy ();

@ -17,11 +17,11 @@
//
// -none-
//
require ("../config.inc.php");
require ("../functions.inc.php");
include ("../languages/" . check_language () . ".lang");
$USERID_USERNAME = check_user_session ();
require_once('../common.php');
authentication_require_role('user');
$USERID_USERNAME = authentication_get_username();
$result = db_query("SELECT * FROM $table_vacation WHERE email='$USERID_USERNAME'");
if ($result['rows'] == 1)
{

@ -19,74 +19,74 @@
// fPassword
// fPassword2
//
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');
authentication_require_role('user');
$USERID_USERNAME = authentication_get_username();
$tmp = preg_split ('/@/', $USERID_USERNAME);
$USERID_DOMAIN = $tmp[1];
if ($_SERVER['REQUEST_METHOD'] == "GET")
{
include ("../templates/header.tpl");
include ("../templates/users_menu.tpl");
include ("../templates/users_password.tpl");
include ("../templates/footer.tpl");
include ("../templates/header.tpl");
include ("../templates/users_menu.tpl");
include ("../templates/users_password.tpl");
include ("../templates/footer.tpl");
}
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$fPassword_current = escape_string ($_POST['fPassword_current']);
$fPassword = escape_string ($_POST['fPassword']);
$fPassword2 = escape_string ($_POST['fPassword2']);
$fPassword_current = escape_string ($_POST['fPassword_current']);
$fPassword = escape_string ($_POST['fPassword']);
$fPassword2 = escape_string ($_POST['fPassword2']);
$username = $USERID_USERNAME;
$result = db_query ("SELECT * FROM $table_mailbox WHERE username='$username'");
if ($result['rows'] == 1)
{
$row = db_array ($result['result']);
$checked_password = pacrypt ($fPassword_current, $row['password']);
$username = $USERID_USERNAME;
$result = db_query ("SELECT * FROM $table_mailbox WHERE username='$username'");
if ($result['rows'] == 1)
{
$row = db_array ($result['result']);
$checked_password = pacrypt ($fPassword_current, $row['password']);
$result = db_query ("SELECT * FROM $table_mailbox WHERE username='$username' AND password='$checked_password'");
if ($result['rows'] != 1)
{
$error = 1;
$pPassword_password_current_text = $PALANG['pPassword_password_current_text_error'];
}
}
else
{
$error = 1;
$pPassword_email_text = $PALANG['pPassword_email_text_error'];
}
$result = db_query ("SELECT * FROM $table_mailbox WHERE username='$username' AND password='$checked_password'");
if ($result['rows'] != 1)
{
$error = 1;
$pPassword_password_current_text = $PALANG['pPassword_password_current_text_error'];
}
}
else
{
$error = 1;
$pPassword_email_text = $PALANG['pPassword_email_text_error'];
}
if (empty ($fPassword) or ($fPassword != $fPassword2))
{
$error = 1;
$pPassword_password_text = $PALANG['pPassword_password_text_error'];
}
if (empty ($fPassword) or ($fPassword != $fPassword2))
{
$error = 1;
$pPassword_password_text = $PALANG['pPassword_password_text_error'];
}
if ($error != 1)
{
$password = pacrypt ($fPassword);
$result = db_query ("UPDATE $table_mailbox SET password='$password',modified=NOW() WHERE username='$username'");
if ($result['rows'] == 1)
{
$tMessage = $PALANG['pPassword_result_succes'];
db_log ($USERID_USERNAME, $USERID_DOMAIN, "change password", "$USERID_USERNAME");
}
else
{
$tMessage = $PALANG['pPassword_result_error'];
}
}
if ($error != 1)
{
$password = pacrypt ($fPassword);
$result = db_query ("UPDATE $table_mailbox SET password='$password',modified=NOW() WHERE username='$username'");
if ($result['rows'] == 1)
{
$tMessage = $PALANG['pPassword_result_succes'];
db_log ($USERID_USERNAME, $USERID_DOMAIN, "change password", "$USERID_USERNAME");
}
else
{
$tMessage = $PALANG['pPassword_result_error'];
}
}
include ("../templates/header.tpl");
include ("../templates/users_menu.tpl");
include ("../templates/users_password.tpl");
include ("../templates/footer.tpl");
include ("../templates/header.tpl");
include ("../templates/users_menu.tpl");
include ("../templates/users_password.tpl");
include ("../templates/footer.tpl");
}
?>

@ -22,126 +22,140 @@
// 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)
{
$row = db_array($result['result']);
$tMessage = $PALANG['pUsersVacation_welcome_text'];
$tSubject = $row['subject'];
$tBody = $row['body'];
}
if ($tSubject == '') { $tSubject = $PALANG['pUsersVacation_subject_text']; }
if ($tBody == '') { $tBody = $PALANG['pUsersVacation_body_text']; }
$template = "users_vacation.tpl";
include ("../templates/header.tpl");
include ("../templates/users_menu.tpl");
include ("../templates/users_vacation.tpl");
include ("../templates/footer.tpl");
$result = db_query("SELECT * FROM $table_vacation WHERE email='$USERID_USERNAME'");
if ($result['rows'] == 1)
{
$row = db_array($result['result']);
$tMessage = $PALANG['pUsersVacation_welcome_text'];
$tSubject = $row['subject'];
$tBody = $row['body'];
}
if ($tSubject == '') { $tSubject = $PALANG['pUsersVacation_subject_text']; }
if ($tBody == '') { $tBody = $PALANG['pUsersVacation_body_text']; }
$template = "users_vacation.tpl";
include ("../templates/header.tpl");
include ("../templates/users_menu.tpl");
include ("../templates/users_vacation.tpl");
include ("../templates/footer.tpl");
}
if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$vacation_domain = $CONF['vacation_domain'];
if (isset ($_POST['fSubject'])) $fSubject = escape_string ($_POST['fSubject']);
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']);
//set a default, reset fields for coming back selection
if ($tSubject == '') { $tSubject = $PALANG['pUsersVacation_subject_text']; }
if ($tBody == '') { $tBody = $PALANG['pUsersVacation_body_text']; }
if (!empty ($fBack) || !empty ($fAway))
{
$result = db_query ("DELETE FROM $table_vacation WHERE email='$USERID_USERNAME'");
if ($result['rows'] != 1)
{
$error = 1;
$tMessage = $PALANG['pUsersVacation_result_error'];
}
else
{
$tMessage = $PALANG['pUsersVacation_result_succes'];
}
$result = db_query ("SELECT * FROM $table_alias WHERE address='$USERID_USERNAME'");
if ($result['rows'] == 1)
{
$row = db_array ($result['result']);
$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/", '', $goto);
}
$result = db_query ("UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$USERID_USERNAME'");
if ($result['rows'] != 1)
{
$error = 1;
$tMessage = $PALANG['pUsersVacation_result_error'];
}
else
{
$tMessage = $PALANG['pUsersVacation_result_succes'];
}
}
if (!empty ($fAway))
{
$result = db_query ("SELECT * FROM $table_alias WHERE address='$USERID_USERNAME'");
if ($result['rows'] == 1)
{
$row = db_array ($result['result']);
$tGoto = $row['goto'];
}
($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)");
if ($result['rows'] != 1)
{
$error = 1;
$tMessage = $PALANG['pUsersVacation_result_error'];
}
$goto = $tGoto . "," . "$USERID_USERNAME@$vacation_domain";
$result = db_query ("UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$USERID_USERNAME'");
if ($result['rows'] != 1)
{
$error = 1;
$tMessage = $PALANG['pUsersVacation_result_error'];
}
else
{
header ("Location: main.php");
exit;
}
}
include ("../templates/header.tpl");
include ("../templates/users_menu.tpl");
include ("../templates/users_vacation.tpl");
include ("../templates/footer.tpl");
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']);
if (isset ($_POST['fAway'])) $fAway = escape_string ($_POST['fAway']);
if (isset ($_POST['fBack'])) $fBack = escape_string ($_POST['fBack']);
//set a default, reset fields for coming back selection
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'");
if ($result['rows'] != 1)
{
$error = 1;
$tMessage = $PALANG['pUsersVacation_result_error'];
}
else
{
$tMessage = $PALANG['pUsersVacation_result_succes'];
}
$result = db_query ("SELECT * FROM $table_alias WHERE address='$USERID_USERNAME'");
if ($result['rows'] == 1)
{
$row = db_array ($result['result']);
$tGoto = $row['goto'];
//only one of these will do something, first handles address at beginning and middle, second at end
$goto= preg_replace ( "/$vacation_goto,/", '', $tGoto);
$goto= preg_replace ( "/,$vacation_goto/", '', $tGoto);
}
$result = db_query ("UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$USERID_USERNAME'");
if ($result['rows'] != 1)
{
$error = 1;
$tMessage = $PALANG['pUsersVacation_result_error'];
}
else
{
$tMessage = $PALANG['pUsersVacation_result_succes'];
}
}
// 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)
{
$row = db_array ($result['result']);
$tGoto = $row['goto'];
}
($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)");
if ($result['rows'] != 1)
{
$error = 1;
$tMessage = $PALANG['pUsersVacation_result_error'];
}
// 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)
{
$error = 1;
$tMessage = $PALANG['pUsersVacation_result_error'];
}
else
{
header ("Location: main.php");
exit;
}
}
include ("../templates/header.tpl");
include ("../templates/users_menu.tpl");
include ("../templates/users_vacation.tpl");
include ("../templates/footer.tpl");
}
?>

Loading…
Cancel
Save