table = 'guide_post'; $this->identifier = 'id_guide_post'; $this->className = 'GuidePost'; $this->lang = true; $this->edit = true; $this->view = true; $this->delete = true; $this->fieldsDisplay = array( 'id_guide_post' => array( 'title' => $this->l('ID'), 'align' => 'center', 'width' => 25 ), 'name' => array( 'title' => $this->l('Category'), 'width' => 200, ), 'link_rewrite' => array( 'title' => $this->l('URL'), 'width' => 200 ), 'meta_title' => array( 'title' => $this->l('Title'), 'width' => 300 ), 'position' => array( 'title' => $this->l('Position'), 'width' => 40, 'filter_key' => 'position', 'align' => 'center', 'position' => 'position' ), 'active' => array( 'title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false ) ); $this->_select = 'a.position, gcl.name, a.id_guide_category '; $this->_join = ' LEFT JOIN `'._DB_PREFIX_.'guide_category` gc ON gc.`id_guide_category` = a.`id_guide_category` LEFT JOIN `'._DB_PREFIX_.'guide_category_lang` gcl ON (gcl.`id_guide_category` = gc.`id_guide_category` AND gcl.`id_lang` = '.(int)($cookie->id_lang).')'; $this->_orderBy = 'position'; $this->_orderWay = 'ASC'; $this->identifiersDnd['id_guide_post'] = 'id_guide_post'; parent::__construct(); } public function displayForm($token = NULL) { global $currentIndex, $cookie, $smarty; parent::displayForm(); if (!($obj = $this->loadObject(true))) return; $langs = Language::getLanguages(false); $form = new FormBuilder('AdminGuidePosts', $this->table, 'id_guide_post', 'Add'); $this->fieldsForm = array( 'id_guide_category' => array( 'title' => $this->l('Catégorie du guide'), 'type' => 'select', 'options_raw' => GuideCategory::findCategoriesTree($cookie->id_lang), 'options_map' => ['id_guide_category', 'name', 'level'], 'initial_value' => $obj->id_guide_category ), 'meta_title' => array( 'title' => $this->l('Title (META)'), 'type' => 'text', 'translatable' => true, 'attrs' => [ 'onkeyup' => "copyField2friendlyURL('meta_title', 'link_rewrite');" ] ), 'meta_description' => array( 'title' => $this->l('Description (META)'), 'type' => 'textarea', 'translatable' => true, ), 'link_rewrite' => array( 'title' => $this->l('Simplified URL'), 'type' => 'text', 'required' => true, ), 'content' => array( 'title' => $this->l('Contenu de la page'), 'type' => 'textarea_tinymce', 'translatable' => true ), 'active' => array( 'title' => $this->l('Displayed'), 'type' => 'yesno', 'required' => true, ), ); $form->setTitle($this->l('Purchase guide page')); $form->setFields($this->fieldsForm); $form->setSubmitButton($this->l('Save')); $form->display($smarty, $langs, $obj); } public function postProcess() { global $cookie, $currentIndex; $link = new Link(); if (Tools::isSubmit('viewguide_post') AND ($id_guide_post = (int)(Tools::getValue('id_guide_post'))) AND $guide_post = new GuidePost($id_guide_post, (int)($cookie->id_lang)) AND Validate::isLoadedObject($guide_post)) { $redir = $link->getGuideLink($guide_post, null, null, $cookie->id_lang); if (!$guide_post->active) { $admin_dir = dirname($_SERVER['PHP_SELF']); $admin_dir = substr($admin_dir, strrpos($admin_dir,'/') + 1); $redir .= '?adtoken='.Tools::encrypt('PreviewGuidePost'.$guide_post->id).'&ad='.$admin_dir; } Tools::redirectAdmin($redir); } else { parent::postProcess(); } } }