diff --git a/admin-dev/tabs/AdminFeatures.php b/admin-dev/tabs/AdminFeatures.php deleted file mode 100644 index 22b3e99bd..000000000 --- a/admin-dev/tabs/AdminFeatures.php +++ /dev/null @@ -1,297 +0,0 @@ - -* @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 7331 $ -* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -include_once(_PS_ADMIN_DIR_.'/tabs/AdminFeaturesValues.php'); - -class AdminFeatures extends AdminTab -{ - public function __construct() - { - $this->adminFeaturesValues = new AdminFeaturesValues(); - $this->table = 'feature'; - $this->className = 'Feature'; - $this->lang = true; - $this->edit = true; - $this->delete = true; - - $this->fieldsDisplay = array( - 'name' => array('title' => $this->l('Name'), 'width' => 128, 'filter_key' => 'b!name'), - 'value' => array('title' => $this->l('Values'), 'width' => 255, 'orderby' => false, 'search' => false), - 'position' => array('title' => $this->l('Position'), 'width' => 40,'filter_key' => 'cp!position', 'align' => 'center', 'position' => 'position')); - - parent::__construct(); - } - - public function display() - { - if (Feature::isFeatureActive()) - { - if ((isset($_POST['submitAddfeature_value']) AND sizeof($this->adminFeaturesValues->_errors)) - OR isset($_GET['updatefeature_value']) OR isset($_GET['addfeature_value'])) - { - $this->adminFeaturesValues->displayForm($this->token); - echo '

'.$this->l('Back to the features list').'
'; - } - else - parent::display(); - } - else - $this->displayWarning($this->l('This feature has been disabled, you can active this feature at this page:').' '.$this->l('Performances').''); - } - - /* Report to AdminTab::displayList() for more details */ - public function displayList() - { - echo '
- '.$this->l('Add a new feature').'
- '.$this->l('Add a new feature value').'

- '.$this->l('Click on a feature name to view its values and then click again if you want to hide them.').'

'; - - $this->displayListHeader(); - echo ''; - - if (!sizeof($this->_list)) - echo ''.$this->l('No features found.').''; - - - echo ' - - - - '; - - $irow = 0; - if ($this->_list AND isset($this->fieldsDisplay['position'])) - { - $positions = array_map(create_function('$elem', 'return (int)$elem[\'position\'];'), $this->_list); - sort($positions); - } - foreach ($this->_list AS $tr) - { - $id = (int)($tr['id_'.$this->table]); - echo ' - - - '.$tr['name'].' - - - '; - - echo ' - '; - - if ($this->_orderBy == 'position' AND $this->_orderWay != 'DESC') - { - echo ' - '.$this->l('Down').''; - - echo ' - '.$this->l('Up').''; - } - else - echo (int)($tr['position'] + 1); - - - echo ' - - - '.$this->l('Edit').'  - - '.$this->l('Delete').' - - '; - } - - $this->displayListFooter(); - - } - - public function displayForm($isMainTab = true) - { - if (!Feature::isFeatureActive()) - { - $this->displayWarning($this->l('This feature has been disabled, you can active this feature at this page:').''.$this->l('Performances').''); - return; - } - - parent::displayForm(); - - if (!($obj = $this->loadObject(true))) - return; - - echo ' -

'.$this->l('Add a new feature').'

-
- '.($obj->id ? '' : '').' -
- '.$this->l('Add a new feature').' - -
'; - foreach ($this->_languages AS $language) - echo ' -
- * - '.$this->l('Invalid characters:').' <>;=#{}  -
- '; - $this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'flag_fields', 'name', false, true); - echo ' -
-
'; - if (Shop::isFeatureActive()) - { - echo '
'; - $this->displayAssoShop('group_shop'); - echo '
'; - } - echo ' - '.Hook::exec('featureForm', array('id_feature' => $obj->id)).' -
- -
-
* '.$this->l('Required field').'
-
-
'; - } - - public function displayErrors() - { - $this->adminFeaturesValues->displayErrors(); - parent::displayErrors(); - } - - public function postProcess() - { - if (!Feature::isFeatureActive()) - return ; - - $this->adminFeaturesValues->tabAccess = Profile::getProfileAccess($this->context->employee->id_profile, $this->id); - - if (Tools::isSubmit('submitAddfeature_value') || Tools::isSubmit('submitDelfeature_value')) - $this->adminFeaturesValues->postProcess($this->token); - - Hook::exec('postProcessFeature', - array('errors' => &$this->_errors)); // send _errors as reference to allow postProcessFeature to stop saving process - - if(Tools::getValue('submitDel'.$this->table)) - { - if ($this->tabAccess['delete'] === '1') - { - if (isset($_POST[$this->table.'Box'])) - { - $object = new $this->className(); - if ($object->deleteSelection($_POST[$this->table.'Box'])) - Tools::redirectAdmin(self::$currentIndex.'&conf=2'.'&token='.$this->token); - $this->_errors[] = Tools::displayError('An error occurred while deleting selection.'); - } - else - $this->_errors[] = Tools::displayError('You must select at least one element to delete.'); - } - else - $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); - } - else if (Tools::isSubmit('submitAdd'.$this->table)) - { - if ($this->tabAccess['add'] === '1') - { - $id_feature = (int)Tools::getValue('id_feature'); - // Adding last position to the feature if not exist - if ($id_feature <= 0) - { - $sql = 'SELECT `position`+1 - FROM `'._DB_PREFIX_.'feature` - ORDER BY position DESC'; - // set the position of the new feature in $_POST for postProcess() method - $_POST['position'] = DB::getInstance()->getValue($sql); - } - // clean \n\r characters - foreach ($_POST as $key => $value) - if (preg_match('/^name_/Ui', $key)) - $_POST[$key] = str_replace ('\n', '', str_replace('\r', '', $value)); - parent::postProcess(); - } - - } - else - parent::postProcess(); - } - - /** - * Modifying initial getList method to display position feature (drag and drop) - */ - public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false) - { - if ($order_by && $this->context->cookie->__get($this->table.'Orderby')) - $order_by = $this->context->cookie->__get($this->table.'Orderby'); - else - $order_by = 'position'; - - parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop); - } -} diff --git a/admin-dev/tabs/AdminFeaturesValues.php b/admin-dev/tabs/AdminFeaturesValues.php deleted file mode 100644 index 1e825c0c1..000000000 --- a/admin-dev/tabs/AdminFeaturesValues.php +++ /dev/null @@ -1,124 +0,0 @@ - -* @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 6844 $ -* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -class AdminFeaturesValues extends AdminTab -{ - public function __construct() - { - $this->table = 'feature_value'; - $this->className = 'FeatureValue'; - $this->lang = true; - $this->edit = true; - $this->delete = true; - - parent::__construct(); - } - - /** - * Display form - */ - public function displayForm($isMainTab = true) - { - if (!Feature::isFeatureActive()) - { - $this->displayWarning($this->l('This feature has been disabled, you can active this feature at this page:').' '.$this->l('Performances').''); - return; - } - - parent::displayForm(); - - if (!($obj = $this->loadObject(true))) - return; - - echo ' -

'.$this->l('Add a new feature value').'

-
- '.($obj->id ? '' : '').' -
- '.$this->l('Add a new feature value').' - -
'; - foreach ($this->_languages as $language) - echo ' -
- * - '.$this->l('Invalid characters:').' <>;=#{}  -
- '; - $this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'flag_fields', 'value', false, true); - echo ' -
-
- -
- * -
- '.Hook::exec('featureValueForm', array('id_feature_value' => $obj->id)).' -
- -
-
* '.$this->l('Required field').'
-
-
'; - } - - /** - * Manage page processing - */ - public function postProcess($token = NULL) - { - Hook::exec('postProcessFeatureValue', - array('errors' => &$this->_errors)); // send _errors as reference to allow postProcessFeatureValue to stop saving process - - if(Tools::getValue('submitDel'.$this->table)) - { - if ($this->tabAccess['delete'] === '1') - { - if (isset($_POST[$this->table.$_POST['groupid'].'Box'])) - { - $object = new $this->className(); - if ($object->deleteSelection($_POST[$this->table.$_POST['groupid'].'Box'])) - Tools::redirectAdmin(self::$currentIndex.'&conf=2'.'&token='.($token ? $token : $this->token)); - $this->_errors[] = Tools::displayError('An error occurred while deleting selection.'); - } - else - $this->_errors[] = Tools::displayError('You must select at least one element to delete.'); - } - else - $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); - } - else - parent::postProcess(); - } -} diff --git a/admin-dev/themes/template/feature_value/form.tpl b/admin-dev/themes/template/feature_value/form.tpl new file mode 100644 index 000000000..09c1444c8 --- /dev/null +++ b/admin-dev/themes/template/feature_value/form.tpl @@ -0,0 +1,33 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 8971 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} +{extends file="helper/form/form.tpl"} + +{block name="end_field_block"} + + {if $input.name == 'id_feature'} + {if isset($hook)}{$hook}{/if} + {/if} +{/block} diff --git a/classes/AdminController.php b/classes/AdminController.php index 8428eb36c..b8bd092f6 100644 --- a/classes/AdminController.php +++ b/classes/AdminController.php @@ -1863,6 +1863,13 @@ class AdminControllerCore extends Controller return $this->_languages; } + + /** + * Return the list of fields value + * + * @param object $obj Object + * @return array + */ public function getFieldsValue($obj) { foreach ($this->fields_form as $fieldset) @@ -1873,11 +1880,12 @@ class AdminControllerCore extends Controller { if ($obj->id) { - $assos = array(); - $sql = 'SELECT `id_'.$input['type'].'`, `'.pSQL($this->identifier).'` - FROM `'._DB_PREFIX_.pSQL($this->table).'_'.$input['type'].'` - WHERE `'.pSQL($this->identifier).'` = '.(int)$obj->id; - foreach (Db::getInstance()->executeS($sql) as $row) + if ($input['type'] == 'group_shop') + $result = GroupShop::getGroupShopById((int)$obj->id, $this->identifier, $this->table); + else + $result = Shop::getShopById((int)$obj->id, $this->identifier, $this->table); + + foreach ($result as $row) $this->fields_value['shop'][$row['id_'.$input['type']]][] = $row[$this->identifier]; } } diff --git a/classes/Feature.php b/classes/Feature.php index 04983d8a9..6e893ef3b 100644 --- a/classes/Feature.php +++ b/classes/Feature.php @@ -28,17 +28,20 @@ class FeatureCore extends ObjectModel { /** @var string Name */ - public $name; - public $position; + public $name; + public $position; - protected $fieldsRequiredLang = array('name'); - protected $fieldsSizeLang = array('name' => 128); - protected $fieldsValidateLang = array('name' => 'isGenericName', 'position' => 'isInt'); + protected $fieldsRequiredLang = array('name'); + protected $fieldsSizeLang = array('name' => 128); + protected $fieldsValidateLang = array( + 'name' => 'isGenericName', + 'position' => 'isInt' + ); - protected $table = 'feature'; - protected $identifier = 'id_feature'; + protected $table = 'feature'; + protected $identifier = 'id_feature'; - protected $webserviceParameters = array( + protected $webserviceParameters = array( 'objectsNodeName' => 'product_features', 'objectNodeName' => 'product_feature', 'fields' => array(), @@ -46,7 +49,7 @@ class FeatureCore extends ObjectModel public function getFields() { - return array('id_feature' => NULL, 'position' => (int)$this->position); + return array('id_feature' => null, 'position' => (int)$this->position); } /** @@ -71,10 +74,12 @@ class FeatureCore extends ObjectModel public static function getFeature($id_lang, $id_feature) { return Db::getInstance()->getRow(' - SELECT * - FROM `'._DB_PREFIX_.'feature` f - LEFT JOIN `'._DB_PREFIX_.'feature_lang` fl ON ( f.`id_feature` = fl.`id_feature` AND fl.`id_lang` = '.(int)($id_lang).') - WHERE f.`id_feature` = '.(int)($id_feature)); + SELECT * + FROM `'._DB_PREFIX_.'feature` f + LEFT JOIN `'._DB_PREFIX_.'feature_lang` fl + ON ( f.`id_feature` = fl.`id_feature` AND fl.`id_lang` = '.(int)$id_lang.') + WHERE f.`id_feature` = '.(int)$id_feature + ); } /** @@ -87,10 +92,12 @@ class FeatureCore extends ObjectModel public static function getFeatures($id_lang) { return Db::getInstance()->executeS(' - SELECT * - FROM `'._DB_PREFIX_.'feature` f - LEFT JOIN `'._DB_PREFIX_.'feature_lang` fl ON (f.`id_feature` = fl.`id_feature` AND fl.`id_lang` = '.(int)($id_lang).') - ORDER BY f.`position` ASC'); + SELECT * + FROM `'._DB_PREFIX_.'feature` f + LEFT JOIN `'._DB_PREFIX_.'feature_lang` fl + ON (f.`id_feature` = fl.`id_feature` AND fl.`id_lang` = '.(int)$id_lang.') + ORDER BY f.`position` ASC + '); } /** @@ -102,7 +109,8 @@ class FeatureCore extends ObjectModel public function deleteSelection($selection) { /* Also delete Attributes */ - foreach ($selection AS $value) { + foreach ($selection as $value) + { $obj = new Feature($value); if (!$obj->delete()) return false; @@ -123,13 +131,22 @@ class FeatureCore extends ObjectModel public function delete() { /* Also delete related attributes */ - Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'feature_value_lang` WHERE `id_feature_value` IN (SELECT id_feature_value FROM `'._DB_PREFIX_.'feature_value` WHERE `id_feature` = '.(int)($this->id).')'); - Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'feature_value` WHERE `id_feature` = '.(int)($this->id)); + Db::getInstance()->execute(' + DELETE FROM `'._DB_PREFIX_.'feature_value_lang` + WHERE `id_feature_value` IN (SELECT id_feature_value FROM `'._DB_PREFIX_.'feature_value` WHERE `id_feature` = '.(int)$this->id.') + '); + Db::getInstance()->execute(' + DELETE FROM `'._DB_PREFIX_.'feature_value` + WHERE `id_feature` = '.(int)$this->id + ); /* Also delete related products */ - Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'feature_product` WHERE `id_feature` = '.(int)($this->id)); + Db::getInstance()->execute(' + DELETE FROM `'._DB_PREFIX_.'feature_product` + WHERE `id_feature` = '.(int)$this->id + ); $return = parent::delete(); - if($return) + if ($return) Hook::exec('afterDeleteFeature', array('id_feature' => $this->id)); /* Reinitializing position */ @@ -174,7 +191,7 @@ class FeatureCore extends ObjectModel $result = Db::getInstance()->getRow(' SELECT COUNT(ag.`id_feature`) as nb FROM `'._DB_PREFIX_.'feature` ag - LEFT JOIN `'._DB_PREFIX_.'feature_lang` agl ON (ag.`id_feature` = agl.`id_feature` AND `id_lang` = '.(int)($id_lang).') + LEFT JOIN `'._DB_PREFIX_.'feature_lang` agl ON (ag.`id_feature` = agl.`id_feature` AND `id_lang` = '.(int)$id_lang.') ORDER BY `name` ASC'); return ($result['nb']); } @@ -188,9 +205,14 @@ class FeatureCore extends ObjectModel */ public static function addFeatureImport($name, $position = false) { - $rq = Db::getInstance()->getRow('SELECT `id_feature` FROM '._DB_PREFIX_.'feature_lang WHERE `name` = \''.pSQL($name).'\' GROUP BY `id_feature`'); + $rq = Db::getInstance()->getRow(' + SELECT `id_feature` + FROM '._DB_PREFIX_.'feature_lang + WHERE `name` = \''.pSQL($name).'\' + GROUP BY `id_feature` + '); if (!empty($rq)) - return (int)($rq['id_feature']); + return (int)$rq['id_feature']; // Feature doesn't exist, create it $feature = new Feature(); $languages = Language::getLanguages(); @@ -210,8 +232,8 @@ class FeatureCore extends ObjectModel return false; $ids = ''; - foreach($list_ids_product as $id) - $ids .= (int)($id).','; + foreach ($list_ids_product as $id) + $ids .= (int)$id.','; $ids = rtrim($ids, ','); @@ -219,14 +241,17 @@ class FeatureCore extends ObjectModel return false; return Db::getInstance()->executeS(' - SELECT * , COUNT(*) as nb - FROM `'._DB_PREFIX_.'feature` f - LEFT JOIN `'._DB_PREFIX_.'feature_product` fp ON f.`id_feature` = fp.`id_feature` - LEFT JOIN `'._DB_PREFIX_.'feature_lang` fl ON f.`id_feature` = fl.`id_feature` - WHERE fp.`id_product` IN ('.$ids.') - AND `id_lang` = '.(int)($id_lang).' - GROUP BY f.`id_feature` - ORDER BY nb DESC'); + SELECT * , COUNT(*) as nb + FROM `'._DB_PREFIX_.'feature` f + LEFT JOIN `'._DB_PREFIX_.'feature_product` fp + ON f.`id_feature` = fp.`id_feature` + LEFT JOIN `'._DB_PREFIX_.'feature_lang` fl + ON f.`id_feature` = fl.`id_feature` + WHERE fp.`id_product` IN ('.$ids.') + AND `id_lang` = '.(int)$id_lang.' + GROUP BY f.`id_feature` + ORDER BY nb DESC + '); } /** @@ -255,11 +280,11 @@ class FeatureCore extends ObjectModel )) return false; - foreach ($res AS $feature) + foreach ($res as $feature) if ((int)$feature['id_feature'] == (int)$this->id) - $movedFeature = $feature; + $moved_feature = $feature; - if (!isset($movedFeature) || !isset($position)) + if (!isset($moved_feature) || !isset($position)) return false; // < and > statements rather than BETWEEN operator @@ -269,12 +294,12 @@ class FeatureCore extends ObjectModel SET `position`= `position` '.($way ? '- 1' : '+ 1').' WHERE `position` '.($way - ? '> '.(int)$movedFeature['position'].' AND `position` <= '.(int)$position - : '< '.(int)$movedFeature['position'].' AND `position` >= '.(int)$position)) - AND Db::getInstance()->execute(' + ? '> '.(int)$moved_feature['position'].' AND `position` <= '.(int)$position + : '< '.(int)$moved_feature['position'].' AND `position` >= '.(int)$position)) + && Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'feature` SET `position` = '.(int)$position.' - WHERE `id_feature`='.(int)$movedFeature['id_feature'])); + WHERE `id_feature`='.(int)$moved_feature['id_feature'])); } /** diff --git a/classes/FeatureValue.php b/classes/FeatureValue.php index d514a35e1..54cb38726 100644 --- a/classes/FeatureValue.php +++ b/classes/FeatureValue.php @@ -1,6 +1,6 @@ 'isUnsignedId', 'custom' => 'isBool'); - protected $fieldsRequiredLang = array('value'); - protected $fieldsSizeLang = array('value' => 255); - protected $fieldsValidateLang = array('value' => 'isGenericName'); - - protected $table = 'feature_value'; - protected $identifier = 'id_feature_value'; - + public $custom = 0; + + protected $fieldsRequired = array('id_feature'); + protected $fieldsValidate = array( + 'id_feature' => 'isUnsignedId', + 'custom' => 'isBool' + ); + + protected $fieldsRequiredLang = array('value'); + protected $fieldsSizeLang = array('value' => 255); + protected $fieldsValidateLang = array('value' => 'isGenericName'); + + protected $table = 'feature_value'; + protected $identifier = 'id_feature_value'; + protected $webserviceParameters = array( 'objectsNodeName' => 'product_feature_values', 'objectNodeName' => 'product_feature_value', @@ -62,7 +66,7 @@ class FeatureValueCore extends ObjectModel return $fields; } - + /** * Check then return multilingual fields for database interaction * @@ -73,7 +77,7 @@ class FeatureValueCore extends ObjectModel $this->validateFieldsLang(); return $this->getTranslationsFields(array('value')); } - + /** * Get all values for a given feature * @@ -84,11 +88,12 @@ class FeatureValueCore extends ObjectModel public static function getFeatureValues($id_feature) { return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' - SELECT * - FROM `'._DB_PREFIX_.'feature_value` - WHERE `id_feature` = '.(int)$id_feature); + SELECT * + FROM `'._DB_PREFIX_.'feature_value` + WHERE `id_feature` = '.(int)$id_feature + ); } - + /** * Get all values for a given feature and language * @@ -100,11 +105,14 @@ class FeatureValueCore extends ObjectModel public static function getFeatureValuesWithLang($id_lang, $id_feature) { return Db::getInstance()->executeS(' - SELECT * - FROM `'._DB_PREFIX_.'feature_value` v - LEFT JOIN `'._DB_PREFIX_.'feature_value_lang` vl ON (v.`id_feature_value` = vl.`id_feature_value` AND vl.`id_lang` = '.(int)$id_lang.') - WHERE v.`id_feature` = '.(int)$id_feature.' AND (v.`custom` IS NULL OR v.`custom` = 0) - ORDER BY vl.`value` ASC'); + SELECT * + FROM `'._DB_PREFIX_.'feature_value` v + LEFT JOIN `'._DB_PREFIX_.'feature_value_lang` vl + ON (v.`id_feature_value` = vl.`id_feature_value` AND vl.`id_lang` = '.(int)$id_lang.') + WHERE v.`id_feature` = '.(int)$id_feature.' + AND (v.`custom` IS NULL OR v.`custom` = 0) + ORDER BY vl.`value` ASC + '); } /** @@ -117,12 +125,13 @@ class FeatureValueCore extends ObjectModel public static function getFeatureValueLang($id_feature_value) { return Db::getInstance()->executeS(' - SELECT * - FROM `'._DB_PREFIX_.'feature_value_lang` - WHERE `id_feature_value` = '.(int)$id_feature_value.' - ORDER BY `id_lang`'); + SELECT * + FROM `'._DB_PREFIX_.'feature_value_lang` + WHERE `id_feature_value` = '.(int)$id_feature_value.' + ORDER BY `id_lang` + '); } - + /** * Select the good lang in tab * @@ -137,32 +146,34 @@ class FeatureValueCore extends ObjectModel if ($tab['id_lang'] == $id_lang) return $tab['value']; } - + public static function addFeatureValueImport($id_feature, $name) { $rq = Db::getInstance()->executeS(' - SELECT fv.`id_feature_value` - FROM '._DB_PREFIX_.'feature_value fv - LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.`id_feature_value` = fv.`id_feature_value`) - WHERE `value` = \''.pSQL($name).'\' - AND fv.`id_feature` = '.(int)$id_feature.' - AND fv.`custom` = 0 - GROUP BY fv.`id_feature_value` LIMIT 1'); + SELECT fv.`id_feature_value` + FROM '._DB_PREFIX_.'feature_value fv + LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl + ON (fvl.`id_feature_value` = fv.`id_feature_value`) + WHERE `value` = \''.pSQL($name).'\' + AND fv.`id_feature` = '.(int)$id_feature.' + AND fv.`custom` = 0 + GROUP BY fv.`id_feature_value` LIMIT 1 + '); - if (!isset($rq[0]['id_feature_value']) OR !$id_feature_value = (int)$rq[0]['id_feature_value']) + if (!isset($rq[0]['id_feature_value']) || !$id_feature_value = (int)$rq[0]['id_feature_value']) { // Feature doesn't exist, create it - $featureValue = new FeatureValue(); - + $feature_value = new FeatureValue(); + $languages = Language::getLanguages(); - foreach ($languages AS $language) - $featureValue->value[$language['id_lang']] = strval($name); + foreach ($languages as $language) + $feature_value->value[$language['id_lang']] = strval($name); - $featureValue->id_feature = (int)$id_feature; - $featureValue->custom = 1; - $featureValue->add(); + $feature_value->id_feature = (int)$id_feature; + $feature_value->custom = 1; + $feature_value->add(); - return (int)$featureValue->id; + return (int)$feature_value->id; } return (int)$id_feature_value; } @@ -178,9 +189,12 @@ class FeatureValueCore extends ObjectModel public function delete() { /* Also delete related products */ - Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'feature_product` WHERE `id_feature_value` = '.(int)$this->id); + Db::getInstance()->execute(' + DELETE FROM `'._DB_PREFIX_.'feature_product` + WHERE `id_feature_value` = '.(int)$this->id + ); $return = parent::delete(); - + if ($return) Hook::exec('afterDeleteFeatureValue', array('id_feature_value' => $this->id)); return $return; diff --git a/classes/HelperList.php b/classes/HelperList.php index 2214949ce..c4cdd654b 100644 --- a/classes/HelperList.php +++ b/classes/HelperList.php @@ -48,6 +48,9 @@ class HelperListCore extends Helper /** @var string Default ORDER BY clause when $orderBy is not defined */ public $_defaultOrderBy = false; + /** @var array : list of vars for button delete*/ + public $tpl_delete_link_vars = array(); + /** @var string Order way (ASC, DESC) determined by arrows in list header */ public $orderWay; @@ -100,7 +103,8 @@ class HelperListCore extends Helper 'id_attribute' => 'id_attribute', 'id_attribute_group' => 'id_attribute_group', 'id_carrier' => 'id_carrier', - 'id_tab' => 'id_tab' + 'id_tab' => 'id_tab', + 'id_feature' => 'id_feature' ); /** @var if not null, a title will be added on that list */ @@ -219,7 +223,7 @@ class HelperListCore extends Helper if (method_exists($this->context->controller, $method_name)) $this->_list[$index][$action] = $this->context->controller->$method_name($token, $id); - elseif (method_exists($this, $method_name)) + else if (method_exists($this, $method_name)) $this->_list[$index][$action] = $this->$method_name($token, $id); } @@ -248,9 +252,9 @@ class HelperListCore extends Helper Tools::getValue('id_product') ); } - elseif (isset($params['activeVisu'])) + else if (isset($params['activeVisu'])) $this->_list[$index][$key] = (bool)$tr[$key]; - elseif (isset($params['position'])) + else if (isset($params['position'])) { $this->_list[$index][$key] = array( 'position' => $tr[$key], @@ -262,7 +266,7 @@ class HelperListCore extends Helper '&way=0&position='.((int)$tr['position'] - 1).'&token='.$this->token ); } - elseif (isset($params['image'])) + else if (isset($params['image'])) { // item_id is the product id in a product image context, else it is the image id. $item_id = isset($params['image_id']) ? $tr[$params['image_id']] : $id; @@ -276,24 +280,24 @@ class HelperListCore extends Helper $this->_list[$index][$key] = cacheImage($path_to_image, $this->table.'_mini_'.$item_id.'.'.$this->imageType, 45, $this->imageType); } - elseif (isset($params['icon']) && (isset($params['icon'][$tr[$key]]) || isset($params['icon']['default']))) + else if (isset($params['icon']) && (isset($params['icon'][$tr[$key]]) || isset($params['icon']['default']))) $this->_list[$index][$key] = isset($params['icon'][$tr[$key]]) ? $params['icon'][$tr[$key]] : $params['icon']['default']; - elseif (isset($params['float'])) + else if (isset($params['float'])) $this->_list[$index][$key] = rtrim(rtrim($tr[$key], '0'), '.'); - elseif (isset($params['type']) && $params['type'] == 'price') + else if (isset($params['type']) && $params['type'] == 'price') { $currency = isset($params['currency']) ? Currency::getCurrencyInstance($tr['id_currency']) : $this->context->currency; $this->_list[$index][$key] = Tools::displayPrice($tr[$key], $currency, false); } - elseif (isset($params['type']) && $params['type'] == 'date') + else if (isset($params['type']) && $params['type'] == 'date') $this->_list[$index][$key] = Tools::displayDate($tr[$key], $this->context->language->id); - elseif (isset($params['type']) && $params['type'] == 'datetime') + else if (isset($params['type']) && $params['type'] == 'datetime') $this->_list[$index][$key] = Tools::displayDate($tr[$key], $this->context->language->id, true); - elseif (isset($tr[$key])) + else if (isset($tr[$key])) { if ($key == 'price') $echo = round($tr[$key], 2); - elseif (isset($params['maxlength']) && Tools::strlen($tr[$key]) > $params['maxlength']) + else if (isset($params['maxlength']) && Tools::strlen($tr[$key]) > $params['maxlength']) $echo = ''.Tools::substr($tr[$key], 0, $params['maxlength']).'...'; else $echo = $tr[$key]; @@ -393,7 +397,7 @@ class HelperListCore extends Helper $tpl->assign(array( 'id' => $id, 'controller' => str_replace('Controller', '', get_class($this->context->controller)), - 'token' => $this->token, + 'token' => $token != null ? $token : $this->token, 'action' => self::$cache_lang['Details'], 'params' => $this->ajax_params )); @@ -496,7 +500,7 @@ class HelperListCore extends Helper isset($this->context->cookie->{$this->table.'_pagination'}) ? $this->context->cookie->{$this->table.'_pagination'} : null ); - $this->is_dnd_identifier = array_key_exists($this->identifier,$this->identifiersDnd); + $this->is_dnd_identifier = array_key_exists($this->identifier, $this->identifiersDnd); /* if ($is_dnd_identifier) { @@ -605,7 +609,6 @@ class HelperListCore extends Helper 'current' => $this->currentIndex, 'simple_header' => $this->simple_header, 'bulk_actions' => $this->bulk_actions, - 'back' => Tools::getValue('back'), 'no_back' => $this->no_back, ))); diff --git a/classes/shop/GroupShop.php b/classes/shop/GroupShop.php index 630b8b5de..4dea52644 100644 --- a/classes/shop/GroupShop.php +++ b/classes/shop/GroupShop.php @@ -30,31 +30,31 @@ */ class GroupShopCore extends ObjectModel { - public $name; - public $active; - public $share_customer; - public $share_order; - public $deleted; + public $name; + public $active; + public $share_customer; + public $share_order; + public $deleted; - protected $fieldsSize = array('name' => 64); - protected $fieldsValidate = array( + protected $fieldsSize = array('name' => 64); + protected $fieldsValidate = array( 'active' => 'isBool', 'share_customer' => 'isBool', 'share_order' => 'isBool', 'name' => 'isGenericName', ); - protected $table = 'group_shop'; - protected $identifier = 'id_group_shop'; + protected $table = 'group_shop'; + protected $identifier = 'id_group_shop'; private static $assoTables = array( - 'attribute_group' => array('type' => 'group_shop'), - 'attribute' => array('type' => 'group_shop'), - 'feature' => array('type' => 'group_shop'), - 'group' => array('type' => 'group_shop'), - 'manufacturer' => array('type' => 'group_shop'), - 'supplier' => array('type' => 'group_shop'), - 'zone' => array('type' => 'shop'), - 'tax_rules_group' => array('type' => 'group_shop'), + 'attribute_group' => array('type' => 'group_shop'), + 'attribute' => array('type' => 'group_shop'), + 'feature' => array('type' => 'group_shop'), + 'group' => array('type' => 'group_shop'), + 'manufacturer' => array('type' => 'group_shop'), + 'supplier' => array('type' => 'group_shop'), + 'zone' => array('type' => 'shop'), + 'tax_rules_group' => array('type' => 'group_shop'), ); public function getFields() @@ -71,9 +71,11 @@ class GroupShopCore extends ObjectModel public static function getGroupShops($active = true) { - return Db::getInstance()->executeS('SELECT * - FROM '._DB_PREFIX_.'group_shop - WHERE `deleted`= 0 AND `active`='.(int)$active); + return Db::getInstance()->executeS(' + SELECT * + FROM '._DB_PREFIX_.'group_shop + WHERE `deleted`= 0 AND `active`='.(int)$active + ); } public function delete() @@ -81,7 +83,7 @@ class GroupShopCore extends ObjectModel if (!$res = parent::delete()) return false; - foreach (Shop::getAssoTables() AS $table_name => $row) + foreach (Shop::getAssoTables() as $table_name => $row) { $id = 'id_'.$row['type']; if ($row['type'] == 'fk_group_shop') @@ -96,7 +98,7 @@ class GroupShopCore extends ObjectModel public static function getAssoTables() { - return self::$assoTables; + return self::$assoTables; } /** @@ -104,7 +106,7 @@ class GroupShopCore extends ObjectModel */ public static function getTotalGroupShops($active = true) { - return sizeof(GroupShop::getGroupShops($active)); + return count(GroupShop::getGroupShops($active)); } public function haveShops() @@ -134,9 +136,28 @@ class GroupShopCore extends ObjectModel return (int)Db::getInstance()->getValue($sql); } + /** + * Return the list of group shop by id + * + * @param int $id + * @param string $identifier + * @param string $table + * @return array + */ + public static function getGroupShopById($id, $identifier, $table) + { + $sql = sprintf(' + SELECT `id_group_shop`, `%s` + FROM `'._DB_PREFIX_.'%s_group_shop` + WHERE `%s` = %d' + , $identifier, $table, $identifier, $id); + + return Db::getInstance()->executeS($sql); + } + public function copyGroupShopData($old_id, $tables_import = false, $deleted = false) { - foreach (GroupShop::getAssoTables() AS $table_name => $row) + foreach (GroupShop::getAssoTables() as $table_name => $row) { if ($tables_import && !isset($tables_import[$table_name])) continue; diff --git a/classes/shop/Shop.php b/classes/shop/Shop.php index 86651be98..8e00ab0a5 100644 --- a/classes/shop/Shop.php +++ b/classes/shop/Shop.php @@ -167,7 +167,10 @@ class ShopCore extends ObjectModel $id = 'id_shop'; else $table_name .= '_'.$row['type']; - $res &= Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.$table_name.'` WHERE `'.$id.'`='.(int)$this->id); + $res &= Db::getInstance()->execute(' + DELETE FROM `'._DB_PREFIX_.$table_name.'` + WHERE `'.$id.'`='.(int)$this->id + ); } Shop::cacheShops(true); @@ -183,13 +186,21 @@ class ShopCore extends ObjectModel public static function has_dependency($id_shop) { $has_dependency = false; - $nbr_customer = (int)Db::getInstance()->getValue('SELECT `id_customer` FROM `'._DB_PREFIX_.'customer` WHERE `id_shop`='.(int)$id_shop); - if($nbr_customer) + $nbr_customer = (int)Db::getInstance()->getValue(' + SELECT `id_customer` + FROM `'._DB_PREFIX_.'customer` + WHERE `id_shop`='.(int)$id_shop + ); + if ($nbr_customer) $has_dependency = true; else { - $nbr_order= (int)Db::getInstance()->getValue('SELECT `id_order` FROM `'._DB_PREFIX_.'orders` WHERE `id_shop`='.(int)$id_shop); - if($nbr_order) + $nbr_order = (int)Db::getInstance()->getValue(' + SELECT `id_order` + FROM `'._DB_PREFIX_.'orders` + WHERE `id_shop`='.(int)$id_shop + ); + if ($nbr_order) $has_dependency = true; } @@ -609,6 +620,25 @@ class ShopCore extends ObjectModel return $list; } + /** + * Return the list of shop by id + * + * @param int $id + * @param string $identifier + * @param string $table + * @return array + */ + public static function getShopById($id, $identifier, $table) + { + $sql = sprintf(' + SELECT `id_shop`, `%s` + FROM `'._DB_PREFIX_.'%s_shop` + WHERE `%s` = %d' + , $identifier, $table, $identifier, $id); + + return Db::getInstance()->executeS($sql); + } + /** * Retrieve the current shop context in FO or BO * diff --git a/controllers/admin/AdminFeaturesController.php b/controllers/admin/AdminFeaturesController.php new file mode 100644 index 000000000..744290a1e --- /dev/null +++ b/controllers/admin/AdminFeaturesController.php @@ -0,0 +1,466 @@ + +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 7331 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ +class AdminFeaturesControllerCore extends AdminController +{ + public function __construct() + { + $this->table = 'feature'; + $this->className = 'Feature'; + $this->lang = true; + + $this->fieldsDisplay = array( + 'id_feature' => array( + 'title' => $this->l('ID'), + 'width' => 25 + ), + 'name' => array( + 'title' => $this->l('Name'), + 'width' => 128, + 'filter_key' => 'b!name' + ), + 'value' => array( + 'title' => $this->l('Values'), + 'width' => 255, + 'orderby' => false, + 'search' => false + ), + 'position' => array( + 'title' => $this->l('Position'), + 'width' => 40, + 'filter_key' => 'cp!position', + 'align' => 'center', + 'position' => 'position' + ) + ); + + parent::__construct(); + } + + /** + * AdminController::initList() override + * @see AdminController::initList() + */ + public function initList() + { + $this->addRowAction('edit'); + $this->addRowAction('delete'); + $this->addRowAction('details'); + + $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); + + // Added specific button in toolbar + $this->toolbar_btn['newAttributes'] = array( + 'href' => self::$currentIndex.'&addfeature_value&token='.$this->token, + 'desc' => $this->l('Add new feature value') + ); + + $this->toolbar_btn['new'] = array( + 'href' => self::$currentIndex.'&addfeature&token='.$this->token, + 'desc' => $this->l('Add new feature') + ); + + return parent::initList(); + } + + /** + * method call when ajax request is made with the details row action + * @see AdminController::postProcess() + */ + public function ajaxProcess() + { + // test if an id is submit + if (($id = Tools::getValue('id')) && Tools::isSubmit('id')) + { + $this->table = 'feature_value'; + $this->className = 'FeatureValue'; + $this->identifier = 'id_feature_value'; + $this->lang = true; + + // override attributes + $this->display = 'list'; + + // Action for list + $this->addRowAction('edit'); + $this->addRowAction('delete'); + + $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); + + if (!Validate::isLoadedObject($obj = new FeatureValue((int)$id))) + $this->_errors[] = Tools::displayError('An error occurred while updating status for object.').' '.$this->table.' '.Tools::displayError('(cannot load object)'); + + $this->fieldsDisplay = array( + 'id_feature_value' => array( + 'title' => $this->l('ID'), + 'width' => 25 + ), + 'value' => array( + 'title' => $this->l('Value'), + 'width' => 100 + ) + ); + + $this->_where = sprintf('AND `id_feature` = %d', (int)$id); + + // get list and force no limit clause in the request + $this->getList($this->context->language->id, null); + + // Render list + $helper = new HelperList(); + $helper->actions = $this->actions; + $helper->no_link = true; + $helper->shopLinkType = ''; + $helper->identifier = $this->identifier; + $helper->toolbar_fix = false; + $helper->orderBy = 'position'; + $helper->orderWay = 'ASC'; + $helper->currentIndex = self::$currentIndex; + $helper->token = $this->token; + $helper->table = $this->table; + $helper->simple_header = true; + $helper->show_toolbar = false; + $helper->bulk_actions = $this->bulk_actions; + $content = $helper->generateList($this->_list, $this->fieldsDisplay); + + $this->content = Tools::jsonEncode(array('use_parent_structure' => false, 'data' => $content)); + } + } + + /** + * Modifying initial getList method to display position feature (drag and drop) + */ + public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false) + { + if ($order_by && $this->context->cookie->__get($this->table.'Orderby')) + $order_by = $this->context->cookie->__get($this->table.'Orderby'); + else if (!is_null($order_by)) + $order_by = 'position'; + + parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop); + } + + /** + * AdminController::initForm() override + * @see AdminController::initForm() + */ + public function initForm() + { + $this->toolbar_title = $this->l('Add a new feature'); + $this->fields_form = array( + 'legend' => array( + 'title' => $this->l('Feature'), + 'image' => '../img/t/AdminFeatures.gif' + ), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l('Name:'), + 'name' => 'name', + 'lang' => true, + 'size' => 33, + 'hint' => $this->l('Invalid characters:').' <>;=#{}', + 'required' => true + ) + ) + ); + + if (Shop::isFeatureActive()) + { + $this->fields_form['input'][] = array( + 'type' => 'group_shop', + 'label' => $this->l('GroupShop association:'), + 'name' => 'checkBoxShopAsso', + 'values' => Shop::getTree() + ); + } + + $this->fields_form['submit'] = array( + 'title' => $this->l(' Save '), + 'class' => 'button' + ); + + return parent::initForm(); + } + + /** + * AdminController::initToolbar() override + * @see AdminController::initToolbar() + */ + public function initToolbar() + { + switch ($this->display) + { + case 'editFeatureValue': + $this->toolbar_btn['save'] = array( + 'href' => '#', + 'desc' => $this->l('Save') + ); + + // Default cancel button - like old back link + if (!isset($this->no_back) || $this->no_back == false) + { + $back = Tools::safeOutput(Tools::getValue('back', '')); + if (empty($back)) + $back = self::$currentIndex.'&token='.$this->token; + + $this->toolbar_btn['cancel'] = array( + 'href' => $back, + 'desc' => $this->l('Cancel') + ); + } + break; + + default: + parent::initToolbar(); + } + } + + /** + * AdminController::initForm() override + * @see AdminController::initForm() + */ + public function initFormFeatureValue() + { + $this->fields_form[0]['form'] = array( + 'legend' => array( + 'title' => $this->l('Feature value'), + 'image' => '../img/t/AdminFeatures.gif' + ), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l('Value:'), + 'name' => 'value', + 'lang' => true, + 'size' => 33, + 'hint' => $this->l('Invalid characters:').' <>;=#{}', + 'required' => true + ), + array( + 'type' => 'select', + 'label' => $this->l('Feature:'), + 'name' => 'id_feature', + 'options' => array( + 'query' => Feature::getFeatures($this->context->language->id), + 'id' => 'id_feature', + 'name' => 'name' + ), + 'required' => true + ) + ), + 'submit' => array( + 'title' => $this->l(' Save '), + 'class' => 'button' + ) + ); + + // Create Object FeatureValue + $feature_value = new FeatureValue(Tools::getValue('id_feature_value')); + + $this->tpl_vars = array( + 'hook' => Hook::exec('featureValueForm', array('id_feature_value' => $feature_value->id)) + ); + + $this->getlanguages(); + $helper = new HelperForm(); + $helper->currentIndex = self::$currentIndex; + $helper->token = $this->token; + $helper->table = 'feature_value'; + $helper->identifier = 'id_feature_value'; + $helper->override_folder = 'feature_value/'; + $helper->id = $feature_value->id; + $helper->toolbar_fix = false; + $helper->tpl_vars = $this->tpl_vars; + $helper->languages = $this->_languages; + $helper->default_form_language = $this->default_form_language; + $helper->allow_employee_form_lang = $this->allow_employee_form_lang; + $helper->fields_value = $this->getFieldsValue($feature_value); + $helper->toolbar_btn = $this->toolbar_btn; + $helper->title = $this->l('Add a new feature value'); + $this->content .= $helper->generateForm($this->fields_form); + } + + /** + * AdminController::init() override + * @see AdminController::init() + */ + public function init() + { + if (isset($_POST['submitAddfeature_value']) || isset($_GET['updatefeature_value']) || isset($_GET['addfeature_value'])) + $this->display = 'editFeatureValue'; + + parent::init(); + } + + /** + * AdminController::initContent() override + * @see AdminController::initContent() + */ + public function initContent() + { + if (Feature::isFeatureActive()) + { + // toolbar (save, cancel, new, ..) + $this->initToolbar(); + if ($this->display == 'edit' || $this->display == 'add') + { + if (!$this->loadObject(true)) + return; + $this->content .= $this->initForm(); + } + else if ($this->display == 'view') + { + // Some controllers use the view action without an object + if ($this->className) + $this->loadObject(true); + $this->content .= $this->initView(); + } + else if ($this->display == 'editFeatureValue') + { + if (!$this->object = new FeatureValue((int)Tools::getValue('id_feature_value'))) + return; + + $this->content .= $this->initFormFeatureValue(); + } + else if (!$this->ajax) + { + $this->content .= $this->initList(); + $this->content .= $this->initOptions(); + } + } + else + $this->displayWarning($this->l('This feature has been disabled, you can active this feature at this page:').''.$this->l('Performances').''); + + $this->context->smarty->assign(array( + 'content' => $this->content, + 'url_post' => self::$currentIndex.'&token='.$this->token, + )); + } + + public function postProcess() + { + if (!Feature::isFeatureActive()) + return; + + if (Tools::isSubmit('deletefeature_value') || Tools::isSubmit('submitAddfeature_value')) + { + Hook::exec('postProcessFeatureValue', + array('errors' => &$this->_errors)); // send _errors as reference to allow postProcessFeatureValue to stop saving process + + if (Tools::isSubmit('deletefeature_value')) + { + if ($this->tabAccess['delete'] === '1') + { + if (Tools::getValue('id_feature_value')) + { + $object = new FeatureValue((int)Tools::getValue('id_feature_value')); + if ($object->delete()) + Tools::redirectAdmin(self::$currentIndex.'&conf=2'.'&token='.$this->token); + else + $this->_errors[] = Tools::displayError('An error occurred during deletion.'); + } + } + else + $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); + } + else if (Tools::isSubmit('submitAddfeature_value')) + { + $id = (int)Tools::getValue('id_feature_value'); + $feature_value = new FeatureValue($id); + $feature_value->value = array(); + $languages = Language::getLanguages(false); + foreach ($languages as $language) + $feature_value->value[$language['id_lang']] = Tools::getValue('value_'.$language['id_lang']); + $feature_value->id_feature = Tools::getValue('id_feature'); + + if (isset($id) && !empty($id)) + { + // Update + if (!$feature_value->update()) + $this->_errors[] = Tools::displayError('An error has occured: Can\'t save the current feature value'); + else + Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token); + } + else + { + // Create + if (!$feature_value->add()) + $this->_errors[] = Tools::displayError('An error has occured: Can\'t save the current feature value'); + else + Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token); + } + } + else + parent::postProcess(); + } + else + { + Hook::exec('postProcessFeature', + array('errors' => &$this->_errors)); // send _errors as reference to allow postProcessFeature to stop saving process + + if (Tools::getValue('submitDel'.$this->table)) + { + if ($this->tabAccess['delete'] === '1') + { + if (isset($_POST[$this->table.'Box'])) + { + $object = new $this->className(); + if ($object->deleteSelection($_POST[$this->table.'Box'])) + Tools::redirectAdmin(self::$currentIndex.'&conf=2'.'&token='.$this->token); + $this->_errors[] = Tools::displayError('An error occurred while deleting selection.'); + } + else + $this->_errors[] = Tools::displayError('You must select at least one element to delete.'); + } + else + $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); + } + else if (Tools::isSubmit('submitAdd'.$this->table)) + { + if ($this->tabAccess['add'] === '1') + { + $id_feature = (int)Tools::getValue('id_feature'); + // Adding last position to the feature if not exist + if ($id_feature <= 0) + { + $sql = 'SELECT `position`+1 + FROM `'._DB_PREFIX_.'feature` + ORDER BY position DESC'; + // set the position of the new feature in $_POST for postProcess() method + $_POST['position'] = DB::getInstance()->getValue($sql); + } + // clean \n\r characters + foreach ($_POST as $key => $value) + if (preg_match('/^name_/Ui', $key)) + $_POST[$key] = str_replace ('\n', '', str_replace('\r', '', $value)); + parent::postProcess(); + } + } + else + parent::postProcess(); + } + } +} diff --git a/controllers/admin/AdminManufacturersController.php b/controllers/admin/AdminManufacturersController.php index 672a04212..8739a469d 100644 --- a/controllers/admin/AdminManufacturersController.php +++ b/controllers/admin/AdminManufacturersController.php @@ -372,7 +372,7 @@ class AdminManufacturersControllerCore extends AdminController // Create Object Address $address = new Address($id_address); - $this->fields_form = array( + $form = array( 'legend' => array( 'title' => $this->l('Addresses'), 'image' => '../img/admin/contact.gif' @@ -380,7 +380,7 @@ class AdminManufacturersControllerCore extends AdminController ); if (!$address->id_manufacturer || !Manufacturer::manufacturerExists($address->id_manufacturer)) - $this->fields_form['input'][] = array( + $form['input'][] = array( 'type' => 'select', 'label' => $this->l('Choose the manufacturer:'), 'name' => 'id_manufacturer', @@ -392,24 +392,24 @@ class AdminManufacturersControllerCore extends AdminController ); else { - $this->fields_form['input'][] = array( + $form['input'][] = array( 'type' => 'text', 'label' => $this->l('Manufacturer:'), 'name' => 'name', 'disabled' => true, ); - $this->fields_form['input'][] = array( + $form['input'][] = array( 'type' => 'hidden', 'name' => 'id_manufacturer' ); } - $this->fields_form['input'][] = array( + $form['input'][] = array( 'type' => 'hidden', 'name' => 'alias', ); - $this->fields_form['input'][] = array( + $form['input'][] = array( 'type' => 'text', 'label' => $this->l('Last name:'), 'name' => 'lastname', @@ -417,7 +417,7 @@ class AdminManufacturersControllerCore extends AdminController 'required' => true, 'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%:' ); - $this->fields_form['input'][] = array( + $form['input'][] = array( 'type' => 'text', 'label' => $this->l('First name:'), 'name' => 'firstname', @@ -425,35 +425,35 @@ class AdminManufacturersControllerCore extends AdminController 'required' => true, 'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%:' ); - $this->fields_form['input'][] = array( + $form['input'][] = array( 'type' => 'text', 'label' => $this->l('Address:'), 'name' => 'address1', 'size' => 33, 'required' => true, ); - $this->fields_form['input'][] = array( + $form['input'][] = array( 'type' => 'text', 'label' => $this->l('Address (2):'), 'name' => 'address2', 'size' => 33, 'required' => false, ); - $this->fields_form['input'][] = array( + $form['input'][] = array( 'type' => 'text', 'label' => $this->l('Postcode / Zip Code:'), 'name' => 'postcode', 'size' => 33, 'required' => false, ); - $this->fields_form['input'][] = array( + $form['input'][] = array( 'type' => 'text', 'label' => $this->l('City:'), 'name' => 'city', 'size' => 33, 'required' => true, ); - $this->fields_form['input'][] = array( + $form['input'][] = array( 'type' => 'select', 'label' => $this->l('Country:'), 'name' => 'id_country', @@ -464,7 +464,7 @@ class AdminManufacturersControllerCore extends AdminController 'name' => 'name' ) ); - $this->fields_form['input'][] = array( + $form['input'][] = array( 'type' => 'select', 'label' => $this->l('State:'), 'name' => 'id_state', @@ -475,21 +475,21 @@ class AdminManufacturersControllerCore extends AdminController 'name' => 'name' ) ); - $this->fields_form['input'][] = array( + $form['input'][] = array( 'type' => 'text', 'label' => $this->l('Home phone:'), 'name' => 'phone', 'size' => 33, 'required' => false, ); - $this->fields_form['input'][] = array( + $form['input'][] = array( 'type' => 'text', 'label' => $this->l('Mobile phone:'), 'name' => 'phone_mobile', 'size' => 33, 'required' => false, ); - $this->fields_form['input'][] = array( + $form['input'][] = array( 'type' => 'textarea', 'label' => $this->l('Other:'), 'name' => 'other', @@ -498,7 +498,7 @@ class AdminManufacturersControllerCore extends AdminController 'required' => false, 'hint' => $this->l('Forbidden characters:').' <>;=#{}' ); - $this->fields_form['submit'] = array( + $form['submit'] = array( 'title' => $this->l(' Save '), 'class' => 'button' ); @@ -508,22 +508,15 @@ class AdminManufacturersControllerCore extends AdminController 'alias' => 'manufacturer' ); - $this->toolbar_btn = array( - 'save' => array( - 'href' => '#', - 'desc' => $this->l('Save') - ), - 'cancel' => array( - 'href' => self::$currentIndex.'&token='.$this->token, - 'desc' => $this->l('Cancel') - ) - ); + $this->initToolbar(); + $this->fields_form[0]['form'] = $form; $this->getlanguages(); $helper = new HelperForm(); $helper->currentIndex = self::$currentIndex; $helper->token = $this->token; $helper->table = $this->table; $helper->identifier = $this->identifier; + $helper->title = $this->l('Edit Addresses'); $helper->id = $address->id; $helper->toolbar_fix = true; $helper->languages = $this->_languages; @@ -534,6 +527,41 @@ class AdminManufacturersControllerCore extends AdminController $this->content .= $helper->generateForm($this->fields_form); } + /** + * AdminController::initToolbar() override + * @see AdminController::initToolbar() + * + */ + public function initToolbar() + { + switch ($this->display) + { + case 'editaddresses': + case 'addaddress': + $this->toolbar_btn['save'] = array( + 'href' => '#', + 'desc' => $this->l('Save') + ); + + // Default cancel button - like old back link + if (!isset($this->no_back) || $this->no_back == false) + { + $back = Tools::safeOutput(Tools::getValue('back', '')); + if (empty($back)) + $back = self::$currentIndex.'&token='.$this->token; + + $this->toolbar_btn['cancel'] = array( + 'href' => $back, + 'desc' => $this->l('Cancel') + ); + } + break; + + default: + parent::initToolbar(); + } + } + public function initView() { if (!($manufacturer = $this->loadObject())) diff --git a/controllers/admin/AdminStatusesController.php b/controllers/admin/AdminStatusesController.php index 351d3b82c..6112c75f7 100644 --- a/controllers/admin/AdminStatusesController.php +++ b/controllers/admin/AdminStatusesController.php @@ -326,7 +326,7 @@ class AdminStatusesControllerCore extends AdminController // Create Object OrderReturnState $order_return_state = new OrderReturnState($id_order_return_state); - $this->fields_form = array( + $this->fields_form[0]['form'] = array( 'tinymce' => true, 'legend' => array( 'title' => $this->l('Order statuses'), @@ -351,18 +351,7 @@ class AdminStatusesControllerCore extends AdminController ) ); - - $this->toolbar_btn = array( - 'save' => array( - 'href' => '#', - 'desc' => $this->l('Save') - ), - 'cancel' => array( - 'href' => self::$currentIndex.'&token='.$this->token, - 'desc' => $this->l('Cancel') - ) - ); - + $this->initToolbar(); $this->getlanguages(); $helper = new HelperForm(); $helper->currentIndex = self::$currentIndex; @@ -376,9 +365,44 @@ class AdminStatusesControllerCore extends AdminController $helper->allow_employee_form_lang = $this->allow_employee_form_lang; $helper->fields_value = $this->getFieldsValue($order_return_state); $helper->toolbar_btn = $this->toolbar_btn; + $helper->title = $this->l('Edit Order Statuses'); $this->content .= $helper->generateForm($this->fields_form); } + /** + * AdminController::initToolbar() override + * @see AdminController::initToolbar() + * + */ + public function initToolbar() + { + switch ($this->display) + { + case 'editstatus': + $this->toolbar_btn['save'] = array( + 'href' => '#', + 'desc' => $this->l('Save') + ); + + // Default cancel button - like old back link + if (!isset($this->no_back) || $this->no_back == false) + { + $back = Tools::safeOutput(Tools::getValue('back', '')); + if (empty($back)) + $back = self::$currentIndex.'&token='.$this->token; + + $this->toolbar_btn['cancel'] = array( + 'href' => $back, + 'desc' => $this->l('Cancel') + ); + } + break; + + default: + parent::initToolbar(); + } + } + private function getTemplates($iso_code) { $array = array(); diff --git a/controllers/admin/AdminTaxRulesGroupController.php b/controllers/admin/AdminTaxRulesGroupController.php index 845b36ec4..c6b109e50 100644 --- a/controllers/admin/AdminTaxRulesGroupController.php +++ b/controllers/admin/AdminTaxRulesGroupController.php @@ -207,7 +207,7 @@ class AdminTaxRulesGroupControllerCore extends AdminController public function initRuleForm() { - $this->fields_form = array( + $this->fields_form[0]['form'] = array( 'legend' => array( 'title' => $this->l('New tax rule'), 'image' => '../img/admin/dollar.gif'