name = 'landingpages'; $this->tab = 'advertising_marketing'; $this->version = '1.0'; $this->author = 'Antadis'; $this->need_instance = 0; $this->displayName = $this->l('Landing Pages'); $this->description = $this->l('Landing pages management for Prestashop'); } public function install() { # Install admin tab $tab = Db::getInstance()->getRow(' SELECT `id_tab` FROM `'._DB_PREFIX_.'tab` WHERE `class_name` = "AdminCustomers" '); Db::getInstance()->ExecuteS(' INSERT INTO `'._DB_PREFIX_.'tab` VALUES (DEFAULT, '.(int) $tab['id_tab'].', "AdminLandingPages", "landingpages", 5) '); $tab_id = Db::getInstance()->Insert_ID(); Db::getInstance()->ExecuteS(' INSERT INTO `'._DB_PREFIX_.'access` VALUES (1, '.$tab_id.', 1, 1, 1, 1) '); foreach(Db::getInstance()->ExecuteS(' SELECT `id_profile` FROM `'._DB_PREFIX_.'profile` WHERE `id_profile` > 1 ') as $profile) { Db::getInstance()->ExecuteS(' INSERT INTO `'._DB_PREFIX_.'access` VALUES ('.$profile['id_profile'].', '.$tab_id.', 0, 0, 0, 0) '); } $tabs_i18n = array( 'fr' => 'Landing pages', 'en' => 'Landing pages', ); $langs = Db::getInstance()->ExecuteS(' SELECT `id_lang`, `iso_code` FROM `'._DB_PREFIX_.'lang` '); foreach($langs as $lang) { if(isset($tabs_i18n[$lang['iso_code']])) { Db::getInstance()->Execute(' INSERT INTO `'._DB_PREFIX_.'tab_lang` VALUES ('.$tab_id.', '.$lang['id_lang'].', "'.$tabs_i18n[$lang['iso_code']].'") '); } else { Db::getInstance()->Execute(' INSERT INTO `'._DB_PREFIX_.'tab_lang` VALUES ('.$tab_id.', '.$lang['id_lang'].', "'.$tabs_i18n['en'].'") '); } } # Add tables $query = ' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'landing_page` ( `id_landing_page` INTEGER NOT NULL AUTO_INCREMENT, `enabled` BOOL NOT NULL, `connect_button` BOOL NOT NULL, `name` VARCHAR(255) NOT NULL, `text1` VARCHAR(255) NOT NULL, `text2` VARCHAR(255) NOT NULL, PRIMARY KEY(`id_landing_page`) ) ENGINE=MyIsam DEFAULT CHARSET=utf8 '; if(!Db::getInstance()->Execute($query)) { return FALSE; } $query = ' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'landing_page_customer` ( `id_landing_page` INTEGER NOT NULL, `id_customer` INTEGER NOT NULL, PRIMARY KEY(`id_landing_page`, `id_customer`) ) ENGINE=MyIsam DEFAULT CHARSET=utf8 '; if(!Db::getInstance()->Execute($query)) { return FALSE; } # Register hooks if(!parent::install() || !$this->registerHook('adminCustomers') || !$this->registerHook('createAccountForm') || !$this->registerHook('createAccountFormBottom') || !$this->registerHook('createAccount')) { return FALSE; } return TRUE; } public function uninstall() { $tab = Db::getInstance()->getRow(' SELECT `id_tab` FROM `'._DB_PREFIX_.'tab` WHERE `module` = "landingpages" '); Db::getInstance()->Execute(' DELETE FROM `'._DB_PREFIX_.'tab_lang` WHERE `id_tab` = '.$tab['id_tab'] ); Db::getInstance()->Execute(' DELETE FROM `'._DB_PREFIX_.'access` WHERE `id_tab` = '.$tab['id_tab'] ); Db::getInstance()->Execute(' DELETE FROM `'._DB_PREFIX_.'tab` WHERE `module` = "privatesales" '); if(parent::uninstall() == FALSE) { return FALSE; } Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'landing_page`'); Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'landing_page_customer`'); $files = glob(dirname(__FILE__).'/img/*'); foreach($files as $file) { unlink($file); } return TRUE; } public function hookCreateAccount($params) { global $cookie; $newCustomer = $params['newCustomer']; if(!Validate::isLoadedObject($newCustomer)) { return FALSE; } if($name = Tools::getValue('lp')) { if($landing = Db::getInstance()->getRow(' SELECT `id_landing_page` FROM `'._DB_PREFIX_.'landing_page` WHERE `enabled` = 1 AND `name` = "'.pSQL($name).'" ')) { $id_landing_page = (int) $landing['id_landing_page']; Db::getInstance()->ExecuteS(' INSERT INTO `'._DB_PREFIX_.'landing_page_customer` VALUES ( '.$id_landing_page.', '.(int) $newCustomer->id.' ) '); } } } public function hookAdminCustomers($params) { global $cookie; $customer = new Customer((int) $params['id_customer']); if (!Validate::isLoadedObject($customer)) die (Tools::displayError('Incorrect object Customer.')); if($landing_page = Db::getInstance()->getRow(' SELECT l.`id_landing_page`, l.`name` FROM `'._DB_PREFIX_.'landing_page` l, `'._DB_PREFIX_.'landing_page_customer` c WHERE c.`id_customer` = '.(int) $customer->id.' AND l.`id_landing_page` = c.`id_landing_page` ')) { echo '
 

'.$this->l('Lead source').'

'.$this->l('Landing page:').' '.$landing_page['name'].'
'; } } public function hookCreateAccountForm($params) { global $smarty, $cookie; $id_landing_page = 0; $lp_text1 = ''; $lp_text2 = ''; if($name = Tools::getValue('lp')) { if($landing = Db::getInstance()->getRow(' SELECT * FROM `'._DB_PREFIX_.'landing_page` WHERE `enabled` = 1 AND `name` = "'.pSQL($name).'" ')) { $id_landing_page = $landing['id_landing_page']; $lp_text1 = $landing['text1']; $lp_text2 = $landing['text2']; $tag = $landing['tag']; } } if($id_landing_page > 0) { if (file_exists(_PS_ROOT_DIR_.'/modules/landingpages/img/'.$id_landing_page.'_1_'.$cookie->id_lang.'.jpg')) { $smarty->assign(array( 'landing' => 1, )); } else { $smarty->assign(array( 'landing' => 0, )); } $smarty->assign(array( 'id_lp' => $id_landing_page, 'tag' => $tag, 'lp_text1' => $lp_text1, 'lp_text2' => $lp_text2, )); return $this->display(__FILE__, 'authentication.tpl'); } } public function hookCreateAccountFormBottom($params) { global $smarty, $cookie; $connect_button = 0; if($name = Tools::getValue('lp')) { if($landing = Db::getInstance()->getRow(' SELECT `connect_button` FROM `'._DB_PREFIX_.'landing_page` WHERE `enabled` = 1 AND `name` = "'.pSQL($name).'" ')) { $connect_button = $landing['connect_button']; } } $smarty->assign(array( 'connect_button' => $connect_button, )); return $this->display(__FILE__, 'authentication_bottom.tpl'); } public function hookPrivateSales_Block($params) { global $smarty, $cookie; $connect_button = 0; $on_home = 0; $lp = Tools::getValue('lpes'); if($lp && _PS_MOBILE_ && _THEME_NAME_ == 'site_mobile') { $link = new Link(); Tools::redirectLink($link->getPageLink('authentication.php').'?create_account=1'.(isset($lp)? '&lp='.$lp: '')); } if($lp) { if($landing = Db::getInstance()->getRow(' SELECT `on_home`,`connect_button` FROM `'._DB_PREFIX_.'landing_page` WHERE `enabled` = 1 AND `name` = "'.pSQL($lp).'" ')) { $connect_button = $landing['connect_button']; $on_home = (int)$landing['on_home']; } } if(!$on_home){ return; } $smarty->assign(array( 'connect_button' => $connect_button, 'lp' => $lp, 'HOOK_CREATE_ACCOUNT_FORM' => Module::hookExec('createAccountForm'), 'HOOK_CREATE_ACCOUNT_TOP' => Module::hookExec('createAccountTop') )); $smarty->assign('newsletter', (int)Module::getInstanceByName('blocknewsletter')->active); return $this->display(__FILE__, 'home_footer.tpl'); } }