diff --git a/Layout/default/Emailtemplates/attachments/new_order.pdf.php b/Layout/default/Emailtemplates/attachments/new_order.pdf.php
new file mode 100644
index 000000000..41b1851f2
--- /dev/null
+++ b/Layout/default/Emailtemplates/attachments/new_order.pdf.php
@@ -0,0 +1,72 @@
+setReturnValue([
+ 'filename' => "xinon_Service_PIN_".$owner->customer_number.".pdf"
+ ]);
+?>
+
+
+
+ Wichtige Kundeninformation - Service PIN
+
+
+
+
+
+
+ | =$servicepin_header?> |
+
+ Kundennummer: =$owner->customer_number?>
+ Vertrag erfasst am: =date('d.m.Y', $order->create)?>
+ Bestelldatum: =date('d.m.Y', $order->order_date)?>
+ |
+
+
+
+
+ Wichtige Kundeninformation
+
+ |
+
+
+ |
+ company): ?>
+ =$owner->company?>
+
+ getFullName()): ?>
+ =$owner->getFullName()?>
+
+ =$owner->zip?> =$owner->city?>
+ |
+
+
+
+
+ Sehr geehrte Damen und Herren,
+
+ 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.
+
+ Bezüglich der ggf. erforderlichen Termine für die Installation melden wir uns (bzw.
+ unsere Partner vom Leitungsbau) sobald die Herstellung möglich ist.
+
+
+
+ | Ihr persönlicher Service-PIN lautet: =$owner->spin?> |
+
+
+
+
+ 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 persönlichen Service-PIN fragen.
+
+ Sollten Sie noch Fragen haben erreichen Sie uns per Mail (office@xinon.at) oder
+ telefonisch unter der Rufnummer 03115 40800.
+
+ Mit besten Grüßen,
+
+ Ihr XINON Team
+
+
\ No newline at end of file
diff --git a/Layout/default/Emailtemplates/customer/new_order.php b/Layout/default/Emailtemplates/customer/new_order.php
new file mode 100644
index 000000000..9e90df0fe
--- /dev/null
+++ b/Layout/default/Emailtemplates/customer/new_order.php
@@ -0,0 +1,22 @@
+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
diff --git a/application/Address/AddressModel.php b/application/Address/AddressModel.php
index bb668d0a6..bdd2227a4 100644
--- a/application/Address/AddressModel.php
+++ b/application/Address/AddressModel.php
@@ -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
*/
diff --git a/application/Emailnotification/Emailnotification.php b/application/Emailnotification/Emailnotification.php
new file mode 100644
index 000000000..d1455fcd8
--- /dev/null
+++ b/application/Emailnotification/Emailnotification.php
@@ -0,0 +1,117 @@
+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);
+ }
+
+}
\ No newline at end of file
diff --git a/application/Order/OrderController.php b/application/Order/OrderController.php
index 1b2b79bb4..ec52b2566 100644
--- a/application/Order/OrderController.php
+++ b/application/Order/OrderController.php
@@ -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();
+ }
+ */
+ }
+
}
}
}
diff --git a/lib/mvcfronk/mfLayout/mfLayout.php b/lib/mvcfronk/mfLayout/mfLayout.php
index 0bd461baa..5984c9ee4 100644
--- a/lib/mvcfronk/mfLayout/mfLayout.php
+++ b/lib/mvcfronk/mfLayout/mfLayout.php
@@ -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
diff --git a/public/assets/pdf/logo.png b/public/assets/pdf/logo.png
new file mode 100644
index 000000000..0d5e5cd51
Binary files /dev/null and b/public/assets/pdf/logo.png differ