Exemplo n.º 1
0
 public function role()
 {
     $role = D('Role');
     //获取当前用户组项目权限信息
     $roleId = isset($_GET['id']) ? $_GET['id'] : '';
     $nodeRoleList = array();
     if (!empty($roleId)) {
         $this->assign("selectRoleId", $roleId);
         //获取当前角色的操作权限列表
         $list = $role->getNodeRoleList($roleId);
         foreach ($list as $vo) {
             $nodeRoleList[$vo['id']] = $vo['id'];
         }
     }
     if (isset($_SESSION[C('USER_AUTH_KEY')])) {
         //显示菜单项
         $menu = array();
         //读取数据库模块列表生成菜单项
         $node = M("Node");
         $where['status'] = array('egt', 0);
         $list = $node->where($where)->field('id,pid,name,title,level')->order('level,sort')->select();
         $accessList = $_SESSION['_ACCESS_LIST'];
         foreach ($list as $key => $module) {
             if (isset($accessList[strtoupper(APP_NAME)][strtoupper($module['name'])]) || $_SESSION['administrator']) {
                 //设置模块访问权限
                 $module['access'] = 1;
                 $menu[$key] = $module;
             }
         }
         $menu = arrToTree($menu, 0);
         $tree = outMenu($menu, $nodeRoleList);
         $this->assign('tree', $tree);
     }
     C('SHOW_RUN_TIME', false);
     // 运行时间显示
     C('SHOW_PAGE_TRACE', false);
     $this->display();
     return;
 }
Exemplo n.º 2
0
function outMenu($tree, $nodeRoleList)
{
    $html = '';
    foreach ($tree as $t) {
        if (in_array($t['id'], $nodeRoleList)) {
            if (empty($t['pid'])) {
                $html .= '<li><span class="zjj"></span><input class="J_checkitem" type="checkbox" name="menu_id[]" value="' . $t['id'] . '" checked=true class="J_checkitem" level="' . $t['level'] . '">&nbsp;' . $t['title'] . '</li>';
            } else {
                $html .= '<li class="m-expanded"><span class="zj"></span><input class="J_checkitem" type="checkbox" name="menu_id[]" value="' . $t['id'] . '" checked=true class="J_checkitem" level="' . $t['level'] . '"><span>&nbsp;' . $t['title'] . '</span><ul>';
                $html .= outMenu($t['pid'], $nodeRoleList);
                $html = $html . '</ul></li>';
            }
        } else {
            if (empty($t['pid'])) {
                $html .= '<li><span class="zjj"></span><input class="J_checkitem" type="checkbox" name="menu_id[]" value="' . $t['id'] . '" class="J_checkitem" level="' . $t['level'] . '">&nbsp;' . $t['title'] . '</li>';
            } else {
                $html .= '<li class="m-expanded"><span class="zj"></span><input class="J_checkitem" type="checkbox" name="menu_id[]" value="' . $t['id'] . '" class="J_checkitem" level="' . $t['level'] . '"><span>&nbsp;' . $t['title'] . '</span><ul>';
                $html .= outMenu($t['pid'], $nodeRoleList);
                $html = $html . '</ul></li>';
            }
        }
    }
    return $html;
}