[*] BO : added right of multi-shop

This commit is contained in:
lLefevre
2011-10-07 15:39:55 +00:00
parent a89f7e73b5
commit 7e7793ec5b
10 changed files with 367 additions and 258 deletions
+6 -5
View File
@@ -408,13 +408,14 @@ function generateShopList()
$value = '';
// Generate HTML
$url = $_SERVER['REQUEST_URI'] . (($_SERVER['QUERY_STRING']) ? '&' : '?') . 'setShopContext=';
$url = $_SERVER['REQUEST_URI'].(($_SERVER['QUERY_STRING']) ? '&' : '?').'setShopContext=';
$html = '<select class="shopList" onchange="location.href = \''.$url.'\'+$(this).val();">';
$html .= '<option value="" class="first">'.translate('All shops').'</option>';
foreach ($tree as $gID => $groupData)
$html .= (Context::getContext()->employee->id_profile == _PS_ADMIN_PROFILE_) ? '<option value="" class="first">'.translate('All shops').'</option>' : '';
foreach ($tree as $gID => $group_data)
{
$html .= '<option class="group" value="g-'.$gID.'" '.(($value == 'g-'.$gID) ? 'selected="selected"' : '').'>'.htmlspecialchars($groupData['name']).'</option>';
foreach ($groupData['shops'] as $sID => $shopData)
$disabled = ($group_data['totalShops'] != count($group_data['shops'])) ? 'disabled="disabled"' : '';
$html .= '<option class="group" value="g-'.$gID.'" '.(($value == 'g-'.$gID) ? 'selected="selected"' : '').' '.$disabled.'>'.htmlspecialchars($group_data['name']).'</option>';
foreach ($group_data['shops'] as $sID => $shopData)
if ($shopData['active'])
$html .= '<option value="s-'.$sID.'" class="shop" '.(($value == 's-'.$sID) ? 'selected="selected"' : '').'>&raquo; '.$shopData['name'].'</option>';
}
+50 -24
View File
@@ -34,21 +34,21 @@ class AdminEmployees extends AdminTab
{
$this->context = Context::getContext();
$this->table = 'employee';
$this->className = 'Employee';
$this->className = 'Employee';
$this->lang = false;
$this->edit = true;
$this->delete = true;
$this->delete = true;
$this->_select = 'pl.`name` AS profile';
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'profile` p ON a.`id_profile` = p.`id_profile`
LEFT JOIN `'._DB_PREFIX_.'profile_lang` pl ON (pl.`id_profile` = p.`id_profile` AND pl.`id_lang` = '.(int)$this->context->language->id.')';
$profiles = Profile::getProfiles($this->context->language->id);
if (!$profiles)
$this->_errors[] = Tools::displayError('No profile');
else
foreach ($profiles AS $profile)
foreach ($profiles as $profile)
$this->profilesArray[$profile['name']] = $profile['name'];
$this->fieldsDisplay = array(
'id_employee' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'lastname' => array('title' => $this->l('Last name'), 'width' => 130),
@@ -64,8 +64,8 @@ class AdminEmployees extends AdminTab
'fields' => array(
'PS_PASSWD_TIME_BACK' => array('title' => $this->l('Password regenerate:'), 'desc' => $this->l('Security minimum time to wait to regenerate a new password'), 'cast' => 'intval', 'size' => 5, 'type' => 'text', 'suffix' => ' '.$this->l('minutes'), 'visibility' => Shop::CONTEXT_ALL),
'PS_BO_ALLOW_EMPLOYEE_FORM_LANG' => array('title' => $this->l('Memorize form language:'), 'desc' => $this->l('Allow employees to save their own default form language'), 'cast' => 'intval', 'type' => 'select', 'identifier' => 'value', 'list' => array(
'0' => array('value' => 0, 'name' => $this->l('No')),
'1' => array('value' => 1, 'name' => $this->l('Yes'))
'0' => array('value' => 0, 'name' => $this->l('No')),
'1' => array('value' => 1, 'name' => $this->l('Yes'))
), 'visibility' => Shop::CONTEXT_ALL)
),
),
@@ -73,22 +73,22 @@ class AdminEmployees extends AdminTab
parent::__construct();
}
protected function _childValidation()
protected function _childValidation()
{
if (!($obj = $this->loadObject(true)))
return false;
$email = $this->getFieldValue($obj, 'email');
if (!Validate::isEmail($email))
$this->_errors[] = Tools::displayError('Invalid e-mail');
else if (Employee::employeeExists($email) AND !Tools::getValue('id_employee'))
else if (Employee::employeeExists($email) && !Tools::getValue('id_employee'))
$this->_errors[] = Tools::displayError('An account already exists for this e-mail address:').' '.$email;
}
public function displayForm($isMainTab = true)
{
parent::displayForm();
if (!($obj = $this->loadObject(true)))
return;
$profiles = Profile::getProfiles($this->context->language->id);
@@ -138,7 +138,7 @@ class AdminEmployees extends AdminTab
<select name="bo_theme">';
$path = dirname(__FILE__).'/../themes/';
foreach (scandir($path) as $theme)
if ($theme[0] != '.' AND file_exists($path.$theme.'/admin.css'))
if ($theme[0] != '.' && file_exists($path.$theme.'/admin.css'))
echo ' <option value="'.Tools::htmlentitiesUTF8($theme).'" '.($this->getFieldValue($obj, 'bo_theme') == $theme ? 'selected="selected"' : '').'>'.Tools::htmlentitiesUTF8($theme).'</option>';
echo ' </select> <sup>*</sup>
</div>';
@@ -172,10 +172,32 @@ class AdminEmployees extends AdminTab
<div class="margin-form">
<select name="id_profile">
<option value="">'.$this->l('-- Choose --').'</option>';
foreach ($profiles AS $profile)
foreach ($profiles as $profile)
echo '<option value="'.$profile['id_profile'].'"'.($profile['id_profile'] === $this->getFieldValue($obj, 'id_profile') ? ' selected="selected"' : '').'>'.$profile['name'].'</option>';
echo '</select> <sup>*</sup>
</div>';
if (Shop::isMultiShopActivated())
{
echo '
<script type="text/javascript">
$(document).ready(function(){
$(\'select[name=id_profile]\').change(function(){
var val = $(this).val();
if(val == '._PS_ADMIN_PROFILE_.')
{
$(\'.assoShop input[type=checkbox]\').attr(\'disabled\', \'disabled\');
$(\'.assoShop input[type=checkbox]\').attr(\'checked\', \'checked\');
}
else
$(\'.assoShop input[type=checkbox]\').attr(\'disabled\', \'\');
});
});
</script>
';
echo '<label>'.$this->l('Shop association:').'</label><div class="margin-form">';
$this->displayAssoShop();
echo '</div>';
}
}
echo '<div class="clear">&nbsp;</div>
<center>
@@ -185,47 +207,51 @@ class AdminEmployees extends AdminTab
</fieldset>
</form>';
}
public function postProcess()
{
$this->context = Context::getContext();
if (Tools::isSubmit('deleteemployee') OR Tools::isSubmit('status') OR Tools::isSubmit('statusemployee'))
$this->context = Context::getContext();
if (Tools::isSubmit('deleteemployee') || Tools::isSubmit('status') || Tools::isSubmit('statusemployee'))
{
if ($this->context->employee->id == Tools::getValue('id_employee'))
{
$this->_errors[] = Tools::displayError('You cannot disable or delete your own account.');
return false;
}
$employee = new Employee(Tools::getValue('id_employee'));
if ($employee->isLastAdmin())
if ($employee->isLastAdmin())
{
$this->_errors[] = Tools::displayError('You cannot disable or delete the last administrator account.');
return false;
}
}
elseif (Tools::isSubmit('submitAddemployee'))
else if (Tools::isSubmit('submitAddemployee'))
{
$employee = new Employee((int)Tools::getValue('id_employee'));
if (!(int)$this->tabAccess['edit'])
$_POST['id_profile'] = $_GET['id_profile'] = $employee->id_profile;
if ($employee->isLastAdmin())
if ($employee->isLastAdmin())
{
if (Tools::getValue('id_profile') != (int)_PS_ADMIN_PROFILE_)
if (Tools::getValue('id_profile') != (int)_PS_ADMIN_PROFILE_)
{
$this->_errors[] = Tools::displayError('You should have at least one employee in the administrator group.');
return false;
}
if (Tools::getvalue('active') == 0)
{
$this->_errors[] = Tools::displayError('You cannot disable or delete the last administrator account.');
return false;
}
}
$assos = self::getAssoShop($this->table);
if (!count($assos[0]) && $this->table = 'employee')
$this->_errors[] = Tools::displayError('The employee must be associated with at least one shop');
}
return parent::postProcess();
}
}
+6 -6
View File
@@ -32,12 +32,12 @@ class AdminShop extends AdminTab
{
$this->context = Context::getContext();
$this->table = 'shop';
$this->className = 'Shop';
$this->className = 'Shop';
$this->edit = true;
$this->delete = false;
$this->deleted = false;
$this->_select = 'gs.name group_shop_name, cl.name category_name';
$this->_select = 'gs.name group_shop_name, cl.name category_name';
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'group_shop` gs ON (a.id_group_shop = gs.id_group_shop)
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (a.id_category = cl.id_category AND cl.id_lang='.(int)$this->context->language->id.')';
$this->_group = 'GROUP BY a.id_shop';
@@ -66,7 +66,7 @@ class AdminShop extends AdminTab
if (Tools::getValue('useImportData') && ($importData = Tools::getValue('importData')) && is_array($importData))
$newShop->copyShopData((int)Tools::getValue('importFromShop'), $importData);
}
public function afterUpdate($newShop)
{
if (Tools::getValue('useImportData') && ($importData = Tools::getValue('importData')) && is_array($importData))
@@ -82,7 +82,7 @@ class AdminShop extends AdminTab
else if (Shop::getTotalShops() == 1)
$this->_errors[] = Tools::displayError('You cannot disable the last shop.');
}
if ($this->_errors)
return false;
return parent::postProcess();
@@ -133,7 +133,7 @@ class AdminShop extends AdminTab
else
{
echo '<select '.$disabled.' name="id_group_shop" id="id_group_shop">';
foreach (GroupShop::getGroupShops() AS $group)
foreach (GroupShop::getGroupShops() as $group)
echo '<option value="'.(int)$group['id_group_shop'].'" '.($obj->id_group_shop == $group['id_group_shop'] ? 'selected="selected"' : '').'">'.$group['name'].'</option>';
echo '</select>';
}