public function reOrderPositions($menu_type) { $id_tab = $this->id; $context = Context::getContext(); $id_shop = $context->shop->id; $max = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT MAX(hss.`position`) as position FROM `' . _DB_PREFIX_ . 'iqitmegamenu_tabs` hss, `' . _DB_PREFIX_ . 'iqitmegamenu` hs WHERE hss.`id_tab` = hs.`id_tab` AND hss.`menu_type` = ' . (int) $menu_type . ' AND hs.`id_shop` = ' . (int) $id_shop); if ((int) $max == (int) $id_tab) { return true; } $rows = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT hss.`position` as position, hss.`id_tab` as id_tab FROM `' . _DB_PREFIX_ . 'iqitmegamenu_tabs` hss LEFT JOIN `' . _DB_PREFIX_ . 'iqitmegamenu` hs ON (hss.`id_tab` = hs.`id_tab`) WHERE hs.`id_shop` = ' . (int) $id_shop . ' AND hss.`menu_type` = ' . (int) $menu_type . ' AND hss.`position` > ' . (int) $this->position); foreach ($rows as $row) { $current_tab = new IqitMenuTab($row['id_tab']); --$current_tab->position; $current_tab->update(); unset($current_tab); } return true; }
private function _postProcess() { $errors = array(); /* Processes tab */ if (Tools::isSubmit('submitAddTab')) { /* Sets ID if needed */ if (Tools::getValue('id_tab')) { $tab = new IqitMenuTab((int) Tools::getValue('id_tab')); if (!Validate::isLoadedObject($tab)) { $this->_html .= $this->displayError($this->l('Invalid id_tab')); return false; } } else { $tab = new IqitMenuTab(); $tab->menu_type = Tools::getValue('menu_type'); $tab->position = IqitMenuTab::getNextPosition(Tools::getValue('menu_type')); } //vals $tab->active = Tools::getValue('active'); $tab->active_label = Tools::getValue('active_label'); $tab->url_type = Tools::getValue('url_type'); $tab->id_url = Tools::getValue('id_url'); $tab->icon_type = Tools::getValue('icon_type'); $tab->icon = Tools::getValue('icon'); $tab->icon_class = Tools::getValue('icon_class'); $tab->legend_icon = Tools::getValue('legend_icon'); $tab->new_window = Tools::getValue('new_window'); $tab->float = Tools::getValue('float'); //colors $tab->bg_color = Tools::getValue('bg_color'); $tab->txt_color = Tools::getValue('txt_color'); $tab->h_bg_color = Tools::getValue('h_bg_color'); $tab->h_txt_color = Tools::getValue('h_txt_color'); $tab->labelbg_color = Tools::getValue('labelbg_color'); $tab->labeltxt_color = Tools::getValue('labeltxt_color'); //submenu $submenu_type = Tools::getValue('submenu_type'); $tab->submenu_type = $submenu_type; $tab->submenu_width = Tools::getValue('submenu_width'); $tab->submenu_bg_color = Tools::getValue('submenu_bg_color'); $tab->submenu_image = Tools::getValue('submenu_image'); $tab->submenu_repeat = Tools::getValue('submenu_repeat'); $tab->submenu_bg_position = Tools::getValue('submenu_bg_position'); $tab->submenu_link_color = Tools::getValue('submenu_link_color'); $tab->submenu_hover_color = Tools::getValue('submenu_hover_color'); $tab->submenu_title_color = Tools::getValue('submenu_title_color'); $tab->submenu_title_colorh = Tools::getValue('submenu_title_colorh'); $tab->submenu_titleb_color = Tools::getValue('submenu_titleb_color'); $tab->submenu_border_t = Tools::getValue('submenu_border_t'); $tab->submenu_border_r = Tools::getValue('submenu_border_r'); $tab->submenu_border_b = Tools::getValue('submenu_border_b'); $tab->submenu_border_l = Tools::getValue('submenu_border_l'); $tab->submenu_border_i = Tools::getValue('submenu_border_i'); $tab->submenu_content = ''; if ($submenu_type == 1) { if (is_array(Tools::getValue('items')) && count(Tools::getValue('items'))) { $tab->submenu_content = (string) implode(',', Tools::getValue('items')); } else { $tab->submenu_content = ''; } } if ($submenu_type == 2) { $tab->submenu_content = urldecode(Tools::getValue('submenu-elements')); } /* Sets each langue fields */ $languages = Language::getLanguages(false); foreach ($languages as $language) { $tab->title[$language['id_lang']] = Tools::getValue('title_' . $language['id_lang']); $tab->label[$language['id_lang']] = Tools::getValue('label_' . $language['id_lang']); $tab->url[$language['id_lang']] = Tools::getValue('url_' . $language['id_lang']); } /* Processes if no errors */ if (!$errors) { /* Adds */ if (!Tools::getValue('id_tab')) { if (!$tab->add()) { $errors[] = $this->displayError($this->l('The tab could not be added.')); } } elseif (!$tab->update()) { $errors[] = $this->displayError($this->l('The tab could not be updated.')); } $this->clearMenuCache(); } } elseif (Tools::isSubmit('delete_id_tab')) { $tab = new IqitMenuTab((int) Tools::getValue('delete_id_tab')); $res = $tab->delete(); $this->clearMenuCache(); if (!$res) { $this->_html .= $this->displayError('Could not delete.'); } else { Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=1&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name); } } elseif (Tools::isSubmit('duplicateTab')) { $this->duplicateMultistoreTab((int) Tools::getValue('duplicateTab')); $this->generateCss(); $this->clearMenuCache(); //Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true).'&conf=1&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name); } elseif (Tools::isSubmit('duplicateTabC')) { $this->duplicateTab((int) Tools::getValue('duplicateTabC')); $this->generateCss(); $this->clearMenuCache(); //Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true).'&conf=1&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name); } $this->generateCss(); $this->clearMenuCache(); /* Display errors if needed */ if (count($errors)) { $this->_html .= $this->displayError(implode('<br />', $errors)); } elseif (Tools::isSubmit('submitAddTab') && Tools::getValue('id_tab')) { Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=4&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name); } elseif (Tools::isSubmit('submitAddTab')) { Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true) . '&conf=3&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name); } }