您好,欢迎访问一九零五行业门户网

php 获取权限列表函数_PHP教程

//获取权限列表 
   public  function getprivelist($id){ 
     $sql=select m.id, m.name 
              from jh_user as u, jh_role as r, jh_role_user as ru, jh_prive as p, jh_menu as m 
              where u.id = ru.user_id 
              and ru.role_id = r.id 
              and r.id = p.role_id 
              and m.id = p.menu_id 
              and m.status =1 
              and m.level =1 
              and u.id ={$id};   
    $rs=$this->query($sql); 
    //$row=$this->fetch_assoc($rs); 
    $m1=array(); 
    while ($row=$this->fetch_assoc($rs)){ 
        $m1[]=$row; 
    } 
    $prive=array(); 
    foreach ($m1 as $key=>$v){ 
        $priveid=$v['id']; 
        $privename=$v['name']; 
        $prive[strtoupper($privename)]=array(); 
        $sql2=select m.id, m.name 
              from jh_user as u, jh_role as r, jh_role_user as ru, jh_prive as p, jh_menu as m 
              where u.id = ru.user_id 
              and ru.role_id = r.id 
              and r.id = p.role_id 
              and m.id = p.menu_id 
              and m.status =1 
              and m.level =2 
              and m.pid ={$priveid} 
              and u.id ={$id};   
        $rs2=$this->query($sql2); 
        $m2=array(); 
        while ($row2=$this->fetch_assoc($rs2)){ 
            $m2[]=$row2; 
        } 
        //判断公共模块  www.2cto.com
        $public=array(); 
        foreach ($m2 as $key =>$m){ 
            $pid=$m['id']; 
            $pname=$m['name']; 
            if('public'==strtoupper($m['name'])){ 
                $sql3=select m.id, m.name 
              from jh_user as u, jh_role as r, jh_role_user as ru, jh_prive as p, jh_menu as m 
              where u.id = ru.user_id 
              and ru.role_id = r.id 
              and r.id = p.role_id 
              and m.id = p.menu_id 
              and m.status =1 
              and m.level =3 
              and m.pid ={$pid} 
              and u.id ={$id}; 
                $rs3=$this->query($sql3); 
                $m3=array(); 
                while ($row3=$this->fetch_assoc($rs3)){ 
                    $m3[]=$row3; 
                } 
                foreach ($m3 as $val){ 
                    $public[$val['name']]=$val['id']; 
                } 
                //print_r( $m2[$key]); 
                unset($m2[$key]); 
                break; 
            } 
        } 
            // print_r($public);
foreach ($m2 as $key =>$m){ 
        $pid=$m['id']; 
        $pname=$m['name']; 
        $sql4=select m.id, m.name 
              from jh_user as u, jh_role as r, jh_role_user as ru, jh_prive as p, jh_menu as m 
              where u.id = ru.user_id 
              and ru.role_id = r.id 
              and r.id = p.role_id 
              and m.id = p.menu_id 
              and m.status =1 
              and m.level =3 
              and m.pid ={$pid} 
              and u.id ={$id}; 
          $rs4=$this->query($sql4); 
          $m4=array(); 
          while ($row4=$this->fetch_assoc($rs4)){ 
            $m4[]=$row4; 
          } 
          $action=array(); 
          foreach ($m4 as $va){ 
            $action[$va['name']]=$va['id']; 
          } 
         $action+=$public; 
         $prive[strtoupper($privename)][strtoupper($pname)] =array_change_key_case($action,case_upper); 
      } 
        } 
    print_r($prive); 
   }
摘自 chaojie2009的专栏
http://www.bkjia.com/phpjc/478387.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/478387.htmltecharticle//获取权限列表 public function getprivelist($id){ $sql=select m.id, m.name from jh_user as u, jh_role as r, jh_role_user as ru, jh_prive as p, jh_menu as m where u.id = ru.us...
其它类似信息

推荐信息