diff --git a/modules/blockcms/views/templates/admin/_configure/helpers/form/form.tpl b/modules/blockcms/views/templates/admin/_configure/helpers/form/form.tpl
index a49f6f970..fcbc49c90 100644
--- a/modules/blockcms/views/templates/admin/_configure/helpers/form/form.tpl
+++ b/modules/blockcms/views/templates/admin/_configure/helpers/form/form.tpl
@@ -25,10 +25,18 @@
{extends file="helpers/form/form.tpl"}
+{block name="label"}
+ {if $input.type == 'cms_blocks'}
+
+ {else}
+ {$smarty.block.parent}
+ {/if}
+{/block}
+
{block name="input"}
{if $input.type == 'cms_blocks'}
-
+
';
+ $this->_html = '';
// Add a link
- if (isset($_POST['submitLinkAdd']))
+ if (Tools::isSubmit('submitLinkAdd') || Tools::isSubmit('updateblocklink'))
{
if (empty($_POST['text_'.Configuration::get('PS_LANG_DEFAULT')]) || empty($_POST['url']))
$this->_html .= $this->displayError($this->l('You must fill in all fields'));
@@ -246,7 +247,7 @@ class BlockLink extends Module
$this->_html .= $this->displayError($this->l('An error occurred during link creation.'));
}
// Update the block title
- elseif (isset($_POST['submitTitle']))
+ elseif (Tools::isSubmit('submitTitle'))
{
if (empty($_POST['title_'.Configuration::get('PS_LANG_DEFAULT')]))
@@ -261,10 +262,10 @@ class BlockLink extends Module
$this->_html .= $this->displayConfirmation($this->l('The block title has been updated.'));
}
// Delete a link
- elseif (Tools::getValue('delete_link') && isset($_GET['id']))
+ elseif (Tools::isSubmit('deleteblocklink') && Tools::getValue('id'))
{
- if (!is_numeric($_GET['id']) || !$this->deleteLink())
+ if (!is_numeric(Tools::getValue('id')) || !$this->deleteLink())
$this->_html .= $this->displayError($this->l('An error occurred during link deletion.'));
else
$this->_html .= $this->displayConfirmation($this->l('The link has been deleted.'));
@@ -278,8 +279,8 @@ class BlockLink extends Module
$this->_html .= $this->displayError($this->l('An error occurred during sort order set-up.'));
}
- $this->_displayForm();
- $this->_list();
+ $this->_html .= $this->renderForm();
+ $this->_html .= $this->renderList();
return $this->_html;
}
@@ -364,7 +365,7 @@ class BlockLink extends Module
'.$this->l('Block URL:').'
-
+
@@ -383,71 +384,199 @@ class BlockLink extends Module
';
}
- private function _list()
+ public function renderList()
{
+ $fields_list = array(
+ 'id' => array(
+ 'title' => $this->l('Id'),
+ 'type' => 'text',
+ ),
+ 'text_'.$this->context->language->id => array(
+ 'title' => $this->l('Text'),
+ 'type' => 'text',
+ ),
+ 'url' => array(
+ 'title' => $this->l('Url'),
+ 'type' => 'text',
+ ),
+ );
+
+ $helper = new HelperList();
+ $helper->shopLinkType = '';
+ $helper->simple_header = true;
+ $helper->identifier = 'id';
+ $helper->actions = array('edit', 'delete');
+ $helper->show_toolbar = false;
+
+ $helper->title = $this->l('Link list');
+ $helper->table = $this->name;
+ $helper->token = Tools::getAdminTokenLite('AdminModules');
+ $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
$links = $this->getLinks();
- $languages = Language::getLanguages();
- $token = Tools::safeOutput(Tools::getValue('token'));
- if (!Validate::isCleanHtml($token))
- $token = '';
- if ($links)
- {
- $this->_html .= '
- ';
- }
- $this->_html .= '
- '.$this->l('Link list').'
-
-
- '.$this->l('ID').'
- '.$this->l('Text').'
- '.$this->l('URL').'
- '.$this->l('Actions').'
- ';
-
- if (!$links)
- $this->_html .= '
-
- '.$this->l('There are no links.').'
- ';
+ if (is_array($links) && count($links))
+ return $helper->generateList($this->getLinks(), $fields_list);
else
- foreach ($links as $link)
- $this->_html .= '
-
- '.(int)$link['id'].'
- '.Tools::safeOutput($link['text_'.$this->context->language->id]).'
- '.Tools::safeOutput($link['url']).'
-
-
-
-
- ';
- $i = 0;
- $nb = count($languages);
- $idLng = 0;
- while ($i < $nb)
+ return false;
+ }
+
+ public function renderForm()
+ {
+ $fields_form_1 = array(
+ 'form' => array(
+ 'legend' => array(
+ 'title' => $this->l('Add a new link'),
+ 'icon' => 'icon-plus-sign-alt'
+ ),
+ 'input' => array(
+ array(
+ 'type' => 'text',
+ 'label' => $this->l('Text'),
+ 'name' => 'text',
+ 'lang' => true,
+ ),
+ array(
+ 'type' => 'text',
+ 'label' => $this->l('Url'),
+ 'name' => 'url',
+ ),
+ array(
+ 'type' => 'switch',
+ 'label' => $this->l('Open in a new window:'),
+ 'name' => 'newWindow',
+ 'is_bool' => true,
+ '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-primary',
+ 'name' => 'submitLinkAdd',
+ )
+ ),
+ );
+
+ $shops = Shop::getShops(true, null, true);
+ if (Shop::isFeatureActive())
{
- if ($languages[$i]['id_lang'] == (int)Configuration::get('PS_LANG_DEFAULT'))
- $idLng = $i;
- $i++;
+ $fields_form_1['form']['input'][] = array(
+ 'type' => 'shop',
+ 'label' => $this->l('Shop association:'),
+ 'name' => 'checkBoxShopAsso',
+ );
}
- $this->_html .= '
-
-
- ';
+
+ $fields_form_2 = array(
+ 'form' => array(
+ 'legend' => array(
+ 'title' => $this->l('Add a new block'),
+ 'icon' => 'icon-plus-sign-alt'
+ ),
+ 'input' => array(
+ array(
+ 'type' => 'text',
+ 'label' => $this->l('Title'),
+ 'name' => 'title',
+ 'lang' => true,
+ ),
+ array(
+ 'type' => 'text',
+ 'label' => $this->l('Url'),
+ 'name' => 'title_url',
+ ),
+ ),
+ 'submit' => array(
+ 'title' => $this->l('Save'),
+ 'class' => 'btn btn-primary',
+ 'name' => 'submitTitle',
+ )
+ ),
+ );
+
+ $fields_form_3 = array(
+ 'form' => array(
+ 'legend' => array(
+ 'title' => $this->l('Settings'),
+ 'icon' => 'icon-cogs'
+ ),
+ 'input' => array(
+ array(
+ 'type' => 'select',
+ 'label' => $this->l('Order list:'),
+ 'name' => 'orderWay',
+ 'options' => array(
+ 'query' => array(
+ array(
+ 'id' => 0,
+ 'name' => $this->l('by most recent links')
+ ),
+ array(
+ 'id' => 1,
+ 'name' => $this->l('by oldest links')
+ )
+ ),
+ 'id' => 'id',
+ 'name' => 'name',
+ )
+ ),
+ ),
+ 'submit' => array(
+ 'title' => $this->l('Save'),
+ 'class' => 'btn btn-primary',
+ 'name' => 'submitOrderWay',
+ )
+ ),
+ );
+
+
+ $helper = new HelperForm();
+ $helper->show_toolbar = false;
+ $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 = 'id_blocklink';
+ $helper->submit_action = 'submit';
+ $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_1, $fields_form_2, $fields_form_3));
+ }
+
+ public function getConfigFieldsValues()
+ {
+ $fields_values = array(
+ 'url' => Tools::getValue('url'),
+ 'newWindow' => Tools::getValue('newWindow'),
+ 'orderWay' => Tools::getValue('orderWay', Configuration::get('PS_BLOCKLINK_ORDERWAY')),
+ 'title_url' => Tools::getValue('title_url', Configuration::get('PS_BLOCKLINK_URL')),
+ );
+
+ $languages = Language::getLanguages(false);
+
+ foreach ($languages as $lang)
+ {
+ $fields_values['text'][$lang['id_lang']] = Tools::getValue('text_'.(int)$lang['id_lang']);
+ $fields_values['title'][$lang['id_lang']] = Tools::getValue('title', Configuration::get('PS_BLOCKLINK_TITLE', $lang['id_lang']));
+ }
+
+ return $fields_values;
}
}