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 '