admin_role.auto_cache.php 4.4 KB

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