public function renderForm() { if (!$this->loadObject(true)) { if (Validate::isLoadedObject($this->object)) { $this->display = 'edit'; } else { $this->display = 'add'; } } $this->initToolbar(); $this->initPageHeaderToolbar(); $id_leoblogcat = (int) Tools::getValue('id_leoblogcat'); $obj = new leoblogcat($id_leoblogcat); // $tree = $obj->getTree(); # validate module $obj->getTree(); $menus = $obj->getDropdown(null, $obj->id_parent); if ($this->object->image) { # validate module $thumb = __PS_BASE_URI__ . 'modules/leoblog/views/img/b/' . $this->object->image; } else { # validate module $thumb = ''; } $this->multiple_fieldsets = true; $this->fields_form[0]['form'] = array('tinymce' => true, 'legend' => array('title' => $this->l('Blog Form'), 'icon' => 'icon-folder-close'), 'input' => array(array('type' => 'select', 'label' => $this->l('Category'), 'name' => 'id_leoblogcat', 'options' => array('query' => $menus, 'id' => 'id', 'name' => 'title'), 'default' => $id_leoblogcat), array('type' => 'text', 'label' => $this->l('Meta title:'), 'name' => 'meta_title', 'id' => 'name', 'lang' => true, 'required' => true, 'class' => 'copyMeta2friendlyURL', 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'text', 'label' => $this->l('Friendly URL'), 'name' => 'link_rewrite', 'required' => true, 'lang' => true, 'hint' => $this->l('Only letters and the minus (-) character are allowed')), array('type' => 'tags', 'label' => $this->l('Tags'), 'name' => 'tags', 'lang' => true, 'hint' => array($this->l('Invalid characters:') . ' <>;=#{}', $this->l('To add "tags" click in the field, write something, and then press "Enter."'))), array('type' => 'file', 'label' => $this->l('Image'), 'name' => 'image', 'display_image' => true, 'default' => '', 'desc' => $this->l(''), 'thumb' => $thumb), array('type' => 'textarea', 'label' => $this->l('Video Code'), 'name' => 'video_code', 'rows' => 5, 'cols' => 30, 'hint' => $this->l('Enter Video Code Copying From Youtube, Vimeo') . ' <>;=#{}'), array('type' => 'textarea', 'label' => $this->l('Blog description'), 'name' => 'description', 'autoload_rte' => true, 'lang' => true, 'rows' => 5, 'cols' => 30, 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'textarea', 'label' => $this->l('Blog Content'), 'name' => 'content', 'autoload_rte' => true, 'lang' => true, 'rows' => 5, 'cols' => 40, 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'switch', 'label' => $this->l('Indexation (by search engines):'), 'name' => 'indexation', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'indexation_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'indexation_off', 'value' => 0, 'label' => $this->l('Disabled')))), array('type' => 'switch', 'label' => $this->l('Displayed:'), 'name' => 'active', 'required' => false, 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))))), 'submit' => array('title' => $this->l('Save'), 'class' => 'btn btn-default pull-right')); $this->fields_form[1]['form'] = array('tinymce' => true, 'legend' => array('title' => $this->l('SEO'), 'icon' => 'icon-folder-close'), 'input' => array(array('type' => 'textarea', 'label' => $this->l('Meta description'), 'name' => 'meta_description', 'lang' => true, 'cols' => 40, 'rows' => 10, 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'tags', 'label' => $this->l('Meta keywords'), 'name' => 'meta_keywords', 'lang' => true, 'hint' => array($this->l('Invalid characters:') . ' <>;=#{}', $this->l('To add "tags" click in the field, write something, and then press "Enter."'))))); /* if (Shop::isFeatureActive()) { $this->fields_form['input'][] = array( 'type' => 'shop', 'label' => $this->l('Shop association:'), 'name' => 'checkBoxShopAsso', ); } */ $this->tpl_form_vars = array('active' => $this->object->active, 'PS_ALLOW_ACCENTED_CHARS_URL', (int) Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL')); $html = ' <script type="text/javascript"> var PS_ALLOW_ACCENTED_CHARS_URL = ' . (int) Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL') . '; </script> '; return $html . parent::renderForm(); }
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>'; } } }
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; //delete blog //get all blog from category ID //$where = '`id_leoblogcat` IN (' . $list . ')'; $result_blog = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT `id_leoblog_blog` as id FROM `' . _DB_PREFIX_ . 'leoblog_blog` WHERE `id_leoblogcat` IN (' . $list . ')'); foreach ($result_blog as $value) { $blog = new LeoBlogBlog($value['id']); $blog->delete(); } Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'leoblogcat` WHERE `id_leoblogcat` IN (' . $list . ')'); Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'leoblogcat_shop` WHERE `id_leoblogcat` IN (' . $list . ')'); Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'leoblogcat_lang` WHERE `id_leoblogcat` IN (' . $list . ')'); leoblogcat::cleanPositions($this->id_parent); return true; }