226 lines
9.3 KiB
PHP
Raw Normal View History

<?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').'&nbsp;&nbsp;&nbsp;<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);
}
}
}