@@ -351,5 +415,91 @@ $pagination_entity_name = "Rechnungen";
status_update = setTimeout(updateStatus, 1000);
});
+
+ async function displayEmailLogEmail(invoice_id, email_id) {
+ $("#email-log-from-value").text("");
+ $("#email-log-to-value").text("");
+ $("#email-log-log-sent-value").text("");
+ $("#email-log-subject-value").text("");
+ document.getElementById("email-log-body-view").contentWindow.document.open();
+ document.getElementById("email-log-body-view").contentWindow.document.write(" ");
+ document.getElementById("email-log-body-view").contentWindow.document.close();
+ $("#email-log-attachments-section").hide();
+ $("#email-log-attachment-list").empty();
+ hideEmailLogHeaders();
+
+ if(!email_id) return false;
+
+ var resp = await fetch("=self::getUrl("PreorderBillingInvoice", "api", ["do" => "getLoggedEmail"])?>&oid=" + invoice_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(
+ "
" + key + ": "
+ + value.replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, ''').replace(//g, '>')
+ + "
");
+ 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('
?aid=' + item.id + '&hash=' + item.hash + '"> ' + item.filename + ' (' + Math.round((item.filesize/1024/1024)*100)/100 + ' MB)');
+ });
+ $("#email-log-attachments-section").show();
+ }
+
+ document.getElementById("email-log-body-view").contentWindow.document.open();
+ if(email.bodyIsHtml) {
+ document.getElementById("email-log-body-view").contentWindow.document.write(email.body);
+ } else {
+ var html_body = '
';
+ html_body += email.body.replaceAll("\r", "").replaceAll("\n", "
");
+ html_body += '
';
+ document.getElementById("email-log-body-view").contentWindow.document.write(html_body);
+ }
+ document.getElementById("email-log-body-view").contentWindow.document.close();
+
+
+ $("#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");
+ }
+ }
\ No newline at end of file
diff --git a/Layout/default/Preordernotification/EmailLog.php b/Layout/default/Preordernotification/EmailLog.php
index bdb613ff4..b0fe6b996 100644
--- a/Layout/default/Preordernotification/EmailLog.php
+++ b/Layout/default/Preordernotification/EmailLog.php
@@ -172,7 +172,9 @@ $pagination_entity_name = "Emails";
$("#email-log-to-value").text("");
$("#email-log-log-sent-value").text("");
$("#email-log-subject-value").text("");
- $("#email-log-view").empty();
+ document.getElementById("email-log-body-view").contentWindow.document.open();
+ document.getElementById("email-log-body-view").contentWindow.document.write(" ");
+ document.getElementById("email-log-body-view").contentWindow.document.close();
$("#email-log-attachments-section").hide();
$("#email-log-attachment-list").empty();
hideHeaders();
@@ -218,11 +220,16 @@ $pagination_entity_name = "Emails";
$("#email-log-attachments-section").show();
}
+ document.getElementById("email-log-body-view").contentWindow.document.open();
if(email.bodyIsHtml) {
- $("#email-log-body-view").html(email.body);
+ document.getElementById("email-log-body-view").contentWindow.document.write(email.body);
} else {
- $("#email-logbody-view").text(email.body);
+ var html_body = '
';
+ html_body += email.body.replaceAll("\r", "").replaceAll("\n", "
");
+ html_body += '
';
+ document.getElementById("email-log-body-view").contentWindow.document.write(html_body);
}
+ document.getElementById("email-log-body-view").contentWindow.document.close();
$("#email-log-modal").modal("show");
diff --git a/application/PreorderBillingInvoice/PreorderBillingInvoice.php b/application/PreorderBillingInvoice/PreorderBillingInvoice.php
index 6e659f1ab..fbaa80445 100644
--- a/application/PreorderBillingInvoice/PreorderBillingInvoice.php
+++ b/application/PreorderBillingInvoice/PreorderBillingInvoice.php
@@ -10,6 +10,7 @@ class PreorderBillingInvoice extends mfBaseModel {
private $pdf;
private $csv;
+ private $emailLog;
private $creator;
private $editor;
@@ -278,6 +279,14 @@ RML Infrastruktur GmbH";
return $this->csv;
}
+ if($name == "emailLog") {
+ $emaillog = EmailLog::getFirst(["object_type" => "PreorderBillingInvoice", "object_id" => $this->id]);
+ if($emaillog) {
+ $this->emailLog = $emaillog;
+ }
+ return $this->emailLog;
+ }
+
if($name == "creator") {
$creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
if($creator) {
diff --git a/application/PreorderBillingInvoice/PreorderBillingInvoiceController.php b/application/PreorderBillingInvoice/PreorderBillingInvoiceController.php
index 89a5fd72d..3b0270f87 100644
--- a/application/PreorderBillingInvoice/PreorderBillingInvoiceController.php
+++ b/application/PreorderBillingInvoice/PreorderBillingInvoiceController.php
@@ -998,6 +998,9 @@ class PreorderBillingInvoiceController extends mfBaseController {
case "getActiveJobs":
$return = $this->getActiveJobsApi();
break;
+ case "getLoggedEmail":
+ $return = $this->getLoggedEmail();
+ break;
default:
$return = false;
}
@@ -1011,6 +1014,56 @@ class PreorderBillingInvoiceController extends mfBaseController {
$this->returnJson($data);
}
+ protected function getLoggedEmail() {
+ $invoice_id = $this->request->oid;
+ $emaillog_id = $this->request->eid;
+
+ if(!is_numeric($invoice_id) || $invoice_id < 1) {
+ return false;
+ }
+
+ if(!is_numeric($emaillog_id) || $emaillog_id < 1) {
+ return false;
+ }
+
+ $invoice = new PreorderBillingInvoice($invoice_id);
+ if(!$invoice->id) {
+ return false;
+ }
+
+ $emaillog = new EmailLog($emaillog_id);
+ if(!$emaillog->id) {
+ return false;
+ }
+
+ $return = [
+ "invoice_id" => $invoice_id,
+ "emaillog_id" => $emaillog_id,
+ "from" => $emaillog->from,
+ "to" => $emaillog->to,
+ "subject" => $emaillog->subject,
+ "body" => ($emaillog->body_html) ? $emaillog->body_html : $emaillog->body_text,
+ "bodyIsHtml" => (bool) $emaillog->body_html,
+ "sent" => date("d.m.Y H:i", $emaillog->create),
+ "headers" => json_decode($emaillog->headers),
+ "attachments" => [],
+ ];
+
+ if(is_array($emaillog->attachments) && count($emaillog->attachments)) {
+ foreach($emaillog->attachments as $attachment) {
+ $return["attachments"][] = [
+ "id" => $attachment->id,
+ "hash" => $attachment->content->sha256,
+ "filename" => $attachment->filename,
+ "filesize" => ($attachment->content) ? $attachment->content->filesize : 0,
+ "mimetype" => ($attachment->content) ? $attachment->content->mimetype : "",
+ ];
+ }
+ }
+
+ return $return;
+ }
+
private function getActiveJobsApi() {
$now = new DateTime("now");
$jobs = [];