From 618288b2b312a8f42c4b5048cad5c43008b06893 Mon Sep 17 00:00:00 2001 From: wlx Date: Sat, 21 Apr 2012 12:39:35 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E8=B7=AF=E5=BE=84=E9=97=AE=E9=A2=98=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=9C=AA=E6=8F=90=E4=BA=A4=E6=95=B0=E6=8D=AE=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/SubmitController.php | 322 +++++++++--------- .../default/views/scripts/submit/index.phtml | 44 ++- .../default/views/scripts/submit/navi.phtml | 2 +- .../views/scripts/submit/newdata.phtml | 5 +- .../views/scripts/submit/unsubmit.phtml | 99 ++++++ application/models/files.php | 2 +- 6 files changed, 294 insertions(+), 180 deletions(-) create mode 100644 application/default/views/scripts/submit/unsubmit.phtml diff --git a/application/default/controllers/SubmitController.php b/application/default/controllers/SubmitController.php index b56e733f..c8a1359f 100644 --- a/application/default/controllers/SubmitController.php +++ b/application/default/controllers/SubmitController.php @@ -3,44 +3,24 @@ class SubmitController extends Zend_Controller_Action { private $limit=10; - //调试模式 - // 调试模式中将显示全部错误细节,电子邮件将发往调试邮箱 - // 1 为开启 - // 0 为关闭 - public $debug = 1; - - //调试模式邮箱地址 - public $debug_email = "la5c@qq.com"; - - function preDispatch() { $this->view->config = Zend_Registry::get('config'); $this->db=Zend_Registry::get('db'); - $this->messenger=$this->_helper->getHelper('FlashMessenger'); - $this->view->messages = $this->messenger->getMessages(); } + function indexAction() { } - - - /* - * helpAction() 帮助文档 - * - */ - function helpAction(){ - }//helpAction()帮助文档 - - //新建元数据 - function newdataAction() - { - $ac = $this->_request->getParam('ac'); - $id = $this->_request->getParam('id'); - $this->wdb=Zend_Db::factory($this->view->config->geonetwork); + //新建元数据 + function newdataAction() + { + $ac = $this->_request->getParam('ac'); + $id = $this->_request->getParam('id'); + $this->wdb=Zend_Db::factory($this->view->config->geonetwork); - $auth = Zend_Auth::getInstance(); + $auth = Zend_Auth::getInstance(); if($auth->hasIdentity()) { $user = $auth->getIdentity(); @@ -108,148 +88,164 @@ class SubmitController extends Zend_Controller_Action $this->view->templates=$sth->fetchAll(); $this->_helper->viewRenderer('newdata-add'); } - - //提交数据 - 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->alertbox('warning','请输入变更信息')); - $this->jsonexit($data); - return true; - } - - // 1. 权限认定:当前用户必须和其owner相同 - // 数据应当没有评审状态,没有作者信息 - $sql="select gn.id from geonetworkmetadata gn - left join mdstatus s on gn.uuid=s.uuid - left join mdauthor a on s.uuid=a.uuid - where s.id is not null and a.id is not null and gn.id=?"; - $sth=$this->db->prepare($sql); - $sth->execute(array($id)); - $row=$sth->fetch(); - if (!emtpy($row)) - { - $data = array("error"=>'错误的入口'); - $this->jsonexit($data); - return true; - } - - $sql="select uuid from metadata where id=? and owner=?"; - $sth=$this->wdb->prepare($sql); - $sth->execute(array($id,$u_id)); - $row=$sth->fetch(); - if (empty($row)) - { - $data = array("error"=>'无权限修改数据'); - $this->jsonexit($data); - return true; - } - // 保存数据作者信息 - $sql="insert into mdauthor (uuid,userid,ts_activated,status) values(?,?,now(),1)"; - $sth=$this->db->query($sql,array($row['uuid'],$u_id)); - - // 2. 保存变化记录 save changelog & userid for the latest version - $sql = "UPDATE mdversion SET changelog=?,userid=? WHERE id in (select id from mdversion where uuid=? order by ts_created desc limit 1)"; - $this->db->query($sql,array($changelog,$u_id,$row['uuid'])); - - // 3. 保存数据评审状态 - //导入元数据 - $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->alertbox('ok','该版本已经成功提交,请等待数据中心进一步处理!')); - $this->jsonexit($data); - return true; - }catch(Exception $e) { - $msg = "提交失败,请确认权限后重试"; - if($this->debug>0) - {$msg .= $e->getMessage();} - $data = array("error"=>$this->alertbox('error',$msg)); - $this->jsonexit($data); - return true; - } - } } - - function uploadAction(){ - + + //未提交数据列表 + function unsubmitAction() + { + $ac = $this->_request->getParam('ac'); + $id = $this->_request->getParam('id'); + $this->wdb=Zend_Db::factory($this->view->config->geonetwork); + + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $u_id = $user->id; + } + + //提交数据 + 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->alertbox('warning','请输入变更信息')); + $this->jsonexit($data); + return true; + } + + // 1. 权限认定:当前用户必须和其owner相同 + // 数据应当没有评审状态,没有作者信息 + $sql="select gn.id from geonetworkmetadata gn + left join mdstatus s on gn.uuid=s.uuid + left join mdauthor a on s.uuid=a.uuid + where s.id is not null and a.id is not null and gn.id=?"; + $sth=$this->db->prepare($sql); + $sth->execute(array($id)); + $row=$sth->fetch(); + if (!emtpy($row)) + { + $data = array("error"=>'错误的入口'); + $this->jsonexit($data); + return true; + } + + $sql="select uuid from metadata where id=? and owner=?"; + $sth=$this->wdb->prepare($sql); + $sth->execute(array($id,$u_id)); + $row=$sth->fetch(); + if (empty($row)) + { + $data = array("error"=>'无权限修改数据'); + $this->jsonexit($data); + return true; + } + // 保存数据作者信息 + $sql="insert into mdauthor (uuid,userid,ts_activated,status) values(?,?,now(),1)"; + $sth=$this->db->query($sql,array($row['uuid'],$u_id)); + + // 2. 保存变化记录 save changelog & userid for the latest version + $sql = "UPDATE mdversion SET changelog=?,userid=? WHERE id in (select id from mdversion where uuid=? order by ts_created desc limit 1)"; + $this->db->query($sql,array($changelog,$u_id,$row['uuid'])); + + // 3. 保存数据评审状态 + //导入元数据 + $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()); + $mail->addTo($this->view->config->service->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()); + $mail->addTo($user->email); + $mail->addCc($this->view->config->service->email); + @$mail->send(); + + $data = array("commited"=>1,"error"=>$this->alertbox('ok','该版本已经成功提交,请等待数据中心进一步处理!')); + $this->jsonexit($data); + return true; + }catch(Exception $e) { + $msg = "提交失败,请确认权限后重试"; + if($this->debug>0) + {$msg .= $e->getMessage();} + $data = array("error"=>$this->alertbox('error',$msg)); + $this->jsonexit($data); + return true; + } + } + else + { + $sql = "SELECT (regexp_matches(gn.data,'(.*)'))[1] as title,gn.id,gn.uuid FROM geonetworkmetadata gn + WHERE gn.uuid not in (select uuid from metadata) and gn.owner=? + order by gn.id desc + "; + $sth = $this->db->prepare($sql); + $sth->execute(array($u_id)); + $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; + } + } + + function uploadAction() + { $this->_helper->layout()->disableLayout(); - - $uuid = $this->_request->getParam('uuid'); - $this->view->uuid=$uuid; - $ac = $this->_request->getParam('ac'); - - $dataFilePath = "../data/"; + $dataFilePath = "../data/upload/"; if($ac=='submit') { - $this->_helper->viewRenderer->setNoRender(); - + $this->_helper->viewRenderer->setNoRender(); $auth = Zend_Auth::getInstance(); if($auth->hasIdentity()) { @@ -285,10 +281,6 @@ class SubmitController extends Zend_Controller_Action $data = array("error"=>'数据文件保存成功'); $this->jsonexit($data); return true; - - - - } diff --git a/application/default/views/scripts/submit/index.phtml b/application/default/views/scripts/submit/index.phtml index 9cc6e9eb..ae2c145b 100755 --- a/application/default/views/scripts/submit/index.phtml +++ b/application/default/views/scripts/submit/index.phtml @@ -21,29 +21,51 @@ $this->breadcrumb()->setSeparator(' > ');
diff --git a/application/default/views/scripts/submit/navi.phtml b/application/default/views/scripts/submit/navi.phtml index 998b6382..ea58a423 100644 --- a/application/default/views/scripts/submit/navi.phtml +++ b/application/default/views/scripts/submit/navi.phtml @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/application/default/views/scripts/submit/newdata.phtml b/application/default/views/scripts/submit/newdata.phtml index 73342260..235d7190 100644 --- a/application/default/views/scripts/submit/newdata.phtml +++ b/application/default/views/scripts/submit/newdata.phtml @@ -8,7 +8,7 @@ $this->headLink()->appendStylesheet('/css/author.css'); $this->headLink()->appendStylesheet('/css/colorbox.css'); $this->breadcrumb('首页'); $this->breadcrumb('数据汇交'); -$this->breadcrumb('数据新闻'); +$this->breadcrumb('新建元数据'); $this->breadcrumb()->setSeparator(' > '); ?> @@ -23,7 +23,8 @@ $this->breadcrumb()->setSeparator(' > ');
diff --git a/application/default/views/scripts/submit/unsubmit.phtml b/application/default/views/scripts/submit/unsubmit.phtml new file mode 100644 index 00000000..548f6eb3 --- /dev/null +++ b/application/default/views/scripts/submit/unsubmit.phtml @@ -0,0 +1,99 @@ +headTitle($this->config->title->site); +$this->headTitle($this->config->title->submit); +$this->headTitle()->setSeparator(' - '); +$this->headScript()->appendFile('/js/jquery-1.7.min.js'); +$this->headScript()->appendFile('/js/jquery.colorbox-min.js'); +$this->headLink()->appendStylesheet('/css/author.css'); +$this->headLink()->appendStylesheet('/css/colorbox.css'); +$this->breadcrumb('首页'); +$this->breadcrumb('数据汇交'); +$this->breadcrumb('未提交元数据'); +$this->breadcrumb()->setSeparator(' > '); +?> + + + + + +
+ +
+ paginator)): + echo "
+ +
+ + + \ No newline at end of file diff --git a/application/models/files.php b/application/models/files.php index 14ab9aa6..c539d793 100644 --- a/application/models/files.php +++ b/application/models/files.php @@ -241,7 +241,7 @@ class files{ { $save_path .= $uuid . "/"; $save_url .= $uuid . "/"; - $dbsave = $uuid.'/'; + $dbsave = $dir.'/'.$uuid.'/'; if (!file_exists($save_path)) { mkdir($save_path); }