9916daa904
- updateTicketField() now targets .lt-frame-ticket[data-priority] (TDS v1.2)
instead of old .priority-indicator / .ticket-container selectors
- All 7 admin views: keyboard-shortcuts.js now uses dynamic ?v={$_v}
instead of hardcoded unversioned path
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
307 lines
14 KiB
PHP
307 lines
14 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../../middleware/SecurityHeadersMiddleware.php';
|
|
require_once __DIR__ . '/../../middleware/CsrfMiddleware.php';
|
|
$nonce = SecurityHeadersMiddleware::getNonce();
|
|
$pageTitle = 'Recurring Tickets';
|
|
$activeNav = 'admin-recurring';
|
|
$_v = $GLOBALS['config']['ASSET_VERSION'] ?? '1';
|
|
$pageStyles = ["/assets/css/dashboard.css?v={$_v}"];
|
|
$pageScripts = ["/assets/js/keyboard-shortcuts.js?v={$_v}"];
|
|
include __DIR__ . '/../../views/layout_header.php';
|
|
?>
|
|
|
|
<div class="lt-page-header">
|
|
<div class="lt-flex lt-flex-gap-sm lt-flex-align-center">
|
|
<a href="/" class="lt-btn lt-btn-ghost lt-btn-sm">← Dashboard</a>
|
|
<span class="lt-text-muted lt-text-xs">/</span>
|
|
<span class="lt-text-muted lt-text-xs">Admin: Recurring Tickets</span>
|
|
</div>
|
|
<button type="button" class="lt-btn lt-btn-primary" data-action="show-create-modal">+ NEW RECURRING TICKET</button>
|
|
</div>
|
|
|
|
<div class="lt-frame">
|
|
<span class="lt-frame-bl">╚</span><span class="lt-frame-br">╝</span>
|
|
<div class="lt-section-header">Scheduled Tickets</div>
|
|
<div class="lt-section-body">
|
|
<p class="lt-text-sm lt-text-muted" style="margin-bottom:0.75rem">
|
|
Recurring tickets are automatically created on a schedule. Use <code>{{date}}</code>, <code>{{month}}</code>, <code>{{year}}</code> in title templates.
|
|
</p>
|
|
<div class="lt-table-wrap">
|
|
<table class="lt-table lt-table-responsive" aria-label="Recurring tickets">
|
|
<thead>
|
|
<tr>
|
|
<th scope="col">Title Template</th>
|
|
<th scope="col">Schedule</th>
|
|
<th scope="col">Category</th>
|
|
<th scope="col">Assigned To</th>
|
|
<th scope="col">Next Run</th>
|
|
<th scope="col">Status</th>
|
|
<th scope="col">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($recurringTickets)): ?>
|
|
<tr><td colspan="7" class="lt-empty">No recurring tickets configured. Create schedules to auto-generate tickets.</td></tr>
|
|
<?php else: foreach ($recurringTickets as $rt): ?>
|
|
<?php
|
|
$schedule = ucfirst($rt['schedule_type']);
|
|
if ($rt['schedule_type'] === 'weekly') {
|
|
$days = ['', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
|
$schedule .= ' (' . ($days[$rt['schedule_day']] ?? '?') . ')';
|
|
} elseif ($rt['schedule_type'] === 'monthly') {
|
|
$schedule .= ' (Day ' . $rt['schedule_day'] . ')';
|
|
}
|
|
$schedule .= ' @ ' . substr($rt['schedule_time'], 0, 5);
|
|
?>
|
|
<tr>
|
|
<td data-label="Title"><strong><?= htmlspecialchars($rt['title_template']) ?></strong></td>
|
|
<td data-label="Schedule" class="lt-text-xs lt-text-cyan"><?= htmlspecialchars($schedule) ?></td>
|
|
<td data-label="Category" class="lt-text-xs"><?= htmlspecialchars($rt['category']) ?></td>
|
|
<td data-label="Assigned To" class="lt-text-xs">
|
|
<?= htmlspecialchars($rt['assigned_name'] ?? $rt['assigned_username'] ?? 'Unassigned') ?>
|
|
</td>
|
|
<td data-label="Next Run" class="lt-text-xs lt-text-muted">
|
|
<?= date('M d, Y H:i', strtotime($rt['next_run_at'])) ?>
|
|
</td>
|
|
<td data-label="Status">
|
|
<span class="lt-status <?= $rt['is_active'] ? 'lt-status-open' : 'lt-status-closed' ?>">
|
|
<?= $rt['is_active'] ? 'Active' : 'Inactive' ?>
|
|
</span>
|
|
</td>
|
|
<td data-label="Actions">
|
|
<div class="lt-btn-group">
|
|
<button type="button" class="lt-btn lt-btn-sm"
|
|
data-action="edit-recurring" data-id="<?= $rt['recurring_id'] ?>">EDIT</button>
|
|
<button type="button" class="lt-btn lt-btn-sm"
|
|
data-action="toggle-recurring" data-id="<?= $rt['recurring_id'] ?>">
|
|
<?= $rt['is_active'] ? 'PAUSE' : 'RESUME' ?>
|
|
</button>
|
|
<button type="button" class="lt-btn lt-btn-sm lt-btn-danger"
|
|
data-action="delete-recurring" data-id="<?= $rt['recurring_id'] ?>">DEL</button>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; endif ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Create/Edit Modal -->
|
|
<div class="lt-modal-overlay" id="recurringModal" aria-hidden="true" role="dialog"
|
|
aria-modal="true" aria-labelledby="recModalTitle">
|
|
<div class="lt-modal">
|
|
<div class="lt-modal-header">
|
|
<span class="lt-modal-title" id="recModalTitle">Create Recurring Ticket</span>
|
|
<button type="button" class="lt-modal-close" data-modal-close aria-label="Close">✕</button>
|
|
</div>
|
|
<form id="recurringForm">
|
|
<input type="hidden" id="recurring_id" name="recurring_id">
|
|
<div class="lt-modal-body">
|
|
<div class="lt-form-group">
|
|
<label class="lt-label" for="rec_title_template">Title Template *</label>
|
|
<input type="text" id="rec_title_template" name="title_template" class="lt-input" required
|
|
placeholder="Use {{date}}, {{month}}, {{year}}">
|
|
</div>
|
|
<div class="lt-form-group">
|
|
<label class="lt-label" for="rec_description_template">Description Template</label>
|
|
<textarea id="rec_description_template" name="description_template"
|
|
class="lt-input lt-textarea" rows="6"></textarea>
|
|
</div>
|
|
<div class="lt-form-group">
|
|
<label class="lt-label" for="schedule_type">Schedule Type *</label>
|
|
<select id="schedule_type" name="schedule_type" class="lt-select" required
|
|
data-action="update-schedule-options">
|
|
<option value="daily">Daily</option>
|
|
<option value="weekly">Weekly</option>
|
|
<option value="monthly">Monthly</option>
|
|
</select>
|
|
</div>
|
|
<div class="lt-form-group is-hidden" id="schedule_day_row">
|
|
<label class="lt-label" for="schedule_day">Schedule Day</label>
|
|
<select id="schedule_day" name="schedule_day" class="lt-select"></select>
|
|
</div>
|
|
<div class="lt-form-group">
|
|
<label class="lt-label" for="schedule_time">Schedule Time *</label>
|
|
<input type="time" id="schedule_time" name="schedule_time" class="lt-input"
|
|
value="09:00" required style="max-width:12rem">
|
|
</div>
|
|
<div class="create-ticket-meta-grid">
|
|
<div class="lt-form-group">
|
|
<label class="lt-label" for="rec-category">Category</label>
|
|
<select id="rec-category" name="category" class="lt-select">
|
|
<?php foreach (['General','Hardware','Software','Network','Security'] as $c): ?>
|
|
<option value="<?= $c ?>"><?= $c ?></option>
|
|
<?php endforeach ?>
|
|
</select>
|
|
</div>
|
|
<div class="lt-form-group">
|
|
<label class="lt-label" for="rec-type">Type</label>
|
|
<select id="rec-type" name="type" class="lt-select">
|
|
<?php foreach (['Issue','Maintenance','Install','Task','Upgrade','Problem'] as $t): ?>
|
|
<option value="<?= $t ?>"><?= $t ?></option>
|
|
<?php endforeach ?>
|
|
</select>
|
|
</div>
|
|
<div class="lt-form-group">
|
|
<label class="lt-label" for="rec-priority">Priority</label>
|
|
<select id="rec-priority" name="priority" class="lt-select">
|
|
<option value="1">P1 — Critical</option>
|
|
<option value="2">P2 — High</option>
|
|
<option value="3">P3 — Medium</option>
|
|
<option value="4" selected>P4 — Low</option>
|
|
<option value="5">P5 — Lowest</option>
|
|
</select>
|
|
</div>
|
|
<div class="lt-form-group">
|
|
<label class="lt-label" for="assigned_to">Assign To</label>
|
|
<select id="assigned_to" name="assigned_to" class="lt-select">
|
|
<option value="">Unassigned</option>
|
|
<!-- Populated by JS -->
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="lt-modal-footer">
|
|
<button type="submit" class="lt-btn lt-btn-primary">SAVE</button>
|
|
<button type="button" class="lt-btn lt-btn-ghost" data-modal-close>CANCEL</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<script nonce="<?= $nonce ?>">
|
|
document.addEventListener('click', function (e) {
|
|
var target = e.target.closest('[data-action]');
|
|
if (!target) return;
|
|
switch (target.getAttribute('data-action')) {
|
|
case 'show-create-modal': showCreateModal(); break;
|
|
case 'edit-recurring': editRecurring(target.getAttribute('data-id')); break;
|
|
case 'toggle-recurring': toggleRecurring(target.getAttribute('data-id')); break;
|
|
case 'delete-recurring': deleteRecurring(target.getAttribute('data-id')); break;
|
|
}
|
|
});
|
|
|
|
document.addEventListener('change', function (e) {
|
|
var target = e.target.closest('[data-action]');
|
|
if (!target) return;
|
|
if (target.getAttribute('data-action') === 'update-schedule-options') updateScheduleOptions();
|
|
});
|
|
|
|
document.getElementById('recurringForm').addEventListener('submit', function (e) {
|
|
saveRecurring(e);
|
|
});
|
|
|
|
if (window.lt) lt.keys.initDefaults();
|
|
|
|
function updateScheduleOptions() {
|
|
var type = document.getElementById('schedule_type').value;
|
|
var dayRow = document.getElementById('schedule_day_row');
|
|
var daySelect = document.getElementById('schedule_day');
|
|
daySelect.innerHTML = '';
|
|
if (type === 'daily') {
|
|
dayRow.classList.add('is-hidden');
|
|
} else if (type === 'weekly') {
|
|
dayRow.classList.remove('is-hidden');
|
|
['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'].forEach(function (day, i) {
|
|
var opt = document.createElement('option');
|
|
opt.value = String(i + 1);
|
|
opt.textContent = day;
|
|
daySelect.appendChild(opt);
|
|
});
|
|
} else if (type === 'monthly') {
|
|
dayRow.classList.remove('is-hidden');
|
|
for (var i = 1; i <= 28; i++) {
|
|
var opt = document.createElement('option');
|
|
opt.value = String(i);
|
|
opt.textContent = 'Day ' + i;
|
|
daySelect.appendChild(opt);
|
|
}
|
|
}
|
|
}
|
|
|
|
function showCreateModal() {
|
|
document.getElementById('recModalTitle').textContent = 'Create Recurring Ticket';
|
|
document.getElementById('recurringForm').reset();
|
|
document.getElementById('recurring_id').value = '';
|
|
updateScheduleOptions();
|
|
lt.modal.open('recurringModal');
|
|
}
|
|
|
|
function editRecurring(id) {
|
|
lt.api.get('/api/manage_recurring.php?id=' + id)
|
|
.then(function (data) {
|
|
if (data.success && data.recurring) {
|
|
var rt = data.recurring;
|
|
document.getElementById('recurring_id').value = rt.recurring_id;
|
|
document.getElementById('rec_title_template').value = rt.title_template;
|
|
document.getElementById('rec_description_template').value = rt.description_template || '';
|
|
document.getElementById('schedule_type').value = rt.schedule_type;
|
|
updateScheduleOptions();
|
|
document.getElementById('schedule_day').value = rt.schedule_day || '';
|
|
document.getElementById('schedule_time').value = rt.schedule_time ? rt.schedule_time.substring(0, 5) : '09:00';
|
|
document.getElementById('rec-category').value = rt.category || 'General';
|
|
document.getElementById('rec-type').value = rt.type || 'Issue';
|
|
document.getElementById('rec-priority').value = rt.priority || 4;
|
|
document.getElementById('assigned_to').value = rt.assigned_to || '';
|
|
document.getElementById('recModalTitle').textContent = 'Edit Recurring Ticket';
|
|
lt.modal.open('recurringModal');
|
|
} else {
|
|
lt.toast.error(data.error || 'Failed to load schedule');
|
|
}
|
|
}).catch(function () { lt.toast.error('Failed to load schedule'); });
|
|
}
|
|
|
|
function toggleRecurring(id) {
|
|
lt.api.post('/api/manage_recurring.php?action=toggle&id=' + id)
|
|
.then(function (data) {
|
|
if (data.success) window.location.reload();
|
|
else lt.toast.error(data.error || 'Failed to toggle');
|
|
}).catch(function () { lt.toast.error('Failed to toggle'); });
|
|
}
|
|
|
|
function deleteRecurring(id) {
|
|
showConfirmModal('Delete Schedule', 'Delete this recurring ticket schedule? This cannot be undone.', 'error', function () {
|
|
lt.api.delete('/api/manage_recurring.php?id=' + id)
|
|
.then(function (data) {
|
|
if (data.success) window.location.reload();
|
|
else lt.toast.error(data.error || 'Failed to delete');
|
|
}).catch(function () { lt.toast.error('Failed to delete'); });
|
|
});
|
|
}
|
|
|
|
function saveRecurring(e) {
|
|
e.preventDefault();
|
|
var form = new FormData(document.getElementById('recurringForm'));
|
|
var data = {};
|
|
form.forEach(function (v, k) { data[k] = v; });
|
|
var url = '/api/manage_recurring.php' + (data.recurring_id ? '?id=' + data.recurring_id : '');
|
|
var apiCall = data.recurring_id ? lt.api.put(url, data) : lt.api.post(url, data);
|
|
apiCall.then(function (result) {
|
|
if (result.success) window.location.reload();
|
|
else lt.toast.error(result.error || 'Failed to save');
|
|
}).catch(function () { lt.toast.error('Failed to save'); });
|
|
}
|
|
|
|
function loadUsers() {
|
|
lt.api.get('/api/get_users.php')
|
|
.then(function (data) {
|
|
if (data.success && data.users) {
|
|
var select = document.getElementById('assigned_to');
|
|
data.users.forEach(function (user) {
|
|
var opt = document.createElement('option');
|
|
opt.value = user.user_id;
|
|
opt.textContent = user.display_name || user.username;
|
|
select.appendChild(opt);
|
|
});
|
|
}
|
|
}).catch(function () { /* non-critical: assigned_to stays as manual input */ });
|
|
}
|
|
|
|
updateScheduleOptions();
|
|
loadUsers();
|
|
</script>
|
|
|
|
<?php include __DIR__ . '/../../views/layout_footer.php'; ?>
|