diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index b2b99d60..bdf5bc08 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -543,6 +543,567 @@ class Admin_DataController extends Zend_Controller_Action }//datasetAction存档管理 + /* + versionAction 版本管理 + */ + + public function versionAction(){ + + $ac = $this->_request->getParam('ac'); + $uuid = $this->_request->getParam('uuid'); + + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $u_id = $user->id; + } + + //查看单条数据的所有版本 + if (!empty($uuid) && empty($ac)) + { + //view the versions of the data + $sql = "SELECT md.title,md.uuid,v.ts_created,v.changelog,v.userid,v.id,u.username,u.realname FROM mdversion v + LEFT JOIN metadata md ON md.uuid=v.uuid + left join users u on v.userid=u.id + WHERE md.title IS NOT NULL AND v.uuid=? + order by v.ts_created desc + "; + $sth = $this->db->prepare($sql); + $sth->execute(array($uuid)); + $rows = $sth->fetchAll(); + @$this->view->mdtitle=$rows[0]['title']; + + $paginator = Zend_Paginator::factory($rows); + $paginator->setCurrentPageNumber($this->_getParam('page')); + $paginator->setItemCountPerPage(15); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); + $this->view->paginator=$paginator; + } + + //查看所有版本列表 + else if((empty($ac) && empty($uuid))|| $ac=='list') + { + $sql = "SELECT md.title,md.uuid,v.ts_created,v.changelog,v.userid,v.id,u.username,u.realname FROM mdversion v + LEFT JOIN metadata md ON md.uuid=v.uuid + left join users u on v.userid=u.id + WHERE md.title IS NOT NULL + order by v.ts_created desc + "; + $sth = $this->db->prepare($sql); + $sth->execute(); + $rows = $sth->fetchAll(); + + $paginator = Zend_Paginator::factory($rows); + $paginator->setCurrentPageNumber($this->_getParam('page')); + $paginator->setItemCountPerPage(15); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); + $this->view->paginator=$paginator; + } + + //按数据浏览 + else if($ac=="bydata") + { + $keywords = $this->_request->getParam('q'); + if(!empty($keywords)) + $this->view->q = $keywords; + $sql = "SELECT md.title,md.uuid,count(v.id) as c FROM mdversion v + LEFT JOIN metadata md ON md.uuid=v.uuid + WHERE md.title IS NOT NULL"; + if(!empty($keywords)) + { + $search=new Search($keywords); + $where=$search->sql_expr(array("md.title","md.description")); + $sql.=' and '.$where; + } + $sql.=" group by md.uuid,md.title"; + + $sth = $this->db->prepare($sql); + $sth->execute(); + $rows = $sth->fetchAll(); + + $paginator = Zend_Paginator::factory($rows); + $paginator->setCurrentPageNumber($this->_getParam('page')); + $paginator->setItemCountPerPage(10); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); + $this->view->paginator=$paginator; + + $this->_helper->viewRenderer('version-bydata'); + } + + + //删除某个版本 + else if($ac=="delete") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $data = ""; + + try{ + $id = $this->_request->getParam('id'); + if(empty($id) || !is_numeric($id)) + { + $data = array("error"=>"参数错误"); + $this->jsonexit($data); + return true; + } + + $sql = "DELETE FROM mdversion WHERE id=?"; + $sth = $this->db->prepare($sql); + $ex = $sth -> execute(array($id)); + + if($ex) + { + $data = array("deleted"=>$id, "error"=>"删除成功"); + $this->jsonexit($data); + return true; + }else{ + $data = array("error"=>'删除失败,请确认权限后重试'); + $this->jsonexit($data); + return true; + } + }catch(Exception $e) { + $msg = "删除失败,请确认权限后重试"; + if($this->debug>0) + {$msg .= $e->getMessage();} + $data = array("error"=>$msg); + $this->jsonexit($data); + return true; + } + } + + //恢复到geonetwork + else if($ac == "restore") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $data = ""; + try{ + $id = $this->_request->getParam('id'); + if(empty($id) || !is_numeric($id)) + { + $data = array("error"=>"参数错误"); + $this->jsonexit($data); + return true; + } + + $this->wdb=Zend_Db::factory($this->view->config->geonetwork); + $sql = "SELECT v.xml,v.uuid FROM mdversion v + WHERE v.id=?"; + $sth = $this->db->prepare($sql); + $sth ->execute(array($id)); + $row = $sth->fetch(); + + $sql = "SELECT data FROM metadata WHERE uuid=?"; + $sth = $this->wdb->prepare($sql); + $sth ->execute(array($row['uuid'])); + $row_geo = $sth->fetch(); + + if($row['xml']==$row_geo['data']) + { + $data = array("error"=>'无须恢复,元数据相同'); + $this->jsonexit($data); + return true; + } + + $sql = "UPDATE metadata SET data=? WHERE uuid=?"; + $sth = $this->wdb->prepare($sql); + $ex = $sth ->execute(array($row['xml'],$row['uuid'])); + + if($ex) + { + $data = array("error"=>'恢复成功'); + $this->jsonexit($data); + return true; + }else{ + $data = array("error"=>'恢复失败,请确认权限后重试'); + $this->jsonexit($data); + return true; + } + }catch(Exception $e) { + $msg = "恢复失败,请确认权限后重试"; + if($this->debug>0) + {$msg .= $e->getMessage();} + $data = array("error"=>$msg); + $this->jsonexit($data); + return true; + } + } + + //发布到评审 + else if($ac == "commit") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $data = ""; + try{ + $id = $this->_request->getParam('id'); + if(empty($id) || !is_numeric($id)) + { + $data = array("error"=>"参数错误"); + $this->jsonexit($data); + return true; + } + + $changelog = $this->_request->getParam('changelog'); + if(empty($changelog)) + { + $data = array("error"=>'请输入变更信息'); + $this->jsonexit($data); + return true; + } + + // 1. 权限认定 --skip + // 2. 保存变化记录 save changelog & userid + $sql = "UPDATE mdversion SET changelog=?,userid=? WHERE id=?"; + $this->db->query($sql,array($changelog,$u_id,$id)); + + // 3. 获取数据评审状态 + $sql = "SELECT s.*,v.xml,m.title FROM mdstatus s left join mdversion v on s.uuid=v.uuid + left join metadata m on s.uuid=m.uuid WHERE v.id=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($id)); + $row = $sth->fetch(); + + $sql="select * from xunsearch where uuid=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($row['uuid'])); + $data_search = $sth->fetch(); + $search=new Search(); + $search->update($data_search); + + if (empty($row)) //无对应记录 + { + $sql="select m.id from metadata m left join mdversion v on m.uuid=v.uuid where v.id=?"; + $sth=$this->db->prepare($sql); + $sth->execute(array($id)); + $mrow=$sth->fetch(); + if (empty($mrow)) //说明是新数据 + { + //导入元数据 + $iso=new ISO19115(); + $iso->saveDB($this->db,$row['xml']); + //进入评审库 + $sql="insert into mdstatus (uuid,status,userid) select uuid,0,? from mdversion where id=?"; + $this->db->query($sql,array($u_id,$id)); + + //email to admin + $mail=new WestdcMailer($this->view->config->smtp); + $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); + $mailtp=new EmailText($this->db,"metadata-new-admin",array( + 'user' => $user->username, + 'uuid' => $iso->uuid, + 'email'=> $user->email, + //元数据标题 + 'title'=> $iso->resTitle, + )); + $mail->setBodyText($mailtp->getBody()); + $mail->setSubject($mailtp->getSubject()); + if($this->debug==0) + { + $mail->addTo($this->view->config->service->email); + }else{ + $mail->addTo($this->debug_email); + } + $mail->send(); + + unset($mail); + unset($mailtp); + //email to author + $mail=new WestdcMailer($this->view->config->smtp); + $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); + $mailtp=new EmailText($this->db,"metadata-new-author",array( + 'user' => $user->username, + 'uuid' => $iso->uuid, + 'email'=> $user->email, + //元数据标题 + 'title'=> $iso->resTitle, + )); + $mail->setBodyText($mailtp->getBody()); + $mail->setSubject($mailtp->getSubject()); + if($this->debug==0) + { + $mail->addTo($user->email); + $mail->addCc($this->view->config->service->email); + }else{ + $mail->addTo($this->debug_email); + } + @$mail->send(); + + $data = array("commited"=>1,"error"=>'该版本已经成功提交,请等待数据中心进一步处理!'); + $this->jsonexit($data); + return true; + } else { //说明是已发布的数据且数据不存在评审信息 + //同步元数据 + $iso=new ISO19115(); + $iso->saveDB($this->db,$row['xml']); + //移除中间版本 + $sql="delete from mdversion where uuid in (select uuid from mdversion where id=?) and changelog is null"; + $this->db->query($sql,array($id)); + //修改评审状态为发布,且由其提交的用户进行管理 + $sql="insert into mdstatus (uuid,status,userid) select uuid,6,? from mdversion where id=?"; + $this->db->query($sql,array($u_id,$id)); + + //email to admin & author + $mail=new WestdcMailer($this->view->config->smtp); + $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); + $mailtp=new EmailText($this->db,"metadata-release",array( + 'user' => $user->username, + 'uuid' => $row['uuid'], + 'email'=> $user->email, + //元数据标题 + 'title'=> $row['title'], + 'changelog'=>$changelog, + )); + $mail->setBodyText($mailtp->getBody()); + $mail->setSubject($mailtp->getSubject()); + if($this->debug==0) + { + $mail->addTo($this->view->config->service->email); + $mail->addCc($this->view->config->service->email); + }else{ + $mail->addTo($this->debug_email); + } + @$mail->send(); + + $data = array("commited"=>1,"error"=>'该版本已经成功发布!'); + $this->jsonexit($data); + return true; + } + } + else if ($row['status']==-1 || $row['status']==0 || $row['status']==1) //取消发布的数据,初始状态,已接收 + { + //同步元数据 + $iso=new ISO19115(); + $iso->saveDB($this->db,$row['xml']); + //email to admin + $mail=new WestdcMailer($this->view->config->smtp); + $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); + $mailtp=new EmailText($this->db,"version-commit-admin",array( + 'user' => $user->username, + 'uuid' => $row['uuid'], + 'email'=> $user->email, + //元数据标题 + 'title'=> $row['title'], + 'changelog'=>$changelog, + )); + $mail->setBodyText($mailtp->getBody()); + $mail->setSubject($mailtp->getSubject()); + if($this->debug==0) + { + $mail->addTo($this->view->config->service->email); + }else{ + $mail->addTo($this->debug_email); + } + $mail->send(); + + unset($mail); + unset($mailtp); + //email to author + $mail=new WestdcMailer($this->view->config->smtp); + $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); + $mailtp=new EmailText($this->db,"version-commit-author",array( + 'user' => $user->username, + 'uuid' => $row['uuid'], + 'email'=> $user->email, + //元数据标题 + 'title'=> $row['title'], + )); + $mail->setBodyText($mailtp->getBody()); + $mail->setSubject($mailtp->getSubject()); + if($this->debug==0) + { + $mail->addTo($user->email); + $mail->addCc($this->view->config->service->email); + }else{ + $mail->addTo($this->debug_email); + } + @$mail->send(); + + $data = array("commited"=>1,"error"=>'该版本已经成功提交并同步,请等待数据中心进一步处理!'); + $this->jsonexit($data); + return true; + } + else if ($row['status']==2 || $row['status']==3 || $row['status']==4)//已发送过外审邮件,需由编辑告知变化信息 + { + //同步元数据 + $iso=new ISO19115(); + $iso->saveDB($this->db,$row['xml']); + + //email to admin + $mail=new WestdcMailer($this->view->config->smtp); + $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); + $mailtp=new EmailText($this->db,"version-commit-admin",array( + 'user' => $user->username, + 'uuid' => $row['uuid'], + 'email'=> $user->email, + //元数据标题 + 'title'=> $row['title'], + 'changelog'=>$changelog, + )); + $mail->setBodyText($mailtp->getBody()); + $mail->setSubject($mailtp->getSubject()); + if($this->debug==0) + { + $mail->addTo($this->view->config->service->email); + }else{ + $mail->addTo($this->debug_email); + } + $mail->send(); + + unset($mail); + unset($mailtp); + //email to author + $mail=new WestdcMailer($this->view->config->smtp); + $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); + $mailtp=new EmailText($this->db,"version-commit-author",array( + 'user' => $user->username, + 'uuid' => $row['uuid'], + 'email'=> $user->email, + //元数据标题 + 'title'=> $row['title'], + )); + $mail->setBodyText($mailtp->getBody()); + $mail->setSubject($mailtp->getSubject()); + if($this->debug==0) + { + $mail->addTo($user->email); + $mail->addCc($this->view->config->service->email); + }else{ + $mail->addTo($this->debug_email); + } + @$mail->send(); + + //email to experts + $sql="select u.username,u.email from mdexpertreview e left join users u on e.id=u.id where e.status in (0,1) and e.uuid=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($row['uuid'])); + $experts = $sth->fetchAll(); + + unset($mail); + unset($mailtp); + $mail=new WestdcMailer($this->view->config->smtp); + $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); + $mailtp=new EmailText($this->db,"version-commit-expert",array( + 'user' => $user->username, + 'uuid' => $row['uuid'], + 'email'=> $user->email, + //元数据标题 + 'title'=> $row['title'], + )); + $mail->setBodyText($mailtp->getBody()); + $mail->setSubject($mailtp->getSubject()); + $filecontent=file_get_contents("http://" . $_SERVER['HTTP_HOST'].'/data/doc/review/1/uuid/'.$uuid); + $mail->createAttachment($filecontent,'application/octet-stream',Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, $row['title'].'.doc'); + $filecontent=file_get_contents("http://" . $_SERVER['HTTP_HOST'].'/service/pdf/uuid/'.$uuid); + $mail->createAttachment($filecontent,'application/octet-stream',Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, $row['title'].'.pdf'); + if($this->debug==0) + { + foreach ($experts as $expert) $mail->addTo($expert['email']); + $mail->addCc($this->view->config->service->email); + }else{ + $mail->addTo($this->debug_email); + } + @$mail->send(); + + $data = array("commited"=>1,"error"=>'该版本已经成功提交,请等待数据中心进一步处理!'); + $this->jsonexit($data); + return true; + } + else if ($row['status']>=5)//数据已经发布,再次修改后将只通知管理员,保留发布状态 + { + //同步元数据 + $iso=new ISO19115(); + $iso->saveDB($this->db,$row['xml']); + //移除中间版本 + $sql="delete from mdversion where uuid in (select uuid from mdversion where id=?) and changelog is null"; + $this->db->query($sql,array($id)); + + //email to admin & author + $mail=new WestdcMailer($this->view->config->smtp); + $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); + $mailtp=new EmailText($this->db,"metadata-release",array( + 'user' => $user->username, + 'uuid' => $row['uuid'], + 'email'=> $user->email, + //元数据标题 + 'title'=> $row['title'], + 'changelog'=>$changelog, + )); + $mail->setBodyText($mailtp->getBody()); + $mail->setSubject($mailtp->getSubject()); + if($this->debug==0) + { + $mail->addTo($this->view->config->service->email); + //$mail->addCc($this->view->config->service->email); + }else{ + $mail->addTo($this->debug_email); + } + @$mail->send(); + + $data = array("commited"=>1,"error"=>'该版本已经成功发布!'); + $this->jsonexit($data); + return true; + } + + }catch(Exception $e) { + $msg = "提交失败,请确认权限后重试"; + if($this->debug>0) + {$msg .= $e->getMessage();} + $data = array("error"=>$msg); + $this->jsonexit($data); + return true; + } + }//发布到评审 + + //与前一个版本对比 + else if($ac == "diff") + { + $this->_helper->viewRenderer('version-diff'); + $id = $this->_request->getParam('id'); + if(empty($id) || !is_numeric($id)) + { + $this->view->error = "参数错误"; + return true; + } + + $sql = "SELECT v.uuid,md.title FROM mdversion v + LEFT JOIN metadata md ON v.uuid=md.uuid + WHERE v.id=?"; + $sth = $this->db->prepare($sql); + $sth -> execute(array($id)); + + $row = $sth->fetch(); + + $sql = "SELECT v.* FROM mdversion v + WHERE v.uuid=? AND v.id<=? + ORDER BY v.ts_created DESC + LIMIT ?"; + $sth = $this->db->prepare($sql); + $sth -> execute(array($row['uuid'],$id,2)); + + $rows = $sth->fetchAll(); + + if(count($rows)<2) + { + $this->view->error = "对比失败:之前没有版本可以对比"; + return true; + } + + $this->view->info = $row; + $this->view->data = $rows; + + } + + + }//versionAction 版本控制 + function commentAction() { $delete=(int)$this->_getParam('delete'); diff --git a/application/admin/views/scripts/data/left.phtml b/application/admin/views/scripts/data/left.phtml index d4adad05..a7f9d42f 100644 --- a/application/admin/views/scripts/data/left.phtml +++ b/application/admin/views/scripts/data/left.phtml @@ -1,10 +1,11 @@ -