name = 'trackingtag'; $this->tab = 'advertising_marketing'; $this->author = 'Antadis'; $this->version = '1.0'; parent::__construct(); $this->displayName = $this->l('Tracking Tag'); $this->description = $this->l('Adds tracking tags on your shop'); $this->_html = ''; $this->_errors = array(); } public function install() { if(count(Db::getInstance()->ExecuteS(' SELECT `id_hook` FROM `'._DB_PREFIX_.'hook` WHERE `name` = "accountValidation" LIMIT 1 ')) == 0) { Db::getInstance()->ExecuteS(' INSERT INTO `'._DB_PREFIX_.'hook` VALUES (DEFAULT, "accountValidation", "Account validation", "Called when a user creates an account successfully", 0, 0) '); } $query = ' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'trackingtag` ( `id_trackingtag` INTEGER NOT NULL AUTO_INCREMENT, `date_start` DATETIME NOT NULL, `date_end` DATETIME NOT NULL, `enabled` BOOL NOT NULL, `date_upd` DATETIME NOT NULL, `name` VARCHAR(255) NOT NULL, `sponsor` VARCHAR(255), `tag` TEXT, PRIMARY KEY(`id_trackingtag`) ) ENGINE=MyIsam DEFAULT CHARSET=utf8 '; if(!Db::getInstance()->Execute($query)) { return FALSE; } if(!parent::install() || !$this->registerHook('accountValidation')) { return FALSE; } return TRUE; } public function uninstall() { Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'trackingtag`'); if(parent::uninstall() == FALSE) { return FALSE; } return TRUE; } public function getContent() { global $currentIndex; $this->curtag = NULL; if($id = (int) Tools::getValue('tid')) { $this->curtag = Db::getInstance()->getRow(' SELECT * FROM `'._DB_PREFIX_.'trackingtag` WHERE `id_trackingtag` = '.$id.' '); if(!$this->curtag) { Tools::redirectAdmin($currentIndex.'&configure=trackingtag&token='.Tools::getValue('token').'&tab_module=advertising_marketing&module_name=trackingtag'); } } $this->_html .= '
'.$this->l('Tag successfully deleted').'
'; } $this->_displayForm(); return $this->_html; } private function _postValidation() { global $cookie; if(Tools::getValue('submitTagAdd')) { if(Tools::getValue('name')) { Db::getInstance()->Execute(' INSERT INTO `'._DB_PREFIX_.'trackingtag` VALUES ( DEFAULT, "'.pSQL(Tools::getValue('date_start')).'", "'.pSQL(Tools::getValue('date_end')).'", '.(int) (bool) Tools::getValue('enabled').', NOW(), "'.pSQL(Tools::getValue('name', '')).'", "'.pSQL(Tools::getValue('sponsor', '')).'", "'.pSQL(Tools::getValue('tag', ''), TRUE).'", "'.pSQL(Tools::getValue('tag_auth', ''), TRUE).'", "'.pSQL(Tools::getValue('version', 'fr'), TRUE).'" ) '); $this->_html .= ''.$this->l('Tag added successfully').'
'; } else { $this->_errors[] = $this->l('The tag name is required'); } } elseif(Tools::getValue('submitTagUpdate')) { $id = (int) Tools::getValue('id_trackingtag', 0); if(Db::getInstance()->getRow(' SELECT * FROM `'._DB_PREFIX_.'trackingtag` WHERE `id_trackingtag` = '.(int) $id.' ')) { if(Tools::getValue('name')) { Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'trackingtag` SET `date_start` = "'.pSQL(Tools::getValue('date_start')).'", `date_end` = "'.pSQL(Tools::getValue('date_end')).'", `enabled` = '.(int) (bool) Tools::getValue('enabled').', `date_upd` = NOW(), `name` = "'.pSQL(Tools::getValue('name')).'", `sponsor` = "'.pSQL(Tools::getValue('sponsor', '')).'", `tag` = "'.pSQL(Tools::getValue('tag', ''), TRUE).'", `tag_auth` = "'.pSQL(Tools::getValue('tag_auth', ''), TRUE).'", `version` = "'.pSQL(Tools::getValue('version', 'fr'), TRUE).'" WHERE `id_trackingtag` = '.$id.' '); $this->_html .= ''.$this->l('Tag updated successfully').'
'; } else { $this->_errors[] = $this->l('The tag name is required'); } } else { $this->_errors[] = $this->l('Wrong tag ID'); } } } private function _displayForm() { global $cookie, $currentIndex; $this->_html .= ' '; $this->_html .= '