2016-01-04 12:49:26 +01:00
< ? php
if ( ! defined ( '_PS_VERSION_' ))
exit ;
class Invite extends Module {
public function __construct () {
$this -> name = 'invite' ;
$this -> tab = 'advertising_marketing' ;
$this -> version = '2.0' ;
$this -> author = 'Antadis' ;
$this -> need_instance = 0 ;
parent :: __construct ();
$this -> displayName = $this -> l ( 'Customer referral program with Open Inviter' );
$this -> description = $this -> l ( 'Integrate a referral program system into your shop with Open Inviter support.' );
$this -> confirmUninstall = $this -> l ( 'All sponsors and friends will be deleted. Are you sure you want to uninstall this module?' );
$this -> _errors = array ();
}
public function installDB () {
return Db :: getInstance () -> Execute ( '
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'invite` (
`id_invite` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`id_sponsor` INT UNSIGNED NOT NULL ,
`email` VARCHAR ( 255 ) NOT NULL ,
`lastname` VARCHAR ( 128 ) NOT NULL ,
`firstname` VARCHAR ( 128 ) NOT NULL ,
`id_customer` INT UNSIGNED DEFAULT NULL ,
`id_discount` INT UNSIGNED DEFAULT NULL ,
`id_discount_sponsor` INT UNSIGNED DEFAULT NULL ,
`credit` BOOL NOT NULL ,
`credit_sponsor` BOOL NOT NULL ,
`date_add` DATETIME NOT NULL ,
`date_upd` DATETIME NOT NULL ,
PRIMARY KEY ( `id_invite` ),
UNIQUE KEY `index_unique_invite_email` ( `email` )
) ENGINE = '._MYSQL_ENGINE_.' DEFAULT CHARSET = utf8 ;
' )
&& Db :: getInstance () -> Execute ( '
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'invite_credit` (
`id_customer` INTEGER UNSIGNED NOT NULL ,
`credit` DECIMAL ( 20 , 6 ) DEFAULT 0.0 NOT NULL ,
PRIMARY KEY ( `id_customer` )
) ENGINE = '._MYSQL_ENGINE_.' DEFAULT CHARSET = utf8 ;
' );
}
public function uninstallDB () {
return Db :: getInstance () -> Execute ( 'DROP TABLE `' . _DB_PREFIX_ . 'invite`;' )
&& Db :: getInstance () -> Execute ( 'DROP TABLE `' . _DB_PREFIX_ . 'invite_credit`;' );
}
public function install () {
if ( ! parent :: install () || ! $this -> installDB ()
|| ! $this -> registerHook ( 'adminCustomers' )
|| ! $this -> registerHook ( 'createAccount' )
|| ! $this -> registerHook ( 'createAccountForm' )
|| ! $this -> registerHook ( 'updateOrderStatus' )
|| ! $this -> registerHook ( 'customerAccount' )
|| ! $this -> registerHook ( 'preProcess' )) {
return FALSE ;
}
return TRUE ;
}
public function uninstall () {
$result = TRUE
&& Configuration :: deleteByName ( 'INVITE_REWARD_SPONSOR_TYPE' )
&& Configuration :: deleteByName ( 'INVITE_REWARD_SPONSORED_TYPE' )
&& Configuration :: deleteByName ( 'INVITE_REWARD_SPONSOR_ON' )
&& Configuration :: deleteByName ( 'INVITE_REWARD_SPONSORED_ON' )
&& Configuration :: deleteByName ( 'INVITE_DISCOUNT_CUMULABLE' )
&& Configuration :: deleteByName ( 'INVITE_DISCOUNT_CUMULABLE_REDUC' )
&& Configuration :: deleteByName ( 'INVITE_DISCOUNT_MINIMAL' )
&& Configuration :: deleteByName ( 'INVITE_DISCOUNT_MINIMAL_WT' )
&& Configuration :: deleteByName ( 'INVITE_DISCOUNT_CART' )
&& Configuration :: deleteByName ( 'INVITE_DISCOUNT_PREFIX' )
&& Configuration :: deleteByName ( 'INVITE_DISCOUNT_DESCRIPTION' )
&& Configuration :: deleteByName ( 'INVITE_DISCOUNT_VALIDITY' )
&& Configuration :: deleteByName ( 'INVITE_OPENINVITER_ENABLE' )
&& Configuration :: deleteByName ( 'INVITE_DISCOUNT_PREFIX' )
&& Configuration :: deleteByName ( 'INVITE_DISCOUNT_DESCRIPTION' )
&& Configuration :: deleteByName ( 'INVITE_DISCOUNT_VALIDITY' )
&& Configuration :: deleteByName ( 'INVITE_CONDITIONS' )
&& Configuration :: deleteByName ( 'INVITE_CREDIT_ENABLE' )
&& Configuration :: deleteByName ( 'INVITE_CREDIT_RATE' )
&& Configuration :: deleteByName ( 'INVITE_CREDIT_DISPLAY' )
&& Configuration :: deleteByName ( 'INVITE_ORDER_QTY' )
&& Configuration :: deleteByName ( 'INVITE_ASK_NAME' )
&& Configuration :: deleteByName ( 'INVITE_FORM_FIELDS' )
&& Configuration :: deleteByName ( 'INVITE_FORM_FIELDS_MAX' )
&& Configuration :: deleteByName ( 'INVITE_FORM_SHOWLINK' )
&& Configuration :: deleteByName ( 'INVITE_FORM_LINKFORMAT' );
foreach ( Group :: getGroups () as $group ) {
$result = $result
&& Configuration :: deleteByName ( 'INVITE_REWARD_SPONSOR_VALUE_' . ( int )( $group [ 'id_group' ]))
&& Configuration :: deleteByName ( 'INVITE_REWARD_SPONSORED_VALUE_' . ( int )( $group [ 'id_group' ]));
foreach ( Currency :: getCurrencies () as $currency ) {
$result = $result
&& Configuration :: deleteByName ( 'INVITE_REWARD_SPONSOR_VALUE_' . ( int )( $group [ 'id_group' ]) . '_' . ( int )( $currency [ 'id_currency' ]))
&& Configuration :: deleteByName ( 'INVITE_REWARD_SPONSORED_VALUE_' . ( int )( $group [ 'id_group' ]) . '_' . ( int )( $currency [ 'id_currency' ]));
}
}
if ( ! parent :: uninstall ()
|| ! $this -> uninstallDB ()
|| ! $result
) {
return FALSE ;
}
return TRUE ;
}
public function getContent () {
$this -> _html .= '<h2>' . $this -> displayName . ' </ h2 >
< style type = " text/css " >
#content .alert {
width : auto ;
}
</ style >
' ;
if ( Tools :: getValue ( 'submitInvite' )) {
$this -> _postValidation ();
if ( ! sizeof ( $this -> _errors )) {
$this -> _postProcess ();
} else {
foreach ( $this -> _errors as $error ) {
$this -> _html .= $this -> displayError ( $error );
}
}
} elseif ( Tools :: getValue ( 'submitImport' )) {
$this -> _doImport ();
}
$this -> _displayForm ();
return $this -> _html ;
}
private function _postValidation () {
global $cookie ;
$groups = Group :: getGroups ( $cookie -> id_lang );
$currencies = Currency :: getCurrencies ();
if ( Tools :: getValue ( 'form_fields' ) && ! Validate :: isInt ( Tools :: getValue ( 'form_fields' ))) {
$this -> _errors [] = $this -> l ( 'The form fields quantity value is invalid.' );
}
if ( Tools :: getValue ( 'form_fields_max' ) && ! Validate :: isInt ( Tools :: getValue ( 'form_fields_max' ))) {
$this -> _errors [] = $this -> l ( 'The maximum invites quantity value is invalid.' );
}
if ( Tools :: getValue ( 'order_qty' ) && ! Validate :: isInt ( Tools :: getValue ( 'order_qty' ))) {
$this -> _errors [] = $this -> l ( 'The order quantity value is invalid.' );
}
if ( Tools :: getValue ( 'credit_rate' ) && ! Validate :: isFloat ( Tools :: getValue ( 'credit_rate' ))) {
$this -> _errors [] = $this -> l ( 'The credit rate value is invalid.' );
}
if ( Tools :: getValue ( 'discount_reward_minimal' ) && ! Validate :: isFloat ( Tools :: getValue ( 'discount_reward_minimal' ))) {
$this -> _errors [] = $this -> l ( 'The minimal order value is invalid.' );
}
if (( int )( Tools :: getValue ( 'sponsor_reward_type' ) == 1 )
|| ( int )( Tools :: getValue ( 'sponsor_reward_type' ) == 2 )
|| ( int )( Tools :: getValue ( 'sponsor_reward_type' ) == 3 )) {
$sponsor_reward = Tools :: getValue ( 'sponsor_reward_value' );
foreach ( $groups as $group ) {
if ( isset ( $sponsor_reward [ $group [ 'id_group' ]]) && ! Validate :: isInt ( $sponsor_reward [ $group [ 'id_group' ]])) {
$this -> _errors [] = $this -> l ( 'The reward value for sponsors in the' ) . ' ' . $group [ 'name' ] . ' ' . $this -> l ( 'is invalid.' );
}
}
} elseif (( int )( Tools :: getValue ( 'sponsor_reward_type' ) == 4 )) {
foreach ( $groups as $group ) {
$sponsor_reward = Tools :: getValue ( 'sponsor_reward_value' );
foreach ( $currencies as $currency ) {
if ( isset ( $sponsor_reward [ $group [ 'id_group' ]][ $currency [ 'id_currency' ]]) && ! Validate :: isInt ( $sponsor_reward [ $group [ 'id_group' ]][ $currency [ 'id_currency' ]])) {
$this -> _errors [] = $this -> l ( 'The reward value for sponsors in the' ) . ' ' . $group [ 'name' ] . ' ' . $this -> l ( 'with the currency' ) . ' ' . $currency [ 'name' ] . ' ' . $this -> l ( 'is invalid.' );
}
}
}
}
if (( int )( Tools :: getValue ( 'sponsored_reward_type' ) == 1 )
|| ( int )( Tools :: getValue ( 'sponsored_reward_type' ) == 2 )
|| ( int )( Tools :: getValue ( 'sponsored_reward_type' ) == 3 )) {
$sponsored_reward = Tools :: getValue ( 'sponsored_reward_value' );
foreach ( $groups as $group ) {
if ( isset ( $sponsored_reward [ $group [ 'id_group' ]]) && ! Validate :: isFloat ( $sponsored_reward [ $group [ 'id_group' ]])) {
$this -> _errors [] = $this -> l ( 'The reward value for sponsored people in the' ) . ' ' . $group [ 'name' ] . ' ' . $this -> l ( 'is invalid.' );
}
}
} elseif (( int )( Tools :: getValue ( 'sponsored_reward_type' ) == 4 )) {
$sponsored_reward = Tools :: getValue ( 'sponsored_reward_value' );
foreach ( $groups as $group ) {
foreach ( $currencies as $currency ) {
if ( isset ( $sponsored_reward [ $group [ 'id_group' ]][ $currency [ 'id_currency' ]]) && ! Validate :: isFloat ( $sponsored_reward [ $group [ 'id_group' ]][ $currency [ 'id_currency' ]])) {
$this -> _errors [] = $this -> l ( 'The reward value for sponsored people in the' ) . ' ' . $group [ 'name' ] . ' ' . $this -> l ( 'with the currency' ) . ' ' . $currency [ 'name' ] . ' ' . $this -> l ( 'is invalid.' );
}
}
}
}
}
private function _doImport () {
$old_struct = TRUE ;
foreach ( Db :: getInstance () -> ExecuteS ( '
DESCRIBE `'._DB_PREFIX_.'invite`
' ) as $column ) {
if ( $column [ 'Field' ] == 'credit' ) {
$old_struct = FALSE ;
break ;
}
}
if ( $old_struct ) {
@ ini_set ( 'max_execution_time' , ( int ) Tools :: getValue ( 'time_limit' ), 30 );
Db :: getInstance () -> Execute ( '
ALTER TABLE `'._DB_PREFIX_.'invite`
ADD COLUMN `credit` BOOL NOT NULL
AFTER `id_discount_sponsor`
' );
Db :: getInstance () -> Execute ( '
ALTER TABLE `'._DB_PREFIX_.'invite`
ADD COLUMN `credit_sponsor` BOOL NOT NULL
AFTER `credit`
' );
if ( Tools :: getValue ( 'reset_credit' , 0 )) {
Db :: getInstance () -> Execute ( '
DELETE FROM `'._DB_PREFIX_.'invite_credit`
' );
}
$credit_customers = array ();
$points = Db :: getInstance () -> ExecuteS ( '
SELECT `id_customer` , SUM ( `points` ) AS `value`
FROM `'._DB_PREFIX_.'loyalty`
WHERE `id_loyalty_state` = 2
AND `points` > 0
GROUP BY `id_customer`
' );
if ( $points ) {
foreach ( $points as $credit ) {
Db :: getInstance () -> ExecuteS ( '
INSERT INTO `'._DB_PREFIX_.'invite_credit`
VALUES (
'.(int) $credit[' id_customer '].' ,
'.(float) $credit[' value '].'
)
' );
$credit_customers [] = ( int ) $credit [ 'id_customer' ];
}
}
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT `id_discount` , `id_customer` , `value`
FROM `'._DB_PREFIX_.'discount`
WHERE `name` LIKE " FID% "
AND `quantity` > 0
AND `active` != 0
AND `date_to` > NOW ()
AND `id_discount` NOT IN (
SELECT `id_discount`
FROM `'._DB_PREFIX_.'order_discount`
)
' ) as $discount ) {
if ( in_array (( int ) $discount [ 'id_customer' ], $credit_customers )) {
Db :: getInstance () -> Execute ( '
UPDATE `'._DB_PREFIX_.'invite_credit`
SET `credit` = `credit` + '.(float) $credit[' value '].'
WHERE `id_customer` = '.(int) $credit[' id_customer '].'
' );
} else {
Db :: getInstance () -> ExecuteS ( '
INSERT INTO `'._DB_PREFIX_.'invite_credit`
VALUES (
'.(int) $credit[' id_customer '].' ,
'.(float) $credit[' value '].'
)
' );
$credit_customers [] = ( int ) $discount [ 'id_customer' ];
}
$d = new Discount (( int ) $discount [ 'id_discount' ]);
$d -> delete ();
}
$this -> _html .= $this -> displayConfirmation ( $this -> l ( 'Import completed.' ));
} else {
$this -> _html .= $this -> displayError ( $this -> l ( 'Database already up-to-date.' ));
}
}
private function _postProcess () {
global $cookie ;
$groups = Group :: getGroups ( $cookie -> id_lang );
$currencies = Currency :: getCurrencies ();
Configuration :: updateValue ( 'INVITE_DISCOUNT_PREFIX' , Tools :: getValue ( 'discount_reward_prefix' ));
Configuration :: updateValue ( 'INVITE_DISCOUNT_DESCRIPTION' , Tools :: getValue ( 'discount_reward_description' ));
Configuration :: updateValue ( 'INVITE_DISCOUNT_VALIDITY' , ( int ) Tools :: getValue ( 'discount_reward_validity' ));
Configuration :: updateValue ( 'INVITE_DISCOUNT_CUMULABLE' , ( int ) Tools :: getValue ( 'discount_reward_cumulable' ));
Configuration :: updateValue ( 'INVITE_DISCOUNT_CUMULABLE_REDUC' , ( int ) Tools :: getValue ( 'discount_reward_cumulable_reduction' ));
Configuration :: updateValue ( 'INVITE_DISCOUNT_MINIMAL' , ( float ) Tools :: getValue ( 'discount_reward_minimal' ));
Configuration :: updateValue ( 'INVITE_DISCOUNT_MINIMAL_WT' , ( int ) Tools :: getValue ( 'discount_reward_minimal_wt' ));
Configuration :: updateValue ( 'INVITE_DISCOUNT_CART' , ( int ) Tools :: getValue ( 'discount_reward_cart' ));
Configuration :: updateValue ( 'INVITE_ORDER_QTY' , ( int ) Tools :: getValue ( 'order_qty' ));
Configuration :: updateValue ( 'INVITE_FORM_FIELDS' , ( int ) Tools :: getValue ( 'form_fields' ));
Configuration :: updateValue ( 'INVITE_FORM_FIELDS_MAX' , ( int ) Tools :: getValue ( 'form_fields_max' ));
Configuration :: updateValue ( 'INVITE_FORM_SHOWLINK' , ( int ) Tools :: getValue ( 'form_show_link' ));
Configuration :: updateValue ( 'INVITE_FORM_LINKFORMAT' , ( int ) Tools :: getValue ( 'form_link_format' ));
Configuration :: updateValue ( 'INVITE_ASK_NAME' , ( int ) Tools :: getValue ( 'form_ask_name' ));
Configuration :: updateValue ( 'INVITE_CREDIT_ENABLE' , ( int ) Tools :: getValue ( 'credit_enable' ));
Configuration :: updateValue ( 'INVITE_CREDIT_RATE' , ( float ) Tools :: getValue ( 'credit_rate' ));
Configuration :: updateValue ( 'INVITE_CREDIT_DISPLAY' , ( int ) Tools :: getValue ( 'credit_display' ));
Configuration :: updateValue ( 'INVITE_REWARD_SPONSOR_ON' , ( int ) Tools :: getValue ( 'sponsor_reward_on' ));
Configuration :: updateValue ( 'INVITE_REWARD_SPONSORED_ON' , ( int ) Tools :: getValue ( 'sponsored_reward_on' ));
Configuration :: updateValue ( 'INVITE_CONDITIONS' , Tools :: getValue ( 'conditions' ), TRUE );
Configuration :: updateValue ( 'INVITE_REWARD_SPONSOR_TYPE' , ( int ) Tools :: getValue ( 'sponsor_reward_type' ));
if (( int )( Tools :: getValue ( 'sponsor_reward_type' )) == 4 ) {
$sponsor_reward = Tools :: getValue ( 'sponsor_reward_value' );
foreach ( $groups as $group ) {
foreach ( $currencies as $currency ) {
Configuration :: updateValue ( 'INVITE_REWARD_SPONSOR_VALUE_' . $group [ 'id_group' ] . '_' . $currency [ 'id_currency' ], ( float )( $sponsor_reward [ $group [ 'id_group' ]][ $currency [ 'id_currency' ]]));
}
}
} elseif (( int )( Tools :: getValue ( 'sponsor_reward_type' )) == 1
|| ( int )( Tools :: getValue ( 'sponsor_reward_type' )) == 2
|| ( int )( Tools :: getValue ( 'sponsor_reward_type' )) == 3 ) {
$sponsor_reward = Tools :: getValue ( 'sponsor_reward_value' );
foreach ( $groups as $group ) {
Configuration :: updateValue ( 'INVITE_REWARD_SPONSOR_VALUE_' . $group [ 'id_group' ], ( int )( $sponsor_reward [ $group [ 'id_group' ]]));
}
}
Configuration :: updateValue ( 'INVITE_REWARD_SPONSORED_TYPE' , ( int ) Tools :: getValue ( 'sponsored_reward_type' ));
if (( int )( Tools :: getValue ( 'sponsored_reward_type' )) == 4 ) {
$sponsored_reward = Tools :: getValue ( 'sponsored_reward_value' );
foreach ( $groups as $group ) {
foreach ( $currencies as $currency ) {
Configuration :: updateValue ( 'INVITE_REWARD_SPONSORED_VALUE_' . $group [ 'id_group' ] . '_' . $currency [ 'id_currency' ], ( float )( $sponsored_reward [ $group [ 'id_group' ]][ $currency [ 'id_currency' ]]));
}
}
} elseif (( int )( Tools :: getValue ( 'sponsored_reward_type' )) == 1
|| ( int )( Tools :: getValue ( 'sponsored_reward_type' )) == 2
|| ( int )( Tools :: getValue ( 'sponsored_reward_type' )) == 3 ) {
$sponsored_reward = Tools :: getValue ( 'sponsored_reward_value' );
foreach ( $groups as $group ) {
Configuration :: updateValue ( 'INVITE_REWARD_SPONSORED_VALUE_' . $group [ 'id_group' ], ( int )( $sponsored_reward [ $group [ 'id_group' ]]));
}
}
Configuration :: updateValue ( 'INVITE_OPENINVITER_ENABLE' , ( int ) Tools :: getValue ( 'openinviter_enable' ));
$this -> _write_oi_config (
Tools :: getValue ( 'openinviter_username' ),
Tools :: getValue ( 'openinviter_pk' ),
Tools :: getValue ( 'openinviter_cookiespath' )
);
$this -> _manage_oi_plugins (
Tools :: getValue ( 'openinviter_plugins_disabled' ),
Tools :: getValue ( 'openinviter_plugins_enabled' )
);
$this -> _html .= $this -> displayConfirmation ( $this -> l ( 'Configuration updated.' ));
}
private function _displayForm () {
$this -> _html .= '
< link rel = " stylesheet " type = " text/css " href = " '.__PS_BASE_URI__.'css/tabpane.css " />
< style type = " text/css " >
. clear {
clear : both ;
}
. block_hidden_only_for_screen {
display : none ;
}
ul . idTabs {
padding : 0 px ;
margin : 0 px ;
overflow : hidden ;
background : none ;
border : 0 px ;
z - index : 10 ;
position : absolute ;
top : 0 px ;
}
ul . idTabs li . tab a {
padding : 3 px 25 px 4 px 25 px ;
margin : 0 px ;
display : block ;
border : 1 px solid #efefef !important;
border - bottom : 1 px solid #cccccc !important;
}
ul . idTabs li a . selected {
border : 1 px solid #ccc !important;
border - bottom : 1 px solid #FFF6D3 !important;
background : #FFF6D3;
z - index : 3 ;
padding : 3 px 25 px 4 px 25 px ;
margin : 0 px ;
top : - 2 px ;
}
ul . idTabs li . tab {
padding : 0 px ;
margin : 0 px ;
border : 0 px ;
}
. tab - page {
margin - top : 24 px ;
}
. tab - pane {
position : relative ;
}
</ style >
< script type = " text/javascript " src = " '.__PS_BASE_URI__.'js/jquery/jquery.idTabs.modified.js " ></ script >
< form action = " '. $_SERVER['REQUEST_URI'] .' " method = " post " class = " tab-pane " enctype = " multipart/form-data " >
< div id = " tabs " >
< ul class = " idTabs tab-row " >
< li class = " tab " >< a href = " #idTab1 " > '.$this->l(' General settings ').' </ a ></ li >
< li class = " tab " >< a href = " #idTab2 " > '.$this->l(' Program conditions ').' </ a ></ li >
< li class = " tab " >< a href = " #idTab3 " > '.$this->l(' Rewards ').' </ a ></ li >
< li class = " tab " >< a href = " #idTab4 " > '.$this->l(' Open Inviter ').' </ a ></ li >
< li class = " tab " >< a href = " #idTab5 " > '.$this->l(' Import ').' </ a ></ li >
</ ul >
< div id = " idTab1 " class = " tab-page " > ' ;
$this -> _tab_1 ();
$this -> _html .= '<div class="clear center"><input class="button" style="margin-top: 10px" name="submitInvite" value="' . $this -> l ( 'Update settings' ) . ' " type= " submit " /></div>
</ div >
< div id = " idTab2 " class = " tab-page " > ' ;
$this -> _tab_2 ();
$this -> _html .= '<div class="clear center"><input class="button" style="margin-top: 10px" name="submitInvite" value="' . $this -> l ( 'Update settings' ) . ' " type= " submit " /></div>
</ div >
< div id = " idTab3 " class = " tab-page " > ' ;
$this -> _tab_3 ();
$this -> _html .= '<div class="clear center"><input class="button" style="margin-top: 10px" name="submitInvite" value="' . $this -> l ( 'Update settings' ) . ' " type= " submit " /></div>
</ div >
< div id = " idTab4 " class = " tab-page " > ' ;
$this -> _tab_4 ();
$this -> _html .= '<div class="clear center"><input class="button" style="margin-top: 10px" name="submitInvite" value="' . $this -> l ( 'Update settings' ) . ' " type= " submit " /></div>
</ div >
< div id = " idTab5 " class = " tab-page " > ' ;
$this -> _tab_5 ();
$this -> _html .= '
</ div >
</ div >
< script type = " text/javascript " >
$ ( " .idTabs li " ) . idTabs ();
</ script >
</ form >
' ;
}
private function _get_oi_plugins ( $enabled = TRUE ) {
$path = realpath ( dirname ( __FILE__ )) . '/openinviter/conf' . ( $enabled ? '' : '_disabled' ) . '/' ;
$dirs = scandir ( $path );
$result = array ();
foreach ( $dirs as $dir ) {
if ( $dir != '.' && $dir != '..' && substr ( $dir , 0 , 1 ) != '_' ) {
$result [] = str_replace ( '.conf' , '' , $dir );
}
}
return $result ;
}
private function _tab_1 () {
$defaultCurrency = Currency :: getDefaultCurrency ();
$this -> _html .= '
< p >
< label class = " t " for = " order_qty " > '.$this->l(' Minimum number of orders a customer must place to unlock the referral program : ').' </ label >
& nbsp ;
< input type = " text " name = " order_qty " style = " width: 50px; " id = " order_qty " value = " '.Configuration::get('INVITE_ORDER_QTY').' " />
</ p >
< p > </ p >
< p >
< label class = " t " for = " form_fields " > '.$this->l(' Default invite fields quantity on the front - office form : ').' </ label >
& nbsp ;
< input type = " text " name = " form_fields " style = " width: 50px; " id = " form_fields " value = " '.Configuration::get('INVITE_FORM_FIELDS').' " />
</ p >
< p >
< label class = " t " for = " form_fields_max " > '.$this->l(' Maximum simultaneous invites : ').' </ label >
& nbsp ;
< input type = " text " name = " form_fields_max " style = " width: 50px; " id = " form_fields_max " value = " '.Configuration::get('INVITE_FORM_FIELDS_MAX').' " />
</ p >
< p >
< label class = " t " > '.$this->l(' Ask for the friend name : ').' </ label >
& nbsp ;
< input type = " radio " name = " form_ask_name " id = " form_ask_name_off " value = " 0 " '.(Tools::getValue(' form_ask_name ', Configuration::get(' INVITE_ASK_NAME ')) == 0 ? ' checked = " checked " ' : ' ').' />
< label class = " t " for = " form_ask_name_off " > '.$this->l(' No ').' </ label >
& nbsp ;
< input type = " radio " name = " form_ask_name " id = " form_ask_name_on " value = " 1 " '.(Tools::getValue(' form_ask_name ', Configuration::get(' INVITE_ASK_NAME ')) == 1 ? ' checked = " checked " ' : ' ').' />
< label class = " t " for = " form_ask_name_on " > '.$this->l(' Yes ').' </ label >
</ p >
< p > </ p >
< p >
< label class = " t " > '.$this->l(' Show the referral link : ').' </ label >
& nbsp ;
< input type = " radio " name = " form_show_link " id = " form_show_link_off " value = " 0 " '.(Tools::getValue(' form_show_link ', Configuration::get(' INVITE_FORM_SHOWLINK ')) == 0 ? ' checked = " checked " ' : ' ').' />
< label class = " t " for = " form_show_link_off " > '.$this->l(' No ').' </ label >
& nbsp ;
< input type = " radio " name = " form_show_link " id = " form_show_link_on " value = " 1 " '.(Tools::getValue(' form_show_link ', Configuration::get(' INVITE_FORM_SHOWLINK ')) == 1 ? ' checked = " checked " ' : ' ').' />
< label class = " t " for = " form_show_link_on " > '.$this->l(' Yes ').' </ label >
</ p > ' ;
if ( Configuration :: get ( 'PS_REWRITING_SETTINGS' )) {
$this -> _html .= '
< p >
< label class = " t " > '.$this->l(' Referral link format : ').' </ label >
& nbsp ;
< input type = " radio " name = " form_link_format " id = " form_link_format_off " value = " 0 " '.(Tools::getValue(' form_link_format ', Configuration::get(' INVITE_FORM_LINKFORMAT ')) == 0 ? ' checked = " checked " ' : ' ').' />
< label class = " t " for = " form_link_format_off " > '.$this->l(' Clear ').' </ label >
& nbsp ;
< input type = " radio " name = " form_link_format " id = " form_link_format_on " value = " 1 " '.(Tools::getValue(' form_link_format ', Configuration::get(' INVITE_FORM_LINKFORMAT ')) == 1 ? ' checked = " checked " ' : ' ').' />
< label class = " t " for = " form_link_format_on " > '.$this->l(' Rewritten ').' </ label >
</ p >
< p >
< label class = " t " for = " rewrite " > '.$this->l(' Add this line to your custom rewrite rules : ').' </ label >
& nbsp ;
< input readonly = " true " type = " text " name = " time_limit " style = " width: 500px; " id = " rewrite " value = "
RewriteRule ^ invite / ( .* ) $ '.__PS_BASE_URI__.' modules / invite / sponsor . php ? sponsor = $ 1 [ QSA , L ] " />
</ p >
' ;
}
$this -> _html .= ' < p > </ p >
< p >
< label class = " t " > '.$this->l(' Enable customer credit : ').' </ label >
& nbsp ;
< input type = " radio " name = " credit_enable " id = " credit_enable_off " value = " 0 " '.(Tools::getValue(' credit_enable ', Configuration::get(' INVITE_CREDIT_ENABLE ')) == 0 ? ' checked = " checked " ' : ' ').' />
< label class = " t " for = " credit_enable_off " > '.$this->l(' No ').' </ label >
& nbsp ;
< input type = " radio " name = " credit_enable " id = " credit_enable_on " value = " 1 " '.(Tools::getValue(' credit_enable ', Configuration::get(' INVITE_CREDIT_ENABLE ')) == 1 ? ' checked = " checked " ' : ' ').' />
< label class = " t " for = " credit_enable_on " > '.$this->l(' Yes ').' </ label >
</ p >
< p >
< label class = " t " for = " credit_rate " > '.$this->l(' Credit conversion rate : ').' </ label >
& nbsp ; '.$this->l(' 1 credit ').' =
< input type = " text " name = " credit_rate " style = " width: 50px; " id = " credit_rate " value = " '.Configuration::get('INVITE_CREDIT_RATE').' " /> '.$defaultCurrency->sign.'
</ p >
< p >
< label class = " t " for = " credit_display " > '.$this->l(' Credit display on the front - office : ').' </ label >
& nbsp ;
< select id = " credit_display " name = " credit_display " >
< option value = " 0 " '.(Configuration::get(' INVITE_CREDIT_DISPLAY ') == 0? ' selected = " selected " ': ' ').' > '.$this->l(' Amount ( Value ) ').' </ option >
< option value = " 1 " '.(Configuration::get(' INVITE_CREDIT_DISPLAY ') == 1? ' selected = " selected " ': ' ').' > '.$this->l(' Value ( Amount ) ').' </ option >
< option value = " 2 " '.(Configuration::get(' INVITE_CREDIT_DISPLAY ') == 2? ' selected = " selected " ': ' ').' > '.$this->l(' Amount ').' </ option >
< option value = " 3 " '.(Configuration::get(' INVITE_CREDIT_DISPLAY ') == 3? ' selected = " selected " ': ' ').' > '.$this->l(' Value ').' </ option >
</ select >
</ p > ' ;
}
private function _tab_2 () {
global $cookie ;
$defaultLanguage = ( int )( Configuration :: get ( 'PS_LANG_DEFAULT' ));
$languages = Language :: getLanguages ( FALSE );
$iso = Language :: getIsoById ( $defaultLanguage );
$divLangName = 'cpara¤dd' ;
$iso = Language :: getIsoById (( int )( $cookie -> id_lang ));
$isoTinyMCE = ( file_exists ( _PS_ROOT_DIR_ . '/js/tiny_mce/langs/' . $iso . '.js' ) ? $iso : 'en' );
$ad = dirname ( $_SERVER [ " PHP_SELF " ]);
$rules = Configuration :: getInt ( 'INVITE_CONDITIONS' );
$this -> _html .= '
< label class = " t " style = " margin-bottom: 5px; display: block; float: none; text-align: left; padding-left: 0px; width: auto; " > '.$this->l(' Referral program conditions : ').' </ label >
< script type = " text/javascript " >
var iso = \ '' . $isoTinyMCE . ' \ ' ;
var pathCSS = \ '' . _THEME_CSS_DIR_ . ' \ ' ;
var ad = \ '' . $ad . ' \ ' ;
</ script >
< script type = " text/javascript " src = " '.__PS_BASE_URI__.'js/tiny_mce/tiny_mce.js " ></ script >
< script type = " text/javascript " src = " '.__PS_BASE_URI__.'js/tinymce.inc.js " ></ script >
< script language = " javascript " > id_language = Number ( '.$defaultLanguage.' ); </ script > ' ;
foreach ( $languages as $language ) {
$this -> _html .= '
< div id = " cpara_'. $language['id_lang'] .' " style = " display: '.( $language['id_lang'] == $defaultLanguage ? 'block' : 'none').';float: left; " >
< textarea class = " rte " cols = " 120 " rows = " 25 " id = " conditions_'. $language['id_lang'] .' " name = " conditions['. $language['id_lang'] .'] " > '.$rules[$language[' id_lang ']].' </ textarea >
</ div > ' ;
}
$this -> _html .= $this -> displayFlags ( $languages , $defaultLanguage , $divLangName , 'cpara' , TRUE );
}
private function _tab_3 () {
global $cookie ;
$groups = Group :: getGroups ( $cookie -> id_lang );
$currencies = Currency :: getCurrencies ();
$defaultLanguage = ( int )( Configuration :: get ( 'PS_LANG_DEFAULT' ));
$languages = Language :: getLanguages ( FALSE );
$iso = Language :: getIsoById ( $defaultLanguage );
$divLangName = 'cpara¤dd' ;
$iso = Language :: getIsoById (( int )( $cookie -> id_lang ));
// TODO: give products, or a percent of the sponsored order
$this -> _html .= '
< script type = " text/javascript " >
var groups = '.json_encode($groups).' ;
var currencies = '.json_encode($currencies).' ;
function showValue ( el , ed ) {
$ ( " #sponsor " + ( ed ? " ed " : " " ) + " _reward_valueform " ) . remove ();
if ( $ ( el ) . val () == 1 || $ ( el ) . val () == 2 || $ ( el ) . val () == 3 ) {
var t = " \
< div id = \ " sponsor " + ( ed ? " ed " : " " ) + " _reward_valueform \" > \
< label class = \ " t \" style= \" margin-bottom: 5px; display: block; float: none; text-align: left; padding-left: 0px; \" >'. $this->l ('Value:').'</label> \
< table class = \ " table \" cellspacing= \" 0 \" > \
< thead > \
< tr > \
< th > '.$this->l(' Group ').' </ th > \
< th > '.$this->l(' Value ').' </ th > \
</ tr > \
</ thead > \
< tfoot > \
< tr > \
< th > '.$this->l(' Group ').' </ th > \
< th > '.$this->l(' Value ').' </ th > \
</ tr > \
</ tfoot > \
< tbody > " ;
$ ( groups ) . each ( function ( id , item ) {
t += " \
< tr > \
< td > " + item[ " name " ] + " </ td > \
< td >< input type = \ " text \" value= \" \" style= \" text-align: right; \" name= \" sponsor " + ( ed ? " ed " : " " ) + " _reward_value[ " + item [ " id_group " ] + " ] \" /></td> \
</ tr > " ;
});
t += " \
</ tbody > \
</ table > \
</ div > " ;
$ ( t ) . insertAfter ( $ ( el ) . parent () . next ());
} else if ( $ ( el ) . val () == 4 ) {
var t = " \
< div id = \ " sponsor " + ( ed ? " ed " : " " ) + " _reward_valueform \" > \
< label class = \ " t \" style= \" margin-bottom: 5px; display: block; float: none; text-align: left; padding-left: 0px; \" >'. $this->l ('Value:').'</label> \
< table class = \ " table \" cellspacing= \" 0 \" > \
< thead > \
< tr > \
< th > '.$this->l(' Group ').' </ th > \
< th > '.$this->l(' Currency ').' </ th > \
< th > '.$this->l(' Value ').' </ th > \
</ tr > \
</ thead > \
< tfoot > \
< tr > \
< th > '.$this->l(' Group ').' </ th > \
< th > '.$this->l(' Currency ').' </ th > \
< th > '.$this->l(' Value ').' </ th > \
</ tr > \
</ tfoot > \
< tbody > " ;
$ ( groups ) . each ( function ( id , item ) {
$ ( currencies ) . each ( function ( id2 , item2 ) {
t += " <tr> " ;
if ( id2 == 0 ) {
t += " <td rowspan= \" " + currencies . length + " \" > " + item [ " name " ] + " </td> " ;
}
t += " <td> " + item2 [ " name " ] + " </td> \
< td >< input type = \ " text \" style= \" text-align: right; \" value= \" \" name= \" sponsor " + ( ed ? " ed " : " " ) + " _reward_value[ " + item [ " id_group " ] + " ][ " + item2 [ " id_currency " ] + " ] \" /></td> \
</ tr > " ;
});
});
t += " \
</ tbody > \
</ table > \
</ div > " ;
$ ( t ) . insertAfter ( $ ( el ) . parent () . next ());
}
}
</ script >
< p >
< label class = " t " for = " sponsor_reward_type " > '.$this->l(' Sponsor reward : ').' </ label >
& nbsp ;
< select id = " sponsor_reward_type " name = " sponsor_reward_type " onchange = " showValue(this, 0); " >
< option value = " 0 " '.(Configuration::get(' INVITE_REWARD_SPONSOR_TYPE ') == 0? ' selected = " selected " ': ' ').' > '.$this->l(' Nothing ').' </ option >
< option value = " 1 " '.(Configuration::get(' INVITE_REWARD_SPONSOR_TYPE ') == 1? ' selected = " selected " ': ' ').' > '.$this->l(' Credit ').' </ option >
< option value = " 2 " '.(Configuration::get(' INVITE_REWARD_SPONSOR_TYPE ') == 2? ' selected = " selected " ': ' ').' > '.$this->l(' Loyalty points ').' </ option >
< option value = " 3 " '.(Configuration::get(' INVITE_REWARD_SPONSOR_TYPE ') == 3? ' selected = " selected " ': ' ').' > '.$this->l(' Voucher ( % ) ').' </ option >
< option value = " 4 " '.(Configuration::get(' INVITE_REWARD_SPONSOR_TYPE ') == 4? ' selected = " selected " ': ' ').' > '.$this->l(' Voucher ( amount ) ').' </ option >
< option value = " 5 " '.(Configuration::get(' INVITE_REWARD_SPONSOR_TYPE ') == 5? ' selected = " selected " ': ' ').' > '.$this->l(' Voucher ( free shipping ) ').' </ option >
</ select >
</ p >
< p >
< label class = " t " for = " sponsor_reward_on " > '.$this->l(' Give the sponsor a reward on : ').' </ label >
& nbsp ;
< select id = " sponsor_reward_on " name = " sponsor_reward_on " >
< option value = " 0 " '.(Configuration::get(' INVITE_REWARD_SPONSOR_ON ') == 0? ' selected = " selected " ': ' ').' > '.$this->l(' The sponsored registration ').' </ option >
< option value = " 1 " '.(Configuration::get(' INVITE_REWARD_SPONSOR_ON ') == 1? ' selected = " selected " ': ' ').' > '.$this->l(' The sponsored first order ').' </ option >
</ select >
</ p > ' ;
if ( Configuration :: get ( 'INVITE_REWARD_SPONSOR_TYPE' ) == 1
|| Configuration :: get ( 'INVITE_REWARD_SPONSOR_TYPE' ) == 2
|| Configuration :: get ( 'INVITE_REWARD_SPONSOR_TYPE' ) == 3 ) {
$this -> _html .= '
< div id = " sponsor_reward_valueform " >
< label class = " t " style = " margin-bottom: 5px; display: block; float: none; text-align: left; padding-left: 0px; " > '.$this->l(' Value : ').' </ label >
< table class = " table " cellspacing = " 0 " >
< thead >
< tr >
< th > '.$this->l(' Group ').' </ th >
< th > '.$this->l(' Value ').' </ th >
</ tr >
</ thead >
< tfoot >
< tr >
< th > '.$this->l(' Group ').' </ th >
< th > '.$this->l(' Value ').' </ th >
</ tr >
</ tfoot >
< tbody > ' ;
foreach ( $groups as $group ) {
$this -> _html .= '
< tr >
< td > '.$group[' name '].' </ td >
< td >< input type = " text " style = " text-align: right; " value = " '.Configuration::get('INVITE_REWARD_SPONSOR_VALUE_'. $group['id_group'] ).' " name = " sponsor_reward_value['. $group['id_group'] .'] " /></ td >
</ tr >
' ;
}
$this -> _html .= '
</ tbody >
</ table >
</ div > ' ;
} elseif ( Configuration :: get ( 'INVITE_REWARD_SPONSOR_TYPE' ) == 4 ) {
$this -> _html .= '
< div id = " sponsor_reward_valueform " >
< label class = " t " style = " margin-bottom: 5px; display: block; float: none; text-align: left; padding-left: 0px; " > '.$this->l(' Value : ').' </ label >
< table class = " table " cellspacing = " 0 " >
< thead >
< tr >
< th > '.$this->l(' Group ').' </ th >
< th > '.$this->l(' Currency ').' </ th >
< th > '.$this->l(' Value ').' </ th >
</ tr >
</ thead >
< tfoot >
< tr >
< th > '.$this->l(' Group ').' </ th >
< th > '.$this->l(' Currency ').' </ th >
< th > '.$this->l(' Value ').' </ th >
</ tr >
</ tfoot >
< tbody > ' ;
foreach ( $groups as $group ) {
$i = 0 ;
foreach ( $currencies as $currency ) {
$this -> _html .= '
< tr >
'.($i === 0? ' < td rowspan = " '.count( $currencies ).' " > '.$group[' name '].' </ td > ': ' ').'
< td > '.$currency[' name '].' </ td >
< td >< input type = " text " style = " text-align: right; " value = " '.Configuration::get('INVITE_REWARD_SPONSOR_VALUE_'. $group['id_group'] .'_'. $currency['id_currency'] ).' " name = " sponsor_reward_value['. $group['id_group'] .']['. $currency['id_currency'] .'] " /></ td >
</ tr >
' ;
$i = 1 ;
}
}
$this -> _html .= '
</ tbody >
</ table >
</ div > ' ;
}
$this -> _html .= '
< p > </ p >< p > </ p >< p > </ p >< p > </ p >
< p >
< label class = " t " > '.$this->l(' Sponsored reward : ').' </ label >
& nbsp ;
< select name = " sponsored_reward_type " onchange = " showValue(this, 1); " >
< option value = " 0 " > '.$this->l(' Nothing ').' </ option >
< option value = " 1 " > '.$this->l(' Credit ').' </ option >
< option value = " 2 " > '.$this->l(' Loyalty points ').' </ option >
< option value = " 3 " > '.$this->l(' Voucher ( % ) ').' </ option >
< option value = " 4 " > '.$this->l(' Voucher ( amount ) ').' </ option >
< option value = " 5 " > '.$this->l(' Voucher ( free shipping ) ').' </ option >
</ select >
</ p >
< p >
< label class = " t " for = " sponsored_reward_on " > '.$this->l(' Give the sponsored a reward on : ').' </ label >
& nbsp ;
< select id = " sponsored_reward_on " name = " sponsored_reward_on " >
< option value = " 0 " '.(Configuration::get(' INVITE_REWARD_SPONSORED_ON ') == 0? ' selected = " selected " ': ' ').' > '.$this->l(' Registration ').' </ option >
< option value = " 1 " '.(Configuration::get(' INVITE_REWARD_SPONSORED_ON ') == 1? ' selected = " selected " ': ' ').' > '.$this->l(' His / Her first order ').' </ option >
</ select >
</ p > ' ;
if ( Configuration :: get ( 'INVITE_REWARD_SPONSORED_TYPE' ) == 1
|| Configuration :: get ( 'INVITE_REWARD_SPONSORED_TYPE' ) == 2
|| Configuration :: get ( 'INVITE_REWARD_SPONSORED_TYPE' ) == 3 ) {
$this -> _html .= '
< div id = " sponsored_reward_valueform " >
< label class = " t " style = " margin-bottom: 5px; display: block; float: none; text-align: left; padding-left: 0px; " > '.$this->l(' Value : ').' </ label >
< table class = " table " cellspacing = " 0 " >
< thead >
< tr >
< th > '.$this->l(' Group ').' </ th >
< th > '.$this->l(' Value ').' </ th >
</ tr >
</ thead >
< tfoot >
< tr >
< th > '.$this->l(' Group ').' </ th >
< th > '.$this->l(' Value ').' </ th >
</ tr >
</ tfoot >
< tbody > ' ;
foreach ( $groups as $group ) {
$this -> _html .= '
< tr >
< td > '.$group[' name '].' </ td >
< td >< input type = " text " style = " text-align: right; " value = " '.Configuration::get('INVITE_REWARD_SPONSORED_VALUE_'. $group['id_group'] ).' " name = " sponsored_reward_value['. $group['id_group'] .'] " /></ td >
</ tr >
' ;
}
$this -> _html .= '
</ tbody >
</ table >
</ div > ' ;
} elseif ( Configuration :: get ( 'INVITE_REWARD_SPONSORED_TYPE' ) == 4 ) {
$this -> _html .= '
< div id = " sponsored_reward_valueform " >
< label class = " t " style = " margin-bottom: 5px; display: block; float: none; text-align: left; padding-left: 0px; " > '.$this->l(' Value : ').' </ label >
< table class = " table " cellspacing = " 0 " >
< thead >
< tr >
< th > '.$this->l(' Group ').' </ th >
< th > '.$this->l(' Currency ').' </ th >
< th > '.$this->l(' Value ').' </ th >
</ tr >
</ thead >
< tfoot >
< tr >
< th > '.$this->l(' Group ').' </ th >
< th > '.$this->l(' Currency ').' </ th >
< th > '.$this->l(' Value ').' </ th >
</ tr >
</ tfoot >
< tbody > ' ;
foreach ( $groups as $group ) {
$i = 0 ;
foreach ( $currencies as $currency ) {
$this -> _html .= '
< tr >
'.($i === 0? ' < td rowspan = " '.count( $currencies ).' " > '.$group[' name '].' </ td > ': ' ').'
< td > '.$currency[' name '].' </ td >
< td >< input type = " text " value = " '.Configuration::get('INVITE_REWARD_SPONSORED_VALUE_'. $group['id_group'] .'_'. $currency['id_currency'] ).' " style = " text-align: right; " name = " sponsored_reward_value['. $group['id_group'] .']['. $currency['id_currency'] .'] " /></ td >
</ tr >
' ;
$i = 1 ;
}
}
$this -> _html .= '
</ tbody >
</ table >
</ div > ' ;
}
$this -> _html .= '
< p > </ p >< p > </ p >< p > </ p >< p > </ p >
< label class = " t " style = " margin-bottom: 5px; display: block; float: none; text-align: left; padding-left: 0px; " > '.$this->l(' Vouchers parameters ').' </ label >
< p >
< label class = " t " for = " discount_reward_prefix " > '.$this->l(' Prefix : ').' </ label >
& nbsp ;
< input type = " text " name = " discount_reward_prefix " style = " width: 50px; " id = " discount_reward_prefix " value = " '.Configuration::get('INVITE_DISCOUNT_PREFIX').' " />
</ p >
< div style = " overflow: auto; " >< label class = " t " for = " discount_reward_description " style = " margin-right: 8px; float: left; text-align: left; width: auto; padding-top: 3px; " > '.$this->l(' Description : ').' </ label > ' ;
$description = Configuration :: getInt ( 'INVITE_DISCOUNT_DESCRIPTION' );
foreach ( $languages AS $language ) {
$this -> _html .= '
< div id = " dd_'. $language['id_lang'] .' " style = " display: '.( $language['id_lang'] == $defaultLanguage ? 'block' : 'none').'; float: left; margin-left: 4px; " >
< input type = " text " name = " discount_reward_description['. $language['id_lang'] .'] " id = " discount_reward_description['. $language['id_lang'] .'] " value = " '.(isset( $_POST['discount_reward_description'] [(int)( $language['id_lang'] )]) ? $_POST['discount_reward_description'] [(int)( $language['id_lang'] )] : $description[(int)($language['id_lang'] )]).' " style = " width: 200px; " />
</ div > ' ;
}
$this -> _html .= $this -> displayFlags ( $languages , $defaultLanguage , $divLangName , 'dd' , TRUE ) . '</div>' ;
$this -> _html .= '
< p style = " clear: both; " >
< label class = " t " for = " discount_reward_validity " > '.$this->l(' Validity ( days ) : ').' </ label >
& nbsp ;
< input type = " text " name = " discount_reward_validity " style = " width: 50px; " id = " discount_reward_validity " value = " '.Configuration::get('INVITE_DISCOUNT_VALIDITY').' " />
</ p >
< p >
< label class = " t " > '.$this->l(' Cumulable : ').' </ label >
& nbsp ;
< input type = " radio " name = " discount_reward_cumulable " id = " discount_reward_cumulable_off " value = " 0 " '.(Tools::getValue(' discount_reward_cumulable ', Configuration::get(' INVITE_DISCOUNT_CUMULABLE ')) == 0 ? ' checked = " checked " ' : ' ').' />
< label class = " t " for = " discount_reward_cumulable_off " > '.$this->l(' No ').' </ label >
& nbsp ;
< input type = " radio " name = " discount_reward_cumulable " id = " discount_reward_cumulable_on " value = " 1 " '.(Tools::getValue(' discount_reward_cumulable ', Configuration::get(' INVITE_DISCOUNT_CUMULABLE ')) == 1 ? ' checked = " checked " ' : ' ').' />
< label class = " t " for = " discount_reward_cumulable_on " > '.$this->l(' Yes ').' </ label >
</ p >
< p >
< label class = " t " > '.$this->l(' Cumulable with specials : ').' </ label >
& nbsp ;
< input type = " radio " name = " discount_reward_cumulable_specials " id = " discount_reward_cumulable_specials_off " value = " 0 " '.(Tools::getValue(' discount_reward_cumulable_specials ', Configuration::get(' INVITE_DISCOUNT_CUMULABLE_REDUC ')) == 0 ? ' checked = " checked " ' : ' ').' />
< label class = " t " for = " discount_reward_cumulable_specials_off " > '.$this->l(' No ').' </ label >
& nbsp ;
< input type = " radio " name = " discount_reward_cumulable_specials " id = " discount_reward_cumulable_specials_on " value = " 1 " '.(Tools::getValue(' discount_reward_cumulable_specials ', Configuration::get(' INVITE_DISCOUNT_CUMULABLE_REDUC ')) == 1 ? ' checked = " checked " ' : ' ').' />
< label class = " t " for = " discount_reward_cumulable_specials_on " > '.$this->l(' Yes ').' </ label >
</ p >
< p >
< label class = " t " > '.$this->l(' Show on cart : ').' </ label >
& nbsp ;
< input type = " radio " name = " discount_reward_cart " id = " discount_reward_cart_off " value = " 0 " '.(Tools::getValue(' discount_reward_cart ', Configuration::get(' INVITE_DISCOUNT_CART ')) == 0 ? ' checked = " checked " ' : ' ').' />
< label class = " t " for = " discount_reward_cart_off " > '.$this->l(' No ').' </ label >
& nbsp ;
< input type = " radio " name = " discount_reward_cart " id = " discount_reward_cart_on " value = " 1 " '.(Tools::getValue(' discount_reward_cart ', Configuration::get(' INVITE_DISCOUNT_CART ')) == 1 ? ' checked = " checked " ' : ' ').' />
< label class = " t " for = " discount_reward_cart_on " > '.$this->l(' Yes ').' </ label >
</ p >
< p style = " clear: both; " >
< label class = " t " for = " discount_reward_minimal " > '.$this->l(' Minimal order amount : ').' </ label >
& nbsp ;
< input type = " text " name = " discount_reward_minimal " style = " width: 50px; text-align: right; " id = " discount_reward_minimal " value = " '.Configuration::get('INVITE_DISCOUNT_MINIMAL').' " />
< select name = " discount_reward_minimal_wt " style = " height: 21px; " >
< option value = " 0 " '.(Configuration::get(' INVITE_DISCOUNT_MINIMAL_WT ') == 0? ' selected = " selected " ': ' ').' > '.$this->l(' without taxes ').' </ option >
< option value = " 1 " '.(Configuration::get(' INVITE_DISCOUNT_MINIMAL_WT ') == 1? ' selected = " selected " ': ' ').' > '.$this->l(' with taxes ').' </ option >
</ select >
</ p > ' ;
}
private function _tab_4 () {
$this -> _html .= '
< script type = " text/javascript " >
function updateSelects () {
var disabled_plugins = [];
$ ( " #select_openinviter_plugins_disabled option " ) . each ( function ( id , value ) {
disabled_plugins [ disabled_plugins . length ] = $ ( value ) . val ();
});
var enabled_plugins = [];
$ ( " #select_openinviter_plugins_enabled option " ) . each ( function ( id , value ) {
enabled_plugins [ enabled_plugins . length ] = $ ( value ) . val ();
});
$ ( " #openinviter_plugins_disabled " ) . attr ( " value " , disabled_plugins . join ( " , " ));
$ ( " #openinviter_plugins_enabled " ) . attr ( " value " , enabled_plugins . join ( " , " ));
}
function enablePlugins () {
var to_enable = $ ( " #select_openinviter_plugins_disabled " ) . val ();
$ ( " #select_openinviter_plugins_disabled option:selected " ) . remove ();
$ ( to_enable ) . each ( function ( id , value ) {
$ ( document . createElement ( " option " )) . attr ( " value " , value ) . text ( value ) . appendTo ( $ ( " #select_openinviter_plugins_enabled " ));
});
updateSelects ();
}
function disablePlugins () {
var to_disable = $ ( " #select_openinviter_plugins_enabled " ) . val ();
$ ( " #select_openinviter_plugins_enabled option:selected " ) . remove ();
$ ( to_disable ) . each ( function ( id , value ) {
$ ( document . createElement ( " option " )) . attr ( " value " , value ) . text ( value ) . appendTo ( $ ( " #select_openinviter_plugins_disabled " ));
});
updateSelects ();
}
</ script >
< p >
< label class = " t " > '.$this->l(' Enable OpenInviter : ').' </ label >
& nbsp ;
< input type = " radio " name = " openinviter_enable " id = " openinviter_enable_off " value = " 0 " '.(Tools::getValue(' openinviter_enable ', Configuration::get(' INVITE_OPENINVITER_ENABLE ')) == 0 ? ' checked = " checked " ' : ' ').' />
< label class = " t " for = " openinviter_enable_off " > '.$this->l(' No ').' </ label >
& nbsp ;
< input type = " radio " name = " openinviter_enable " id = " openinviter_enable_on " value = " 1 " '.(Tools::getValue(' openinviter_enable ', Configuration::get(' INVITE_OPENINVITER_ENABLE ')) == 1 ? ' checked = " checked " ' : ' ').' />
< label class = " t " for = " openinviter_enable_on " > '.$this->l(' Yes ').' </ label >
</ p >
< p > </ p >
< p >
< label class = " t " for = " openinviter_username " > '.$this->l(' Username : ').' </ label >
& nbsp ;
< input type = " text " name = " openinviter_username " id = " openinviter_username " value = " " />
</ p >
< p >
< label class = " t " for = " openinviter_pk " > '.$this->l(' Private key : ').' </ label >
& nbsp ;
< input type = " text " name = " openinviter_pk " id = " openinviter_pk " value = " " />
</ p >
< p >
< label class = " t " for = " openinviter_cookiespath " > '.$this->l(' Path to the cookies directory : ').' </ label >
& nbsp ;
< input type = " text " name = " openinviter_cookiespath " id = " openinviter_cookiespath " value = " " style = " width: 400px; " />
</ p >
< p > </ p >
< label style = " display: block; float: none; text-align: left; padding: 0px; margin: 0px 0px 10px; " > '.$this->l(' Plugins ').' </ label >
< select name = " select_openinviter_plugins_disabled[] " id = " select_openinviter_plugins_disabled " style = " width: 200px; height: 300px; float: left; margin-left: 200px; " multiple = " multiple " > ' ;
$plugins = $this -> _get_oi_plugins ( FALSE );
foreach ( $plugins as $plugin ) {
$this -> _html .= '<option value="' . $plugin . '" style="padding: 0px 2px;">' . $plugin . '</option>' ;
}
$this -> _html .= ' </ select >
< input type = " hidden " id = " openinviter_plugins_disabled " name = " openinviter_plugins_disabled " value = " '.implode(',', $plugins ).' " >
< div style = " height: 180px; float: left; padding: 120px 10px 0px; " >
< a class = " button " onclick = " disablePlugins();return false; " style = " padding: 5px 10px; display: block; cursor: pointer; text-align: center; " >& lt ; '.$this->l(' Disable ').' </ a >< br />
< a class = " button " onclick = " enablePlugins();return false; " style = " padding: 5px 10px; display: block; cursor: pointer; text-align: center; " > '.$this->l(' Enable ').' & gt ; </ a >
</ div > ' ;
$plugins = $this -> _get_oi_plugins ();
$this -> _html .= '<select name="select_openinviter_plugins_enabled[]" id="select_openinviter_plugins_enabled" style="width: 200px; height: 300px; float: left;" multiple="multiple">' ;
foreach ( $plugins as $plugin ) {
$this -> _html .= '<option value="' . $plugin . '" style="padding: 0px 2px;">' . $plugin . '</option>' ;
}
$this -> _html .= ' </ select >
< input type = " hidden " id = " openinviter_plugins_enabled " name = " openinviter_plugins_enabled " value = " '.implode(',', $plugins ).' " >
< p class = " clear " ></ p > ' ;
}
private function _tab_5 () {
$this -> _html .= '
< p > '.$this->l(' This tab allows you to import referrals from the referralprogram module or from the previous version of this module . ').' </ p >
< p >< strong > '.$this->l(' Note : ').' </ strong > '.$this->l(' clicking on the import button will discard any modification made in the other tabs . ').' </ p >
< p > </ p >
< p >
< label class = " t " for = " time_limit " > '.$this->l(' Time limit for the import : ').' </ label >
& nbsp ;
< input type = " text " name = " time_limit " style = " width: 30px; text-align: right; " id = " time_limit " value = " '.ini_get('max_execution_time').' " /> '.$this->l(' seconds ').'
</ p >
< p >
< label class = " t " > '.$this->l(' Reset existing credit values : ').' </ label >
& nbsp ;
< input type = " radio " name = " reset_credit " id = " reset_credit_off " value = " 0 " '.(Tools::getValue(' reset_credit ', 0) == 0 ? ' checked = " checked " ' : ' ').' />
< label class = " t " for = " reset_credit_off " > '.$this->l(' No ').' </ label >
& nbsp ;
< input type = " radio " name = " reset_credit " id = " reset_credit_on " value = " 1 " '.(Tools::getValue(' reset_credit ', 0) == 1 ? ' checked = " checked " ' : ' ').' />
< label class = " t " for = " reset_credit_on " > '.$this->l(' Yes ').' </ label >
</ p >
< div class = " clear center " >< input class = " button " style = " margin-top: 10px " name = " submitImport " value = " '. $this->l ('Import').' " type = " submit " /></ div > ' ;
}
private function _manage_oi_plugins ( $to_disable = FALSE , $to_enable = FALSE ) {
if ( $to_disable !== FALSE && $to_enable !== FALSE ) {
$to_disable = explode ( ',' , str_replace ( array ( '.' , '..' , '/' , '\\' ), '' , $to_disable ));
$to_enable = explode ( ',' , str_replace ( array ( '.' , '..' , '/' , '\\' ), '' , $to_enable ));
$path = dirname ( __FILE__ ) . '/openinviter/' ;
foreach ( $to_disable as $plugin ) {
@ rename ( $path . 'conf/' . $plugin . '.conf' , $path . 'conf_disabled/' . $plugin . '.conf' );
@ rename ( $path . 'plugins/' . $plugin . '.plg.php' , $path . 'plugins_disabled/' . $plugin . '.plg.php' );
}
foreach ( $to_enable as $plugin ) {
@ rename ( $path . 'conf_disabled/' . $plugin . '.conf' , $path . 'conf/' . $plugin . '.conf' );
@ rename ( $path . 'plugins_disabled/' . $plugin . '.plg.php' , $path . 'plugins/' . $plugin . '.plg.php' );
}
include ( dirname ( __FILE__ ) . '/openinviter/config.php' );
@ unlink ( $openinviter_settings [ 'cookie_path' ] . '/oi_plugins.php' );
}
}
private function _write_oi_config ( $username = FALSE , $pk = FALSE , $path = FALSE ) {
if ( $username !== FALSE && $pk !== FALSE && ! empty ( $username ) && ! empty ( $pk )) {
@ file_put_contents ( dirname ( __FILE__ ) . '/openinviter/config.php' , ' < ? php
$openinviter_settings = array (
\ 'username\'=>\'' . addslashes ( $username ) . ' \ ' ,
\ 'private_key\'=>\'' . addslashes ( $pk ) . ' \ ' ,
\ 'cookie_path\'=>' . ( $path !== FALSE && ! empty ( $path ) ? '\'' . $path . '\'' : 'dirname(__FILE__).\'/cookies\'' ) . ' ,
\ ' message_body\ ' => \ ' \ ' ,
\ ' message_subject\ ' => \ ' \ ' ,
\ ' transport\ ' => \ ' curl\ ' , // curl or wget
\ ' local_debug\ ' => \ ' on_error\ ' , // on_error => log only requests containing errors; always => log all requests; false => don`t log anything
\ ' remote_debug\ ' => FALSE , // When set to TRUE OpenInviter sends debug information to our servers. Set it to FALSE to disable this feature
\ ' hosted\ ' => FALSE , //When set to TRUE OpenInviter uses the OpenInviter Hosted Solution servers to import the contacts.
\ ' proxies\ ' => array (), //If you want to use a proxy in OpenInviter by adding another key to the array. Example: \'proxy_1\'=>array(\'host\'=>\'1.2.3.4\',\'port\'=>\'8080\',\'user\'=>\'user\',\'password\'=>\'pass\')
//You can add as many proxies as you want and OpenInviter will randomly choose which one to use on each import.
\ ' stats\ ' => TRUE ,
\ ' plugins_cache_time\ ' => 1800 ,
\ ' plugins_cache_file\ ' => \ ' oi_plugins . php\ ' ,
\ ' update_files\ ' => true ,
\ ' stats_user\ ' => \ ' \ ' , //Required to access the stats
\ ' stats_password\ ' => \ ' \ ' //Required to access the stats
);
?> ');
}
}
public function hookCustomerAccount ( $params ) {
return $this -> display ( __FILE__ , 'my-account.tpl' );
}
public function hookMyAccountBlock ( $params ) {
return $this -> hookCustomerAccount ( $params );
}
public function hookCreateAccountForm ( $params ) {
global $smarty , $site_version_front ;
if ( $firstname = Tools :: getValue ( 'firstname' )) {
$_POST [ 'firstname' ] = $firstname ;
}
if ( $lastname = Tools :: getValue ( 'lastname' )) {
$_POST [ 'lastname' ] = $lastname ;
}
if ( $email = Tools :: getValue ( 'email' )) {
$_POST [ 'email' ] = $email ;
}
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 ;
$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 ( Module :: isInstalled ( 'trackingtag' ) && Db :: getInstance () -> getRow ( '
SELECT `id_trackingtag`
FROM `'._DB_PREFIX_.'trackingtag`
WHERE `sponsor` = " '.pSQL( $email ).' "
AND `version` = " '.pSQL( $site_version_front ).' "
AND `enabled` = 1
' )) {
$smarty -> assign ( array (
'hide_sponsor' => TRUE ,
));
//get tracking info
$tr_infos = Db :: getInstance () -> getRow ( '
SELECT *
FROM `'._DB_PREFIX_.'trackingtag`
WHERE ( `date_start` <= NOW () OR `date_start` = " 0000-00-00 00:00:00 " )
AND ( `date_end` > NOW () OR `date_end` = " 0000-00-00 00:00:00 " )
AND `enabled` = 1
AND `version` = " '.pSQL( $site_version_front ).' "
AND `sponsor` = " '.pSQL( $email ).' "
' );
if ( ! empty ( $tr_infos [ 'tag_auth' ])) {
$smarty -> assign ( array (
'tag_auth' => $tr_infos [ 'tag_auth' ],
));
}
}
if ( $c = Db :: getInstance () -> getRow ( '
SELECT i . `email`
FROM `'._DB_PREFIX_.'invite` i
WHERE i . `id_sponsor` = '.(int) $customer->id.'
AND i . `id_invite` = '.(int) $id_invite.'
' )) {
$_POST [ 'email' ] = $c [ 'email' ];
}
}
}
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' );
}
}
// 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);
// }
return $this -> display ( __FILE__ , 'authentication.tpl' );
}
public function hookPreProcess ( $params ) {
global $cookie ;
if ( Configuration :: get ( 'INVITE_CREDIT_ENABLE' ) == 1 && $cookie -> isLogged ()) {
global $smarty , $page_name , $cart ;
$smarty -> assign ( 'customer_credit' , $this -> _get_credit (( int ) $cookie -> id_customer , FALSE , FALSE , 'frontoffice' ));
if ( $page_name == 'order' && $cart -> nbProducts () && isset ( $_GET [ 'deleteDiscount' ]) && Validate :: isUnsignedId ( $_GET [ 'deleteDiscount' ])) {
$discount = new Discount (( int ) $_GET [ 'deleteDiscount' ]);
if ( substr ( $discount -> name , 0 , strlen ( Configuration :: get ( 'INVITE_DISCOUNT_PREFIX' ))) == Configuration :: get ( 'INVITE_DISCOUNT_PREFIX' ) && ( int ) $discount -> id_customer == ( int ) $cookie -> id_customer ) {
$this -> set_credit_value ( $cookie -> id_customer , $this -> get_credit_value ( $cookie -> id_customer ) + ( float ) $discount -> value );
$discount -> delete ();
}
}
}
}
public function get_credit_value ( $id_customer = 0 ) {
global $cookie ;
if ( Configuration :: get ( 'INVITE_CREDIT_ENABLE' ) == 1 && $cookie -> isLogged ()) {
return $this -> _get_credit (( int ) $cookie -> id_customer , TRUE );
}
}
public function set_credit_value ( $id_customer = 0 , $value = 0 ) {
global $cookie ;
if ( Configuration :: get ( 'INVITE_CREDIT_ENABLE' ) == 1 && $cookie -> isLogged ()) {
Db :: getInstance () -> Execute ( '
UPDATE `'._DB_PREFIX_.'invite_credit`
SET `credit` = '.((float) $value / Configuration::get(' INVITE_CREDIT_RATE ')).'
WHERE `id_customer` = ' . ( int ) $id_customer
);
}
}
public function hookAdminCustomers ( $params ) {
global $cookie ;
$customer = new Customer (( int ) $params [ 'id_customer' ]);
if ( ! Validate :: isLoadedObject ( $customer ))
die ( Tools :: displayError ( 'Incorrect object Customer.' ));
$result = '' ;
if ( Configuration :: get ( 'INVITE_CREDIT_ENABLE' ) == 1 ) {
$credit = $this -> _get_credit ( $customer -> id , FALSE , FALSE , 'info' );
$result .= '
< div class = " clear " >& nbsp ; </ div >< br />
< h2 > '.$this->l(' Customer credit : ').' '.$credit.' </ h2 > ' ;
}
$sponsor = $this -> _get_sponsor ( $customer -> id );
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 ( $customer -> 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|' . $customer -> email . '|' ));
}
$result .= '
< div class = " clear " >& nbsp ; </ div >
< h2 > '.$this->l(' Referral program ').' </ h2 >
< h3 > '.$this->l(' Invite link : ').' </ h3 >
< input type = " text " style = " width: 800px " onclick = " $ (this).select(); " value = " '. $invitelink .' " />
< br />< br />< br />
< h3 > '.($sponsor? $this->l(' Customer\ 's sponsor:' ) . ' <a href="index.php?tab=AdminCustomers&id_customer=' . ( int ) $sponsor [ 'id_customer' ] . '&viewcustomer&token=' . Tools :: getAdminToken ( 'AdminCustomers' . ( int ) Tab :: getIdFromClassName ( 'AdminCustomers' ) . ( int ) $cookie -> id_employee ) . '">' . $sponsor [ 'firstname' ] . ' ' . $sponsor [ 'lastname' ] . '</a>' : $this -> l ( 'No one has sponsored this customer.' )) . ' </ h3 >
< br />
< h3 > '.$this->l(' Customer\ 's pending friends:' ) . ' </ h3 >
< button onclick = " var btn = $ (this); btn.attr( \ 'disabled \ ', \ 'disabled \ '); $ .ajax( {
url : \ '' . __PS_BASE_URI__ . 'modules/invite/ajax_friends.php?id=' . $customer -> id . '&pending=1&adtoken=' . Tools :: encrypt ( 'InviteAdmFriendsPending' . $customer -> id ) . ' \ ' ,
success : function ( response ) {
btn . replaceWith ( response )
}
}); " class= " button " >'. $this->l ('Click here to load the friends list').'</button>
< br />< br />< br />
< h3 > '.$this->l(' Customer\ 's friends:' ) . ' </ h3 >
< p > Nb filleuls : '.(int) $this->getNbFriends((int) $customer->id).' </ p >
< button onclick = " var btn = $ (this); btn.attr( \ 'disabled \ ', \ 'disabled \ '); $ .ajax( {
url : \ '' . __PS_BASE_URI__ . 'modules/invite/ajax_friends.php?id=' . $customer -> id . '&adtoken=' . Tools :: encrypt ( 'InviteAdmFriends' . $customer -> id ) . ' \ ' ,
success : function ( response ) {
btn . replaceWith ( response )
}
}); " class= " button " >'. $this->l ('Click here to load the friends list').'</button>
' ;
return $result . '<br /><br />' ;
}
private function _get_credit ( $id_customer = FALSE , $value = FALSE , $with_sign = FALSE , $mode = FALSE ) {
$credit = Db :: getInstance () -> ExecuteS ( '
SELECT *
FROM `'._DB_PREFIX_.'invite_credit`
WHERE `id_customer` = ' . ( int ) $id_customer
);
if ( count ( $credit ) == 0 ) {
$credit = 0 ;
} else {
$credit = $credit [ 0 ][ 'credit' ];
}
if ( $mode === FALSE ) {
if ( ! $value ) {
return $credit ;
} else {
$value = $credit * Configuration :: get ( 'INVITE_CREDIT_RATE' );
if ( ! $with_sign ) {
return $value ;
} else {
$currency = Currency :: getDefaultCurrency ();
return $value . ' ' . $currency -> sign ;
}
}
} else {
$value = $credit * Configuration :: get ( 'INVITE_CREDIT_RATE' );
$currency = Currency :: getDefaultCurrency ();
if ( $mode === 'info' ) {
return sprintf ( '%.02f' , $credit ) . ' (' . $value . ' ' . $currency -> sign . ')' ;
} elseif ( $mode === 'frontoffice' ) {
$format = ( int ) Configuration :: get ( 'INVITE_CREDIT_DISPLAY' );
if ( $format === 0 ) {
return rtrim ( rtrim ( sprintf ( '%.02f' , $credit ), '0' ), '.' ) . ' (' . $value . ' ' . $currency -> sign . ')' ;
} elseif ( $format === 1 ) {
return $value . ' ' . $currency -> sign . ' (' . rtrim ( rtrim ( sprintf ( '%.02f' , $credit ), '0' ), '.' ) . ')' ;
} elseif ( $format === 2 ) {
return rtrim ( rtrim ( sprintf ( '%.02f' , $credit ), '0' ), '.' );
} else {
2016-05-10 15:44:36 +02:00
return Tools :: displayPrice ( $value , $currency );
//return $value.' '.$currency->sign;
2016-01-04 12:49:26 +01:00
}
} else {
return array ( $credit , $value , $currency -> sign );
}
}
}
private function _get_sponsor ( $id_customer = FALSE ) {
if ( ! ( int ) $id_customer ) {
return FALSE ;
}
return Db :: getInstance ( _PS_USE_SQL_SLAVE_ ) -> getRow ( '
SELECT c . `id_customer` , c . `firstname` , c . `lastname`
FROM `'._DB_PREFIX_.'customer` c
LEFT JOIN `'._DB_PREFIX_.'invite` i
ON i . `id_sponsor` = c . `id_customer`
WHERE i . `id_customer` = '.(int) $id_customer.'
' );
}
private function _register_discount ( $params ) {
$discount = new Discount ();
$discount -> id_customer = $params [ 'id_customer' ];
$discount -> id_discount_type = $params [ 'discount_type' ];
$discount -> cumulable = Configuration :: get ( 'INVITE_DISCOUNT_CUMULABLE' );
$discount -> cumulable_reduction = Configuration :: get ( 'INVITE_DISCOUNT_CUMULABLE_REDUC' );
$discount -> minimal = Configuration :: get ( 'INVITE_DISCOUNT_MINIMAL' );
$discount -> include_tax = Configuration :: get ( 'INVITE_DISCOUNT_MINIMAL_WT' );
$discount -> cart_display = Configuration :: get ( 'INVITE_DISCOUNT_CART' );
$discount -> active = 1 ;
$discount -> quantity = 1 ;
$discount -> quantity_per_user = 1 ;
$discount -> date_from = date ( 'Y-m-d H:i:s' );
$discount -> date_to = date ( 'Y-m-d H:i:s' , time () + Configuration :: get ( 'INVITE_DISCOUNT_VALIDITY' ) * 86400 );
$name = Tools :: passwdGen ( 8 );
if ( Discount :: discountExists ( Configuration :: get ( 'INVITE_DISCOUNT_PREFIX' ) . $name )) {
// It should not happen, but who knows...
$name = Tools :: passwdGen ( 8 );
}
$discount -> name = Configuration :: get ( 'INVITE_DISCOUNT_PREFIX' ) . $name ;
$discount -> description = Configuration :: getInt ( 'INVITE_DISCOUNT_DESCRIPTION' );
if ( isset ( $params [ 'value' ]) && isset ( $params [ 'currency' ])) {
$discount -> id_currency = $params [ 'currency' ];
$discount -> value = $params [ 'value' ];
}
$discount -> add ();
return $discount ;
}
public function hookUpdateOrderStatus ( $params ) {
if ( ! Validate :: isLoadedObject ( $params [ 'newOrderStatus' ])) {
die ( Tools :: displayError ( 'Missing parameters' ));
}
$orderState = $params [ 'newOrderStatus' ];
$order = new Order (( int )( $params [ 'id_order' ]));
if ( $order AND ! Validate :: isLoadedObject ( $order )) {
die ( Tools :: displayError ( 'Incorrect object Order.' ));
}
$customer = new Customer (( int ) $order -> id_customer );
$stats = $customer -> getStats ();
$nbOrdersCustomer = ( int ) $stats [ 'nb_orders' ] + 1 ;
$invite = Db :: getInstance () -> ExecuteS ( '
SELECT *
FROM `'._DB_PREFIX_.'invite`
WHERE `id_customer` = ' . $customer -> id
);
if ( count ( $invite ) > 0 ) {
$invite = $invite [ 0 ];
$sponsor = new Customer (( int ) $invite [ 'id_sponsor' ]);
if (( int ) $orderState -> logable && $nbOrdersCustomer == 1 ) {
if ( Configuration :: get ( 'INVITE_REWARD_SPONSOR_ON' ) == 1 ) {
$this -> _make_rewards ( $sponsor );
}
if ( Configuration :: get ( 'INVITE_REWARD_SPONSORED_ON' ) == 1 ) {
$this -> _make_rewards ( $customer , TRUE );
}
return TRUE ;
}
}
return FALSE ;
}
public function hookCreateAccount ( $params ) {
global $cookie ;
$newCustomer = $params [ 'newCustomer' ];
if ( ! Validate :: isLoadedObject ( $newCustomer )) {
return FALSE ;
}
$postVars = $params [ '_POST' ];
if ( empty ( $postVars ) || ! isset ( $postVars [ 'invite' ]) || empty ( $postVars [ 'invite' ])) {
return FALSE ;
}
$sponsorEmail = $postVars [ 'invite' ];
if ( ! Validate :: isEmail ( $sponsorEmail ) || $sponsorEmail == $newCustomer -> email ) {
return FALSE ;
}
$sponsor = new Customer ();
if ( $sponsor = $sponsor -> getByEmail ( $sponsorEmail )) {
$invite = Db :: getInstance () -> ExecuteS ( '
SELECT *
FROM `'._DB_PREFIX_.'invite`
WHERE `email` = " '.pSQL( $newCustomer->email ).' "
' );
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 (
DEFAULT ,
'.$sponsor->id.' ,
" '.pSQL( $newCustomer->email ).' " ,
" '.pSQL( $newCustomer->lastname ).' " ,
" '.pSQL( $newCustomer->firstname ).' " ,
'.$newCustomer->id.' ,
0 ,
0 ,
0 ,
0 ,
NOW (),
NOW (),
0
)
' );
$invite = Db :: getInstance () -> ExecuteS ( '
SELECT *
FROM `'._DB_PREFIX_.'invite`
WHERE `email` = " '.pSQL( $newCustomer->email ).' "
' );
} else {
Db :: getInstance () -> Execute ( '
UPDATE `'._DB_PREFIX_.'invite`
SET `id_customer` = '.$newCustomer->id.' , `date_upd` = NOW ()
WHERE `email` = " '.pSQL( $newCustomer->email ).' "
' );
$invite [ 0 ][ 'id_customer' ] = $newCustomer -> id ;
}
$invite = $invite [ 0 ];
if ( Configuration :: get ( 'INVITE_REWARD_SPONSOR_ON' ) == 0 ) {
$this -> _make_rewards ( $sponsor );
}
if ( Configuration :: get ( 'INVITE_REWARD_SPONSORED_ON' ) == 0 ) {
$this -> _make_rewards ( $newCustomer , TRUE );
}
return TRUE ;
}
return FALSE ;
}
public function hookShoppingCart ( $params ) {
global $cookie , $cart , $smarty ;
if ( $cookie -> isLogged () && $cart -> getOrderTotal () > 0 ) {
$customer = new Customer (( int ) $cookie -> id_customer );
if ( Validate :: isLoadedObject ( $customer )) {
if ( Configuration :: get ( 'INVITE_CREDIT_ENABLE' ) == 1 ) {
$credit = $this -> _get_credit ( $customer -> id , FALSE , FALSE , 'array' );
$already_used = FALSE ;
$d_prefix = Configuration :: get ( 'INVITE_DISCOUNT_PREFIX' );
$d_prefix_l = strlen ( $d_prefix );
foreach ( $cart -> getDiscounts ( TRUE ) as $d ) {
if ( substr ( $d [ 'name' ], 0 , $d_prefix_l ) == $d_prefix ) {
$already_used = TRUE ;
break ;
}
}
$display_credits = true ;
$sql = 'SELECT id_customer FROM `' . _DB_PREFIX_ . 'customer_credits` WHERE id_customer = ' . ( int ) $customer -> id ;
if ( Db :: getInstance () -> getValue ( $sql )){
$display_credits = false ;
}
if ( $credit [ 0 ] > 0 && ! $already_used ) {
$smarty -> assign ( array (
'display_credits' => $display_credits ,
'invite_credit' => $credit ,
));
return $this -> display ( __FILE__ , 'shopping-cart-credit.tpl' );
}
}
}
}
}
private function _make_rewards ( $customer , $sponsored = FALSE ) {
$reward_type = Configuration :: get ( 'INVITE_REWARD_SPONSOR' . ( $sponsored ? 'ED' : '' ) . '_TYPE' );
if ( $reward_type == 1 ) {
$groups = $customer -> getGroups ();
$value = 0 ;
foreach ( $groups as $group ) {
$value = max ( $value , Configuration :: get ( 'INVITE_REWARD_SPONSOR' . ( $sponsored ? 'ED' : '' ) . '_VALUE_' . $group ));
}
if ( $value != 0 ) {
if ( count ( Db :: getInstance () -> ExecuteS ( '
SELECT `id_customer`
FROM `'._DB_PREFIX_.'invite_credit`
WHERE `id_customer` = ' . $customer -> id
)) == 0 ) {
Db :: getInstance () -> ExecuteS ( '
INSERT INTO `'._DB_PREFIX_.'invite_credit`
VALUES (
'.$customer->id.' ,
'.(int) $value.'
)
' );
} else {
Db :: getInstance () -> Execute ( '
UPDATE `'._DB_PREFIX_.'invite_credit`
SET `credit` = `credit` + '.(int) $value.'
WHERE `id_customer` = ' . $customer -> id
);
}
Db :: getInstance () -> Execute ( '
UPDATE `'._DB_PREFIX_.'invite`
SET `credit'.($sponsored? '': '_sponsor').'` = 1
WHERE `id_invite` = '.$invite[' id_invite ' ]
);
$this -> _send_credit_mail ( array (
'id_lang' => ( int ) $cookie -> id_lang ,
'firstname' => $customer -> firstname ,
'lastname' => $customer -> lastname ,
'email' => $customer -> email ,
'credit' => $value ,
));
}
} elseif ( $reward_type == 2 ) {
$groups = $customer -> getGroups ();
$value = 0 ;
foreach ( $groups as $group ) {
$value = max ( $value , Configuration :: get ( 'INVITE_REWARD_SPONSOR' . ( $sponsored ? 'ED' : '' ) . '_VALUE_' . $group ));
}
if ( $value != 0 ) {
// Auto-validate points
Db :: getInstance () -> ExecuteS ( '
INSERT INTO `'._DB_PREFIX_.'loyalty`
VALUES (
DEFAULT ,
2 ,
'.$customer->id.' ,
0 ,
0 ,
'.$value.' ,
NOW (),
NOW ()
)
' );
$id_loyalty = Db :: getInstance () -> Insert_ID ();
Db :: getInstance () -> ExecuteS ( '
INSERT INTO `'._DB_PREFIX_.'loyalty_history`
VALUES (
DEFAULT
'.$id_loyalty.' ,
2 ,
'.$value.' ,
NOW ()
)
' );
$this -> _send_loyalty_mail ( array (
'id_lang' => ( int ) $cookie -> id_lang ,
'firstname' => $customer -> firstname ,
'lastname' => $customer -> lastname ,
'email' => $customer -> email ,
'value' => $value ,
));
}
} elseif ( $reward_type == 3 ) {
$groups = $customer -> getGroups ();
$value = 0 ;
foreach ( $groups as $group ) {
$value = max ( $value , Configuration :: get ( 'INVITE_REWARD_SPONSOR' . ( $sponsored ? 'ED' : '' ) . '_VALUE_' . $group ));
}
if ( $value != 0 ) {
$discount = $this -> _register_discount ( array (
'discount_type' => 3 ,
'id_customer' => $customer -> id ,
'id_lang' => ( int ) $cookie -> id_lang ,
'value' => $value ,
'id_currency' => ( int ) $cookie -> id_currency ,
));
Db :: getInstance () -> Execute ( '
UPDATE `'._DB_PREFIX_.'invite`
SET `id_discount'.($sponsored? '': '_sponsor').'` = '.(int) $discount->id.'
WHERE `id_invite` = '.$invite[' id_invite ' ]
);
$this -> _send_discount_mail ( 'percent' , array (
'id_lang' => ( int ) $cookie -> id_lang ,
'firstname' => $customer -> firstname ,
'lastname' => $customer -> lastname ,
'email' => $customer -> email ,
'discount' => $discount -> name ,
'discount_value' => $discount -> value . '%' ,
));
}
} elseif ( $reward_type == 4 ) {
$groups = $customer -> getGroups ();
$value = 0 ;
foreach ( $groups as $group ) {
$value = max ( $value , Configuration :: get ( 'INVITE_REWARD_SPONSOR' . ( $sponsored ? 'ED' : '' ) . '_VALUE_' . $group . '_' . ( int ) $cookie -> id_currency ));
}
if ( $value != 0 ) {
$discount = $this -> _register_discount ( array (
'discount_type' => 3 ,
'id_customer' => $customer -> id ,
'id_lang' => ( int ) $cookie -> id_lang ,
'value' => $value ,
'id_currency' => ( int ) $cookie -> id_currency ,
));
$currency = new Currency (( int ) $cookie -> id_currency );
Db :: getInstance () -> Execute ( '
UPDATE `'._DB_PREFIX_.'invite`
SET `id_discount'.($sponsored? '': '_sponsor').'` = '.(int) $discount->id.'
WHERE `id_invite` = '.$invite[' id_invite ' ]
);
$this -> _send_discount_mail ( 'amount' , array (
'id_lang' => ( int ) $cookie -> id_lang ,
'firstname' => $customer -> firstname ,
'lastname' => $customer -> lastname ,
'email' => $customer -> email ,
'discount' => $discount -> name ,
'discount_value' => $discount -> value . $currency -> sign ,
));
}
} elseif ( $reward_type == 5 ) {
$discount = $this -> _register_discount ( array (
'discount_type' => 3 ,
'id_customer' => $customer -> id ,
'id_lang' => ( int ) $cookie -> id_lang ,
));
Db :: getInstance () -> Execute ( '
UPDATE `'._DB_PREFIX_.'invite`
SET `id_discount'.($sponsored? '': '_sponsor').'` = '.(int) $discount->id.'
WHERE `id_invite` = '.$invite[' id_invite ' ]
);
$this -> _send_discount_mail ( 'shipping' , array (
'id_lang' => ( int ) $cookie -> id_lang ,
'firstname' => $customer -> firstname ,
'lastname' => $customer -> lastname ,
'email' => $customer -> email ,
'discount' => $discount -> name ,
'discount_value' => '' ,
));
}
}
private function _send_discount_mail ( $type , $params ) {
Mail :: Send (
$params [ 'id_lang' ],
'invite-voucher-' . $type ,
Mail :: l ( 'Congratulations!' ),
array (
'{firstname}' => $params [ 'firstname' ],
'{lastname}' => $params [ 'lastname' ],
'{voucher_num}' => $params [ 'discount' ],
'{voucher_value}' => $params [ 'discount_value' ],
),
$params [ 'email' ],
$params [ 'firstname' ] . ' ' . $params [ 'lastname' ],
strval ( Configuration :: get ( 'PS_SHOP_EMAIL' )),
strval ( Configuration :: get ( 'PS_SHOP_NAME' )),
NULL ,
NULL ,
dirname ( __FILE__ ) . '/mails/'
);
}
private function _send_credit_mail ( $params ) {
Mail :: Send (
$params [ 'id_lang' ],
'invite-credit' ,
Mail :: l ( 'Congratulations!' ),
array (
'{firstname}' => $params [ 'firstname' ],
'{lastname}' => $params [ 'lastname' ],
'{credit}' => $params [ 'credit' ],
),
$params [ 'email' ],
$params [ 'firstname' ] . ' ' . $params [ 'lastname' ],
strval ( Configuration :: get ( 'PS_SHOP_EMAIL' )),
strval ( Configuration :: get ( 'PS_SHOP_NAME' )),
NULL ,
NULL ,
dirname ( __FILE__ ) . '/mails/'
);
}
private function _send_loyalty_mail ( $params ) {
Mail :: Send (
$params [ 'id_lang' ],
'invite-loyalty' ,
Mail :: l ( 'Congratulations!' ),
array (
'{firstname}' => $params [ 'firstname' ],
'{lastname}' => $params [ 'lastname' ],
'{value}' => $params [ 'value' ],
),
$params [ 'email' ],
$params [ 'firstname' ] . ' ' . $params [ 'lastname' ],
strval ( Configuration :: get ( 'PS_SHOP_EMAIL' )),
strval ( Configuration :: get ( 'PS_SHOP_NAME' )),
NULL ,
NULL ,
dirname ( __FILE__ ) . '/mails/'
);
}
public function getPendingFriends ( $id_customer = FALSE ) {
if ( ! ( int ) $id_customer ) {
return array ();
}
return Db :: getInstance ( _PS_USE_SQL_SLAVE_ ) -> ExecuteS ( '
SELECT `'._DB_PREFIX_.'invite` .*
FROM `'._DB_PREFIX_.'invite`
WHERE `'._DB_PREFIX_.'invite` . `id_sponsor` = '.(int) $id_customer.'
AND `'._DB_PREFIX_.'invite` . `id_customer` = 0
AND `'._DB_PREFIX_.'invite` . `email` NOT IN (
SELECT `'._DB_PREFIX_.'customer` . `email`
FROM `'._DB_PREFIX_.'customer`
WHERE `email` = `'._DB_PREFIX_.'invite` . `email`
)
' );
}
2016-02-09 10:46:07 +01:00
public function getFriends ( $id_customer = FALSE , $nb_limit ) {
2016-01-04 12:49:26 +01:00
if ( ! ( int ) $id_customer ) {
return array ();
}
2016-02-09 10:46:07 +01:00
if ( $nb_limit ) {
// $date_end = new DateTime();
// $date = new DateTime();
// $date_end->modify('-'. (int) $date_limit.' days');
2016-01-04 12:49:26 +01:00
return Db :: getInstance ( _PS_USE_SQL_SLAVE_ ) -> ExecuteS ( '
2016-02-09 10:46:07 +01:00
SELECT `id_customer` , `firstname` , `lastname` , `email`
2016-01-04 12:49:26 +01:00
FROM `'._DB_PREFIX_.'invite`
WHERE `id_sponsor` = '.(int) $id_customer.'
AND `id_customer` != 0
2016-02-09 10:46:07 +01:00
ORDER BY `id_customer` DESC
LIMIT 0 , '.(int) $nb_limit.'
2016-01-04 12:49:26 +01:00
' );
}
return Db :: getInstance ( _PS_USE_SQL_SLAVE_ ) -> ExecuteS ( '
SELECT *
FROM `'._DB_PREFIX_.'invite`
WHERE `id_sponsor` = '.(int) $id_customer.'
2016-02-09 10:46:07 +01:00
AND `id_customer` != 0
2016-01-04 12:49:26 +01:00
' );
}
public function getNbFriends ( $id_customer = FALSE ) {
if ( ! ( int ) $id_customer ) {
return 0 ;
}
return Db :: getInstance ( _PS_USE_SQL_SLAVE_ ) -> getValue ( '
SELECT COUNT ( `id_customer` ) as total
FROM `'._DB_PREFIX_.'invite`
WHERE `id_sponsor` = '.(int) $id_customer.'
AND `id_customer` != 0
' );
}
public function addInvite ( $id_customer = FALSE , $friend_firstname = '' , $friend_lastname = '' , $friend_email = '' , $when_invite = 0 ) {
Db :: getInstance ( _PS_USE_SQL_SLAVE_ ) -> ExecuteS ( '
INSERT INTO `'._DB_PREFIX_.'invite`
VALUES (
DEFAULT ,
'.(int) $id_customer.' ,
" '.pSQL( $friend_email ).' " ,
" '.pSQL( $friend_lastname ).' " ,
" '.pSQL( $friend_firstname ).' " ,
0 ,
0 ,
0 ,
0 ,
0 ,
NOW (),
NOW (),
'. $when_invite .'
)
' );
return Db :: getInstance () -> Insert_ID ();
}
public function isFriend ( $id_customer , $id_invite ) {
return ( bool ) count ( Db :: getInstance ( _PS_USE_SQL_SLAVE_ ) -> ExecuteS ( '
SELECT `id_invite`
FROM `'._DB_PREFIX_.'invite`
WHERE `id_sponsor` = '.(int) $id_customer.'
AND `id_invite` = '.(int) $id_invite.'
' ));
}
public function getInvite ( $id_invite = FALSE ) {
$result = Db :: getInstance ( _PS_USE_SQL_SLAVE_ ) -> ExecuteS ( '
SELECT *
FROM `'._DB_PREFIX_.'invite`
WHERE `id_invite` = '.(int) $id_invite.'
' );
if ( count ( $result ) > 0 ) {
return $result [ 0 ];
} else {
return FALSE ;
}
}
public function emailExists ( $email = '' ) {
return ( bool ) count ( Db :: getInstance ( _PS_USE_SQL_SLAVE_ ) -> ExecuteS ( '
SELECT `id_invite`
FROM `'._DB_PREFIX_.'invite`
WHERE `email` = " '.pSQL( $email ).' "
' ));
}
public function updateInvite ( $id_invite = FALSE ) {
Db :: getInstance () -> Execute ( '
UPDATE `'._DB_PREFIX_.'invite`
SET `date_upd` = NOW ()
WHERE `id_invite` = '.(int) $id_invite.'
' );
}
}