Files
2025-01-14 21:53:49 +01:00

341 lines
20 KiB
PHP

<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/header.php"); ?>
<!-- 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("MailtemplateDispatch")?>">Emailversand</a></li>
<li class="breadcrumb-item active"><?=($dispatch->id) ? "bearbeiten" : "Neu" ?></li>
</ol>
</div>
<h4 class="page-title"><?=($dispatch->id) ? "Emailaussendung bearbeiten" : "Neue Emailaussendung" ?></h4>
</div>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-lg-12">
<div class="card bg-light">
<div class="card-body">
<form class="form-horizontal" method="post" action="<?=self::getUrl("MailtemplateDispatch", "save")?>" enctype="multipart/form-data">
<div class="card">
<div class="card-body">
<input type="hidden" name="id" value="<?=$dispatch->id?>" />
<h4>Absender</h4>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="sender_name">Name *</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="sender_name" id="sender_name" value="<?=$dispatch->sender_name?>" />
<small>Wird beim Empfänger als Absender angezeigt</small>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="sender_email">Emailadresse *</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="sender_email" id="sender_email" value="<?=$dispatch->sender_email?>" />
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="sender_replyto">Antworten an (Reply-To):</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="sender_replyto" id="sender_replyto" value="<?=$dispatch->sender_replyto?>" />
</div>
</div>
<hr />
<h4 class="mt-4">Empfänger</h4>
<p>Die Aussendung wird an die Kontaktemailadresse aller Bestellungen versendet. Wählen Sie folgende Konditionen aus, um die Empfänger zu beschränken:</p>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="filter_datasource">Empfängerdatenbasis</label>
<div class="col-lg-10">
<select class="form-control select2" name="filter_datasource[]" id="filter_datasource" multiple="multiple">
<option value="contract" <?=($dispatch && in_array("contract", $dispatch->filter_datasource_array)) ? "selected='selected'" : ""?>>Aktive Contracts</option>
<option value="order" <?=($dispatch && in_array("order", $dispatch->filter_datasource_array)) ? "selected='selected'" : ""?>>Bestellung</option>
<option value="sysowner" <?=($dispatch && in_array("sysowner", $dispatch->filter_datasource_array)) ? "selected='selected'" : ""?>>Alle Xinon Kunden (mit Kundennummer)</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="filter_datasource">Empfängerfilter</label>
<div class="col-lg-10">
<h4>Bestellungen</h4>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="1" name="filter_order_open" id="filter_order_open" <?=(array_key_exists("order_open", $dispatch->recipient_filter_array) && $dispatch->recipient_filter_array["order_open"]) ? 'checked="checked"' : ''?> />
<label class="form-check-label" for="filter_order_open">Nur offene Bestellungen</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="1" name="filter_order_int_products" id="filter_order_int_products" <?=(array_key_exists("order_int_products", $dispatch->recipient_filter_array) && $dispatch->recipient_filter_array["order_int_products"]) ? 'checked="checked"' : ''?> />
<label class="form-check-label" for="filter_order_int_products">Nur Xinonprodukte</label>
</div>
<h4 class="mt-3">Aktive Contracts</h4>
<h4 class="mt-3">Allgemein</h4>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="1" name="filter_fibu_account" id="filter_fibu_account" <?=(array_key_exists("fibu_account", $dispatch->recipient_filter_array) && $dispatch->recipient_filter_array["fibu_account"]) ? 'checked="checked"' : ''?> />
<label class="form-check-label" for="filter_fibu_account">Nur Kunden mit Fibu Kontonummer</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="1" name="filter_billingaddress" id="filter_billingaddress" <?=(array_key_exists("billingaddress", $dispatch->recipient_filter_array) && $dispatch->recipient_filter_array["billingaddress"]) ? 'checked="checked"' : ''?> />
<label class="form-check-label" for="filter_billingaddress">Auch an Rechnungsadresse</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="1" name="filter_techcontact" id="filter_techcontact" <?=(array_key_exists("techcontact", $dispatch->recipient_filter_array) && $dispatch->recipient_filter_array["techcontact"]) ? 'checked="checked"' : ''?> />
<label class="form-check-label" for="filter_techcontact">Auch an Technischen Kontakt</label>
</div>
<div class="form-group row mt-2 col-12">
<label class="form-label" for="filter_zip">PLZ-Beschränkung (Kundenadresse)</label>
<input type="text" class="form-control" name="filter_zip" id="filter_zip" value="<?=(array_key_exists("zip", $dispatch->recipient_filter_array)) ? implode(", ", $dispatch->recipient_filter_array["zip"]) : ""?>" />
<small class="text-primary">PLZ' mit Leerzeichen oder Komma getrennt</small>
</div>
<input type="hidden" name="filter_zip_source" value="owner" />
<!--div class="form-group row mt-2 col-12">
<label class="form-label" for="filter_zip">PLZ-Beschränkung anhand</label>
<select class="form-control" name="filter_zip_source" id="filter_zip_source">
<option value="owner">Kundenadresse</option>
<option value="termination">Anschlussadresse</option>
</select>
</div-->
</div>
</div>
<hr />
<h4 class="mt-4">Email</h4>
<p>Wählen Sie das gewünschte Emailtemplate aus. Der Betreff kann für diese Aussendung angepasst werden.</p>
<div class="form-group row mt-3 col-12">
<label class="form-label" for="mailtemplate_id">Emailtemplate *</label>
<select class="form-control select2" name="mailtemplate_id" id="mailtemplate_id">
<option></option>
<?php foreach(MailtemplateModel::search(["is_include" => "0"]) as $template): ?>
<option value="<?=$template->id?>" <?=($dispatch->mailtemplate_id == $template->id) ? "selected='selected'" : "" ?>><?=$template->name?> ("<?=$template->subject?>")</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group row mt-3 col-12">
<label class="form-label" for="subject">Betreff *</label>
<input type="text" class="form-control" name="subject" id="subject" value="<?=$dispatch->subject?>" placeholder="Betreff" style="border-radius:0;" />
</div>
<div id="body_preview" style="min-height: 48px; min-width: 1440px; max-width: 50vh; border: 1px solid #000; padding: 8px;">
<?php if($dispatch->mailtemplate_id): ?>
<?php if($dispatch->mailtemplate->body_html): ?>
<?=$dispatch->mailtemplate->renderBody()?>
<?php else: ?>
<?=nl2br(htmlentities($dispatch->mailtemplate->renderBody()))?>
<?php endif; ?>
<?php else: ?>
<em>Emailvorschau</em>
<?php endif; ?>
</div>
<h4 class="mt-4">Dateianhänge</h4>
<div class="row ">
<div class="col-4">
<ul class="list-group" id="files-container">
<?php if(!$dispatch->mailtemplate->files): ?>
<li class="list-group-item"><em>Keine Dateianhänge</em></li>
<?php else: ?>
<?php foreach($dispatch->mailtemplate->files as $file): ?>
<li id="file-<?=$file->file_id?>" class="list-group-item"><a href="<?=self::getUrl("File", "Download", ["id" => $file->file_id])?>"><i class="far fa-fw fa-file"></i> <?=$file->filename?></a></li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-body">
<h4>Versand</h4>
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="tosend_day">Versandzeitpunkt</label>
<div class="col-lg-2">
<label>Datum</label>
<input type="text" class="form-control" name="tosend_day" id="tosend_date" value="<?=($dispatch->tosend_date) ? date("d.m.Y", $dispatch->tosend_date) : ""?>" />
<small>Emailversand wird zu diesem Zeitpunkt gestartet</small>
</div>
<div class="col-lg-2">
<label>Uhrzeit</label>
<select name="tosend_hour" class="form-control">
<?php for($h = 0; $h < 24; $h++): ?>
<option value="<?=$h?>" <?=($dispatch->tosend_date && date('H', $dispatch->tosend_date) == $h) ? "selected='selected'" : ""?>><?=str_pad($h, 2, "0", STR_PAD_LEFT)?>:00</option>
<?php endfor; ?>
</select>
</div>
</div>
<hr />
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="testmail_to">Test Email versenden</label>
<div class="col-lg-10">
<div class="row">
<div class="col-6">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-envelope"></i></span>
</div>
<input type="text" class="form-control" name="testmail_to" id="testmail_to" value="" placeholder="Testempfänger" />
</div>
</div>
<div class="col-6">
<button type="submit" name="send_testmail" value="1" class="btn btn-outline-success"><i class="far fa-paper-plane"></i> Testmail jetzt abschicken</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-body">
<div class="form-group row">
<label class="col-lg-2 col-form-label" for="note">Interne Notiz</label>
<div class="col-lg-10">
<textarea id="note" class="form-control" name="note" rows="5"><?=$dispatch->note?></textarea>
</div>
</div>
</div>
</div>
<div class="form-group row">
<label class="col-lg-2"></label>
<div class="col-lg-10">
<button type="submit" name="return" value="form" class="btn btn-primary mr-1">Speichern</button>
<button type="submit" name="return" value="index" class="btn btn-primary">Speichern und zur Übersicht</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="<?=self::getResourcePath()?>plugins/tinymce/tinymce.min.js"></script>
<script type="text/javascript" src="<?=self::getResourcePath()?>plugins/bs-custom-file-input/bs-custom-file-input.min.js"></script>
<script type="text/javascript">
$(function () {
bsCustomFileInput.init();
$('#tosend_date').datepicker({
language: 'de',
format: "dd.mm.yyyy",
showWeekDays: true,
todayBtn: 'linked',
autoclose: true
});
$(".select2").select2({
allowClear: true,
placeholder: ""
});
$("#status_id").select2({
allowClear: true,
placeholder: "",
closeOnSelect: false
});
$("#mailtemplate_id").change(async () => {
var tid = $("#mailtemplate_id").val();
if(!tid) {
clearMailtemplate();
return;
}
//getMailtemplate();
try {
$("#body_preview").empty();
var response = await fetch('<?=self::getUrl("Mailtemplate", "Api", ["do" => "getMailtemplate"])?>&id=' + tid);
if (!response.ok) {
return false;
}
var resp_json = await response.json();
var template = resp_json.result;
$("#subject").val(template.subject);
if(template.body_html) {
$("#body_preview").html(template.body_html);
} else {
var div = document.createElement('div');
div.appendChild(document.createTextNode(template.body_text));
var encoded_html = div.innerHTML;
$("#body_preview").html(encoded_html.replace("\n", "<br />"));
}
// files
$("#files-container").empty();
if(template.files.length) {
template.files.forEach( (file) => {
console.log(file.file_id, file.filename);
$("#files-container").append('<li class="list-group-item id="file-' + file.file_id + '"><a href="<?=self::getUrl("File", "Download")?>?id=' + file.file_id + '"><i class="far fa-fw fa-file"></i> ' + file.filename + '</a></li>');
})
} else {
$("#files-container").append('<li class="list-group-item"><em>Keine Dateianhänge</em></li>');
}
} catch(error) {
return false;
}
});
});
/*async function getMailtemplate(tid) {
}*/
function clearMailtemplate() {
$("#subject").val("");
$("#body_preview").empty();
}
</script>
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>