Merge branch 'fronkdev' of code.fronk.at:fronk/thetool into fronkdev

This commit is contained in:
Frank Schubert
2024-09-20 13:09:15 +02:00
11 changed files with 158 additions and 23 deletions
+2 -1
View File
@@ -1047,12 +1047,13 @@ class PreorderApicontroller extends mfBaseApicontroller {
}
$return['status'] = $preorder->status->getApiArray();
foreach($preorder->statusflags as $sflag) {
$return['status']['flags'][$sflag->code] = [
$return['status']['flags'][] = [
"code" => (int)$sflag->code,
"text" => $sflag->name,
"value" => ($sflag->value->value == 1)
];
}
//var_dump($return['status']);exit;
if($addon_data) {
$return["additionalData"] = $addon_data;
}
@@ -122,6 +122,18 @@ class Emailnotification {
//$log->debug(print_r($headers, true));
$mail =& Mail::factory('mail', ["-f ".$this->email_from]);
/*
* PHP 8's mail() function now outputs proper line endings in headers (CRLF instead of LF).
* Mail_mail < 2.0 would detect a unix system and change the headers line ending to LF.
* On Mail submission to Exim (via sendmail), mail() adds its own headers first with CRLF line ending,
* making Exim treat every subsequent header's LF as an invalid line ending, adding a whitespace after the LF,
* making all our custom headers into one long header.
*
* See: https://www.exim.org/exim-html-current/doc/html/spec_html/ch-message_processing.html#SECTlineendings
*
* So we force CRLF line endings for headers here.
*/
$mail->sep = "\r\n";
$mail->send($this->email_to, $headers, $body);
}
+1 -1
View File
@@ -837,7 +837,7 @@ class InvoiceController extends mfBaseController {
public function createPDFs($limit = false) {
$invoice_path_base = MFUPLOAD_FILE_SAVE_PATH."/".TT_INVOICE_SAVE_SUBFOLDER;
$created = 0;
foreach(InvoiceModel::getAll() as $invoice) {
foreach(InvoiceModel::search(["invoice_file" => false]) as $invoice) {
if($limit && $created >= $limit) {
return $created;
}
+21 -4
View File
@@ -238,7 +238,11 @@ class InvoiceModel {
$db = FronkDB::singleton();
$res = $db->select("Invoice", "*", "1 = 1 ORDER BY invoice_number");
$sql = "SELECT Invoice.* FROM Invoice
LEFT JOIN InvoiceFile ON (InvoiceFile.invoice_id = Invoice.id)
ORDER BY invoice_number";
$res = $db->query($sql);
if($db->num_rows($res)) {
while($data = $db->fetch_object($res)) {
$items[] = new Invoice($data);
@@ -252,7 +256,8 @@ class InvoiceModel {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM Invoice
$sql = "SELECT Invoice.* FROM Invoice
LEFT JOIN InvoiceFile ON (InvoiceFile.invoice_id = Invoice.id)
WHERE $where
ORDER BY invoice_number LIMIT 1";
//var_dump($sql);exit;
@@ -273,7 +278,8 @@ class InvoiceModel {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM Invoice
$sql = "SELECT Invoice.* FROM Invoice
LEFT JOIN InvoiceFile ON (InvoiceFile.invoice_id = Invoice.id)
WHERE $where
ORDER BY invoice_number DESC LIMIT 1";
@@ -297,6 +303,7 @@ class InvoiceModel {
$where = self::getSqlFilter($filter);
$sql = "SELECT COUNT(*) as cnt FROM Invoice
LEFT JOIN InvoiceFile ON (InvoiceFile.invoice_id = Invoice.id)
WHERE $where";
mfLoghandler::singleton()->debug($sql);
@@ -320,7 +327,8 @@ class InvoiceModel {
$db = FronkDB::singleton();
$where = self::getSqlFilter($filter);
$sql = "SELECT * FROM Invoice
$sql = "SELECT Invoice.* FROM Invoice
LEFT JOIN InvoiceFile ON (InvoiceFile.invoice_id = Invoice.id)
WHERE $where
ORDER BY $order";
@@ -358,6 +366,15 @@ class InvoiceModel {
}
}
if(array_key_exists("invoice_file", $filter)) {
$invoice_file = $filter['invoice_file'];
if($invoice_file === true) {
$where .= " AND InvoiceFile.id > 0'";
} elseif($invoice_file === false || $invoice_file === null) {
$where .= " AND InvoiceFile.id IS NULL";
}
}
if(array_key_exists("invoice_number", $filter)) {
$invoice_number = $filter['invoice_number'];
if($invoice_number === true) {
+39 -3
View File
@@ -11,19 +11,55 @@ class Mailtemplate extends mfBaseModel {
}
public function getVariableReplacedBody($replaceVars) {
return $this->replaceVariables($this->body, $replaceVars);
$body = $this->body_html ? $this->body_html : $this->body_text;
return $this->replaceVariables($body, $replaceVars);
}
private function replaceVariables($text, $replaceVars) {
if(!is_array($replaceVars)) return false;
if(!is_array($replaceVars)) return $text;
foreach($replaceVars as $key => $replacement) {
$body = str_replace("{{".$key."}}", $replacement, $body);
$text = str_replace("{{".$key."}}", $replacement, $text);
}
return $text;
}
public function renderBody($body_replacers = null) {
if(is_array($body_replacers)) {
$body = $this->getVariableReplacedBody($body_replacers);
} else {
$body = $this->body_html ? $this->body_html : $this->body_text;
}
// handle EMBED Tokens
$m = [];
if(preg_match_all('/{{EMBED:([^}]+)}}/i', $body, $m)) {
if(array_key_exists(1, $m)) {
foreach($m[1] as $match) {
$tpl_name = $match;
$tpl = MailtemplateModel::getFirst(["code" => $tpl_name]);
if(!$tpl) continue;
$tpl_body = $tpl->body_html ? $tpl->body_html : $tpl->body_text;
$tpl_replace = $this->replaceVariables($tpl_body, $body_replacers);
$body = $this->replaceVariables($body, ["EMBED:$tpl_name" => $tpl_replace]);
}
}
}
return $body;
}
public function renderSubject($subject_replacers = null) {
if(is_array($subject_replacers)) {
$subject = $this->getVariableReplacedSubject($subject_replacers);
} else {
$subject = $this->subject;
}
return $subject;
}
public function getProperty($name) {
if($this->$name == null) {
@@ -53,6 +53,10 @@ class MailtemplateController extends mfBaseController {
private function getPreparedFilter($filter) {
$new_filter = [];
if(array_key_exists("is_include", $filter) && !is_numeric($filter["is_include"])) {
unset($filter["is_include"]);
}
foreach($filter as $name => $value) {
$new_filter[$name] = $value;
}
+2 -2
View File
@@ -608,13 +608,13 @@ class Preorder extends mfBaseModel {
$status = $this->getProperty("status")->getApiArray();
foreach($this->getProperty("statusflags") as $sflag) {
$status["flags"][$sflag->code] = [
$status["flags"][] = [
"code" => (int)$sflag->code,
"text" => $sflag->name,
"value" => ($sflag->value->value == 1)
];
}
//var_dump($status);exit;
$a = [];
$a['code'] = strtoupper($this->ucode);