lang = TRUE;
parent::__construct();
}
public function postProcess() {
global $cookie, $currentIndex;
if(Tools::isSubmit('submitLPAdd')) {
if($name = Tools::getValue('name')) {
if(Db::getInstance()->getRow('
SELECT `id_landing_page`
FROM `'._DB_PREFIX_.'landing_page`
WHERE `name` = "'.pSQL(Tools::str2url($name)).'"
')) {
$this->_errors[] = $this->l('A landing page with this name already exists.');
} else {
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'landing_page`
VALUES (
DEFAULT,
'.(int) (bool) Tools::getValue('enabled').',
'.(int) (bool) Tools::getValue('connect_button').',
'.(int) (bool) Tools::getValue('on_home').',
"'.pSQL(Tools::str2url($name)).'",
"'.pSQL(Tools::getValue('text1')).'",
"'.pSQL(Tools::getValue('text2')).'",
"'.pSQL(Tools::getValue('tag')).'"
)
');
$id_landing_page = Db::getInstance()->Insert_ID();
foreach(Language::getLanguages(FALSE) as $language) {
if(isset($_FILES['img1_'.$language['id_lang']]) && $_FILES['img1_'.$language['id_lang']]['name'] != '') {
if(!copy($_FILES['img1_'.$language['id_lang']]['tmp_name'], _PS_ROOT_DIR_.'/modules/landingpages/img/'.$id_landing_page.'_1_'.$language['id_lang'].'.jpg')) {
$this->_errors[] = $this->l('An error occured during the image upload.');
}
}
if(isset($_FILES['img2_'.$language['id_lang']]) && $_FILES['img2_'.$language['id_lang']]['name'] != '') {
if(!copy($_FILES['img2_'.$language['id_lang']]['tmp_name'], _PS_ROOT_DIR_.'/modules/landingpages/img/'.$id_landing_page.'_2_'.$language['id_lang'].'.png')) {
$this->_errors[] = $this->l('An error occured during the image upload.');
}
}
}
echo '
'.$this->l('Page added successfully').'
';
}
} else {
$this->_errors[] = $this->l('A landing page name is required.');
}
} elseif(Tools::isSubmit('submitLPUpdate') && $id_landing_page = (int) Tools::getValue('id_lp')) {
$this->curlp = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'landing_page`
WHERE `id_landing_page` = '.$id_landing_page.'
');
if(!$this->curlp) {
Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminLandingPage'));
}
if($name = Tools::getValue('name')) {
if(Db::getInstance()->getRow('
SELECT `id_landing_page`
FROM `'._DB_PREFIX_.'landing_page`
WHERE `name` = "'.pSQL(Tools::str2url($name)).'"
AND `id_landing_page` != '.$id_landing_page.'
')) {
$this->_errors[] = $this->l('A landing page with this name already exists.');
} else {
Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'landing_page`
SET `enabled` = '.(int) (bool) Tools::getValue('enabled').',
`connect_button` = '.(int) (bool) Tools::getValue('connect_button').',
`on_home` = '.(int) (bool) Tools::getValue('on_home').',
`name` = "'.pSQL(Tools::str2url($name)).'",
`text1` = "'.pSQL(Tools::getValue('text1')).'",
`text2` = "'.pSQL(Tools::getValue('text2')).'",
`tag` = "'.pSQL(Tools::getValue('tag'), true).'"
WHERE `id_landing_page` = '.$id_landing_page.'
');
foreach(Language::getLanguages(FALSE) as $language) {
if(isset($_FILES['img1_'.$language['id_lang']]) && $_FILES['img1_'.$language['id_lang']]['name'] != '') {
if(!copy($_FILES['img1_'.$language['id_lang']]['tmp_name'], _PS_ROOT_DIR_.'/modules/landingpages/img/'.$id_landing_page.'_1_'.$language['id_lang'].'.jpg')) {
$this->_errors[] = $this->l('An error occured during the image upload.');
}
}
if(isset($_FILES['img2_'.$language['id_lang']]) && $_FILES['img2_'.$language['id_lang']]['name'] != '') {
if(!copy($_FILES['img2_'.$language['id_lang']]['tmp_name'], _PS_ROOT_DIR_.'/modules/landingpages/img/'.$id_landing_page.'_2_'.$language['id_lang'].'.png')) {
$this->_errors[] = $this->l('An error occured during the image upload.');
}
}
}
echo ''.$this->l('Page updated successfully').'
';
}
} else {
$this->_errors[] = $this->l('A landing page name is required.');
}
}
}
public function display() {
global $cookie, $currentIndex;
$this->curlp = FALSE;
if(isset($_GET['edit_lp']) && $id_landing_page = (int) Tools::getValue('id_lp')) {
$this->curlp = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'landing_page`
WHERE `id_landing_page` = '.$id_landing_page.'
');
if(!$this->curlp) {
Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminLandingPage'));
}
}
$this->displayForm();
$pages = Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'landing_page`
ORDER BY `id_landing_page` ASC
');
$counts = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_landing_page`, COUNT(c.id_customer) AS `count`
FROM `'._DB_PREFIX_.'landing_page_customer` c
GROUP BY `id_landing_page`;
') as $count) {
$counts[$count['id_landing_page']] = $count['count'];
}
echo '
';
}
public function displayForm($isMainTab=TRUE) {
global $currentIndex, $cookie;
parent::displayForm();
$iso = Language::getIsoById((int)($cookie->id_lang));
$divLangName = 'img1¤img2';
echo '
';
}
}