Files
itflow/agent/modals/email_unprocessed/email_unprocessed_view.php

90 lines
5.3 KiB
PHP

<?php
/*
* Tickets > Unprocessed Email > View - the email as it came, from its copy (mailUnprocessedRead(),
* functions/mail_unprocessed.php): who it is from and to, why it wasn't taken, its text, attachments and headers.
* Shown as text - nothing in it runs or loads. Make a Ticket and Add to a Ticket open their own windows.
*/
require_once '../../../includes/modal_header.php';
enforceUserPermission('module_support');
$row = mailUnprocessedReady() ? mailUnprocessedRow($_GET['id'] ?? 0) : null;
if (!$row) {
echo json_encode(['error' => "That email isn't there any more."]);
exit;
}
$id = intval($row['email_unprocessed_id']);
$state = mailUnprocessedState($row);
$email = mailUnprocessedRead($row);
$can_edit = lookupUserPermission('module_support') >= 2 && $state['key'] === 'waiting';
$subject = trim((string) $row['email_unprocessed_subject']) !== '' ? escapeHtml($row['email_unprocessed_subject']) : '(no subject)';
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title text-truncate"><i class="fas fa-fw fa-envelope-open-text me-2"></i><?= $subject ?></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" data-unprocessed-view="<?= $id ?>">
<div class="d-flex flex-wrap align-items-center gap-2 mb-3">
<span class="badge rounded-pill <?= $state['badge'] ?>"><?= escapeHtml($state['label']) ?></span>
<?php if ($state['key'] === 'waiting' && trim((string) $row['email_unprocessed_reason']) !== '') { ?>
<span class="small text-warning-emphasis" data-unprocessed-reason><i class="fas fa-fw fa-exclamation-triangle me-1"></i><?= escapeHtml($row['email_unprocessed_reason']) ?></span>
<?php } elseif ($state['detail'] !== '') { ?>
<span class="small text-body-secondary"><?= escapeHtml($state['detail']) ?></span>
<?php } ?>
</div>
<?php if ($email['missing']) { ?>
<div class="alert alert-warning small mb-0">Its copy is missing, so only what was noted when it came is shown.</div>
<dl class="row small mt-3 mb-0">
<dt class="col-sm-2">From</dt><dd class="col-sm-10 text-break"><?= escapeHtml(trim($row['email_unprocessed_from_name'] . ' <' . $row['email_unprocessed_from_email'] . '>')) ?></dd>
<dt class="col-sm-2">Received</dt><dd class="col-sm-10"><?= escapeHtml($row['email_unprocessed_received_at']) ?></dd>
</dl>
<?php if (trim((string) $row['email_unprocessed_preview']) !== '') { ?>
<div class="border rounded p-3 small text-break" style="white-space: pre-wrap"><?= escapeHtml($row['email_unprocessed_preview']) ?></div>
<?php } ?>
<?php } elseif ($email['too_big']) { ?>
<div class="alert alert-warning small mb-0">It is too big to show here - download it to open it in your email program.</div>
<?php } else { ?>
<dl class="row small mb-2" data-unprocessed-fields>
<?php foreach ($email['fields'] as $label => $value) { ?>
<dt class="col-sm-2 text-body-secondary fw-normal"><?= escapeHtml($label) ?></dt>
<dd class="col-sm-10 text-break mb-1"><?= escapeHtml($value) ?></dd>
<?php } ?>
</dl>
<?php if ($email['attachments']) { ?>
<div class="small mb-3" data-unprocessed-attachments>
<i class="fas fa-fw fa-paperclip text-body-secondary me-1"></i><?= implode(', ', array_map('escapeHtml', $email['attachments'])) ?>
</div>
<?php } ?>
<div class="border rounded p-3 small text-break overflow-auto" style="white-space: pre-wrap; max-height: 50vh" data-unprocessed-text><?= $email['text'] !== '' ? escapeHtml($email['text']) : '<span class="text-body-secondary">It has no text to show.</span>' ?></div>
<details class="mt-3 small">
<summary class="text-body-secondary">Headers</summary>
<pre class="mt-2 mb-0 p-2 bg-body-tertiary rounded small overflow-auto" style="max-height: 30vh"><?= escapeHtml($email['headers']) ?></pre>
</details>
<?php } ?>
</div>
<div class="modal-footer">
<?php if ($can_edit) { ?>
<button type="button" class="btn btn-primary fw-bold ajax-modal" data-modal-url="modals/email_unprocessed/email_unprocessed_ticket.php?id=<?= $id ?>"><i class="fas fa-plus me-2"></i>Make a Ticket</button>
<button type="button" class="btn btn-outline-primary ajax-modal" data-modal-url="modals/email_unprocessed/email_unprocessed_reply.php?id=<?= $id ?>"><i class="fas fa-reply me-2"></i>Add to a Ticket</button>
<a class="btn btn-outline-secondary" href="post.php?unprocessed_email=retry&id=<?= $id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>" title="As any email is taken - after making them a contact, say"><i class="fas fa-redo-alt me-2"></i>Try Again</a>
<a class="btn btn-outline-danger" href="post.php?unprocessed_email=dismiss&id=<?= $id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>"><i class="fas fa-times me-2"></i>Dismiss</a>
<?php } ?>
<?php if (!$email['missing']) { ?>
<a class="btn btn-light" href="post.php?download_unprocessed_email=<?= $id ?>"><i class="fas fa-download me-2"></i>Download</a>
<?php } ?>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fas fa-times me-2"></i>Close</button>
</div>
<?php
require_once '../../../includes/modal_footer.php';