* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7465 $
* @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_.'/../classes/AdminTab.php');
include_once(_PS_ADMIN_DIR_.'/tabs/AdminAttributes.php');
class AdminAttributesGroups extends AdminTab
{
/** @var object AdminAttributes() instance */
private $adminAttributes;
public function __construct()
{
$this->adminAttributes = new AdminAttributes();
$this->table = 'attribute_group';
$this->className = 'AttributeGroup';
$this->lang = true;
$this->edit = true;
$this->delete = true;
$this->fieldsDisplay = array(
'name' => array('title' => $this->l('Name'), 'width' => 140, 'filter_key' => 'b!name'),
'attribute' => array('title' => $this->l('Attributes'), 'width' => 240, '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 (Combination::isFeatureActive())
{
if ((isset($_POST['submitAddattribute']) AND sizeof($this->adminAttributes->_errors))
OR isset($_GET['updateattribute']) OR isset($_GET['addattribute']))
{
$this->adminAttributes->displayForm($this->token);
echo '
'.$this->l('Back to 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').'');
}
public function postProcess()
{
if (!Combination::isFeatureActive())
return;
$this->adminAttributes->tabAccess = Profile::getProfileAccess(Context::getContext()->employee->id_profile, $this->id);
if (Tools::isSubmit('submitAddattribute') || Tools::isSubmit('submitDelattribute'))
$this->adminAttributes->postProcess($this->token);
Module::hookExec('postProcessAttributeGroup',
array('errors' => &$this->_errors)); // send _errors as reference to allow postProcessAttributeGroup 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.');
// clean position after delete
AttributeGroup::cleanPositions();
}
else if (Tools::isSubmit('submitAdd'.$this->table))
{
$id_attribute_group = (int)Tools::getValue('id_attribute_group');
// Adding last position to the attribute if not exist
if ($id_attribute_group <= 0)
{
$sql = 'SELECT `position`+1
FROM `'._DB_PREFIX_.'attribute_group`
ORDER BY position DESC';
// set the position of the new group attribute 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();
}
public function displayErrors()
{
$this->adminAttributes->displayErrors();
parent::displayErrors();
}
/* Report to AdminTab::displayList() for more details */
public function displayList()
{
echo '
'.$this->l('Add attributes group').'
'.$this->l('Add attribute').'
'.$this->l('Click on the group name to view its attributes. Click again to hide them.').'
';
if ($this->_list === false)
Tools::displayError('No elements found');
$this->displayListHeader($this->token);
echo '';
if (!sizeof($this->_list))
echo '
';
echo '
';
}
else
echo (int)($tr['position'] + 1);
echo '