* @copyright 2007-2012 PrestaShop SA
* @version Release: $Revision: 7095 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
require dirname(__FILE__).'/menutoplinks.class.php';
class blocktopmenu extends Module
{
private $_menu = '';
private $_html = '';
/*
* Pattern for matching config values
*/
private $pattern = '/^([A-Z_]*)[0-9]+/';
/*
* Name of the controller
* Used to set item selected or not in top menu
*/
private $page_name = '';
/*
* Spaces per depth in BO
*/
private $spacer_size = '5';
public function __construct()
{
$this->name = 'blocktopmenu';
$this->tab = 'front_office_features';
$this->version = 1.4;
$this->author = 'PrestaShop';
parent::__construct();
$this->displayName = $this->l('Top horizontal menu');
$this->description = $this->l('Add a new menu on top of your shop.');
}
public function install()
{
if(!parent::install() ||
!$this->registerHook('top') ||
!Configuration::updateGlobalValue('MOD_BLOCKTOPMENU_ITEMS', 'CAT1,CMS1,CMS2,PRD1') ||
!Configuration::updateGlobalValue('MOD_BLOCKTOPMENU_SEARCH', '1') ||
!$this->installDB())
return false;
return true;
}
public function installDb()
{
return (Db::getInstance()->execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'linksmenutop` (
`id_linksmenutop` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`id_shop` INT UNSIGNED NOT NULL,
`new_window` TINYINT( 1 ) NOT NULL,
`link` VARCHAR( 128 ) NOT NULL,
INDEX (`id_shop`)
) ENGINE = '._MYSQL_ENGINE_.' CHARACTER SET utf8 COLLATE utf8_general_ci;') AND
Db::getInstance()->execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'linksmenutop_lang` (
`id_linksmenutop` INT NOT NULL,
`id_lang` INT NOT NULL,
`id_shop` INT NOT NULL,
`label` VARCHAR( 128 ) NOT NULL ,
INDEX ( `id_linksmenutop` , `id_lang`, `id_shop`)
) ENGINE = '._MYSQL_ENGINE_.' CHARACTER SET utf8 COLLATE utf8_general_ci;'));
}
public function uninstall()
{
if (!parent::uninstall() ||
!Configuration::deleteByName('MOD_BLOCKTOPMENU_ITEMS') ||
!Configuration::deleteByName('MOD_BLOCKTOPMENU_SEARCH') ||
!$this->uninstallDB())
return false;
return true;
}
private function uninstallDb()
{
Db::getInstance()->execute('DROP TABLE `'._DB_PREFIX_.'linksmenutop`');
Db::getInstance()->execute('DROP TABLE `'._DB_PREFIX_.'linksmenutop_lang`');
return true;
}
public function getContent()
{
$id_lang = Shop::getContextShopID();
$spacer = str_repeat(' ', $this->spacer_size);
if(Tools::isSubmit('submitBlocktopmenu'))
{
if (Configuration::updateValue('MOD_BLOCKTOPMENU_ITEMS', Tools::getValue('items')))
$this->_html .= $this->displayConfirmation($this->l('Settings Updated'));
else
$this->_html .= $this->displayError($this->l('Unable to update settings'));
Configuration::updateValue('MOD_BLOCKTOPMENU_SEARCH', (bool)Tools::getValue('search'));
}
else if(Tools::isSubmit('submitBlocktopmenuLinks'))
{
if(Tools::getValue('link') == '')
{
$this->_html .= $this->displayError($this->l('Unable to add this link'));
}
else
{
MenuTopLinks::add(Tools::getValue('link'), Tools::getValue('label'), Tools::getValue('new_window', 0), (int)$this->context->shop->id);
$this->_html .= $this->displayConfirmation($this->l('The link has been added'));
}
}
else if(Tools::isSubmit('submitBlocktopmenuRemove'))
{
$id_linksmenutop = Tools::getValue('id_linksmenutop', 0);
MenuTopLinks::remove($id_linksmenutop, (int)$this->context->shop->id);
Configuration::updateValue('MOD_BLOCKTOPMENU_ITEMS', str_replace(array('LNK'.$id_linksmenutop.',', 'LNK'.$id_linksmenutop), '', Configuration::get('MOD_BLOCKTOPMENU_ITEMS')));
$this->_html .= $this->displayConfirmation($this->l('The link has been removed'));
}
$this->_html .= '