2011-09-19 09:33:50 +00:00
< ? php
class Admin_DataController 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 ()
{
//其他连接
}
//提供和GEONETWORK中的元数据的同步功能
//提供双向同步功能, 但只处理ISO 19115格式的元数据?
function syncAction ()
{
set_time_limit ( 0 );
$sql = " select * from (select count(*) as westdccount from metadata) as t1,(select count(uuid) as gncount from geonetworkmetadata where schemaid='iso19115') as t2,(select count(uuid) as watergncount from watergn where schemaid='iso19115') as t3 " ;
$this -> db -> setFetchMode ( Zend_Db :: FETCH_OBJ );
$this -> view -> mdcount = $this -> db -> fetchRow ( $sql );
$source = $this -> _request -> getParam ( 'source' );
$delete = $this -> _request -> getParam ( 'delete' );
$thumb = $this -> _request -> getParam ( 'thumb' );
$list = $this -> _request -> getParam ( 'list' );
$adminuser = $this -> _request -> getParam ( 'adminuser' );
$uuid = $this -> _request -> getParam ( 'uuid' );
if ( $this -> _request -> isPost ()) $uuid = $this -> _request -> getPost ( 'uuid' );
//$uuid=$this->_request->getParam('uuid');
if ( $source == " geonetwork " && empty ( $uuid ) ) {
//从geonetwork向WESTDC同步
2011-10-25 08:48:51 +00:00
$sql = " select uuid,data,source from geonetworkmetadata where schemaid='iso19115' " ;
2011-09-19 09:33:50 +00:00
$rs = $this -> db -> fetchAll ( $sql );
foreach ( $rs as $gmd ) {
$this -> import ( $gmd -> data );
$this -> db -> query ( " update metadata set source=? where uuid=? " , array ( $gmd -> source , $gmd -> uuid ));
}
$this -> view -> msg = '成功同步元数据!' ;
} elseif ( $source == " watergn " && empty ( $uuid ) ) {
//首先删除所有的黑河试验数据
2011-10-14 09:33:44 +00:00
//$sql="delete from metadata where source='e3ad32dc-f573-11e0-aa7b-b768cfd88d80'";
2011-10-25 08:48:51 +00:00
$sql = " delete from metadata where uuid in (select uuid from watergn) " ;
2011-10-14 09:33:44 +00:00
$this -> db -> query ( $sql );
2011-09-19 09:33:50 +00:00
$sql = " delete from responsible where id not in (select distinct(resid) from role) " ;
$this -> db -> query ( $sql );
//同步黑河遥感实验的元数据
2011-10-25 08:48:51 +00:00
$sql = " select uuid,data,source from watergn where schemaid='iso19115' " ;
2011-09-19 09:33:50 +00:00
$rs = $this -> db -> fetchAll ( $sql );
foreach ( $rs as $gmd ) {
$this -> import ( $gmd -> data );
$this -> db -> query ( " update metadata set source=? where uuid=? " , array ( $gmd -> source , $gmd -> uuid ));
}
$this -> view -> msg = '成功同步黑河遥感综合实验元数据!' ;
2011-09-19 15:12:35 +00:00
} elseif ( $source == " westdc " && empty ( $uuid ) ) {
//从westdc向geonetwork同步
2011-09-28 01:29:21 +00:00
$sql = " select m.uuid,m.source,x.data from metadata m left join xml x on m.id=x.id where m.uuid not in (select uuid from geonetworkmetadata) " ;
$rs = $this -> db -> fetchAll ( $sql );
foreach ( $rs as $gmd ) {
$sql = " insert into geonetworkmetadata (uuid,source,data) values(' " . $gmd -> uuid . " ',' " . $gmd -> source . " ', " . $this -> db -> quote ( $gmd -> data ) . " ) " ;
$this -> db -> exec ( $sql );
}
$sql = " select m.uuid,m.source,x.data from metadata m left join xml x on m.id=x.id where m.uuid in (select uuid from geonetworkmetadata) " ;
$rs = $this -> db -> fetchAll ( $sql );
foreach ( $rs as $gmd ) {
2011-10-26 08:50:00 +00:00
$sql = " update geonetworkmetadata set source=' " . $gmd -> source . " ',data= " . $this -> db -> quote ( $gmd -> data ) . " where uuid=' " . $gmd -> uuid . " ' " ;
2011-09-28 01:29:21 +00:00
$this -> db -> exec ( $sql );
}
2011-09-20 02:13:59 +00:00
$this -> view -> msg = '成功同步WESTDC元数据到GEONETWORK! ' ;
2011-09-19 09:33:50 +00:00
} elseif ( ! empty ( $uuid ) && isset ( $_POST [ 'submit' ])) {
//同步单条元数据
2011-10-25 09:59:48 +00:00
$sql = $this -> db -> quoteInto ( " select data,source from geonetworkmetadata where uuid=? " , $uuid );
2011-09-19 09:33:50 +00:00
if ( $rs = $this -> db -> fetchRow ( $sql )) {
2011-10-26 08:50:00 +00:00
$this -> import ( $rs -> data );
2011-10-25 09:59:48 +00:00
$this -> db -> exec ( $this -> db -> quoteInto ( " update metadata set source=? where uuid=' $uuid ' " , $rs -> source ));
2011-09-19 09:33:50 +00:00
$this -> view -> msg = '成功同步元数据:' . $uuid ;
} else $this -> view -> msg = '不存在此元数据:' . $uuid ;
2011-09-20 07:23:02 +00:00
} elseif ( ! empty ( $uuid ) && isset ( $_POST [ 'gnsubmit' ])) {
//同步单条元数据到geonetwork
$sql = $this -> db -> quoteInto ( " select m.uuid,m.source,x.data,g.id from metadata m left join xml x on m.id=x.id left join geonetworkmetadata g on g.uuid=m.uuid where m.uuid=? " , $uuid );
if ( $gmd = $this -> db -> fetchRow ( $sql )) {
2011-09-28 01:29:21 +00:00
if ( ! empty ( $gmd -> id )) {
$sql = " update geonetworkmetadata set source=' " . $gmd -> source . " ',data= " . $this -> db -> quote ( $gmd -> data ) . " where uuid=' " . $gmd -> uuid . " ' " ;
} else {
$sql = " insert into geonetworkmetadata (uuid,source,data) values(' " . $gmd -> uuid . " ',' " . $gmd -> source . " ', " . $this -> db -> quote ( $gmd -> data ) . " ) " ;
}
2011-09-20 07:23:02 +00:00
$this -> db -> exec ( $sql );
$this -> view -> msg = '成功同步元数据:' . $uuid ;
2011-09-28 01:29:21 +00:00
} else $this -> view -> msg = '不存在此元数据:' . $uuid ;
2011-09-19 09:33:50 +00:00
} elseif ( ! empty ( $uuid ) && isset ( $_POST [ 'watersubmit' ])) {
//同步单条元数据
2011-10-25 09:59:48 +00:00
$sql = $this -> db -> quoteInto ( " select data,source from watergn where uuid=? " , $uuid );
2011-09-20 08:43:48 +00:00
if ( $rs = $this -> db -> fetchRow ( $sql )) {
2011-10-26 08:50:00 +00:00
$this -> import ( $rs -> data );
2011-10-20 06:57:30 +00:00
$this -> db -> query ( " update metadata set source=? where uuid=? " , array ( $rs -> source , $uuid ));
2011-09-20 08:43:48 +00:00
$this -> view -> msg = '成功同步元数据:' . $uuid ;
2011-09-28 01:29:21 +00:00
} else $this -> view -> msg = '不存在此元数据:' . $uuid ;
2011-09-20 08:43:48 +00:00
} elseif ( ! empty ( $uuid )) {
//同步单条元数据
2011-10-25 09:59:48 +00:00
$sql = $this -> db -> quoteInto ( " select data,source from geonetworkmetadata where uuid=? " , $uuid );
2011-09-19 09:33:50 +00:00
if ( $rs = $this -> db -> fetchRow ( $sql )) {
2011-10-26 08:50:00 +00:00
$this -> import ( $rs -> data );
2011-10-25 09:59:48 +00:00
$this -> db -> query ( " update metadata set source=? where uuid=? " , array ( $rs -> source , $uuid ));
2011-09-19 09:33:50 +00:00
$this -> view -> msg = '成功同步元数据:' . $uuid ;
} else $this -> view -> msg = '不存在此元数据:' . $uuid ;
} elseif ( $list == 'water' ) {
$sql = " select uuid,title from metadata where uuid not in (select uuid from watergn where schemaid='iso19115') and uuid not in (select uuid from geonetworkmetadata where schemaid='iso19115') " ;
$this -> view -> metadata = $this -> db -> query ( $sql );
} elseif ( $delete == 'westdc' ) {
$sql = " delete from metadata where uuid not in (select uuid from geonetworkmetadata where schemaid='iso19115') " ;
$this -> db -> query ( $sql );
$this -> view -> msg = '已删除WESTDC中多出的元数据! ' ;
2011-10-26 08:50:00 +00:00
} elseif ( $delete == 'geonetwork' ) {
//dblink view中删除多条有问题, 暂时用单条删除替代
//$sql="delete from geonetworkmetadata where uuid not in (select uuid from metadata)";
$sql = " select uuid from geonetworkmetadata where uuid not in (select uuid from metadata) " ;
$rows = $this -> db -> fetchAll ( $sql );
foreach ( $rows as $row )
{
$this -> db -> exec ( $this -> db -> quoteInto ( " delete from geonetworkmetadata where uuid=? " , $row -> uuid ));
2011-10-25 07:34:26 +00:00
}
$this -> view -> msg = '已删除GEONETWORK中多出的元数据! ' ;
2011-09-19 09:33:50 +00:00
} elseif ( $delete == 'water' ) {
$sql = " delete from metadata where uuid not in (select uuid from watergn where schemaid='iso19115') and uuid not in (select uuid from geonetworkmetadata where schemaid='iso19115') " ;
$this -> db -> query ( $sql );
$this -> view -> msg = '已删除WESTDC中多出的元数据! ' ;
} elseif ( $thumb == 'geonetwork' ) {
$sql = " select g.id as gid,m.uuid,t.* from thumbnail t left join metadata m on t.id=m.id left join geonetworkmetadata g on m.uuid=g.uuid where t.filetype is not null and t.filename is not null " ;
$rows = $this -> db -> fetchAll ( $sql );
foreach ( $rows as $row ) {
$data = file_get_contents ( $this -> view -> config -> geonetwork -> url . 'srv/cn/resources.get?access=public&id=' . $row -> gid . '&fname=' . urlencode ( $row -> filename ));
$sql = " update thumbnail set data=? where id=? " ;
$this -> db -> query ( $sql , array ( base64_encode ( $data ), $row -> id ));
}
$this -> view -> msg = '已成功同步缩略图!' ;
} elseif ( $thumb == 'water' ) {
2011-11-14 02:32:54 +00:00
$sql = " select g.id as gid,m.uuid,t.* from watergn g left join metadata m on m.uuid=g.uuid left join thumbnail t on t.id=m.id where t.filetype is not null and t.filename is not null " ;
2011-09-19 09:33:50 +00:00
$rows = $this -> db -> fetchAll ( $sql );
foreach ( $rows as $row ) {
$data = file_get_contents ( $this -> view -> config -> watergeonetwork -> url . 'srv/cn/resources.get?access=public&id=' . $row -> gid . '&fname=' . urlencode ( $row -> filename ));
$sql = " update thumbnail set data=? where id=? " ;
$this -> db -> query ( $sql , array ( base64_encode ( $data ), $row -> id ));
}
$this -> view -> msg = '已成功同步缩略图!' ;
} elseif ( $adminuser == 'geonetwork' ) {
2012-03-16 06:19:31 +00:00
$sql = " select id,username,password,email from users " ;
2011-09-19 09:33:50 +00:00
$rows = $this -> db -> fetchAll ( $sql );
foreach ( $rows as $row ) {
$sql = " select * from geonetworkusers where id=? " ;
$r = $this -> db -> fetchRow ( $sql , array ( $row -> id ));
if ( $r ) {
2012-03-16 06:19:31 +00:00
$sql = " update geonetworkusers set username=' $row->username ',password=encode(digest(md5(' $row->password '),'sha1'),'hex'),email=' $row->email ' where id= $row->id " ;
2011-09-19 09:33:50 +00:00
$this -> db -> query ( $sql );
} else {
2012-03-16 06:19:31 +00:00
$sql = " insert into geonetworkusers (id,username,password,email) values( $row->id ,' $row->username ',encode(digest(md5(' $row->password '),'sha1'),'hex'),' $row->email ') " ;
2011-09-19 09:33:50 +00:00
$this -> db -> query ( $sql );
}
}
2012-03-16 06:19:31 +00:00
$this -> view -> msg = '已成功同步帐号!' ;
2011-09-19 09:33:50 +00:00
}
}
function datasetcdAction ()
{
$add = ( int ) $this -> _getParam ( 'add' );
$edit = ( int ) $this -> _getParam ( 'edit' );
$delete = ( int ) $this -> _getParam ( 'delete' );
if ( $add ) {
$form = new DatasetcdForm ();
$form -> img -> setRequired ( true );
$form -> document -> setRequired ( true );
if ( $this -> _request -> isPost ()) {
$formdata = $this -> _request -> getPost ();
if ( $form -> isValid ( $formdata )) {
$uploadedData = $form -> getValues ();
$img = '/' . $form -> img -> getFileName ();
$document = '/' . $form -> document -> getFileName ();
$sql = " insert into datasetcd (title,size,uuid,img,document,descript) values(?,?,?,?,?,?) " ;
$this -> db -> query ( $sql , array ( $formdata [ 'title' ], $formdata [ 'size' ], $formdata [ 'uuid' ], $img , $document , $formdata [ 'descript' ]));
$this -> messenger -> addMessage ( '提示信息:您已经成功添加该特色数据集。' );
$this -> _redirect ( '/admin/data/datasetcd' );
} else {
$form -> populate ( $formdata );
}
}
$this -> view -> form = $form ;
$this -> _helper -> viewRenderer ( 'datasetcdadd' );
} elseif ( $edit ){
$form = new DatasetcdForm ();
if ( $this -> _request -> isPost ()) {
$formdata = $this -> _request -> getPost ();
if ( $form -> isValid ( $formdata )) {
$uploadedData = $form -> getValues ();
$img = '/' . $form -> img -> getFileName ();
$document = '/' . $form -> document -> getFileName ();
$sql = " update datasetcd set title=?,size=?,uuid=?, " ;
if ( $form -> img -> isUploaded ()) $sql .= " img=?, " ;
if ( $form -> document -> isUploaded ()) $sql .= " document=?, " ;
$sql .= " descript=? where id=? " ;
$param = array ( $formdata [ 'title' ], $formdata [ 'size' ], $formdata [ 'uuid' ]);
if ( $form -> img -> isUploaded ()) $param [] = $img ;
if ( $form -> document -> isUploaded ()) $param [] = $document ;
$param [] = $formdata [ 'descript' ];
$param [] = $edit ;
$this -> db -> query ( $sql , $param );
$this -> messenger -> addMessage ( '提示信息:您已经编辑添加该特色数据集。' );
$this -> _redirect ( '/admin/data/datasetcd' );
} else {
$form -> populate ( $formdata );
}
} else {
$sql = " select * from datasetcd where id=? " ;
$formdata = $this -> db -> fetchRow ( $sql , array ( $edit ));
$form -> populate ( $formdata );
}
$this -> view -> form = $form ;
$this -> _helper -> viewRenderer ( 'datasetcdadd' );
} elseif ( $delete ) {
$sql = " delete from datasetcd where id=? " ;
try {
$this -> db -> query ( $sql , array ( $delete ));
$this -> messenger -> addMessage ( '提示信息:您已经成功删除该特色数据集。' );
} catch ( Exception $e ) {
$this -> messenger -> addMessage ( $e -> getMessage ());
}
$this -> _redirect ( " /admin/data/datasetcd " );
}
$select = $this -> db -> select ();
$select -> from ( 'datasetcd' ) -> order ( 'id desc' );
$paginator = Zend_Paginator :: factory ( $select );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( $this -> view -> config -> page -> max );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination.phtml' );
$this -> view -> paginator = $paginator ;
}
function mdAction ()
{
$delete = ( int ) $this -> _getParam ( 'delete' );
$down = ( int ) $this -> _getParam ( 'down' );
2011-09-20 02:13:59 +00:00
$search = $this -> _getParam ( 'search' );
$keyword = $this -> _getParam ( 'keyword' );
2011-09-29 07:55:05 +00:00
$att = $this -> _getParam ( 'att' );
2011-09-20 02:13:59 +00:00
2011-09-19 09:33:50 +00:00
if ( $delete )
{
$sql = " delete from metadata where id=? " ;
try {
$this -> db -> query ( $sql , array ( $delete ));
$this -> messenger -> addMessage ( '提示信息:您已经成功删除该数据。' );
} catch ( Exception $e ) {
$this -> messenger -> addMessage ( $e -> getMessage ());
}
$this -> _redirect ( " /admin/data/md " );
2011-09-29 07:55:05 +00:00
} //删除
elseif ( $att > 0 ){
$submit = $this -> _request -> getParam ( 'submit' );
$uuid = $this -> _request -> getParam ( 'uuid' );
$atts = $this -> _request -> getParam ( 'ids' );
$addatts = $this -> _request -> getParam ( 'addatts' );
$this -> view -> id = $att ;
$this -> view -> uuid = $uuid ;
if ( ! empty ( $addatts ))
{
if ( empty ( $submit ))
{
$sql = " select title from metadata where uuid=' $uuid ' " ;
$re = $this -> db -> query ( $sql );
$rows = $re -> fetch ();
$this -> view -> id = $att ;
$this -> view -> uuid = $uuid ;
$this -> view -> mdtitle = $rows [ 'title' ];
$this -> view -> thisatt = $rows ;
$this -> _redirect ( " /admin/data/attachments/uuid/ $uuid /mdtitle/ { $rows [ 'title' ] } " );
}
else
{
if ( ! empty ( $uuid ))
{
foreach ( $atts as $v )
{
$sql = " insert into mdattach (uuid,id) values (' $uuid ',' $v ') " ;
try {
$this -> db -> exec ( $sql );
$this -> messenger -> addMessage ( '成功添加附件:' . $v );
} catch ( Exception $e )
{
$this -> messenger -> addMessage ( '添加附件失败:' . $v );
}
}
$this -> _redirect ( " /admin/data/md/att/1/uuid/ $uuid " );
}
}
} //empty($addatts)
else
{
if ( ! empty ( $uuid ))
{
$sql = " select m.*,a.*,d.title from mdattach m
left join attachments a on m . id = a . id
left join metadata d on m . uuid = d . uuid where m . uuid = '$uuid' " ;
$re = $this -> db -> query ( $sql );
$rows = $re -> fetchAll ();
$sql = " select title from metadata where uuid=' $uuid ' " ;
$re = $this -> db -> query ( $sql );
$title = $re -> fetch ();
$this -> view -> atts = $rows ;
$this -> view -> mdtitle = $title [ 'title' ];
$this -> _helper -> viewRenderer ( 'attmanager' );
}
}
} //编辑附件
2012-03-19 08:50:13 +00:00
/*
* 输出打包下载的xml文件
*
* 文件量大时可能出现超时,需要修改超时时间为无限
*/
2011-09-29 07:55:05 +00:00
elseif ( $down ) {
2012-03-19 08:50:13 +00:00
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
//临时zip文件名
$tmpname = " dataxml " ;
//xml文件存放的缓存目录
2011-09-19 09:33:50 +00:00
$dirName = '../data/import/' ;
2012-03-19 08:50:13 +00:00
//查询需要创建的文件
$sql = " SELECT md.title,md.uuid,x.* from xml x
2012-03-20 07:34:34 +00:00
LEFT JOIN normalmetadata md ON md . id = x . id " ;
2012-03-19 08:50:13 +00:00
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ();
$rows = $sth -> fetchAll (); //将结果储存,但不使用
//创建zip文件, 创建成功后再使用查询结果
$zip = new ZipArchive ();
$url = tempnam ( $this -> config -> temp -> path , $tmpname ); //创建临时文件
if ( $zip -> open ( $url , ZIPARCHIVE :: CREATE | ZIPARCHIVE :: OVERWRITE ) !== true )
{
throw new Exception ( " cannot open { $url } for writing. " );
}
foreach ( $rows as $k => $v )
{
$filename = $dirName . $v [ 'uuid' ] . '.xml' ;
//创建xml文件
$handle = fopen ( $filename , " w " );
fwrite ( $handle , $v [ 'data' ]);
fclose ( $handle );
//添加到zip文件
//zip localname 直接使用UUID作为文件名
$zip -> addFile ( $filename , $v [ 'uuid' ] . " .xml " );
}
$zip -> close ();
//zip文件创建完成后删除服务器上的缓存文件, 防止发生冗余
foreach ( $rows as $k => $v )
{
$filename = $dirName . $v [ 'uuid' ] . '.xml' ;
unlink ( $filename );
}
//输出下载
$content = file_get_contents ( $url );
2011-09-19 09:33:50 +00:00
$this -> getResponse () -> setHeader ( 'Content-Type' , 'application/octet-stream' )
2012-03-19 08:50:13 +00:00
-> setHeader ( 'Content-Disposition' , 'attachment; filename="dataxml.zip"' )
-> setHeader ( 'Content-Length' , strlen ( $content ))
-> setHeader ( 'Content-Type' , 'application/force-download' )
-> setHeader ( 'Content-Type' , 'application/download' )
-> setHeader ( 'Content-Type' , 'application/zip' )
-> setHeader ( 'Content-Description' , 'File Transfer' )
-> setHeader ( 'Content-Transfer-Encoding' , 'binary' )
-> setHeader ( 'Expires' , 0 )
-> setHeader ( 'Cache-Control' , 'must-revalidate, post-check=0, pre-check=0' )
-> setHeader ( 'Pragma' , 'public' )
-> setBody ( $content );
2011-09-20 02:13:59 +00:00
} //down
else if ( $search ){
if ( ! empty ( $keyword ))
{
$sql = " select m.*,md.viewed,g.id as gid from metadata m
left join mdstat md on m . uuid = md . uuid
left join geonetworkmetadata g on g . uuid = m . uuid
where m . title like '%$keyword%'
order by m . id desc
" ;
$re = $this -> db -> query ( $sql );
$row = $re -> fetchAll ();
$paginator = Zend_Paginator :: factory ( $row );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( $this -> view -> config -> page -> max );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
$this -> messenger -> addMessage ( $keyword . ' 的搜索结果' );
}
else
{
$this -> messenger -> addMessage ( '请输入搜索关键字' );
$this -> _redirect ( " /admin/data/md " );
}
} //search
else {
2011-09-19 09:33:50 +00:00
$select = $this -> db -> select ();
$select -> from ( 'metadata' )
-> joinLeft ( 'mdstat' , 'metadata.uuid=mdstat.uuid' , 'viewed' )
2011-10-14 09:33:44 +00:00
-> joinLeft ( 'geonetworkmetadata' , 'geonetworkmetadata.uuid=metadata.uuid' , 'id as gid' )
2011-10-14 03:20:45 +00:00
-> joinLeft ( 'mdstatus' , 'metadata.uuid=mdstatus.uuid' , 'status as mdstatus' )
2011-09-19 09:33:50 +00:00
-> order ( 'metadata.id desc' );
$paginator = Zend_Paginator :: factory ( $select );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( $this -> view -> config -> page -> max );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination.phtml' );
2011-09-20 02:13:59 +00:00
$this -> view -> paginator = $paginator ;
}
2011-09-19 09:33:50 +00:00
}
function commentAction ()
{
$delete = ( int ) $this -> _getParam ( 'delete' );
if ( $delete )
{
$sql = " delete from comments where id=? " ;
try {
$this -> db -> query ( $sql , array ( $delete ));
$this -> messenger -> addMessage ( '提示信息:您已经成功删除该评论。' );
} catch ( Exception $e ) {
$this -> messenger -> addMessage ( $e -> getMessage ());
}
$this -> _redirect ( " /admin/data/comment " );
}
$select = $this -> db -> select ();
$select -> from ( 'comments' )
-> joinLeft ( 'metadata' , 'metadata.uuid=comments.uuid' , 'title' )
-> order ( 'comments.ts_created desc' )
-> order ( 'comments.id desc' );
$paginator = Zend_Paginator :: factory ( $select );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( $this -> view -> config -> page -> max );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination.phtml' );
$this -> view -> paginator = $paginator ;
}
function newsletterAction ()
{
$form = new Zend_Form ();
$form -> setName ( 'newsletter' );
$form -> setAttrib ( 'enctype' , 'multipart/form-data' );
$nlf = new Zend_Form_Element_File ( 'nlf' );
$nlf -> setLabel ( '数据通讯' )
-> setRequired ( true )
-> setDestination ( $this -> view -> config -> paths -> newsletter )
-> addValidator ( 'Count' , false , 1 ) // ensure only 1 file
-> addValidator ( 'Size' , false , 2048000 ) // limit to 2M
-> addValidator ( 'Extension' , false , 'pdf' ); // only JPEG, PNG, and GIFs
$submit = new Zend_Form_Element_Submit ( 'submit' );
$form -> addElements ( array ( $nlf , $submit ));
if ( $this -> _request -> isPost ()) {
$formdata = $this -> _request -> getPost ();
if ( $form -> isValid ( $formdata )) {
$uploadedData = $form -> getValues ();
//自动生成JPG文件
$pdf = $form -> nlf -> getFileName ();
$img = new Imagick ( $pdf . '[0]' );
$img -> thumbnailImage ( 200 , 0 );
$img -> writeImage ( $this -> view -> config -> paths -> newsletter . basename ( $pdf , '.pdf' ) . '.jpg' );
$this -> messenger -> addMessage ( '提示信息:您已经成功添加该数据通讯。' );
$this -> _redirect ( '/admin/data/newsletter' );
}
}
$l = new mydir ( $this -> view -> config -> paths -> newsletter , " newsletter_*.pdf " );
$this -> view -> newsletters = $l -> toArray ();
$this -> view -> addHelperPath ( 'helper' , 'Zend_View_Helper_' );
rsort ( $this -> view -> newsletters );
$this -> view -> form = $form ;
}
function featureAction ()
{
$add = ( int ) $this -> _getParam ( 'add' );
$edit = ( int ) $this -> _getParam ( 'edit' );
$delete = ( int ) $this -> _getParam ( 'delete' );
if ( $add ) {
$form = new DatafeatureForm ();
if ( $this -> _request -> isPost ()) {
$formdata = $this -> _request -> getPost ();
if ( $form -> isValid ( $formdata )) {
$uploadedData = $form -> getValues ();
if ( ! $form -> imgurl ) {
$imgurl = '/' . $form -> img -> getFileName ();
} else
$imgurl = $formdata [ 'imgurl' ];
$sql = " insert into datafeature (title,detailurl,imgurl,description) values(?,?,?,?) " ;
$this -> db -> query ( $sql , array ( $formdata [ 'title' ], $formdata [ 'detailurl' ], $imgurl , $formdata [ 'description' ]));
$this -> messenger -> addMessage ( '提示信息:您已经成功添加该特色推荐。' );
$this -> _redirect ( '/admin/data/feature' );
} else {
$form -> populate ( $formdata );
}
}
$this -> view -> form = $form ;
$this -> _helper -> viewRenderer ( 'featureadd' );
} elseif ( $edit ){
$form = new DatafeatureForm ();
if ( $this -> _request -> isPost ()) {
$formdata = $this -> _request -> getPost ();
if ( $form -> isValid ( $formdata )) {
$uploadedData = $form -> getValues ();
if ( ! $form -> imgurl ) {
$imgurl = '/' . $form -> img -> getFileName ();
} else
$imgurl = $form -> imgurl ;
$sql = " update datafeature set title=?,detailurl=?,imgurl=?,description=? where id=? " ;
$param = array ( $formdata [ 'title' ], $formdata [ 'detailurl' ], $formdata [ 'imgurl' ], $formdata [ 'description' ], $edit );
$this -> db -> query ( $sql , $param );
$this -> messenger -> addMessage ( '提示信息:您已经编辑该特色推荐。' );
$this -> _redirect ( '/admin/data/feature' );
} else {
$form -> populate ( $formdata );
}
} else {
$sql = " select * from datafeature where id=? " ;
$formdata = $this -> db -> fetchRow ( $sql , array ( $edit ));
$form -> populate ( $formdata );
}
$this -> view -> form = $form ;
$this -> _helper -> viewRenderer ( 'featureadd' );
} elseif ( $delete ) {
$sql = " delete from datafeature where id=? " ;
try {
$this -> db -> query ( $sql , array ( $delete ));
$this -> messenger -> addMessage ( '提示信息:您已经成功删除该特色推荐。' );
} catch ( Exception $e ) {
$this -> messenger -> addMessage ( $e -> getMessage ());
}
$this -> _redirect ( " /admin/data/feature " );
}
$select = $this -> db -> select ();
$select -> from ( 'datafeature' ) -> order ( 'id desc' );
$paginator = Zend_Paginator :: factory ( $select );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( $this -> view -> config -> page -> max );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination.phtml' );
$this -> view -> paginator = $paginator ;
}
/*
* 数据文献管理
*/
function referenceAction ()
{
$add = ( int ) $this -> _getParam ( 'add' );
$edit = ( int ) $this -> _getParam ( 'edit' );
$delete = ( int ) $this -> _getParam ( 'delete' );
$uuid = $this -> _getParam ( 'uuid' );
$search = $this -> _getParam ( 'search' );
2011-12-09 03:27:37 +00:00
$keyword = $this -> _getParam ( 'keyword' );
2011-11-26 10:51:45 +00:00
$import = ( int ) $this -> _getParam ( 'import' );
2011-12-09 08:01:16 +00:00
$show = $this -> _getParam ( 'show' );
2011-09-19 09:33:50 +00:00
if ( $add ) {
$form = new ReferenceForm ();
if ( $this -> _request -> isPost ()) {
$formdata = $this -> _request -> getPost ();
if ( $form -> isValid ( $formdata )) {
$sql = " select id from reference where reference=? " ;
$row = $this -> db -> fetchRow ( $sql , array ( trim ( $formdata [ 'reference' ])));
if ( ! $row )
{
$sql = " insert into reference (reference,link) values(?,?) " ;
$this -> db -> query ( $sql , array ( trim ( $formdata [ 'reference' ]), trim ( $formdata [ 'link' ])));
$sql = " select id from reference where reference=? " ;
$row = $this -> db -> fetchRow ( $sql , array ( trim ( $formdata [ 'reference' ])));
}
$sql = " insert into mdref (uuid,refid) values(?,?) " ;
$this -> db -> query ( $sql , array ( trim ( $formdata [ 'uuid' ]), $row [ 'id' ]));
$this -> messenger -> addMessage ( '提示信息:您已经成功添加该数据文献。' );
2011-12-09 08:01:16 +00:00
$this -> _redirect ( '/admin/data/reference/show/' . $formdata [ 'uuid' ]);
2011-09-19 09:33:50 +00:00
} else {
$form -> populate ( $formdata );
}
} else {
if ( $uuid )
{
$formdata [ 'uuid' ] = $uuid ;
$form -> populate ( $formdata );
}
}
$this -> view -> form = $form ;
$this -> _helper -> viewRenderer ( 'referenceadd' );
2011-12-09 08:01:16 +00:00
} //添加
else if ( $show ){
$sql = " select mr.id as mdid,mr.refid,r.reference,md.title,md.uuid FROM mdref mr
left join metadata md on md . uuid = mr . uuid
left join reference r on r . id = mr . refid
where mr . uuid = '$show' ;
" ;
$rs = $this -> db -> query ( $sql );
$rows = $rs -> fetchAll ();
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 30 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination.phtml' );
$this -> view -> paginator = $paginator ;
} //按UUID查看
elseif ( $edit ){
2011-09-19 09:33:50 +00:00
$form = new ReferenceForm ();
if ( $this -> _request -> isPost ()) {
$formdata = $this -> _request -> getPost ();
if ( $form -> isValid ( $formdata )) {
2011-12-09 06:35:21 +00:00
$sql = " select id from reference where reference=? order by id desc " ;
2011-12-09 03:27:37 +00:00
$rs = $this -> db -> query ( $sql , array ( $formdata [ 'reference' ]));
$row = $rs -> fetch ();
if ( $row [ 'id' ] != '' )
2011-09-19 09:33:50 +00:00
{
//更新文献信息
$sql = " update mdref set refid=? where uuid=? and refid=? " ;
2011-12-09 03:27:37 +00:00
$td = $this -> db -> query ( $sql , array ( $row [ 'id' ], $formdata [ 'uuid' ], $edit ));
if ( $td )
{
$this -> messenger -> addMessage ( '提示信息:您已经编辑该数据文献。' );
2011-12-09 08:01:16 +00:00
$this -> _redirect ( '/admin/data/reference/show/' . $formdata [ 'uuid' ]);
2011-12-09 03:27:37 +00:00
}
} else
{
$sql = " INSERT INTO reference (reference,link) VALUES (' " . $formdata [ 'reference' ] . " ',' " . $formdata [ 'link' ] . " ') RETURNING id " ;
$sth = $this -> db -> prepare ( $sql );
if ( $sth -> execute ())
{
$temp = $sth -> fetch ( PDO :: FETCH_ASSOC );
$sql = " INSERT INTO mdref (uuid,refid) VALUES (' " . $formdata [ 'uuid' ] . " ',' " . $temp [ 'id' ] . " ') " ;
if ( $this -> db -> exec ( $sql ))
{
2011-12-09 06:35:21 +00:00
$sql = " DELETE FROM mdref where uuid=' " . $formdata [ 'uuid' ] . " ' and refid=' $edit ' " ;
@ $this -> db -> exec ( $sql );
2011-12-09 03:27:37 +00:00
$this -> messenger -> addMessage ( '提示信息:您已经编辑该数据文献。' );
2011-12-09 08:01:16 +00:00
$this -> _redirect ( '/admin/data/reference/show/' . $formdata [ 'uuid' ]);
2011-12-09 03:27:37 +00:00
} else
{
$this -> messenger -> addMessage ( '提示信息:文献关联失败,请重试' );
$this -> _redirect ( '/admin/data/reference/edit/' . $edit );
}
} else
{
$this -> messenger -> addMessage ( '提示信息:文献创建失败,请重试' );
$this -> _redirect ( '/admin/data/reference/edit/' . $edit );
}
2011-09-19 09:33:50 +00:00
}
} else {
$form -> populate ( $formdata );
}
} else {
$sql = " select * from reference r left join mdref m on r.id=m.refid where r.id=? " ;
$formdata = $this -> db -> fetchRow ( $sql , array ( $edit ));
$form -> populate ( $formdata );
}
$this -> view -> form = $form ;
$this -> _helper -> viewRenderer ( 'referenceadd' );
2011-12-09 08:01:16 +00:00
} //编辑相关文献
elseif ( $delete ) {
$sql = " select uuid from mdref where id= $delete " ;
$rs = $this -> db -> query ( $sql );
$row = $rs -> fetch ();
2011-09-19 09:33:50 +00:00
$sql = " delete from mdref where id=? " ;
try {
$this -> db -> query ( $sql , array ( $delete ));
$this -> messenger -> addMessage ( '提示信息:您已经成功删除该数据文献。' );
} catch ( Exception $e ) {
$this -> messenger -> addMessage ( $e -> getMessage ());
}
2011-12-09 08:01:16 +00:00
$this -> _redirect ( '/admin/data/reference/show/' . $row [ 'uuid' ]);
} //删除相关文献
elseif ( $import ) {
2011-12-09 03:27:37 +00:00
if ( $this -> _request -> isPost ()) {
2011-11-26 10:51:45 +00:00
if ( $_FILES [ " ref " ][ " error " ] == UPLOAD_ERR_OK ) {
$tmp_name = $_FILES [ " ref " ][ " tmp_name " ];
$fp = fopen ( $tmp_name , " rb " );
$ref = fread ( $fp , filesize ( $tmp_name ));
2011-12-09 03:27:37 +00:00
fclose ( $fp );
$lines = explode ( " \n " , $ref );
foreach ( $lines as $line )
{
2012-03-19 08:50:13 +00:00
$data = explode ( " ; " , $line );
if ( count ( $data ) == 2 )
$link = '' ;
else
$link = $data [ 2 ];
2011-12-20 09:20:20 +00:00
$link = $this -> db -> quote ( $link );
$sql = " insert into reference (reference,link) values(?, " . $link . " ) " ;
2011-12-09 03:27:37 +00:00
try {
$this -> db -> exec ( $this -> db -> quoteInto ( $sql , $data [ 1 ]));
} catch ( Exception $e ) {}
$sql = " select id from reference where reference=? " ;
$row = $this -> db -> fetchRow ( $this -> db -> quoteInto ( $sql , $data [ 1 ]));
$sql = " insert into mdref (uuid,refid) values(?, " . $row [ 'id' ] . " ) " ;
try {
$this -> db -> exec ( $this -> db -> quoteInto ( $sql , $data [ 0 ]));
} catch ( Exception $e ) {}
2011-11-26 10:51:45 +00:00
}
} //end if
2011-12-09 03:27:37 +00:00
}
$this -> _helper -> viewRenderer ( 'referenceimport' );
2011-12-09 08:01:16 +00:00
} //引用
else if ( $search ){
2011-09-19 09:33:50 +00:00
if ( ! empty ( $keyword ))
{
$sql = " select rf.id as mdid,rf.refid,m.*,r.* from mdref rf
left join metadata m on m . uuid = rf . uuid
left join reference r on r . id = rf . refid
where m . title like '%$keyword%'
order by m . title " ;
$re = $this -> db -> query ( $sql );
$row = $re -> fetchAll ();
$paginator = Zend_Paginator :: factory ( $row );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 30 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
$this -> messenger -> addMessage ( $keyword . ' 的搜索结果' );
}
else
{
$this -> messenger -> addMessage ( '请输入搜索关键字' );
$this -> _redirect ( " /admin/data/reference " );
}
2011-12-09 08:01:16 +00:00
} //搜索
else {
2011-09-19 09:33:50 +00:00
$select = $this -> db -> select ();
$select -> from ( 'mdref' , array ( 'id as mdid' , 'refid' ))
-> join ( 'metadata' , 'metadata.uuid=mdref.uuid' )
-> join ( 'reference' , 'reference.id=mdref.refid' )
-> order ( 'metadata.title' );
$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 ;
2011-12-09 08:01:16 +00:00
} //列表
2011-09-19 09:33:50 +00:00
}
/*
* 删除元数据,删除前有确认
*/
function deleteAction ()
{
if ( $this -> _request -> isPost ()) {
$id = ( int ) $this -> _request -> getPost ( 'id' );
$del = $this -> _request -> getPost ( 'del' );
if ( $del == 'Yes' && $id > 0 ) {
$md = new MetadataTable ();
$where = 'id = ' . $id ;
$md -> delete ( $where );
}
$this -> _redirect ( '/data' );
} else {
$id = ( int ) $this -> _request -> getParam ( 'id' );
if ( $id > 0 ) {
$mdt = new MetadataTable ();
$this -> view -> md = $mdt -> fetchRow ( 'id=' . $id );
}
}
}
/*
* 导入本地元数据
*/
function importAction ()
{
$md = new MetadataTable ();
$thumb = new ThumbnailTable ();
$xmlt = new XmlTable ();
$cgt = new CategoryTable ();
$cgct = new CategoryCodeTable ();
$keyt = new KeywordTable ();
$dst = new DatasetSeriesTable ();
$seriestable = new SeriesTable ();
if ( $this -> _request -> isPost ()) {
foreach ( $_FILES [ " xmlfile " ][ " error " ] as $key => $error ) {
if ( $error == UPLOAD_ERR_OK ) {
$tmp_name = $_FILES [ " xmlfile " ][ " tmp_name " ][ $key ];
$name = $_FILES [ " xmlfile " ][ " name " ][ $key ];
$fp = fopen ( $tmp_name , " rb " );
$xml = fread ( $fp , filesize ( $tmp_name ));
fclose ( $fp );
$this -> import ( $xml );
//采用UUID为文件名?
//move_uploaded_file($tmp_name, "../data/import/$name");
} //end if
} //foreach
2011-11-26 10:51:45 +00:00
$this -> _redirect ( '/data' );
2011-09-19 09:33:50 +00:00
} else {
//do nothing now.
}
}
/*
* 批量处理元数据(元数据保存在服务器的一个目录上)
*/
function batchimportAction ()
{
if ( $this -> _request -> isPost ()) {
$dir = $this -> _request -> getPost ( 'directory' );
$subdir = $this -> _request -> getPost ( 'subdir' );
$l = new mydir ( $dir , " *.xml " );
$xmlfiles = $l -> toArray ();
foreach ( $xmlfiles as $xmlfile )
{
$fp = fopen ( $dir . '/' . $xmlfile , 'rb' );
$xml = fread ( $fp , filesize ( $dir . '/' . $xmlfile ));
fclose ( $fp );
$this -> import ( $xml );
}
$this -> _redirect ( '/data' );
}
}
function datafileimportAction ()
{
if ( $this -> _request -> isPost ()) {
set_time_limit ( 0 );
$dir = $this -> _request -> getPost ( 'directory' );
if ( file_exists ( $dir . '/dataset.txt' ))
{
$fp = fopen ( $dir . '/dataset.txt' , 'rb' );
$ds = fread ( $fp , filesize ( $dir . '/dataset.txt' ));
fclose ( $fp );
$ds1 = explode ( " \n " , $ds );
for ( $i = 0 ; $i < floor ( count ( $ds1 ) / 2 ); $i ++ )
{
$dpath = trim ( $ds1 [ $i * 2 ]);
$duuid = trim ( $ds1 [ $i * 2 + 1 ]);
if ( file_exists ( $dir . '/' . $duuid . '.txt' ))
{
$sql = " delete from dataset where uuid=' " . $duuid . " ' " ;
//datafile table will auto-delete
$this -> db -> query ( $sql );
//$sql="insert into dataset (path,uuid) values('".$dpath."','".$duuid."')";
$sql = " insert into dataset (path,uuid) values(?,?) " ;
$this -> db -> query ( $sql , array ( $dpath , $duuid ));
$sql = " select id from dataset where uuid=' " . $duuid . " ' " ;
$rs = $this -> db -> fetchRow ( $sql );
$dsid = $rs [ " id " ];
$fp = fopen ( $dir . '/' . $duuid . '.txt' , 'rb' );
$filep = fread ( $fp , filesize ( $dir . '/' . $duuid . '.txt' ));
fclose ( $fp );
$filep1 = explode ( " \n " , $filep );
//print $duuid."<br/>";
//print $dpath." ".count($dpatch)."<br/>";
for ( $j = 0 ; $j < floor ( count ( $filep1 ) / 2 ); $j ++ )
{
$fpath1 = explode ( " \t " , $filep1 [ $j * 2 ]);
$fsize = $fpath1 [ 0 ];
$fpath = mb_substr ( $fpath1 [ 1 ], mb_strlen ( $dpath ));
$fdir = ( $filep1 [ $j * 2 + 1 ] == " directory " ) ? 1 : 0 ;
if ( $fdir == 1 ) $fsize = 0 ;
if ( $fpath != " " )
{
$fdepth = substr_count ( $fpath , " / " ) + 1 ;
if ( $fdir == 1 ) $fpath .= " / " ;
//print $fsize." ".$fpath." ".$fdir."<br/>";
//$sql="insert into datafile (dsid,filename,filesize,isdir,depth) values(".$dsid.",'".$this->db->escape($fpath)."',".$fsize.",".$fdir.",".$fdepth.")";
$sql = " insert into datafile (dsid,filename,filesize,isdir,depth) values(?,?,?,?,?) " ;
$this -> db -> query ( $sql , array ( $dsid , $fpath , $fsize , $fdir , $fdepth ));
}
}
}
}
}
$this -> view -> msg = '已成功处理数据目录信息!' ;
}
2011-09-28 01:29:21 +00:00
} //datafileimportAction
function sourceAction ()
{
2011-10-26 08:50:00 +00:00
$do = $this -> _request -> getParam ( 'do' );
$uuid = $this -> _request -> getParam ( 'uuid' );
$id = $this -> _request -> getParam ( 'id' );
$q = $this -> _request -> getParam ( 'q' );
$search = $this -> _request -> getParam ( 'search' );
2011-09-28 01:29:21 +00:00
2011-10-26 08:50:00 +00:00
if ( $do == 'add' ) {
$redirect = " /admin/data/source/ " ;
2011-09-28 01:29:21 +00:00
if ( ! empty ( $_POST [ 'submit' ]))
{
2011-10-26 08:50:00 +00:00
try {
$title = $this -> _request -> getParam ( 'title' );
$uuid = $this -> _request -> getParam ( 'uuid' );
$code = $this -> _request -> getParam ( 'code' );
$description = $this -> _request -> getParam ( 'description' );
$has_pages = $this -> _request -> getParam ( 'has_pages' );
$has_agreement = $this -> _request -> getParam ( 'has_agreement' );
2011-09-28 01:29:21 +00:00
2011-10-26 08:50:00 +00:00
$data = array (
'title' => $title ,
'uuid' => $uuid ,
'code' => $code ,
'description' => $description ,
'has_pages' => $has_pages ,
'has_agreement' => $has_agreement
);
if ( $this -> db -> insert ( 'source' , $data ))
{
$this -> messenger -> addMessage ( '添加来源信息成功' );
$this -> _redirect ( $redirect );
}
} catch ( Exception $e ){
$this -> messenger -> addMessage ( '添加来源信息失败:' . $e -> getMessage ());
$this -> _redirect ( '/admin/data/source/do/add' );
}
2011-09-28 01:29:21 +00:00
}
$this -> _helper -> viewRenderer ( 'sourceadd' );
} // 添加项目来源
2011-10-26 08:50:00 +00:00
else if ( $do == 'edit' && ! empty ( $id ))
{
if ( ! empty ( $_POST [ 'submit' ]))
{
try {
$title = $this -> _request -> getParam ( 'title' );
$uuid = $this -> _request -> getParam ( 'uuid' );
$code = $this -> _request -> getParam ( 'code' );
$description = $this -> _request -> getParam ( 'description' );
$has_pages = $this -> _request -> getParam ( 'has_pages' );
$has_agreement = $this -> _request -> getParam ( 'has_agreement' );
$sql = " update source set title=' $title ',uuid=' $uuid ',code=' $code ',description=' $description ',has_pages=' $has_pages ',has_agreement=' $has_agreement ' where id=' $id ' " ;
2011-10-27 03:03:11 +00:00
if ( $this -> db -> exec ( $sql ))
2011-10-26 08:50:00 +00:00
{
$this -> messenger -> addMessage ( '修改来源信息成功' );
$this -> _redirect ( " /admin/data/source/do/edit/id/ $id " );
}
} catch ( Exception $e ){
$this -> messenger -> addMessage ( '修改来源信息失败:' . $e -> getMessage ());
$this -> _redirect ( " /admin/data/source/do/edit/id/ $id " );
}
}
$sql = " select * from source where id=' $id ' " ;
$rs = $this -> db -> query ( $sql );
$row = $rs -> fetch ();
$this -> view -> info = $row ;
$this -> _helper -> viewRenderer ( 'sourceadd' );
} // 编辑单条信息
2011-10-27 03:03:11 +00:00
else if ( $do == 'datasource' && ! empty ( $uuid ))
{
$redirect = " /admin/data/source/do/datasource/uuid/ $uuid " ;
$this -> view -> uuid = $uuid ;
$sql = " select md.title,ds.id,ds.sourceid,s.title as stitle,s.code from metadata md
left join datasource ds on ds . uuid = md . uuid
left join source s on s . id = ds . sourceid
where md . uuid = '$uuid' " ;
$rs = $this -> db -> query ( $sql );
$row = $rs -> fetch ();
$this -> view -> info = $row ;
if ( ! empty ( $_POST [ 'submit' ]))
{
$sourceid = $this -> _request -> getParam ( 'sourceid' );
if ( empty ( $sourceid ))
{
$this -> messenger -> addMessage ( '请选择项目来源' );
$this -> _redirect ( $redirect );
}
$sql = " " ;
if ( empty ( $row [ 'id' ]))
{
$sql = " insert into datasource (uuid,sourceid) values (' $uuid ',' $sourceid ') " ;
} else
{
$sql = " update datasource set uuid=' $uuid ',sourceid=' $sourceid ' where id=' { $row [ 'id' ] } ' " ;
}
try {
if ( $this -> db -> exec ( $sql ))
{
$this -> messenger -> addMessage ( '修改项目来源成功' );
$this -> _redirect ( $redirect );
}
else
{
$this -> messenger -> addMessage ( '修改项目来源失败' );
$this -> _redirect ( $redirect );
}
} catch ( Exception $e ){
$this -> messenger -> addMessage ( '修改项目来源失败:' . $e -> getMessage ());
$this -> _redirect ( $redirect );
}
}
$wheresql = array ();
if ( ! empty ( $q ) && ! empty ( $search ))
{
$this -> view -> q = $q ;
$wheresql [] = " title like '% $q %' " ;
}
if ( count ( $wheresql > 0 )) $wheresql = join ( ' and ' , $wheresql );
else $wheresql = '' ;
if ( $wheresql != '' )
{
$wheresql = 'where ' . $wheresql ;
}
$sql = " select * from source $wheresql order by id desc " ;
$rs = $this -> db -> query ( $sql );
$rows = $rs -> fetchAll ();
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 30 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
$this -> _helper -> viewRenderer ( 'sourceselect' );
2011-10-27 03:26:02 +00:00
} // 为元数据选择项目来源
else if ( $do == 'del' && ! empty ( $id ))
{
$redirect = " /admin/data/source/ " ;
$sql = " delete from source where id=' $id ' " ;
try {
if ( $this -> db -> exec ( $sql ))
{
$this -> messenger -> addMessage ( '删除成功' );
$this -> _redirect ( $redirect );
} else {
$this -> messenger -> addMessage ( '删除失败,可能该数据已不存在' );
$this -> _redirect ( $redirect );
}
} catch ( Exception $e ){
$this -> messenger -> addMessage ( '删除失败:' . $e -> getMessage ());
$this -> _redirect ( $redirect );
}
} // 删除项目来源
2011-10-27 03:03:11 +00:00
2011-10-27 08:42:31 +00:00
else if ( $do == 'fetch' && ! empty ( $id ))
{
$wheresql = array ();
$wheresql [] = " ds.sourceid=' $id ' " ;
if ( ! empty ( $q ) && ! empty ( $search ))
{
$this -> view -> q = $q ;
$wheresql [] = " title like '% $q %' " ;
}
if ( count ( $wheresql > 0 )) $wheresql = join ( ' and ' , $wheresql );
else $wheresql = '' ;
if ( $wheresql != '' )
{
$wheresql = 'where ' . $wheresql ;
}
$sql = " select md.title,md.uuid,ds.id,ds.sourceid,s.title as stitle,s.code from metadata md
left join datasource ds on ds . uuid = md . uuid
left join source s on s . id = ds . sourceid
$wheresql
order by id desc " ;
$rs = $this -> db -> query ( $sql );
$rows = $rs -> fetchAll ();
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 30 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
$this -> _helper -> viewRenderer ( 'sourcefetchone' );
} //查看某项目来源中的所有元数据
else if ( $do == 'delsource' && ! empty ( $id ))
{
$redirect = " /admin/data/source/do/datasource/uuid/ $uuid " ;
$sql = " delete from datasource where id=' $id ' " ;
try {
if ( $this -> db -> exec ( $sql ))
{
$this -> messenger -> addMessage ( '删除成功' );
$this -> _redirect ( $redirect );
} else {
$this -> messenger -> addMessage ( '删除失败,可能该数据已不存在' );
$this -> _redirect ( $redirect );
}
} catch ( Exception $e ){
$this -> messenger -> addMessage ( '删除失败:' . $e -> getMessage ());
$this -> _redirect ( $redirect );
}
} // 清除元数据来源记录
2012-03-19 08:50:13 +00:00
elseif ( $do == 'sync' ) { //同步数据来源到metadata表
2011-12-11 07:57:59 +00:00
$redirect = " /admin/data/source/ " ;
$sql = " update metadata m set source=s.uuid from source s right join datasource d on s.id=d.sourceid where m.uuid=d.uuid " ;
if ( $this -> db -> exec ( $sql ))
{
$this -> messenger -> addMessage ( '成功同步数据来源' );
$this -> _redirect ( $redirect );
} else {
$this -> messenger -> addMessage ( '同步数据来源失败' );
$this -> _redirect ( $redirect );
}
}
2011-10-27 08:42:31 +00:00
2011-10-26 08:50:00 +00:00
else
{
$wheresql = array ();
if ( ! empty ( $q ) && ! empty ( $search ))
{
$this -> view -> q = $q ;
$wheresql [] = " title like '% $q %' " ;
}
if ( count ( $wheresql > 0 )) $wheresql = join ( ' and ' , $wheresql );
else $wheresql = '' ;
if ( $wheresql != '' )
{
$wheresql = 'where ' . $wheresql ;
}
$sql = " select * from source $wheresql order by id desc " ;
$rs = $this -> db -> query ( $sql );
$rows = $rs -> fetchAll ();
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 30 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
} // 项目来源管理
2011-09-28 01:29:21 +00:00
} //function sourceAction
function attachmentsAction ()
{
$submit = $this -> _request -> getParam ( 'submit' );
$add = $this -> _request -> getParam ( 'add' );
$search = $this -> _request -> getParam ( 'search' );
$delete = $this -> _request -> getParam ( 'delete' );
$edit = $this -> _request -> getParam ( 'edit' );
$down = $this -> _request -> getParam ( 'down' );
2011-09-29 07:55:05 +00:00
$uuid = $this -> _request -> getParam ( 'uuid' );
$mdtitle = $this -> _request -> getParam ( 'mdtitle' );
if ( ! empty ( $uuid ) &&! empty ( $mdtitle ))
{
$this -> view -> uuid = $uuid ;
$this -> view -> mdtitle = $mdtitle ;
}
2011-09-28 01:29:21 +00:00
2011-11-07 08:34:13 +00:00
if ( $add )
2011-09-28 01:29:21 +00:00
{
$this -> _helper -> viewRenderer ( 'attachmentsadd' );
2011-11-07 08:34:13 +00:00
if ( ! empty ( $uuid ))
2011-09-28 01:29:21 +00:00
{
2011-11-07 08:34:13 +00:00
$this -> view -> uuid = $uuid ;
2011-09-28 01:29:21 +00:00
}
} //附件添加
else if ( $delete )
{
//需要删除文件, 通过Zend_Registry::get('upload')获得上传文件的根目录
2011-11-04 01:48:16 +00:00
$basepath = $this -> view -> config -> upload ;
2011-09-28 01:29:21 +00:00
//从数据库获取文件路径
$info = $this -> getFileinfo ( $delete );
$filepath = $basepath . $info [ 'filename' ];
if ( unlink ( $filepath ))
{
$sql = " delete from attachments where id=' $delete ' " ;
if ( $this -> db -> exec ( $sql ) > 0 )
{
$this -> messenger -> addMessage ( '删除文件成功' );
$this -> _redirect ( " /admin/data/attachments/ " );
}
}
else
{
$sql = " delete from attachments where id=' $delete ' " ;
if ( $this -> db -> exec ( $sql ) > 0 )
{
$this -> messenger -> addMessage ( '文件删除失败,仅删除数据库记录,请手动删除文件:' . $info [ 'filename' ]);
$this -> _redirect ( " /admin/data/attachments/ " );
}
}
} //删除
else if ( $edit > 0 )
{
if ( empty ( $submit ))
{
$this -> view -> info = $this -> getFileinfo ( $edit );
$this -> _helper -> viewRenderer ( 'attachmentsadd' );
}
else
{
$filedesc = $this -> _request -> getParam ( 'filedesc' );
$sql = " update attachments set filedesc=' $filedesc ' where id=' $edit ' " ;
if ( $this -> db -> exec ( $sql ) > 0 )
{
$this -> messenger -> addMessage ( '编辑成功' );
$this -> _redirect ( " /admin/data/attachments/edit/ $edit " );
}
}
} //编辑
else if ( $search && $search != 'my' )
{
$keyword = $this -> _request -> getParam ( 'keyword' );
if ( empty ( $keyword ))
{
$this -> messenger -> addMessage ( '请输入关键词' );
$this -> _redirect ( " /admin/data/attachments/search/1 " );
}
else
{
$sql = " select * from attachments where filedesc like '% $keyword %' " ;
$re = $this -> db -> query ( $sql );
$rows = $re -> fetchAll ();
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 30 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination_param.phtml' );
$this -> view -> paginator = $paginator ;
}
} //搜索
else if ( $search && $search == 'my' )
{
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$userid = $user -> id ;
$sql = " select * from attachments where userid=' $userid ' " ;
$re = $this -> db -> query ( $sql );
$rows = $re -> fetchAll ();
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 30 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination.phtml' );
$this -> view -> paginator = $paginator ;
}
} //我的附件列表
2011-09-28 04:04:25 +00:00
else if ( $down > 0 )
{
$sql = " select * from attachments where id=' $down ' " ;
$re = $this -> db -> query ( $sql );
$row = $re -> fetch ();
$file = new files ();
2011-11-04 08:54:32 +00:00
$fullPath = $this -> view -> config -> upload . $row [ 'filename' ];
2011-09-28 04:04:25 +00:00
// Parse Info / Get Extension
$fsize = filesize ( $fullPath );
$path_parts = pathinfo ( $fullPath );
$ext = strtolower ( $path_parts [ " extension " ]);
// Determine Content Type
switch ( $ext ) {
case " pdf " : $ctype = " application/pdf " ; break ;
case " exe " : $ctype = " application/octet-stream " ; break ;
case " zip " : $ctype = " application/zip " ; break ;
case " doc " : $ctype = " application/msword " ; break ;
case " xls " : $ctype = " application/vnd.ms-excel " ; break ;
case " ppt " : $ctype = " application/vnd.ms-powerpoint " ; break ;
case " gif " : $ctype = " image/gif " ; break ;
case " png " : $ctype = " image/png " ; break ;
case " jpeg " :
case " jpg " : $ctype = " image/jpg " ; break ;
default : $ctype = " application/force-download " ;
}
$content = file_get_contents ( $fullPath );
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$this -> getResponse () -> setHeader ( 'Content-Type' , 'application/octet-stream' )
-> setHeader ( 'Content-Disposition' , 'attachment; filename="' . basename ( $fullPath ) . '"' )
-> setHeader ( 'Content-Length' , $fsize )
-> setHeader ( 'Content-Type' , 'application/force-download' )
-> setHeader ( 'Content-Type' , 'application/download' )
-> setHeader ( 'Content-Type' , $ctype )
-> setHeader ( 'Content-Description' , 'File Transfer' )
-> setHeader ( 'Content-Transfer-Encoding' , 'binary' )
-> setHeader ( 'Expires' , 0 )
-> setHeader ( 'Cache-Control' , 'must-revalidate, post-check=0, pre-check=0' )
-> setHeader ( 'Pragma' , 'public' )
-> setBody ( $content );
2011-09-28 06:56:03 +00:00
//$sql = "update attachments set downtimes=downtimes+1 where id='$down'";
//$this->db->exec($sql);
2011-09-28 04:04:25 +00:00
} //附件下载
2011-09-28 01:29:21 +00:00
else
{
2011-09-29 07:55:05 +00:00
2011-09-28 04:04:25 +00:00
$sql = " select * from attachments order by id desc " ;
2011-09-28 01:29:21 +00:00
$re = $this -> db -> query ( $sql );
$rows = $re -> fetchAll ();
$paginator = Zend_Paginator :: factory ( $rows );
$paginator -> setCurrentPageNumber ( $this -> _getParam ( 'page' ));
$paginator -> setItemCountPerPage ( 30 );
$paginator -> setView ( $this -> view );
Zend_View_Helper_PaginationControl :: setDefaultViewPartial ( 'pagination.phtml' );
$this -> view -> paginator = $paginator ;
} //所有附件
} //attachments 附件
2011-11-07 08:34:13 +00:00
function uploadAction (){
$this -> _helper -> layout () -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$uuid = $this -> _getParam ( 'uuid' );
try {
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$userid = $user -> id ;
}
if ( empty ( $userid ) ||! is_numeric ( $userid )){
$msg [ 'error' ] = " 请先登录 " ;
echo Zend_Json :: encode ( $msg );
exit ();
}
2011-11-09 09:54:08 +00:00
if ( $user -> usertype != 'administrator' )
{
$msg [ 'error' ] = " 您无权使用此功能 " ;
echo Zend_Json :: encode ( $msg );
exit ();
}
2011-11-07 08:34:13 +00:00
$files = new files ();
$msg = $files -> upload ( $this -> view -> config -> upload , $_FILES [ 'Filedata' ], 'md' );
if ( empty ( $msg [ 'error' ]))
{
$msg [ 'error' ] = " " ;
$filename = $msg [ 'db_path' ];
$filesize = $msg [ 'file_size' ];
$filedesc = $this -> _request -> getParam ( 'filedesc' );
2011-11-09 09:08:06 +00:00
$filetype = $msg [ 'file_type' ];
2011-11-07 08:34:13 +00:00
$realname = $msg [ 'realname' ];
2011-11-09 09:08:06 +00:00
$sql = " insert into attachments (filename,filetype,filedesc,userid,filesize,realname) values (' $filename ',' $filetype ',' $filedesc ',' $userid ',' $filesize ',' $realname ') RETURNING id " ;
2011-11-07 08:34:13 +00:00
$sth = $this -> db -> prepare ( $sql );
$sth -> execute ();
$att = $sth -> fetch ( PDO :: FETCH_ASSOC );
$msg [ 'attid' ] = $attid = $att [ 'id' ];
$sql = " insert into mdattach (uuid,id) values (' $uuid ',' $attid ') " ;
if ( $this -> db -> exec ( $sql ))
{
2011-11-09 09:54:08 +00:00
$msg [ 'html' ] = $realname . '[' . round ( $filesize / 1024 , 2 ) . ' kb]<input type="hidden" name="atts[]" value="' . $attid . '" /><div class="cancel"><a href="javascript:;" id="deletebtn_' . $attid . '"><img border="0" src="/static/js/uploadify/cancel.png" /></a></div>' ;
2011-11-07 08:34:13 +00:00
echo Zend_Json :: encode ( $msg );
exit ();
} else {
$msg [ 'error' ] = '附件上传失败:写入附件表出错' ;
@ unlink ( $filename );
echo Zend_Json :: encode ( $msg );
exit ();
}
} else {
$msg [ 'error' ] = '附件上传失败:' . $msg [ 'error' ];
@ unlink ( $filename );
echo Zend_Json :: encode ( $msg );
exit ();
}
} catch ( Exception $e ){
$msg [ 'error' ] = " 错误: " . $e -> getMessage ();
echo Zend_Json :: encode ( $msg );
exit ();
}
} // uploadAction ajax上传附件
2011-11-09 09:54:08 +00:00
function getattsAction (){
$this -> _helper -> layout () -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
$uuid = $this -> _request -> getParam ( 'uuid' );
if ( $uuid != '' )
{
$auth = Zend_Auth :: getInstance ();
if ( $auth -> hasIdentity ())
{
$user = $auth -> getIdentity ();
$userid = $user -> id ;
$sql = " select m.*,a.*,d.title from mdattach m
left join attachments a on m . id = a . id
left join metadata d on m . uuid = d . uuid where m . uuid = '$uuid' " ;
$rs = $this -> db -> query ( $sql );
$atts = $rs -> fetchAll ();
2011-12-09 03:27:37 +00:00
2011-11-09 09:54:08 +00:00
foreach ( $atts as $k => $v )
2011-12-09 03:27:37 +00:00
{
$atts [ $k ][ 'html' ] = $v [ 'realname' ] . '[' . round ( $v [ 'filesize' ] / 1024 , 2 ) . ' kb]<input type="hidden" name="atts[]" value="' . $v [ 'id' ] . '" /><div class="cancel"><a href="javascript:;" id="deletebtn_' . $v [ 'id' ] . '"><img border="0" src="/static/js/uploadify/cancel.png" /></a></div>' ;
2011-11-09 09:54:08 +00:00
}
echo Zend_Json :: encode ( $atts );
exit ();
} else
{
exit ();
}
} else {
exit ();
}
//不输出错误
} //获取附件
2011-11-07 08:34:13 +00:00
2011-09-28 01:29:21 +00:00
/*
获得单个文件的信息
return array row
*/
public function getFileinfo ( $id ){
$sql = " select * from attachments where id=' $id ' " ;
$re = $this -> db -> query ( $sql );
$row = $re -> fetch ();
return $row ;
}
2011-09-19 09:33:50 +00:00
/*
* 保存XML数据到数据库
*/
private function import ( $xml )
{
$iso = new ISO19115 ();
$iso -> loadXML ( $xml );
$md = new MetadataTable ();
$thumb = new ThumbnailTable ();
$xmlt = new XmlTable ();
$cgt = new CategoryTable ();
$cgct = new CategoryCodeTable ();
$keyt = new KeywordTable ();
$dst = new DatasetSeriesTable ();
$seriestable = new SeriesTable ();
$db = $seriestable -> getAdapter ();
//save metadata
//先删除已有元数据,然后再插入新数据
$sql = " delete from metadata where uuid=? " ;
$this -> db -> query ( $sql , array ( $iso -> uuid ));
//删除所有未用到的responsible数据
$sql = " delete from responsible where id not in (select distinct(resid) from role) " ;
$this -> db -> query ( $sql );
$row = $md -> createRow ();
$trow = $thumb -> createRow ();
$row -> uuid = $iso -> uuid ;
$row -> title = $iso -> resTitle ;
$row -> title_en = $iso -> resAltTitle ;
$row -> description = $iso -> idAbs ;
$row -> citation = $iso -> citation ;
$row -> suppinfo = $iso -> suppinfo ;
$row -> fileformat = $iso -> fileformat ;
$row -> projection = $iso -> projection ;
//$row->author=$iso->author;
$row -> datatype = $iso -> datatype ;
$row -> filesize = $iso -> filesize ;
$row -> ts_created = $iso -> mdDateSt ;
$row -> timebegin = $iso -> timebegin ;
$row -> timeend = $iso -> timeend ;
$row -> west = $iso -> geoBox [ 'w' ];
$row -> south = $iso -> geoBox [ 's' ];
$row -> north = $iso -> geoBox [ 'n' ];
$row -> east = $iso -> geoBox [ 'e' ];
if ( ! empty ( $iso -> doi )) $row -> doi = $iso -> doi ;
//生成空白统计数据
$sql = $db -> quoteInto ( " select * from mdstat where uuid=? " , $iso -> uuid );
if ( ! $db -> fetchRow ( $sql ))
{
$sql = " insert into mdstat (uuid) values(?) " ;
$db -> query ( $sql , array ( $iso -> uuid ));
}
try {
$id = $row -> save ();
//处理在线资源
if ( $iso -> onlineresource ) foreach ( $iso -> onlineresource as $resource )
{
$sql = " insert into onlineresource (uuid,linkage,protocol,name,description) values(?,?,?,?,?) " ;
$db -> query ( $sql , array ( $iso -> uuid , $resource [ 'linkage' ], $resource [ 'protocol' ], $resource [ 'name' ], $resource [ 'description' ]));
}
//处理缩略图
if ( ! empty ( $iso -> thumbnail )) {
$trow -> id = $id ;
$trow -> data = $iso -> thumbnail ;
$trow -> filetype = 'jpg' ;
$trow -> save ();
} elseif ( $iso -> graph ) {
$trow -> id = $id ;
//$trow->data=$iso->graph['data'];
$sql = " select id as gid from geonetworkmetadata where uuid=? " ;
$r = $this -> db -> fetchRow ( $sql , array ( $iso -> uuid ));
if ( $r )
{
$trow -> data = base64_encode ( file_get_contents ( $this -> view -> config -> geonetwork -> url . 'srv/cn/resources.get?access=public&id=' . $r -> gid . '&fname=' . urlencode ( $iso -> graph [ 'filename' ])));
}
$trow -> filetype = $iso -> graph [ 'filetype' ];
$trow -> filedesc = $iso -> graph [ 'filedesc' ];
$trow -> filename = $iso -> graph [ 'filename' ];
$trow -> save ();
}
//todo:处理关键词
//1:N relation
foreach ( $iso -> keyword as $keytype => $keys )
{
foreach ( $keys as $key )
{
$row = $keyt -> createRow ();
$row -> id = $id ;
//统一转换为大写
//不再统一转换
$row -> keyword = $key ;
$row -> keytype = $keytype ;
$row -> save ();
}
}
//todo:处理数据集序列
//M:N relation
if ( $iso -> datasetSeries ) foreach ( $iso -> datasetSeries as $ds )
{
$where = $db -> quoteInto ( 'name = ?' , $ds [ 'seriesName' ]);
$trow = $seriestable -> fetchRow ( $where );
if ( $trow )
$sid = $trow -> id ;
else {
$trow = $seriestable -> createRow ();
$trow -> name = $ds [ 'seriesName' ];
$sid = $trow -> save ();
}
$row = $dst -> createRow ();
$row -> id = $id ;
$row -> sid = $sid ;
$row -> save ();
}
//处理XML入库
$row = $xmlt -> createRow ();
$row -> id = $id ;
$row -> data = $xml ;
$row -> save ();
//处理数据分类
foreach ( $iso -> tpCat as $cat ){
if ( is_numeric ( $cat )) {
$row = $cgt -> createRow ();
$row -> id = $id ;
$row -> code = ( int ) $cat ;
$row -> save ();
} else {
//是字符串, geonetwork会采用这种模式
//从categorycode表中查找其对应的code
$where = $db -> quoteInto ( 'name= ?' , trim ( $cat ));
$trow = $cgct -> fetchRow ( $where );
if ( $trow ) {
$row = $cgt -> createRow ();
$row -> id = $id ;
$row -> code = $trow -> code ;
$row -> save ();
}
//$db=$cgt->getAdapter();
//$sql="insert into category (id,code) values($id,(select code from categorycode where name='$cat'))";
//$db->query($sql);
}
}
//处理联系人信息
//先查询再进行处理
//若用户信息发生变化,则存在问题
//无法保证数据的更新状态
foreach ( $iso -> author as $au )
{
2012-03-26 09:46:59 +00:00
$inds = explode ( " ; " , $au [ 'individual' ]);
2011-09-19 09:33:50 +00:00
foreach ( $inds as $ind )
{
$sql = " select id from responsible where individual=? and organisation=? " ;
$row = $this -> db -> fetchRow ( $sql , array ( trim ( $ind ), trim ( $au [ 'organisation' ])));
if ( ! $row )
{
$sql = " insert into responsible (individual,organisation,position,delivery,phone,email,city,country,administrative,postal) values(?,?,?,?,?,?,?,?,?,?) " ;
$this -> db -> query ( $sql , array ( trim ( $ind ), trim ( $au [ 'organisation' ]), trim ( $au [ 'position' ]), trim ( $au [ 'delivery' ]), trim ( $au [ 'phone' ]), trim ( $au [ 'email' ]), trim ( $au [ 'city' ]), trim ( $au [ 'country' ]), trim ( $au [ 'administrative' ]), trim ( $au [ 'postal' ])));
} elseif ( count ( $inds ) == 1 ) {
//deal email address
if (( $au [ 'email' ]) && empty ( $row -> email ))
{
$sql = " update responsible set email=? where id=? " ;
$this -> db -> query ( $sql , array ( trim ( $au [ 'email' ]), $row -> id ));
}
}
$sql = " select id from responsible where individual=? and organisation=? " ;
$row = $this -> db -> fetchRow ( $sql , array ( trim ( $ind ), trim ( $au [ 'organisation' ])));
if ( $row -> id > 0 )
{
$sql = " insert into role (resid,uuid,role) values(?,?,?) " ;
$this -> db -> query ( $sql , array ( $row -> id , $iso -> uuid , trim ( $au [ 'role' ])));
}
}
}
//处理数据限制信息
foreach ( $iso -> limits as $uselimit )
{
$sql = " select id from uselimit where uselimit=? " ;
$row = $this -> db -> fetchRow ( $sql , array ( $uselimit ));
if ( ! $row )
{
$sql = " insert into uselimit (uselimit) values (?) " ;
$this -> db -> query ( $sql , array ( $uselimit ));
}
$sql = " select id from uselimit where uselimit=? " ;
$row = $this -> db -> fetchRow ( $sql , array ( $uselimit ));
if ( $row )
{
$sql = " insert into mdlimit (uuid,lid) values(?,?) " ;
$this -> db -> query ( $sql , array ( $iso -> uuid , $row -> id ));
}
}
$iso -> save ( " ../data/import/ $iso->uuid .xml " );
} catch ( Exception $e ) {
//数据重复插入,此处忽略所有错误
print $iso -> uuid . ' has error: ' . $e -> getMessage () . '<br />' ;
}
}
}