Exemplo n.º 1
0
 public function delete()
 {
     if ($this->id == 1) {
         return false;
     }
     $this->clearCache();
     // Get children categories
     $to_delete = array((int) $this->id);
     $this->recursiveDelete($to_delete, (int) $this->id);
     $to_delete = array_unique($to_delete);
     // Delete CMS Category and its child from database
     $list = count($to_delete) > 1 ? implode(',', $to_delete) : (int) $this->id;
     Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'sbmegamenu` WHERE `id_sbmegamenu` IN (' . pSQL($list) . ')');
     Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'sbmegamenu_shop` WHERE `id_sbmegamenu` IN (' . pSQL($list) . ')');
     Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'sbmegamenu_lang` WHERE `id_sbmegamenu` IN (' . pSQL($list) . ')');
     Sbmegamenu::cleanPositions($this->id_parent);
     return true;
 }
Exemplo n.º 2
0
 /**
  * render content info
  */
 public function getContent()
 {
     $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) {
                 $parent_id = $root;
             }
             $child[$parent_id][] = $id;
         }
         $res = true;
         foreach ($child as $id_parent => $menus) {
             $i = 0;
             foreach ($menus as $id_sbmegamenu) {
                 $sql = 'UPDATE `' . _DB_PREFIX_ . 'sbmegamenu` SET `position` = ' . (int) $i . ', id_parent = ' . (int) $id_parent . ' 
                     WHERE `id_sbmegamenu` = ' . (int) $id_sbmegamenu;
                 $res &= Db::getInstance()->execute($sql);
                 $i++;
             }
         }
         $this->clearCache();
         die($this->l('Update Positions Done'));
     }
     if (Tools::getValue('typesub') && Tools::isSubmit('updatetypesub')) {
         $type = Tools::getValue('type');
         Configuration::updateValue('LEO_MENUSIDEBAR_TYPE', $type);
         $this->clearCache();
         die($this->l('Update Type Sub  Done'));
     }
     /* delete megamenu item */
     if (Tools::getValue('dodel')) {
         $obj = new Sbmegamenu((int) Tools::getValue('id_sbmegamenu'));
         $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 !count($errors)){
         if ($id_sbmegamenu = Tools::getValue('id_sbmegamenu')) {
             $megamenu = new Sbmegamenu((int) $id_sbmegamenu);
         } else {
             $megamenu = new Sbmegamenu();
         }
         $keys = LeoSbmegamenuHelper::getConfigKey(false);
         $post = LeoSbmegamenuHelper::getPost($keys, false);
         $keys = LeoSbmegamenuHelper::getConfigKey(true);
         $post += LeoSbmegamenuHelper::getPost($keys, true);
         $megamenu->copyFromPost($post);
         $megamenu->id_shop = $this->context->shop->id;
         $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->type && $megamenu->type != 'html' && Tools::getValue($megamenu->type . '_type')) {
             $megamenu->item = Tools::getValue($megamenu->type . '_type');
         }
         $errors = array();
         if ($megamenu->validateFields(false) && $megamenu->validateFieldsLang(false)) {
             # Auto set position
             $megamenu->position = Sbmegamenu::getLastPosition((int) $megamenu->id_parent);
             $megamenu->save();
             $megamenu->cleanPositions($megamenu->id_parent);
             if (isset($_FILES['image']) && isset($_FILES['image']['tmp_name']) && !empty($_FILES['image']['tmp_name'])) {
                 $this->checkFolderIcon();
                 if (ImageManagerCore::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=leomenusidebar&save' . $this->name . '&token=' . Tools::getValue('token') . '&id_sbmegamenu=' . $megamenu->id);
         } else {
             $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();
 }