disabled email sending in Order::save()
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
117
application/Emailnotification/Emailnotification.php
Normal file
117
application/Emailnotification/Emailnotification.php
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user