150 lines
4.3 KiB
PHP
150 lines
4.3 KiB
PHP
<?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");
|
|
|
|
|
|
}
|
|
} |