/** * render content info */ public function getContent() { $this->base_config_url = 'index.php?controller=AdminModules&configure=' . $this->name . '&token=' . Tools::getValue('token'); $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) { $parent_id = $root; } $child[$parent_id][] = $id; } $res = true; foreach ($child as $id_parent => $menus) { $i = 0; foreach ($menus as $id_psmegamenu) { $res &= Db::getInstance()->execute(' UPDATE `' . _DB_PREFIX_ . 'psmegamenu` SET `position` = ' . (int) $i . ', id_parent = ' . (int) $id_parent . ' WHERE `id_psmegamenu` = ' . (int) $id_psmegamenu); $i++; } } $this->clearCache(); die($this->l('Update Positions Done')); } /* delete megamenu item */ if (Tools::getValue('dodel')) { $obj = new Psbtmegamenu((int) Tools::getValue('id_psmegamenu')); $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 ($id_psmegamenu = Tools::getValue('id_psmegamenu')) { $megamenu = new Psbtmegamenu((int) $id_psmegamenu); } else { $megamenu = new Psbtmegamenu(); } $megamenu->copyFromPost(); $megamenu->id_shop = $this->context->shop->id; if ($megamenu->type && $megamenu->type != 'html' && Tools::getValue($megamenu->type . '_type')) { $megamenu->item = Tools::getValue($megamenu->type . '_type'); } if ($megamenu->validateFields(false) && $megamenu->validateFieldsLang(false)) { $megamenu->save(); if (isset($_FILES['image']) && isset($_FILES['image']['tmp_name']) && !empty($_FILES['image']['tmp_name'])) { $error = ImageManager::validateUpload($_FILES['image']); if ($error) { 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, _PSMEGAMENU_IMAGE_DIR_ . $_FILES['image']['name'])) { return false; } unlink($tmp_name); $megamenu->image = $_FILES['image']['name']; $megamenu->save(); } elseif (Tools::getIsset('delete_icon')) { if ($megamenu->image) { unlink(_PSMEGAMENU_IMAGE_DIR_ . $megamenu->image); $megamenu->image = ''; $megamenu->save(); } } $this->clearCache(); Tools::redirectAdmin(AdminController::$currentIndex . '&configure=psmegamenu&save' . $this->name . '&token=' . Tools::getValue('token') . '&id_psmegamenu=' . $megamenu->id); } else { $this->_html .= '<div class="conf error alert alert-warning">' . $this->l('An error occurred while attempting to save.') . '</div>'; } } return $this->displayForm(); }