Merge branch 'fronkdev' into 'master'
Preorder Status Notification & Preordernotification Borderpoint image from Mapbox API See merge request fronk/thetool!771
This commit is contained in:
@@ -376,6 +376,24 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h4>Emailbenachrichtigungen</h4>
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="from_email_name">Absender Name</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" name="from_email_name" id="from_email_name" value="<?= $campaign->from_email_name ?>"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="from_email">Absender Emailadresse</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="text" class="form-control" name="from_email" id="from_email" value="<?= $campaign->from_email ?>"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<h4>API-User</h4>
|
||||
<div class="card">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php include(realpath(dirname(__FILE__)."/../../$mfLayoutPackage")."/header.php"); ?>
|
||||
<?php //var_dump($notification->filter);exit;?>
|
||||
|
||||
<!-- start page title -->
|
||||
<div class="row">
|
||||
@@ -93,6 +94,18 @@
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="status_id">Bestellstatus</label>
|
||||
<div class="col-lg-10">
|
||||
<select class="form-control" name="status_id[]" id="status_id" multiple="multiple">
|
||||
<?php foreach(PreorderstatusModel::getAll() as $status): ?>
|
||||
<option value="<?=$status->id?>" <?=($notification && array_key_exists("status_id", $notification->filter) && is_array($notification->filter["status_id"]) && in_array($status->id, $notification->filter["status_id"])) ? "selected='selected'" : ""?>><?=$status->code?> - <?=$status->name?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!--div class="form-group row">
|
||||
@@ -129,6 +142,16 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h4 class="mt-4">Übergabepunkt Bilddatei</h4>
|
||||
<div class="form-group row">
|
||||
<div class="col-lg-10">
|
||||
<select class="form-control" name="attach_borderpoint" id="attach_borderpoint">
|
||||
<option value="0" <?=(!$notification->attach_borderpoint) ? "selected='selected'" : ""?>>Nicht anhängen</option>
|
||||
<option value="1" <?=($notification->attach_borderpoint) ? "selected='selected'" : ""?>>Anhängen</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if(is_array($notification->files) && count($notification->files)): ?>
|
||||
<div class="row">
|
||||
@@ -349,6 +372,11 @@
|
||||
allowClear: true,
|
||||
placeholder: ""
|
||||
});
|
||||
$("#status_id").select2({
|
||||
allowClear: true,
|
||||
placeholder: "",
|
||||
closeOnSelect: false
|
||||
});
|
||||
});
|
||||
|
||||
function deleteFile(id) {
|
||||
|
||||
@@ -19,6 +19,7 @@ class Mailtemplate extends mfBaseModel {
|
||||
if(!is_array($replaceVars)) return $text;
|
||||
|
||||
foreach($replaceVars as $key => $replacement) {
|
||||
$key = strtoupper($key);
|
||||
$text = str_replace("{{".$key."}}", $replacement, $text);
|
||||
}
|
||||
|
||||
|
||||
@@ -153,6 +153,8 @@ class Preorder extends mfBaseModel {
|
||||
$this->log->error("config TT_PREORDER_STATUS_MATRIX not defined!");
|
||||
}
|
||||
|
||||
$actions = [];
|
||||
|
||||
// run every trigger bnetween old and new status code
|
||||
foreach(TT_PREORDER_STATUS_MATRIX as $intermediate_code => $status) {
|
||||
if($intermediate_code <= $old_status->code) continue;
|
||||
@@ -180,14 +182,155 @@ class Preorder extends mfBaseModel {
|
||||
$trigger = new $classname($this, $new_status);
|
||||
$trigger->run();
|
||||
|
||||
|
||||
//var_dump($status["action"]);
|
||||
if(array_key_exists("action", $status) && is_array($status) && property_exists($trigger, "run_action") && $trigger->run_action) {
|
||||
foreach($status["action"] as $type => $action) {
|
||||
if(!array_key_exists($type, $actions)) {
|
||||
$actions[$type] = [];
|
||||
}
|
||||
$action["status_code"] = $intermediate_code;
|
||||
$actions[$type][] = $action;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// run last email action
|
||||
if(array_key_exists("email", $actions) && is_array($actions["email"]) && count($actions["email"])) {
|
||||
// get last email action, ignore previous status'
|
||||
// we only want to send emails for the highest new status
|
||||
$email_action = array_pop($actions["email"]);
|
||||
|
||||
// check if this or a higher-status email was sent already
|
||||
$send_email = true;
|
||||
foreach(PreorderStatusnotificationLog::search(["preorder_id" => $this->id]) as $log) {
|
||||
if($log->status_code >= $email_action["status_code"]) {
|
||||
$send_email = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if($send_email) {
|
||||
$email_to = $this->runTriggerEmailAction($email_action);
|
||||
if($email_to === false) {
|
||||
$this->log->warning(__METHOD__ . ": Could not send preorder action email (Preorder " . $this->id . ")");
|
||||
} elseif(is_string($email_to)) {
|
||||
// TODO Save history
|
||||
$psn_log = PreorderStatusnotificationLog::create([
|
||||
"preorder_id" => $this->id,
|
||||
"status_code" => $email_action["status_code"],
|
||||
"email" => $email_to
|
||||
]);
|
||||
$psn_log->save();
|
||||
}
|
||||
} else {
|
||||
$this->log->warning(__METHOD__.": Not sending status email because same or higher status email was sent already (Preorder ".$this->id.")");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public function runTriggerEmailAction($action) {
|
||||
if(!array_key_exists("template", $action)) return false;
|
||||
if(!array_key_exists("from", $action)) return false;
|
||||
|
||||
$from_name = $this->getProperty("campaign")->from_email_name;
|
||||
$from_email = $this->getProperty("campaign")->from_email;
|
||||
if(!$from_email || !$from_name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$to = $this->email;
|
||||
if(!$to) {
|
||||
$this->log->warning(__METHOD__.": Keine To Adresse (Preorder ".$this->id.")");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$data = [];
|
||||
if(array_key_exists("data", $action)) {
|
||||
foreach(preg_split('/ *, */', $action["data"]) as $data_type) {
|
||||
if($data_type == "preorder") {
|
||||
$data["preorder"] = $this->getPropertiesAsArray();
|
||||
}
|
||||
if($data_type == "adb_hausnummer") {
|
||||
// TODO Array convertion in jeweilige Klasse auslagern
|
||||
$hausnummer = $this->getProperty("adb_hausnummer");
|
||||
if(!$hausnummer) continue;
|
||||
$hausnummer_data = (array) $this->getProperty("adb_hausnummer")->data;
|
||||
unset($hausnummer->data, $hausnummer->_old_data, $hausnummer->db, $hausnummer->log);
|
||||
|
||||
$data["adb_hausnummer"] = array_merge((array) $hausnummer, $hausnummer_data);
|
||||
}
|
||||
if($data_type == "adb_wohneinheit") {
|
||||
$wohneinheit = $this->getProperty("adb_wohneinheit");
|
||||
if(!$wohneinheit) continue;
|
||||
$wohneinheit_data = (array) $this->getProperty("adb_wohneinheit")->data;
|
||||
unset($wohneinheit->data, $wohneinheit->_old_data, $wohneinheit->db, $wohneinheit->log);
|
||||
|
||||
$data["adb_wohneinheit"] = array_merge((array) $wohneinheit, $wohneinheit_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$mailtemplate = MailtemplateModel::getFirst(["code" => $action["template"]]);
|
||||
if(!$mailtemplate) {
|
||||
$this->log->warning(__METHOD__.": Mailtemplate nicht gefunden: ".$action["template"]." (Preorder ".$this->id.")");
|
||||
return false;
|
||||
}
|
||||
|
||||
$replacers = [];
|
||||
foreach($data as $type => $values) {
|
||||
foreach($values as $key => $value) {
|
||||
if(substr($key, 0, 1) == "\0") continue;
|
||||
$replacers[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$subject = $mailtemplate->getVariableReplacedSubject($replacers);
|
||||
$body = $mailtemplate->renderBody($replacers);
|
||||
|
||||
$body_type = $mailtemplate->body_html ? "html" : "text";
|
||||
|
||||
$email = new Emailnotification();
|
||||
$email->setSubject($subject);
|
||||
if($body_type == "html") {
|
||||
$email->setHtmlBody($body);
|
||||
} else {
|
||||
$email->setBody($body);
|
||||
}
|
||||
$email->setFrom($from_email, $from_name);
|
||||
$email->setTo($to);
|
||||
$email->setHeader("X-".ucfirst(MFAPPNAME)."-pid", $this->id);
|
||||
$email->setHeader("X-".ucfirst(MFAPPNAME)."-ps", $this->getProperty("status")->code);
|
||||
// add attachments
|
||||
foreach($mailtemplate->files as $file) {
|
||||
if($file->filename && $file->file_id && $file->file->storage_filename);
|
||||
$this->log->debug($file->file->getFullPath());
|
||||
$email->addAttachment($file->file->getFullPath(), null, $file->filename, $file->file->mimetype ?: null);
|
||||
}
|
||||
$email->send();
|
||||
$this->log->info(__METHOD__.": Sending StatusTrigger Email to $to");
|
||||
|
||||
return $to;
|
||||
}
|
||||
|
||||
private function getPropertiesAsArray() {
|
||||
$preorder = clone $this;
|
||||
unset($preorder->data, $preorder->_old_data, $preorder->db, $preorder->log);
|
||||
$status = $this->getProperty("status");
|
||||
$array = (array) $preorder;
|
||||
|
||||
$array = array_merge($array, (array) $this->data);
|
||||
$return = [];
|
||||
foreach($array as $key => $value) {
|
||||
if(substr($key, 0, 1) == "\0") continue;
|
||||
$return[$key] = $value;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Cascade status changes down to adb_hausnummer and adb_wohneinheit
|
||||
*/
|
||||
@@ -704,6 +847,86 @@ class Preorder extends mfBaseModel {
|
||||
return $a;
|
||||
}
|
||||
|
||||
public function getBorderpointImageFile() {
|
||||
if(!$this->adb_hausnummer_id) return false;
|
||||
|
||||
$border_lat = $this->getProperty("adb_hausnummer")->borderpoint_lat;
|
||||
$border_long = $this->getProperty("adb_hausnummer")->borderpoint_long;
|
||||
|
||||
if(!$border_lat || !$border_long ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$filename = "borderpoint_map_h".$this->adb_hausnummer_id."_{$border_lat}_{$border_long}";
|
||||
|
||||
$bpi_file = PreorderFile::getFirst(["preorder_id" => $this->id, "filename" => $filename]);
|
||||
if($bpi_file) {
|
||||
return $bpi_file;
|
||||
}
|
||||
|
||||
|
||||
// get new Borderpoint Image from Mapbox API
|
||||
$params = [
|
||||
"gps_lat" => $border_lat,
|
||||
"gps_long" => $border_long,
|
||||
"zoom" => 19,
|
||||
"size_x" => 640,
|
||||
"size_y" => 640,
|
||||
"style" => "satellite-streets-v12",
|
||||
"pin" => [
|
||||
"gps_lat" => $border_lat,
|
||||
"gps_long" => $border_long,
|
||||
"size" => "l",
|
||||
"color" => "ee9900",
|
||||
"icon" => "embassy"
|
||||
],
|
||||
"access_token" => TT_MAPBOX_TILE_API_TOKEN
|
||||
];
|
||||
|
||||
$image_content = Mapbox_StaticImageApi::getImageFileContent($params);
|
||||
if(!$image_content) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$fs_filename = "$filename.jpg";
|
||||
if(!file_put_contents(MFUPLOAD_FILE_SAVE_PATH."/preorder-borderpoint/$fs_filename", $image_content)) {
|
||||
$this->log->error(__METHOD__.": Error saving Borderpoint Static Map Image File");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$file = FileModel::create([
|
||||
"name" => "borderpoint_map",
|
||||
"description" => $this->adb_hausnummer_id,
|
||||
"filename" => "$filename.jpg",
|
||||
"orig_filename" => "$filename.jpg",
|
||||
"store_filename" => $fs_filename,
|
||||
"subfolder" => "preorder-borderpoint",
|
||||
]);
|
||||
if(!$file->save()) {
|
||||
$this->log->error(__METHOD__.": Error saving File Object");
|
||||
return false;
|
||||
}
|
||||
|
||||
$file->mimetype = $file->getMimetype();
|
||||
$file->save();
|
||||
|
||||
$pf = PreorderFile::create([
|
||||
"preorder_id" => $this->id,
|
||||
"file_id" => $file->id,
|
||||
"filename" => $filename
|
||||
]);
|
||||
|
||||
if(!$pf->save()) {
|
||||
$this->log->error(__METHOD__.": Error saving PreorderFile Object");
|
||||
return false;
|
||||
}
|
||||
|
||||
return $pf;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function getApiArray($options = []) {
|
||||
if(!$this->id) {
|
||||
return false;
|
||||
@@ -1041,7 +1264,7 @@ class Preorder extends mfBaseModel {
|
||||
$this->partner = null;
|
||||
$this->building = null;
|
||||
$this->adb_hausnummer = null;
|
||||
$this->adb_wohneinheit;
|
||||
$this->adb_wohneinheit = null;
|
||||
|
||||
// cleanup Preorder data
|
||||
$this->create_by = $me->id;
|
||||
|
||||
@@ -506,6 +506,8 @@ class PreorderModel {
|
||||
$status_code = $filter['status_code'];
|
||||
if(is_numeric($status_code)) {
|
||||
$where .= " AND tt_preorderstatus.code=$status_code";
|
||||
} elseif(is_array($status_code)) {
|
||||
$where .= " AND tt_preorderstatus.code IN (".implode(",", $status_code).")";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
28
application/Preorder/statustrigger/130.php
Normal file
28
application/Preorder/statustrigger/130.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
class Preorder_Statustrigger_130 {
|
||||
private $log;
|
||||
|
||||
private $preorder;
|
||||
private $new_status;
|
||||
public $run_action = true;
|
||||
|
||||
public function __construct(Preorder $preorder, Preorderstatus $new_status) {
|
||||
$this->log = mfLoghandler::singleton();
|
||||
|
||||
$this->preorder = $preorder;
|
||||
$this->new_status = $new_status;
|
||||
}
|
||||
|
||||
public function run() {
|
||||
$this->log->debug(__METHOD__.": running trigger");
|
||||
|
||||
$changes = false;
|
||||
|
||||
if($changes) {
|
||||
$this->preorder->save();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
28
application/Preorder/statustrigger/245.php
Normal file
28
application/Preorder/statustrigger/245.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
class Preorder_Statustrigger_245 {
|
||||
private $log;
|
||||
|
||||
private $preorder;
|
||||
private $new_status;
|
||||
public $run_action = true;
|
||||
|
||||
public function __construct(Preorder $preorder, Preorderstatus $new_status) {
|
||||
$this->log = mfLoghandler::singleton();
|
||||
|
||||
$this->preorder = $preorder;
|
||||
$this->new_status = $new_status;
|
||||
}
|
||||
|
||||
public function run() {
|
||||
$this->log->debug(__METHOD__.": running trigger");
|
||||
|
||||
$changes = false;
|
||||
|
||||
if($changes) {
|
||||
$this->preorder->save();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
178
application/PreorderFile/PreorderFile.php
Normal file
178
application/PreorderFile/PreorderFile.php
Normal file
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
class PreorderFile extends mfBaseModel {
|
||||
private $file;
|
||||
private $preorder;
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
$classname = ucfirst($name);
|
||||
$idfield = $name . "_id";
|
||||
$this->$name = mfValuecache::singleton()->get("mfObjectmodel-$name-" . $this->$idfield);
|
||||
if($this->$name === null) {
|
||||
$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 PreorderFile();
|
||||
|
||||
$table_fields = [
|
||||
"preorder_id", "file_id", "filename",
|
||||
"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("PreorderFile", "*", "1 = 1 ORDER BY preorder_id,file_id");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new PreorderFile($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter = []) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$res = $db->select("PreorderFile", "*", "$where ORDER BY preorder_id,file_id LIMIT 1");
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new PreorderFile($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 `PreorderFile`
|
||||
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) {
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
|
||||
$sql = "SELECT PreorderFile.* FROM `PreorderFile`
|
||||
WHERE $where
|
||||
ORDER BY preorder_id,file_id
|
||||
";
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
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'];
|
||||
}
|
||||
}
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new PreorderFile($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("id", $filter)) {
|
||||
$id = $db->escape($filter['id']);
|
||||
if($id) {
|
||||
$where .= " AND PreorderFile.`id` = '$id'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("preorder_id", $filter)) {
|
||||
$preorder_id = $filter['preorder_id'];
|
||||
if(is_numeric($preorder_id)) {
|
||||
$where .= " AND preorder_id=$preorder_id";
|
||||
} elseif(is_array($preorder_id) && count($preorder_id)) {
|
||||
$where .= " AND PreorderFile.preorder_id IN (". implode(",", $preorder_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists("file_id", $filter)) {
|
||||
$file_id = $filter['file_id'];
|
||||
if(is_numeric($file_id)) {
|
||||
$where .= " AND PreorderFile.file_id=$file_id";
|
||||
} elseif(is_array($file_id) && count($file_id)) {
|
||||
$where .= " AND PreorderFile.file_id IN (". implode(",", $file_id).")";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("filename", $filter)) {
|
||||
$filename = FronkDB::singleton()->escape($filter['filename']);
|
||||
if($filename) {
|
||||
$where .= " AND filename LIKE '$filename'";
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
class PreorderStatusnotificationLog extends mfBaseModel {
|
||||
|
||||
|
||||
/********************************
|
||||
* Begin static Model functions
|
||||
*/
|
||||
|
||||
public static function create(Array $data) {
|
||||
$model = new PreorderStatusnotificationLog();
|
||||
|
||||
$table_fields = [
|
||||
"preorder_id", "status_code", "email",
|
||||
"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("PreorderStatusnotificationLog", "*", "1 = 1 ORDER BY preorder_id, status_code");
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new PreorderStatusnotificationLog($data);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT * FROM PreorderStatusnotificationLog
|
||||
WHERE $where
|
||||
ORDER BY adb_hausnummer_id LIMIT 1";
|
||||
//var_dump($sql);exit;
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
$item = new PreorderStatusnotificationLog($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 PreorderStatusnotificationLog
|
||||
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 = "preorder_id, status_code ASC";
|
||||
}
|
||||
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT * FROM PreorderStatusnotificationLog
|
||||
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 PreorderStatusnotificationLog($data);
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
private static function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
if(array_key_exists("preorder_id", $filter)) {
|
||||
$preorder_id = $filter['preorder_id'];
|
||||
if(is_numeric($preorder_id)) {
|
||||
$where .= " AND PreorderStatusnotificationLog.preorder_id=$preorder_id";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("status_code", $filter)) {
|
||||
$status_code = $filter['status_code'];
|
||||
if(is_numeric($status_code)) {
|
||||
$where .= " AND PreorderStatusnotificationLog.status_code=$status_code";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("email", $filter)) {
|
||||
$email = FronkDB::singleton()->escape($filter["email"]);
|
||||
if($email) {
|
||||
$where .= " AND PreorderStatusnotificationLog.email='$email'";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists("add-where", $filter)) {
|
||||
$where .= " ".$filter['add-where'];
|
||||
}
|
||||
|
||||
//var_dump($filter, $where);exit;
|
||||
return $where;
|
||||
}
|
||||
}
|
||||
@@ -236,6 +236,8 @@ class PreordercampaignController extends mfBaseController {
|
||||
$data['homes_total'] = (int)$r->homes_total;
|
||||
$data["cifurl"] = trim($r->cifurl);
|
||||
$data["cifcableurl"] = trim($r->cifcableurl);
|
||||
$data["from_email_name"] = trim($r->from_email_name);
|
||||
$data["from_email"] = trim($r->from_email);
|
||||
|
||||
if($r->from) {
|
||||
$data['from'] = self::dateToTimestamp($r->from);
|
||||
|
||||
@@ -19,6 +19,8 @@ class PreordercampaignModel {
|
||||
public $allow_unit_update;
|
||||
public $cifurl;
|
||||
public $cifcableurl;
|
||||
public $from_email_name;
|
||||
public $from_email;
|
||||
public $banned_rimo_fcp;
|
||||
public $note;
|
||||
|
||||
|
||||
@@ -31,7 +31,16 @@ class Preordernotification extends mfBaseModel {
|
||||
if($this->sender_replyto) {
|
||||
$reply_to = $this->sender_replyto;
|
||||
}
|
||||
|
||||
|
||||
$borderpoint_file = false;
|
||||
|
||||
if($this->attach_borderpoint) {
|
||||
$borderpoint_file = $preorder->getBorderpointImageFile();
|
||||
if(!$borderpoint_file) return false;
|
||||
|
||||
if(!file_exists($borderpoint_file->file->getFullPath())) return false;
|
||||
}
|
||||
|
||||
$to = $preorder->email;
|
||||
|
||||
if($email_to) {
|
||||
@@ -88,6 +97,9 @@ class Preordernotification extends mfBaseModel {
|
||||
$email->addAttachment($file["path"], null, $file["filename"], $file['mimetype']);
|
||||
}
|
||||
}
|
||||
if($this->attach_borderpoint && $borderpoint_file) {
|
||||
$email->addAttachment($borderpoint_file->file->getFullPath(), null, $borderpoint_file->file->filename, $borderpoint_file->file->mimetype);
|
||||
}
|
||||
$email->send();
|
||||
$this->log->info(__CLASS__."::sendToPreorder(): Sending Preordernotification for Preorder id ".$preorder->id);
|
||||
|
||||
|
||||
@@ -1,451 +1,461 @@
|
||||
<?php
|
||||
|
||||
class PreordernotificationController 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("Preordernotification/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);
|
||||
}
|
||||
|
||||
$preorder_filter = $filter;
|
||||
$my_campaigns = [];
|
||||
$my_campaign_ids = [];
|
||||
|
||||
if($this->me->is("Admin")) {
|
||||
if($filter['preordercampaign_id']) {
|
||||
$this->layout()->set("campaign", new Preordercampaign($filter['preordercampaign_id']));
|
||||
} else {
|
||||
$my_campaigns = PreordercampaignModel::getAll();
|
||||
}
|
||||
$this->layout()->set("my_campaigns", PreordercampaignModel::getAll());
|
||||
} else {
|
||||
$my_networks = $this->me->myNetworks(["netowner", "salespartner"]);
|
||||
//var_dump($my_networks);exit;
|
||||
|
||||
$user_network_ids = $this->me->getFlag("preorder_networks")->value();
|
||||
if($user_network_ids) {
|
||||
$user_network_ids = json_decode($user_network_ids);
|
||||
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("Preordernotification/Index");
|
||||
|
||||
$rfilter = $this->request->filter;
|
||||
if(!is_array($rfilter)) {
|
||||
$rfilter = [];
|
||||
}
|
||||
|
||||
if(is_array($user_network_ids) && count($user_network_ids)) {
|
||||
$this->layout->set("filter", $rfilter);
|
||||
|
||||
if(!$my_networks) {
|
||||
foreach($user_network_ids as $mnid) {
|
||||
$my_networks[] = new Network($mnid);
|
||||
}
|
||||
} else {
|
||||
//var_dump($user_network_ids, $my_networks);exit;
|
||||
$new_my_networks = [];
|
||||
foreach($my_networks as $network) {
|
||||
if(in_array($network->id, $user_network_ids)) {
|
||||
$new_my_networks[$network->id] = $network;
|
||||
}
|
||||
}
|
||||
$my_networks = $new_my_networks;
|
||||
}
|
||||
$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);
|
||||
}
|
||||
|
||||
foreach($my_networks as $network) {
|
||||
foreach(PreordercampaignModel::search(['network_id' => $network->id]) as $campaign) {
|
||||
$my_campaigns[] = $campaign;
|
||||
if(!in_array($campaign->id, $my_campaign_ids)) $my_campaign_ids[] = $campaign->id;
|
||||
}
|
||||
}
|
||||
//var_dump($my_network_ids,$my_campaign_ids);exit;
|
||||
$this->layout()->set("my_campaigns", $my_campaigns);
|
||||
|
||||
if($filter['preordercampaign_id'] && in_array($filter['preordercampaign_id'], $my_campaign_ids)) {
|
||||
$campaign_id = $filter['preordercampaign_id'];
|
||||
if(is_numeric($campaign_id) && $campaign_id > 0) {
|
||||
$campaign = new Preordercampaign($campaign_id);
|
||||
$this->layout()->set("campaign", $campaign);
|
||||
}
|
||||
} else {
|
||||
$filter['preordercampaign_id'] = $my_campaign_ids;
|
||||
}
|
||||
}
|
||||
//var_dump($filter);exit;
|
||||
$pagination['maxItems'] = PreordernotificationModel::count($filter);
|
||||
$notifications = PreordernotificationModel::search($filter, $pagination);
|
||||
|
||||
$this->layout()->set("pagination", $pagination);
|
||||
$this->layout()->set("notifications", $notifications);
|
||||
|
||||
|
||||
}
|
||||
|
||||
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("Preordernotification/Form");
|
||||
if(!$this->request->preordercampaign_id) {
|
||||
$this->layout()->setFlash("Keine Kampagne ausgewählt!", "warn");
|
||||
}
|
||||
|
||||
$campaign_id = $this->request->preordercampaign_id;
|
||||
$campaign = new Preordercampaign($campaign_id);
|
||||
$this->layout()->set("campaign", $campaign);
|
||||
|
||||
$partners = AddressModel::search(['addresstype' => ['netowner','salespartner']]);
|
||||
$this->layout()->set("partners", $partners);
|
||||
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
$id = $this->request->id;
|
||||
if(!is_numeric($id) || $id < 1) {
|
||||
$this->layout()->setFlash("Aussendung nicht gefunden", "error");
|
||||
$this->redirect("Preordernotification");
|
||||
}
|
||||
|
||||
$notification = new Preordernotification($id);
|
||||
if(!$notification->id) {
|
||||
$this->layout()->setFlash("Aussendung nicht gefunden", "error");
|
||||
$this->redirect("Preordernotification");
|
||||
}
|
||||
|
||||
//var_dump($notification->filter);exit;
|
||||
|
||||
$this->request->set("preordercampaign_id", $notification->preordercampaign_id); // needed in addAction()
|
||||
$this->layout()->set("notification", $notification);
|
||||
|
||||
return $this->addAction();
|
||||
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
//var_dump($r->get(), $_FILES);exit;
|
||||
|
||||
/*
|
||||
* add or edit
|
||||
*/
|
||||
$id = $r->id;
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$notification = new Preordernotification($id);
|
||||
if(!$notification->id) {
|
||||
$this->layout()->setFlash("Aussendung nicht gefunden", "error");
|
||||
$this->redirect("Preordernotification");
|
||||
}
|
||||
} else {
|
||||
$id = false;
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
/*
|
||||
* check campaign and permissions
|
||||
*/
|
||||
|
||||
$campaign_id = $r->preordercampaign_id;
|
||||
if(!$campaign_id) {
|
||||
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
|
||||
$this->redirect("Preordernotification");
|
||||
}
|
||||
$campaign = new Preordercampaign($campaign_id);
|
||||
if(!$campaign->id) {
|
||||
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
|
||||
$this->redirect("Preordernotification");
|
||||
}
|
||||
|
||||
// check permission
|
||||
if(!$this->me->is("Admin")) {
|
||||
/*$my_campaign_ids = [];
|
||||
$my_networks = $this->me->myNetworks(["netowner", "salespartner"]);
|
||||
//var_dump($my_networks);exit;
|
||||
|
||||
foreach($my_networks as $network) {
|
||||
foreach(PreordercampaignModel::search(['network_id' => $network->id]) as $campaign) {
|
||||
if(!in_array($campaign->id, $my_campaign_ids)) $my_campaign_ids[] = $campaign->id;
|
||||
}
|
||||
}
|
||||
|
||||
if(!in_array($campaign_id, $my_campaign_ids)) {
|
||||
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
|
||||
$this->redirect("Preordernotification");
|
||||
}*/
|
||||
|
||||
$preorder_filter = $filter;
|
||||
$my_campaigns = [];
|
||||
$my_campaign_ids = [];
|
||||
|
||||
$my_networks = $this->me->myNetworks(["netowner", "salespartner"]);
|
||||
//var_dump($my_networks);exit;
|
||||
if($this->me->is("Admin")) {
|
||||
if($filter['preordercampaign_id']) {
|
||||
$this->layout()->set("campaign", new Preordercampaign($filter['preordercampaign_id']));
|
||||
} else {
|
||||
$my_campaigns = PreordercampaignModel::getAll();
|
||||
}
|
||||
$this->layout()->set("my_campaigns", PreordercampaignModel::getAll());
|
||||
} else {
|
||||
$my_networks = $this->me->myNetworks(["netowner", "salespartner"]);
|
||||
//var_dump($my_networks);exit;
|
||||
|
||||
$user_network_ids = $this->me->getFlag("preorder_networks")->value();
|
||||
if($user_network_ids) {
|
||||
$user_network_ids = json_decode($user_network_ids);
|
||||
}
|
||||
$user_network_ids = $this->me->getFlag("preorder_networks")->value();
|
||||
if($user_network_ids) {
|
||||
$user_network_ids = json_decode($user_network_ids);
|
||||
}
|
||||
|
||||
if(is_array($user_network_ids) && count($user_network_ids)) {
|
||||
if(!$my_networks) {
|
||||
foreach($user_network_ids as $mnid) {
|
||||
$my_networks[] = new Network($mnid);
|
||||
if(is_array($user_network_ids) && count($user_network_ids)) {
|
||||
|
||||
if(!$my_networks) {
|
||||
foreach($user_network_ids as $mnid) {
|
||||
$my_networks[] = new Network($mnid);
|
||||
}
|
||||
} else {
|
||||
//var_dump($user_network_ids, $my_networks);exit;
|
||||
$new_my_networks = [];
|
||||
foreach($my_networks as $network) {
|
||||
if(in_array($network->id, $user_network_ids)) {
|
||||
$new_my_networks[$network->id] = $network;
|
||||
}
|
||||
}
|
||||
$my_networks = $new_my_networks;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($my_networks as $network) {
|
||||
foreach(PreordercampaignModel::search(['network_id' => $network->id]) as $campaign) {
|
||||
$my_campaigns[] = $campaign;
|
||||
if(!in_array($campaign->id, $my_campaign_ids)) $my_campaign_ids[] = $campaign->id;
|
||||
}
|
||||
}
|
||||
//var_dump($my_network_ids,$my_campaign_ids);exit;
|
||||
$this->layout()->set("my_campaigns", $my_campaigns);
|
||||
|
||||
if($filter['preordercampaign_id'] && in_array($filter['preordercampaign_id'], $my_campaign_ids)) {
|
||||
$campaign_id = $filter['preordercampaign_id'];
|
||||
if(is_numeric($campaign_id) && $campaign_id > 0) {
|
||||
$campaign = new Preordercampaign($campaign_id);
|
||||
$this->layout()->set("campaign", $campaign);
|
||||
}
|
||||
} else {
|
||||
//var_dump($user_network_ids, $my_networks);exit;
|
||||
$new_my_networks = [];
|
||||
foreach($my_networks as $network) {
|
||||
if(in_array($network->id, $user_network_ids)) {
|
||||
$new_my_networks[$network->id] = $network;
|
||||
}
|
||||
}
|
||||
$my_networks = $new_my_networks;
|
||||
$filter['preordercampaign_id'] = $my_campaign_ids;
|
||||
}
|
||||
}
|
||||
//var_dump($filter);exit;
|
||||
$pagination['maxItems'] = PreordernotificationModel::count($filter);
|
||||
$notifications = PreordernotificationModel::search($filter, $pagination);
|
||||
|
||||
$this->layout()->set("pagination", $pagination);
|
||||
$this->layout()->set("notifications", $notifications);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function getPreparedFilter($filter) {
|
||||
$new_filter = [];
|
||||
|
||||
if(is_array($filter) && count($filter)) {
|
||||
foreach($filter as $name => $value) {
|
||||
$new_filter[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($my_networks as $network) {
|
||||
foreach(PreordercampaignModel::search(['network_id' => $network->id]) as $campaign) {
|
||||
if(!in_array($campaign->id, $my_campaign_ids)) $my_campaign_ids[] = $campaign->id;
|
||||
}
|
||||
return $new_filter;
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
$this->layout()->setTemplate("Preordernotification/Form");
|
||||
if(!$this->request->preordercampaign_id) {
|
||||
$this->layout()->setFlash("Keine Kampagne ausgewählt!", "warn");
|
||||
}
|
||||
|
||||
if(!in_array($campaign_id, $my_campaign_ids)) {
|
||||
$campaign_id = $this->request->preordercampaign_id;
|
||||
$campaign = new Preordercampaign($campaign_id);
|
||||
$this->layout()->set("campaign", $campaign);
|
||||
|
||||
$partners = AddressModel::search(['addresstype' => ['netowner', 'salespartner']]);
|
||||
$this->layout()->set("partners", $partners);
|
||||
|
||||
}
|
||||
|
||||
protected function editAction() {
|
||||
$id = $this->request->id;
|
||||
if(!is_numeric($id) || $id < 1) {
|
||||
$this->layout()->setFlash("Aussendung nicht gefunden", "error");
|
||||
$this->redirect("Preordernotification");
|
||||
}
|
||||
|
||||
$notification = new Preordernotification($id);
|
||||
if(!$notification->id) {
|
||||
$this->layout()->setFlash("Aussendung nicht gefunden", "error");
|
||||
$this->redirect("Preordernotification");
|
||||
}
|
||||
|
||||
//var_dump($notification->filter);exit;
|
||||
|
||||
$this->request->set("preordercampaign_id", $notification->preordercampaign_id); // needed in addAction()
|
||||
$this->layout()->set("notification", $notification);
|
||||
|
||||
return $this->addAction();
|
||||
|
||||
}
|
||||
|
||||
protected function saveAction() {
|
||||
$r = $this->request;
|
||||
//var_dump($r->get(), $_FILES);exit;
|
||||
|
||||
/*
|
||||
* add or edit
|
||||
*/
|
||||
$id = $r->id;
|
||||
if(is_numeric($id) && $id > 0) {
|
||||
$mode = "edit";
|
||||
$notification = new Preordernotification($id);
|
||||
if(!$notification->id) {
|
||||
$this->layout()->setFlash("Aussendung nicht gefunden", "error");
|
||||
$this->redirect("Preordernotification");
|
||||
}
|
||||
} else {
|
||||
$id = false;
|
||||
$mode = "add";
|
||||
}
|
||||
|
||||
/*
|
||||
* check campaign and permissions
|
||||
*/
|
||||
|
||||
$campaign_id = $r->preordercampaign_id;
|
||||
if(!$campaign_id) {
|
||||
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
|
||||
$this->redirect("Preordernotification");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* data colletion
|
||||
*/
|
||||
$filter = [];
|
||||
if(is_array($r->type) && count($r->type)) {
|
||||
$filter['type'] = [];
|
||||
foreach($r->type as $type) {
|
||||
switch($type) {
|
||||
case "interest":
|
||||
$filter["type"][] = "interest";
|
||||
break;
|
||||
case "provision":
|
||||
$filter["type"][] = "provision";
|
||||
break;
|
||||
case "order":
|
||||
$filter["type"][] = "order";
|
||||
break;
|
||||
case "reorder":
|
||||
$filter["type"][] = "reorder";
|
||||
break;
|
||||
$campaign = new Preordercampaign($campaign_id);
|
||||
if(!$campaign->id) {
|
||||
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
|
||||
$this->redirect("Preordernotification");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(is_array($r->connection_type) && count($r->connection_type)) {
|
||||
$filter['connection_type'] = [];
|
||||
foreach($r->connection_type as $type) {
|
||||
switch($type) {
|
||||
case "single-dwelling":
|
||||
$filter["connection_type"][] = "single-dwelling";
|
||||
break;
|
||||
case "multi-dwelling":
|
||||
$filter["connection_type"][] = "multi-dwelling";
|
||||
break;
|
||||
case "apartment-building":
|
||||
$filter["connection_type"][] = "apartment-building";
|
||||
break;
|
||||
case "apartment":
|
||||
$filter["connection_type"][] = "apartment";
|
||||
break;
|
||||
case "business":
|
||||
$filter["connection_type"][] = "business";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter);
|
||||
$data = [];
|
||||
$data['preordercampaign_id'] = $campaign_id;
|
||||
$data['sender_email'] = $r->sender_email;
|
||||
$data['sender_name'] = $r->sender_name;
|
||||
$data['sender_replyto'] = $r->sender_replyto;
|
||||
$data['subject'] = $r->subject;
|
||||
$data['body_html'] = $r->body_html;
|
||||
$data['note'] = $r->note;
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
$data['preorder_filter'] = json_encode($filter);
|
||||
|
||||
//var_dump($data);exit;
|
||||
|
||||
if($mode == "edit") {
|
||||
$notification->update($data);
|
||||
} else {
|
||||
$notification = PreordernotificationModel::create($data);
|
||||
}
|
||||
|
||||
$new_id = $notification->save();
|
||||
if(!$new_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
if($id) {
|
||||
$this->redirect("Preordernotification", "edit", ['id' => $id]);
|
||||
} else {
|
||||
$this->redirect("Preordernotification");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Attachment upload
|
||||
*/
|
||||
|
||||
if(array_key_exists("attachment", $_FILES)) {
|
||||
$files = $_FILES['attachment'];
|
||||
if(is_array($files) && count($files)) {
|
||||
$file_errors = 0;
|
||||
foreach($files['name'] as $i => $name) {
|
||||
if(!$name) continue;
|
||||
$upload_error = false;
|
||||
try {
|
||||
$upload = new mfUpload(['attachment', $i]);
|
||||
$upload->setSavepath(MFUPLOAD_FILE_SAVE_PATH . "/" . TT_PREORDERNOTIFICATION_FILE_UPLOAD_SUBFOLDER);
|
||||
} catch(Exception $e) {
|
||||
$this->layout()->setFlash("Dateiupload fehlgeschlagen: ".$e->getMessage(), "warn");
|
||||
$file_errors++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!$upload->getSize()) {
|
||||
$this->layout()->setFlash("Dateiupload fehlgeschlagen: Datei ist leer!", "warn");
|
||||
$upload_error = true;
|
||||
}
|
||||
|
||||
$mime = "";
|
||||
|
||||
if(!$upload_error) {
|
||||
try {
|
||||
$mime = $upload->getMimetype();
|
||||
$upload->save();
|
||||
} catch(Exception $e) {
|
||||
$this->layout()->setFlash("Dateiupload fehlgeschlagen", "warn");
|
||||
$upload_error = true;
|
||||
}
|
||||
}
|
||||
|
||||
if($upload_error) {
|
||||
$file_errors++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$file_data = [];
|
||||
$file_data['name'] = $upload->getOriginalFilename();
|
||||
$file_data['filename'] = $upload->getOriginalFilename();
|
||||
$file_data['subfolder'] = TT_PREORDERNOTIFICATION_FILE_UPLOAD_SUBFOLDER;
|
||||
$file_data['store_filename'] = $upload->getFilename();
|
||||
$file_data['orig_filename'] = $upload->getOriginalFilename();
|
||||
$file_data['mimetype'] = $mime;
|
||||
|
||||
$file = FileModel::create($file_data);
|
||||
$file_id = $file->save();
|
||||
if(!$file_id) {
|
||||
$this->layout()->setFlash("Dateiupload fehlgeschlagen", "warn");
|
||||
unlink($upload->getSavepath()."/".$upload->getFilename());
|
||||
} else {
|
||||
$pnf = [];
|
||||
$pnf['preordernotification_id'] = $notification->id;
|
||||
$pnf['file_id'] = $file_id;
|
||||
$pnf['filename'] = $file->filename;
|
||||
|
||||
$notification_file = PreordernotificationFileModel::create($pnf);
|
||||
if(!$notification_file->save()) {
|
||||
$file->delete();
|
||||
unlink($upload->getSavepath()."/".$upload->getFilename());
|
||||
$this->layout()->setFlash("Dateiupload fehlgeschlagen", "warn");
|
||||
// check permission
|
||||
if(!$this->me->is("Admin")) {
|
||||
/*$my_campaign_ids = [];
|
||||
$my_networks = $this->me->myNetworks(["netowner", "salespartner"]);
|
||||
//var_dump($my_networks);exit;
|
||||
|
||||
foreach($my_networks as $network) {
|
||||
foreach(PreordercampaignModel::search(['network_id' => $network->id]) as $campaign) {
|
||||
if(!in_array($campaign->id, $my_campaign_ids)) $my_campaign_ids[] = $campaign->id;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!in_array($campaign_id, $my_campaign_ids)) {
|
||||
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
|
||||
$this->redirect("Preordernotification");
|
||||
}*/
|
||||
|
||||
$my_campaigns = [];
|
||||
$my_campaign_ids = [];
|
||||
|
||||
$my_networks = $this->me->myNetworks(["netowner", "salespartner"]);
|
||||
//var_dump($my_networks);exit;
|
||||
|
||||
$user_network_ids = $this->me->getFlag("preorder_networks")->value();
|
||||
if($user_network_ids) {
|
||||
$user_network_ids = json_decode($user_network_ids);
|
||||
}
|
||||
|
||||
if(is_array($user_network_ids) && count($user_network_ids)) {
|
||||
if(!$my_networks) {
|
||||
foreach($user_network_ids as $mnid) {
|
||||
$my_networks[] = new Network($mnid);
|
||||
}
|
||||
} else {
|
||||
//var_dump($user_network_ids, $my_networks);exit;
|
||||
$new_my_networks = [];
|
||||
foreach($my_networks as $network) {
|
||||
if(in_array($network->id, $user_network_ids)) {
|
||||
$new_my_networks[$network->id] = $network;
|
||||
}
|
||||
}
|
||||
$my_networks = $new_my_networks;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($my_networks as $network) {
|
||||
foreach(PreordercampaignModel::search(['network_id' => $network->id]) as $campaign) {
|
||||
if(!in_array($campaign->id, $my_campaign_ids)) $my_campaign_ids[] = $campaign->id;
|
||||
}
|
||||
}
|
||||
|
||||
if(!in_array($campaign_id, $my_campaign_ids)) {
|
||||
$this->layout()->setFlash("Vorbestellkampagne nicht gefunden", "error");
|
||||
$this->redirect("Preordernotification");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* data colletion
|
||||
*/
|
||||
$filter = [];
|
||||
if(is_array($r->type) && count($r->type)) {
|
||||
$filter['type'] = [];
|
||||
foreach($r->type as $type) {
|
||||
switch($type) {
|
||||
case "interest":
|
||||
$filter["type"][] = "interest";
|
||||
break;
|
||||
case "provision":
|
||||
$filter["type"][] = "provision";
|
||||
break;
|
||||
case "order":
|
||||
$filter["type"][] = "order";
|
||||
break;
|
||||
case "reorder":
|
||||
$filter["type"][] = "reorder";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(is_array($r->connection_type) && count($r->connection_type)) {
|
||||
$filter['connection_type'] = [];
|
||||
foreach($r->connection_type as $type) {
|
||||
switch($type) {
|
||||
case "single-dwelling":
|
||||
$filter["connection_type"][] = "single-dwelling";
|
||||
break;
|
||||
case "multi-dwelling":
|
||||
$filter["connection_type"][] = "multi-dwelling";
|
||||
break;
|
||||
case "apartment-building":
|
||||
$filter["connection_type"][] = "apartment-building";
|
||||
break;
|
||||
case "apartment":
|
||||
$filter["connection_type"][] = "apartment";
|
||||
break;
|
||||
case "business":
|
||||
$filter["connection_type"][] = "business";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(is_array($r->status_id) && count($r->status_id)) {
|
||||
$filter["status_id"] = [];
|
||||
foreach($r->status_id as $status_id) {
|
||||
$test_status = new Preorderstatus($status_id);
|
||||
if(!$test_status || !$test_status->id) continue;
|
||||
$filter["status_id"][] = $status_id;
|
||||
}
|
||||
}
|
||||
|
||||
//var_dump($filter);
|
||||
$data = [];
|
||||
$data['preordercampaign_id'] = $campaign_id;
|
||||
$data['sender_email'] = $r->sender_email;
|
||||
$data['sender_name'] = $r->sender_name;
|
||||
$data['sender_replyto'] = $r->sender_replyto;
|
||||
$data['subject'] = $r->subject;
|
||||
$data['body_html'] = $r->body_html;
|
||||
$data["attach_borderpoint"] = $r->attach_borderpoint;
|
||||
$data['note'] = $r->note;
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
$data['preorder_filter'] = json_encode($filter);
|
||||
|
||||
//var_dump($data);exit;
|
||||
|
||||
if($mode == "edit") {
|
||||
$notification->update($data);
|
||||
} else {
|
||||
$notification = PreordernotificationModel::create($data);
|
||||
}
|
||||
|
||||
$new_id = $notification->save();
|
||||
if(!$new_id) {
|
||||
$this->layout()->setFlash("Fehler beim Speichern", "error");
|
||||
if($id) {
|
||||
$this->redirect("Preordernotification", "edit", ['id' => $id]);
|
||||
} else {
|
||||
$this->redirect("Preordernotification");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Attachment upload
|
||||
*/
|
||||
|
||||
if(array_key_exists("attachment", $_FILES)) {
|
||||
$files = $_FILES['attachment'];
|
||||
if(is_array($files) && count($files)) {
|
||||
$file_errors = 0;
|
||||
foreach($files['name'] as $i => $name) {
|
||||
if(!$name) continue;
|
||||
$upload_error = false;
|
||||
try {
|
||||
$upload = new mfUpload(['attachment', $i]);
|
||||
$upload->setSavepath(MFUPLOAD_FILE_SAVE_PATH . "/" . TT_PREORDERNOTIFICATION_FILE_UPLOAD_SUBFOLDER);
|
||||
} catch(Exception $e) {
|
||||
$this->layout()->setFlash("Dateiupload fehlgeschlagen: " . $e->getMessage(), "warn");
|
||||
$file_errors++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!$upload->getSize()) {
|
||||
$this->layout()->setFlash("Dateiupload fehlgeschlagen: Datei ist leer!", "warn");
|
||||
$upload_error = true;
|
||||
}
|
||||
|
||||
$mime = "";
|
||||
|
||||
if(!$upload_error) {
|
||||
try {
|
||||
$mime = $upload->getMimetype();
|
||||
$upload->save();
|
||||
} catch(Exception $e) {
|
||||
$this->layout()->setFlash("Dateiupload fehlgeschlagen", "warn");
|
||||
$upload_error = true;
|
||||
}
|
||||
}
|
||||
|
||||
if($upload_error) {
|
||||
$file_errors++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$file_data = [];
|
||||
$file_data['name'] = $upload->getOriginalFilename();
|
||||
$file_data['filename'] = $upload->getOriginalFilename();
|
||||
$file_data['subfolder'] = TT_PREORDERNOTIFICATION_FILE_UPLOAD_SUBFOLDER;
|
||||
$file_data['store_filename'] = $upload->getFilename();
|
||||
$file_data['orig_filename'] = $upload->getOriginalFilename();
|
||||
$file_data['mimetype'] = $mime;
|
||||
|
||||
$file = FileModel::create($file_data);
|
||||
$file_id = $file->save();
|
||||
if(!$file_id) {
|
||||
$this->layout()->setFlash("Dateiupload fehlgeschlagen", "warn");
|
||||
unlink($upload->getSavepath() . "/" . $upload->getFilename());
|
||||
} else {
|
||||
$pnf = [];
|
||||
$pnf['preordernotification_id'] = $notification->id;
|
||||
$pnf['file_id'] = $file_id;
|
||||
$pnf['filename'] = $file->filename;
|
||||
|
||||
$notification_file = PreordernotificationFileModel::create($pnf);
|
||||
if(!$notification_file->save()) {
|
||||
$file->delete();
|
||||
unlink($upload->getSavepath() . "/" . $upload->getFilename());
|
||||
$this->layout()->setFlash("Dateiupload fehlgeschlagen", "warn");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* delete files
|
||||
*/
|
||||
//var_dump($r->deletefile);exit;
|
||||
if(is_array($r->deletefile)) {
|
||||
foreach($r->deletefile as $pnf_id => $check) {
|
||||
if(!$check) continue;
|
||||
$pnf = new PreordernotificationFile($pnf_id);
|
||||
if($pnf->preordernotification_id != $notification->id) continue;
|
||||
$pnf->file->delete();
|
||||
$pnf->delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// get and save preorder count
|
||||
$preorder_filter = json_decode($notification->preorder_filter, true);
|
||||
$preorder_filter['preordercampaign_id'] = $notification->preordercampaign_id;
|
||||
$preorder_count = PreorderModel::countActive($preorder_filter);
|
||||
$notification->recipient_count = $preorder_count;
|
||||
$notification->save();
|
||||
|
||||
if($r->send_testmail && $r->testmail_to) {
|
||||
$preorder = PreorderModel::getFirstActive($preorder_filter);
|
||||
if(!$preorder) {
|
||||
$this->layout()->setFlash("Testmail konnte nicht versendet werden. Keine Empfänger gefunden", "warn");
|
||||
$this->redirect("Preordernotification", "edit", ['id' => $new_id]);
|
||||
}
|
||||
$notification->sendToPreorder($preorder, $r->testmail_to);
|
||||
$this->layout()->setFlash("Test Email erfolgreich versendet", "success");
|
||||
$this->redirect("Preordernotification", "edit", ['id' => $new_id]);
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Erfolgreich gepeichert.", "success");
|
||||
if($r->return == "index") {
|
||||
$this->redirect("Preordernotification");
|
||||
} else {
|
||||
$this->redirect("Preordernotification", "edit", ['id' => $new_id]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* delete files
|
||||
*/
|
||||
//var_dump($r->deletefile);exit;
|
||||
if(is_array($r->deletefile)) {
|
||||
foreach($r->deletefile as $pnf_id => $check) {
|
||||
if(!$check) continue;
|
||||
$pnf = new PreordernotificationFile($pnf_id);
|
||||
if($pnf->preordernotification_id != $notification->id) continue;
|
||||
$pnf->file->delete();
|
||||
$pnf->delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// get and save preorder count
|
||||
$preorder_filter = json_decode($notification->preorder_filter, true);
|
||||
$preorder_filter['preordercampaign_id'] = $notification->preordercampaign_id;
|
||||
$preorder_count = PreorderModel::countActive($preorder_filter);
|
||||
$notification->recipient_count = $preorder_count;
|
||||
$notification->save();
|
||||
|
||||
if($r->send_testmail && $r->testmail_to) {
|
||||
$preorder = PreorderModel::getFirstActive($preorder_filter);
|
||||
if(!$preorder) {
|
||||
$this->layout()->setFlash("Testmail konnte nicht versendet werden. Keine Empfänger gefunden", "warn");
|
||||
$this->redirect("Preordernotification", "edit", ['id' => $new_id]);
|
||||
}
|
||||
$notification->sendToPreorder($preorder, $r->testmail_to);
|
||||
$this->layout()->setFlash("Test Email erfolgreich versendet", "success");
|
||||
$this->redirect("Preordernotification", "edit", ['id' => $new_id]);
|
||||
}
|
||||
|
||||
$this->layout()->setFlash("Erfolgreich gepeichert.", "success");
|
||||
if($r->return == "index") {
|
||||
$this->redirect("Preordernotification");
|
||||
} else {
|
||||
$this->redirect("Preordernotification", "edit", ['id' => $new_id]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ class PreordernotificationFileModel {
|
||||
|
||||
}
|
||||
|
||||
public static function getFirst() {
|
||||
public static function getFirst($filter = []) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
@@ -97,7 +97,7 @@ class PreordernotificationFileModel {
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||
} elseif(is_numeric($count)) {
|
||||
} elseif(is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class PreordercampaignAddEmailFrom extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$table = $this->table('Preordercampaign');
|
||||
$table->addColumn('from_email_name', 'string', ["null" => true, "default" => null, 'limit' => 64, "after" => "cifcableurl"]);
|
||||
$table->addColumn('from_email', 'string', ["null" => true, "default" => null, 'limit' => 64, "after" => "from_email_name"]);
|
||||
$table->update();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class CreatePreorderStatusnotificationLog extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$table = $this->table("PreorderStatusnotificationLog");
|
||||
$table->addColumn("preorder_id", "integer", ["null" => false]);
|
||||
$table->addColumn("status_code", "integer", ["null" => false]);
|
||||
$table->addColumn("email", "string", ["null" => false, "limit" => 255]);
|
||||
$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("PreorderStatusnotificationLog")->drop()->save();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class PreordernotificationAddAttachBorderpointAndCreatePreorderFile extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$table = $this->table("Preordernotification");
|
||||
$table->addColumn("attach_borderpoint", "integer", ["null" => false, "default" => 0, "limit" => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY, "after" => "preordercampaign_id"]);
|
||||
$table->update();
|
||||
|
||||
$pf = $this->table("PreorderFile");
|
||||
$pf->addColumn("preorder_id", "integer", ["null" => false]);
|
||||
$pf->addColumn("file_id", "integer", ["null" => false]);
|
||||
$pf->addColumn("filename", "string", ["null" => false]);
|
||||
$pf->addColumn("create_by", "integer", ["null" => false]);
|
||||
$pf->addColumn("edit_by", "integer", ["null" => false]);
|
||||
$pf->addColumn("create", "integer", ["null" => false]);
|
||||
$pf->addColumn("edit", "integer", ["null" => false]);
|
||||
$pf->create();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
$this->table("PreorderFile")->drop()->save();
|
||||
|
||||
$table = $this->table("Preordernotification");
|
||||
$table->removeColumn("attach_borderpoint");
|
||||
$table->update();
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
50
lib/Mapbox/StaticImageApi.php
Normal file
50
lib/Mapbox/StaticImageApi.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
class Mapbox_StaticImageApi {
|
||||
|
||||
public static function getImageFileContent(Array $params) : ?string {
|
||||
$access_token = $params["access_token"];
|
||||
$gps_lat = $params["gps_lat"];
|
||||
$gps_long = $params["gps_long"];
|
||||
$zoom = $params["zoom"];
|
||||
$size_x = $params["size_x"];
|
||||
$size_y = $params["size_y"];
|
||||
$style = $params["style"];
|
||||
$pin = $params["pin"];
|
||||
|
||||
$pin_part = "";
|
||||
|
||||
// https://api.mapbox.com/styles/v1/mapbox/satellite-streets-v12/static/pin-l-embassy+ee9900(15.4200370610,46.9599897293)/15.4200370610,46.9599897293,19/640x640?access_token=pk.eyJ1Ijoic2tuZXR3b3J4IiwiYSI6ImNqdWw3eXoyMzBieWU0M284OTU2eWNxMTMifQ.GrgBYKMXVt3TiwU53OBllQ
|
||||
$url = "https://api.mapbox.com/styles/v1/mapbox/$style/static";
|
||||
if(is_array($pin) && $pin["gps_lat"] && $pin["gps_long"] && $pin["size"]) {
|
||||
$pin_gps_lat = $pin["gps_lat"];
|
||||
$pin_gps_long = $pin["gps_long"];
|
||||
$pin_size = $pin["size"];
|
||||
$pin_color = $pin["color"];
|
||||
$pin_icon = $pin["icon"];
|
||||
|
||||
$pin_part .= "/pin-$pin_size";
|
||||
if($pin_icon) $pin_part .= "-$pin_icon";
|
||||
$pin_part .= "+$pin_color($pin_gps_long,$pin_gps_lat)";
|
||||
}
|
||||
|
||||
$url .= "$pin_part/$gps_long,$gps_lat,$zoom/{$size_x}x{$size_y}?access_token=$access_token";
|
||||
|
||||
$ctx_opts = [
|
||||
'http' => [
|
||||
'method' => 'GET',
|
||||
'header' => 'accept: application/json'
|
||||
]
|
||||
];
|
||||
|
||||
$ctx = stream_context_create($ctx_opts);
|
||||
$response = file_get_contents($url, false, $ctx);
|
||||
|
||||
if($response === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,9 @@ foreach(PreordernotificationModel::search(["send_finish" => null, "send_lock" =>
|
||||
}
|
||||
$notification->send_lock = ($mypid) ? $mypid : 1;
|
||||
$notification->save();
|
||||
|
||||
|
||||
$preorders = $notification->getPreorders();
|
||||
|
||||
foreach($notification->getPreorders() as $preorder) {
|
||||
$notification->sendToPreorder($preorder);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user