* @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'; $this->tab = 'front_office_features'; $this->version = 1.1; $this->author = 'PrestaShop'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('CMS Block'); $this->description = $this->l('Adds a block with several CMS links.'); $this->secure_key = Tools::encrypt($this->name); } public function install() { if (!parent::install() || !$this->registerHook('leftColumn') || !$this->registerHook('rightColumn') || !$this->registerHook('footer') || !$this->registerHook('header') || !Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'cms_block`( `id_cms_block` int(10) unsigned NOT NULL auto_increment, `id_cms_category` int(10) unsigned NOT NULL, `location` tinyint(1) unsigned NOT NULL, `position` int(10) unsigned NOT NULL default \'0\', `display_store` tinyint(1) unsigned NOT NULL default \'1\', PRIMARY KEY (`id_cms_block`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8') || !Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'cms_block_lang`( `id_cms_block` int(10) unsigned NOT NULL, `id_lang` int(10) unsigned NOT NULL, `name` varchar(40) NOT NULL default \'\', PRIMARY KEY (`id_cms_block`, `id_lang`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8') || !Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'cms_block_page`( `id_cms_block_page` int(10) unsigned NOT NULL auto_increment, `id_cms_block` int(10) unsigned NOT NULL, `id_cms` int(10) unsigned NOT NULL, `is_category` tinyint(1) unsigned NOT NULL, PRIMARY KEY (`id_cms_block_page`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8') || !Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'cms_block_shop` ( `id_cms_block` int(10) unsigned NOT NULL auto_increment, `id_shop` int(10) unsigned NOT NULL, PRIMARY KEY (`id_cms_block`, `id_shop`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8') || !Configuration::updateValue('FOOTER_CMS', '') || !Configuration::updateValue('FOOTER_BLOCK_ACTIVATION', 1) || !Configuration::updateValue('FOOTER_POWEREDBY', 1)) return false; // Install fixtures for blockcms if (!Db::getInstance()->insert('cms_block', array( 'id_cms_category' => 1, 'location' => 0, 'position' => 0, ))) return false; $id_cms_block = Db::getInstance()->Insert_ID(); $result = true; $shops = Shop::getShops(true, null, true); foreach ($shops as $shop) $result &= Db::getInstance()->insert('cms_block_shop', array( 'id_cms_block' => $id_cms_block, 'id_shop' => $shop )); foreach (Language::getLanguages(false) as $lang) $result &= Db::getInstance()->insert('cms_block_lang', array( 'id_cms_block' => $id_cms_block, 'id_lang' => $lang['id_lang'], 'name' => $this->l('Information'), )); foreach (CMS::getCMSPages(null, 1) as $cms) $result &= Db::getInstance()->insert('cms_block_page', array( 'id_cms_block' => $id_cms_block, 'id_cms' => $cms['id_cms'], 'is_category' => 0, )); return $result; } public function uninstall() { if (!parent::uninstall() || !Configuration::deleteByName('FOOTER_CMS') || !Configuration::deleteByName('FOOTER_BLOCK_ACTIVATION') || !Configuration::deleteByName('FOOTER_POWEREDBY') || !Db::getInstance()->execute('DROP TABLE `'._DB_PREFIX_.'cms_block` , `'._DB_PREFIX_.'cms_block_page`, `'._DB_PREFIX_.'cms_block_lang`, `'._DB_PREFIX_.'cms_block_shop`')) 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 LEFT JOIN `'._DB_PREFIX_.'cms_block_lang` cbl ON (cbl.`id_cms_block` = cb.`id_cms_block`) WHERE cb.`id_cms_block` = '.(int)$id_cms_block); $store_display_update = array(0, $size = count($cmsBlocks), $display = Configuration::get('PS_STORES_DISPLAY_FOOTER')); foreach ($cmsBlocks as $cmsBlock) { $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']; ++$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 INNER JOIN `'._DB_PREFIX_.'cms_category_lang` ccl ON (bc.`id_cms_category` = ccl.`id_cms_category`) INNER JOIN `'._DB_PREFIX_.'cms_block_lang` bcl ON (bc.`id_cms_block` = bcl.`id_cms_block`) 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)); } public static function getCMStitlesFooter() { $context = Context::getContext(); $footerCms = Configuration::get('FOOTER_CMS'); if (empty($footerCms)) return array(); $cmsCategories = explode('|', $footerCms); $content = array(); foreach ($cmsCategories as $cmsCategory) { $ids = explode('_', $cmsCategory); if ($ids[0] == 1) { $query = Db::getInstance()->getRow(' SELECT cl.`name`, cl.`link_rewrite` FROM `'._DB_PREFIX_.'cms_category_lang` cl 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` 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']; } } return $content; } public static function getCMStitles($location) { $context = Context::getContext(); $cmsCategories = Db::getInstance()->executeS(' SELECT bc.`id_cms_block`, bc.`id_cms_category`, bc.`display_store`, ccl.`link_rewrite`, ccl.`name` category_name, bcl.`name` block_name FROM `'._DB_PREFIX_.'cms_block` bc LEFT JOIN `'._DB_PREFIX_.'cms_block_shop` bcs ON (bcs.id_cms_block = bc.id_cms_block) INNER JOIN `'._DB_PREFIX_.'cms_category_lang` ccl ON (bc.`id_cms_category` = ccl.`id_cms_category`) 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 bcs.id_shop = '.$context->shop->getID(true).' ORDER BY `position`'); $content = array(); if (is_array($cmsCategories) && count($cmsCategories)) 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 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 (count($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 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 (count($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(); foreach (self::getCMStitles(self::LEFT_COLUMN) as $key => $title) { unset($title['categories'], $title['name'], $title['category_link'], $title['category_name']); $titles[$key] = $title; } foreach (self::getCMStitles(self::RIGHT_COLUMN) as $key => $title) { 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).'_'.((count($categories['cms']) || isset($categories['children'])) ? 'b' : 'f').'.gif'; $this->_html .= ' '.$categories['id_cms_category'].' '; for ($i = 1; $i < $categories['level_depth']; $i++) $this->_html .= ''; $this->_html .= '   '; if (isset($categories['children'])) foreach ($categories['children'] as $key => $category) { $has_suite[$categories['level_depth']] = 1; if (count($categories['children']) == $key + 1 && !count($categories['cms'])) $has_suite[$categories['level_depth']] = 0; $this->displayRecurseCheckboxes($category, $selected, $has_suite, 0); } $cpt = 0; foreach ($categories['cms'] as $cms) { $this->_html .= ' '.$cms['id_cms'].' '; for ($i = 0; $i < $categories['level_depth']; $i++) $this->_html .= ''; $this->_html .= '   '; } } private function _displayForm() { $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 .= '
'.$this->l('CMS block configuration').'

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

'; $this->_html .= '

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

'; if (count($cms_blocks_left)) { $this->_html .= ' '; $irow = 0; foreach ($cms_blocks_left as $cms_block) { $this->_html .= ' '; } $this->_html .= '
'.$this->l('ID').' '.$this->l('Name of block').' '.$this->l('Category Name').' '.$this->l('Position').' '.$this->l('Actions').'
'.$cms_block['id_cms_block'].' '.(empty($cms_block['block_name']) ? $cms_block['category_name'] : $cms_block['block_name']).' '.$cms_block['category_name'].' '.$this->l('Down').' '.$this->l('Up').'
'; } else $this->_html .= '

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

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

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

'; if (count($cms_blocks_right)) { $this->_html .= ' '; $irow = 0; foreach ($cms_blocks_right as $cms_block) { $this->_html .= ' '; } $this->_html .= '
'.$this->l('ID').' '.$this->l('Name of block').' '.$this->l('Category Name').' '.$this->l('Position').' '.$this->l('Actions').'
'.$cms_block['id_cms_block'].' '.(empty($cms_block['block_name']) ? $cms_block['category_name'] : $cms_block['block_name']).' '.$cms_block['category_name'].' '.$this->l('Down').' '.$this->l('Up').'
'; } else $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 .= '

'.$this->l('Footer\'s various links Configuration').'





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

'; } private function _displayAddForm() { $defaultLanguage = (int)Configuration::get('PS_LANG_DEFAULT'); $languages = Language::getLanguages(false); $divLangName = 'name'; $cmsBlock = null; if (Tools::isSubmit('editBlockCMS') && Tools::getValue('id_cms_block')) $cmsBlock = $this->getBlockCMS((int)Tools::getValue('id_cms_block')); $this->_html .= '
'; if (Tools::getValue('id_cms_block')) $this->_html .= ''; $this->_html .= '
'; if (Tools::isSubmit('addBlockCMS')) $this->_html .= ' '.$this->l('New CMS block').''; elseif (Tools::isSubmit('editBlockCMS')) $this->_html .= ' '.$this->l('Edit CMS block').''; $this->_html .= '
'; foreach ($languages as $language) $this->_html .= '
'; $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').'



'; $this->_html .= '
Yes No
' .$this->l('Display "our stores" at the end of the block') .'
'; $this->_html .= '
 
'; $helper = new Helper(); $helper->id = (int)Tools::getValue('id_cms_block'); $helper->table = 'cms_block'; $helper->identifier = 'id_cms_block'; if (Shop::isFeatureActive()) $this->_html .= '
'.$helper->renderAssoShop().'
'; $this->_html .= '

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

'; } private function _postValidation() { $errors = array(); if (Tools::isSubmit('submitBlockCMS')) { $languages = Language::getLanguages(false); $cmsBoxes = Tools::getValue('cmsBox'); if (!Validate::isInt(Tools::getValue('PS_STORES_DISPLAY_CMS')) || (Tools::getValue('PS_STORES_DISPLAY_CMS') != 0 && Tools::getValue('PS_STORES_DISPLAY_CMS') != 1)) $errors[] = $this->l('Invalid store display'); if (!Validate::isInt(Tools::getValue('block_location')) || (Tools::getValue('block_location') != self::LEFT_COLUMN && Tools::getValue('block_location') != self::RIGHT_COLUMN)) $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.'); else 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'); } elseif (Tools::isSubmit('deleteBlockCMS') && !Validate::isInt(Tools::getValue('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'); $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 && Tools::getValue('footer_active') != 1) $errors[] = $this->l('Invalid activation footer'); } if (count($errors)) { $this->_html .= $this->displayError(implode('
', $errors)); return false; } return true; } private function changePosition() { if (!Validate::isInt(Tools::getValue('position')) || (Tools::getValue('location') != self::LEFT_COLUMN && Tools::getValue('location') != self::RIGHT_COLUMN) || (Tools::getValue('way') != 0 && Tools::getValue('way') != 1)) Tools::displayError(); $this->_html .= 'pos change!'; if (Tools::getValue('way') == 0) { if (Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'cms_block` SET `position` = '.((int)Tools::getValue('position') + 1).' WHERE `position` = '.((int)Tools::getValue('position')).' AND `location` = '.(int)Tools::getValue('location'))) Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'cms_block` SET `position` = '.((int)Tools::getValue('position')).' WHERE `id_cms_block` = '.(int)Tools::getValue('id_cms_block')); } elseif (Tools::getValue('way') == 1) { if (Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'cms_block` SET `position` = '.((int)Tools::getValue('position') - 1).' WHERE `position` = '.((int)Tools::getValue('position')).' AND `location` = '.(int)Tools::getValue('location'))) 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(AdminController::$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` 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').', '.(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'].', "'.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')); } 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` 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` 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'].' AND `location` = '.(int)$old_block[0]['location']); Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'cms_block` SET `location` = '.(int)(Tools::getvalue('block_location')).', `id_cms_category` = '.(int)(Tools::getvalue('id_category')).' '.($location_change == true ? ', `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.' AND `id_lang`= '.(int)$language['id_lang']); } if (Tools::isSubmit('submitBlockCMS') || Tools::isSubmit('editBlockCMS')) { $assos_shop = Tools::getValue('checkBoxShopAsso_cms_block'); Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'cms_block_shop WHERE id_cms_block='.(int)$id_cms_block); foreach ($assos_shop as $asso) foreach ($asso as $id_shop => $row) Db::getInstance()->insert('cms_block_shop', array( 'id_cms_block' => (int)$id_cms_block, 'id_shop' => (int)$id_shop, )); } $cmsBoxes = Tools::getValue('cmsBox'); if (count($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`) VALUES('.(int)$id_cms_block.', '.(int)$cms_properties[1].', '.(int)$cms_properties[0].')'); } if (Tools::isSubmit('addBlockCMS')) Tools::redirectAdmin(AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&addBlockCMSConfirmation'); elseif (Tools::isSubmit('editBlockCMS')) Tools::redirectAdmin(AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&editBlockCMSConfirmation'); } elseif (Tools::isSubmit('deleteBlockCMS') && Tools::getValue('id_cms_block')) { $old_block = Db::getInstance()->executeS('SELECT `location`, `position` FROM `'._DB_PREFIX_.'cms_block` WHERE `id_cms_block` = '.Tools::getvalue('id_cms_block')); if (count($old_block)) { 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(' 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` WHERE `id_cms_block` = '.(int)(Tools::getValue('id_cms_block'))); Tools::redirectAdmin(AdminController::$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')); } elseif (Tools::isSubmit('submitFooterCMS')) { $footer = ''; if (Tools::getValue('footerBox')) 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')); elseif (Tools::isSubmit('editBlockCMSConfirmation')) $this->_html = $this->displayConfirmation($this->l('Block CMS edited')); elseif (Tools::isSubmit('deleteBlockCMSConfirmation')) $this->_html .= $this->displayConfirmation($this->l('Deletion successful')); elseif (Tools::isSubmit('id_cms_block') && Tools::isSubmit('way') && Tools::isSubmit('position') && Tools::isSubmit('location')) $this->changePosition(); } public function getContent() { $this->_html = ''; if ($this->_postValidation()) $this->_postProcess(); $this->_html .= '

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

'; if (Tools::isSubmit('addBlockCMS') || Tools::isSubmit('editBlockCMS')) $this->_displayAddForm(); else $this->_displayForm(); return $this->_html; } public function displayBlockCMS($column) { $cms_titles = self::getCMStitles($column); $this->smarty->assign(array( 'block' => 1, 'cms_titles' => $cms_titles, 'contact_url' => (_PS_VERSION_ >= 1.5) ? 'contact' : 'contact-form' )); return $this->display(__FILE__, 'blockcms.tpl'); } public function hookLeftColumn() { return $this->displayBlockCMS(self::LEFT_COLUMN); } public function hookRightColumn() { return $this->displayBlockCMS(self::RIGHT_COLUMN); } public function hookFooter() { if (Configuration::get('FOOTER_BLOCK_ACTIVATION')) { $cms_titles = self::getCMStitlesFooter(); $this->smarty->assign(array( 'block' => 0, 'cmslinks' => $cms_titles, 'display_stores_footer' => Configuration::get('PS_STORES_DISPLAY_FOOTER'), '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( 'ID' => $this->l('ID'), 'Name' => $this->l('Name'), 'There is nothing to display in this CMS category' => $this->l('There is nothing to display in this CMS category') ); return $trad[$key]; } }