[*] PDF : PDF is now rendered by TCPDF throught HTML template
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10231 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -245,3 +245,4 @@ class AdminTaxesControllerCore extends AdminController
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -528,7 +528,7 @@ class AdminTranslationsControllerCore extends AdminController
|
||||
{
|
||||
if (!Validate::isLanguageIsoCode(Tools::strtolower(Tools::getValue('lang'))))
|
||||
die(Tools::displayError());
|
||||
$this->writeTranslationFile('PDF', _PS_TRANSLATIONS_DIR_.Tools::strtolower(Tools::getValue('lang')).'/pdf.php', 'PDF');
|
||||
$this->writeTranslationFile('PDF', _PS_THEME_DIR_.'pdf/lang/'.Tools::strtolower(Tools::getValue('lang')).'.php', 'PDF');
|
||||
}
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
|
||||
@@ -1624,25 +1624,46 @@ class AdminTranslationsControllerCore extends AdminController
|
||||
{
|
||||
$lang = Tools::strtolower(Tools::getValue('lang'));
|
||||
$_LANG = array();
|
||||
$str_output = '';
|
||||
|
||||
if (!file_exists(_PS_TRANSLATIONS_DIR_.$lang))
|
||||
if (!mkdir(_PS_TRANSLATIONS_DIR_.$lang, 0700))
|
||||
die('Please create a "'.$iso.'" directory in '._PS_TRANSLATIONS_DIR_);
|
||||
if (!file_exists(_PS_TRANSLATIONS_DIR_.$lang.'/pdf.php'))
|
||||
if (!file_put_contents(_PS_TRANSLATIONS_DIR_.$lang.'/pdf.php', "<?php\n\nglobal \$_LANGPDF;\n\$_LANGPDF = array();\n\n?>"))
|
||||
if (!Validate::isLangIsoCode($lang))
|
||||
die('Invalid iso lang ('.$lang.')');
|
||||
|
||||
$i18n_dir = _PS_THEME_DIR_.'pdf/lang/';
|
||||
$i18n_file = $i18n_dir.$lang.'.php';
|
||||
if (!file_exists($i18n_file))
|
||||
if (!mkdir($i18n_dir, 0700))
|
||||
die('Please create a "'.$lang.'" directory in '._PS_TRANSLATIONS_DIR_);
|
||||
|
||||
if (!file_exists($i18n_file))
|
||||
if (!file_put_contents($i18n_file, "<?php\n\nglobal \$_LANGPDF;\n\$_LANGPDF = array();\n\n?>"))
|
||||
die('Please create a "'.Tools::strtolower($lang).'.php" file in '.realpath(_PS_ADMIN_DIR_.'/'));
|
||||
unset($_LANGPDF);
|
||||
@include(_PS_TRANSLATIONS_DIR_.$lang.'/pdf.php');
|
||||
@include($i18n_file);
|
||||
$files = array();
|
||||
$count = 0;
|
||||
$tab = 'PDF_invoice';
|
||||
$tab = 'PDF';
|
||||
$tabsArray = array($tab=>array());
|
||||
$regex = '/self::l\(\''._PS_TRANS_PATTERN_.'\'[\)|\,]/U';
|
||||
// need to parse PDF.php in order to find $regex and add this to $tabsArray
|
||||
// this has to be done for the core class, and eventually for the override
|
||||
$tabsArray = $this->_parsePdfClass(_PS_CLASS_DIR_.'PDF.php', $regex, $_LANGPDF, $tab, $tabsArray);
|
||||
if(file_exists(_PS_ROOT_DIR_.'/override/classes/PDF.php'))
|
||||
$tabsArray = $this->_parsePdfClass(_PS_ROOT_DIR_.'/override/classes/PDF.php', $regex, $_LANGPDF, $tab, $tabsArray);
|
||||
foreach (glob(_PS_CLASS_DIR_.'pdf/'."*.php") as $filename)
|
||||
{
|
||||
$tabsArray = $this->_parsePdfClass($filename, $regex, $_LANGPDF, $tab, $tabsArray);
|
||||
if (file_exists(_PS_ROOT_DIR_.'/override/classes/pdf/'.basename($filename)))
|
||||
$tabsArray = $this->_parsePdfClass(_PS_ROOT_DIR_.'/override/classes/pdf/'.basename($filename), $regex, $_LANGPDF, $tab, $tabsArray);
|
||||
}
|
||||
|
||||
// parse pdf template
|
||||
/* Search language tags (eg {l s='to translate'}) */
|
||||
$regex = '/\{l s=\''._PS_TRANS_PATTERN_.'\'( js=1)?( pdf=\'true\')?\}/U';
|
||||
foreach (glob( _PS_THEME_DIR_.'/pdf/*.tpl') as $filename)
|
||||
{
|
||||
preg_match_all($regex, file_get_contents($filename), $matches);
|
||||
foreach ($matches[1] as $key)
|
||||
$tabsArray[$tab][$key] = stripslashes(key_exists($tab.md5(addslashes($key)), $_LANGPDF) ? html_entity_decode($_LANGPDF[$tab.md5(addslashes($key))], ENT_COMPAT, 'UTF-8') : '');
|
||||
|
||||
}
|
||||
|
||||
$count += isset($tabsArray[$tab]) ? sizeof($tabsArray[$tab]) : 0;
|
||||
|
||||
|
||||
@@ -104,3 +104,4 @@ class OrderFollowControllerCore extends FrontController
|
||||
$this->addJS(_THEME_JS_DIR_.'history.js');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,5 +84,10 @@ class OrderReturnControllerCore extends FrontController
|
||||
));
|
||||
$this->setTemplate(_PS_THEME_DIR_.'order-return.tpl');
|
||||
}
|
||||
|
||||
public function displayAjax()
|
||||
{
|
||||
$this->context->smarty->display($this->template);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,29 +25,66 @@
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
|
||||
|
||||
class PdfInvoiceControllerCore extends FrontController
|
||||
{
|
||||
protected $display_header = false;
|
||||
protected $display_footer = false;
|
||||
|
||||
public $content_only = true;
|
||||
|
||||
protected $template;
|
||||
public $filename;
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
$id_order = (int)Tools::getValue('id_order');
|
||||
|
||||
if (!$this->context->customer->isLogged() && !Tools::getValue('secure_key'))
|
||||
Tools::redirect('index.php?controller=authentication&back=pdf-invoice');
|
||||
|
||||
if (!(int)Configuration::get('PS_INVOICE'))
|
||||
die(Tools::displayError('Invoices are disabled in this shop.'));
|
||||
|
||||
if (isset($_GET['id_order']) && Validate::isUnsignedId($_GET['id_order']))
|
||||
$order = new Order($_GET['id_order']);
|
||||
if (isset($id_order) && Validate::isUnsignedId($id_order))
|
||||
$order = new Order($id_order);
|
||||
|
||||
if (!isset($order) || !Validate::isLoadedObject($order))
|
||||
die(Tools::displayError('Invoice not found'));
|
||||
else if ((isset($this->context->customer->id) && $order->id_customer != $this->context->customer->id) || (Tools::isSubmit('secure_key') && $order->secure_key != Tools::getValue('secure_key')))
|
||||
|
||||
if ((isset($this->context->customer->id) && $order->id_customer != $this->context->customer->id) || (Tools::isSubmit('secure_key') && $order->secure_key != Tools::getValue('secure_key')))
|
||||
die(Tools::displayError('Invoice not found'));
|
||||
else if (!OrderState::invoiceAvailable($order->getCurrentState()) && !$order->invoice_number)
|
||||
|
||||
if (!OrderState::invoiceAvailable($order->getCurrentState()) && !$order->invoice_number)
|
||||
die(Tools::displayError('No invoice available'));
|
||||
else
|
||||
PDF::invoice($order);
|
||||
|
||||
// assignments
|
||||
$country = new Country((int)$order->id_address_invoice);
|
||||
|
||||
$this->order = $order;
|
||||
}
|
||||
}
|
||||
|
||||
public function display()
|
||||
{
|
||||
$pdf = new PDF($this->order, PDF::TEMPLATE_INVOICE, $this->context->smarty, $this->context->language->id);
|
||||
$pdf->render();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the invoice template associated to the country iso_code
|
||||
* @param string $iso_user
|
||||
*/
|
||||
public function getTemplate($iso_country)
|
||||
{
|
||||
$template = _PS_THEME_PDF_DIR_.'/invoice.tpl';
|
||||
|
||||
$iso_template = _PS_THEME_PDF_DIR_.'/invoice.'.$iso_country.'.tpl';
|
||||
if (file_exists($iso_template))
|
||||
$template = $iso_template;
|
||||
|
||||
return $template;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,16 +35,22 @@ class PdfOrderReturnControllerCore extends FrontController
|
||||
if (!$this->context->customer->isLogged())
|
||||
Tools::redirect('index.php?controller=authentication&back=order-follow');
|
||||
|
||||
if (isset($_GET['id_order_return']) && Validate::isUnsignedId($_GET['id_order_return']))
|
||||
$orderReturn = new OrderReturn($_GET['id_order_return']);
|
||||
if (isset(Tools::getValue('id_order_return')) && Validate::isUnsignedId(Tools::getValue('id_order_return')))
|
||||
$this->orderReturn = new OrderReturn(Tools::getValue('id_order_return'));
|
||||
|
||||
if (!isset($orderReturn) || !Validate::isLoadedObject($orderReturn))
|
||||
if (!isset($this->orderReturn) || !Validate::isLoadedObject($this->orderReturn))
|
||||
die(Tools::displayError('Order return not found'));
|
||||
else if ($orderReturn->id_customer != $this->context->customer->id)
|
||||
else if ($this->orderReturn->id_customer != $this->context->customer->id)
|
||||
die(Tools::displayError('Order return not found'));
|
||||
else if ($orderReturn->state < 2)
|
||||
else if ($this->orderReturn->state < 2)
|
||||
die(Tools::displayError('Order return not confirmed'));
|
||||
else
|
||||
PDF::orderReturn($orderReturn);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function display()
|
||||
{
|
||||
$pdf = new PDF($this->orderReturn, PDF::TEMPLATE_ORDER_RETURN, $this->context->smarty);
|
||||
$pdf->render();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,25 +30,29 @@ class PdfOrderSlipControllerCore extends FrontController
|
||||
protected $display_header = false;
|
||||
protected $display_footer = false;
|
||||
|
||||
protected $order_slip;
|
||||
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if (!$this->context->customer->isLogged())
|
||||
Tools::redirect('index.php?controller=authentication&back=order-follow');
|
||||
|
||||
if (isset($_GET['id_order_slip']) && Validate::isUnsignedId($_GET['id_order_slip']))
|
||||
$orderSlip = new OrderSlip($_GET['id_order_slip']);
|
||||
$this->order_slip = new OrderSlip($_GET['id_order_slip']);
|
||||
|
||||
if (!isset($orderSlip) || !Validate::isLoadedObject($orderSlip))
|
||||
die(Tools::displayError('Order return not found'));
|
||||
else if ($orderSlip->id_customer != $this->context->customer->id)
|
||||
if (!isset($this->order_slip) || !Validate::isLoadedObject($this->order_slip))
|
||||
die(Tools::displayError('Order return not found'));
|
||||
|
||||
$order = new Order($orderSlip->id_order);
|
||||
if (!Validate::isLoadedObject($order))
|
||||
die(Tools::displayError('Order not found'));
|
||||
else if ($this->order_slip->id_customer != $this->context->customer->id)
|
||||
die(Tools::displayError('Order return not found'));
|
||||
|
||||
$order->products = OrderSlip::getOrdersSlipProducts((int)$orderSlip->id, $order);
|
||||
$ref = null;
|
||||
PDF::invoice($order, 'D', false, $ref, $orderSlip);
|
||||
}
|
||||
|
||||
public function display()
|
||||
{
|
||||
$pdf = new PDF($this->order_slip, PDF::TEMPLATE_ORDER_SLIP, $this->context->smarty);
|
||||
$pdf->render();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user