bebeboutik/modules/ant_promobanner/AdminAntPromobanner.php
2017-10-24 18:24:17 +02:00

161 lines
8.9 KiB
PHP

<?php
if(!defined('_PS_VERSION_')) {
exit;
}
require_once(PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php');
class AdminAntPromobanner extends AdminTab
{
public function __construct() {
$this->lang = TRUE;
parent::__construct();
$this->imagelist = array(
'bmobile' => array($this->l('Bannière Mobile'), '500x178'),
//'bsite' => array($this->l('Bannière Site'), '800x300'),
);
}
public function postProcess()
{
global $currentIndex, $cookie;
if(Tools::isSubmit('submitBanners')) {
foreach(Language::getLanguages(false) as $language) {
Configuration::updateValue('ANT_PROMO_BANNER_2',Tools::getValue('enabled_fr', 0));
Configuration::updateValue('ANT_PROMO_BANNER_3',Tools::getValue('enabled_es', 0));
Configuration::updateValue('ANT_PROMO_BANNERURL_2',Tools::getValue('url_2', ''));
Configuration::updateValue('ANT_PROMO_BANNERURL_3',Tools::getValue('url_3', ''));
foreach(array_keys($this->imagelist) as $img) {
if(isset($_FILES['img_'.$img.'_'.$language['id_lang']]) && $_FILES['img_'.$img.'_'.$language['id_lang']]['name'] != '') {
$random = Tools::passwdGen(7);
if (glob(_PS_ROOT_DIR_.'/modules/ant_promobanner/img/img_'.$img.'_*_'.$language['id_lang'].'.jpg')) {
foreach (glob(_PS_ROOT_DIR_.'/modules/ant_promobanner/img/img_'.$img.'_*_'.$language['id_lang'].'.jpg') as $filename) {
unlink($filename);
}
}
if(!copy($_FILES['img_'.$img.'_'.$language['id_lang']]['tmp_name'], _PS_ROOT_DIR_.'/modules/ant_promobanner/img/img_'.$img.'_'.$random.'_'.$language['id_lang'].'.jpg')) {
HelperFormBootstrap::displayErrors($this->l('An error occured during the image upload.'));
}
Configuration::updateValue('ANT_PROMO_BANNERNAME_'.$language['id_lang'], $random);
}
}
}
HelperFormBootstrap::displaySuccess('Mise à jour réussie');
}
}
public function display()
{
global $cookie, $currentIndex;
$languages = Language::getLanguages(false);
$images = array();
foreach(array_keys($this->imagelist) as $img) {
$images[] = 'img_'.$img;
}
$divLangName = 'img_bmobile¤url';
$helper = new HelperFormBootstrap();
$helper->_select2 = true;
$helper->_inputSwitch = true;
$html = $helper->renderStyle();
$html .= '
<div class="row">
<div class="col-md-12">
<div class="panel">
<div class="panel-title">
<h2 style="font-size:24px;"><span class="anticon anticon-images" style="font-size:24px;"></span> Bannière Promotionnelle</h2>
<div class="clearfix"></div>
</div>
<div class="panel-content">
<div class="row">
<form action="'.$currentIndex.'&token='.$this->token.'" method="post" enctype="multipart/form-data">
<div class="col-sm-6 col-sm-offset-3">
<div class="row">
<label class="text-left col-md-12">Activation</label>
</div>';
$input = array(
'type' => 'switch',
'name' => 'enabled_fr',
'title' => $this->l('Version FR'),
'class-group' => 'col-md-6',
'default' => (int)Configuration::get('ANT_PROMO_BANNER_2'),
'checked' => (int)Configuration::get('ANT_PROMO_BANNER_2'),
'required' => true,
);
$html.= $helper->generateInput($input);
$input = array(
'type' => 'switch',
'name' => 'enabled_es',
'title' => $this->l('Version ES'),
'class-group' => 'col-md-6',
'default' => (int)Configuration::get('ANT_PROMO_BANNER_3'),
'checked' => (int)Configuration::get('ANT_PROMO_BANNER_3'),
'required' => true,
);
$html.= $helper->generateInput($input);
$html.= '<div class="clearfix"></div>';
$urldefaults = array(
2 => Configuration::get('ANT_PROMO_BANNERURL_2'),
3 => Configuration::get('ANT_PROMO_BANNERURL_3')
);
$input = array(
'type' => 'text',
'label' => $this->l('Url :'),
'lang' => true,
'name' => 'url',
'id' => 'url',
'required' => true,
'help' => "Renseignez l'url sans le nom de domain, ex : 8737618-boumy pour https://www.bebeboutik.com/8737618-boumy",
'languages' => $languages,
'id_langs' => $divLangName,
'link_flag_img' => '../img/l/',
'default' => $urldefaults
);
$html.= $helper->generateInput($input);
$html.= '<div class="clearfix"></div>';
foreach($this->imagelist as $k => $v) {
$input = array(
'type' => 'uploadImage',
'lang' => true,
'label' => $v[0],
'name' => 'img_'.$k,
'name_img_lang' => array(
2 => 'img_'.$k.'_'.Configuration::get('ANT_PROMO_BANNERNAME_2'),
3 => 'img_'.$k.'_'.Configuration::get('ANT_PROMO_BANNERNAME_3'),
),
'id' => $k,
'help' => 'L\'image sera la même sur tous les écrans (évitez de charger un image trop lourde).<br>Privilégiez un ratio 500*178',
'languages' => $languages,
'default_language' => 2,
'input-class' => '',
'id_langs' => $divLangName,
'link_flag_img' => '../img/l/',
'url_imgs' => __PS_BASE_URI__.'modules/ant_promobanner/img/',
'url_to_show' => _PS_ROOT_DIR_.'/modules/ant_promobanner/img/',
);
$html .= $helper->generateInput($input);
$html .= '<div class="clearfix"></div>';
}
$html .='
</div>
<div class="clear"></div>
<div class="ln_solid-small"></div>
<div class="text-right">
<input type="submit" class="btn btn-primary" name="submitBanners" value="Engregistrer" />
</div>
</form>
</div>
</div>
</div>
</div>
</div>';
$html .= $helper->renderScript();
echo $html;
}
}