From 1947e320c9548671ff5c221fb8cf30db1fec39ce Mon Sep 17 00:00:00 2001 From: fBrignoli Date: Wed, 21 Sep 2011 09:41:54 +0000 Subject: [PATCH] [*] MO : blockcms - Customizable footer git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8680 b9a71923-0436-4b27-9f14-aed3839534dd --- modules/blockcms/blockcms.php | 451 +++++++++++++++++++--------------- modules/blockcms/blockcms.tpl | 4 +- 2 files changed, 258 insertions(+), 197 deletions(-) diff --git a/modules/blockcms/blockcms.php b/modules/blockcms/blockcms.php index 9d53d907f..f1808302f 100755 --- a/modules/blockcms/blockcms.php +++ b/modules/blockcms/blockcms.php @@ -1,40 +1,40 @@ -* @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 7060 $ -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ + * 2007-2011 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-2011 PrestaShop SA + * @version Release: $Revision: 7060 $ + * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) + * International Registered Trademark & Property of PrestaShop SA + */ if (!defined('_PS_VERSION_')) exit; - + class BlockCms extends Module { private $_html; const LEFT_COLUMN = 0; const RIGHT_COLUMN = 1; - + public function __construct() { $this->name = 'blockcms'; @@ -55,8 +55,8 @@ class BlockCms extends Module $languages = Language::getLanguages(false); $queryLang = 'INSERT INTO `'._DB_PREFIX_.'cms_block_lang` (`id_cms_block`, `id_lang`) VALUES'; foreach ($languages AS $language) - $queryLang .= '(1, '.(int)($language['id_lang']).'),'; - + $queryLang .= '(1, '.(int)($language['id_lang']).'),'; + if (!parent::install() OR !$this->registerHook('leftColumn') OR !$this->registerHook('rightColumn') OR !$this->registerHook('footer') OR !$this->registerHook('header') OR !Db::getInstance()->Execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'cms_block`( @@ -88,7 +88,7 @@ class BlockCms extends Module !Configuration::updateValue('FOOTER_CMS', '') OR !Configuration::updateValue('FOOTER_BLOCK_ACTIVATION', 1) OR !Configuration::updateValue('FOOTER_POWEREDBY', 1)) - return false; + return false; return true; } @@ -99,12 +99,12 @@ class BlockCms extends Module !Configuration::deleteByName('FOOTER_BLOCK_ACTIVATION') OR !Configuration::deleteByName('FOOTER_POWEREDBY') OR !Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'cms_block` , `'._DB_PREFIX_.'cms_block_page`, `'._DB_PREFIX_.'cms_block_lang`')) - return false; + return false; return true; } public function getBlockCMS($id_cms_block) - { + { $cmsBlocks = Db::getInstance()->ExecuteS(' SELECT cb.`id_cms_category`, cb.`location`, cb.`display_store`, cbl.id_lang, cbl.name FROM `'._DB_PREFIX_.'cms_block` cb @@ -116,15 +116,15 @@ class BlockCms extends Module { $cmsBlocks['name'][(int)$cmsBlock['id_lang']] = $cmsBlock['name']; if ($store_display_update['0'] < $store_display_update['1']) - $cmsBlocks[$store_display_update['0']]['display_store'] = $store_display_update['2']; + $cmsBlocks[$store_display_update['0']]['display_store'] = $store_display_update['2']; ++$store_display_update['0']; } return $cmsBlocks; } - + private function getBlocksCMS($location) { - + return Db::getInstance()->ExecuteS(' SELECT bc.`id_cms_block`, bcl.`name` block_name, ccl.`name` category_name, bc.`position`, bc.`id_cms_category`, bc.`display_store` FROM `'._DB_PREFIX_.'cms_block` bc @@ -133,7 +133,7 @@ class BlockCms extends Module WHERE ccl.`id_lang` = '.(int)$this->context->language->id.' AND bc.`location` = '.(int)$location.' AND bcl.`id_lang` = '.(int)$this->context->language->id.' ORDER BY bc.`position`'); } - + public function getAllBlocksCMS() { return array_merge($this->getBlocksCMS(self::LEFT_COLUMN), $this->getBlocksCMS(self::RIGHT_COLUMN)); @@ -145,7 +145,7 @@ class BlockCms extends Module $footerCms = Configuration::get('FOOTER_CMS'); if (empty($footerCms)) - return array(); + return array(); $cmsCategories = explode('|', $footerCms); $content = array(); @@ -160,19 +160,19 @@ class BlockCms extends Module INNER JOIN `'._DB_PREFIX_.'cms_category` c ON (cl.`id_cms_category` = c.`id_cms_category`) WHERE cl.`id_cms_category` = '.(int)$ids[1].' AND (c.`active` = 1 OR c.`id_cms_category` = 1) AND cl.`id_lang` = '.(int)$context->language->id); - + $content[$cmsCategory]['link'] = $context->link->getCMSCategoryLink((int)$ids[1], $query['link_rewrite']); $content[$cmsCategory]['meta_title'] = $query['name']; } elseif (!$ids[0]) { $query = Db::getInstance()->getRow(' - SELECT cl.`meta_title`, cl.`link_rewrite` + SELECT cl.`meta_title`, cl.`link_rewrite` FROM `'._DB_PREFIX_.'cms_lang` cl INNER JOIN `'._DB_PREFIX_.'cms` c ON (cl.`id_cms` = c.`id_cms`) WHERE cl.`id_cms` = '.(int)$ids[1].' AND c.`active` = 1 AND cl.`id_lang` = '.(int)$context->language->id); - + $content[$cmsCategory]['link'] = $context->link->getCMSLink((int)$ids[1], $query['link_rewrite']); $content[$cmsCategory]['meta_title'] = $query['meta_title']; } @@ -192,58 +192,58 @@ class BlockCms extends Module INNER JOIN `'._DB_PREFIX_.'cms_block_lang` bcl ON (bc.`id_cms_block` = bcl.`id_cms_block`) WHERE bc.`location` = '.(int)($location).' AND ccl.`id_lang` = '.(int)$context->language->id.' AND bcl.`id_lang` = '.(int)$context->language->id.' AND bc.id_shop = '.$context->shop->getID(true).' ORDER BY `position`'); - + $content = array(); if (is_array($cmsCategories) AND sizeof($cmsCategories)) - foreach ($cmsCategories AS $cmsCategory) - { - $key = (int)$cmsCategory['id_cms_block']; - $content[$key]['display_store'] = $cmsCategory['display_store']; - - $content[$key]['cms'] = Db::getInstance()->ExecuteS(' + foreach ($cmsCategories AS $cmsCategory) + { + $key = (int)$cmsCategory['id_cms_block']; + $content[$key]['display_store'] = $cmsCategory['display_store']; + + $content[$key]['cms'] = Db::getInstance()->ExecuteS(' SELECT cl.`id_cms`, cl.`meta_title`, cl.`link_rewrite` - FROM `'._DB_PREFIX_.'cms_block_page` bcp + FROM `'._DB_PREFIX_.'cms_block_page` bcp INNER JOIN `'._DB_PREFIX_.'cms_lang` cl ON (bcp.`id_cms` = cl.`id_cms`) INNER JOIN `'._DB_PREFIX_.'cms` c ON (bcp.`id_cms` = c.`id_cms`) WHERE bcp.`id_cms_block` = '.(int)$cmsCategory['id_cms_block'].' AND cl.`id_lang` = '.(int)$context->language->id.' AND bcp.`is_category` = 0 AND c.`active` = 1 ORDER BY `position`'); - - $links = array(); - if (sizeof($content[$key]['cms'])) - foreach ($content[$key]['cms'] AS $row) - { - $row['link'] = $context->link->getCMSLink((int)($row['id_cms']), $row['link_rewrite']); - $links[] = $row; - } - - $content[$key]['cms'] = $links; - - $content[$key]['categories'] = Db::getInstance()->ExecuteS(' + + $links = array(); + if (sizeof($content[$key]['cms'])) + foreach ($content[$key]['cms'] AS $row) + { + $row['link'] = $context->link->getCMSLink((int)($row['id_cms']), $row['link_rewrite']); + $links[] = $row; + } + + $content[$key]['cms'] = $links; + + $content[$key]['categories'] = Db::getInstance()->ExecuteS(' SELECT bcp.`id_cms`, cl.`name`, cl.`link_rewrite` - FROM `'._DB_PREFIX_.'cms_block_page` bcp + FROM `'._DB_PREFIX_.'cms_block_page` bcp INNER JOIN `'._DB_PREFIX_.'cms_category_lang` cl ON (bcp.`id_cms` = cl.`id_cms_category`) WHERE bcp.`id_cms_block` = '.(int)$cmsCategory['id_cms_block'].' AND cl.`id_lang` = '.(int)$context->language->id.' AND bcp.`is_category` = 1'); - - $links = array(); - if (sizeof($content[$key]['categories'])) - foreach ($content[$key]['categories'] as $row) - { - $row['link'] = $context->link->getCMSCategoryLink((int)$row['id_cms'], $row['link_rewrite']); - $links[] = $row; - } - - $content[$key]['categories'] = $links; - $content[$key]['name'] = $cmsCategory['block_name']; - $content[$key]['category_link'] = $context->link->getCMSCategoryLink((int)$cmsCategory['id_cms_category'], $cmsCategory['link_rewrite']); - $content[$key]['category_name'] = $cmsCategory['category_name']; + + $links = array(); + if (sizeof($content[$key]['categories'])) + foreach ($content[$key]['categories'] as $row) + { + $row['link'] = $context->link->getCMSCategoryLink((int)$row['id_cms'], $row['link_rewrite']); + $links[] = $row; } + $content[$key]['categories'] = $links; + $content[$key]['name'] = $cmsCategory['block_name']; + $content[$key]['category_link'] = $context->link->getCMSCategoryLink((int)$cmsCategory['id_cms_category'], $cmsCategory['link_rewrite']); + $content[$key]['category_name'] = $cmsCategory['category_name']; + } + return $content; } - + public function getAllCMSTitles() { $titles = array(); @@ -256,47 +256,47 @@ class BlockCms extends Module { unset($title['categories'], $title['name'], $title['category_link'], $title['category_name']); $titles[$key] = $title; - } + } return $titles; } private function displayRecurseCheckboxes($categories, $selected, $has_suite = array()) { static $irow = 0; - + $img = $categories['level_depth'] == 0 ? 'lv1.gif' : 'lv'.($categories['level_depth'] + 1).'_'.((sizeof($categories['cms']) OR isset($categories['children'])) ? 'b' : 'f').'.gif'; - + $this->_html .= ' + (in_array('1_'.$categories['id_cms_category'], $selected) ? ' checked="checked"' : '').' /> '.$categories['id_cms_category'].' '; for ($i = 1; $i < $categories['level_depth']; $i++) - $this->_html .= ''; + $this->_html .= ''; $this->_html .= '   '; if (isset($categories['children'])) - foreach ($categories['children'] as $key => $category) - { - $has_suite[$categories['level_depth']] = 1; - if (sizeof($categories['children']) == $key + 1 AND !sizeof($categories['cms'])) - $has_suite[$categories['level_depth']] = 0; - $this->displayRecurseCheckboxes($category, $selected, $has_suite, 0); - } - + foreach ($categories['children'] as $key => $category) + { + $has_suite[$categories['level_depth']] = 1; + if (sizeof($categories['children']) == $key + 1 AND !sizeof($categories['cms'])) + $has_suite[$categories['level_depth']] = 0; + $this->displayRecurseCheckboxes($category, $selected, $has_suite, 0); + } + $cpt = 0; foreach ($categories['cms'] as $cms) { $this->_html .= ' + (in_array('0_'.$cms['id_cms'], $selected) ? ' checked="checked"' : '').' /> '.$cms['id_cms'].' '; for ($i = 0; $i < $categories['level_depth']; $i++) - $this->_html .= ''; + $this->_html .= ''; $this->_html .= '   '; @@ -305,11 +305,21 @@ class BlockCms extends Module private function _displayForm() { - $this->context = Context::getContext(); + $this->context = Context::getContext(); $cms_blocks_left = $this->getBlocksCMS(0); $cms_blocks_right = $this->getBlocksCMS(1); + $isoTinyMCE = (file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$this->context->language->iso_code.'.js') ? $this->context->language->iso_code : 'en'); + $ad = dirname($_SERVER["PHP_SELF"]); + $this->_html .= ' + + + @@ -317,7 +327,7 @@ class BlockCms extends Module '.$this->l('CMS block configuration').'

'.$this->l('Add a new CMS block').'

'; - + $this->_html .= '

'.$this->l('List of Left CMS blocks').'

'; if (sizeof($cms_blocks_left)) { @@ -348,19 +358,19 @@ class BlockCms extends Module '.$this->l('Up').' - + '; } - $this->_html .= ' + $this->_html .= ' '; } else - $this->_html .= '

'.$this->l('There is no CMS block set').'

'; + $this->_html .= '

'.$this->l('There is no CMS block set').'

'; $this->_html .= '
'; - + $this->_html .= '

'.$this->l('List of Right CMS blocks').'

'; if (sizeof($cms_blocks_right)) { @@ -391,17 +401,30 @@ class BlockCms extends Module '.$this->l('Up').' - + '; } - $this->_html .= ' + $this->_html .= ' '; } else - $this->_html .= '

'.$this->l('There is no CMS block set').'

'; + $this->_html .= '

'.$this->l('There is no CMS block set').'

'; + + $languages = Language::getLanguages(false); + $default_language = (int)Configuration::get('PS_LANG_DEFAULT'); + $div_id_language = 'block_language'; + + $footer_content_i18n = ''; + foreach ($languages as $lang) + $footer_content_i18n .= '
+ +
'; + + $footer_content_i18n .= $this->displayFlags($languages, $default_language, $div_id_language, $div_id_language, true); + $this->_html .= '

@@ -410,13 +433,16 @@ class BlockCms extends Module '.$this->l('Footer\'s various links Configuration').'



- +

+ '.$footer_content_i18n.' + +
'; - $this->displayRecurseCheckboxes(CMSCategory::getRecurseCategory($this->context->language->id), explode('|', Configuration::get('FOOTER_CMS'))); + $this->displayRecurseCheckboxes(CMSCategory::getRecurseCategory($this->context->language->id), explode('|', Configuration::get('FOOTER_CMS'))); $this->_html .= '
'.$this->l('ID').' '.$this->l('Name').'

@@ -432,7 +458,7 @@ class BlockCms extends Module $cmsBlock = NULL; if (Tools::isSubmit('editBlockCMS') AND Tools::getValue('id_cms_block')) - $cmsBlock = $this->getBlockCMS((int)Tools::getValue('id_cms_block')); + $cmsBlock = $this->getBlockCMS((int)Tools::getValue('id_cms_block')); $this->_html .= ' @@ -440,25 +466,25 @@ class BlockCms extends Module
'; if (Tools::getValue('id_cms_block')) - $this->_html .= ''; + $this->_html .= ''; $this->_html .= '
'; - + if (Tools::isSubmit('addBlockCMS')) - $this->_html .= ' '.$this->l('New CMS block').''; + $this->_html .= ' '.$this->l('New CMS block').''; elseif (Tools::isSubmit('editBlockCMS')) - $this->_html .= ' '.$this->l('Edit CMS block').''; - + $this->_html .= ' '.$this->l('Edit CMS block').''; + $this->_html .= '
'; - - foreach ($languages as $language) - $this->_html .= ' + + foreach ($languages as $language) + $this->_html .= '
'; - $this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'name', true); + $this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'name', true); $this->_html .= '

'.$this->l('If you leave this field empty, the block name will use the category name').'


@@ -469,7 +495,7 @@ class BlockCms extends Module $this->_html .= '
- +

' - .$this->l('Display "our stores" at the end of the block') - .'
'; - $this->_html .= '
+ .$this->l('Display "our stores" at the end of the block') + .''; + $this->_html .= '

'.$this->l('Cancel').'

'; - - $this->_html .= ' + + $this->_html .= '
'; @@ -508,29 +534,59 @@ class BlockCms extends Module $languages = Language::getLanguages(false); $cmsBoxes = Tools::getValue('cmsBox'); if (!Validate::isInt(Tools::getValue('PS_STORES_DISPLAY_CMS')) OR (Tools::getValue('PS_STORES_DISPLAY_CMS') != 0 AND Tools::getValue('PS_STORES_DISPLAY_CMS') != 1)) - $errors[] = $this->l('Invalid store display'); + $errors[] = $this->l('Invalid store display'); if (!Validate::isInt(Tools::getValue('block_location')) OR (Tools::getValue('block_location') != self::LEFT_COLUMN AND Tools::getValue('block_location') != self::RIGHT_COLUMN)) - $errors[] = $this->l('Invalid block location'); + $errors[] = $this->l('Invalid block location'); if (!is_array($cmsBoxes)) - $errors[] = $this->l('You must choose at least one page or subcategory to create a CMS block.'); + $errors[] = $this->l('You must choose at least one page or subcategory to create a CMS block.'); else - foreach ($cmsBoxes as $cmsBox) - if (!preg_match("#^[01]_[0-9]+$#", $cmsBox)) - $errors[] = $this->l('Invalid CMS page or category'); + foreach ($cmsBoxes as $cmsBox) + if (!preg_match("#^[01]_[0-9]+$#", $cmsBox)) + $errors[] = $this->l('Invalid CMS page or category'); foreach ($languages as $language) - if (strlen(Tools::getValue('block_name_'.$language['id_lang'])) > 40) - $errors[] = $this->l('Block name is too long'); + if (strlen(Tools::getValue('block_name_'.$language['id_lang'])) > 40) + $errors[] = $this->l('Block name is too long'); } elseif (Tools::isSubmit('deleteBlockCMS') AND !Validate::isInt(Tools::getValue('id_cms_block'))) - $errors[] = $this->l('Invalid id_cms_block'); + $errors[] = $this->l('Invalid id_cms_block'); elseif (Tools::isSubmit('submitFooterCMS')) { if (Tools::getValue('footerBox')) - foreach (Tools::getValue('footerBox') as $cmsBox) - if (!preg_match("#^[01]_[0-9]+$#", $cmsBox)) - $errors[] = $this->l('Invalid CMS page or category'); + foreach (Tools::getValue('footerBox') as $cmsBox) + if (!preg_match("#^[01]_[0-9]+$#", $cmsBox)) + $errors[] = $this->l('Invalid CMS page or category'); + + $empty_footer_text = true; + $footer_text = array(); + $footer_text[(int)Configuration::get('PS_LANG_DEFAULT')] = Tools::getValue('footer_text_'.(int)Configuration::get('PS_LANG_DEFAULT')); + + $languages = Language::getLanguages(false); + // set default values + foreach ($languages as $lang) + { + if ($lang['id_lang'] == (int)Configuration::get('PS_LANG_DEFAULT')) + continue; + + $footer_text_value = Tools::getValue('footer_text_'.(int)$lang['id_lang']); + if (!empty($footer_text_value)) + { + $empty_footer_text = false; + $footer_text[(int)$lang['id_lang']] = $footer_text_value; + } + else + $footer_text[(int)$lang['id_lang']] = $footer_text[(int)Configuration::get('PS_LANG_DEFAULT')]; + } + + if (!$empty_footer_text && empty($footer_text[(int)Configuration::get('PS_LANG_DEFAULT')])) + $errors[] = $this->l('Please provide a footer text for the default language'); + else + { + foreach ($languages as $lang) + Configuration::updateValue('FOOTER_CMS_TEXT_'.(int)$lang['id_lang'], $footer_text[(int)$lang['id_lang']], true); + } + if (Tools::getValue('footer_active') != 0 AND Tools::getValue('footer_active') != 1) - $errors[] = $this->l('Invalid activation footer'); + $errors[] = $this->l('Invalid activation footer'); } if (sizeof($errors)) { @@ -539,14 +595,14 @@ class BlockCms extends Module } return true; } - + private function changePosition() { - if (!Validate::isInt(Tools::getValue('position')) OR - (Tools::getValue('location') != self::LEFT_COLUMN AND Tools::getValue('location') != self::RIGHT_COLUMN) OR - (Tools::getValue('way') != 0 AND Tools::getValue('way') != 1)) - Tools::displayError(); - + if (!Validate::isInt(Tools::getValue('position')) OR + (Tools::getValue('location') != self::LEFT_COLUMN AND Tools::getValue('location') != self::RIGHT_COLUMN) OR + (Tools::getValue('way') != 0 AND Tools::getValue('way') != 1)) + Tools::displayError(); + $this->_html .= 'pos change!'; if (Tools::getValue('way') == 0) { @@ -555,7 +611,7 @@ class BlockCms extends Module SET `position` = '.((int)Tools::getValue('position') + 1).' WHERE `position` = '.((int)Tools::getValue('position')).' AND `location` = '.(int)Tools::getValue('location'))) - Db::getInstance()->Execute(' + Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'cms_block` SET `position` = '.((int)Tools::getValue('position')).' WHERE `id_cms_block` = '.(int)Tools::getValue('id_cms_block')); @@ -567,36 +623,36 @@ class BlockCms extends Module SET `position` = '.((int)Tools::getValue('position') - 1).' WHERE `position` = '.((int)Tools::getValue('position')).' AND `location` = '.(int)Tools::getValue('location'))) - Db::getInstance()->Execute(' + Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'cms_block` SET `position` = '.((int)Tools::getValue('position')).' WHERE `id_cms_block` = '.(int)Tools::getValue('id_cms_block')); } Tools::redirectAdmin(AdminTab::$currentIndex.'index.php?tab=AdminModules&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules')); } - + private function _postProcess() { if (Tools::isSubmit('submitBlockCMS')) { $position = Db::getInstance()->getValue(' - SELECT COUNT(*) - FROM `'._DB_PREFIX_.'cms_block` + SELECT COUNT(*) + FROM `'._DB_PREFIX_.'cms_block` WHERE `location` = '.(int)Tools::getValue('block_location')); $languages = Language::getLanguages(false); if (Tools::isSubmit('addBlockCMS')) { Db::getInstance()->Execute(' - INSERT INTO `'._DB_PREFIX_.'cms_block` (`id_cms_category`, `location`, `position`, `display_store`) - VALUES('.(int)Tools::getValue('id_category').', '.(int)Tools::getValue('block_location').', + INSERT INTO `'._DB_PREFIX_.'cms_block` (`id_cms_category`, `location`, `position`, `display_store`) + VALUES('.(int)Tools::getValue('id_category').', '.(int)Tools::getValue('block_location').', '.(int)$position.', '.(int)Tools::getValue('PS_STORES_DISPLAY_CMS').')'); $id_cms_block = Db::getInstance()->Insert_ID(); foreach ($languages as $language) - Db::getInstance()->Execute(' - INSERT INTO `'._DB_PREFIX_.'cms_block_lang` (`id_cms_block`, `id_lang`, `name`) - VALUES('.(int)$id_cms_block.', '.(int)$language['id_lang'].', + Db::getInstance()->Execute(' + INSERT INTO `'._DB_PREFIX_.'cms_block_lang` (`id_cms_block`, `id_lang`, `name`) + VALUES('.(int)$id_cms_block.', '.(int)$language['id_lang'].', "'.pSQL(Tools::getValue('block_name_'.$language['id_lang'])).'")'); - + Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'cms_block` SET `display_store` = '.Configuration::get('PS_STORES_DISPLAY_FOOTER')); @@ -604,23 +660,23 @@ class BlockCms extends Module elseif (Tools::isSubmit('editBlockCMS')) { $id_cms_block = Tools::getvalue('id_cms_block'); - + $old_block = Db::getInstance()->ExecuteS(' - SELECT `location`, `position` - FROM `'._DB_PREFIX_.'cms_block` + SELECT `location`, `position` + FROM `'._DB_PREFIX_.'cms_block` WHERE `id_cms_block` = '.(int)$id_cms_block); - + $location_change = ($old_block[0]['location'] != (int)Tools::getvalue('block_location')); Db::getInstance()->Execute(' - DELETE FROM `'._DB_PREFIX_.'cms_block_page` + DELETE FROM `'._DB_PREFIX_.'cms_block_page` WHERE `id_cms_block` = '.(int)$id_cms_block); - + if ($location_change == true) - Db::getInstance()->Execute(' - UPDATE `'._DB_PREFIX_.'cms_block` - SET `position` = (`position` - 1) WHERE `position` > '.(int)$old_block[0]['position'].' + Db::getInstance()->Execute(' + UPDATE `'._DB_PREFIX_.'cms_block` + SET `position` = (`position` - 1) WHERE `position` > '.(int)$old_block[0]['position'].' AND `location` = '.(int)$old_block[0]['location']); - + Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'cms_block` SET `location` = '.(int)(Tools::getvalue('block_location')).', @@ -629,29 +685,29 @@ class BlockCms extends Module `position` = '.(int)($position) : '').', `display_store` = '.(int)(Tools::getValue('PS_STORES_DISPLAY_CMS')).' WHERE `id_cms_block` = '.(int)($id_cms_block)); - + Configuration::updateValue('PS_STORES_DISPLAY_FOOTER', (int)(Tools::getValue('PS_STORES_DISPLAY_CMS'))); foreach ($languages as $language) - Db::getInstance()->Execute(' - UPDATE `'._DB_PREFIX_.'cms_block_lang` - SET `name` = "'.pSQL(Tools::getValue('block_name_'.$language['id_lang'])).'" - WHERE `id_cms_block` = '.(int)$id_cms_block.' + Db::getInstance()->Execute(' + UPDATE `'._DB_PREFIX_.'cms_block_lang` + SET `name` = "'.pSQL(Tools::getValue('block_name_'.$language['id_lang'])).'" + WHERE `id_cms_block` = '.(int)$id_cms_block.' AND `id_lang`= '.(int)$language['id_lang']); } $cmsBoxes = Tools::getValue('cmsBox'); if (sizeof($cmsBoxes)) - foreach ($cmsBoxes as $cmsBox) - { - $cms_properties = explode('_', $cmsBox); - Db::getInstance()->Execute(' - INSERT INTO `'._DB_PREFIX_.'cms_block_page` (`id_cms_block`, `id_cms`, `is_category`) + foreach ($cmsBoxes as $cmsBox) + { + $cms_properties = explode('_', $cmsBox); + Db::getInstance()->Execute(' + INSERT INTO `'._DB_PREFIX_.'cms_block_page` (`id_cms_block`, `id_cms`, `is_category`) VALUES('.(int)$id_cms_block.', '.(int)$cms_properties[1].', '.(int)$cms_properties[0].')'); - } + } if (Tools::isSubmit('addBlockCMS')) - Tools::redirectAdmin(AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&addBlockCMSConfirmation'); + Tools::redirectAdmin(AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&addBlockCMSConfirmation'); elseif (Tools::isSubmit('editBlockCMS')) - Tools::redirectAdmin(AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&editBlockCMSConfirmation'); + Tools::redirectAdmin(AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&editBlockCMSConfirmation'); } elseif (Tools::isSubmit('deleteBlockCMS') AND Tools::getValue('id_cms_block')) { @@ -659,62 +715,64 @@ class BlockCms extends Module if (sizeof($old_block)) { Db::getInstance()->Execute(' - UPDATE `'._DB_PREFIX_.'cms_block` - SET `position` = (`position` - 1) - WHERE `position` > '.(int)$old_block[0]['position'].' + UPDATE `'._DB_PREFIX_.'cms_block` + SET `position` = (`position` - 1) + WHERE `position` > '.(int)$old_block[0]['position'].' AND `location` = '.(int)$old_block[0]['location']); - + Db::getInstance()->Execute(' - DELETE FROM `'._DB_PREFIX_.'cms_block` + DELETE FROM `'._DB_PREFIX_.'cms_block` WHERE `id_cms_block` = '.(int)(Tools::getValue('id_cms_block'))); - + Db::getInstance()->Execute(' - DELETE FROM `'._DB_PREFIX_.'cms_block_page` + DELETE FROM `'._DB_PREFIX_.'cms_block_page` WHERE `id_cms_block` = '.(int)(Tools::getValue('id_cms_block'))); - + Tools::redirectAdmin(AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&deleteBlockCMSConfirmation'); } else - $this->_html .= $this->displayError($this->l('Error: you are trying to delete a non-existent block cms')); + $this->_html .= $this->displayError($this->l('Error: you are trying to delete a non-existent block cms')); } elseif (Tools::isSubmit('submitFooterCMS')) { $footer = ''; if (Tools::getValue('footerBox')) - foreach (Tools::getValue('footerBox') as $box) - $footer .= $box.'|'; + foreach (Tools::getValue('footerBox') as $box) + $footer .= $box.'|'; Configuration::updateValue('FOOTER_CMS', rtrim($footer, '|')); Configuration::updateValue('FOOTER_BLOCK_ACTIVATION', Tools::getValue('footer_active')); Configuration::updateValue('FOOTER_POWEREDBY', (Tools::getValue('footer_poweredby_active') == 'on' ? 1 : 0)); - + + + $this->_html = $this->displayConfirmation($this->l('Footer\'s CMS updated')); } elseif (Tools::isSubmit('addBlockCMSConfirmation')) - $this->_html = $this->displayConfirmation($this->l('Block CMS added')); + $this->_html = $this->displayConfirmation($this->l('Block CMS added')); elseif (Tools::isSubmit('editBlockCMSConfirmation')) - $this->_html = $this->displayConfirmation($this->l('Block CMS edited')); + $this->_html = $this->displayConfirmation($this->l('Block CMS edited')); elseif (Tools::isSubmit('deleteBlockCMSConfirmation')) - $this->_html .= $this->displayConfirmation($this->l('Deletion successful')); + $this->_html .= $this->displayConfirmation($this->l('Deletion successful')); elseif (Tools::isSubmit('id_cms_block') AND Tools::isSubmit('way') AND Tools::isSubmit('position') AND Tools::isSubmit('location')) - $this->changePosition(); + $this->changePosition(); } public function getContent() { $this->_html = ''; if ($this->_postValidation()) - $this->_postProcess(); + $this->_postProcess(); $this->_html .= '

'.$this->l('CMS Block configuration').'

'; if (Tools::isSubmit('addBlockCMS') OR Tools::isSubmit('editBlockCMS')) - $this->_displayAddForm(); + $this->_displayAddForm(); else - $this->_displayForm(); + $this->_displayForm(); return $this->_html; } - + public function hookLeftColumn() { - $this->context = Context::getContext(); + $this->context = Context::getContext(); $cms_titles = self::getCMStitles(self::LEFT_COLUMN); $this->context->smarty->assign(array( 'block' => 1, @@ -723,7 +781,7 @@ class BlockCms extends Module )); return $this->display(__FILE__, 'blockcms.tpl'); } - + public function hookRightColumn() { @@ -735,10 +793,10 @@ class BlockCms extends Module )); return $this->display(__FILE__, 'blockcms.tpl'); } - + public function hookFooter() { - + if (Configuration::get('FOOTER_BLOCK_ACTIVATION')) { $cms_titles = self::getCMStitlesFooter(); @@ -747,18 +805,19 @@ class BlockCms extends Module 'cmslinks' => $cms_titles, 'theme_dir' => _PS_THEME_DIR_, 'display_stores_footer' => Configuration::get('PS_STORES_DISPLAY_FOOTER'), - 'display_poweredby' => ((int)Configuration::get('FOOTER_POWEREDBY') === 1 || Configuration::get('FOOTER_POWEREDBY') === false) + 'display_poweredby' => ((int)Configuration::get('FOOTER_POWEREDBY') === 1 || Configuration::get('FOOTER_POWEREDBY') === false), + 'footer_text' => Configuration::get('FOOTER_CMS_TEXT_'.(int)$this->context->language->id) )); return $this->display(__FILE__, 'blockcms.tpl'); } return ''; } - + public function hookHeader($params) { $this->context->controller->addCSS(($this->_path).'blockcms.css', 'all'); } - + public function getL($key) { $trad = array( diff --git a/modules/blockcms/blockcms.tpl b/modules/blockcms/blockcms.tpl index c0a9337e6..c945a0972 100755 --- a/modules/blockcms/blockcms.tpl +++ b/modules/blockcms/blockcms.tpl @@ -1,5 +1,5 @@ {* -* 2007-2011 PrestaShop +* 2007-2011 PrestaShop * * NOTICE OF LICENSE * @@ -58,5 +58,7 @@ {/foreach} {if $display_poweredby}
  • {l s='Powered by' mod='blockcms'} PrestaShop
  • {/if} + + {$footer_text} {/if}