fix ticket #147, 实现后台用户管理
This commit is contained in:
parent
fe555c4b8f
commit
54c27d0dbf
|
@ -0,0 +1,178 @@
|
|||
<?php
|
||||
class Admin_UserController extends Zend_Controller_Action
|
||||
{
|
||||
function preDispatch()
|
||||
{
|
||||
$this->db=Zend_Registry::get('db');
|
||||
$this->view->config = Zend_Registry::get('config');
|
||||
$this->messenger=$this->_helper->getHelper('FlashMessenger');
|
||||
$this->view->messages = $this->messenger->getMessages();
|
||||
}
|
||||
function postDispatch()
|
||||
{
|
||||
$this->view->messages = $this->messenger->getMessages();
|
||||
}
|
||||
function indexAction()
|
||||
{
|
||||
//其他连接
|
||||
}
|
||||
|
||||
function listAction()
|
||||
{
|
||||
$select=$this->db->select();
|
||||
$select->from('users')
|
||||
->where('usertype = ?', 'member')
|
||||
->order('users.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;
|
||||
}
|
||||
|
||||
function deleteAction()
|
||||
{
|
||||
$delete=(int)$this->_getParam('id');
|
||||
$deletename = $this->_getParam('uname');
|
||||
|
||||
if (isset($delete))
|
||||
{
|
||||
$sql="delete from users where id=?";
|
||||
try {
|
||||
$this->db->query($sql,array($delete));
|
||||
$this->messenger->addMessage('您已经成功的删除了用户:'.$deletename);
|
||||
} catch (Exception $e) {
|
||||
$this->messenger->addMessage($e->getMessage());
|
||||
}
|
||||
$this->_redirect("/admin/user/list");
|
||||
}
|
||||
}
|
||||
|
||||
function adminlistAction()
|
||||
{
|
||||
$select=$this->db->select();
|
||||
$select->from('users')
|
||||
->where('usertype = ?', 'administrator')
|
||||
->order('users.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;
|
||||
}
|
||||
|
||||
function showAction()
|
||||
{
|
||||
$id=(int)$this->_getParam('id');
|
||||
if (isset($id))
|
||||
{
|
||||
try {
|
||||
$sql="select * from users where id=?";
|
||||
$result=$this->db->query($sql,$id);
|
||||
$rows = $result->fetch();
|
||||
$this->view->infos=$rows;
|
||||
} catch (Exception $e) {
|
||||
$this->messenger->addMessage($e->getMessage());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_redirect("/admin/user/list");
|
||||
}
|
||||
}
|
||||
|
||||
function editAction()
|
||||
{
|
||||
$id=(int)$this->_getParam('id');
|
||||
$usertype=$this->_getParam('usertype');
|
||||
$newpwd=$this->_getParam('newpwd');
|
||||
$cfnewpwd=$this->_getParam('cfnewpwd');
|
||||
$sql="";
|
||||
$updates=array();
|
||||
if (isset($id))
|
||||
{
|
||||
if(!empty($newpwd)&&!empty($cfnewpwd))
|
||||
{
|
||||
if($newpwd==$cfnewpwd)
|
||||
{
|
||||
$password=md5($newpwd);
|
||||
$updates[]="password='$password'";
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->messenger->addMessage('两次密码不相同');
|
||||
$this->_redirect("/admin/user/show/id/$id");
|
||||
}
|
||||
}
|
||||
if(isset($usertype))
|
||||
{
|
||||
$updates[]="usertype='$usertype'";
|
||||
}
|
||||
|
||||
$update=join(',',$updates);
|
||||
$sql="update users set $update where id='$id'";
|
||||
|
||||
try {
|
||||
$this->db->query($sql);
|
||||
$this->messenger->addMessage('编辑成功!');
|
||||
} catch (Exception $e) {
|
||||
$this->messenger->addMessage($e->getMessage());
|
||||
}
|
||||
$this->_redirect("/admin/user/show/id/$id");
|
||||
}
|
||||
else {
|
||||
$this->_redirect("/admin/user/list");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function fetchpwdAction()
|
||||
{
|
||||
$id=(int)$this->_getParam('id');
|
||||
$email=$this->_getParam('email');
|
||||
if (!empty($email))
|
||||
{
|
||||
try {
|
||||
$sql="select * from users where email=?";
|
||||
$uq=$this->db->query($sql,$email);
|
||||
if ($urow=$uq->fetch())
|
||||
{
|
||||
//email the url to user
|
||||
$username=$urow['username'];
|
||||
$sql="update users set activation=? where email=?";
|
||||
$uid=uniqid();
|
||||
$this->db->query($sql,array($uid,$email));
|
||||
$mail=new WestdcMailer($this->view->config->smtp);
|
||||
$body="尊敬的西部数据中心用户:
|
||||
有人提出了针对此用户名的密码重置请求。
|
||||
|
||||
用户名:";
|
||||
$body.=$username;
|
||||
$body.="
|
||||
|
||||
若想重置您的密码请打开下面的链接,否则请忽略此邮件,一切如常。
|
||||
";
|
||||
$body.="http://westdc.westgis.ac.cn/account/fetchpwd/".$username."/".$uid;
|
||||
$mail->setBodyText($body);
|
||||
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
|
||||
$mail->addTo($email);
|
||||
$mail->setSubject('密码已重置');
|
||||
$mail->send();
|
||||
$this->messenger->addMessage('密码重置成功!');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->messenger->addMessage($e->getMessage().$email);
|
||||
}
|
||||
$this->_redirect("/admin/user/show/id/$id");
|
||||
}
|
||||
else {
|
||||
$this->_redirect("/admin/user/list");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//overview
|
||||
}
|
||||
|
|
@ -8,8 +8,7 @@
|
|||
<li><a href="/admin"><span>后台首页</span></a></li>
|
||||
<li><a href="/admin/data"><span>数据管理</span></a></li>
|
||||
<li><a href="/admin/down"><span>申请管理</span></a></li>
|
||||
|
||||
<li><a href="/admin/account"><span>用户管理</span></a></li>
|
||||
<li><a href="/admin/user"><span>用户管理</span></a></li>
|
||||
<li><a href="/admin/stat"><span>统计数据</span></a></li>
|
||||
</ul>
|
||||
<div id="userNavi">
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
<li><a href="/admin/watermd">WATER元数据处理工具</a></li>
|
||||
<li><a href="/admin/test">数据测试管理</a></li>
|
||||
<li><a href="/admin/dbtool">数据库工具</a></li>
|
||||
<li><a href="/admin/user">用户管理</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
$this->headTitle($this->config->title->site);
|
||||
$this->headTitle('后台管理');
|
||||
$this->headTitle()->setSeparator(' - ');
|
||||
$this->headLink()->appendStylesheet('/css/admin.css');
|
||||
$this->breadcrumb('<a href="/">首页</a>');
|
||||
$this->breadcrumb('后台管理首页');
|
||||
$this->breadcrumb()->setSeparator(' > ');
|
||||
?>
|
||||
<div id="divContent">
|
||||
|
||||
<div id="leftPanel">
|
||||
用户管理工具:
|
||||
<ul>
|
||||
<li><a href="/admin/user/list">普通用户列表</a></li>
|
||||
<li><a href="/admin/user/adminlist">管理员列表</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="rightPanel">
|
||||
<table>
|
||||
<tr>
|
||||
<td width='150'>用户名</td>
|
||||
<td width='250'>电子邮箱</td>
|
||||
<td width='100'>用户类型</td>
|
||||
<td width='150'>真实姓名</td>
|
||||
<td width='150'>电话</td>
|
||||
<td width='150'>操作</td>
|
||||
</tr>
|
||||
<?php if (count($this->paginator)): ?>
|
||||
<?php foreach ($this->paginator as $item): ?>
|
||||
<tr>
|
||||
<td><?= $item['username']?></td>
|
||||
<td><?= $item['email']; ?></td>
|
||||
<td><?= $item['usertype']; ?></td>
|
||||
<td><?= $item['realname']; ?></td>
|
||||
<td><?= $item['phone']; ?></td>
|
||||
<td>
|
||||
<a href='/admin/user/show/id/<?= $item['id'];?>'>查看详细</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</table>
|
||||
<div style="width:50%;text-align:left;">
|
||||
<?= $this->paginator; ?>
|
||||
</div>
|
||||
|
||||
</div>
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
$this->headTitle($this->config->title->site);
|
||||
$this->headTitle('后台管理');
|
||||
$this->headTitle()->setSeparator(' - ');
|
||||
$this->headLink()->appendStylesheet('/css/admin.css');
|
||||
$this->breadcrumb('<a href="/">首页</a>');
|
||||
$this->breadcrumb('后台管理首页');
|
||||
$this->breadcrumb()->setSeparator(' > ');
|
||||
?>
|
||||
<div id="divContent">
|
||||
|
||||
<div id="leftPanel">
|
||||
用户管理工具:
|
||||
<ul>
|
||||
<li><a href="/admin/user/list">普通用户列表</a></li>
|
||||
<li><a href="/admin/user/adminlist">管理员列表</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="rightPanel">
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
$this->headTitle($this->config->title->site);
|
||||
$this->headTitle('后台管理');
|
||||
$this->headTitle()->setSeparator(' - ');
|
||||
$this->headLink()->appendStylesheet('/css/admin.css');
|
||||
$this->breadcrumb('<a href="/">首页</a>');
|
||||
$this->breadcrumb('<a href="/admin">后台管理首页</a>');
|
||||
$this->breadcrumb('用户列表');
|
||||
$this->breadcrumb()->setSeparator(' > ');
|
||||
?>
|
||||
<div id="divContent">
|
||||
|
||||
<div id="leftPanel">
|
||||
用户管理工具:
|
||||
<ul>
|
||||
<li><a href="/admin/user/list">普通用户列表</a></li>
|
||||
<li><a href="/admin/user/adminlist">管理员列表</a></li>
|
||||
</ul>
|
||||
</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">
|
||||
<table>
|
||||
<tr>
|
||||
<td width='150'>用户名</td>
|
||||
<td width='250'>电子邮箱</td>
|
||||
<td width='100'>用户类型</td>
|
||||
<td width='150'>真实姓名</td>
|
||||
<td width='150'>操作</td>
|
||||
</tr>
|
||||
<?php if (count($this->paginator)): ?>
|
||||
<?php foreach ($this->paginator as $item): ?>
|
||||
<tr>
|
||||
<td><?= $item['username']?></td>
|
||||
<td><?= $item['email']; ?></td>
|
||||
<td><?= $item['usertype']; ?></td>
|
||||
<td><?= $item['realname']; ?></td>
|
||||
<td>
|
||||
<a href='/admin/user/delete/id/<?= $item['id'];?>/uname/<?= $item['username'];?>' onclick="return confirm('确定将此记录删除?')">删除</a>
|
||||
<a href='/admin/user/show/id/<?= $item['id'];?>'>查看详细</a>
|
||||
<a href='/admin/user/fetchpwd/email/<?= $item['email'];?>/id/<?= $item['id'];?>' onclick="return confirm('是否确定为他重置密码?')">重置密码</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</table>
|
||||
<div style="width:50%;text-align:left;">
|
||||
<?= $this->paginator; ?>
|
||||
</div>
|
||||
|
||||
</div>
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
$this->headTitle($this->config->title->site);
|
||||
$this->headTitle('后台管理');
|
||||
$this->headTitle()->setSeparator(' - ');
|
||||
$this->headLink()->appendStylesheet('/css/admin.css');
|
||||
$this->breadcrumb('<a href="/">首页</a>');
|
||||
$this->breadcrumb('<a href="/admin">后台管理首页</a>');
|
||||
$this->breadcrumb('用户列表');
|
||||
$this->breadcrumb()->setSeparator(' > ');
|
||||
?>
|
||||
<div id="divContent">
|
||||
|
||||
<div id="leftPanel">
|
||||
用户管理工具:
|
||||
<ul>
|
||||
<li><a href="/admin/user/list">普通用户列表</a></li>
|
||||
<li><a href="/admin/user/adminlist">管理员列表</a></li>
|
||||
</ul>
|
||||
</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">
|
||||
<form name="form1" method="post" action="/admin/user/edit">
|
||||
<table>
|
||||
<tr><td>ID</td><td><?= $this->infos['id'];?></td></tr>
|
||||
<tr><td>用户名</td><td><?= $this->infos['username'];?></td></tr>
|
||||
<tr><td>真实姓名</td><td><?= $this->infos['realname'];?></td></tr>
|
||||
<tr><td>电子邮箱</td><td><?= $this->infos['email'];?></td></tr>
|
||||
<tr><td>注册时间</td><td><?=$this->infos['ts_created'];?></td></tr>
|
||||
<tr><td>最后登陆时间</td><td><?= $this->infos['ts_last_login'];?></td></tr>
|
||||
<tr><td>单位</td><td><?= $this->infos['unit'];?></td></tr>
|
||||
<tr><td>地址</td><td><?= $this->infos['address'];?></td></tr>
|
||||
<tr><td>电话</td><td><?= $this->infos['phone'];?></td></tr>
|
||||
<tr><td>项目</td><td><?= $this->infos['project'];?></td></tr>
|
||||
<tr><td>用户权限</td><td>
|
||||
<select name="usertype">
|
||||
<?php
|
||||
|
||||
if ($this->infos['usertype']=='member')
|
||||
|
||||
{ echo "
|
||||
<option value='member' selected='selected'>普通会员</option>
|
||||
<option value='administrator'>系统管理员</option>
|
||||
";}
|
||||
|
||||
else if($this->infos['usertype']=='administrator')
|
||||
|
||||
{ echo "<option value='administrator' selected='selected'>系统管理员</option>
|
||||
<option value='member'>普通会员</option>
|
||||
";}
|
||||
?>
|
||||
</select>
|
||||
</td></tr>
|
||||
<tr><td>用户密码</td><td><input type='password' name="newpwd" /></td></tr>
|
||||
<tr><td>确认用户密码</td><td><input type='password' name="cfnewpwd" /></td></tr>
|
||||
</table>
|
||||
<input type='hidden' value="<?php echo $this->infos['id'];?>" name='id' />
|
||||
<input type="submit" value="提交" />
|
||||
</form>
|
||||
<form name="lostpwd" action="/admin/user/fetchpwd">
|
||||
<input type="hidden" name="id" value="<?= $this->infos['id'];?>" />
|
||||
<input type="hidden" name="email" value="<?= $this->infos['email'];?>" />
|
||||
<input type="submit" value="为他执行重置密码"/>
|
||||
</form>
|
||||
</div>
|
Loading…
Reference in New Issue