* @copyright 2012-2015 IXYCOM
* @license You are just allowed to modify this copy for your own use. You must not redistribute it. License is permitted for one Prestashop instance only but you can install it on your test instances.
*/
if (!defined('_PS_VERSION_'))
exit;
class SiretProgram extends Module
{
public function __construct()
{
$this->name = 'siretprogram';
$this->tab = 'pricing_promotion';
$this->bootstrap = true;
$this->display = 'view';
$this->version = '2.4.1';
$this->module_key = 'ef37574de7dcf6a69770cba0c6a2d936';
$this->need_instance = 0;
$this->author = 'Ixycom';
parent::__construct();
$this->displayName = $this->l('SIRET – Groupe automatique');
$this->description = $this->l("Intègre le SIRET à l'inscription et classe le client dans le groupe professionnel.");
$this->confirmUninstall = $this->l('Tous les numéros de SIRET enregistrés seront supprimés. Etes vous sûr de vouloir
désinstaller ce module ?');
}
public function install()
{
if (parent::install() == false
|| !$this->registerHook('AdditionalCustomerFormFields')
|| !$this->registerHook('actionCustomerAccountAdd')
|| !$this->registerHook('displayTop')
|| !$this->registerHook('displayAdminCustomers')
|| !$this->registerHook('displayPDFInvoice')
|| !$this->registerHook('displayCustomerAccount')
|| !$this->registerHook('displayBackOfficeHeader')
|| !Configuration::updateGlobalValue('SIRET_MODE_MANUEL', 0)
|| !Configuration::updateGlobalValue('SIRET_OBLIGATOIRE', 0)
|| !Configuration::updateGlobalValue('SIRET_ACCES_VALIDATION', 0)
|| !Configuration::updateGlobalValue('SIRET_PROF_GROUP', 1)
|| !Configuration::updateGlobalValue('SIRET_NONPROF_GROUP', 1)
|| !Configuration::updateGlobalValue('SIRET_STOPRATING', 0)
|| !$this->installDB())
return false;
return true;
}
public function installDB()
{
return Db::getInstance()->Execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'customer_siret` (
`id_customer` int(10) NOT NULL,
`siret` varchar(14) NOT NULL,
`statut` tinyint(1) NOT NULL,
PRIMARY KEY (`id_customer`)
) DEFAULT CHARSET=utf8 ;');
}
public function uninstall()
{
if (!parent::uninstall())
return false;
if (!Configuration::deleteByName('SIRET_MODE_MANUEL')
|| !Configuration::deleteByName('SIRET_OBLIGATOIRE')
|| !Configuration::deleteByName('SIRET_ACCES_VALIDATION')
|| !Configuration::deleteByName('SIRET_PROF_GROUP')
|| !Configuration::deleteByName('SIRET_NONPROF_GROUP')
|| !Configuration::deleteByName('SIRET_STOPRATING'))
return false;
return true;
}
public function getContent()
{
$output = $this->postProcess();
$output .= $this->getRating();
$output .= $this->renderForm();
$output .= $this->listSiret();
//$output .= $this->getCredit();
return $output;
}
public function getRating()
{
$ouput = '';
$stop_rating = (int)Configuration::get('SIRET_STOPRATING');
if ($stop_rating != 1)
{
$ouput .= '
';
}
return $ouput;
}
public function getCredit()
{
return '';
}
public function renderForm()
{
if (_PS_VERSION_ >= 1.6)
{
$fields_form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Configuration'),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => 'switch',
'label' => $this->l('Mode manuel'),
'name' => 'siret_manuel',
'is_bool' => true,
'desc' => $this->l('Lorsque le mode manuel est activé, vous devez valider la mise en groupe
professionnel vous-même. Si vous désactivez ce mode, tous les SIRET de la base de données seront
considérés comme "Validé'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
)
),
array(
'type' => 'switch',
'label' => $this->l('Access en attente de verification'),
'name' => 'siret_validation',
'is_bool' => true,
'desc' => $this->l('Les visiteurs dont le SIRET n\'a pas été vérifié auront accès à la boutique avec les
avantages du groupe non professionnel plutôt que d\'être bloqués.'),
'values' => array(
array(
'id' => 'active_on2',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off2',
'value' => 0,
'label' => $this->l('Disabled')
)
)
),
array(
'type' => 'switch',
'label' => $this->l('Siret obligatoire'),
'name' => 'siret_obligatoire',
'is_bool' => true,
'desc' => $this->l('Les clients n\'ayant pas entré leur SIRET seront bloqués sur la page "Mon compte" afin de l\'enregistrer'),
'values' => array(
array(
'id' => 'active_on3',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off3',
'value' => 0,
'label' => $this->l('Disabled')
)
)
),
array(
'type' => 'select',
'label' => $this->l('Groupe ordinaire'),
'name' => 'siret_noprogroup',
'desc' => $this->l('Choisissez le groupe dédié aux particuliers. Celui dans lequel doivent être envoyé les
utilisateurs en attente de validation ou refusé.'),
'options' => array(
'query' => Group::getGroups($this->context->language->id),
'id' => 'id_group',
'name' => 'name'
)
),
array(
'type' => 'select',
'label' => $this->l('Groupe professionnel'),
'name' => 'siret_progroup',
'desc' => $this->l('Choisissez le groupe dédié aux professionnels. Celui dans lequel doivent être envoyé
les utilisateurs au SIRET valide'),
'options' => array(
'query' => Group::getGroups($this->context->language->id),
'id' => 'id_group',
'name' => 'name'
)
)
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right')
),
);
}
else
{
$fields_form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Configuration'),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => 'radio',
'label' => $this->l('Mode manuel'),
'name' => 'siret_manuel',
'is_bool' => true,
'class' => 't',
'desc' => $this->l('Lorsque le mode manuel est activé, vous devez valider la mise en groupe
professionnel vous-même. Si vous désactivez ce mode, tous les SIRET de la base de données seront
considérés comme "Validé'),
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
)
),
array(
'type' => 'radio',
'label' => $this->l('Access en attente de verification'),
'name' => 'siret_validation',
'is_bool' => true,
'class' => 't',
'desc' => $this->l('Les visiteurs dont le SIRET n\'a pas été vérifié auront accès à la boutique avec les
avantages du groupe non professionnel plutôt que d\'être bloqués.'),
'values' => array(
array(
'id' => 'active_on2',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off2',
'value' => 0,
'label' => $this->l('Disabled')
)
)
),
array(
'type' => 'radio',
'label' => $this->l('Siret obligatoire'),
'name' => 'siret_obligatoire',
'is_bool' => true,
'class' => 't',
'desc' => $this->l('Les clients n\'ayant pas entré leur SIRET seront bloqués sur la page "Mon compte" afin de l\'enregistrer'),
'values' => array(
array(
'id' => 'active_on3',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off3',
'value' => 0,
'label' => $this->l('Disabled')
)
)
),
array(
'type' => 'select',
'label' => $this->l('Groupe ordinaire'),
'name' => 'siret_noprogroup',
'desc' => $this->l('Choisissez le groupe dédié aux particuliers. Celui dans lequel doivent être envoyé les
utilisateurs en attente de validation ou refusé.'),
'options' => array(
'query' => Group::getGroups($this->context->language->id),
'id' => 'id_group',
'name' => 'name'
)
),
array(
'type' => 'select',
'label' => $this->l('Groupe professionnel'),
'name' => 'siret_progroup',
'desc' => $this->l('Choisissez le groupe dédié aux professionnels. Celui dans lequel doivent être envoyé
les utilisateurs au SIRET valide'),
'options' => array(
'query' => Group::getGroups($this->context->language->id),
'id' => 'id_group',
'name' => 'name'
)
)
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right')
),
);
}
$helper = new HelperForm();
$helper->title = $this->l('Siret Program');
$helper->show_toolbar = true;
$helper->table = $this->table;
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language = $lang->id;
$helper->allow_employee_form_lang =
Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$this->fields_form = array();
$helper->toolbar_btn = array(
'save' => array('href' => '#', 'desc' => $this->l('Save'))
);
$helper->identifier = $this->identifier;
$helper->submit_action = 'submitSIRETProgram';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false)
.'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFieldsValues(),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id
);
return $helper->generateForm(array($fields_form));
}
public function postProcess()
{
if (Tools::getValue('stop_rating'))
{
Configuration::updateValue('SIRET_STOPRATING', 1);
die;
}
$output = '';
if (Tools::isSubmit('submitSIRETProgram'))
{
/* Validation automatique des clients non trié si passage en automatique */
if ((Configuration::get('SIRET_MODE_MANUEL')) && ((int)Tools::getValue('siret_manuel') == 0))
{
$sirets = $this->getSIRET();
foreach ($sirets as $siret)
{
if ($siret['statut'] == 1)
$this->setStatut($siret['id_customer'], 2, false);
}
}
Configuration::updateValue('SIRET_ACCES_VALIDATION', (int)Tools::getValue('siret_validation'));
Configuration::updateValue('SIRET_OBLIGATOIRE', (int)Tools::getValue('siret_obligatoire'));
Configuration::updateValue('SIRET_MODE_MANUEL', (int)Tools::getValue('siret_manuel'));
$my_protected_group = array(Configuration::get('PS_GUEST_GROUP'), Configuration::get('PS_UNIDENTIFIED_GROUP'));
if (count($my_protected_group))
if ((in_array((int)Tools::getValue('siret_progroup'), $my_protected_group))
|| (in_array((int)Tools::getValue('siret_noprogroup'), $my_protected_group)))
return $this->displayError($this->l('Vous ne pouvez pas utiliser les pseudo-groupes Visiteur ou Invité.'));
Configuration::updateValue('SIRET_PROF_GROUP', (int)Tools::getValue('siret_progroup'));
Configuration::updateValue('SIRET_NONPROF_GROUP', (int)Tools::getValue('siret_noprogroup'));
$output .= $this->displayConfirmation($this->l('Configuration enregistrée.'));
}
if (Tools::isSubmit('submitValidation'))
{
$sirets = $this->getSIRET();
if ($sirets & !empty($sirets))
{
foreach ($sirets as $siret)
{
$enbase = $this->getCustomerSIRET($siret['id_customer']);
if ((int)$enbase['statut'] != (int)Tools::getValue('check'.$siret['id_customer']))
$this->setStatut($siret['id_customer'], Tools::getValue('check'.$siret['id_customer']));
}
$output .= $this->displayConfirmation($this->l('SIRETs enregistrés.'));
}
}
return $output;
}
public function getConfigFieldsValues()
{
$values = array(
'siret_manuel' => Tools::getValue('siret_manuel', Configuration::get('SIRET_MODE_MANUEL')),
'siret_obligatoire' => Tools::getValue('siret_obligatoire', Configuration::get('SIRET_OBLIGATOIRE')),
'siret_validation' => Tools::getValue('siret_validation', Configuration::get('SIRET_ACCES_VALIDATION')),
'siret_progroup' => Tools::getValue('siret_progroup', Configuration::get('SIRET_PROF_GROUP')),
'siret_noprogroup' => Tools::getValue('siret_noprogroup', Configuration::get('SIRET_NONPROF_GROUP')));
return $values;
}
public function getSIRET()
{
$result = array();
$sql = 'SELECT c.id_customer, firstname, lastname, company, cs.siret, cs.statut
FROM '._DB_PREFIX_.'customer c, '._DB_PREFIX_.'customer_siret cs
WHERE c.id_customer = cs.id_customer
ORDER BY cs.statut';
if (!$sirets = Db::getInstance()->ExecuteS($sql))
return false;
foreach ($sirets as $siret)
{
$pro = array();
$pro['id_customer'] = (int)$siret['id_customer'];
$pro['firstname'] = Tools::stripslashes($siret['firstname']);
$pro['lastname'] = Tools::stripslashes($siret['lastname']);
$pro['company'] = Tools::stripslashes($siret['company']);
$pro['siret'] = $siret['siret'];
$pro['statut'] = $siret['statut'];
$result[] = $pro;
}
return $result;
}
public function listSiret()
{
$output = '';
$sirets = $this->getSIRET();
if (!$sirets)
return $this->displayError($this->l('Aucun SIRET n\'est actuellement enregistré.'));
$output .= '
';
}
public function hookdisplayCustomerAccount()
{
return $this->display(__FILE__, 'my-account.tpl');
}
public function hookdisplayMyAccountBlock()
{
return $this->hookdisplayCustomerAccount();
}
public function hookdisplayBackOfficeHeader()
{
if ((Tools::getValue('module_name') == 'siretprogram') || (Tools::getValue('configure') == 'siretprogram'))
{
$this->context->controller->addJquery();
$this->context->controller->addJS($this->_path.'views/js/admin.js');
}
}
public function hookDisplayTop()
{
if (!empty(Context::getContext()->customer->id) && ((int)Configuration::get('SIRET_OBLIGATOIRE') == 1)
&& (Tools::getValue('module')) != 'siretprogram')
{
$restriction = $this->getCustomerSIRET(Context::getContext()->customer->id);
if (($restriction == null) || (($restriction['statut'] != 2) && ((int)Configuration::get('SIRET_ACCES_VALIDATION') == 0)))
Tools::redirect(Context::getContext()->link->getModuleLink('siretprogram'));
}
}
public function hookAdditionalCustomerFormFields($params)
{
$label = $this->trans('Numéro SIRET');
if (Configuration::get('SIRET_OBLIGATOIRE'))
return array(
(new FormField())
->setName('siret')
->setRequired(true)
->setType('text')
->setLabel($label));
else
return array(
(new FormField())
->setName('siret')
->setType('text')
->setLabel($label));
}
public function hookactionCustomerAccountAdd($params)
{
$new_customer = $params['newCustomer'];
if (empty($params) || empty($params['newCustomer']->siret) || empty($params['newCustomer']))
return false;
$siret = $params['newCustomer']->siret;
return $this->processSiret($siret, $new_customer);
}
public function hookdisplayAdminCustomers($params)
{
$customer = new Customer((int)$params['id_customer']);
if (!Validate::isLoadedObject($customer))
die(Tools::displayError('Incorrect object Customer.'));
if (empty($customer->siret))
$sirets = $this->l('Aucun SIRET n\'est actuellement enregistré');
else
$sirets = ''.$customer->siret.'';
$output = '';
return $output;
}
public function hookdisplayPDFInvoice($params)
{
// TheCoreDev le 11/05/2020 : ce module est obsolète et génère des erreurs PHP dans les logs --> essayons de l'adapter à PS 1.7
$id_order = (_PS_VERSION_ > '1.5' ? $params['object']->id_order : $params['id_order']);
$ma_order = new Order($id_order);
$mon_customer_id = $ma_order->id_customer;
$my_customer = new Customer($mon_customer_id);
if (!empty($my_customer->siret))
{
$text = $this->l('SIRET : ').str_replace(' ', '', $my_customer->siret);
if (_PS_VERSION_ > '1.5')
return $text;
else
{
$pdf = $params['pdf'];
$pdf->Ln(20);
$pdf->SetFont('Helvetica', '', 8);
$pdf->Cell(0, 0, $text, 0, 0, 'R');
$pdf->Ln(10);
}
}
/* L'ancien code -----------------------
$pdf = $params['pdf'];
$id_order = $params['id_order'];
$ma_order = new Order($id_order);
$mon_customer_id = $ma_order->id_customer;
$my_customer = new Customer($mon_customer_id);
if (!empty($my_customer->siret))
{
$pdf->Ln(20);
$pdf->SetFont('Helvetica', '', 8);
$pdf->Cell(0, 0, $this->l('SIRET : ').str_replace(' ', '', $my_customer->siret), 0, 0, 'R');
$pdf->Ln(10);
}
*/
}
public function processSiret($siret, $new_customer)
{
$id_client = $new_customer->id;
if ($siret === '')
{
$this->deleteGroupClient1et3($id_client);
$this->insertGroupClient1et3($id_client);
$this->updateGroupClient1et3($id_client);
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'customer_siret` WHERE `id_customer` = '.(int)$id_client);
Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'customer` SET `siret` = "" WHERE `id_customer` = '.(int)$id_client);
return true;
}
else
{
if ($this->isSIRET($siret))
{
if ($this->checkSIRET($siret))
{
if (Configuration::get('SIRET_MODE_MANUEL'))
{
if ($this->insertSIRETClient($id_client, $siret))
{
$configuration = Configuration::getMultiple(array(
'PS_SHOP_EMAIL',
'PS_MAIL_METHOD',
'PS_MAIL_SERVER',
'PS_MAIL_USER',
'PS_MAIL_PASSWD',
'PS_SHOP_NAME'));
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$iso = Language::getIsoById($id_lang);
if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/new_registration.txt')
&& file_exists(dirname(__FILE__).'/mails/'.$iso.'/new_registration.html'))
{
Mail::Send($id_lang, 'new_registration', $this->l('New registration', false, $id_lang),
null, $configuration['PS_SHOP_EMAIL'], null, $configuration['PS_SHOP_EMAIL'],
$configuration['PS_SHOP_NAME'], null, null, dirname(__FILE__).'/mails/');
}
if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/registration_waiting_validation.txt')
&& file_exists(dirname(__FILE__).'/mails/'.$iso.'/registration_waiting_validation.html'))
{
Mail::Send($id_lang, 'registration_waiting_validation',
$this->l('Registration waiting for validation', false, $id_lang), null,
$new_customer->email,
$new_customer->lastname.' '.$new_customer->firstname, $configuration['PS_SHOP_EMAIL'],
$configuration['PS_SHOP_NAME'], null, null, dirname(__FILE__).'/mails/');
}
return true;
}
}
else
{
if ($this->insertGroupClient($id_client))
{
if ($this->updateGroupClient($id_client))
{
if ($this->deleteGroupClient($id_client))
{
if ($this->insertSIRETClient($id_client, $siret))
return true;
}
}
}
}
}
}
}
return false;
}
private function insertGroupClient($id_customer)
{
if (!(int)$id_customer)
return false;
$query = ' INSERT IGNORE INTO `'._DB_PREFIX_.'customer_group` (`id_customer` ,`id_group`) VALUES ('.
(int)$id_customer.', '.(int)Configuration::get('SIRET_PROF_GROUP').')';
return Db::getInstance()->Execute($query);
}
private function insertGroupClient1et3($id_customer)
{
if (!(int)$id_customer)
return false;
$query = 'INSERT IGNORE INTO `'._DB_PREFIX_.'customer_group` (`id_customer` ,`id_group`) VALUES ('.
(int)$id_customer.', '.(int)Configuration::get('SIRET_NONPROF_GROUP').')';
return Db::getInstance()->Execute($query);
}
private function updateGroupClient($id_customer)
{
if (!(int)$id_customer)
return false;
$my_customer = new Customer($id_customer);
$my_customer->id_default_group = Configuration::get('SIRET_PROF_GROUP');
return $my_customer->update();
}
private function updateGroupClient1et3($id_customer)
{
if (!(int)$id_customer)
return false;
$my_customer = new Customer($id_customer);
$my_customer->id_default_group = Configuration::get('SIRET_NONPROF_GROUP');
return $my_customer->update();
}
private function deleteGroupClient($id_customer)
{
if (!(int)$id_customer)
return false;
$query3 = ' DELETE FROM `'._DB_PREFIX_.'customer_group` WHERE `id_customer` = '.(int)$id_customer.
' AND `id_group` <> '.(int)Configuration::get('SIRET_PROF_GROUP');
return Db::getInstance()->Execute($query3);
}
private function deleteGroupClient1et3($id_customer)
{
if (!(int)$id_customer)
return false;
$query313 = 'DELETE FROM `'._DB_PREFIX_.'customer_group` WHERE `id_customer` = '.(int)$id_customer.
' AND `id_group` <> '.(int)Configuration::get('SIRET_NONPROF_GROUP');
return Db::getInstance()->Execute($query313);
}
private function isSIRET($lesiret)
{
$lesiret = str_replace(' ', '', $lesiret);
if (Tools::strlen($lesiret) == 14)
return true;
return false;
}
private function checkSIRET($lesiret)
{
$lesiret = str_replace(' ', '', $lesiret);
$lesiret = str_split($lesiret, 1);
if (is_string($lesiret))
return false;
else
{
$lesiret[0] *= 2;
$lesiret[2] *= 2;
$lesiret[4] *= 2;
$lesiret[6] *= 2;
$lesiret[8] *= 2;
$lesiret[10] *= 2;
$lesiret[12] *= 2;
$somme = 0;
$nb_caracters = count($lesiret);
for ($i = 0; $i < $nb_caracters; $i++)
{
if ($lesiret[$i] > 9)
{
$a = (int)Tools::substr($lesiret[$i], 0, 1);
$b = (int)Tools::substr($lesiret[$i], 1, 1);
$lesiret[$i] = $a + $b;
}
$somme += $lesiret[$i];
}
if (($somme % 10) == 0)
return true;
else
return false;
}
}
public function getCustomerSIRET($id_customer)
{
if (!(int)$id_customer)
return false;
if (!$sirets = Db::getInstance()->ExecuteS('SELECT `siret`, `statut` FROM '._DB_PREFIX_.'customer_siret WHERE id_customer = '.(int)$id_customer))
return false;
foreach ($sirets as $siret)
return $siret;
}
private function insertSIRETClient($id_customer, $numsiret)
{
if (!(int)$id_customer)
return false;
$numsiret = str_replace(' ', '', htmlspecialchars($numsiret));
$my_customer = new Customer($id_customer);
$my_customer->siret = $numsiret;
$my_customer->update();
if ($this->getCustomerSIRET($id_customer))
$update = 1;
else
$update = 0;
if ($update == 1)
{
if (Configuration::get('SIRET_MODE_MANUEL'))
$query = 'UPDATE '._DB_PREFIX_.'customer_siret SET `siret` = "'.pSQL($numsiret).'", `statut` = "1" WHERE id_customer = '.(int)$id_customer;
else
$query = 'UPDATE '._DB_PREFIX_.'customer_siret SET `siret` = "'.pSQL($numsiret).'", `statut` = "2" WHERE id_customer = '.(int)$id_customer;
}
else
{
if (Configuration::get('SIRET_MODE_MANUEL'))
$query = 'INSERT INTO '._DB_PREFIX_.'customer_siret VALUES ('.(int)$id_customer.', '.pSQL($numsiret).', 1)';
else
$query = 'INSERT INTO '._DB_PREFIX_.'customer_siret VALUES ('.(int)$id_customer.', '.pSQL($numsiret).', 2)';
}
return Db::getInstance()->Execute($query);
}
private function setStatut($id_customer, $statut, $mail = true)
{
if ((!(int)$id_customer) || (!(int)$statut))
return false;
$configuration =
Configuration::getMultiple(array('PS_SHOP_EMAIL', 'PS_MAIL_METHOD', 'PS_MAIL_SERVER', 'PS_MAIL_USER',
'PS_MAIL_PASSWD', 'PS_SHOP_NAME'));
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$iso = Language::getIsoById($id_lang);
$new_customer = new Customer($id_customer);
/* SI A VALIDER */
if ($statut == 1)
{
if ($this->insertGroupClient1et3($id_customer))
{
if ($this->updateGroupClient1et3($id_customer))
$this->deleteGroupClient1et3($id_customer);
}
}
/* SI ACCEPTER */
if ($statut == 2)
{
if ($mail)
{
if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/registration_ok.txt') && file_exists(dirname(__FILE__).'/mails/'.$iso.'/registration_ok.html'))
{
Mail::Send($id_lang, 'registration_ok', $this->l('Registration accepted', false, $id_lang),
null,
$new_customer->email, $new_customer->lastname.' '.$new_customer->firstname,
$configuration['PS_SHOP_EMAIL'], $configuration['PS_SHOP_NAME'], null, null,
dirname(__FILE__).'/mails/');
}
}
if ($this->insertGroupClient($id_customer))
{
if ($this->updateGroupClient($id_customer))
$this->deleteGroupClient($id_customer);
}
}
/* SI REFUSER */
if ($statut == 3)
{
if ($mail)
{
if (file_exists(dirname(__FILE__).'/mails/'.$iso.'/registration_ko.txt') && file_exists(dirname(__FILE__).'/mails/'.$iso.'/registration_ko.html'))
{
Mail::Send($id_lang, 'registration_ko', $this->l('Registration refused', false, $id_lang),
null,
$new_customer->email, $new_customer->lastname.' '.$new_customer->firstname,
$configuration['PS_SHOP_EMAIL'], $configuration['PS_SHOP_NAME'], null, null,
dirname(__FILE__).'/mails/');
}
}
if ($this->insertGroupClient1et3($id_customer))
{
if ($this->updateGroupClient1et3($id_customer))
$this->deleteGroupClient1et3($id_customer);
}
}
$querystatut =
'UPDATE `'._DB_PREFIX_.'customer_siret` SET `statut` = '.(int)$statut.' WHERE `id_customer` = '.
(int)$id_customer;
return Db::getInstance()->Execute($querystatut);
}
}
?>