From 857a59ae9dd4ab50690cb776fce246bdf2468c18 Mon Sep 17 00:00:00 2001 From: mDeflotte Date: Wed, 21 Dec 2011 10:56:09 +0000 Subject: [PATCH] // BugFix : BlockTopMenu is not visible when user is connected git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11468 b9a71923-0436-4b27-9f14-aed3839534dd --- install-dev/sql/db_settings_extends.sql | 3 + modules/blocktopmenu/blocktopmenu.php | 862 ++++++++++++------------ modules/blocktopmenu/blocktopmenu.tpl | 42 +- 3 files changed, 456 insertions(+), 451 deletions(-) diff --git a/install-dev/sql/db_settings_extends.sql b/install-dev/sql/db_settings_extends.sql index 33e5a6acf..d50967717 100644 --- a/install-dev/sql/db_settings_extends.sql +++ b/install-dev/sql/db_settings_extends.sql @@ -1404,6 +1404,7 @@ INSERT INTO `PREFIX_module_group` (`id_group`, `id_module`) VALUES ("1", "53"), ("1", "54"), ("1", "55"), +("1", "56"); ("2", "1"), ("2", "2"), ("2", "3"), @@ -1456,6 +1457,7 @@ INSERT INTO `PREFIX_module_group` (`id_group`, `id_module`) VALUES ("2", "53"), ("2", "54"), ("2", "55"), +("2", "56"); ("3", "1"), ("3", "2"), ("3", "3"), @@ -1508,6 +1510,7 @@ INSERT INTO `PREFIX_module_group` (`id_group`, `id_module`) VALUES ("3", "53"), ("3", "54"), ("3", "55"); +("3", "56"); INSERT INTO `PREFIX_stock_available` (`id_stock_available`, `id_product`, `id_product_attribute`, `id_shop`, `id_group_shop`, `quantity`, `depends_on_stock`, `out_of_stock`) VALUES (1, 1, 25, 1, 0, 10, 0, 0), diff --git a/modules/blocktopmenu/blocktopmenu.php b/modules/blocktopmenu/blocktopmenu.php index c4687c05d..59ad75888 100644 --- a/modules/blocktopmenu/blocktopmenu.php +++ b/modules/blocktopmenu/blocktopmenu.php @@ -1,6 +1,6 @@ name = 'blocktopmenu'; - $this->tab = 'Julien Breux Developpement'; - $this->version = 1.3; - parent::__construct(); - $this->displayName = $this->l('Top horizontal menu'); - $this->description = $this->l('Add a new menu on top of your shop.'); - } + public function __construct() + { + $this->name = 'blocktopmenu'; + $this->tab = 'Julien Breux Developpement'; + $this->version = 1.3; + 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::updateValue('MOD_BLOCKTOPMENU_ITEMS', 'CAT1,CMS1,CMS2,PRD1') || - !Configuration::updateValue('MOD_BLOCKTOPMENU_SEARCH', '1') || - !$this->installDB()) - return false; - return true; - } + public function install() + { + if(!parent::install() || + !$this->registerHook('top') || + !Configuration::updateValue('MOD_BLOCKTOPMENU_ITEMS', 'CAT1,CMS1,CMS2,PRD1') || + !Configuration::updateValue('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_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, - 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 installDb() + { + return (Db::getInstance()->execute(' + CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'linksmenutop` ( + `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, + 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() - { - if(!parent::uninstall() || - !Configuration::deleteByName('MOD_BLOCKTOPMENU_ITEMS') || - !Configuration::deleteByName('MOD_BLOCKTOPMENU_SEARCH') || - !$this->uninstallDB()) - return false; - return true; - } + 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; - } + 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() - { - global $cookie; - 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')); - } - 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')); - } - } - if(Tools::isSubmit('submitBlocktopmenuRemove')) - { - $id_link = Tools::getValue('id_link', 0); - 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').' -
-
- -
- -
-
+ public function getContent() + { + global $cookie; + 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')); + } + 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')); + } + } + if(Tools::isSubmit('submitBlocktopmenuRemove')) + { + $id_link = Tools::getValue('id_link', 0); + 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').' + +
+ +
+ +
+
-
 
- - - - - - - -
-
-
- '.$this->l('Remove').' >> -
-
-
- << '.$this->l('Add').' -
-
 
- - -
- -
-

- -

- -

'; +
 
+ + + + + + + +
+
+
+ '.$this->l('Remove').' >> +
+
+
+ << '.$this->l('Add').' +
+
 
+ + +
+ +
+

+ +

+ +

'; $defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT')); $languages = Language::getLanguages(); $iso = Language::getIsoById($defaultLanguage); $divLangName = 'link_label'; - $this->_html .= ' -
- '.$this->l('Add Menu Top Link').' -
- -
'; + $this->_html .= ' +
+ '.$this->l('Add Menu Top Link').' + + +
'; foreach ($languages as $language) { $this->_html .= ' @@ -264,228 +264,230 @@ class blocktopmenu extends Module } $this->_html .= $this->displayFlags($languages, $defaultLanguage, $divLangName, 'link_label', true); - $this->_html .= '

- -
- -
- -
- -
-

- -

- -

'; + $this->_html .= '

+ +
+ +
+ +
+ +
+

+ +

+ +

'; - $this->_html .= ' -
- '.$this->l('List Menu Top Link').' - - - - - - - - - - - '; - $links = MenuTopLinks::gets($cookie->id_lang, null, $this->context->shop->id); - foreach($links as $link) - { - $this->_html .= ' - - - - - - - '; - } - $this->_html .= ' -
'.$this->l('Id Link').''.$this->l('Label').''.$this->l('Link').''.$this->l('New Window').''.$this->l('Action').'
'.$link['id_link'].''.$link['label'].''.$link['link'].''.(($link['new_window']) ? $this->l('Yes') : $this->l('No')).' -
- - -
-
-
'; - return $this->_html; - } - - private function getMenuItems() - { - 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 $type => $items) - { - 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 $type => $items) - { - 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; - } - } + $this->_html .= ' +
    + '.$this->l('List Menu Top Link').' + + + + + + + + + + + '; + $links = MenuTopLinks::gets($cookie->id_lang, null, $this->context->shop->id); + foreach($links as $link) + { + $this->_html .= ' + + + + + + + '; + } + $this->_html .= ' +
    '.$this->l('Id Link').''.$this->l('Label').''.$this->l('Link').''.$this->l('New Window').''.$this->l('Action').'
    '.$link['id_link'].''.$link['label'].''.$link['link'].''.(($link['new_window']) ? $this->l('Yes') : $this->l('No')).' +
    + + +
    +
    +
    '; + return $this->_html; } - } - private function getCategoryOption($id_category, $id_lang, $children = true) - { - $categorie = new Category($id_category, $id_lang); - if(is_null($categorie->id)) - return; - if(count(explode('.', $categorie->name)) > 1) - $name = str_replace('.', '', strstr($categorie->name, '.')); - else - $name = $categorie->name; - $this->_html .= ''; - if($children) - { - $childrens = Category::getChildren($id_category, $id_lang); - if(count($childrens)) - foreach($childrens as $children) - $this->getCategoryOption($children['id_category'], $id_lang); - } - } + private function getMenuItems() + { + 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 getCategory($id_category, $id_lang) - { - global $page_name; + private function makeMenuOption() + { + global $cookie; + foreach($this->getMenuItems() as $type => $items) + { + 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; + } + } + } + } - $categorie = new Category($id_category, $id_lang); - if(is_null($categorie->id)) - return; - $selected = ($page_name == 'category' && ((int)Tools::getValue('id_category') == $id_category)) ? ' class="sfHoverForce"' : ''; - $this->_menu .= ''; - if(count(explode('.', $categorie->name)) > 1) - $name = str_replace('.', '', strstr($categorie->name, '.')); - else - $name = $categorie->name; - $this->_menu .= ''.$name.''; - $childrens = Category::getChildren($id_category, $id_lang); - if(count($childrens)) - { - $this->_menu .= '
      '; - foreach($childrens as $children) - $this->getCategory($children['id_category'], $id_lang); - $this->_menu .= '
    '; - } - $this->_menu .= ''; - } + private function makeMenu() + { + global $cookie, $page_name; + foreach($this->getMenuItems() as $type => $items) + { + 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; + } + } + } + } - public function hooktop($param) - { + private function getCategoryOption($id_category, $id_lang, $children = true) + { + $categorie = new Category($id_category, $id_lang); + if(is_null($categorie->id)) + return; + if(count(explode('.', $categorie->name)) > 1) + $name = str_replace('.', '', strstr($categorie->name, '.')); + else + $name = $categorie->name; + $this->_html .= ''; + if($children) + { + $childrens = Category::getChildren($id_category, $id_lang); + if(count($childrens)) + foreach($childrens as $children) + $this->getCategoryOption($children['id_category'], $id_lang); + } + } + + private function getCategory($id_category, $id_lang) + { + global $page_name; + + $categorie = new Category($id_category, $id_lang); + if(is_null($categorie->id)) + return; + $selected = ($page_name == 'category' && ((int)Tools::getValue('id_category') == $id_category)) ? ' class="sfHoverForce"' : ''; + $this->_menu .= ''; + if(count(explode('.', $categorie->name)) > 1) + $name = str_replace('.', '', strstr($categorie->name, '.')); + else + $name = $categorie->name; + $this->_menu .= ''.$name.''; + $childrens = Category::getChildren($id_category, $id_lang); + if(count($childrens)) + { + $this->_menu .= '
      '; + foreach($childrens as $children) + $this->getCategory($children['id_category'], $id_lang); + $this->_menu .= '
    '; + } + $this->_menu .= ''; + } + + public function hookTop($param) + { + elog('rrrrrr'); + caller(); global $smarty; $this->makeMenu(); $smarty->assign('MENU_SEARCH', Configuration::get('MOD_BLOCKTOPMENU_SEARCH')); $smarty->assign('MENU', $this->_menu); $smarty->assign('this_path', $this->_path); - return $this->display(__FILE__, 'blocktopmenu.tpl'); - } + return $this->display(__FILE__, 'blocktopmenu.tpl'); + } } -?> + diff --git a/modules/blocktopmenu/blocktopmenu.tpl b/modules/blocktopmenu/blocktopmenu.tpl index bb80693fa..2d29a4fd1 100644 --- a/modules/blocktopmenu/blocktopmenu.tpl +++ b/modules/blocktopmenu/blocktopmenu.tpl @@ -1,22 +1,22 @@ - {if $MENU != ''} - + {if $MENU != ''} + -
    -
      - {$MENU} - {if $MENU_SEARCH} - - {/if} -
    -
     
    - - - - - {/if} \ No newline at end of file +
    +
      + {$MENU} + {if $MENU_SEARCH} + + {/if} +
    +
     
    + + + + + {/if} \ No newline at end of file