AccessAction.class.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. *
  4. * Access (权限设置)
  5. *
  6. */
  7. if(!defined("Ainaphp")) exit("Access Denied");
  8. class AccessAction extends AdminbaseAction {
  9. protected $dao;
  10. function _initialize()
  11. {
  12. parent::_initialize();
  13. $this->dao=M('Access');
  14. }
  15. function index(){
  16. $rid=intval($_GET['rid']);
  17. $alist = $this->dao->where('role_id = '.$rid)->getField('node_id,role_id');
  18. $node=M('Node');
  19. $r=$node->where("pid=0 and status=1")->select();
  20. $this->assign('topnode', $r);
  21. $groups[0]=array('id'=>0,'name'=>L('ACCESS_PUBLIC'));
  22. foreach($this->menudata as $key=>$r){ if($r['parentid']==0)$groups[$r[id]]=$r;}
  23. $this->assign('groups', $groups);
  24. foreach($groups as $key=>$res){
  25. $result=$node->where("groupid=$res[id] and status=1")->select();
  26. $array=array();
  27. foreach($result as $r) {
  28. $r['parentid']=$r['pid'];
  29. $r['selected'] = array_key_exists($r['id'],$alist) ? 'checked' : '';
  30. $array[] = $r;
  31. }
  32. $nodes[$res['id']]['data'] =$array;
  33. $nodes[$res['id']]['groupinfo']=$res;
  34. }
  35. $node_app=$this->dao->where("pid=0 and status=1")->select();
  36. $this->assign('node_app', $node_app);
  37. $this->assign('alist', $alist);
  38. $this->assign('node', $nodes);
  39. $this->assign('rid', $rid);
  40. $this->display();
  41. }
  42. function insert(){
  43. $rid=$_POST['rid'];
  44. $nid=$_POST['nid'];
  45. if(!empty($rid)){
  46. if($nid){
  47. $node_id=implode(',',$nid);
  48. $node=M('Node');
  49. $list=$node->where('id in('.$node_id.')')->select();
  50. $this->dao->where('role_id = '.$rid)->delete();
  51. foreach($list as $key=> $node){
  52. $data[$key]['role_id']=$rid;
  53. $data[$key]['node_id']=$node['id'];
  54. $data[$key]["level"]=$node['level'];
  55. $data[$key]["pid"]=$node['pid'];
  56. }
  57. $r=$this->dao->addAll($data);
  58. }else{
  59. $r= $this->dao->where('role_id = '.$rid)->delete();
  60. }
  61. if(false!==$r){
  62. $this->success(L('role_ok'));
  63. }else{
  64. $this->error(L('role_error'));
  65. }
  66. }else{
  67. $this->error(L('do_empty'));
  68. }
  69. }
  70. }
  71. ?>