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 '
'.$this->l('Edit a field').''; echo '
'; foreach($this->_languages as $language) { echo '
'; } $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'name'); echo '
'; echo '
curfield !== NULL? ((int) $this->curfield['type'] == 0? ' checked="checked"': ''): ' checked="checked"').' /> '.$this->l('Small text').'   curfield !== NULL && (int) $this->curfield['type'] == 1? ' checked="checked"': '').' /> '.$this->l('Large text').'
'; echo '
curfield !== NULL? ((int) $this->curfield['blank'] == 0? ' checked="checked"': ''): ' checked="checked"').' /> '.$this->l('No').'   curfield !== NULL && (int) $this->curfield['blank'] == 1? ' checked="checked"': '').' /> '.$this->l('Yes').'

'.$this->l('If set to No, the field format will not be displayed if the value is empty.').'

'; echo '
'; foreach($this->_languages as $language) { echo '
'; } $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $divLangName, 'format'); echo '

'.$this->l('HTML allowed, {name} will be replaced by the field name, {value} will be replaced by the field value.').'

'; echo '
curfield !== NULL? '': ' disabled="disabled"').' id="submitFieldUpdate" />
'; echo '
'; } 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 '
'.$this->l('Fields list').' '; 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 ''; } echo '
'.$this->l('ID').' '.$this->l('Name').' '.$this->l('Type').' '.$this->l('Show if blank').' '.$this->l('Actions').'
'.$field['id_field'].' '.$field['name'].' '.($field['type'] == 0? $this->l('Small'): $this->l('Large')).' '.($field['blank'] == 0? $this->l('No'): $this->l('Yes')).'
'; } 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')); } } }