添加同步管理员到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
use Helpers\View as view;
use Helpers\PDO;
class Admin_UserController extends Zend_Controller_Action
{
function preDispatch()
@ -117,12 +119,45 @@ class Admin_UserController extends Zend_Controller_Action
$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;
$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()

View File

@ -1,46 +1,47 @@
<?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('<a href="/admin/user">用户管理</a>');
$this->breadcrumb()->setSeparator(' > ');
?>
<div id="leftPanel">
<?= $this->partial('user/left.phtml'); ?>
</div>
<div id="rightPanel">
<div class="title">管理员列表</div>
<table>
<thead>
<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>
</thead>
<?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['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 class="pagenavi"><?= $this->paginator; ?></div>
<?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('<a href="/admin/user">用户管理</a>');
$this->breadcrumb()->setSeparator(' > ');
?>
<div id="leftPanel">
<?= $this->partial('user/left.phtml'); ?>
</div>
<div id="rightPanel">
<div class="title">管理员列表</div>
<div class=""><a href="/admin/user/adminlist/ac/sync">同步管理员到geonetwork</a></div>
<table>
<thead>
<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>
</thead>
<?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['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 class="pagenavi"><?= $this->paginator; ?></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);
}
}
}
}