diff --git a/modules/blocktopmenu/blocktopmenu.php b/modules/blocktopmenu/blocktopmenu.php index 2a73fa2f0..c4687c05d 100644 --- a/modules/blocktopmenu/blocktopmenu.php +++ b/modules/blocktopmenu/blocktopmenu.php @@ -1,4 +1,30 @@ +* @copyright 2007-2011 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 +*/ + include _PS_MODULE_DIR_.'blocktopmenu/menutoplinks.class.php'; class blocktopmenu extends Module { @@ -28,20 +54,22 @@ class blocktopmenu extends Module public function installDb() { - Db::getInstance()->execute(' + return (Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'linksmenutop` ( - `id_link` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , + `id_link` 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 - ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;'); - Db::getInstance()->execute(' - CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'linksmenutop_lang` ( - `id_link` INT NOT NULL , - `id_lang` INT NOT NULL , - `label` VARCHAR( 128 ) NOT NULL , - INDEX ( `id_link` , `id_lang` ) - ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;'); - return true; + `link` VARCHAR( 128 ) NOT NULL, + INDEX (`id_shop`) + ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;') AND + Db::getInstance()->execute(' + CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'linksmenutop_lang` ( + `id_link` INT NOT NULL, + `id_lang` INT NOT NULL, + `id_shop` INT NOT NULL, + `label` VARCHAR( 128 ) NOT NULL , + INDEX ( `id_link` , `id_lang`, `id_shop`) + ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;')); } public function uninstall() @@ -64,7 +92,6 @@ class blocktopmenu extends Module public function getContent() { global $cookie; - if(Tools::isSubmit('submitBlocktopmenu')) { if(Configuration::updateValue('MOD_BLOCKTOPMENU_ITEMS', Tools::getValue('items'))) @@ -81,21 +108,25 @@ class blocktopmenu extends Module } else { - MenuTopLinks::add(Tools::getValue('link'), Tools::getValue('label'), Tools::getValue('new_window', 0)); + 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')); } } if(Tools::isSubmit('submitBlocktopmenuRemove')) { $id_link = Tools::getValue('id_link', 0); - MenuTopLinks::remove($id_link); + MenuTopLinks::remove($id_link, (int)$this->context->shop->id); Configuration::updateValue('MOD_BLOCKTOPMENU_ITEMS', str_replace(array('LNK'.$id_link.',', 'LNK'.$id_link), '', Configuration::get('MOD_BLOCKTOPMENU_ITEMS'))); $this->_html .= $this->displayConfirmation($this->l('The link has been removed')); } + $this->_html .= '
+
+ '.$this->l('The modifications will be applied to').' '.(Context::shop() == Shop::CONTEXT_SHOP ? $this->l('shop:').' '.$this->context->shop->name : $this->l('all shops')).'. +
'.$this->l('Settings').' -
+
@@ -149,7 +180,7 @@ class blocktopmenu extends Module // END Products // BEGIN Menu Top Links $this->_html .= ''; - $links = MenuTopLinks::gets($cookie->id_lang); + $links = MenuTopLinks::gets($cookie->id_lang, null, (int)$this->context->shop->id); foreach($links as $link) $this->_html .= ''; $this->_html .= ''; @@ -221,7 +252,7 @@ class blocktopmenu extends Module $this->_html .= '
'.$this->l('Add Menu Top Link').' - +
'; foreach ($languages as $language) @@ -262,7 +293,7 @@ class blocktopmenu extends Module '; - $links = MenuTopLinks::gets($cookie->id_lang); + $links = MenuTopLinks::gets($cookie->id_lang, null, $this->context->shop->id); foreach($links as $link) { $this->_html .= ' @@ -282,108 +313,125 @@ class blocktopmenu extends Module $this->_html .= '
'; - echo $this->_html; + return $this->_html; } private function getMenuItems() { - $items = Configuration::get('MOD_BLOCKTOPMENU_ITEMS'); - $items = explode(',', $items); - return $items; + if (Context::shop() == Shop::CONTEXT_SHOP) + { + if (!Configuration::isOverridenByCurrentContext('MOD_BLOCKTOPMENU_ITEMS')) + $items_shop = Configuration::get('MOD_BLOCKTOPMENU_ITEMS'); + } + if (!isset($items_shop)) + $items_shop = ''; + + $items_shop = explode(',', $items_shop); + $items_global = Configuration::getGlobalValue('MOD_BLOCKTOPMENU_ITEMS'); + $items_global = explode(',', $items_global); + + return array('global' => $items_global, 'shop' => $items_shop); } private function makeMenuOption() { global $cookie; - foreach($this->getMenuItems() as $item) + foreach($this->getMenuItems() as $type => $items) { - $id = (int)substr($item, 3, strlen($item)); - switch(substr($item, 0, 3)) - { - case'CAT': - $this->getCategoryOption($id, $cookie->id_lang, false); - break; - case'PRD': - $product = new Product($id, true, $cookie->id_lang); - if(!is_null($product->id)) - $this->_html .= ''.PHP_EOL; - break; - case'CMS': - $cms = CMS::getLinks($cookie->id_lang, array($id)); - if(count($cms)) - $this->_html .= ''.PHP_EOL; - break; - case'MAN': - $manufacturer = new Manufacturer($id, $cookie->id_lang); - if(!is_null($manufacturer->id)) - $this->_html .= ''.PHP_EOL; - break; - case'SUP': - $supplier = new Supplier($id, $cookie->id_lang); - if(!is_null($supplier->id)) - $this->_html .= ''.PHP_EOL; - break; - case'LNK': - $link = MenuTopLinks::get($id, $cookie->id_lang); - if(count($link)) - $this->_html .= ''.PHP_EOL; - break; + foreach ($items as $item) + { + $id = (int)substr($item, 3, strlen($item)); + $disabled = ((Context::shop() == Shop::CONTEXT_SHOP && $type == 'global') ? ' disabled="disabled"': ''); + switch(substr($item, 0, 3)) + { + case'CAT': + $this->getCategoryOption($id, $cookie->id_lang, false); + break; + case'PRD': + $product = new Product($id, true, $cookie->id_lang); + if(!is_null($product->id)) + $this->_html .= ''.PHP_EOL; + break; + case'CMS': + $cms = CMS::getLinks($cookie->id_lang, array($id)); + if(count($cms)) + $this->_html .= ''.PHP_EOL; + break; + case'MAN': + $manufacturer = new Manufacturer($id, $cookie->id_lang); + if(!is_null($manufacturer->id)) + $this->_html .= ''.PHP_EOL; + break; + case'SUP': + $supplier = new Supplier($id, $cookie->id_lang); + if(!is_null($supplier->id)) + $this->_html .= ''.PHP_EOL; + break; + case'LNK': + $link = MenuTopLinks::get($id, $cookie->id_lang, (int)$this->context->shop->id); + if(count($link)) + $this->_html .= ''.PHP_EOL; + break; + } } } } private function makeMenu() { - global $cookie, $page_name; - foreach($this->getMenuItems() as $item) + global $cookie, $page_name; + foreach($this->getMenuItems() as $type => $items) { - $id = (int)substr($item, 3, strlen($item)); - switch(substr($item, 0, 3)) - { - case'CAT': - $this->getCategory($id, $cookie->id_lang); - break; - case'PRD': - $selected = ($page_name == 'product' && (Tools::getValue('id_product') == $id)) ? ' class="sfHover"' : ''; - $product = new Product($id, true, $cookie->id_lang); - if(!is_null($product->id)) - $this->_menu .= ''.$product->name.''.PHP_EOL; - break; - case'CMS': - $selected = ($page_name == 'cms' && (Tools::getValue('id_cms') == $id)) ? ' class="sfHover"' : ''; - $cms = CMS::getLinks($cookie->id_lang, array($id)); - if(count($cms)) - $this->_menu .= ''.$cms[0]['meta_title'].''.PHP_EOL; - break; - case'MAN': - $selected = ($page_name == 'manufacturer' && (Tools::getValue('id_manufacturer') == $id)) ? ' class="sfHover"' : ''; - $manufacturer = new Manufacturer($id, $cookie->id_lang); - if(!is_null($manufacturer->id)) - { - if (intval(Configuration::get('PS_REWRITING_SETTINGS'))) - $manufacturer->link_rewrite = Tools::link_rewrite($manufacturer->name, false); - else - $manufacturer->link_rewrite = 0; - $link = new Link; - $this->_menu .= ''.$manufacturer->name.''.PHP_EOL; - } - break; - case'SUP': - $selected = ($page_name == 'supplier' && (Tools::getValue('id_supplier') == $id)) ? ' class="sfHover"' : ''; - $supplier = new Supplier($id, $cookie->id_lang); - if(!is_null($supplier->id)) - { - $link = new Link; - $this->_menu .= ''.$supplier->name.''.PHP_EOL; - } - break; - case'LNK': - $link = MenuTopLinks::get($id, $cookie->id_lang); - if(count($link)) - $this->_menu .= '
  • '.$link[0]['label'].'
  • '.PHP_EOL; - break; - } - } + foreach ($items as $item) + { + $id = (int)substr($item, 3, strlen($item)); + switch(substr($item, 0, 3)) + { + case'CAT': + $this->getCategory($id, $cookie->id_lang); + break; + case'PRD': + $selected = ($page_name == 'product' && (Tools::getValue('id_product') == $id)) ? ' class="sfHover"' : ''; + $product = new Product($id, true, $cookie->id_lang); + if(!is_null($product->id)) + $this->_menu .= ''.$product->name.''.PHP_EOL; + break; + case'CMS': + $selected = ($page_name == 'cms' && (Tools::getValue('id_cms') == $id)) ? ' class="sfHover"' : ''; + $cms = CMS::getLinks($cookie->id_lang, array($id)); + if(count($cms)) + $this->_menu .= ''.$cms[0]['meta_title'].''.PHP_EOL; + break; + case'MAN': + $selected = ($page_name == 'manufacturer' && (Tools::getValue('id_manufacturer') == $id)) ? ' class="sfHover"' : ''; + $manufacturer = new Manufacturer($id, $cookie->id_lang); + if(!is_null($manufacturer->id)) + { + if (intval(Configuration::get('PS_REWRITING_SETTINGS'))) + $manufacturer->link_rewrite = Tools::link_rewrite($manufacturer->name, false); + else + $manufacturer->link_rewrite = 0; + $link = new Link; + $this->_menu .= ''.$manufacturer->name.''.PHP_EOL; + } + break; + case'SUP': + $selected = ($page_name == 'supplier' && (Tools::getValue('id_supplier') == $id)) ? ' class="sfHover"' : ''; + $supplier = new Supplier($id, $cookie->id_lang); + if(!is_null($supplier->id)) + { + $link = new Link; + $this->_menu .= ''.$supplier->name.''.PHP_EOL; + } + break; + case'LNK': + $link = MenuTopLinks::get($id, $cookie->id_lang, (int)$this->context->shop->id); + if(count($link)) + $this->_menu .= '
  • '.$link[0]['label'].'
  • '.PHP_EOL; + break; + } + } + } } private function getCategoryOption($id_category, $id_lang, $children = true) @@ -440,4 +488,4 @@ class blocktopmenu extends Module return $this->display(__FILE__, 'blocktopmenu.tpl'); } } -?> \ No newline at end of file +?> diff --git a/modules/blocktopmenu/index.php b/modules/blocktopmenu/index.php index 4a2aa31b2..56129df6a 100644 --- a/modules/blocktopmenu/index.php +++ b/modules/blocktopmenu/index.php @@ -1,4 +1,29 @@ +* @copyright 2007-2011 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 +*/ header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); @@ -9,4 +34,4 @@ header("Pragma: no-cache"); header("Location: ../"); exit; -?> \ No newline at end of file +?> diff --git a/modules/blocktopmenu/menutoplinks.class.php b/modules/blocktopmenu/menutoplinks.class.php index 8d5eb7815..8de71b1f1 100644 --- a/modules/blocktopmenu/menutoplinks.class.php +++ b/modules/blocktopmenu/menutoplinks.class.php @@ -1,22 +1,50 @@ +* @copyright 2007-2011 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 +*/ + class MenuTopLinks { - public static function gets($id_lang, $id_link = null) + public static function gets($id_lang, $id_link = null, $id_shop) { return Db::getInstance()->executeS(' SELECT l.id_link, l.new_window, l.link, ll.label FROM '._DB_PREFIX_.'linksmenutop l - LEFT JOIN '._DB_PREFIX_.'linksmenutop_lang ll ON (l.id_link = ll.id_link AND ll.id_lang = "'.$id_lang.'") - '.((!is_null($id_link)) ? 'WHERE l.id_link = "'.$id_link.'"' : '').' + LEFT JOIN '._DB_PREFIX_.'linksmenutop_lang ll ON (l.id_link = ll.id_link AND ll.id_lang = '.(int)$id_lang.' AND ll.id_shop='.(int)$id_shop.') + WHERE 1 + '.((!is_null($id_link)) ? ' AND l.id_link = "'.(int)$id_link.'"' : '').' + AND l.id_shop IN (0, '.(int)$id_shop.') '); } - public static function get($id_link, $id_lang) + public static function get($id_link, $id_lang, $id_shop) { - return self::gets($id_lang, $id_link); + return self::gets($id_lang, $id_link, $id_shop); } - public static function add($link, $label, $newWindow = 0) + public static function add($link, $label, $newWindow = 0, $id_shop) { if(!is_array($label)) return false; @@ -25,7 +53,8 @@ class MenuTopLinks _DB_PREFIX_.'linksmenutop', array( 'new_window'=>(int)$newWindow, - 'link'=>$link + 'link'=>pSQL($link), + 'id_shop' => (int)$id_shop ), 'INSERT' ); @@ -35,19 +64,20 @@ class MenuTopLinks Db::getInstance()->autoExecute( _DB_PREFIX_.'linksmenutop_lang', array( - 'id_link'=>$id_link, - 'id_lang'=>$id_lang, - 'label'=>$label + 'id_link'=>(int)$id_link, + 'id_lang'=>(int)$id_lang, + 'id_shop'=>(int)$id_shop, + 'label'=>pSQL($label) ), 'INSERT' ); } } - public static function remove($id_link) + public static function remove($id_link, $id_shop) { - Db::getInstance()->delete(_DB_PREFIX_.'linksmenutop', "id_link = '{$id_link}'"); - Db::getInstance()->delete(_DB_PREFIX_.'linksmenutop_lang', "id_link = '{$id_link}'"); + Db::getInstance()->delete(_DB_PREFIX_.'linksmenutop', 'id_link = '.(int)$id_link.' AND id_shop = '.(int)$id_shop); + Db::getInstance()->delete(_DB_PREFIX_.'linksmenutop_lang', 'id_link = '.(int)$id_link); } } -?> \ No newline at end of file +?>