#407 添加用户组管理功能

This commit is contained in:
Li Jianxuan 2012-10-30 02:20:40 +00:00
parent fd5436c41a
commit be8b6ef2b5
4 changed files with 540 additions and 12 deletions

View File

@ -279,8 +279,229 @@ class Admin_UserController extends Zend_Controller_Action
$this->_redirect("/admin/user/list");
}
} //overview
/*
* groupAction() 用户组管理
*
*/
function groupAction(){
$ac = $this->_getParam('ac');
$groupsTable = "groups";
$userGroupTable = "usergroup";
$nameField = $paramName = "name";
if(empty($ac) || $ac == "index")
{
$select=$this->db->select();
$select->from($groupsTable)
->order('groups.id desc');
$paginator = Zend_Paginator::factory($select);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(30);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
$this->view->paginator=$paginator;
}//首页
if($ac == "add")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$data[$nameField] = $this->_getParam($paramName);
if(empty($data[$nameField]))
{
$this->jsonexit(array("error"=>'请输入组名'));
return true;
}
//overview
if($this->db->insert($groupsTable,$data))
{
$this->jsonexit(array("status"=>1));
return true;
}else{
$this->jsonexit(array("error"=>"出现错误,请重试"));
return true;
}
return true;
}//增加用户组
if($ac == "edit")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$id = $this->_getParam('id');
$data[$nameField] = $this->_getParam($paramName);
if(empty($id))
{
$this->jsonexit(array("error"=>'参数错误'));
return true;
}
if(empty($data[$nameField]))
{
$this->jsonexit(array("error"=>'请输入组名'));
return true;
}
if($this->db->update($groupsTable,$data,"id=$id"))
{
$this->jsonexit(array("status"=>1,"name"=>$data[$nameField]));
return true;
}else{
$this->jsonexit(array("error"=>"出现错误,请重试"));
return true;
}
return true;
}//编辑
if($ac == "del")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$id = $this->_getParam('id');
if(empty($id))
{
$this->jsonexit(array("error"=>'参数错误'));
return true;
}
if($this->db->delete($groupsTable,"id=$id"))
{
$this->jsonexit(array("status"=>1));
return true;
}else{
$this->jsonexit(array("error"=>"出现错误,请重试"));
return true;
}
return true;
}//删除
if($ac == "show")
{
$this->_helper->viewRenderer('group-users');
$gid = (int)$this->_getParam('id');
if(empty($gid))
{
echo "参数错误!";
return true;
}
$this->view->groupid = $gid;
$sql = "SELECT ug.uid,ug.gid,u.id,u.username,u.realname,u.email FROM $userGroupTable ug
LEFT JOIN users u ON ug.uid=u.id
WHERE ug.gid=$gid
ORDER BY ug.ts_created DESC";
$sth = $this->db->query($sql);
$rows = $sth->fetchAll();
$paginator = Zend_Paginator::factory($rows);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(20);
$paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$this->view->paginator=$paginator;
}//查看用户
if($ac == "adduser")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$data['uid'] = $this->_getParam('uid');
$data['gid'] = $this->_getParam('gid');
if(empty($data['uid']) || empty($data['gid']))
{
$this->jsonexit(array("error"=>'参数错误'));
return true;
}
$sql = "SELECT * FROM users WHERE id={$data['uid']}";
$sth = $this->db->query($sql);
$rows = $sth->fetchAll();
if(count($rows)<1)
{
$this->jsonexit(array("error"=>'用户不存在'));
return true;
}
$sql = "SELECT * FROM $userGroupTable WHERE uid={$data['uid']} AND gid='{$data['gid']}'";
$sth = $this->db->query($sql);
$rows = $sth->fetchAll();
if(count($rows)>0)
{
$this->jsonexit(array("error"=>'该用户已经存在于要加入的组'));
return true;
}
if($this->db->insert($userGroupTable,$data))
{
$this->jsonexit(array("status"=>1));
return true;
}else{
$this->jsonexit(array("error"=>"出现错误,请重试"));
return true;
}
return true;
}//往组中添加用户
if($ac == "deluser")
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$uid = $this->_getParam('uid');
$gid = $this->_getParam('gid');
if(empty($uid) || empty($gid))
{
$this->jsonexit(array("error"=>'参数错误'));
return true;
}
if($this->db->delete($userGroupTable,"uid=$uid AND gid=$gid"))
{
$this->jsonexit(array("status"=>1));
return true;
}else{
$this->jsonexit(array("error"=>"出现错误,请重试"));
return true;
}
return true;
}//从组中删除用户
}// groupAction()
public function jsonexit($data){
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(json_encode($data,JSON_NUMERIC_CHECK));
return true;
}
}

View File

@ -0,0 +1,122 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
$this->headLink()->appendStylesheet('/css/admin.css');
$this->headScript()->appendFile('/static/js/jquery-1.7.2.min.js');
$this->headScript()->appendFile('/js/jquery.colorbox-min.js');
$this->headLink()->appendStylesheet('/css/colorbox.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin/">后台首页</a>');
$this->breadcrumb('<a href="/admin/user">用户管理</a>');
$this->breadcrumb()->setSeparator(' > ');
?>
<div id="leftPanel">
<?= $this->partial('user/left.phtml'); ?>
</div>
<?php if ($this->msg or $this->messages) :?>
<div id="message">
<?php if ($this->msg) : ?>
<p><?php echo $this->msg; ?></p>
<?php endif; if ($this->messages): foreach($this->messages as $msg): ?>
<p><?php echo $msg; ?></p>
<?php endforeach;endif; ?>
</div>
<?php endif; ?>
<div id="rightPanel">
<div style="font-size:16px;line-height:30px; font-weight:bold;">组用户查看</div>
<div id="userform" style="margin:5px 0;">
<form id="userform" >
用户ID(数字) <input type="text" id="addUserInputUid" name="uid" />
&nbsp;组ID(数字) <input type="text" id="addUserInputGid" name="gid" value="<?php if(!empty($this->groupid)) echo $this->groupid; ?>" readonly="readonly" />
<input type="hidden" name="ac" value="adduser" />
<i id="checkbtn_addUser">
<input type="button" class="btn btn-green" onclick="SubmitUser()" value="添加" />
</i>
</form>
</div>
<table>
<thead>
<tr>
<td width='150'>ID</td>
<td width='250'>用户名</td>
<td width='250'>姓名</td>
<td width='150'>操作</td>
</tr>
</thead><!-- table's head -->
<?php if (count($this->paginator)): ?>
<?php $autoindex=0;?>
<?php foreach ($this->paginator as $item): ?>
<?php $autoindex++;?>
<tr class="<?php if($autoindex%2 == 0) echo 'even'; else echo 'odd'; ?>" id="row_<?= $item['uid'];?>">
<td><?= $item['uid']?></td>
<td><?= $item['username']; ?></td>
<td><?= $item['realname']; ?></td>
<td>
<i id="del_chectbtn_<?= $item['id']?>"><a href='javascript:removeUserFromGroup(<?= $item['uid'];?>,<?= $item['gid'];?>);' onclick="return confirm('确定将此用户移除?')">移除</a></i>
<a href='/admin/user/show/id/<?= $item['id'];?>'>查看用户</a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</table>
<div class="pagenavi"><?= $this->paginator; ?></div>
</div>
<script>
//<-- users
function showuserform(){
$('#userform').toggle();
}
function SubmitUser(){
uid = $('#addUserInputUid').val();
gid = $('#addUserInputGid').val();
dom = '#checkbtn_addUser';
addUserToGroup(dom,uid,gid);
}
function addUserToGroup(dom,uid,gid){
html = $(dom).html();
$.ajax({
'type': "POST",
'url': "/admin/user/group/",
'data': 'ac=adduser&uid='+uid+'&gid='+gid,
'success': function(data){
if($.isEmptyObject(data)){Alert('遇到错误,请重试');return false;}
if(data.error!=null){Alert(data.error);return false;}
if(data.status==1){top.location=top.location;}
},
'beforeSend':function(){$(dom).html('<img src="/images/ajax-load-small.gif" />');},
'complete':function(){$(dom).html(html)},
'timeout': 20000,
'dataType': 'json',
'error': function(){Alert('处理中出现问题,请重试');return false;}
});
}
function removeUserFromGroup(uid,gid){
html = $('#del_chectbtn_'+uid).html();
$.ajax({
'type': "POST",
'url': "/admin/user/group/",
'data': 'ac=deluser&uid='+uid+'&gid='+gid,
'success': function(data){
if($.isEmptyObject(data)){Alert('遇到错误,请重试');return false;}
if(data.error!=null){Alert(data.error);return false;}
if(data.status==1){$('#row_'+uid).fadeOut();}
},
'beforeSend':function(){$('#del_chectbtn_'+uid).html('<img src="/images/ajax-load-small.gif" />');},
'complete':function(){$('#del_chectbtn_'+uid).html(html)},
'timeout': 20000,
'dataType': 'json',
'error': function(){Alert('处理中出现问题,请重试');}
});
}
// users -->
function Alert(html){
$.colorbox({'innerWidth':'50%','html':'<h4>'+html+'</h4>'});
}
</script>

View File

@ -0,0 +1,184 @@
<?php
$this->headTitle($this->config->title->site);
$this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - ');
$this->headLink()->appendStylesheet('/css/admin.css');
$this->headScript()->appendFile('/static/js/jquery-1.7.2.min.js');
$this->headScript()->appendFile('/js/jquery.colorbox-min.js');
$this->headLink()->appendStylesheet('/css/colorbox.css');
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin/">后台首页</a>');
$this->breadcrumb('<a href="/admin/user">用户管理</a>');
$this->breadcrumb()->setSeparator(' > ');
?>
<div id="leftPanel">
<?= $this->partial('user/left.phtml'); ?>
</div>
<?php if ($this->msg or $this->messages) :?>
<div id="message">
<?php if ($this->msg) : ?>
<p><?php echo $this->msg; ?></p>
<?php endif; if ($this->messages): foreach($this->messages as $msg): ?>
<p><?php echo $msg; ?></p>
<?php endforeach;endif; ?>
</div>
<?php endif; ?>
<div id="rightPanel">
<div style="font-size:16px;line-height:30px; font-weight:bold;">用户组</div>
<div class="search" style="margin:5px 0;">
<button type="button" class="btn" onclick="showaddform()">添加用户组</button>
<button type="button" class="btn" onclick="showuserform()">添加用户到组</button>
</div><!-- search DIV -->
<div id="addform" style="display: none;">
<form id="groupadd">
组名 <input type="text" name="name" />
<input type="hidden" name="ac" value="add" />
<i id="checkbtn">
<input type="button" class="btn btn-green" onclick="Submit()" value="添加" />
</i>
</form>
</div>
<div id="userform" style="margin:5px 0; display:none;">
<form id="userform" >
用户ID(数字) <input type="text" id="addUserInputUid" name="uid" />
&nbsp;组ID(数字) <input type="text" id="addUserInputGid" name="gid" />
<input type="hidden" name="ac" value="adduser" />
<i id="checkbtn_addUser">
<input type="button" class="btn btn-green" onclick="SubmitUser()" value="添加" />
</i>
</form>
</div>
<table>
<thead>
<tr>
<td width='150'>组ID</td>
<td width='250'>用户组</td>
<td width='150'>操作</td>
</tr>
</thead><!-- table's head -->
<?php if (count($this->paginator)): ?>
<?php $autoindex=0;?>
<?php foreach ($this->paginator as $item): ?>
<?php $autoindex++;?>
<tr class="<?php if($autoindex%2 == 0) echo 'even'; else echo 'odd'; ?>">
<td><?= $item['id']?></td>
<td id="name_<?= $item['id']?>"><?= $item['name']; ?></td>
<td>
<i id="del_chectbtn_<?= $item['id']?>"><a href='javascript:del(<?= $item['id'];?>);' onclick="return confirm('确定将此记录删除?')">删除</a></i>
<a href="javascript:;" onclick="showinput(<?= $item['id']?>);">编辑</a>
<a href='/admin/user/group/ac/show/id/<?= $item['id'];?>'>查看用户</a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</table>
<div class="pagenavi"><?= $this->paginator; ?></div>
</div>
<script>
//<-- group manage
function showaddform(){
$('#addform').toggle();
}
function Submit(){
$.ajax({
'type': "POST",
'url': "/admin/user/group/",
'data': $('#groupadd').serialize(),
'success': function(data){
if($.isEmptyObject(data)){Alert('遇到错误,请重试');return false;}
if(data.error!=null){Alert(data.error);return false;}
if(data.status==1){top.location=top.location;}
},
'beforeSend':function(){$('#checkbtn').html('<img src="/images/ajax-load-small.gif" />');},
'complete':function(){$('#checkbtn').html('<input type="button" class="btn btn-green" onclick="Submit()" value="添加" />')},
'timeout': 20000,
'dataType': 'json',
'error': function(){Alert('处理中出现问题,请重试');}
});
}
function del(id){
html = $('#del_chectbtn_'+id).html();
$.ajax({
'type': "POST",
'url': "/admin/user/group/",
'data': 'ac=del&id='+id,
'success': function(data){
if($.isEmptyObject(data)){Alert('遇到错误,请重试');return false;}
if(data.error!=null){Alert(data.error);return false;}
if(data.status==1){top.location=top.location;}
},
'beforeSend':function(){$('#del_chectbtn_'+id).html('<img src="/images/ajax-load-small.gif" />');},
'complete':function(){$('#del_chectbtn_'+id).html(html)},
'timeout': 20000,
'dataType': 'json',
'error': function(){Alert('处理中出现问题,请重试');}
});
}
function showinput(id){
var val = $('#name_'+id).html();
var input = '<input type="text" value="'+val+'" id="input_'+id+'" />';
input += '<button type="button" class="btn btn-green" onclick="edit('+id+')">修改</button>';
$('#name_'+id).html(input);
}
function edit(id){
html = $('#name_').html();
dom = '#name_'+id;
$.ajax({
'type': "POST",
'url': "/admin/user/group/",
'data': 'ac=edit&id='+id+'&name='+$('#input_'+id).val(),
'success': function(data){
if($.isEmptyObject(data)){Alert('遇到错误,请重试');return false;}
if(data.error!=null){Alert(data.error);return false;}
if(data.status==1){html = data.name}
},
'beforeSend':function(){$(dom).html('<img src="/images/ajax-load-small.gif" />');},
'complete':function(){$(dom).html(html)},
'timeout': 20000,
'dataType': 'json',
'error': function(){Alert('处理中出现问题,请重试');}
});
}
// group manage -->
//<-- users
function showuserform(){
$('#userform').toggle();
}
function SubmitUser(){
uid = $('#addUserInputUid').val();
gid = $('#addUserInputGid').val();
dom = '#checkbtn_addUser';
addUserToGroup(dom,uid,gid);
}
function addUserToGroup(dom,uid,gid){
html = $(dom).html();
$.ajax({
'type': "POST",
'url': "/admin/user/group/",
'data': 'ac=adduser&uid='+uid+'&gid='+gid,
'success': function(data){
if($.isEmptyObject(data)){Alert('遇到错误,请重试');return false;}
if(data.error!=null){Alert(data.error);return false;}
if(data.status==1){Alert('添加成功!');return true;}
},
'beforeSend':function(){$(dom).html('<img src="/images/ajax-load-small.gif" />');},
'complete':function(){$(dom).html(html)},
'timeout': 20000,
'dataType': 'json',
'error': function(){Alert('处理中出现问题,请重试');return false;}
});
}
// users -->
function Alert(html){
$.colorbox({'innerWidth':'50%','html':'<h4>'+html+'</h4>'});
}
</script>

View File

@ -3,5 +3,6 @@
<li><a href="/admin/user/">用户管理首页</a></li>
<li><a href="/admin/user/list">普通用户列表</a></li>
<li><a href="/admin/user/adminlist">管理员列表</a></li>
<li><a href="/admin/user/group">用户组管理</a></li>
<li><a href="/admin/review/experts">元数据评审专家库</a></li>
</ul>