qc.ifish7.com/Application/Admin/Controller/RoleController.class.php

146 lines
4.9 KiB
PHP

<?php
namespace Admin\Controller;
use Think\Controller;
class RoleController extends AdminController{
public function index(){
$tab=D('role');
$ptitle=$p[title]?$p[title]:"菜单管理";
$data=$tab->order('id desc')->select();
$this->assign("data",$data);
$this->display();
}
public function add(){
$tab=D('role');
if(IS_POST){
$data=$tab->create();
if($data){
$id=$tab->add($data);
D("UserLog")->add("add",D('role')->getTableName(),$id);
$this->success($data);
}else{
$this->error($tab->getError());
}
}else{
$this->display();
}
}
public function editor(){
$tab=D('role');
if(IS_POST){
$data=$tab->create();
if($data){
$tab->save($data);
D("UserLog")->add("update",D('role')->getTableName(),$data[id]);
$this->success($data);
}else{
$this->error($tab->getError());
}
}else{
$id=I("get.id");
$r=$tab->find($id);
$this->assign("r",$r);
$this->display();
}
}
//删除
public function del(){
$tab=M("role");
$id=I("id",0,'intval');
$result=$tab->delete($id);
if($result){
D("UserLog")->add("delete",D('role')->getTableName(),$id);
$this->success("删除成功");
}else{
$this->error("删除失败");
}
}
//配置权限
public function access(){
$tab=D('access');
if(IS_POST){
$role_id=I("role_id",0,"int");
if(!$role_id){
$this->error("缺少参数");
}
$db=M('access');
//清空原权限
$tab->where(array("role_id"=>$role_id))->delete();
//重新组装权限
$data=array();
if($_POST['access']){
foreach($_POST['access'] as $v){
$tmp=explode("_",$v);
$data[]=array(
"role_id"=>$role_id,
"node_id"=>$tmp[0],
"level"=>$tmp[1],
);
}
if($tab->addAll($data)){
D("UserLog")->add("update",D('role')->getTableName(),$role_id);
$this->success("操作成功",U("role"));
}
}
}else{
$role_id=I("get.role_id");
$this->assign("role_id",$role_id);
$r=M("role")->find($rid);
$data=M("node")->where("is_dev=0")->order('sort asc')->select();
//原有权限
$access=M("access")->where(array("role_id"=>$role_id))->getField("node_id",true);
$data=node_merge($data,$access);
$this->assign("data",$data);
$this->display();
}
}
//栏目权限配置
public function access_cat(){
$tab=D('access');
if(IS_POST){
$role_id=I("role_id",0,"int");
if(!$role_id){
$this->error("缺少参数");
}
//
$info_checked=implode("|",$_POST["info_checked"]);
if($info_checked){
$info_checked="|".$info_checked."|";
}
$info_view=implode("|",$_POST["info_view"]);
if($info_view){
$info_view="|".$info_view."|";
}
$info_add= implode("|",$_POST["info_add"]);
if($info_add){
$info_add="|".$info_add."|";
}
$info_editor=implode("|",$_POST["info_editor"]);
if($info_editor){
$info_editor="|".$info_editor."|";
}
$info_delete=implode("|",$_POST["info_delete"]);
if($info_delete){
$info_delete="|".$info_delete."|";
}
$info_checked= json_encode($info_checked);
D('role')->save(array(
"id"=>$role_id,
"info_checked"=>$info_checked,
"info_view"=>$info_view,
"info_add"=>$info_add,
"info_editor"=>$info_editor,
"info_delete"=>$info_delete,
));
D("UserLog")->add("update",D('role')->getTableName(),$role_id);
$this->success("操作成功",U("role"));
}else{
$role_id=I("get.role_id");
$this->assign("role_id",$role_id);
$r=M("role")->find($role_id);
$CatController=new \Admin\Controller\CatController();
$this->catData=$CatController->forCat2();
$this->assign("r",$r);
$this->display();
}
}
}