Ticket templates stage 1: templates now set up the whole ticket - category, priority, billable, agent, due time and tags (migration 3.1.9 adds them, the ticket_template_tags table and tickets.ticket_template_id) - and fill [Client], [Contact], [Asset], [Site], [Agent], [Project], [Ticket], [Date], [Month], [Quarter] and [Year] in the subject, details and tasks when a ticket is raised, leaving other bracketed text for whoever picks it up; tickets remember the template they came from and each template shows how many tickets it raised, how many are open and when it was last used; the template picker fills New Ticket, the New Tickets windows on the assets and clients lists and recurring tickets, and project templates use each template's setup and agent; Admin > Ticket Templates rebuilt with search, Current/Archived, Copy, Archive/Restore and New ticket from it, and each template gets a page showing the ticket it starts, its tasks in drag-to-sort order with time estimates, what it sets up, its placeholders and the tickets, recurring tickets and project templates that use it; template handling moved into functions/ticket_template.php with ticketTemplateFinish, tagKeepIds and tagIdsFromValues split out of tagSetForRecord, and template task editing moved to admin/post; fixes editing a template task moving it to the top of the list, client bulk tickets skipping the template's tasks and time estimates, and the client bulk window not validating the agent, priority and category, and adds an option there to raise each client's ticket for its primary contact; changelog updated

This commit is contained in:
johnnyq
2026-10-18 00:01:43 -04:00
parent 9457442804
commit 3f90d2b0d0
26 changed files with 1562 additions and 669 deletions

View File

@@ -2,6 +2,9 @@
require_once '../../includes/modal_header.php';
$template = [];
$template_tag_ids = [];
ob_start();
?>
@@ -13,53 +16,7 @@ ob_start();
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<div class="modal-body">
<div class="mb-3">
<label>Template Name <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-life-ring"></i></span>
<input type="text" class="form-control" name="name" placeholder="Template name" maxlength="200" required autofocus>
</div>
</div>
<div class="mb-3">
<label>Subject</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-angle-right"></i></span>
<input type="text" class="form-control" name="subject" placeholder="Subject" maxlength="500">
</div>
</div>
<div class="mb-3">
<textarea class="form-control tinymceTicket" name="details"></textarea>
</div>
<div class="mb-3">
<label>Description</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-angle-right"></i></span>
<input type="text" class="form-control" name="description" placeholder="Short description">
</div>
</div>
<div class="mb-3">
<label>Add it to a Project Template?</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-project-diagram"></i></span>
<select class="form-select select2" name="project_template">
<option value="0">- No -</option>
<?php
$sql_project_templates = mysqli_query($mysqli, "SELECT project_template_id, project_template_name FROM project_templates WHERE project_template_archived_at IS NULL ORDER BY project_template_name ASC");
while ($row = mysqli_fetch_assoc($sql_project_templates)) {
$project_template_id_select = intval($row['project_template_id']);
$project_template_name_select = escapeHtml($row['project_template_name']); ?>
<option value="<?= $project_template_id_select ?>"><?= $project_template_name_select ?></option>
<?php } ?>
</select>
</div>
</div>
<?php require __DIR__ . '/ticket_template_form.php'; ?>
</div>
<div class="modal-footer">
<button type="submit" name="add_ticket_template" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Create Template</button>

View File

@@ -1,51 +1,39 @@
<div class="modal" id="editTicketTemplateModal" tabindex="-1">
<?php
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fa fa-fw fa-life-ring me-2"></i>Editing Ticket Template: <?= $ticket_template_name ?></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'] ?>">
<input type="hidden" name="ticket_template_id" value="<?= $ticket_template_id ?>">
/*
* Edit a ticket template - the fields are ticket_template_form.php. Its tasks
* are changed on its page (admin/ticket_template.php).
*/
<div class="modal-body">
require_once '../../includes/modal_header.php';
<div class="mb-3">
<label>Template Name <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-life-ring"></i></span>
<input type="text" class="form-control" name="name" maxlength="200" value="<?= $ticket_template_name ?>" placeholder="Template name" required autofocus>
</div>
</div>
$template = ticketTemplateRow($_GET['id'] ?? 0);
<div class="mb-3">
<label>Subject</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-angle-right"></i></span>
<input type="text" class="form-control" name="subject" maxlength="500" value="<?= $ticket_template_subject ?>" placeholder="Subject">
</div>
</div>
ob_start();
<div class="mb-3">
<textarea class="form-control tinymceTicket" name="details"><?= $ticket_template_details ?></textarea>
</div>
if (!$template) { ?>
<div class="modal-body text-center text-secondary py-5">That ticket template is gone - it may have been deleted.</div>
<?php } else {
$ticket_template_id = intval($template['ticket_template_id']);
$template_tag_ids = ticketTemplateTagIds($ticket_template_id); ?>
<div class="mb-3">
<label>Description</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-angle-right"></i></span>
<input type="text" class="form-control" name="description" value="<?= $ticket_template_description ?>" placeholder="Short description">
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="edit_ticket_template" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Save</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
</div>
</div>
<div class="modal-header bg-dark">
<h5 class="modal-title text-truncate"><i class="fa fa-fw fa-life-ring me-2"></i>Ticket template: <strong><?= escapeHtml($template['ticket_template_name']) ?></strong></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'] ?>">
<input type="hidden" name="ticket_template_id" value="<?= $ticket_template_id ?>">
<div class="modal-body">
<?php require __DIR__ . '/ticket_template_form.php'; ?>
</div>
<div class="modal-footer">
<button type="submit" name="edit_ticket_template" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Save</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php }
require_once '../../../includes/modal_footer.php';

View File

@@ -0,0 +1,164 @@
<?php
/*
* A ticket template's fields - shared by ticket_template_add.php and
* ticket_template_edit.php, which set $template (ticketTemplateRow(), or []
* for a new one) and $template_tag_ids before including this. Posts what
* ticketTemplateFields() reads (functions/ticket_template.php).
*
* Two tabs: Ticket (its name, what it is for, the subject and details it
* starts with) and Sets up (category, priority, billing, agent, due time and
* tags - each left alone unless set).
*
* Should not be accessed directly.
*/
isset($mysqli) || die("Direct file access is not allowed");
$t = $template;
$due_hours = intval($t['ticket_template_due_hours'] ?? 0);
$due_in_days = $due_hours === 0 || $due_hours % 24 === 0;
$due_amount = $due_hours ? ($due_in_days ? intdiv($due_hours, 24) : $due_hours) : '';
$billable = array_key_exists('ticket_template_billable', $t) && $t['ticket_template_billable'] !== null ? (string) intval($t['ticket_template_billable']) : '';
$priority = (string) ($t['ticket_template_priority'] ?? '');
$assigned_to = intval($t['ticket_template_assigned_to'] ?? 0);
$placeholder_help = implode(', ', array_map(function ($name) {
return "[$name]";
}, array_keys(TICKET_PLACEHOLDERS)));
?>
<ul class="nav nav-pills nav-fill flex-nowrap overflow-auto mb-3 itflow-asset-form-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" data-bs-toggle="pill" href="#ticketTemplateFormTicket"><i class="fas fa-fw fa-life-ring me-2 d-none d-sm-inline"></i>Ticket</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#ticketTemplateFormSetUp"><i class="fas fa-fw fa-sliders-h me-2 d-none d-sm-inline"></i>Sets up</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane fade show active" id="ticketTemplateFormTicket">
<div class="row g-3">
<div class="col-md-6">
<label class="form-label">Template name <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-life-ring"></i></span>
<input type="text" class="form-control" name="name" placeholder="New Hire Onboarding" maxlength="200" value="<?= escapeHtml($t['ticket_template_name'] ?? '') ?>" required autofocus>
</div>
</div>
<div class="col-md-6">
<label class="form-label">What it is for</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-info-circle"></i></span>
<input type="text" class="form-control" name="description" placeholder="Shown when it is picked" maxlength="500" value="<?= escapeHtml($t['ticket_template_description'] ?? '') ?>">
</div>
</div>
<div class="col-12">
<label class="form-label">Subject</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="subject" placeholder="New hire onboarding - [Employee Name]" maxlength="500" value="<?= escapeHtml($t['ticket_template_subject'] ?? '') ?>">
</div>
</div>
<div class="col-12">
<label class="form-label">Details</label>
<textarea class="form-control tinymceTicket" name="details"><?= escapeHtml($t['ticket_template_details'] ?? '') ?></textarea>
<div class="form-text">
Filled in when a ticket is raised: <span class="font-monospace"><?= escapeHtml($placeholder_help) ?></span>.
Anything else in square brackets - <span class="font-monospace">[Employee Name]</span> - stays for whoever picks it up.
</div>
</div>
<?php if (empty($t)) { ?>
<div class="col-12">
<label class="form-label">Add it to a project template</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-project-diagram"></i></span>
<select class="form-select select2" name="project_template">
<option value="0">- No -</option>
<?php
$sql_project_templates = mysqli_query($mysqli, "SELECT project_template_id, project_template_name FROM project_templates WHERE project_template_archived_at IS NULL ORDER BY project_template_name ASC");
while ($row = mysqli_fetch_assoc($sql_project_templates)) { ?>
<option value="<?= intval($row['project_template_id']) ?>"><?= escapeHtml($row['project_template_name']) ?></option>
<?php } ?>
</select>
</div>
<div class="form-text">It goes at the end of that project template's tickets.</div>
</div>
<?php } ?>
</div>
</div>
<div class="tab-pane fade" id="ticketTemplateFormSetUp">
<p class="small text-secondary">How a ticket from it is set up. Anything left as it is stays as the New Ticket window has it, and can still be changed there before the ticket is made.</p>
<div class="row g-3">
<div class="col-md-6">
<label class="form-label">Category</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-layer-group"></i></span>
<select class="form-select select2" name="category_id">
<option value="0">- Leave as it is -</option>
<?= categoryOptionsHtml('Ticket', intval($t['ticket_template_category_id'] ?? 0) ?: null) ?>
</select>
</div>
</div>
<div class="col-md-6">
<label class="form-label">Priority</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-thermometer-half"></i></span>
<select class="form-select select2" name="priority">
<option value="">- Leave as it is -</option>
<?php foreach (['Low' => 'var(--bs-info)', 'Medium' => 'var(--bs-warning)', 'High' => 'var(--bs-danger)', 'Urgent' => 'var(--bs-emphasis-color)'] as $level => $color) { ?>
<option value="<?= $level ?>" data-color="<?= $color ?>" <?= $priority === $level ? 'selected' : '' ?>><?= $level ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-md-6">
<label class="form-label">Assign to</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-user-check"></i></span>
<select class="form-select select2" name="assigned_to">
<option value="0">- Leave as it is -</option>
<?php
$sql_agents = mysqli_query($mysqli, "SELECT user_id, user_name, user_avatar FROM users WHERE user_type = 1 AND user_status = 1 AND (user_archived_at IS NULL OR user_id = $assigned_to) ORDER BY user_name ASC");
while ($row = mysqli_fetch_assoc($sql_agents)) { ?>
<option value="<?= intval($row['user_id']) ?>" <?= intval($row['user_id']) === $assigned_to ? 'selected' : '' ?><?= selectOptionUser($row['user_id'], $row['user_name'], $row['user_avatar'] ?? '') ?>><?= escapeHtml($row['user_name']) ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-md-6">
<label class="form-label">Due</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-calendar-check"></i></span>
<input type="number" class="form-control" name="due_amount" min="0" max="8784" placeholder="No due date" value="<?= $due_amount ?>">
<select class="form-select" name="due_unit" style="max-width: 9rem;" aria-label="Hours or days">
<option value="days" <?= $due_in_days ? 'selected' : '' ?>>days after</option>
<option value="hours" <?= $due_in_days ? '' : 'selected' ?>>hours after</option>
</select>
</div>
<div class="form-text">After it is raised.</div>
</div>
<?php if (!empty($config_module_enable_accounting)) { ?>
<div class="col-md-6">
<label class="form-label">Billable</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-dollar-sign"></i></span>
<select class="form-select" name="billable">
<option value="" <?= $billable === '' ? 'selected' : '' ?>>- Leave as it is -</option>
<option value="1" <?= $billable === '1' ? 'selected' : '' ?>>Billable</option>
<option value="0" <?= $billable === '0' ? 'selected' : '' ?>>Not billable</option>
</select>
</div>
</div>
<?php } else { ?>
<input type="hidden" name="billable" value="<?= escapeHtml($billable) ?>">
<?php } ?>
<div class="col-12">
<?= tagFormFieldHtml('ticket', $template_tag_ids, 'Onboarding, Hardware, Escalated') ?>
</div>
</div>
</div>
</div>

View File

@@ -1,24 +1,23 @@
<?php
/*
* One of a ticket template's tasks - its name and how long it takes. Its place
* in the list is changed by dragging it on the template's page.
*/
require_once '../../includes/modal_header.php';
$task_template_id = intval($_GET['id']);
$task_template_id = intval($_GET['id'] ?? 0);
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT task_template_completion_estimate, task_template_name FROM task_templates WHERE task_template_id = $task_template_id LIMIT 1"));
$sql = mysqli_query($mysqli, "SELECT task_template_completion_estimate, task_template_name, task_template_order FROM task_templates WHERE task_template_id = $task_template_id LIMIT 1");
$row = mysqli_fetch_assoc($sql);
$task_template_name = escapeHtml($row['task_template_name']);
$task_template_order = intval($row['task_template_order']);
$task_template_completion_estimate = intval($row['task_template_completion_estimate']);
//$task_template_description = escapeHtml($row['task_template_description']);
// Generate the HTML form content using output buffering.
ob_start();
?>
if (!$row) { ?>
<div class="modal-body text-center text-secondary py-5">That task is gone - it may have been deleted.</div>
<?php } else { ?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fa fa-fw fa-tasks me-2"></i>Editing task</h5>
<h5 class="modal-title"><i class="fa fa-fw fa-tasks me-2"></i>Task</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
@@ -28,18 +27,19 @@ ob_start();
<div class="modal-body">
<div class="mb-3">
<label>Name <strong class="text-danger">*</strong></label>
<label class="form-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="name" placeholder="Name the task" maxlength="255" value="<?= $task_template_name ?>" required autofocus>
<span class="input-group-text"><i class="fa fa-fw fa-tasks"></i></span>
<input type="text" class="form-control" name="name" placeholder="Name the task" maxlength="200" value="<?= escapeHtml($row['task_template_name']) ?>" required autofocus>
</div>
</div>
<div class="mb-3">
<label>Estimated Completion Time <span class="text-secondary">(Minutes)</span></label>
<label class="form-label">How long it takes</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-clock"></i></span>
<input type="number" class="form-control" name="completion_estimate" placeholder="Estimated time to complete task in mins" value="<?= $task_template_completion_estimate ?>">
<span class="input-group-text"><i class="far fa-fw fa-clock"></i></span>
<input type="number" class="form-control" name="completion_estimate" min="0" placeholder="Minutes" value="<?= intval($row['task_template_completion_estimate']) ?: '' ?>">
<span class="input-group-text">minutes</span>
</div>
</div>
@@ -52,6 +52,6 @@ ob_start();
</form>
<?php
<?php }
require_once '../../../includes/modal_footer.php';