admin_role.auto_cache.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. //商城的导航dz_chh
  3. class admin_role_auto_cache extends auto_cache{
  4. public function load($param)
  5. {
  6. $key = $this->build_key(__CLASS__,$param);
  7. $GLOBALS['cache']->set_dir(APP_ROOT_PATH."public/runtime/data/".__CLASS__."/");
  8. $return = $GLOBALS['cache']->get($key);
  9. //$return = false;
  10. if($return === false)
  11. {
  12. //start
  13. $navs = require_once APP_ROOT_PATH."system/admnav_cfg.php";
  14. $navs = deal_admin_nav($navs);
  15. $role_list = $GLOBALS['db']->getAll("select * from ".DB_PREFIX."role_node where is_delete=0 and is_effect=1 order by id");
  16. $role_access_list = $GLOBALS['db']->getAll("select * from ".DB_PREFIX."role_access where role_id=".intval($param['id'])." order by id");
  17. //$nodes = M("RoleModule")->where("is_delete=0 and is_effect=1 and module <> 'Index' and module = '".$nv['module']."' ")->order("module asc")->findAll();
  18. $modules = $GLOBALS['db']->getAll("select * from ".DB_PREFIX."role_module where is_delete=0 and is_effect=1 order by id");
  19. $node_list =array();
  20. $access_list = array();
  21. $module_list = array();
  22. foreach($modules as $k=>$v){
  23. unset($v['name']);
  24. $module_list[$v['id']] = $v;
  25. $module_list[$v['module']] = $v;
  26. }
  27. foreach($role_list as $k=>$v){
  28. $node_list[$module_list[$v['module_id']]['module']][]=$v;
  29. }
  30. foreach($role_access_list as $k=>$v){
  31. $access_list[$module_list[$v['module_id']]['module']][]=$v;
  32. }
  33. foreach($navs as $k=> $v){
  34. foreach($v['groups'] as $gk=> $gv){
  35. foreach($gv['nodes'] as $nk=> $nv){
  36. $navs[$k]['groups'][$gk]['nodes'][$nk]['node_list']= $node_list[$nv['module']];
  37. foreach($module_list[$nv['module']] as $mk=>$mv){
  38. $navs[$k]['groups'][$gk]['nodes'][$nk][$mk] = $mv;
  39. }
  40. }
  41. }
  42. }
  43. foreach($navs as $k=> $v) {
  44. foreach ($v['groups'] as $gk => $gv) {
  45. /*if($gk =='index'){
  46. unset($navs[$k]['groups'][$gk]);
  47. unset($gv);
  48. }*/
  49. foreach ($gv['nodes'] as $nk => $nv) {
  50. // M("RoleAccess")->where("role_id=".$param['id']." and action_id=".$nv['action_id']." and node_id =0")->count()>0
  51. foreach($access_list[$nv['module']] as $k1=>$v1){
  52. if(($nv['id'] == $v1['module_id'])&&($v1['node_id']==0)){
  53. $navs[$k]['groups'][$gk]['nodes'][$nk]['module_auth'] = 1;
  54. }else{
  55. $navs[$k]['groups'][$gk]['nodes'][$nk]['module_auth'] = 0;
  56. }
  57. }
  58. foreach ($nv['node_list'] as $nlk => $nlv) {
  59. //if(M("RoleAccess")->where("role_id=".$param['id']." and action_id=".$nv['action_id']." and node_id =".$nlv['id'])->count()>0)
  60. foreach ($access_list[$nv['module']] as $k2 => $v2) {
  61. if ($v2['node_id'] == $nlv['id']) {
  62. $navs[$k]['groups'][$gk]['nodes'][$nk]['node_list'][$nlk]['node_auth'] = 1;
  63. } else {
  64. if($navs[$k]['groups'][$gk]['nodes'][$nk]['node_list'][$nlk]['node_auth']!=1){
  65. $navs[$k]['groups'][$gk]['nodes'][$nk]['node_list'][$nlk]['node_auth'] = 0;
  66. }
  67. }
  68. }
  69. //if(M("RoleAccess")->where("role_id=".$param['id']." and action_id=".$nv['action_id']." and node_id <>0")->count()==
  70. // M("RoleNode")->where("is_delete=0 and is_effect=1 and action_id=".$nv['action_id'])->count()&&
  71. // M("RoleNode")->where("is_delete=0 and is_effect=1 and action_id=".$nv['action_id'])->count() != 0)
  72. $access_count = 0;
  73. foreach($access_list[$nv['module']] as $k_1=>$v_1){
  74. if($v_1['node_id']!=0){
  75. $access_count++;
  76. }
  77. }
  78. $node_count =intval(count($node_list[$nv['module']]));
  79. if (($access_count==$node_count)&&$node_count>0) {
  80. $navs[$k]['groups'][$gk]['nodes'][$nk]['node_list'][$nlk]['check_all'] = 1;
  81. //$navs[$k]['groups'][$gk]['nodes'][$nk]['module_auth'] = 1;
  82. } else {
  83. $navs[$k]['groups'][$gk]['nodes'][$nk]['node_list'][$nlk]['check_all'] = 0;
  84. //$navs[$k]['groups'][$gk]['nodes'][$nk]['module_auth'] = 0;
  85. }
  86. }
  87. }
  88. }
  89. }
  90. //end
  91. $return=array();
  92. $return = $navs;
  93. $GLOBALS['cache']->set_dir(APP_ROOT_PATH."public/runtime/data/".__CLASS__."/");
  94. $GLOBALS['cache']->set($key,$return);
  95. }
  96. return $return;
  97. }
  98. public function rm($param)
  99. {
  100. $key = $this->build_key(__CLASS__,$param);
  101. $GLOBALS['cache']->set_dir(APP_ROOT_PATH."public/runtime/data/".__CLASS__."/");
  102. $GLOBALS['cache']->rm($key);
  103. }
  104. public function clear_all()
  105. {
  106. $GLOBALS['cache']->set_dir(APP_ROOT_PATH."public/runtime/data/".__CLASS__."/");
  107. $GLOBALS['cache']->clear();
  108. }
  109. }
  110. ?>