mirror of
https://github.com/itflow-org/itflow
synced 2026-12-03 09:39:02 +00:00
198 lines
12 KiB
PHP
198 lines
12 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Edit Reply - an agent's reply or note on a ticket: its words, its time, and who sees it. Internal note, public note -
|
|
* or email reply, which makes it public and emails it now to the people in To, as the reply box would (with its
|
|
* writer's signature, from them by name, its files with it). Email reply is there while the ticket isn't closed, mail is
|
|
* set up and the reply hasn't been emailed yet. Saved by edit_ticket_reply (agent/post/ticket.php).
|
|
*/
|
|
|
|
require_once '../../../includes/modal_header.php';
|
|
|
|
enforceUserPermission('module_support', 2);
|
|
|
|
$ticket_reply_id = intval($_GET['id']);
|
|
|
|
$sql = mysqli_query($mysqli, "SELECT ticket_id, ticket_client_id, ticket_closed_at, ticket_reply, ticket_reply_time_worked, ticket_reply_type, ticket_reply_created_at, ticket_reply_by, user_name AS reply_by_name,
|
|
" . (ticketWorkTimesReady() ? 'ticket_reply_work_start, ticket_reply_work_end,' : 'NULL AS ticket_reply_work_start, NULL AS ticket_reply_work_end,') . "
|
|
" . (ticketReplyEmailReady() ? 'ticket_reply_emailed, ticket_reply_emailed_to' : 'NULL AS ticket_reply_emailed, NULL AS ticket_reply_emailed_to') . " FROM ticket_replies
|
|
LEFT JOIN tickets ON ticket_id = ticket_reply_ticket_id
|
|
LEFT JOIN users ON user_id = ticket_reply_by AND user_type = 1
|
|
WHERE ticket_reply_id = $ticket_reply_id
|
|
LIMIT 1"
|
|
);
|
|
|
|
$row = mysqli_fetch_assoc($sql);
|
|
if (!$row) {
|
|
echo json_encode(['error' => 'That reply no longer exists.']);
|
|
exit;
|
|
}
|
|
$ticket_reply_type = escapeHtml($row['ticket_reply_type']);
|
|
$ticket_reply_time_worked = date_create($row['ticket_reply_time_worked']);
|
|
$ticket_reply_time_worked_formatted = date_format($ticket_reply_time_worked, 'H:i:s');
|
|
$ticket_reply = escapeHtml($row['ticket_reply']);
|
|
$client_id = intval($row['ticket_client_id']);
|
|
|
|
if ($client_id) {
|
|
enforceClientAccess();
|
|
}
|
|
|
|
// Emailing it from here - as the reply box can: mail set up and a contact with an email address - not on a closed ticket,
|
|
// nor a second time
|
|
$contact_email = (string) (mysqli_fetch_row(mysqli_query($mysqli, "SELECT contact_email FROM tickets JOIN contacts ON contact_id = ticket_contact_id WHERE ticket_id = " . intval($row['ticket_id'])))[0] ?? '');
|
|
$can_email = $row['ticket_reply_type'] !== 'Client' && empty($row['ticket_closed_at']) && intval($row['ticket_reply_emailed']) !== 1
|
|
&& $contact_email !== '' && !empty($config_smtp_provider);
|
|
$reply_to = $can_email && ticketReplyRecipientsReady() ? ticketReplyRecipients(intval($row['ticket_id'])) : [];
|
|
$writer = $row['reply_by_name'] !== null ? (string) $row['reply_by_name'] : '';
|
|
|
|
// Who it was emailed to - they have it as it was sent
|
|
$emailed_to = '';
|
|
if (intval($row['ticket_reply_emailed']) === 1) {
|
|
$emailed_names = array_map(function ($recipient) {
|
|
return (string) (($recipient['name'] ?? '') !== '' ? $recipient['name'] : ($recipient['email'] ?? ''));
|
|
}, (array) json_decode((string) $row['ticket_reply_emailed_to'], true));
|
|
$emailed_names = array_values(array_filter($emailed_names));
|
|
$emailed_to = $emailed_names ? $emailed_names[0] . (count($emailed_names) > 1 ? ' and ' . (count($emailed_names) - 1) . ' more' : '') : 'the client';
|
|
}
|
|
|
|
// Generate the HTML form content using output buffering.
|
|
ob_start();
|
|
|
|
?>
|
|
|
|
<div class="modal-header bg-dark">
|
|
<h5 class="modal-title"><i class="fas fa-fw fa-edit me-2"></i>Edit Reply</h5>
|
|
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></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_reply_id" value="<?= $ticket_reply_id ?>">
|
|
|
|
<div class="modal-body">
|
|
|
|
<div class="mb-3" data-reply-edit-types>
|
|
<div class="btn-group w-100" role="group" aria-label="Who sees it">
|
|
<input class="btn-check" id="ticket_reply_type_opt0" type="radio" name="ticket_reply_type" value="Internal" <?php if ($ticket_reply_type == 'Internal') { echo "checked"; } ?>>
|
|
<label class="btn btn-outline-dark" for="ticket_reply_type_opt0"><i class="fas fa-fw fa-lock me-1"></i>Internal note</label>
|
|
<input class="btn-check" id="ticket_reply_type_opt1" type="radio" name="ticket_reply_type" value="Public" <?php if ($ticket_reply_type == 'Public') { echo "checked"; } ?>>
|
|
<label class="btn btn-outline-info" for="ticket_reply_type_opt1"><i class="fas fa-fw fa-eye me-1"></i>Public note</label>
|
|
<?php if ($can_email) { ?>
|
|
<input class="btn-check" id="ticket_reply_type_opt2" type="radio" name="ticket_reply_type" value="Email">
|
|
<label class="btn btn-outline-info" for="ticket_reply_type_opt2"><i class="fas fa-fw fa-paper-plane me-1"></i>Email reply</label>
|
|
<?php } ?>
|
|
</div>
|
|
<div class="form-text" data-reply-edit-says="Internal"<?= $ticket_reply_type == 'Internal' ? '' : ' hidden' ?>><i class="fas fa-fw fa-lock me-1"></i>Only your team can see this.</div>
|
|
<div class="form-text" data-reply-edit-says="Public"<?= $ticket_reply_type == 'Public' ? '' : ' hidden' ?>><i class="fas fa-fw fa-eye me-1"></i>The client can see this in the portal. <strong>No email is sent.</strong></div>
|
|
<?php if ($can_email) { ?>
|
|
<div class="form-text" data-reply-edit-says="Email" hidden>
|
|
<i class="fas fa-fw fa-paper-plane me-1"></i>Saving emails it now to the people in To, and it shows in the portal - from <?= $writer !== '' ? escapeHtml($writer) . ' by name, with their signature' : 'the ticket mailbox' ?>, and its files with it.
|
|
</div>
|
|
<?php } ?>
|
|
</div>
|
|
|
|
<?php if ($can_email && $reply_to) { ?>
|
|
<!-- Who it is emailed to - the ticket's To line, as the reply box has it (functions/ticket_reply_recipients.php) -->
|
|
<div class="mb-3" data-reply-edit-to hidden>
|
|
<input type="hidden" name="email_to_shown" value="1" disabled>
|
|
<div class="input-group">
|
|
<span class="input-group-text"><i class="fas fa-fw fa-envelope me-1"></i>To</span>
|
|
<select class="form-select select2" name="email_to[]" multiple data-tags="true" data-avatar="initials" data-placeholder="Type a name or an email address" aria-label="Email it to">
|
|
<?php foreach ($reply_to as $reply_to_email => $reply_to_person) { ?>
|
|
<option value="<?= escapeHtml($reply_to_email) ?>"<?= $reply_to_person['send'] ? ' selected' : '' ?><?= $reply_to_person['look'] ?><?= selectOptionData(['description' => TICKET_REPLY_TO_GROUPS[$reply_to_person['group']] . ($reply_to_person['name'] !== '' ? " - $reply_to_email" : ''), 'keywords' => $reply_to_email]) ?>><?= escapeHtml($reply_to_person['name'] !== '' ? $reply_to_person['name'] : $reply_to_email) ?></option>
|
|
<?php } ?>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<?php } ?>
|
|
|
|
<?php if ($emailed_to !== '') { ?>
|
|
<div class="alert alert-info small py-2" data-reply-edit-emailed>
|
|
<i class="fas fa-fw fa-paper-plane me-1"></i>This was emailed to <strong><?= escapeHtml($emailed_to) ?></strong>. They keep the email as it was sent - what you change here only changes the ticket<?= $ticket_reply_type == 'Public' ? ' and the portal' : '' ?>.
|
|
</div>
|
|
<?php } ?>
|
|
|
|
<?php
|
|
// @ offers the agents who can open the ticket, while it is an internal note (functions/ticket_mention.php)
|
|
$mention_attr = ticketMentionAgentsAttr($client_id);
|
|
?>
|
|
<div class="mb-3">
|
|
<textarea class="form-control tinymce" name="ticket_reply"<?= $mention_attr ?>><?= $ticket_reply ?></textarea>
|
|
<?php if ($mention_attr !== '') { ?>
|
|
<div class="form-text" data-mention-hint hidden><i class="fas fa-fw fa-at me-1"></i>Type @ to mention someone on your team - anyone you add is told in ITFlow and by email.</div>
|
|
<div class="form-text text-warning-emphasis" data-mention-public hidden><i class="fas fa-fw fa-exclamation-triangle me-1"></i>Mentions only tell people in an internal note - made public, they're plain text, and nobody is told.</div>
|
|
<?php } ?>
|
|
</div>
|
|
|
|
<?php if (!empty($ticket_reply_time_worked)) { ?>
|
|
<div class="row g-2">
|
|
<div class="col-sm-4">
|
|
<div class="mb-3">
|
|
<label class="form-label">Time worked</label>
|
|
<div class="input-group">
|
|
<span class="input-group-text"><i class="fas fa-fw fa-stopwatch"></i></span>
|
|
<input class="form-control" name="time" type="text" placeholder="HH:MM:SS" pattern="([01]?[0-9]|2[0-3]):([0-5]?[0-9]):([0-5]?[0-9])" value="<?= $ticket_reply_time_worked_formatted ?>" required>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php if (ticketWorkTimesReady() && $ticket_reply_time_worked_formatted !== '00:00:00') {
|
|
// When it was worked - for a note without times, ending when it was posted (functions/ticket.php)
|
|
[$work_start, $work_end] = !empty($row['ticket_reply_work_start']) ? [$row['ticket_reply_work_start'], $row['ticket_reply_work_end']] : ticketWorkTimesShown($row); ?>
|
|
<div class="col-sm-8">
|
|
<div class="mb-3">
|
|
<label class="form-label">When it was worked</label>
|
|
<div class="input-group">
|
|
<span class="input-group-text"><i class="fas fa-fw fa-calendar-day"></i></span>
|
|
<input type="date" class="form-control" name="work_date" max="2999-12-31" style="min-width: 9.5rem" value="<?= escapeHtml(substr($work_start, 0, 10)) ?>" aria-label="Date worked">
|
|
<input type="time" class="form-control" name="work_start" step="60" style="min-width: 7.5rem" value="<?= escapeHtml(substr($work_start, 11, 5)) ?>" aria-label="Start">
|
|
<span class="input-group-text px-2">-</span>
|
|
<input type="time" class="form-control" name="work_end" step="60" style="min-width: 7.5rem" value="<?= escapeHtml(substr($work_end, 11, 5)) ?>" aria-label="End">
|
|
</div>
|
|
<div class="form-text">Change the times and the time worked follows them. Change only the time worked and the start moves.</div>
|
|
</div>
|
|
</div>
|
|
<?php } ?>
|
|
</div>
|
|
<?php } ?>
|
|
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="submit" name="edit_ticket_reply" class="btn btn-primary fw-bold" data-reply-edit-save><i class="fas fa-check me-2"></i><span>Save</span></button>
|
|
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fas fa-times me-2"></i>Cancel</button>
|
|
</div>
|
|
</form>
|
|
|
|
<script>
|
|
(function () {
|
|
// What the picked type means, the To line for an email, and the button saying what it does
|
|
const box = document.querySelector('.modal.show [data-reply-edit-types]') || document.querySelector('[data-reply-edit-types]');
|
|
if (!box) {
|
|
return;
|
|
}
|
|
const form = box.closest('form');
|
|
const to = form.querySelector('[data-reply-edit-to]');
|
|
const save = form.querySelector('[data-reply-edit-save] span');
|
|
function show() {
|
|
const picked = form.querySelector('input[name="ticket_reply_type"]:checked');
|
|
const type = picked ? picked.value : '';
|
|
form.querySelectorAll('[data-reply-edit-says]').forEach(function (line) {
|
|
line.hidden = line.dataset.replyEditSays !== type;
|
|
});
|
|
if (to) {
|
|
to.hidden = type !== 'Email';
|
|
to.querySelector('[name="email_to_shown"]').disabled = type !== 'Email';
|
|
}
|
|
if (save) {
|
|
save.textContent = type === 'Email' ? 'Save and Email' : 'Save';
|
|
}
|
|
}
|
|
form.querySelectorAll('input[name="ticket_reply_type"]').forEach(function (radio) {
|
|
radio.addEventListener('change', show);
|
|
});
|
|
show();
|
|
})();
|
|
</script>
|
|
|
|
<?php
|
|
|
|
require_once '../../../includes/modal_footer.php';
|