diff --git a/modules/homeslider/homeslider.php b/modules/homeslider/homeslider.php index 2596d04a5..d2f2417b8 100644 --- a/modules/homeslider/homeslider.php +++ b/modules/homeslider/homeslider.php @@ -183,7 +183,6 @@ class HomeSlider extends Module public function getContent() { $this->_html .= $this->headerHTML(); - $this->_html .= '

'.$this->displayName.'.

'; /* Validate & process */ if (Tools::isSubmit('submitSlide') || Tools::isSubmit('delete_id_slide') || @@ -191,14 +190,24 @@ class HomeSlider extends Module Tools::isSubmit('changeStatus')) { if ($this->_postValidation()) + { $this->_postProcess(); - $this->_displayForm(); + $this->_html .= $this->renderForm(); + $this->_html .= $this->renderList(); + } + else + $this->_html .= $this->renderAddForm(); + + } elseif (Tools::isSubmit('addSlide') || (Tools::isSubmit('id_slide') && $this->slideExists((int)Tools::getValue('id_slide')))) - $this->_displayAddForm(); + $this->_html .= $this->renderAddForm(); else - $this->_displayForm(); - + { + $this->_html .= $this->renderForm(); + $this->_html .= $this->renderList(); + } + return $this->_html; } @@ -456,6 +465,8 @@ class HomeSlider extends Module /* If edit : checks id_slide */ if (Tools::isSubmit('id_slide')) { + + //d(var_dump(Tools::getValue('id_slide'))); if (!Validate::isInt(Tools::getValue('id_slide')) && !$this->slideExists(Tools::getValue('id_slide'))) $errors[] = $this->l('Invalid id_slide'); } @@ -774,4 +785,245 @@ class HomeSlider extends Module $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($req); return ($row); } + + public function renderList() + { + $slides = $this->getSlides(); + foreach ($slides as $key => $slide) + $slides[$key]['status'] = $this->displayStatus($slide['id_slide'], $slide['active']); + + $this->context->smarty->assign(array( + 'link' => $this->context->link, + 'slides' => $slides, + )); + + return $this->display(__FILE__, 'list.tpl'); + } + + public function renderAddForm() + { + $fields_form = array( + 'form' => array( + 'legend' => array( + 'title' => $this->l('Slide informations'), + 'icon' => 'icon-cogs' + ), + 'input' => array( + array( + 'type' => 'file_lang', + 'label' => $this->l('Select a file:'), + 'name' => 'image', + 'lang' => true, + ), + array( + 'type' => 'text', + 'label' => $this->l('Title:'), + 'name' => 'title', + 'lang' => true, + ), + array( + 'type' => 'text', + 'label' => $this->l('URL:'), + 'name' => 'url', + 'lang' => true, + ), + array( + 'type' => 'text', + 'label' => $this->l('Legend:'), + 'name' => 'legend', + 'lang' => true, + ), + array( + 'type' => 'textarea', + 'label' => $this->l('Description:'), + 'name' => 'description', + 'lang' => true, + ), + array( + 'type' => 'switch', + 'label' => $this->l('Active'), + 'name' => 'active_slide', + 'is_bool' => true, + 'values' => array( + array( + 'id' => 'active_on', + 'value' => 1, + 'label' => $this->l('Yes') + ), + array( + 'id' => 'active_off', + 'value' => 0, + 'label' => $this->l('No') + ) + ), + ), + ), + 'submit' => array( + 'title' => $this->l('Save'), + 'class' => 'btn btn-default') + ), + ); + + if (Tools::isSubmit('id_slide') && $this->slideExists((int)Tools::getValue('id_slide'))) + { + $slide = new HomeSlide((int)Tools::getValue('id_slide')); + $fields_form['form']['input'][] = array('type' => 'hidden', 'name' => 'id_slide'); + + $has_picture = true; + + foreach (Language::getLanguages(false) as $lang) + if (!isset($slide->image[$lang['id_lang']])) + $has_picture &= false; + + if ($has_picture) + $fields_form['form']['input'][] = array('type' => 'hidden', 'name' => 'has_picture'); + } + + + $helper = new HelperForm(); + $helper->show_toolbar = false; + $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->module = $this; + $helper->identifier = $this->identifier; + $helper->submit_action = 'submitSlide'; + $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name; + $helper->token = Tools::getAdminTokenLite('AdminModules'); + $language = new Language((int)Configuration::get('PS_LANG_DEFAULT')); + $helper->tpl_vars = array( + 'base_url' => $this->context->shop->getBaseURL(), + 'language' => array( + 'id_lang' => $language->id, + 'iso_code' => $language->iso_code + ), + 'fields_value' => $this->getAddFieldsValues(), + 'languages' => $this->context->controller->getLanguages(), + 'id_language' => $this->context->language->id + ); + + $helper->override_folder = '/'; + + return $helper->generateForm(array($fields_form)); + } + + public function renderForm() + { + $fields_form = array( + 'form' => array( + 'legend' => array( + 'title' => $this->l('Settings'), + 'icon' => 'icon-cogs' + ), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l('Height:'), + 'name' => 'HOMESLIDER_HEIGHT', + 'suffix' => 'px' + ), + array( + 'type' => 'text', + 'label' => $this->l('Width:'), + 'name' => 'HOMESLIDER_WIDTH', + 'suffix' => 'px' + ), + array( + 'type' => 'text', + 'label' => $this->l('Speed:'), + 'name' => 'HOMESLIDER_SPEED', + 'suffix' => 'ms' + ), + array( + 'type' => 'text', + 'label' => $this->l('Pause:'), + 'name' => 'HOMESLIDER_PAUSE', + 'suffix' => 'ms' + ), + array( + 'type' => 'switch', + 'label' => $this->l('Loop:'), + 'name' => 'HOMESLIDER_LOOP', + 'values' => array( + array( + 'id' => 'active_on', + 'value' => 1, + 'label' => $this->l('Enabled') + ), + array( + 'id' => 'active_off', + 'value' => 0, + 'label' => $this->l('Disabled') + ) + ), + ) + ), + 'submit' => array( + 'title' => $this->l('Save'), + 'class' => 'btn btn-default') + ), + ); + + $helper = new HelperForm(); + $helper->show_toolbar = false; + $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->identifier = $this->identifier; + $helper->submit_action = 'submitSlider'; + $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 getConfigFieldsValues() + { + return array( + 'HOMESLIDER_HEIGHT' => Tools::getValue('HOMESLIDER_HEIGHT', Configuration::get('HOMESLIDER_HEIGHT')), + 'HOMESLIDER_WIDTH' => Tools::getValue('HOMESLIDER_WIDTH', Configuration::get('HOMESLIDER_WIDTH')), + 'HOMESLIDER_SPEED' => Tools::getValue('HOMESLIDER_SPEED', Configuration::get('HOMESLIDER_SPEED')), + 'HOMESLIDER_PAUSE' => Tools::getValue('HOMESLIDER_PAUSE', Configuration::get('HOMESLIDER_PAUSE')), + 'HOMESLIDER_LOOP' => Tools::getValue('HOMESLIDER_LOOP', Configuration::get('HOMESLIDER_LOOP')), + ); + } + + public function getAddFieldsValues() + { + $fields = array(); + + if (Tools::isSubmit('id_slide') && $this->slideExists((int)Tools::getValue('id_slide'))) + { + $slide = new HomeSlide((int)Tools::getValue('id_slide')); + $fields['id_slide'] = (int)Tools::getValue('id_slide', $slide->id); + } + else + $slide = new HomeSlide(); + + $fields['active_slide'] = Tools::getValue('active_slide', $slide->active); + $fields['has_picture'] = true; + + $languages = Language::getLanguages(false); + + foreach ($languages as $lang) + { + $fields['image'][$lang['id_lang']] = Tools::getValue('image_'.(int)$lang['id_lang']); + $fields['title'][$lang['id_lang']] = Tools::getValue('title_'.(int)$lang['id_lang'], $slide->title[$lang['id_lang']]); + $fields['url'][$lang['id_lang']] = Tools::getValue('url_'.(int)$lang['id_lang'], $slide->url[$lang['id_lang']]); + $fields['legend'][$lang['id_lang']] = Tools::getValue('legend_'.(int)$lang['id_lang'], $slide->legend[$lang['id_lang']]); + $fields['description'][$lang['id_lang']] = Tools::getValue('description_'.(int)$lang['id_lang'], $slide->description[$lang['id_lang']]); + } + + return $fields; + } } diff --git a/modules/homeslider/views/index.php b/modules/homeslider/views/index.php new file mode 100644 index 000000000..fd6bae0d3 --- /dev/null +++ b/modules/homeslider/views/index.php @@ -0,0 +1,35 @@ + +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../../../'); +exit; \ No newline at end of file diff --git a/modules/homeslider/views/templates/admin/_configure/helpers/form/form.tpl b/modules/homeslider/views/templates/admin/_configure/helpers/form/form.tpl new file mode 100644 index 000000000..058d07867 --- /dev/null +++ b/modules/homeslider/views/templates/admin/_configure/helpers/form/form.tpl @@ -0,0 +1,78 @@ +{* +* 2007-2013 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 +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{extends file="helpers/form/form.tpl"} +{block name="field"} + {if $input.type == 'file_lang'} +
+ {foreach from=$languages item=language} + {if $languages|count > 1} +
+ {/if} +
+ +
+ + + + + +
+
+ {if $languages|count > 1} +
+ + +
+ {/if} + {if $languages|count > 1} +
+ {/if} + + {/foreach} +
+ {/if} + {$smarty.block.parent} +{/block} \ No newline at end of file diff --git a/modules/homeslider/views/templates/hook/index.php b/modules/homeslider/views/templates/hook/index.php new file mode 100644 index 000000000..c7a193905 --- /dev/null +++ b/modules/homeslider/views/templates/hook/index.php @@ -0,0 +1,35 @@ + +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../../../../../'); +exit; \ No newline at end of file diff --git a/modules/homeslider/views/templates/hook/list.tpl b/modules/homeslider/views/templates/hook/list.tpl new file mode 100644 index 000000000..ba32d9f5a --- /dev/null +++ b/modules/homeslider/views/templates/hook/list.tpl @@ -0,0 +1,50 @@ +{* +* 2007-2013 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 +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +
+
+ {l s='Slides list'} + + + + + +
+ +
+
    + {foreach from=$slides item=slide} +
  • + #{$slide.id_slide} {$slide.title} +

    + {$slide.status} + {l s='Edit'} + {l s='Delete'} +

    +
  • + {/foreach} +
+
+
\ No newline at end of file diff --git a/modules/homeslider/views/templates/index.php b/modules/homeslider/views/templates/index.php new file mode 100644 index 000000000..3f4b16e7e --- /dev/null +++ b/modules/homeslider/views/templates/index.php @@ -0,0 +1,35 @@ + +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../../../../'); +exit; \ No newline at end of file