This commit is contained in:
David Goodwin committed 2021-01-12 22:08:35 +00:00
1 parent b7c247606f
commit a20f05ca71
2 files changed
+84 -84

No files matched your search

+60 -67
View File
@@ -41,10 +41,12 @@ require_once('common.php');
$CONF = Config::getInstance()->getAll();
$smarty = PFASmarty::getInstance();
$now = new \DateTime();
// only allow admins to change someone else's 'stuff'
if (authentication_has_role('admin')) {
$Admin_role = 1 ;
$Admin_role = 1;
$fUsername = safeget('username');
list(/*NULL*/, $fDomain) = explode('@', $fUsername);
$Return_url = "list-virtual.php?domain=" . urlencode($fDomain);
@@ -55,12 +57,14 @@ if (authentication_has_role('admin')) {
die("Invalid username!"); # TODO: better error message
}
} else {
$Admin_role = 0 ;
$Admin_role = 0;
$Return_url = "main.php";
authentication_require_role('user');
$fUsername = authentication_get_username();
}
$smarty->assign('return_url', $Return_url);
// is vacation support enabled in $CONF ?
if ($CONF['vacation'] == 'NO') {
header("Location: $Return_url");
@@ -78,28 +82,27 @@ foreach (array_keys($choice_of_reply) as $key) {
$choice_of_reply[$key] = Config::Lang($choice_of_reply[$key]);
}
$tUseremail = null;
$tUseremail = $fUsername;
$tInterval_Time = null;
$tBody = null;
$tSubject = null;
$details = ['active' => 0];
$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];
}
if ($_SERVER['REQUEST_METHOD'] == "GET") {
$tSubject = '';
$tBody = '';
$tActiveFrom = '';
$tActiveUntil = '';
$tUseremail = $fUsername;
$tInterval_Time = '';
$details = $vh->get_details();
if (is_array($details )) {
$tSubject = $details['subject'];
$tBody = $details['body'];
$tInterval_Time = $details['interval_time'];
$tActiveFrom = $details['activeFrom'];
$tActiveUntil = $details['activeUntil'];
}
if ($vh->check_vacation()) {
flash_info(sprintf($PALANG['pUsersVacation_welcome_text'], htmlentities($tUseremail)));
@@ -119,25 +122,18 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
die('Invalid token!');
}
if (isset($_POST['fCancel'])) {
header("Location: $Return_url");
exit(0);
}
$tActiveFrom = date("Y-m-d 00:00:00", strtotime(safepost('fActiveFrom')));
$tActiveUntil = date("Y-m-d 23:59:59", strtotime(safepost('fActiveUntil')));
$tActiveFrom = (new \DateTime(safepost('fActiveFrom')));
$tActiveUntil = (new \DateTime(safepost('fActiveUntil')));
$tSubject = safepost('fSubject');
$fSubject = $tSubject;
$tBody = safepost('fBody');
$fBody = $tBody;
$tSubject = safepost('fSubject');
$fSubject = $tSubject;
$tBody = safepost('fBody');
$fBody = $tBody;
$tInterval_Time = safepost('fInterval_Time');
$fChange = escape_string(safepost('fChange'));
$fBack = escape_string(safepost('fBack'));
$tUseremail = $fUsername;
$action = safepost('action');
//set a default, reset fields for coming back selection
if ($tSubject == '') {
@@ -158,18 +154,20 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
//Set the vacation data for $fUsername
if (!empty($fChange)) {
if ($action == 'fChange') {
## check if ActiveUnitl is not back in time,
## check if ActiveUnitl is not back in time,
## 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 >= date("Y-m-d")) and ($tActiveUntil >= $tActiveFrom)) {
if (!$vh->set_away($fSubject, $fBody, $fInterval_Time, $tActiveFrom, $tActiveUntil)) {
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'))) {
$error = 1;
}
} else {
if ($tActiveUntil < date("Y-m-d")) {
if ($tActiveUntil < $now) {
flash_error($PALANG['pVacation_until_before_today']);
} else {
flash_error($PALANG['pVacation_until_before_from']);
@@ -179,54 +177,49 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
}
//if change, remove old one, then perhaps set new one
if (!empty($fBack)) {
if ($action == 'fBack') {
if (!$vh->remove()) {
$error = 1;
}
}
}
// If NO error then diplay flash message and go back to right url where we came from
if ($error == 0) {
if (!empty($fBack)) {
flash_info(sprintf($PALANG['pVacation_result_removed'], htmlentities($tUseremail)));
header("Location: $Return_url");
exit;
// 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)));
}
if (!empty($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)));
}
$today = date("Y-m-d");
if (empty($tActiveFrom)) {
$tActiveFrom = $today;
}
if (empty($tActiveUntil)) {
$tActiveUntil = $today;
}
if (!$details['active']) {
if (! $details['active']) {
# 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 < $today) {
$tActiveFrom = $today;
if ($tActiveFrom < $now) {
$tActiveFrom = $now;
}
if ($tActiveUntil < $today) {
$tActiveUntil = $today;
if ($tActiveUntil < $now) {
$tActiveUntil = $now;
}
}
$smarty->assign('tUseremail', $tUseremail);
$smarty->assign('tSubject', $tSubject);
$smarty->assign('tBody', $tBody);
$smarty->assign('tActiveFrom', date("d.m.Y", strtotime($tActiveFrom)));
$smarty->assign('tActiveUntil', date("d.m.Y", strtotime($tActiveUntil)));
$smarty->assign('tActiveFrom', $tActiveFrom->format(DateTime::ISO8601));
$smarty->assign('tActiveUntil', $tActiveUntil->format(DateTime::ISO8601));
$smarty->assign('select_options', $choice_of_reply);
$smarty->assign('tInterval_Time', $tInterval_Time);
$smarty->assign('smarty_template', 'vacation');
+24 -17
View File
@@ -29,7 +29,8 @@
<input type='hidden' name="fActiveUntil" id="fActiveUntil" value="{$tActiveUntil}"
class="form-control hidden"/>
<div class="input-group date" id="datetimepicker-fActiveUntil">
<input type='text' name="fActiveUntilForm" id="fActiveUntilForm" value="{$tActiveUntil}"
<input type='text'
name="fActiveUntilForm" id="fActiveUntilForm" value="{$tActiveUntil}"
class="form-control" readonly="readonly"/>
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
@@ -60,52 +61,58 @@
</div>
<div class="panel-footer">
<div class="btn-toolbar" role="toolbar">
<div class="pull-right">
<button class="btn btn-secondary" type="submit" name="fCancel">{$PALANG.exit}</button>
<button class="btn btn-primary" type="submit" name="fChange">{$PALANG.pEdit_vacation_set}</button>
<a href="{$return_url}" class="btn btn-secondary bg-info" title="Go back">{$PALANG.exit}</a>
<button class="btn btn-primary" type="submit" name="fBack">{$PALANG.pEdit_vacation_remove}</button>
<button class="btn btn-primary " type="submit" name="action"
value="fChange">{$PALANG.pEdit_vacation_set}</button>
<button class="btn btn-danger " type="submit" name="action"
value="fBack">{$PALANG.pEdit_vacation_remove}</button>
</div>
</div>
</div>
</div>
</div>
</form>
{literal}
<script type="text/javascript">
{/literal}
{if isset($smarty.session.lang)}var locale = '{$smarty.session.lang}';{/if}
{literal}
$(function () {
// See: https://momentjs.com/docs/#/displaying/format/ for format spec.
// See: https://getdatepicker.com/4/Options/ for docs
$('#datetimepicker-fActiveFrom').datetimepicker({
ignoreReadonly: true,
locale: locale,
// locale: locale,
showTodayButton: true,
showClear: true,
showClose: true,
allowInputToggle: true,
format: 'L',
format: 'YYYY/MM/DD HH:mm', // should use 'L' but it's crappy mm/dd/YYYY format for me in the U.K.
date: $('#fActiveFrom').val(),
});
$('#datetimepicker-fActiveUntil').datetimepicker({
ignoreReadonly: true,
locale: locale,
// locale: locale,
showTodayButton: true,
showClear: true,
showClose: true,
allowInputToggle: true,
format: 'L',
format: 'YYYY/MM/DD HH:mm', // should use 'L' but it's crappy mm/dd/YYYY format for me in the U.K.
date: $('#fActiveUntil').val(),
useCurrent: false //Important! See issue #1075
});
$("#datetimepicker-fActiveFrom").on("dp.change", function (e) {
$('#datetimepicker-fActiveUntil').data("DateTimePicker").minDate(e.date);
$('#fActiveFrom').val((e.date) ? e.date.format('YYYY-MM-DD') : '').trigger("change");
$('#fActiveFrom').val((e.date) ? e.date.format() : '').trigger("change");
});
$("#datetimepicker-fActiveUntil").on("dp.change", function (e) {
$('#datetimepicker-fActiveFrom').data("DateTimePicker").maxDate(e.date);
$('#fActiveUntil').val((e.date) ? e.date.format('YYYY-MM-DD') : '').trigger("change");
$('#fActiveUntil').val((e.date) ? e.date.format() : '').trigger("change");
});
});
{/literal}
</script>
{/literal}