From 3f4ce1821da0e6745003f69fdbc99707b5e1dfe3 Mon Sep 17 00:00:00 2001 From: PLESK5 Date: Tue, 16 Aug 2016 14:37:31 +0200 Subject: [PATCH] yieldify --- .../admin/AdminPreferenceYieldify.php | 167 ++++++++++++++++++ .../admin/helpers/uploader/simple.tpl | 61 +++++++ 2 files changed, 228 insertions(+) create mode 100644 modules/yieldify/controllers/admin/AdminPreferenceYieldify.php create mode 100644 modules/yieldify/views/templates/admin/helpers/uploader/simple.tpl diff --git a/modules/yieldify/controllers/admin/AdminPreferenceYieldify.php b/modules/yieldify/controllers/admin/AdminPreferenceYieldify.php new file mode 100644 index 00000000..51273203 --- /dev/null +++ b/modules/yieldify/controllers/admin/AdminPreferenceYieldify.php @@ -0,0 +1,167 @@ +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( + 'YIELDIFY_CUSTOMER_YIELD' => array( + 'title' => $this->l('Activer la popup de la home'), + 'validation' => 'isBool', + 'cast' => 'intval', + 'type' => 'bool', + 'default' => Configuration::get('YIELDIFY_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' + ), + 'YIELDIFY_CUSTOMER_YIELD_LINK' => array( + 'title' => $this->l('Lien de la popup'), + 'type' => 'text', + 'default' => Configuration::get('YIELDIFY_CUSTOMER_YIELD_LINK'), + ), + 'YIELDIFY_CUSTOMER_YIELD_TEXT' => array( + 'title' => $this->l('Texte du lien'), + 'type' => 'text', + 'default' => Configuration::get('YIELDIFY_CUSTOMER_YIELD_TEXT'), + ), + ), + + 'popup_promo' => array( + 'YIELDIFY_PROMO_YIELD' => array( + 'title' => $this->l('Activer la popup de la home (promo)'), + 'validation' => 'isBool', + 'cast' => 'intval', + 'type' => 'bool', + 'default' => Configuration::get('YIELDIFY_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' + ), + 'YIELDIFY_PROMO_YIELD_LINK' => array( + 'title' => $this->l('Lien de la popup'), + 'type' => 'text', + 'default' => Configuration::get('YIELDIFY_PROMO_YIELD_LINK'), + ), + 'YIELDIFY_PROMO_YIELD_TEXT' => array( + 'title' => $this->l('Texte du lien'), + 'type' => 'text', + 'default' => Configuration::get('YIELDIFY_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('YIELDIFY_CUSTOMER_YIELD', Tools::getValue('YIELDIFY_CUSTOMER_YIELD')); + Configuration::updateValue('YIELDIFY_CUSTOMER_YIELD_LINK', Tools::getValue('YIELDIFY_CUSTOMER_YIELD_LINK')); + Configuration::updateValue('YIELDIFY_CUSTOMER_YIELD_TEXT', Tools::getValue('YIELDIFY_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('YIELDIFY_PROMO_YIELD', Tools::getValue('YIELDIFY_PROMO_YIELD')); + Configuration::updateValue('YIELDIFY_PROMO_YIELD_LINK', Tools::getValue('YIELDIFY_PROMO_YIELD_LINK')); + Configuration::updateValue('YIELDIFY_PROMO_YIELD_TEXT', Tools::getValue('YIELDIFY_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('YIELDIFY_CART_YIELD', Tools::getValue('YIELDIFY_CART_YIELD')); + Configuration::updateValue('YIELDIFY_PRODUCT_YIELD', Tools::getValue('YIELDIFY_PRODUCT_YIELD')); + Configuration::updateValue('YIELDIFY_CONCOURS_YIELD', Tools::getValue('YIELDIFY_CONCOURS_YIELD')); + } + } +} diff --git a/modules/yieldify/views/templates/admin/helpers/uploader/simple.tpl b/modules/yieldify/views/templates/admin/helpers/uploader/simple.tpl new file mode 100644 index 00000000..92c42361 --- /dev/null +++ b/modules/yieldify/views/templates/admin/helpers/uploader/simple.tpl @@ -0,0 +1,61 @@ +{assign var=languages value=Language::getLanguages(false)} +{if !isset($defaultFormLanguage)} + {assign var=defaultFormLanguage value=$languages[0].id_lang} +{/if} +
+ {foreach from=$languages item=language} + {if $languages|count > 1} +
+ {/if} +
+ {if $url != "noimg" + && $name != "imagepopup_home" + && $name != "imagepopup_promo"} + + {/if} + {if $name == "imagebg" + || $name == "imagepopup_home" + || $name == "imagepopup_promo"} + + {/if} + +
+ + + + + +
+
+ {if $languages|count > 1} +
+ + +
+ {/if} + {if $languages|count > 1} +
+ {/if} + + {/foreach} +
\ No newline at end of file