php代码
<?php
namespace Home\Controller;
use Common\Common\CommonController;
class AccessController extends CommonController {
public function adminlist(){
$M=M("admin");
$data=$M->select();
foreach($data as &$value)
{
if($value[‘last_login_time‘]!=0)
{
$value[‘last_login_time‘]=date(‘Y-m-d H:i:s‘,$value[‘last_login_time‘]);
}
else
{
$value[‘last_login_time‘]=‘尚未登录‘;
}
if($value[‘status‘]==1)
{
$value[‘status‘]=‘已启用‘;
}
else{
$value[‘status‘]=‘未启用‘;
}
}
//print_r($data);exit;
$this->assign("userlist",$data);
$this->display();
}
function addadmin()
{
if(isset($_POST) && !empty($_POST))
{
$M=M("admin");
$data=array();
$data[‘username‘]=$_POST[‘username‘];
$data[‘password‘]=md5($_POST[‘password‘]);
$data[‘status‘]=$_POST[‘status‘];
$succ=$M->add($data);
if(!empty($succ))
{
$RUS=M(‘role_user‘);
$ru[‘user_id‘]=$M->getLastInsID();
$ru[‘role_id‘]=$_POST[‘role‘];
$is=$RUS->add($ru);
if(!empty($is))
{
$this->success("添加成功","adminlist");
}
else
{
$this->error("添加用户权限失败","__URL__/addadmin");
}
}
else
{
$this->error("添加用户信息失败","__URL__/addadmin");
}
}
else
{
$M=M("role");
$data=$M->select();
$this->assign("roles",$data);
$this->display();
}
}
function admin_update()
{
$M=M("admin");
$ID=$_GET[‘id‘];
$data=$M->where("id=".$ID."")->select();
//print_r($data);exit;
$this->assign("datas",$data);
$M=M("role");
$datas=$M->select();
$this->assign("roles",$datas);
$this->display("admin_update");
}
function do_admin_update()
{
$M=M("admin");
$data[‘id‘]=$_POST[‘id‘];
$data[‘username‘]=$_POST[‘username‘];
$data[‘password‘]=$_POST[‘password‘];
$data[‘status‘]=$_POST[‘status‘];
$data[‘role_id‘]=$_POST[‘role‘];
//print_r($_POST);exit;
$sql=array(‘id‘=>$data[‘id‘],‘username‘=>$data[‘username‘],‘password‘=>$data[‘password‘],‘status‘=>$data[‘status‘]);
$succ=$M->save($sql);
if(!empty($succ))
{
$RU=M(‘role_user‘);
$sqls=array(‘role_id‘=>$data[‘role_id‘]);
$us=$RU->where(array(‘user_id‘=>$data[‘id‘]))->save($sqls);
if(!empty($us))
{
$this->success("修改成功","adminlist");
}
else
{
$this->error("修改用户权限失败","adminlist");
}
}
else
{
$this->error("修改用户信息失败","adminlist");
}
}
function admin_delete()
{
$M=M("admin");
$ID=$_GET[‘id‘];
$data=$M->where("id=".$ID."")->delete();
if(!empty($data))
{
$RU=M(‘role_user‘);
$infos=$RU->where(array(‘user_id‘=>$id))->delete();
if(!empty($infos))
{
$this->success("删除成功","adminlist");
}
else
{
$this->error("删除用户权限失败","adminlist");
}
}
else
{
$this->error("删除用户信息失败","adminlist");
}
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。