name = 'privatesales_extrafields'; $this->tab = 'pricing_promotion'; $this->author = 'Antadis'; $this->version = '1.0'; parent::__construct(); $this->displayName = $this->l('Private Sales Extra Fields'); $this->description = $this->l('Adds extra fields to private sales'); } public function install() { if(!Module::isInstalled('privatesales')) { return FALSE; } # Install admin tab $id_mod = Db::getInstance()->ExecuteS(' SELECT `id_tab` FROM `'._DB_PREFIX_.'tab` WHERE `class_name` = "AdminPrivateSales" '); if(count($id_mod) == 0) { return FALSE; } $id_mod = $id_mod[0]['id_tab']; $posmax = Db::getInstance()->ExecuteS('SELECT MAX(`position`) + 1 AS `max` FROM `'._DB_PREFIX_.'tab` WHERE `id_parent` = '.$id_mod); $posmax = $posmax[0]['max']; Db::getInstance()->Execute(' INSERT INTO `'._DB_PREFIX_.'tab` VALUES ( DEFAULT, '.$id_mod.', "AdminPrivateSalesExtraFields", "privatesales_extrafields", '.$posmax.' ) '); $tab_id = Db::getInstance()->Insert_ID(); Db::getInstance()->Execute(' INSERT INTO `'._DB_PREFIX_.'access` VALUES (1, '.$tab_id.', 1, 1, 1, 1) '); $tabs_i18n = array( 'fr' => 'Champs suppl.', 'en' => 'Extra Fields', ); $langs = Db::getInstance()->ExecuteS(' SELECT `id_lang`, `iso_code` FROM `'._DB_PREFIX_.'lang` '); foreach($langs as $lang) { if(isset($tabs_i18n[$lang['iso_code']])) { Db::getInstance()->Execute(' INSERT INTO `'._DB_PREFIX_.'tab_lang` VALUES ('.$tab_id.', '.$lang['id_lang'].', "'.$tabs_i18n[$lang['iso_code']].'") '); } else { Db::getInstance()->Execute(' INSERT INTO `'._DB_PREFIX_.'tab_lang` VALUES ('.$tab_id.', '.$lang['id_lang'].', "'.$tabs_i18n['en'].'") '); } } # Add tags tables $query = ' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesale_extrafield` ( `id_field` INTEGER NOT NULL AUTO_INCREMENT, `type` TINYINT NOT NULL, `blank` BOOLEAN NOT NULL, PRIMARY KEY(`id_field`) ) ENGINE=MyIsam DEFAULT CHARSET=utf8 '; if(!Db::getInstance()->Execute($query)) { return FALSE; } $query = ' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesale_extrafield_lang` ( `id_field` INTEGER NOT NULL, `id_lang` INTEGER NOT NULL, `name` VARCHAR(255) NOT NULL, `format` TEXT, PRIMARY KEY(`id_field`, `id_lang`) ) ENGINE=MyIsam DEFAULT CHARSET=utf8 '; if(!Db::getInstance()->Execute($query)) { return FALSE; } $query = ' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'privatesale_extrafield_sale` ( `id_field` INTEGER NOT NULL, `id_sale` INTEGER NOT NULL, `id_lang` INTEGER NOT NULL, `value` TEXT, PRIMARY KEY(`id_field`, `id_sale`, `id_lang`) ) ENGINE=MyIsam DEFAULT CHARSET=utf8 '; if(!Db::getInstance()->Execute($query)) { return FALSE; } # Register hooks if(!parent::install() OR !$this->registerHook('privatesales_create') OR !$this->registerHook('privatesales_update') OR !$this->registerHook('privatesales_delete') OR !$this->registerHook('privatesales_edit') OR !$this->registerHook('privatesales_listing')) { return FALSE; } Db::getInstance()->Execute(' INSERT INTO `'._DB_PREFIX_.'privatesale_module` VALUES ( (SELECT `id_module` FROM `'._DB_PREFIX_.'module` WHERE `name` = "privatesales_extrafields"), "privatesales_extrafields" ) '); return TRUE; } function uninstall() { $tab = Db::getInstance()->Execute(' SELECT `id_tab` FROM `'._DB_PREFIX_.'tab` WHERE `module` = "privatesales_extrafields" '); if(count($tab) == 0) { return FALSE; } $tab = $tab[0]; Db::getInstance()->Execute(' DELETE FROM `'._DB_PREFIX_.'tab_lang` WHERE `id_tab` = '.$tab['id_tab'] ); Db::getInstance()->Execute(' DELETE FROM `'._DB_PREFIX_.'access` WHERE `id_tab` = '.$tab['id_tab'] ); Db::getInstance()->Execute(' DELETE FROM `'._DB_PREFIX_.'tab` WHERE `module` = "privatesales_extrafields" '); Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'tab` SET `position` = `position` - 1 WHERE `id_parent` = '.$tab['id_parent'].' AND `position` > '.$tab['position'] ); if(parent::uninstall() == FALSE) { return FALSE; } Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'privatesale_extrafield`'); Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'privatesale_extrafield_lang`'); Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'privatesale_extrafield_sale`'); Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'privatesale_module` WHERE `modulename` = "privatesales_extrafields"'); return TRUE; } public function hookPrivateSales_Edit($params) { global $cookie; $iso = Language::getIsoById((int)($cookie->id_lang)); $this->_languages = Language::getLanguages(FALSE); $this->_defaultFormLanguage = (int) $cookie->id_lang; $fields = Db::getInstance()->ExecuteS(' SELECT f.`type`, l.`id_field`, l.`name` FROM `'._DB_PREFIX_.'privatesale_extrafield_lang` l, `'._DB_PREFIX_.'privatesale_extrafield` f WHERE l.`id_lang` = '.$cookie->id_lang.' AND f.`id_field` = l.`id_field` '); $fields_values = array(); if(isset($params['sale']->id)){ foreach(Db::getInstance()->ExecuteS(' SELECT * FROM `'._DB_PREFIX_.'privatesale_extrafield_sale` s WHERE s.`id_sale` = '.(int) $params['sale']->id.' ') as $value) { if($fields_values[$value['id_field']] === NULL) { $fields_values[$value['id_field']] = array(); } $fields_values[$value['id_field']][$value['id_lang']] = $value['value']; } } else{ $fields_values[] = array(); } // foreach(Db::getInstance()->ExecuteS(' // SELECT * // FROM `'._DB_PREFIX_.'privatesale_extrafield_sale` s // WHERE s.`id_sale` = '.(int) $params['sale']->id.' // ') as $value) { // if($fields_values[$value['id_field']] === NULL) { // $fields_values[$value['id_field']] = array(); // } // $fields_values[$value['id_field']][$value['id_lang']] = $value['value']; // } $divLangName = array(); foreach($fields as $field) { $divLangName[] = 'm_extrafields_'.$field['id_field'].'_value'; } $divLangName = implode('ยค', $divLangName); foreach($fields as $field) { echo '