adding module ant_support et ant_support_form
This commit is contained in:
parent
c154535cec
commit
58084aa3c7
@ -376,6 +376,21 @@ class AdminCustomerThreads extends AdminTab
|
||||
.'<br /><b>'.$this->l('Subject:').'</b> '.$message['subject'];
|
||||
}
|
||||
|
||||
// Adding Antadis - linking with ant_support_form module
|
||||
$result = Db::getInstance()->getRow('
|
||||
SELECT sr.*, srl.title
|
||||
FROM `'._DB_PREFIX_.'support_reason` sr
|
||||
LEFT JOIN `'._DB_PREFIX_.'support_reason_lang` srl ON (srl.id_reason = sr.id_reason)
|
||||
LEFT JOIN `'._DB_PREFIX_.'support_reason_customerthread` src ON (src.id_reason = sr.id_reason)
|
||||
WHERE `id_customer_thread` = '.(int) $message['id_customer_thread'].'
|
||||
AND srl.id_lang = '.$cookie->id_lang
|
||||
);
|
||||
if ($result) {
|
||||
$output .='<br /><br />
|
||||
<b>'.$this->l('Reason:').'</b> '.$result['title'].'<br />';
|
||||
}
|
||||
// end adding
|
||||
|
||||
$message['message'] = preg_replace('/(https?:\/\/[a-z0-9#%&_=\(\)\.\? \+\-@\/]{6,1000})([\s\n<])/Uui', '<a href="\1">\1</a>\2', html_entity_decode($message['message'], ENT_NOQUOTES, 'UTF-8'));
|
||||
$output .= '<br /><br />
|
||||
<b>'.$this->l('Thread ID:').'</b> '.(int)$message['id_customer_thread'].'<br />
|
||||
@ -419,7 +434,7 @@ class AdminCustomerThreads extends AdminTab
|
||||
|
||||
public function viewcustomer_thread()
|
||||
{
|
||||
global $cookie, $currentIndex;
|
||||
global $cookie, $currentIndex;
|
||||
|
||||
if (!($thread = $this->loadObject()))
|
||||
return;
|
||||
|
232
modules/ant_support/AdminQuestions.php
Normal file
232
modules/ant_support/AdminQuestions.php
Normal file
@ -0,0 +1,232 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
}
|
230
modules/ant_support/AdminSections.php
Normal file
230
modules/ant_support/AdminSections.php
Normal file
@ -0,0 +1,230 @@
|
||||
<?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/AdminSupport.php');
|
||||
include_once(_PS_ROOT_DIR_.'/modules/ant_support/AdminQuestions.php');*/
|
||||
|
||||
class AdminSections extends AdminTab
|
||||
{
|
||||
private $_section;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
$this->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 '<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 section').'</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->section!==null?$this->section->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->section!==null?($this->section->status==0?' checked="checked"': ''):'').' /> '.$this->l('Disabled').' <input name="status" type="radio" value="1"'.($this->section!==null?($this->section->status==1?' checked="checked"': ''):'checked="checked"').' /> '.$this->l('Enabled').'
|
||||
<sup> *</sup>
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
</div>';
|
||||
|
||||
echo '<label>'.$this->l('Description:').'</label>
|
||||
<div class="margin-form">';
|
||||
foreach($this->_languages as $language) {
|
||||
echo '<div id="description_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
|
||||
<textarea style="width: 500px; height: 150px;" name="description_'.$language['id_lang'].'">';
|
||||
if($this->section !== null) {
|
||||
// echo htmlentities(utf8_decode($this->section->description[$language['id_lang']]));
|
||||
echo htmlentities($this->section->description[$language['id_lang']]);
|
||||
}
|
||||
echo '</textarea>
|
||||
</div>';
|
||||
}
|
||||
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'description');
|
||||
echo '<div class="clear"></div>
|
||||
</div>';
|
||||
|
||||
echo '<br class="clear" />
|
||||
<div class="margin-form">
|
||||
<input type="hidden" name="id_section" value="'.($this->section !== null? $this->section->id: '').'" />
|
||||
<input type="submit" class="button" '.($this->section !== null ? 'disabled=disabled': '').' name="submitSectionAdd" value="'.$this->l('Add this section').'" />
|
||||
<input type="submit" class="button'.($this->section !== null? '': ' disable"').'" name="submitSectionUpdate" value="'.$this->l('Edit this section').'"'.($this->section !== null? '': ' disabled="disabled"').' id="submitSectionUpdate" />
|
||||
</div>';
|
||||
|
||||
echo '</fieldset>
|
||||
</form>';
|
||||
}
|
||||
|
||||
|
||||
public function displayList($token = null)
|
||||
{
|
||||
global $currentIndex, $cookie;
|
||||
$sections = Section::getSections();
|
||||
|
||||
echo '<fieldset class="space">
|
||||
<legend><img src="../img/admin/prefs.gif" alt="" title="" /> '.$this->l('Sections 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:70px;">'.$this->l('Actions').'</th>
|
||||
</tr>
|
||||
</thead>';
|
||||
echo ' <tbody id="sectionActive" class="sortable">';
|
||||
|
||||
if (isset($sections)) {
|
||||
foreach ($sections as $key => $section) {
|
||||
echo '<tr id="item_'.$section->id. '" class="section_'.($key%2).'">
|
||||
<td>'.$section->id.'</td>
|
||||
<td><strong>'.$section->title[intval($cookie->id_lang)].'</strong></td>
|
||||
<td><img src="../img/admin/'.($section->status?'enabled.gif':'disabled.gif').'"</td>
|
||||
<td class="position">';
|
||||
if($key != 0){
|
||||
echo '<a onclick="updatePositionSection('.$section->id.',0,'.$section->position.')" class="position" data-way="0" data-position='. $section->position .'><img title="Haut" alt="Haut" src="../img/admin/up.gif"></a>';
|
||||
}
|
||||
if($key + 1 != count($sections)){
|
||||
echo '<a onclick="updatePositionSection('.$section->id.',1,'.$section->position.')" class="position" data-way="1" data-position='. $section->position .'><img title="Bas" alt="Bas" src="../img/admin/down.gif"></a>';
|
||||
}
|
||||
echo '</td>
|
||||
<td>
|
||||
<img style="cursor: pointer;" onclick="sectionItemEdition('.$section->id.')" title="Éditer cette section" alt="" src="../img/admin/edit.gif">
|
||||
<img style="cursor: pointer;" onclick="sectionItemDeletion('.$section->id.')" title="Supprimer cette section" alt="" src="../img/admin/delete.gif">
|
||||
<a href="'.__PS_BASE_URI__.substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__)).'?tab=AdminSupport&id_section='.$section->id.'&token='.($token!=null ? $token : Tools::getAdminTokenLite('AdminSupport')).'">
|
||||
<img style="cursor: pointer;" title="Voir cette section" alt="" src="../img/admin/details.gif">
|
||||
</a>
|
||||
</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&addsection&token='.($token!=null ? $token : Tools::getAdminTokenLite('AdminSupport')).'"><img src="../img/admin/add.gif" border="0" /> '.$this->l('Add a new section').'</a>';
|
||||
echo '<div style="margin:10px;">';
|
||||
$this->displayList($token);
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
100
modules/ant_support/AdminSupport.php
Normal file
100
modules/ant_support/AdminSupport.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?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/AdminQuestions.php');
|
||||
|
||||
class AdminSupport extends AdminTab
|
||||
{
|
||||
private $adminSections;
|
||||
private $adminQuestions;
|
||||
private static $_section = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
$id_section = abs((int)(Tools::getValue('id_section')));
|
||||
if ($id_section) self::$_section = new Section($id_section);
|
||||
$this->adminSections = new AdminSections();
|
||||
$this->adminQuestions = new AdminQuestions();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public static function getCurrentSection()
|
||||
{
|
||||
return self::$_section;
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if (Tools::isSubmit('submitSectionAdd') || Tools::isSubmit('submitSectionUpdate')) {
|
||||
$this->adminSections->postProcess();
|
||||
}
|
||||
if (Tools::isSubmit('submitQuestionAdd') || Tools::isSubmit('submitQuestionUpdate')) {
|
||||
$this->adminQuestions->postProcess();
|
||||
}
|
||||
}
|
||||
|
||||
public function display()
|
||||
{
|
||||
global $cookie, $currentIndex;
|
||||
|
||||
echo '<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/ant_support/ant_support.js"></script>
|
||||
<script type="text/javascript">
|
||||
i18n_delete = "'.$this->l('Are you sure you want to delete this?').'";
|
||||
current_location = "'.$currentIndex.'&token='.Tools::getAdminTokenLite('AdminSupport').(self::$_section!==null?'&id_section='.self::$_section->id_section:'').'";
|
||||
url_ajax_admin_support = "'.__PS_BASE_URI__.'modules/ant_support/ajax_admin_support.php?&token='.Tools::getAdminTokenLite('AdminSupport').'";
|
||||
</script>';
|
||||
echo '<style type="text/css">
|
||||
.green {
|
||||
background : #dffad3;
|
||||
}
|
||||
.red {
|
||||
background : #f29b9b;
|
||||
}
|
||||
.position {
|
||||
cursor:pointer;
|
||||
}
|
||||
</style>';
|
||||
|
||||
if (((Tools::isSubmit('submitAddsection') OR Tools::isSubmit('submitAddsectionAndStay')) AND sizeof($this->adminSections->_errors)) OR isset($_GET['updatesection']) OR isset($_GET['addsection']))
|
||||
{
|
||||
$this->adminSections->displayForm($this->token);
|
||||
echo '<br /><br /><a href="'.$currentIndex.'&token='.$this->token.'"><img src="../img/admin/arrow2.gif" /> '.$this->l('Back to list').'</a><br />';
|
||||
}
|
||||
elseif (((Tools::isSubmit('submitAddquestion') OR Tools::isSubmit('submitAddquestionAndPreview') OR Tools::isSubmit('submitAddquestionAndStay') AND sizeof($this->adminQuestions->_errors)) OR isset($_GET['updatequestion']) OR isset($_GET['addquestion'])))
|
||||
{
|
||||
$this->adminQuestions->displayForm($this->token);
|
||||
echo '<br /><br /><a href="index.php?tab='.Tools::getValue('tab').'&token='.$this->token.'"><img src="../img/admin/arrow2.gif" /> '.$this->l('Back to list').'</a><br />';
|
||||
}
|
||||
elseif (isset($_GET['deletesection']))
|
||||
{
|
||||
$this->adminSections->deleteSection($this->token);
|
||||
}
|
||||
elseif (isset($_GET['deletequestion']))
|
||||
{
|
||||
$this->adminQuestions->deleteQuestion($this->token);
|
||||
}
|
||||
|
||||
echo '<h2>'.$this->l('Sections').'</h2>';
|
||||
$this->adminSections->display();
|
||||
echo '<div style="margin:10px"> </div>';
|
||||
if (self::$_section !== null) {
|
||||
echo '<h2>'.$this->l('Questions in this section').'</h2>';
|
||||
$this->adminQuestions->display();
|
||||
}
|
||||
}
|
||||
|
||||
public function displayErrors()
|
||||
{
|
||||
parent::displayErrors();
|
||||
$this->adminQuestions->displayErrors();
|
||||
$this->adminSections->displayErrors();
|
||||
}
|
||||
|
||||
}
|
209
modules/ant_support/Question.php
Normal file
209
modules/ant_support/Question.php
Normal file
@ -0,0 +1,209 @@
|
||||
<?php
|
||||
class Question
|
||||
{
|
||||
public $id;
|
||||
public $id_question;
|
||||
public $id_section;
|
||||
public $status = 0;
|
||||
public $position;
|
||||
public $title = array();
|
||||
public $answer = array();
|
||||
public $versions = array();
|
||||
|
||||
protected $fieldsRequired = array('id_section', 'answer');
|
||||
|
||||
public function __construct($id=NULL)
|
||||
{
|
||||
if($id !== NULL) {
|
||||
$question = Question::getQuestion($id);
|
||||
if($question) {
|
||||
$this->id = $id;
|
||||
$this->id_question = $question['id_question'];
|
||||
$this->id_section = $question['id_section'];
|
||||
$this->status = $question['status'];
|
||||
$this->position = $question['position'];
|
||||
$this->title = $question['title'];
|
||||
$this->answer = $question['answer'];
|
||||
/*$this->versions = $question['versions'];*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function getQuestion($id) {
|
||||
if(!($q = Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'support_question`
|
||||
WHERE `id_question` = '.(int) $id
|
||||
)) || count($q) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
'id_question' => $q[0]['id_question'],
|
||||
'id_section' => $q[0]['id_section'],
|
||||
'status' => $q[0]['status'],
|
||||
'position' => $q[0]['position'],
|
||||
'title' => array(),
|
||||
'answer' => array(),
|
||||
);
|
||||
|
||||
$ql = Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'support_question_lang`
|
||||
WHERE `id_question` = '.(int) $id
|
||||
);
|
||||
foreach($ql as $l) {
|
||||
$result['answer'][$l['id_lang']] = $l['answer'];
|
||||
$result['title'][$l['id_lang']] = $l['title'];
|
||||
}
|
||||
|
||||
/*foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT `version`
|
||||
FROM `'._DB_PREFIX_.'support_section_site_version`
|
||||
WHERE `id_section` = '.(int) $id
|
||||
) as $version) {
|
||||
$result['versions'][] = $version['version'];
|
||||
}*/
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getQuestionsByIdSection($id) {
|
||||
if(!($questions = Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'support_question`
|
||||
WHERE `id_section` = '.(int) $id.'
|
||||
ORDER BY `position`'
|
||||
)) || count($questions) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach($questions AS $question) {
|
||||
$result[] = new Question($question['id_question']);
|
||||
}
|
||||
return $result;
|
||||
|
||||
/*$result = array();
|
||||
$ids = array();
|
||||
foreach ($questions as $q) {
|
||||
$result[$q['id_question']] = array(
|
||||
'id_question' => $q['id_question'],
|
||||
'id_section' => $q['id_section'],
|
||||
'status' => $q['status'],
|
||||
'position' => $q['position'],
|
||||
'title' => array(),
|
||||
'answer' => array(),
|
||||
);
|
||||
$ids[] = $q['id_question'];
|
||||
}
|
||||
|
||||
$ql = Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'support_question_lang`
|
||||
WHERE `id_question` IN ('.implode(',', $ids).')'
|
||||
);
|
||||
foreach($ql as $l) {
|
||||
$result[$l['id_question']]['answer'][$l['id_lang']] = $l['answer'];
|
||||
$result[$l['id_question']]['title'][$l['id_lang']] = $l['title'];
|
||||
}*/
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getQuestionIdsByIdSection($id) {
|
||||
if(!($questions = Db::getInstance()->ExecuteS('
|
||||
SELECT `id_question`
|
||||
FROM `'._DB_PREFIX_.'support_question`
|
||||
WHERE `id_section` = '.(int) $id
|
||||
)) || count($questions) == 0) {
|
||||
return false;
|
||||
} else {
|
||||
return $questions;
|
||||
}
|
||||
}
|
||||
|
||||
public function save() {
|
||||
if($this->id !== null) {
|
||||
Db::getInstance()->Execute('
|
||||
UPDATE `'._DB_PREFIX_.'support_question` SET
|
||||
`status` = '.(int) $this->status.',
|
||||
`id_section` = '.(int) $this->id_section.',
|
||||
`position` = '.(int) $this->position.'
|
||||
WHERE `id_question` = '.(int) $this->id.'
|
||||
');
|
||||
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'support_question_lang` WHERE `id_question` = '.(int) $this->id);
|
||||
$question_i18n = array();
|
||||
foreach($this->title as $k => $v) {
|
||||
if(!isset($question_i18n[$k])) {
|
||||
$question_i18n[$k] = array();
|
||||
}
|
||||
$question_i18n[$k]['title'] = $v;
|
||||
}
|
||||
foreach($this->answer as $k => $v) {
|
||||
if(!isset($question_i18n[$k])) {
|
||||
$question_i18n[$k] = array();
|
||||
}
|
||||
$question_i18n[$k]['answer'] = $v;
|
||||
}
|
||||
foreach($question_i18n as $lang => $values) {
|
||||
Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'support_question_lang` VALUES (
|
||||
'.$this->id.',
|
||||
'.$lang.',
|
||||
"'.(isset($values['title'])? pSQL($values['title']): '').'",
|
||||
"'.(isset($values['answer'])? pSQL($values['answer'], true): '').'"
|
||||
)
|
||||
');
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$sql_position = 'SELECT MAX(position) FROM '. _DB_PREFIX_.'support_question WHERE `id_section`='.(int) $this->id_section;
|
||||
$position = Db::getInstance()->getValue($sql_position);
|
||||
|
||||
Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'support_question` VALUES (
|
||||
DEFAULT,
|
||||
'.(int) $this->id_section.',
|
||||
'.(int) $this->status.',
|
||||
'.($position+1).'
|
||||
)
|
||||
');
|
||||
$this->id = Db::getInstance()->Insert_ID();
|
||||
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'support_question_lang` WHERE `id_question` = '.(int) $this->id);
|
||||
$question_i18n = array();
|
||||
foreach($this->title as $k => $v) {
|
||||
if(!isset($question_i18n[$k])) {
|
||||
$question_i18n[$k] = array();
|
||||
}
|
||||
$question_i18n[$k]['title'] = $v;
|
||||
}
|
||||
foreach($this->answer as $k => $v) {
|
||||
if(!isset($question_i18n[$k])) {
|
||||
$question_i18n[$k] = array();
|
||||
}
|
||||
$question_i18n[$k]['answer'] = $v;
|
||||
}
|
||||
foreach($question_i18n as $lang => $values) {
|
||||
Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'support_question_lang` VALUES (
|
||||
'.$this->id.',
|
||||
'.$lang.',
|
||||
"'.(isset($values['title'])? pSQL($values['title']): '').'",
|
||||
"'.(isset($values['answer'])? pSQL($values['answer'], true): '').'"
|
||||
)
|
||||
');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function deleteQuestion($id) {
|
||||
if($question = Question::getQuestion($id)) {
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'support_question_lang` WHERE `id_question` = '.(int) $id);
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'support_question` WHERE `id_question` = '.(int) $id);
|
||||
}
|
||||
}
|
||||
}
|
203
modules/ant_support/Section.php
Normal file
203
modules/ant_support/Section.php
Normal file
@ -0,0 +1,203 @@
|
||||
<?php
|
||||
include_once(_PS_ROOT_DIR_.'/modules/ant_support/Question.php');
|
||||
class Section
|
||||
{
|
||||
public $id;
|
||||
public $id_section;
|
||||
public $status = 0;
|
||||
public $position = 0;
|
||||
public $title = array();
|
||||
public $description = array();
|
||||
public $versions = array();
|
||||
|
||||
public function __construct($id=NULL)
|
||||
{
|
||||
if($id !== NULL) {
|
||||
$section = Section::getSection($id);
|
||||
if($section) {
|
||||
$this->id = $id;
|
||||
$this->id_section = $section['id_section'];
|
||||
$this->status = $section['status'];
|
||||
$this->position = $section['position'];
|
||||
$this->title = $section['title'];
|
||||
$this->description = $section['description'];
|
||||
/*$this->versions = $section['versions'];*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function getSection($id) {
|
||||
if(!($s = Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'support_section`
|
||||
WHERE `id_section` = '.(int) $id
|
||||
)) || count($s) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
'id_section' => $s[0]['id_section'],
|
||||
'status' => $s[0]['status'],
|
||||
'position' => $s[0]['position'],
|
||||
'title' => array(),
|
||||
'description' => array(),
|
||||
);
|
||||
|
||||
$sl = Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'support_section_lang`
|
||||
WHERE `id_section` = '.(int) $id
|
||||
);
|
||||
foreach($sl as $l) {
|
||||
$result['description'][$l['id_lang']] = $l['description'];
|
||||
$result['title'][$l['id_lang']] = $l['title'];
|
||||
}
|
||||
|
||||
/*foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT `version`
|
||||
FROM `'._DB_PREFIX_.'support_section_site_version`
|
||||
WHERE `id_section` = '.(int) $id
|
||||
) as $version) {
|
||||
$result['versions'][] = $version['version'];
|
||||
}*/
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getSections($status=null, $lite=false, $order_by='`position` ASC', $limit=null) {
|
||||
global $cookie;
|
||||
$result = array();
|
||||
$where = array();
|
||||
|
||||
$query = '
|
||||
SELECT ss.`id_section`
|
||||
FROM `'._DB_PREFIX_.'support_section` ss
|
||||
';
|
||||
|
||||
$status !== null? $where[] = '`status` = '.(int) $status: true;
|
||||
!empty($where)? $query .= 'WHERE '.implode(' AND ', $where):$query;
|
||||
$query .= ' ORDER BY '.$order_by;
|
||||
|
||||
if($limit !== null) {
|
||||
$query .= ' LIMIT '.$limit;
|
||||
}
|
||||
if($sections = Db::getInstance()->ExecuteS($query)) {
|
||||
if ($lite) {
|
||||
foreach($sections AS $section) {
|
||||
$result[] = $section['id_section'];
|
||||
}
|
||||
} else {
|
||||
foreach($sections AS $section) {
|
||||
$result[] = new Section($section['id_section']);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getCompleteSections($status=null,$order_by='`position` ASC') {
|
||||
$result = array();
|
||||
$sections = self::getSections($status, $lite=false, $order_by);
|
||||
if (!empty($sections)) {
|
||||
foreach($sections AS $section) {
|
||||
$result[$section->id_section] = array(
|
||||
'section' => new Section($section->id_section),
|
||||
'questions' => array()
|
||||
);
|
||||
|
||||
$questions = Question::getQuestionsByIdSection($section->id_section);
|
||||
if (!empty($questions)) {
|
||||
$result[$section->id_section]['questions'] = $questions;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function save() {
|
||||
if($this->id !== null) {
|
||||
Db::getInstance()->Execute('
|
||||
UPDATE `'._DB_PREFIX_.'support_section` SET
|
||||
`status` = '.(int) $this->status.'
|
||||
WHERE `id_section` = '.(int) $this->id.'
|
||||
');
|
||||
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'support_section_lang` WHERE `id_section` = '.(int) $this->id);
|
||||
$section_i18n = array();
|
||||
foreach($this->title as $k => $v) {
|
||||
if(!isset($section_i18n[$k])) {
|
||||
$section_i18n[$k] = array();
|
||||
}
|
||||
$section_i18n[$k]['title'] = $v;
|
||||
}
|
||||
foreach($this->description as $k => $v) {
|
||||
if(!isset($section_i18n[$k])) {
|
||||
$section_i18n[$k] = array();
|
||||
}
|
||||
$section_i18n[$k]['description'] = $v;
|
||||
}
|
||||
foreach($section_i18n as $lang => $values) {
|
||||
Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'support_section_lang` VALUES (
|
||||
'.$this->id.',
|
||||
'.$lang.',
|
||||
"'.(isset($values['title'])? pSQL($values['title']): '').'",
|
||||
"'.(isset($values['description'])? pSQL($values['description'], true): '').'"
|
||||
)
|
||||
');
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$sql_position = 'SELECT MAX(position) FROM '. _DB_PREFIX_.'support_section';
|
||||
$position = Db::getInstance()->getValue($sql_position);
|
||||
|
||||
Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'support_section` VALUES (
|
||||
DEFAULT,
|
||||
'.(int) $this->status.',
|
||||
'.($position+1).'
|
||||
)
|
||||
');
|
||||
$this->id = Db::getInstance()->Insert_ID();
|
||||
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'support_section_lang` WHERE `id_section` = '.(int) $this->id);
|
||||
$section_i18n = array();
|
||||
foreach($this->title as $k => $v) {
|
||||
if(!isset($section_i18n[$k])) {
|
||||
$section_i18n[$k] = array();
|
||||
}
|
||||
$section_i18n[$k]['title'] = $v;
|
||||
}
|
||||
foreach($this->description as $k => $v) {
|
||||
if(!isset($section_i18n[$k])) {
|
||||
$section_i18n[$k] = array();
|
||||
}
|
||||
$section_i18n[$k]['description'] = $v;
|
||||
}
|
||||
foreach($section_i18n as $lang => $values) {
|
||||
Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'support_section_lang` VALUES (
|
||||
'.$this->id.',
|
||||
'.$lang.',
|
||||
"'.(isset($values['title'])? pSQL($values['title']): '').'",
|
||||
"'.(isset($values['description'])? pSQL($values['description'], true): '').'"
|
||||
)
|
||||
');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function deleteSection($id) {
|
||||
if($section = Section::getSection($id)) {
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'support_section_lang` WHERE `id_section` = '.(int) $id);
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'support_section` WHERE `id_section` = '.(int) $id);
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'support_question` WHERE `id_section` = '.(int) $id);
|
||||
|
||||
$question_ids = Question::getQuestionIdsByIdSection($id);
|
||||
foreach ($question_ids as $key => $id_question) {
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'support_question_lang` WHERE `id_question` = '.(int) $id_question);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
109
modules/ant_support/ajax_admin_support.php
Normal file
109
modules/ant_support/ajax_admin_support.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__).'/../../config/config.inc.php');
|
||||
require_once(dirname(__FILE__).'/../../init.php');
|
||||
include_once(_PS_ROOT_DIR_.'/modules/ant_support/Question.php');
|
||||
include_once(_PS_ROOT_DIR_.'/modules/ant_support/Section.php');
|
||||
|
||||
if (Tools::getValue('token')) {
|
||||
if (isset($_GET['id']) && isset($_GET['position']) && Tools::getIsset('updatepositionQuestion')) {
|
||||
$question = new Question((int) $_GET['id']);
|
||||
$sql = Db::getInstance()->getRow('
|
||||
SELECT `id_question`
|
||||
FROM `'._DB_PREFIX_.'support_question`
|
||||
WHERE `position` = '.(int) $_GET['position'].'
|
||||
AND `id_section` = '.(int) $question->id_section
|
||||
);
|
||||
$question2 = new Question((int) $sql['id_question']);
|
||||
Db::getInstance()->Execute('
|
||||
UPDATE `'._DB_PREFIX_.'support_question` SET
|
||||
`position` = '.(int) $question->position.'
|
||||
WHERE `id_question` = '.(int) $question2->id.'
|
||||
');
|
||||
Db::getInstance()->Execute('
|
||||
UPDATE `'._DB_PREFIX_.'support_question` SET
|
||||
`position` = '.(int) $_GET['position'].'
|
||||
WHERE `id_question` = '.(int) $question->id.'
|
||||
');
|
||||
|
||||
$questions = Question::getQuestionsByIdSection($question->id_section);
|
||||
$html = '';
|
||||
foreach ($questions as $key => $question) {
|
||||
$html .= '<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){
|
||||
$html .= '<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)){
|
||||
$html .= '<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>';
|
||||
}
|
||||
$html .= '</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>
|
||||
';
|
||||
}
|
||||
die(Tools::jsonEncode(array(
|
||||
'has_error' => false,
|
||||
'html' => $html
|
||||
),JSON_HEX_QUOT | JSON_HEX_TAG));
|
||||
|
||||
} elseif (isset($_GET['id']) && isset($_GET['position']) && Tools::getIsset('updatepositionSection')) {
|
||||
$section = new Section((int) $_GET['id']);
|
||||
$sql = Db::getInstance()->getRow('
|
||||
SELECT `id_section`
|
||||
FROM `'._DB_PREFIX_.'support_section`
|
||||
WHERE `position` = '.(int) $_GET['position']
|
||||
);
|
||||
$section2 = new Section((int) $sql['id_section']);
|
||||
Db::getInstance()->Execute('
|
||||
UPDATE `'._DB_PREFIX_.'support_section` SET
|
||||
`position` = '.(int) $section->position.'
|
||||
WHERE `id_section` = '.(int) $section2->id.'
|
||||
');
|
||||
Db::getInstance()->Execute('
|
||||
UPDATE `'._DB_PREFIX_.'support_section` SET
|
||||
`position` = '.(int) $_GET['position'].'
|
||||
WHERE `id_section` = '.(int) $section->id.'
|
||||
');
|
||||
|
||||
$sections = Section::getSections();
|
||||
$html='';
|
||||
foreach ($sections as $key => $section) {
|
||||
$html .= '<tr id="item_'.$section->id. '" class="section_'.($key%2).'">
|
||||
<td>'.$section->id.'</td>
|
||||
<td><strong>'.$section->title[intval($cookie->id_lang)].'</strong></td>
|
||||
<td><img src="../img/admin/'.($section->status?'enabled.gif':'disabled.gif').'"</td>
|
||||
<td class="position">';
|
||||
if($key != 0){
|
||||
$html .= '<a onclick="updatePositionSection('.$section->id.',0,'.$section->position.')" class="position" data-way="0" data-position='. $section->position .'><img title="Haut" alt="Haut" src="../img/admin/up.gif"></a>';
|
||||
}
|
||||
if($key + 1 != count($sections)){
|
||||
$html .= '<a onclick="updatePositionSection('.$section->id.',1,'.$section->position.')" class="position" data-way="1" data-position='. $section->position .'><img title="Bas" alt="Bas" src="../img/admin/down.gif"></a>';
|
||||
}
|
||||
$html .= '</td>
|
||||
<td>
|
||||
<img style="cursor: pointer;" onclick="sectionItemEdition('.$section->id.')" title="Éditer cette section" alt="" src="../img/admin/edit.gif">
|
||||
<img style="cursor: pointer;" onclick="sectionItemDeletion('.$section->id.')" title="Supprimer cette section" alt="" src="../img/admin/delete.gif">
|
||||
<a href="index.php?tab=AdminSupport&id_section='.$section->id.'&token='.Tools::getValue('token').'">
|
||||
<img style="cursor: pointer;" title="Voir cette section" alt="" src="../img/admin/details.gif">
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
';
|
||||
}
|
||||
|
||||
die(Tools::jsonEncode(array(
|
||||
'has_error' => false,
|
||||
'html' => $html
|
||||
),JSON_HEX_QUOT | JSON_HEX_TAG));
|
||||
}
|
||||
}
|
||||
die(Tools::jsonEncode(array(
|
||||
'has_error' => true,
|
||||
'html' => '<p>Probleme de token<p>'
|
||||
)));
|
17
modules/ant_support/ant_support.css
Normal file
17
modules/ant_support/ant_support.css
Normal file
@ -0,0 +1,17 @@
|
||||
.ant_support {
|
||||
padding:10px;
|
||||
}
|
||||
.section-help {
|
||||
padding:10px;
|
||||
margin-bottom: 20px;
|
||||
border-bottom: 1px solid #535085;
|
||||
}
|
||||
.ant_support h3 {
|
||||
font-size: 18px;
|
||||
}
|
||||
.ant_support h4 {
|
||||
margin-top: 10px;
|
||||
}
|
||||
.ant_support .ui-accordion-content{
|
||||
/* padding-bottom: 20px !important; */
|
||||
}
|
61
modules/ant_support/ant_support.js
Normal file
61
modules/ant_support/ant_support.js
Normal file
@ -0,0 +1,61 @@
|
||||
function questionItemEdition(linkId) {
|
||||
document.location.href = current_location + "&updatequestion&id=" + linkId;
|
||||
}
|
||||
function questionItemDeletion(linkId) {
|
||||
var ok = confirm(i18n_delete)
|
||||
if(ok == true) {
|
||||
document.location.href = current_location + "&id=" + linkId + "&deletequestion=1";
|
||||
}
|
||||
}
|
||||
function updatePositionQuestion(id, way, position) {
|
||||
if (way==0) {
|
||||
way = -1;
|
||||
} else {
|
||||
way = 1;
|
||||
}
|
||||
diff = position + way;
|
||||
if(diff != 0){
|
||||
$.ajax({
|
||||
url: url_ajax_admin_support,
|
||||
type: "GET",
|
||||
dataType:'json',
|
||||
data: "id=" + id + "&position=" + diff +"&updatepositionQuestion",
|
||||
success: function(response) {
|
||||
if (!response.has_error){
|
||||
$('#questionActive').html(response.html);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
function updatePositionSection(id, way, position) {
|
||||
if (way==0) {
|
||||
way = -1;
|
||||
} else {
|
||||
way = 1;
|
||||
}
|
||||
diff = position + way;
|
||||
if(diff != 0){
|
||||
$.ajax({
|
||||
url: url_ajax_admin_support,
|
||||
type: "GET",
|
||||
dataType:'json',
|
||||
data: "id=" + id + "&position=" + diff +"&updatepositionSection",
|
||||
success: function(response) {
|
||||
if (!response.has_error){
|
||||
$('#sectionActive').html(response.html);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function sectionItemEdition(linkId) {
|
||||
document.location.href = current_location + "&updatesection&id=" + linkId;
|
||||
}
|
||||
function sectionItemDeletion(linkId) {
|
||||
var ok = confirm(i18n_delete)
|
||||
if(ok == true) {
|
||||
document.location.href = current_location + "&id=" + linkId + "&deletesection=1";
|
||||
}
|
||||
}
|
117
modules/ant_support/ant_support.php
Normal file
117
modules/ant_support/ant_support.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
class Ant_Support extends Module
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->name = 'ant_support';
|
||||
$this->tab = 'administration';
|
||||
$this->author = 'Antadis';
|
||||
$this->version = '1.0';
|
||||
$this->need_instance = 0;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->displayName = $this->l('Help and contact section');
|
||||
$this->description = $this->l('Creating sections, questions and answers for help section');
|
||||
}
|
||||
|
||||
public function install()
|
||||
{
|
||||
|
||||
$query = '
|
||||
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'support_section` (
|
||||
`id_section` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`status` BOOL NOT NULL,
|
||||
`position` INTEGER,
|
||||
PRIMARY KEY(`id_section`)
|
||||
) ENGINE=MyIsam DEFAULT CHARSET=utf8
|
||||
';
|
||||
if(!Db::getInstance()->Execute($query)) {
|
||||
return false;
|
||||
}
|
||||
$query = '
|
||||
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'support_section_lang` (
|
||||
`id_section` INTEGER NOT NULL,
|
||||
`id_lang` INTEGER NOT NULL,
|
||||
`title` VARCHAR(255) NOT NULL,
|
||||
`description` TEXT,
|
||||
PRIMARY KEY(`id_section`, `id_lang`)
|
||||
) ENGINE=MyIsam DEFAULT CHARSET=utf8
|
||||
';
|
||||
if(!Db::getInstance()->Execute($query)) {
|
||||
return false;
|
||||
}
|
||||
$query = '
|
||||
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'support_question` (
|
||||
`id_question` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`id_section` INTEGER NOT NULL,
|
||||
`status` BOOL NOT NULL,
|
||||
`position` INTEGER,
|
||||
PRIMARY KEY(`id_question`)
|
||||
) ENGINE=MyIsam DEFAULT CHARSET=utf8
|
||||
';
|
||||
if(!Db::getInstance()->Execute($query)) {
|
||||
return false;
|
||||
}
|
||||
$query = '
|
||||
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'support_question_lang` (
|
||||
`id_question` INTEGER NOT NULL,
|
||||
`id_lang` INTEGER NOT NULL,
|
||||
`title` TEXT,
|
||||
`answer` TEXT,
|
||||
PRIMARY KEY(`id_question`, `id_lang`)
|
||||
) ENGINE=MyIsam DEFAULT CHARSET=utf8
|
||||
';
|
||||
if(!Db::getInstance()->Execute($query)) {
|
||||
return false;
|
||||
}
|
||||
/* $query = '
|
||||
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'support_answer` (
|
||||
`id_answer` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`id_section` INTEGER NOT NULL,
|
||||
`status` BOOL NOT NULL,
|
||||
PRIMARY KEY(`id_answer`)
|
||||
) ENGINE=MyIsam DEFAULT CHARSET=utf8
|
||||
';
|
||||
if(!Db::getInstance()->Execute($query)) {
|
||||
return false;
|
||||
}
|
||||
$query = '
|
||||
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'support_answer_lang` (
|
||||
`id_answer` INTEGER NOT NULL,
|
||||
`id_lang` INTEGER NOT NULL,
|
||||
`content` TEXT,
|
||||
PRIMARY KEY(`id_answer`, `id_lang`)
|
||||
) ENGINE=MyIsam DEFAULT CHARSET=utf8
|
||||
';
|
||||
if(!Db::getInstance()->Execute($query)) {
|
||||
return false;
|
||||
}*/
|
||||
|
||||
if(!(parent::install())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function uninstall() {
|
||||
|
||||
if(parent::uninstall() == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'support_section`');
|
||||
Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'support_section_lang`');
|
||||
Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'support_question`');
|
||||
Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'support_question_lang`');
|
||||
/*Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'support_answer`');
|
||||
Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'support_answer_lang`');*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
20
modules/ant_support/help.php
Normal file
20
modules/ant_support/help.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__).'/../../config/config.inc.php');
|
||||
require_once(dirname(__FILE__).'/../../init.php');
|
||||
require_once(dirname(__FILE__).'/Section.php');
|
||||
$controller->preProcess();
|
||||
|
||||
$langs = Language::getLanguages();
|
||||
$lang = (int) $cookie->id_lang;
|
||||
$isolang = Language::getIsoById($lang);
|
||||
|
||||
$result = Section::getCompleteSections();
|
||||
$smarty->assign(array(
|
||||
'result' => $result
|
||||
));
|
||||
|
||||
require_once(dirname(__FILE__).'/../../header.php');
|
||||
|
||||
echo Module::display(dirname(__FILE__), 'help.tpl');
|
||||
|
||||
require_once(dirname(__FILE__).'/../../footer.php');
|
39
modules/ant_support/help.tpl
Normal file
39
modules/ant_support/help.tpl
Normal file
@ -0,0 +1,39 @@
|
||||
<script type="text/javascript" src="{$base_dir_ssl}js/jquery/accordion/accordion.ui.js"></script>
|
||||
<link media="all" type="text/css" rel="stylesheet" href="{$base_dir_ssl}modules/ant_support/ant_support.css">
|
||||
|
||||
{include file="$tpl_dir./breadcrumb.tpl"}
|
||||
|
||||
<h1>{l s='Questions frequentes' mod='ant_support'}</h1>
|
||||
<div class='ant_support'>
|
||||
{foreach $result as $section name=result}
|
||||
|
||||
{literal}
|
||||
<script>
|
||||
$(function() {
|
||||
$('#accordion_{/literal}{$section['section']->id_section}{literal}').accordion({
|
||||
collapsible: true,
|
||||
autoHeight: false,
|
||||
navigation: true
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{/literal}
|
||||
<div class="section-help">
|
||||
<h2>{$section['section']->title[$cookie->id_lang]}</h2>
|
||||
<div id="accordion_{$section['section']->id_section}">
|
||||
{if !empty($section['section']->description[$cookie->id_lang])}
|
||||
<p>{$section['section']->description[$cookie->id_lang]}</p>
|
||||
{/if}
|
||||
{foreach $section['questions'] as $question name=questions}
|
||||
<h4 style="cursor:pointer;">{$question->title[$cookie->id_lang]}</h4>
|
||||
<div>
|
||||
{$question->answer[$cookie->id_lang]}
|
||||
</div>
|
||||
{/foreach}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/foreach}
|
||||
</div>
|
||||
|
||||
|
225
modules/ant_support_form/AdminReasons.php
Normal file
225
modules/ant_support_form/AdminReasons.php
Normal file
@ -0,0 +1,225 @@
|
||||
<?php
|
||||
if(!defined('_PS_VERSION_')) {
|
||||
exit;
|
||||
}
|
||||
include_once(_PS_ROOT_DIR_.'/modules/ant_support_form/Reason.php');
|
||||
|
||||
class AdminReasons extends AdminTab
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
global $cookie;
|
||||
|
||||
$this->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 '<style type="text/css">
|
||||
.green {
|
||||
background : #dffad3;
|
||||
}
|
||||
.red {
|
||||
background : #f29b9b;
|
||||
}
|
||||
.position {
|
||||
cursor:pointer;
|
||||
}
|
||||
</style>
|
||||
<form action="'.$currentIndex.'&token='.Tools::getAdminTokenLite('AdminReasons').'" method="post" enctype="multipart/form-data">
|
||||
<fieldset>
|
||||
<legend><img src="../img/admin/cms.gif" alt="" title="" /> '.$this->l('Manage a reason').'</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->reason!==null?$this->reason->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('Contact:').'</label>
|
||||
<div class="margin-form">
|
||||
<select name="id_contact">';
|
||||
foreach($contacts as $contact) {
|
||||
echo '<option value="'.$contact['id_contact'].'" '.(($this->reason!==null && $this->reason->id_contact == (int)$contact['id_contact'])? 'selected':'').'>'.$contact['name'].'</option>';
|
||||
}
|
||||
echo '</select>
|
||||
<div class="clear"></div>
|
||||
</div>';
|
||||
|
||||
echo '<label>'.$this->l('Visible on front:').'</label>
|
||||
<div class="margin-form">
|
||||
<div id="enabled" style="float: left;">
|
||||
<input name="visible" type="radio" value="0"'.($this->reason!==null?($this->reason->visible==0?' checked="checked"': ''):'').' /> '.$this->l('Disabled').' <input name="visible" type="radio" value="1"'.($this->reason!==null?($this->reason->visible==1?' checked="checked"': ''):'checked="checked"').' /> '.$this->l('Enabled').'
|
||||
<sup> *</sup>
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
</div>';
|
||||
|
||||
echo '<br class="clear" />
|
||||
<div class="margin-form">
|
||||
<input type="hidden" name="id_reason" value="'.($this->reason !== null? $this->reason->id: '').'" />
|
||||
<input type="submit" class="button" '.($this->reason !== null ? 'disabled=disabled': '').' name="submitReasonAdd" value="'.$this->l('Add this reason').'" />
|
||||
<input type="submit" class="button'.($this->reason !== null? '': ' disable"').'" name="submitReasonUpdate" value="'.$this->l('Edit this reason').'"'.($this->reason !== null? '': ' disabled="disabled"').' id="submitReasonUpdate" />
|
||||
</div>';
|
||||
|
||||
echo '</fieldset>
|
||||
</form>';
|
||||
}
|
||||
|
||||
|
||||
public function displayList($token = null)
|
||||
{
|
||||
global $currentIndex, $cookie;
|
||||
|
||||
echo '<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/ant_support_form/ant_support_form.js"></script>
|
||||
<script type="text/javascript">
|
||||
i18n_delete = "'.$this->l('Are you sure you want to delete this?').'";
|
||||
current_location = "'.$currentIndex.'&token='.Tools::getAdminTokenLite('AdminReasons').'";
|
||||
</script>';
|
||||
echo '<style type="text/css">
|
||||
.green {
|
||||
background : #dffad3;
|
||||
}
|
||||
.red {
|
||||
background : #f29b9b;
|
||||
}
|
||||
.position {
|
||||
cursor:pointer;
|
||||
}
|
||||
</style>';
|
||||
|
||||
$reasons = Reason::getReasons();
|
||||
|
||||
echo '<fieldset class="space">
|
||||
<legend><img src="../img/admin/prefs.gif" alt="" title="" /> '.$this->l('Reason 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('Contact').'</th>
|
||||
<th>'.$this->l('Visible').'</th>
|
||||
<th style="width:70px;">'.$this->l('Actions').'</th>
|
||||
</tr>
|
||||
</thead>';
|
||||
echo ' <tbody id="sectionActive" class="sortable">';
|
||||
|
||||
if (isset($reasons)) {
|
||||
foreach ($reasons as $key => $reason) {
|
||||
echo '<tr id="item_'.$reason->id. '" class="reason_'.($key%2).'">
|
||||
<td>'.$reason->id.'</td>
|
||||
<td><strong>'.$reason->title[intval($cookie->id_lang)].'</strong></td>
|
||||
<th>'.$reason->contact[intval($cookie->id_lang)].'</th>
|
||||
<td><img src="../img/admin/'.($reason->visible?'enabled.gif':'disabled.gif').'"</td>
|
||||
<td>
|
||||
<img style="cursor: pointer;" onclick="reasonItemEdition('.$reason->id.')" title="Éditer cette reason" alt="" src="../img/admin/edit.gif">
|
||||
<img style="cursor: pointer;" onclick="reasonItemDeletion('.$reason->id.')" title="Supprimer cette reason" alt="" src="../img/admin/delete.gif">
|
||||
</td>
|
||||
</tr>
|
||||
';
|
||||
}
|
||||
}
|
||||
echo '</tbody>
|
||||
</table>
|
||||
</fieldset>';
|
||||
}
|
||||
|
||||
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 '<br /><br /><a href="'.__PS_BASE_URI__.substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__)).'?tab=AdminReasons&token='.$this->token.'"><img src="../img/admin/arrow2.gif" /> '.$this->l('Back to list').'</a><br />';
|
||||
}
|
||||
elseif (isset($_GET['deletereason']))
|
||||
{
|
||||
$this->deleteReason($this->token);
|
||||
}
|
||||
|
||||
echo '<a href="'.__PS_BASE_URI__.substr($_SERVER['PHP_SELF'], strlen(__PS_BASE_URI__)).'?tab=AdminReasons&addreason&token='.($token!=null ? $token : Tools::getAdminTokenLite('AdminReasons')).'"><img src="../img/admin/add.gif" border="0" /> '.$this->l('Add a new reason').'</a>';
|
||||
echo '<div style="margin:10px;">';
|
||||
$this->displayList($token);
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
184
modules/ant_support_form/Reason.php
Normal file
184
modules/ant_support_form/Reason.php
Normal file
@ -0,0 +1,184 @@
|
||||
<?php
|
||||
class Reason
|
||||
{
|
||||
public $id;
|
||||
public $id_reason;
|
||||
public $id_contact;
|
||||
public $visible;
|
||||
public $contact = array();
|
||||
public $title = array();
|
||||
public $versions = array();
|
||||
|
||||
public function __construct($id=NULL)
|
||||
{
|
||||
if($id !== NULL) {
|
||||
$reason = Reason::getReason($id);
|
||||
if($reason) {
|
||||
$this->id = $id;
|
||||
$this->id_reason = $reason['id_reason'];
|
||||
$this->id_contact = $reason['id_contact'];
|
||||
$this->visible = $reason['visible'];
|
||||
$this->contact = $reason['contact'];
|
||||
$this->title = $reason['title'];
|
||||
/*$this->versions = $reason['versions'];*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function getReason($id) {
|
||||
if(!($r = Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'support_reason`
|
||||
WHERE `id_reason` = '.(int) $id
|
||||
)) || count($r) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = array(
|
||||
'id_reason' => $r[0]['id_reason'],
|
||||
'id_contact' => $r[0]['id_contact'],
|
||||
'visible' => $r[0]['visible'],
|
||||
'title' => array(),
|
||||
);
|
||||
|
||||
$rl = Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'support_reason_lang`
|
||||
WHERE `id_reason` = '.(int) $id
|
||||
);
|
||||
foreach($rl as $l) {
|
||||
$result['title'][$l['id_lang']] = $l['title'];
|
||||
}
|
||||
|
||||
$cl = Db::getInstance()->ExecuteS('
|
||||
SELECT cl.`name`, cl.`id_lang`
|
||||
FROM `'._DB_PREFIX_.'contact_lang` cl
|
||||
LEFT JOIN `'._DB_PREFIX_.'support_reason` sr ON sr.`id_contact` = cl.`id_contact`
|
||||
WHERE sr.`id_reason` = '.(int) $id
|
||||
);
|
||||
|
||||
foreach($cl as $l) {
|
||||
$result['contact'][$l['id_lang']] = $l['name'];
|
||||
}
|
||||
|
||||
/*foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT `version`
|
||||
FROM `'._DB_PREFIX_.'support_reason_site_version`
|
||||
WHERE `id_reason` = '.(int) $id
|
||||
) as $version) {
|
||||
$result['versions'][] = $version['version'];
|
||||
}*/
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getReasons($where = array(), $lite=false, $order_by='`id_reason` ASC', $limit=null) {
|
||||
global $cookie;
|
||||
$result = array();
|
||||
|
||||
$query = '
|
||||
SELECT sr.`id_reason`
|
||||
FROM `'._DB_PREFIX_.'support_reason` sr
|
||||
';
|
||||
|
||||
!empty($where)? $query .= 'WHERE '.implode(' AND ', $where):$query;
|
||||
$query .= ' ORDER BY '.$order_by;
|
||||
|
||||
if($limit !== null) {
|
||||
$query .= ' LIMIT '.$limit;
|
||||
}
|
||||
if($reasons = Db::getInstance()->ExecuteS($query)) {
|
||||
if ($lite) {
|
||||
foreach($reasons AS $reason) {
|
||||
$result[] = $reason['id_reason'];
|
||||
}
|
||||
} else {
|
||||
foreach($reasons AS $reason) {
|
||||
$result[] = new Reason($reason['id_reason']);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function save() {
|
||||
if($this->id !== null) {
|
||||
Db::getInstance()->Execute('
|
||||
UPDATE `'._DB_PREFIX_.'support_reason` SET
|
||||
`id_contact` = '.(int) $this->id_contact.'
|
||||
`visible` = '.(int) $this->visible.'
|
||||
WHERE `id_reason` = '.(int) $this->id.'
|
||||
');
|
||||
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'support_reason_lang` WHERE `id_reason` = '.(int) $this->id);
|
||||
$reason_i18n = array();
|
||||
foreach($this->title as $k => $v) {
|
||||
if(!isset($reason_i18n[$k])) {
|
||||
$reason_i18n[$k] = array();
|
||||
}
|
||||
$reason_i18n[$k]['title'] = $v;
|
||||
}
|
||||
foreach($reason_i18n as $lang => $values) {
|
||||
Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'support_reason_lang` VALUES (
|
||||
'.$this->id.',
|
||||
'.$lang.',
|
||||
"'.(isset($values['title'])? pSQL($values['title']): '').'"
|
||||
)
|
||||
');
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'support_reason` VALUES (
|
||||
DEFAULT,
|
||||
'.(int) $this->id_contact.',
|
||||
'.(int) $this->visible.'
|
||||
)
|
||||
');
|
||||
$this->id = Db::getInstance()->Insert_ID();
|
||||
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'support_reason_lang` WHERE `id_reason` = '.(int) $this->id);
|
||||
$reason_i18n = array();
|
||||
foreach($this->title as $k => $v) {
|
||||
if(!isset($reason_i18n[$k])) {
|
||||
$reason_i18n[$k] = array();
|
||||
}
|
||||
$reason_i18n[$k]['title'] = $v;
|
||||
}
|
||||
foreach($reason_i18n as $lang => $values) {
|
||||
Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'support_reason_lang` VALUES (
|
||||
'.$this->id.',
|
||||
'.$lang.',
|
||||
"'.(isset($values['title'])? pSQL($values['title']): '').'"
|
||||
)
|
||||
');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function deleteReason($id) {
|
||||
if($reason = Reason::getReason($id)) {
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'support_reason_lang` WHERE `id_reason` = '.(int) $id);
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'support_reason` WHERE `id_reason` = '.(int) $id);
|
||||
}
|
||||
}
|
||||
|
||||
public function insertReasonCustomerThread($id_thread) {
|
||||
|
||||
if(!($result = Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'support_reason_customerthread`
|
||||
WHERE `id_customer_thread` = '.(int) $id_thread
|
||||
)) || count($result) == 0) {
|
||||
$insert = Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'support_reason_customerthread` VALUES (
|
||||
'.$this->id.',
|
||||
'.(int) $id_thread.'
|
||||
)
|
||||
');
|
||||
}
|
||||
}
|
||||
}
|
9
modules/ant_support_form/ant_support_form.js
Normal file
9
modules/ant_support_form/ant_support_form.js
Normal file
@ -0,0 +1,9 @@
|
||||
function reasonItemEdition(linkId) {
|
||||
document.location.href = current_location + "&updatereason&id=" + linkId;
|
||||
}
|
||||
function reasonItemDeletion(linkId) {
|
||||
var ok = confirm(i18n_delete)
|
||||
if(ok == true) {
|
||||
document.location.href = current_location + "&id=" + linkId + "&deletereason=1";
|
||||
}
|
||||
}
|
77
modules/ant_support_form/ant_support_form.php
Normal file
77
modules/ant_support_form/ant_support_form.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
class Ant_Support_Form extends Module
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->name = 'ant_support_form';
|
||||
$this->tab = 'administration';
|
||||
$this->author = 'Antadis';
|
||||
$this->version = '1.0';
|
||||
$this->need_instance = 0;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->displayName = $this->l('Cancellation and Problem forms');
|
||||
$this->description = $this->l('Adding forms for cancellations and problemes, adding reasons for cancellation');
|
||||
}
|
||||
|
||||
public function install()
|
||||
{
|
||||
|
||||
$query = '
|
||||
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'support_reason` (
|
||||
`id_reason` INTEGER NOT NULL AUTO_INCREMENT,
|
||||
`id_contact` INTEGER NOT NULL,
|
||||
`visible` BOOL NOT NULL,
|
||||
PRIMARY KEY(`id_reason`)
|
||||
) ENGINE=MyIsam DEFAULT CHARSET=utf8
|
||||
';
|
||||
if(!Db::getInstance()->Execute($query)) {
|
||||
return false;
|
||||
}
|
||||
$query = '
|
||||
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'support_reason_lang` (
|
||||
`id_reason` INTEGER NOT NULL,
|
||||
`id_lang` INTEGER NOT NULL,
|
||||
`title` VARCHAR(255) NOT NULL,
|
||||
PRIMARY KEY(`id_reason`, `id_lang`)
|
||||
) ENGINE=MyIsam DEFAULT CHARSET=utf8
|
||||
';
|
||||
if(!Db::getInstance()->Execute($query)) {
|
||||
return false;
|
||||
}
|
||||
$query = '
|
||||
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'support_reason_customerthread` (
|
||||
`id_reason` INTEGER NOT NULL,
|
||||
`id_customer_thread` INTEGER NOT NULL,
|
||||
PRIMARY KEY(`id_reason`, `id_customer_thread`)
|
||||
) ENGINE=MyIsam DEFAULT CHARSET=utf8
|
||||
';
|
||||
if(!Db::getInstance()->Execute($query)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!(parent::install())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function uninstall() {
|
||||
|
||||
if(parent::uninstall() == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'support_reason`');
|
||||
Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'support_reason_lang`');
|
||||
Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'support_reason_customerthread`');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
BIN
modules/ant_support_form/logo.gif
Normal file
BIN
modules/ant_support_form/logo.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
BIN
modules/ant_support_form/prefs.gif
Normal file
BIN
modules/ant_support_form/prefs.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 351 B |
5
modules/ant_support_form/support.css
Normal file
5
modules/ant_support_form/support.css
Normal file
@ -0,0 +1,5 @@
|
||||
#module-ant_support_form-support #center_column textarea{
|
||||
height: 150px;
|
||||
padding: 5px;
|
||||
width: 748px;
|
||||
}
|
0
modules/ant_support_form/support.js
Normal file
0
modules/ant_support_form/support.js
Normal file
287
modules/ant_support_form/support.php
Normal file
287
modules/ant_support_form/support.php
Normal file
@ -0,0 +1,287 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__).'/../../config/config.inc.php');
|
||||
require_once(dirname(__FILE__).'/../../init.php');
|
||||
require_once(dirname(__FILE__).'/Reason.php');
|
||||
$controller->preProcess();
|
||||
|
||||
$langs = Language::getLanguages();
|
||||
$lang = (int) $cookie->id_lang;
|
||||
$isolang = Language::getIsoById($lang);
|
||||
$errors = array();
|
||||
if ($cookie->isLogged()) {
|
||||
|
||||
$smarty->assign('isLogged', 1);
|
||||
$customer = new Customer((int)($cookie->id_customer));
|
||||
if (!Validate::isLoadedObject($customer)) {
|
||||
die(Tools::displayError('Customer not found'));
|
||||
}
|
||||
$products = array();
|
||||
$orders = array();
|
||||
$getOrders = Db::getInstance()->ExecuteS('
|
||||
SELECT id_order
|
||||
FROM '._DB_PREFIX_.'orders
|
||||
WHERE id_customer = '.(int)$customer->id.' ORDER BY date_add
|
||||
');
|
||||
foreach ($getOrders as $row) {
|
||||
$order = new Order($row['id_order']);
|
||||
$date = explode(' ', $order->date_add);
|
||||
$orders[$row['id_order']] = Tools::displayDate($date[0], $cookie->id_lang);
|
||||
$tmp = $order->getProducts();
|
||||
foreach ($tmp as $key => $val)
|
||||
$products[$val['product_id']] = $val['product_name'];
|
||||
}
|
||||
|
||||
$orderList = '';
|
||||
foreach ($orders as $key => $val) {
|
||||
$orderList .= '<option value="'.$key.'" '.((int)(Tools::getValue('id_order')) == $key ? 'selected' : '').' >'.$key.' -- '.$val.'</option>';
|
||||
}
|
||||
$orderedProductList = '';
|
||||
|
||||
foreach ($products as $key => $val) {
|
||||
$orderedProductList .= '<option value="'.$key.'" '.((int)(Tools::getValue('id_product')) == $key ? 'selected' : '').' >'.$val.'</option>';
|
||||
}
|
||||
$smarty->assign('orderList', $orderList);
|
||||
$smarty->assign('orderedProductList', $orderedProductList);
|
||||
}
|
||||
|
||||
if (Tools::isSubmit('submitMessage')) {
|
||||
$fileAttachment = NULL;
|
||||
if (isset($_FILES['fileUpload']['name']) AND !empty($_FILES['fileUpload']['name']) AND !empty($_FILES['fileUpload']['tmp_name']))
|
||||
{
|
||||
$extension = array('.txt', '.rtf', '.doc', '.docx', '.pdf', '.zip', '.png', '.jpeg', '.gif', '.jpg');
|
||||
$filename = uniqid().substr($_FILES['fileUpload']['name'], -5);
|
||||
$fileAttachment['content'] = file_get_contents($_FILES['fileUpload']['tmp_name']);
|
||||
$fileAttachment['name'] = $_FILES['fileUpload']['name'];
|
||||
$fileAttachment['mime'] = $_FILES['fileUpload']['type'];
|
||||
}
|
||||
$message = Tools::htmlentitiesUTF8(Tools::getValue('message'));
|
||||
if (!($from = trim(Tools::getValue('from'))) OR !Validate::isEmail($from))
|
||||
$errors[] = Tools::displayError('Invalid e-mail address');
|
||||
elseif (!($message = nl2br2($message)))
|
||||
$errors[] = Tools::displayError('Message cannot be blank');
|
||||
elseif (!Validate::isCleanHtml($message))
|
||||
$errors[] = Tools::displayError('Invalid message');
|
||||
elseif (!($id_contact = (int)(Tools::getValue('id_contact'))) OR !(Validate::isLoadedObject($contact = new Contact((int)($id_contact), (int)($cookie->id_lang)))))
|
||||
$errors[] = Tools::displayError('Please select a subject on the list.');
|
||||
elseif (($id_contact = (int)(Tools::getValue('id_contact'))) && $id_contact == 9 && !Tools::getValue('id_reason'))
|
||||
$errors[] = Tools::displayError('Please select a reason on the list.');
|
||||
elseif (($id_contact = (int)(Tools::getValue('id_contact'))) && ($id_contact == 9 || $id_contact == 1) && !Tools::getValue('id_order'))
|
||||
$errors[] = Tools::displayError('Please enter/choose an order ID');
|
||||
elseif (($id_contact = (int)(Tools::getValue('id_contact'))) && $id_contact == 1 && !Tools::getValue('id_product'))
|
||||
$errors[] = Tools::displayError('Please choose a product');
|
||||
elseif (!empty($_FILES['fileUpload']['name']) AND $_FILES['fileUpload']['error'] != 0)
|
||||
$errors[] = Tools::displayError('An error occurred during the file upload');
|
||||
elseif (!empty($_FILES['fileUpload']['name']) AND !in_array(substr($_FILES['fileUpload']['name'], -4), $extension) AND !in_array(substr($_FILES['fileUpload']['name'], -5), $extension))
|
||||
$errors[] = Tools::displayError('Bad file extension');
|
||||
else
|
||||
{
|
||||
if ((int)($cookie->id_customer))
|
||||
$customer = new Customer((int)($cookie->id_customer));
|
||||
else
|
||||
{
|
||||
$customer = new Customer();
|
||||
$customer->getByEmail($from);
|
||||
}
|
||||
|
||||
$contact = new Contact($id_contact, $cookie->id_lang);
|
||||
|
||||
if (!((
|
||||
$id_customer_thread = (int)Tools::getValue('id_customer_thread')
|
||||
AND (int)Db::getInstance()->getValue('
|
||||
SELECT cm.id_customer_thread FROM '._DB_PREFIX_.'customer_thread cm
|
||||
WHERE cm.id_customer_thread = '.(int)$id_customer_thread.' AND token = \''.pSQL(Tools::getValue('token')).'\'')
|
||||
) OR (
|
||||
$id_customer_thread = (int)Db::getInstance()->getValue('
|
||||
SELECT cm.id_customer_thread FROM '._DB_PREFIX_.'customer_thread cm
|
||||
WHERE cm.email = \''.pSQL($from).'\' AND cm.id_order = '.(int)(Tools::getValue('id_order')).'')
|
||||
)))
|
||||
{
|
||||
$fields = Db::getInstance()->ExecuteS('
|
||||
SELECT cm.id_customer_thread, cm.id_contact, cm.id_customer, cm.id_order, cm.id_product, cm.email
|
||||
FROM '._DB_PREFIX_.'customer_thread cm
|
||||
WHERE email = \''.pSQL($from).'\' AND ('.
|
||||
($customer->id ? 'id_customer = '.(int)($customer->id).' OR ' : '').'
|
||||
id_order = '.(int)(Tools::getValue('id_order')).')');
|
||||
$score = 0;
|
||||
foreach ($fields as $key => $row)
|
||||
{
|
||||
$tmp = 0;
|
||||
if ((int)$row['id_customer'] AND $row['id_customer'] != $customer->id AND $row['email'] != $from)
|
||||
continue;
|
||||
if ($row['id_order'] != 0 AND Tools::getValue('id_order') != $row['id_order'])
|
||||
continue;
|
||||
if ($row['email'] == $from)
|
||||
$tmp += 4;
|
||||
if ($row['id_contact'] == $id_contact)
|
||||
$tmp++;
|
||||
if (Tools::getValue('id_product') != 0 AND $row['id_product'] == Tools::getValue('id_product'))
|
||||
$tmp += 2;
|
||||
if ($tmp >= 5 AND $tmp >= $score)
|
||||
{
|
||||
$score = $tmp;
|
||||
$id_customer_thread = $row['id_customer_thread'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$old_message = Db::getInstance()->getValue('
|
||||
SELECT cm.message FROM '._DB_PREFIX_.'customer_message cm
|
||||
WHERE cm.id_customer_thread = '.(int)($id_customer_thread).'
|
||||
ORDER BY date_add DESC');
|
||||
if ($old_message == htmlentities($message, ENT_COMPAT, 'UTF-8'))
|
||||
{
|
||||
$smarty->assign('alreadySent', 1);
|
||||
$contact->email = '';
|
||||
$contact->customer_service = 0;
|
||||
}
|
||||
if (!empty($contact->email))
|
||||
{
|
||||
/*if (Mail::Send((int)($cookie->id_lang), 'contact_form', Mail::l('Your message has been correctly sent'), array('{message}' => stripslashes($message)), $from)) {
|
||||
$smarty->assign('confirmation', 1);
|
||||
}
|
||||
else
|
||||
$errors[] = Tools::displayError('An error occurred while sending message.');*/
|
||||
// local
|
||||
$smarty->assign('confirmation', 1);
|
||||
}
|
||||
|
||||
if ($contact->customer_service)
|
||||
{
|
||||
if ((int)$id_customer_thread)
|
||||
{
|
||||
$ct = new CustomerThread($id_customer_thread);
|
||||
$ct->status = 'open';
|
||||
$ct->id_lang = (int)$cookie->id_lang;
|
||||
$ct->id_contact = (int)($id_contact);
|
||||
if ($id_order = (int)Tools::getValue('id_order'))
|
||||
$ct->id_order = $id_order;
|
||||
if ($id_product = (int)Tools::getValue('id_product'))
|
||||
$ct->id_product = $id_product;
|
||||
$ct->update();
|
||||
}
|
||||
else
|
||||
{
|
||||
$ct = new CustomerThread();
|
||||
if (isset($customer->id))
|
||||
$ct->id_customer = (int)($customer->id);
|
||||
if ($id_order = (int)Tools::getValue('id_order'))
|
||||
$ct->id_order = $id_order;
|
||||
if ($id_product = (int)Tools::getValue('id_product'))
|
||||
$ct->id_product = $id_product;
|
||||
$ct->id_contact = (int)($id_contact);
|
||||
$ct->id_lang = (int)$cookie->id_lang;
|
||||
$ct->email = $from;
|
||||
$ct->status = 'open';
|
||||
$ct->token = Tools::passwdGen(12);
|
||||
$ct->add();
|
||||
}
|
||||
|
||||
if ($ct->id)
|
||||
{
|
||||
// adding (antadis) - linking reason and customer_thread
|
||||
if (Tools::getValue('id_reason')) {
|
||||
$id_reason = (int) Tools::getValue('id_reason');
|
||||
$reason = new Reason($id_reason);
|
||||
if ($reason->id !== null) {
|
||||
$reason->insertReasonCustomerThread((int) $ct->id);
|
||||
}
|
||||
}
|
||||
|
||||
$cm = new CustomerMessage();
|
||||
$cm->id_customer_thread = $ct->id;
|
||||
$cm->message = htmlentities($message, ENT_COMPAT, 'UTF-8');
|
||||
if (isset($filename) AND rename($_FILES['fileUpload']['tmp_name'], _PS_MODULE_DIR_.'../upload/'.$filename))
|
||||
$cm->file_name = $filename;
|
||||
$cm->ip_address = ip2long($_SERVER['REMOTE_ADDR']);
|
||||
$cm->user_agent = $_SERVER['HTTP_USER_AGENT'];
|
||||
if ($cm->add())
|
||||
{
|
||||
/*if (empty($contact->email)) {
|
||||
Mail::Send((int)($cookie->id_lang), 'contact_form', Mail::l('Your message has been correctly sent'), array('{message}' => stripslashes($message)), $from);
|
||||
}*/
|
||||
$smarty->assign('confirmation', 1);
|
||||
}
|
||||
else
|
||||
$errors[] = Tools::displayError('An error occurred while sending message.');
|
||||
}
|
||||
else
|
||||
$errors[] = Tools::displayError('An error occurred while sending message.');
|
||||
}
|
||||
if (count($errors) > 1)
|
||||
array_unique($errors);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$email = Tools::safeOutput(Tools::getValue('from', ((isset($cookie) AND isset($cookie->email) AND Validate::isEmail($cookie->email)) ? $cookie->email : '')));
|
||||
$smarty->assign(array(
|
||||
'errors' => $errors,
|
||||
'message' => html_entity_decode(Tools::getValue('message')),
|
||||
'contacts' => Contact::getContacts((int)($cookie->id_lang)),
|
||||
'email' => $email,
|
||||
'fileupload' => Configuration::get('PS_CUSTOMER_SERVICE_FILE_UPLOAD')
|
||||
));
|
||||
|
||||
if ($id_customer_thread = (int)Tools::getValue('id_customer_thread') AND $token = Tools::getValue('token')) {
|
||||
$customerThread = Db::getInstance()->getRow('
|
||||
SELECT cm.* FROM '._DB_PREFIX_.'customer_thread cm
|
||||
WHERE cm.id_customer_thread = '.(int)$id_customer_thread.' AND token = \''.pSQL($token).'\'');
|
||||
$smarty->assign('customerThread', $customerThread);
|
||||
}
|
||||
|
||||
if (isset($_GET['id_contact']) && is_numeric($_GET['id_contact'])) {
|
||||
$id_contact = $_GET['id_contact'];
|
||||
$contact = new Contact((int) $id_contact, $lang);
|
||||
if (Validate::isLoadedObject($contact)) {
|
||||
// A changer selon id_contact
|
||||
switch ($id_contact) {
|
||||
case '1':
|
||||
$allow_product = true;
|
||||
$allow_order = true;
|
||||
break;
|
||||
case '9':
|
||||
$allow_order = true;
|
||||
$allow_product = false;
|
||||
break;
|
||||
default:
|
||||
$allow_product = false;
|
||||
$allow_order = false;
|
||||
break;
|
||||
}
|
||||
$smarty->assign(array(
|
||||
'id_contact' => $id_contact,
|
||||
'allow_product' => $allow_product,
|
||||
'allow_order' => $allow_order,
|
||||
'subject' => $contact->name
|
||||
));
|
||||
|
||||
if (isset($_GET['id_reason']) && is_numeric($_GET['id_reason'])) {
|
||||
$smarty->assign('id_reason', $_GET['id_reason']);
|
||||
} else {
|
||||
$reasons = Reason::getReasons(array('id_contact = '.(int)$id_contact));
|
||||
foreach ($reasons as $key => &$reason) {
|
||||
if (!$reason->visible) {
|
||||
unset($reasons[$key]);
|
||||
}
|
||||
}
|
||||
$smarty->assign('reasons', $reasons);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/*$reasons = Reason::getReasons();
|
||||
foreach ($reasons as $key => &$reason) {
|
||||
if (!$reason->visible) {
|
||||
unset($reasons[$key]);
|
||||
}
|
||||
}
|
||||
$smarty->assign('reasons', $reasons);*/
|
||||
}
|
||||
|
||||
$_POST = array_merge($_POST, $_GET);
|
||||
|
||||
require_once(dirname(__FILE__).'/../../header.php');
|
||||
|
||||
echo Module::display(dirname(__FILE__), 'support.tpl');
|
||||
|
||||
require_once(dirname(__FILE__).'/../../footer.php');
|
||||
|
||||
|
143
modules/ant_support_form/support.tpl
Normal file
143
modules/ant_support_form/support.tpl
Normal file
@ -0,0 +1,143 @@
|
||||
<link media="all" type="text/css" rel="stylesheet" href="{$base_dir_ssl}modules/ant_support_form/support.css">
|
||||
|
||||
{capture name=path}{l s='Contact' mod='ant_support_form'}{/capture}
|
||||
{include file="$tpl_dir./breadcrumb.tpl"}
|
||||
|
||||
<h1>{l s='Customer Service' mod='ant_support_form'} - {if isset($customerThread) && $customerThread}{l s='Your reply' mod='ant_support_form'}{elseif isset($subject)}{$subject}{else}{l s='Contact us' mod='ant_support_form'}{/if}</h1>
|
||||
|
||||
{if isset($confirmation)}
|
||||
<p class="success">{l s='Your message has been successfully sent to our team.' mod='ant_support_form'}</p>
|
||||
<p class="footer_links">
|
||||
<a href="{$base_dir}" class="button">{l s='Home' mod='ant_support_form'}</a>
|
||||
</p>
|
||||
{elseif isset($alreadySent)}
|
||||
<p class="notification">{l s='Your message has already been sent.' mod='ant_support_form'}</p>
|
||||
<p class="footer_links">
|
||||
<a href="{$base_dir}" class="button">{l s='Home' mod='ant_support_form'}</a>
|
||||
</p>
|
||||
{else}
|
||||
<p class="bold">{l s='For questions about an order or for more information about our products' mod='ant_support_form'}.</p>
|
||||
{include file="$tpl_dir./errors.tpl"}
|
||||
<form action="{$request_uri|escape:'htmlall':'UTF-8'}" method="post" class="std" enctype="multipart/form-data">
|
||||
<fieldset>
|
||||
<div class="content">
|
||||
<p class="text">
|
||||
<label for="email">{l s='E-mail address' mod='ant_support_form'}</label>
|
||||
{if isset($customerThread.email)}
|
||||
<input type="text" id="email" name="from" value="{$customerThread.email}" readonly="readonly" />
|
||||
{else}
|
||||
<input type="text" id="email" name="from" value="{$email}" />
|
||||
{/if}
|
||||
</p>
|
||||
{if !$PS_CATALOG_MODE}
|
||||
{if (!isset($customerThread.id_order) || $customerThread.id_order > 0) && (isset($allow_order) && $allow_order)}
|
||||
{if !isset($customerThread.id_order) && isset($isLogged) && $isLogged == 1 && !empty($orderList)}
|
||||
<p class="text">
|
||||
<label for="id_order">{l s='Order ID' mod='ant_support_form'}</label>
|
||||
<select name="id_order" ><option value="0">{l s='-- Choose --' mod='ant_support_form'}</option>{$orderList}</select>
|
||||
{elseif !isset($customerThread.id_order) && !isset($isLogged)}
|
||||
<p class="text">
|
||||
<label for="id_order">{l s='Order ID' mod='ant_support_form'}</label>
|
||||
<input type="text" name="id_order" id="id_order" value="{if isset($customerThread.id_order) && $customerThread.id_order > 0}{$customerThread.id_order|intval}{else}{if isset($smarty.post.id_order)}{$smarty.post.id_order|intval}{/if}{/if}" />
|
||||
{elseif $customerThread.id_order > 0}
|
||||
<p class="text">
|
||||
<label for="id_order">{l s='Order ID' mod='ant_support_form'}</label>
|
||||
<input type="text" name="id_order" id="id_order" value="{$customerThread.id_order|intval}" readonly="readonly" />
|
||||
{else}
|
||||
<p class="text error cant-submit">
|
||||
{l s='You don\'t have any order' mod='ant_support_form'} - <a href="{$base_dir}" class="button">{l s='Home' mod='ant_support_form'}</a>
|
||||
{/if}
|
||||
</p>
|
||||
{/if}
|
||||
{if isset($isLogged) && $isLogged && isset($allow_product) && $allow_product}
|
||||
{if !isset($customerThread.id_product) && !empty($orderedProductList)}
|
||||
<p class="text">
|
||||
<label for="id_product">{l s='Product' mod='ant_support_form'}</label>
|
||||
<select name="id_product" style="width:300px;"><option value="0">{l s='-- Choose --'}</option>{$orderedProductList}</select>
|
||||
</p>
|
||||
{elseif $customerThread.id_product > 0}
|
||||
<p class="text">
|
||||
<label for="id_product">{l s='Product' mod='ant_support_form'}</label>
|
||||
<input type="text" name="id_product" id="id_product" value="{$customerThread.id_product|intval}" readonly="readonly" />
|
||||
</p>
|
||||
{else}
|
||||
<p class="text error cant-submit">
|
||||
{l s='You have not yet ordered products from us' mod='ant_support_form'} - <a href="{$base_dir}" class="button">{l s='Home' mod='ant_support_form'}</a>
|
||||
</p>
|
||||
{/if}
|
||||
{/if}
|
||||
{/if}
|
||||
<p class="select" style="display: none;">
|
||||
<label for="id_contact">{l s='Subject Heading' mod='ant_support_form'}</label>
|
||||
{if isset($customerThread.id_contact)}
|
||||
{foreach from=$contacts item=contact}
|
||||
{if $contact.id_contact == $customerThread.id_contact}
|
||||
<input type="text" id="contact_name" name="contact_name" value="{$contact.name|escape:'htmlall':'UTF-8'}" readonly="readonly" />
|
||||
<input type="hidden" name="id_contact" value="{$contact.id_contact}" />
|
||||
{/if}
|
||||
{/foreach}
|
||||
</p>
|
||||
{else}
|
||||
<select id="id_contact" name="id_contact" onchange="showElemFromSelect('id_contact', 'desc_contact')">
|
||||
<option value="0">{l s='-- Choose --' mod='ant_support_form'}</option>
|
||||
{foreach from=$contacts item=contact}
|
||||
<option value="{$contact.id_contact|intval}" {if isset($smarty.post.id_contact) && $smarty.post.id_contact == $contact.id_contact}selected="selected"{/if}>{$contact.name|escape:'htmlall':'UTF-8'}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</p>
|
||||
{/if}
|
||||
{*{if $fileupload == 1}
|
||||
<p class="text">
|
||||
<label for="fileUpload">{l s='Attach File' mod='ant_support_form'}</label>
|
||||
<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
|
||||
<input type="file" name="fileUpload" id="fileUpload" />
|
||||
</p>
|
||||
{/if}*}
|
||||
{if isset($reasons) && !empty($reasons)}
|
||||
<p class="select">
|
||||
<label for="id_reason">{l s='Reason' mod='ant_support_form'}</label>
|
||||
<select id="id_reason" name="id_reason">
|
||||
<option value="0">{l s='-- Choose --' mod='ant_support_form'}</option>
|
||||
{foreach from=$reasons item=reason}
|
||||
{if $reason->visible}
|
||||
<option data-contact="{$reason->id_contact}" value="{$reason->id_reason}" {if isset($smarty.post.id_reason) && $smarty.post.id_reason == $reason->id_reason}selected="selected"{/if}>{$reason->title[$cookie->id_lang]}</option>
|
||||
{/if}
|
||||
{/foreach}
|
||||
</select>
|
||||
</p>
|
||||
{elseif isset($id_reason)}
|
||||
<input type="hidden" name='id_reason' value="{$id_reason}">
|
||||
{/if}
|
||||
<p class="textarea">
|
||||
<label for="message">{l s='Message' mod='ant_support_form'}</label>
|
||||
<textarea id="message" name="message">{if isset($message)}{$message|escape:'htmlall':'UTF-8'|stripslashes}{/if}</textarea>
|
||||
</p>
|
||||
<p class="submit">
|
||||
<input type="submit" name="submitMessage" id="submitMessage" value="{l s='Send' mod='ant_support_form'}" class="button_large" onclick="$(this).hide();" />
|
||||
</p>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
{literal}
|
||||
<script>
|
||||
$(function() {
|
||||
if($('.cant-submit').length>0) {
|
||||
$('#submitMessage').hide();
|
||||
}
|
||||
$('#id_reason option[data-contact!="'+ $("option:selected", $('#id_contact')).val()+'"]').each(function(index, el) {
|
||||
$(this).hide();
|
||||
});
|
||||
$('#id_contact').change(function() {
|
||||
$('#id_reason option[value!="0"]').each(function(index, el) {
|
||||
if ($(this).data('contact') != $("option:selected", $('#id_contact')).val()) {
|
||||
$(this).hide();
|
||||
} else {
|
||||
$(this).show();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{/literal}
|
||||
{/if}
|
@ -373,7 +373,7 @@ class FrontController extends FrontControllerCore {
|
||||
'module-referralprogram-referral-program', 'module-cheque-payment',
|
||||
'module-bankwire-payment', 'module-invite-invite-rules',
|
||||
'module-advsendtoafriend-sendtoafriend-form', 'featured',
|
||||
'list-tag-sales',
|
||||
'list-tag-sales','module-ant_support-help','module-ant_support_form-support',
|
||||
);
|
||||
|
||||
$displayRight = array(
|
||||
|
@ -5604,6 +5604,32 @@ div#giftvoucher_ask_infos_block .gv_customization > .gv_param input {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/** Module ant_support_form **/
|
||||
#module-ant_support_form-support #center_column p.submit {
|
||||
text-align: right;
|
||||
}
|
||||
#module-ant_support_form-support #center_column textarea{
|
||||
height: 150px;
|
||||
padding: 5px;
|
||||
width: 748px;
|
||||
}
|
||||
#module-ant_support_form-support #center_column p.submit .button_large {
|
||||
text-align: center;
|
||||
text-transform: none;
|
||||
border: 0px;
|
||||
color: #FFF;
|
||||
font-size: 12px;
|
||||
padding: 8px 40px 8px 20px;
|
||||
text-decoration: none;
|
||||
font-weight: normal;
|
||||
background: #504d8b url("../img/arrow.png") right 9px no-repeat;
|
||||
-moz-border-radius: 20px;
|
||||
-webkit-border-radius: 20px;
|
||||
border-radius: 20px;
|
||||
font-family: georgia, times new roman, serif;
|
||||
font-style: italic;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
@keyframes slideInDown {
|
||||
0% {
|
||||
|
Loading…
Reference in New Issue
Block a user