215 lines
9.0 KiB
PHP
Executable File
215 lines
9.0 KiB
PHP
Executable File
<?php
|
|
include_once(_PS_ROOT_DIR_.'/modules/privatesales/Sale.php');
|
|
|
|
class AdminPrivateSalesExtraFields extends AdminTab {
|
|
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¤format';
|
|
|
|
echo '<script type="text/javascript" src="'.__PS_BASE_URI__.'modules/privatesales_extrafields/privatesale.js"></script>
|
|
<script type="text/javascript">
|
|
i18n_delete = "'.$this->l('Are you sure you want to delete this field?').'";
|
|
current_location = "'.$currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesExtraFields').'";
|
|
</script>
|
|
<form action="'.$currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesExtraFields').'" method="post" enctype="multipart/form-data">
|
|
<fieldset>
|
|
<legend><img src="../img/admin/cms.gif" alt="" title="" /> '.$this->l('Edit a field').'</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->curfield !== NULL? $this->curfield['name'][$language['id_lang']]: '').'" />
|
|
</div>';
|
|
}
|
|
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'name');
|
|
echo '<div class="clear"></div>
|
|
</div>';
|
|
|
|
echo '<label>'.$this->l('Type:').'</label>
|
|
<div class="margin-form">
|
|
<div id="type" style="float: left; margin-top: 3px;">
|
|
<input name="type" type="radio" value="0"'.($this->curfield !== NULL? ((int) $this->curfield['type'] == 0? ' checked="checked"': ''): ' checked="checked"').' /> '.$this->l('Small text').' <input name="type" type="radio" value="1"'.($this->curfield !== NULL && (int) $this->curfield['type'] == 1? ' checked="checked"': '').' /> '.$this->l('Large text').'
|
|
</div>
|
|
<div class="clear"></div>
|
|
</div>';
|
|
|
|
echo '<label>'.$this->l('Show if blank:').'</label>
|
|
<div class="margin-form">
|
|
<div id="blank" style="float: left; margin-top: 3px;">
|
|
<input name="blank" type="radio" value="0"'.($this->curfield !== NULL? ((int) $this->curfield['blank'] == 0? ' checked="checked"': ''): ' checked="checked"').' /> '.$this->l('No').' <input name="blank" type="radio" value="1"'.($this->curfield !== NULL && (int) $this->curfield['blank'] == 1? ' checked="checked"': '').' /> '.$this->l('Yes').'
|
|
</div>
|
|
<div class="clear"></div>
|
|
<p>'.$this->l('If set to No, the field format will not be displayed if the value is empty.').'</p>
|
|
</div>';
|
|
|
|
echo '<label>'.$this->l('Format:').'</label>
|
|
<div class="margin-form">';
|
|
foreach($this->_languages as $language) {
|
|
echo '<div id="format_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
|
|
<textarea style="width: 500px; height: 150px;" name="format_'.$language['id_lang'].'">'.($this->curfield !== NULL? $this->curfield['format'][$language['id_lang']]: '').'</textarea>
|
|
</div>';
|
|
}
|
|
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'format');
|
|
echo '<div class="clear"></div>
|
|
<p>'.$this->l('HTML allowed, {name} will be replaced by the field name, {value} will be replaced by the field value.').'</p>
|
|
</div>';
|
|
|
|
echo '<br class="clear" />
|
|
<div class="margin-form">
|
|
<input type="hidden" name="id_field" value="'.($this->curfield !== NULL? $this->curfield['id']: '').'" />
|
|
<input type="submit" class="button" name="submitFieldAdd" value="'.$this->l('Add this field').'" />
|
|
<input type="submit" class="button'.($this->curfield !== NULL? '': ' disable"').'" name="submitFieldUpdate" value="'.$this->l('Edit this field').'"'.($this->curfield !== NULL? '': ' disabled="disabled"').' id="submitFieldUpdate" />
|
|
</div>';
|
|
|
|
echo '</fieldset>
|
|
</form>';
|
|
}
|
|
|
|
public function display() {
|
|
global $cookie, $currentIndex;
|
|
$this->curfield = null;
|
|
if($id = Tools::getValue('id')) {
|
|
$field = Db::getInstance()->ExecuteS('SELECT * FROM `'._DB_PREFIX_.'privatesale_extrafield_lang` WHERE `id_field` = '.(int) $id);
|
|
if(count($field) > 0) {
|
|
$field_info = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'privatesale_extrafield` WHERE `id_field` = '.(int) $id);
|
|
$this->curfield = array('id' => $id, 'type' => $field_info['type'], 'blank' => $field_info['blank'], 'name' => array());
|
|
foreach($field as $f) {
|
|
$this->curfield['name'][$f['id_lang']] = $f['name'];
|
|
$this->curfield['format'][$f['id_lang']] = $f['format'];
|
|
}
|
|
} else {
|
|
Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesExtraFields'));
|
|
}
|
|
}
|
|
|
|
$this->displayForm();
|
|
|
|
echo '<fieldset class="space">
|
|
<legend><img src="'.__PS_BASE_URI__.'modules/privatesales_extrafields/prefs.gif" alt="" title="" /> '.$this->l('Fields list').'</legend>
|
|
<table class="table" style="width: 100%;">
|
|
<tr>
|
|
<th>'.$this->l('ID').'</th>
|
|
<th>'.$this->l('Name').'</th>
|
|
<th>'.$this->l('Type').'</th>
|
|
<th>'.$this->l('Show if blank').'</th>
|
|
<th style="width: 55px;">'.$this->l('Actions').'</th>
|
|
</tr>';
|
|
foreach(Db::getInstance()->ExecuteS('
|
|
SELECT *
|
|
FROM `'._DB_PREFIX_.'privatesale_extrafield_lang` l, `'._DB_PREFIX_.'privatesale_extrafield` f
|
|
WHERE l.`id_lang` = '.$cookie->id_lang.'
|
|
AND l.`id_field` = f.`id_field`
|
|
') as $field) {
|
|
echo '<tr>
|
|
<td>'.$field['id_field'].'</td>
|
|
<td>'.$field['name'].'</td>
|
|
<td>'.($field['type'] == 0? $this->l('Small'): $this->l('Large')).'</td>
|
|
<td>'.($field['blank'] == 0? $this->l('No'): $this->l('Yes')).'</td>
|
|
<td>
|
|
<img style="cursor: pointer;" onclick="itemEdition('.$field['id_field'].')" title="'.$this->l('Edit this field').'" alt="" src="../img/admin/edit.gif">
|
|
<img style="cursor: pointer;" onclick="itemDeletion('.$field['id_field'].')" title="'.$this->l('Delete this field').'" alt="" src="../img/admin/delete.gif">
|
|
</td>
|
|
</tr>';
|
|
}
|
|
echo '</table>
|
|
</fieldset>';
|
|
}
|
|
|
|
function postProcess() {
|
|
global $cookie, $currentIndex;
|
|
|
|
if(Tools::isSubmit('submitFieldAdd')) {
|
|
Db::getInstance()->Execute('
|
|
INSERT INTO `'._DB_PREFIX_.'privatesale_extrafield` VALUES (
|
|
DEFAULT,
|
|
'.(int) Tools::getValue('type').',
|
|
'.(int) (bool) Tools::getValue('blank').'
|
|
)
|
|
');
|
|
$id_field = 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_extrafield_lang` VALUES (
|
|
'.$id_field.',
|
|
'.$language['id_lang'].',
|
|
"'.pSQL($name).'",
|
|
"'.pSQL(Tools::getValue('format_'.$language['id_lang'], ''), TRUE).'"
|
|
)
|
|
');
|
|
} else {
|
|
Db::getInstance()->Execute('
|
|
INSERT INTO `'._DB_PREFIX_.'privatesale_extrafield_lang` VALUES (
|
|
'.$id_field.',
|
|
'.$language['id_lang'].',
|
|
"",
|
|
""
|
|
)
|
|
');
|
|
}
|
|
}
|
|
} elseif(Tools::isSubmit('submitFieldUpdate') && $id_field = (int) Tools::getValue('id_field')) {
|
|
if(count(Db::getInstance()->ExecuteS('
|
|
SELECT *
|
|
FROM `'._DB_PREFIX_.'privatesale_extrafield`
|
|
WHERE `id_field` = '.$id_field)
|
|
) > 0) {
|
|
Db::getInstance()->Execute('
|
|
UPDATE `'._DB_PREFIX_.'privatesale_extrafield`
|
|
SET `type` = '.(int) Tools::getValue('type').',
|
|
`blank` = '.(int) (bool) Tools::getValue('blank').'
|
|
WHERE `id_field` = '.$id_field.'
|
|
');
|
|
Db::getInstance()->Execute('
|
|
DELETE FROM `'._DB_PREFIX_.'privatesale_extrafield_lang`
|
|
WHERE `id_field` = '.$id_field.'
|
|
');
|
|
foreach(Language::getLanguages(FALSE) as $language) {
|
|
if($name = Tools::getValue('name_'.$language['id_lang'])) {
|
|
Db::getInstance()->Execute('
|
|
INSERT INTO `'._DB_PREFIX_.'privatesale_extrafield_lang` VALUES (
|
|
'.$id_field.',
|
|
'.$language['id_lang'].',
|
|
"'.pSQL($name).'",
|
|
"'.pSQL(Tools::getValue('format_'.$language['id_lang'], ''), TRUE).'"
|
|
)
|
|
');
|
|
} else {
|
|
Db::getInstance()->Execute('
|
|
INSERT INTO `'._DB_PREFIX_.'privatesale_extrafield_lang` VALUES (
|
|
'.$id_field.',
|
|
'.$language['id_lang'].',
|
|
"",
|
|
""
|
|
)
|
|
');
|
|
}
|
|
}
|
|
}
|
|
} elseif(isset($_GET['delete']) && $id_field = Tools::getValue('id')) {
|
|
Db::getInstance()->Execute('
|
|
DELETE FROM `'._DB_PREFIX_.'privatesale_extrafield_lang`
|
|
WHERE `id_field` = '.(int) $id_field.'
|
|
');
|
|
Db::getInstance()->Execute('
|
|
DELETE FROM `'._DB_PREFIX_.'privatesale_extrafield_sale`
|
|
WHERE `id_field` = '.(int) $id_field.'
|
|
');
|
|
Db::getInstance()->Execute('
|
|
DELETE FROM `'._DB_PREFIX_.'privatesale_extrafield`
|
|
WHERE `id_field` = '.(int) $id_field.'
|
|
');
|
|
Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesExtraFields'));
|
|
}
|
|
}
|
|
}
|