public function postProcess() { 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_leoblogcat) { $sql = 'UPDATE `' . _DB_PREFIX_ . 'leoblogcat` SET `position` = ' . (int) $i . ', id_parent = ' . (int) $id_parent . ' WHERE `id_leoblogcat` = ' . (int) $id_leoblogcat; $res &= Db::getInstance()->execute($sql); $i++; } } die($this->l('Update Positions Done')); } /* delete megamenu item */ if (Tools::getValue('dodel')) { $obj = new leoblogcat((int) Tools::getValue('id_leoblogcat')); $res = $obj->delete(); Tools::redirectAdmin(AdminController::$currentIndex . '&token=' . Tools::getValue('token')); } if (Tools::isSubmit('save' . $this->name) && Tools::isSubmit('active')) { if ($id_leoblogcat = Tools::getValue('id_leoblogcat')) { # validate module $megamenu = new leoblogcat((int) $id_leoblogcat); } else { # validate module $megamenu = new leoblogcat(); } $this->copyFromPost($megamenu, $this->table); $megamenu->id_shop = $this->context->shop->id; if ($megamenu->validateFields(false) && $megamenu->validateFieldsLang(false)) { $megamenu->save(); if (isset($_FILES['image']) && isset($_FILES['image']['tmp_name']) && !empty($_FILES['image']['tmp_name'])) { 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, _LEOBLOG_BLOG_IMG_DIR_ . 'c/' . $_FILES['image']['name'])) { return false; } unlink($tmp_name); $megamenu->image = $_FILES['image']['name']; $megamenu->save(); } Tools::redirectAdmin(AdminController::$currentIndex . '&saveleoblog&token=' . Tools::getValue('token') . '&id_leoblogcat=' . $megamenu->id); } else { // validate module $this->_html .= '<div class="conf error alert alert-warning">' . $this->l('An error occurred while attempting to save.') . '</div>'; } } }