From 3c8af49bdb2de044990c83a9535f2a6598dc20eb Mon Sep 17 00:00:00 2001 From: vChabot Date: Mon, 2 Apr 2012 10:05:24 +0000 Subject: [PATCH] [-] BO : BugFix : #PSTEST-1054 : Employees and permission updated git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@14401 b9a71923-0436-4b27-9f14-aed3839534dd --- .../controllers/access/helpers/form/form.tpl | 39 ++++++++++++++++++- .../employees/helpers/form/form.tpl | 28 ++++++++++++- classes/Tab.php | 19 +++++++++ controllers/admin/AdminAccessController.php | 23 +++++++---- .../admin/AdminEmployeesController.php | 18 +++++++++ 5 files changed, 117 insertions(+), 10 deletions(-) diff --git a/admin-dev/themes/default/template/controllers/access/helpers/form/form.tpl b/admin-dev/themes/default/template/controllers/access/helpers/form/form.tpl index 01e5f1b85..cc58dd17c 100644 --- a/admin-dev/themes/default/template/controllers/access/helpers/form/form.tpl +++ b/admin-dev/themes/default/template/controllers/access/helpers/form/form.tpl @@ -48,6 +48,41 @@ var tabnumber = tout[4]; var table = 'table#table_'+id_profile; + if (perm == 'all' && $(this).parent().parent().hasClass('parent')) + { + checked = enabled ? 'checked': ''; + $(this).parent().parent().parent().find('.child-'+id_tab+' input[type=checkbox]').attr('checked', checked); + $.ajax({ + url: "{$link->getAdminLink('AdminAccess')}", + cache: false, + data : { + ajaxMode : '1', + id_tab: id_tab, + id_profile: id_profile, + perm: perm, + enabled: enabled, + submitAddAccess: '1', + addFromParent: '1', + action: 'updateAccess', + ajax: '1', + token: '{getAdminToken tab='AdminAccess'}' + }, + success : function(res,textStatus,jqXHR) + { + try + { + if (res == 'ok') + showSuccessMessage("{l s='Update successful'}"); + else + showErrorMessage("{l s='Update error'}"); + } + catch(e) + { + jAlert('Technical error'); + } + } + }); + } perfect_access_js_gestion(this, perm, id_tab, tabsize, tabnumber, table, '{$id_tab_access}'); $.ajax({ @@ -236,7 +271,7 @@ {if !$tab.id_parent OR $tab.id_parent == -1} {assign var=is_child value=false} {assign var=result_accesses value=0} - + {if $is_child} » {/if}{$tab.name} {foreach $perms as $perm} {if $access_edit == 1} @@ -275,7 +310,7 @@ {if isset($access[$child.id_tab])} {assign var=is_child value=true} {assign var=result_accesses value=0} - + {if $is_child} » {/if}{$child.name} {foreach $perms as $perm} {if $access_edit == 1} diff --git a/admin-dev/themes/default/template/controllers/employees/helpers/form/form.tpl b/admin-dev/themes/default/template/controllers/employees/helpers/form/form.tpl index ee711e522..4835e9f21 100644 --- a/admin-dev/themes/default/template/controllers/employees/helpers/form/form.tpl +++ b/admin-dev/themes/default/template/controllers/employees/helpers/form/form.tpl @@ -59,8 +59,34 @@ $(document).ready(function(){ $('select[name=id_profile]').change(function(){ ifSuperAdmin($(this)); - }); + $.ajax({ + url: "{$link->getAdminLink('AdminEmployees')}", + cache: false, + data : { + ajax : '1', + action : 'getTabByIdProfile', + id_profile : $(this).val() + }, + dataType : 'json', + success : function(resp,textStatus,jqXHR) + { + if (resp != false) + { + $('select[name=default_tab]').html(''); + $.each(resp, function(key, r){ + if (r.id_parent == 0) + { + $('select[name=default_tab]').append(''); + $.each(r.children, function(k, value){ + $('select[name=default_tab]').append('') + }); + } + }); + } + } + }); + }); ifSuperAdmin($('select[name=id_profile]')); }); diff --git a/classes/Tab.php b/classes/Tab.php index c2ee9aac1..d4b65773d 100644 --- a/classes/Tab.php +++ b/classes/Tab.php @@ -464,4 +464,23 @@ class TabCore extends ObjectModel return parent::update($null_values); } + + public static function getTabByIdProfile($id_parent, $id_profile) + { + return Db::getInstance()->executeS(' + SELECT t.`id_tab`, t.`id_parent`, tl.`name`, a.`id_profile` + FROM `'._DB_PREFIX_.'tab` t + LEFT JOIN `'._DB_PREFIX_.'access` a + ON (a.`id_tab` = t.`id_tab`) + LEFT JOIN `'._DB_PREFIX_.'tab_lang` tl + ON (t.`id_tab` = tl.`id_tab` AND tl.`id_lang` = '.(int)Context::getContext()->language->id.') + WHERE a.`id_profile` = '.(int)$id_profile.' + AND t.`id_parent` = '.(int)$id_parent.' + AND a.`view` = 1 + AND a.`edit` = 1 + AND a.`delete` = 1 + AND a.`add` = 1 + ORDER BY t.`id_parent` ASC + '); + } } diff --git a/controllers/admin/AdminAccessController.php b/controllers/admin/AdminAccessController.php index 4d38d8557..9a39ffac5 100644 --- a/controllers/admin/AdminAccessController.php +++ b/controllers/admin/AdminAccessController.php @@ -150,33 +150,42 @@ class AdminAccessControllerCore extends AdminController $enabled = (int)Tools::getValue('enabled'); $id_tab = (int)Tools::getValue('id_tab'); $id_profile = (int)Tools::getValue('id_profile'); + $where = '`id_tab`'; + $join = ''; + if (Tools::isSubmit('addFromParent')) + { + $where = 't.`id_parent`'; + $join = 'LEFT JOIN `'._DB_PREFIX_.'tab` t ON (t.`id_tab` = a.`id_tab`)'; + } if ($id_tab == -1 && $perm == 'all' && $enabled == 0) $sql = ' - UPDATE `'._DB_PREFIX_.'access` + UPDATE `'._DB_PREFIX_.'access` a SET `view` = '.(int)$enabled.', `add` = '.(int)$enabled.', `edit` = '.(int)$enabled.', `delete` = '.(int)$enabled.' WHERE `id_profile` = '.(int)$id_profile.' AND `id_tab` != '.(int)$this->id_tab_access; else if ($id_tab == -1 && $perm == 'all') $sql = ' - UPDATE `'._DB_PREFIX_.'access` + UPDATE `'._DB_PREFIX_.'access` a SET `view` = '.(int)$enabled.', `add` = '.(int)$enabled.', `edit` = '.(int)$enabled.', `delete` = '.(int)$enabled.' WHERE `id_profile` = '.(int)$id_profile; else if ($id_tab == -1) $sql = ' - UPDATE `'._DB_PREFIX_.'access` + UPDATE `'._DB_PREFIX_.'access` a SET `'.bqSQL($perm).'` = '.(int)$enabled.' WHERE `id_profile` = '.(int)$id_profile; else if ($perm == 'all') $sql = ' - UPDATE `'._DB_PREFIX_.'access` + UPDATE `'._DB_PREFIX_.'access` a + '.$join.' SET `view` = '.(int)$enabled.', `add` = '.(int)$enabled.', `edit` = '.(int)$enabled.', `delete` = '.(int)$enabled.' - WHERE `id_tab` = '.(int)$id_tab.' + WHERE '.bqSQL($where).' = '.(int)$id_tab.' AND `id_profile` = '.(int)$id_profile; else $sql = ' - UPDATE `'._DB_PREFIX_.'access` + UPDATE `'._DB_PREFIX_.'access` a + '.$join.' SET `'.bqSQL($perm).'` = '.(int)$enabled.' - WHERE `id_tab` = '.(int)$id_tab.' + WHERE '.bqSQL($where).' = '.(int)$id_tab.' AND `id_profile` = '.(int)$id_profile; $res = Db::getInstance()->execute($sql) ? 'ok' : 'error'; diff --git a/controllers/admin/AdminEmployeesController.php b/controllers/admin/AdminEmployeesController.php index 3a81249b2..9e7618aca 100644 --- a/controllers/admin/AdminEmployeesController.php +++ b/controllers/admin/AdminEmployeesController.php @@ -421,6 +421,24 @@ class AdminEmployeesControllerCore extends AdminController return parent::initContent(); } + + public function ajaxProcessGetTabByIdProfile() + { + $id_profile = Tools::getValue('id_profile'); + $tabs = Tab::getTabByIdProfile(0, $id_profile); + $this->tabs_list = array(); + foreach ($tabs as $tab) + { + if (Tab::checkTabRights($tab['id_tab'])) + { + $this->tabs_list[$tab['id_tab']] = $tab; + foreach (Tab::getTabByIdProfile($tab['id_tab'], $id_profile) as $children) + if (Tab::checkTabRights($children['id_tab'])) + $this->tabs_list[$tab['id_tab']]['children'][] = $children; + } + } + die(Tools::jsonEncode($this->tabs_list)); + } }