public function getPermissions() { if (null == $this->_permissions) { $groupId = $this->getUserGroupId(); $groupRight = new Sam_Model_User_Group_Right(); $groupRights = $groupRight->fetchAll($groupRight->select()->where("groupid=?", $groupId)); foreach ($groupRights as $right) { $resource = $right->resource; $action = $right->action; $isAllow = $right->isAllow; //echo "$resource $action = $isAllow <br/>"; $this->_permissions[$resource][$action] = $isAllow; } } return $this->_permissions; }
public function permissionManagerTable($group, $readonly = true, $processUrl = '') { $this->_group = $group; $this->_processUrl = $processUrl; $request = Zend_Controller_Front::getInstance()->getRequest(); $method = $request->getParam('method'); if ($method == 'savepermission') { return $this->savePermissionHendle($request); } else { $this->_readonly = $readonly; $groupRight = new Sam_Model_User_Group_Right(); $groupid = $group->getId(); $select = $groupRight->select()->where("groupid=?", $groupid)->order("resource"); $result = $groupRight->fetchAll($select); // print_r($result); // die('ds'); $permissions = array(); foreach ($result as $right) { $action = strtolower($right->action); $allow = $right->isAllow; $resurce = strtolower($right->resource); $permissions[$resurce][$action] = $allow == 'Yes' ? 'Yes' : 'No'; } // print_r($permissions); $resource = new Sam_Model_Resource(); $resources = $resource->fetchAll(); $resourceslist = array(); foreach ($resources as $re) { $resourceName = strtolower($re->name); $strActions = strtolower($re->actions); $arActions = explode(';', $strActions); $resourceslist[$resourceName]['description'] = $re->description; $resourceslist[$resourceName]['actions'] = $arActions; } // print_r($resourceslist); // print_r($permissions); $this->_resourceslist = $resourceslist; $this->_permissions = $permissions; return $this->reder(); } }
public function permissionAction() { $request = $this->getRequest(); $this->_useAjaxLayout(); $groupid = $this->_request->getParam('id', ''); if ($groupid == '') { return $this->render('blank', null, true); } else { if ($request->getPost()) { $db = Zend_Registry::get('db'); $db->query("DELETE FROM sys_group_rights WHERE groupid=?", array($groupid)); foreach ($_POST as $key => $val) { $arKey = explode('#', $key); $resourceName = $arKey[0]; $actionName = $arKey[1]; $gr = new Sam_Model_User_Group_Right(); $gr->setGroupid($groupid)->setResource($resourceName)->setAction($actionName)->save(); } $this->view->infocode = 8; } $groupRight = new Sam_Model_User_Group_Right(); $select = $groupRight->select()->where("groupid=?", $groupid)->order("resource"); $result = $groupRight->fetchAll($select); $permissions = array(); foreach ($result as $right) { $action = $right->action; $allow = $right->isAllow; $resurce = $right->resource; $permissions[$resurce][$action] = $allow == 'Yes' ? 'Yes' : 'No'; } $resource = new Sam_Model_Resource(); $resources = $resource->fetchAll(null, 'name'); $resourceslist = array(); foreach ($resources as $re) { $resourceName = $re->name; $strActions = $re->actions; $arActions = explode(';', $strActions); $resourceslist[$resourceName]['description'] = $re->description; $resourceslist[$resourceName]['actions'] = $arActions; } $this->view->resources = $resourceslist; $this->view->permissions = $permissions; // $this->render ( 'ajaxform', null, true ); } }