/** * 生成act文件 */ public function createAct() { Tools::import('Model_Act'); $modelAct = new Model_Act(); $dataList = $modelAct->findAll(); $actArr = array(); foreach ($dataList as $value) { $actArr[$value['value']] = $value['allow']; } return $this->_addCache($actArr, $this->_cacheFile); }
/** * 显示权限下的所有用户 * @author doter */ function _ajaxActForUser() { $actVal = $_GET['act_val']; $this->_modelAct = $this->_getGlobalData('Model_Act', 'object'); $act_roles = $this->_modelAct->getActRoles($actVal); if ($act_roles['allow'] == 'RBAC_EVERYONE') { echo '<div id="show" style="float:left;width:100%"> 所有用户具有该权限.</div>'; return; } $act_roles = explode(',', $act_roles['allow']); //获取拥有该权限的所有用户组 $this->_modelUser = $this->_getGlobalData('Model_User', 'object'); $userList = $this->_modelUser->getAllUser(); $users = array(); foreach ($userList as $user) { $userRoles = explode(',', $user['roles']); $intersect = array_intersect($act_roles, $userRoles); $userAct = $user['act'] != '' ? explode(',', $user['act']) : array(); if (count($intersect)) { //在有用该权限的角色中 $users[] = $user; } elseif (in_array($actVal, $userAct)) { $users[] = $user; } } $str = ''; if (count($users)) { $str = '<div id="show" style="float:right;width:100%"> <ul>'; foreach ($users as $user) { $str .= '<li style="float:left;width:25%">' . $user['user_name'] . ' : ' . $user['nick_name'] . '</li>'; } $str .= '</ul></div>'; } else { } echo $str; }
public function actionEditPrem() { if ($this->_isPost()) { $roleValue = strtolower($_POST['role_value']); $selectIds = $_POST['Id']; if (!$selectIds) { $selectIds = array(); } $dataList = $this->_modelAct->findAll(); foreach ($dataList as &$value) { if ($value['allow'] == RBAC_EVERYONE) { continue; } //如果是所有用户将跳过不执行 if (empty($value['allow'])) { $roles = array(); } else { $roles = explode(',', $value['allow']); //获取当前模板的所有角色 } $key = array_search($value['Id'], $selectIds); //搜索用户是否选中此模块 if ($key === false) { //如果没有找到,就表示用户让角色对此模块没有权限,将更新此模块删除allow字段里这个角色 $rolesKey = array_search($roleValue, $roles); if ($rolesKey !== false) { unset($roles[$rolesKey]); } //如果有这个角色,将删除这个角色 $roles = implode(',', $roles); $updateArr = array('allow' => $roles); } else { //否则将加上这个角色,并且更新allow字段 $rolesKey = array_search($roleValue, $roles); if ($rolesKey !== false) { continue; } //如果找到此值,就说明此模块已经有这个角色,不用做操作. array_push($roles, $roleValue); $roles = implode(',', $roles); $updateArr = array('allow' => $roles); } $this->_modelAct->update($updateArr, "Id={$value['Id']}"); } $rbac = $this->_getGlobalData('Util_Rbac', 'object'); $rbac->createAct(); $this->_utilMsg->showMsg('更新成功', 1); } else { #------获得菜单项一维数组------# $this->_modelMenu = $this->_getGlobalData('Model_Menu', 'object'); $menuList = $this->_modelMenu->findAll(); $menuArr = array(); foreach ($menuList as $value) { $menuArr[$value['value']] = $value['name']; } #------获得菜单项一维数组------# $roleValue = strtolower($_GET['role_value']); $dataList = $this->_modelAct->findAll(); $controlList = array(); $actionList = array(); $selectedList = array(); foreach ($dataList as &$value) { $value['value'] = "{$menuArr[$value['value']]}.{$value['value']}"; $roles = explode(',', $value['allow']); if (in_array($roleValue, $roles) || $value['allow'] == RBAC_EVERYONE) { array_push($selectedList, $value['Id']); } if ($value['parent_id'] == 0) { array_push($controlList, $value); } else { array_push($actionList, $value); } } $controlList = $this->_modelAct->getTtwoArrConvertOneArr($controlList, 'Id', 'value'); $checkBox = ''; foreach ($controlList as $key => $value) { $checkBox .= '<tr><td align="left">'; $checked = in_array($key, $selectedList) ? 'checked="checked"' : ''; $checkBox .= "<input type='checkbox' value={$key} name='Id[]' {$checked} /><b>{$value}</b><hr />"; foreach ($actionList as $childValue) { if ($childValue['parent_id'] == $key) { $checked = in_array($childValue['Id'], $selectedList) ? 'checked="checked"' : ''; $checkBox .= " →<input type='checkbox' value={$childValue['Id']} name='Id[]' {$checked} />{$childValue['value']}<br/>"; } } $checkBox .= '</td></tr>'; } $this->_view->assign('checkBox', $checkBox); $this->_view->assign('roleValue', $roleValue); $this->_view->assign('css', $this->_view->get_curCss()); $this->_utilMsg->createNavBar(); $this->_view->display(); } }