php 获取权限列表函数
程序员文章站
2024-02-14 23:25:28
...
//获取权限列表
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);
}
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的专栏
推荐阅读
-
php 获取权限列表函数
-
ThinkPHP 3.2 中获取所有函数方法名,以及注释,完整可运行,thinkphp3.2_PHP教程
-
编程 - curl、file_get_contents等PHP获取网页内容函数的问题
-
PHP获取远程验证码到本地的PHP函数代码
-
PHP获取指定月份的第一天开始和最后一天结束的时间戳函数
-
finfo_file函数获取文件mime值验证出错的解决方法_PHP教程
-
php数组函数序列之array_keys() - 获取数组键名_PHP教程
-
PHP获取类中常量,属性,及方法列表的方法_PHP教程
-
php 利用array_slice函数获取随机数组或前几条数据
-
php数组函数序列之array_values() 获取数组元素值的函数与方法_PHP教程