controller_displayName = $this->l('Settings');
$this->toolbar_title = $this->l('Settings');
$this->bootstrap = true;
}
public function postProcess()
{
if (Tools::isSubmit('submitConfiguratorSettings'))
{
Configuration::updateValue('configurator_from_date', Tools::getValue("configurator_from_date"));
Configuration::updateValue('configurator_to_date', Tools::getValue("configurator_to_date"));
$configurator_group = Tools::getValue("configurator_group");
$q = "SELECT `name` FROM `" . _DB_PREFIX_ . "configurator_group` WHERE `id_configurator_group` = ".(int)$configurator_group;
$configurator_group_name = Db::getInstance()->getValue($q);
$q = "SELECT * FROM `" . _DB_PREFIX_ . "config_product` where `date` >= '".Tools::getValue("configurator_from_date")."' AND `date` <= '".Tools::getValue("configurator_to_date")."' AND `id_configurator_group` = ".(int)$configurator_group;
$configsproducts = Db::getInstance()->executeS($q);
array_map('unlink', array_filter((array) glob(dirname(__FILE__)."/../../tmp/*/*")));
array_map('unlink', array_filter((array) glob(dirname(__FILE__)."/../../tmp/*")));
$zipUrl = dirname(__FILE__)."/../../tmp/".$configurator_group_name."_".date("Y-m-d").".zip";
if(file_exists($zipUrl)) {
unlink($zipUrl);
}
$zip = new ZipArchive();
if ($zip->open($zipUrl, ZipArchive::CREATE) === TRUE) {
foreach ($configsproducts as $configproduct) {
try {
$cart = new Cart($configproduct['id_cart']);
$customer = new Customer($cart->id_customer);
$this->saveConfigFile($configproduct, $customer->email);
$zip->addFile(dirname(__FILE__).'/../../tmp/'.$customer->email.'/config_product_'.$configproduct['id_config_product'].'.pdf', $customer->email."/".$configproduct['id_config_product'].'.pdf');
} catch (Exception $e) {
}
}
$zip->close();
}
// Header content type
header("Content-type: application/zip");
header("Content-Length: " . filesize($zipUrl));
header('Content-disposition: attachment; filename="'.$configurator_group_name."_".date("Y-m-d").'.zip"');
ob_clean();
flush();
die(readfile($zipUrl));
}
}
public function saveConfigFile($configproduct, $email)
{
if(!file_exists(dirname(__FILE__).'/../../tmp/'.$email)) {
mkdir(dirname(__FILE__).'/../../tmp/'.$email, 0755);
}
$configurator_fields = array();
$q = "SELECT * FROM `" . _DB_PREFIX_ . "config` where `id_product` = ".(int)$configproduct['id_cart_product'].' AND `id_page` = '.(int)$configproduct['page'];
$configsIds = Db::getInstance()->executeS($q);
$fonts = json_decode(file_get_contents(dirname(__FILE__)."/../../fonts.json"), true);
if($configsIds) {
foreach ($configsIds as $configId) {
$print_width = $configId['print_width'];
$print_height = $configId['print_height'];
$orientation = PDF_PAGE_ORIENTATION;
if($configId['print_width'] < $configId['print_height']) {
$print_width = $configId['print_height'];
$print_height = $configId['print_width'];
$orientation = 'H';
}
$q = "SELECT * FROM `" . _DB_PREFIX_ . "config_field_value` where `id_config` = ".$configId['id_config']." AND `id_config_product` = ".$configproduct['id_config_product'];
$fields = Db::getInstance()->executeS($q);
$html_first = '';
$pdf = new My_PDF($orientation, PDF_UNIT, array($this->getUnitsCount($print_width), $this->getUnitsCount($print_height)), true, 'UTF-8', true);
$pdf->changeTheDefault(false);
$pdf->AddPage();
$pdf->SetMargins(0, 0, 0,true);
$pdf->writeHTMLCell($this->pixelsToUnits($configId['width']), $this->pixelsToUnits($configId['height']), 0, 0, $html_first);
foreach ($fields as $field) {
$width = (float)(($configId['width']*$field['width'])/100);
$height = (float)(($configId['height']*$field['height'])/100);
$x = (float)(($configId['width']*$field['x'])/100);
$y = (float)(($configId['height']*$field['y'])/100);
foreach($fonts as $font) {
if($font['font-family'] === $field['font']) {
$fontname = TCPDF_FONTS::addTTFfont($font['src'], 'TrueTypeUnicode', '', 96);
$pdf->SetFont($fontname, '', $this->pixelsToUnits($field['fontsize']), '', false);
break;
}
}
// die($this->percentToUnits($configId['width'], $width).", ".$this->percentToUnits($configId['height'], $height).", ".$this->percentToUnits($configId['width'], $x).", ".$this->percentToUnits($configId['height'], $y));
if($field['type'] == 1) {
$html_first = '