diff --git a/common.php b/common.php
new file mode 100644
index 00000000..0eb61980
--- /dev/null
+++ b/common.php
@@ -0,0 +1,28 @@
+
+// Copyright (c) 2002 - 2005 High5!
+// Licensed under GPL for more info check GPL-LICENSE.TXT
+//
+// File: common.php.php
+//
+// Template File: -none-
+//
+// Template Variables: -none-
+//
+// Form POST \ GET Variables: -none-
+//
+
+$incpath = dirname(__FILE__);
+
+require_once("$incpath/variables.inc.php");
+if(!is_file("$incpath/config.inc.php")) {
+ // incorrectly setup...
+ header("Location: setup.php");
+ exit(0);
+}
+require_once("$incpath/config.inc.php");
+require_once("$incpath/functions.inc.php");
+require_once("$incpath/languages/" . check_language () . ".lang");
+
+session_start();
diff --git a/create-alias.php b/create-alias.php
index 3154d130..486de662 100644
--- a/create-alias.php
+++ b/create-alias.php
@@ -23,21 +23,16 @@
// fDomain
//
-if (!isset($incpath)) $incpath = '.';
+require_once('common.php');
-require ("$incpath/variables.inc.php");
-require ("$incpath/config.inc.php");
-require ("$incpath/functions.inc.php");
-include ("$incpath/languages/" . check_language () . ".lang");
-
-$SESSID_USERNAME = check_session ();
-if (!check_admin($SESSID_USERNAME))
-{
- $list_domains = list_domains_for_admin ($SESSID_USERNAME);
+authentication_require_role('admin');
+$username = authentication_get_username();
+$SESSID_USERNAME = $username;
+if(authentication_has_role('global-admin')) {
+ $list_domains = list_domains ();
}
-else
-{
- $list_domains = list_domains ();
+else {
+ $list_domains = list_domains_for_admin ($username);
}
$pCreate_alias_goto_text = $PALANG['pCreate_alias_goto_text'];
@@ -64,7 +59,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
$fGoto = $fGoto . "@" . escape_string ($_POST['fDomain']);
}
- if (! (check_admin($SESSID_USERNAME) || check_owner ($SESSID_USERNAME, $fDomain) ))
+ if (! (authentication_has_role('global-admin') || check_owner ($SESSID_USERNAME, $fDomain) ))
{
$error = 1;
$tAddress = escape_string ($_POST['fAddress']);
@@ -149,7 +144,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
include ("$incpath/templates/header.tpl");
-if (check_admin($SESSID_USERNAME)) {
+if (authentication_has_role('global-admin')) {
include ("$incpath/templates/admin_menu.tpl");
} else {
include ("$incpath/templates/menu.tpl");
diff --git a/create-mailbox.php b/create-mailbox.php
index 6840890c..492f3219 100644
--- a/create-mailbox.php
+++ b/create-mailbox.php
@@ -29,26 +29,21 @@
// fMail
//
-if (!isset($incpath)) $incpath = '.';
+require_once('common.php');
-require ("$incpath/variables.inc.php");
-require ("$incpath/config.inc.php");
-require ("$incpath/functions.inc.php");
-include ("$incpath/languages/" . check_language () . ".lang");
-
-$SESSID_USERNAME = check_session ();
-if (!check_admin($SESSID_USERNAME))
-{
- $list_domains = list_domains_for_admin ($SESSID_USERNAME);
-}
-else
-{
+authentication_require_role('admin');
+$SESSID_USERNAME = authentication_get_username();
+if(authentication_has_role('global-admin')) {
$list_domains = list_domains ();
}
+else {
+ $list_domains = list_domains_for_admin ($SESSID_USERNAME);
+}
- $pCreate_mailbox_password_text = $PALANG['pCreate_mailbox_password_text'];
- $pCreate_mailbox_name_text = $PALANG['pCreate_mailbox_name_text'];
- $pCreate_mailbox_quota_text = $PALANG['pCreate_mailbox_quota_text'];
+
+$pCreate_mailbox_password_text = $PALANG['pCreate_mailbox_password_text'];
+$pCreate_mailbox_name_text = $PALANG['pCreate_mailbox_name_text'];
+$pCreate_mailbox_quota_text = $PALANG['pCreate_mailbox_quota_text'];
if ($_SERVER['REQUEST_METHOD'] == "GET")
{
@@ -61,8 +56,6 @@ if ($_SERVER['REQUEST_METHOD'] == "GET")
$tQuota = $row['maxquota'];
}
-
-
}
if ($_SERVER['REQUEST_METHOD'] == "POST")
@@ -79,7 +72,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
if (isset ($_POST['fMail'])) $fMail = escape_string ($_POST['fMail']);
- if ( (!check_owner ($SESSID_USERNAME, $fDomain)) && (!check_admin($SESSID_USERNAME)) )
+ if ( (!check_owner ($SESSID_USERNAME, $fDomain)) && (!authentication_has_role('global-admin')) )
{
$error = 1;
$tUsername = escape_string ($_POST['fUsername']);
@@ -98,7 +91,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
$tDomain = $fDomain;
$pCreate_mailbox_username_text = $PALANG['pCreate_mailbox_username_text_error3'];
}
-
+
if (empty ($fUsername) or !check_email ($fUsername))
{
$error = 1;
@@ -113,7 +106,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
{
if (empty ($fPassword) and empty ($fPassword2) and $CONF['generate_password'] == "YES")
{
- $fPassword = generate_password ();
+ $fPassword = generate_password ();
}
else
{
@@ -138,7 +131,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
$pCreate_mailbox_quota_text = $PALANG['pCreate_mailbox_quota_text_error'];
}
}
-
+
$result = db_query ("SELECT * FROM $table_alias WHERE address='$fUsername'");
if ($result['rows'] == 1)
{
@@ -153,7 +146,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
if ($error != 1)
{
$password = pacrypt ($fPassword);
-
+
if ($CONF['domain_path'] == "YES")
{
if ($CONF['domain_in_mailbox'] == "YES")
@@ -169,7 +162,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$maildir = $fUsername . "/";
}
-
+
if (!empty ($fQuota))
{
$quota = multiply_quota ($fQuota);
@@ -178,7 +171,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$quota = 0;
}
-
+
if ($fActive == "on")
{
$fActive = 1;
@@ -214,7 +207,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
}
else
{
-
+
$error=TRUE; // Being pessimistic
if (mailbox_postcreation($fUsername,$fDomain,$maildir))
{
@@ -222,7 +215,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$result=db_query("COMMIT");
- /* should really not be possible: */
+/* should really not be possible: */
/*
if (!$result) die('COMMIT-query failed.');
}
@@ -233,14 +226,14 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$result=db_query("ROLLBACK");
- /* should really not be possible: */
+/* should really not be possible: */
/*
if (!$result) die('ROLLBACK-query failed.');
} else {
/*
When we cannot count on transactions, we need to move forward, despite
the problems.
- */
+ */
/*
$error=FALSE;
}
@@ -250,14 +243,14 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
if (!$error)
{
db_log ($CONF['admin_email'], $fDomain, "create mailbox", $fUsername);
-
-*/
+
+ */
/*
TODO: this is the start of /create-mailbox code segment that was originally used in /create-mailbox.php instead
of the above from admin/create-mailbox.php.
To be compared / merged.
-*/
+ */
$result = db_query ("INSERT INTO $table_mailbox (username,password,name,maildir,quota,domain,created,modified,active) VALUES ('$fUsername','$password','$fName','$maildir','$quota','$fDomain',NOW(),NOW(),'$sqlActive')");
if ($result['rows'] != 1 || !mailbox_postcreation($fUsername,$fDomain,$maildir))
@@ -272,71 +265,71 @@ TODO: this is the start of /create-mailbox code segment that was originally used
db_log ($SESSID_USERNAME, $fDomain, "create mailbox", "$fUsername");
/*
TODO: this is the end of /create-mailbox.php code segment
-*/
- $tDomain = $fDomain;
+ */
+ $tDomain = $fDomain;
- if (create_mailbox_subfolders($fUsername,$fPassword))
- {
- $tMessage = $PALANG['pCreate_mailbox_result_succes'] . "
($fUsername";
- } else {
- $tMessage = $PALANG['pCreate_mailbox_result_succes_nosubfolders'] . "
($fUsername";
- }
+ if (create_mailbox_subfolders($fUsername,$fPassword))
+ {
+ $tMessage = $PALANG['pCreate_mailbox_result_succes'] . "
($fUsername";
+ } else {
+ $tMessage = $PALANG['pCreate_mailbox_result_succes_nosubfolders'] . "
($fUsername";
+ }
- if ($CONF['generate_password'] == "YES")
+ if ($CONF['generate_password'] == "YES")
+ {
+ $tMessage .= " / $fPassword)";
+ }
+ else
+ {
+ if ($CONF['show_password'] == "YES")
{
$tMessage .= " / $fPassword)";
}
else
{
- if ($CONF['show_password'] == "YES")
- {
- $tMessage .= " / $fPassword)";
- }
- else
- {
- $tMessage .= ")";
- }
+ $tMessage .= ")";
}
-
- $tQuota = $CONF['maxquota'];
+ }
- if ($fMail == "on")
+ $tQuota = $CONF['maxquota'];
+
+ if ($fMail == "on")
+ {
+ $fTo = $fUsername;
+ $fFrom = $SESSID_USERNAME;
+ $fHeaders = "To: " . $fTo . "\n";
+ $fHeaders .= "From: " . $fFrom . "\n";
+
+ if (!empty ($PALANG['charset']))
{
- $fTo = $fUsername;
- $fFrom = $SESSID_USERNAME;
- $fHeaders = "To: " . $fTo . "\n";
- $fHeaders .= "From: " . $fFrom . "\n";
-
- if (!empty ($PALANG['charset']))
- {
- $fHeaders .= "Subject: " . encode_header ($PALANG['pSendmail_subject_text'], $PALANG['charset']) . "\n";
- $fHeaders .= "MIME-Version: 1.0\n";
- $fHeaders .= "Content-Type: text/plain; charset=" . $PALANG['charset'] . "\n";
- $fHeaders .= "Content-Transfer-Encoding: 8bit\n";
- }
- else
- {
- $fHeaders .= "Subject: " . $PALANG['pSendmail_subject_text'] . "\n\n";
- }
-
- $fHeaders .= $CONF['welcome_text'];
-
- if (!smtp_mail ($fTo, $fFrom, $fHeaders))
- {
- $tMessage .= "
" . $PALANG['pSendmail_result_error'] . "
";
- }
- else
- {
- $tMessage .= "
" . $PALANG['pSendmail_result_succes'] . "
";
- }
+ $fHeaders .= "Subject: " . encode_header ($PALANG['pSendmail_subject_text'], $PALANG['charset']) . "\n";
+ $fHeaders .= "MIME-Version: 1.0\n";
+ $fHeaders .= "Content-Type: text/plain; charset=" . $PALANG['charset'] . "\n";
+ $fHeaders .= "Content-Transfer-Encoding: 8bit\n";
}
+ else
+ {
+ $fHeaders .= "Subject: " . $PALANG['pSendmail_subject_text'] . "\n\n";
+ }
+
+ $fHeaders .= $CONF['welcome_text'];
+
+ if (!smtp_mail ($fTo, $fFrom, $fHeaders))
+ {
+ $tMessage .= "
" . $PALANG['pSendmail_result_error'] . "
";
+ }
+ else
+ {
+ $tMessage .= "
" . $PALANG['pSendmail_result_succes'] . "
";
+ }
+ }
}
}
}
include ("$incpath/templates/header.tpl");
-if (check_admin($SESSID_USERNAME)) {
+if (authentication_has_role('global-admin')) {
include ("$incpath/templates/admin_menu.tpl");
} else {
include ("$incpath/templates/menu.tpl");
diff --git a/delete.php b/delete.php
index 971de074..68fc96be 100644
--- a/delete.php
+++ b/delete.php
@@ -18,12 +18,12 @@
// fDelete
// fDomain
//
-require ("./variables.inc.php");
-require ("./config.inc.php");
-require ("./functions.inc.php");
-include ("./languages/" . check_language () . ".lang");
-$SESSID_USERNAME = check_session();
+require_once('common.php');
+
+authentication_require_role('admin');
+
+$SESSID_USERNAME = authentication_get_username();
if ($_SERVER['REQUEST_METHOD'] == "GET")
{
@@ -43,6 +43,7 @@ if ($_SERVER['REQUEST_METHOD'] == "GET")
else
{
if ($CONF['database_type'] == "pgsql") db_query('BEGIN');
+
$result = db_query ("DELETE FROM $table_alias WHERE address='$fDelete' AND domain='$fDomain'");
if ($result['rows'] != 1)
{
diff --git a/edit-active.php b/edit-active.php
index b7a3a172..df37678a 100644
--- a/edit-active.php
+++ b/edit-active.php
@@ -20,14 +20,10 @@
// fReturn
//
-if (!isset($incpath)) $incpath = '.';
+require_once('common.php');
-require ("$incpath/variables.inc.php");
-require ("$incpath/config.inc.php");
-require ("$incpath/functions.inc.php");
-include ("$incpath/languages/" . check_language () . ".lang");
-
-$SESSID_USERNAME = check_session ();
+authentication_require_role('admin');
+$SESSID_USERNAME = authentication_get_username();
if ($_SERVER['REQUEST_METHOD'] == "GET")
{
@@ -36,7 +32,7 @@ if ($_SERVER['REQUEST_METHOD'] == "GET")
if (isset ($_GET['domain'])) $fDomain = escape_string ($_GET['domain']);
if (isset ($_GET['return'])) $fReturn = escape_string ($_GET['return']);
- if (! (check_owner ($SESSID_USERNAME, $fDomain) || check_admin($SESSID_USERNAME) ) )
+ if (! (check_owner ($SESSID_USERNAME, $fDomain) || authentication_has_role('global-admin') ) )
{
$error = 1;
$tMessage = $PALANG['pEdit_mailbox_domain_error'] . "$fDomain!";
@@ -83,7 +79,7 @@ if ($_SERVER['REQUEST_METHOD'] == "GET")
}
else
{
- if (check_admin($SESSID_USERNAME)) {
+ if (authentication_has_role('global-admin')) {
header ("Location: list-virtual.php?domain=$fDomain");
} else {
header ("Location: overview.php?domain=$fDomain");
@@ -95,7 +91,7 @@ if ($_SERVER['REQUEST_METHOD'] == "GET")
include ("$incpath/templates/header.tpl");
-if (check_admin($SESSID_USERNAME)) {
+if (authentication_has_role('global-admin')) {
include ("$incpath/templates/admin_menu.tpl");
} else {
include ("$incpath/templates/menu.tpl");
diff --git a/edit-alias.php b/edit-alias.php
index dde57c1c..623011cd 100644
--- a/edit-alias.php
+++ b/edit-alias.php
@@ -21,21 +21,17 @@
// fGoto
//
-if (!isset($incpath)) $incpath = '.';
+require_once('common.php');
-require ("$incpath/variables.inc.php");
-require ("$incpath/config.inc.php");
-require ("$incpath/functions.inc.php");
-include ("$incpath/languages/" . check_language () . ".lang");
-
-$SESSID_USERNAME = check_session ();
+authentication_require_role('admin');
+$SESSID_USERNAME = authentication_get_username();
if ($_SERVER['REQUEST_METHOD'] == "GET")
{
if (isset ($_GET['address'])) $fAddress = escape_string ($_GET['address']);
if (isset ($_GET['domain'])) $fDomain = escape_string ($_GET['domain']);
- if (check_owner ($SESSID_USERNAME, $fDomain) || check_admin($SESSID_USERNAME))
+ if (check_owner ($SESSID_USERNAME, $fDomain) || authentication_has_role('global-admin'))
{
$result = db_query ("SELECT * FROM $table_alias WHERE address='$fAddress' AND domain='$fDomain'");
if ($result['rows'] == 1)
@@ -60,7 +56,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
if (isset ($_POST['fGoto'])) $fGoto = escape_string ($_POST['fGoto']);
$fGoto = strtolower ($fGoto);
- if (! (check_owner ($SESSID_USERNAME, $fDomain) || check_admin($SESSID_USERNAME)) )
+ if (! (check_owner ($SESSID_USERNAME, $fDomain) || authentication_has_role('global-admin')) )
{
$error = 1;
$tGoto = $_POST['fGoto'];
@@ -114,7 +110,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
{
db_log ($SESSID_USERNAME, $fDomain, "edit alias", "$fAddress -> $goto");
- if (check_admin($SESSID_USERNAME)) {
+ if (authentication_has_role('global-admin')) {
header ("Location: list-virtual.php?domain=$fDomain");
} else {
header ("Location: overview.php?domain=$fDomain");
@@ -126,7 +122,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
include ("$incpath/templates/header.tpl");
-if (check_admin($SESSID_USERNAME)) {
+if (authentication_has_role('global-admin')) {
include ("$incpath/templates/admin_menu.tpl");
} else {
include ("$incpath/templates/menu.tpl");
diff --git a/edit-mailbox.php b/edit-mailbox.php
index 3c85b522..eda91eaa 100644
--- a/edit-mailbox.php
+++ b/edit-mailbox.php
@@ -26,14 +26,10 @@
// fActive
//
-if (!isset($incpath)) $incpath = '.';
+require_once('common.php');
-require ("$incpath/variables.inc.php");
-require ("$incpath/config.inc.php");
-require ("$incpath/functions.inc.php");
-include ("$incpath/languages/" . check_language () . ".lang");
-
-$SESSID_USERNAME = check_session ();
+authentication_require_role('admin');
+$SESSID_USERNAME = authentication_get_username();
if (isset ($_GET['username'])) $fUsername = escape_string ($_GET['username']);
$fUsername = strtolower ($fUsername);
@@ -44,7 +40,7 @@ $pEdit_mailbox_quota_text = $PALANG['pEdit_mailbox_quota_text'];
if ($_SERVER['REQUEST_METHOD'] == "GET")
{
- if (check_owner ($SESSID_USERNAME, $fDomain) || check_admin($SESSID_USERNAME))
+ if (check_owner ($SESSID_USERNAME, $fDomain) || authentication_has_role('global-admin'))
{
$result = db_query ("SELECT * FROM $table_mailbox WHERE username='$fUsername' AND domain='$fDomain'");
if ($result['rows'] == 1)
@@ -79,7 +75,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
if (isset ($_POST['fQuota'])) $fQuota = intval ($_POST['fQuota']);
if (isset ($_POST['fActive'])) $fActive = escape_string ($_POST['fActive']);
- if (! (check_owner ($SESSID_USERNAME, $fDomain) || check_admin($SESSID_USERNAME)) )
+ if (! (check_owner ($SESSID_USERNAME, $fDomain) || authentication_has_role('global-admin')) )
{
$error = 1;
$tName = $fName;
@@ -153,7 +149,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
{
db_log ($SESSID_USERNAME, $fDomain, "edit mailbox", $fUsername);
- if (check_admin($SESSID_USERNAME)) {
+ if (authentication_has_role('global-admin')) {
header ("Location: list-virtual.php?domain=$fDomain");
} else {
header ("Location: overview.php?domain=$fDomain");
@@ -165,7 +161,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
include ("$incpath/templates/header.tpl");
-if (check_admin($SESSID_USERNAME)) {
+if (authentication_has_role('global-admin')) {
include ("$incpath/templates/admin_menu.tpl");
} else {
include ("$incpath/templates/menu.tpl");
diff --git a/edit-vacation.php b/edit-vacation.php
index baf9b7fb..c08c4359 100644
--- a/edit-vacation.php
+++ b/edit-vacation.php
@@ -1,4 +1,6 @@
@@ -11,6 +13,7 @@
//
// Template Variables:
//
+// tUseremail
// tMessage
// tSubject
// tBody
@@ -25,38 +28,27 @@
// fQuota
// fActive
//
-// This is a copy of the superadmin edit-vacation.php with
-// template references changed
-//
-if (!isset($incpath)) $incpath = '.';
+require_once('common.php');
-require ("$incpath/variables.inc.php");
-require ("$incpath/config.inc.php");
-require ("$incpath/functions.inc.php");
-include ("$incpath/languages/" . check_language () . ".lang");
+$SESSID_USERNAME = authentication_get_username();
+
+if($CONF['vacation'] == 'NO') {
+ header("Location: " . $CONF['postfix_admin_url'] . "/main.php");
+ exit(0);
+}
+
+$vacation_domain = $CONF['vacation_domain'];
+$vacation_goto = preg_replace('/@/', '#', $SESSID_USERNAME);
+$vacation_goto = $vacation_goto . '@' . $vacation_domain;
-$SESSID_USERNAME = check_session ();
-(($CONF['vacation'] == 'NO') ? header("Location: " . $CONF['postfix_admin_url'] . "/main.php") && exit : '1');
$tmp = preg_split ('/@/', $SESSID_USERNAME);
$USERID_DOMAIN = $tmp[1];
if (isset ($_GET['username'])) $fUsername = escape_string ($_GET['username']);
if (isset ($_GET['domain'])) $fDomain = escape_string ($_GET['domain']);
-if (check_admin($SESSID_USERNAME))
-{
- $fCanceltarget= $CONF['postfix_admin_url'] . "/admin/list-virtual.php?domain=$fDomain";
-}
-else
-{
- if (check_owner ($SESSID_USERNAME, $fDomain))
- {
- $fCanceltarget= $CONF['postfix_admin_url'] . "/overview.php?domain=$fDomain";
- }
- //unauthorized, exit
- else { exit; }
-}
+$fCanceltarget = $CONF['postfix_admin_url'] . '/main.php';
if ($_SERVER['REQUEST_METHOD'] == "GET")
{
@@ -74,72 +66,70 @@ if ($_SERVER['REQUEST_METHOD'] == "GET")
if ($tSubject == '') { $tSubject = $PALANG['pUsersVacation_subject_text']; }
if ($tBody == '') { $tBody = $PALANG['pUsersVacation_body_text']; }
-
-
}
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['fChange'])) $fChange = escape_string ($_POST['fChange']);
if (isset ($_POST['fBack'])) $fBack = escape_string ($_POST['fBack']);
- if (isset ($_GET['domain'])) $fDomain = escape_string ($_GET['domain']);
- if (isset ($_GET['username'])) $fUsername = escape_string ($_GET['username']);
+ if (isset ($_GET['domain'])) {
+ $fDomain = escape_string ($_GET['domain']);
+ }
+ else {
+ $fDomain = $USERID_DOMAIN;
+ }
+ if (isset ($_GET['username'])) {
+ $fUsername = escape_string ($_GET['username']);
+ }
+ else {
+ $fUsername = authentication_get_username();
+ }
$tUseremail = $fUsername;
if ($tSubject == '') { $tSubject = $PALANG['pUsersVacation_subject_text']; }
if ($tBody == '') { $tBody = $PALANG['pUsersVacation_body_text']; }
- //if change, remove old one, then set new one
+ //if change, remove old one, then perhaps set new one
if (!empty ($fBack) || !empty ($fChange))
{
- //if we find an existing vacation entry, delete 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;
- $tMessage = $PALANG['pVacation_result_error'];
- $tMessage = "cannot remove $fUsername from $table_vacation";
- }
- else
- {
- $tMessage = $PALANG['pVacation_result_success'];
- }
-
- $result = db_query ("SELECT * FROM $table_alias WHERE address='$fUsername'");
+ //if we find an existing vacation entry, delete it
+ $result = db_query("SELECT * FROM $table_vacation WHERE email='$fUsername'");
if ($result['rows'] == 1)
{
- $row = db_array ($result['result']);
- $goto = $row['goto'];
-
- //only one of these will do something, first handles address at beginning and middle, second at end
- $goto= preg_replace ( "/$fUsername@$vacation_domain,/", '', $goto);
- $goto= preg_replace ( "/,$fUsername@$vacation_domain/", '', $goto);
-
- $result = db_query ("UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$fUsername'");
+ $result = db_query ("DELETE FROM $table_vacation WHERE email='$fUsername'");
if ($result['rows'] != 1)
{
$error = 1;
- $tMessage = $PALANG['pVacation_result_error'];
}
- else
+
+ $result = db_query ("SELECT * FROM $table_alias WHERE address='$fUsername'");
+ if ($result['rows'] == 1)
{
- $tMessage = $PALANG['pVacation_result_success'];
+ $row = db_array ($result['result']);
+ $goto = $row['goto'];
+
+ //only one of these will do something, first handles address at beginning and middle, second at end
+ $goto= preg_replace ( "/$vacation_goto,/", '', $goto);
+ $goto= preg_replace ( "/,$vacation_goto/", '', $goto);
+
+ $result = db_query ("UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$fUsername'");
+ if ($result['rows'] != 1)
+ {
+ $error = 1;
+ }
}
}
- }
}
+
//Set the vacation data for $fUsername
if (!empty ($fChange))
{
+ $goto = '';
$result = db_query ("SELECT * FROM $table_alias WHERE address='$fUsername'");
if ($result['rows'] == 1)
{
@@ -149,30 +139,37 @@ if ($_SERVER['REQUEST_METHOD'] == "POST")
($CONF['database_type']=='pgsql') ? $Active='true' : $Active=1;
$result = db_query ("INSERT INTO $table_vacation (email,subject,body,domain,created,active) VALUES ('$fUsername','$fSubject','$fBody','$fDomain',NOW(),$Active)");
+
if ($result['rows'] != 1)
{
$error = 1;
- $tMessage = $PALANG['pVacation_result_error'];
}
- $goto = $goto . "," . "$fUsername@$vacation_domain";
+ $goto = $goto . "," . $vacation_goto;
$result = db_query ("UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$fUsername'");
if ($result['rows'] != 1)
{
$error = 1;
- $tMessage = $PALANG['pVacation_result_error'];
- }
- else
- {
- header ("Location: $fCanceltarget");
- exit;
}
}
}
+if($error == 0) {
+ if(!empty ($fBack)) {
+ $tMessage = $PALANG['pVacation_result_removed'];
+ }
+ if(!empty($fChange)) {
+ $tMessage= $PALANG['pVacation_result_added'];
+ }
+}
+else {
+ $tMessage = $PALANG['pVacation_result_error'];
+}
+
+$tUseremail = $SESSID_USERNAME;
include ("$incpath/templates/header.tpl");
-if (check_admin($SESSID_USERNAME)) {
+if (authentication_has_role('global-admin')) {
include ("$incpath/templates/admin_menu.tpl");
} else {
include ("$incpath/templates/menu.tpl");
diff --git a/index.php b/index.php
index 66ed3eb3..9b2f756c 100644
--- a/index.php
+++ b/index.php
@@ -19,36 +19,30 @@
//
if (!file_exists (realpath ("./setup.php")))
{
- header ("Location: login.php");
- exit;
+ header ("Location: login.php");
+ exit;
}
else
{
- print <<< EOF
+ print <<< EOF
-