mirror of
https://github.com/itflow-org/itflow
synced 2026-11-17 01:47:25 +00:00
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:
30
admin/database_updates/3.1.9.php
Normal file
30
admin/database_updates/3.1.9.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ITFlow - Database update to version 3.1.9 (from 3.1.8)
|
||||
* Included by admin/database_updates.php - do not access directly
|
||||
*/
|
||||
|
||||
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
|
||||
|
||||
// A ticket template sets up the whole ticket: its category, priority,
|
||||
// billing, who it goes to and when it is due, and its tags. NULL priority
|
||||
// or billable, 0 category, agent or due: the template leaves that alone.
|
||||
mysqli_query($mysqli, "ALTER TABLE `ticket_templates`
|
||||
ADD `ticket_template_category_id` int(11) NOT NULL DEFAULT 0 AFTER `ticket_template_details`,
|
||||
ADD `ticket_template_priority` varchar(20) DEFAULT NULL AFTER `ticket_template_category_id`,
|
||||
ADD `ticket_template_billable` tinyint(1) DEFAULT NULL AFTER `ticket_template_priority`,
|
||||
ADD `ticket_template_assigned_to` int(11) NOT NULL DEFAULT 0 AFTER `ticket_template_billable`,
|
||||
ADD `ticket_template_due_hours` int(11) NOT NULL DEFAULT 0 AFTER `ticket_template_assigned_to`");
|
||||
|
||||
mysqli_query($mysqli, "CREATE TABLE `ticket_template_tags` (
|
||||
`ticket_template_id` int(11) NOT NULL,
|
||||
`tag_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`ticket_template_id`,`tag_id`),
|
||||
KEY `tag_id` (`tag_id`),
|
||||
CONSTRAINT `ticket_template_tags_ibfk_1` FOREIGN KEY (`ticket_template_id`) REFERENCES `ticket_templates` (`ticket_template_id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `ticket_template_tags_ibfk_2` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`tag_id`) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci");
|
||||
|
||||
// Which template a ticket was raised from - for the template's use, from now on
|
||||
mysqli_query($mysqli, "ALTER TABLE `tickets` ADD `ticket_template_id` int(11) NOT NULL DEFAULT 0 AFTER `ticket_recurring_ticket_id`, ADD KEY `ticket_template_id` (`ticket_template_id`)");
|
||||
@@ -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>
|
||||
|
||||
@@ -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';
|
||||
|
||||
164
admin/modals/ticket_template/ticket_template_form.php
Normal file
164
admin/modals/ticket_template/ticket_template_form.php
Normal 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>
|
||||
@@ -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';
|
||||
|
||||
@@ -1,56 +1,86 @@
|
||||
<?php
|
||||
|
||||
// Ticket Templates
|
||||
/*
|
||||
* Ticket templates - Admin > Ticket Templates. The work is in
|
||||
* functions/ticket_template.php.
|
||||
*/
|
||||
|
||||
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
|
||||
|
||||
// Import shared code from user-side tickets/tasks as we reuse functions
|
||||
require_once '../agent/post/ticket.php';
|
||||
require_once '../agent/post/task.php';
|
||||
/** The template a request names - back to the list with an error when it is gone. */
|
||||
function ticketTemplateForRequest($ticket_template_id) {
|
||||
$row = ticketTemplateRow($ticket_template_id);
|
||||
if (!$row) {
|
||||
flashAlert('That ticket template no longer exists.', 'error');
|
||||
redirect('ticket_templates.php');
|
||||
}
|
||||
return $row;
|
||||
}
|
||||
|
||||
if (isset($_POST['add_ticket_template'])) {
|
||||
if (isset($_POST['add_ticket_template']) || isset($_POST['edit_ticket_template'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$name = escapeSql($_POST['name']);
|
||||
$description = escapeSql($_POST['description']);
|
||||
$subject = escapeSql($_POST['subject']);
|
||||
$details = mysqli_real_escape_string($mysqli, $_POST['details']);
|
||||
$project_template_id = intval($_POST['project_template']);
|
||||
$editing = isset($_POST['edit_ticket_template']);
|
||||
$ticket_template_id = 0;
|
||||
if ($editing) {
|
||||
$ticket_template_id = intval(ticketTemplateForRequest($_POST['ticket_template_id'] ?? 0)['ticket_template_id']);
|
||||
}
|
||||
|
||||
mysqli_query($mysqli, "INSERT INTO ticket_templates SET ticket_template_name = '$name', ticket_template_description = '$description', ticket_template_subject = '$subject', ticket_template_details = '$details'");
|
||||
$fields = ticketTemplateFields($_POST, $error);
|
||||
if (!$fields) {
|
||||
flashAlert($error, 'error');
|
||||
redirect();
|
||||
}
|
||||
$ticket_template_id = ticketTemplateSave($ticket_template_id, $fields);
|
||||
$name = escapeSql($fields['name']);
|
||||
|
||||
$ticket_template_id = mysqli_insert_id($mysqli);
|
||||
|
||||
// At the end of the project template's tickets
|
||||
if ($project_template_id && mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM project_templates WHERE project_template_id = $project_template_id"))) {
|
||||
// A new one can go at the end of a project template's tickets
|
||||
$project_template_id = intval($_POST['project_template'] ?? 0);
|
||||
if (!$editing && $project_template_id && mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM project_templates WHERE project_template_id = $project_template_id"))) {
|
||||
$order = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COALESCE(MAX(ticket_template_order), 0) + 1 FROM project_template_ticket_templates WHERE project_template_id = $project_template_id"))[0]);
|
||||
mysqli_query($mysqli, "INSERT INTO project_template_ticket_templates SET project_template_id = $project_template_id, ticket_template_id = $ticket_template_id, ticket_template_order = $order");
|
||||
}
|
||||
|
||||
logAudit("Ticket Template", "Create", "$session_name created ticket template $name", 0, $ticket_template_id);
|
||||
logAudit("Ticket Template", $editing ? "Edit" : "Create", "$session_name " . ($editing ? 'edited' : 'created') . " ticket template $name", 0, $ticket_template_id);
|
||||
|
||||
flashAlert("Ticket template <strong>" . stripslashes($name) . "</strong> created");
|
||||
flashAlert("Ticket template <strong>" . escapeHtml($fields['name']) . "</strong> " . ($editing ? 'saved' : 'created'));
|
||||
|
||||
redirect();
|
||||
// A new one opens, to add its tasks
|
||||
redirect($editing ? null : "ticket_template.php?ticket_template_id=$ticket_template_id");
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['edit_ticket_template'])) {
|
||||
if (isset($_GET['copy_ticket_template'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$ticket_template_id = intval($_POST['ticket_template_id']);
|
||||
$name = escapeSql($_POST['name']);
|
||||
$description = escapeSql($_POST['description']);
|
||||
$subject = escapeSql($_POST['subject']);
|
||||
$details = mysqli_real_escape_string($mysqli, $_POST['details']);
|
||||
$row = ticketTemplateForRequest($_GET['copy_ticket_template']);
|
||||
$new_id = ticketTemplateCopy($row['ticket_template_id']);
|
||||
|
||||
mysqli_query($mysqli, "UPDATE ticket_templates SET ticket_template_name = '$name', ticket_template_description = '$description', ticket_template_subject = '$subject', ticket_template_details = '$details' WHERE ticket_template_id = $ticket_template_id");
|
||||
logAudit("Ticket Template", "Create", "$session_name copied ticket template " . escapeSql($row['ticket_template_name']), 0, $new_id);
|
||||
|
||||
logAudit("Ticket Template", "Edit", "$session_name edited ticket template $name", 0, $ticket_template_id);
|
||||
flashAlert("Ticket template <strong>" . escapeHtml($row['ticket_template_name']) . "</strong> copied - this is the copy");
|
||||
|
||||
flashAlert("Ticket template <strong>" . stripslashes($name) . "</strong> saved");
|
||||
redirect("ticket_template.php?ticket_template_id=$new_id");
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['archive_ticket_template']) || isset($_GET['restore_ticket_template'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$archive = isset($_GET['archive_ticket_template']);
|
||||
$row = ticketTemplateForRequest($archive ? $_GET['archive_ticket_template'] : $_GET['restore_ticket_template']);
|
||||
$ticket_template_id = intval($row['ticket_template_id']);
|
||||
$name = escapeSql($row['ticket_template_name']);
|
||||
|
||||
// Archived, it isn't offered for new tickets - recurring tickets and project templates that use it keep it, so restoring it is all it takes
|
||||
mysqli_query($mysqli, "UPDATE ticket_templates SET ticket_template_archived_at = " . ($archive ? 'NOW()' : 'NULL') . " WHERE ticket_template_id = $ticket_template_id");
|
||||
|
||||
logAudit("Ticket Template", $archive ? "Archive" : "Restore", "$session_name " . ($archive ? 'archived' : 'restored') . " ticket template $name", 0, $ticket_template_id);
|
||||
|
||||
flashAlert("Ticket template <strong>" . escapeHtml($row['ticket_template_name']) . "</strong> " . ($archive ? 'archived' : 'restored'), $archive ? 'error' : 'success');
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -60,25 +90,28 @@ if (isset($_GET['delete_ticket_template'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$ticket_template_id = intval($_GET['delete_ticket_template']);
|
||||
|
||||
$ticket_template_name = escapeSql(getFieldById('ticket_templates', $ticket_template_id, 'ticket_template_name'));
|
||||
$row = ticketTemplateForRequest($_GET['delete_ticket_template']);
|
||||
$ticket_template_id = intval($row['ticket_template_id']);
|
||||
$ticket_template_name = escapeSql($row['ticket_template_name']);
|
||||
|
||||
mysqli_query($mysqli, "DELETE FROM ticket_templates WHERE ticket_template_id = $ticket_template_id");
|
||||
|
||||
// Delete Associations
|
||||
// Its tasks and tags go with it, and it comes off the project templates that raise it
|
||||
mysqli_query($mysqli, "DELETE FROM task_templates WHERE task_template_ticket_template_id = $ticket_template_id");
|
||||
mysqli_query($mysqli, "DELETE FROM ticket_template_tags WHERE ticket_template_id = $ticket_template_id");
|
||||
mysqli_query($mysqli, "DELETE FROM project_template_ticket_templates WHERE ticket_template_id = $ticket_template_id");
|
||||
|
||||
// Unlink from recurring tickets rather than deleting them - the schedule is still
|
||||
// wanted, it just stops contributing tasks to the tickets it raises
|
||||
// wanted, it just stops contributing tasks to the tickets it raises. Tickets raised
|
||||
// from it keep everything they were given, but not the link.
|
||||
mysqli_query($mysqli, "UPDATE recurring_tickets SET recurring_ticket_ticket_template_id = 0 WHERE recurring_ticket_ticket_template_id = $ticket_template_id");
|
||||
mysqli_query($mysqli, "UPDATE tickets SET ticket_template_id = 0 WHERE ticket_template_id = $ticket_template_id");
|
||||
|
||||
logAudit("Ticket Template", "Delete", "$session_name deleted ticket template $ticket_template_name");
|
||||
|
||||
flashAlert("Ticket template <strong>" . stripslashes($ticket_template_name) . "</strong> and its tasks deleted", 'error');
|
||||
flashAlert("Ticket template <strong>" . escapeHtml($row['ticket_template_name']) . "</strong> and its tasks deleted", 'error');
|
||||
|
||||
redirect();
|
||||
redirect(isset($_GET['from_page']) ? 'ticket_templates.php' : null);
|
||||
|
||||
}
|
||||
|
||||
@@ -86,16 +119,48 @@ if (isset($_POST['add_ticket_template_task'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$ticket_template_id = intval($_POST['ticket_template_id']);
|
||||
$task_name = escapeSql($_POST['task_name']);
|
||||
$row = ticketTemplateForRequest($_POST['ticket_template_id'] ?? 0);
|
||||
$ticket_template_id = intval($row['ticket_template_id']);
|
||||
$task_name = trim(mb_substr(strip_tags((string) ($_POST['task_name'] ?? '')), 0, 200));
|
||||
if ($task_name === '') {
|
||||
flashAlert('Give the task a name.', 'error');
|
||||
redirect();
|
||||
}
|
||||
$estimate = max(0, min(100000, intval($_POST['task_estimate'] ?? 0)));
|
||||
$task_name_sql = escapeSql($task_name);
|
||||
$order = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COALESCE(MAX(task_template_order), 0) + 1 FROM task_templates WHERE task_template_ticket_template_id = $ticket_template_id"))[0]);
|
||||
|
||||
mysqli_query($mysqli, "INSERT INTO task_templates SET task_template_name = '$task_name', task_template_ticket_template_id = $ticket_template_id");
|
||||
mysqli_query($mysqli, "INSERT INTO task_templates SET task_template_name = '$task_name_sql', task_template_order = $order, task_template_completion_estimate = $estimate, task_template_ticket_template_id = $ticket_template_id");
|
||||
|
||||
$task_template_id = mysqli_insert_id($mysqli);
|
||||
logAudit("Ticket Template", "Edit", "$session_name added task $task_name_sql to ticket template " . escapeSql($row['ticket_template_name']), 0, $ticket_template_id);
|
||||
|
||||
logAudit("Ticket Template", "Create", "$session_name created task $task_name for ticket template", 0, $ticket_template_id);
|
||||
flashAlert("Task <strong>" . escapeHtml($task_name) . "</strong> added");
|
||||
|
||||
flashAlert("Task <strong>" . stripslashes($task_name) . "</strong> added");
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['edit_ticket_template_task'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$task_template_id = intval($_POST['task_template_id'] ?? 0);
|
||||
$task = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT task_template_ticket_template_id FROM task_templates WHERE task_template_id = $task_template_id"));
|
||||
$row = ticketTemplateForRequest($task['task_template_ticket_template_id'] ?? 0);
|
||||
$task_name = trim(mb_substr(strip_tags((string) ($_POST['name'] ?? '')), 0, 200));
|
||||
if ($task_name === '') {
|
||||
flashAlert('Give the task a name.', 'error');
|
||||
redirect();
|
||||
}
|
||||
$task_name_sql = escapeSql($task_name);
|
||||
$estimate = max(0, min(100000, intval($_POST['completion_estimate'] ?? 0)));
|
||||
|
||||
// Its place in the list stays as it is - the list is reordered by dragging
|
||||
mysqli_query($mysqli, "UPDATE task_templates SET task_template_name = '$task_name_sql', task_template_completion_estimate = $estimate WHERE task_template_id = $task_template_id");
|
||||
|
||||
logAudit("Ticket Template", "Edit", "$session_name edited task $task_name_sql on ticket template " . escapeSql($row['ticket_template_name']), 0, intval($row['ticket_template_id']));
|
||||
|
||||
flashAlert("Task <strong>" . escapeHtml($task_name) . "</strong> saved");
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -106,14 +171,14 @@ if (isset($_GET['delete_task_template'])) {
|
||||
validateCSRFToken();
|
||||
|
||||
$task_template_id = intval($_GET['delete_task_template']);
|
||||
|
||||
$task_template_name = escapeSql(getFieldById('task_templates', $task_template_id, 'task_template_name'));
|
||||
$task = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT task_template_name, task_template_ticket_template_id FROM task_templates WHERE task_template_id = $task_template_id"));
|
||||
$row = ticketTemplateForRequest($task['task_template_ticket_template_id'] ?? 0);
|
||||
|
||||
mysqli_query($mysqli, "DELETE FROM task_templates WHERE task_template_id = $task_template_id");
|
||||
|
||||
logAudit("Ticket Template", "Edit", "$session_name deleted task $task_template_name from ticket template");
|
||||
logAudit("Ticket Template", "Edit", "$session_name deleted task " . escapeSql($task['task_template_name']) . " from ticket template " . escapeSql($row['ticket_template_name']), 0, intval($row['ticket_template_id']));
|
||||
|
||||
flashAlert("Task <strong>" . stripslashes($task_template_name) . "</strong> deleted", 'error');
|
||||
flashAlert("Task <strong>" . escapeHtml($task['task_template_name']) . "</strong> deleted", 'error');
|
||||
|
||||
redirect();
|
||||
|
||||
|
||||
@@ -1,161 +1,314 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* One ticket template - the ticket it starts (subject and details, with its
|
||||
* placeholders marked), how it sets the ticket up, its tasks (added, changed,
|
||||
* dragged into order) and their time, and its use: how many tickets it has
|
||||
* raised, the latest of them, and the recurring tickets and project templates
|
||||
* that raise it. The work is in functions/ticket_template.php.
|
||||
*/
|
||||
|
||||
require_once "includes/inc_all_admin.php";
|
||||
|
||||
|
||||
//Initialize the HTML Purifier to prevent XSS
|
||||
require "../libs/htmlpurifier/HTMLPurifier.standalone.php";
|
||||
|
||||
$purifier_config = HTMLPurifier_Config::createDefault();
|
||||
$purifier_config->set('Cache.DefinitionImpl', null); // Disable cache by setting a non-existent directory or an invalid one
|
||||
$purifier_config->set('URI.AllowedSchemes', ['data' => true, 'src' => true, 'http' => true, 'https' => true]);
|
||||
$purifier = new HTMLPurifier($purifier_config);
|
||||
|
||||
if (isset($_GET['ticket_template_id'])) {
|
||||
$ticket_template_id = intval($_GET['ticket_template_id']);
|
||||
}
|
||||
|
||||
$sql_ticket_template = mysqli_query($mysqli, "SELECT ticket_template_created_at, ticket_template_description, ticket_template_details,
|
||||
ticket_template_name, ticket_template_subject, ticket_template_updated_at FROM ticket_templates WHERE ticket_template_id = $ticket_template_id LIMIT 1");
|
||||
|
||||
if (mysqli_num_rows($sql_ticket_template) == 0) {
|
||||
echo "<center><h1 class='text-secondary mt-5'>Nothing to see here</h1><a class='btn btn-lg btn-secondary mt-3' href='javascript:history.back()'><i class='fa fa-fw fa-arrow-left'></i> Go Back</a></center>";
|
||||
$template = ticketTemplateRow($_GET['ticket_template_id'] ?? 0);
|
||||
if (!$template) {
|
||||
echo emptyStateHtml(['thing' => 'ticket templates', 'title' => 'That ticket template is gone', 'text' => 'It may have been deleted.', 'icon' => 'fa-life-ring', 'filtered' => false,
|
||||
'actions' => [['label' => 'Ticket Templates', 'href' => 'ticket_templates.php']]]);
|
||||
require_once "../includes/footer.php";
|
||||
exit();
|
||||
}
|
||||
|
||||
$row = mysqli_fetch_assoc($sql_ticket_template);
|
||||
$ticket_template_id = intval($template['ticket_template_id']);
|
||||
$name = escapeHtml($template['ticket_template_name']);
|
||||
$archived = !empty($template['ticket_template_archived_at']);
|
||||
$tasks = ticketTemplateTasks($ticket_template_id);
|
||||
$task_minutes = array_sum(array_column($tasks, 'estimate'));
|
||||
$tag_ids = ticketTemplateTagIds($ticket_template_id);
|
||||
$tag_rows = [];
|
||||
if ($tag_ids) {
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM tags WHERE tag_id IN (" . implode(',', $tag_ids) . ") ORDER BY tag_name");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$tag_rows[] = $row;
|
||||
}
|
||||
}
|
||||
$usage = ticketTemplateUsage([$ticket_template_id])[$ticket_template_id] ?? ['count' => 0, 'open' => 0, 'last' => null];
|
||||
$csrf = $_SESSION['csrf_token'];
|
||||
|
||||
$ticket_template_name = escapeHtml($row['ticket_template_name']);
|
||||
$ticket_template_description = escapeHtml($row['ticket_template_description']);
|
||||
$ticket_template_subject = escapeHtml($row['ticket_template_subject']);
|
||||
$ticket_template_details = $purifier->purify($row['ticket_template_details']);
|
||||
$ticket_template_created_at = escapeHtml($row['ticket_template_created_at']);
|
||||
$ticket_template_updated_at = escapeHtml($row['ticket_template_updated_at']);
|
||||
// The tickets it raised most lately
|
||||
$recent = [];
|
||||
$sql = mysqli_query($mysqli, "SELECT ticket_id, ticket_prefix, ticket_number, ticket_subject, ticket_client_id, ticket_created_at, ticket_resolved_at, ticket_closed_at, client_name, ticket_status_name, ticket_status_color
|
||||
FROM tickets
|
||||
LEFT JOIN clients ON client_id = ticket_client_id
|
||||
LEFT JOIN ticket_statuses ON ticket_status_id = ticket_status
|
||||
WHERE ticket_template_id = $ticket_template_id AND ticket_archived_at IS NULL
|
||||
ORDER BY ticket_created_at DESC, ticket_id DESC LIMIT 8");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$recent[] = $row;
|
||||
}
|
||||
|
||||
// Get Task Templates
|
||||
$sql_task_templates = mysqli_query($mysqli, "SELECT task_template_completion_estimate, task_template_id, task_template_name FROM task_templates WHERE task_template_ticket_template_id = $ticket_template_id ORDER BY task_template_order ASC, task_template_id ASC");
|
||||
// What raises it
|
||||
$recurring = [];
|
||||
$sql = mysqli_query($mysqli, "SELECT recurring_ticket_id, recurring_ticket_subject, recurring_ticket_frequency, recurring_ticket_client_id, client_name FROM recurring_tickets
|
||||
LEFT JOIN clients ON client_id = recurring_ticket_client_id
|
||||
WHERE recurring_ticket_ticket_template_id = $ticket_template_id ORDER BY client_name, recurring_ticket_subject");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$recurring[] = $row;
|
||||
}
|
||||
$projects = [];
|
||||
$sql = mysqli_query($mysqli, "SELECT project_templates.project_template_id, project_template_name FROM project_template_ticket_templates
|
||||
JOIN project_templates ON project_templates.project_template_id = project_template_ticket_templates.project_template_id
|
||||
WHERE project_template_ticket_templates.ticket_template_id = $ticket_template_id ORDER BY project_template_name");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$projects[] = $row;
|
||||
}
|
||||
|
||||
// Its placeholders - filled in from the ticket, or left for whoever picks it up
|
||||
$known = array_map('strtolower', array_keys(TICKET_PLACEHOLDERS));
|
||||
$found = ticketTemplatePlaceholdersIn($template['ticket_template_subject'] . ' ' . $template['ticket_template_details'] . ' ' . implode(' ', array_column($tasks, 'name')));
|
||||
$filled = array_values(array_filter($found, function ($word) use ($known) {
|
||||
return in_array(strtolower($word), $known, true);
|
||||
}));
|
||||
$left = array_values(array_diff($found, $filled));
|
||||
|
||||
// [Words] marked where they appear - escaped text, or HTML already made safe
|
||||
$mark = function ($html) {
|
||||
return preg_replace('/\[([A-Za-z][A-Za-z0-9 _\-\/]{0,40})\]/', '<span class="badge rounded-pill text-bg-light border font-monospace fw-normal">[$1]</span>', $html);
|
||||
};
|
||||
$details = trim((string) $template['ticket_template_details']) !== '' ? $mark(documentHtmlPurify($template['ticket_template_details'])) : '';
|
||||
|
||||
$edit_url = "modals/ticket_template/ticket_template_edit.php?id=$ticket_template_id";
|
||||
|
||||
?>
|
||||
|
||||
<ol class="breadcrumb d-print-none">
|
||||
<li class="breadcrumb-item">
|
||||
<a href="../index.php">Home</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item">
|
||||
<a href="users.php">Admin</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item">
|
||||
<a href="ticket_templates.php">Ticket Templates</a>
|
||||
</li>
|
||||
<li class="breadcrumb-item active"><i class="fas fa-life-ring me-2"></i><?= $ticket_template_name ?></li>
|
||||
<li class="breadcrumb-item"><a href="../index.php">Home</a></li>
|
||||
<li class="breadcrumb-item"><a href="users.php">Admin</a></li>
|
||||
<li class="breadcrumb-item"><a href="ticket_templates.php">Ticket Templates</a></li>
|
||||
<li class="breadcrumb-item active"><?= $name ?></li>
|
||||
</ol>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-9">
|
||||
|
||||
<div class="card card-dark">
|
||||
<div class="card-header">
|
||||
<h3 class="card-title mt-1"><?= $ticket_template_name ?></h3>
|
||||
<div class="card-tools">
|
||||
<button type="button" class="btn btn-tool btn-sm" title="Edit template" data-bs-toggle="modal" data-bs-target="#editTicketTemplateModal">
|
||||
<i class="fas fa-edit"></i>
|
||||
</button>
|
||||
<div class="card mb-3">
|
||||
<div class="card-body d-flex flex-wrap align-items-center gap-3">
|
||||
<span class="itflow-asset-icon itflow-asset-tone-other" aria-hidden="true"><i class="fas fa-fw fa-life-ring"></i></span>
|
||||
<div class="min-w-0 flex-grow-1">
|
||||
<h1 class="h4 mb-0"><?= $name ?></h1>
|
||||
<?php if (trim((string) $template['ticket_template_description']) !== '') { ?>
|
||||
<div class="text-secondary"><?= escapeHtml($template['ticket_template_description']) ?></div>
|
||||
<?php } ?>
|
||||
<?php if ($archived) { ?>
|
||||
<div class="small text-secondary"><i class="fas fa-fw fa-archive me-1"></i>Archived <?= date('M j, Y', strtotime($template['ticket_template_archived_at'])) ?> - not offered for new tickets</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="d-flex flex-wrap gap-2">
|
||||
<?php if (!$archived) { ?>
|
||||
<a class="btn btn-primary" href="/agent/tickets.php?new_from_template=<?= $ticket_template_id ?>"><i class="fas fa-fw fa-plus me-2"></i>New ticket from it</a>
|
||||
<?php } ?>
|
||||
<button type="button" class="btn btn-outline-secondary ajax-modal" data-modal-size="lg" data-modal-url="<?= $edit_url ?>"><i class="fas fa-fw fa-edit me-2"></i>Edit</button>
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-outline-secondary" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-fw fa-ellipsis-h"></i></button>
|
||||
<div class="dropdown-menu dropdown-menu-end">
|
||||
<a class="dropdown-item" href="post.php?copy_ticket_template=<?= $ticket_template_id ?>&csrf_token=<?= $csrf ?>"><i class="fas fa-fw fa-copy me-2"></i>Copy</a>
|
||||
<?php if ($archived) { ?>
|
||||
<a class="dropdown-item" href="post.php?restore_ticket_template=<?= $ticket_template_id ?>&csrf_token=<?= $csrf ?>"><i class="fas fa-fw fa-redo me-2"></i>Restore</a>
|
||||
<?php } else { ?>
|
||||
<a class="dropdown-item" href="post.php?archive_ticket_template=<?= $ticket_template_id ?>&csrf_token=<?= $csrf ?>"><i class="fas fa-fw fa-archive me-2"></i>Archive</a>
|
||||
<?php } ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-danger confirm-link" href="post.php?delete_ticket_template=<?= $ticket_template_id ?>&from_page=1&csrf_token=<?= $csrf ?>"
|
||||
data-confirm-title="Delete <?= $name ?>?" data-confirm-text="Its tasks go with it. Tickets raised from it stay as they are." data-confirm-button="Delete"><i class="fas fa-fw fa-trash me-2"></i>Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-body prettyContent">
|
||||
<?= $ticket_template_details ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row g-3">
|
||||
<div class="col-lg-8">
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card-header d-flex align-items-center">
|
||||
<h3 class="card-title mb-0"><i class="fas fa-fw fa-life-ring me-2"></i>The ticket it starts</h3>
|
||||
<button type="button" class="btn btn-sm btn-link ms-auto ajax-modal" data-modal-size="lg" data-modal-url="<?= $edit_url ?>"><i class="fas fa-edit me-1"></i>Edit</button>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="small text-secondary">Subject</div>
|
||||
<div class="fw-semibold mb-3"><?= trim((string) $template['ticket_template_subject']) !== '' ? $mark(escapeHtml($template['ticket_template_subject'])) : '<span class="text-secondary fw-normal">None - typed in on New Ticket</span>' ?></div>
|
||||
<div class="small text-secondary">Details</div>
|
||||
<div class="prettyContent"><?= $details !== '' ? $details : '<span class="text-secondary">None</span>' ?></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
|
||||
<div class="card card-dark">
|
||||
<div class="card-header">
|
||||
<h5 class="card-title"><i class="fa fa-fw fa-tasks me-2"></i>Tasks</h5>
|
||||
<div class="card mb-3">
|
||||
<div class="card-header d-flex align-items-center">
|
||||
<h3 class="card-title mb-0"><i class="fas fa-fw fa-tasks me-2"></i>Tasks</h3>
|
||||
<span class="ms-auto small text-secondary"><?= count($tasks) ?> task<?= count($tasks) === 1 ? '' : 's' ?><?= $task_minutes ? ' · <i class="far fa-clock me-1"></i>' . escapeHtml(ticketTemplateMinutesText($task_minutes)) : '' ?></span>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<form action="post.php" method="post" autocomplete="off" class="mb-3">
|
||||
<input type="hidden" name="csrf_token" value="<?= $csrf ?>">
|
||||
<input type="hidden" name="ticket_template_id" value="<?= $ticket_template_id ?>">
|
||||
<div class="mb-3">
|
||||
<div class="input-group input-group-sm">
|
||||
<input type="text" class="form-control" name="task_name" placeholder="Create a task" required maxlength="200">
|
||||
<button type="submit" name="add_ticket_template_task" class="btn btn-primary" title="Add task"><i class="fas fa-fw fa-check"></i></button>
|
||||
<div class="row g-2">
|
||||
<div class="col-sm">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-tasks"></i></span>
|
||||
<input type="text" class="form-control" name="task_name" placeholder="Add a task" required maxlength="200">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-8 col-sm-3">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="far fa-fw fa-clock"></i></span>
|
||||
<input type="number" class="form-control" name="task_estimate" min="0" placeholder="Mins" aria-label="Estimate in minutes">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-4 col-sm-auto">
|
||||
<button type="submit" name="add_ticket_template_task" class="btn btn-primary w-100"><i class="fas fa-fw fa-plus me-1"></i>Add</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<table class="table table-sm" id="tasks">
|
||||
<?php
|
||||
while($row = mysqli_fetch_assoc($sql_task_templates)){
|
||||
$task_id = intval($row['task_template_id']);
|
||||
$task_name = escapeHtml($row['task_template_name']);
|
||||
$task_completion_estimate = intval($row['task_template_completion_estimate']);
|
||||
//$task_description = escapeHtml($row['task_template_description']);
|
||||
?>
|
||||
<tr data-task-id="<?= $task_id ?>">
|
||||
<td>
|
||||
<a href="#" class="drag-handle"><i class="fas fa-bars text-muted me-2"></i></a>
|
||||
<span class="text-dark"><?= $task_name ?></span>
|
||||
</td>
|
||||
<td class="text-end">
|
||||
<div class="float-end">
|
||||
<div class="dropdown dropstart text-center">
|
||||
<button class="btn btn-light text-secondary btn-sm" title="More actions" type="button" data-bs-toggle="dropdown">
|
||||
<i class="fas fa-ellipsis-v"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item ajax-modal" href="#"
|
||||
data-modal-url="modals/ticket_template/ticket_template_task_edit.php?id=<?= $task_id ?>">
|
||||
<i class="fas fa-fw fa-edit me-2"></i>Edit
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-danger confirm-link" href="post.php?delete_task_template=<?= $task_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-trash-alt me-2"></i>Delete
|
||||
</a>
|
||||
</div>
|
||||
<?php if ($tasks) { ?>
|
||||
<div class="list-group" id="ticketTemplateTasks">
|
||||
<?php foreach ($tasks as $number => $task) { ?>
|
||||
<div class="list-group-item d-flex align-items-center gap-2" data-task-id="<?= $task['id'] ?>">
|
||||
<span class="drag-handle text-secondary" title="Drag to reorder" style="cursor: grab;"><i class="fas fa-fw fa-grip-vertical"></i></span>
|
||||
<span class="text-secondary small" style="min-width: 1.5rem;"><?= $number + 1 ?>.</span>
|
||||
<span class="flex-grow-1 min-w-0 text-break"><?= $mark(escapeHtml($task['name'])) ?></span>
|
||||
<?php if ($task['estimate']) { ?><span class="small text-secondary text-nowrap"><i class="far fa-clock me-1"></i><?= escapeHtml(ticketTemplateMinutesText($task['estimate'])) ?></span><?php } ?>
|
||||
<div class="dropdown dropstart">
|
||||
<button class="btn btn-light text-secondary btn-sm" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-ellipsis-v"></i></button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/ticket_template/ticket_template_task_edit.php?id=<?= $task['id'] ?>"><i class="fas fa-fw fa-edit me-2"></i>Edit</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-danger confirm-link" href="post.php?delete_task_template=<?= $task['id'] ?>&csrf_token=<?= $csrf ?>"><i class="fas fa-fw fa-trash-alt me-2"></i>Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<div class="text-secondary small">No tasks yet. A ticket raised from it gets a copy of each, in this order - and later changes here don't touch tickets already raised.</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col-lg-4">
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card-header d-flex align-items-center">
|
||||
<h3 class="card-title mb-0"><i class="fas fa-fw fa-sliders-h me-2"></i>Sets up</h3>
|
||||
<button type="button" class="btn btn-sm btn-link ms-auto ajax-modal" data-modal-size="lg" data-modal-url="<?= $edit_url ?>"><i class="fas fa-edit me-1"></i>Edit</button>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php
|
||||
$leave = '<span class="text-secondary">As it is</span>';
|
||||
$set_up = [
|
||||
'Category' => intval($template['ticket_template_category_id']) && !empty($template['category_name'])
|
||||
? categoryChip(['category_name' => $template['category_name'], 'category_type' => 'Ticket', 'category_color' => $template['category_color'], 'category_icon' => $template['category_icon']]) : $leave,
|
||||
'Priority' => !empty($template['ticket_template_priority']) ? ticketPriorityHtml($template['ticket_template_priority'], 'detail') : $leave,
|
||||
'Assign to' => intval($template['ticket_template_assigned_to']) && !empty($template['assignee_name'])
|
||||
? userAvatar($template['ticket_template_assigned_to'], $template['assignee_name'], $template['assignee_avatar'] ?? '', 'sm') . ' ' . escapeHtml($template['assignee_name']) : $leave,
|
||||
'Due' => intval($template['ticket_template_due_hours']) ? escapeHtml(ticketTemplateDueText($template['ticket_template_due_hours'])) . ' after it is raised' : '<span class="text-secondary">No due date</span>',
|
||||
];
|
||||
if (!empty($config_module_enable_accounting)) {
|
||||
$set_up['Billable'] = $template['ticket_template_billable'] === null ? $leave : (intval($template['ticket_template_billable']) ? 'Billable' : 'Not billable');
|
||||
}
|
||||
$set_up['Tags'] = $tag_rows ? '<span class="d-inline-flex flex-wrap gap-1">' . implode('', array_map('tagPill', $tag_rows)) . '</span>' : '<span class="text-secondary">None</span>';
|
||||
?>
|
||||
<dl class="row mb-0 small">
|
||||
<?php foreach ($set_up as $label => $value) { ?>
|
||||
<dt class="col-5 fw-normal text-secondary"><?= $label ?></dt>
|
||||
<dd class="col-7 mb-2"><?= $value ?></dd>
|
||||
<?php } ?>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($found) { ?>
|
||||
<div class="card mb-3">
|
||||
<div class="card-header"><h3 class="card-title mb-0"><i class="fas fa-fw fa-code me-2"></i>Placeholders</h3></div>
|
||||
<div class="card-body small">
|
||||
<?php if ($filled) { ?>
|
||||
<div class="text-secondary mb-1">Filled in from the ticket</div>
|
||||
<div class="d-flex flex-wrap gap-1 mb-3">
|
||||
<?php foreach ($filled as $word) { ?>
|
||||
<span class="badge rounded-pill text-bg-light border font-monospace fw-normal" title="<?= escapeHtml(ucfirst(TICKET_PLACEHOLDERS[ucfirst(strtolower($word))] ?? '')) ?>">[<?= escapeHtml($word) ?>]</span>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php if ($left) { ?>
|
||||
<div class="text-secondary mb-1">Left for whoever picks it up</div>
|
||||
<div class="d-flex flex-wrap gap-1">
|
||||
<?php foreach ($left as $word) { ?>
|
||||
<span class="badge rounded-pill text-bg-warning font-monospace fw-normal">[<?= escapeHtml($word) ?>]</span>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="card mb-3">
|
||||
<div class="card-header"><h3 class="card-title mb-0"><i class="fas fa-fw fa-chart-line me-2"></i>Used</h3></div>
|
||||
<div class="card-body">
|
||||
<?php if ($usage['count']) { ?>
|
||||
<div class="mb-2"><strong><?= $usage['count'] ?></strong> ticket<?= $usage['count'] === 1 ? '' : 's' ?> raised<?= $usage['open'] ? ', <strong>' . $usage['open'] . '</strong> still open' : '' ?> <span class="small text-secondary">- last <?= timeAgo($usage['last']) ?></span></div>
|
||||
<div class="list-group list-group-flush small">
|
||||
<?php foreach ($recent as $row) {
|
||||
$open = !$row['ticket_resolved_at'] && !$row['ticket_closed_at']; ?>
|
||||
<a class="list-group-item list-group-item-action px-0 d-flex align-items-center gap-2" href="/agent/<?= escapeHtml(ticketUrl($row['ticket_id'], $row['ticket_client_id'])) ?>">
|
||||
<span class="font-monospace text-nowrap"><?= escapeHtml(ticketReference($row)) ?></span>
|
||||
<span class="min-w-0 flex-grow-1 text-truncate <?= $open ? '' : 'text-secondary' ?>"><?= escapeHtml($row['client_name'] ?: $row['ticket_subject']) ?></span>
|
||||
<?= ticketStatusHtml($row['ticket_status_name'] ?? '', $row['ticket_status_color'] ?? '', 'detail') ?>
|
||||
</a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<div class="small text-secondary">No tickets raised from it yet - counting started with this version of ITFlow.</div>
|
||||
<?php } ?>
|
||||
<?php if ($recurring || $projects) { ?>
|
||||
<div class="small text-secondary mt-3 mb-1">Raised by</div>
|
||||
<ul class="list-unstyled small mb-0">
|
||||
<?php foreach ($recurring as $row) { ?>
|
||||
<li class="mb-1"><i class="fas fa-fw fa-redo-alt text-secondary me-1"></i><a href="/agent/recurring_tickets.php?client_id=<?= intval($row['recurring_ticket_client_id']) ?>"><?= escapeHtml($row['recurring_ticket_subject']) ?></a> <span class="text-secondary">- <?= escapeHtml(trim($row['recurring_ticket_frequency'] . ', ' . ($row['client_name'] ?? ''), ', ')) ?></span></li>
|
||||
<?php } ?>
|
||||
<?php foreach ($projects as $row) { ?>
|
||||
<li class="mb-1"><i class="fas fa-fw fa-project-diagram text-secondary me-1"></i><a href="project_template.php?project_template_id=<?= intval($row['project_template_id']) ?>"><?= escapeHtml($row['project_template_name']) ?></a> <span class="text-secondary">- project template</span></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="../js/pretty_content.js"></script>
|
||||
|
||||
<script src="../libs/SortableJS/Sortable.min.js"></script>
|
||||
<script>
|
||||
new Sortable(document.querySelector('table#tasks tbody'), {
|
||||
handle: '.drag-handle',
|
||||
animation: 150,
|
||||
onEnd: function (evt) {
|
||||
const rows = document.querySelectorAll('table#tasks tbody tr');
|
||||
const positions = Array.from(rows).map((row, index) => ({
|
||||
id: row.dataset.taskId,
|
||||
order: index
|
||||
}));
|
||||
|
||||
itflowPostForm('/agent/ajax.php', {
|
||||
update_task_templates_order: true,
|
||||
csrf_token: '<?= $_SESSION['csrf_token'] ?>',
|
||||
ticket_template_id: <?= $ticket_template_id ?>,
|
||||
positions: positions
|
||||
(function () {
|
||||
var list = document.getElementById('ticketTemplateTasks');
|
||||
if (!list) {
|
||||
return;
|
||||
}
|
||||
new Sortable(list, {
|
||||
handle: '.drag-handle',
|
||||
animation: 150,
|
||||
onEnd: function () {
|
||||
var positions = Array.from(list.querySelectorAll('[data-task-id]')).map(function (row, index) {
|
||||
row.querySelector('.text-secondary.small').textContent = (index + 1) + '.';
|
||||
return { id: row.dataset.taskId, order: index + 1 };
|
||||
});
|
||||
itflowPostForm('/agent/ajax.php', {
|
||||
update_task_templates_order: true,
|
||||
csrf_token: <?= json_encode($csrf) ?>,
|
||||
ticket_template_id: <?= $ticket_template_id ?>,
|
||||
positions: positions
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
<?php
|
||||
|
||||
require_once "modals/ticket_template/ticket_template_edit.php";
|
||||
require_once "../includes/footer.php";
|
||||
|
||||
@@ -1,25 +1,53 @@
|
||||
<?php
|
||||
|
||||
// Default Column Sortby Filter
|
||||
$sort = "ticket_template_name";
|
||||
$order = "ASC";
|
||||
/*
|
||||
* Admin > Ticket Templates - tickets ready to raise: a subject, details and
|
||||
* tasks, and how the ticket is set up (category, priority, billing, agent, due
|
||||
* time and tags). Each row shows what it sets up, its tasks and their time,
|
||||
* and how often it has been used. A template can be changed, copied as the
|
||||
* start of another, archived - kept for the recurring tickets and project
|
||||
* templates that use it, not offered for new tickets - or deleted. The work is
|
||||
* in functions/ticket_template.php; the handlers are admin/post/ticket_template.php.
|
||||
*/
|
||||
|
||||
require_once "includes/inc_all_admin.php";
|
||||
|
||||
$sql = mysqli_query(
|
||||
$mysqli,
|
||||
"SELECT SQL_CALC_FOUND_ROWS *,
|
||||
COUNT(task_template_id) AS task_count
|
||||
FROM ticket_templates
|
||||
LEFT JOIN task_templates ON task_template_ticket_template_id = ticket_template_id
|
||||
WHERE (ticket_template_name LIKE '%$q%' OR ticket_template_description LIKE '%$q%')
|
||||
AND ticket_template_archived_at IS NULL
|
||||
GROUP BY ticket_template_id
|
||||
ORDER BY $sort $order
|
||||
LIMIT $record_from, $record_to"
|
||||
);
|
||||
$show_archived = isset($_GET['archived']);
|
||||
$search = trim((string) ($_GET['q'] ?? ''));
|
||||
$search_sql = escapeSql($search);
|
||||
|
||||
$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
$templates = [];
|
||||
$sql = mysqli_query($mysqli, "SELECT ticket_templates.*, category_name, category_color, category_icon, user_name AS assignee_name,
|
||||
(SELECT COUNT(*) FROM task_templates WHERE task_template_ticket_template_id = ticket_templates.ticket_template_id) AS task_count,
|
||||
(SELECT COALESCE(SUM(task_template_completion_estimate), 0) FROM task_templates WHERE task_template_ticket_template_id = ticket_templates.ticket_template_id) AS task_minutes,
|
||||
(SELECT COUNT(*) FROM recurring_tickets WHERE recurring_ticket_ticket_template_id = ticket_templates.ticket_template_id) AS recurring_count,
|
||||
(SELECT COUNT(*) FROM project_template_ticket_templates WHERE project_template_ticket_templates.ticket_template_id = ticket_templates.ticket_template_id) AS project_count
|
||||
FROM ticket_templates
|
||||
LEFT JOIN categories ON category_id = ticket_template_category_id AND ticket_template_category_id > 0
|
||||
LEFT JOIN users ON user_id = ticket_template_assigned_to AND ticket_template_assigned_to > 0
|
||||
WHERE ticket_template_archived_at IS " . ($show_archived ? 'NOT NULL' : 'NULL') . "
|
||||
" . ($search !== '' ? "AND (ticket_template_name LIKE '%$search_sql%' OR ticket_template_description LIKE '%$search_sql%' OR ticket_template_subject LIKE '%$search_sql%')" : '') . "
|
||||
ORDER BY ticket_template_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$templates[intval($row['ticket_template_id'])] = $row;
|
||||
}
|
||||
$usage = ticketTemplateUsage(array_keys($templates));
|
||||
$archived_count = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM ticket_templates WHERE ticket_template_archived_at IS NOT NULL"))[0]);
|
||||
$tag_rows = [];
|
||||
$sql_tags = mysqli_query($mysqli, "SELECT ticket_template_id, tags.* FROM ticket_template_tags JOIN tags ON tags.tag_id = ticket_template_tags.tag_id ORDER BY tag_name");
|
||||
while ($row = mysqli_fetch_assoc($sql_tags)) {
|
||||
$tag_rows[intval($row['ticket_template_id'])][] = $row;
|
||||
}
|
||||
|
||||
// This page with some of its query changed - null drops a key
|
||||
$page_url = function (array $change = []) use ($show_archived, $search) {
|
||||
$query = array_merge(['q' => $search !== '' ? $search : null, 'archived' => $show_archived ? 1 : null], $change);
|
||||
return 'ticket_templates.php' . (($query = http_build_query(array_filter($query, function ($v) {
|
||||
return $v !== null;
|
||||
}))) ? "?$query" : '');
|
||||
};
|
||||
|
||||
$csrf = $_SESSION['csrf_token'];
|
||||
|
||||
?>
|
||||
|
||||
@@ -30,98 +58,132 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
<button type="button" class="btn btn-primary ajax-modal" data-modal-url="modals/ticket_template/ticket_template_add.php" data-modal-size="lg"><i class="fas fa-plus me-2"></i>New Ticket Template</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-header py-3">
|
||||
<form autocomplete="off">
|
||||
<div class="row g-2 align-items-center">
|
||||
|
||||
<div class="col-md-4">
|
||||
<div class="input-group">
|
||||
<input type="search" class="form-control" name="q" value="<?php if(isset($q)){ echo stripslashes(escapeHtml($q)); } ?>" placeholder="Search Ticket Templates">
|
||||
<button class="btn btn-dark" title="Search"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-8">
|
||||
</div>
|
||||
|
||||
<div class="p-2 border-bottom">
|
||||
<p class="small text-secondary mb-2">
|
||||
A ticket ready to raise - its subject, details and tasks, and how it is set up. Pick one on New Ticket, when raising tickets for several assets or clients, and on recurring tickets;
|
||||
project templates raise theirs. <span class="font-monospace">[Client]</span>, <span class="font-monospace">[Contact]</span>, <span class="font-monospace">[Month]</span> and the like are filled in when a ticket is raised.
|
||||
</p>
|
||||
<form autocomplete="off" class="d-flex flex-wrap align-items-center gap-2">
|
||||
<?php if ($show_archived) { ?><input type="hidden" name="archived" value="1"><?php } ?>
|
||||
<div class="input-group input-group-sm w-auto">
|
||||
<input type="search" class="form-control" name="q" value="<?= escapeHtml($search) ?>" placeholder="Search templates">
|
||||
<button class="btn btn-primary" title="Search"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
<div class="btn-group btn-group-sm" role="group" aria-label="Current or archived">
|
||||
<a class="btn btn-outline-secondary<?= $show_archived ? '' : ' active' ?>" href="<?= escapeHtml($page_url(['archived' => null])) ?>">Current</a>
|
||||
<a class="btn btn-outline-secondary<?= $show_archived ? ' active' : '' ?>" href="<?= escapeHtml($page_url(['archived' => 1])) ?>">Archived <span class="badge text-bg-secondary ms-1"><?= $archived_count ?></span></a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive-sm">
|
||||
<table class="table table-striped table-borderless table-hover mb-0">
|
||||
<thead class="text-dark <?php if($num_rows[0] == 0) { echo "d-none"; } ?>">
|
||||
<tr>
|
||||
<th class="ps-3">
|
||||
<a class="text-secondary" href="?<?= $url_query_strings_sort ?>&sort=ticket_template_name&order=<?= $disp ?>">
|
||||
Template <?php if ($sort == 'ticket_template_name') { echo $order_icon; } ?>
|
||||
</a>
|
||||
</th>
|
||||
<th>
|
||||
<a class="text-secondary" href="?<?= $url_query_strings_sort ?>&sort=task_count&order=<?= $disp ?>">
|
||||
Tasks <?php if ($sort == 'task_count') { echo $order_icon; } ?>
|
||||
</a>
|
||||
</th>
|
||||
<th class="text-center">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<table class="table table-borderless table-hover align-middle mb-0">
|
||||
<?php if ($templates) { ?>
|
||||
<thead class="text-dark">
|
||||
<tr>
|
||||
<th class="ps-3">Template</th>
|
||||
<th class="d-none d-lg-table-cell">Sets up</th>
|
||||
<th class="d-none d-sm-table-cell">Tasks</th>
|
||||
<th class="d-none d-md-table-cell">Used</th>
|
||||
<th class="text-center" style="width: 1%">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<?php } ?>
|
||||
<tbody>
|
||||
<?php
|
||||
|
||||
while($row = mysqli_fetch_assoc($sql)){
|
||||
$ticket_template_id = intval($row['ticket_template_id']);
|
||||
$ticket_template_name = escapeHtml($row['ticket_template_name']);
|
||||
$ticket_template_description = escapeHtml($row['ticket_template_description']);
|
||||
$ticket_template_subject = escapeHtml($row['ticket_template_subject']);
|
||||
$ticket_template_created_at = escapeHtml($row['ticket_template_created_at']);
|
||||
<?php foreach ($templates as $template_id => $row) {
|
||||
$name = escapeHtml($row['ticket_template_name']);
|
||||
$task_count = intval($row['task_count']);
|
||||
|
||||
$minutes = intval($row['task_minutes']);
|
||||
$used = $usage[$template_id] ?? ['count' => 0, 'open' => 0, 'last' => null];
|
||||
$tags = $tag_rows[$template_id] ?? [];
|
||||
$defaults = ticketTemplateDefaultsHtml($row);
|
||||
$tags_html = $tags ? '<span class="d-inline-flex flex-wrap gap-1">' . implode('', array_map('tagPill', $tags)) . '</span>' : '';
|
||||
$set_up = trim($defaults . ($defaults !== '' && $tags_html !== '' ? ' ' : '') . $tags_html);
|
||||
$linked = [];
|
||||
if (intval($row['recurring_count'])) {
|
||||
$linked[] = intval($row['recurring_count']) . ' recurring ticket' . (intval($row['recurring_count']) === 1 ? '' : 's');
|
||||
}
|
||||
if (intval($row['project_count'])) {
|
||||
$linked[] = intval($row['project_count']) . ' project template' . (intval($row['project_count']) === 1 ? '' : 's');
|
||||
}
|
||||
ob_start(); ?>
|
||||
<?php if ($used['count']) { ?>
|
||||
<div class="small text-nowrap"><?= $used['count'] ?> ticket<?= $used['count'] === 1 ? '' : 's' ?><?= $used['open'] ? ' <span class="text-secondary">· ' . $used['open'] . ' open</span>' : '' ?></div>
|
||||
<div class="small text-secondary text-nowrap" title="<?= escapeHtml($used['last']) ?>">Last <?= timeAgo($used['last']) ?></div>
|
||||
<?php } else { ?>
|
||||
<span class="small text-secondary">Not yet</span>
|
||||
<?php } ?>
|
||||
<?php if ($linked) { ?><div class="small text-secondary"><i class="fas fa-fw fa-link me-1"></i><?= escapeHtml(implode(', ', $linked)) ?></div><?php } ?>
|
||||
<?php $used_html = ob_get_clean();
|
||||
?>
|
||||
<tr>
|
||||
<td class="ps-3">
|
||||
<a class="text-dark">
|
||||
<div class="d-flex">
|
||||
<i class="fa fa-fw fa-2x fa-life-ring me-3"></i>
|
||||
<div class="flex-grow-1">
|
||||
<div>
|
||||
<a href="ticket_template.php?ticket_template_id=<?= $ticket_template_id ?>">
|
||||
<?= $ticket_template_name ?>
|
||||
</a>
|
||||
</div>
|
||||
<div><small class="text-secondary"><?= $ticket_template_description ?></small></div>
|
||||
</div>
|
||||
<div class="d-flex align-items-center gap-3">
|
||||
<span class="itflow-asset-icon itflow-asset-tone-other d-none d-sm-inline-flex" aria-hidden="true"><i class="fas fa-fw fa-life-ring"></i></span>
|
||||
<div class="min-w-0">
|
||||
<a class="fw-semibold text-body" href="ticket_template.php?ticket_template_id=<?= $template_id ?>"><?= $name ?></a>
|
||||
<?php if (trim((string) $row['ticket_template_description']) !== '') { ?>
|
||||
<div class="small text-secondary"><?= escapeHtml($row['ticket_template_description']) ?></div>
|
||||
<?php } elseif (trim((string) $row['ticket_template_subject']) !== '') { ?>
|
||||
<div class="small text-secondary text-truncate"><?= escapeHtml($row['ticket_template_subject']) ?></div>
|
||||
<?php } ?>
|
||||
<?php if ($row['ticket_template_archived_at']) { ?>
|
||||
<div class="small text-secondary"><i class="fas fa-fw fa-archive me-1"></i>Archived <?= date('M j, Y', strtotime($row['ticket_template_archived_at'])) ?></div>
|
||||
<?php } ?>
|
||||
<!-- On smaller screens what it sets up and its use come along under the name -->
|
||||
<?php if ($set_up !== '') { ?><div class="d-lg-none mt-1"><?= $set_up ?></div><?php } ?>
|
||||
<div class="d-md-none mt-1"><?= $used_html ?></div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</td>
|
||||
<td><?= $task_count ?></td>
|
||||
<td class="d-none d-lg-table-cell"><?= $set_up !== '' ? $set_up : '<span class="small text-secondary">Just the subject and details</span>' ?></td>
|
||||
<td class="d-none d-sm-table-cell text-nowrap">
|
||||
<?php if ($task_count) { ?>
|
||||
<div class="small"><?= $task_count ?> task<?= $task_count === 1 ? '' : 's' ?></div>
|
||||
<?php if ($minutes) { ?><div class="small text-secondary"><i class="far fa-fw fa-clock me-1"></i><?= escapeHtml(ticketTemplateMinutesText($minutes)) ?></div><?php } ?>
|
||||
<?php } else { ?>
|
||||
<span class="small text-secondary">None</span>
|
||||
<?php } ?>
|
||||
</td>
|
||||
<td class="d-none d-md-table-cell"><?= $used_html ?></td>
|
||||
<td>
|
||||
<div class="dropdown dropstart text-center">
|
||||
<button class="btn btn-secondary btn-sm" title="More actions" data-bs-toggle="dropdown">
|
||||
<i class="fas fa-ellipsis-h"></i>
|
||||
</button>
|
||||
<button class="btn btn-secondary btn-sm" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-ellipsis-h"></i></button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_ticket_template=<?= $ticket_template_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-trash me-2"></i>Delete
|
||||
</a>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/ticket_template/ticket_template_edit.php?id=<?= $template_id ?>"><i class="fas fa-fw fa-edit me-2"></i>Edit</a>
|
||||
<?php if (!$row['ticket_template_archived_at']) { ?>
|
||||
<a class="dropdown-item" href="/agent/tickets.php?new_from_template=<?= $template_id ?>"><i class="fas fa-fw fa-plus me-2"></i>New ticket from it</a>
|
||||
<?php } ?>
|
||||
<a class="dropdown-item" href="post.php?copy_ticket_template=<?= $template_id ?>&csrf_token=<?= $csrf ?>" title="A new template starting from this one"><i class="fas fa-fw fa-copy me-2"></i>Copy</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<?php if ($row['ticket_template_archived_at']) { ?>
|
||||
<a class="dropdown-item" href="post.php?restore_ticket_template=<?= $template_id ?>&csrf_token=<?= $csrf ?>"><i class="fas fa-fw fa-redo me-2"></i>Restore</a>
|
||||
<?php } else { ?>
|
||||
<a class="dropdown-item" href="post.php?archive_ticket_template=<?= $template_id ?>&csrf_token=<?= $csrf ?>" title="Not offered for new tickets - recurring tickets and project templates that use it keep it"><i class="fas fa-fw fa-archive me-2"></i>Archive</a>
|
||||
<?php } ?>
|
||||
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_ticket_template=<?= $template_id ?>&csrf_token=<?= $csrf ?>"
|
||||
data-confirm-title="Delete <?= $name ?>?" data-confirm-text="Its tasks go with it<?= $linked ? ', and ' . escapeHtml(implode(' and ', $linked)) . ' stop using it' : '' ?>. Tickets raised from it stay as they are." data-confirm-button="Delete"><i class="fas fa-fw fa-trash me-2"></i>Delete</a>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php
|
||||
$empty_state = [
|
||||
'thing' => 'ticket templates',
|
||||
'icon' => 'fa-life-ring',
|
||||
'text' => 'The details and tasks to start a ticket with.',
|
||||
'actions' => [['label' => 'New Ticket Template', 'modal' => 'modals/ticket_template/ticket_template_add.php', 'size' => 'lg']],
|
||||
];
|
||||
?>
|
||||
<?php require_once "../includes/filter_footer.php";
|
||||
?>
|
||||
|
||||
<?php if (!$templates) { ?>
|
||||
<?= emptyStateHtml([
|
||||
'thing' => 'ticket templates',
|
||||
'title' => $show_archived ? 'No archived ticket templates' : 'No ticket templates yet',
|
||||
'text' => $show_archived ? 'An archived template isn\'t offered for new tickets, but the recurring tickets and project templates that use it keep it.' : 'A ticket ready to raise - its subject, details and tasks, and how it is set up.',
|
||||
'icon' => 'fa-life-ring',
|
||||
'filtered' => $search !== '',
|
||||
'clear_url' => $page_url(['q' => null]),
|
||||
'actions' => $show_archived ? [] : [['label' => 'New Ticket Template', 'modal' => 'modals/ticket_template/ticket_template_add.php', 'size' => 'lg']],
|
||||
]) ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
Reference in New Issue
Block a user