/** * 递归重组节点信息为多维数组 */ function node_merge($node, $access = null, $pid = 0) { // p($node); $arr = array(); foreach ($node as $v) { if (is_array($access)) { // echo "mark"; // p($access); // p($v); $v['access'] = in_array($v['id'], $access) ? 1 : 0; // p($v['access']); } // p($v); // die(); if ($v['pid'] == $pid) { // p($v); // die(); $v['child'] = node_merge($node, $access, $v['id']); // p($v['child']); $arr[] = $v; // p($arr[]); } // p($v); } return $arr; }
public function access() { $rid = I('rid', 0, 'intval'); $node = M('node')->order('sort')->select(); $access = M('access')->where(array('role_id' => $rid))->getField('node_id', true); $this->node = node_merge($node, $access); $this->rid = $rid; $this->display(); }
public function __construct() { parent::__construct(); $menu = D('Menu'); $map['status'] = 1; $this->menu = node_merge($menu->getAllMenu($map)); $this->remark = CONTROLLER_NAME . '/' . ACTION_NAME; $this->controller = CONTROLLER_NAME; //dd($this->menu); }
public function checkAuth() { $ci =& get_instance(); $module = strtolower($ci->uri->segment(1)); if ($module == 'admin') { // 判断已登录 $user = $ci->session->userdata('user'); // 登录方法做是否已登录判断 $action = strtolower($ci->uri->segment(3)); $controller = strtolower($ci->uri->segment(2)); if ($user && $action == 'login') { redirect('/admin/main/index'); } else { if (!$user && $action != 'login') { redirect('/admin/login/login'); } } $noauth = $ci->config->item('noauth_controller'); $ci->load->model('M_node', 'node'); $list = $ci->node->getList(array('ASC' => 'sort', 'id_in' => $user['node'])); $open = 0; $actId = 0; $nav = array('首页', '网站信息'); foreach ($list as $k => $v) { $con = explode('/', $v['name']); $num = count($con); if (strtolower($con[0]) == $controller && $num > 1) { $open = $v['pid']; $nav = array($list[$v['pid']]['title'], $v['title']); foreach ($list as $val) { if ($val['pid'] == $v['id'] && $action == strtolower($val['name'])) { $actId = $val['id']; break; } } break; } } $list = node_merge($list); $ci->assign('leftnav', $list); $ci->assign('open', $open); if (!in_array(ucwords($controller), $noauth)) { if ($open <= 0 || $actId <= 0) { $json = $ci->input->get('json'); if (isset($json) && $json == 1) { $ci->outJson(101, '', '对不起,您没有权限操作此项!'); } $ci->error('对不起,您没有权限操作此项!', 2); } } $ci->assign('nav', $nav); } // show_error('您无权访问该功能,该错误已经被记录!点击<a href="'. site_url('admin/main/index') .'">返回</a>'); }
/** * 递归重组节点信息 */ function node_merge($node, $pid = 0) { $arr = array(); foreach ($node as $v) { if ($v['pid'] == $pid) { $v['child'] = node_merge($node, $v['id']); $arr[] = $v; } } return $arr; }
public function edit() { $rid = I('role_id', 0, 'intval'); $field = array('id', 'name', 'title', 'pid'); $node = M('node')->order('sort')->field($field)->select(); //原有权限 $access = M('access')->where(array('role_id' => $rid))->getField('node_id', true); $node = node_merge($node, $access); //组装数组 $this->assign('node', $node); $this->assign('rid', $rid); $this->display(); }
public function index() { if (IS_POST) { M('Admin')->data(I("post."))->save(); $this->mtReturn(200, '保存成功', '', true); } $menu = D('Menu'); $map['status'] = 1; $this->menu = node_merge($menu->getAllMenu($map)); $Rs = M('Admin')->find(session('uid')); $this->assign('Rs', $Rs); $this->display(); }
function node_merge($node, $access = null, $pid = 0) { $arr = array(); foreach ($node as $v) { if (is_array($access)) { $v['access'] = in_array($v['id'], $access) ? 1 : 0; } if ($v['pid'] == $pid) { $v['child'] = node_merge($node, $access, $v['id']); $arr[] = $v; } } return $arr; }
function node_merge($node, $access = null, $pid = 0) { $arr = array(); //本轮数组初始为空 foreach ($node as $v) { if (is_array($access)) { $v['access'] = in_array($v['id'], $access) ? 1 : 0; } if ($v['pid'] == $pid) { //筛选本轮合格的对象 $v['child'] = node_merge($node, $access, $v['id']); //将上级返回的数组写入['child'] $arr[] = $v; //将自己写入本轮数组 } } return $arr; //返回给上级['child'] }
public function add() { $input = $this->input->post(); if ($input) { $this->load->library('form_validation'); $this->form_validation->set_data($input); $this->form_validation->set_rules($this->rules); if ($this->form_validation->run() == TRUE) { $input['time'] = time(); if (isset($input['id'])) { $res = $this->node->update($input, 'id'); } else { $res = $this->node->add($input); } if ($res) { $this->outJson(0); } else { $this->outJson(1); } } else { $this->outJson(101, '', current($this->form_validation->error_array())); } } else { $id = $this->input->get('id'); $data = array(); if ($id) { $data = $this->node->getOne($id); if (!$data) { $this->error('节点不存在'); } } // echo '<pre>';print_r($data);die; $list = $this->node->getAll(); $list = node_merge($list); $this->assign('list', $list); $this->assign('data', $data); $this->display(); } }
public function add() { $input = $this->input->post(); if ($input) { $this->load->library('form_validation'); $this->form_validation->set_data($input); $this->form_validation->set_rules($this->rules); if ($this->form_validation->run() == TRUE) { $input['time'] = time(); if (isset($input['id'])) { $res = $this->category->update($input, 'id'); } else { $res = $this->category->add($input); } if ($res) { $this->outJson(0); } else { $this->outJson(1); } } else { $this->outJson(101, '', current($this->form_validation->error_array())); } } else { $id = $this->input->get('id'); $cate = array(); if ($id) { $cate = $this->category->getOne($id); if (!$cate) { $this->error('分类不存在'); } } $this->assign('cate', $cate); $list = $this->category->getAll(); $list = node_merge($list); $this->assign('list', $list); $this->display(); } }
public function access() { if (IS_POST) { $rid = isset($_POST['rid']) ? $_POST['rid'] : 0; $arr = array(); $acc = M('access'); $acc->where('role_id=' . $rid)->delete(); foreach ($_POST['access'] as $v) { $tmp = explode('_', $v); // p($tmp); $arr[] = array('role_id' => $rid, 'node_id' => $tmp[0], 'level' => $tmp[1]); } // p($arr);die; $res = $acc->addAll($arr); if ($res) { $this->success('权限修改成功', U('adminList')); } else { $this->error('权限修改失败', U('access')); } return; } $rid = isset($_GET['rid']) ? $_GET['rid'] : 0; $res = K('Node')->getNode(); $acc = M('access')->where('role_id=' . $rid)->all(); if (!$res) { $res = 0; } $role = array(); foreach ($acc as $v) { $role[] = $v['node_id']; } $res = node_merge($res, $role); $this->assign('node', $res); $this->assign('rid', $rid); $this->display(); }
public function add() { $input = $this->input->post(); if ($input) { // print_r($input);die; $this->load->library('form_validation'); $this->form_validation->set_data($input); $this->form_validation->set_rules($this->rules); if ($this->form_validation->run() == TRUE) { $user = $this->session->userdata('user'); $input['userid'] = $user['info']['id']; $input['publish_time'] = strtotime($input['publish_time']); if (isset($input['id'])) { $input['update_time'] = time(); $res = $this->article->update($input, 'id'); } else { $input['time'] = time(); $res = $this->article->add($input); } if ($res) { $this->outJson(0); } else { $this->outJson(1); } } else { $this->outJson(101, '', current($this->form_validation->error_array())); } } else { $id = $this->input->get('id'); $article = array(); if ($id) { $article = $this->article->getOne($id); if (!$article) { $this->error('文章不存在'); } $this->load->model('M_Admin', 'user'); $user = $this->user->getUserById($article['userid']); $article['username'] = $user['username']; } $this->assign('article', $article); $list = $this->category->getAll(); $list = node_merge($list); $this->assign('list', $list); $this->display(); } }
/** * [cate_list 公共的无限级分类] * @param [type] $model [description] * @return [type] [description] */ public function cate_list($model, $where = array(), $order = array()) { $list = $model->where($where)->order($order)->select(); return node_merge($list); }
public function access() { $rid = $_GET['rid']; //读取有用字段 $field = array('id', 'name', 'title', 'pid'); $node = M('node')->order('sort')->field($field)->select(); //读取用户原有权限 $access = M('access')->where(array('role_id' => $rid))->getField('node_id', true); $node = node_merge($node, $access); $this->assign('rid', $rid); $this->assign('node', $node); $this->display(); }
public function getwhere() { $info = D('Node')->getRbac($_SESSION['id']); $list = node_merge($info); foreach ($list as $k => $v) { foreach ($v['child'] as $key => $va) { $list[$k]['child'][$key]['url'] = U($va['name'] . '/index'); } } return $list; //$result=M('access')->alias('a')->join('') }
public function distribute() { $input = $this->input->post(); $this->load->model('M_Access', 'access'); if ($input) { if (isset($input['id'])) { $user = $this->session->userdata('user'); if ($input['id'] == 1 && $user['info']['role_id'] != 1) { $this->outJson(101, '', '不可以修改超级管理员权限!'); } $data = $this->role->getOne($input['id']); if (!$data) { $this->outJson(101, '', '参数错误'); } $this->access->del($input['id']); $data = array(); foreach ($input['check'] as $v) { $data[] = array('role_id' => $input['id'], 'node_id' => $v); } $res = $this->access->addMuti($data); if ($res) { $this->outJson(0); } else { $this->outJson(1); } } else { $this->outJson(101, '', '参数错误'); } } else { $id = $this->input->get('id'); if (!$id) { $this->outJson(-1); } $data = $this->role->getOne($id); if (!$data) { $this->outJson(101, '', '参数错误'); } $access = $this->access->getList(array('role_id' => $id)); $auth = array(); foreach ($access as $k => $v) { $auth[] = $v['node_id']; } $this->load->model('M_node', 'node'); $list = $this->node->getAll(); $list = node_merge($list); $this->assign('auth', $auth); $this->assign('list', $list); $this->assign('data', $data); $this->display(); } }
/** * 权限配置 * @author jiangwenshu <*****@*****.**> */ public function role() { $role_id = I('role_id', 0, 'intval'); $data = array(); if (IS_POST) { M('access')->where('role_id=' . $role_id)->delete(); foreach ($_POST['role'] as $v) { //获取菜单节点 $tmp = explode('_', $v); $data[] = array('role_id' => $role_id, 'node_id' => $tmp[0], 'level' => $tmp[1]); } //插入新权限 addAll循环插入 if (M('access')->addAll($data)) { $this->success('操作成功!', "index"); } else { $this->error('操作失败!'); } } else { $menus = D("Menu")->order('sort')->field(array('id', 'title', 'pid'))->select(); $access = M('access')->where('role_id=' . $role_id)->getField('node_id', true); $lists = node_merge($menus, $access); $this->assign("role_id", $role_id); $this->assign("menus", $lists); $this->display(); } }
public function nodeList() { $nodes = $this->order("sort asc")->select(); $list = node_merge($nodes); return $list; }
/** * 根据表单生成查询条件 * 进行列表过滤 * @param Model $model 数据对象 * @param HashMap $map 过滤条件 * @param string $sortBy 排序 * @param boolean $asc 是否正序 */ protected function _list($model, $map = array(), $sortBy = '', $asc = false) { //排序字段 默认为主键名 if (!empty($_REQUEST['_order'])) { $order = $_REQUEST['_order']; } else { $order = !empty($sortBy) ? $sortBy : $model->getPk(); } //排序方式默认按照倒序排列 //接受 sort参数 0 表示倒序 非0都 表示正序 if (!empty($_REQUEST['_sort'])) { $sort = $_REQUEST['_sort'] == 'asc' ? 'asc' : 'desc'; } else { $sort = $asc ? 'asc' : 'desc'; } //取得满足条件的记录数 $count = $model->where($map)->count(); //每页显示的记录数 if (!empty($_REQUEST['numPerPage'])) { $listRows = $_REQUEST['numPerPage']; } else { $listRows = '10'; } //设置当前页码 if (!empty($_REQUEST['pageNum'])) { $nowPage = $_REQUEST['pageNum']; } else { $nowPage = 1; } $_GET['p'] = $nowPage; //创建分页对象 import("ORG.Util.Page"); $p = new Page($count, $listRows); //分页查询数据 //$list = $model->where($map)->order($order . ' ' . $sort)->select(); $list = $model->where($map)->order($order . ' ' . $sort)->limit($p->firstRow . ',' . $p->listRows)->select(); //回调函数,用于数据加工,如将用户id,替换成用户名称 if (method_exists($this, '_tigger_list')) { $this->_tigger_list($list); } //分页跳转的时候保证查询条件 foreach ($map as $key => $val) { if (!is_array($val)) { $p->parameter .= "{$key}=" . urlencode($val) . "&"; } } //分页显示 $page = $p->show(); //列表排序显示 $sortImg = $sort; //排序图标 $sortAlt = $sort == 'desc' ? '升序排列' : '倒序排列'; //排序提示 $sort = $sort == 'desc' ? 1 : 0; //排序方式 //读取节点数据 $app = M('Node')->order('sort')->select(); $app = node_merge($app); //打包数组 //模板赋值显示 $this->assign('app', $app); $this->assign('list', $list); $this->assign('sort', $sort); $this->assign('order', $order); $this->assign('sortImg', $sortImg); $this->assign('sortType', $sortAlt); $this->assign("page", $page); $this->assign("search", $search); //搜索类型 $this->assign("values", $_POST['values']); //搜索输入框内容 $this->assign("totalCount", $count); //总条数 $this->assign("numPerPage", $p->listRows); //每页显多少条 $this->assign("currentPage", $nowPage); //当前页码 }
/** * 配置权限 */ public function accessAction() { $rid = I('rid', 0, 'intval'); $field = array('id', 'name', 'title', 'pid'); $node = M('node')->order('sort')->field($field)->select(); //; //读取原有权限 $access = M('access')->where(array('role_id' => $rid))->getField('node_id', true); $node = node_merge($node, $access); $this->assign('rid', $rid); $this->assign('node', $node); if (array_key_exists('HTTP_X_PJAX', $_SERVER) && $_SERVER['HTTP_X_PJAX']) { $this->display(); } else { layout(true); $this->display(); } }
public function access() { $rid = I('rid', 0, 'intval'); $field = array('id', 'name', 'title', 'pid'); $node = M('node')->order('sort')->field($field)->select(); // p($node); // p($_GET); //读取原有权限 $access = M('access')->where(array('role_id' => $rid))->getField('node_id', true); // p($access); $node = node_merge($node, $access); // p($node); $this->node = $node; $this->rid = $rid; $this->display(); }
public function index() { $node = $this->getMenus(); $this->node = node_merge($node); $this->display(); }
public function access() { $rid = I('rid', 0, 'intval'); //读取角色权限 $access = M('access')->where(array('role_id' => $rid))->getField('node_id', true); //读取所有权限 $node = M('node')->order('sort')->select(); //整理权限 $node = node_merge($node, $access); //p($node);die; $this->rid = $rid; $this->assign('node', $node)->display(); }
public function access() { if (IS_POST) { $rid = I('rid', 0, 'intval'); $db = M('access'); $db->where(array('role_id' => $rid))->delete(); //清除旧权限 //组合权限数组 $data = array(); foreach ($_POST['access'] as $v) { $tmp = explode('_', $v); $data[] = array('role_id' => $rid, 'node_id' => $tmp[0], 'level' => $tmp[1]); } //写入新权限 if ($db->addAll($data)) { $this->success('配置成功', U('Admin/Rbac/role')); } else { $this->error('配置失败'); } } else { $rid = I('rid', 0, 'intval'); $field = array('id', 'name', 'title', 'pid'); $node = M('node')->field($field)->order('sort')->select(); /* 读取原有权限 */ $access = M('access')->where(array('role_id' => $rid))->getField('node_id', true); $this->node = node_merge($node, $access); $this->rid = $rid; $this->display(); } }
public function access() { $rid = isset($_GET['rid']) ? $_GET['rid'] : 0; $field = array('id', 'name', 'title', 'pid', 'status'); $node = M('node')->field($field)->all(); $acc = M('access')->where('role_id=' . $rid)->all(); $role = array(); foreach ($acc as $v) { $role[] = $v['node_id']; } $node = node_merge($node, $role); // p($node);die; $this->assign('node', $node); $this->assign('rid', $rid); $this->display(); }