mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 09:09:01 +00:00
86 lines
4.8 KiB
PHP
86 lines
4.8 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Tickets > Unprocessed Email > Add to a Ticket - the ticket it goes on: an open one, or one closed in the last 30
|
|
* days. Asked of the email parser (agent/post/email_unprocessed.php), which adds it as it would a reply to the ticket -
|
|
* a client reply from a contact or CC, else a note only your team sees. The sender can be made a CC on the ticket
|
|
* first, so it is their reply and they hear back.
|
|
*/
|
|
|
|
require_once '../../../includes/modal_header.php';
|
|
|
|
enforceUserPermission('module_support', 2);
|
|
|
|
$row = mailUnprocessedReady() ? mailUnprocessedRow($_GET['id'] ?? 0) : null;
|
|
if (!$row || $row['email_unprocessed_done_at'] !== null) {
|
|
echo json_encode(['error' => $row ? 'That email was sorted already.' : "That email isn't there any more."]);
|
|
exit;
|
|
}
|
|
|
|
$id = intval($row['email_unprocessed_id']);
|
|
$from_email = trim((string) $row['email_unprocessed_from_email']);
|
|
$from_name = trim((string) $row['email_unprocessed_from_name']);
|
|
$can_add = filter_var($from_email, FILTER_VALIDATE_EMAIL) !== false;
|
|
|
|
// Open tickets, and ones closed lately - the newest first
|
|
$sql_tickets = mysqli_query($mysqli, "SELECT ticket_id, ticket_prefix, ticket_number, ticket_subject, ticket_closed_at, ticket_status_name, client_name, contact_name, contact_email FROM tickets
|
|
LEFT JOIN ticket_statuses ON ticket_status_id = ticket_status
|
|
LEFT JOIN clients ON client_id = ticket_client_id
|
|
LEFT JOIN contacts ON contact_id = ticket_contact_id
|
|
WHERE (ticket_closed_at IS NULL OR ticket_closed_at > NOW() - INTERVAL 30 DAY) " . clientScopeSql('ticket_client_id') . "
|
|
ORDER BY ticket_closed_at IS NOT NULL, ticket_id DESC LIMIT 2000");
|
|
|
|
ob_start();
|
|
|
|
?>
|
|
|
|
<div class="modal-header bg-dark">
|
|
<h5 class="modal-title"><i class="fas fa-fw fa-reply me-2"></i>Add to a Ticket</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="email_unprocessed_id" value="<?= $id ?>">
|
|
<div class="modal-body">
|
|
|
|
<div class="alert alert-info small">
|
|
From <strong><?= escapeHtml($from_name !== '' ? $from_name : ($from_email !== '' ? $from_email : 'no sender address')) ?></strong><?= $from_name !== '' && $from_email !== '' ? ' <' . escapeHtml($from_email) . '>' : '' ?>
|
|
- <?= escapeHtml(trim((string) $row['email_unprocessed_subject']) !== '' ? $row['email_unprocessed_subject'] : '(no subject)') ?><br>
|
|
It is added to the ticket as a reply would be, within a minute - from someone who isn't a contact or CC, as a note only your team sees.
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">Ticket <strong class="text-danger">*</strong></label>
|
|
<div class="input-group">
|
|
<span class="input-group-text"><i class="fas fa-fw fa-life-ring"></i></span>
|
|
<select class="form-select select2" name="ticket_id" required data-placeholder="Search by number, subject or client">
|
|
<option value="">- Pick the ticket -</option>
|
|
<?php while ($ticket = mysqli_fetch_assoc($sql_tickets)) {
|
|
$details = array_filter([(string) $ticket['client_name'], $ticket['ticket_closed_at'] ? 'Closed' : (string) $ticket['ticket_status_name'], (string) $ticket['contact_name']]);
|
|
?>
|
|
<option value="<?= intval($ticket['ticket_id']) ?>" data-description="<?= escapeHtml(implode(' · ', $details)) ?>" data-keywords="<?= escapeHtml(trim($ticket['ticket_number'] . ' ' . $ticket['client_name'] . ' ' . $ticket['contact_email'])) ?>"><?= escapeHtml(ticketReference($ticket) . ' - ' . $ticket['ticket_subject']) ?></option>
|
|
<?php } ?>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($can_add) { ?>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" id="unprocessedAddCcCheck" name="make_cc" value="1">
|
|
<label class="form-check-label" for="unprocessedAddCcCheck">
|
|
Make <?= escapeHtml($from_email) ?> a CC on the ticket
|
|
</label>
|
|
<div class="form-text">So it goes on as their reply - reopening the ticket - and they hear back.</div>
|
|
</div>
|
|
<?php } ?>
|
|
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="submit" name="unprocessed_email_reply" class="btn btn-primary fw-bold"><i class="fas fa-check me-2"></i>Add to Ticket</button>
|
|
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fas fa-times me-2"></i>Cancel</button>
|
|
</div>
|
|
</form>
|
|
|
|
<?php
|
|
require_once '../../../includes/modal_footer.php';
|