* @copyright PrestaShop
* @license http://www.opensource.org/licenses/osl-3.0.php Open-source licence 3.0
* @version 1.3
*
*/
include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php');
class AdminGroups extends AdminTab
{
public function __construct()
{
$this->table = 'group';
$this->className = 'Group';
$this->lang = true;
$this->edit = true;
$this->view = true;
$this->delete = true;
$this->_select = '
(SELECT COUNT(jcg.`id_customer`)
FROM `'._DB_PREFIX_.'customer_group` jcg
LEFT JOIN `'._DB_PREFIX_.'customer` jc ON (jc.`id_customer` = jcg.`id_customer`)
WHERE jc.`deleted` != 1
AND jcg.`id_group` = a.`id_group`) AS nb
';
$this->_group = 'GROUP BY a.id_group';
$this->_listSkipDelete = array(1);
$this->fieldsDisplay = array(
'id_group' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'name' => array('title' => $this->l('Name'), 'width' => 80, 'filter_key' => 'b!name'),
'reduction' => array('title' => $this->l('Reduction'), 'width' => 50, 'align' => 'right'),
'nb' => array('title' => $this->l('Members'), 'width' => 25, 'align' => 'center'),
'date_add' => array('title' => $this->l('Creation date'), 'width' => 60, 'type' => 'date'));
parent::__construct();
}
public function displayForm($isMainTab = true)
{
global $currentIndex;
parent::displayForm();
$obj = $this->loadObject(true);
echo '
';
}
public function viewgroup()
{
global $cookie;
$currentIndex = 'index.php?tab=AdminGroups';
$obj = $this->loadObject(true);
$group = new Group(intval($obj->id));
$defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
echo '
';
$customers = $obj->getCustomers();
$this->fieldsDisplay = (array(
'ID' => array('title' => $this->l('ID')),
'sex' => array('title' => $this->l('Sex')),
'name' => array('title' => $this->l('Name')),
'e-mail' => array('title' => $this->l('e-mail')),
'birthdate' => array('title' => $this->l('Birth date')),
'register_date' => array('title' => $this->l('Register date')),
'orders' => array('title' => $this->l('Orders')),
'status' => array('title' => $this->l('Status')),
'actions' => array('title' => $this->l('Actions'))
));
if (isset($customers) AND !empty($customers) AND $nbCustomers = sizeof($customers))
{
echo ''.$this->l('Customers member of this group').' ('.$nbCustomers.')
';
foreach ($this->fieldsDisplay AS $field)
echo '| '.$field['title'].' | ';
echo '
';
$irow = 0;
foreach ($customers AS $k => $customer)
{
$imgGender = $customer['id_gender'] == 1 ? '
' : ($customer['id_gender'] == 2 ? '
' : '');
echo '
| '.$customer['id_customer'].' |
'.$imgGender.' |
'.stripslashes($customer['lastname']).' '.stripslashes($customer['firstname']).' |
'.stripslashes($customer['email']).'  |
'.Tools::displayDate($customer['birthday'], intval($cookie->id_lang)).' |
'.Tools::displayDate($customer['date_add'], intval($cookie->id_lang)).' |
'.Order::getCustomerNbOrders($customer['id_customer']).' |
.') |
|
';
}
echo '
';
}
else
echo '
'.$this->l('No user in this group.').'
';
}
public function postProcess()
{
global $currentIndex;
$token = Tools::getValue('token') ? Tools::getValue('token') : $this->token;
if (Tools::isSubmit('submitAddgroup'))
{
if (Tools::getValue('reduction') > 100 OR Tools::getValue('reduction') < 0)
$this->_errors[] = Tools::displayError('reduction value is incorrect');
else
return parent::postProcess();
}
elseif (isset($_GET['delete'.$this->table]))
{
if ($this->tabAccess['delete'] === '1')
{
if (Validate::isLoadedObject($object = $this->loadObject()))
{
if ($object->id == 1)
$this->_errors[] = Tools::displayError('You cannot delete default group');
else
{
if ($object->delete())
Tools::redirectAdmin($currentIndex.'&conf=1&token='.$token);
$this->_errors[] = Tools::displayError('an error occurred during deletion');
}
}
else
$this->_errors[] = Tools::displayError('an error occurred while deleting object').' '.$this->table.' '.Tools::displayError('(cannot load object)');
}
else
$this->_errors[] = Tools::displayError('You do not have permission to delete here.');
}
else
parent::postProcess();
}
}