lang = TRUE;
parent::__construct();
}
public function displayForm($isMainTab=TRUE) {
global $currentIndex, $cookie;
parent::displayForm();
echo '
';
echo '
';
}
public function display() {
global $cookie, $currentIndex;
$this->curnewsletter = null;
if($id = Tools::getValue('id')) {
$newsletter = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'privatesale_newsletter` WHERE `id_newsletter` = '.(int) $id);
if(count($newsletter) > 0) {
$this->curnewsletter = $newsletter[0];
} else {
Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesNewsletter'));
}
}
$this->displayForm();
echo '
';
echo '';
}
function postProcess() {
global $cookie, $currentIndex;
if(Tools::isSubmit('submitNewsletterAdd')) {
Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'privatesale_newsletter` VALUES (
DEFAULT,
"'.pSQL(Tools::getValue('title')).'",
"'.pSQL(Tools::getValue('image_url')).'",
"'.pSQL(Tools::getValue('date_pub')).'",
"'.pSQL(Tools::getValue('version')).'"
)
');
$id_newsletter = Db::getInstance()->Insert_ID();
// if(isset($_FILES['image']) && $_FILES['image']['name'] != '') {
// if(!copy($_FILES['image']['tmp_name'], _PS_ROOT_DIR_.'/modules/privatesales/img/newsletter/'.$id_newsletter.'.jpg')) {
// echo $this->displayError($this->l('An error occured during the image upload.'));
// }
// }
} elseif(Tools::isSubmit('submitNewsletterUpdate') && $id_newsletter = (int) Tools::getValue('id_newsletter')) {
if(count(Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'privatesale_newsletter`
WHERE `id_newsletter` = '.$id_newsletter)
) > 0) {
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'privatesale_newsletter`
SET `title` = "'.pSQL(Tools::getValue('title')).'",
`image_url` = "'.pSQL(Tools::getValue('image_url')).'",
`date_pub` = "'.pSQL(Tools::getValue('date_pub')).'",
`version` = "'.pSQL(Tools::getValue('version')).'"
WHERE `id_newsletter` = '.$id_newsletter.'
');
}
// if(isset($_FILES['image']) && $_FILES['image']['name'] != '') {
// if(!copy($_FILES['image']['tmp_name'], _PS_ROOT_DIR_.'/modules/privatesales/img/newsletter/'.$id_newsletter.'.jpg')) {
// echo $this->displayError($this->l('An error occured during the image upload.'));
// }
// }
} elseif(isset($_GET['delete']) && $id_newsletter = Tools::getValue('id')) {
Db::getInstance()->Execute('
DELETE FROM `'._DB_PREFIX_.'privatesale_newsletter`
WHERE `id_newsletter` = '.(int) $id_newsletter.'
');
Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesNewsletter'));
} else if(Tools::isSubmit('submitTitleDimanche')) {
Configuration::updateValue('TITLE_NEWS_DIMANCHE', Tools::getValue('title'));
Configuration::updateValue('TITLE_NEWS_DIMANCHE_ES', Tools::getValue('title_es'));
Configuration::updateValue('TITLE_NEWS_LAST_DAY', Tools::getValue('title_last_day'));
Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesNewsletter'));
} else if(Tools::isSubmit('submitForwardSale')) {
$forward = Tools::getValue('sale_forward', 0);
$sales = Sale::getSales(NULL, NULL, NULL, 'not_ended', FALSE, FALSE, '`position` DESC');
foreach($sales as $sale) {
if(in_array($sale->id, $forward)) {
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'privatesale` SET
`forward_news` = 1,
`date_upd` = NOW()
WHERE `id_sale` = '.(int) $sale->id.'
');
} else {
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'privatesale` SET
`forward_news` = 0,
`date_upd` = NOW()
WHERE `id_sale` = '.(int) $sale->id.'
');
}
}
}
}
}