388 lines
15 KiB
PHP
388 lines
15 KiB
PHP
<?php
|
|
$useSSL = TRUE;
|
|
require_once(dirname(__FILE__).'/../../config/config.inc.php');
|
|
require_once(dirname(__FILE__).'/../../init.php');
|
|
$controller->preProcess();
|
|
|
|
if (!$cookie->isLogged())
|
|
Tools::redirect('authentication.php?back=modules/invite/invite-program.php');
|
|
|
|
include_once(dirname(__FILE__).'/invite.php');
|
|
Tools::addJS(_PS_JS_DIR_.'jquery/jquery.idTabs.modified.js');
|
|
include(dirname(__FILE__).'/../../header.php');
|
|
|
|
$invite = new Invite();
|
|
|
|
$activeTab = 'credit';
|
|
$error = FALSE;
|
|
$revive_sent = FALSE;
|
|
$mails_exists = array();
|
|
$orderQuantity = Configuration::get('INVITE_ORDER_QTY');
|
|
$canSendInvitations = FALSE;
|
|
$askName = (int) Configuration::get('INVITE_ASK_NAME');
|
|
|
|
$customer = new Customer((int) $cookie->id_customer);
|
|
$groups = $customer->getGroups();
|
|
$stats = $customer->getStats();
|
|
if((int) $stats['nb_orders'] >= $orderQuantity) {
|
|
$canSendInvitations = TRUE;
|
|
}
|
|
|
|
if(Configuration::get('INVITE_FORM_LINKFORMAT')) {
|
|
$invitelink = Tools::getShopDomain(TRUE).__PS_BASE_URI__.'invite/'.substr(base64_encode($customer->date_add), 0, 12).strrev(base64_encode(strval($cookie->email)));
|
|
} else {
|
|
if(Configuration::get('PS_CIPHER_ALGORITHM')) {
|
|
$cipherTool = new Rijndael(_RIJNDAEL_KEY_, _RIJNDAEL_IV_);
|
|
} else {
|
|
$cipherTool = new Blowfish(_COOKIE_KEY_, _COOKIE_IV_);
|
|
}
|
|
$invitelink = $link->getPageLink('authentication.php', TRUE).'?create_account=1&sponsor='.urlencode($cipherTool->encrypt('1|'.$cookie->email.'|'));
|
|
}
|
|
|
|
$reward_sponsor_on = (int) Configuration::get('INVITE_REWARD_SPONSOR_ON');
|
|
$reward_sponsored_on = (int) Configuration::get('INVITE_REWARD_SPONSORED_ON');
|
|
$reward_sponsor = (int) Configuration::get('INVITE_REWARD_SPONSOR_TYPE');
|
|
$reward_sponsored = (int) Configuration::get('INVITE_REWARD_SPONSORED_TYPE');
|
|
|
|
if($reward_sponsor == 4) {
|
|
$reward_sponsor_value = (int) Configuration::get('INVITE_REWARD_SPONSOR_VALUE_'.$groups[count($groups) - 1].'_'.$cookie->id_currency);
|
|
$reward_sponsor_credit_value = 0;
|
|
} elseif($reward_sponsor == 1) {
|
|
$reward_sponsor_value = (int) Configuration::get('INVITE_REWARD_SPONSOR_VALUE_'.$groups[count($groups) - 1]);
|
|
$reward_sponsor_credit_value = $reward_sponsor_value * (int) Configuration::get('INVITE_CREDIT_RATE');
|
|
} else {
|
|
$reward_sponsor_value = (int) Configuration::get('INVITE_REWARD_SPONSOR_VALUE_'.$groups[count($groups) - 1]);
|
|
$reward_sponsor_credit_value = 0;
|
|
}
|
|
|
|
if($reward_sponsored == 4) {
|
|
$reward_sponsored_value = (int) Configuration::get('INVITE_REWARD_SPONSORED_VALUE_'.$groups[count($groups) - 1].'_'.$cookie->id_currency);
|
|
$reward_sponsor_credit_value = 0;
|
|
} elseif($reward_sponsored == 1) {
|
|
$reward_sponsored_value = (int) Configuration::get('INVITE_REWARD_SPONSORED_VALUE_'.$groups[count($groups) - 1]);
|
|
$reward_sponsored_credit_value = $reward_sponsored_value * (int) Configuration::get('INVITE_CREDIT_RATE');
|
|
} else {
|
|
$reward_sponsored_value = (int) Configuration::get('INVITE_REWARD_SPONSORED_VALUE_'.$groups[count($groups) - 1]);
|
|
$reward_sponsor_credit_value = 0;
|
|
}
|
|
|
|
$nbInvitation = 0;
|
|
$nbRevive = 0;
|
|
$invitation_sent = FALSE;
|
|
$revive_sent = FALSE;
|
|
|
|
if($canSendInvitations) {
|
|
if (Tools::isSubmit('submitSponsorFriends')
|
|
&& Tools::getValue('friendsEmail')
|
|
&& sizeof($friendsEmail = Tools::getValue('friendsEmail')) >= 1) {
|
|
|
|
if (!Tools::getValue('conditionsValided')) {
|
|
$error = 'conditions not valided';
|
|
} else {
|
|
$friendsLastName = Tools::getValue('friendsLastName');
|
|
$friendsFirstName = Tools::getValue('friendsFirstName');
|
|
$mails_exists = array();
|
|
foreach ($friendsEmail AS $key => $friendEmail) {
|
|
$friendEmail = $emailOri = strtolower(trim(strval($friendEmail)));
|
|
|
|
// Prepare Check email
|
|
$domains = array(
|
|
/* Default domains included */
|
|
"aol.com", "att.net", "comcast.net", "facebook.com", "gmail.com", "gmx.com", "googlemail.com",
|
|
"google.com", "hotmail.com", "hotmail.co.uk", "mac.com", "me.com", "mail.com", "msn.com",
|
|
"live.com", "sbcglobal.net", "verizon.net", "yahoo.com", "yahoo.co.uk",
|
|
|
|
/* Other global domains */
|
|
"email.com", "fastmail.fm", "games.com" /* AOL */, "gmx.net", "hush.com", "hushmail.com", "icloud.com",
|
|
"iname.com", "inbox.com", "lavabit.com", "love.com" /* AOL */, "outlook.com", "pobox.com", "protonmail.com",
|
|
"rocketmail.com" /* Yahoo */, "safe-mail.net", "wow.com" /* AOL */, "ygm.com" /* AOL */,
|
|
"ymail.com" /* Yahoo */, "zoho.com", "yandex.com",
|
|
|
|
/* United States ISP domains */
|
|
"bellsouth.net", "charter.net", "cox.net", "earthlink.net", "juno.com",
|
|
|
|
/* British ISP domains */
|
|
"btinternet.com", "virginmedia.com", "blueyonder.co.uk", "freeserve.co.uk", "live.co.uk",
|
|
"ntlworld.com", "o2.co.uk", "orange.net", "sky.com", "talktalk.co.uk", "tiscali.co.uk",
|
|
"virgin.net", "wanadoo.co.uk", "bt.com",
|
|
|
|
/* Domains used in Asia */
|
|
"sina.com", "qq.com", "naver.com", "hanmail.net", "daum.net", "nate.com", "yahoo.co.jp", "yahoo.co.kr", "yahoo.co.id", "yahoo.co.in", "yahoo.com.sg", "yahoo.com.ph",
|
|
|
|
/* French ISP domains */
|
|
"hotmail.fr", "live.fr", "laposte.net", "yahoo.fr", "wanadoo.fr", "orange.fr", "gmx.fr", "sfr.fr", "neuf.fr", "free.fr",
|
|
|
|
/* German ISP domains */
|
|
"gmx.de", "hotmail.de", "live.de", "online.de", "t-online.de" /* T-Mobile */, "web.de", "yahoo.de",
|
|
|
|
/* Italian ISP domains */
|
|
"libero.it", "virgilio.it", "hotmail.it", "aol.it", "tiscali.it", "alice.it", "live.it", "yahoo.it", "email.it", "tin.it", "poste.it", "teletu.it",
|
|
|
|
/* Russian ISP domains */
|
|
"mail.ru", "rambler.ru", "yandex.ru", "ya.ru", "list.ru",
|
|
|
|
/* Belgian ISP domains */
|
|
"hotmail.be", "live.be", "skynet.be", "voo.be", "tvcablenet.be", "telenet.be",
|
|
|
|
/* Argentinian ISP domains */
|
|
"hotmail.com.ar", "live.com.ar", "yahoo.com.ar", "fibertel.com.ar", "speedy.com.ar", "arnet.com.ar",
|
|
|
|
/* Domains used in Mexico */
|
|
"yahoo.com.mx", "live.com.mx", "hotmail.es", "hotmail.com.mx", "prodigy.net.mx",
|
|
|
|
/* Domains used in Brazil */
|
|
"yahoo.com.br", "hotmail.com.br", "outlook.com.br", "uol.com.br", "bol.com.br", "terra.com.br", "ig.com.br", "itelefonica.com.br", "r7.com", "zipmail.com.br", "globo.com", "globomail.com", "oi.com.br"
|
|
);
|
|
|
|
// Real association
|
|
$replaceSLD = array(
|
|
'@hotmil.' => '@hotmail.',
|
|
'@htmail.' => '@hotmail.',
|
|
'@hotmal.' => '@hotmail.',
|
|
'@hotml.' => '@hotmail.',
|
|
'@hotmai.' => '@hotmail.',
|
|
'@gmal.' => '@gmail.',
|
|
'@gail.' => '@gmail.',
|
|
'@gml.' => '@gmail.',
|
|
'@gmai.' => '@gmail.',
|
|
'@gmil.' => '@gmail.',
|
|
);
|
|
|
|
$replaceGlobal = array(
|
|
'@gmailcom' => '@gmail.com',
|
|
'@hotmailcom' => '@hotmail.com',
|
|
'@hotmailfr' => '@hotmail.fr',
|
|
'@yahoocom' => '@yahoo.com',
|
|
'@yahoofr' => '@yahoo.fr',
|
|
);
|
|
// Real use case replacement
|
|
$friendEmail = strtr($friendEmail, $replaceGlobal);
|
|
|
|
// Check TLD
|
|
$atPos = strpos($friendEmail, '@');
|
|
$pointPos = strpos($friendEmail, '.', $atPos);
|
|
$tld = substr($friendEmail, $pointPos + 1);
|
|
$sld = substr($friendEmail, $atPos + 1, strlen($friendEmail) - ($atPos+1) - (strlen($tld)+1) );
|
|
if (empty($tld)) {
|
|
$errors[] = Tools::displayError('Invalid email');
|
|
$_POST['friendsEmail'] = '';
|
|
}
|
|
if (empty($errors)) {
|
|
// If you have a complete list of TLD, check it !
|
|
}
|
|
|
|
// Check SLD
|
|
if (empty($errors)) {
|
|
// Real use case replacement
|
|
$friendEmail = strtr($friendEmail, $replaceSLD);
|
|
// Levenhstein remplacement
|
|
if (count($domains) > 0 && $friendEmail == $emailOri) {
|
|
foreach ($domains as $d) {
|
|
$dpPos = strpos($d, '.');
|
|
$realDomain = substr($d, 0, $dpPos);
|
|
$lev = levenshtein($sld, $realDomain);
|
|
if ($lev == O) {
|
|
break;
|
|
}
|
|
elseif ($lev == 1 && $tld == substr($d, $dpPos+1)) {
|
|
$friendEmail = str_replace('@'.$sld.'.', '@'.$realDomain.'.', $friendEmail);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if($askName) {
|
|
$friendLastName = strval($friendsLastName[$key]);
|
|
$friendFirstName = strval($friendsFirstName[$key]);
|
|
} else {
|
|
$friendLastName = '';
|
|
$friendFirstName = '';
|
|
}
|
|
|
|
if(empty($friendEmail) && empty($friendLastName) && empty($friendFirstName)) {
|
|
continue;
|
|
} elseif(empty($friendEmail) || !Validate::isEmail($friendEmail)) {
|
|
$error = 'email invalid';
|
|
} elseif($askName && (empty($friendFirstName) || empty($friendLastName) || !Validate::isName($friendLastName) || !Validate::isName($friendFirstName))) {
|
|
$error = 'name invalid';
|
|
} elseif($invite->emailExists($friendEmail) || Customer::customerExists($friendEmail)) {
|
|
$mails_exists[] = $friendEmail;
|
|
} else {
|
|
$when_invite = Tools::getValue('when_invite', 0);
|
|
$id_invite = $invite->addInvite($cookie->id_customer, $friendFirstName, $friendLastName, $friendEmail, $when_invite);
|
|
if(!$id_invite) {
|
|
$error = 'cannot add friends';
|
|
} else {
|
|
if(Configuration::get('INVITE_FORM_LINKFORMAT')) {
|
|
$_invitelink = Tools::getShopDomain(TRUE).__PS_BASE_URI__.'invite/'.substr(base64_encode($customer->date_add), 0, 12).strrev(base64_encode(strval($cookie->email))).'?email='.rawurlencode($friendEmail);
|
|
} else {
|
|
if(Configuration::get('PS_CIPHER_ALGORITHM')) {
|
|
$cipherTool = new Rijndael(_RIJNDAEL_KEY_, _RIJNDAEL_IV_);
|
|
} else {
|
|
$cipherTool = new Blowfish(_COOKIE_KEY_, _COOKIE_IV_);
|
|
}
|
|
$_invitelink = $link->getPageLink('authentication.php').'?create_account=1&sponsor='.urlencode($cipherTool->encrypt($id_invite.'|'.$cookie->email.'|'));
|
|
}
|
|
|
|
$vars = array(
|
|
'{email}' => strval($cookie->email),
|
|
'{lastname}' => strval($cookie->customer_lastname),
|
|
'{firstname}' => strval($cookie->customer_firstname),
|
|
'{email_friend}' => $friendEmail,
|
|
'{name_friend}' => ($askName? strval($friendFirstName).' '.strval($friendLastName).'... ': ''),
|
|
'{link}' => $_invitelink,
|
|
'{reward_sponsor}' => $reward_sponsor,
|
|
'{reward_sponsored}' => $reward_sponsored,
|
|
'{reward_sponsor_value}' => $reward_sponsor_value,
|
|
'{reward_sponsored_value}' => $reward_sponsored_value,
|
|
'{reward_sponsor_credit_value}' => $reward_sponsor_credit_value,
|
|
'{reward_sponsored_credit_value}' => $reward_sponsored_credit_value,
|
|
'{currency}' => $currency->sign,
|
|
);
|
|
|
|
Mail::Send(
|
|
(int) $cookie->id_lang,
|
|
($reward_sponsored == 1? 'invite-invitation-credit': ($reward_sponsored == 2? 'invite-invitation-loyalty': ($reward_sponsored == 3? 'invite-invitation-discount-percent': ($reward_sponsored == 4? 'invite-invitation-discount-amount': ($reward_sponsored == 5? 'invite-invitation-shipping': 'invite-invitation'))))),
|
|
Mail::l('Referral Program'),
|
|
$vars,
|
|
$friendEmail,
|
|
($askName? $friendFirstName.' '.$friendLastName: $friendEmail),
|
|
strval(Configuration::get('PS_SHOP_EMAIL')),
|
|
strval(Configuration::get('PS_SHOP_NAME')),
|
|
NULL,
|
|
NULL,
|
|
dirname(__FILE__).'/mails/'
|
|
);
|
|
|
|
$invitation_sent = TRUE;
|
|
$nbInvitation++;
|
|
}
|
|
}
|
|
|
|
if($error) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
if($nbInvitation > 0) {
|
|
$activeTab = 'pending';
|
|
unset($_POST);
|
|
}
|
|
|
|
if(sizeof($mails_exists)) {
|
|
$error = 'email exists';
|
|
}
|
|
}
|
|
}
|
|
|
|
if (Tools::isSubmit('revive')) {
|
|
$activeTab = 'pending';
|
|
if (Tools::getValue('friendChecked') && sizeof($friendsChecked = Tools::getValue('friendChecked')) >= 1) {
|
|
foreach ($friendsChecked as $key => $friendChecked) {
|
|
if ($invite->isFriend((int) $cookie->id_customer, (int) $key)) {
|
|
$infos = $invite->getInvite((int) $key);
|
|
|
|
if(Configuration::get('INVITE_FORM_LINKFORMAT')) {
|
|
$_invitelink = Tools::getShopDomain(TRUE).__PS_BASE_URI__.'invite/'.substr(base64_encode($customer->date_add), 0, 12).strrev(base64_encode(strval($cookie->email))).'?email='.rawurlencode($infos['email']);
|
|
} else {
|
|
if (Configuration::get('PS_CIPHER_ALGORITHM')) {
|
|
$cipherTool = new Rijndael(_RIJNDAEL_KEY_, _RIJNDAEL_IV_);
|
|
} else {
|
|
$cipherTool = new Blowfish(_COOKIE_KEY_, _COOKIE_IV_);
|
|
}
|
|
$_invitelink = $link->getPageLink('authentication.php').'?create_account=1&sponsor='.urlencode($cipherTool->encrypt($infos['id_invite'].'|'.$cookie->email.'|'));
|
|
}
|
|
|
|
$vars = array(
|
|
'{email}' => $cookie->email,
|
|
'{lastname}' => $cookie->customer_lastname,
|
|
'{firstname}' => $cookie->customer_firstname,
|
|
'{email_friend}' => $infos['email'],
|
|
'{name_friend}' => ($askName? strval($infos['firstname']).' '.strval($infos['lastname']).'... ': ''),
|
|
'{link}' => $_invitelink,
|
|
'{reward_sponsor}' => $reward_sponsor,
|
|
'{reward_sponsored}' => $reward_sponsored,
|
|
'{reward_sponsor_value}' => $reward_sponsor_value,
|
|
'{reward_sponsored_value}' => $reward_sponsored_value,
|
|
'{reward_sponsor_credit_value}' => $reward_sponsor_credit_value,
|
|
'{reward_sponsored_credit_value}' => $reward_sponsored_credit_value,
|
|
'{currency}' => $currency->sign,
|
|
);
|
|
|
|
Mail::Send(
|
|
(int) $cookie->id_lang,
|
|
($reward_sponsored == 1? 'invite-invitation-credit': ($reward_sponsored == 2? 'invite-invitation-loyalty': ($reward_sponsored == 3? 'invite-invitation-discount-percent': ($reward_sponsored == 4? 'invite-invitation-discount-amount': ($reward_sponsored == 5? 'invite-invitation-shipping': 'invite-invitation'))))),
|
|
Mail::l('Referral Program'),
|
|
$vars,
|
|
$infos['email'],
|
|
($askName? $infos['firstname'].' '.$infos['lastname']: $infos['email']),
|
|
strval(Configuration::get('PS_SHOP_EMAIL')),
|
|
strval(Configuration::get('PS_SHOP_NAME')),
|
|
NULL,
|
|
NULL,
|
|
dirname(__FILE__).'/mails/'
|
|
);
|
|
$invite->updateInvite((int) $friendChecked);
|
|
|
|
$revive_sent = TRUE;
|
|
$nbRevive++;
|
|
}
|
|
}
|
|
} else {
|
|
$error = 'no revive checked';
|
|
}
|
|
}
|
|
}
|
|
|
|
$oi_services = FALSE;
|
|
if ($oi_enable = Configuration::get('INVITE_OPENINVITER_ENABLE')) {
|
|
include('openinviter/openinviter.php');
|
|
$inviter = new OpenInviter();
|
|
$oi_services = $inviter->getPlugins();
|
|
}
|
|
|
|
$display_credits = false;
|
|
$sql = 'SELECT id_customer FROM `'._DB_PREFIX_.'customer_credits` WHERE id_customer = ' . (int)$customer->id;
|
|
if (Db::getInstance()->getValue($sql) === false) {
|
|
$display_credits = true;
|
|
}
|
|
|
|
$customer_credit = 0;
|
|
if ($display_credits === true) {
|
|
$customer_credit = $invite->_get_credit((int) $cookie->id_customer, false, false, 'frontoffice');
|
|
}
|
|
|
|
$smarty->assign(array(
|
|
'activeTab' => $activeTab,
|
|
'orderQuantity' => $orderQuantity,
|
|
'canSendInvitations' => $canSendInvitations,
|
|
'nbFriends' => (int) Configuration::get('INVITE_FORM_FIELDS'),
|
|
'showInviteLink' => (int) Configuration::get('INVITE_FORM_SHOWLINK'),
|
|
'askName' => $askName,
|
|
'invitelink' => $invitelink,
|
|
'reward_sponsor_on' => $reward_sponsor_on,
|
|
'reward_sponsored_on' => $reward_sponsored_on,
|
|
'reward_sponsor' => $reward_sponsor,
|
|
'reward_sponsored' => $reward_sponsored,
|
|
'reward_sponsor_value' => $reward_sponsor_value,
|
|
'reward_sponsored_value' => $reward_sponsored_value,
|
|
'error' => $error,
|
|
'mails_exists' => $mails_exists,
|
|
'revive_sent' => $revive_sent,
|
|
'invitation_sent' => $invitation_sent,
|
|
'nbInvitation' => $nbInvitation,
|
|
'nbRevive' => $nbRevive,
|
|
'oi_services' => $oi_services,
|
|
'oi_enable' => $oi_enable,
|
|
'pendingFriends' => $invite->getPendingFriends($customer->id),
|
|
'subscribeFriends' => $invite->getFriends($customer->id),
|
|
'currency' => $currency->sign,
|
|
'customer_credit' => $customer_credit,
|
|
'credits_display' => $display_credits,
|
|
));
|
|
|
|
echo Module::display(dirname(__FILE__).'/invite.php', 'invite-program.tpl');
|
|
|
|
include(dirname(__FILE__).'/../../footer.php');
|