diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index 555f26aa..b9eb09a5 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -58,18 +58,18 @@ class Admin_DataController extends Zend_Controller_Action $this->view->msg='成功同步黑河遥感综合实验元数据!'; } elseif ($source=="westdc" && empty($uuid) ) { //从westdc向geonetwork同步 - $sql="select m.uuid,m.source,x.data from metadata m left join xml x on m.id=x.id where m.uuid not in (select uuid from geonetworkmetadata)"; - $rs=$this->db->fetchAll($sql); - foreach($rs as $gmd) { - $sql="insert into geonetworkmetadata (uuid,source,data) values('".$gmd->uuid."','".$gmd->source."',".$this->db->quote($gmd->data).")"; - $this->db->exec($sql); - } - $sql="select m.uuid,m.source,x.data from metadata m left join xml x on m.id=x.id where m.uuid in (select uuid from geonetworkmetadata)"; - $rs=$this->db->fetchAll($sql); - foreach($rs as $gmd) { - $sql="update geonetworkmetadata set source='".$gmd->source."',data=".$this->db->quote($gmd->data)." where uuid='".$gmd->uuid."'"; - $this->db->exec($sql); - } + $sql="select m.uuid,m.source,x.data from metadata m left join xml x on m.id=x.id where m.uuid not in (select uuid from geonetworkmetadata)"; + $rs=$this->db->fetchAll($sql); + foreach($rs as $gmd) { + $sql="insert into geonetworkmetadata (uuid,source,data) values('".$gmd->uuid."','".$gmd->source."',".$this->db->quote($gmd->data).")"; + $this->db->exec($sql); + } + $sql="select m.uuid,m.source,x.data from metadata m left join xml x on m.id=x.id where m.uuid in (select uuid from geonetworkmetadata)"; + $rs=$this->db->fetchAll($sql); + foreach($rs as $gmd) { + $sql="update geonetworkmetadata set source='".$gmd->source."',data=".$this->db->quote($gmd->data)." where uuid='".$gmd->uuid."'"; + $this->db->exec($sql); + } $this->view->msg='成功同步WESTDC元数据到GEONETWORK!'; } elseif (!empty($uuid) && isset($_POST['submit'])) { //同步单条元数据 @@ -82,21 +82,21 @@ class Admin_DataController extends Zend_Controller_Action //同步单条元数据到geonetwork $sql=$this->db->quoteInto("select m.uuid,m.source,x.data,g.id from metadata m left join xml x on m.id=x.id left join geonetworkmetadata g on g.uuid=m.uuid where m.uuid=?",$uuid); if ($gmd=$this->db->fetchRow($sql)) { - if (!empty($gmd->id)) { - $sql="update geonetworkmetadata set source='".$gmd->source."',data=".$this->db->quote($gmd->data)." where uuid='".$gmd->uuid."'"; - } else { - $sql="insert into geonetworkmetadata (uuid,source,data) values('".$gmd->uuid."','".$gmd->source."',".$this->db->quote($gmd->data).")"; - } + if (!empty($gmd->id)) { + $sql="update geonetworkmetadata set source='".$gmd->source."',data=".$this->db->quote($gmd->data)." where uuid='".$gmd->uuid."'"; + } else { + $sql="insert into geonetworkmetadata (uuid,source,data) values('".$gmd->uuid."','".$gmd->source."',".$this->db->quote($gmd->data).")"; + } $this->db->exec($sql); $this->view->msg='成功同步元数据:'.$uuid; - } else $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; + } else $this->view->msg='不存在此元数据:'.$uuid; } elseif (!empty($uuid)) { //同步单条元数据 $sql=$this->db->quoteInto("select data from geonetworkmetadata where uuid=?",$uuid); @@ -700,7 +700,217 @@ class Admin_DataController extends Zend_Controller_Action } $this->view->msg='已成功处理数据目录信息!'; } - } + }//datafileimportAction + + + function sourceAction() + { + + $add=(int)$this->_getParam('add'); + $edit=(int)$this->_getParam('edit'); + $delete=(int)$this->_getParam('delete'); + $search=$this->_getParam('search'); + $keyword=$this->_getParam('keyword'); + + if ($add) { + + if(!empty($_POST['submit'])) + { + + } + + $this->_helper->viewRenderer('sourceadd'); + }// 添加项目来源 + + + }//function sourceAction + + + function attachmentsAction() + { + $submit = $this->_request->getParam('submit'); + $add = $this->_request->getParam('add'); + $search = $this->_request->getParam('search'); + $delete = $this->_request->getParam('delete'); + $edit = $this->_request->getParam('edit'); + $down = $this->_request->getParam('down'); + + if($add && empty($edit)) + { + if(empty($submit)) + $this->_helper->viewRenderer('attachmentsadd'); + else + { + $files=new files(); + $msg = $files -> upload(Zend_Registry::get('upload'),$_FILES['Filedata'],$_POST['dir']); + + if(empty($msg['error'])) + { + $filename = $msg['db_path']; + $filedesc = $this->_request->getParam('filedesc'); + $filetype = $this->_request->getParam('dir'); + + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $userid = $user->id; + $sql = "insert into attachments (filename,filetype,filedesc,userid) values ('$filename','$filetype','$filedesc','$userid')"; + if($this->db->exec($sql)>0) + { + $this->messenger->addMessage('附件上传成功!'); + $this->_redirect("/admin/data/attachments/add/1"); + } + } + else + { + $this->messenger->addMessage('读取用户信息出错'); + $this->_redirect("/admin/data/attachments/add/1"); + @unlink($filename); + } + }else + { + $this->messenger->addMessage('附件上传失败:'.$msg['error']); + $this->_redirect("/admin/data/attachments/add/1"); + @unlink($filename); + } + } + }//附件添加 + else if($delete) + { + + //需要删除文件,通过Zend_Registry::get('upload')获得上传文件的根目录 + + $basepath = Zend_Registry::get('upload'); + + //从数据库获取文件路径 + + $info = $this->getFileinfo($delete); + + $filepath = $basepath.$info['filename']; + + if(unlink($filepath)) + { + $sql = "delete from attachments where id='$delete'"; + if($this->db->exec($sql)>0) + { + $this->messenger->addMessage('删除文件成功'); + $this->_redirect("/admin/data/attachments/"); + } + } + else + { + $sql = "delete from attachments where id='$delete'"; + if($this->db->exec($sql)>0) + { + $this->messenger->addMessage('文件删除失败,仅删除数据库记录,请手动删除文件:'.$info['filename']); + $this->_redirect("/admin/data/attachments/"); + } + } + + }//删除 + + else if($edit>0) + { + + if(empty($submit)) + { + + $this->view->info = $this->getFileinfo($edit); + + $this->_helper->viewRenderer('attachmentsadd'); + + } + else + { + $filedesc = $this->_request->getParam('filedesc'); + + $sql="update attachments set filedesc='$filedesc' where id='$edit'"; + + if($this->db->exec($sql)>0) + { + $this->messenger->addMessage('编辑成功'); + $this->_redirect("/admin/data/attachments/edit/$edit"); + } + } + + }//编辑 + + else if($search && $search!='my') + { + $keyword = $this->_request->getParam('keyword'); + if(empty($keyword)) + { + $this->messenger->addMessage('请输入关键词'); + $this->_redirect("/admin/data/attachments/search/1"); + } + else + { + $sql="select * from attachments where filedesc like '%$keyword%'"; + $re = $this->db->query($sql); + $rows=$re->fetchAll(); + + $paginator = Zend_Paginator::factory($rows); + $paginator->setCurrentPageNumber($this->_getParam('page')); + $paginator->setItemCountPerPage(30); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); + $this->view->paginator=$paginator; + } + + }//搜索 + + else if($search && $search=='my') + { + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $userid = $user->id; + $sql="select * from attachments where userid='$userid'"; + $re= $this->db->query($sql); + $rows = $re->fetchAll(); + + $paginator = Zend_Paginator::factory($rows); + $paginator->setCurrentPageNumber($this->_getParam('page')); + $paginator->setItemCountPerPage(30); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml'); + $this->view->paginator=$paginator; + } + }//我的附件列表 + + else + { + $sql="select * from attachments"; + $re= $this->db->query($sql); + $rows = $re->fetchAll(); + + $paginator = Zend_Paginator::factory($rows); + $paginator->setCurrentPageNumber($this->_getParam('page')); + $paginator->setItemCountPerPage(30); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml'); + $this->view->paginator=$paginator; + }//所有附件 + + + + + }//attachments 附件 + + /* + 获得单个文件的信息 + return array row + */ + public function getFileinfo($id){ + $sql = "select * from attachments where id='$id'"; + $re= $this->db->query($sql); + $row= $re->fetch(); + return $row; + } + + /* * 保存XML数据到数据库 */