Php permission list function

Source: Internet
Author: User
// Obtain the permission list publicfunctiongetPriveList ($ id) {$ SQL & quot; SELECTm. id, m. nameFROMjh_userASu, jh_roleASr, jh_role_userASru, jh_priveASp, jh_menuASmWHERE

// Obtain the permission list
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;
}
// Determine the public module 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 );
}

 

From chaojie2009

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.