168 lines
7.6 KiB
PHP
168 lines
7.6 KiB
PHP
|
<?php
|
||
|
|
||
|
class AdminPreferenceAntPopOverController extends ModuleAdminController {
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
*/
|
||
|
public function __construct(){
|
||
|
$this->context = Context::getContext();
|
||
|
$this->className = 'Configuration';
|
||
|
$this->table = 'configuration';
|
||
|
$this->bootstrap = true;
|
||
|
|
||
|
$imagepopup_home = _THEME_IMG_DIR_.'home/popup_home.png';
|
||
|
$imagepopup_promo = _THEME_IMG_DIR_.'home/popup_promo.png';
|
||
|
|
||
|
$fields = array(
|
||
|
'popup_home' => array(
|
||
|
'ANT_POPOVER_CUSTOMER_YIELD' => array(
|
||
|
'title' => $this->l('Activer la popup de la home'),
|
||
|
'validation' => 'isBool',
|
||
|
'cast' => 'intval',
|
||
|
'type' => 'bool',
|
||
|
'default' => Configuration::get('ANT_POPOVER_CUSTOMER_YIELD'),
|
||
|
),
|
||
|
array(
|
||
|
'title' => $this->l('Image popup'),
|
||
|
'type' => 'file',
|
||
|
'label' => $this->l('Image popup'),
|
||
|
'name' => 'imagepopup_home',
|
||
|
'form_group_class' => 'fieldhide input_img',
|
||
|
'url' => $imagepopup_home,
|
||
|
'desc' => 'dimension 500px x 500px'
|
||
|
),
|
||
|
'ANT_POPOVER_CUSTOMER_YIELD_LINK' => array(
|
||
|
'title' => $this->l('Lien de la popup'),
|
||
|
'type' => 'text',
|
||
|
'default' => Configuration::get('ANT_POPOVER_CUSTOMER_YIELD_LINK'),
|
||
|
),
|
||
|
'ANT_POPOVER_CUSTOMER_YIELD_TEXT' => array(
|
||
|
'title' => $this->l('Texte du lien'),
|
||
|
'type' => 'text',
|
||
|
'default' => Configuration::get('ANT_POPOVER_CUSTOMER_YIELD_TEXT'),
|
||
|
),
|
||
|
),
|
||
|
|
||
|
'popup_promo' => array(
|
||
|
'ANT_POPOVER_PROMO_YIELD' => array(
|
||
|
'title' => $this->l('Activer la popup de la home (promo)'),
|
||
|
'validation' => 'isBool',
|
||
|
'cast' => 'intval',
|
||
|
'type' => 'bool',
|
||
|
'default' => Configuration::get('ANT_POPOVER_PROMO_YIELD'),
|
||
|
'desc' => 'La popup s\'affichera une seule fois par jour',
|
||
|
),
|
||
|
array(
|
||
|
'title' => $this->l('Image popup'),
|
||
|
'type' => 'file',
|
||
|
'label' => $this->l('Image popup'),
|
||
|
'name' => 'imagepopup_promo',
|
||
|
'form_group_class' => 'fieldhide input_img',
|
||
|
'url' => $imagepopup_promo,
|
||
|
'desc' => 'dimension 500px x 500px'
|
||
|
),
|
||
|
'ANT_POPOVER_PROMO_YIELD_LINK' => array(
|
||
|
'title' => $this->l('Lien de la popup'),
|
||
|
'type' => 'text',
|
||
|
'default' => Configuration::get('ANT_POPOVER_PROMO_YIELD_LINK'),
|
||
|
),
|
||
|
'ANT_POPOVER_PROMO_YIELD_TEXT' => array(
|
||
|
'title' => $this->l('Texte du lien'),
|
||
|
'type' => 'text',
|
||
|
'default' => Configuration::get('ANT_POPOVER_PROMO_YIELD_TEXT'),
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
|
||
|
$this->fields_options = array(
|
||
|
/*'popup_home' => array(
|
||
|
'title' => $this->l('POPUP HOME (popup entrée de site)'),
|
||
|
'icon' => 'tab-preferences',
|
||
|
'fields' => $fields['popup_home'],
|
||
|
'submit' => array(
|
||
|
'name' => 'submitPopupHome',
|
||
|
'title' => $this->l('Enregistrer'),
|
||
|
),
|
||
|
),*/
|
||
|
'popup_promo' => array(
|
||
|
'title' => $this->l('POPUP HOME (popup entrée de site, promo)'),
|
||
|
'icon' => 'tab-preferences',
|
||
|
'fields' => $fields['popup_promo'],
|
||
|
'submit' => array(
|
||
|
'name' => 'submitPopupPromo',
|
||
|
'title' => $this->l('Enregistrer'),
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
|
||
|
parent::__construct();
|
||
|
}
|
||
|
|
||
|
public function postProcess(){
|
||
|
parent::postProcess();
|
||
|
|
||
|
if (Tools::isSubmit('submitPopupHome')) {
|
||
|
Configuration::updateValue('ANT_POPOVER_CUSTOMER_YIELD', Tools::getValue('ANT_POPOVER_CUSTOMER_YIELD'));
|
||
|
Configuration::updateValue('ANT_POPOVER_CUSTOMER_YIELD_LINK', Tools::getValue('ANT_POPOVER_CUSTOMER_YIELD_LINK'));
|
||
|
Configuration::updateValue('ANT_POPOVER_CUSTOMER_YIELD_TEXT', Tools::getValue('ANT_POPOVER_CUSTOMER_YIELD_TEXT'));
|
||
|
|
||
|
$languages = Language::getLanguages(false);
|
||
|
foreach ($languages as $language) {
|
||
|
$namePost = 'imagepopup_home_'.$language['id_lang'];
|
||
|
|
||
|
if(isset($_FILES[$namePost]) && !empty($_FILES[$namePost]['tmp_name']) ){
|
||
|
|
||
|
$fileTemp = $_FILES[$namePost]['tmp_name'];
|
||
|
$fileParts = pathinfo($_FILES[$namePost]['name']);
|
||
|
|
||
|
if($fileParts['extension'] == 'jpg' || $fileParts['extension'] == 'png'){
|
||
|
$res = move_uploaded_file($fileTemp, _PS_THEME_DIR_.'img/home/popup_home.png');
|
||
|
if(!$res) {
|
||
|
$this->errors[] = sprintf(Tools::displayError('An error occured during upload of file %s'), 'popup_home.png');
|
||
|
} else {
|
||
|
$this->confirmations[] = sprintf($this->l('File %s has been uploaded'), 'popup_home.png');
|
||
|
}
|
||
|
} else {
|
||
|
$this->errors[] = sprintf(Tools::displayError('File %s have not good extension, only .jpg or .png'), 'popup_home.png');
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if(Tools::isSubmit('submitPopupPromo')) {
|
||
|
Configuration::updateValue('ANT_POPOVER_PROMO_YIELD', Tools::getValue('ANT_POPOVER_PROMO_YIELD'));
|
||
|
Configuration::updateValue('ANT_POPOVER_PROMO_YIELD_LINK', Tools::getValue('ANT_POPOVER_PROMO_YIELD_LINK'));
|
||
|
Configuration::updateValue('ANT_POPOVER_PROMO_YIELD_TEXT', Tools::getValue('ANT_POPOVER_PROMO_YIELD_TEXT'));
|
||
|
|
||
|
$languages = Language::getLanguages(false);
|
||
|
foreach ($languages as $language) {
|
||
|
$namePost = 'imagepopup_promo_'.$language['id_lang'];
|
||
|
|
||
|
if(isset($_FILES[$namePost]) && !empty($_FILES[$namePost]['tmp_name']) ){
|
||
|
|
||
|
$fileTemp = $_FILES[$namePost]['tmp_name'];
|
||
|
$fileParts = pathinfo($_FILES[$namePost]['name']);
|
||
|
|
||
|
if($fileParts['extension'] == 'jpg' || $fileParts['extension'] == 'png'){
|
||
|
$res = move_uploaded_file($fileTemp, _PS_THEME_DIR_.'img/home/popup_promo.png');
|
||
|
if(!$res) {
|
||
|
$this->errors[] = sprintf(Tools::displayError('An error occured during upload of file %s'), 'popup_promo.png');
|
||
|
} else {
|
||
|
$this->confirmations[] = sprintf($this->l('File %s has been uploaded'), 'popup_promo.png');
|
||
|
}
|
||
|
} else {
|
||
|
$this->errors[] = sprintf(Tools::displayError('File %s have not good extension, only .jpg or .png'), 'popup_promo.png');
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (Tools::isSubmit('submitOtherPopups')){
|
||
|
Configuration::updateValue('ANT_POPOVER_CART_YIELD', Tools::getValue('ANT_POPOVER_CART_YIELD'));
|
||
|
Configuration::updateValue('ANT_POPOVER_PRODUCT_YIELD', Tools::getValue('ANT_POPOVER_PRODUCT_YIELD'));
|
||
|
Configuration::updateValue('ANT_POPOVER_CONCOURS_YIELD', Tools::getValue('ANT_POPOVER_CONCOURS_YIELD'));
|
||
|
}
|
||
|
}
|
||
|
}
|