1467 lines
61 KiB
PHP
Executable File
1467 lines
61 KiB
PHP
Executable File
<?php
|
||
class DataController extends Zend_Controller_Action
|
||
{
|
||
private $limit=10;
|
||
|
||
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 indexAction()
|
||
{
|
||
$md = new MetadataTable();
|
||
$db=$md->getAdapter();
|
||
//序列
|
||
$state=$db->query('select s.id,name,count(*) from series s,dataseries d where d.sid=s.id group by s.id,s.name');
|
||
$this->view->serie=$state->fetchAll();
|
||
//分类
|
||
$state=$db->query('select c.code,name,name_zh,count(*) from category c,categorycode cc where c.code=cc.code group by c.code,cc.name,cc.name_zh');
|
||
$this->view->category=$state->fetchAll();
|
||
//关键词
|
||
$state=$db->query("select keyword,count(*) from keyword where keytype='place' group by keyword order by count desc limit 20");
|
||
$k1=$state->fetchAll();
|
||
//$state=$db->query("select keyword,count(*) from keyword where keytype='theme' group by keyword order by count desc limit 20");
|
||
$state=$db->query("select k.keyword,count(k.keyword) from keyword k left join metadata m on k.id=m.id where k.keytype='theme' and (m.uuid in (select uuid from dataorder group by uuid order by count(uuid) desc limit 20)) group by k.keyword order by count(k.keyword) desc limit 20");
|
||
$k2=$state->fetchAll();
|
||
$state=$db->query("select keyword,count(*) from keyword where keytype='discipline' group by keyword order by count desc limit 20");
|
||
$k3=$state->fetchAll();
|
||
$state=$db->query("select keyword,count(*) from keyword where keytype='stratum' group by keyword order by count desc limit 20");
|
||
$k4=$state->fetchAll();
|
||
//$state=$db->query("select keyword,count(*) from keyword where keytype='temporal' group by keyword order by count desc limit 20");
|
||
$state=$db->query("select k.keyword,count(k.keyword) from keyword k left join metadata m on k.id=m.id where k.keytype='temporal' and (m.uuid in (select uuid from dataorder group by uuid order by count(uuid) desc limit 20)) group by k.keyword order by count(k.keyword) desc limit 20");
|
||
$k5=$state->fetchAll();
|
||
$this->view->keywords=array('place'=>$k1,'theme'=>$k2,'discipline'=>$k3,'stratum'=>$k4,'temporal'=>$k5);
|
||
//最新10个入库数据
|
||
$state=$db->query('select id,uuid,title from metadata order by id desc limit 10');
|
||
$this->view->metadata = $state->fetchAll();
|
||
//特色数据
|
||
|
||
//服务
|
||
$l=new mydir($this->view->config->paths->newsletter,"newsletter_*.pdf");
|
||
$this->view->newsletter=$l->getLast();
|
||
$name=basename($this->view->newsletter,'.pdf');
|
||
list(,$this->view->newsletterno)=explode("_",$name);
|
||
|
||
$this->view->addHelperPath('helper','Zend_View_Helper_');
|
||
$form=new MaillistForm();
|
||
$form->submit->setLabel('输入邮件地址,订阅数据通讯列表');
|
||
|
||
$this->view->form=$form;
|
||
if ($this->_request->isPost()) {
|
||
//发送邮件
|
||
$formData=$this->_request->getPost();
|
||
if ($form->isValid($formData)) {
|
||
$mail=new WestdcMailer($this->view->config->smtp);
|
||
$mail->setFrom($formData['email']);
|
||
$mail->setBodyText(".");
|
||
$mail->setSubject('subscribe');
|
||
$mail->addTo($this->view->config->reportemail);
|
||
$mail->send();
|
||
$this->messenger->addMessage('订阅成功,请检查您的邮件!');
|
||
$this->_redirect('/data/');
|
||
}
|
||
} else {
|
||
$auth = Zend_Auth::getInstance();
|
||
if ($auth->hasIdentity()) {
|
||
$user=$auth->getIdentity();
|
||
$formData['email']=$user->email;
|
||
$form->populate($formData);
|
||
}
|
||
}
|
||
$searchform=new SearchForm();
|
||
$this->view->searchform=$searchform;
|
||
|
||
//其他连接
|
||
}
|
||
function onlinelistAction()
|
||
{
|
||
$md=new MetadataTable();
|
||
$db=$md->getAdapter();
|
||
$page=(int)$this->_request->getParam('page');
|
||
if (empty($page)) $page=1;
|
||
$limit=30;
|
||
$offset=$limit*($page-1);
|
||
$state=$db->query('select count(*) from metadata where datatype=0');
|
||
$row=$state->fetchAll();
|
||
$sum=$row[0]['count'];
|
||
$select=$db->select();
|
||
$select->from('metadata','*')->where('datatype=0')->order('title')->limitPage($page,$limit);
|
||
$this->view->metadata = $db->fetchAll($select);
|
||
$this->view->page=new Pagination($sum,$page,$limit);
|
||
}
|
||
function offlinelistAction()
|
||
{
|
||
$md=new MetadataTable();
|
||
$db=$md->getAdapter();
|
||
$page=(int)$this->_request->getParam('page');
|
||
if (empty($page)) $page=1;
|
||
$limit=30;
|
||
$offset=$limit*($page-1);
|
||
$state=$db->query('select count(*) from metadata where datatype=1');
|
||
$row=$state->fetchAll();
|
||
$sum=$row[0]['count'];
|
||
$select=$db->select();
|
||
$select->from('metadata','*')->where('datatype=1')->order('title')->limitPage($page,$limit);
|
||
$this->view->metadata = $db->fetchAll($select);
|
||
$this->view->page=new Pagination($sum,$page,$limit);
|
||
}
|
||
//展示最近20条离线神情记录情况
|
||
function offlineappAction()
|
||
{
|
||
$sql="select * from offlineapp where ts_approved is not null and pdflink<>'' and status>=0 order by ts_created desc limit 20";
|
||
$this->view->rows=$this->db->fetchAll($sql);
|
||
}
|
||
function requestAction()
|
||
{
|
||
}
|
||
function submitAction()
|
||
{
|
||
}
|
||
function serviceAction()
|
||
{
|
||
}
|
||
function newsletterAction()
|
||
{
|
||
$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);
|
||
$form=new MaillistForm();
|
||
$this->view->form=$form;
|
||
$form->submit->setLabel('输入邮件地址,订阅数据通讯列表');
|
||
if ($this->_request->isPost()) {
|
||
//发送邮件
|
||
$formData=$this->_request->getPost();
|
||
if ($form->isValid($formData)) {
|
||
//$mail=new Zend_Mail('utf-8');
|
||
$mail=new WestdcMailer($this->view->config->smtp);
|
||
$mail->setFrom($formData['email']);
|
||
$mail->setBodyText(".");
|
||
$mail->setSubject('subscribe');
|
||
$mail->addTo($this->view->config->reportemail);
|
||
/*
|
||
$tr=new Zend_Mail_Transport_Smtp($this->view->config->smtp->host,
|
||
array('ssl' => $this->view->config->smtp->ssl,
|
||
'auth'=>$this->view->config->smtp->auth,
|
||
'username'=>$this->view->config->smtp->username,
|
||
'password'=>$this->view->config->smtp->password));
|
||
$mail->send($tr);
|
||
*/
|
||
$mail->send();
|
||
$this->messenger->addMessage('订阅成功,请检查您的邮件!');
|
||
$this->_redirect('/data/newsletter');
|
||
}
|
||
} else {
|
||
$auth = Zend_Auth::getInstance();
|
||
if ($auth->hasIdentity()) {
|
||
$user=$auth->getIdentity();
|
||
$formData['email']=$user->email;
|
||
$form->populate($formData);
|
||
}
|
||
}
|
||
}
|
||
function featureAction()
|
||
{
|
||
$sql="select * from datafeature order by id desc";
|
||
$this->view->feature=$this->db->fetchAll($sql);
|
||
}
|
||
|
||
function datasetcdAction()
|
||
{
|
||
$cd=new DatasetcdTable();
|
||
$this->view->rows=$cd->fetchAll();
|
||
}
|
||
/*
|
||
* 数据浏览
|
||
*/
|
||
function browseAction()
|
||
{
|
||
$md=new MetadataTable();
|
||
$db=$md->getAdapter();
|
||
$page=(int)$this->_request->getParam('page');
|
||
if (empty($page)) $page=1;
|
||
$limit=10;
|
||
$offset=$limit*($page-1);
|
||
$state=$db->query('select count(*) from metadata');
|
||
$row=$state->fetchAll();
|
||
$sum=$row[0]['count'];
|
||
$select=$db->select();
|
||
$select->from('metadata','*')->order('id desc')->limitPage($page,$limit);
|
||
$this->view->metadata = $db->fetchAll($select);
|
||
$this->view->page=new Pagination($sum,$page,$limit);
|
||
}
|
||
function tagAction()
|
||
{
|
||
$id = (int)$this->_request->getParam('id');
|
||
$key = $this->_request->getParam('key');
|
||
$md=new KeywordTable();
|
||
$db=$md->getAdapter();
|
||
$page=(int)$this->_request->getParam('page');
|
||
if (empty($page)) $page=1;
|
||
$limit=10;
|
||
$offset=$limit*($page-1);
|
||
$state=$db->query('select keyword,count(*),keytype from keyword group by keyword,keytype order by keytype,keyword,count desc');
|
||
$this->view->keywords=$state->fetchAll();
|
||
if ($id>0 or !empty($key)) {
|
||
if (empty($key)) {
|
||
$where=$db->quoteInto('id = ?',$id);
|
||
$row=$md->fetchRow($where);
|
||
$key=$row->name;
|
||
}
|
||
$this->view->codename=$key;
|
||
$sql=$db->quoteInto('select count(m.id) from metadata m,keyword k where m.id=k.id and k.keyword=?',$key);
|
||
$state=$db->query($sql);
|
||
$row=$state->fetchAll();
|
||
$sum=$row[0]['count'];
|
||
$select=$db->select();
|
||
$select->from('metadata','*')->join('keyword','metadata.id=keyword.id')->where('keyword.keyword=?',$key)->order('metadata.title')->limitPage($page,$limit);
|
||
//$sql=$db->quoteInto('select m.* from metadata m,keyword k where m.id=k.id and k.keyword=?',$key);
|
||
//$state=$db->query($sql);
|
||
$this->view->metadata=$db->fetchAll($select);
|
||
$this->view->page=new Pagination($sum,$page,$limit);
|
||
}
|
||
}
|
||
/*
|
||
* 数据集序列浏览
|
||
*/
|
||
function seriesAction()
|
||
{
|
||
$id = $this->_request->getParam('id');
|
||
if (empty($id)) $id=0;
|
||
if (!is_numeric($id))
|
||
{
|
||
$name=$id;
|
||
$id='';
|
||
}
|
||
$keyword=$this->_request->getParam('keyword');
|
||
$md=new SeriesTable();
|
||
$db=$md->getAdapter();
|
||
if (empty($id)) {
|
||
if (!empty($name))
|
||
{
|
||
$where=$db->quoteInto('name = ?',$name);
|
||
$row=$md->fetchRow($where);
|
||
}
|
||
} else {
|
||
$where=$db->quoteInto('id = ?',$id);
|
||
$row=$md->fetchRow($where);
|
||
}
|
||
if (!empty($id) or !empty($name))
|
||
{
|
||
if (!$row) $this->_redirect('/data');
|
||
$id=$row->id;
|
||
}
|
||
$page=(int)$this->_request->getParam('page');
|
||
if (empty($page)) $page=1;
|
||
$limit=10;
|
||
$offset=$limit*($page-1);
|
||
$state=$db->query('select s.id,name,count(*) from series s,dataseries d where d.sid=s.id group by s.id,s.name');
|
||
$this->view->serie=$state->fetchAll();
|
||
if ($id>0) {
|
||
$where=$db->quoteInto('id = ?',$id);
|
||
$row=$md->fetchRow($where);
|
||
$this->view->codename=$row->name;
|
||
if (!empty($keyword))
|
||
{
|
||
$sql='select count(m.id) as count from metadata m,dataseries d,keyword k where m.id=d.id and m.id=k.id and d.sid=? and k.keyword=?';
|
||
$row=$db->fetchAll($sql,array($id,$keyword));
|
||
}else{
|
||
$sql='select count(m.id) as count from metadata m,dataseries d where m.id=d.id and d.sid=?';
|
||
$row=$db->fetchAll($sql,array($id));
|
||
}
|
||
$sum=$row[0]['count'];
|
||
$select=$db->select();
|
||
$select->from('metadata','*')->join('dataseries','metadata.id=dataseries.id')->where('dataseries.sid=?',$id)->order('metadata.title')->limitPage($page,$limit);
|
||
if (!empty($keyword)) $select->join('keyword','keyword.id=metadata.id')->where('keyword.keyword=?',$keyword);
|
||
$this->view->metadata=$db->fetchAll($select);
|
||
$this->view->page=new Pagination($sum,$page,$limit);
|
||
$this->view->showtools=($sum>$page)?true:false;
|
||
$this->view->form=new SearchForm();
|
||
$sql=$db->quoteInto("select keyword,count(*) as count from (select t.keyword,t.id from keyword t left join dataseries d on t.id=d.id where t.keytype='place' and d.sid=?) as f group by keyword order by count desc limit 30",$id);
|
||
$state=$db->query($sql);
|
||
$row=$state->fetchAll();
|
||
$this->view->places=$row;
|
||
$this->view->seriesid=$id;
|
||
} else {
|
||
//提供全部数据集序列列表
|
||
}
|
||
}
|
||
/*
|
||
* 分类浏览模式
|
||
*/
|
||
function categoryAction()
|
||
{
|
||
$page = $this->_request->getParam('page');
|
||
$code = (int)$this->_request->getParam('code');
|
||
$md=new CategoryCodeTable();
|
||
$db=$md->getAdapter();
|
||
$state=$db->query('select c.code,name,name_zh,count(*) from category c,categorycode cc where c.code=cc.code group by c.code,cc.name,cc.name_zh');
|
||
$this->view->category=$state->fetchAll();
|
||
if ($code>0 && $code<20) {
|
||
$where=$db->quoteInto('code = ?',$code);
|
||
$row=$md->fetchRow($where);
|
||
$this->view->codename=(empty($row->name_zh)?$row->name:$row->name_zh);
|
||
$sql='select m.* from metadata m,category c where m.id=c.id and c.code=? order by m.title';
|
||
$state=$db->query($sql,array($code));
|
||
$rows = $state->fetchAll();
|
||
|
||
$paginator = Zend_Paginator::factory($rows);
|
||
$paginator->setCurrentPageNumber($page);//($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;
|
||
|
||
} else {
|
||
//提供全部分类列表
|
||
}
|
||
}
|
||
/*
|
||
* 时间浏览方式
|
||
* todo:实现xml的缓存,基于时间的缓存(每天)?基于元数据修改的缓存,每次导入后都重新生成一次。
|
||
*/
|
||
function timelineAction()
|
||
{
|
||
$fn="time1.xml";
|
||
$rows=$this->db->fetchAll("select ts_created from metadata order by ts_created desc limit 1");
|
||
$last_update=strtotime($rows[0]['ts_created']);
|
||
if (!file_exists($fn) || (filemtime($fn)<$last_update))
|
||
{
|
||
$dateformat="M j Y";
|
||
$md = new MetadataTable();
|
||
$db=$md->getAdapter();
|
||
$state=$db->query('select id,uuid,description,title,timebegin,timeend from metadata where timebegin is not null order by timebegin');
|
||
$rows=$state->fetchAll();
|
||
$timexml='<data>';
|
||
foreach($rows as $row) {
|
||
$timexml.='<event start="'.date($dateformat,strtotime($row['timebegin'])).'" ';
|
||
if ($row['timeend']!='' && $row['timeend']!=$row['timebegin']) $timexml.=' end="'.date($dateformat,strtotime($row['timeend'])).'" isDuration="true"';
|
||
$timexml.= ' title="'.htmlspecialchars($row['title']).'" image="/images/westdc_40w.gif" link="/data/'.$row['uuid'].'">';
|
||
$desc_length=mb_strlen($row['description'],"UTF-8");
|
||
$desc=mb_substr($row['description'],0,($desc_length>300)?300:$desc_length,"UTF-8");
|
||
if ($desc_length>300) $desc.=" ...";
|
||
$timexml.=htmlspecialchars($desc);
|
||
$timexml.="</event>\n";
|
||
}
|
||
$timexml.='</data>';
|
||
$fp=fopen($fn,'w');
|
||
fwrite($fp,$timexml);
|
||
fclose($fp);
|
||
}
|
||
//$this->_helper->layout->disableLayout();
|
||
}
|
||
/*
|
||
* todo:空间浏览
|
||
*/
|
||
function mapAction()
|
||
{
|
||
//use json & openlayers?
|
||
$id=(int)$this->_request->getParam('id');
|
||
if ($id>0) $this->view->params="/id/$id";
|
||
}
|
||
/*
|
||
* 产生geojson数据
|
||
*/
|
||
function jsonAction()
|
||
{
|
||
$md=new MetadataTable();
|
||
$db=$md->getAdapter();
|
||
$id = (int)$this->_request->getParam('id');
|
||
$where='';
|
||
if (!empty($id)) { $where=' where id='.$id; }
|
||
$sql='select id,uuid,west,south,north,east,title from metadata'.$where;
|
||
$state=$db->query($sql);
|
||
$rows=$state->fetchAll();
|
||
$geomd=new GeoMetaData();
|
||
foreach($rows as $row){
|
||
if ($id)
|
||
$box=new GeoBox($row['west'],$row['south'],$row['east'],$row['north']);
|
||
else
|
||
$box=new GeoBoxLine($row['west'],$row['south'],$row['east'],$row['north']);
|
||
$feature=new Geofeature();
|
||
$feature->id=$row['id'];
|
||
$feature->addProperties('title',$row['title']);
|
||
$feature->addProperties('uuid',$row['uuid']);
|
||
$feature->addProperties('id',$row['id']);
|
||
$feature->geometry=$box;
|
||
$geomd->addFeature($feature);
|
||
}
|
||
$this->_helper->json($geomd);
|
||
}
|
||
/*
|
||
* 时空动态浏览
|
||
*/
|
||
function timemapAction()
|
||
{
|
||
$sql='select id,uuid,west,south,north,east,title,timebegin,timeend from metadata where timebegin is not null';
|
||
$this->view->rows=$this->db->fetchAll($sql);
|
||
}
|
||
/*
|
||
* 返回XML源文件
|
||
*/
|
||
function xmlAction()
|
||
{
|
||
$uuid=$this->_request->getParam('uuid');
|
||
$row=$this->db->fetchRow("select xml.data from xml left join metadata on xml.id=metadata.id where metadata.uuid=?",array($uuid));
|
||
$this->_helper->layout->disableLayout();
|
||
$this->_helper->viewRenderer->setNoRender();
|
||
$this->getResponse()->setHeader('Content-Type', 'text/xml')
|
||
->setBody($row['data']);
|
||
}
|
||
function detailAction()
|
||
{
|
||
$id=(int)$this->_request->getParam('id');
|
||
$xml=new XmlTable();
|
||
$db=$xml->getAdapter();
|
||
$where=$db->quoteInto('id=?',$id);
|
||
$order='id desc';
|
||
$row=$xml->fetchRow($where,$order);
|
||
// Load the XML source
|
||
$xml = new DOMDocument;
|
||
$xml->loadXML($row->data);
|
||
$xsl = new DOMDocument;
|
||
$xsl->load($this->view->config->westdc->xsl);
|
||
// Configure the transformer
|
||
$proc = new XSLTProcessor;
|
||
$proc->importStyleSheet($xsl); // attach the xsl rules
|
||
$this->view->xml=$proc->transformToXML($xml);
|
||
//$this->_helper->layout->disableLayout();
|
||
//$this->_helper->viewRenderer->setNoRender();
|
||
//$this->getResponse()->setHeader('Content-Type', 'text/html')
|
||
// ->setBody($proc->transformToXML($xml));
|
||
}
|
||
function feedAction()
|
||
{
|
||
$feedArray = array(
|
||
'title' => '中国西部环境与生态科学数据中心',
|
||
'link' => 'http://'.$_SERVER['SERVER_NAME'].'/data/feed',
|
||
'description' => '共享西部计划产生的数据',
|
||
'language' => 'zh-CN',
|
||
'charset' => 'utf-8',
|
||
'published' => time(),
|
||
//'generator' => 'Zend Framework Zend_Feed',
|
||
'entries' => array()
|
||
);
|
||
$sql="select * from metadata order by ts_created desc";
|
||
$rs=$this->db->fetchAll($sql);
|
||
$feedArray['published']=strtotime($rs[0]['ts_created']);
|
||
foreach($rs as $r)
|
||
{
|
||
$feedArray['entries'][] = array(
|
||
'title' => $r['title'],
|
||
'link' => 'http://'.$_SERVER['SERVER_NAME'].'/data/' . $r['uuid'],
|
||
'guid' => 'http://'.$_SERVER['SERVER_NAME'].'/data/' . $r['uuid'],
|
||
//'content'=>$r['description'],
|
||
'description' => $r['description'],
|
||
'lastUpdate' => strtotime($r['ts_created'])
|
||
);
|
||
}
|
||
$feed = Zend_Feed::importArray($feedArray,'rss');
|
||
$this->_helper->layout->disableLayout();
|
||
$this->_helper->viewRenderer->setNoRender();
|
||
$feed->send();
|
||
}
|
||
/*
|
||
* todo: search
|
||
*/
|
||
function searchAction()
|
||
{
|
||
$this->view->addHelperPath('helper','Zend_View_Helper_');
|
||
$form=new SearchForm();
|
||
$this->view->form=$form;
|
||
//$form->submit->setLabel('快速搜索');
|
||
$key=$this->_request->getParam('q');
|
||
if (!empty($key)) {
|
||
//$formData=$this->_request->getPost();
|
||
//include_once("bcspamblock.php");
|
||
//if ($form->isValid($formData)) {
|
||
$page=@(int)$this->_request->getParam('page');
|
||
if (empty($page)) $page=1;
|
||
$offset=$this->limit*($page-1);
|
||
$search=new Search($key);
|
||
$where=$search->sql_expr(array("title","description"));
|
||
$row=$this->db->fetchAll("select count(*) from metadata where ".$where);
|
||
$sum=$row[0]['count'];
|
||
$sql="select uuid,title,id,description from metadata where ".$where." order by title limit ? offset ?";
|
||
$this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset));
|
||
$this->view->page=new Pagination($sum,$page,$this->limit);
|
||
$this->view->key=$key;
|
||
}
|
||
}
|
||
/*
|
||
* todo: 高级搜索
|
||
*/
|
||
function advancesearchAction()
|
||
{
|
||
$this->view->addHelperPath('helper','Zend_View_Helper_');
|
||
//$form=new SearchForm();
|
||
//$this->view->form=$form;
|
||
|
||
$md=new MetadataTable();
|
||
$db=$md->getAdapter();
|
||
$page=(int)$this->_request->getParam('page');
|
||
if (empty($page)) $page=1;
|
||
$limit=10;
|
||
$offset=$limit*($page-1);
|
||
$key=$this->_request->getParam('q');
|
||
$n=(int)$this->_request->getParam('n');
|
||
$s=(int)$this->_request->getParam('s');
|
||
$e=(int)$this->_request->getParam('e');
|
||
$w=(int)$this->_request->getParam('w');
|
||
if (!(empty($n) && empty($key))) {
|
||
if (empty($n)) $n=90;
|
||
if (empty($s)) $s=-90;
|
||
if (empty($e)) $e=180;
|
||
if (empty($w)) $w=-180;
|
||
$start=$this->_request->getParam('start');
|
||
$end=$this->_request->getParam('end');
|
||
if (!empty($key)) {
|
||
$sql='select count(*) from metadata where east<? and west>? and north<? and south>? and (title ilike ? or description ilike ?)';
|
||
$row=$db->fetchAll($sql,array($e,$w,$n,$s,'%'.$key.'%','%'.$key.'%'));
|
||
} else {
|
||
$sql='select count(*) from metadata where east<? and west>? and north<? and south>?';
|
||
$row=$db->fetchAll($sql,array($e,$w,$n,$s));
|
||
}
|
||
$sum=$row[0]['count'];
|
||
$select=$db->select();
|
||
$select->from('metadata','*')->where('east<?',$e)->where('west>?',$w)->where('north<?',$n)->where('south>?',$s);
|
||
if (!empty($key)) $select->where('(title ilike ? or description ilike ?)','%'.$key.'%');
|
||
$select->order('title')->limit($limit,$offset);
|
||
$this->view->metadata = $db->fetchAll($select);
|
||
$this->view->page=new Pagination($sum,$page);
|
||
$this->view->key=$key;
|
||
}
|
||
}
|
||
/*
|
||
* 根据id或uuid来查看元数据
|
||
* id为一组数字,uuid为唯一标识符
|
||
*/
|
||
function viewAction()
|
||
{
|
||
$md=new MetadataTable();
|
||
$db=$md->getAdapter();
|
||
$id = (int)$this->_request->getParam('id');
|
||
if (empty($id)) {
|
||
$uuid = $this->_request->getParam('uuid');
|
||
if (empty($uuid)) $this->_redirect('/data');
|
||
$where=$db->quoteInto('uuid = ?',$uuid);
|
||
$row=$md->fetchRow($where);
|
||
} else {
|
||
$where=$db->quoteInto('id = ?',$id);
|
||
$row=$md->fetchRow($where);
|
||
}
|
||
if (!$row) $this->_redirect('/data');
|
||
$id=$row->id;
|
||
$uuid=$row->uuid;
|
||
$this->view->metadata=$row;
|
||
//提前对表格进行预处理
|
||
$wiki=new WikiFormat();
|
||
$this->view->metadata->description=$wiki->parseTable($this->view->escape($row->description));
|
||
//处理外部链接
|
||
$this->view->metadata->description=preg_replace('/\[\s*(http:\/\/.+?)\s+(.*?)\]/m','<a href="$1">$2</a>',$this->view->metadata->description);
|
||
if (is_numeric($row->projection))
|
||
{
|
||
$sql="select proj4text from spatial_ref_sys where auth_srid=?";
|
||
$rs=$db->fetchRow($sql,array((int)$row->projection));
|
||
if ($rs) $this->view->projection=$rs['proj4text'];
|
||
}
|
||
$this->view->keys=$this->db->fetchAll("select * from keyword where id=? order by keytype,ts_created",array($id));
|
||
$sql='select c.code,cc.name,cc.name_zh from category c,categorycode cc where c.code=cc.code and c.id= ?';
|
||
$state=$db->query($sql,array($id));
|
||
$this->view->category=$state->fetchAll();
|
||
$sql='select s.name,s.id from dataseries d, series s where d.sid=s.id and d.id= ?';
|
||
$state=$db->query($sql,array($id));
|
||
$this->view->series=$state->fetchAll();
|
||
$sql=$db->quoteInto("select count(*) as count from dataorder where uuid=?",$uuid);
|
||
$row=$db->fetchRow($sql);
|
||
$this->view->downloaded=$row['count'];
|
||
//update the viewed times
|
||
$sql="update mdstat set viewed=viewed+1 where uuid=?";
|
||
$db->query($sql,array($uuid));
|
||
$sql=$db->quoteInto("select viewed from mdstat where uuid=?",$uuid);
|
||
$row=$db->fetchRow($sql);
|
||
$this->view->viewed=$row['viewed'];
|
||
//数据文档
|
||
$sql="select linkage from onlineresource where uuid=? and description='数据说明文档'";
|
||
$sql=$db->quoteInto($sql,$uuid);
|
||
$row=$db->fetchRow($sql);
|
||
if ($row) $this->view->doc=$row['linkage'];
|
||
//相关资源
|
||
$sql="select * from onlineresource where uuid=? and description<>'数据说明文档' and (linkage not like '%ftp.westgis%') and name<>'元数据地址'";
|
||
$sql=$db->quoteInto($sql,$uuid);
|
||
$this->view->resources=$db->fetchAll($sql);
|
||
//建议参考文献
|
||
$sql="select r.* from reference r left join mdref m on m.refid=r.id where m.uuid=?";
|
||
$sql=$db->quoteInto($sql,$uuid);
|
||
$this->view->ref=$db->fetchAll($sql);
|
||
//相关用户
|
||
$sql="select p.email,p.individual,p.organisation,r.role from role r left join responsible p on r.resid=p.id where r.uuid=? order by r.role,r.id";
|
||
$this->view->authors=$db->fetchAll($sql,array($uuid));
|
||
//数据限制信息
|
||
$sql="select u.* from uselimit u left join mdlimit m on u.id=m.lid where m.uuid=?";
|
||
$this->view->uselimits=$db->fetchAll($sql,array($uuid));
|
||
//相关元数据,根据同名关键词实现
|
||
//$sql="select distinct(md.uuid),md.title from keyword kw left join metadata md on kw.id=md.id where kw.keyword in (select k.keyword from keyword k left join metadata m on k.id=m.id where m.id=? and k.keytype='theme') and kw.id<>? limit 10";
|
||
$sql="select distinct(md.uuid),md.title from keyword kw left join metadata md on kw.id=md.id where kw.keyword in (select k.keyword from keyword k left join metadata m on k.id=m.id where m.id=?) and kw.id<>? limit 10";
|
||
$this->view->related=$this->db->fetchAll($sql,array($id,$id));
|
||
//相关文献
|
||
$sql="select * from knl_article where ";
|
||
foreach($this->view->keys as $k)
|
||
{
|
||
if ($k["keytype"]=='theme')
|
||
{
|
||
$sql.=" title like '%".$k["keyword"]."%' or ";
|
||
}
|
||
}
|
||
$sql.=" 1<>1 limit 10";
|
||
$this->view->literature=$this->db->fetchAll($sql);
|
||
//数据附件
|
||
$sql = "select id from mdattach where uuid='$uuid'";
|
||
$re = $this->db->query($sql);
|
||
$row = $re->fetch();
|
||
if(empty($row['id']))
|
||
{
|
||
$this->view->attachment = "无";
|
||
}
|
||
else
|
||
{
|
||
$this->view->attachment = "<a href='/data/attach/uuid/$uuid'>有可下载的附件</a>";
|
||
}
|
||
//数据评论
|
||
$sql="select * from comments where uuid=? order by id desc";
|
||
$this->view->comments=$this->db->fetchAll($sql,array($uuid));
|
||
$user=Zend_Auth::getInstance()->getIdentity();
|
||
$commentForm=new CommentForm();
|
||
$formdata['uuid']=$uuid;
|
||
$formdata['uid']=0;//用户ID,默认为0,即未登录用户
|
||
$this->view->addHelperPath('helper','Zend_View_Helper_');
|
||
if ($this->_request->isPost()) {
|
||
include_once("bcspamblock.php");
|
||
$formdata=$this->_request->getPost();
|
||
if (bcspamblock_verify() && $commentForm->isValid($formdata)) {
|
||
$sql="insert into comments (userid,uuid,author,email,url,ip,content,agent,type) values(?,?,?,?,?,?,?,?,?)";
|
||
$agent=$this->_request->getHeader('User-Agent');
|
||
$ip=$this->_request->getServer('REMOTE_ADDR');
|
||
$type='comment';
|
||
$stripper = new Zend_Filter_StripTags('strong');//剔除特殊字符HTML
|
||
$content=$stripper->filter($formdata['content']);
|
||
$author=$stripper->filter($formdata['author']);
|
||
$this->db->query($sql,array($formdata['uid'],$formdata['uuid'],$author,$formdata['email'],$formdata['url'],$ip,$content,$agent,$type));
|
||
$formdata['content']='';
|
||
}
|
||
} elseif ($user) {
|
||
$formdata['uid']=$user->id;
|
||
$formdata['author']=$user->username;
|
||
$formdata['email']=$user->email;
|
||
}
|
||
$commentForm->populate($formdata);
|
||
$this->view->commentForm=$commentForm;
|
||
|
||
//metadata,keyword,series,category,
|
||
}
|
||
/*
|
||
* 数据评论,根据UUID读取
|
||
*/
|
||
function commentAction()
|
||
{
|
||
$this->_helper->layout->disableLayout();
|
||
$this->_helper->viewRenderer->setNoRender();
|
||
$uuid=$this->_request->getParam('uuid');
|
||
if (empty($uuid)) die();
|
||
$sql="select * from comments where uuid=? order by id desc";
|
||
$comments=$this->db->fetchAll($sql,array($uuid));
|
||
if ($comments)
|
||
{
|
||
foreach($comments as $c)
|
||
{
|
||
//$author=$this->view->escape($c['author']);
|
||
$author=$c['author'];
|
||
$author=($c['userid'])?"<strong>".$author."</strong>":$author;
|
||
$author=($c['url'])?'<a href="'.$c['url'].'">'.$author.'</a>':$author;
|
||
print "<div class='comment-content'><span>".$author." 发表于".date('Y-m-d H:i:s',strtotime($c['ts_created']))."</span><p>".($c['content'])."</p></div>";
|
||
}
|
||
}//else echo "<li>No comments.</li>";
|
||
}
|
||
|
||
function creatform($datas) {
|
||
return '
|
||
<div class="downloadtip">温馨提示:您需要填写以下信息才可以下载该数据</div>
|
||
<form id="todownloadform" name="todownloadform" action="/data/todownload/">
|
||
<table>
|
||
<tr><td>真实姓名</td><td><input type="text" name="username" value="'.$datas['username'].'" /></td></tr>
|
||
<tr><td>单位名称</td><td><input type="text" name="unit" value="'.$datas['unit'].'"/></td></tr>
|
||
<tr><td>联系电话</td><td><input type="text" name="phone" value="'.$datas['phone'].'"/></td></tr>
|
||
<tr><td>联系地址</td><td><input type="text" name="address" value="'.$datas['address'].'"/></td></tr>
|
||
<tr><td>邮政编码</td><td><input type="text" name="postcode" value="'.$datas['postcode'].'"/></td></tr>
|
||
<tr><td>电子邮箱</td><td><input type="text" name="email" value="'.$datas['email'].'"/></td></tr>
|
||
<tr><td>项目说明</td><td><textarea name="project">'.$datas['project'].'</textarea></td></tr>
|
||
</table>
|
||
请您填写完整的数据用途信息,包括项目类型、编号、题目、负责人等信息;若仅用于论文写作,请告知研究题目或主要内容,并注明导师姓名;其他用途如实注明即可。清晰明确的数据用途有助于我们更快得审核和通过申请,也会使您更快获得数据!<br />
|
||
例一:<br />
|
||
项目类型:973<br />
|
||
项目名称:飞行终端区复杂场景建模的理论与方法子课题:基于多源遥感影像的目标和场景三维重建研究<br />
|
||
项目编号:2010CB731801<br />
|
||
项目负责人:邵振峰<br />
|
||
使用目的:用于模拟基于多源遥感影像的目标和场景<br />
|
||
<br />
|
||
例二:<br />
|
||
硕士毕业论文:《全波形激光雷达数据处理研究》,导师:李传荣研究员。<br />
|
||
<input type="button" value="提交" onclick="todownload(0)" class="btn" />
|
||
<input type="hidden" name="submited" value="1" />
|
||
</form>';
|
||
}
|
||
/**
|
||
* 判断用户是否填写了申请信息
|
||
* @param string $uuid
|
||
* @param int $userid
|
||
*/
|
||
function todownloadAction() {
|
||
|
||
$this->_helper->layout->disableLayout();
|
||
$this->_helper->viewRenderer->setNoRender();
|
||
|
||
$uuid = $this->_request->getParam('uuid');
|
||
$ft = $this->_request->getParam('ft');
|
||
|
||
if (empty($uuid))
|
||
{
|
||
echo "请按正确的下载步骤进行下载<br />
|
||
如果页面没有自动跳转,<a href='/data'>请点击这里</a>
|
||
<script>self.location='/data'</script>";
|
||
exit();
|
||
}
|
||
|
||
$auth = Zend_Auth::getInstance();
|
||
if (!$auth->hasIdentity())
|
||
{
|
||
echo "您需要登录才能下载<br />
|
||
如果页面没有自动跳转,<a href='/account/login'>请点击这里进入登录页面</a>
|
||
<script>self.location='/account/login/?href='+location.href</script>";
|
||
exit();
|
||
}
|
||
|
||
$userid=Zend_Auth::getInstance()->getIdentity()->id;
|
||
|
||
$datas = array();
|
||
$submited = $this->_request->getParam('submited');
|
||
$datas['username'] = $this->_request->getParam('username');
|
||
$datas['unit'] = $this->_request->getParam('unit');
|
||
$datas['phone'] = $this->_request->getParam('phone');
|
||
$datas['address'] = $this->_request->getParam('address');
|
||
$datas['postcode'] = $this->_request->getParam('postcode');
|
||
$datas['email'] = $this->_request->getParam('email');
|
||
$datas['project'] = $this->_request->getParam('project');
|
||
|
||
|
||
|
||
$form=$this->creatform($datas);
|
||
|
||
if (!empty($submited) && $ft==0){
|
||
|
||
foreach($datas as $k=>$v)
|
||
{
|
||
if(empty($v))
|
||
{
|
||
echo $form.'<script>alert("每一项内容都需要填写")</script>';
|
||
exit();
|
||
}
|
||
}
|
||
|
||
if(!is_numeric($datas['postcode']))
|
||
{
|
||
echo $form.'<script>alert("联系电话和邮政编码请填写数字")</script>';
|
||
exit();
|
||
}
|
||
|
||
if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i",$datas['email']))
|
||
{
|
||
echo $form.'<script>alert("请填写正确的email地址")</script>';
|
||
exit();
|
||
}
|
||
|
||
$data = array(
|
||
'userid' => $userid,
|
||
'username' => $datas['username'],
|
||
'unit' => $datas['unit'],
|
||
'phone' => $datas['phone'],
|
||
'address' => $datas['address'],
|
||
'postcode' => $datas['postcode'],
|
||
'project' => $datas['project'],
|
||
'uuid' =>$uuid,
|
||
'email' =>$datas['email']
|
||
);
|
||
|
||
if($this->db->insert('onlineapp',$data))
|
||
{
|
||
$select = "select id from onlineapp where userid='$userid' order by id desc";
|
||
$re=$this->db->query($select);
|
||
$row=$re->fetch();
|
||
echo "您的信息已经提交成功,可以进行下载。<br />
|
||
如果页面没有自动跳转,<a href='/data/download/uuid/$uuid/onlineappid/{$row['id']}'>请点击这里进入下载页面</a>
|
||
<script>self.location='/data/download/uuid/$uuid/onlineappid/{$row['id']}'</script>";
|
||
exit();
|
||
}
|
||
else {
|
||
echo $form.'<script>alert("服务器忙,请重试")</script>';
|
||
exit();
|
||
}
|
||
|
||
}else if( $ft==1 )
|
||
{
|
||
$testsql="select * from onlineapp where userid='$userid' and uuid='$uuid' order by id desc";
|
||
$result=$this->db->query($testsql);
|
||
$rows = $result->fetch();
|
||
if (empty($rows['id']))
|
||
{
|
||
$sql="select * from users where id='$userid'";
|
||
$result=$this->db->query($sql);
|
||
$rows = $result->fetch();
|
||
|
||
$datas['username'] = $rows['realname'];
|
||
$datas['unit'] = $rows['unit'];
|
||
$datas['phone'] = $rows['phone'];
|
||
$datas['address'] = $rows['address'];
|
||
//$datas['postcode'] = $rows['postcode'];
|
||
$datas['email'] = $rows['email'];
|
||
$datas['project'] = $rows['project'];
|
||
|
||
echo $this->creatform($datas);
|
||
exit();
|
||
}
|
||
else
|
||
{
|
||
$datas['username'] = $rows['username'];
|
||
$datas['unit'] = $rows['unit'];
|
||
$datas['phone'] = $rows['phone'];
|
||
$datas['address'] = $rows['address'];
|
||
$datas['postcode'] = $rows['postcode'];
|
||
$datas['email'] = $rows['email'];
|
||
$datas['project'] = $rows['project'];
|
||
|
||
echo $this->creatform($datas);
|
||
exit();
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
/*
|
||
* 数据下载,根据UUID进行判断
|
||
* 一次只下载一个数据(一个元数据项)
|
||
*/
|
||
function downloadAction()
|
||
{
|
||
$uuid=$this->_request->getParam('uuid');
|
||
$onlineappid=$this->_request->getParam('onlineappid');
|
||
|
||
if (empty($uuid)) $this->_redirect('/data');
|
||
$userid=Zend_Auth::getInstance()->getIdentity()->id;
|
||
$testsql="select id from onlineapp where userid='$userid' and uuid='$uuid' order by id desc";
|
||
$result=$this->db->query($testsql);
|
||
$rows = $result->fetch();
|
||
if (empty($rows['id']))
|
||
{
|
||
$this->_redirect('/data/'.$uuid);
|
||
}
|
||
else
|
||
{
|
||
$sql="select onlineappid,id from dataorder where userid='$userid' and uuid='$uuid' order by id desc";
|
||
$re=$this->db->query($sql);
|
||
$row=$re->fetch();
|
||
if(empty($row['onlineappid']))
|
||
{
|
||
$data = array(
|
||
'userid' => $userid,
|
||
'uuid' => $uuid,
|
||
'onlineappid'=> $onlineappid,
|
||
);
|
||
try {$this->db->insert('dataorder',$data);} catch (Exception $e) {}
|
||
}else
|
||
{
|
||
$sql="update dataorder set onlineappid='$onlineappid' where id='{$row['id']}'";
|
||
try {$this->db->exec($sql);} catch (Exception $e) {}
|
||
}
|
||
}
|
||
$this->view->username='westdc'.Zend_Auth::getInstance()->getIdentity()->id;
|
||
$sql=$this->db->quoteInto("select o.* from onlineresource o left join metadata m on o.uuid=m.uuid where m.datatype=0 and m.uuid=?",$uuid);
|
||
$rows=$this->db->fetchAll($sql);
|
||
$updateftp=$updateftp1=false;
|
||
$sql=$this->db->quoteInto("select * from metadata where uuid=?",$uuid);
|
||
$this->view->md=$this->db->fetchRow($sql);
|
||
$bigfile=($this->view->md['filesize']>5);
|
||
$this->view->userpass=md5('westdc'.rand(1000,9999));
|
||
$this->view->ftptime=date('Y-m-d H:i:s', strtotime('+1 week'));
|
||
$sql=$this->db->quoteInto("select * from ftpuser where userid=?",$userid);
|
||
$row=$this->db->fetchRow($sql);
|
||
$datacount=$row['datacount'];
|
||
foreach ($rows as $row) {
|
||
$url=$row['linkage'];
|
||
$p=parse_url($url);
|
||
if ($p['scheme']=='ftp')
|
||
//if ($row['protocol']=="WWW:DOWNLOAD-1.0-ftp--download")
|
||
{
|
||
//判断FTP URL是否附带了用户名和密码
|
||
if ($p['host']=='ftp.westgis.ac.cn')
|
||
$url='ftp://'.$this->view->config->ftp->user.':'.$this->view->config->ftp->password.'@ftp.westgis.ac.cn'.$p['path'];
|
||
if (!$bigfile &&is_file($url) && file_exists($url))
|
||
{
|
||
$this->_helper->layout->disableLayout();
|
||
$this->_helper->viewRenderer->setNoRender();
|
||
$content=file_get_contents($url);
|
||
$this->getResponse()->setHeader('Content-Type', 'application/octet-stream')
|
||
->setHeader('Content-Disposition','attachment; filename="'.basename($url).'"')
|
||
->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);
|
||
} else {
|
||
//是一个FTP,返回用户名称和密码说明
|
||
if ($p['host']=='ftp.westgis.ac.cn')
|
||
{
|
||
//添加FTP帐号信息以及时间控制信息,只更新一次
|
||
$updateftp=true;
|
||
$g6=new G6ftp();
|
||
$g6->db=$this->db;
|
||
//不进行判断,每个元数据中的下载地址都对应一个虚拟路径
|
||
//if (is_file($url)) $path=dirname($p['path']); else $path[]=$p['path'];
|
||
$path[]=$p['path'];
|
||
$uu=(object)array("id"=>$userid,
|
||
"username"=>$this->view->username,
|
||
"password"=>$this->view->userpass,
|
||
"path"=>$path,
|
||
"maxdata"=>$this->view->config->download->max,
|
||
"time"=>$this->view->ftptime,
|
||
"datacount"=>$datacount);
|
||
if ($g6->createuser($uu)) {
|
||
$this->view->userpass=$g6->pwd;
|
||
$this->view->ftptime=$g6->time;
|
||
} else {
|
||
$this->messenger->addMessage('错误:您正在进行下载的在线数据数已经超过系统允许的最大值,请在下面点击“完成”或“取消”对应的在线数据下载!');
|
||
$this->_redirect('/data/order');
|
||
}
|
||
} elseif (!$updateftp1 && $p['host']=='ftp1.westgis.ac.cn')
|
||
{
|
||
//添加FTP1帐号信息以及时间控制信息,只更新一次
|
||
$updateftp1=true;
|
||
}
|
||
if ($p['host']=='ftp.westgis.ac.cn')
|
||
{
|
||
//更新URL
|
||
$ftpurls[]='ftp://'.$this->view->username.'@ftp.westgis.ac.cn'.$p['path'];
|
||
} elseif ($p['host']=='ftp1.westgis.ac.cn')
|
||
$ftpurls[]='ftp://ftp1.westgis.ac.cn'.$p['path'];
|
||
else
|
||
$ftpurls[]=$url;
|
||
}
|
||
} else {
|
||
//若不清楚协议,只是列出来?
|
||
$links[]=$row;
|
||
}
|
||
}
|
||
//设置输出
|
||
//if ($updateftp || $updateftp1) $this->view->userpass=$password;
|
||
@$this->view->ftpurls=$ftpurls;
|
||
@$this->view->links=$links;
|
||
//更新下载记录
|
||
//todo: 尝试添加一个RULE:若有对应数据存在,则不插入( userid,uuid,status=0,ts_approved:null)
|
||
$sql="select * from dataorder where userid=? and uuid=? and status=0 and (ts_approved is null)";
|
||
$u=$this->db->fetchRow($sql,array($userid,$uuid));
|
||
if (empty($u)) {
|
||
$sql="insert into dataorder (userid,uuid,ts_created) values(?,?,now())";
|
||
$this->db->query($sql,array($userid,$uuid));
|
||
}
|
||
}
|
||
/*
|
||
* 离线申请(可以包括在线数据),在无数据参数时,则显示已有列表
|
||
*/
|
||
function orderAction()
|
||
{
|
||
$uuid=$this->_request->getParam('uuid');
|
||
$del = $this->_request->getParam('del');
|
||
$apply = $this->_request->getParam('apply');
|
||
$finish = $this->_request->getParam('finish');
|
||
$cancel = $this->_request->getParam('cancel');
|
||
$pdf = $this->_request->getParam('pdf');
|
||
//if (empty($uuid)) $this->_redirect('/data');
|
||
$userid=Zend_Auth::getInstance()->getIdentity()->id;
|
||
if ($uuid)
|
||
{
|
||
//处理数据入库
|
||
//离线申请的数据不应该重复,因此需要在数据库限制?还是在WEB端限制?
|
||
//在数据库中控制,只保证uuid,userid,status唯一就可以?
|
||
//存在历史遗留问题,原来的数据并不能保证唯一
|
||
//status: 1 开始进入离线申请申请程序中
|
||
// 2 填写并提交离线申请表
|
||
// 3 邮寄离线申请表
|
||
// 4 收到离线申请表
|
||
// 5 处理离线申请表
|
||
// 10:离线申请完成?
|
||
// -1: 取消了在线下载进程
|
||
//首先判断离线申请的数据数量是否超过系统限制
|
||
$sql="select count(*) as datacount from dataorder where (ts_approved is null) and userid=? and status>0 and status<5";
|
||
$r=$this->db->fetchRow($sql,array($userid));
|
||
//保证添加的离线数据申请未申请
|
||
$sql="select count(*) as datacount from dataorder where (ts_approved is null) and userid=? and uuid=? and status=1";
|
||
$r1=$this->db->fetchRow($sql,array($userid,$uuid));
|
||
if ($r['datacount']<$this->view->config->download->max && $r1['datacount']<1) {
|
||
$sql="insert into dataorder (uuid,ts_created,userid,status) values(?,now(),?,?)";
|
||
$this->db->query($sql,array($uuid,$userid,1));
|
||
//成功信息提示
|
||
$sql=$this->db->quoteInto("select title,uuid from metadata where uuid=?",$uuid);
|
||
$this->view->md=$this->db->fetchRow($sql);
|
||
} else {
|
||
if ($r1['datacount']>=1)
|
||
$this->view->msg="错误:您申请的数据已经在数据蓝中!";
|
||
else
|
||
$this->view->msg="错误:您正在进行的离线申请的数据数已经超过系统允许的最大值,请在完成本次离线申请后再进行操作!";
|
||
}
|
||
} elseif ($del) {
|
||
//删除数据申请
|
||
$sql=$this->db->quoteInto("delete from dataorder where id=?",$del);
|
||
$this->db->query($sql);
|
||
$this->_redirect('/data/order');
|
||
} elseif ($apply) {
|
||
if ($apply=='all') {
|
||
$sql=$this->db->quoteInto("update dataorder set status=2 where status=1 and userid=?",$userid);
|
||
$this->db->query($sql);
|
||
} else {
|
||
$sql="update dataorder set status=2 where status=1 and userid=? and id=?";
|
||
$this->db->query($sql,array($userid,(int)$apply));
|
||
}
|
||
} elseif ($finish) {
|
||
if ($finish=='all') {
|
||
$sql=$this->db->quoteInto("update dataorder set ts_approved=now() where status=0 and userid=?",$userid);
|
||
$this->db->query($sql);
|
||
$sql="update ftpuser set datacount=0 where userid=?";
|
||
$this->db->query($sql,array($userid));
|
||
} else {
|
||
$sql="update dataorder set ts_approved=now() where status=0 and userid=? and id=?";
|
||
$this->db->query($sql,array($userid,(int)$finish));
|
||
$sql="update ftpuser set datacount=datacount-1 where userid=?";
|
||
$this->db->query($sql,array($userid));
|
||
}
|
||
} elseif ($cancel) {
|
||
if ($cancel=='all') {
|
||
$sql=$this->db->quoteInto("update dataorder set ts_approved=now(),status=-1 where status=0 and userid=?",$userid);
|
||
$this->db->query($sql);
|
||
$sql="update ftpuser set datacount=0 where userid=?";
|
||
$this->db->query($sql,array($userid));
|
||
} else {
|
||
$sql="update dataorder set ts_approved=now(),status=-1 where status=0 and userid=? and id=?";
|
||
$this->db->query($sql,array($userid,(int)$cancel));
|
||
$sql="update ftpuser set datacount=datacount-1 where userid=?";
|
||
$this->db->query($sql,array($userid));
|
||
}
|
||
} elseif ($pdf) {
|
||
//生成PDF离线申请文件
|
||
//用户信息可以从SESSION中读取?离线申请信息
|
||
//$sql="select * from users where id=?";
|
||
$sql="select m.title||'('||m.filesize::text||'MB)' as title from dataorder d left join metadata m on d.uuid=m.uuid where d.status=2 and d.userid=? order by d.ts_created desc";
|
||
$rows=$this->db->fetchAll($sql,array($userid));
|
||
if ($rows) {
|
||
$this->view->data2=$rows;
|
||
$this->view->form=new OfflinePdfForm();
|
||
|
||
$this->_helper->viewRenderer('pdf');
|
||
if ($this->_request->isPost()) {
|
||
$formData = $this->_request->getPost();
|
||
$datalist='';
|
||
foreach($rows as $i=>$row) $datalist.=($i+1).". ".$row['title'].";";
|
||
$formData['datalist']=$datalist;
|
||
if ($this->view->form->isValid($formData)) {
|
||
if (@$formData['save']) {
|
||
//保存
|
||
//根据pdflink字段,以判断是否已经提交
|
||
//在数据库中创建rules,在更新offlineapp表时同时更新users表中对应的信息
|
||
$sql="select id from offlineapp where userid=? and (pdflink is null or pdflink='') and (ts_approved is null)";
|
||
$row=$this->db->fetchRow($sql,array($userid));
|
||
if ($row) {
|
||
$sql="update offlineapp set username=?,email=?,phone=?,address=?,postcode=?,project=?,unit=?,datalist=?,ts_created=now() where id=?";
|
||
$this->db->query($sql,array($formData['realname'],$formData['email'],$formData['phone'],$formData['address'],$formData['postcode'],$formData['project'],$formData['unit'],$datalist,$row['id']));
|
||
} else {
|
||
$sql="insert into offlineapp (userid,username,email,phone,address,postcode,project,unit,datalist) values(?,?,?,?,?,?,?,?,?)";
|
||
$this->db->query($sql,array($userid,$formData['realname'],$formData['email'],$formData['phone'],$formData['address'],$formData['postcode'],$formData['project'],$formData['unit'],$datalist));
|
||
}
|
||
$this->_helper->layout->disableLayout();
|
||
$this->_helper->viewRenderer->setNoRender();
|
||
//生成PDF
|
||
$pdf = new ApplicantPDF();
|
||
$pdf->template=$this->view->config->offline->template;
|
||
$pdf->data = $formData;
|
||
$pdf->drawWestdc();
|
||
header("Content-Disposition: inline; filename=westdc-data-apply.pdf");
|
||
header("Content-Type:application/pdf");
|
||
//header("Content-Length: " . strlen($pdfstring));
|
||
echo $pdf->Output('westdc-data-apply.pdf','S');
|
||
die();
|
||
//exit;
|
||
} elseif ($formData['submit']) {
|
||
//提交
|
||
//生成PDF
|
||
$pdf = new ApplicantPDF();
|
||
$pdf->template=$this->view->config->offline->template;
|
||
$pdf->data = $formData;
|
||
$pdf->drawWestdc();
|
||
|
||
$fn=$formData['realname'].date('YmdHis').".pdf";
|
||
$pdf->Output($this->view->config->offline->savepath."/".$fn, 'F');
|
||
|
||
//保存到数据库
|
||
$sql="select id from offlineapp where userid=? and pdflink is null and (ts_approved is null)";
|
||
$row=$this->db->fetchRow($sql,array($userid));
|
||
if ($row) {
|
||
$sql="update offlineapp set username=?,email=?,phone=?,address=?,postcode=?,project=?,unit=?,datalist=?,ts_created=now(),pdflink=? where id=?";
|
||
$this->db->query($sql,array($formData['realname'],$formData['email'],$formData['phone'],$formData['address'],$formData['postcode'],$formData['project'],$formData['unit'],$datalist,$fn,$row['id']));
|
||
} else {
|
||
$sql="insert into offlineapp (userid,username,email,phone,address,postcode,project,unit,datalist,pdflink) values(?,?,?,?,?,?,?,?,?,?)";
|
||
$this->db->query($sql,array($userid,$formData['realname'],$formData['email'],$formData['phone'],$formData['address'],$formData['postcode'],$formData['project'],$formData['unit'],$datalist,$fn));
|
||
$sql="select id from offlineapp where userid=? and pdflink=?";
|
||
$row=$this->db->fetchRow($sql,array($userid,$fn));
|
||
}
|
||
$sql="update dataorder set status=3, offlineappid=? where status=2 and userid=?";
|
||
$this->db->query($sql,array($row['id'],$userid));
|
||
|
||
//发送用户邮件进行信息提示和说明
|
||
//$mail = new Zend_Mail('utf-8');
|
||
$mail = new WestdcMailer($this->view->config->smtp);
|
||
$body=file_get_contents($this->view->config->offline->email->template);
|
||
$body=str_replace("[username]",$formData['realname'],$body);
|
||
$body=str_replace("[datalist]",str_replace(";","\n",$datalist),$body);
|
||
$mail->setBodyText($body);
|
||
$mail->addTo($formData['email']);
|
||
$mail->setSubject('您在西部数据中心进行的离线申请');
|
||
$mail->setFrom($this->view->config->service->email,'西部数据中心服务组');
|
||
$attach=$mail->createAttachment($pdf->Output('applicant','S'));
|
||
$attach->filename='数据申请-'.$formData['realname'].'.pdf';
|
||
$mail->send();
|
||
|
||
//跳转到/data/order,并提示帮助信息,告知用户已经发送EMAIL
|
||
$this->messenger->addMessage('提示信息:您的离线申请已经提交,系统已经发送一封邮件给您,请打印出申请表并签字后邮寄给西部数据中心服务组,具体信息请参考邮件说明。');
|
||
$this->_redirect('/data/order');
|
||
}
|
||
}
|
||
} else {
|
||
$sql="select u.*,o.postcode from users u left join offlineapp o on u.id=o.userid where u.id=?";
|
||
$row=$this->db->fetchRow($sql,array($userid));
|
||
/*$row=$ut->fetchRow('id='.$userid);
|
||
$formData['email']=$row->email;
|
||
$formData['phone']=$row->phone;
|
||
$formData['realname']=$row->realname;
|
||
$formData['unit']=$row->unit;
|
||
$formData['address']=$row->address;
|
||
$formData['purpose']=$row->project;
|
||
$formData['id']=$row->id;*/
|
||
$this->view->form->populate($row);
|
||
}
|
||
} else
|
||
$this->view->msg="错误:您还没有提交任何离线申请的数据,或您的数据申请已经正式提交(等待处理过程中)!";
|
||
}
|
||
//显示已经申请的数据,包括已经提交的申请和未提交的申请,还有已经处理完成的申请,正在进行的在线数据下载
|
||
$sql="select d.*,m.title,m.datatype from dataorder d left join metadata m on d.uuid=m.uuid where (d.status>0 or (d.status=0 and (d.ts_approved is null))) and d.userid=? order by d.status,d.ts_created desc";
|
||
$rows=$this->db->fetchAll($sql,array($userid));
|
||
foreach($rows as $row) {
|
||
switch ($row['status']){
|
||
case 0:
|
||
$dataorder0[]=$row;
|
||
break;
|
||
case 1:
|
||
$dataorder1[]=$row;
|
||
break;
|
||
case 2:
|
||
case 3:
|
||
case 4:
|
||
$dataorder2[]=$row;
|
||
break;
|
||
case 5:
|
||
$dataorder3[]=$row;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
@$this->view->dataorder0=$dataorder0;
|
||
@$this->view->dataorder1=$dataorder1;
|
||
@$this->view->dataorder2=$dataorder2;
|
||
@$this->view->dataorder3=$dataorder3;
|
||
}
|
||
/*
|
||
* 查看数据缩略图
|
||
*/
|
||
function thumbAction()
|
||
{
|
||
$id = (int)$this->_request->getParam('id');
|
||
if ($id>0) {
|
||
$md=new ThumbnailTable();
|
||
$thumb=$md->fetchRow('id='.$id);
|
||
$this->_helper->layout->disableLayout();
|
||
$this->_helper->viewRenderer->setNoRender();
|
||
if (empty($thumb->data)) {
|
||
header("Content-Type:image/png");
|
||
header("Content-Length: " . filesize("images/nothumb.png"));
|
||
$file=fopen("images/nothumb.png",'r');
|
||
fpassthru($file);
|
||
exit;
|
||
} else {
|
||
header("Content-Type:image/".$thumb->filetype);
|
||
print base64_decode($thumb->data);
|
||
}
|
||
}
|
||
}
|
||
|
||
/*
|
||
*附件下载
|
||
*/
|
||
function attachAction(){
|
||
|
||
$uuid = $this->_request->getParam('uuid');
|
||
|
||
if(!empty($uuid))
|
||
{
|
||
|
||
$sql="select * from mdattach m left join attachments a on m.id=a.id where m.uuid='$uuid'";
|
||
$re=$this->db->query($sql);
|
||
$atts = $re->fetch();
|
||
|
||
if(empty($atts['id']))
|
||
{
|
||
$this->_redirect("/data/$uuid");
|
||
}//没有附件
|
||
|
||
$auth = Zend_Auth::getInstance();
|
||
if($auth->hasIdentity())
|
||
{
|
||
/*
|
||
$user = $auth->getIdentity();
|
||
$userid = $user->id;
|
||
$sql = "select d.* from dataorder d
|
||
left join users u on u.id=d.userid
|
||
left join metadata m on m.uuid=d.uuid
|
||
where (d.status=5 and d.userid='$userid' and d.uuid='$uuid') or u.usertype='administrator'";
|
||
$re= $this->db->query($sql);
|
||
$row=$re->fetch();
|
||
if(!empty($row['uuid']))
|
||
{
|
||
$this->messenger->addMessage('您没有权限下载该附件');
|
||
$this->_redirect("/data");
|
||
}
|
||
else
|
||
{*/
|
||
//由于涉及多个文件下载,所以将附件添加到zip压缩文件再输出
|
||
|
||
$sql="select * from mdattach m left join attachments a on m.id=a.id where m.uuid='$uuid'";
|
||
$re=$this->db->query($sql);
|
||
$atts = $re->fetchAll();
|
||
|
||
$zip = new ZipArchive();
|
||
$url=Zend_Registry::get('upload')."tmp/attachments_$uuid.zip";//创建临时文件
|
||
$opened=$zip->open($url, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
|
||
if( $opened !== true ){
|
||
die("cannot open {$url} for writing.");
|
||
}
|
||
|
||
$updates = array(); //统计被下载的附件ID
|
||
|
||
foreach ($atts as $k=>$v)
|
||
{
|
||
if (is_file(Zend_Registry::get('upload').$v['filename'])) {
|
||
$updates[]=$v['id'];
|
||
$zip->addFile(Zend_Registry::get('upload').$v['filename'],'/'.basename($v['filename']));
|
||
}
|
||
}
|
||
$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->_helper->layout->disableLayout();
|
||
$this->_helper->viewRenderer->setNoRender();
|
||
$this->getResponse()->setHeader('Content-Type', 'application/octet-stream')
|
||
->setHeader('Content-Disposition','attachment; filename="'.basename($url).'"')
|
||
->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);
|
||
// }
|
||
}//end if
|
||
else
|
||
{
|
||
$this->messenger->addMessage('您没有权限下载该附件');
|
||
$this->_redirect("/data/$uuid");
|
||
}//未登陆
|
||
}//end if
|
||
else
|
||
{
|
||
$this->messenger->addMessage('您没有权限下载该附件');
|
||
$this->_redirect("/data/$uuid");
|
||
}//无权限
|
||
|
||
}
|
||
|
||
|
||
/*
|
||
* 西部计划项目及其数据产出
|
||
*/
|
||
public function westeeAction()
|
||
{
|
||
//$sql="select w.*,m.uuid from westee w left join westeemd m on w.id=m.eeid order by w.id";
|
||
$sql="select * from westee order by id";
|
||
$this->view->westee=$this->db->fetchAll($sql);
|
||
$sql="select w.eeid,m.title,m.uuid from westeemd w left join metadata m on w.uuid=m.uuid order by w.eeid";
|
||
$this->view->westeemd=$this->db->fetchAll($sql);
|
||
}
|
||
|
||
public function pingbackAction()
|
||
{
|
||
$this->_helper->ViewRenderer->setNoRender();
|
||
$this->_helper->layout->disableLayout();
|
||
$server = new Zend_XmlRpc_Server();
|
||
$server->setClass('PingbackRpc', 'pingback');
|
||
echo $server->handle();
|
||
}
|
||
|
||
public function pingtestAction()
|
||
{
|
||
$this->_helper->ViewRenderer->setNoRender();
|
||
$this->_helper->layout->disableLayout();
|
||
$client = new Zend_XmlRpc_Client('http://test.westgis.ac.cn/data/pingback');
|
||
$arg1 = 'http://wlx.westgis.ac.cn/567/';
|
||
$arg2 = 'http://test.westgis.ac.cn/data/487591d0-d437-4114-b810-cbef7c4ee4b2';
|
||
//$result = $client->call('pingback.ping', array($arg1, $arg2));
|
||
$test = $client->getProxy('pingback');
|
||
$test->ping($arg1,$arg2);
|
||
//var_dump($result);
|
||
}
|
||
public function outputAction()
|
||
{
|
||
$this->_helper->layout->disableLayout();
|
||
$this->_helper->viewRenderer->setNoRender();
|
||
$sql="select title,datatype,filesize,id from metadata";
|
||
$md=$this->db->fetchAll($sql);
|
||
foreach($md as $m)
|
||
{
|
||
print $m["title"].",";
|
||
print ($m["datatype"]?"内部":"公开").",";
|
||
print ($m["filesize"]==1?" ":$m["filesize"]).",";
|
||
$sql1="select keyword from keyword where id=".$m["id"]." and keytype='place'";
|
||
$kd=$this->db->fetchAll($sql1);
|
||
foreach ($kd as $p) print $p["keyword"]." ";
|
||
print ",";
|
||
$sql1="select keyword from keyword where id=".$m["id"]." and keytype='temporal'";
|
||
$kd=$this->db->fetchAll($sql1);
|
||
foreach ($kd as $p) print $p["keyword"]." ";
|
||
print ",";
|
||
print "<br>";
|
||
}
|
||
|
||
}
|
||
/*
|
||
* 转换元数据为WORD DOC格式
|
||
*/
|
||
public function docAction()
|
||
{
|
||
$this->_helper->layout->disableLayout();
|
||
$this->_helper->viewRenderer->setNoRender();
|
||
$uuid=$this->_request->getParam('uuid');
|
||
$review=$this->_request->getParam('review');
|
||
if (!empty($uuid))
|
||
{
|
||
$sql="select x.data,m.title,m.description,g.id,m.projection from xml x left join metadata m on m.id=x.id 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='<ol>';
|
||
foreach($ref as $refer)
|
||
{
|
||
$reference.='<li>'.$refer['reference'].'</li>';
|
||
}
|
||
$reference.='</ol>';
|
||
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)) $projection=$row['projection'];
|
||
} else
|
||
$projection='';
|
||
|
||
$dom = new DOMDocument();
|
||
$dom->loadXML($row['data']);
|
||
//提前对表格进行预处理
|
||
$wiki=new WikiFormat();
|
||
$abs=$wiki->parseTable($this->view->escape($row["description"]));
|
||
//处理外部链接
|
||
$abs=preg_replace('/\[\s*(http:\/\/.+?)\s+(.*?)\]/m','<a href="$1">$2</a>',$abs);
|
||
$abs=str_replace(array("\r\n", "\n", "\r"),'</p><p>',$abs);
|
||
$abs=str_replace("'","'",$abs);//not needed?
|
||
$id = $row['id'];
|
||
$thumburl=sprintf('%05d',floor(($id+0.1)/100)*100).'-'.sprintf('%05d',ceil(($id+0.1)/100)*100-1)."/".$id;
|
||
$xslt = new XSLTProcessor();
|
||
$xslt->registerPHPFunctions();
|
||
$xslt->setParameter('', 'thumburl', $thumburl);
|
||
$xslt->setParameter('', 'abstract', $abs);
|
||
$xslt->setParameter('','projection',$projection);
|
||
$xslt->setParameter('','reference',$reference);
|
||
$XSL = new DOMDocument();
|
||
$XSL->load( '../data/doc.xsl', LIBXML_NOCDATA);
|
||
$xslt->importStylesheet($XSL);
|
||
$content='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
|
||
$content.='<title>'.$row['title'].'</title>';
|
||
$content.='<style>
|
||
body{MARGIN-RIGHT: auto;MARGIN-LEFT: auto;font-size:14px;line-height:22px;font-family:宋体,Arial;}
|
||
span{font-size:14px;}
|
||
div{clear: both;margin: 0 auto;width:100%;vertical-align:baseline;}
|
||
#uuid{text-align: right;}
|
||
h3{font-size: 18px;}
|
||
img {border:0 none;}
|
||
a, a:visited {color:Blue;text-decoration:none;}
|
||
a:hover{text-decoration:underline;}
|
||
ul{list-style: none;margin: 0;}
|
||
ul li{list-style:none;}
|
||
#etitle{font-size:16px;margin-left:10px;}
|
||
span{font-weight:bolder;}
|
||
#content{padding:5px 0 10px 0;border:1px solid #BF5008;}
|
||
#divFooter {background-color:#BF5008;color:White;font-size:12px;padding:5px 15px;}
|
||
#divFooter a:link, #divFooter a:visited, #divFooter a:active {color:White;font-family:Arial,Serif;text-decoration:none;}
|
||
</style>
|
||
</head>
|
||
<body>';
|
||
$content.=$xslt->transformToXML($dom);
|
||
if ($review==1) $content.=file_get_contents('../data/review-table.htm',true);
|
||
$content.="</body></html>";
|
||
$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);
|
||
}
|
||
}
|
||
|