添加用户删除和修改权限功能
This commit is contained in:
parent
c655474e7e
commit
6f82e374c0
|
@ -11,6 +11,7 @@ namespace Admin\Controller;
|
|||
|
||||
use Zend\Mvc\Controller\AbstractActionController;
|
||||
use Zend\View\Model\ViewModel;
|
||||
use Zend\View\Model\JsonModel;
|
||||
use Sookon\Helpers\View as view;
|
||||
use Sookon\Helpers\Db;
|
||||
|
||||
|
@ -100,6 +101,45 @@ class UsersController extends AbstractActionController
|
|||
return view::Post($this,"用户密码重置失败!",-1);
|
||||
}
|
||||
}
|
||||
|
||||
if($ac == "auth")
|
||||
{
|
||||
if($this->getRequest()->isXmlHttpRequest())
|
||||
{
|
||||
$userid = $this->params()->fromPost('userid');
|
||||
$usertype = $this->params()->fromPost('usertype');
|
||||
|
||||
if(empty($userid) || empty($usertype))
|
||||
{
|
||||
return new JsonModel(array('error'=>"参数错误"));
|
||||
}
|
||||
|
||||
$users = new \Westdc\Member\Member;
|
||||
if($users->changeUsertype($userid,$usertype) > 0)
|
||||
{
|
||||
return new JsonModel(array('success'=>1));
|
||||
}else{
|
||||
return new JsonModel(array('error'=>"未发生任何变更"));
|
||||
}
|
||||
}
|
||||
}//修改usetype
|
||||
|
||||
if($ac == 'del')
|
||||
{
|
||||
if(!is_numeric($id) || $id < 1)
|
||||
{
|
||||
return view::Post($this,"参数错误",-1);
|
||||
}
|
||||
|
||||
$users = new \Westdc\Member\Member;
|
||||
|
||||
if($users->deleteUser($id) > 0)
|
||||
{
|
||||
return view::Post($this,"删除成功",-1);
|
||||
}else{
|
||||
return view::Post($this,"删除失败",-1);
|
||||
}
|
||||
}//删除
|
||||
}
|
||||
|
||||
# 邮件模板模块
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
<th>姓名</th>
|
||||
<th>单位</th>
|
||||
<th>Email</th>
|
||||
<th>权限</th>
|
||||
<th>添加时间</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
|
@ -48,16 +49,27 @@
|
|||
<td><?= $v['realname'] ?></td>
|
||||
<td><?= $v['unit'] ?></td>
|
||||
<td><?= $v['email'] ?></td>
|
||||
<td><?= $v['usertype'] ?></td>
|
||||
<td><?= date("Y-m-d H:i",strtotime($v['ts_created'])) ?></td>
|
||||
<td>
|
||||
<a href="<?= $this->url('admin',array('controller'=>'users','action'=>'view','ac'=>'detail','id'=>$v['id'])) ?>">
|
||||
<span class="glyphicon glyphicon-eye-open"></span>
|
||||
</a>
|
||||
<a href="javascript:void(0);" title="设置" class="btn-user-settings"
|
||||
data-username="<?= isset($v['realname']) ? $v['realname'] : $v['username'] ?>"
|
||||
data-userid="<?= $v['id'] ?>">
|
||||
<span class="glyphicon glyphicon-cog"></span>
|
||||
</a>
|
||||
<a href="<?= $this->url('admin',array('controller'=>'users','action'=>'edit','ac'=>'reset','id'=>$v['id'])) ?>"
|
||||
onclick="return confirm('是否确定重置他的密码?')"
|
||||
title="重置密码">
|
||||
<span class="glyphicon glyphicon-retweet"></span>
|
||||
</a>
|
||||
<a href="<?= $this->url('admin',array('controller'=>'users','action'=>'edit','ac'=>'del','id'=>$v['id'])) ?>"
|
||||
onclick="return confirm('是否确定删除此用户?此操作不可逆')"
|
||||
title="删除用户">
|
||||
<span class="glyphicon glyphicon-trash"></span>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
|
@ -81,4 +93,96 @@
|
|||
<?= $this->partial("layout/admin/users/nav") ?>
|
||||
</div><!-- col-lg-4 -->
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="window-user-setting" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title" id="myModalLabel"></h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="form-horizontal" role="form" id="form-user-setting">
|
||||
<div class="form-group">
|
||||
<label for="inputEmail3" class="col-sm-3 control-label">将用户更改为</label>
|
||||
<div class="col-sm-9">
|
||||
<select class="form-control" name="usertype">
|
||||
<option value="member">普通用户</option>
|
||||
<option value="administrator">管理员</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="userid" id="input-userid" value="" />
|
||||
<div id="alert-info">
|
||||
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="progress progress-striped active pull-left" id="submit-loading" style="height:40px; position:absolute;left:0;z-index:1;display:none;width:100%;">
|
||||
<div class="progress-bar" style="width:100%"></div>
|
||||
</div>
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
|
||||
<button type="button" class="btn btn-primary" id="btn-submit">保存</button>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div><!-- /.modal -->
|
||||
<script>
|
||||
$('.btn-user-settings').click(function(e) {
|
||||
$('#myModalLabel').html('编辑用户: '+ $(this).data('username'));
|
||||
$('#input-userid').val($(this).data('userid'));
|
||||
$('#window-user-setting').modal('show');
|
||||
});
|
||||
|
||||
$('#btn-submit').click(function(e) {
|
||||
$.ajax({
|
||||
'type':"POST",
|
||||
'url':"<?= $this->url('admin',array('controller'=>'users','action'=>'edit','ac'=>'auth','id'=>$v['id'])) ?>",
|
||||
'data' : $('#form-user-setting').serialize(),
|
||||
'success':submited,
|
||||
'timeout': 30000,
|
||||
'error': function(){
|
||||
$("#alert-info").attr('class','alert alert-danger');
|
||||
$("#alert-info").html("出现错误,请稍后重试");
|
||||
$('#submit-loading').hide();
|
||||
return false;
|
||||
},
|
||||
'beforeSend': function(){
|
||||
$("#btn-submit").addClass('disabled');
|
||||
$("#btn-submit").attr('disabled','disabled');
|
||||
$('#submit-loading').show();
|
||||
},
|
||||
complete: function(){
|
||||
$("#btn-submit").removeClass('disabled');
|
||||
$("#btn-submit").removeAttr('disabled');
|
||||
$('#submit-loading').hide();
|
||||
}
|
||||
});
|
||||
});
|
||||
function submited(data){
|
||||
if (typeof(data)=='object')
|
||||
{
|
||||
if(typeof(data.error)!='undefined')
|
||||
{
|
||||
$("#alert-info").attr('class','alert alert-danger');
|
||||
$("#alert-info").html(data.error);
|
||||
return false;
|
||||
}
|
||||
if(typeof(data.success)!='undefined')
|
||||
{
|
||||
$("#btn-submit").attr('disabled','disabled');
|
||||
$("#alert-info").attr('class','alert alert-success');
|
||||
$("#alert-info").html("编辑成功!(页面将自动跳转,<a href=\"javascript:void(0);\" onclick=\"window.location.href=window.location.href\" class=\"alert-link\">如果没有跳转请点击这里</a>)");
|
||||
setTimeout("window.location.href=window.location.href",3000);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
$("#alert-info").attr('class','alert alert-danger');
|
||||
$("#alert-info").html('服务器掉链子了,请重试');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -122,5 +122,17 @@ class Member
|
|||
}
|
||||
}
|
||||
|
||||
public function changeUsertype($uid,$utype)
|
||||
{
|
||||
$sql = "UPDATE {$this->table->member} SET usertype='$utype' WHERE id=$uid";
|
||||
return $this->db->exec($sql);
|
||||
}
|
||||
|
||||
public function deleteUser($uid)
|
||||
{
|
||||
$sql = "DELETE FROM {$this->table->member} WHERE id=$uid";
|
||||
return $this->db->exec($sql);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue