disabled email sending in Order::save()

This commit is contained in:
Frank Schubert
2021-08-26 22:46:48 +02:00
parent d77642f9de
commit ef38faa949
7 changed files with 309 additions and 16 deletions

View File

@@ -0,0 +1,72 @@
<?php
$this->setReturnValue([
'filename' => "xinon_Service_PIN_".$owner->customer_number.".pdf"
]);
?>
<html>
<head>
<title>Wichtige Kundeninformation - Service PIN</title>
</head>
<body>
<img src="<?=self::getResourcePath()?>assets/pdf/logo.png">
<table cellpadding="5" cellspacing="0" style="width: 100%; ">
<tr>
<td><?=$servicepin_header?></td>
<td style="text-align: right">
Kundennummer: <?=$owner->customer_number?><br>
Vertrag erfasst am: <?=date('d.m.Y', $order->create)?><br>
Bestelldatum: <?=date('d.m.Y', $order->order_date)?><br>
</td>
</tr>
<tr>
<td style="font-size:1.3em; font-weight: bold;">
<br><br>
Wichtige Kundeninformation
<br>
</td>
</tr>
<tr>
<td colspan="2">
<?php if($owner->company): ?>
<?=$owner->company?>
<?php endif; ?>
<?php if($owner->getFullName()): ?>
<?=$owner->getFullName()?>
<?php endif; ?>
<?=$owner->zip?> <?=$owner->city?>
</td>
</tr>
</table>
<br><br><br>
Sehr geehrte Damen und Herren,
<br><br>
wir freuen uns, dass Sie sich für ein Produkt von Xinon bzw. einem unserer Partner
entschieden haben und bestätigen hiermit den Eingang Ihrer Bestellung.
<br><br>
Bezüglich der ggf. erforderlichen Termine für die Installation melden wir uns (bzw.
unsere Partner vom Leitungsbau) sobald die Herstellung möglich ist.
<br><br>
<table cellpadding="5" cellspacing="0" style="width: 100%;" border="0">
<tr style="background-color: #cccccc; padding:5px;">
<td style="padding:5px;"><b>Ihr persönlicher Service-PIN lautet: <?=$owner->spin?></b></td>
</tr>
</table>
Gemäß der EU Datenschutzverordung sind wir dazu verpflichtet, vor der Beauskunftung
von persönlichen Daten eine Kundenidentifizierung vorzunehmen. Daher werden wir und
unsere Partner Sie bei zukünftigen Kontaktaufnahmen (z.B. vergessenen Passwörtern,
Rechnungsauskünfte, etc) nach Ihrem <b>persönlichen Service-PIN</b> fragen.
<b>Sollten Sie noch Fragen haben erreichen Sie uns per Mail (office@xinon.at) oder
telefonisch unter der Rufnummer 03115 40800.</b>
Mit besten Grüßen,
Ihr XINON Team
</body>
</html>

View File

@@ -0,0 +1,22 @@
<?php
$this->setReturnValue([
'subject' => "Ihre Bestellung wurde erfasst",
'from_email' => "vertrieb@xinon.at",
'from_email_name' => "XINON Kundenservice"
]);
?>
Sehr geehrte Damen und Herren,
im Anhang finden Sie weitere Informationen zur Ihrer Breitbandbestellung, sowie Ihren persönlichen Service-PIN.
Mit besten Grüßen,
Ihr XINON Team
--
XINON GmbH
p: +43 3115 40 800
f: +43 3115 40 800 10
a: Fladnitz im Raabtal 150, 8322 Studenzen, AUSTRIA
w: www.xinon.at  e: office@xinon.at

View File

@@ -80,13 +80,17 @@ class AddressModel {
public static function getLastCustomerNumber() {
$db = FronkDB::singleton();
$res = $db->select("Addres","customer_number", "customer_number > 0 ORDER BY customer_number DESC LIMIT 1");
$res = $db->select("Address","customer_number", "customer_number > 0 ORDER BY customer_number DESC LIMIT 1");
if(!$db->num_rows($res)) {
return false;
}
$data = $db->num_rows($res);
return $data->customer_number;
if($db->num_rows($res)) {
$data = $db->fetch_object($res);
return $data->customer_number;
}
return false;
}
public static function byNetwork($network_id, $addresstype) {
@@ -153,6 +157,20 @@ class AddressModel {
private function getSqlFilter($filter) {
$where = "1=1 ";
if(array_key_exists("customer_number", $filter)) {
$cn = $filter["customer_number"];
if(is_numeric($cn)) {
$where .= " AND customer_number=$cn";
}
}
if(array_key_exists("spin", $filter)) {
$spin = FronkDB::singleton()->escape($filter["spin"]);
if($spin) {
$where .= " AND spin='$spin'";
}
}
/*
* Address Type
*/

View File

@@ -0,0 +1,117 @@
<?php
require_once("Mail.php");
require_once("Mail/mime.php");
class Emailnotification {
private $headers = [];
private $subject;
private $body;
private $from_name = false;
private $email_from = false;
private $email_to = false;
private $attachments = [];
public function __construct() {
$this->headers = [
'X-Mailer' => 'XINON Mailer',
];
$this->email_from = TT_OUTGOING_EMAIL;
$this->from_name = TT_OUTGOING_EMAIL_NAME;
}
public function addAttachment($file = null, $content = null, $name = false, $c_type = "application/octet-stream", $disposition = "attachment", $encoding = "base64" , $charset = "utf-8") {
$attachment = [
"file" => $file,
"content" => $content,
"name" => $name,
"c_type" => $c_type,
"disposition" => $disposition,
"encoding" => $encoding,
"charset" => $charset
];
$attachment["isfile"] = false;
if($filename) {
$attachment['isfile'] = true;
}
$this->attachments[] = $attachment;
}
public function setHeader($name, $value) {
$this->headers[$name] = $value;
}
public function setSubject($subject) {
$this->subject = $subject;
}
public function setBody($body) {
$this->body = $body;
}
public function setFrom($email, $name = false) {
$this->email_from = $email;
$this->from_name = $name;
}
public function setTo($email) {
$this->email_to = $email;
$this->to_name = $name;
}
public function send() {
if(!$this->email_to) {
return false;
}
if(!$this->body) {
return false;
}
if(!is_array($this->headers) || !count($this->headers)) {
return false;
}
if(!$this->subject) {
return false;
}
if(!$this->headers['Subject']) {
$this->setHeader("Subject", $this->subject);
}
if(!$this->headers['From'] && $this->from_name) {
$this->headers['From'] = '"'.$this->from_name.'" <'.$this->email_from.'>';
}
//var_dump($this);exit;
$mimeparams['text_encoding']="8bit";
$mimeparams['text_charset']="utf-8";
$mimeparams['html_charset']="utf-8";
$mimeparams['head_charset']="utf-8";
$mime = new Mail_mime();
$mime->setTXTBody($this->body);
var_dump($att);exit;
if(count($this->attachments)) {
foreach($this->attachments as $att) {
if($att['isfile']) {
$mime->addAttachment($att["file"], $att["c_type"], $att["name"], true, $att['encoding'], $att['disposition'], $att['charset']);
} else {
$mime->addAttachment($att["content"], $att["c_type"], $att["name"], false, $att['encoding'], $att['disposition'], $att['charset']);
}
}
}
$body = $mime->get($mimeparams);
$headers = $mime->headers($this->headers);
$mail =& Mail::factory('mail', ["-f ".$this->email_from]);
$mail->send($this->email_to, $headers, $body);
}
}

View File

@@ -360,26 +360,70 @@ class OrderController extends mfBaseController {
}
// if product is not external and customer is new, create customer_number and service pin
if(!$prod->external ) {
if(!$owner->customer_number) {
$last_num = AddressModel::getLastCustomerNumber();
$this->log->debug("last_num: $last_num");
if($last_num) {
$new_num = $last_num + 1;
} else {
$new_num = TT_FIRST_CUSTNUM;
}
$owner->customer_number = $new_num;
$owner->save();
if(!AddressModel::search(['customer_number' => $new_num])) {
$owner->customer_number = $new_num;
$owner->save();
}
}
if(!$owner->spin) {
$spin = $owner->generateServicePin();
if($spin) {
if($spin && !AddressModel::search(['spin' => $spin])) {
$owner->spin = $spin;
$owner->save();
if($owner->save()) {
/*
// render service pin PDF
$pdf = new Layout();
$pdf->setTemplate("Emailtemplates/attachments/new_order.pdf");
$pdf->set("owner", $owner);
$pdfpath = $pdf->renderPDF();
$tvalue = $pdf->getReturnedValue();
$pdfname = $tvalue['filename'];
//var_dump($pdfpath);exit;
// send email to customer
// TODO template rendern auslagern nach Emailtempate klasse
$tpl = new Layout();
$tpl->setTemplate("Emailtemplates/customer/new_order");
$tpl->set("owner", $owner);
$body = $tpl->render();
$values = $tpl->getReturnedValue();
$subject = $values['subject'];
$from = $values['from_email'];
$from_name = $values['from_email_name'];
$to = $owner->email;
if(!$subject || !$from || !$from_name || !$to) {
$this->log->warn("Service PIN Email not sent. (subject: '$subject', from: '$from', from_email: '$from_email', to: '$to')");
} else {
$email = new Emailnotification();
$email->setSubject($subject);
$email->setBody($body);
$email->setFrom($from, $from_name);
$email->setTo($to);
$email->setHeader("X-xinon-oid", $order->id);
$email->setHeader("X-xinon-pid", $product->id);
$email->addAttachment($pdfpath, null, $pdfname, "application/pdf");
$email->send();
}
*/
}
}
}
}

View File

@@ -6,6 +6,7 @@ class mfLayout {
private $template="cli";
private $package="default";
private $inline;
private $returnValue;
protected static $instance;
@@ -45,6 +46,14 @@ class mfLayout {
$this->template=$template;
}
private function setReturnValue($value) {
$this->returnValue = $value;
}
public function getReturnedValue() {
return $this->returnValue;
}
public function render() {
$this->defaultLayoutvariables();
@@ -63,7 +72,7 @@ class mfLayout {
echo $this->render();
}
public function displayPDF($filename=false,$extraPdfArgs=false) {
public function renderPDF($filename=false,$extraPdfArgs=false) {
$html = $this->render();
if(!$filename)
@@ -84,16 +93,27 @@ class mfLayout {
$file = PDFOUTPUTPATH."/$filename";
header('Content-Type: application/octet-stream');
return $file;
}
public function displayPDF($filename=false,$extraPdfArgs=false) {
$filepath = $this->renderPDF($filename, $extraPdfArgs);
if(!$filename && strpos($filepath, "/") !== false) {
$path_parts = explode("/", $filepath);
$filename = end($path_parts);
}
header('Content-Type: application/octet-stream');
header('Content-disposition: attachment; filename='.$filename);
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Type: '.mime_content_type($file));
header("Content-Length: ".filesize($file));
readfile($file);
header('Content-Type: '.mime_content_type($filename));
header("Content-Length: ".filesize($filename));
readfile($file);
exit;
}
}
public function setFlash($msg, $type="info") {
// info, warning, error

BIN
public/assets/pdf/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB