* @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 AdminAccess extends AdminTab { public function postProcess() { if (Tools::isSubmit('submitAddaccess') AND $action = Tools::getValue('action') AND $id_tab = intval(Tools::getValue('id_tab')) AND $id_profile = intval(Tools::getValue('id_profile')) AND $this->tabAccess['edit'] == 1) Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'access` SET `'.pSQL($action).'` = '.intval(Tools::getValue('perm')).' WHERE `id_tab` = '.intval($id_tab).' AND `id_profile` = '.intval($id_profile)); } public function display() { $this->displayForm(); } /** * Get the current profile id * * @return the $_GET['profile'] if valid, else 1 (the first profile id) */ function getCurrentProfileId() { return (isset($_GET['profile']) AND !empty($_GET['profile']) AND is_numeric($_GET['profile'])) ? intval($_GET['profile']) : 1; } public function displayForm($isMainTab = true) { global $cookie, $currentIndex; parent::displayForm(); $currentProfile = intval($this->getCurrentProfileId()); $tabs = Tab::getTabs($cookie->id_lang); $profiles = Profile::getProfiles(intval($cookie->id_lang)); $accesses = Profile::getProfileAccesses(intval($currentProfile)); echo '
'; if (!sizeof($tabs)) echo ''; else foreach ($tabs AS $tab) if (!$tab['id_parent'] OR intval($tab['id_parent']) == -1) { $this->printTabAccess(intval($currentProfile), $tab, $accesses[$tab['id_tab']], false); foreach ($tabs AS $child) if ($child['id_parent'] === $tab['id_tab']) $this->printTabAccess($currentProfile, $child, $accesses[$child['id_tab']], true); } echo '
'.$this->l('View').' '.$this->l('Add').' '.$this->l('Edit').' '.$this->l('Delete').'
'.$this->l('No tab').'
'; } private function printTabAccess($currentProfile, $tab, $access, $is_child) { $perms = array('view', 'add', 'edit', 'delete'); echo ''.($is_child ? ' » ' : '').$tab['name'].''; foreach ($perms as $perm) if($this->tabAccess['edit'] == 1) echo ''; else echo ''; echo ''; } } ?>