228 lines
8.6 KiB
PHP
228 lines
8.6 KiB
PHP
|
<?php
|
||
|
include_once(_PS_ROOT_DIR_.'/modules/privatesales/Sale.php');
|
||
|
|
||
|
class AdminPrivateSalesDelay extends AdminTab
|
||
|
{
|
||
|
private $imagelist;
|
||
|
|
||
|
public function __construct()
|
||
|
{
|
||
|
$this->lang = TRUE;
|
||
|
parent::__construct();
|
||
|
}
|
||
|
|
||
|
public function displayForm($isMainTab=TRUE)
|
||
|
{
|
||
|
global $currentIndex, $cookie;
|
||
|
parent::displayForm();
|
||
|
|
||
|
$iso = Language::getIsoById((int)($cookie->id_lang));
|
||
|
$divLangName = 'name¤short_name¤value¤value_max';
|
||
|
|
||
|
echo '<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/privatesales_delay/privatesale.js"></script>
|
||
|
<script type="text/javascript">
|
||
|
i18n_delete = "'.$this->l('Are you sure you want to delete this delay?').'";
|
||
|
current_location = "'.$currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesDelay').'";
|
||
|
</script>
|
||
|
<form action="'.$currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesDelay').'" method="post" enctype="multipart/form-data">
|
||
|
<fieldset>
|
||
|
<legend><img src="../img/admin/cms.gif" alt="" title="" /> '.$this->l('Edit a delay').'</legend>';
|
||
|
|
||
|
echo '<label>'.$this->l('Name:').'</label>
|
||
|
<div class="margin-form">';
|
||
|
foreach($this->_languages as $language) {
|
||
|
echo '<div id="name_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
|
||
|
<input type="text" style="width: 500px;" name="name_'.$language['id_lang'].'" value="'.($this->curdelay !== NULL? $this->curdelay['name'][$language['id_lang']]: '').'" />
|
||
|
</div>';
|
||
|
}
|
||
|
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'name');
|
||
|
echo '<div class="clear"></div>
|
||
|
</div>';
|
||
|
|
||
|
echo '<label>'.$this->l('Short name:').'</label>
|
||
|
<div class="margin-form">';
|
||
|
foreach($this->_languages as $language) {
|
||
|
echo '<div id="short_name_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
|
||
|
<input type="text" style="width: 500px;" name="short_name_'.$language['id_lang'].'" value="'.($this->curdelay !== NULL? $this->curdelay['short_name'][$language['id_lang']]: '').'" />
|
||
|
</div>';
|
||
|
}
|
||
|
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'short_name');
|
||
|
echo '<div class="clear"></div>
|
||
|
</div>';
|
||
|
|
||
|
echo '<label>'.$this->l('Value (days):').'</label>
|
||
|
<div class="margin-form">';
|
||
|
foreach($this->_languages as $language) {
|
||
|
echo '<div id="value_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
|
||
|
<input type="text" style="width: 500px;" name="value_'.$language['id_lang'].'" value="'.($this->curdelay !== NULL? $this->curdelay['value'][$language['id_lang']]: '').'" />
|
||
|
</div>';
|
||
|
}
|
||
|
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'value');
|
||
|
echo '<div class="clear"></div>
|
||
|
</div>';
|
||
|
|
||
|
echo '<label>'.$this->l('Value max (days):').'</label>
|
||
|
<div class="margin-form">';
|
||
|
foreach($this->_languages as $language) {
|
||
|
echo '<div id="value_max_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
|
||
|
<input type="text" style="width: 500px;" name="value_max_'.$language['id_lang'].'" value="'.($this->curdelay !== NULL? $this->curdelay['value_max'][$language['id_lang']]: '').'" />
|
||
|
</div>';
|
||
|
}
|
||
|
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'value_max');
|
||
|
echo '<div class="clear"></div>
|
||
|
</div>';
|
||
|
|
||
|
|
||
|
echo '<p>* Jours ouvrés</p>';
|
||
|
echo '<br class="clear" />
|
||
|
<div class="margin-form">
|
||
|
<input type="hidden" name="id_delay" value="'.($this->curdelay !== NULL? $this->curdelay['id']: '').'" />
|
||
|
<input type="submit" class="button" name="submitDelayAdd" value="'.$this->l('Add this delay').'" />
|
||
|
<input type="submit" class="button'.($this->curdelay !== NULL? '': ' disable"').'" name="submitDelayUpdate" value="'.$this->l('Edit this delay').'"'.($this->curdelay !== NULL? '': ' disabled="disabled"').' id="submitDelayUpdate" />
|
||
|
</div>';
|
||
|
|
||
|
echo '</fieldset>
|
||
|
</form>';
|
||
|
}
|
||
|
|
||
|
public function display()
|
||
|
{
|
||
|
global $cookie, $currentIndex;
|
||
|
$this->curdelay = null;
|
||
|
if($id = Tools::getValue('id')) {
|
||
|
$delay = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'privatesale_delay_lang` WHERE `id_delay` = '.(int) $id);
|
||
|
if(count($delay) > 0) {
|
||
|
$this->curdelay = array('id' => $id, 'name' => array());
|
||
|
foreach($delay as $t) {
|
||
|
$this->curdelay['name'][$t['id_lang']] = $t['name'];
|
||
|
$this->curdelay['short_name'][$t['id_lang']] = $t['short_name'];
|
||
|
$this->curdelay['value'][$t['id_lang']] = $t['value'];
|
||
|
$this->curdelay['value_max'][$t['id_lang']] = $t['value_max'];
|
||
|
}
|
||
|
} else {
|
||
|
Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesDelay'));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$this->displayForm();
|
||
|
|
||
|
echo '<fieldset class="space">
|
||
|
<legend><img src="'.__PS_BASE_URI__.'modules/privatesales/prefs.gif" alt="" title="" /> '.$this->l('Delays list').'</legend>
|
||
|
<table class="table" style="width: 100%;">
|
||
|
<tr>
|
||
|
<th>'.$this->l('ID').'</th>
|
||
|
<th>'.$this->l('Name').'</th>
|
||
|
<th>'.$this->l('Short name').'</th>
|
||
|
<th>'.$this->l('Value').'</th>
|
||
|
<th>'.$this->l('Value Max').'</th>
|
||
|
<th style="width: 55px;">'.$this->l('Actions').'</th>
|
||
|
</tr>';
|
||
|
foreach(Db::getInstance()->ExecuteS('
|
||
|
SELECT *
|
||
|
FROM `'._DB_PREFIX_.'privatesale_delay_lang`
|
||
|
WHERE `id_lang` = '.(int) $cookie->id_lang.'
|
||
|
ORDER BY `id_delay` ASC
|
||
|
') as $delay) {
|
||
|
echo '<tr>
|
||
|
<td>'.$delay['id_delay'].'</td>
|
||
|
<td>'.$delay['name'].'</td>
|
||
|
<td>'.$delay['short_name'].'</td>
|
||
|
<td>'.$delay['value'].'</td>
|
||
|
<td>'.$delay['value_max'].'</td>
|
||
|
<td>
|
||
|
<img style="cursor: pointer;" onclick="itemEdition('.$delay['id_delay'].')" title="Éditer ce délai" alt="" src="../img/admin/edit.gif">
|
||
|
<img style="cursor: pointer;" onclick="itemDeletion('.$delay['id_delay'].')" title="Supprimer ce délai" alt="" src="../img/admin/delete.gif">
|
||
|
</td>
|
||
|
</tr>';
|
||
|
}
|
||
|
echo '</table>
|
||
|
</fieldset>
|
||
|
';
|
||
|
}
|
||
|
|
||
|
function postProcess()
|
||
|
{
|
||
|
global $cookie, $currentIndex;
|
||
|
|
||
|
if(Tools::isSubmit('submitDelayAdd')) {
|
||
|
Db::getInstance()->Execute('
|
||
|
INSERT INTO `'._DB_PREFIX_.'privatesale_delay` VALUES (
|
||
|
DEFAULT
|
||
|
)
|
||
|
');
|
||
|
$id_delay = Db::getInstance()->Insert_ID();
|
||
|
foreach(Language::getLanguages(FALSE) as $language) {
|
||
|
if($name = Tools::getValue('name_'.$language['id_lang'])) {
|
||
|
Db::getInstance()->Execute('
|
||
|
INSERT INTO `'._DB_PREFIX_.'privatesale_delay_lang` VALUES (
|
||
|
'.$id_delay.',
|
||
|
'.$language['id_lang'].',
|
||
|
"'.pSQL($name).'",
|
||
|
"'.pSQL(Tools::getValue('short_name_'.$language['id_lang'])).'",
|
||
|
'.(int) Tools::getValue('value_'.$language['id_lang']).',
|
||
|
'.(int) Tools::getValue('value_max'.$language['id_lang']).'
|
||
|
)
|
||
|
');
|
||
|
} else {
|
||
|
Db::getInstance()->Execute('
|
||
|
INSERT INTO `'._DB_PREFIX_.'privatesale_delay_lang` VALUES (
|
||
|
'.$id_delay.',
|
||
|
'.$language['id_lang'].',
|
||
|
"",
|
||
|
"",
|
||
|
0,
|
||
|
0
|
||
|
)
|
||
|
');
|
||
|
}
|
||
|
}
|
||
|
} elseif(Tools::isSubmit('submitDelayUpdate') && $id_delay = (int) Tools::getValue('id_delay')) {
|
||
|
if(count(Db::getInstance()->ExecuteS('
|
||
|
SELECT *
|
||
|
FROM `'._DB_PREFIX_.'privatesale_delay`
|
||
|
WHERE `id_delay` = '.$id_delay)
|
||
|
) > 0) {
|
||
|
Db::getInstance()->Execute('
|
||
|
DELETE FROM `'._DB_PREFIX_.'privatesale_delay_lang`
|
||
|
WHERE `id_delay` = '.$id_delay.'
|
||
|
');
|
||
|
foreach(Language::getLanguages(FALSE) as $language) {
|
||
|
if($name = Tools::getValue('name_'.$language['id_lang'])) {
|
||
|
Db::getInstance()->Execute('
|
||
|
INSERT INTO `'._DB_PREFIX_.'privatesale_delay_lang` VALUES (
|
||
|
'.$id_delay.',
|
||
|
'.$language['id_lang'].',
|
||
|
"'.pSQL($name).'",
|
||
|
"'.pSQL(Tools::getValue('short_name_'.$language['id_lang'])).'",
|
||
|
'.(int) Tools::getValue('value_'.$language['id_lang']).',
|
||
|
'.(int) Tools::getValue('value_max_'.$language['id_lang']).'
|
||
|
)
|
||
|
');
|
||
|
} else {
|
||
|
Db::getInstance()->Execute('
|
||
|
INSERT INTO `'._DB_PREFIX_.'privatesale_delay_lang` VALUES (
|
||
|
'.$id_delay.',
|
||
|
'.$language['id_lang'].',
|
||
|
"",
|
||
|
"",
|
||
|
0,
|
||
|
0
|
||
|
)
|
||
|
');
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
} elseif(isset($_GET['delete']) && $id_delay = Tools::getValue('id')) {
|
||
|
Db::getInstance()->Execute('
|
||
|
DELETE FROM `'._DB_PREFIX_.'privatesale_delay_lang`
|
||
|
WHERE `id_delay` = '.(int) $id_delay.'
|
||
|
');
|
||
|
Db::getInstance()->Execute('
|
||
|
DELETE FROM `'._DB_PREFIX_.'privatesale_delay`
|
||
|
WHERE `id_delay` = '.(int) $id_delay.'
|
||
|
');
|
||
|
Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesDelay'));
|
||
|
}
|
||
|
}
|
||
|
}
|