diff --git a/modules/ant_trackingtag/AdminAntTrackingTag.php b/modules/ant_trackingtag/AdminAntTrackingTag.php new file mode 100644 index 00000000..14b00598 --- /dev/null +++ b/modules/ant_trackingtag/AdminAntTrackingTag.php @@ -0,0 +1,307 @@ +_object = false; + $this->controller = 'AdminModules'; + $this->module_name = 'ant_trackingtag'; + $this->config_tab = (bool)$config_tab; + if ($config_tab) { + $this->controller = 'AdminAntTrackingTag'; + } + $this->helperForm = new HelperFormBootstrap(); + $this->helperForm->_select2 = true; + $this->helperForm->_inputSwitch = true; + } + + public function display() + { + parent::displayForm(); + + $this->_html = ''; + + $this->_postProcess(); + + $this->_addCss(); + $this->_html .= $this->helperForm->renderStyle(); + + $this->_displayForm(); + $this->_displayList(); + + $this->_html .='
'; + $this->_addJs(); + $this->_html .= $this->helperForm->renderScript(); + echo $this->_html; + } + + + protected function _addJs() + { + $this->helperForm->_js .= ''; + } + + protected function _addCss() + { + $this->helperForm->_css .=' + .table tr th { + background: #565485; + background: rgba(86,84,133,0.9); + color: #fff; + font-size: 12px; + } + .table tr:nth-child(even) { + background: #F1F1F1; + } + .table .input-group-btn .btn { + padding: 4px 5px; + color: #504d8b; + + } + .table .input-group-btn .btn .anticon{ + font-size: 12px; + } + .bg-grey{ + background: #EFEFEF; + border-radius:4px; + } + .bg-grey .div-title { + border-bottom: 2px solid #504D8B; + } + '; + } + + protected function _displayList() + { + global $cookie, $currentIndex; + + $id_lang = (int)$cookie->id_lang; + + $tags = AntTrackingTag::getTags(false); + $_current_index = ($this->config_tab ? $currentIndex . '&token=' . Tools::getAdminTokenLite($this->controller) : $_SERVER['REQUEST_URI']); + + $this->_html .=' +'.$this->l('ID').' | +'.$this->l('Name').' | +'.$this->l('tag').' | +'.$this->l('Active').' | +'.$this->l('Nb').' | +'.$this->l('Total').' | +'.$this->l('Action').' | +
---|---|---|---|---|---|---|
#'.$tag['id_trackingtag'].' | +'.$tag['name'].' | +'.$tag['tag'].' | +'.((int)$tag['enabled']?'':'').' | +'; + foreach ($customer_numbers as $info) { + $total += (int)$info['nb']; + $this->_html.=' + '; + } + $this->_html.= + ' | +'.$total.' | ++ + | +
Les balises doivent être présentes dans l\'url et sont trackées à l\'inscription
+Le nouveau client est comptabilisé avec la valeur que contient la balise.
+ Par exemple :
Ici le client sera associé au tag ed qui aura pour valeur 564.
+Le client est donc comptabilisé pour le tag ed et plus précisément pour la valeur 564 de ce tag.
+Si plusieurs tags présents, le client sera comptabilisé dans tous les tags
+ ' + ), + ), + 'actions' => array(), + 'actions-class' => 'text-right', + ) + ); + + + if (isset($trackingTag)) { + $this->helperForm->_forms[0]['sections'][0]['title'] = "Editer le tag ".$trackinTag->name; + $this->helperForm->_forms[0]['sections'][0]['inputs'][] = array( + 'type' => 'hidden', + 'name' => 'id_trackingtag', + 'value' => $trackingTag->id, + 'class' => 'large' + ); + $this->helperForm->_forms[0]['sections'][0]['actions'] = array( + array( + 'type' => 'submit', + 'class' => 'btn-default', + 'name' => 'newTag', + 'value' => $this->l('Nouveau Tag') + ), + array( + 'type' => 'submit', + 'class' => 'btn-primary', + 'name' => 'editTag', + 'value' => $this->l('Editer le Tag') + ), + ); + } else { + $this->helperForm->_forms[0]['sections'][0]['title'] = "Ajouter un tag"; + $this->helperForm->_forms[0]['sections'][0]['actions'] = array( + array( + 'type' => 'submit', + 'class' => 'btn-primary', + 'name' => 'addTag', + 'value' => $this->l('Ajouter le tag') + ), + ); + } + + $this->helperForm->renderForm(); + } +} diff --git a/modules/ant_trackingtag/ant_trackingtag.php b/modules/ant_trackingtag/ant_trackingtag.php new file mode 100644 index 00000000..f0eabe7e --- /dev/null +++ b/modules/ant_trackingtag/ant_trackingtag.php @@ -0,0 +1,129 @@ +name = 'ant_trackingtag'; + $this->tab = 'advertising_marketing'; + $this->version = '1.0'; + $this->author = 'Antadis'; + $this->need_instance = 0; + + $this->displayName = $this->l('Tracking Tag'); + $this->description = $this->l('Allows to track tags set in url'); + } + + public function install() { + + # Add tables + $query = ' + CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'ant_trackingtag` ( + `id_trackingtag` INTEGER NOT NULL AUTO_INCREMENT, + `enabled` BOOL NOT NULL, + `name` VARCHAR(255) NOT NULL, + `tag` VARCHAR(255) NOT NULL, + `date_add` DATETIME NOT NULL, + `date_upd` DATETIME NOT NULL, + PRIMARY KEY(`id_trackingtag`) + ) ENGINE=MyIsam DEFAULT CHARSET=utf8 + '; + if(!Db::getInstance()->Execute($query)) { + return false; + } + + $query = ' + CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'ant_trackingtag_customer` ( + `id_trackingtag` INTEGER NOT NULL, + `id_customer` INTEGER NOT NULL, + `value` VARCHAR(255) NOT NULL, + PRIMARY KEY(`id_trackingtag`, `id_customer`, `value`) + ) ENGINE=MyIsam DEFAULT CHARSET=utf8 + '; + if(!Db::getInstance()->Execute($query)) { + return false; + } + + # Register hooks + if(!parent::install() + || !$this->registerHook('createAccount') + || !$this->registerHook('createAccountForm') + || !$this->registerHook('PrivateSales_Block') + ) { + return false; + } + + return true; + } + + public function uninstall() { + + if(parent::uninstall() == false) { + return false; + } + + Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'ant_trackingtag`'); + Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'ant_trackingtag_customer`'); + + return true; + } + + public function hookCreateAccount($params) { + global $cookie; + + $newCustomer = $params['newCustomer']; + if(!Validate::isLoadedObject($newCustomer)) { + return false; + } + if(Tools::getValue('trackingtags')){ + $id_tags = Tools::getValue('trackingtags'); + foreach ($id_tags as $id_tag => $value) { + if(AntTrackingTag::isExistAndEnabled($id_tag)){ + Db::getInstance()->ExecuteS(' + INSERT INTO `'._DB_PREFIX_.'ant_trackingtag_customer` + VALUES ( + '.$id_tag.', + '.(int) $newCustomer->id.', + "'.pSQL($value).'" + ) + '); + } + } + } + } + + public function hookCreateAccountForm($params) { + global $smarty, $cookie; + + $tags = AntTrackingTag::getTags(); + $tracking_tags = []; + foreach ($tags as $tag) { + if($value = Tools::getValue($tag['tag'])) { + $tracking_tags[(int)$tag['id_trackingtag']] = $value; + } + } + + $smarty->assign(array( + 'tracking_tags' => $tracking_tags, + )); + return $this->display(__FILE__, 'authentication.tpl'); + } + + public function hookPrivateSales_Block($params) { + global $smarty, $cookie; + + $tags = AntTrackingTag::getTags(); + $tracking_tags = []; + foreach ($tags as $tag) { + if($value = Tools::getValue($tag['tag'])) { + $tracking_tags[(int)$tag['id_trackingtag']] = $value; + } + } + + $smarty->assign(array( + 'tracking_tags' => $tracking_tags, + )); + } +} diff --git a/modules/ant_trackingtag/authentication.tpl b/modules/ant_trackingtag/authentication.tpl new file mode 100644 index 00000000..a94bcefc --- /dev/null +++ b/modules/ant_trackingtag/authentication.tpl @@ -0,0 +1,7 @@ + \ No newline at end of file diff --git a/modules/ant_trackingtag/models/AntTrackingTag.php b/modules/ant_trackingtag/models/AntTrackingTag.php new file mode 100644 index 00000000..70aa4dd1 --- /dev/null +++ b/modules/ant_trackingtag/models/AntTrackingTag.php @@ -0,0 +1,116 @@ + 'isUnsignedId', + 'enabled' => 'isBool', + 'name' => 'isString', + 'tag' => 'isString', + 'date_add' => 'isDate', + 'date_upd' => 'isDate', + ); + + protected $table = 'ant_trackingtag'; + protected $identifier = 'id_trackingtag'; + + + public function getFields() + { + parent::validateFields(); + + $fields['id_trackingtag'] = (int)$this->id_trackingtag; + $fields['enabled'] = (int)$this->enabled; + $fields['name'] = pSQL($this->name); + $fields['tag'] = pSQL($this->tag); + $fields['date_add'] = pSQL($this->date_add); + $fields['date_upd'] = pSQL($this->date_upd); + + return $fields; + } + + public function delete() + { + return true; + } + + /** + * Get demands + * @param $states array get only demands in specific states + * @return Array Groups + */ + public static function getTags($enabled = true, $where = false) + { + if($where){ + return Db::getInstance()->executeS(' + SELECT * + FROM `'._DB_PREFIX_.'ant_trackingtag` tt + WHERE '.$where.' + '.($enabled ? ' AND tt.`enabled` = 1' : '').' + '); + } else { + return Db::getInstance()->executeS(' + SELECT * + FROM `'._DB_PREFIX_.'ant_trackingtag` tt + WHERE 1 + '.($enabled ? ' AND tt.`enabled` = 1' : '').' + '); + } + } + + public function save($nullValues = false, $autodate = true) + { + if (parent::save($nullValues,$autodate)) { + return true; + } + } + + public static function getTagByName($name) + { + return Db::getInstance()->getValue(" + SELECT `id_trackingtag` + FROM `"._DB_PREFIX_."ant_trackingtag` + WHERE `name` = " .pSQL($name) + ); + } + + public static function isExistAndEnabled($id_trackingtag) + { + return Db::getInstance()->getValue(" + SELECT `id_trackingtag` + FROM `"._DB_PREFIX_."ant_trackingtag` + WHERE `id_trackingtag` = " .pSQL($id_trackingtag)." + AND `enabled`=1" + ); + } + + public static function getCountCustomerByTag($id_trackingtag) + { + return Db::getInstance()->ExecuteS(" + SELECT COUNT(id_customer) as `nb`, `value` + FROM `"._DB_PREFIX_."ant_trackingtag_customer` + WHERE `id_trackingtag` = " . (int)$id_trackingtag." + GROUP BY `value`" + ); + } + + public static function getCustomer($id_trackingtag) + { + return Db::getInstance()->ExecuteS(" + SELECT c.* + FROM `" . _DB_PREFIX_ . "customer` c + LEFT JOIN `" . _DB_PREFIX_ . "ant_trackingtag_customer` t ON (t.id_customer = c.id_customer) + WHERE sd.`id_trackingtag` = " . (int)$id_trackingtag + ); + } +} + diff --git a/modules/invite/sponsor.php b/modules/invite/sponsor.php index ecb86f36..05cdebe5 100644 --- a/modules/invite/sponsor.php +++ b/modules/invite/sponsor.php @@ -4,35 +4,47 @@ include(dirname(__FILE__).'/../../init.php'); if(($sponsor = Tools::getValue('sponsor')) && strlen($sponsor) > 12) { - setcookie('554b43403edef30d31412286d5098965', $sponsor, time() + 3600 * 24 * 365, '/', '.bebeboutik.com'); + setcookie('554b43403edef30d31412286d5098965', $sponsor, time() + 3600 * 24 * 365, '/', '.bebeboutik.com'); - $email = base64_decode(strrev(substr($sponsor, 12))); - if(count(Db::getInstance()->ExecuteS(' - SELECT `id_customer` - FROM `'._DB_PREFIX_.'customer` - WHERE `email` = "'.pSQL($email).'" - ')) > 0) { - if(Configuration::get('PS_CIPHER_ALGORITHM')) { - $cipherTool = new Rijndael(_RIJNDAEL_KEY_, _RIJNDAEL_IV_); - } else { - $cipherTool = new Blowfish(_COOKIE_KEY_, _COOKIE_IV_); - } + $email = base64_decode(strrev(substr($sponsor, 12))); + if(count(Db::getInstance()->ExecuteS(' + SELECT `id_customer` + FROM `'._DB_PREFIX_.'customer` + WHERE `email` = "'.pSQL($email).'" + ')) > 0) { + if(Configuration::get('PS_CIPHER_ALGORITHM')) { + $cipherTool = new Rijndael(_RIJNDAEL_KEY_, _RIJNDAEL_IV_); + } else { + $cipherTool = new Blowfish(_COOKIE_KEY_, _COOKIE_IV_); + } - $url = parse_url($_SERVER['REQUEST_URI']); - $gclid = Tools::getIsset('gclid')?'&gclid='.Tools::getValue('gclid'):''; - if(Tools::getIsset('lpes')) { - $lp = Tools::getValue('lpes'); - if( _THEME_NAME_ !== 'site_mobile') { - Tools::redirect('?sponsor='.rawurlencode($cipherTool->encrypt('1|'.$email.'|')).(isset($lp)? '&lpes='.$lp: '').$gclid); - } - } + $url = parse_url($_SERVER['REQUEST_URI']); + $gclid = Tools::getIsset('gclid')?'&gclid='.Tools::getValue('gclid'):''; + if(Tools::getIsset('lpes')) { + $lp = Tools::getValue('lpes'); + if( _THEME_NAME_ !== 'site_mobile') { + Tools::redirect('?sponsor='.rawurlencode($cipherTool->encrypt('1|'.$email.'|')).(isset($lp)? '&lpes='.$lp: '').$gclid); + } + } - if(Tools::getIsset('lp')) { - $lp = Tools::getValue('lp'); - } - Tools::redirectLink($link->getPageLink('authentication.php').'?create_account=1&sponsor='.rawurlencode($cipherTool->encrypt('1|'.$email.'|')).(isset($url['query'])? '&'.$url['query']: '').(isset($lp)? '&lp='.$lp: '').$gclid); - // Tools::redirectLink($link->getPageLink('authentication.php').'?create_account=1&sponsor='.rawurlencode($cipherTool->encrypt('1|'.$email.'|')).(isset($url['query'])? '&'.$url['query']: '')); - } + if(Tools::getIsset('lp')) { + $lp = Tools::getValue('lp'); + } + + if(!class_exists('AntTrackingTag')){ + include_once(_PS_MODULE_DIR_.'/ant_trackingtag/models/AntTrackingTag.php'); + } + $tags = AntTrackingTag::getTags(); + $url_tag =''; + foreach ($tags as $tag) { + if(Tools::getIsset($tag['tag'])) { + $value = Tools::getValue($tag['tag']); + $url_tag .='&'.$tag['tag'].'='.$value; + } + } + Tools::redirectLink($link->getPageLink('authentication.php').'?create_account=1&sponsor='.rawurlencode($cipherTool->encrypt('1|'.$email.'|')).(isset($url['query'])? '&'.$url['query']: '').(isset($lp)? '&lp='.$lp: '').$url_tag.$gclid); + // Tools::redirectLink($link->getPageLink('authentication.php').'?create_account=1&sponsor='.rawurlencode($cipherTool->encrypt('1|'.$email.'|')).(isset($url['query'])? '&'.$url['query']: '')); + } } Tools::redirect(); diff --git a/modules/landingpages/home_footer.tpl b/modules/landingpages/home_footer.tpl index 3c000f08..040b8d89 100644 --- a/modules/landingpages/home_footer.tpl +++ b/modules/landingpages/home_footer.tpl @@ -40,6 +40,14 @@ }); + +