8
0
pdfdokumente/Modules/Application/controllers/d3_overview_controller_pdfdocuments.php

51 Zeilen
1.9 KiB
PHP

2020-05-19 16:06:32 +02:00
<?php
namespace D3\PdfDocuments\Modules\Application\controllers;
2020-05-20 11:51:48 +02:00
use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Core\DatabaseProvider;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\TableViewNameGenerator;
2020-05-19 16:06:32 +02:00
class d3_overview_controller_pdfdocuments extends d3_overview_controller_pdfdocuments_parent
{
public function canExport()
{
// We force reading from master to prevent issues with slow replications or open transactions (see ESDEV-3804).
2020-05-20 11:51:48 +02:00
$masterDb = DatabaseProvider::getMaster();
2020-05-19 16:06:32 +02:00
$sOrderId = $this->getEditObjectId();
2020-05-20 11:51:48 +02:00
$viewNameGenerator = Registry::get(TableViewNameGenerator::class);
2020-05-19 16:06:32 +02:00
$sTable = $viewNameGenerator->getViewName("oxorderarticles");
$sQ = "select count(oxid) from {$sTable} where oxorderid = " . $masterDb->quote($sOrderId) . " and oxstorno = 0";
$blCan = (bool) $masterDb->getOne($sQ);
return $blCan;
}
public function createPDF()
{
$soxId = $this->getEditObjectId();
if ($soxId != "-1" && isset($soxId)) {
// load object
2020-05-20 11:51:48 +02:00
$oOrder = oxNew(Order::class);
2020-05-19 16:06:32 +02:00
if ($oOrder->load($soxId)) {
2020-05-20 11:51:48 +02:00
self::$_blIsAdmin = 0;
$oUtils = Registry::getUtils();
2020-05-19 16:06:32 +02:00
$sTrimmedBillName = trim($oOrder->oxorder__oxbilllname->getRawValue());
$sFilename = $oOrder->oxorder__oxordernr->value . "_" . $sTrimmedBillName . ".pdf";
$sFilename = $this->makeValidFileName($sFilename);
2020-05-20 11:51:48 +02:00
ob_start();
$oOrder->genPDF($sFilename, Registry::getConfig()->getRequestParameter("pdflanguage"));
2020-05-19 16:06:32 +02:00
$sPDF = ob_get_contents();
ob_end_clean();
$oUtils->setHeader("Pragma: public");
$oUtils->setHeader("Cache-Control: must-revalidate, post-check=0, pre-check=0");
$oUtils->setHeader("Expires: 0");
$oUtils->setHeader("Content-type: application/pdf");
$oUtils->setHeader("Content-Disposition: attachment; filename=" . $sFilename);
2020-05-20 11:51:48 +02:00
Registry::getUtils()->showMessageAndExit($sPDF);
2020-05-19 16:06:32 +02:00
}
}
}
}