示例#1
0
 public function renderChoicesSelect()
 {
     $spacer = str_repeat(' ', $this->spacer_size);
     $items = $this->getMenuItems();
     $html = '<select multiple="multiple" id="availableItems" style="width: 300px; height: 160px;">';
     $html .= '<optgroup label="' . $this->l('CMS') . '">';
     $html .= $this->getCMSOptions(0, 1, $this->context->language->id, $items);
     $html .= '</optgroup>';
     // BEGIN SUPPLIER
     $html .= '<optgroup label="' . $this->l('Supplier') . '">';
     // Option to show all Suppliers
     $html .= '<option value="ALLSUP0">' . $this->l('All suppliers') . '</option>';
     $suppliers = Supplier::getSuppliers(false, $this->context->language->id);
     foreach ($suppliers as $supplier) {
         if (!in_array('SUP' . $supplier['id_supplier'], $items)) {
             $html .= '<option value="SUP' . $supplier['id_supplier'] . '">' . $spacer . $supplier['name'] . '</option>';
         }
     }
     $html .= '</optgroup>';
     // BEGIN Manufacturer
     $html .= '<optgroup label="' . $this->l('Manufacturer') . '">';
     // Option to show all Manufacturers
     $html .= '<option value="ALLMAN0">' . $this->l('All manufacturers') . '</option>';
     $manufacturers = Manufacturer::getManufacturers(false, $this->context->language->id);
     foreach ($manufacturers as $manufacturer) {
         if (!in_array('MAN' . $manufacturer['id_manufacturer'], $items)) {
             $html .= '<option value="MAN' . $manufacturer['id_manufacturer'] . '">' . $spacer . $manufacturer['name'] . '</option>';
         }
     }
     $html .= '</optgroup>';
     // BEGIN Categories
     $shop = new Shop((int) Shop::getContextShopID());
     $html .= '<optgroup label="' . $this->l('Categories') . '">';
     $shops_to_get = Shop::getContextListShopID();
     foreach ($shops_to_get as $shop_id) {
         $html .= $this->generateCategoriesOption($this->customGetNestedCategories($shop_id, null, (int) $this->context->language->id, false), $items);
     }
     $html .= '</optgroup>';
     // BEGIN Shops
     if (Shop::isFeatureActive()) {
         $html .= '<optgroup label="' . $this->l('Shops') . '">';
         $shops = Shop::getShopsCollection();
         foreach ($shops as $shop) {
             if (!$shop->setUrl() && !$shop->getBaseURL()) {
                 continue;
             }
             if (!in_array('SHOP' . (int) $shop->id, $items)) {
                 $html .= '<option value="SHOP' . (int) $shop->id . '">' . $spacer . $shop->name . '</option>';
             }
         }
         $html .= '</optgroup>';
     }
     // BEGIN Products
     $html .= '<optgroup label="' . $this->l('Products') . '">';
     $html .= '<option value="PRODUCT" style="font-style:italic">' . $spacer . $this->l('Choose product ID') . '</option>';
     $html .= '</optgroup>';
     // BEGIN Menu Top Links
     $html .= '<optgroup label="' . $this->l('Menu Top Links') . '">';
     $links = MenuTopLinks::gets($this->context->language->id, null, (int) Shop::getContextShopID());
     foreach ($links as $link) {
         if ($link['label'] == '') {
             $default_language = Configuration::get('PS_LANG_DEFAULT');
             $link = MenuTopLinks::get($link['id_linksmenutop'], $default_language, (int) Shop::getContextShopID());
             if (!in_array('LNK' . (int) $link[0]['id_linksmenutop'], $items)) {
                 $html .= '<option value="LNK' . (int) $link[0]['id_linksmenutop'] . '">' . $spacer . Tools::safeOutput($link[0]['label']) . '</option>';
             }
         } elseif (!in_array('LNK' . (int) $link['id_linksmenutop'], $items)) {
             $html .= '<option value="LNK' . (int) $link['id_linksmenutop'] . '">' . $spacer . Tools::safeOutput($link['label']) . '</option>';
         }
     }
     $html .= '</optgroup>';
     $html .= '</select>';
     return $html;
 }
    public function getContent()
    {
        $id_lang = (int) Context::getContext()->language->id;
        $languages = $this->context->controller->getLanguages();
        $default_language = (int) Configuration::get('PS_LANG_DEFAULT');
        $labels = Tools::getValue('label') ? array_filter(Tools::getValue('label'), 'strlen') : array();
        $links_label = Tools::getValue('link') ? array_filter(Tools::getValue('link'), 'strlen') : array();
        $spacer = str_repeat('&nbsp;', $this->spacer_size);
        $divLangName = 'link_label';
        $update_cache = false;
        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_HOME', (bool) Tools::getValue('home'));
            $update_cache = true;
        } else {
            if (Tools::isSubmit('submitBlocktopmenuLinks')) {
                if (!count($links_label) && !count($labels)) {
                } else {
                    if (!count($links_label)) {
                        $this->_html .= $this->displayError($this->l('Please, fill the "Link" field'));
                    } else {
                        if (!count($labels)) {
                            $this->_html .= $this->displayError($this->l('Please add a label'));
                        } else {
                            if (!isset($labels[$default_language])) {
                                $this->_html .= $this->displayError($this->l('Please add a label for your default language'));
                            } else {
                                MenuTopLinks_mod::add(Tools::getValue('link'), Tools::getValue('label'), Tools::getValue('new_window', 0), (int) Shop::getContextShopID());
                                $this->_html .= $this->displayConfirmation($this->l('The link has been added'));
                            }
                        }
                    }
                }
                $update_cache = true;
            } else {
                if (Tools::isSubmit('submitBlocktopmenuRemove')) {
                    $id_linksmenutop = Tools::getValue('id_linksmenutop', 0);
                    MenuTopLinks_mod::remove($id_linksmenutop, (int) Shop::getContextShopID());
                    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'));
                    $update_cache = true;
                } else {
                    if (Tools::isSubmit('submitBlocktopmenuEdit')) {
                        $id_linksmenutop = (int) Tools::getValue('id_linksmenutop', 0);
                        $id_shop = (int) Shop::getContextShopID();
                        if (!Tools::isSubmit('link')) {
                            $tmp = MenuTopLinks_mod::getLinkLang($id_linksmenutop, $id_shop);
                            $links_label_edit = $tmp['link'];
                            $labels_edit = $tmp['label'];
                            $new_window_edit = $tmp['new_window'];
                        } else {
                            MenuTopLinks_mod::update(Tools::getValue('link'), Tools::getValue('label'), Tools::getValue('new_window', 0), (int) $id_shop, (int) $id_linksmenutop, (int) $id_linksmenutop);
                            $this->_html .= $this->displayConfirmation($this->l('The link has been edited'));
                        }
                        $update_cache = true;
                    }
                }
            }
        }
        if ($update_cache) {
            $this->clearMenuCache();
        }
        $this->_html .= '
        <fieldset>
            <div class="multishop_info">
            ' . $this->l('The modifications will be applied to') . ' ' . (Shop::getContext() == Shop::CONTEXT_SHOP ? $this->l('shop:') . ' ' . $this->context->shop->name : $this->l('all shops')) . '.
            </div>
            <legend><img src="' . $this->_path . 'logo.gif" alt="" title="" />' . $this->l('Settings') . '</legend>
            <form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '" method="post" id="form">
                <div style="display: none">
                <label>' . $this->l('Items') . '</label>
                <div class="margin-form">
                    <input type="text" name="items" id="itemsInput" value="' . Tools::safeOutput(Configuration::get('MOD_BLOCKTOPMENU_ITEMS')) . '" size="70" />
                </div>
                </div>

                <div class="clear">&nbsp;</div>
                <table style="margin-left: 130px;">
                    <tbody>
                        <tr>
                            <td style="padding-left: 20px;">
                                <select multiple="multiple" id="availableItems" style="width: 300px; height: 160px;">';
        // BEGIN CMS
        $this->_html .= '<optgroup label="' . $this->l('CMS') . '">';
        $this->getCMSOptions(0, 1, $id_lang);
        $this->_html .= '</optgroup>';
        // BEGIN SUPPLIER
        $this->_html .= '<optgroup label="' . $this->l('Supplier') . '">';
        $suppliers = Supplier::getSuppliers(false, $id_lang);
        foreach ($suppliers as $supplier) {
            $this->_html .= '<option value="SUP' . $supplier['id_supplier'] . '">' . $spacer . $supplier['name'] . '</option>';
        }
        $this->_html .= '</optgroup>';
        // BEGIN Manufacturer
        $this->_html .= '<optgroup label="' . $this->l('Manufacturer') . '">';
        $manufacturers = Manufacturer::getManufacturers(false, $id_lang);
        foreach ($manufacturers as $manufacturer) {
            $this->_html .= '<option value="MAN' . $manufacturer['id_manufacturer'] . '">' . $spacer . $manufacturer['name'] . '</option>';
        }
        $this->_html .= '</optgroup>';
        // BEGIN Categories
        $this->_html .= '<optgroup label="' . $this->l('Categories') . '">';
        $this->getCategoryOption(1, (int) $id_lang, (int) Shop::getContextShopID());
        $this->_html .= '</optgroup>';
        // BEGIN Shops
        if (Shop::isFeatureActive()) {
            $this->_html .= '<optgroup label="' . $this->l('Shops') . '">';
            $shops = Shop::getShopsCollection();
            foreach ($shops as $shop) {
                if (!$shop->setUrl() && !$shop->getBaseURL()) {
                    continue;
                }
                $this->_html .= '<option value="SHOP' . (int) $shop->id . '">' . $spacer . $shop->name . '</option>';
            }
            $this->_html .= '</optgroup>';
        }
        // BEGIN Products
        $this->_html .= '<optgroup label="' . $this->l('Products') . '">';
        $this->_html .= '<option value="PRODUCT" style="font-style:italic">' . $spacer . $this->l('Choose ID product') . '</option>';
        $this->_html .= '</optgroup>';
        // BEGIN Menu Top Links
        $this->_html .= '<optgroup label="' . $this->l('Menu Top Links') . '">';
        $links = MenuTopLinks_mod::gets($id_lang, null, (int) Shop::getContextShopID());
        foreach ($links as $link) {
            if ($link['label'] == '') {
                $link = MenuTopLinks_mod::get($link['id_linksmenutop'], $default_language, (int) Shop::getContextShopID());
                $this->_html .= '<option value="LNK' . (int) $link[0]['id_linksmenutop'] . '">' . $spacer . $link[0]['label'] . '</option>';
            } else {
                $this->_html .= '<option value="LNK' . (int) $link['id_linksmenutop'] . '">' . $spacer . $link['label'] . '</option>';
            }
        }
        $this->_html .= '</optgroup>';
        $this->_html .= '</select><br />
                                <br />
                                <a href="#" id="addItem" style="border: 1px solid rgb(170, 170, 170); margin: 2px; padding: 2px; text-align: center; display: block; text-decoration: none; background-color: rgb(250, 250, 250); color: rgb(18, 52, 86);">' . $this->l('Add') . ' &gt;&gt;</a>
                            </td>
                            <td>
                                <select multiple="multiple" id="items" style="width: 300px; height: 160px;">';
        $this->makeMenuOption();
        $this->_html .= '</select><br/>
                                <br/>
                                <a href="#" id="removeItem" style="border: 1px solid rgb(170, 170, 170); margin: 2px; padding: 2px; text-align: center; display: block; text-decoration: none; background-color: rgb(250, 250, 250); color: rgb(18, 52, 86);">&lt;&lt; ' . $this->l('Remove') . '</a>
                            </td>
                        </tr>
                    </tbody>
                </table>
                <div class="clear">&nbsp;</div>
                <script type="text/javascript">
                $(document).ready(function(){
                    $("#addItem").click(add);
                    $("#availableItems").dblclick(add);
                    $("#removeItem").click(remove);
                    $("#items").dblclick(remove);
                    function add()
                    {
                        $("#availableItems option:selected").each(function(i){
                            var val = $(this).val();
                            var text = $(this).text();
                            text = text.replace(/(^\\s*)|(\\s*$)/gi,"");
                            if (val == "PRODUCT")
                            {
                                val = prompt("' . $this->l('Set ID product') . '");
                                if (val == null || val == "" || isNaN(val))
                                    return;
                                text = "' . $this->l('Product ID') . ' "+val;
                                val = "PRD"+val;
                            }
                            $("#items").append("<option value=\\""+val+"\\">"+text+"</option>");
                        });
                        serialize();
                        return false;
                    }
                    function remove()
                    {
                        $("#items option:selected").each(function(i){
                            $(this).remove();
                        });
                        serialize();
                        return false;
                    }
                    function serialize()
                    {
                        var options = "";
                        $("#items option").each(function(i){
                            options += $(this).val()+",";
                        });
                        $("#itemsInput").val(options.substr(0, options.length - 1));
                    }
                });
                </script>
                <label for="s">' . $this->l('Home Item') . '</label>
                <div class="margin-form">
                    <input type="checkbox" name="home" id="s" value="1"' . (Configuration::get('MOD_BLOCKTOPMENU_HOME') ? ' checked=""' : '') . '/>
                </div>
                <p class="center">
                    <input type="submit" name="submitBlocktopmenu" value="' . $this->l('	Save	') . '" class="button" />
                </p>
            </form>
        </fieldset><br />';
        $this->_html .= '
        <fieldset>
            <legend><img src="../img/admin/add.gif" alt="" title="" />' . $this->l('Add Menu Top Link') . '</legend>
            <form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '" method="post" id="form">

                ';
        foreach ($languages as $language) {
            $this->_html .= '
                    <div id="link_label_' . (int) $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $id_lang ? 'block' : 'none') . ';">
                <label>' . $this->l('Label') . '</label>
                <div class="margin-form">
                        <input type="text" name="label[' . (int) $language['id_lang'] . ']" id="label_' . (int) $language['id_lang'] . '" size="70" value="' . (isset($labels_edit[$language['id_lang']]) ? Tools::safeOutput($labels_edit[$language['id_lang']]) : '') . '" />
              </div>
                    ';
            $this->_html .= '
                  <label>' . $this->l('Link') . '</label>
                <div class="margin-form">
                    <input type="text" name="link[' . (int) $language['id_lang'] . ']" id="link_' . (int) $language['id_lang'] . '" value="' . (isset($links_label_edit[$language['id_lang']]) ? Tools::safeOutput($links_label_edit[$language['id_lang']]) : '') . '" size="70" />
                </div>
                </div>';
        }
        $this->_html .= '<label>' . $this->l('Language') . '</label>
                <div class="margin-form">' . $this->displayFlags($languages, (int) $id_lang, $divLangName, 'link_label', true) . '</div><p style="clear: both;"> </p>';
        $this->_html .= '<label style="clear: both;">' . $this->l('New Window') . '</label>
                <div class="margin-form">
                    <input style="clear: both;" type="checkbox" name="new_window" value="1" ' . (isset($new_window_edit) && $new_window_edit ? 'checked' : '') . '/>
                </div>
<div class="margin-form">';
        if (Tools::isSubmit('id_linksmenutop')) {
            $this->_html .= '<input type="hidden" name="id_linksmenutop" value="' . (int) Tools::getValue('id_linksmenutop') . '" />';
        }
        if (Tools::isSubmit('submitBlocktopmenuEdit')) {
            $this->_html .= '<input type="submit" name="submitBlocktopmenuEdit" value="' . $this->l('Edit') . '" class="button" />';
        }
        $this->_html .= '
                    <input type="submit" name="submitBlocktopmenuLinks" value="' . $this->l('	Add	') . '" class="button" />
</div>

            </form>
        </fieldset><br />';
        $links = MenuTopLinks_mod::gets((int) $id_lang, null, (int) Shop::getContextShopID());
        if (!count($links)) {
            return $this->_html;
        }
        $this->_html .= '
        <fieldset>
            <legend><img src="../img/admin/details.gif" alt="" title="" />' . $this->l('List Menu Top Link') . '</legend>
            <table style="width:100%;">
                <thead>
                    <tr style="text-align: left;">
                        <th>' . $this->l('Id Link') . '</th>
                        <th>' . $this->l('Label') . '</th>
                        <th>' . $this->l('Link') . '</th>
                        <th>' . $this->l('New Window') . '</th>
                        <th>' . $this->l('Action') . '</th>
                    </tr>
                </thead>
                <tbody>';
        foreach ($links as $link) {
            $this->_html .= '
                    <tr>
                        <td>' . (int) $link['id_linksmenutop'] . '</td>
                        <td>' . Tools::safeOutput($link['label']) . '</td>
                        <td><a href="' . Tools::safeOutput($link['link']) . '"' . ($link['new_window'] ? ' target="_blank"' : '') . '>' . Tools::safeOutput($link['link']) . '</a></td>
                        <td>' . ($link['new_window'] ? $this->l('Yes') : $this->l('No')) . '</td>
                        <td>
                            <form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '" method="post">
                                <input type="hidden" name="id_linksmenutop" value="' . (int) $link['id_linksmenutop'] . '" />
                                <input type="submit" name="submitBlocktopmenuEdit" value="' . $this->l('Edit') . '" class="button" />
                                <input type="submit" name="submitBlocktopmenuRemove" value="' . $this->l('Remove') . '" class="button" />
                            </form>
                        </td>
                    </tr>';
        }
        $this->_html .= '</tbody>
            </table>
        </fieldset>';
        return $this->_html;
    }
    /**
     * loadUpdateSQL will create default lang values when you create a new lang, based on default id lang
     *
     * @return bool true if succeed
     */
    public function loadUpdateSQL()
    {
        $tables = Db::getInstance()->executeS('SHOW TABLES LIKE \'' . str_replace('_', '\\_', _DB_PREFIX_) . '%\\_lang\' ');
        $langTables = array();
        foreach ($tables as $table) {
            foreach ($table as $t) {
                if ($t != _DB_PREFIX_ . 'configuration_lang') {
                    $langTables[] = $t;
                }
            }
        }
        $return = true;
        $shops = Shop::getShopsCollection(false);
        foreach ($shops as $shop) {
            /** @var Shop $shop */
            $id_lang_default = Configuration::get('PS_LANG_DEFAULT', null, $shop->id_shop_group, $shop->id);
            foreach ($langTables as $name) {
                preg_match('#^' . preg_quote(_DB_PREFIX_) . '(.+)_lang$#i', $name, $m);
                $identifier = 'id_' . $m[1];
                $fields = '';
                // We will check if the table contains a column "id_shop"
                // If yes, we will add "id_shop" as a WHERE condition in queries copying data from default language
                $shop_field_exists = $primary_key_exists = false;
                $columns = Db::getInstance()->executeS('SHOW COLUMNS FROM `' . $name . '`');
                foreach ($columns as $column) {
                    $fields .= $column['Field'] . ', ';
                    if ($column['Field'] == 'id_shop') {
                        $shop_field_exists = true;
                    }
                    if ($column['Field'] == $identifier) {
                        $primary_key_exists = true;
                    }
                }
                $fields = rtrim($fields, ', ');
                if (!$primary_key_exists) {
                    continue;
                }
                $sql = 'INSERT IGNORE INTO `' . $name . '` (' . $fields . ') (SELECT ';
                // For each column, copy data from default language
                reset($columns);
                foreach ($columns as $column) {
                    if ($identifier != $column['Field'] && $column['Field'] != 'id_lang') {
                        $sql .= '(
							SELECT `' . bqSQL($column['Field']) . '`
							FROM `' . bqSQL($name) . '` tl
							WHERE tl.`id_lang` = ' . (int) $id_lang_default . '
							' . ($shop_field_exists ? ' AND tl.`id_shop` = ' . (int) $shop->id : '') . '
							AND tl.`' . bqSQL($identifier) . '` = `' . bqSQL(str_replace('_lang', '', $name)) . '`.`' . bqSQL($identifier) . '`
						),';
                    } else {
                        $sql .= '`' . bqSQL($column['Field']) . '`,';
                    }
                }
                $sql = rtrim($sql, ', ');
                $sql .= ' FROM `' . _DB_PREFIX_ . 'lang` CROSS JOIN `' . bqSQL(str_replace('_lang', '', $name)) . '`)';
                $return &= Db::getInstance()->execute($sql);
            }
        }
        return $return;
    }
示例#4
0
 protected function generateAllLinkOptions($selected = '')
 {
     $suppliers = Supplier::getSuppliers(false, false);
     $manufacturers = Manufacturer::getManufacturers(false, false);
     $allLink = '';
     if ($selected == 'CUSTOMLINK|0') {
         $allLink .= '<option selected="selected" value="CUSTOMLINK|0">' . $this->l('-- Custom Link --') . '</option>';
     } else {
         $allLink .= '<option value="CUSTOMLINK|0">' . $this->l('-- Custom Link --') . '</option>';
     }
     $allLink .= '<optgroup label="' . $this->l('Category Link') . '">' . $this->generateCategoryLinkOption(0, $selected) . '</optgroup>';
     $allLink .= '<optgroup label="' . $this->l('CMS Link') . '">' . $this->generateCMSLinkOption(0, 1, false, $selected) . '</optgroup>';
     $allLink .= '<optgroup label="' . $this->l('Supplier Link') . '">';
     if ($selected == 'ALLSUP|0') {
         $allLink .= '<option selected="selected" value="ALLSUP|0">' . $this->l('All suppliers') . '</option>';
     } else {
         $allLink .= '<option value="ALLSUP|0">' . $this->l('All suppliers') . '</option>';
     }
     foreach ($suppliers as $supplier) {
         $key = 'SUP|' . $supplier['id_supplier'];
         if ($key == $selected) {
             $allLink .= '<option selected="selected" value="' . $key . '">|- ' . $supplier['name'] . '</option>';
         } else {
             $allLink .= '<option value="' . $key . '">|- ' . $supplier['name'] . '</option>';
         }
     }
     $allLink .= '</optgroup>';
     $allLink .= '<optgroup label="' . $this->l('Manufacturer Link') . '">';
     if ($selected == 'ALLMAN|0') {
         $allLink .= '<option selected="selected" value="ALLMAN|0">' . $this->l('All manufacturers') . '</option>';
     } else {
         $allLink .= '<option value="ALLMAN|0">' . $this->l('All manufacturers') . '</option>';
     }
     foreach ($manufacturers as $manufacturer) {
         $key = 'MAN|' . $manufacturer['id_manufacturer'];
         if ($key == $selected) {
             $allLink .= '<option selected="selected" value="' . $key . '">|- ' . $manufacturer['name'] . '</option>';
         } else {
             $allLink .= '<option value="' . $key . '">|- ' . $manufacturer['name'] . '</option>';
         }
     }
     $allLink .= '</optgroup>';
     $allLink .= '<optgroup label="' . $this->l('Page Link') . '">' . $this->generatePageLinkOption(0, $selected) . '</optgroup>';
     if (Shop::isFeatureActive()) {
         $allLink .= '<optgroup label="' . $this->l('Shops Link') . '">';
         $shops = Shop::getShopsCollection();
         foreach ($shops as $shop) {
             if (!$shop->setUrl() && !$shop->getBaseURL()) {
                 continue;
             }
             $key = 'SHO|' . $shop->id;
             if ($key == $selected) {
                 $allLink .= '<option selected="selected" value="' . $key . '">' . $shop->name . '</option>';
             } else {
                 $allLink .= '<option value="' . $key . '">' . $shop->name . '</option>';
             }
         }
         $allLink .= '</optgroup>';
     }
     $allLink .= '<optgroup label="' . $this->l('Product Link') . '">';
     if ($selected == 'PRODUCT|0') {
         $allLink .= '<option selected value="PRODUCT|0" style="font-style:italic">' . $this->l('Choose product ID') . '</option>';
     } else {
         $allLink .= '<option value="PRODUCT|0" style="font-style:italic">' . $this->l('Choose product ID') . '</option>';
     }
     $allLink .= '</optgroup>';
     return $allLink;
 }
示例#5
0
 public function getAllLinkOptions($selected = '')
 {
     $suppliers = Supplier::getSuppliers(false, false);
     $manufacturers = Manufacturer::getManufacturers(false, false);
     $allLink = '';
     if ($selected == 'CUSTOMLINK-0') {
         $allLink .= '<option selected="selected" value="CUSTOMLINK-0">' . $this->l('-- Custom Link --') . '</option>';
     } else {
         $allLink .= '<option value="CUSTOMLINK-0">' . $this->l('-- Custom Link --') . '</option>';
     }
     if ($selected == 'CURRENCY-BOX') {
         $allLink .= '<option selected="selected" value="CURRENCY-BOX">' . $this->l('-- Box Currency --') . '</option>';
     } else {
         $allLink .= '<option value="CURRENCY-BOX">' . $this->l('-- Box Currency --') . '</option>';
     }
     if ($selected == 'LANGUAGE-BOX') {
         $allLink .= '<option selected="selected" value="LANGUAGE-BOX">' . $this->l('-- Box Languages --') . '</option>';
     } else {
         $allLink .= '<option value="LANGUAGE-BOX">' . $this->l('-- Box Languages --') . '</option>';
     }
     $allLink .= '<optgroup label="' . $this->l('Category Link') . '">' . $this->getCategoryLinkOptions(0, $selected) . '</optgroup>';
     $allLink .= '<optgroup label="' . $this->l('CMS Link') . '">' . $this->getCMSOptions(0, 1, false, $selected) . '</optgroup>';
     $allLink .= '<optgroup label="' . $this->l('Supplier Link') . '">';
     if ($selected == 'ALLSUP-0') {
         $allLink .= '<option value="ALLSUP-0">' . $this->l('All suppliers') . '</option>';
     } else {
         $allLink .= '<option value="ALLSUP-0">' . $this->l('All suppliers') . '</option>';
     }
     foreach ($suppliers as $supplier) {
         $key = 'SUP-' . $supplier['id_supplier'];
         if ($key == $selected) {
             $allLink .= '<option selected="selected" value="' . $key . '">|- ' . $supplier['name'] . '</option>';
         } else {
             $allLink .= '<option value="' . $key . '">|- ' . $supplier['name'] . '</option>';
         }
     }
     $allLink .= '</optgroup>';
     $allLink .= '<optgroup label="' . $this->l('Manufacturer Link') . '">';
     if ($selected == 'ALLMAN-0') {
         $allLink .= '<option value="ALLMAN-0">' . $this->l('All manufacturers') . '</option>';
     } else {
         $allLink .= '<option value="ALLMAN-0">' . $this->l('All manufacturers') . '</option>';
     }
     foreach ($manufacturers as $manufacturer) {
         $key = 'MAN-' . $manufacturer['id_manufacturer'];
         if ($key == $selected) {
             $allLink .= '<option selected="selected" value="' . $key . '">|- ' . $manufacturer['name'] . '</option>';
         } else {
             $allLink .= '<option value="' . $key . '">|- ' . $manufacturer['name'] . '</option>';
         }
     }
     $allLink .= '</optgroup>';
     $allLink .= '<optgroup label="' . $this->l('Page Link') . '">' . $this->getPagesOption(null, $selected) . '</optgroup>';
     if (Shop::isFeatureActive()) {
         $allLink .= '<optgroup label="' . $this->l('Shops Link') . '">';
         $shops = Shop::getShopsCollection();
         foreach ($shops as $shop) {
             if (!$shop->setUrl() && !$shop->getBaseURL()) {
                 continue;
             }
             $key = 'SHO-' . $shop->id;
             if ($key == $selected) {
                 $allLink .= '<option selected="selected" value="SHOP-' . (int) $shop->id . '">' . $shop->name . '</option>';
             } else {
                 $allLink .= '<option value="SHOP-' . (int) $shop->id . '">' . $shop->name . '</option>';
             }
         }
         $allLink .= '</optgroup>';
     }
     $allLink .= '<optgroup label="' . $this->l('Product Link') . '">';
     if ($selected == 'PRODUCT-0') {
         $allLink .= '<option selected value="PRODUCT-0" style="font-style:italic">' . $this->l('Choose product ID') . '</option>';
     } else {
         $allLink .= '<option value="PRODUCT-0" style="font-style:italic">' . $this->l('Choose product ID') . '</option>';
     }
     $allLink .= '</optgroup>';
     return $allLink;
 }
    private function _displayForm()
    {
        $id_lang = (int) Context::getContext()->language->id;
        $languages = $this->context->controller->getLanguages();
        $default_language = (int) Configuration::get('PS_LANG_DEFAULT');
        $spacer = str_repeat('&nbsp;', $this->spacer_size);
        $divLangName = 'link_label';
        if (Tools::isSubmit('submitBlocktopmegaEdit')) {
            $id_linksvegatop = (int) Tools::getValue('id_linksvegatop', 0);
            $id_shop = (int) Shop::getContextShopID();
            if (!Tools::isSubmit('link')) {
                $tmp = VegaTopLinks::getLinkLang($id_linksvegatop, $id_shop);
                $links_label_edit = $tmp['link'];
                $labels_edit = $tmp['label'];
                $new_window_edit = $tmp['new_window'];
            } else {
                VegaTopLinks::update(Tools::getValue('link'), Tools::getValue('label'), Tools::getValue('new_window', 0), (int) $id_shop, (int) $id_linksvegatop, (int) $id_linksvegatop);
                $this->_html .= $this->displayConfirmation($this->l('The link has been edited'));
            }
        }
        $this->_html .= '
		<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">
                  <fieldset>
                    <legend><img src="../img/admin/cog.gif" alt="" class="middle" />' . $this->l('Settings') . '</legend>
                     <label>' . $this->l('Show Homepage: ') . '</label>
                    <div class="margin-form">';
        $this->_html .= $this->getSelectOptionsHtml(array(0 => 'No', 1 => 'Yes'), 'show_homepage', Tools::getValue('show_homepage') ? Tools::getValue('show_homepage') : Configuration::get($this->name . '_show_homepage'));
        $this->_html .= '
                    </div>
                    <label>' . $this->l('Show number columns: ') . '</label>
                    <div class="margin-form">
                            <input type = "text"  name="menu_depth" value =' . (Tools::getValue('menu_depth') ? Tools::getValue('menu_depth') : Configuration::get($this->name . '_menu_depth')) . ' ></input>
                    </div>';
        $this->_html .= '<label>' . $this->l('Show Levels: ') . '</label>
                    <div class="margin-form">
                            <input type = "text"  name="show_depth" value =' . (Tools::getValue('show_depth') ? Tools::getValue('show_depth') : Configuration::get($this->name . '_show_depth')) . ' ></input>
                    </div>';
        $this->_html .= '<label>' . $this->l('Show Link/Label Category: ') . '</label>';
        $this->_html .= '<div class="margin-form">';
        $this->_html .= '<select multiple="multiple" name ="list_cate[]" style="width: 200px; height: 160px;">';
        // BEGIN Categories
        $id_lang = (int) Context::getContext()->language->id;
        $this->getCategoryOption(1, (int) $id_lang, (int) Shop::getContextShopID());
        $this->_html .= '</select>
            </div>
                <label>' . $this->l('Merge small subcategories: ') . '</label>
                <div class="margin-form">';
        $this->_html .= $this->getSelectOptionsHtml(array(0 => 'No', 1 => 'Yes'), 'merge_cate', Tools::getValue('merge_cate') ? Tools::getValue('merge_cate') : Configuration::get($this->name . '_merge_cate'));
        $this->_html .= '
                </div>';
        $this->_html .= '<label>' . $this->l('Top offset: ') . '</label>
            <div class="margin-form">
                    <input type = "text"  name="top_offset" value =' . (Tools::getValue('top_offset') ? Tools::getValue('top_offset') : Configuration::get($this->name . '_top_offset')) . ' ></input>
            </div>';
        $this->_html .= '<label>' . $this->l('Effect Popup: ') . '</label>
                    <div class="margin-form">';
        $this->_html .= $this->getSelectOptionsHtml(array(0 => 'SlideDown', 1 => 'FadeIn', 2 => 'Show'), 'effect', Tools::getValue('effect') ? Tools::getValue('effect') : Configuration::get($this->name . '_effect'));
        $this->_html .= '
                    </div>';
        $this->_html .= '<div class ="submit">
                      <input type="submit" name="submitPosMegamenu" value="' . $this->l('Update') . '" class="button" />
            </div>              
                 </fieldset>
            </form>';
        $this->_html .= '
		<fieldset>
			<div class="multishop_info">
			' . $this->l('The modifications will be applied to') . ' ' . (Shop::getContext() == Shop::CONTEXT_SHOP ? $this->l('shop') . ' ' . $this->context->shop->name : $this->l('all shops')) . '.
			</div>
			<legend><img src="' . $this->_path . 'logo.gif" alt="" title="" />' . $this->l('Settings') . '</legend>
			<form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '" method="post" id="form">
				<div style="display: none">
				<label>' . $this->l('Items') . '</label>
				<div class="margin-form">
					<input type="text" name="items" id="itemsInput" value="' . Tools::safeOutput(Configuration::get('MOD_BLOCKPOSVENU_ITEMS')) . '" size="70" />
				</div>
				</div>

				<div class="clear">&nbsp;</div>
				<table style="margin-left: 130px;">
					<tbody>
						<tr>
							<td style="padding-left: 20px;">
								<select multiple="multiple" id="availableItems" style="width: 300px; height: 160px;">';
        // BEGIN CMS
        $this->_html .= '<optgroup label="' . $this->l('CMS') . '">';
        $this->getCMSOptions(0, 1, $id_lang);
        $this->_html .= '</optgroup>';
        // BEGIN SUPPLIER
        $this->_html .= '<optgroup label="' . $this->l('Supplier') . '">';
        // Option to show all Suppliers
        $this->_html .= '<option value="ALLSUP0">' . $this->l('All suppliers') . '</option>';
        $suppliers = Supplier::getSuppliers(false, $id_lang);
        foreach ($suppliers as $supplier) {
            $this->_html .= '<option value="SUP' . $supplier['id_supplier'] . '">' . $spacer . $supplier['name'] . '</option>';
        }
        $this->_html .= '</optgroup>';
        // BEGIN Manufacturer
        $this->_html .= '<optgroup label="' . $this->l('Manufacturer') . '">';
        // Option to show all Manufacturers
        $this->_html .= '<option value="ALLMAN0">' . $this->l('All manufacturers') . '</option>';
        $manufacturers = Manufacturer::getManufacturers(false, $id_lang);
        foreach ($manufacturers as $manufacturer) {
            $this->_html .= '<option value="MAN' . $manufacturer['id_manufacturer'] . '">' . $spacer . $manufacturer['name'] . '</option>';
        }
        $this->_html .= '</optgroup>';
        // BEGIN Categories
        $this->_html .= '<optgroup label="' . $this->l('Categories') . '">';
        $this->getCategoryOptionLink(1, (int) $id_lang, (int) Shop::getContextShopID());
        $this->_html .= '</optgroup>';
        // BEGIN Shops
        if (Shop::isFeatureActive()) {
            $this->_html .= '<optgroup label="' . $this->l('Shops') . '">';
            $shops = Shop::getShopsCollection();
            foreach ($shops as $shop) {
                if (!$shop->setUrl() && !$shop->getBaseURL()) {
                    continue;
                }
                $this->_html .= '<option value="SHOP' . (int) $shop->id . '">' . $spacer . $shop->name . '</option>';
            }
            $this->_html .= '</optgroup>';
        }
        // BEGIN Products
        $this->_html .= '<optgroup label="' . $this->l('Products') . '">';
        $this->_html .= '<option value="PRODUCT" style="font-style:italic">' . $spacer . $this->l('Choose product ID') . '</option>';
        $this->_html .= '</optgroup>';
        // BEGIN Menu Top Links
        $this->_html .= '<optgroup label="' . $this->l('Mega menu Top Links') . '">';
        $links = VegaTopLinks::gets($id_lang, null, (int) Shop::getContextShopID());
        foreach ($links as $link) {
            if ($link['label'] == '') {
                $link = VegaTopLinks::get($link['id_linksvegatop'], $default_language, (int) Shop::getContextShopID());
                $this->_html .= '<option value="LNK' . (int) $link[0]['id_linksvegatop'] . '">' . $spacer . $link[0]['label'] . '</option>';
            } else {
                $this->_html .= '<option value="LNK' . (int) $link['id_linksvegatop'] . '">' . $spacer . $link['label'] . '</option>';
            }
        }
        $this->_html .= '</optgroup>';
        $this->_html .= '</select><br />
								<br />
								<a href="#" id="addItem" style="border: 1px solid rgb(170, 170, 170); margin: 2px; padding: 2px; text-align: center; display: block; text-decoration: none; background-color: rgb(250, 250, 250); color: rgb(18, 52, 86);">' . $this->l('Add') . ' &gt;&gt;</a>
							</td>
							<td>
								<select multiple="multiple" id="items" style="width: 300px; height: 160px;">';
        $this->makeMenuOption();
        $this->_html .= '</select><br/>
								<br/>
								<a href="#" id="removeItem" style="border: 1px solid rgb(170, 170, 170); margin: 2px; padding: 2px; text-align: center; display: block; text-decoration: none; background-color: rgb(250, 250, 250); color: rgb(18, 52, 86);">&lt;&lt; ' . $this->l('Remove') . '</a>
							</td>
							<td style="vertical-align:top;padding:5px 15px;">
								<h4 style="margin-top:5px;">' . $this->l('Change position') . '</h4> 
								<a href="#" id="menuOrderUp" class="button" style="font-size:20px;display:block;">&uarr;</a><br/>
								<a href="#" id="menuOrderDown" class="button" style="font-size:20px;display:block;">&darr;</a><br/>
							</td>
						</tr>
					</tbody>
				</table>
				<div class="clear">&nbsp;</div>
				<script type="text/javascript">
				function add()
				{
					$("#availableItems option:selected").each(function(i){
						var val = $(this).val();
						var text = $(this).text();
						text = text.replace(/(^\\s*)|(\\s*$)/gi,"");
						if (val == "PRODUCT")
						{
							val = prompt("' . $this->l('Set ID product') . '");
							if (val == null || val == "" || isNaN(val))
								return;
							text = "' . $this->l('Product ID') . ' "+val;
							val = "PRD"+val;
						}
						$("#items").append("<option value=\\""+val+"\\">"+text+"</option>");
					});
					serialize();
					return false;
				}

				function remove()
				{
					$("#items option:selected").each(function(i){
						$(this).remove();
					});
					serialize();
					return false;
				}

				function serialize()
				{
					var options = "";
					$("#items option").each(function(i){
						options += $(this).val() + ",";
					});
					$("#itemsInput").val(options.substr(0, options.length - 1));
				}

				function move(up)
				{
					var tomove = $("#items option:selected");
					if (tomove.length >1)
					{
						alert(\'' . Tools::htmlentitiesUTF8($this->l('Please select just one item')) . '\');
						return false;
					}
					if (up)
						tomove.prev().insertAfter(tomove);
					else
						tomove.next().insertBefore(tomove);
					serialize();
					return false;
				}

				$(document).ready(function(){
					$("#addItem").click(add);
					$("#availableItems").dblclick(add);
					$("#removeItem").click(remove);
					$("#items").dblclick(remove);
					$("#menuOrderUp").click(function(e){
						e.preventDefault();
						move(true);
					});
					$("#menuOrderDown").click(function(e){
						e.preventDefault();
						move();
					});
				});
				</script>
				<p class="center">
					<input type="submit" name="submitBlockposmenu" value="' . $this->l('Save	') . '" class="button" />
				</p>
			</form>
		</fieldset><br />';
        $this->_html .= '
		<fieldset>
			<legend><img src="../img/admin/add.gif" alt="" title="" />' . $this->l('Add Menu Top Link') . '</legend>
			<form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '" method="post" id="form">

				';
        foreach ($languages as $language) {
            $this->_html .= '
					<div id="link_label_' . (int) $language['id_lang'] . '" style="display: ' . ($language['id_lang'] == $id_lang ? 'block' : 'none') . ';">
				<label>' . $this->l('Label') . '</label>
				<div class="margin-form">
						<input type="text" name="label[' . (int) $language['id_lang'] . ']" id="label_' . (int) $language['id_lang'] . '" size="70" value="' . (isset($labels_edit[$language['id_lang']]) ? $labels_edit[$language['id_lang']] : '') . '" />
			  </div>
					';
            $this->_html .= '
				  <label>' . $this->l('Link') . '</label>
				<div class="margin-form">
					<input type="text" name="link[' . (int) $language['id_lang'] . ']" id="link_' . (int) $language['id_lang'] . '" value="' . (isset($links_label_edit[$language['id_lang']]) ? $links_label_edit[$language['id_lang']] : '') . '" size="70" />
				</div>
				</div>';
        }
        $this->_html .= '<label>' . $this->l('Language') . '</label>
				<div class="margin-form">' . $this->displayFlags($languages, (int) $id_lang, $divLangName, 'link_label', true) . '</div><p style="clear: both;"> </p>';
        $this->_html .= '<label style="clear: both;">' . $this->l('New Window') . '</label>
				<div class="margin-form">
					<input style="clear: both;" type="checkbox" name="new_window" value="1" ' . (isset($new_window_edit) && $new_window_edit ? 'checked' : '') . '/>
				</div>
				<div class="margin-form">';
        if (Tools::isSubmit('id_linksvegatop')) {
            $this->_html .= '<input type="hidden" name="id_linksvegatop" value="' . (int) Tools::getValue('id_linksvegatop') . '" />';
        }
        if (Tools::isSubmit('submitBlocktopmegaEdit')) {
            $this->_html .= '<input type="submit" name="submitBlocktopmegaEdit" value="' . $this->l('Edit') . '" class="button" />';
        }
        $this->_html .= '
									<input type="submit" name="submitBlocktopmegaLinks" value="' . $this->l('Add	') . '" class="button" />
				</div>

			</form>
		</fieldset><br />';
        $links = VegaTopLinks::gets((int) $id_lang, null, (int) Shop::getContextShopID());
        if (!count($links)) {
            return $this->_html;
        }
        $this->_html .= '
			<fieldset>
				<legend><img src="../img/admin/details.gif" alt="" title="" />' . $this->l('List Menu Top Link') . '</legend>
				<table style="width:100%;">
					<thead>
						<tr style="text-align: left;">
							<th>' . $this->l('Id Link') . '</th>
							<th>' . $this->l('Label') . '</th>
							<th>' . $this->l('Link') . '</th>
							<th>' . $this->l('New Window') . '</th>
							<th>' . $this->l('Action') . '</th>
						</tr>
					</thead>
					<tbody>';
        foreach ($links as $link) {
            $this->_html .= '
						<tr>
							<td>' . (int) $link['id_linksvegatop'] . '</td>
							<td>' . Tools::safeOutput($link['label']) . '</td>
							<td><a href="' . Tools::safeOutput($link['link']) . '"' . ($link['new_window'] ? ' target="_blank"' : '') . '>' . Tools::safeOutput($link['link']) . '</a></td>
							<td>' . ($link['new_window'] ? $this->l('Yes') : $this->l('No')) . '</td>
							<td>
								<form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '" method="post">
									<input type="hidden" name="id_linksvegatop" value="' . (int) $link['id_linksvegatop'] . '" />
									<input type="submit" name="submitBlocktopmegaEdit" value="' . $this->l('Edit') . '" class="button" />
									<input type="submit" name="submitBlocktopmegaRemove" value="' . $this->l('Remove') . '" class="button" />
								</form>
							</td>
						</tr>';
        }
        $this->_html .= '</tbody>
				</table>
			</fieldset>';
        return $this->_html;
    }