0
0
mirror of https://github.com/postfixadmin/postfixadmin.git synced 2024-09-20 03:36:20 +02:00
postfixadmin/public/vacation.php

227 lines
6.6 KiB
PHP
Raw Normal View History

<?php
/**
* Postfix Admin
*
* LICENSE
* This source file is subject to the GPL license that is bundled with
* this package in the file LICENSE.TXT.
*
2018-01-26 15:45:57 +01:00
* Further details on the project are available at http://postfixadmin.sf.net
*
* @version $Id$
* @license GNU GPL v2 or later.
*
* File: edit-vacation.php
*
* Allows users to update their vacation status and
2018-01-26 15:45:57 +01:00
* admins to update the vacation status for the their users
*
* Template File: vacation.tpl
*
* Template Variables:
*
* tUseremail
Merge users/vacation.php and edit-vacation.php into vacation.php vacation.php - result of merging edit-vacation.php and users/vacation.php - vacation.php comes with the svn history of edit-vacation.php - display "vacation already active" (only) in user mode if vacation is active (would be useful in admin mode too, but needs a text change) - various comment updates - add username in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] using sprintf - change compared to Jan Kruis' patch: - set return url for users to main.php instead of users/main.php - set return url for admins after setting $fDomain. Otherwise the return url does not contain the domain. - removed unused variable $tDomain users/vacation.php: - require(../vacation.php) - remove everything else - whitespace changes in the license header - note: this is completely different from Jan Kruis' patch - his intention was to remove this file and use ../vacation.php. However, with his way all links in the users menu would point to the wrong place/directory edit-vacation.php: - deleted templates/vacation.tpl - display username only in admin mode templates/list-virtual_mailbox.tpl - link changed to merged vacation.php languages/en.lang - add username in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] as sprintf variable - (comments added by Jan Kruis' patch are not part of this commit) languages/nl.lang - translation updates - already contains the sprintf variable in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] (updates for other *.lang files follow in another commit) The following parts of Jan Kruis' patch are not part of this commit: - rejected: - variables.inc.php: don't add $Admin_role and $Return_url If we initialize them, it should be done directly in (edit-)vacation.php, but the current code always sets them already in all cases. - templates/users_main.tpl: do not change url for vacation.php - postponed: - added comments in en.lang about obsolete texts Most parts of this commit (see exceptions above) were provided as patch by Jan Kruis (jan-kruis@SF), see https://sourceforge.net/tracker/?func=detail&aid=3383236&group_id=191583&atid=937966 git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1169 a1433add-5e2c-0410-b055-b7f2511e0802
2011-08-15 01:12:20 +02:00
* tActiveFrom
* tActiveUntil
* tSubject
* tBody
* tInterval_time
*
* Form POST \ GET Variables:
*
* fUsername
* fDomain
Merge users/vacation.php and edit-vacation.php into vacation.php vacation.php - result of merging edit-vacation.php and users/vacation.php - vacation.php comes with the svn history of edit-vacation.php - display "vacation already active" (only) in user mode if vacation is active (would be useful in admin mode too, but needs a text change) - various comment updates - add username in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] using sprintf - change compared to Jan Kruis' patch: - set return url for users to main.php instead of users/main.php - set return url for admins after setting $fDomain. Otherwise the return url does not contain the domain. - removed unused variable $tDomain users/vacation.php: - require(../vacation.php) - remove everything else - whitespace changes in the license header - note: this is completely different from Jan Kruis' patch - his intention was to remove this file and use ../vacation.php. However, with his way all links in the users menu would point to the wrong place/directory edit-vacation.php: - deleted templates/vacation.tpl - display username only in admin mode templates/list-virtual_mailbox.tpl - link changed to merged vacation.php languages/en.lang - add username in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] as sprintf variable - (comments added by Jan Kruis' patch are not part of this commit) languages/nl.lang - translation updates - already contains the sprintf variable in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] (updates for other *.lang files follow in another commit) The following parts of Jan Kruis' patch are not part of this commit: - rejected: - variables.inc.php: don't add $Admin_role and $Return_url If we initialize them, it should be done directly in (edit-)vacation.php, but the current code always sets them already in all cases. - templates/users_main.tpl: do not change url for vacation.php - postponed: - added comments in en.lang about obsolete texts Most parts of this commit (see exceptions above) were provided as patch by Jan Kruis (jan-kruis@SF), see https://sourceforge.net/tracker/?func=detail&aid=3383236&group_id=191583&atid=937966 git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1169 a1433add-5e2c-0410-b055-b7f2511e0802
2011-08-15 01:12:20 +02:00
* fCancel
* fChange
* fBack
* fActive
*/
require_once('common.php');
2020-09-27 12:02:58 +02:00
$CONF = Config::getInstance()->getAll();
$smarty = PFASmarty::getInstance();
$now = new \DateTime();
2020-09-27 12:02:58 +02:00
// only allow admins to change someone else's 'stuff'
2018-01-26 15:45:57 +01:00
if (authentication_has_role('admin')) {
$Admin_role = 1;
2018-01-26 15:45:57 +01:00
$fUsername = safeget('username');
list(/*NULL*/, $fDomain) = explode('@', $fUsername);
$Return_url = "list-virtual.php?domain=" . urlencode($fDomain);
# TODO: better check for valid username (check if mailbox exists)
# TODO: (should be done in VacationHandler)
if ($fDomain == '' || !check_owner(authentication_get_username(), $fDomain)) {
die("Invalid username!"); # TODO: better error message
}
} else {
$Admin_role = 0;
2018-01-26 15:45:57 +01:00
$Return_url = "main.php";
authentication_require_role('user');
$fUsername = authentication_get_username();
}
$smarty->assign('return_url', $Return_url);
Merge users/vacation.php and edit-vacation.php into vacation.php vacation.php - result of merging edit-vacation.php and users/vacation.php - vacation.php comes with the svn history of edit-vacation.php - display "vacation already active" (only) in user mode if vacation is active (would be useful in admin mode too, but needs a text change) - various comment updates - add username in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] using sprintf - change compared to Jan Kruis' patch: - set return url for users to main.php instead of users/main.php - set return url for admins after setting $fDomain. Otherwise the return url does not contain the domain. - removed unused variable $tDomain users/vacation.php: - require(../vacation.php) - remove everything else - whitespace changes in the license header - note: this is completely different from Jan Kruis' patch - his intention was to remove this file and use ../vacation.php. However, with his way all links in the users menu would point to the wrong place/directory edit-vacation.php: - deleted templates/vacation.tpl - display username only in admin mode templates/list-virtual_mailbox.tpl - link changed to merged vacation.php languages/en.lang - add username in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] as sprintf variable - (comments added by Jan Kruis' patch are not part of this commit) languages/nl.lang - translation updates - already contains the sprintf variable in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] (updates for other *.lang files follow in another commit) The following parts of Jan Kruis' patch are not part of this commit: - rejected: - variables.inc.php: don't add $Admin_role and $Return_url If we initialize them, it should be done directly in (edit-)vacation.php, but the current code always sets them already in all cases. - templates/users_main.tpl: do not change url for vacation.php - postponed: - added comments in en.lang about obsolete texts Most parts of this commit (see exceptions above) were provided as patch by Jan Kruis (jan-kruis@SF), see https://sourceforge.net/tracker/?func=detail&aid=3383236&group_id=191583&atid=937966 git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1169 a1433add-5e2c-0410-b055-b7f2511e0802
2011-08-15 01:12:20 +02:00
// is vacation support enabled in $CONF ?
2018-01-26 15:45:57 +01:00
if ($CONF['vacation'] == 'NO') {
header("Location: $Return_url");
exit(0);
Merge users/vacation.php and edit-vacation.php into vacation.php vacation.php - result of merging edit-vacation.php and users/vacation.php - vacation.php comes with the svn history of edit-vacation.php - display "vacation already active" (only) in user mode if vacation is active (would be useful in admin mode too, but needs a text change) - various comment updates - add username in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] using sprintf - change compared to Jan Kruis' patch: - set return url for users to main.php instead of users/main.php - set return url for admins after setting $fDomain. Otherwise the return url does not contain the domain. - removed unused variable $tDomain users/vacation.php: - require(../vacation.php) - remove everything else - whitespace changes in the license header - note: this is completely different from Jan Kruis' patch - his intention was to remove this file and use ../vacation.php. However, with his way all links in the users menu would point to the wrong place/directory edit-vacation.php: - deleted templates/vacation.tpl - display username only in admin mode templates/list-virtual_mailbox.tpl - link changed to merged vacation.php languages/en.lang - add username in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] as sprintf variable - (comments added by Jan Kruis' patch are not part of this commit) languages/nl.lang - translation updates - already contains the sprintf variable in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] (updates for other *.lang files follow in another commit) The following parts of Jan Kruis' patch are not part of this commit: - rejected: - variables.inc.php: don't add $Admin_role and $Return_url If we initialize them, it should be done directly in (edit-)vacation.php, but the current code always sets them already in all cases. - templates/users_main.tpl: do not change url for vacation.php - postponed: - added comments in en.lang about obsolete texts Most parts of this commit (see exceptions above) were provided as patch by Jan Kruis (jan-kruis@SF), see https://sourceforge.net/tracker/?func=detail&aid=3383236&group_id=191583&atid=937966 git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1169 a1433add-5e2c-0410-b055-b7f2511e0802
2011-08-15 01:12:20 +02:00
}
date_default_timezone_set(@date_default_timezone_get()); # Suppress date.timezone warnings
$error = 0;
$vh = new VacationHandler($fUsername);
$choice_of_reply = Config::read_array('vacation_choice_of_reply');
foreach (array_keys($choice_of_reply) as $key) {
2018-01-26 15:45:57 +01:00
$choice_of_reply[$key] = Config::Lang($choice_of_reply[$key]);
}
$tUseremail = $fUsername;
2020-03-12 21:45:51 +01:00
$tInterval_Time = null;
$tBody = null;
$tSubject = null;
$tActiveFrom = new DateTime();
$tActiveUntil = new DateTime();
$details = $vh->get_details();
if (is_array($details)) {
$tSubject = $details['subject'];
$tBody = $details['body'];
$tInterval_Time = $details['interval_time'];
$tActiveFrom = new \DateTime($details['activeFrom']);
$tActiveUntil = new \DateTime($details['activeUntil']);
} else {
$details = ['active' => 0];
}
2020-03-12 21:45:51 +01:00
Merge users/vacation.php and edit-vacation.php into vacation.php vacation.php - result of merging edit-vacation.php and users/vacation.php - vacation.php comes with the svn history of edit-vacation.php - display "vacation already active" (only) in user mode if vacation is active (would be useful in admin mode too, but needs a text change) - various comment updates - add username in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] using sprintf - change compared to Jan Kruis' patch: - set return url for users to main.php instead of users/main.php - set return url for admins after setting $fDomain. Otherwise the return url does not contain the domain. - removed unused variable $tDomain users/vacation.php: - require(../vacation.php) - remove everything else - whitespace changes in the license header - note: this is completely different from Jan Kruis' patch - his intention was to remove this file and use ../vacation.php. However, with his way all links in the users menu would point to the wrong place/directory edit-vacation.php: - deleted templates/vacation.tpl - display username only in admin mode templates/list-virtual_mailbox.tpl - link changed to merged vacation.php languages/en.lang - add username in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] as sprintf variable - (comments added by Jan Kruis' patch are not part of this commit) languages/nl.lang - translation updates - already contains the sprintf variable in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] (updates for other *.lang files follow in another commit) The following parts of Jan Kruis' patch are not part of this commit: - rejected: - variables.inc.php: don't add $Admin_role and $Return_url If we initialize them, it should be done directly in (edit-)vacation.php, but the current code always sets them already in all cases. - templates/users_main.tpl: do not change url for vacation.php - postponed: - added comments in en.lang about obsolete texts Most parts of this commit (see exceptions above) were provided as patch by Jan Kruis (jan-kruis@SF), see https://sourceforge.net/tracker/?func=detail&aid=3383236&group_id=191583&atid=937966 git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1169 a1433add-5e2c-0410-b055-b7f2511e0802
2011-08-15 01:12:20 +02:00
if ($_SERVER['REQUEST_METHOD'] == "GET") {
2018-01-26 15:45:57 +01:00
if ($vh->check_vacation()) {
flash_info(sprintf($PALANG['pUsersVacation_welcome_text'], htmlentities($tUseremail)));
Merge users/vacation.php and edit-vacation.php into vacation.php vacation.php - result of merging edit-vacation.php and users/vacation.php - vacation.php comes with the svn history of edit-vacation.php - display "vacation already active" (only) in user mode if vacation is active (would be useful in admin mode too, but needs a text change) - various comment updates - add username in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] using sprintf - change compared to Jan Kruis' patch: - set return url for users to main.php instead of users/main.php - set return url for admins after setting $fDomain. Otherwise the return url does not contain the domain. - removed unused variable $tDomain users/vacation.php: - require(../vacation.php) - remove everything else - whitespace changes in the license header - note: this is completely different from Jan Kruis' patch - his intention was to remove this file and use ../vacation.php. However, with his way all links in the users menu would point to the wrong place/directory edit-vacation.php: - deleted templates/vacation.tpl - display username only in admin mode templates/list-virtual_mailbox.tpl - link changed to merged vacation.php languages/en.lang - add username in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] as sprintf variable - (comments added by Jan Kruis' patch are not part of this commit) languages/nl.lang - translation updates - already contains the sprintf variable in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] (updates for other *.lang files follow in another commit) The following parts of Jan Kruis' patch are not part of this commit: - rejected: - variables.inc.php: don't add $Admin_role and $Return_url If we initialize them, it should be done directly in (edit-)vacation.php, but the current code always sets them already in all cases. - templates/users_main.tpl: do not change url for vacation.php - postponed: - added comments in en.lang about obsolete texts Most parts of this commit (see exceptions above) were provided as patch by Jan Kruis (jan-kruis@SF), see https://sourceforge.net/tracker/?func=detail&aid=3383236&group_id=191583&atid=937966 git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1169 a1433add-5e2c-0410-b055-b7f2511e0802
2011-08-15 01:12:20 +02:00
}
//set a default, reset fields for coming back selection
2018-01-26 15:45:57 +01:00
if ($tSubject == '') {
$tSubject = html_entity_decode($PALANG['pUsersVacation_subject_text'], ENT_QUOTES, 'UTF-8');
}
if ($tBody == '') {
$tBody = html_entity_decode($PALANG['pUsersVacation_body_text'], ENT_QUOTES, 'UTF-8');
}
}
2018-01-26 15:45:57 +01:00
if ($_SERVER['REQUEST_METHOD'] == "POST") {
if (safepost('token') != $_SESSION['PFA_token']) {
die('Invalid token!');
}
$tActiveFrom = (new \DateTime(safepost('fActiveFrom')));
$tActiveUntil = (new \DateTime(safepost('fActiveUntil')));
$tSubject = safepost('fSubject');
$fSubject = $tSubject;
$tBody = safepost('fBody');
$fBody = $tBody;
2018-01-26 15:45:57 +01:00
$tInterval_Time = safepost('fInterval_Time');
$action = safepost('action');
2018-01-26 15:45:57 +01:00
//set a default, reset fields for coming back selection
if ($tSubject == '') {
$tSubject = html_entity_decode($PALANG['pUsersVacation_subject_text'], ENT_QUOTES, 'UTF-8');
}
if ($tBody == '') {
$tBody = html_entity_decode($PALANG['pUsersVacation_body_text'], ENT_QUOTES, 'UTF-8');
}
2018-01-26 15:45:57 +01:00
if (isset($choice_of_reply[$tInterval_Time])) {
2021-02-17 22:29:18 +01:00
$fInterval_Time = (int) $tInterval_Time;
2018-01-26 15:45:57 +01:00
} else {
$fInterval_Time = 0;
}
2018-01-26 15:45:57 +01:00
// if they've set themselves change OR back, delete any record of vacation emails.
// the user is going away - set the goto alias and vacation table as necessary.
Merge users/vacation.php and edit-vacation.php into vacation.php vacation.php - result of merging edit-vacation.php and users/vacation.php - vacation.php comes with the svn history of edit-vacation.php - display "vacation already active" (only) in user mode if vacation is active (would be useful in admin mode too, but needs a text change) - various comment updates - add username in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] using sprintf - change compared to Jan Kruis' patch: - set return url for users to main.php instead of users/main.php - set return url for admins after setting $fDomain. Otherwise the return url does not contain the domain. - removed unused variable $tDomain users/vacation.php: - require(../vacation.php) - remove everything else - whitespace changes in the license header - note: this is completely different from Jan Kruis' patch - his intention was to remove this file and use ../vacation.php. However, with his way all links in the users menu would point to the wrong place/directory edit-vacation.php: - deleted templates/vacation.tpl - display username only in admin mode templates/list-virtual_mailbox.tpl - link changed to merged vacation.php languages/en.lang - add username in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] as sprintf variable - (comments added by Jan Kruis' patch are not part of this commit) languages/nl.lang - translation updates - already contains the sprintf variable in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] (updates for other *.lang files follow in another commit) The following parts of Jan Kruis' patch are not part of this commit: - rejected: - variables.inc.php: don't add $Admin_role and $Return_url If we initialize them, it should be done directly in (edit-)vacation.php, but the current code always sets them already in all cases. - templates/users_main.tpl: do not change url for vacation.php - postponed: - added comments in en.lang about obsolete texts Most parts of this commit (see exceptions above) were provided as patch by Jan Kruis (jan-kruis@SF), see https://sourceforge.net/tracker/?func=detail&aid=3383236&group_id=191583&atid=937966 git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1169 a1433add-5e2c-0410-b055-b7f2511e0802
2011-08-15 01:12:20 +02:00
2018-01-26 15:45:57 +01:00
//Set the vacation data for $fUsername
if ($action == 'fChange') {
## check if ActiveUntil is not back in time,
2018-01-26 15:45:57 +01:00
## because vacation.pl will report SMTP recipient $smtp_recipient which resolves to $email does not have an active vacation (rv: $rv, email: $email)"
## and will not send message
if (($tActiveUntil >= $now && ($tActiveUntil >= $tActiveFrom))) {
if (!$vh->set_away($fSubject, $fBody, $fInterval_Time, $tActiveFrom->format('Y-m-d H:i'), $tActiveUntil->format('Y-m-d H:i'))) {
2018-01-26 15:45:57 +01:00
$error = 1;
}
} else {
if ($tActiveUntil < $now) {
2018-01-26 15:45:57 +01:00
flash_error($PALANG['pVacation_until_before_today']);
} else {
flash_error($PALANG['pVacation_until_before_from']);
}
$error = 1;
}
}
//if change, remove old one, then perhaps set new one
if ($action == 'fBack') {
2018-01-26 15:45:57 +01:00
if (!$vh->remove()) {
$error = 1;
}
}
Merge users/vacation.php and edit-vacation.php into vacation.php vacation.php - result of merging edit-vacation.php and users/vacation.php - vacation.php comes with the svn history of edit-vacation.php - display "vacation already active" (only) in user mode if vacation is active (would be useful in admin mode too, but needs a text change) - various comment updates - add username in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] using sprintf - change compared to Jan Kruis' patch: - set return url for users to main.php instead of users/main.php - set return url for admins after setting $fDomain. Otherwise the return url does not contain the domain. - removed unused variable $tDomain users/vacation.php: - require(../vacation.php) - remove everything else - whitespace changes in the license header - note: this is completely different from Jan Kruis' patch - his intention was to remove this file and use ../vacation.php. However, with his way all links in the users menu would point to the wrong place/directory edit-vacation.php: - deleted templates/vacation.tpl - display username only in admin mode templates/list-virtual_mailbox.tpl - link changed to merged vacation.php languages/en.lang - add username in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] as sprintf variable - (comments added by Jan Kruis' patch are not part of this commit) languages/nl.lang - translation updates - already contains the sprintf variable in $PALANG[pVacation_result_removed] and $PALANG[pVacation_result_added] (updates for other *.lang files follow in another commit) The following parts of Jan Kruis' patch are not part of this commit: - rejected: - variables.inc.php: don't add $Admin_role and $Return_url If we initialize them, it should be done directly in (edit-)vacation.php, but the current code always sets them already in all cases. - templates/users_main.tpl: do not change url for vacation.php - postponed: - added comments in en.lang about obsolete texts Most parts of this commit (see exceptions above) were provided as patch by Jan Kruis (jan-kruis@SF), see https://sourceforge.net/tracker/?func=detail&aid=3383236&group_id=191583&atid=937966 git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1169 a1433add-5e2c-0410-b055-b7f2511e0802
2011-08-15 01:12:20 +02:00
// If NO error then diplay flash message and go back to right url where we came from
if ($error == 0) {
if ($action == 'fBack') {
flash_info(sprintf($PALANG['pVacation_result_removed'], htmlentities($tUseremail)));
header("Location: $Return_url");
exit;
}
if ($action == 'fChange') {
flash_info(sprintf($PALANG['pVacation_result_added'], htmlentities($tUseremail)));
header("Location: $Return_url");
exit;
}
} else {
flash_error(sprintf($PALANG['pVacation_result_error'], htmlentities($fUsername)));
2018-01-26 15:45:57 +01:00
}
}
if (!$details['active']) {
2018-01-26 15:45:57 +01:00
# if vacation is disabled, there's no point in displaying the date of the last vacation ;-)
# (which also means users would have to scroll in the calendar a lot)
# so let's be user-friendly and set today's date (but only if the last vacation is in the past)
if ($tActiveFrom < $now) {
$tActiveFrom = $now;
2018-01-26 15:45:57 +01:00
}
if ($tActiveUntil < $now) {
$tActiveUntil = $now;
2018-01-26 15:45:57 +01:00
}
}
2018-01-26 15:45:57 +01:00
$smarty->assign('tUseremail', $tUseremail);
$smarty->assign('tSubject', $tSubject);
$smarty->assign('tBody', $tBody);
$smarty->assign('tActiveFrom', $tActiveFrom->format(DateTime::ISO8601));
$smarty->assign('tActiveUntil', $tActiveUntil->format(DateTime::ISO8601));
2018-01-26 15:45:57 +01:00
$smarty->assign('select_options', $choice_of_reply);
$smarty->assign('tInterval_Time', $tInterval_Time);
$smarty->assign('smarty_template', 'vacation');
$smarty->display('index.tpl');
/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */