table = 'support_question'; $this->className = 'Question'; $this->lang = true; $this->_section = AdminSupport::getCurrentSection(); parent::__construct(); } public function displayForm($isMainTab=TRUE) { global $currentIndex, $cookie; if(!$id_section = Tools::getValue('id_section')) { $this->_errors[] = Tools::displayError('at least one section have to be added.'); Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminSupport')); } parent::displayForm(); $this->question = null; if($id = Tools::getValue('id')) { $this->question = new Question($id); if($this->question->id === null) { Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminSupport')); } } $iso = Language::getIsoById((int)($cookie->id_lang)); $divLangName = 'title¤answer'; echo '
'.$this->l('Manage a question in section: ').$this->_section->title[$cookie->id_lang].''; echo '
'; foreach($this->_languages as $language) { echo '
'; echo '
'; } $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'title'); echo '
'; echo '
question!==null?($this->question->status==0?' checked="checked"': ''):'').' /> '.$this->l('Disabled').'   question!==null?($this->question->status==1?' checked="checked"': ''):'checked="checked"').' /> '.$this->l('Enabled').' *
'; echo '
'; foreach($this->_languages as $language) { echo '
'; } $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'answer'); echo '
'; echo '
question !== null ? 'disabled=disabled': '').' name="submitQuestionAdd" value="'.$this->l('Add this question').'" /> question !== null? '': ' disabled="disabled"').' id="submitQuestionUpdate" />
'; echo '
'; } public function displayList($token = null) { global $currentIndex, $cookie; $questions = Question::getQuestionsByIdSection($this->_section->id); echo '
'.$this->l('Question list').' '; echo ' '; if (!empty($questions)) { foreach ($questions as $key => $question) { echo ' '; } } echo '
'.$this->l('ID').' '.$this->l('Title').' '.$this->l('Status').' '.$this->l('Position').' '.$this->l('Actions').'
'.$question->id.' '.$question->title[intval($cookie->id_lang)].' '; if($key != 0){ echo 'Haut'; } if($key + 1 != count($questions)){ echo 'Bas'; } echo '
'; } public function display($token=null) { echo ' '.$this->l('Add a new question').''; echo '
'; $this->displayList($token); echo '
'; } public function submitAddQuestion() { $sql_position = 'SELECT MAX(position) FROM '. _DB_PREFIX_.'support_question'; $position = Db::getInstance()->getValue($sql_position); $question = new Question(); $question->status = Tools::getValue('status', 0); $question->id_section = Tools::getValue('id_section', 0); $question->versions = array(); foreach(Language::getLanguages(false) as $language) { if($title = Tools::getValue('title_'.$language['id_lang'])) { $question->title[$language['id_lang']] = $title; } else { $question->title[$language['id_lang']] = ''; } if($answer = Tools::getValue('answer_'.$language['id_lang'])) { $question->answer[$language['id_lang']] = $answer; } else { $question->answer[$language['id_lang']] = ''; } } $question->save(); } public function submitUpdateQuestion($id_question) { $question = new Question($id_question); $question->status = Tools::getValue('status', 0); $question->id_section = Tools::getValue('id_section',0); $question->versions = array(); foreach(Language::getLanguages(false) as $language) { if($title = Tools::getValue('title_'.$language['id_lang'])) { $question->title[$language['id_lang']] = $title; } else { $question->title[$language['id_lang']] = ''; } if($answer = Tools::getValue('answer_'.$language['id_lang'])) { $question->answer[$language['id_lang']] = $answer; } else { $question->answer[$language['id_lang']] = ''; } } $question->save(); } public function deleteQuestion($token=null) { global $currentIndex, $cookie; if($id = Tools::getValue('id')) { $this->question = new Question($id); if($this->question->id === null) { Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminSupport')); } Question::deleteQuestion($id); } Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminSupport')); } public function postProcess($token=null) { global $cookie, $currentIndex; if(Tools::isSubmit('submitQuestionAdd')) { $this->submitAddQuestion(); } elseif(Tools::isSubmit('submitQuestionUpdate') && $id_question = (int) Tools::getValue('id_question')) { $this->submitUpdateQuestion($id_question); } } }