首页 > 代码库 > php代码
php代码
<?php
namespace Home\Controller;
use Common\Common\CommonController;
class AccessController extends CommonController {
public function adminlist(){
$M=M("admin");
$data=http://www.mamicode.com/$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=http://www.mamicode.com/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=http://www.mamicode.com/$M->select();
$this->assign("roles",$data);
$this->display();
}
}
function admin_update()
{
$M=M("admin");
$ID=$_GET[‘id‘];
$data=http://www.mamicode.com/$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=http://www.mamicode.com/$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");
}
}
php代码