name = 'privatesales_newsletter'; $this->tab = 'pricing_promotion'; $this->author = 'Antadis'; $this->version = '1.0'; parent::__construct(); $this->displayName = $this->l('Private Sales Newsletter'); $this->description = $this->l('Allows to create content for newsletters'); } public function install() { if(!Module::isInstalled('privatesales')) { return FALSE; } # Install admin tab $id_mod = Db::getInstance()->ExecuteS(' SELECT `id_tab` FROM `'._DB_PREFIX_.'tab` WHERE `class_name` = "AdminPrivateSales" '); if(count($id_mod) == 0) { return FALSE; } $id_mod = $id_mod[0]['id_tab']; $posmax = Db::getInstance()->ExecuteS('SELECT MAX(`position`) + 1 AS `max` FROM `'._DB_PREFIX_.'tab` WHERE `id_parent` = '.$id_mod); $posmax = $posmax[0]['max']; Db::getInstance()->Execute(' INSERT INTO `'._DB_PREFIX_.'tab` VALUES ( DEFAULT, '.$id_mod.', "AdminPrivateSalesNewsletter", "privatesales_newsletter", '.$posmax.' ) '); $tab_id = Db::getInstance()->Insert_ID(); Db::getInstance()->Execute(' INSERT INTO `'._DB_PREFIX_.'access` VALUES (1, '.$tab_id.', 1, 1, 1, 1) '); $tabs_i18n = array( 'fr' => 'Newsletter', 'en' => 'Newsletter', ); $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 newsletter table $query = ' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesale_newsletter` ( `id_newsletter` INTEGER NOT NULL AUTO_INCREMENT, `title` VARCHAR(255) NOT NULL, `image_url` VARCHAR(255) NOT NULL, `date_pub` DATE NOT NULL, PRIMARY KEY(`id_newsletter`) ) ENGINE=MyIsam DEFAULT CHARSET=utf8 '; if(!Db::getInstance()->Execute($query)) { return FALSE; } # Register hooks if(!parent::install()) { return FALSE; } Db::getInstance()->Execute(' INSERT INTO `'._DB_PREFIX_.'privatesale_module` VALUES ( (SELECT `id_module` FROM `'._DB_PREFIX_.'module` WHERE `name` = "privatesales_newsletter"), "privatesales_newsletter" ) '); // if(!$this->registerHook('privatesales_create') // OR !$this->registerHook('privatesales_update') // OR !$this->registerHook('privatesales_delete') // OR !$this->registerHook('privatesales_edit')) { // return FALSE; // } return TRUE; } function uninstall() { $tab = Db::getInstance()->Execute(' SELECT `id_tab` FROM `'._DB_PREFIX_.'tab` WHERE `module` = "privatesales_newsletter" '); if(count($tab) == 0) { return FALSE; } $tab = $tab[0]; 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_newsletter" '); Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'tab` SET `position` = `position` - 1 WHERE `id_parent` = '.$tab['id_parent'].' AND `position` > '.$tab['position'] ); if(parent::uninstall() == FALSE) { return FALSE; } Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'privatesales_newsletter`'); Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'privatesale_module` WHERE `modulename` = "privatesales_newsletter"'); return TRUE; } }