* @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::isMultiShopActivated()) { echo '
'; $this->displayAssoShop('group_shop'); echo '
'; } echo ' '.Module::hookExec('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); Module::hookExec('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(); } }