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 ea1000253..1dc0a8e50 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,8 +48,8 @@ var tabnumber = tout[4]; var table = 'table#table_'+id_profile; - perfect_access_js_gestion(this, perm, id_tab, tabsize, tabnumber, table); - + perfect_access_js_gestion(this, perm, id_tab, tabsize, tabnumber, table, '{$id_tab_access}'); + $.ajax({ url: "{$link->getAdminLink('AdminAccess')}", cache: false, @@ -62,7 +62,7 @@ submitAddAccess: '1', action: 'updateAccess', ajax: '1', - token: '{getAdminToken tab='AdminAccess'}', + token: '{getAdminToken tab='AdminAccess'}' }, success : function(res,textStatus,jqXHR) { @@ -86,7 +86,7 @@ var id_module = tout[0]; var perm = tout[1]; var id_profile = tout[2]; - var enabled = $(this).is(':checked')? 1 : 0; + var enabled = $(this).is(':checked') ? 1 : 0; var table = 'table#table_module_'+id_profile; if (id_module == -1) @@ -110,7 +110,7 @@ changeModuleAccess: '1', action: 'updateModuleAccess', ajax: '1', - token: '{getAdminToken tab='AdminAccess'}', + token: '{getAdminToken tab='AdminAccess'}' }, success : function(res,textStatus,jqXHR) { diff --git a/controllers/admin/AdminAccessController.php b/controllers/admin/AdminAccessController.php index 4af49627c..4d38d8557 100644 --- a/controllers/admin/AdminAccessController.php +++ b/controllers/admin/AdminAccessController.php @@ -27,9 +27,12 @@ class AdminAccessControllerCore extends AdminController { - /* Black list of id_tab that do not have access */ + /* @var array : Black list of id_tab that do not have access */ public $accesses_black_list = array(); + /* @var int : id tab of controller AdminAccess */ + public $id_tab_access; + public function __construct() { $this->table = 'access'; @@ -40,6 +43,9 @@ class AdminAccessControllerCore extends AdminController // Blacklist AdminLogin $this->accesses_black_list[] = Tab::getIdFromClassName('AdminLogin'); + // Get id tab of controller AdminAccess + $this->id_tab_access = (int)Db::getInstance()->getValue('SELECT `id_tab` FROM `'._DB_PREFIX_.'tab` WHERE `class_name` = "AdminAccess"'); + parent::__construct(); } @@ -100,7 +106,8 @@ class AdminAccessControllerCore extends AdminController 'access_edit' => $this->tabAccess['edit'], 'perms' => array('view', 'add', 'edit', 'delete'), 'modules' => $modules, - 'link' => $this->context->link + 'link' => $this->context->link, + 'id_tab_access' => (int)$this->id_tab_access ); return parent::renderForm(); @@ -143,41 +150,37 @@ class AdminAccessControllerCore extends AdminController $enabled = (int)Tools::getValue('enabled'); $id_tab = (int)Tools::getValue('id_tab'); $id_profile = (int)Tools::getValue('id_profile'); - $res = true; if ($id_tab == -1 && $perm == 'all' && $enabled == 0) - $res &= Db::getInstance()->execute(' + $sql = ' UPDATE `'._DB_PREFIX_.'access` SET `view` = '.(int)$enabled.', `add` = '.(int)$enabled.', `edit` = '.(int)$enabled.', `delete` = '.(int)$enabled.' - WHERE `id_profile` = '.(int)$id_profile.' AND `id_tab` != 31 - '); + WHERE `id_profile` = '.(int)$id_profile.' AND `id_tab` != '.(int)$this->id_tab_access; else if ($id_tab == -1 && $perm == 'all') - $res &= Db::getInstance()->execute(' + $sql = ' UPDATE `'._DB_PREFIX_.'access` SET `view` = '.(int)$enabled.', `add` = '.(int)$enabled.', `edit` = '.(int)$enabled.', `delete` = '.(int)$enabled.' - WHERE `id_profile` = '.(int)$id_profile - ); + WHERE `id_profile` = '.(int)$id_profile; else if ($id_tab == -1) - $res &= Db::getInstance()->execute(' + $sql = ' UPDATE `'._DB_PREFIX_.'access` SET `'.bqSQL($perm).'` = '.(int)$enabled.' - WHERE `id_profile` = '.(int)$id_profile - ); + WHERE `id_profile` = '.(int)$id_profile; else if ($perm == 'all') - $res &= Db::getInstance()->execute(' + $sql = ' UPDATE `'._DB_PREFIX_.'access` SET `view` = '.(int)$enabled.', `add` = '.(int)$enabled.', `edit` = '.(int)$enabled.', `delete` = '.(int)$enabled.' WHERE `id_tab` = '.(int)$id_tab.' - AND `id_profile` = '.(int)$id_profile - ); + AND `id_profile` = '.(int)$id_profile; else - $res &= Db::getInstance()->execute(' + $sql = ' UPDATE `'._DB_PREFIX_.'access` SET `'.bqSQL($perm).'` = '.(int)$enabled.' WHERE `id_tab` = '.(int)$id_tab.' - AND `id_profile` = '.(int)$id_profile - ); - $res = $res?'ok':'error'; + AND `id_profile` = '.(int)$id_profile; + + $res = Db::getInstance()->execute($sql) ? 'ok' : 'error'; + die($res); } } @@ -194,30 +197,24 @@ class AdminAccessControllerCore extends AdminController $enabled = (int)Tools::getValue('enabled'); $id_module = (int)Tools::getValue('id_module'); $id_profile = (int)Tools::getValue('id_profile'); - $res = true; if (!in_array($perm, array('view', 'configure'))) throw new PrestaShopException('permission not exists'); if ($id_module == -1) - { - $res &= Db::getInstance()->execute(' + $sql = ' UPDATE `'._DB_PREFIX_.'module_access` SET `'.bqSQL($perm).'` = '.(int)$enabled.' - WHERE `id_profile` = '.(int)$id_profile - ); - } + WHERE `id_profile` = '.(int)$id_profile; else - { - $res &= Db::getInstance()->execute(' + $sql = ' UPDATE `'._DB_PREFIX_.'module_access` SET `'.bqSQL($perm).'` = '.(int)$enabled.' WHERE `id_module` = '.(int)$id_module.' - AND `id_profile` = '.(int)$id_profile - ); - } + AND `id_profile` = '.(int)$id_profile; + + $res = Db::getInstance()->execute($sql) ? 'ok' : 'error'; - $res = $res?'ok':'error'; die($res); } } diff --git a/js/ajax.js b/js/ajax.js index f8a80a011..a3da65806 100644 --- a/js/ajax.js +++ b/js/ajax.js @@ -87,7 +87,7 @@ function check_for_all_accesses(tabsize, tabnumber) } } -function perfect_access_js_gestion(src, action, id_tab, tabsize, tabnumber, table) +function perfect_access_js_gestion(src, action, id_tab, tabsize, tabnumber, table, id_tab_access) { if (id_tab == '-1' && action == 'all') { @@ -96,14 +96,14 @@ function perfect_access_js_gestion(src, action, id_tab, tabsize, tabnumber, tabl $(table+' .delete').attr('checked', src.checked); $(table+' .view').attr('checked', src.checked); $(table+' .all').attr('checked', src.checked); - $(table+' .31').attr('checked', "checked"); + $(table+' .'+id_tab_access).attr('checked', "checked"); } else if (action == 'all') $(table+' .'+id_tab).attr('checked', src.checked); else if (id_tab == '-1') { $(table+' .'+action).attr('checked', src.checked); - $(table+' #'+action+'31').attr('checked', "checked"); + $(table+' #'+action+id_tab_access).attr('checked', "checked"); } check_for_all_accesses(tabsize, tabnumber); }