MailtemplateDispatch Index and Form done
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
<?php
|
||||
$pagination_baseurl = $this->getUrl($Mod, "Index");
|
||||
$pagination_baseurl_params = ["filter" => $filter];
|
||||
$pagination_entity_name = "Emailtemplates";
|
||||
?>
|
||||
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/header.php"); ?>
|
||||
|
||||
<!-- start page title -->
|
||||
|
||||
320
Layout/default/MailtemplateDispatch/Form.php
Normal file
320
Layout/default/MailtemplateDispatch/Form.php
Normal file
@@ -0,0 +1,320 @@
|
||||
<?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>
|
||||
|
||||
<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 mit Fibu Kontonummer</label>
|
||||
</div>
|
||||
<div class="form-group row mt-2 col-12">
|
||||
<label class="form-label" for="filter_zip">PLZ-Beschränkung</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>
|
||||
</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"); ?>
|
||||
110
Layout/default/MailtemplateDispatch/Index.php
Normal file
110
Layout/default/MailtemplateDispatch/Index.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
$pagination_baseurl = $this->getUrl($Mod, "Index");
|
||||
$pagination_baseurl_params = ["filter" => $filter];
|
||||
$pagination_entity_name = "Emailversände";
|
||||
?>
|
||||
<?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 active">Emailversand</li>
|
||||
</ol>
|
||||
</div>
|
||||
<h4 class="page-title">Emailversand</h4>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end page title -->
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body mb-3">
|
||||
<h4 class="header-title mb-3">Filter</h4>
|
||||
|
||||
<form method="get" action="<?=self::getUrl("MailtemplateDispatch")?>">
|
||||
<div class="row">
|
||||
|
||||
<div class="col-1">
|
||||
<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_description">Beschreibung</label>
|
||||
<input type="text" class="form-control" name="filter[description]" id="filter_description" value="<?=(array_key_exists("description", $filter)) ? $filter['description'] : ""?>" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="row mt-2">
|
||||
<div class="col">
|
||||
<button type="submit" class="btn btn-primary">Filter anwenden</button>
|
||||
<a class="btn btn-secondary" href="<?=self::getUrl("Mailtemplate")?>?resetFilter=1">Filter zurücksetzen</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body mb-3">
|
||||
<div class="float-left">
|
||||
<h4 class="header-title">Emailversand</h4>
|
||||
</div>
|
||||
<div class="float-right">
|
||||
<a class="btn btn-primary mb-2" href="<?=self::getUrl("MailtemplateDispatch", "add")?>"><i class="fas fa-plus"></i> Neuen Emailversand erstellen</a>
|
||||
</div>
|
||||
|
||||
<table class="table table-striped table-hover">
|
||||
<tr>
|
||||
<th>Versandstatus</th>
|
||||
<th>Absender</th>
|
||||
<th>Betreff</th>
|
||||
<th>Anhänge</th>
|
||||
<th>Anzahl Empfänger</th>
|
||||
<th>Geplanter Versand</th>
|
||||
<th>Erstellt</th>
|
||||
<th>Bearbeitet</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
<?php foreach($dispatches as $dispatch): ?>
|
||||
<tr>
|
||||
<td>
|
||||
<?php if($dispatch->send_finish): ?>
|
||||
<i class="fas fa-fw fa-check text-success" title="Versand abgeschlossen"></i>
|
||||
<?php elseif($dispatch->send_lock): ?>
|
||||
<i class="far fa-fw fa-evelope fa-spin-pulse text-primary" title="Versand läuft"></i>
|
||||
<?php elseif($dispatch->tosend_date && !$dispatch->send_lock): ?>
|
||||
<i class="far fa-fw fa-clock" title="Warte auf Versand"></i>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td><?=$dispatch->sender_name?> <<?=$dispatch->sender_email?>></td>
|
||||
<td><?=$dispatch->subject?></td>
|
||||
<td><?=(is_array($dispatch->files)) ? count($dispatch->files) : ""?></td>
|
||||
<td><?=$dispatch->recipient_count?></td>
|
||||
<td></td>
|
||||
<td><?=date("d.m.Y H:i",$dispatch->create)?> (<?=$dispatch->editor->name?>)</td>
|
||||
<td><?=date("d.m.Y H:i",$dispatch->edit)?> (<?=$dispatch->creator->name?>)</td>
|
||||
<td style="text-align: left; letter-spacing: 4px; font-size: 1.1em;">
|
||||
<a href="<?=self::getUrl("MailtemplateDispatch", "edit", ["id" => $dispatch->id])?>"><i class="far fa-edit" title="Emailversand bearbeiten"></i></a>
|
||||
<a href="<?=self::getUrl("MailtemplateDispatch", "delete", ["id" => $dispatch->id])?>" class="text-danger" onclick="if(!confirm('Emailversand wirklich löschen?')) return false;" title="Emailversand Löschen"><i class="fas fa-trash"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/footer.php"); ?>
|
||||
@@ -20,7 +20,7 @@ class Mailtemplate extends mfBaseModel {
|
||||
|
||||
foreach($replaceVars as $key => $replacement) {
|
||||
$key = strtoupper($key);
|
||||
$text = str_replace("{{".$key."}}", $replacement, $text);
|
||||
$text = str_ireplace("{{".$key."}}", $replacement, $text);
|
||||
}
|
||||
|
||||
return $text;
|
||||
|
||||
@@ -284,4 +284,69 @@ class MailtemplateController extends mfBaseController {
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function apiAction() {
|
||||
if(!$this->me->is(["Admin"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
$do = $this->request->do;
|
||||
$data = [];
|
||||
|
||||
switch($do) {
|
||||
case "getMailtemplate":
|
||||
$return = $this->getMailtemplateApi();
|
||||
break;
|
||||
default:
|
||||
$return = false;
|
||||
}
|
||||
|
||||
if(!is_array($return) || !count($return)) {
|
||||
$data = ["status" => "error"];
|
||||
$this->returnJson($data);
|
||||
}
|
||||
$data['status'] = "OK";
|
||||
$data['result'] = $return;
|
||||
$this->returnJson($data);
|
||||
}
|
||||
|
||||
private function getMailtemplateApi() {
|
||||
$mt_id = $this->request->id;
|
||||
|
||||
if(!$mt_id) {
|
||||
$this->log->debug(__METHOD__.": mt_id invalid");
|
||||
return false;
|
||||
}
|
||||
|
||||
$template = new Mailtemplate($mt_id);
|
||||
if(!$template->id) {
|
||||
$this->log->debug(__METHOD__.": Mailtemplate not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = $template->data;
|
||||
|
||||
$data->is_include = boolval($data->is_include);
|
||||
if($data->body_text) {
|
||||
$data->body_text = $template->renderBody();
|
||||
}
|
||||
if($data->body_html) {
|
||||
$data->body_html = $template->renderBody();
|
||||
}
|
||||
unset($data->create_by, $data->edit_by, $data->note);
|
||||
|
||||
$template_files = [];
|
||||
if(is_array($template->files) && count($template->files)) {
|
||||
foreach($template->files as $file) {
|
||||
$template_files[] = [
|
||||
"file_id" => $file->file_id,
|
||||
"filename" => $file->filename
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data->files = $template_files;
|
||||
|
||||
return (array)$data;
|
||||
|
||||
}
|
||||
}
|
||||
264
application/MailtemplateDispatch/MailtemplateDispatch.php
Normal file
264
application/MailtemplateDispatch/MailtemplateDispatch.php
Normal file
@@ -0,0 +1,264 @@
|
||||
<?php
|
||||
|
||||
class MailtemplateDispatch extends mfBaseModel {
|
||||
private $mailtemplate;
|
||||
private $filter_datasource_array;
|
||||
private $recipient_filter_array;
|
||||
|
||||
private $creator;
|
||||
private $editor;
|
||||
|
||||
|
||||
public function sendToRecipients($test_to_email = false) {
|
||||
$emails = $this->getRecipients();
|
||||
if(!$emails) return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function getRecipients($list_recipients = false) {
|
||||
$datasources = $this->getProperty("filter_datasource_array");
|
||||
$filter = $this->getProperty("recipient_filter_array");
|
||||
|
||||
if(!is_array($datasources) || !count($datasources)) {
|
||||
$this->log->warn(__METHOD__.": Mailtemplate ".$this->id.": no datasource");
|
||||
return false;
|
||||
}
|
||||
|
||||
$emails = [];
|
||||
|
||||
if(in_array("contract", $datasources)) {
|
||||
|
||||
}
|
||||
if(in_array("order", $datasources)) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
if($name == "filter_datasource_array") {
|
||||
$json = $this->filter_datasource;
|
||||
if(!$json) {
|
||||
return [];
|
||||
}
|
||||
$ds = json_decode($json, true);
|
||||
if(!is_array($ds)) {
|
||||
return [];
|
||||
}
|
||||
$this->filter_datasource_array = $ds;
|
||||
return $this->filter_datasource_array;
|
||||
}
|
||||
|
||||
if($name == "recipient_filter_array") {
|
||||
$json = $this->recipient_filter;
|
||||
if(!$json) {
|
||||
return [];
|
||||
}
|
||||
$rf = json_decode($json, true);
|
||||
if(!is_array($rf)) {
|
||||
return [];
|
||||
}
|
||||
$this->recipient_filter_array = $rf;
|
||||
return $this->recipient_filter_array;
|
||||
}
|
||||
|
||||
|
||||
if($name == "file") {
|
||||
if(!$this->id) return null;
|
||||
$file = MailtemplateDispatchFile::getFirst(["MailtemplateDispatch_id" => $this->id]);
|
||||
if($file) {
|
||||
$this->file = $file;
|
||||
}
|
||||
return $this->file;
|
||||
}
|
||||
|
||||
|
||||
if($name == "creator") {
|
||||
$this->creator = mfValuecache::singleton()->get("Worker-id-".$this->create_by);
|
||||
if($this->creator === null) {
|
||||
$this->creator = new User($this->create_by);
|
||||
if($this->creator->id) {
|
||||
mfValuecache::singleton()->set("Worker-id-".$this->create_by, $this->creator);
|
||||
}
|
||||
}
|
||||
return $this->creator;
|
||||
}
|
||||
|
||||
if($name == "editor") {
|
||||
$this->editor = mfValuecache::singleton()->get("Worker-id-".$this->edit_by);
|
||||
if($this->editor === null) {
|
||||
$this->editor = new User($this->edit_by);
|
||||
if($this->editor->id) {
|
||||
mfValuecache::singleton()->set("Worker-id-".$this->edit_by, $this->editor);
|
||||
}
|
||||
}
|
||||
return $this->editor;
|
||||
}
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name."_id";
|
||||
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-".$this->$idfield);
|
||||
if(!$this->$name) {
|
||||
$this->$name = new $classname($this->$idfield);
|
||||
}
|
||||
|
||||
if($this->$name->id) {
|
||||
mfValuecache::singleton()->set("mfObjectmodel-$name-".$this->$name->id, $this->$name);
|
||||
return $this->$name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
/********************************
|
||||
* Begin static Model functions
|
||||
*/
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new MailtemplateDispatch();
|
||||
|
||||
$table_fields = [
|
||||
"mailtemplate_id", "sender_email","sender_name", "sender_replyto", "tosend_date", "send_start", "send_finish", "send_lock", "recipient_count",
|
||||
"subject", "body_text", "body_html", "filter_datasource", "recipient_filter",
|
||||
"note", "create_by","edit_by","create","edit"
|
||||
];
|
||||
|
||||
foreach($data as $field => $value) {
|
||||
if(in_array($field, $table_fields)) {
|
||||
$model->$field = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
|
||||
if($model->create_by === null) {
|
||||
$model->create_by = $me->id;
|
||||
}
|
||||
if($model->edit_by === null) {
|
||||
$model->edit_by = $me->id;
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getAll() {
|
||||
$items = [];
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$res = $db->select("MailtemplateDispatch", "*", "1 = 1 ORDER BY `create`");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new MailtemplateDispatch($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT * FROM MailtemplateDispatch
|
||||
WHERE $where
|
||||
ORDER BY `create` LIMIT 1";
|
||||
//var_dump($sql);exit;
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new MailtemplateDispatch($data);
|
||||
if($item->id) {
|
||||
return $item;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) as cnt FROM MailtemplateDispatch
|
||||
WHERE $where";
|
||||
|
||||
//mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
return $data->cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit = false, $order = false) {
|
||||
//var_dump($filter);exit;
|
||||
$items = [];
|
||||
|
||||
if(!$order) {
|
||||
$order = "`create` ASC";
|
||||
}
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT * FROM MailtemplateDispatch
|
||||
WHERE $where
|
||||
ORDER BY $order";
|
||||
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||
} elseif(is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[$data->id] = new MailtemplateDispatch($data);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
if(array_key_exists("mailtemplate_id", $filter)) {
|
||||
$mailtemplate_id = $filter['mailtemplate_id'];
|
||||
if(is_numeric($mailtemplate_id)) {
|
||||
$where .= " AND MailtemplateDispatch.mailtemplate_id=$mailtemplate_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("subject", $filter)) {
|
||||
$subject = FronkDB::singleton()->escape($filter["subject"]);
|
||||
if($subject) {
|
||||
$where .= " AND subject='$subject'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists("add-where", $filter)) {
|
||||
$where .= " ".$filter['add-where'];
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
class MailtemplateDispatchController extends mfBaseController {
|
||||
|
||||
protected function init() {
|
||||
$this->needlogin = true;
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->me = $me;
|
||||
$this->layout()->set("me", $me);
|
||||
|
||||
if(!$me->is(["Admin", "netowner", "salespartner"])) {
|
||||
$this->redirect("Dashboard");
|
||||
}
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
$this->layout()->setTemplate("MailtemplateDispatch/Index");
|
||||
|
||||
$rfilter = $this->request->filter;
|
||||
if(!is_array($rfilter)) {
|
||||
$rfilter = [];
|
||||
}
|
||||
|
||||
$this->layout->set("filter", $rfilter);
|
||||
|
||||
$where = "";
|
||||
$filter = $this->getPreparedFilter($rfilter);
|
||||
|
||||
// pagination defaults
|
||||
$pagination = [];
|
||||
$pagination['start'] = 0;
|
||||
$pagination['count'] = 25;
|
||||
$pagination['maxItems'] = 0;
|
||||
|
||||
if(is_numeric($this->request->s)) {
|
||||
$pagination['start'] = intval($this->request->s);
|
||||
}
|
||||
|
||||
$pagination["maxItems"] = MailtemplateDispatch::count($filter);
|
||||
$this->layout()->set("pagination", $pagination);
|
||||
$dispatches = MailtemplateDispatch::search($filter);
|
||||
$this->layout()->set("dispatches", $dispatches);
|
||||
|
||||
}
|
||||
|
||||
private function getPreparedFilter($filter) {
|
||||
$new_filter = [];
|
||||
|
||||
if(is_array($filter) && count($filter)) {
|
||||
foreach($filter as $name => $value) {
|
||||
$new_filter[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $new_filter;
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
$this->layout()->setTemplate("MailtemplateDispatch/Form");
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
$id = $this->request->id;
|
||||
$dispatch = new MailtemplateDispatch($id);
|
||||
if(!$dispatch->id) {
|
||||
$this->layout()->setFlash("Emailversand nicht gefunden.", "error");
|
||||
$this->redirect("MailtemplateDispatch");
|
||||
}
|
||||
|
||||
$this->layout()->set("dispatch", $dispatch);
|
||||
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
//var_dump($r->get());exit;
|
||||
$id = $r->id;
|
||||
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$dispatch = new MailtemplateDispatch($id);
|
||||
if(!$dispatch->id) {
|
||||
$this->layout()->setFlash("Emailversand nicht gefunden", "error");
|
||||
$this->redirect("MailtemplateDispatch");
|
||||
}
|
||||
} else {
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$data["mailtemplate_id"] = $r->mailtemplate_id;
|
||||
$data["sender_name"] = $r->sender_name;
|
||||
$data["sender_email"] = $r->sender_email;
|
||||
$data["sender_replyto"] = $r->sender_replyto;
|
||||
$data["subject"] = $r->subject;
|
||||
$data["filter_datasource"] = null;
|
||||
$data['tosend_date'] = null;
|
||||
|
||||
if(is_array($r->filter_datasource) && count($r->filter_datasource)) {
|
||||
$data["filter_datasource"] = json_encode($r->filter_datasource);
|
||||
}
|
||||
|
||||
if($r->tosend_day) {
|
||||
$tosend_day = $r->tosend_day;
|
||||
$tosend_hour = $r->tosend_hour;
|
||||
if($tosend_hour < 0 || $tosend_hour > 23) {
|
||||
$tosend_hour = 0;
|
||||
}
|
||||
$data['tosend_date'] = self::dateToTimestamp($tosend_day . " " . str_pad($tosend_hour, 2, "0", STR_PAD_LEFT) . ":00:00");
|
||||
}
|
||||
|
||||
$filter = [];
|
||||
if($r->filter_fibu_account) {
|
||||
$filter["fibu_account"] = true;
|
||||
}
|
||||
if($r->filter_order_open) {
|
||||
$filter["order_open"] = true;
|
||||
}
|
||||
|
||||
if($r->filter_zip) {
|
||||
foreach(preg_split("/[, ]+/", $r->filter_zip) as $zip) {
|
||||
$filter["zip"][] = trim($zip);
|
||||
}
|
||||
}
|
||||
|
||||
$data["recipient_filter"] = json_encode($filter);
|
||||
|
||||
//var_dump($data);
|
||||
if($mode == "edit") {
|
||||
$dispatch->update($data);
|
||||
} else {
|
||||
$dispatch = MailtemplateDispatch::create($data);
|
||||
}
|
||||
$this->layout()->set("dispatch", $dispatch);
|
||||
|
||||
//var_dump($dispatch);exit;
|
||||
|
||||
if(!$dispatch->save()) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
return $this->addAction();
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Emailversand erfolgreich gespeichert", "success");
|
||||
$this->redirect("MailtemplateDispatch");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreateMailtemplateDispatch extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$table = $this->table("MailtemplateDispatch");
|
||||
$table->addColumn("mailtemplate_id", "integer", ["null" => false]);
|
||||
$table->addColumn("sender_email", "string", ["null" => false, "limit" => 64]);
|
||||
$table->addColumn("sender_name", "string", ["null" => false, "limit" => 64]);
|
||||
$table->addColumn("sender_replyto", "string", ["null" => true, "default" => null, "limit" => 64]);
|
||||
$table->addColumn("tosend_date", "integer", ["null" => true, "default" => null]);
|
||||
$table->addColumn("send_start", "integer", ["null" => true, "default" => null]);
|
||||
$table->addColumn("send_finish", "integer", ["null" => true, "default" => null]);
|
||||
$table->addColumn("send_lock", "integer", ["null" => true, "default" => null]);
|
||||
$table->addColumn("recipient_count", "integer", ["null" => false, "default" => 0]);
|
||||
$table->addColumn("subject", "string", ["null" => false, "limit" => 255]);
|
||||
$table->addColumn("filter_datasource", "json", ["null" => true, "default" => null]);
|
||||
$table->addColumn("recipient_filter", "json", ["null" => true, "default" => null]);
|
||||
$table->addColumn("note", "text", ["null" => true, "default" => null]);
|
||||
|
||||
$table->addColumn("create_by", "integer", ["null" => false]);
|
||||
$table->addColumn("edit_by", "integer", ["null" => false]);
|
||||
$table->addColumn("create", "integer", ["null" => false]);
|
||||
$table->addColumn("edit", "integer", ["null" => false]);
|
||||
|
||||
$table->create();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$this->table("MailtemplateDispatch")->drop()->save();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user