231 lines
10 KiB
PHP
231 lines
10 KiB
PHP
<?php
|
|
if(!defined('_PS_VERSION_')) {
|
|
exit;
|
|
}
|
|
/*include_once(_PS_ROOT_DIR_.'/modules/ant_support/Section.php');
|
|
include_once(_PS_ROOT_DIR_.'/modules/ant_support/Question.php');
|
|
include_once(_PS_ROOT_DIR_.'/modules/ant_support/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);
|
|
}
|
|
}
|
|
|
|
}
|