diff --git a/modules/invite/invite.php b/modules/invite/invite.php index 94f88379..250b2a07 100644 --- a/modules/invite/invite.php +++ b/modules/invite/invite.php @@ -2,7 +2,8 @@ if (!defined('_PS_VERSION_')) exit; -class Invite extends Module { +class Invite extends Module +{ public function __construct() { $this->name = 'invite'; $this->tab = 'advertising_marketing'; @@ -1127,41 +1128,37 @@ RewriteRule ^invite/(.*)$ '.__PS_BASE_URI__.'modules/invite/sponsor.php?sponsor= return $this->hookCustomerAccount($params); } - public function hookCreateAccountForm($params) { + public function hookCreateAccountForm($params) + { global $smarty, $site_version_front; - - if($firstname = Tools::getValue('firstname')) { + + if ($firstname = Tools::getValue('firstname')) { $_POST['firstname'] = $firstname; } - if($lastname = Tools::getValue('lastname')) { + if ($lastname = Tools::getValue('lastname')) { $_POST['lastname'] = $lastname; } - if($email = Tools::getValue('email')) { + if ($email = Tools::getValue('email')) { $_POST['email'] = $email; } - if(Configuration::get('PS_CIPHER_ALGORITHM')) { + if (Configuration::get('PS_CIPHER_ALGORITHM')) { $cipherTool = new Rijndael(_RIJNDAEL_KEY_, _RIJNDAEL_IV_); } else { $cipherTool = new Blowfish(_COOKIE_KEY_, _COOKIE_IV_); } + $explodeResult = explode('|', $cipherTool->decrypt(rawurldecode(Tools::getValue('sponsor')))); - - if($explodeResult - && count($explodeResult) > 1) { - list($id_invite, $email) = $explodeResult; + if ($explodeResult && count($explodeResult) > 1) { + + list($id_invite, $email) = $explodeResult; $customer = new Customer(); - if((int) $id_invite - && !empty($email) - && Validate::isEmail($email) - && ($customer = $customer->getByEmail($email)) - && Validate::isLoadedObject($customer)) { - $smarty->assign(array( - 'sponsor_email' => $email, - )); + if ((int) $id_invite && !empty($email) && Validate::isEmail($email) + && ($customer = $customer->getByEmail($email)) + && Validate::isLoadedObject($customer)) { if(Module::isInstalled('trackingtag') && Db::getInstance()->getRow(' SELECT `id_trackingtag` @@ -1171,7 +1168,7 @@ RewriteRule ^invite/(.*)$ '.__PS_BASE_URI__.'modules/invite/sponsor.php?sponsor= AND `enabled` = 1 ')) { $smarty->assign(array( - 'hide_sponsor' => TRUE, + 'hide_sponsor' => true, )); //get tracking info @@ -1189,7 +1186,6 @@ RewriteRule ^invite/(.*)$ '.__PS_BASE_URI__.'modules/invite/sponsor.php?sponsor= 'tag_auth' => $tr_infos['tag_auth'], )); } - } if($c = Db::getInstance()->getRow(' @@ -1202,23 +1198,23 @@ RewriteRule ^invite/(.*)$ '.__PS_BASE_URI__.'modules/invite/sponsor.php?sponsor= } } } - - if(isset($_COOKIE['4598484FDSFDSREFERAL8849FDS'])){ - $referal_email = base64_decode($_COOKIE['4598484FDSFDSREFERAL8849FDS']); - $smarty->assign('sponsor_email', $referal_email); - } else { - if (isset($customer)) { - setcookie('4598484FDSFDSREFERAL8849FDS', base64_encode($customer->email), time() + 3600 * 24, '/', 'bebeboutik.com'); - } + + // Cookie + $referal_email = ''; + $cName = '4598484FDSFDSREFERAL8849FDS'; + if (Validate::isLoadedObject($customer)) { + $referal_email = $customer->email; + } elseif (isset($_COOKIE[$cName])) { + $referal_email = base64_decode($_COOKIE[$cName]); } - // setcookie('554b43403edef30d31412286d5098965', $sponsor, time() + 3600 * 24, '/', 'bebeboutik.com'); - - // if(isset($_COOKIE['554b43403edef30d31412286d5098965'])){ - // $sponsor = $_COOKIE['554b43403edef30d31412286d5098965']; - // $email = base64_decode(strrev(substr($sponsor, 12))); - // $smarty->assign('referralprogram', $email); - // } - + // Init cookie + if ($_COOKIE[$cName] != base64_encode($referal_email)) { + unset($_COOKIE[$cName]); + } + setcookie($cName, base64_encode($referal_email), time() + 3600 * 24, '/', 'bebeboutik.com'); + + $smarty->assign('sponsor_email', $referal_email); + return $this->display(__FILE__, 'authentication.tpl'); } @@ -1524,7 +1520,8 @@ RewriteRule ^invite/(.*)$ '.__PS_BASE_URI__.'modules/invite/sponsor.php?sponsor= return $discount; } - public function hookUpdateOrderStatus($params) { + public function hookUpdateOrderStatus($params) + { if(!Validate::isLoadedObject($params['newOrderStatus'])) { die (Tools::displayError('Missing parameters')); } @@ -1565,7 +1562,8 @@ RewriteRule ^invite/(.*)$ '.__PS_BASE_URI__.'modules/invite/sponsor.php?sponsor= return FALSE; } - public function hookCreateAccount($params) { + public function hookCreateAccount($params) + { global $cookie; $newCustomer = $params['newCustomer']; @@ -1585,15 +1583,16 @@ RewriteRule ^invite/(.*)$ '.__PS_BASE_URI__.'modules/invite/sponsor.php?sponsor= } $sponsor = new Customer(); - if($sponsor = $sponsor->getByEmail($sponsorEmail)) { + // Looks for sponsor exist as a customer + if ($sponsor = $sponsor->getByEmail($sponsorEmail)) { $invite = Db::getInstance()->ExecuteS(' SELECT * FROM `'._DB_PREFIX_.'invite` WHERE `email` = "'.pSQL($newCustomer->email).'" '); + // The new customer was not invited by the sponsor, so we force to create invite dynamically if(count($invite) == 0) { - // If the customer was not invited by the sponsor, we create the invitation dynamically Db::getInstance()->ExecuteS(' INSERT INTO `'._DB_PREFIX_.'invite` VALUES ( @@ -1617,7 +1616,9 @@ RewriteRule ^invite/(.*)$ '.__PS_BASE_URI__.'modules/invite/sponsor.php?sponsor= FROM `'._DB_PREFIX_.'invite` WHERE `email` = "'.pSQL($newCustomer->email).'" '); - } else { + } + // Associate sponsor with the new customer + else { Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'invite` SET `id_customer` = '.$newCustomer->id.' , `date_upd` = NOW() @@ -1629,20 +1630,21 @@ RewriteRule ^invite/(.*)$ '.__PS_BASE_URI__.'modules/invite/sponsor.php?sponsor= $invite = $invite[0]; if(Configuration::get('INVITE_REWARD_SPONSOR_ON') == 0) { - $this->_make_rewards($sponsor, FALSE, $invite); + $this->_make_rewards($sponsor, false, $invite); } if(Configuration::get('INVITE_REWARD_SPONSORED_ON') == 0) { - $this->_make_rewards($newCustomer, TRUE, $invite); + $this->_make_rewards($newCustomer, true, $invite); } - return TRUE; + return true; } - return FALSE; + return false; } - public function hookShoppingCart($params) { + public function hookShoppingCart($params) + { global $cookie, $cart, $smarty; if($cookie->isLogged() && $cart->getOrderTotal() > 0) { diff --git a/modules/invite/sponsor.php b/modules/invite/sponsor.php index e42842db..31683c5c 100644 --- a/modules/invite/sponsor.php +++ b/modules/invite/sponsor.php @@ -4,14 +4,18 @@ include(dirname(__FILE__).'/../../init.php'); if(($sponsor = Tools::getValue('sponsor')) && strlen($sponsor) > 12) { - setcookie('554b43403edef30d31412286d5098965', $sponsor, time() + 3600 * 24 * 365, '/', '.bebeboutik.com'); + $cName = '554b43403edef30d31412286d5098965'; + if ($_COOKIE[$cName] != $sponsor) { + unset($_COOKIE[$cName]); + } + setcookie($cName, $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) { + + $isExist = Db::getInstance()->ExecuteS(' + SELECT `id_customer` FROM `'._DB_PREFIX_.'customer` + WHERE `email` = "'.pSQL($email).'"'); + if(count($isExist) > 0) { if(Configuration::get('PS_CIPHER_ALGORITHM')) { $cipherTool = new Rijndael(_RIJNDAEL_KEY_, _RIJNDAEL_IV_); } else { @@ -40,16 +44,20 @@ if(($sponsor = Tools::getValue('sponsor')) && strlen($sponsor) > 12) { 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: '').$url_tag.$gclid); + Tools::redirect('?sponsor='.rawurlencode($cipherTool->encrypt('1|'.$email.'|')). + (isset($lp)? '&lpes='.$lp: '').$url_tag.$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: '').$url_tag.$gclid); - // Tools::redirectLink($link->getPageLink('authentication.php').'?create_account=1&sponsor='.rawurlencode($cipherTool->encrypt('1|'.$email.'|')).(isset($url['query'])? '&'.$url['query']: '')); + + 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); + } }