bebeboutik/modules/privatesales_shipping/AdminPrivateSalesShipping.php
2016-11-21 10:11:27 +01:00

171 lines
6.3 KiB
PHP
Executable File

<?php
include_once(_PS_ROOT_DIR_.'/modules/privatesales/Sale.php');
class AdminPrivateSalesShipping 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¤legend¤description';
echo '<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/privatesales_shipping/privatesale.js"></script>
<script type="text/javascript">
i18n_delete = "'.$this->l('Are you sure you want to delete this shipping method?').'";
current_location = "'.$currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesShipping').'";
</script>
<form action="'.$currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesShipping').'" method="post" enctype="multipart/form-data">
<fieldset>
<legend><img src="../img/admin/cms.gif" alt="" title="" /> '.$this->l('Edit a shipping method').'</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->curshipping !== NULL? $this->curshipping['name'][$language['id_lang']]: '').'" />
</div>';
}
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'name');
echo '<div class="clear"></div>
</div>';
echo '<br class="clear" />
<div class="margin-form">
<input type="hidden" name="id_shipping" value="'.($this->curshipping !== NULL? $this->curshipping['id']: '').'" />
<input type="submit" class="button" name="submitShippingAdd" value="'.$this->l('Add this shipping method').'" />
<input type="submit" class="button'.($this->curshipping !== NULL? '': ' disable"').'" name="submitShippingUpdate" value="'.$this->l('Edit this shipping method').'"'.($this->curshipping !== NULL? '': ' disabled="disabled"').' id="submitShippingUpdate" />
</div>';
echo '</fieldset>
</form>';
}
public function display() {
global $cookie, $currentIndex;
$this->curshipping = null;
if($id = Tools::getValue('id')) {
$shipping = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'privatesale_shipping_lang` WHERE `id_shipping` = '.(int) $id);
if(count($shipping) > 0) {
$this->curshipping = array('id' => $id, 'name' => array());
foreach($shipping as $t) {
$this->curshipping['name'][$t['id_lang']] = $t['value'];
$this->curshipping['legend'][$t['id_lang']] = $t['legend'];
$this->curshipping['description'][$t['id_lang']] = $t['description'];
}
} else {
Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesShipping'));
}
}
$this->displayForm();
echo '<fieldset class="space">
<legend><img src="'.__PS_BASE_URI__.'modules/privatesales/prefs.gif" alt="" title="" /> '.$this->l('Shipping methods list').'</legend>
<table class="table" style="width: 100%;">
<tr>
<th>'.$this->l('ID').'</th>
<th>'.$this->l('Name').'</th>
<th style="width: 55px;">'.$this->l('Actions').'</th>
</tr>';
foreach(Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'privatesale_shipping_lang`
WHERE `id_lang` = '.$cookie->id_lang
) as $shipping) {
echo '<tr>
<td>'.$shipping['id_shipping'].'</td>
<td>'.$shipping['value'].'</td>
<td>
<img style="cursor: pointer;" onclick="itemEdition('.$shipping['id_shipping'].')" title="'.$this->l('Edit this shipping method').'" alt="" src="../img/admin/edit.gif">
<img style="cursor: pointer;" onclick="itemDeletion('.$shipping['id_shipping'].')" title="'.$this->l('Delete this shipping method').'" alt="" src="../img/admin/delete.gif">
</td>
</tr>';
}
echo '</table>
</fieldset>';
}
function postProcess() {
global $cookie, $currentIndex;
if(Tools::isSubmit('submitShippingAdd')) {
Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'privatesale_shipping` VALUES (
DEFAULT
)
');
$id_shipping = 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_shipping_lang` VALUES (
'.$id_shipping.',
'.$language['id_lang'].',
"'.pSQL($name).'"
)
');
} else {
Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'privatesale_shipping_lang` VALUES (
'.$id_shipping.',
'.$language['id_lang'].',
""
)
');
}
}
} elseif(Tools::isSubmit('submitShippingUpdate') && $id_shipping = (int) Tools::getValue('id_shipping')) {
if(count(Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'privatesale_shipping`
WHERE `id_shipping` = '.$id_shipping)
) > 0) {
Db::getInstance()->Execute('
DELETE FROM `'._DB_PREFIX_.'privatesale_shipping_lang`
WHERE `id_shipping` = '.$id_shipping.'
');
foreach(Language::getLanguages(FALSE) as $language) {
if($name = Tools::getValue('name_'.$language['id_lang'])) {
Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'privatesale_shipping_lang` VALUES (
'.$id_shipping.',
'.$language['id_lang'].',
"'.pSQL($name).'"
)
');
} else {
Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'privatesale_shipping_lang` VALUES (
'.$id_shipping.',
'.$language['id_lang'].',
""
)
');
}
}
}
} elseif(isset($_GET['delete']) && $id_shipping = Tools::getValue('id')) {
Db::getInstance()->Execute('
DELETE FROM `'._DB_PREFIX_.'privatesale_shipping_lang`
WHERE `id_shipping` = '.(int) $id_shipping.'
');
Db::getInstance()->Execute('
DELETE FROM `'._DB_PREFIX_.'privatesale_shipping_sale`
WHERE `id_shipping` = '.(int) $id_shipping.'
');
Db::getInstance()->Execute('
DELETE FROM `'._DB_PREFIX_.'privatesale_shipping`
WHERE `id_shipping` = '.(int) $id_shipping.'
');
Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesShipping'));
}
}
}