コード例 #1
0
 /**
  * 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();
 }