private function _postProcess() { $errors = array(); /* Processes Slider */ if (Tools::isSubmit('submitUpdateConfig')) { $res = $this->getParams()->batchUpdate($this->_configs); $this->getParams()->refreshConfig(); if (!$res) { $errors[] = $this->l('Configuration could not be updated'); } $this->_html .= $this->displayConfirmation($this->l('Configuration updated')); } elseif (Tools::isSubmit('saveMenu') || Tools::isSubmit('saveMenuAndEdit')) { /* Sets ID if needed */ if (Tools::getValue('id_btmegamenu')) { $objMenu = new Btmegamenu((int) Tools::getValue('id_btmegamenu')); if (!Validate::isLoadedObject($objMenu)) { $this->_html .= $this->displayError($this->l('Invalid id_btmegamenu')); return; } } else { $objMenu = new Btmegamenu(); } if (isset($_FILES['fileicon']) && $_FILES['fileicon']['name']) { $objMenu->image = $_FILES['fileicon']['name']; if (!$this->_lofUpload()) { $errors[] = $this->l('Can\'t upload icon'); } } /* Sets position */ $objMenu->active = (int) Tools::getValue('menu_active'); $objMenu->type = Tools::getValue('type'); if ($objMenu->type == 'url') { $objMenu->url = Tools::getValue('url'); } if ($objMenu->type == 'category') { $objMenu->item = Tools::getValue('type_category'); } if ($objMenu->type == 'product') { $objMenu->item = Tools::getValue('type_product'); } if ($objMenu->type == 'manufacturer') { $objMenu->item = Tools::getValue('type_manufacturer'); } if ($objMenu->type == 'supplier') { $objMenu->item = Tools::getValue('type_supplier'); } if ($objMenu->type == 'cms') { $objMenu->item = Tools::getValue('type_cms'); } $objMenu->id_parent = Tools::getValue('id_parent'); $objMenu->menu_class = Tools::getValue('menu_class'); $objMenu->show_title = Tools::getValue('show_title'); $objMenu->is_group = Tools::getValue('is_group'); $objMenu->is_content = Tools::getValue('is_content'); $objMenu->colums = Tools::getValue('colums'); $objMenu->submenu_colum_width = Tools::getValue('submenu_colum_width'); $objMenu->type_submenu = Tools::getValue('type_submenu'); /* Sets each langue fields */ $languages = Language::getLanguages(false); foreach ($languages as $language) { if (Tools::getValue('title_' . $language['id_lang']) != '') { $objMenu->title[$language['id_lang']] = pSQL(Tools::getValue('title_' . $language['id_lang'])); } if (Tools::getValue('description_' . $language['id_lang']) != '') { $objMenu->description[$language['id_lang']] = pSQL(Tools::getValue('description_' . $language['id_lang'])); } if (Tools::getValue('content_text_' . $language['id_lang']) != '' && Tools::getValue('type') == 'html') { $objMenu->content_text[$language['id_lang']] = Tools::getValue('content_text_' . $language['id_lang']); } if (Tools::getValue('submenu_content_text_' . $language['id_lang']) != '' && Tools::getValue('type_submenu') == 'html') { $objMenu->submenu_content_text[$language['id_lang']] = Tools::getValue('submenu_content_text_' . $language['id_lang']); } } /* Processes if no errors */ if (!$errors) { /* Adds */ if (!Tools::getValue('id_btmegamenu')) { if (!$objMenu->add()) { $errors[] = $this->l('Menu could not be added'); } } elseif (!$objMenu->update()) { $errors[] = $this->l('Menu could not be updated'); } if (!$errors) { if (Tools::isSubmit('saveMenuAndEdit')) { Tools::redirectAdmin($this->base_config_url . '&id_btmegamenu=' . $objMenu->id); } else { Tools::redirectAdmin($this->base_config_url); } } } } elseif (Tools::getValue('deleteMenu')) { $obj = new Btmegamenu((int) Tools::getValue('id_btmegamenu')); $res = $obj->delete(); if (!$res) { $this->_html .= $this->displayError('Could not delete'); } else { $this->_html .= $this->displayConfirmation($this->l('menu deleted')); } } /* Display errors if needed */ if (count($errors)) { $this->_html .= $this->displayError(implode('<br />', $errors)); } elseif (Tools::isSubmit('submitSlide') && Tools::getValue('id_slide')) { $this->_html .= $this->displayConfirmation($this->l('Slide updated')); } elseif (Tools::isSubmit('submitSlide')) { $this->_html .= $this->displayConfirmation($this->l('Slide added')); } }
/** * render content info */ public function getContent() { // $resultCheck = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('SELECT `id_btmegamenu` as id FROM `' . _DB_PREFIX_ . 'btmegamenu_shop` WHERE `id_btmegamenu` = 1 AND `id_shop`=' . (int) ($this->context->shop->id)); // if ($resultCheck["id"] != 1){ // Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'btmegamenu_shop`(`id_btmegamenu`,`id_shop`) VALUES( 1, '.(int)$this->context->shop->id.' )'); // } $output = ''; $this->_html .= $this->headerHTML(); $this->_html .= '<h2>' . $this->displayName . '.</h2>'; /* update tree megamenu positions */ if (Tools::getValue('doupdatepos') && Tools::isSubmit('updatePosition')) { $list = Tools::getValue('list'); $root = 1; $child = array(); foreach ($list as $id => $parent_id) { if ($parent_id <= 0) { # validate module $parent_id = $root; } $child[$parent_id][] = $id; } $res = true; foreach ($child as $id_parent => $menus) { $i = 0; foreach ($menus as $id_btmegamenu) { $res &= Db::getInstance()->execute(' UPDATE `' . _DB_PREFIX_ . 'btmegamenu` SET `position` = ' . (int) $i . ', id_parent = ' . (int) $id_parent . ' WHERE `id_btmegamenu` = ' . (int) $id_btmegamenu); $i++; } } $this->clearCache(); die($this->l('Update Positions Done')); } if (Tools::getValue('show_cavas') && Tools::isSubmit('updatecavas')) { $show = Tools::getValue('show') ? Tools::getValue('show') : 0; if (Configuration::updateValue('LEO_MEGAMENU_CAVAS', $show)) { $this->clearCache(); die($this->l('Update Done')); } else { die($this->l('Can not Update')); } } /* delete megamenu item */ if (Tools::getValue('dodel')) { $obj = new Btmegamenu((int) Tools::getValue('id_btmegamenu')); $res = $obj->delete(); $this->clearCache(); Tools::redirectAdmin(AdminController::$currentIndex . '&configure=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules')); } if (Tools::isSubmit('save' . $this->name) && Tools::isSubmit('active')) { // if( Tools::getValue('type') == 'url' && !Tools::getValue('url')){ // $errors[] = $this->l('Account details are required.'); // } // if (!isset($errors) AND !sizeof($errors)){ if ($id_btmegamenu = Tools::getValue('id_btmegamenu')) { # validate module $megamenu = new Btmegamenu((int) $id_btmegamenu); } else { # validate module $megamenu = new Btmegamenu(); } $keys = LeoBtmegamenuHelper::getConfigKey(false); $post = LeoBtmegamenuHelper::getPost($keys, false); $keys = LeoBtmegamenuHelper::getConfigKey(true); $post += LeoBtmegamenuHelper::getPost($keys, true); $megamenu->copyFromPost($post); $megamenu->id_shop = $this->context->shop->id; if ($megamenu->type && $megamenu->type != 'html' && Tools::getValue($megamenu->type . '_type')) { # validate module $megamenu->item = Tools::getValue($megamenu->type . '_type'); } $url_default = ''; foreach ($megamenu->url as $menu_url) { if ($menu_url) { $url_default = $menu_url; break; } } if ($url_default) { foreach ($megamenu->url as &$menu_url) { if (!$menu_url) { $menu_url = $url_default; } } } if ($megamenu->validateFields(false) && $megamenu->validateFieldsLang(false)) { $megamenu->save(); if (isset($_FILES['image']) && isset($_FILES['image']['tmp_name']) && !empty($_FILES['image']['tmp_name'])) { $this->checkFolderIcon(); if (ImageManager::validateUpload($_FILES['image'])) { return false; } elseif (!($tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS')) || !move_uploaded_file($_FILES['image']['tmp_name'], $tmp_name)) { return false; } elseif (!ImageManager::resize($tmp_name, $this->img_path . $_FILES['image']['name'])) { return false; } unlink($tmp_name); $megamenu->image = $_FILES['image']['name']; $megamenu->save(); } else { if (Tools::getIsset('delete_icon')) { if ($megamenu->image) { unlink($this->img_path . $megamenu->image); $megamenu->image = ''; $megamenu->save(); } } } Tools::redirectAdmin(AdminController::$currentIndex . '&configure=leobootstrapmenu&save' . $this->name . '&token=' . Tools::getValue('token') . '&id_btmegamenu=' . $megamenu->id); } else { # validate module $errors = array(); $errors[] = $this->l('An error occurred while attempting to save.'); } // } if (isset($errors) && count($errors)) { $output .= $this->displayError(implode('<br />', $errors)); } else { $this->clearCache(); $output .= $this->displayConfirmation($this->l('Settings updated.')); } } return $output . $this->displayForm(); }
public function deleteSelection($menus) { $return = 1; foreach ($menus as $id_btmegamenu) { $objMenu = new Btmegamenu($id_btmegamenu); $return &= $objMenu->delete(); } return $return; }