添加同步管理员到geonetwork的功能

This commit is contained in:
Li Jianxuan 2014-03-25 09:21:28 +00:00
parent 72c353f435
commit 4381b008ae
3 changed files with 126 additions and 45 deletions

View File

@ -1,4 +1,6 @@
<?php <?php
use Helpers\View as view;
use Helpers\PDO;
class Admin_UserController extends Zend_Controller_Action class Admin_UserController extends Zend_Controller_Action
{ {
function preDispatch() function preDispatch()
@ -117,12 +119,45 @@ class Admin_UserController extends Zend_Controller_Action
$select->from('users') $select->from('users')
->where('usertype = ?', 'administrator') ->where('usertype = ?', 'administrator')
->order('users.id desc'); ->order('users.id desc');
$paginator = Zend_Paginator::factory($select); $paginator = Zend_Paginator::factory($select);
$paginator->setCurrentPageNumber($this->_getParam('page')); $paginator->setCurrentPageNumber($this->_getParam('page'));
$paginator->setItemCountPerPage(30); $paginator->setItemCountPerPage(30);
$paginator->setView($this->view); $paginator->setView($this->view);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml'); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
$this->view->paginator=$paginator; $this->view->paginator=$paginator;
$ac = $this->_getParam('ac');
if($ac == 'sync')
{
$sql = "SELECT id FROM users WHERE usertype='administrator'";
$rs = $this->db->query($sql);
$ids = $rs->fetchAll();
$data = array();
foreach($ids as $v)
{
$data[] = $v['id'];
}
unset($ids);
$ids = join(",",$data);
$gn_sql = "update users set profile='Administrator' where id in ($ids)";
$gn_db = new PDO(array(
'host'=> $this->view->config->geonetwork->params->host,
'port' => 5432,
'user' => $this->view->config->geonetwork->params->username,
'pwd' => $this->view->config->geonetwork->params->password ,
'db' => $this->view->config->geonetwork->params->dbname
));
$gn_db->exec($gn_sql);
view::Post($this,"同步成功!",-1);
}
} }
function showAction() function showAction()

View File

@ -1,46 +1,47 @@
<?php <?php
$this->headTitle($this->config->title->site); $this->headTitle($this->config->title->site);
$this->headTitle('后台管理'); $this->headTitle('后台管理');
$this->headTitle()->setSeparator(' - '); $this->headTitle()->setSeparator(' - ');
$this->headLink()->appendStylesheet('/css/admin.css'); $this->headLink()->appendStylesheet('/css/admin.css');
$this->breadcrumb('<a href="/">首页</a>'); $this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/admin/">后台首页</a>'); $this->breadcrumb('<a href="/admin/">后台首页</a>');
$this->breadcrumb('<a href="/admin/user">用户管理</a>'); $this->breadcrumb('<a href="/admin/user">用户管理</a>');
$this->breadcrumb()->setSeparator(' > '); $this->breadcrumb()->setSeparator(' > ');
?> ?>
<div id="leftPanel"> <div id="leftPanel">
<?= $this->partial('user/left.phtml'); ?> <?= $this->partial('user/left.phtml'); ?>
</div> </div>
<div id="rightPanel"> <div id="rightPanel">
<div class="title">管理员列表</div> <div class="title">管理员列表</div>
<table> <div class=""><a href="/admin/user/adminlist/ac/sync">同步管理员到geonetwork</a></div>
<thead> <table>
<tr> <thead>
<td width='150'>用户名</td> <tr>
<td width='250'>电子邮箱</td> <td width='150'>用户名</td>
<td width='100'>用户类型</td> <td width='250'>电子邮箱</td>
<td width='150'>真实姓名</td> <td width='100'>用户类型</td>
<td width='150'>电话</td> <td width='150'>真实姓名</td>
<td width='150'>操作</td> <td width='150'>电话</td>
</tr> <td width='150'>操作</td>
</thead> </tr>
<?php if (count($this->paginator)): ?> </thead>
<?php $autoindex=0;?> <?php if (count($this->paginator)): ?>
<?php foreach ($this->paginator as $item): ?> <?php $autoindex=0;?>
<?php $autoindex++;?> <?php foreach ($this->paginator as $item): ?>
<tr class="<?php if($autoindex%2 == 0) echo 'even'; else echo 'odd'; ?>"> <?php $autoindex++;?>
<td><?= $item['username']?></td> <tr class="<?php if($autoindex%2 == 0) echo 'even'; else echo 'odd'; ?>">
<td><?= $item['email']; ?></td> <td><?= $item['username']?></td>
<td><?= $item['usertype']; ?></td> <td><?= $item['email']; ?></td>
<td><?= $item['realname']; ?></td> <td><?= $item['usertype']; ?></td>
<td><?= $item['phone']; ?></td> <td><?= $item['realname']; ?></td>
<td> <td><?= $item['phone']; ?></td>
<a href='/admin/user/show/id/<?= $item['id'];?>'>查看详细</a> <td>
</td> <a href='/admin/user/show/id/<?= $item['id'];?>'>查看详细</a>
</tr> </td>
<?php endforeach; ?> </tr>
<?php endif; ?> <?php endforeach; ?>
</table> <?php endif; ?>
<div class="pagenavi"><?= $this->paginator; ?></div> </table>
<div class="pagenavi"><?= $this->paginator; ?></div>
</div> </div>

View File

@ -0,0 +1,45 @@
<?php
namespace Helpers;
class PDO extends \PDO
{
private $debug = 0; //调试模式
private $config_local_path = "config/autoload/local.php";
public $db_cfg;
function __construct($DSN = NULL)
{
if(empty($DSN))
{
$config_local = new Zend_Config(include $this->config_local_path);
$dsn = "pgsql:host={$config_local->db->hostname};"
."port=5432;"
."dbname={$config_local->db->database};"
."user={$config_local->db->username};"
."password={$config_local->db->password}";
parent::__construct($dsn);
}
else{
if(is_string($DSN))
{
parent::__construct($DSN);
}
else{
$dsn = "pgsql:host={$DSN['host']};"
."port={$DSN['port']};"
."dbname={$DSN['db']};"
."user={$DSN['user']};"
."password={$DSN['pwd']}";
parent::__construct($dsn);
}
}
}
}