diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index 2b292abd..7a80637b 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -1,2677 +1,2707 @@ -db=Zend_Registry::get('db'); - $this->view->config = Zend_Registry::get('config'); - $this->messenger=$this->_helper->getHelper('FlashMessenger'); - $this->view->messages = $this->messenger->getMessages(); - $this->debug = 0; //1:debug, 0:release - $this->debug_email='wangliangxu@lzb.ac.cn'; - $this->view->theme = new Theme(); - $this->_helper->layout->setLayout('administry'); - } - function postDispatch() - { - $this->view->messages = $this->messenger->getMessages(); - } - function indexAction() - { - //其他连接 - } - - /* - * - * mdAction() - * 元数据管理 - * - */ - function mdAction() - { - $delete=$this->_getParam('delete'); - $down=(int)$this->_getParam('down'); - $search = $this->_getParam('search'); - $keyword = $this->_getParam('keyword'); - $att=$this->_getParam('att'); - $attupdate = $this->_getParam('attupdate'); - - $submd=$this->view->config->sub->metadata; - - if ($delete) - { - $sql="delete from metadata where uuid=? and uuid in (select uuid from ".$this->view->config->sub->meatadata.")"; - try { - $this->db->query("delete from mdstatus where uuid=? and uuid in (select uuid from ".$this->view->config->sub->meatadata.")",array($delete)); - $this->db->query("delete from mdauthor where uuid=? and uuid in (select uuid from ".$this->view->config->sub->meatadata.")",array($delete)); - $this->db->query($sql,array($delete)); - $this->messenger->addMessage('提示信息:您已经成功删除该数据。'); - $search=new Search(); - $search->del($delete,'uuid'); - } catch (Exception $e) { - $this->messenger->addMessage($e->getMessage()); - } - $this->_redirect("/admin/data/md"); - }//删除 - - elseif($att>0){ - $submit=$this->_request->getParam('submit'); - $uuid=$this->_request->getParam('uuid'); - $atts=$this->_request->getParam('ids'); - $addatts=$this->_request->getParam('addatts'); - - $this->view->id = $att; - $this->view->uuid = $uuid; - - if(!empty($addatts)) - { - - if(empty($submit)) - { - $sql = "select title from metadata where uuid='$uuid'"; - $re = $this->db->query($sql); - $rows = $re->fetch(); - - - $this->view->id = $att; - $this->view->uuid = $uuid; - $this->view->mdtitle = $rows['title']; - $this->view->thisatt = $rows; - - $this->_redirect("/admin/data/attachments/uuid/$uuid/mdtitle/{$rows['title']}"); - } - else - { - if(!empty($uuid)) - { - foreach($atts as $v) - { - $sql = "insert into mdattach (uuid,id) values ('$uuid','$v')"; - try{ - $this->db->exec($sql); - $this->messenger->addMessage('成功添加附件:'.$v); - }catch (Exception $e) - { - $this->messenger->addMessage('添加附件失败:'.$v); - } - } - $this->_redirect("/admin/data/md/att/1/uuid/$uuid"); - } - } - }//empty($addatts) - else - { - if(!empty($uuid)) - { - - $sql = "select m.*,a.*,d.title from mdattach m - left join attachments a on m.id = a.id - left join metadata d on m.uuid=d.uuid where m.uuid='$uuid'"; - $re = $this->db->query($sql); - - $rows = $re->fetchAll(); - - $sql = "select title from metadata where uuid='$uuid'"; - $re = $this->db->query($sql); - $title = $re->fetch(); - - $this->view->atts=$rows; - $this->view->mdtitle = $title['title']; - - $this->_helper->viewRenderer('attmanager'); - } - - - } - - }//编辑附件 - - /* - * 输出打包下载的xml文件 - * - * 文件量大时可能出现超时,需要修改超时时间为无限 - */ - elseif ($down) { - - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - //临时zip文件名 - $tmpname="dataxml"; - - //xml文件存放的缓存目录 - $dirName = '../data/import/'; - - //查询需要创建的文件 - $sql = "SELECT md.title,md.uuid,x.* from xml x - LEFT JOIN $submd md ON md.id=x.id"; - - $sth = $this->db->prepare($sql); - $sth->execute(); - $rows = $sth->fetchAll(); //将结果储存,但不使用 - - //创建zip文件,创建成功后再使用查询结果 - $zip = new ZipArchive(); - $url = tempnam($this->config->temp->path,$tmpname);//创建临时文件 - - if( $zip->open($url, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true ) - { - throw new Exception("cannot open {$url} for writing."); - } - - foreach($rows as $k=>$v) - { - - $filename = $dirName.$v['uuid'].'.xml'; - - //创建xml文件 - $handle = fopen($filename,"w"); - fwrite($handle,$v['data']); - fclose($handle); - - //添加到zip文件 - //zip localname 直接使用UUID作为文件名 - $zip->addFile($filename,$v['uuid'].".xml"); - - } - $zip->close(); - - //zip文件创建完成后删除服务器上的缓存文件,防止发生冗余 - foreach($rows as $k=>$v) - { - $filename = $dirName.$v['uuid'].'.xml'; - unlink($filename); - } - - //输出下载 - $content=file_get_contents($url); - $this->getResponse()->setHeader('Content-Type', 'application/octet-stream') - ->setHeader('Content-Disposition','attachment; filename="dataxml.zip"') - ->setHeader('Content-Length', strlen($content)) - ->setHeader('Content-Type','application/force-download') - ->setHeader('Content-Type','application/download') - ->setHeader('Content-Type','application/zip') - ->setHeader('Content-Description','File Transfer') - ->setHeader('Content-Transfer-Encoding','binary') - ->setHeader('Expires',0) - ->setHeader('Cache-Control','must-revalidate, post-check=0, pre-check=0') - ->setHeader('Pragma','public') - ->setBody($content); - }//down - else if($search){ - - if(!empty($keyword)) - { - $sql = "select m.*,md.viewed,g.id as gid, ds.id as datasetid from $submd m - left join mdstat md on m.uuid=md.uuid - left join geonetworkmetadata g on g.uuid=m.uuid - left join dataset ds on m.uuid=ds.uuid - where m.title like '%$keyword%' - order by m.id desc - "; - - $re=$this->db->query($sql); - $row=$re->fetchAll(); - $paginator = Zend_Paginator::factory($row); - $paginator->setCurrentPageNumber($this->_getParam('page')); - $paginator->setItemCountPerPage($this->view->config->page->max); - $paginator->setView($this->view); - Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); - $this->view->paginator=$paginator; - $this->messenger->addMessage($keyword.' 的搜索结果'); - } - else - { - $this->messenger->addMessage('请输入搜索关键字'); - $this->_redirect("/admin/data/md"); - } - - }//search - else{ - - $sql = "SELECT md.*,s.viewed,g.id as gid,st.status as mdstatus,ds.id as datasetid FROM $submd md - LEFT JOIN mdstat s ON md.uuid=s.uuid - LEFT JOIN geonetworkmetadata g ON g.uuid=md.uuid - LEFT JOIN mdstatus st ON md.uuid=st.uuid - LEFT JOIN dataset ds ON md.uuid=ds.uuid - ORDER BY md.id DESC"; - $sth = $this->db->prepare($sql); - $sth->execute(); - $rows = $sth->fetchAll(); - - $paginator = Zend_Paginator::factory($rows); - $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; - } - - }//mdAction 元数据管理 - - /* - * datasetAction() - * 数据路径:即数据的物理主目录 - * - */ - function datasetAction() - { - - $ac = $this->_request->getParam('ac'); - - if($ac == "getdataset") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer('md-dataset'); - - $uuid = $this->_request->getParam('uuid'); - $sql = "SELECT * FROM dataset WHERE uuid=?"; - $sth = $this->db->prepare($sql); - $sth ->execute(array($uuid)); - $row = $sth->fetch(); - - $this->view->dataset = $row; - $this->view->uuid = $uuid; - } - - else if($ac == "update") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $uuid = $this->_request->getParam('uuid'); - $host = $this->_getParam('host'); - $path = $this->_getParam('path'); - - $sql = "UPDATE dataset SET host=?,path=? WHERE uuid=?"; - $sth = $this->db->prepare($sql); - $ds = $sth ->execute(array($host,$path,$uuid)); - if ($host=='ftp1.westgis.ac.cn') - { - file_get_contents("http://ftp1.westgis.ac.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); - } else if ($host=='ftp.sanjiangyuan.org.cn') - { - file_get_contents("http://ftp.sanjiangyuan.org.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); - } - - if($ds) - { - $data = array("ok"=>1); - $this->jsonexit($data); - return true; - }else{ - $data = array("error"=>"处理中出现错误"); - $this->jsonexit($data); - return true; - } - } - - else if($ac == "add") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $uuid = $this->_request->getParam('uuid'); - $host = $this->_getParam('host'); - $path = $this->_getParam('path'); - - $sql = "SELECT * FROM dataset WHERE uuid=?"; - $sth = $this->db->prepare($sql); - $sth ->execute(array($uuid)); - $row = $sth->fetch(); - if(!empty($row['id'])) - { - $data = array("error"=>"该数据已经有存档信息,不能重复添加"); - $this->jsonexit($data); - return true; - } - - $sql = "INSERT INTO dataset (uuid,host,path) VALUES (?,?,?)"; - $sth = $this->db->prepare($sql); - $ds = $sth ->execute(array($uuid,$host,$path)); - if ($host=='ftp1.westgis.ac.cn') - { - file_get_contents("http://ftp1.westgis.ac.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); - } else if ($host=='ftp.sanjiangyuan.org.cn') - { - file_get_contents("http://ftp.sanjiangyuan.org.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); - } - - if($ds) - { - $data = array("ok"=>1); - $this->jsonexit($data); - return true; - }else{ - $data = array("error"=>"处理中出现错误"); - $this->jsonexit($data); - return true; - } - } - else if ($ac=="import") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $uuid = $this->_request->getParam('uuid'); - $sql = "SELECT * FROM dataset WHERE uuid=?"; - $sth = $this->db->prepare($sql); - $sth ->execute(array($uuid)); - $row = $sth->fetch(); - - if ($row['host']=='ftp1.westgis.ac.cn') - { - file_get_contents("http://ftp1.westgis.ac.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); - echo '