changes to new order PDF

This commit is contained in:
Frank Schubert
2021-08-27 10:56:36 +02:00
parent a045592d96
commit ad2cdbe4dd
4 changed files with 177 additions and 177 deletions
@@ -20,13 +20,13 @@
   
</div> </div>
<table> <table style="width: 100%">
<tr> <tr>
<td style="width:65%"> <td style="width:60%">
<img src="<?=$ressourcePathPrefix?>assets/pdf/logo.png" /> <img src="<?=$ressourcePathPrefix?>assets/pdf/logo.png" />
</td> </td>
<td style="width:35%;"> <td style="width:40%; text-align: right; margin-right: 1px;">
<table> <table style="text-align: left;">
<tr> <tr>
<td style="text-align: right;">Kundennummer:</td> <td style="text-align: right;">Kundennummer:</td>
<td><?=$owner->customer_number?></td> <td><?=$owner->customer_number?></td>
+1 -1
View File
@@ -383,7 +383,7 @@ class OrderController extends mfBaseController {
if($owner->save()) { if($owner->save()) {
// render service pin PDF // render service pin PDF
$pdf = new Layout(); $pdf = Layout::singleton();
$pdf->setTemplate("Emailtemplates/attachments/new_order.pdf"); $pdf->setTemplate("Emailtemplates/attachments/new_order.pdf");
$pdf->set("ressourcePathPrefix", BASEDIR."/public/"); $pdf->set("ressourcePathPrefix", BASEDIR."/public/");
$pdf->set("owner", $owner); $pdf->set("owner", $owner);
-4
View File
@@ -3,10 +3,6 @@
class Layout extends mfLayout { class Layout extends mfLayout {
protected static $instance; protected static $instance;
public function __construct(){
}
public static function singleton($param=false) { public static function singleton($param=false) {
if(!isset(self::$instance)) { if(!isset(self::$instance)) {
+136 -132
View File
@@ -1,50 +1,49 @@
<?php <?php
class mfLayout { class mfLayout {
private $log;
private $tvars=array(); private $log;
private $template="cli"; private $tvars = array();
private $package="default"; private $template = "cli";
private $inline; private $package = "default";
private $inline;
private $returnValue; private $returnValue;
protected static $instance;
protected function __construct() {
$this->log = mfLoghandler::singleton();
$this->inline = new stdClass();
protected static $instance; if (!defined("LAYOUT_DEFAULTPACKAGE")) {
protected function __construct() {
$this->log=mfLoghandler::singleton();
$this->inline=new stdClass();
if(!defined("LAYOUT_DEFAULTPACKAGE")) {
$this->package = "default"; $this->package = "default";
} else { } else {
$this->package = LAYOUT_DEFAULTPACKAGE; $this->package = LAYOUT_DEFAULTPACKAGE;
} }
if(method_exists($this, "init")) { if (method_exists($this, "init")) {
$this->init(); $this->init();
} }
} }
public static function singleton($param=false) { public static function singleton($param = false) {
if(!isset(self::$instance)) { if (!isset(self::$instance)) {
$c=__CLASS__; $c = __CLASS__;
self::$instance=new $c($param); self::$instance = new $c($param);
} }
return self::$instance; return self::$instance;
} }
public function set($name,$value) { public function set($name, $value) {
$this->tvars[$name]=$value; $this->tvars[$name] = $value;
} }
public function setPackage($package) { public function setPackage($package) {
$this->package=$package; $this->package = $package;
} }
public function setTemplate($template) { public function setTemplate($template) {
$this->template=$template; $this->template = $template;
} }
private function setReturnValue($value) { private function setReturnValue($value) {
$this->returnValue = $value; $this->returnValue = $value;
@@ -54,155 +53,159 @@ class mfLayout {
return $this->returnValue; return $this->returnValue;
} }
public function render() { public function render() {
$this->defaultLayoutvariables(); $this->defaultLayoutvariables();
foreach($this->tvars as $name => $value) { foreach ($this->tvars as $name => $value) {
if($name === "this") continue; if ($name === "this")
$$name=$value; continue;
} $$name = $value;
}
ob_end_clean(); ob_end_clean();
ob_start(); ob_start();
include(VIEWDIR."/".$this->package."/".$this->template.".php"); include(VIEWDIR . "/" . $this->package . "/" . $this->template . ".php");
return ob_get_clean(); return ob_get_clean();
} }
public function display() { public function display() {
echo $this->render(); echo $this->render();
} }
public function renderPDF($filename=false,$extraPdfArgs=false) { public function renderPDF($filename = false, $extraPdfArgs = false) {
$html = $this->render(); $html = $this->render();
if(!$filename) if (!$filename)
$filename = date('U').".pdf"; $filename = date('U') . ".pdf";
$wk = new mfWkhtmltopdf($html); $wk = new mfWkhtmltopdf($html);
$pdfargs = ""; $pdfargs = "";
if($extraPdfArgs) { if ($extraPdfArgs) {
$pdfargs .= " $extraPdfArgs"; $pdfargs .= " $extraPdfArgs";
} }
$filename = $wk->generate($filename,$pdfargs); $filename = $wk->generate($filename, $pdfargs);
if(!$filename) { if (!$filename) {
throw new Exception("Error generating PDF document."); throw new Exception("Error generating PDF document.");
} }
$file = PDFOUTPUTPATH."/$filename"; $file = PDFOUTPUTPATH . "/$filename";
return $file; return $file;
} }
public function displayPDF($filename=false,$extraPdfArgs=false) { public function displayPDF($filename = false, $extraPdfArgs = false) {
$filepath = $this->renderPDF($filename, $extraPdfArgs); $filepath = $this->renderPDF($filename, $extraPdfArgs);
if(!$filename && strpos($filepath, "/") !== false) { if (!$filename && strpos($filepath, "/") !== false) {
$path_parts = explode("/", $filepath); $path_parts = explode("/", $filepath);
$filename = end($path_parts); $filename = end($path_parts);
} }
header('Content-Type: application/octet-stream'); header('Content-Type: application/octet-stream');
header('Content-disposition: attachment; filename='.$filename); header('Content-disposition: attachment; filename=' . $filename);
header('Content-Transfer-Encoding: binary'); header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Type: '.mime_content_type($filename)); header('Content-Type: ' . mime_content_type($filename));
header("Content-Length: ".filesize($filename)); header("Content-Length: " . filesize($filename));
readfile($file); readfile($file);
exit; exit;
} }
public function setFlash($msg, $type="info") { public function setFlash($msg, $type = "info") {
// info, warning, error // info, warning, error
if(!$msg) { if (!$msg) {
return true; return true;
} }
if($type == "error") { if ($type == "error") {
$_SESSION[MFAPPNAME.'_mfError'] = $msg; $_SESSION[MFAPPNAME . '_mfError'] = $msg;
} elseif ($type == "warning" || $type == "warn") { } elseif ($type == "warning" || $type == "warn") {
$_SESSION[MFAPPNAME.'_mfWarning'] = $msg; $_SESSION[MFAPPNAME . '_mfWarning'] = $msg;
} elseif($type == "success") { } elseif ($type == "success") {
$_SESSION[MFAPPNAME.'_mfSuccess'] = $msg; $_SESSION[MFAPPNAME . '_mfSuccess'] = $msg;
} else { } else {
$_SESSION[MFAPPNAME.'_mfInfo'] = $msg; $_SESSION[MFAPPNAME . '_mfInfo'] = $msg;
} }
return true; return true;
} }
private function defaultLayoutvariables() { private function defaultLayoutvariables() {
$this->set('mfLayoutPackage',$this->package); $this->set('mfLayoutPackage', $this->package);
if(isset($_SESSION[MFAPPNAME.'_mfError'])) { if (isset($_SESSION[MFAPPNAME . '_mfError'])) {
$this->set("mfError",$_SESSION[MFAPPNAME.'_mfError']); $this->set("mfError", $_SESSION[MFAPPNAME . '_mfError']);
$this->set("_flash_set", true); $this->set("_flash_set", true);
unset($_SESSION[MFAPPNAME.'_mfError']); unset($_SESSION[MFAPPNAME . '_mfError']);
} }
if(isset($_SESSION[MFAPPNAME.'_mfWarning'])) { if (isset($_SESSION[MFAPPNAME . '_mfWarning'])) {
$this->set("mfWarning",$_SESSION[MFAPPNAME.'_mfWarning']); $this->set("mfWarning", $_SESSION[MFAPPNAME . '_mfWarning']);
$this->set("_flash_set", true); $this->set("_flash_set", true);
unset($_SESSION[MFAPPNAME.'_mfWarning']); unset($_SESSION[MFAPPNAME . '_mfWarning']);
} }
if(isset($_SESSION[MFAPPNAME.'_mfInfo'])) { if (isset($_SESSION[MFAPPNAME . '_mfInfo'])) {
$this->set("mfInfo",$_SESSION[MFAPPNAME.'_mfInfo']); $this->set("mfInfo", $_SESSION[MFAPPNAME . '_mfInfo']);
$this->set("_flash_set", true); $this->set("_flash_set", true);
unset($_SESSION[MFAPPNAME.'_mfInfo']); unset($_SESSION[MFAPPNAME . '_mfInfo']);
} }
if(isset($_SESSION[MFAPPNAME.'_mfSuccess'])) { if (isset($_SESSION[MFAPPNAME . '_mfSuccess'])) {
$this->set("mfSuccess",$_SESSION[MFAPPNAME.'_mfSuccess']); $this->set("mfSuccess", $_SESSION[MFAPPNAME . '_mfSuccess']);
$this->set("_flash_set", true); $this->set("_flash_set", true);
unset($_SESSION[MFAPPNAME.'_mfSuccess']); unset($_SESSION[MFAPPNAME . '_mfSuccess']);
} }
} }
/*
* Begin inline functions
*/
public static function strtrim($string,$chars) {
if(strlen($string) <= $chars) return $string;
return substr($string,0,$chars)."...";
}
// produces url for generating links /*
public static function getUrl($mod, $action=null, $param=null) { * Begin inline functions
if(!$mod) { */
return "";
} public static function strtrim($string, $chars) {
if (strlen($string) <= $chars)
return $string;
return substr($string, 0, $chars) . "...";
}
// produces url for generating links
public static function getUrl($mod, $action = null, $param = null) {
if (!$mod) {
return "";
}
if(MFUSEFANCYURLS) { if (MFUSEFANCYURLS) {
// use fancy urls // use fancy urls
$url=MFFANCYBASEURL; $url = MFFANCYBASEURL;
if($mod) { if ($mod) {
$url.="/$mod"; $url .= "/$mod";
if($action) { if ($action) {
$url.="/$action"; $url .= "/$action";
} }
} }
$url = preg_replace('#//#','/',$url); $url = preg_replace('#//#', '/', $url);
} else { } else {
// no fancy urls // no fancy urls
$url="?action=$mod"; $url = "?action=$mod";
if($action) { if ($action) {
$url.="_$action"; $url .= "_$action";
} }
} }
if(is_array($param) && count($param)) { if (is_array($param) && count($param)) {
$url .= (MFUSEFANCYURLS) ? "/" : "&amp;"; $url .= (MFUSEFANCYURLS) ? "/" : "&amp;";
$param_qs = http_build_query($param); $param_qs = http_build_query($param);
$url .= "$param_qs"; $url .= "$param_qs";
} }
return $url; return $url;
} }
public static function getResourcePath() { public static function getResourcePath() {
if(MFUSEFANCYURLS) { if (MFUSEFANCYURLS) {
$path = MFFANCYBASEURL; $path = MFFANCYBASEURL;
if(substr($path, -1, 1) != "/") { if (substr($path, -1, 1) != "/") {
$path .= "/"; $path .= "/";
} }
} else { } else {
@@ -211,31 +214,32 @@ class mfLayout {
return $path; return $path;
} }
public function cycle() { public function cycle() {
$args=func_get_args(); $args = func_get_args();
if(is_array($this->inline->cycle) && count($this->inline->cycle)) { if (is_array($this->inline->cycle) && count($this->inline->cycle)) {
if(array_diff($this->inline->cycle,$args)) { // if different, start new cycle if (array_diff($this->inline->cycle, $args)) { // if different, start new cycle
$this->inline->cycle=$args; $this->inline->cycle = $args;
$this->inline->cyclecount=0; $this->inline->cyclecount = 0;
} }
} else { } else {
$this->inline->cycle=$args; $this->inline->cycle = $args;
$this->inline->cyclecount=0; $this->inline->cyclecount = 0;
} }
if($this->inline->cyclecount>=count($this->inline->cycle)) { if ($this->inline->cyclecount >= count($this->inline->cycle)) {
$this->inline->cyclecount=0; $this->inline->cyclecount = 0;
} }
return $this->inline->cycle[$this->inline->cyclecount++];
}
return $this->inline->cycle[$this->inline->cyclecount++];
}
} }
function __($string) { function __($string) {
$lang = []; $lang = [];
include(BASEDIR."/lang/de.php"); include(BASEDIR . "/lang/de.php");
if(array_key_exists($string, $lang['de'])) { if (array_key_exists($string, $lang['de'])) {
return $lang['de'][$string]; return $lang['de'][$string];
} }
return $string; return $string;