Added Email Logging for Emailnotification class
This commit is contained in:
@@ -643,6 +643,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">×</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() {
|
||||
@@ -1690,6 +1749,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, '&').replace(/"/g, '"').replace(/'/g, ''').replace(/</g, '<').replace(/>/g, '>')
|
||||
+ "<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() {
|
||||
|
||||
@@ -823,6 +823,7 @@
|
||||
|
||||
<div id="preorder-detail-<?=$preorder->id?>-emails" class="tab-pane preorder-emails-view">
|
||||
<?php
|
||||
$email_logs = EmailLog::search(["object_type" => "preorder", "object_id" => $preorder->id]);
|
||||
$allPreorderEmails = PreordernotificationLogModel::search(["preorder_id" => $preorder->id]);
|
||||
$allStatusFlagEmails = PreorderStatusnotificationLog::search(["preorder_id" => $preorder->id]);
|
||||
?>
|
||||
@@ -830,6 +831,7 @@
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
|
||||
<h5 class="mb-3">
|
||||
<i class="fas fa-envelope mr-2 text-muted"></i>
|
||||
E-Mail Benachrichtigungen
|
||||
@@ -984,8 +986,34 @@
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<?php if($email_logs): ?>
|
||||
<h5>Alle ausgehenden Emails <small>(ab 25.08.2025)</small></h5>
|
||||
|
||||
<table class="table table-sm table-striped mb-3">
|
||||
<tr>
|
||||
<th>Von</th>
|
||||
<th>An</th>
|
||||
<th>Betreff</th>
|
||||
<th>Anhänge</th>
|
||||
<th>Gesendet</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
<?php foreach($email_logs as $email): ?>
|
||||
<tr>
|
||||
<td><?=$email->from?></td>
|
||||
<td><?=$email->to?></td>
|
||||
<td><?=htmlentities($email->subject)?></td>
|
||||
<td><?=(is_array($email->attachments)) ? count($email->attachments) : 0?></td>
|
||||
<td><?=date("d.m.Y H:i",$email->create)?></td>
|
||||
<td><i class="fas fa-eye text-primary pointer" onclick="displayEmailLogEmail(<?=$preorder->id?>,<?=$email->id?>); return false;"></i></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Empty State -->
|
||||
<?php if (empty($allPreorderEmails) && empty($allStatusFlagEmails)): ?>
|
||||
<?php if (empty($email_logs) && empty($allPreorderEmails) && empty($allStatusFlagEmails)): ?>
|
||||
<div class="card border-0">
|
||||
<div class="card-body text-center py-4">
|
||||
<div class="mb-3">
|
||||
|
||||
250
Layout/default/Preordernotification/EmailLog.php
Normal file
250
Layout/default/Preordernotification/EmailLog.php
Normal file
@@ -0,0 +1,250 @@
|
||||
<?php
|
||||
$pagination_baseurl = $this->getUrl($Mod, "EmailLog/$notification->id");
|
||||
$pagination_baseurl_params = ["filter" => $filter];
|
||||
$pagination_entity_name = "Emails";
|
||||
?>
|
||||
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/header.php"); ?>
|
||||
<?php //var_dump($notification->filter);exit;?>
|
||||
|
||||
<!-- start page title -->
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="page-title-box">
|
||||
<div class="page-title-right">
|
||||
<ol class="breadcrumb m-0">
|
||||
<li class="breadcrumb-item"><a href="<?=self::getUrl("Dashboard")?>"><?=MFAPPNAME_SLUG?></a></li>
|
||||
<li class="breadcrumb-item"><a href="<?=self::getUrl("Preorder")?>">Vorbestellung</a></li>
|
||||
<li class="breadcrumb-item"><a href="<?=self::getUrl("Preordernotification")?>">Emailaussendungen</a></li>
|
||||
<li class="breadcrumb-item active"><?=$notification->campaign->name?> "<?=htmlentities($notification->subject)?>"</li>
|
||||
</ol>
|
||||
</div>
|
||||
<h4 class="page-title">Emailaussendungen <?=$notification->campaign->name?> "<?=htmlentities($notification->subject)?>"</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end page title -->
|
||||
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body mb-3">
|
||||
<h4 class="header-title mb-3">Filter</h4>
|
||||
|
||||
<form method="get" action="<?=self::getUrl("Invoice")?>">
|
||||
<div class="row">
|
||||
|
||||
<div class="col-2">
|
||||
<label class="form-label" for="filter_from">Absender</label>
|
||||
<input type="text" class="form-control" name="filter[from]" id="filter_from" value="<?=(array_key_exists("from", $filter)) ? $filter['from'] : ""?>"/>
|
||||
</div>
|
||||
|
||||
<div class="col-2">
|
||||
<label class="form-label" for="filter_to">Empfänger</label>
|
||||
<input type="text" class="form-control" name="filter[to]" id="filter_to" value="<?=(array_key_exists("to", $filter)) ? $filter['to'] : ""?>"/>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<label class="form-label" for="filter_subject">Betreff</label>
|
||||
<input type="text" class="form-control" name="filter[subject]" id="filter_subject" value="<?=(array_key_exists("subject", $filter)) ? $filter['subject'] : ""?>"/>
|
||||
</div>
|
||||
<!--div class="col-1">
|
||||
<label class="form-label" for="filter_has_attachments">Anhang</label>
|
||||
<select name="filter[has_attachments]" id="filter_has_attachments" class="form-control">
|
||||
<option></option>
|
||||
<option value="1" <?=((array_key_exists("has_attachments", $filter)) && ($filter['has_attachments'])) ? "selected" : ""?>>Mit Anhang</option>
|
||||
<option value="0" <?=((array_key_exists("has_attachments", $filter)) && (!$filter['has_attachments'])) ? "selected" : ""?>>Ohne Anhang</option>
|
||||
</select>
|
||||
</div-->
|
||||
|
||||
</div>
|
||||
<div class="row mt-2">
|
||||
<div class="col-12">
|
||||
<button type="submit" class="btn btn-primary"><i class="fas fa-fw fa-search"></i> Filter anwenden</button>
|
||||
<a class="btn btn-secondary" href="<?=self::getUrl("Preordernotification", "EmailLog", ["id" => $notification->id])?>?resetFilter=1"><i class="fas fa-fw fa-xmark-large"></i> Filter zurücksetzen</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4 class="header-title mb-3">Ausgehende Emails zur Aussendung <?=$notification->campaign->name?> "<?=htmlentities($notification->subject)?>"</h4>
|
||||
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination.php"); ?>
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination-summary.php"); ?>
|
||||
|
||||
<table class="table table-striped table-hover">
|
||||
<tr>
|
||||
<th>Von</th>
|
||||
<th>An</th>
|
||||
<th>Betreff</th>
|
||||
<th>Anhänge</th>
|
||||
<th>Gesendet</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
<?php foreach($emails as $email): ?>
|
||||
<tr>
|
||||
<td><?=$email->from?></td>
|
||||
<td><?=$email->to?></td>
|
||||
<td><?=$email->subject?></td>
|
||||
<td><?=(is_array($email->attachments)) ? count($email->attachments) : 0?></td>
|
||||
<td><?=date("d.m.Y H:i",$email->create)?></td>
|
||||
<td><i class="fas fa-eye text-primary pointer" onclick="displayEmailLogEmail(<?=$email->id?>); return false;"></i></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination-summary.php"); ?>
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/tpl/pagination.php"); ?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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">×</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-6">
|
||||
<h5>Dateianhänge</h5>
|
||||
<ul id="email-log-attachment-list" class="list-group"></ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
async function displayEmailLogEmail(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();
|
||||
hideHeaders();
|
||||
|
||||
if(!email_id) return false;
|
||||
|
||||
var resp = await fetch("<?=self::getUrl("Preordernotification", "api", ["do" => "getLoggedEmail", "nid" => $notification->id])?>&eid=" + email_id);
|
||||
console.log(resp);
|
||||
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, '&').replace(/"/g, '"').replace(/'/g, ''').replace(/</g, '<').replace(/>/g, '>')
|
||||
+ "<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");
|
||||
}
|
||||
}
|
||||
|
||||
//$("#email-log-modal").modal("show");
|
||||
</script>
|
||||
@@ -91,7 +91,7 @@
|
||||
<tr>
|
||||
<td class="text-center">
|
||||
<?php if($notification->send_start && $notification->send_finish): ?>
|
||||
<i class='fas fa-check text-success' title='Versand erfolgreich abgeschlossen'></i>
|
||||
<a href="<?=self::getUrl("Preordernotification", "EmailLog", ["id" => $notification->id])?>"><i class='fas fa-check text-success' title='Versand erfolgreich abgeschlossen'></i></a>
|
||||
<?php elseif($notification->send_start && !$notification->send_finish): ?>
|
||||
<i class='fas fa-loader text-info' title='Versand gestartet'></i>
|
||||
<?php elseif(!$notification->send_start && !$notification->send_finish): ?>
|
||||
|
||||
Reference in New Issue
Block a user