mirror of
https://github.com/itflow-org/itflow
synced 2026-12-03 09:39:02 +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:
@@ -3,69 +3,76 @@
|
||||
/*
|
||||
* ITFlow - Ticket template picker
|
||||
*
|
||||
* Shared by the ticket add modal and the recurring ticket add/edit modals. Each
|
||||
* option carries the template's subject, details and task list as data
|
||||
* attributes, which agent/js/ticket_tasks_modal.js applies to the form when the
|
||||
* template is picked.
|
||||
* Shared by New Ticket, the New Tickets windows of the assets and clients
|
||||
* lists, and the recurring ticket add/edit windows. Each option carries what
|
||||
* the template puts into the form (ticketTemplatePickerData(),
|
||||
* functions/ticket_template.php) - its subject, details and tasks, and its
|
||||
* category, priority, billing, agent, due time and tags - which
|
||||
* agent/js/ticket_tasks_modal.js writes into the form's fields marked
|
||||
* data-template-field when it is picked. A form leaves out the fields it
|
||||
* doesn't have.
|
||||
*
|
||||
* Set $selected_ticket_template_id before including to pre-select a template (an
|
||||
* archived one stays listed while it is the one selected, so an existing link
|
||||
* remains visible). Defaults to none.
|
||||
* Set before including:
|
||||
* $selected_ticket_template_id the one to start with (an archived one stays listed
|
||||
* while it is the one selected, so an existing link shows)
|
||||
* $ticket_template_field the field's name - ticket_template_id by default
|
||||
* $ticket_template_apply_on_load fill the form in from the one selected as it opens
|
||||
* $ticket_template_hint the line under it, when it should say something else
|
||||
*/
|
||||
|
||||
$selected_ticket_template_id = intval($selected_ticket_template_id ?? 0);
|
||||
$ticket_template_field = $ticket_template_field ?? 'ticket_template_id';
|
||||
$ticket_template_apply_on_load = !empty($ticket_template_apply_on_load);
|
||||
$ticket_template_hint = $ticket_template_hint ?? 'Picking one fills in the ticket - change anything before it is made. <span class="font-monospace">[Client]</span>, <span class="font-monospace">[Month]</span> and the like are filled in when it is saved.';
|
||||
|
||||
// Every template's tasks in one pass, rather than a query per option
|
||||
// Every template's tasks and tags in one pass each, rather than a query per option
|
||||
$ticket_template_tasks = [];
|
||||
|
||||
$sql_ticket_template_tasks = mysqli_query(
|
||||
$mysqli,
|
||||
"SELECT task_template_ticket_template_id, task_template_name, task_template_completion_estimate
|
||||
FROM task_templates
|
||||
ORDER BY task_template_order ASC, task_template_id ASC"
|
||||
);
|
||||
|
||||
$sql_ticket_template_tasks = mysqli_query($mysqli, "SELECT task_template_id, task_template_ticket_template_id, task_template_name, task_template_completion_estimate
|
||||
FROM task_templates ORDER BY task_template_order ASC, task_template_id ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql_ticket_template_tasks)) {
|
||||
$ticket_template_tasks[intval($row['task_template_ticket_template_id'])][] = [
|
||||
'name' => $row['task_template_name'],
|
||||
'estimate' => intval($row['task_template_completion_estimate'])
|
||||
];
|
||||
$ticket_template_tasks[intval($row['task_template_ticket_template_id'])][] = ['id' => intval($row['task_template_id']), 'name' => $row['task_template_name'], 'estimate' => intval($row['task_template_completion_estimate'])];
|
||||
}
|
||||
$ticket_template_tags = [];
|
||||
$sql_ticket_template_tags = mysqli_query($mysqli, "SELECT ticket_template_id, ticket_template_tags.tag_id FROM ticket_template_tags
|
||||
JOIN tags ON tags.tag_id = ticket_template_tags.tag_id AND tag_archived_at IS NULL");
|
||||
while ($row = mysqli_fetch_row($sql_ticket_template_tags)) {
|
||||
$ticket_template_tags[intval($row[0])][] = intval($row[1]);
|
||||
}
|
||||
|
||||
$sql_ticket_templates = mysqli_query($mysqli, "SELECT ticket_templates.*, category_name, user_name AS assignee_name 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 NULL OR ticket_template_id = $selected_ticket_template_id
|
||||
ORDER BY ticket_template_name ASC");
|
||||
|
||||
?>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Template</label>
|
||||
<label class="form-label">Template</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-cube"></i></span>
|
||||
<select class="form-select select2" id="ticket_template_select" name="ticket_template_id">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-cube"></i></span>
|
||||
<select class="form-select select2" id="ticket_template_select" name="<?= escapeHtml($ticket_template_field) ?>" data-template-picker<?= $ticket_template_apply_on_load ? ' data-template-apply="1"' : '' ?>>
|
||||
<option value="0">- No Template -</option>
|
||||
<?php
|
||||
$sql_ticket_templates = mysqli_query(
|
||||
$mysqli,
|
||||
"SELECT ticket_template_id, ticket_template_name, ticket_template_subject, ticket_template_details
|
||||
FROM ticket_templates
|
||||
WHERE ticket_template_archived_at IS NULL OR ticket_template_id = $selected_ticket_template_id
|
||||
ORDER BY ticket_template_name ASC"
|
||||
);
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql_ticket_templates)) {
|
||||
$ticket_template_id_select = intval($row['ticket_template_id']);
|
||||
$ticket_template_name_select = escapeHtml($row['ticket_template_name']);
|
||||
$ticket_template_subject_select = escapeHtml($row['ticket_template_subject']);
|
||||
$ticket_template_details_select = escapeHtml($row['ticket_template_details']);
|
||||
$ticket_template_task_list = $ticket_template_tasks[$ticket_template_id_select] ?? [];
|
||||
$task_count = count($ticket_template_task_list);
|
||||
<?php while ($row = mysqli_fetch_assoc($sql_ticket_templates)) {
|
||||
$id = intval($row['ticket_template_id']);
|
||||
$tasks = $ticket_template_tasks[$id] ?? [];
|
||||
// A second line saying what it sets up, and what it is for
|
||||
$about = [count($tasks) . ' task' . (count($tasks) === 1 ? '' : 's')];
|
||||
if (!empty($row['ticket_template_priority'])) {
|
||||
$about[] = $row['ticket_template_priority'];
|
||||
}
|
||||
if (!empty($row['category_name'])) {
|
||||
$about[] = $row['category_name'];
|
||||
}
|
||||
if (intval($row['ticket_template_due_hours'])) {
|
||||
$about[] = 'due in ' . ticketTemplateDueText($row['ticket_template_due_hours']);
|
||||
}
|
||||
$description = trim((string) $row['ticket_template_description']);
|
||||
$data = ticketTemplatePickerData($row, $tasks, $ticket_template_tags[$id] ?? []);
|
||||
?>
|
||||
<option value="<?= $ticket_template_id_select ?>"
|
||||
data-subject="<?= $ticket_template_subject_select ?>"
|
||||
data-details="<?= $ticket_template_details_select ?>"
|
||||
data-tasks="<?= escapeHtml(json_encode($ticket_template_task_list)) ?>"
|
||||
<?php if ($selected_ticket_template_id == $ticket_template_id_select) { echo "selected"; } ?>>
|
||||
<?= $ticket_template_name_select ?> (<?= $task_count ?> tasks)
|
||||
</option>
|
||||
<option value="<?= $id ?>" <?= $selected_ticket_template_id === $id ? 'selected' : '' ?><?= selectOptionData(['icon' => 'fas fa-cube', 'description' => implode(' · ', $about) . ($description !== '' ? " - $description" : ''), 'keywords' => $description]) ?><?php foreach ($data as $key => $value) { ?> data-template-<?= $key ?>="<?= escapeHtml($value) ?>"<?php } ?>><?= escapeHtml($row['ticket_template_name']) ?><?= $row['ticket_template_archived_at'] ? ' (archived)' : '' ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
<small class="form-text text-muted">Picking a template fills in the subject, details and tasks below. You can edit them afterwards.</small>
|
||||
<div class="form-text"><?= $ticket_template_hint ?></div>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Editable task rows for the ticket and recurring ticket add/edit modals, and the
|
||||
// ticket template picker that pre-fills them.
|
||||
// ticket template picker (agent/includes/inc_ticket_template_select.php) that
|
||||
// fills in the form - its fields marked data-template-field.
|
||||
//
|
||||
// Rows submit as parallel tasks[] and task_estimates[] arrays, aligned by their
|
||||
// order in the form, so removing a row removes both of its inputs together.
|
||||
@@ -86,27 +87,6 @@
|
||||
});
|
||||
}
|
||||
|
||||
// dataset always gives a string; jQuery used to auto-parse JSON here, so
|
||||
// parse it explicitly and still tolerate an already-parsed value
|
||||
function readTemplateTasks(option) {
|
||||
|
||||
const tasks = option.dataset.tasks;
|
||||
|
||||
if (!tasks) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (typeof tasks === 'string') {
|
||||
try {
|
||||
return JSON.parse(tasks);
|
||||
} catch (error) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
return tasks;
|
||||
}
|
||||
|
||||
document.addEventListener('click', function (e) {
|
||||
if (!e.target.closest('#ticketTaskAdd')) {
|
||||
return;
|
||||
@@ -125,38 +105,101 @@
|
||||
}
|
||||
});
|
||||
|
||||
// Ticket template picker - fills in the subject, details and task rows
|
||||
document.addEventListener('change', function (e) {
|
||||
const select = e.target.closest('#ticket_template_select');
|
||||
if (!select) {
|
||||
// The form's field for one thing a template sets - marked data-template-field
|
||||
function templateField(form, name) {
|
||||
return form.querySelector('[data-template-field="' + name + '"]');
|
||||
}
|
||||
|
||||
// Pick a value in a <select> when it has it - the picker redraws by itself
|
||||
function pickOption(select, value) {
|
||||
if (!select || value === '' || value === undefined) {
|
||||
return;
|
||||
}
|
||||
const option = Array.from(select.options).find(o => o.value === String(value));
|
||||
if (option) {
|
||||
select.value = option.value;
|
||||
select.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
}
|
||||
}
|
||||
|
||||
// Write a template into its form: what it sets, field by field. A field
|
||||
// the form doesn't have is skipped, and anything the template leaves
|
||||
// alone ('' on the option) stays as it is.
|
||||
function applyTemplate(select) {
|
||||
|
||||
const option = select.options[select.selectedIndex];
|
||||
const form = select.closest('form');
|
||||
|
||||
// Selecting "- No Template -" only unlinks the template - it must not wipe
|
||||
// whatever the user has already written or added
|
||||
if (!parseInt(option.value, 10)) {
|
||||
if (!option || !parseInt(option.value, 10) || !form) {
|
||||
return;
|
||||
}
|
||||
const data = option.dataset;
|
||||
|
||||
const templateSubject = option.dataset.subject || '';
|
||||
const templateDetails = option.dataset.details || '';
|
||||
|
||||
document.getElementById('subjectInput').value = templateSubject;
|
||||
|
||||
if (window.tinymce) {
|
||||
const editor = tinymce.get('detailsInput');
|
||||
if (editor) {
|
||||
editor.setContent(templateDetails);
|
||||
} else {
|
||||
document.getElementById('detailsInput').value = templateDetails;
|
||||
}
|
||||
} else {
|
||||
document.getElementById('detailsInput').value = templateDetails;
|
||||
const subject = templateField(form, 'subject') || document.getElementById('subjectInput');
|
||||
if (subject && data.templateSubject) {
|
||||
subject.value = data.templateSubject;
|
||||
}
|
||||
|
||||
setTaskRows(readTemplateTasks(option));
|
||||
const details = templateField(form, 'details') || document.getElementById('detailsInput');
|
||||
if (details && data.templateDetails) {
|
||||
const editor = window.tinymce && details.id ? tinymce.get(details.id) : null;
|
||||
if (editor) {
|
||||
editor.setContent(data.templateDetails);
|
||||
} else {
|
||||
details.value = data.templateDetails;
|
||||
}
|
||||
}
|
||||
|
||||
pickOption(templateField(form, 'priority'), data.templatePriority);
|
||||
pickOption(templateField(form, 'category'), data.templateCategory);
|
||||
pickOption(templateField(form, 'assigned'), data.templateAssigned);
|
||||
|
||||
const billable = templateField(form, 'billable');
|
||||
if (billable && data.templateBillable !== '' && data.templateBillable !== undefined) {
|
||||
billable.checked = data.templateBillable === '1';
|
||||
}
|
||||
|
||||
const due = templateField(form, 'due');
|
||||
if (due && data.templateDue) {
|
||||
due.value = data.templateDue;
|
||||
}
|
||||
|
||||
// Its tags are added to any already picked
|
||||
const tags = templateField(form, 'tags');
|
||||
if (tags && data.templateTags) {
|
||||
data.templateTags.split(',').forEach(function (id) {
|
||||
const tag = Array.from(tags.options).find(o => o.value === id);
|
||||
if (tag) {
|
||||
tag.selected = true;
|
||||
}
|
||||
});
|
||||
tags.dispatchEvent(new Event('change', { bubbles: true }));
|
||||
}
|
||||
|
||||
if (document.getElementById('ticketTasksContainer')) {
|
||||
let tasks = [];
|
||||
try {
|
||||
tasks = JSON.parse(data.templateTasks || '[]');
|
||||
} catch (error) {
|
||||
tasks = [];
|
||||
}
|
||||
setTaskRows(tasks);
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('change', function (e) {
|
||||
const select = e.target.closest('[data-template-picker]');
|
||||
if (select) {
|
||||
applyTemplate(select);
|
||||
}
|
||||
});
|
||||
|
||||
// Opened for one template - New ticket from it - it is filled in straight away
|
||||
document.querySelectorAll('[data-template-picker][data-template-apply]').forEach(function (select) {
|
||||
select.removeAttribute('data-template-apply');
|
||||
applyTemplate(select);
|
||||
});
|
||||
|
||||
})();
|
||||
|
||||
@@ -21,16 +21,22 @@ ob_start();
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<?php
|
||||
$ticket_template_field = 'bulk_ticket_template_id';
|
||||
$ticket_template_hint = "Picking one fills in the tickets - change anything before they are made. <span class=\"font-monospace\">[Asset]</span>, <span class=\"font-monospace\">[Contact]</span> and the like are filled in for each; with <span class=\"font-monospace\">[Asset]</span> in the subject, the asset's name isn't put in front.";
|
||||
require_once '../../includes/inc_ticket_template_select.php';
|
||||
?>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Subject <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="bulk_subject" placeholder="Asset Name will be prepended to Subject" maxlength="200" required>
|
||||
<input type="text" class="form-control" name="bulk_subject" data-template-field="subject" placeholder="Asset Name will be prepended to Subject" maxlength="500" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<textarea class="form-control tinymceTicket" id="textInput" name="bulk_details"></textarea>
|
||||
<textarea class="form-control tinymceTicket" id="textInput" name="bulk_details" data-template-field="details"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
@@ -40,7 +46,7 @@ ob_start();
|
||||
<label>Priority <strong class="text-danger">*</strong></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="bulk_priority" required>
|
||||
<select class="form-select select2" name="bulk_priority" data-template-field="priority" required>
|
||||
<option data-color="var(--bs-info)">Low</option>
|
||||
<option selected data-color="var(--bs-warning)">Medium</option>
|
||||
<option data-color="var(--bs-danger)">High</option>
|
||||
@@ -55,7 +61,7 @@ ob_start();
|
||||
<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="bulk_category">
|
||||
<select class="form-select select2" name="bulk_category" data-template-field="category">
|
||||
<option value="0">- Not Categorized -</option>
|
||||
<?= categoryOptionsHtml('Ticket') ?>
|
||||
</select>
|
||||
@@ -70,7 +76,7 @@ ob_start();
|
||||
<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="bulk_assigned_to">
|
||||
<select class="form-select select2" name="bulk_assigned_to" data-template-field="assigned">
|
||||
<option value="0">Not Assigned</option>
|
||||
<?php
|
||||
|
||||
@@ -117,7 +123,7 @@ ob_start();
|
||||
<?php if ($config_module_enable_accounting) { ?>
|
||||
<div class="mb-3">
|
||||
<div class="form-check form-switch">
|
||||
<input type="checkbox" class="form-check-input" name="bulk_billable" <?php if ($config_ticket_default_billable == 1) { echo "checked"; } ?> value="1" id="billableSwitch">
|
||||
<input type="checkbox" class="form-check-input" name="bulk_billable" data-template-field="billable" <?php if ($config_ticket_default_billable == 1) { echo "checked"; } ?> value="1" id="billableSwitch">
|
||||
<label class="form-check-label" for="billableSwitch">Billable</label>
|
||||
</div>
|
||||
</div>
|
||||
@@ -131,5 +137,7 @@ ob_start();
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script src="/agent/js/ticket_tasks_modal.js"></script>
|
||||
|
||||
<?php
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
|
||||
@@ -22,16 +22,22 @@ ob_start();
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<?php
|
||||
$ticket_template_field = 'bulk_ticket_template_id';
|
||||
$ticket_template_hint = "Picking one fills in the tickets - change anything before they are made. <span class=\"font-monospace\">[Client]</span>, <span class=\"font-monospace\">[Month]</span> and the like are filled in for each.";
|
||||
require_once '../../includes/inc_ticket_template_select.php';
|
||||
?>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Subject <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-tag"></i></span>
|
||||
<input type="text" class="form-control" name="bulk_subject" placeholder="Enter a subject" maxlength="200" required>
|
||||
<input type="text" class="form-control" name="bulk_subject" data-template-field="subject" placeholder="Enter a subject" maxlength="500" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<textarea class="form-control tinymceTicket" id="textInput" name="bulk_details"></textarea>
|
||||
<textarea class="form-control tinymceTicket" id="textInput" name="bulk_details" data-template-field="details"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
@@ -41,7 +47,7 @@ ob_start();
|
||||
<label>Priority <strong class="text-danger">*</strong></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="bulk_priority" required>
|
||||
<select class="form-select select2" name="bulk_priority" data-template-field="priority" required>
|
||||
<option data-color="var(--bs-info)">Low</option>
|
||||
<option selected data-color="var(--bs-warning)">Medium</option>
|
||||
<option data-color="var(--bs-danger)">High</option>
|
||||
@@ -56,7 +62,7 @@ ob_start();
|
||||
<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="bulk_category">
|
||||
<select class="form-select select2" name="bulk_category" data-template-field="category">
|
||||
<option value="0">- Not Categorized -</option>
|
||||
<?= categoryOptionsHtml('Ticket') ?>
|
||||
</select>
|
||||
@@ -74,7 +80,7 @@ ob_start();
|
||||
<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="bulk_assigned_to">
|
||||
<select class="form-select select2" name="bulk_assigned_to" data-template-field="assigned">
|
||||
<option value="0">Not Assigned</option>
|
||||
<?php
|
||||
|
||||
@@ -118,10 +124,17 @@ ob_start();
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="form-check form-switch">
|
||||
<input type="checkbox" class="form-check-input" name="use_primary_contact" value="1" id="bulkTicketPrimaryContact">
|
||||
<label class="form-check-label" for="bulkTicketPrimaryContact">For each client's primary contact</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($config_module_enable_accounting) { ?>
|
||||
<div class="mb-3">
|
||||
<div class="form-check form-switch">
|
||||
<input type="checkbox" class="form-check-input" name="bulk_billable" <?php if ($config_ticket_default_billable == 1) { echo "checked"; } ?> value="1" id="billableSwitch">
|
||||
<input type="checkbox" class="form-check-input" name="bulk_billable" data-template-field="billable" <?php if ($config_ticket_default_billable == 1) { echo "checked"; } ?> value="1" id="billableSwitch">
|
||||
<label class="form-check-label" for="billableSwitch">Billable</label>
|
||||
</div>
|
||||
</div>
|
||||
@@ -135,5 +148,7 @@ ob_start();
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script src="/agent/js/ticket_tasks_modal.js"></script>
|
||||
|
||||
<?php
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
|
||||
@@ -92,18 +92,21 @@ ob_start();
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<?php require_once '../../includes/inc_ticket_template_select.php'; ?>
|
||||
<?php
|
||||
$ticket_template_hint = "Picking one fills in the recurring ticket - change anything before it is saved. <span class=\"font-monospace\">[Client]</span>, <span class=\"font-monospace\">[Month]</span> and the like are filled in each time it raises a ticket.";
|
||||
require_once '../../includes/inc_ticket_template_select.php';
|
||||
?>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Subject <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" id="subjectInput" name="subject" placeholder="Subject" maxlength="500" required>
|
||||
<input type="text" class="form-control" id="subjectInput" name="subject" data-template-field="subject" placeholder="Subject" maxlength="500" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<textarea class="form-control tinymceTicket" id="detailsInput" name="details"></textarea>
|
||||
<textarea class="form-control tinymceTicket" id="detailsInput" name="details" data-template-field="details"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
@@ -113,7 +116,7 @@ ob_start();
|
||||
<label>Priority <strong class="text-danger">*</strong></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" required>
|
||||
<select class="form-select select2" name="priority" data-template-field="priority" required>
|
||||
<option data-color="var(--bs-info)">Low</option>
|
||||
<option selected data-color="var(--bs-warning)">Medium</option>
|
||||
<option data-color="var(--bs-danger)">High</option>
|
||||
@@ -128,7 +131,7 @@ ob_start();
|
||||
<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">
|
||||
<select class="form-select select2" name="category_id" data-template-field="category">
|
||||
<option value="0">- Not Categorized -</option>
|
||||
<?= categoryOptionsHtml('Ticket') ?>
|
||||
</select>
|
||||
@@ -143,7 +146,7 @@ ob_start();
|
||||
<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">
|
||||
<select class="form-select select2" name="assigned_to" data-template-field="assigned">
|
||||
<option value="0">- Unassigned -</option>
|
||||
<?php
|
||||
|
||||
@@ -164,7 +167,7 @@ ob_start();
|
||||
<?php if ($config_module_enable_accounting && lookupUserPermission('module_sales') >= 2) { ?>
|
||||
<div class="mb-3">
|
||||
<div class="form-check form-switch">
|
||||
<input type="checkbox" class="form-check-input" name="billable" <?php if ($config_ticket_default_billable == 1) { echo "checked"; } ?> value="1" id="billable">
|
||||
<input type="checkbox" class="form-check-input" name="billable" <?php if ($config_ticket_default_billable == 1) { echo "checked"; } ?> value="1" id="billable" data-template-field="billable">
|
||||
<label class="form-check-label" for="billable">The tickets it raises are billable</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -107,6 +107,7 @@ ob_start();
|
||||
|
||||
<?php
|
||||
$selected_ticket_template_id = intval($recurring['recurring_ticket_ticket_template_id']);
|
||||
$ticket_template_hint = "Picking one fills in the recurring ticket - change anything before it is saved. <span class=\"font-monospace\">[Client]</span>, <span class=\"font-monospace\">[Month]</span> and the like are filled in each time it raises a ticket.";
|
||||
require_once '../../includes/inc_ticket_template_select.php';
|
||||
?>
|
||||
|
||||
@@ -114,12 +115,12 @@ ob_start();
|
||||
<label>Subject <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" id="subjectInput" name="subject" placeholder="Subject" maxlength="500" value="<?= escapeHtml($recurring['recurring_ticket_subject']) ?>" required>
|
||||
<input type="text" class="form-control" id="subjectInput" name="subject" data-template-field="subject" placeholder="Subject" maxlength="500" value="<?= escapeHtml($recurring['recurring_ticket_subject']) ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<textarea class="form-control tinymceTicket" id="detailsInput" name="details"><?= escapeHtml($recurring['recurring_ticket_details']) ?></textarea>
|
||||
<textarea class="form-control tinymceTicket" id="detailsInput" name="details" data-template-field="details"><?= escapeHtml($recurring['recurring_ticket_details']) ?></textarea>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
@@ -128,7 +129,7 @@ ob_start();
|
||||
<label>Priority <strong class="text-danger">*</strong></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" required>
|
||||
<select class="form-select select2" name="priority" data-template-field="priority" required>
|
||||
<?php foreach (['Low' => 'var(--bs-info)', 'Medium' => 'var(--bs-warning)', 'High' => 'var(--bs-danger)', 'Urgent' => 'var(--bs-emphasis-color)'] as $priority => $color) { ?>
|
||||
<option <?= $recurring['recurring_ticket_priority'] === $priority ? 'selected' : '' ?> data-color="<?= $color ?>"><?= $priority ?></option>
|
||||
<?php } ?>
|
||||
@@ -141,7 +142,7 @@ ob_start();
|
||||
<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">
|
||||
<select class="form-select select2" name="category_id" data-template-field="category">
|
||||
<option value="0">- Not categorized -</option>
|
||||
<?= categoryOptionsHtml('Ticket', $category_id) ?>
|
||||
</select>
|
||||
@@ -155,7 +156,7 @@ ob_start();
|
||||
<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">
|
||||
<select class="form-select select2" name="assigned_to" data-template-field="assigned">
|
||||
<option value="0">- Unassigned -</option>
|
||||
<?php
|
||||
$sql_agents = mysqli_query($mysqli, "SELECT user_id, user_name, user_avatar FROM users
|
||||
@@ -170,7 +171,7 @@ ob_start();
|
||||
|
||||
<?php if ($config_module_enable_accounting && lookupUserPermission('module_sales') >= 2) { ?>
|
||||
<div class="form-check form-switch">
|
||||
<input type="checkbox" class="form-check-input" id="recurringBillable<?= $recurring_ticket_id ?>" name="billable" <?= $billable ? 'checked' : '' ?> value="1">
|
||||
<input type="checkbox" class="form-check-input" id="recurringBillable<?= $recurring_ticket_id ?>" name="billable" <?= $billable ? 'checked' : '' ?> value="1" data-template-field="billable">
|
||||
<label class="form-check-label" for="recurringBillable<?= $recurring_ticket_id ?>">The tickets it raises are billable</label>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
@@ -20,6 +20,10 @@ $asset_id = intval($_GET['asset_id'] ?? 0);
|
||||
$location_id = intval($_GET['location_id'] ?? 0);
|
||||
$vendor_id = intval($_GET['vendor_id'] ?? 0);
|
||||
|
||||
// Opened for one template - New ticket from it, on the template's page - it starts filled in
|
||||
$selected_ticket_template_id = intval($_GET['ticket_template_id'] ?? 0);
|
||||
$ticket_template_apply_on_load = $selected_ticket_template_id > 0;
|
||||
|
||||
// A ticket started from somewhere that knows what it is about (a license's
|
||||
// Renewal Ticket) - plain text in, escaped here
|
||||
$prefill_subject = mb_substr(trim((string) ($_GET['subject'] ?? '')), 0, 500);
|
||||
@@ -148,12 +152,12 @@ ob_start();
|
||||
<label>Subject <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" id="subjectInput" name="subject" placeholder="Subject" maxlength="500" value="<?= escapeHtml($prefill_subject) ?>" required>
|
||||
<input type="text" class="form-control" id="subjectInput" name="subject" placeholder="Subject" maxlength="500" value="<?= escapeHtml($prefill_subject) ?>" data-template-field="subject" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<textarea class="form-control tinymceTicket" id="detailsInput" name="details"><?= escapeHtml($prefill_details_html) ?></textarea>
|
||||
<textarea class="form-control tinymceTicket" id="detailsInput" name="details" data-template-field="details"><?= escapeHtml($prefill_details_html) ?></textarea>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
@@ -163,7 +167,7 @@ ob_start();
|
||||
<label>Priority <strong class="text-danger">*</strong></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" required>
|
||||
<select class="form-select select2" name="priority" data-template-field="priority" required>
|
||||
<option data-color="var(--bs-info)">Low</option>
|
||||
<option selected data-color="var(--bs-warning)">Medium</option>
|
||||
<option data-color="var(--bs-danger)">High</option>
|
||||
@@ -178,7 +182,7 @@ ob_start();
|
||||
<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">
|
||||
<select class="form-select select2" name="category_id" data-template-field="category">
|
||||
<option value="0">- Not Categorized -</option>
|
||||
<?= categoryOptionsHtml('Ticket') ?>
|
||||
</select>
|
||||
@@ -195,7 +199,7 @@ ob_start();
|
||||
<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">
|
||||
<select class="form-select select2" name="assigned_to" data-template-field="assigned">
|
||||
<option value="0">- Unassigned -</option>
|
||||
<?php
|
||||
|
||||
@@ -218,20 +222,20 @@ ob_start();
|
||||
<label>Due</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-calendar-check"></i></span>
|
||||
<input type="datetime-local" class="form-control" name="due">
|
||||
<input type="datetime-local" class="form-control" name="due" data-template-field="due">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<?= tagFormFieldHtml('ticket', [], 'Onboarding, Hardware, Escalated') ?>
|
||||
<?= tagFormFieldHtml('ticket', [], 'Onboarding, Hardware, Escalated', 'Tags', 'data-template-field="tags"') ?>
|
||||
</div>
|
||||
|
||||
<?php if ($config_module_enable_accounting) { ?>
|
||||
<div class="mb-3">
|
||||
<div class="form-check form-switch">
|
||||
<input type="checkbox" class="form-check-input" name="billable" <?php if ($config_ticket_default_billable == 1) { echo "checked"; } ?> value="1" id="billable">
|
||||
<input type="checkbox" class="form-check-input" name="billable" <?php if ($config_ticket_default_billable == 1) { echo "checked"; } ?> value="1" id="billable" data-template-field="billable">
|
||||
<label class="form-check-label" for="billable">Mark Billable</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -718,116 +718,87 @@ if (isset($_POST['bulk_add_client_ticket'])) {
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$assigned_to = intval($_POST['bulk_assigned_to']);
|
||||
if ($assigned_to == 0) {
|
||||
$ticket_status = 1;
|
||||
} else {
|
||||
$ticket_status = 2;
|
||||
}
|
||||
$subject = escapeSql($_POST['bulk_subject']);
|
||||
$priority = escapeSql($_POST['bulk_priority']);
|
||||
$category_id = intval($_POST['bulk_category']);
|
||||
$details = mysqli_real_escape_string($mysqli, $_POST['bulk_details']);
|
||||
$project_id = intval($_POST['bulk_project']);
|
||||
$use_primary_contact = intval($_POST['use_primary_contact']);
|
||||
$ticket_template_id = intval($_POST['bulk_ticket_template_id']);
|
||||
$billable = intval($_POST['bulk_billable'] ?? 0);
|
||||
|
||||
// Check to see if adding a ticket by template
|
||||
if($ticket_template_id) {
|
||||
$sql = mysqli_query($mysqli, "SELECT ticket_template_details, ticket_template_subject FROM ticket_templates WHERE ticket_template_id = $ticket_template_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
|
||||
// Override Template Subject
|
||||
if(empty($subject)) {
|
||||
$subject = escapeSql($row['ticket_template_subject']);
|
||||
}
|
||||
$details = mysqli_escape_string($mysqli, $row['ticket_template_details']);
|
||||
|
||||
// Get Associated Tasks from the ticket template
|
||||
$sql_task_templates = mysqli_query($mysqli, "SELECT task_template_name, task_template_order FROM task_templates WHERE task_template_ticket_template_id = $ticket_template_id");
|
||||
|
||||
// Every client picked, checked before any ticket is made
|
||||
$client_ids = array_values(array_unique(array_filter(array_map('intval', (array) ($_POST['client_ids'] ?? [])))));
|
||||
foreach ($client_ids as $client_id) {
|
||||
enforceClientAccess($client_id);
|
||||
}
|
||||
|
||||
// Create ticket for each selected asset
|
||||
if (isset($_POST['client_ids'])) {
|
||||
$assigned_to = ticketAgentId($_POST['bulk_assigned_to'] ?? 0);
|
||||
$ticket_status = $assigned_to ? TICKET_STATUS_OPEN : TICKET_STATUS_NEW;
|
||||
$subject_input = trim((string) ($_POST['bulk_subject'] ?? ''));
|
||||
$priority = escapeSql(ticketPriority($_POST['bulk_priority'] ?? ''));
|
||||
$category_id = ticketCategoryId($_POST['bulk_category'] ?? 0);
|
||||
$details = mysqli_real_escape_string($mysqli, (string) ($_POST['bulk_details'] ?? ''));
|
||||
$project_id = intval($_POST['bulk_project'] ?? 0);
|
||||
$use_primary_contact = !empty($_POST['use_primary_contact']);
|
||||
$ticket_template_id = intval($_POST['bulk_ticket_template_id'] ?? 0);
|
||||
$billable = intval($_POST['bulk_billable'] ?? 0) ? 1 : 0;
|
||||
$ticket_prefix = escapeSql($config_ticket_prefix);
|
||||
|
||||
// Check every selected client before creating any tickets
|
||||
foreach ($_POST['client_ids'] as $client_id) {
|
||||
enforceClientAccess(intval($client_id));
|
||||
// A template fills in what was left empty
|
||||
$template = ticketTemplateRow($ticket_template_id);
|
||||
if ($template) {
|
||||
$subject_input = $subject_input !== '' ? $subject_input : (string) $template['ticket_template_subject'];
|
||||
$details = trim((string) ($_POST['bulk_details'] ?? '')) !== '' ? $details : mysqli_real_escape_string($mysqli, (string) $template['ticket_template_details']);
|
||||
}
|
||||
if ($subject_input === '') {
|
||||
flashAlert('The tickets need a subject.', 'error');
|
||||
redirect();
|
||||
}
|
||||
$subject = escapeSql(mb_substr($subject_input, 0, 500));
|
||||
|
||||
$ticket_ids = [];
|
||||
foreach ($client_ids as $client_id) {
|
||||
if (!getFieldById('clients', $client_id, 'client_name')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get a Asset Count
|
||||
$client_count = count($_POST['client_ids']);
|
||||
// Each client's primary contact, when asked; a shared project only when it is internal
|
||||
$contact_id = 0;
|
||||
if ($use_primary_contact) {
|
||||
$primary = mysqli_fetch_row(mysqli_query($mysqli, "SELECT contact_id FROM contacts WHERE contact_client_id = $client_id AND contact_primary = 1 AND contact_archived_at IS NULL LIMIT 1"));
|
||||
$contact_id = $primary ? intval($primary[0]) : 0;
|
||||
}
|
||||
$ticket_project_id = ticketClientOwnedId('project', $project_id, $client_id);
|
||||
|
||||
foreach ($_POST['client_ids'] as $client_id) {
|
||||
$client_id = intval($client_id);
|
||||
// Atomically increment and get the new ticket number
|
||||
mysqli_query($mysqli, "UPDATE settings SET config_ticket_next_number = LAST_INSERT_ID(config_ticket_next_number), config_ticket_next_number = config_ticket_next_number + 1 WHERE company_id = 1");
|
||||
$ticket_number = mysqli_insert_id($mysqli);
|
||||
$url_key = randomString(32);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT client_name FROM clients WHERE client_id = $client_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$ticket_prefix', ticket_number = $ticket_number, ticket_source = 'Agent', ticket_category = $category_id,
|
||||
ticket_subject = '$subject', ticket_details = '$details', ticket_priority = '$priority', ticket_billable = $billable, ticket_status = $ticket_status,
|
||||
ticket_created_by = $session_user_id, ticket_assigned_to = $assigned_to, ticket_contact_id = $contact_id, ticket_url_key = '$url_key',
|
||||
ticket_client_id = $client_id, ticket_invoice_id = 0, ticket_project_id = $ticket_project_id");
|
||||
$ticket_id = mysqli_insert_id($mysqli);
|
||||
applyTicketSla($ticket_id);
|
||||
|
||||
$client_name = escapeSql($row['client_name']);
|
||||
|
||||
// Atomically increment and get the new ticket number
|
||||
mysqli_query($mysqli, "
|
||||
UPDATE settings
|
||||
SET
|
||||
config_ticket_next_number = LAST_INSERT_ID(config_ticket_next_number),
|
||||
config_ticket_next_number = config_ticket_next_number + 1
|
||||
WHERE company_id = 1
|
||||
");
|
||||
|
||||
$ticket_number = mysqli_insert_id($mysqli);
|
||||
|
||||
// Sanitize Config Vars from get_settings.php and Session Vars from check_login.php
|
||||
$config_ticket_prefix = escapeSql($config_ticket_prefix);
|
||||
$config_ticket_from_name = escapeSql($config_ticket_from_name);
|
||||
$config_ticket_from_email = escapeSql($config_ticket_from_email);
|
||||
$config_base_url = escapeSql($config_base_url);
|
||||
|
||||
//Generate a unique URL key for clients to access
|
||||
$url_key = randomString(32);
|
||||
|
||||
// Only a project of this client's, or an internal one
|
||||
$ticket_project_id = ticketClientOwnedId('project', $project_id, $client_id);
|
||||
|
||||
mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_category = $category_id, ticket_subject = '$subject', ticket_details = '$details', ticket_priority = '$priority', ticket_billable = $billable, ticket_status = $ticket_status, ticket_created_by = $session_user_id, ticket_assigned_to = $assigned_to, ticket_url_key = '$url_key', ticket_client_id = $client_id, ticket_project_id = $ticket_project_id");
|
||||
|
||||
$ticket_id = mysqli_insert_id($mysqli);
|
||||
applyTicketSla($ticket_id);
|
||||
|
||||
// Add Tasks
|
||||
if (!empty($_POST['tasks'])) {
|
||||
foreach ($_POST['tasks'] as $task) {
|
||||
$task_name = escapeSql($task);
|
||||
// Check that task_name is not-empty (For some reason the !empty on the array doesnt work here like in watchers)
|
||||
if (!empty($task_name)) {
|
||||
mysqli_query($mysqli,"INSERT INTO tasks SET task_name = '$task_name', task_ticket_id = $ticket_id");
|
||||
}
|
||||
}
|
||||
// Tasks typed in, then the template's - its tags and due time too, and [Client] filled in
|
||||
foreach ((array) ($_POST['tasks'] ?? []) as $task) {
|
||||
$task_name = escapeSql(mb_substr(trim((string) $task), 0, 255));
|
||||
if ($task_name !== '') {
|
||||
mysqli_query($mysqli, "INSERT INTO tasks SET task_name = '$task_name', task_ticket_id = $ticket_id");
|
||||
}
|
||||
|
||||
// Add Tasks from Template if Template was selected
|
||||
if($ticket_template_id) {
|
||||
if (mysqli_num_rows($sql_task_templates) > 0) {
|
||||
while ($row = mysqli_fetch_assoc($sql_task_templates)) {
|
||||
$task_order = intval($row['task_template_order']);
|
||||
$task_name = escapeSql($row['task_template_name']);
|
||||
|
||||
mysqli_query($mysqli,"INSERT INTO tasks SET task_name = '$task_name', task_order = $task_order, task_ticket_id = $ticket_id");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Custom action/notif handler
|
||||
triggerCustomAction('ticket_create', $ticket_id);
|
||||
}
|
||||
if ($template) {
|
||||
ticketTemplateFinish($ticket_id, $ticket_template_id, true, true);
|
||||
}
|
||||
|
||||
logAudit("Ticket", "Bulk Create", "$session_name created $client_count tickets for $client_name");
|
||||
|
||||
flashAlert("<strong>$client_count</strong> tickets created for selected clients");
|
||||
|
||||
logAudit("Ticket", "Create", "$session_name created ticket $ticket_prefix$ticket_number - $subject", $client_id, $ticket_id);
|
||||
triggerCustomAction('ticket_create', $ticket_id);
|
||||
$ticket_ids[] = $ticket_id;
|
||||
}
|
||||
$count = count($ticket_ids);
|
||||
|
||||
// The agent they went to hears once, about all of them
|
||||
if ($ticket_ids && $assigned_to) {
|
||||
ticketMailAssigned($assigned_to, $ticket_ids, stripslashes($session_name));
|
||||
}
|
||||
|
||||
logAudit("Ticket", "Bulk Create", "$session_name created $count ticket(s) for the clients picked");
|
||||
|
||||
flashAlert("Created <strong>$count</strong> ticket" . ($count === 1 ? '' : 's') . " for the clients picked");
|
||||
|
||||
redirect();
|
||||
|
||||
|
||||
@@ -68,27 +68,6 @@ if (isset($_POST['edit_ticket_task'])) {
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['edit_ticket_template_task'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$task_template_id = intval($_POST['task_template_id']);
|
||||
$task_name = escapeSql($_POST['name']);
|
||||
$task_order = intval($_POST['order']);
|
||||
$task_completion_estimate = intval($_POST['completion_estimate']);
|
||||
|
||||
mysqli_query($mysqli, "UPDATE task_templates SET task_template_name = '$task_name', task_template_order = $task_order, task_template_completion_estimate = $task_completion_estimate WHERE task_template_id = $task_template_id");
|
||||
|
||||
logAudit("Task", "Edit", "$session_name edited task $task_name", 0, $task_template_id);
|
||||
|
||||
flashAlert("Task <strong>" . stripslashes($task_name) . "</strong> saved");
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['delete_task'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
@@ -138,8 +138,6 @@ if (isset($_POST['add_ticket'])) {
|
||||
foreach (parseSubmittedTasks() as $task) {
|
||||
mysqli_query($mysqli, "INSERT INTO tasks SET task_name = '{$task['name']}', task_order = {$task['order']}, task_completion_estimate = {$task['estimate']}, task_ticket_id = $ticket_id");
|
||||
}
|
||||
} else {
|
||||
addTasksFromTicketTemplate($ticket_id, $ticket_template_id);
|
||||
}
|
||||
|
||||
// Store any attached files against the ticket itself
|
||||
@@ -149,6 +147,12 @@ if (isset($_POST['add_ticket'])) {
|
||||
ticketSetOtherAssets($ticket_id, $other_asset_ids);
|
||||
tagSetForRecord('ticket', $ticket_id, (array) ($_POST['tags'] ?? []));
|
||||
|
||||
// Raised from a template - kept for the template's use, and its [Client] and the like filled in.
|
||||
// The form had the template's fields in it already, so nothing more is added here.
|
||||
if ($ticket_template_id) {
|
||||
ticketTemplateFinish($ticket_id, $ticket_template_id, false, !isset($_POST['tasks_submitted']));
|
||||
}
|
||||
|
||||
// Raised about a service - from the service page's "Report a problem"
|
||||
foreach (array_unique(array_map('intval', (array) ($_POST['service_ids'] ?? []))) as $service_id) {
|
||||
$service = serviceRow($service_id);
|
||||
@@ -900,15 +904,13 @@ if (isset($_POST['bulk_add_asset_ticket'])) {
|
||||
$ticket_prefix = escapeSql($config_ticket_prefix);
|
||||
|
||||
// A template fills in what was left empty
|
||||
if ($ticket_template_id) {
|
||||
$template = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT ticket_template_details, ticket_template_subject FROM ticket_templates WHERE ticket_template_id = $ticket_template_id"));
|
||||
if ($template) {
|
||||
$subject_input = $subject_input !== '' ? $subject_input : (string) $template['ticket_template_subject'];
|
||||
$details = $details !== '' ? $details : mysqli_real_escape_string($mysqli, (string) $template['ticket_template_details']);
|
||||
}
|
||||
$template = ticketTemplateRow($ticket_template_id);
|
||||
if ($template) {
|
||||
$subject_input = $subject_input !== '' ? $subject_input : (string) $template['ticket_template_subject'];
|
||||
$details = $details !== '' ? $details : mysqli_real_escape_string($mysqli, (string) $template['ticket_template_details']);
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
$ticket_ids = [];
|
||||
foreach (array_unique(array_map('intval', (array) ($_POST['asset_ids'] ?? []))) as $asset_id) {
|
||||
$asset = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT asset_client_id, asset_name, asset_contact_id, asset_location_id FROM assets WHERE asset_id = $asset_id"));
|
||||
if (!$asset) {
|
||||
@@ -921,7 +923,8 @@ if (isset($_POST['bulk_add_asset_ticket'])) {
|
||||
$contact_id = ticketClientOwnedId('contact', $asset['asset_contact_id'], $client_id);
|
||||
$location_id = ticketClientOwnedId('location', $asset['asset_location_id'], $client_id);
|
||||
$project_id = ticketClientOwnedId('project', $project_input, $client_id);
|
||||
$subject = escapeSql(mb_substr($asset['asset_name'] . ' - ' . $subject_input, 0, 500));
|
||||
// The asset's name goes in front - unless the subject says where, with [Asset]
|
||||
$subject = escapeSql(mb_substr(stripos($subject_input, '[asset]') !== false ? $subject_input : $asset['asset_name'] . ' - ' . $subject_input, 0, 500));
|
||||
|
||||
mysqli_query($mysqli, "UPDATE settings SET config_ticket_next_number = LAST_INSERT_ID(config_ticket_next_number), config_ticket_next_number = config_ticket_next_number + 1 WHERE company_id = 1");
|
||||
$ticket_number = mysqli_insert_id($mysqli);
|
||||
@@ -934,18 +937,26 @@ if (isset($_POST['bulk_add_asset_ticket'])) {
|
||||
$ticket_id = mysqli_insert_id($mysqli);
|
||||
applyTicketSla($ticket_id);
|
||||
|
||||
// Tasks from the modal, then the template's
|
||||
// Tasks from the modal, then the template's - its tags and due time too, and [Asset] filled in
|
||||
foreach ((array) ($_POST['tasks'] ?? []) as $task) {
|
||||
$task_name = escapeSql(mb_substr(trim((string) $task), 0, 255));
|
||||
if ($task_name !== '') {
|
||||
mysqli_query($mysqli, "INSERT INTO tasks SET task_name = '$task_name', task_ticket_id = $ticket_id");
|
||||
}
|
||||
}
|
||||
addTasksFromTicketTemplate($ticket_id, $ticket_template_id);
|
||||
if ($template) {
|
||||
ticketTemplateFinish($ticket_id, $ticket_template_id, true, true);
|
||||
}
|
||||
|
||||
logAudit("Ticket", "Create", "$session_name created ticket $ticket_prefix$ticket_number - $subject", $client_id, $ticket_id);
|
||||
triggerCustomAction('ticket_create', $ticket_id);
|
||||
$count++;
|
||||
$ticket_ids[] = $ticket_id;
|
||||
}
|
||||
$count = count($ticket_ids);
|
||||
|
||||
// The agent they went to hears once, about all of them
|
||||
if ($ticket_ids && $assigned_to) {
|
||||
ticketMailAssigned($assigned_to, $ticket_ids, stripslashes($session_name));
|
||||
}
|
||||
|
||||
logAudit("Ticket", "Bulk Create", "$session_name created $count ticket(s) for the assets picked");
|
||||
|
||||
@@ -536,15 +536,16 @@ $export_extra = [
|
||||
?>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($_GET['open'])) { ?>
|
||||
<?php if (!empty($_GET['open']) || !empty($_GET['new_from_template'])) { ?>
|
||||
<script>
|
||||
// Opened from somewhere that wants one ticket's quick look
|
||||
// Opened from somewhere that wants one ticket's quick look - or a new
|
||||
// ticket from a template (New ticket from it, Admin > Ticket Templates)
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var open = document.createElement('a');
|
||||
open.className = 'ajax-modal';
|
||||
open.href = '#';
|
||||
open.dataset.modalSize = 'lg';
|
||||
open.dataset.modalUrl = 'modals/ticket/ticket.php?id=<?= intval($_GET['open']) ?>';
|
||||
open.dataset.modalUrl = <?= json_encode(!empty($_GET['open']) ? 'modals/ticket/ticket.php?id=' . intval($_GET['open']) : 'modals/ticket/ticket_add.php?ticket_template_id=' . intval($_GET['new_from_template'])) ?>;
|
||||
document.body.appendChild(open);
|
||||
open.click();
|
||||
open.remove();
|
||||
|
||||
Reference in New Issue
Block a user