From 83fb46f8d7e67d9badd34ba76a4013a52e79751a Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Mon, 19 Sep 2011 09:33:50 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=96=87=E7=8C=AE=E5=85=B3=E8=81=94=E7=AE=A1=E7=90=86=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E6=90=9C=E7=B4=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controllers/DataController.php | 1639 +++++++++-------- .../admin/views/scripts/data/left.phtml | 23 +- .../admin/views/scripts/data/reference.phtml | 108 +- 3 files changed, 909 insertions(+), 861 deletions(-) diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index c255e79a..7bcf01d2 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -1,805 +1,834 @@ -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同步 - $sql="select uuid,data from geonetworkmetadata where schemaid='iso19115'"; - $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) ) { - //首先删除所有的黑河试验数据 - $sql="delete from metadata where source='0595169a-279e-4b95-819f-129d0ba4280d'"; - $this->db->query($sql); - $sql="delete from responsible where id not in (select distinct(resid) from role)"; - $this->db->query($sql); - //同步黑河遥感实验的元数据 - $sql="select uuid,data,source from watergn where schemaid='iso19115'"; - $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 (!empty($uuid) && isset($_POST['submit'])) { - //同步单条元数据 - $sql=$this->db->quoteInto("select data from geonetworkmetadata where uuid=?",$uuid); - if ($rs=$this->db->fetchRow($sql)) { - $this->import($rs->data); - $this->view->msg='成功同步元数据:'.$uuid; - } else $this->view->msg='不存在此元数据:'.$uuid; - } elseif (!empty($uuid) && isset($_POST['watersubmit'])) { - //同步单条元数据 - $sql=$this->db->quoteInto("select data from watergn where uuid=?",$uuid); - if ($rs=$this->db->fetchRow($sql)) { - $this->import($rs->data); - $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中多出的元数据!'; - } 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') { - $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"; - $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') { - $sql="select id,username,password,email from users where usertype='administrator'"; - $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) { - $sql="update geonetworkusers set username='$row->username',password='$row->password',email='$row->email' where id=$row->id"; - $this->db->query($sql); - } else { - $sql="insert into geonetworkusers (id,username,password,email) values($row->id,'$row->username','$row->password','$row->email')"; - $this->db->query($sql); - } - } - $this->view->msg='已成功同步管理员帐号!'; - } - } - - 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'); - 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"); - } elseif ($down) { - $zip = new ZipArchive(); - $url="/tmp/xml.zip"; - $opened=$zip->open($url, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE); - if( $opened !== true ){ - die("cannot open {$url} for writing."); - } - $dirName = '../data/import/'; - $zip->addEmptyDir("xml/"); - - $filesToAdd = array(); - $dir = dir($dirName); - while (false !== ($node = $dir->read())) { - if (($node == '..') || ($node == '.')) { - continue; - } - if (is_file($dirName.$node)) { - $zip->addFile($dirName.$node,"xml/".$node); - } - } - $zip->close(); - $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); - } - $select=$this->db->select(); - $select->from('metadata') - ->joinLeft('mdstat','metadata.uuid=mdstat.uuid','viewed') - ->joinLeft('geonetworkmetadata','geonetworkmetadata.uuid=metadata.uuid','id as gid') - ->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'); - $this->view->paginator=$paginator; - - } - 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'); - 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('提示信息:您已经成功添加该数据文献。'); - $this->_redirect('/admin/data/reference'); - }else { - $form->populate($formdata); - } - } else { - if ($uuid) - { - $formdata['uuid']=$uuid; - $form->populate($formdata); - } - } - $this->view->form=$form; - $this->_helper->viewRenderer('referenceadd'); - } elseif ($edit){ - $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->query($sql,array($formdata['reference'])); - if ($row) - { - //更新文献信息 - $sql="update reference set reference=?,link=? where id=?"; - $param=array($formdata['reference'],$formdata['link'],$edit); - $this->db->query($sql,$param); - } else { - //更新文献链接表 - $sql="update mdref set refid=? where uuid=? and refid=?"; - $this->db->query($sql,array($row['id'],$formdata['uuid'],$edit)); - } - $this->messenger->addMessage('提示信息:您已经编辑该数据文献。'); - $this->_redirect('/admin/data/reference'); - } 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'); - } elseif ($delete) { - $sql="delete from mdref where id=?"; - try { - $this->db->query($sql,array($delete)); - $this->messenger->addMessage('提示信息:您已经成功删除该数据文献。'); - } catch (Exception $e) { - $this->messenger->addMessage($e->getMessage()); - } - $this->_redirect("/admin/data/reference"); - } - $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; - } - /* - * 删除元数据,删除前有确认 - */ - 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 - $this->_redirect('/metadata'); - } 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;$idb->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."
"; - //print $dpath." ".count($dpatch)."
"; - for($j=0;$j"; - //$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='已成功处理数据目录信息!'; - } - } - /* - * 保存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) - { - $inds=explode(",",$au['individual']); - 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().'
'; - } - } -} - +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同步 + $sql="select uuid,data from geonetworkmetadata where schemaid='iso19115'"; + $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) ) { + //首先删除所有的黑河试验数据 + $sql="delete from metadata where source='0595169a-279e-4b95-819f-129d0ba4280d'"; + $this->db->query($sql); + $sql="delete from responsible where id not in (select distinct(resid) from role)"; + $this->db->query($sql); + //同步黑河遥感实验的元数据 + $sql="select uuid,data,source from watergn where schemaid='iso19115'"; + $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 (!empty($uuid) && isset($_POST['submit'])) { + //同步单条元数据 + $sql=$this->db->quoteInto("select data from geonetworkmetadata where uuid=?",$uuid); + if ($rs=$this->db->fetchRow($sql)) { + $this->import($rs->data); + $this->view->msg='成功同步元数据:'.$uuid; + } else $this->view->msg='不存在此元数据:'.$uuid; + } elseif (!empty($uuid) && isset($_POST['watersubmit'])) { + //同步单条元数据 + $sql=$this->db->quoteInto("select data from watergn where uuid=?",$uuid); + if ($rs=$this->db->fetchRow($sql)) { + $this->import($rs->data); + $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中多出的元数据!'; + } 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') { + $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"; + $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') { + $sql="select id,username,password,email from users where usertype='administrator'"; + $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) { + $sql="update geonetworkusers set username='$row->username',password='$row->password',email='$row->email' where id=$row->id"; + $this->db->query($sql); + } else { + $sql="insert into geonetworkusers (id,username,password,email) values($row->id,'$row->username','$row->password','$row->email')"; + $this->db->query($sql); + } + } + $this->view->msg='已成功同步管理员帐号!'; + } + } + + 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'); + 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"); + } elseif ($down) { + $zip = new ZipArchive(); + $url="/tmp/xml.zip"; + $opened=$zip->open($url, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE); + if( $opened !== true ){ + die("cannot open {$url} for writing."); + } + $dirName = '../data/import/'; + $zip->addEmptyDir("xml/"); + + $filesToAdd = array(); + $dir = dir($dirName); + while (false !== ($node = $dir->read())) { + if (($node == '..') || ($node == '.')) { + continue; + } + if (is_file($dirName.$node)) { + $zip->addFile($dirName.$node,"xml/".$node); + } + } + $zip->close(); + $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); + } + $select=$this->db->select(); + $select->from('metadata') + ->joinLeft('mdstat','metadata.uuid=mdstat.uuid','viewed') + ->joinLeft('geonetworkmetadata','geonetworkmetadata.uuid=metadata.uuid','id as gid') + ->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'); + $this->view->paginator=$paginator; + + } + 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'); + $keyword=$this->_getParam('keyword'); + + 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('提示信息:您已经成功添加该数据文献。'); + $this->_redirect('/admin/data/reference'); + }else { + $form->populate($formdata); + } + } else { + if ($uuid) + { + $formdata['uuid']=$uuid; + $form->populate($formdata); + } + } + $this->view->form=$form; + $this->_helper->viewRenderer('referenceadd'); + } elseif ($edit){ + $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->query($sql,array($formdata['reference'])); + if ($row) + { + //更新文献信息 + $sql="update reference set reference=?,link=? where id=?"; + $param=array($formdata['reference'],$formdata['link'],$edit); + $this->db->query($sql,$param); + } else { + //更新文献链接表 + $sql="update mdref set refid=? where uuid=? and refid=?"; + $this->db->query($sql,array($row['id'],$formdata['uuid'],$edit)); + } + $this->messenger->addMessage('提示信息:您已经编辑该数据文献。'); + $this->_redirect('/admin/data/reference'); + } 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'); + } elseif ($delete) { + $sql="delete from mdref where id=?"; + try { + $this->db->query($sql,array($delete)); + $this->messenger->addMessage('提示信息:您已经成功删除该数据文献。'); + } catch (Exception $e) { + $this->messenger->addMessage($e->getMessage()); + } + $this->_redirect("/admin/data/reference"); + } else if($search){ + 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"); + } + }else{ + $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; + + } + } + /* + * 删除元数据,删除前有确认 + */ + 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 + $this->_redirect('/metadata'); + } 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;$idb->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."
"; + //print $dpath." ".count($dpatch)."
"; + for($j=0;$j"; + //$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='已成功处理数据目录信息!'; + } + } + /* + * 保存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) + { + $inds=explode(",",$au['individual']); + 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().'
'; + } + } +} + diff --git a/application/admin/views/scripts/data/left.phtml b/application/admin/views/scripts/data/left.phtml index d46b2d03..f63d6abc 100644 --- a/application/admin/views/scripts/data/left.phtml +++ b/application/admin/views/scripts/data/left.phtml @@ -1,12 +1,13 @@ -'; - $i=0; - $u=$item['uuid']; - endif; - if ($i==0) echo ''; -?> - - +headTitle($this->config->title->site); + $this->headTitle('后台管理'); + $this->headTitle()->setSeparator(' - '); + $this->headLink()->appendStylesheet('/css/admin.css'); + $this->breadcrumb('首页'); + $this->breadcrumb('后台首页'); + $this->breadcrumb('数据管理'); + $this->breadcrumb('数据文献关联管理'); + $this->breadcrumb()->setSeparator(' > '); +?> +
+partial('data/left.phtml'); ?> +
+
+msg or $this->messages) :?> +
+msg) : ?> +

msg; ?>

+messages): foreach($this->messages as $msg): ?> +

+ +
+ + +
数据文献关联管理
+ + + + + +paginator)): ?> +
+paginator as $item): + if ($u==$item['uuid']) : + $i+=1; + else : + if (!empty($u)) echo ''; + $i=0; + $u=$item['uuid']; + endif; + if ($i==0) echo ''; +?> +
+ +paginator; ?>
\ No newline at end of file