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 = 'sponsor'; $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 = strval($friendEmail); 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(); } $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, )); echo Module::display(dirname(__FILE__).'/invite.php', 'invite-program.tpl'); include(dirname(__FILE__).'/../../footer.php');