summaryrefslogtreecommitdiff
path: root/emailhtml.php
diff options
context:
space:
mode:
Diffstat (limited to 'emailhtml.php')
-rw-r--r--emailhtml.php454
1 files changed, 454 insertions, 0 deletions
diff --git a/emailhtml.php b/emailhtml.php
new file mode 100644
index 0000000..0b44ec3
--- /dev/null
+++ b/emailhtml.php
@@ -0,0 +1,454 @@
+<?php
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+?>
+<?php
+/* vim: set ts=4 sw=4 et : */
+
+$_title = "E-Mail senden";
+
+require_once __DIR__ . "/check_auth.php";
+require_once __DIR__ . "/../includes/common.php";
+
+require_once "./config.php";
+require_once __DIR__ . "/lookup.php";
+
+require_once __DIR__ . "/header.php";
+
+if (isset($_GET['demo'])) $_SESSION['demo'] = true;
+
+$num = 0;
+if ($_POST['ids'] != '')
+ $num = count(explode(',', $_POST['ids']));
+?>
+
+<div id="email_modal" style="display: none;" class="transparent_modal">
+ <button onclick="abortAll()" class="emergency_off">NOT-AUS</button>
+ <div class="sk-folding-cube hvcenter">
+ <div class="sk-cube1 sk-cube"></div>
+ <div class="sk-cube2 sk-cube"></div>
+ <div class="sk-cube4 sk-cube"></div>
+ <div class="sk-cube3 sk-cube"></div>
+ </div>
+</div>
+
+<h1>E-Mail senden</h1>
+
+<? if ($_SESSION['demo']) { ?>
+<p>Demo-Flag ist an</p>
+<? } ?>
+
+<table border="0" style="display: inline-block;">
+<? if (!(isset($_POST['nocount']) && $_POST['nocount'])) { ?>
+ <tr>
+ <td colspan="2">
+ an <?=$num?> Empfänger
+ </td>
+ </tr>
+<? } ?>
+ <tr>
+ <td>Absender</td>
+ <td><input class="mand" type="text" name="email_from" placeholder="absender@demo.de"></td>
+ </tr>
+ <tr>
+ <td>To (Preview)</td>
+ <td><input type="text" disabled name="email_to" value=""></td>
+ </tr>
+ <tr>
+ <td>ID (Preview)</td>
+ <td><input type="text" disabled name="email_id" value=""></td>
+ </tr>
+ <tr>
+ <td>Cc</td>
+ <td><input type="text" name="email_cc" placeholder="erster@kontakt.cc, zweiter@kontakt.cc"></td>
+ </tr>
+ <tr>
+ <td>Bcc</td>
+ <td><input type="text" name="email_bcc" placeholder="bcc@demo.de"></td>
+ </tr>
+ <tr>
+ <td>Betreff</td>
+ <td><input class="mand" type="text" name="email_subject" placeholder="Betreff"></td>
+ </tr>
+</table>
+
+<div style="display: inline-block; margin-left: 1em; vertical-align: top;">
+ <button onclick="return sendAll();" class="medium" style="width: 12em;"><i class="fas fa-mail-bulk"></i> an alle senden</button><br />
+ <button onclick="return sendOne();" class="medium" style="width: 12em;"><i class="fas fa-envelope"></i> an diesen senden</button>
+
+ <div style="color: darkorange; margin-top: .5em;">
+ Letzter Status:
+ <p id="email_status"></p>
+ </div>
+</div>
+
+<div style="display: inline-block; margin-left: 1em; vertical-align: top;">
+ <b>Gespeicherte Templates</b>
+ <div style="color: darkorange; margin-top: .5em;">
+<?
+ $sql = "SELECT id, name, text, subject, `from`, cc, bcc, ts FROM email_templates ORDER BY name";
+ $stmt = $mysqli->prepare($sql);
+ $stmt->bind_result($id, $name, $text, $subject, $from, $cc, $bcc, $ts);
+ $stmt->execute();
+?>
+ <select id="email_template">
+ <option data-text="" data-from="" data-cc="" data-bcc="" data-subject="" value="" selected></option>
+<?
+ $templates = [];
+ while ($stmt->fetch()) {
+ $templates[$id] = ['name' => $name, 'text' => $text, 'ts' => $ts];
+?>
+ <option data-id="<?=$id?>"
+ data-name="<?=str_replace("\"", "&qout;", $name)?>"
+ data-from="<?=str_replace("\"", "&quot;", $from)?>"
+ data-cc="<?=str_replace("\"", "&quot;", $cc)?>"
+ data-bcc="<?=str_replace("\"", "&quot;", $bcc)?>"
+ data-subject="<?=str_replace("\"", "&quot;", $subject)?>"
+ data-text="<?=str_replace("\"", "&quot;", $text)?>"
+ value="<?=$id?>"><?=$name?> (ID <?=$id?>; <?=$ts?>)</option>
+<?
+ }
+?>
+ </select>
+ <br />
+ <br />
+ <button class="small" onclick="return loadEmailTemplate();"><i class="fas fa-upload"></i> Laden</button>
+ <button class="small" onclick="return saveEmailTemplate();" style="background: orange"><i class="fas fa-download"></i> &Uuml;berschreiben</button>
+ <button class="small" onclick="return newEmailTemplate();"><i class="far fa-file"></i> Neu</button>
+ <button class="small" onclick="return renameEmailTemplate();"><i class="fas fa-pencil-alt"></i> Umbenennen</button>
+ <button class="small" onclick="return delEmailTemplate();" style="background: red;"><i class="fas fa-trash"></i> L&ouml;schen</button>
+<?
+ $stmt->reset();
+?>
+
+ </div>
+</div>
+
+<div style="display: inline-block; margin-left: 1em; vertical-align: top;">
+ <b>Anhang</b>
+<?
+ $sql = "SELECT hash, name FROM pages_files WHERE mime='application/pdf' ORDER BY name";
+ $stmt = $mysqli->prepare($sql);
+ $stmt->bind_result($fid, $fname);
+ $stmt->execute();
+?>
+ <select id="attachment">
+ <option value="" selected></option>
+<?
+ while ($stmt->fetch()) {
+?>
+ <option value="<?=$fid?>"><?=$fname?></option>
+<?
+ }
+ $stmt->reset();
+?>
+ </select>
+</div>
+
+<script>
+<?php minStart(); ?>
+
+$('#email_template').on('change', function () {
+ $('#email_template').css('background', 'white');
+});
+
+$(document).ready(function () {
+quill.on('text-change', function () {
+ $('#email_template').css('background', 'lightgrey');
+});
+});
+
+function newEmailTemplate() {
+ var n = prompt('Name des neuen Templates:', '');
+ if (!n) return;
+
+ var text = $("#editor .ql-editor").html();
+ var from = $('input[name=email_from]').val();
+ var cc = $('input[name=email_cc]').val();
+ var bcc = $('input[name=email_bcc]').val();
+ var subject = $('input[name=email_subject').val();
+
+ $.ajaxSetup({async:false});
+ $.post('/db/main/addtemplate.php', {
+ 'name': n,
+ 'text': text,
+ 'from': from,
+ 'cc': cc,
+ 'bcc': bcc,
+ 'subject': subject,
+ 'email': true
+ });
+ alert(unescape('Seite neuladen, damit neues Template im Dropdown erscheint.\nIn dem neuen Template wurden die aktuellen Werte gespeichert.'));
+}
+
+function renameEmailTemplate() {
+ var id = $('#email_template :selected').attr('data-id');
+ var on = $('#email_template :selected').attr('data-name');
+ var n = prompt('Name des Templates:', on);
+ if (!n) return;
+
+ $.ajaxSetup({async:false});
+ $.post('/db/main/rentemplate.php', {
+ 'id': id,
+ 'name': n,
+ 'email': true
+ });
+
+ $('#email_template :selected').attr('data-name', n);
+ $('#email_template :selected').text(n + ' (ID ' + id + ')');
+}
+
+function delEmailTemplate() {
+ var id = $('#email_template').val();
+ var v = $('#email_template :selected').text();
+ if (!v) return;
+
+ if (confirm(unescape('Wirklich Template\n "' + v + '"\nunwiderruflich verwerfen?'))) {
+ $.ajaxSetup({async:false});
+ $.post('/db/main/deltemplate.php', {
+ 'id': id,
+ 'email': true
+ });
+ $('#email_template :selected').remove();
+ $('#email_template').css('background', 'red');
+ }
+}
+
+function loadEmailTemplate() {
+ $("#editor .ql-editor")[0].innerHTML = $('#email_template :selected').attr('data-text');
+ $("#editor .ql-editor").html($('#email_template :selected').attr('data-text').replace(/<br>/g, '<br>\n'));
+ $('input[name=email_from]').val($('#email_template :selected').attr('data-from'));
+ $('input[name=email_cc]').val($('#email_template :selected').attr('data-cc'));
+ $('input[name=email_bcc]').val($('#email_template :selected').attr('data-bcc'));
+ $('input[name=email_subject]').val($('#email_template :selected').attr('data-subject'));
+
+ setTimeout(function () {
+ $('#email_template').css('background', 'lightgreen');
+ }, 200);
+}
+
+function saveEmailTemplate() {
+ var text = $("#editor .ql-editor").html();
+ var from = $('input[name=email_from]').val();
+ var cc = $('input[name=email_cc]').val();
+ var bcc = $('input[name=email_bcc]').val();
+ var subject = $('input[name=email_subject').val();
+ var id = $('#email_template').val();
+
+ $('#email_template :selected').attr('data-text', text);
+ $('#email_template :selected').attr('data-from', from);
+ $('#email_template :selected').attr('data-cc', cc);
+ $('#email_template :selected').attr('data-bcc', bcc);
+ $('#email_template :selected').attr('data-subject', subject);
+ $('#email_template :selected').text($('#email_template :selected').attr('data-name') + ' (ID ' + $('#email_template :selected').attr('data-id') + ')');
+
+ $.ajaxSetup({async:false});
+ $.post('/db/main/updtemplate.php', {
+ 'id': id,
+ 'text': text,
+ 'from': from,
+ 'cc': cc,
+ 'bcc': bcc,
+ 'subject': subject,
+ 'email': true
+ });
+
+ setTimeout(function () {
+ $('#email_template').css('background', 'lightgreen');
+ }, 200);
+}
+
+<?php minEnd(); ?>
+</script>
+
+<?
+$sql = $_POST['sql'];
+$payload_sql = $_POST['payload_sql'];
+$payload_sql_order = $_POST['payload_sql_order'];
+$independent_payload_sql = $_POST['independent_payload_sql'];
+$independent_payload_sql_order = $_POST['independent_payload_sql_order'];
+require_once __DIR__ . "/templater_common.php";
+?>
+
+<script>
+<?php minStart(); ?>
+
+function sendOne(skip) {
+ if (typeof skip !== 'boolean')
+ skip = false;
+
+ if (typeof pivot.__skip !== 'undefined') {
+ if (pivot.__skip) {
+ delete pivot.__done;
+ delete pivot.__failed;
+ data[pivot.index].__skip = true;
+ redoRows($("tr[data-id='" + pivot.uid + "']")[0], 0, 0, 0, pivot.index);
+ redoRows($("tr[data-id='" + pivot.ID + "']")[0], 0, 0, 0, pivot.index);
+ redoRows($("tr[data-id='" + pivot.id + "']")[0], 0, 0, 0, pivot.index);
+ return true;
+ }
+ }
+
+ if (typeof pivot.__done !== 'undefined') {
+ if (!confirm(unescape('An diese Adresse wurde schon gesendet. Nochmal senden?')))
+ return;
+ }
+
+ var from = $('input[name=email_from]').val();
+ var to = $('input[name=email_to]').val();
+ var cc = $('input[name=email_cc]').val();
+ var bcc = $('input[name=email_bcc]').val();
+ var subject = $('input[name=email_subject]').val();
+ var html = $('#preview').html();
+
+ var persid = null;
+ var stipid = null;
+ var uid = null;
+
+ if (typeof pivot.ID !== 'undefined') persid = pivot.ID;
+ if (typeof pivot.id !== 'undefined') persid = pivot.id;
+ if (typeof pivot.PersID !== 'undefined') persid = pivot.PersID;
+ if (typeof pivot.persid !== 'undefined') persid = pivot.persid;
+ if (typeof pivot.StipID !== 'undefined') stipid = pivot.StipID;
+ if (typeof pivot.stipid !== 'undefined') stipid = pivot.stipid;
+ if (typeof pivot.UID !== 'undefined') uid = pivot.UID;
+ if (typeof pivot.uid !== 'undefined') uid = pivot.uid;
+
+ var noerror = false;
+ var response = "";
+ $.ajaxSetup({async:false});
+ $.ajax({
+ type: 'POST',
+ url: '/db/main/sendmail.php',
+ data: {
+ 'from': from,
+ 'to': to,
+ 'cc': cc,
+ 'bcc' : bcc,
+ 'html' : html,
+ 'subject': subject,
+ 'persid': persid,
+ 'stipid': stipid,
+ 'uid': uid,
+ 'attachment': $('#attachment :selected').val(),
+ 'attachment_fn': $('#attachment :selected').text()
+ },
+ success: function (d, s, x) {
+ if (d == 1) {
+ noerror = true;
+ response = x.responseText;
+ }
+ }
+ });
+
+ if (noerror && response == '1') {
+ pivot.__done = true;
+ delete pivot.__failed;
+
+ redoRows($("tr[data-id='" + pivot.uid + "']")[0], 0, 0, 0, pivot.index);
+ redoRows($("tr[data-id='" + pivot.ID + "']")[0], 0, 0, 0, pivot.index);
+ redoRows($("tr[data-id='" + pivot.id + "']")[0], 0, 0, 0, pivot.index);
+
+ if (!skip) alert('E-Mail an ' + to + ' erfolgreich gesendet.');
+
+ $('#email_status').html('[#' + (count_s + count_f + 1) + '] E-Mail erfolgreich: ' + to);
+ return true;
+ }
+
+ pivot.__failed = true;
+ delete pivot.__done;
+
+ redoRows($("tr[data-id='" + pivot.uid + "']")[0], 0, 0, 0, pivot.index);
+ redoRows($("tr[data-id='" + pivot.ID + "']")[0], 0, 0, 0, pivot.index);
+ redoRows($("tr[data-id='" + pivot.id + "']")[0], 0, 0, 0, pivot.index);
+
+ alert('Fehler beim Senden an ' + to + ': ' + response);
+ $('#email_status').html('Fehler: ' + to);
+ return false;
+}
+
+function waitASec(time) {
+ $.ajaxSetup({async:false});
+ $.post('/db/main/delay.php', {
+ time: time
+ });
+}
+
+function sendAllDone() {
+ $('#email_modal').hide();
+ window.scrollTo(0, 0);
+ alert(unescape('Fertig. Erfolg für ' + count_s + ' Empfänger.\nFehlgeschlagen bei ' + count_f + '.'));
+ $('#email_status').html('Erfolg: ' + count_s + ', Fehler: ' + count_f);
+}
+
+function sendAllLoop() {
+ if (typeof window.emergencyOff !== 'undefined') {
+ sendAllDone();
+ delete window.emergencyOff;
+ return;
+ }
+
+ if (typeof pivot.__done === 'undefined') {
+ $('#email_status').html('Sende an: ' + pivot['email']);
+
+ if (sendOne(true)) count_s++;
+ else count_f++;
+
+ pivot_iter++;
+ if (pivot_iter < data.length) {
+ pivot = data[pivot_iter];
+ bP();
+ setTimeout(sendAllLoop, 100);
+ return;
+ }
+
+ setTimeout(sendAllDone, 100);
+ return;
+ }
+
+ pivot_iter++;
+ if (pivot_iter < data.length) {
+ pivot = data[pivot_iter];
+ bP();
+ setTimeout(sendAllLoop, 10);
+ return;
+ }
+
+ setTimeout(sendAllDone, 100);
+ return;
+}
+
+function sendAll() {
+ if (!confirm(unescape('Wirklich E-Mail an ' + $.grep(data, function (e) { return (typeof e.__done === 'undefined'); }).length + ' Empfänger senden?')))
+ return;
+
+ count_s = 0;
+ count_f = 0;
+ pivot = data[0];
+ pivot_iter = 0;
+ bP();
+
+ window.scrollTo(0, 0);
+ $('#email_modal').show();
+ setTimeout(sendAllLoop, 100);
+}
+
+function abortAll() {
+ window.emergencyOff = true;
+}
+
+<?php minEnd(); ?>
+</script>
+
+<?
+include_once __DIR__ . "/footer.php";
+?>