mirror of
https://github.com/itflow-org/itflow
synced 2026-08-31 20:05:12 +00:00
Add Holiday / Closure Days to SLA to pause SLA timer on defined days, also has a US Holiday Importer
This commit is contained in:
26
admin/database_updates/2.7.4.php
Normal file
26
admin/database_updates/2.7.4.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ITFlow - Database update to version 2.7.4 (from 2.7.3)
|
||||
* Included by admin/database_updates.php - do not access directly
|
||||
*/
|
||||
|
||||
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
|
||||
|
||||
// Closure days for the SLA business calendar. A date listed here yields no
|
||||
// business minutes at all, exactly like a weekday that is not a business
|
||||
// day - holidays are a calendar concept, not a per-ticket pause, so they
|
||||
// never touch sla_history.
|
||||
//
|
||||
// holiday_date is UNIQUE so the US federal holiday generator can be run
|
||||
// repeatedly (and over a year that was partly entered by hand) without
|
||||
// creating duplicates.
|
||||
|
||||
mysqli_query($mysqli, "CREATE TABLE IF NOT EXISTS `business_holidays` (
|
||||
`holiday_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`holiday_date` date NOT NULL,
|
||||
`holiday_name` varchar(200) NOT NULL,
|
||||
`holiday_created_at` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
PRIMARY KEY (`holiday_id`),
|
||||
UNIQUE KEY `holiday_date` (`holiday_date`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci");
|
||||
40
admin/modals/sla/holiday_add.php
Normal file
40
admin/modals/sla/holiday_add.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
require_once '../../includes/modal_header.php';
|
||||
ob_start();
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fas fa-fw fa-calendar-times me-2"></i>New Closure Day</h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label>Date <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-calendar-day"></i></span>
|
||||
<input type="date" class="form-control" name="holiday_date" required autofocus>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Name <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-tag"></i></span>
|
||||
<input type="text" class="form-control" name="holiday_name" placeholder="e.g. Christmas Day, Office closed for move" maxlength="200" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<small class="text-muted">SLA clocks do not run on this day at all, the same as a day outside your business days. Open tickets have their targets recalculated when you save.</small>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="add_holiday" class="btn btn-primary text-bold"><i class="fas fa-check me-2"></i>Add</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fas fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
@@ -113,12 +113,7 @@ if (isset($_POST['edit_sla_settings'])) {
|
||||
getSlaSettings(true);
|
||||
|
||||
// Business hours feed the due date math - re-stamp open SLA tickets
|
||||
$restamped = 0;
|
||||
$sql_tickets = mysqli_query($mysqli, "SELECT ticket_id, ticket_sla_id FROM tickets WHERE ticket_sla_id > 0 AND ticket_closed_at IS NULL AND ticket_archived_at IS NULL");
|
||||
while ($ticket_row = mysqli_fetch_assoc($sql_tickets)) {
|
||||
applyTicketSla($ticket_row['ticket_id'], $ticket_row['ticket_sla_id']);
|
||||
$restamped++;
|
||||
}
|
||||
$restamped = restampOpenSlaTickets();
|
||||
|
||||
logAudit("Settings", "Edit", "$session_name edited SLA / business hours settings");
|
||||
|
||||
@@ -128,6 +123,105 @@ if (isset($_POST['edit_sla_settings'])) {
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['add_holiday'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
// Deliberately NOT validateDate() - that falls back to today's date on bad
|
||||
// input, which would silently close the office today. Reject instead. The
|
||||
// round-trip comparison also catches impossible dates like 2026-02-30,
|
||||
// which createFromFormat would otherwise roll forward into March.
|
||||
$holiday_date_input = $_POST['holiday_date'] ?? '';
|
||||
$parsed_date = DateTime::createFromFormat('Y-m-d', $holiday_date_input);
|
||||
|
||||
if (!$parsed_date || $parsed_date->format('Y-m-d') !== $holiday_date_input) {
|
||||
flashAlert("Enter a valid date for the closure day.", 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
$holiday_name_input = trim($_POST['holiday_name'] ?? '');
|
||||
if ($holiday_name_input === '') {
|
||||
flashAlert("Enter a name for the closure day.", 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
$holiday_date = escapeSql($holiday_date_input);
|
||||
$holiday_name = escapeSql($holiday_name_input);
|
||||
|
||||
// INSERT IGNORE rather than an error: the date is UNIQUE, and re-adding a day
|
||||
// that is already listed is a no-op the operator does not need telling about
|
||||
mysqli_query($mysqli, "INSERT IGNORE INTO business_holidays SET holiday_date = '$holiday_date', holiday_name = '$holiday_name'");
|
||||
|
||||
getBusinessHolidays(true);
|
||||
$restamped = restampOpenSlaTickets();
|
||||
|
||||
logAudit("Settings", "Create", "$session_name added SLA closure day $holiday_date - $holiday_name");
|
||||
|
||||
flashAlert("Closure day added - targets recalculated on $restamped open ticket(s)");
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['delete_holiday'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$holiday_id = intval($_POST['holiday_id']);
|
||||
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT holiday_date, holiday_name FROM business_holidays WHERE holiday_id = $holiday_id LIMIT 1"));
|
||||
if (!$row) {
|
||||
flashAlert("Closure day not found.", 'error');
|
||||
redirect();
|
||||
}
|
||||
$holiday_date = escapeSql($row['holiday_date']);
|
||||
$holiday_name = escapeSql($row['holiday_name']);
|
||||
|
||||
mysqli_query($mysqli, "DELETE FROM business_holidays WHERE holiday_id = $holiday_id");
|
||||
|
||||
getBusinessHolidays(true);
|
||||
$restamped = restampOpenSlaTickets();
|
||||
|
||||
logAudit("Settings", "Delete", "$session_name removed SLA closure day $holiday_date - $holiday_name");
|
||||
|
||||
flashAlert("Closure day removed - targets recalculated on $restamped open ticket(s)");
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['generate_holidays'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$holiday_year = intval($_POST['holiday_year']);
|
||||
|
||||
if ($holiday_year < 2000 || $holiday_year > 2100) {
|
||||
flashAlert("Enter a year between 2000 and 2100.", 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
// Existing rows win - INSERT IGNORE leaves a hand-entered name on a date the
|
||||
// generator also produces, so running this over a partly-filled year is safe
|
||||
$added = 0;
|
||||
foreach (usFederalHolidays($holiday_year) as $holiday) {
|
||||
$holiday_date = escapeSql($holiday['date']);
|
||||
$holiday_name = escapeSql($holiday['name']);
|
||||
mysqli_query($mysqli, "INSERT IGNORE INTO business_holidays SET holiday_date = '$holiday_date', holiday_name = '$holiday_name'");
|
||||
$added += mysqli_affected_rows($mysqli) > 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
getBusinessHolidays(true);
|
||||
$restamped = restampOpenSlaTickets();
|
||||
|
||||
logAudit("Settings", "Create", "$session_name generated $added US federal holiday closure day(s) for $holiday_year");
|
||||
|
||||
flashAlert("Added $added US federal holiday(s) for $holiday_year - targets recalculated on $restamped open ticket(s)");
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['save_sla_assignments'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
@@ -22,6 +22,15 @@ while ($active_sla_row = mysqli_fetch_assoc($sql_active_slas)) {
|
||||
$active_slas[intval($active_sla_row['sla_id'])] = $active_sla_row['sla_name'];
|
||||
}
|
||||
|
||||
// Closure days, newest first - past ones are kept as a record of what was applied
|
||||
$holidays = [];
|
||||
$sql_holidays = mysqli_query($mysqli, "SELECT holiday_date, holiday_id, holiday_name FROM business_holidays ORDER BY holiday_date DESC");
|
||||
while ($holiday_row = mysqli_fetch_assoc($sql_holidays)) {
|
||||
$holidays[] = $holiday_row;
|
||||
}
|
||||
|
||||
$holiday_year = intval(date('Y'));
|
||||
|
||||
// Global default assignments: [priority] = sla_id (per-client overrides live on the client edit modal)
|
||||
$assignments = [];
|
||||
$sql_assignments = mysqli_query($mysqli, "SELECT sla_assignment_priority, sla_assignment_sla_id FROM sla_assignments WHERE sla_assignment_client_id = 0");
|
||||
@@ -196,4 +205,70 @@ while ($assignment_row = mysqli_fetch_assoc($sql_assignments)) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card card-dark">
|
||||
<div class="card-header py-2">
|
||||
<h3 class="card-title mt-2"><i class="fas fa-fw fa-calendar-times me-2"></i>Holidays & Closure Days</h3>
|
||||
<div class="card-tools">
|
||||
<form action="post.php" method="post" class="d-inline" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<div class="input-group input-group-sm d-inline-flex w-auto align-middle me-2">
|
||||
<input type="number" class="form-control" name="holiday_year" min="2000" max="2100" value="<?= $holiday_year ?>" required>
|
||||
<button type="submit" name="generate_holidays" class="btn btn-secondary"><i class="fas fa-magic me-2"></i>Add US Holidays</button>
|
||||
</div>
|
||||
</form>
|
||||
<button type="button" class="btn btn-sm btn-primary ajax-modal" data-modal-url="modals/sla/holiday_add.php"><i class="fas fa-plus me-2"></i>New Closure Day</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
|
||||
<p class="text-muted">
|
||||
SLA clocks stop completely on these dates, the same as a day outside your business days.
|
||||
Use them for public holidays or any other day the office is shut. Adding or removing one
|
||||
recalculates the targets on every open ticket.
|
||||
</p>
|
||||
|
||||
<?php if (empty($holidays)) { ?>
|
||||
<p class="text-secondary mb-0">No closure days configured - SLA clocks run on every business day.</p>
|
||||
<?php } else { ?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-borderless table-hover align-middle">
|
||||
<thead class="border-bottom">
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Day</th>
|
||||
<th>Name</th>
|
||||
<th class="text-end">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($holidays as $holiday) {
|
||||
$holiday_id = intval($holiday['holiday_id']);
|
||||
$holiday_date_raw = $holiday['holiday_date'];
|
||||
$holiday_date = escapeHtml(date('M j, Y', strtotime($holiday_date_raw)));
|
||||
$holiday_day = escapeHtml(date('l', strtotime($holiday_date_raw)));
|
||||
$holiday_name = escapeHtml($holiday['holiday_name']);
|
||||
$holiday_is_past = strtotime($holiday_date_raw) < strtotime(date('Y-m-d'));
|
||||
?>
|
||||
<tr class="<?php if ($holiday_is_past) { echo "text-secondary"; } ?>">
|
||||
<td><?= $holiday_date ?></td>
|
||||
<td><?= $holiday_day ?></td>
|
||||
<td><?= $holiday_name ?></td>
|
||||
<td class="text-end">
|
||||
<form action="post.php" method="post" onsubmit="return confirm('Remove this closure day? Open ticket targets will be recalculated.');">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="holiday_id" value="<?= $holiday_id ?>">
|
||||
<button type="submit" name="delete_holiday" class="btn btn-sm btn-light border"><i class="fas fa-fw fa-trash text-danger"></i></button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once "../includes/footer.php";
|
||||
|
||||
Reference in New Issue
Block a user