table = 'support_reason'; $this->className = 'Reason'; $this->lang = true; parent::__construct(); } public function displayForm($isMainTab=true) { global $currentIndex, $cookie; parent::displayForm(); $this->reason = null; if($id = Tools::getValue('id')) { $this->reason = new Reason($id); if($this->reason->id === null) { Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminReasons')); } } $iso = Language::getIsoById((int)($cookie->id_lang)); $contacts = Contact::getContacts((int)($cookie->id_lang)); $divLangName = 'title'; echo '
'.$this->l('Manage a reason').''; echo '
'; foreach($this->_languages as $language) { echo '
'; echo '
'; } $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'title'); echo '
'; echo '
'; echo '
reason!==null?($this->reason->visible==0?' checked="checked"': ''):'').' /> '.$this->l('Disabled').'   reason!==null?($this->reason->visible==1?' checked="checked"': ''):'checked="checked"').' /> '.$this->l('Enabled').' *
'; echo '
reason !== null ? 'disabled=disabled': '').' name="submitReasonAdd" value="'.$this->l('Add this reason').'" /> reason !== null? '': ' disabled="disabled"').' id="submitReasonUpdate" />
'; echo '
'; } public function displayList($token = null) { global $currentIndex, $cookie; echo ' '; echo ''; $reasons = Reason::getReasons(); echo '
'.$this->l('Reason list').' '; echo ' '; if (isset($reasons)) { foreach ($reasons as $key => $reason) { echo ' '; } } echo '
'.$this->l('ID').' '.$this->l('Title').' '.$this->l('Contact').' '.$this->l('Visible').' '.$this->l('Actions').'
'.$reason->id.' '.$reason->title[intval($cookie->id_lang)].' '.$reason->contact[intval($cookie->id_lang)].'
'; } public function display($token=null) { if (((Tools::isSubmit('submitAddreason') OR Tools::isSubmit('submitAddreasonAndStay')) AND sizeof($this->_errors)) OR isset($_GET['updatereason']) OR isset($_GET['addreason'])) { $this->displayForm($this->token); echo '

'.$this->l('Back to list').'
'; } elseif (isset($_GET['deletereason'])) { $this->deleteReason($this->token); } echo ' '.$this->l('Add a new reason').''; echo '
'; $this->displayList($token); echo '
'; } public function submitAddReason() { $reason = new Reason(); $reason->id_contact = Tools::getValue('id_contact', 0); $reason->visible = Tools::getValue('visible', 0); $reason->versions = array(); foreach(Language::getLanguages(false) as $language) { if($title = Tools::getValue('title_'.$language['id_lang'])) { $reason->title[$language['id_lang']] = $title; } else { $reason->title[$language['id_lang']] = ''; } } $reason->save(); } public function submitUpdateReason($id_reason) { $reason = new Reason($id_reason); $reason->id_contact = Tools::getValue('id_contact', 0); $reason->visible = Tools::getValue('visible', 0); $reason->versions = array(); foreach(Language::getLanguages(false) as $language) { if($title = Tools::getValue('title_'.$language['id_lang'])) { $reason->title[$language['id_lang']] = $title; } else { $reason->title[$language['id_lang']] = ''; } } $reason->save(); } public function deleteReason($token=null) { global $currentIndex, $cookie; if($id = Tools::getValue('id')) { $this->reason = new Reason($id); if($this->reason->id === null) { Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminReasons')); } Reason::deleteReason($id); } Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminReasons')); } public function postProcess() { global $cookie, $currentIndex; if (Tools::isSubmit('submitReasonAdd')) { $this->submitAddReason(); } elseif (Tools::isSubmit('submitReasonUpdate') && $id_reason = (int) Tools::getValue('id_reason')) { $this->submitUpdateReason($id_reason); } } }