';
$content.=''.$row['title'].'';
$content.='
';
$content.=$xslt->transformToXML($dom);
if ($review==1) $content.=file_get_contents('../data/review-table.htm',true);
$content.="";
$this->getResponse()->setHeader('Content-Type', 'application/vnd.ms-doc')
->setHeader('Content-Disposition','attachment; filename="'.$row['title'].'.doc"')
->setHeader('Content-Length', strlen($content))
->setHeader('Content-Type','application/force-download')
->setHeader('Content-Type','application/download')
->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);
}
/*
* 转换元数据为PDF格式
*/
public function pdfAction()
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$uuid=$this->_request->getParam('uuid');
$review=$this->_request->getParam('review');
error_reporting(1);
if (!empty($uuid))
{
$sql="select x.data,m.title,m.citation,m.suppinfo,m.doi,m.filesize,m.fileformat,m.south,m.east,m.west,m.north,m.timebegin,m.timeend,m.title_en,m.uuid,m.description,g.id,m.projection,t.filetype,
cc.name as category, cc.name_zh as category_zh
from xml x left join metadata m on m.id=x.id left join thumbnail t on x.id=t.id
left join category c on c.id=m.id left join categorycode cc on c.code=cc.code
left join geonetworkmetadata g on g.uuid=m.uuid where m.uuid=".$this->db->quote($uuid);
$row=$this->db->fetchRow($sql);
$sql="select r.* from reference r left join mdref m on m.refid=r.id where m.uuid=?";
$sql=$this->db->quoteInto($sql,$uuid);
$ref=$this->db->fetchAll($sql);
$reference="";
foreach($ref as $k=>$refer)
{
$reference.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$refer['reference'])."\r\n";
}
$row['reference']=$reference;
$sql="select u.uselimit from mdlimit ml left join metadata m on ml.uuid=m.uuid left join uselimit u on ml.lid=u.id where m.uuid=?";
$sql=$this->db->quoteInto($sql,$uuid);
$limits=$this->db->fetchAll($sql);
$uselimits="";
foreach($limits as $k=>$limit)
{
//$uselimits.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$limit['uselimit'])."\r\n";
$uselimits.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$limit['uselimit'])."\r\n";
}
$row['uselimits']=$uselimits;
$sql="select ol.* from onlineresource ol left join metadata m on ol.uuid=m.uuid where m.uuid=?";
$sql=$this->db->quoteInto($sql,$uuid);
$row['resources']=$this->db->fetchAll($sql);
$sql="select r.role,s.* from role r left join responsible s on r.resid=s.id left join metadata m on m.uuid=r.uuid where m.uuid=? order by r.role,r.id";
$sql=$this->db->quoteInto($sql,$uuid);
$row['contacts']=$this->db->fetchAll($sql);
$sql="select k.keyword, k.keytype from keyword k left join metadata m on k.id=m.id where m.uuid=? order by k.keytype";
$sql=$this->db->quoteInto($sql,$uuid);
$keys=$this->db->fetchAll($sql);
$keyword=array();
foreach($keys as $key)
{
@$keyword[$key['keytype']].=$key['keyword'].',';
}
$row['keyword']=$keyword;
if (is_numeric($row['projection']))
{
$sql="select proj4text from spatial_ref_sys where auth_srid=?";
$rs=$this->db->fetchRow($sql,array($row['projection']));
if ($rs) $projection=$rs['proj4text'];
}
if (!empty($projection)) $row['projection']=$projection;
} else
$projection='';
$dom = new DOMDocument();
$dom->loadXML($row['data']);
$xpath = new DOMXpath($dom);
$row['rfdenom']=@$dom->getElementsByTagName('rfDenom')->item(0)->nodeValue;
$row['resolution']=@$xpath->query('//scaleDist/value/Real')->item(0)->nodeValue;
$row['resolution'].=@$dom->getElementsByTagName('uomName')->item(0)->nodeValue;
//提前对表格进行预处理
/*$wiki=new WikiFormat();
$row['description']=$wiki->parseTable($row["description"]);
preg_match_all('/
[\s\S]*?<\/table>/im', $row['description'],$tables);
foreach($tables as $k=>$table)
{
$row['description']=@str_replace($tables[$k],"\n 【表格内容暂不支持,请访问网站查看,此处请忽略】\n",$row['description']);
}*/
$pdf=new MetadataPDF();
$pdf->metadata=$row;
$pdf->Draw();
$pdf->setTitle($row['title'],true);
$pdf->setAuthor('中国西部环境与生态科学数据中心',true);
$this->getResponse()->setHeader('Content-Type', 'application/pdf');
//->setHeader('Content-Disposition','inline; filename="'.$row['title'].'.pdf"');
$pdf->Output($row['title'].'.pdf','I');
//die();
}
public function odtAction()
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$uuid=$this->_request->getParam('uuid');
$review=$this->_request->getParam('review');
//error_reporting(1);
if (!empty($uuid))
{
$sql="select x.data,m.title,m.citation,m.suppinfo,m.doi,m.filesize,m.fileformat,m.south,m.east,m.west,m.north,m.timebegin,m.timeend,m.title_en,m.uuid,m.description,g.id,m.projection,t.filetype,
cc.name as category, cc.name_zh as category_zh
from xml x left join metadata m on m.id=x.id left join thumbnail t on x.id=t.id
left join category c on c.id=m.id left join categorycode cc on c.code=cc.code
left join geonetworkmetadata g on g.uuid=m.uuid where m.uuid=".$this->db->quote($uuid);
$row=$this->db->fetchRow($sql);
$sql="select r.* from reference r left join mdref m on m.refid=r.id where m.uuid=?";
$sql=$this->db->quoteInto($sql,$uuid);
$ref=$this->db->fetchAll($sql);
$reference="";
foreach($ref as $k=>$refer)
{
$reference.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$refer['reference'])."\r\n";
}
$row['reference']=$reference;
$sql="select u.uselimit from mdlimit ml left join metadata m on ml.uuid=m.uuid left join uselimit u on ml.lid=u.id where m.uuid=?";
$sql=$this->db->quoteInto($sql,$uuid);
$limits=$this->db->fetchAll($sql);
$uselimits="";
foreach($limits as $k=>$limit)
{
//$uselimits.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$limit['uselimit'])."\r\n";
$uselimits.=($k+1).'. '.str_replace(array("\r\n", "\n", "\r"),'',$limit['uselimit'])."\r\n";
}
$row['uselimits']=$uselimits;
$sql="select ol.* from onlineresource ol left join metadata m on ol.uuid=m.uuid where m.uuid=?";
$sql=$this->db->quoteInto($sql,$uuid);
$res=$this->db->fetchAll($sql);
$resource="";
foreach($res as $k=>$r)
{
$resource.=($k+1).". ".$r['name'].' '.$r['linkage']."\n";
}
$row['resources']=$resource;
$sql="select r.role,s.* from role r left join responsible s on r.resid=s.id left join metadata m on m.uuid=r.uuid where m.uuid=? order by r.role,r.id";
$sql=$this->db->quoteInto($sql,$uuid);
$contact=$this->db->fetchAll($sql);
$contacts="";
$party_zh=array('resourceProvider'=>'资源提供者','custodian'=>'维护者','owner'=>'拥有者','user'=>'用户','distributor'=>'数据服务联系人','originator'=>'创建者','pointOfContact'=>'联系人','principalInvestigator'=>'数据调查与处理者','processor'=>'处理者','publisher'=>'元数据发布者','author'=>'元数据作者');
foreach($contact as $k=>$c)
{
@$contacts.=($k+1).". ".$party_zh[$c['role']]."\n";
@$contacts.=$c['individual'].' 单位:'.$c['organisation']."\n";
@$contacts.='地址:'.$c['country'].' '.$c['administractive'].' '.$c['city'].' '.$c['delivery']."\n";
@$contacts.='邮编:'.$c['postal'].' 电话:'.$c['phone'].' 邮件:'.$c['email']."\n\n";
}
$row['contacts']=$contacts;
$sql="select k.keyword, k.keytype from keyword k left join metadata m on k.id=m.id where m.uuid=? order by k.keytype";
$sql=$this->db->quoteInto($sql,$uuid);
$keys=$this->db->fetchAll($sql);
$keyword=array();
foreach($keys as $key)
{
@$keyword[$key['keytype']].=$key['keyword'].',';
}
$row['keyword']=$keyword;
if (is_numeric($row['projection']))
{
$sql="select proj4text from spatial_ref_sys where auth_srid=?";
$rs=$this->db->fetchRow($sql,array($row['projection']));
if ($rs) $projection=$rs['proj4text'];
}
if (!empty($projection)) $row['projection']=$projection;
} else
$projection='';
$dom = new DOMDocument();
$dom->loadXML($row['data']);
$xpath = new DOMXpath($dom);
$row['rfdenom']=@$dom->getElementsByTagName('rfDenom')->item(0)->nodeValue;
$row['resolution']=@$xpath->query('//scaleDist/value/Real')->item(0)->nodeValue;
$row['resolution'].=@$dom->getElementsByTagName('uomName')->item(0)->nodeValue;
//提前对表格进行预处理
$wiki=new WikiFormat();
$row['description']=$wiki->parseTable($row["description"]);
preg_match_all('/
[\s\S]*?<\/table>/im', $row['description'],$tables);
$search=array();
$replace=array();
foreach($tables as $k=>$table)
{
/*$search[]="
';
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();
}
}
function filelistAction()
{
$uuid=$this->_request->getParam('uuid');
$sql="select f.filename,f.id,s.uuid,f.depth from datafile f,dataset s where s.id=f.dsid and s.uuid=? and f.depth=1 and f.filename<>'/uuid.txt' order by f.isdir desc,f.filename";
$files=$this->db->fetchAll($this->db->quoteInto($sql,$uuid));
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
echo Zend_Json::encode($files);
}
function subfilelistAction()
{
$uuid=$this->_request->getParam('uuid');
$subpath=(int)$this->_request->getParam('subpath');
$depth=(int)$this->_request->getParam('depth');
$depth++;
$sql="select f.filename,f.id,s.uuid,f.depth from datafile f,dataset s where s.id=f.dsid and s.uuid=? and f.depth=".$depth." and f.filename<>'/uuid.txt' and f.filename ilike (select filename from datafile where id=".$subpath.")||'%' order by f.isdir desc,f.filename";
$files=$this->db->fetchAll($this->db->quoteInto($sql,$uuid));
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender();
echo Zend_Json::encode($files);
}
/*
* 附件下载
*/
function attachAction()
{
$zipuuid = $this->_request->getParam('zip');
$id=(int)$this->_request->getParam('id');
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
if(!empty($zipuuid))
{
$sql=$this->db->quoteInto("select a.*,md.title from mdattach m left join metadata md on m.uuid=md.uuid left join attachments a on m.id=a.id where m.uuid=? order by a.ts_created desc",$zipuuid);
$atts = $this->db->fetchAll($sql);
$title=$atts[0]['title'];
$zip = new ZipArchive();
$url = tempnam($this->config->temp->path,$zipuuid);//创建临时文件
$last_update=strtotime($atts[0]['ts_created']);
if (!file_exists($url) || (filemtime($fn)<$last_update))
{
if( $zip->open($url, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true )
{
throw new Exception("cannot open {$url} for writing.");
}
$updates = array(); //统计被下载的附件ID
foreach ($atts as $k=>$v)
{
if (file_exists($this->config->upload.$v['filename'])) {
$updates[]=$v['id'];
$zip->addFile($this->config->upload.$v['filename'],'/'.basename($v['realname']));
}
}
$zip->close();
}
//更新统计
$ids=join(',',$updates);
$sql = "update attachments set downtimes=downtimes+1 where id in ($ids)";
@$this->db->exec($sql);
//输出下载
$content=file_get_contents($url);
$this->getResponse()->setHeader('Content-Type', 'application/octet-stream')
->setHeader('Content-Disposition','attachment; filename="'.basename($title).'-文档.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);
}
elseif ($id>0)
{
//下载单个附件
$sql=$this->db->quoteInto("select a.* from attachments a where a.id=? order by a.ts_created desc",$id);
$atts = $this->db->fetchRow($sql);
$updates = array(); //统计被下载的附件ID
//更新统计
$sql = "update attachments set downtimes=downtimes+1 where id in ($id)";
@$this->db->exec($sql);
//输出下载
$content=file_get_contents($this->config->upload.$atts['filename']);
$this->getResponse()->setHeader('Content-Type', 'application/octet-stream')
->setHeader('Content-Disposition','attachment; filename="'.$atts['realname'].'"')
->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);
}
else
{
throw new Exception('发生严重意外!您确认链接正确?');
}
}
function mdjsonAction()
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
$num=(int)$this->_request->getParam('num');
$source=$this->_request->getParam('source');
if (empty($num)) $num=3;
$sql="select m.uuid,m.title,m.id,substring(m.description from 0 for 200) as description from normalmetadata m left join thumbnail t on m.id=t.id where ";
if (!empty($source))
$sql.=$this->db->quoteInto(" m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code=?) and ",$source);
$sql.=" length(t.data)>2 order by random() limit $num";
$rows=$this->db->fetchAll($sql);
echo Zend_Json::encode($rows);
}
}