Serveur preprod f0c0c48223 first push
2016-04-14 16:14:31 +02:00

228 lines
6.8 KiB
PHP
Executable File

<?php
/*
* 2007-2014 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2014 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
if (!defined('_PS_VERSION_'))
exit;
include_once(_PS_MODULE_DIR_.'relancecommande/models/RelancecommandeCore.php');
class Relancecommande extends Module
{
const NB_DAYS_FIELD_NAME = '_RELANCE_COMMANDE_NB_DAYS_';
const MAIL_SUBJECT = '_RELANCE_COMMANDE_MAIL_SUBJECT_';
public function __construct()
{
$this->name = 'relancecommande';
$this->tab = 'front_office_features';
$this->version = '0.1.0';
$this->author = 'Antadis';
$this->need_instance = 0;
$this->bootstrap = 1;
parent::__construct();
$this->displayName = $this->l('Relance commande');
$this->description = $this->l('Sends an email to a customer x days after order has been created if order state sticks at "saved".');
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
}
public function install()
{
return ($this->createTable()
&& parent::install()
);
}
public function uninstall()
{
return (parent::uninstall()
&& $this->deleteTable()
);
}
private function createTable(){
$sql = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'relancecommande` (
`id_relancecommande` int(11) NOT NULL AUTO_INCREMENT,
`id_customer` int(11) NOT NULL,
`id_order` int(11) NOT NULL,
`date_add` datetime NOT NULL DEFAULT "0000-00-00 00:00:00",
PRIMARY KEY (`id_relancecommande`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;';
return Db::getInstance()->execute($sql);
}
private function deleteTable(){
return Db::getInstance()->execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'relancecommande`');
}
public function postProcess(){
if(Tools::isSubmit('submitUpdateSettings')){
$this->updateSettings();
}
if(Tools::isSubmit('submitExport')){
$obj = new RelancecommandeCore();
$obj->exportCustomers(false);
}
if(Tools::isSubmit('submitTestMail') && Validate::isEmail(Tools::getValue('email'))){
$obj = new RelancecommandeCore();
$obj->sendTestMail(Tools::getValue('email'));
}
}
public function getContent(){
$this->html = '';
$this->postProcess();
$this->displaySettingsForm();
$this->displayExportForm();
$this->displayMailTestForm();
return $this->html;
}
private function displaySettingsForm(){
$n1 = RelancecommandeCore::getNumber();
$form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Paramétrages relance commande'),
'icon' => 'icon-cogs'
),
'description' => sprintf($this->l('%d e-mail(s) concernés.'), $n1),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Nombre de jours'),
'name' => self::NB_DAYS_FIELD_NAME
),
array(
'type' => 'text',
'label' => $this->l('Sujet du mail'),
'name' => self::MAIL_SUBJECT,
'hint' => $this->l('les champs disponibles sont %lastname%, %firstname%, %reference%')
)
),
'submit' => array(
'title' => $this->l('Mettre à jours')
)
)
);
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$helper->module = $this;
$helper->submit_action = 'submitUpdateSettings';
$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->getSettingsVar()
);
$this->html .= $helper->generateForm(array($form));
}
private function displayExportForm(){
$form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Export CSV'),
'icon' => 'icon-wheel'
),
'submit' => array(
'title' => $this->l('Exporter les clients relancés'),
)
),
);
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$helper->module = $this;
$helper->submit_action = 'submitExport';
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$this->html .= $helper->generateForm(array($form));
}
private function displayMailTestForm(){
$form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Envoyer un mail test'),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Adresse email'),
'name' => 'email'
)
),
'submit' => array(
'title' => $this->l('Envoyer email de test')
)
)
);
$helper = new HelperForm();
$helper->show_toolbar = false;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$helper->module = $this;
$helper->submit_action = 'submitTestMail';
$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' => array('email' => '')
);
$this->html .= $helper->generateForm(array($form));
}
private function getSettingsVar(){
return array(
self::NB_DAYS_FIELD_NAME => Configuration::get(self::NB_DAYS_FIELD_NAME),
self::MAIL_SUBJECT => Configuration::get(self::MAIL_SUBJECT)
);
}
private function updateSettings(){
if(Validate::isInt(Tools::getValue(self::NB_DAYS_FIELD_NAME)))
Configuration::updateValue(self::NB_DAYS_FIELD_NAME,Tools::getValue(self::NB_DAYS_FIELD_NAME));
Configuration::updateValue(self::MAIL_SUBJECT,Tools::getValue(self::MAIL_SUBJECT));
}
}