table = 'support_section'; $this->className = 'Section'; $this->lang = true; /*$this->edit = true; $this->view = true; $this->delete = true;*/ $this->_section = AdminSupport::getCurrentSection(); parent::__construct(); } public function displayForm($isMainTab=true) { global $currentIndex, $cookie; parent::displayForm(); $this->section = null; if($id = Tools::getValue('id')) { $this->section = new Section($id); if($this->section->id === null) { Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminSupport')); } } $iso = Language::getIsoById((int)($cookie->id_lang)); $divLangName = 'title¤description'; echo '
'.$this->l('Manage a section').''; echo '
'; foreach($this->_languages as $language) { echo '
'; echo '
'; } $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'title'); echo '
'; echo '
section!==null?($this->section->status==0?' checked="checked"': ''):'').' /> '.$this->l('Disabled').'   section!==null?($this->section->status==1?' checked="checked"': ''):'checked="checked"').' /> '.$this->l('Enabled').' *
'; echo '
'; foreach($this->_languages as $language) { echo '
'; } $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'description'); echo '
'; echo '
section !== null ? 'disabled=disabled': '').' name="submitSectionAdd" value="'.$this->l('Add this section').'" /> section !== null? '': ' disabled="disabled"').' id="submitSectionUpdate" />
'; echo '
'; } public function displayList($token = null) { global $currentIndex, $cookie; $sections = Section::getSections(); echo '
'.$this->l('Sections list').' '; echo ' '; if (isset($sections)) { foreach ($sections as $key => $section) { echo ' '; } } echo '
'.$this->l('ID').' '.$this->l('Title').' '.$this->l('Status').' '.$this->l('Position').' '.$this->l('Actions').'
'.$section->id.' '.$section->title[intval($cookie->id_lang)].' '; if($key != 0){ echo 'Haut'; } if($key + 1 != count($sections)){ echo 'Bas'; } echo '
'; } public function display($token=null) { echo ' '.$this->l('Add a new section').''; echo '
'; $this->displayList($token); echo '
'; } public function submitAddSection() { $section = new Section(); $section->status = Tools::getValue('status', 0); $section->versions = array(); foreach(Language::getLanguages(false) as $language) { if($title = Tools::getValue('title_'.$language['id_lang'])) { $section->title[$language['id_lang']] = $title; } else { $section->title[$language['id_lang']] = ''; } if($description = Tools::getValue('description_'.$language['id_lang'])) { $section->description[$language['id_lang']] = $description; } else { $section->description[$language['id_lang']] = ''; } } $section->save(); } public function submitUpdateSection($id_section) { $section = new section($id_section); $section->status = Tools::getValue('status', 0); $section->id_section = Tools::getValue('id_section',0); $section->versions = array(); foreach(Language::getLanguages(false) as $language) { if($title = Tools::getValue('title_'.$language['id_lang'])) { $section->title[$language['id_lang']] = $title; } else { $section->title[$language['id_lang']] = ''; } if($description = Tools::getValue('description_'.$language['id_lang'])) { $section->description[$language['id_lang']] = $description; } else { $section->description[$language['id_lang']] = ''; } } $section->save(); } public function deleteSection($token=null) { global $currentIndex, $cookie; if($id = Tools::getValue('id')) { $this->section = new Section($id); if($this->section->id === null) { Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminSupport')); } Section::deleteSection($id); } Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminSupport')); } public function postProcess() { global $cookie, $currentIndex; if(Tools::isSubmit('submitSectionAdd')) { $this->submitAddSection(); } elseif(Tools::isSubmit('submitSectionUpdate') && $id_section = (int) Tools::getValue('id_section')) { $this->submitUpdateSection($id_section); } } }