Merge branch 'fronkdev' into 'master'

Added Email Logging for Emailnotification class

See merge request fronk/thetool!1675
This commit is contained in:
Frank Schubert
2025-08-22 15:51:04 +00:00
26 changed files with 1636 additions and 46 deletions
+141
View File
@@ -654,6 +654,65 @@ $pagination_entity_name = "Vorbestellungen";
</div>
</div>
<style>
#email-log-modal p {
margin-top: 8px;
margin-bottom: 8px;
}
</style>
<div class="modal" tabindex="-1" id="email-log-modal" style="max-height: 100vh;">
<div class="modal-dialog modal-dialog-centered modal-xl">
<div class="modal-content" style="overflow: auto;">
<div class="modal-header">
<h5 class="modal-title">Emailansicht</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col">
<table class="table">
<tr>
<th>Von:</th>
<td id="email-log-from-value" class="text-monospace"></td>
</tr><tr>
<th>An:</th>
<td id="email-log-to-value" class="text-monospace"></td>
</tr><tr>
<th>Gesendet:</th>
<td id="email-log-sent-value" class="text-monospace"></td>
</tr><tr>
<th>Betreff:</th>
<td id="email-log-subject-value" class="text-monospace"></td>
</tr>
</table>
</div>
</div>
<div class="row mb-3" id="email-log-header-section">
<div class="col">
<a href="#" onclick="displayEmailLogHeaders(); return false;"><i class="fas fa-chevron-right fa-fw"></i> Alle Header anzeigen</a>
<div id="email-log-header-view" class="mt-2 text-monospace hidden" style="min-height: 48px; width:100%; border: 1px solid #ccc; padding: 8px; font-family: sans-serif;"></div>
</div>
</div>
<div class="row mb-2" id="email-log-body-section">
<div class="col">
<div id="email-log-body-view" style="min-height: 48px; width:100%; border: 1px solid #000; padding: 8px; font-family: sans-serif; overflow-y: auto;"></div>
</div>
</div>
<div class="row mb-3 hidden" id="email-log-attachments-section">
<div class="col">
<h5>Dateianhänge</h5>
<ul id="email-log-attachment-list" class="list-group"></ul>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
@@ -1702,6 +1761,88 @@ $pagination_entity_name = "Vorbestellungen";
new_remark_elem.prop("readonly", false);
}
/***********************
* Email Log
***********************/
async function displayEmailLogEmail(preorder_id, email_id) {
$("#email-log-from-value").text("");
$("#email-log-to-value").text("");
$("#email-log-log-sent-value").text("");
$("#email-log-subject-value").text("");
$("#email-log-view").empty();
$("#email-log-attachments-section").hide();
$("#email-log-attachment-list").empty();
hideEmailLogHeaders();
if(!email_id) return false;
var resp = await fetch("<?=self::getUrl("Preorder", "api", ["do" => "getLoggedEmail"])?>&eid=" + email_id + "&pid=" + preorder_id);
if(!resp.ok) {
notify("error", "Email konnte nicht geladen werden");
return false;
}
var response = await resp.json();
if(!("result" in response) || typeof response.result !== "object") {
notify("error", "Email konnte nicht geladen werden");
return false;
}
var email = response.result;
$("#email-log-from-value").text(email.from);
$("#email-log-to-value").text(email.to);
$("#email-log-sent-value").text(email.sent);
$("#email-log-subject-value").text(email.subject);
if("headers" in email && typeof email.headers === "object" && Object.keys(email.headers).length > 0) {
for (const [key, value] of Object.entries(email.headers)) {
$("#email-log-header-view").append(
"<strong>" + key + "</strong>: "
+ value.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#39;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
+ "<br/>");
if(key == "From") {
$("#email-log-from-value").text(value);
}
}
}
if("attachments" in email && typeof email.attachments === "object" && Object.keys(email.attachments).length > 0) {
email.attachments.forEach( (item, index) => {
$("#email-log-attachment-list").append('<li class="list-group-item flex-fill p-1" style="border-radius: 0;"><a href="<?=self::getUrl("EmailLog", "downloadContent")?>?aid=' + item.id + '&hash=' + item.hash + '"><span class="filename text-monospace"><i class="far fa-file"></i> ' + item.filename + '</span></a> (' + Math.round((item.filesize/1024/1024)*100)/100 + ' MB)</li>');
});
$("#email-log-attachments-section").show();
}
if(email.bodyIsHtml) {
$("#email-log-body-view").html(email.body);
} else {
$("#email-logbody-view").text(email.body);
}
$("#email-log-modal").modal("show");
}
function displayEmailLogHeaders() {
$("#email-log-header-view").toggleClass("hidden");
if($("#email-log-header-view").hasClass("hidden")) {
$("#email-log-header-section").find("i").addClass("fa-chevron-right").removeClass("fa-chevron-down");
} else {
$("#email-log-header-section").find("i").addClass("fa-chevron-down").removeClass("fa-chevron-right");
}
}
function hideEmailLogHeaders() {
$("#email-log-header-view").empty();
if(!$("#email-log-header-view").hasClass("hidden")) {
$("#email-log-header-view").addClass("hidden");
$("#email-log-header-section").find("i").addClass("fa-chevron-down").removeClass("fa-chevron-right");
}
}
</script>
<script>
$(document).ready(function() {