diff --git a/application/admin/controllers/UserController.php b/application/admin/controllers/UserController.php index b9c84727..43045e38 100755 --- a/application/admin/controllers/UserController.php +++ b/application/admin/controllers/UserController.php @@ -59,10 +59,10 @@ class Admin_UserController extends Zend_Controller_Action { $this->messenger->addMessage('搜索结果'); $select->from('users'); - if(!empty($realname)) + if(!empty($realname)) { - $select->where('realname like ? ', '%'.$realname.'%'); - $select->orWhere('username like ? ', '%'.$realname.'%'); + $select->where('realname like ? ', '%'.$realname.'%'); + $select->orWhere('username like ? ', '%'.$realname.'%'); } if(!empty($unit)) $select->where('unit like ? ', '%'.$unit.'%'); @@ -279,8 +279,229 @@ class Admin_UserController extends Zend_Controller_Action $this->_redirect("/admin/user/list"); } - } - - //overview + } //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; + } + + 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; + } } diff --git a/application/admin/views/scripts/user/group-users.phtml b/application/admin/views/scripts/user/group-users.phtml new file mode 100644 index 00000000..6bc06561 --- /dev/null +++ b/application/admin/views/scripts/user/group-users.phtml @@ -0,0 +1,122 @@ +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('首页'); + $this->breadcrumb('后台首页'); + $this->breadcrumb('用户管理'); + $this->breadcrumb()->setSeparator(' > '); +?> +
msg; ?>
+messages): foreach($this->messages as $msg): ?> + + +ID | +用户名 | +姓名 | +操作 | +
= $item['uid']?> | += $item['username']; ?> | += $item['realname']; ?> | ++,= $item['gid'];?>);' onclick="return confirm('确定将此用户移除?')">移除 +'>查看用户 + | +
msg; ?>
+messages): foreach($this->messages as $msg): ?> + + +组ID | +用户组 | +操作 | +
= $item['id']?> | += $item['name']; ?> | ++);' onclick="return confirm('确定将此记录删除?')">删除 +编辑 +'>查看用户 + | +