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 '
'.$this->l('Landing pages list').' '; foreach($pages as $page) { echo ''; } echo '
'.$this->l('ID').' '.$this->l('Name').' '.$this->l('URL chunk').' '.$this->l('Customers').' '.$this->l('Enabled').' '.$this->l('Connect').' '.$this->l('Home').' '.$this->l('Actions').'
'.$page['id_landing_page'].' '.$page['name'].' '.($page['on_home']?'https://'.$_SERVER['SERVER_NAME'].'?lpes='.$page['name']:'https://'.$_SERVER['SERVER_NAME'].'/authentification?create_account=1&lp='.$page['name']).' '.(isset($counts[$page['id_landing_page']])? $counts[$page['id_landing_page']]: '0').' '.($page['enabled']? $this->l('Yes'): $this->l('No')).' '.($page['connect_button']? $this->l('Yes'): $this->l('No')).' '.($page['on_home']? $this->l('Yes'): $this->l('No')).'
'; } public function displayForm($isMainTab=TRUE) { global $currentIndex, $cookie; parent::displayForm(); $iso = Language::getIsoById((int)($cookie->id_lang)); $divLangName = 'img1¤img2'; echo '
'.$this->l('Edit a landing page').''; echo '
*
'; echo '
curlp? ($this->curlp['enabled'] == 0? ' checked="checked"': ''):' checked="checked"').' /> '.$this->l('No').'   curlp && $this->curlp['enabled'] == 1? ' checked="checked"': '').' /> '.$this->l('Yes').' *
'; echo '
curlp? ($this->curlp['connect_button'] == 0? ' checked="checked"': ''):' checked="checked"').' /> '.$this->l('No').'   curlp && $this->curlp['connect_button'] == 1? ' checked="checked"': '').' /> '.$this->l('Yes').' *
'; echo '
curlp? ($this->curlp['on_home'] == 0? ' checked="checked"': ''):' checked="checked"').' /> '.$this->l('No').'   curlp && $this->curlp['on_home'] == 1? ' checked="checked"': '').' /> '.$this->l('Yes').' *
'; echo '
'; echo '
'; echo '
'; echo '
'; foreach($this->_languages as $language) { echo '

'.$this->l('Size:').' '.$this->l('img1 size').'

'; if($this->curlp && file_exists(_PS_ROOT_DIR_.'/modules/landingpages/img/'.$this->curlp['id_landing_page'].'_1_'.$language['id_lang'].'.jpg')) { echo '

'.$this->l('Preview').'

'; } echo '
'; } $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'img1'); echo '
'; echo ' '; echo '
curlp? '': ' disabled="disabled"').' id="submitLPUpdate" />
'; echo '
'; } }