232 lines
11 KiB
PHP
232 lines
11 KiB
PHP
<?php
|
|
if(!defined('_PS_VERSION_')) {
|
|
exit;
|
|
}
|
|
/*include_once(_PS_ROOT_DIR_.'/modules/ant_support/Section.php');
|
|
include_once(_PS_ROOT_DIR_.'/modules/ant_support/Question.php');
|
|
include_once(_PS_ROOT_DIR_.'/modules/ant_support/AdminSections.php');
|
|
include_once(_PS_ROOT_DIR_.'/modules/ant_support/AdminSupport.php');*/
|
|
|
|
class AdminQuestions extends AdminTab
|
|
{
|
|
|
|
private $_section;
|
|
|
|
public function __construct()
|
|
{
|
|
global $currentIndex;
|
|
|
|
$this->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 '<style type="text/css">
|
|
.green {
|
|
background : #dffad3;
|
|
}
|
|
.red {
|
|
background : #f29b9b;
|
|
}
|
|
.position {
|
|
cursor:pointer;
|
|
}
|
|
</style>
|
|
<form action="'.$currentIndex.'&token='.Tools::getAdminTokenLite('AdminSupport').'" method="post" enctype="multipart/form-data">
|
|
<fieldset>
|
|
<legend><img src="../img/admin/cms.gif" alt="" title="" /> '.$this->l('Manage a question in section: ').$this->_section->title[$cookie->id_lang].'</legend>';
|
|
|
|
echo '<label>'.$this->l('Title:').'</label>
|
|
<div class="margin-form">';
|
|
foreach($this->_languages as $language) {
|
|
echo '<div id="title_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
|
|
<input type="text" value="'.($this->question!==null?$this->question->title[$language['id_lang']]:'').'" name="title_'.$language['id_lang'].'">';
|
|
echo '</div>';
|
|
}
|
|
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'title');
|
|
echo '<div class="clear"></div>
|
|
</div>';
|
|
|
|
echo '<label>'.$this->l('Status:').'</label>
|
|
<div class="margin-form">
|
|
<div id="enabled" style="float: left;">
|
|
<input name="status" type="radio" value="0"'.($this->question!==null?($this->question->status==0?' checked="checked"': ''):'').' /> '.$this->l('Disabled').' <input name="status" type="radio" value="1"'.($this->question!==null?($this->question->status==1?' checked="checked"': ''):'checked="checked"').' /> '.$this->l('Enabled').'
|
|
<sup> *</sup>
|
|
</div>
|
|
<div class="clear"></div>
|
|
</div>';
|
|
|
|
echo '<label>'.$this->l('Answer:').'</label>
|
|
<div class="margin-form">';
|
|
foreach($this->_languages as $language) {
|
|
echo '<div id="answer_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
|
|
<textarea style="width: 500px; height: 150px;" name="answer_'.$language['id_lang'].'">';
|
|
if($this->question !== null) {
|
|
// echo htmlentities(utf8_decode($this->question->answer[$language['id_lang']]));
|
|
echo htmlentities($this->question->answer[$language['id_lang']]);
|
|
}
|
|
echo '</textarea>
|
|
</div>';
|
|
}
|
|
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'answer');
|
|
echo '<div class="clear"></div>
|
|
</div>';
|
|
|
|
echo '<br class="clear" />
|
|
<div class="margin-form">
|
|
<input type="hidden" name="id_question" value="'.($this->question !== null? $this->question->id: '').'" />
|
|
<input type="hidden" name="id_section" value="'.($this->_section !== null? $this->_section->id: '').'" />
|
|
<input type="submit" class="button" '.($this->question !== null ? 'disabled=disabled': '').' name="submitQuestionAdd" value="'.$this->l('Add this question').'" />
|
|
<input type="submit" class="button'.($this->question !== null? '': ' disable"').'" name="submitQuestionUpdate" value="'.$this->l('Edit this question').'"'.($this->question !== null? '': ' disabled="disabled"').' id="submitQuestionUpdate" />
|
|
</div>';
|
|
|
|
echo '</fieldset>
|
|
</form>';
|
|
}
|
|
|
|
public function displayList($token = null)
|
|
{
|
|
global $currentIndex, $cookie;
|
|
$questions = Question::getQuestionsByIdSection($this->_section->id);
|
|
echo '<fieldset class="space">
|
|
<legend><img src="../img/admin/prefs.gif" alt="" title="" /> '.$this->l('Question list').'</legend>
|
|
<table class="table list_section" style="width: 100%;">
|
|
<thead>
|
|
<tr>
|
|
<th>'.$this->l('ID').'</th>
|
|
<th>'.$this->l('Title').'</th>
|
|
<th>'.$this->l('Status').'</th>
|
|
<th>'.$this->l('Position').'</th>
|
|
<th style="width:55px;">'.$this->l('Actions').'</th>
|
|
</tr>
|
|
</thead>';
|
|
echo ' <tbody id="questionActive" class="sortable">';
|
|
|
|
if (!empty($questions)) {
|
|
foreach ($questions as $key => $question) {
|
|
echo '<tr id="item_'.$question->id. '" class="question_'.($key%2).'">
|
|
<td>'.$question->id.'</td>
|
|
<td><strong>'.$question->title[intval($cookie->id_lang)].'</strong></td>
|
|
<td><img src="../img/admin/'.($question->status?'enabled.gif':'disabled.gif').'"</td>
|
|
<td class="position">';
|
|
if($key != 0){
|
|
echo '<a onclick="updatePositionQuestion('.$question->id.',0,'.$question->position.')" class="position" data-way="0" data-position='. $question->position .'><img title="Haut" alt="Haut" src="../img/admin/up.gif"></a>';
|
|
}
|
|
if($key + 1 != count($questions)){
|
|
echo '<a onclick="updatePositionQuestion('.$question->id.',1,'.$question->position.')" class="position" data-way="1" data-position='. $question->position .'><img title="Bas" alt="Bas" src="../img/admin/down.gif"></a>';
|
|
}
|
|
echo '</td>
|
|
<td>
|
|
<img style="cursor: pointer;" onclick="questionItemEdition('.$question->id.')" title="Éditer cette question" alt="" src="../img/admin/edit.gif">
|
|
<img style="cursor: pointer;" onclick="questionItemDeletion('.$question->id.')" title="Supprimer cette question" alt="" src="../img/admin/delete.gif">
|
|
</td>
|
|
</tr>
|
|
';
|
|
}
|
|
}
|
|
echo '</tbody>
|
|
</table>
|
|
</fieldset>';
|
|
}
|
|
|
|
public function display($token=null)
|
|
{
|
|
echo '<a href="'.__PS_BASE_URI__.substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__)).'?tab=AdminSupport&addquestion&id_section='.$this->_section->id.'&token='.($token!=NULL ? $token : Tools::getAdminTokenLite('AdminSupport')).'"><img src="../img/admin/add.gif" border="0" /> '.$this->l('Add a new question').'</a>';
|
|
echo '<div style="margin:10px;">';
|
|
$this->displayList($token);
|
|
echo '</div>';
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
} |