[*] MO : blockcms - Customizable footer

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8680 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
fBrignoli
2011-09-21 09:41:54 +00:00
parent 1b836a3920
commit 1947e320c9
2 changed files with 258 additions and 197 deletions
+255 -196
View File
@@ -1,40 +1,40 @@
<?php <?php
/* /*
* 2007-2011 PrestaShop * 2007-2011 PrestaShop
* *
* NOTICE OF LICENSE * NOTICE OF LICENSE
* *
* This source file is subject to the Academic Free License (AFL 3.0) * This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt. * that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL: * It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php * http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to * 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 * obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately. * to license@prestashop.com so we can send you a copy immediately.
* *
* DISCLAIMER * DISCLAIMER
* *
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer * 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 * versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information. * needs please refer to http://www.prestashop.com for more information.
* *
* @author PrestaShop SA <contact@prestashop.com> * @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2011 PrestaShop SA * @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7060 $ * @version Release: $Revision: 7060 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*/ */
if (!defined('_PS_VERSION_')) if (!defined('_PS_VERSION_'))
exit; exit;
class BlockCms extends Module class BlockCms extends Module
{ {
private $_html; private $_html;
const LEFT_COLUMN = 0; const LEFT_COLUMN = 0;
const RIGHT_COLUMN = 1; const RIGHT_COLUMN = 1;
public function __construct() public function __construct()
{ {
$this->name = 'blockcms'; $this->name = 'blockcms';
@@ -55,8 +55,8 @@ class BlockCms extends Module
$languages = Language::getLanguages(false); $languages = Language::getLanguages(false);
$queryLang = 'INSERT INTO `'._DB_PREFIX_.'cms_block_lang` (`id_cms_block`, `id_lang`) VALUES'; $queryLang = 'INSERT INTO `'._DB_PREFIX_.'cms_block_lang` (`id_cms_block`, `id_lang`) VALUES';
foreach ($languages AS $language) 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 if (!parent::install() OR !$this->registerHook('leftColumn') OR !$this->registerHook('rightColumn') OR !$this->registerHook('footer') OR !$this->registerHook('header') OR
!Db::getInstance()->Execute(' !Db::getInstance()->Execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'cms_block`( 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_CMS', '') OR
!Configuration::updateValue('FOOTER_BLOCK_ACTIVATION', 1) OR !Configuration::updateValue('FOOTER_BLOCK_ACTIVATION', 1) OR
!Configuration::updateValue('FOOTER_POWEREDBY', 1)) !Configuration::updateValue('FOOTER_POWEREDBY', 1))
return false; return false;
return true; return true;
} }
@@ -99,12 +99,12 @@ class BlockCms extends Module
!Configuration::deleteByName('FOOTER_BLOCK_ACTIVATION') OR !Configuration::deleteByName('FOOTER_BLOCK_ACTIVATION') OR
!Configuration::deleteByName('FOOTER_POWEREDBY') 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`')) !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; return true;
} }
public function getBlockCMS($id_cms_block) public function getBlockCMS($id_cms_block)
{ {
$cmsBlocks = Db::getInstance()->ExecuteS(' $cmsBlocks = Db::getInstance()->ExecuteS('
SELECT cb.`id_cms_category`, cb.`location`, cb.`display_store`, cbl.id_lang, cbl.name SELECT cb.`id_cms_category`, cb.`location`, cb.`display_store`, cbl.id_lang, cbl.name
FROM `'._DB_PREFIX_.'cms_block` cb FROM `'._DB_PREFIX_.'cms_block` cb
@@ -116,15 +116,15 @@ class BlockCms extends Module
{ {
$cmsBlocks['name'][(int)$cmsBlock['id_lang']] = $cmsBlock['name']; $cmsBlocks['name'][(int)$cmsBlock['id_lang']] = $cmsBlock['name'];
if ($store_display_update['0'] < $store_display_update['1']) 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']; ++$store_display_update['0'];
} }
return $cmsBlocks; return $cmsBlocks;
} }
private function getBlocksCMS($location) private function getBlocksCMS($location)
{ {
return Db::getInstance()->ExecuteS(' 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` 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 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.' 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`'); ORDER BY bc.`position`');
} }
public function getAllBlocksCMS() public function getAllBlocksCMS()
{ {
return array_merge($this->getBlocksCMS(self::LEFT_COLUMN), $this->getBlocksCMS(self::RIGHT_COLUMN)); 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'); $footerCms = Configuration::get('FOOTER_CMS');
if (empty($footerCms)) if (empty($footerCms))
return array(); return array();
$cmsCategories = explode('|', $footerCms); $cmsCategories = explode('|', $footerCms);
$content = array(); $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`) 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) 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); AND cl.`id_lang` = '.(int)$context->language->id);
$content[$cmsCategory]['link'] = $context->link->getCMSCategoryLink((int)$ids[1], $query['link_rewrite']); $content[$cmsCategory]['link'] = $context->link->getCMSCategoryLink((int)$ids[1], $query['link_rewrite']);
$content[$cmsCategory]['meta_title'] = $query['name']; $content[$cmsCategory]['meta_title'] = $query['name'];
} }
elseif (!$ids[0]) elseif (!$ids[0])
{ {
$query = Db::getInstance()->getRow(' $query = Db::getInstance()->getRow('
SELECT cl.`meta_title`, cl.`link_rewrite` SELECT cl.`meta_title`, cl.`link_rewrite`
FROM `'._DB_PREFIX_.'cms_lang` cl FROM `'._DB_PREFIX_.'cms_lang` cl
INNER JOIN `'._DB_PREFIX_.'cms` c ON (cl.`id_cms` = c.`id_cms`) INNER JOIN `'._DB_PREFIX_.'cms` c ON (cl.`id_cms` = c.`id_cms`)
WHERE cl.`id_cms` = '.(int)$ids[1].' AND c.`active` = 1 WHERE cl.`id_cms` = '.(int)$ids[1].' AND c.`active` = 1
AND cl.`id_lang` = '.(int)$context->language->id); AND cl.`id_lang` = '.(int)$context->language->id);
$content[$cmsCategory]['link'] = $context->link->getCMSLink((int)$ids[1], $query['link_rewrite']); $content[$cmsCategory]['link'] = $context->link->getCMSLink((int)$ids[1], $query['link_rewrite']);
$content[$cmsCategory]['meta_title'] = $query['meta_title']; $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`) 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).' 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`'); ORDER BY `position`');
$content = array(); $content = array();
if (is_array($cmsCategories) AND sizeof($cmsCategories)) if (is_array($cmsCategories) AND sizeof($cmsCategories))
foreach ($cmsCategories AS $cmsCategory) foreach ($cmsCategories AS $cmsCategory)
{ {
$key = (int)$cmsCategory['id_cms_block']; $key = (int)$cmsCategory['id_cms_block'];
$content[$key]['display_store'] = $cmsCategory['display_store']; $content[$key]['display_store'] = $cmsCategory['display_store'];
$content[$key]['cms'] = Db::getInstance()->ExecuteS(' $content[$key]['cms'] = Db::getInstance()->ExecuteS('
SELECT cl.`id_cms`, cl.`meta_title`, cl.`link_rewrite` 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_lang` cl ON (bcp.`id_cms` = cl.`id_cms`)
INNER JOIN `'._DB_PREFIX_.'cms` c ON (bcp.`id_cms` = c.`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 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`'); ORDER BY `position`');
$links = array(); $links = array();
if (sizeof($content[$key]['cms'])) if (sizeof($content[$key]['cms']))
foreach ($content[$key]['cms'] AS $row) foreach ($content[$key]['cms'] AS $row)
{ {
$row['link'] = $context->link->getCMSLink((int)($row['id_cms']), $row['link_rewrite']); $row['link'] = $context->link->getCMSLink((int)($row['id_cms']), $row['link_rewrite']);
$links[] = $row; $links[] = $row;
} }
$content[$key]['cms'] = $links; $content[$key]['cms'] = $links;
$content[$key]['categories'] = Db::getInstance()->ExecuteS(' $content[$key]['categories'] = Db::getInstance()->ExecuteS('
SELECT bcp.`id_cms`, cl.`name`, cl.`link_rewrite` 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`) 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'].' WHERE bcp.`id_cms_block` = '.(int)$cmsCategory['id_cms_block'].'
AND cl.`id_lang` = '.(int)$context->language->id.' AND cl.`id_lang` = '.(int)$context->language->id.'
AND bcp.`is_category` = 1'); AND bcp.`is_category` = 1');
$links = array(); $links = array();
if (sizeof($content[$key]['categories'])) if (sizeof($content[$key]['categories']))
foreach ($content[$key]['categories'] as $row) foreach ($content[$key]['categories'] as $row)
{ {
$row['link'] = $context->link->getCMSCategoryLink((int)$row['id_cms'], $row['link_rewrite']); $row['link'] = $context->link->getCMSCategoryLink((int)$row['id_cms'], $row['link_rewrite']);
$links[] = $row; $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'];
} }
$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; return $content;
} }
public function getAllCMSTitles() public function getAllCMSTitles()
{ {
$titles = array(); $titles = array();
@@ -256,47 +256,47 @@ class BlockCms extends Module
{ {
unset($title['categories'], $title['name'], $title['category_link'], $title['category_name']); unset($title['categories'], $title['name'], $title['category_link'], $title['category_name']);
$titles[$key] = $title; $titles[$key] = $title;
} }
return $titles; return $titles;
} }
private function displayRecurseCheckboxes($categories, $selected, $has_suite = array()) private function displayRecurseCheckboxes($categories, $selected, $has_suite = array())
{ {
static $irow = 0; 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'; $img = $categories['level_depth'] == 0 ? 'lv1.gif' : 'lv'.($categories['level_depth'] + 1).'_'.((sizeof($categories['cms']) OR isset($categories['children'])) ? 'b' : 'f').'.gif';
$this->_html .= ' $this->_html .= '
<tr '.($irow++ % 2 ? 'class="alt_row"' : '').'> <tr '.($irow++ % 2 ? 'class="alt_row"' : '').'>
<td width="3%"><input type="checkbox" name="footerBox[]" class="cmsBox" id="1_'.$categories['id_cms_category'].'" value="1_'.$categories['id_cms_category'].'" '. <td width="3%"><input type="checkbox" name="footerBox[]" class="cmsBox" id="1_'.$categories['id_cms_category'].'" value="1_'.$categories['id_cms_category'].'" '.
(in_array('1_'.$categories['id_cms_category'], $selected) ? ' checked="checked"' : '').' /></td> (in_array('1_'.$categories['id_cms_category'], $selected) ? ' checked="checked"' : '').' /></td>
<td width="3%">'.$categories['id_cms_category'].'</td> <td width="3%">'.$categories['id_cms_category'].'</td>
<td width="94%">'; <td width="94%">';
for ($i = 1; $i < $categories['level_depth']; $i++) for ($i = 1; $i < $categories['level_depth']; $i++)
$this->_html .= '<img style="vertical-align:middle;" src="../img/admin/lvl_'.$has_suite[$i - 1].'.gif" alt="" />'; $this->_html .= '<img style="vertical-align:middle;" src="../img/admin/lvl_'.$has_suite[$i - 1].'.gif" alt="" />';
$this->_html .= '<img style="vertical-align:middle;" src="../img/admin/'.($categories['level_depth'] == 0 ? 'lv1' : 'lv2_'.(($has_suite[$categories['level_depth'] - 1]) ? 'b' : 'f')).'.gif" alt="" /> &nbsp; $this->_html .= '<img style="vertical-align:middle;" src="../img/admin/'.($categories['level_depth'] == 0 ? 'lv1' : 'lv2_'.(($has_suite[$categories['level_depth'] - 1]) ? 'b' : 'f')).'.gif" alt="" /> &nbsp;
<label for="1_'.$categories['id_cms_category'].'" class="t"><b>'.$categories['name'].'</b></label></td> <label for="1_'.$categories['id_cms_category'].'" class="t"><b>'.$categories['name'].'</b></label></td>
</tr>'; </tr>';
if (isset($categories['children'])) if (isset($categories['children']))
foreach ($categories['children'] as $key => $category) foreach ($categories['children'] as $key => $category)
{ {
$has_suite[$categories['level_depth']] = 1; $has_suite[$categories['level_depth']] = 1;
if (sizeof($categories['children']) == $key + 1 AND !sizeof($categories['cms'])) if (sizeof($categories['children']) == $key + 1 AND !sizeof($categories['cms']))
$has_suite[$categories['level_depth']] = 0; $has_suite[$categories['level_depth']] = 0;
$this->displayRecurseCheckboxes($category, $selected, $has_suite, 0); $this->displayRecurseCheckboxes($category, $selected, $has_suite, 0);
} }
$cpt = 0; $cpt = 0;
foreach ($categories['cms'] as $cms) foreach ($categories['cms'] as $cms)
{ {
$this->_html .= ' $this->_html .= '
<tr '.($irow++ % 2 ? 'class="alt_row"' : '').'> <tr '.($irow++ % 2 ? 'class="alt_row"' : '').'>
<td width="3%"><input type="checkbox" name="footerBox[]" class="cmsBox" id="0_'.$cms['id_cms'].'" value="0_'.$cms['id_cms'].'" '. <td width="3%"><input type="checkbox" name="footerBox[]" class="cmsBox" id="0_'.$cms['id_cms'].'" value="0_'.$cms['id_cms'].'" '.
(in_array('0_'.$cms['id_cms'], $selected) ? ' checked="checked"' : '').' /></td> (in_array('0_'.$cms['id_cms'], $selected) ? ' checked="checked"' : '').' /></td>
<td width="3%">'.$cms['id_cms'].'</td> <td width="3%">'.$cms['id_cms'].'</td>
<td width="94%">'; <td width="94%">';
for ($i = 0; $i < $categories['level_depth']; $i++) for ($i = 0; $i < $categories['level_depth']; $i++)
$this->_html .= '<img style="vertical-align:middle;" src="../img/admin/lvl_'.$has_suite[$i].'.gif" alt="" />'; $this->_html .= '<img style="vertical-align:middle;" src="../img/admin/lvl_'.$has_suite[$i].'.gif" alt="" />';
$this->_html .= '<img style="vertical-align:middle;" src="../img/admin/lv2_'.(++$cpt == sizeof($categories['cms']) ? 'f' : 'b').'.gif" alt="" /> &nbsp; $this->_html .= '<img style="vertical-align:middle;" src="../img/admin/lv2_'.(++$cpt == sizeof($categories['cms']) ? 'f' : 'b').'.gif" alt="" /> &nbsp;
<label for="0_'.$cms['id_cms'].'" class="t" style="margin-top:6px;">'.$cms['meta_title'].'</label></td> <label for="0_'.$cms['id_cms'].'" class="t" style="margin-top:6px;">'.$cms['meta_title'].'</label></td>
</tr>'; </tr>';
@@ -305,11 +305,21 @@ class BlockCms extends Module
private function _displayForm() private function _displayForm()
{ {
$this->context = Context::getContext(); $this->context = Context::getContext();
$cms_blocks_left = $this->getBlocksCMS(0); $cms_blocks_left = $this->getBlocksCMS(0);
$cms_blocks_right = $this->getBlocksCMS(1); $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 .= ' $this->_html .= '
<script type="text/javascript">
var iso = \''.$isoTinyMCE.'\' ;
var pathCSS = \''._THEME_CSS_DIR_.'\' ;
var ad = \''.$ad.'\' ;
</script>
<script type="text/javascript" src="'.__PS_BASE_URI__.'js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="'.__PS_BASE_URI__.'js/tinymce.inc.js"></script>
<script type="text/javascript" src="../js/jquery/jquery.tablednd_0_5.js"></script> <script type="text/javascript" src="../js/jquery/jquery.tablednd_0_5.js"></script>
<script type="text/javascript" src="../modules/blockcms/blockcms.js"></script> <script type="text/javascript" src="../modules/blockcms/blockcms.js"></script>
<script type="text/javascript">CMSBlocksDnD(\''.$this->secure_key.'\');</script> <script type="text/javascript">CMSBlocksDnD(\''.$this->secure_key.'\');</script>
@@ -317,7 +327,7 @@ class BlockCms extends Module
<legend><img src="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/logo.gif" alt="" /> '.$this->l('CMS block configuration').'</legend> <legend><img src="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/logo.gif" alt="" /> '.$this->l('CMS block configuration').'</legend>
<p><a href="'.AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&addBlockCMS"><img src="'._PS_ADMIN_IMG_.'add.gif" alt="" /> '.$this->l('Add a new CMS block').'</a></p>'; <p><a href="'.AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&addBlockCMS"><img src="'._PS_ADMIN_IMG_.'add.gif" alt="" /> '.$this->l('Add a new CMS block').'</a></p>';
$this->_html .= '<div style="width:440px; float:left; margin-right:10px;" ><h3>'.$this->l('List of Left CMS blocks').'</h3>'; $this->_html .= '<div style="width:440px; float:left; margin-right:10px;" ><h3>'.$this->l('List of Left CMS blocks').'</h3>';
if (sizeof($cms_blocks_left)) if (sizeof($cms_blocks_left))
{ {
@@ -348,19 +358,19 @@ class BlockCms extends Module
<img src="../img/admin/up.gif" alt="'.$this->l('Up').'" title="'.$this->l('Up').'" /></a> <img src="../img/admin/up.gif" alt="'.$this->l('Up').'" title="'.$this->l('Up').'" /></a>
</td> </td>
<td width="10%" class="center"> <td width="10%" class="center">
<a href="'.AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&editBlockCMS&id_cms_block='.(int)($cms_block['id_cms_block']).'" title="'.$this->l('Edit').'"><img src="'._PS_ADMIN_IMG_.'edit.gif" alt="" /></a> <a href="'.AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&editBlockCMS&id_cms_block='.(int)($cms_block['id_cms_block']).'" title="'.$this->l('Edit').'"><img src="'._PS_ADMIN_IMG_.'edit.gif" alt="" /></a>
<a href="'.AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&deleteBlockCMS&id_cms_block='.(int)($cms_block['id_cms_block']).'" title="'.$this->l('Delete').'"><img src="'._PS_ADMIN_IMG_.'delete.gif" alt="" /></a> <a href="'.AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&deleteBlockCMS&id_cms_block='.(int)($cms_block['id_cms_block']).'" title="'.$this->l('Delete').'"><img src="'._PS_ADMIN_IMG_.'delete.gif" alt="" /></a>
</td> </td>
</tr>'; </tr>';
} }
$this->_html .= ' $this->_html .= '
</tbody> </tbody>
</table>'; </table>';
} }
else else
$this->_html .= '<p style="margin-left:40px;">'.$this->l('There is no CMS block set').'</p>'; $this->_html .= '<p style="margin-left:40px;">'.$this->l('There is no CMS block set').'</p>';
$this->_html .= '</div>'; $this->_html .= '</div>';
$this->_html .= '<div style="width:440px; float:left;" ><h3>'.$this->l('List of Right CMS blocks').'</h3>'; $this->_html .= '<div style="width:440px; float:left;" ><h3>'.$this->l('List of Right CMS blocks').'</h3>';
if (sizeof($cms_blocks_right)) if (sizeof($cms_blocks_right))
{ {
@@ -391,17 +401,30 @@ class BlockCms extends Module
<img src="../img/admin/up.gif" alt="'.$this->l('Up').'" title="'.$this->l('Up').'" /></a> <img src="../img/admin/up.gif" alt="'.$this->l('Up').'" title="'.$this->l('Up').'" /></a>
</td> </td>
<td width="10%" class="center"> <td width="10%" class="center">
<a href="'.AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&editBlockCMS&id_cms_block='.(int)($cms_block['id_cms_block']).'" title="'.$this->l('Edit').'"><img src="'._PS_ADMIN_IMG_.'edit.gif" alt="" /></a> <a href="'.AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&editBlockCMS&id_cms_block='.(int)($cms_block['id_cms_block']).'" title="'.$this->l('Edit').'"><img src="'._PS_ADMIN_IMG_.'edit.gif" alt="" /></a>
<a href="'.AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&deleteBlockCMS&id_cms_block='.(int)($cms_block['id_cms_block']).'" title="'.$this->l('Delete').'"><img src="'._PS_ADMIN_IMG_.'delete.gif" alt="" /></a> <a href="'.AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&deleteBlockCMS&id_cms_block='.(int)($cms_block['id_cms_block']).'" title="'.$this->l('Delete').'"><img src="'._PS_ADMIN_IMG_.'delete.gif" alt="" /></a>
</td> </td>
</tr>'; </tr>';
} }
$this->_html .= ' $this->_html .= '
</tbody> </tbody>
</table>'; </table>';
} }
else else
$this->_html .= '<p style="margin-left:40px;">'.$this->l('There is no CMS block set').'</p>'; $this->_html .= '<p style="margin-left:40px;">'.$this->l('There is no CMS block set').'</p>';
$languages = Language::getLanguages(false);
$default_language = (int)Configuration::get('PS_LANG_DEFAULT');
$div_id_language = 'block_language';
$footer_content_i18n = '<script type="text/javascript">id_language = Number('.$default_language.');</script>';
foreach ($languages as $lang)
$footer_content_i18n .= '<div id="block_language_'.$lang['id_lang'].'" style="display: '.($lang['id_lang'] == $default_language ? 'block' : 'none').'; float:left;">
<textarea class="rte" name="footer_text_'.(int)$lang['id_lang'].'">'.Tools::htmlentitiesUTF8(Configuration::get('FOOTER_CMS_TEXT_'.(int)$lang['id_lang'])).'</textarea>
</div>';
$footer_content_i18n .= $this->displayFlags($languages, $default_language, $div_id_language, $div_id_language, true);
$this->_html .= '</div> $this->_html .= '</div>
<div class="clear"></div> <div class="clear"></div>
</fieldset><br /> </fieldset><br />
@@ -410,13 +433,16 @@ class BlockCms extends Module
<legend><img src="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/logo.gif" alt="" /> '.$this->l('Footer\'s various links Configuration').'</legend> <legend><img src="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/logo.gif" alt="" /> '.$this->l('Footer\'s various links Configuration').'</legend>
<input type="checkbox" name="footer_poweredby_active" id="footer_poweredby_active" '.(((int)Configuration::get('FOOTER_POWEREDBY') === 1 || Configuration::get('FOOTER_POWEREDBY') === false) ? 'checked="checked"' : '').'> <label for="footer_active" style="float:none;">'.$this->l('Display "Powered by Prestashop"').'</label><br /><br /> <input type="checkbox" name="footer_poweredby_active" id="footer_poweredby_active" '.(((int)Configuration::get('FOOTER_POWEREDBY') === 1 || Configuration::get('FOOTER_POWEREDBY') === false) ? 'checked="checked"' : '').'> <label for="footer_active" style="float:none;">'.$this->l('Display "Powered by Prestashop"').'</label><br /><br />
<input type="checkbox" name="footer_active" id="footer_active" '.(Configuration::get('FOOTER_BLOCK_ACTIVATION') ? 'checked="checked"' : '').'> <label for="footer_active" style="float:none;">'.$this->l('Display the Footer\'s various links').'</label><br /><br /> <input type="checkbox" name="footer_active" id="footer_active" '.(Configuration::get('FOOTER_BLOCK_ACTIVATION') ? 'checked="checked"' : '').'> <label for="footer_active" style="float:none;">'.$this->l('Display the Footer\'s various links').'</label><br /><br />
<table cellspacing="0" cellpadding="0" class="table" width="100%"> <label style="display:block; padding:0; text-align: left">'.$this->l('Footer informations:').'</label><br /><br />
'.$footer_content_i18n.'
<table cellspacing="0" style="margin-top: 20px" cellpadding="0" class="table" width="100%">
<tr> <tr>
<th width="3%"><input type="checkbox" name="checkme" class="noborder" onclick="checkallCMSBoxes($(this).attr(\'checked\'))" /></th> <th width="3%"><input type="checkbox" name="checkme" class="noborder" onclick="checkallCMSBoxes($(this).attr(\'checked\'))" /></th>
<th width="3%">'.$this->l('ID').'</th> <th width="3%">'.$this->l('ID').'</th>
<th width="94%">'.$this->l('Name').'</th> <th width="94%">'.$this->l('Name').'</th>
</tr>'; </tr>';
$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->_html .= '
</table> </table>
<p class="center"><input type="submit" class="button" name="submitFooterCMS" value="'.$this->l('Save').'" /></p> <p class="center"><input type="submit" class="button" name="submitFooterCMS" value="'.$this->l('Save').'" /></p>
@@ -432,7 +458,7 @@ class BlockCms extends Module
$cmsBlock = NULL; $cmsBlock = NULL;
if (Tools::isSubmit('editBlockCMS') AND Tools::getValue('id_cms_block')) 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 .= ' $this->_html .= '
<script type="text/javascript" src="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/'.$this->name.'.js"></script> <script type="text/javascript" src="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/'.$this->name.'.js"></script>
@@ -440,25 +466,25 @@ class BlockCms extends Module
<form method="POST" action="'.Tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']).'"> <form method="POST" action="'.Tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']).'">
'; ';
if (Tools::getValue('id_cms_block')) if (Tools::getValue('id_cms_block'))
$this->_html .= '<input type="hidden" name="id_cms_block" value="'.(int)Tools::getValue('id_cms_block').'" id="id_cms_block" />'; $this->_html .= '<input type="hidden" name="id_cms_block" value="'.(int)Tools::getValue('id_cms_block').'" id="id_cms_block" />';
$this->_html .= ' $this->_html .= '
<fieldset>'; <fieldset>';
if (Tools::isSubmit('addBlockCMS')) if (Tools::isSubmit('addBlockCMS'))
$this->_html .= '<legend><img src="'._PS_ADMIN_IMG_.'add.gif" alt="" /> '.$this->l('New CMS block').'</legend>'; $this->_html .= '<legend><img src="'._PS_ADMIN_IMG_.'add.gif" alt="" /> '.$this->l('New CMS block').'</legend>';
elseif (Tools::isSubmit('editBlockCMS')) elseif (Tools::isSubmit('editBlockCMS'))
$this->_html .= '<legend><img src="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/logo.gif" alt="" /> '.$this->l('Edit CMS block').'</legend>'; $this->_html .= '<legend><img src="'._PS_BASE_URL_.__PS_BASE_URI__.'modules/'.$this->name.'/logo.gif" alt="" /> '.$this->l('Edit CMS block').'</legend>';
$this->_html .= ' $this->_html .= '
<label>'.$this->l('Name of block:').'</label> <label>'.$this->l('Name of block:').'</label>
<div class="margin-form">'; <div class="margin-form">';
foreach ($languages as $language) foreach ($languages as $language)
$this->_html .= ' $this->_html .= '
<div id="name_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $defaultLanguage ? 'block' : 'none').';float: left;"> <div id="name_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $defaultLanguage ? 'block' : 'none').';float: left;">
<input type="text" name="block_name_'.$language['id_lang'].'" id="block_name_'.$language['id_lang'].'" size="30" value="'.(Tools::getValue('block_name_'.$language['id_lang']) ? Tools::getValue('block_name_'.$language['id_lang']) : (isset($cmsBlock['name'][$language['id_lang']]) ? $cmsBlock['name'][$language['id_lang']] : '')).'" /> <input type="text" name="block_name_'.$language['id_lang'].'" id="block_name_'.$language['id_lang'].'" size="30" value="'.(Tools::getValue('block_name_'.$language['id_lang']) ? Tools::getValue('block_name_'.$language['id_lang']) : (isset($cmsBlock['name'][$language['id_lang']]) ? $cmsBlock['name'][$language['id_lang']] : '')).'" />
</div>'; </div>';
$this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'name', true); $this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'name', true);
$this->_html .= '<p class="clear">'.$this->l('If you leave this field empty, the block name will use the category name').'</p> $this->_html .= '<p class="clear">'.$this->l('If you leave this field empty, the block name will use the category name').'</p>
</div><br /> </div><br />
<label for="id_category">'.$this->l('Choose a CMS category:').'</label> <label for="id_category">'.$this->l('Choose a CMS category:').'</label>
@@ -469,7 +495,7 @@ class BlockCms extends Module
$this->_html .= ' $this->_html .= '
</select> </select>
</div><br /> </div><br />
<label>'.$this->l('Location:').'</label> <label>'.$this->l('Location:').'</label>
<div class="margin-form"> <div class="margin-form">
<select name="block_location" id="block_location"> <select name="block_location" id="block_location">
@@ -486,15 +512,15 @@ class BlockCms extends Module
<img src="../img/admin/disabled.gif" alt="No" title="No" style="margin-left: 10px;" /> <img src="../img/admin/disabled.gif" alt="No" title="No" style="margin-left: 10px;" />
<input type="radio" name="PS_STORES_DISPLAY_CMS" id="PS_STORES_DISPLAY_CMS_off" '.(($cmsBlock AND ( isset($cmsBlock[0]['display_store']) && $cmsBlock[0]['display_store'] == 0)) ? 'checked="checked" ' : '').'value="0" /> <input type="radio" name="PS_STORES_DISPLAY_CMS" id="PS_STORES_DISPLAY_CMS_off" '.(($cmsBlock AND ( isset($cmsBlock[0]['display_store']) && $cmsBlock[0]['display_store'] == 0)) ? 'checked="checked" ' : '').'value="0" />
<label class="t" for="PS_STORES_DISPLAY_CMS_off">'.$this->l('No').'</label><br />' <label class="t" for="PS_STORES_DISPLAY_CMS_off">'.$this->l('No').'</label><br />'
.$this->l('Display "our stores" at the end of the block') .$this->l('Display "our stores" at the end of the block')
.'</div>'; .'</div>';
$this->_html .= '<div id="cms_subcategories"></div> $this->_html .= '<div id="cms_subcategories"></div>
<p class="center"> <p class="center">
<input type="submit" class="button" name="submitBlockCMS" value="'.$this->l('Save').'" /> <input type="submit" class="button" name="submitBlockCMS" value="'.$this->l('Save').'" />
<a class="button" style="position:relative; padding:3px 3px 4px 3px; top:1px" href="'.AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'">'.$this->l('Cancel').'</a> <a class="button" style="position:relative; padding:3px 3px 4px 3px; top:1px" href="'.AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'">'.$this->l('Cancel').'</a>
</p>'; </p>';
$this->_html .= ' $this->_html .= '
</fieldset> </fieldset>
</form> </form>
<script type="text/javascript">CMSCategory_js($(\'#id_category\').val(), \''.$this->secure_key.'\')</script>'; <script type="text/javascript">CMSCategory_js($(\'#id_category\').val(), \''.$this->secure_key.'\')</script>';
@@ -508,29 +534,59 @@ class BlockCms extends Module
$languages = Language::getLanguages(false); $languages = Language::getLanguages(false);
$cmsBoxes = Tools::getValue('cmsBox'); $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)) 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)) 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)) 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 else
foreach ($cmsBoxes as $cmsBox) foreach ($cmsBoxes as $cmsBox)
if (!preg_match("#^[01]_[0-9]+$#", $cmsBox)) if (!preg_match("#^[01]_[0-9]+$#", $cmsBox))
$errors[] = $this->l('Invalid CMS page or category'); $errors[] = $this->l('Invalid CMS page or category');
foreach ($languages as $language) foreach ($languages as $language)
if (strlen(Tools::getValue('block_name_'.$language['id_lang'])) > 40) if (strlen(Tools::getValue('block_name_'.$language['id_lang'])) > 40)
$errors[] = $this->l('Block name is too long'); $errors[] = $this->l('Block name is too long');
} }
elseif (Tools::isSubmit('deleteBlockCMS') AND !Validate::isInt(Tools::getValue('id_cms_block'))) 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')) elseif (Tools::isSubmit('submitFooterCMS'))
{ {
if (Tools::getValue('footerBox')) if (Tools::getValue('footerBox'))
foreach (Tools::getValue('footerBox') as $cmsBox) foreach (Tools::getValue('footerBox') as $cmsBox)
if (!preg_match("#^[01]_[0-9]+$#", $cmsBox)) if (!preg_match("#^[01]_[0-9]+$#", $cmsBox))
$errors[] = $this->l('Invalid CMS page or category'); $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) 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)) if (sizeof($errors))
{ {
@@ -539,14 +595,14 @@ class BlockCms extends Module
} }
return true; return true;
} }
private function changePosition() private function changePosition()
{ {
if (!Validate::isInt(Tools::getValue('position')) OR if (!Validate::isInt(Tools::getValue('position')) OR
(Tools::getValue('location') != self::LEFT_COLUMN AND Tools::getValue('location') != self::RIGHT_COLUMN) 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::getValue('way') != 0 AND Tools::getValue('way') != 1))
Tools::displayError(); Tools::displayError();
$this->_html .= 'pos change!'; $this->_html .= 'pos change!';
if (Tools::getValue('way') == 0) if (Tools::getValue('way') == 0)
{ {
@@ -555,7 +611,7 @@ class BlockCms extends Module
SET `position` = '.((int)Tools::getValue('position') + 1).' SET `position` = '.((int)Tools::getValue('position') + 1).'
WHERE `position` = '.((int)Tools::getValue('position')).' WHERE `position` = '.((int)Tools::getValue('position')).'
AND `location` = '.(int)Tools::getValue('location'))) AND `location` = '.(int)Tools::getValue('location')))
Db::getInstance()->Execute(' Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'cms_block` UPDATE `'._DB_PREFIX_.'cms_block`
SET `position` = '.((int)Tools::getValue('position')).' SET `position` = '.((int)Tools::getValue('position')).'
WHERE `id_cms_block` = '.(int)Tools::getValue('id_cms_block')); 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).' SET `position` = '.((int)Tools::getValue('position') - 1).'
WHERE `position` = '.((int)Tools::getValue('position')).' WHERE `position` = '.((int)Tools::getValue('position')).'
AND `location` = '.(int)Tools::getValue('location'))) AND `location` = '.(int)Tools::getValue('location')))
Db::getInstance()->Execute(' Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'cms_block` UPDATE `'._DB_PREFIX_.'cms_block`
SET `position` = '.((int)Tools::getValue('position')).' SET `position` = '.((int)Tools::getValue('position')).'
WHERE `id_cms_block` = '.(int)Tools::getValue('id_cms_block')); 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')); Tools::redirectAdmin(AdminTab::$currentIndex.'index.php?tab=AdminModules&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'));
} }
private function _postProcess() private function _postProcess()
{ {
if (Tools::isSubmit('submitBlockCMS')) if (Tools::isSubmit('submitBlockCMS'))
{ {
$position = Db::getInstance()->getValue(' $position = Db::getInstance()->getValue('
SELECT COUNT(*) SELECT COUNT(*)
FROM `'._DB_PREFIX_.'cms_block` FROM `'._DB_PREFIX_.'cms_block`
WHERE `location` = '.(int)Tools::getValue('block_location')); WHERE `location` = '.(int)Tools::getValue('block_location'));
$languages = Language::getLanguages(false); $languages = Language::getLanguages(false);
if (Tools::isSubmit('addBlockCMS')) if (Tools::isSubmit('addBlockCMS'))
{ {
Db::getInstance()->Execute(' Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'cms_block` (`id_cms_category`, `location`, `position`, `display_store`) INSERT INTO `'._DB_PREFIX_.'cms_block` (`id_cms_category`, `location`, `position`, `display_store`)
VALUES('.(int)Tools::getValue('id_category').', '.(int)Tools::getValue('block_location').', VALUES('.(int)Tools::getValue('id_category').', '.(int)Tools::getValue('block_location').',
'.(int)$position.', '.(int)Tools::getValue('PS_STORES_DISPLAY_CMS').')'); '.(int)$position.', '.(int)Tools::getValue('PS_STORES_DISPLAY_CMS').')');
$id_cms_block = Db::getInstance()->Insert_ID(); $id_cms_block = Db::getInstance()->Insert_ID();
foreach ($languages as $language) foreach ($languages as $language)
Db::getInstance()->Execute(' Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'cms_block_lang` (`id_cms_block`, `id_lang`, `name`) INSERT INTO `'._DB_PREFIX_.'cms_block_lang` (`id_cms_block`, `id_lang`, `name`)
VALUES('.(int)$id_cms_block.', '.(int)$language['id_lang'].', VALUES('.(int)$id_cms_block.', '.(int)$language['id_lang'].',
"'.pSQL(Tools::getValue('block_name_'.$language['id_lang'])).'")'); "'.pSQL(Tools::getValue('block_name_'.$language['id_lang'])).'")');
Db::getInstance()->Execute(' Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'cms_block` UPDATE `'._DB_PREFIX_.'cms_block`
SET `display_store` = '.Configuration::get('PS_STORES_DISPLAY_FOOTER')); SET `display_store` = '.Configuration::get('PS_STORES_DISPLAY_FOOTER'));
@@ -604,23 +660,23 @@ class BlockCms extends Module
elseif (Tools::isSubmit('editBlockCMS')) elseif (Tools::isSubmit('editBlockCMS'))
{ {
$id_cms_block = Tools::getvalue('id_cms_block'); $id_cms_block = Tools::getvalue('id_cms_block');
$old_block = Db::getInstance()->ExecuteS(' $old_block = Db::getInstance()->ExecuteS('
SELECT `location`, `position` SELECT `location`, `position`
FROM `'._DB_PREFIX_.'cms_block` FROM `'._DB_PREFIX_.'cms_block`
WHERE `id_cms_block` = '.(int)$id_cms_block); WHERE `id_cms_block` = '.(int)$id_cms_block);
$location_change = ($old_block[0]['location'] != (int)Tools::getvalue('block_location')); $location_change = ($old_block[0]['location'] != (int)Tools::getvalue('block_location'));
Db::getInstance()->Execute(' 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); WHERE `id_cms_block` = '.(int)$id_cms_block);
if ($location_change == true) if ($location_change == true)
Db::getInstance()->Execute(' Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'cms_block` UPDATE `'._DB_PREFIX_.'cms_block`
SET `position` = (`position` - 1) WHERE `position` > '.(int)$old_block[0]['position'].' SET `position` = (`position` - 1) WHERE `position` > '.(int)$old_block[0]['position'].'
AND `location` = '.(int)$old_block[0]['location']); AND `location` = '.(int)$old_block[0]['location']);
Db::getInstance()->Execute(' Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'cms_block` UPDATE `'._DB_PREFIX_.'cms_block`
SET `location` = '.(int)(Tools::getvalue('block_location')).', SET `location` = '.(int)(Tools::getvalue('block_location')).',
@@ -629,29 +685,29 @@ class BlockCms extends Module
`position` = '.(int)($position) : '').', `position` = '.(int)($position) : '').',
`display_store` = '.(int)(Tools::getValue('PS_STORES_DISPLAY_CMS')).' `display_store` = '.(int)(Tools::getValue('PS_STORES_DISPLAY_CMS')).'
WHERE `id_cms_block` = '.(int)($id_cms_block)); WHERE `id_cms_block` = '.(int)($id_cms_block));
Configuration::updateValue('PS_STORES_DISPLAY_FOOTER', (int)(Tools::getValue('PS_STORES_DISPLAY_CMS'))); Configuration::updateValue('PS_STORES_DISPLAY_FOOTER', (int)(Tools::getValue('PS_STORES_DISPLAY_CMS')));
foreach ($languages as $language) foreach ($languages as $language)
Db::getInstance()->Execute(' Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'cms_block_lang` UPDATE `'._DB_PREFIX_.'cms_block_lang`
SET `name` = "'.pSQL(Tools::getValue('block_name_'.$language['id_lang'])).'" SET `name` = "'.pSQL(Tools::getValue('block_name_'.$language['id_lang'])).'"
WHERE `id_cms_block` = '.(int)$id_cms_block.' WHERE `id_cms_block` = '.(int)$id_cms_block.'
AND `id_lang`= '.(int)$language['id_lang']); AND `id_lang`= '.(int)$language['id_lang']);
} }
$cmsBoxes = Tools::getValue('cmsBox'); $cmsBoxes = Tools::getValue('cmsBox');
if (sizeof($cmsBoxes)) if (sizeof($cmsBoxes))
foreach ($cmsBoxes as $cmsBox) foreach ($cmsBoxes as $cmsBox)
{ {
$cms_properties = explode('_', $cmsBox); $cms_properties = explode('_', $cmsBox);
Db::getInstance()->Execute(' Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'cms_block_page` (`id_cms_block`, `id_cms`, `is_category`) 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].')'); VALUES('.(int)$id_cms_block.', '.(int)$cms_properties[1].', '.(int)$cms_properties[0].')');
} }
if (Tools::isSubmit('addBlockCMS')) 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')) 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')) elseif (Tools::isSubmit('deleteBlockCMS') AND Tools::getValue('id_cms_block'))
{ {
@@ -659,62 +715,64 @@ class BlockCms extends Module
if (sizeof($old_block)) if (sizeof($old_block))
{ {
Db::getInstance()->Execute(' Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'cms_block` UPDATE `'._DB_PREFIX_.'cms_block`
SET `position` = (`position` - 1) SET `position` = (`position` - 1)
WHERE `position` > '.(int)$old_block[0]['position'].' WHERE `position` > '.(int)$old_block[0]['position'].'
AND `location` = '.(int)$old_block[0]['location']); AND `location` = '.(int)$old_block[0]['location']);
Db::getInstance()->Execute(' 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'))); WHERE `id_cms_block` = '.(int)(Tools::getValue('id_cms_block')));
Db::getInstance()->Execute(' 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'))); WHERE `id_cms_block` = '.(int)(Tools::getValue('id_cms_block')));
Tools::redirectAdmin(AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&deleteBlockCMSConfirmation'); Tools::redirectAdmin(AdminTab::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&deleteBlockCMSConfirmation');
} }
else 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')) elseif (Tools::isSubmit('submitFooterCMS'))
{ {
$footer = ''; $footer = '';
if (Tools::getValue('footerBox')) if (Tools::getValue('footerBox'))
foreach (Tools::getValue('footerBox') as $box) foreach (Tools::getValue('footerBox') as $box)
$footer .= $box.'|'; $footer .= $box.'|';
Configuration::updateValue('FOOTER_CMS', rtrim($footer, '|')); Configuration::updateValue('FOOTER_CMS', rtrim($footer, '|'));
Configuration::updateValue('FOOTER_BLOCK_ACTIVATION', Tools::getValue('footer_active')); Configuration::updateValue('FOOTER_BLOCK_ACTIVATION', Tools::getValue('footer_active'));
Configuration::updateValue('FOOTER_POWEREDBY', (Tools::getValue('footer_poweredby_active') == 'on' ? 1 : 0)); Configuration::updateValue('FOOTER_POWEREDBY', (Tools::getValue('footer_poweredby_active') == 'on' ? 1 : 0));
$this->_html = $this->displayConfirmation($this->l('Footer\'s CMS updated')); $this->_html = $this->displayConfirmation($this->l('Footer\'s CMS updated'));
} }
elseif (Tools::isSubmit('addBlockCMSConfirmation')) 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')) 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')) 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')) 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() public function getContent()
{ {
$this->_html = ''; $this->_html = '';
if ($this->_postValidation()) if ($this->_postValidation())
$this->_postProcess(); $this->_postProcess();
$this->_html .= '<h2>'.$this->l('CMS Block configuration').'</h2>'; $this->_html .= '<h2>'.$this->l('CMS Block configuration').'</h2>';
if (Tools::isSubmit('addBlockCMS') OR Tools::isSubmit('editBlockCMS')) if (Tools::isSubmit('addBlockCMS') OR Tools::isSubmit('editBlockCMS'))
$this->_displayAddForm(); $this->_displayAddForm();
else else
$this->_displayForm(); $this->_displayForm();
return $this->_html; return $this->_html;
} }
public function hookLeftColumn() public function hookLeftColumn()
{ {
$this->context = Context::getContext(); $this->context = Context::getContext();
$cms_titles = self::getCMStitles(self::LEFT_COLUMN); $cms_titles = self::getCMStitles(self::LEFT_COLUMN);
$this->context->smarty->assign(array( $this->context->smarty->assign(array(
'block' => 1, 'block' => 1,
@@ -723,7 +781,7 @@ class BlockCms extends Module
)); ));
return $this->display(__FILE__, 'blockcms.tpl'); return $this->display(__FILE__, 'blockcms.tpl');
} }
public function hookRightColumn() public function hookRightColumn()
{ {
@@ -735,10 +793,10 @@ class BlockCms extends Module
)); ));
return $this->display(__FILE__, 'blockcms.tpl'); return $this->display(__FILE__, 'blockcms.tpl');
} }
public function hookFooter() public function hookFooter()
{ {
if (Configuration::get('FOOTER_BLOCK_ACTIVATION')) if (Configuration::get('FOOTER_BLOCK_ACTIVATION'))
{ {
$cms_titles = self::getCMStitlesFooter(); $cms_titles = self::getCMStitlesFooter();
@@ -747,18 +805,19 @@ class BlockCms extends Module
'cmslinks' => $cms_titles, 'cmslinks' => $cms_titles,
'theme_dir' => _PS_THEME_DIR_, 'theme_dir' => _PS_THEME_DIR_,
'display_stores_footer' => Configuration::get('PS_STORES_DISPLAY_FOOTER'), '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 $this->display(__FILE__, 'blockcms.tpl');
} }
return ''; return '';
} }
public function hookHeader($params) public function hookHeader($params)
{ {
$this->context->controller->addCSS(($this->_path).'blockcms.css', 'all'); $this->context->controller->addCSS(($this->_path).'blockcms.css', 'all');
} }
public function getL($key) public function getL($key)
{ {
$trad = array( $trad = array(
+3 -1
View File
@@ -1,5 +1,5 @@
{* {*
* 2007-2011 PrestaShop * 2007-2011 PrestaShop
* *
* NOTICE OF LICENSE * NOTICE OF LICENSE
* *
@@ -58,5 +58,7 @@
{/foreach} {/foreach}
{if $display_poweredby}<li class="last_item">{l s='Powered by' mod='blockcms'} <a href="http://www.prestashop.com">PrestaShop</a>&trade;</li>{/if} {if $display_poweredby}<li class="last_item">{l s='Powered by' mod='blockcms'} <a href="http://www.prestashop.com">PrestaShop</a>&trade;</li>{/if}
</ul> </ul>
{$footer_text}
<!-- /MODULE Block footer --> <!-- /MODULE Block footer -->
{/if} {/if}