From c30f1c68267316b1acc94244636e4efffe23f265 Mon Sep 17 00:00:00 2001 From: wlx Date: Tue, 15 Oct 2013 10:04:41 +0000 Subject: [PATCH 001/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E7=8C=AE?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E7=9A=84=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/module/Reference/Handler/ReferenceHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/module/Reference/Handler/ReferenceHandler.php b/application/module/Reference/Handler/ReferenceHandler.php index 77300d78..d92b3a27 100644 --- a/application/module/Reference/Handler/ReferenceHandler.php +++ b/application/module/Reference/Handler/ReferenceHandler.php @@ -110,7 +110,7 @@ class ReferenceHandler implements \Reference\Event\ReferenceEvent return "UUID格式不正确"; } - if(empty($data['reftype'])) + if(($data['reftype']=='')) { return "请选择文献类型"; } From 29557c14c19a47a3f48479716e6baa75e1dfdd77 Mon Sep 17 00:00:00 2001 From: wlx Date: Tue, 15 Oct 2013 10:06:42 +0000 Subject: [PATCH 002/173] fix condition judgement --- application/module/Reference/Handler/ReferenceHandler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/module/Reference/Handler/ReferenceHandler.php b/application/module/Reference/Handler/ReferenceHandler.php index d92b3a27..efb6732b 100644 --- a/application/module/Reference/Handler/ReferenceHandler.php +++ b/application/module/Reference/Handler/ReferenceHandler.php @@ -110,7 +110,7 @@ class ReferenceHandler implements \Reference\Event\ReferenceEvent return "UUID格式不正确"; } - if(($data['reftype']=='')) + if(($data['reftype']==='')) { return "请选择文献类型"; } @@ -135,4 +135,4 @@ class ReferenceHandler implements \Reference\Event\ReferenceEvent return $data; } -} \ No newline at end of file +} From 3acef46848e8fe697e5ee27f659e82ef33d8b677 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Wed, 16 Oct 2013 08:07:54 +0000 Subject: [PATCH 003/173] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=E9=99=84?= =?UTF-8?q?=E4=BB=B6=E4=B8=8A=E4=BC=A0=E4=B8=AD=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controllers/DataController.php | 16 +-- .../views/scripts/data/attachmentsadd.phtml | 134 ++++++++++-------- 2 files changed, 78 insertions(+), 72 deletions(-) diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index ed125cf4..27584057 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -1788,8 +1788,8 @@ class Admin_DataController extends Zend_Controller_Action $id = $this->_getParam('attupdate'); - $files=new files(); - $msg = $files -> upload($this->view->config->upload,$_FILES['Filedata'],empty($uuid)?'file':'md'); + $files=new Files(); + $msg = $files -> upload($_FILES['Filedata'],empty($uuid)?'file/':'md/',true); if(empty($msg['error'])) { @@ -1797,7 +1797,7 @@ class Admin_DataController extends Zend_Controller_Action $filename = $msg['db_path']; $filesize = $msg['file_size']; $filedesc = $this->_request->getParam('filedesc'); - $filetype = $msg['file_type']; + $filetype = 'md'; $realname = $msg['realname']; @@ -2116,8 +2116,8 @@ class Admin_DataController extends Zend_Controller_Action exit(); } - $files=new files(); - $msg = $files -> upload($this->view->config->upload,$_FILES['Filedata'],empty($uuid)?'file':'md'); + $files=new Files(); + $msg = $files -> upload($_FILES['Filedata'],empty($uuid)?'file/':'md/',true); if(empty($msg['error'])) { @@ -2125,7 +2125,7 @@ class Admin_DataController extends Zend_Controller_Action $filename = $msg['db_path']; $filesize = $msg['file_size']; $filedesc = $this->_request->getParam('filedesc'); - $filetype = $msg['file_type']; + $filetype = 'md'; $realname = $msg['realname']; @@ -2184,10 +2184,6 @@ class Admin_DataController extends Zend_Controller_Action $rs = $this->db->query($sql); $atts = $rs->fetchAll(); - foreach($atts as $k=>$v) - { - $atts[$k]['html']= $v['realname'].'['. round($v['filesize']/1024,2) .' kb]
'; - } echo Zend_Json::encode($atts); exit(); }else diff --git a/application/admin/views/scripts/data/attachmentsadd.phtml b/application/admin/views/scripts/data/attachmentsadd.phtml index c6a37c0a..5660ef70 100644 --- a/application/admin/views/scripts/data/attachmentsadd.phtml +++ b/application/admin/views/scripts/data/attachmentsadd.phtml @@ -7,12 +7,7 @@ $this->breadcrumb('后台首页'); $this->breadcrumb('数据管理'); $this->breadcrumb()->setSeparator(' > '); - $this->headLink()->appendStylesheet('/static/js/uploadify/uploadify.css'); - $this->headScript()->appendFile('/static/js/jquery-1.7.2.min.js'); - $this->headScript()->appendFile('/js/jquery.colorbox-min.js'); - $this->headLink()->appendStylesheet('/css/colorbox.css'); - $this->headScript()->appendFile('/static/js/uploadify/swfobject.js'); - $this->headScript()->appendFile('/static/js/uploadify/jquery.uploadify.v2.1.4.min.js'); + $this->theme->AppendPlus($this,"uploadify"); ?>
partial('data/left.phtml'); ?> @@ -21,7 +16,7 @@ @@ -30,7 +25,8 @@

注:可选择多个文件
-

    +
    +

    @@ -38,65 +34,79 @@
    + \ No newline at end of file diff --git a/application/default/views/scripts/water/view.phtml b/application/default/views/scripts/water/view.phtml index 217c6742..3d4a58e9 100755 --- a/application/default/views/scripts/water/view.phtml +++ b/application/default/views/scripts/water/view.phtml @@ -46,33 +46,59 @@ if ($md->title_en) echo '
    '.$this->escape($md->title_en);?> echo substr($md->authors,1,-1).'. '.$md->title.'. '.$md->publisher.', '.$md->publish_year.'. doi:'.$md->doi; echo ' ['.substr($md->author_en,1,-1).'. '.$md->title_en.'. '.$md->publisher_en.', '.(empty($md->ts_published)?$md->publish_year:date('Y',strtotime($md->ts_published))).'. doi:'.$md->doi.']'; ?> (下载引用:RIS格式 | RIS英文格式 | Bibtex格式 | Bibtex英文格式)

    - ref) : ?> + + ref) : ?>
    -

    建议参考文献

    +

    相关文献(作者推荐)

      ref as $ref) : echo '
    1. '.$ref->reference; + echo '查看'; if (empty($ref->link)) { - if(!empty($ref->attid)) + if(!empty($ref->attid)) echo '下载'; + }else{ + echo '下载'; + } + echo "
    2. "; + endforeach; + ?> +
    + themeref) :?> + +
    +

    专题文献

    +
      + themeref as $ref) : + echo '
    1. '.$ref->reference; + echo '查看'; + if (empty($ref->link)) + { + if(!empty($ref->attid)) + echo ' | 下载'; }else{ - echo '下载'; + echo ' | 下载'; } echo "
    2. "; endforeach; ?>
    - userref) : ?>
    -

    数据用户发表文献

    +

    数据施引文献

      userref as $ref) : + echo '
    1. '.$ref->reference; + echo '查看'; if (empty($ref->link)) - echo '
    2. '.$ref->reference.'
    3. '; - else - echo '
    4. '.$ref->reference.' 下载
    5. '; + { + if(!empty($ref->attid)) + echo '下载'; + }else{ + echo '下载'; + } + echo ""; endforeach; ?>
    From c1f5c7de566b5d4dd7006d5685dbe8ec07255330 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Mon, 28 Oct 2013 09:45:48 +0000 Subject: [PATCH 022/173] =?UTF-8?q?#558=20=E5=A2=9E=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E4=BB=8E=E8=A1=A8=E4=B8=AD=E8=AF=BB=E5=8F=96=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/KnowledgeController.php | 120 +++++++++--------- .../default/controllers/ServiceController.php | 18 +++ .../views/scripts/knowledge/paper.phtml | 114 +++++++++++------ 3 files changed, 152 insertions(+), 100 deletions(-) diff --git a/application/default/controllers/KnowledgeController.php b/application/default/controllers/KnowledgeController.php index 3ad91082..dd6baa2e 100755 --- a/application/default/controllers/KnowledgeController.php +++ b/application/default/controllers/KnowledgeController.php @@ -1,17 +1,17 @@ -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->view->theme=new Theme(); - } +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->view->theme=new Theme(); + } function datacenterAction() { $siteid="e31f5ea7-a4af-4ae3-9ac1-1a84132c4338";//site uuid from geonetowrk @@ -24,8 +24,8 @@ class KnowledgeController extends Zend_Controller_Action $paginator->setItemCountPerPage(10); $paginator->setView($this->view); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); - $this->view->paginator=$paginator; - } + $this->view->paginator=$paginator; + } function userAction() { $sql="select * from reference where id in (select refid from mdref where reftype=1 and uuid in (select uuid from normalmetadata)) order by id desc"; @@ -37,8 +37,8 @@ class KnowledgeController extends Zend_Controller_Action $paginator->setItemCountPerPage(10); $paginator->setView($this->view); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); - $this->view->paginator=$paginator; - } + $this->view->paginator=$paginator; + } function authorAction() { $sql="select * from reference where id in (select refid from mdref where reftype=0 and uuid in (select uuid from normalmetadata)) order by id desc"; @@ -50,12 +50,12 @@ class KnowledgeController extends Zend_Controller_Action $paginator->setItemCountPerPage(10); $paginator->setView($this->view); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); - $this->view->paginator=$paginator; - } - - function westplanAction() - { - $sql="select distinct array_to_string(array(select author from knl_author t where t.item_id=c.item_id order by place asc),'; ') as author,c.title,c.publisher,c.ts_created,c.ts_issued,c.item_id,c.url from knl_article c where c.url <>'' order by ts_created desc"; + $this->view->paginator=$paginator; + } + + function westplanAction() + { + $sql="select distinct array_to_string(array(select author from knl_author t where t.item_id=c.item_id order by place asc),'; ') as author,c.title,c.publisher,c.ts_created,c.ts_issued,c.item_id,c.url from knl_article c where c.url <>'' order by ts_created desc"; $sth = $this->db->prepare($sql); $sth->execute(); $rows = $sth->fetchAll(); @@ -64,11 +64,11 @@ class KnowledgeController extends Zend_Controller_Action $paginator->setItemCountPerPage(10); $paginator->setView($this->view); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); - $this->view->paginator=$paginator; - } - function searchAction() - { - $key=$this->_request->getParam('q'); + $this->view->paginator=$paginator; + } + function searchAction() + { + $key=$this->_request->getParam('q'); $source=$this->_request->getParam('searchsource'); if(preg_match("/\"|'|<|>/",$key)) { @@ -89,7 +89,7 @@ class KnowledgeController extends Zend_Controller_Action if (!empty($key) && $source=='datasource') { $search=new SimpleSearch($key); $where=$search->sql_expr(array("reference")); - $sql="select * from reference where ".$where." order by id desc"; + $sql="select * from reference where ".$where." order by id desc"; $sth = $this->db->prepare($sql); $sth->execute(); $rows = $sth->fetchAll(); @@ -98,14 +98,14 @@ class KnowledgeController extends Zend_Controller_Action $paginator->setItemCountPerPage(10); $paginator->setView($this->view); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); - $this->view->paginator=$paginator; - $this->view->key=$key; - $this->view->source=$source; + $this->view->paginator=$paginator; + $this->view->key=$key; + $this->view->source=$source; $this->_helper->viewRenderer('search-data'); - } - else if (!empty($key) && $source=='westsource') { + } + else if (!empty($key) && $source=='westsource') { $search=new SimpleSearch($key); - $where=$search->sql_expr(array("c.title","a.author")); + $where=$search->sql_expr(array("c.title","a.author")); $sql="select distinct a.author,c.title,c.publisher,c.ts_created,c.ts_issued,c.item_id,c.url from knl_article c left join knl_author a on c.item_id=a.item_id where c.url <>'' and a.place=1 and $where order by ts_created desc"; $sth = $this->db->prepare($sql); $sth->execute(); @@ -115,28 +115,28 @@ class KnowledgeController extends Zend_Controller_Action $paginator->setItemCountPerPage(10); $paginator->setView($this->view); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); - $this->view->paginator=$paginator; - $this->view->key=$key; - $this->view->source=$source; - //$this->_helper->viewRenderer('search-data'); - } - } - function paperAction() - { - $id = (int)$this->_request->getParam('id'); - $sql="select * from reference where id=$id"; - $sth = $this->db->prepare($sql); - $sth->execute(); - $this->view->paper = $sth->fetch(); - - $sql="select * from ref_author where id=$id order by place"; - $sth = $this->db->prepare($sql); - $sth->execute(); - $this->view->author = $sth->fetchAll(); - - $sql="select * from ref_tag where id=$id"; - $sth = $this->db->prepare($sql); - $sth->execute(); - $this->view->tag = $sth->fetchAll(); - } + $this->view->paginator=$paginator; + $this->view->key=$key; + $this->view->source=$source; + //$this->_helper->viewRenderer('search-data'); + } + } + function paperAction() + { + $id = (int)$this->_request->getParam('id'); + $sql="select * from reference where id=$id"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $this->view->paper = $sth->fetch(); + + $sql="select * from ref_author where id=$id order by place"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $this->view->author = $sth->fetchAll(); + + $sql="select * from ref_tag where id=$id"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $this->view->tag = $sth->fetchAll(); + } } \ No newline at end of file diff --git a/application/default/controllers/ServiceController.php b/application/default/controllers/ServiceController.php index 446dd0a6..8d2c5af4 100644 --- a/application/default/controllers/ServiceController.php +++ b/application/default/controllers/ServiceController.php @@ -1453,6 +1453,24 @@ class ServiceController extends Zend_Controller_Action echo ''; echo $pagnation; }//文档页面相关数据 + + function refdatacountAction() + { + if(view::isXmlHttpRequest($this)) + { + $id = (int)$this->_getParam('id'); + if($id < 1){ + echo 0; + return; + } + $sql = "select count(md.id) as total from mdref mr + right join normalmetadata md on md.uuid=mr.uuid + where mr.refid=$id"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + echo $row['total']; + } + } function tagdatalistAction(){ diff --git a/application/default/views/scripts/knowledge/paper.phtml b/application/default/views/scripts/knowledge/paper.phtml index fe82d450..a0fa71e8 100644 --- a/application/default/views/scripts/knowledge/paper.phtml +++ b/application/default/views/scripts/knowledge/paper.phtml @@ -6,7 +6,7 @@ $this->headLink()->appendStylesheet('/css/mdreview.css'); $this->breadcrumb('首页'); $this->breadcrumb('知识积累'); $this->breadcrumb('文章查看'); -$this->breadcrumb()->setSeparator(' > '); +$this->breadcrumb()->setSeparator(' > '); $this->headScript()->appendFile('/js/jquery.colorbox-min.js'); $this->headLink()->appendStylesheet('/css/colorbox.css'); ?> @@ -16,48 +16,71 @@ $this->headLink()->appendStylesheet('/css/colorbox.css');
    -

    paper['title']; ?>

    -
      - author as $a) : ?> -
    • - -
    - paper['abstract']) : ?> - 摘要: - paper['abstract']; endif; if ($this->tag) : ?> - 关键词: -
      - tag as $t) : ?> -
    • - -
    - - - paper['reference']; ?> - + paper['title'])){ ?> +

    paper['title']; ?>

    +
    + + author) > 0) {?> +

    作者

    +
      + author as $a) : ?> +
    • + +
    +
    + + + paper['abstract']){ ?> +

    摘要

    +

    paper['abstract']; ?>

    +
    + + + tag) > 0) { ?> +

    关键词

    +
      + tag as $t) : ?> +
    • + +
    +
    + + + paper['reference'])) { ?> +

    引用方式

    +
    + paper['reference']; ?> +
    +
    + -
    - paper['link'])) - { - if(!empty($this->paper[‘attid’])) - echo 'PDF下载'; - }else{ - echo 'PDF下载'; - } - - if (!empty($item['link'])) : - echo ' 下载'; - endif; - ?> - 相关数据(共?条) - -
    +
    + paper['link'])) + { + if(!empty($this->paper['attid'])) + { + echo 'PDF下载'; + } + }else{ + echo 'PDF下载'; + } + + + if (!empty($item['link'])) : + echo ' 下载'; + endif; + ?> + 相关数据(共条) +
    + +
    - - + + \ No newline at end of file From 8e1db6cd3d1e3bb29a286a0e653d1416a704b59b Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Wed, 30 Oct 2013 06:51:28 +0000 Subject: [PATCH 023/173] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=B2=A1=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/default/controllers/AccountController.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/application/default/controllers/AccountController.php b/application/default/controllers/AccountController.php index 40dd9b20..78487b85 100755 --- a/application/default/controllers/AccountController.php +++ b/application/default/controllers/AccountController.php @@ -374,15 +374,6 @@ class AccountController extends Zend_Controller_Action view::Post($this,"登录成功,正在跳转",$tohref); return true; } - - if($options['module']=="default" && $options['controller'] == "account" && $options['action'] == "login") - { - view::Post($this,"登录成功,正在跳转",'/'); - return true; - }else{ - view::Post($this,"登录成功,正在跳转",$_SERVER['REQUEST_URI']); - return true; - } } }else{ $this->setCaptcha($captcha); From e3a6acc635254b6220c47d4b63fc9b4147f6bff7 Mon Sep 17 00:00:00 2001 From: wlx Date: Thu, 31 Oct 2013 05:17:00 +0000 Subject: [PATCH 024/173] fix logic error --- .../default/views/scripts/water/view.phtml | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/application/default/views/scripts/water/view.phtml b/application/default/views/scripts/water/view.phtml index 3d4a58e9..db5ab149 100755 --- a/application/default/views/scripts/water/view.phtml +++ b/application/default/views/scripts/water/view.phtml @@ -23,10 +23,10 @@ h3.gs_rt{font-size:110%;} render('breadcrumbs.phtml'); ?> metadata;if ($md):?> -

    escape($md->title); -if ($md->title_en) echo '
    '.$this->escape($md->title_en);?> -

    -
    +

    escape($md->title); + if ($md->title_en) echo '
    '.$this->escape($md->title_en);?> +

    +
    @@ -36,18 +36,19 @@ if ($md->title_en) echo '
    '.$this->escape($md->title_en);?>

    - citation) : ?> + citation) : ?>

    本数据引用方式数据引用帮助

    datadoi) || !strpos($md->citation,$md->datadoi)) : ?>文章的引用 escape($md->citation);?>

    - datadoi) && !strpos($md->citation,$md->datadoi)) : ?> -

    数据的引用datadoi) && !strpos($md->citation,$md->datadoi)) : ?> +

    数据的引用 + authors,1,-1).'. '.$md->title.'. '.$md->publisher.', '.$md->publish_year.'. doi:'.$md->doi; echo ' ['.substr($md->author_en,1,-1).'. '.$md->title_en.'. '.$md->publisher_en.', '.(empty($md->ts_published)?$md->publish_year:date('Y',strtotime($md->ts_published))).'. doi:'.$md->doi.']'; ?> (下载引用:RIS格式 | RIS英文格式 | Bibtex格式 | Bibtex英文格式)

    - - ref) : ?> + ref) : ?>

    相关文献(作者推荐)

      @@ -65,7 +66,7 @@ if ($md->title_en) echo '
      '.$this->escape($md->title_en);?> endforeach; ?>
    - themeref) :?> + themeref) :?>

    专题文献

    @@ -84,7 +85,7 @@ if ($md->title_en) echo '
    '.$this->escape($md->title_en);?> endforeach; ?> - userref) : ?> + userref) : ?>

    数据施引文献

      From fff01b40ce9eaf1c0978ee1122026194a63dadbb Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 1 Nov 2013 09:13:35 +0000 Subject: [PATCH 025/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=82=E8=80=83?= =?UTF-8?q?=E6=96=87=E7=8C=AE=E6=A0=BC=E5=BC=8F=E7=94=9F=E6=88=90=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=EF=BC=9B=E4=BF=AE=E6=94=B9=E6=89=B9=E9=87=8F=E5=AF=BC?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/module/Reference/Reference.php | 2 +- application/module/Reference/Ris.php | 30 ++++++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/application/module/Reference/Reference.php b/application/module/Reference/Reference.php index ca7abfd6..bb9731dd 100644 --- a/application/module/Reference/Reference.php +++ b/application/module/Reference/Reference.php @@ -453,7 +453,7 @@ class Reference public function referenceType() { return array( - 0 => '相关文献', + 0 => '相关文献',//作者建议的文献或数据中心建议的文献 1 => '施引文献', 2 => '参考文献', 3 => '多篇文献', diff --git a/application/module/Reference/Ris.php b/application/module/Reference/Ris.php index 3b891373..c9432ddd 100644 --- a/application/module/Reference/Ris.php +++ b/application/module/Reference/Ris.php @@ -174,18 +174,20 @@ class Ris $results = $this->events()->trigger('checkLoad', $this, compact('ref')); $id = $results->bottom(); - $this->unsetVar($ref); + if ($id > 0) - { + { + $this->unsetVar($ref); $this->events()->trigger('deleteAuthor', $this, compact('id')); $this->events()->trigger('deleteTag', $this, compact('id')); unset($ref['reference']); $dbh->update($this->table->reference,$ref," id=$id "); - } else { - $ref['reference'] = $this->makeReferenceFlag($ref); + } else { + $ref['reference'] = $this->makeReferenceFlag($ref); + $this->unsetVar($ref); $id = $dbh->insert($this->table->reference,$ref,true); } @@ -272,17 +274,17 @@ class Ris //创建reference 字段 public function makeReferenceFlag($ref){ - $str = array(); - isset($ref['author']) ? $str[] = join(",",$ref['author']):""; - isset($ref['title']) ? $str[] = $ref['title']:""; - isset($ref['year']) ? $str[] = $ref['year']:""; - isset($ref['volume']) ? $str[] = $ref['volume']:""; - isset($ref['issue']) ? $str[] = $ref['issue']:""; - isset($ref['pages']) ? $str[] = $ref['pages']:""; - isset($ref['endpage'])? $str[] = $ref['endpage']:""; - isset($ref['doi']) ? $str[] = $ref['doi'] : ""; + $str = join(', ',$ref['author']).'. '; + $str .= $ref['title'].'. '; + $str .= $ref['publisher'].', '; + isset($ref['year']) ? $str .= $ref['year'].', ':""; + isset($ref['volume']) ? $str .= $ref['volume']:""; + isset($ref['issue']) ? $str .= '('.$ref['issue'].')':""; + isset($ref['pages']) ? $str .= ':'.$ref['pages']:""; + isset($ref['endpage'])? $str .= '-'.$ref['endpage']:""; + isset($ref['doi']) ? $str .= '. doi:'.$ref['doi'] : ""; - return join(",",$str); + return $str; } //卸载不需要的变量 From 075ff2b2c09b45351dca70a7fdf8c405dff7a9cb Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 1 Nov 2013 09:14:13 +0000 Subject: [PATCH 026/173] =?UTF-8?q?=E6=94=BE=E5=AE=BD=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E7=9A=84=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/module/Reference/Handler/RisHandler.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/application/module/Reference/Handler/RisHandler.php b/application/module/Reference/Handler/RisHandler.php index 6659abee..9de4d5d0 100644 --- a/application/module/Reference/Handler/RisHandler.php +++ b/application/module/Reference/Handler/RisHandler.php @@ -36,13 +36,14 @@ class RisHandler implements \Reference\Event\RisEvent $wheresql = array(); - $wheresql[] = " title='{$ref['title']}' "; + $wheresql[] = " lower(title)=lower('{$ref['title']}') "; $wheresql[] = " year='{$ref['year']}' "; - - if(isset($ref['publisher'])) + + //暂时不使用期刊限制 + /*if(isset($ref['publisher'])) { $wheresql[] = " publisher='{$ref['publisher']}' "; - } + }*/ if(count($wheresql) > 0) { From 6ae3223a84b2f5b459bc36e8f8f307ed118c8011 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Mon, 4 Nov 2013 07:08:58 +0000 Subject: [PATCH 027/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E7=8C=AE?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=98=BE=E7=A4=BA=E6=96=B9=E5=BC=8F=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8C=89=E5=B9=B4=E6=98=BE=E7=A4=BA=E7=9A=84?= =?UTF-8?q?=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 | 29 +++- .../views/scripts/data/attachmentsadd.phtml | 3 +- .../admin/views/scripts/data/ref-nav.phtml | 5 +- .../admin/views/scripts/data/ref.phtml | 46 ++--- application/module/Helpers/Table.php | 7 + application/module/Helpers/dbh.php | 28 +++ application/module/Open/App.php | 162 +++++++++++++++++- application/module/Open/Open.php | 70 +++----- application/module/Reference/Reference.php | 58 +++++++ 9 files changed, 328 insertions(+), 80 deletions(-) diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index ed9cf60e..5389eabf 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -1128,6 +1128,7 @@ class Admin_DataController extends Zend_Controller_Action $keyword = $this->view->q = trim($this->_getParam('q')); $order = $this->view->search_order = trim($this->_getParam('order')); $sort = $this->view->search_sort = trim($this->_getParam('sort')); + $field = $this->view->search_field = $this->_getParam('field'); $reference = new Reference(); @@ -1136,6 +1137,11 @@ class Admin_DataController extends Zend_Controller_Action $reference->keyword = $keyword; } + if(!empty($field)) + { + $reference->field = $field; + } + if(!empty($order)) { $reference->order = $order; @@ -1146,11 +1152,18 @@ class Admin_DataController extends Zend_Controller_Action $reference->sort = $sort; } + $this->view->reference = $reference; + //文献首页 if(empty($ac)) { $this->view->referenceType = $reference->referenceType(); - view::addPaginator($reference->fetchReferences(),$this,12); + + $this->view->page = $this->_getParam('page'); + $this->view->pagelimit = 12; + + view::addPaginator($reference->fetchReferences(),$this, $this->view->pagelimit); + $this->view->years = $reference->countByYear(); return true; } else if ($ac == "water") @@ -1172,6 +1185,8 @@ class Admin_DataController extends Zend_Controller_Action return true; } + unset($this->view->reference); + //添加 if($ac == "add") { @@ -1378,6 +1393,18 @@ class Admin_DataController extends Zend_Controller_Action return true; }//ris单篇更新 + + //ris导出 + if($ac == "risoutput") + { + $this->_helper->viewRenderer('ref-risoutput'); + $this->view->years = $reference->countByYear(); + + if(!empty($submit)) + { + + } + }//ris output }//文献管理 refAction() diff --git a/application/admin/views/scripts/data/attachmentsadd.phtml b/application/admin/views/scripts/data/attachmentsadd.phtml index 5660ef70..3c7c33f4 100644 --- a/application/admin/views/scripts/data/attachmentsadd.phtml +++ b/application/admin/views/scripts/data/attachmentsadd.phtml @@ -28,7 +28,6 @@
      -

      @@ -71,7 +70,7 @@ var upload = { makeFileHtml : function(data){ return '
      ' + '' - + data.realname + + '' +data.realname + '' +'' +'
      '; }, diff --git a/application/admin/views/scripts/data/ref-nav.phtml b/application/admin/views/scripts/data/ref-nav.phtml index 85329fdd..c3406955 100644 --- a/application/admin/views/scripts/data/ref-nav.phtml +++ b/application/admin/views/scripts/data/ref-nav.phtml @@ -1,10 +1,11 @@ \ No newline at end of file diff --git a/application/admin/views/scripts/data/ref.phtml b/application/admin/views/scripts/data/ref.phtml index b1298c2b..7813e18a 100644 --- a/application/admin/views/scripts/data/ref.phtml +++ b/application/admin/views/scripts/data/ref.phtml @@ -37,6 +37,13 @@ table thead tr th {background:#EBF2F6;} msg)) { ?> msg ?> + + years)) { ?> + years as $k=>$v){ ?> + () + + +
      paginator)): ?> @@ -45,8 +52,7 @@ table thead tr th {background:#EBF2F6;} - @@ -58,37 +64,31 @@ table thead tr th {background:#EBF2F6;} - page > 1) + { + $autoindex = ($this->page - 1) * $this->pagelimit; + }else{ + $autoindex=0; + } foreach ($this->paginator as $item): $autoindex++;?> - - - - + - - - - - - - - - - -
      标题 - 年份 + 年份
      + []  + {reference->getAuthorByReference($item['id'],true); echo count($authors) ? join(",",$authors):'未知作者'; ?>}  + {未知标题':$item['title'] ?>}  + {未知期刊':$item['publisher'] ?>}  + {未知年份':$item['year'] ?>}  + + 编辑 RIS编辑 数据(+) 删除
      - 编辑 - RIS编辑 - 数据 - 删除 -
      diff --git a/application/module/Helpers/Table.php b/application/module/Helpers/Table.php index 87ceade0..69256584 100644 --- a/application/module/Helpers/Table.php +++ b/application/module/Helpers/Table.php @@ -20,4 +20,11 @@ class Table //元数据 public $metadata = "metadata"; + + //会员 + public $member = "users"; + + //开放平台 + public $oauth_clients = "oauth_clients"; + public $oauth_access_tokens = "oauth_access_tokens"; } \ No newline at end of file diff --git a/application/module/Helpers/dbh.php b/application/module/Helpers/dbh.php index 83791cd1..b9f2e7a8 100644 --- a/application/module/Helpers/dbh.php +++ b/application/module/Helpers/dbh.php @@ -1,11 +1,15 @@ debug == 1) + { + view::Dump($sql,false); + } + try{ return $this->db->exec($sql); }catch (Exception $e) { @@ -53,6 +63,12 @@ class dbh } }else{ $sql = "INSERT INTO \"".$table."\" ($fields) VALUES ($datas) RETURNING id"; + + if($this->debug == 1) + { + view::Dump($sql,false); + } + try{ $sth = $this->db->prepare($sql); if($sth->execute()) @@ -108,6 +124,12 @@ class dbh try{ $sql = "UPDATE \"".$table."\" SET $fields $wheresql"; + + if($this->debug == 1) + { + view::Dump($sql,false); + } + if($this->db->exec($sql)) { return true; @@ -125,6 +147,12 @@ class dbh }else{ try{ $sql = "UPDATE \"".$table."\" SET $fields $wheresql"; + + if($this->debug == 1) + { + view::Dump($sql,false); + } + return $this->db->exec($sql); }catch (Exception $e) { if($this->product) diff --git a/application/module/Open/App.php b/application/module/Open/App.php index 23d3b377..a4da49a0 100644 --- a/application/module/Open/App.php +++ b/application/module/Open/App.php @@ -1,15 +1,72 @@ load(); + if(empty($db)) + { + $this->db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + + $Listener = new Listener(); + @$this->events()->attachAggregate($Listener); + + $this->table = new \Helpers\Table(); + } + + public function events(\Zend_EventManager_EventCollection $events = NULL) + { + if ($events !== NULL) { + $this->events = $events; + } elseif ($this->events === NULL) { + $this->events = new \Zend_EventManager_EventManager(__CLASS__); + } + return $this->events; + } + + public function appStatus() + { + return array( + -1 => '关闭', + 0 => '测试', + 1 => '启用' + ); + } + + //检查用户资料完整性 + public function checkinfo() + { + $uid = view::User('id'); + $sql = "SELECT * FROM ".$this->table->member. " WHERE id=$uid"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + + foreach($this->checkFiled as $v) + { + if(empty($row[$v])) + { + return "请完善个人信息"; + } + } + + return true; } //获得用户创建的app @@ -17,10 +74,10 @@ class app extends open implements openbase { if(empty($uid)) { - $uid = $this->user->id; + $uid = view::User('id'); } - $sql = "SELECT * FROM ".$this->tbl_oauth_clients." WHERE user_id=".$this->user->id; + $sql = "SELECT * FROM ".$this->table->oauth_clients." WHERE user_id=".$uid ." ORDER BY id DESC"; $rs = $this->db->query($sql); $rows = $rs->fetchAll(); @@ -34,12 +91,103 @@ class app extends open implements openbase { return false; } - $sql = "SELECT * FROM ".$this->tbl_oauth_clients." WHERE id=".$id; + $sql = "SELECT * FROM ".$this->table->oauth_clients." WHERE id=".$id; $rs = $this->db->query($sql); $rows = $rs->fetch(); return $rows; } + //收集创建应用的参数 + public function getAppCreateParam(\Zend_Controller_Request_Abstract $request = NULL) + { + $request = new \Zend_Controller_Request_Http(); + $data = array( + 'subject' => trim($request->getParam('subject')), + 'client_domain' => trim($request->getParam('client_domain')), + 'redirect_uri' => trim($request->getParam('redirect_uri')), + 'status' => (int)$request->getParam('status') + ); + return $data; + }//getAppCreateParam + //添加或者编辑 + public function appCreate($id = NULL) + { + if(!empty($id)) + { + if(!is_numeric($id) || $id<1) + { + return "参数错误"; + } + } + + $data = $this->getAppCreateParam(); + + $params = compact('data'); + $results = $this->events()->trigger('app.checkParam', $this, $params); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + return $cache_data; + } + + if(!empty($id)) + { + $params = compact('data','id'); + } + + $results = $this->events()->trigger('app.processData', $this, $params); + $data = $results->bottom(); + + $dbh = new dbh(); + + if(empty($id)) + { + $id = $dbh->insert($this->table->oauth_clients,$data,true); + if($id > 0) + { + $results = $this->events()->trigger('app.created', $this, compact("data","id")); + $cache_data = $results->bottom(); + return $id; + }else{ + return "应用创建中发生错误,请重试!"; + } + }else{ + $status = $dbh->update($this->table->oauth_clients,$data," id=$id "); + if($status) + { + $results = $this->events()->trigger('app.eidted', $this, compact("data","id")); + $cache_data = $results->bottom(); + return true; + }else{ + return "应用编辑中发生错误,请重试"; + } + } + + }//appCreate + + //删除App + public function delete($id) + { + if(!is_numeric($id) || $id<1) + { + return "参数错误"; + } + + try{ + $sql = "DELETE FROM {$this->table->oauth_clients} WHERE id=$id"; + $rs = $this->db->exec($sql); + if($rs) + { + return true; + }else{ + return "删除失败"; + } + }catch(Excaption $e){ + return "服务器处理中遇到错误"; + } + + }//delete } \ No newline at end of file diff --git a/application/module/Open/Open.php b/application/module/Open/Open.php index 8a6445df..29534eb9 100644 --- a/application/module/Open/Open.php +++ b/application/module/Open/Open.php @@ -1,26 +1,18 @@ config = \Zend_Registry::get('config'); + + public function __construct($db = NULL,$auth = NULL){ if(empty($db)) { $this->db = \Zend_Registry::get('db'); @@ -28,39 +20,27 @@ abstract class open extends \Zend_Controller_Plugin_Abstract implements openexte $this->db = $db; } - if(empty($auth)) - { - $this->auth = \Zend_Auth::getInstance(); - if($this->auth->hasIdentity()) - { - $this->user = $this->auth->getIdentity(); - } - }else{ - $this->auth = false; - } + $this->config = \Zend_Registry::get('config'); + + $Listener = new Listener(); + @$this->events()->attachAggregate($Listener); + + $this->table = new \Helpers\Table(); } - //检查用户资料完整性 - public function checkinfo() + public function events(\Zend_EventManager_EventCollection $events = NULL) + { + if ($events !== NULL) { + $this->events = $events; + } elseif ($this->events === NULL) { + $this->events = new \Zend_EventManager_EventManager(__CLASS__); + } + return $this->events; + } + + public function clientCredentials() { - if($this->auth === false) - { - return "未登陆"; - } - include_once("Users.php"); - $user = new \Users($this->db); - $info = $user->getUserInfo($this->user->id); - - foreach($this->checkFiled as $v) - { - if(empty($info[$v])) - { - return "请完善个人信息"; - } - } - - return true; } } \ No newline at end of file diff --git a/application/module/Reference/Reference.php b/application/module/Reference/Reference.php index bb9731dd..0b8fc73c 100644 --- a/application/module/Reference/Reference.php +++ b/application/module/Reference/Reference.php @@ -16,6 +16,7 @@ class Reference public $keyword; public $order; public $sort = "DESC"; + public $field; public $reftype; @@ -176,6 +177,24 @@ class Reference { $wheresql[] = " ({$this->table->reference}.title LIKE '%{$this->keyword}%' OR {$this->table->reference}.reference LIKE '%{$this->keyword}%') "; } + + if(!empty($this->field)) + { + foreach($this->field as $k=>$v) + { + if(!empty($v)) + { + if(!is_numeric($v)) $v="'{$v}'"; + $wheresql[] = " ({$this->table->reference}.{$k}={$v} ) "; + }else{ + if(is_numeric($v)) + $wheresql[] = " ({$this->table->reference}.{$k} IS NULL OR {$this->table->reference}.{$k}=0 ) "; + else + $wheresql[] = " ({$this->table->reference}.{$k} IS NULL ) "; + }//if(empty($v) + }//foreach + } + if(count($wheresql)>0) { $wheresql = " WHERE ".join(" AND ",$wheresql); @@ -517,4 +536,43 @@ class Reference } } + //按年份获得文献数量 + public function countByYear() + { + $sql = "SELECT count(id) as num,year FROM {$this->table->reference} GROUP BY year ORDER BY year DESC"; + $rs = $this->db->query($sql); + $rows = $rs->fetchAll(); + + return $rows; + } + + //获得作者 + public function getAuthorByReference($id,$join = false) + { + if(is_numeric($id)) + { + $sql = "SELECT * FROM {$this->table->reference_author} WHERE id=$id ORDER BY place ASC"; + $rs = $this->db->query($sql); + if(!$join) + { + return $rs->fetchAll(); + }else{ + foreach($rows = $rs->fetchAll() as $k=>$v) + { + $rows[$k] = (string)$v['firstname'].$v['lastname']; + } + return $rows; + } + } + + if(is_array($id)) + { + $sql = "SELECT * FROM {$this->table->reference_author} WHERE id IN (".join(",",$id).")"; + $rs = $this->db->query($sql); + return $rs->fetchAll(); + } + + return; + } + } From 8d89e9f43578129842a435da459c1c56b7085749 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Mon, 4 Nov 2013 09:04:07 +0000 Subject: [PATCH 028/173] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86ris=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=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 | 21 +++ .../views/scripts/data/ref-risoutput.phtml | 50 ++++++ application/module/Reference/Reference.php | 22 +++ application/module/Reference/RisOutput.php | 153 ++++++++++++++++++ 4 files changed, 246 insertions(+) create mode 100644 application/admin/views/scripts/data/ref-risoutput.phtml create mode 100644 application/module/Reference/RisOutput.php diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index 5389eabf..3ee7db2a 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -2,6 +2,7 @@ use Helpers\View as view; use Reference\Reference; use Reference\Ris; +use Reference\RisOutput; use Helpers\dbh; use \Files\Files; @@ -1402,9 +1403,29 @@ class Admin_DataController extends Zend_Controller_Action if(!empty($submit)) { + $mode = $this->_getParam('mode'); + $risOutput = new RisOutput(); + $preData = $risOutput->preRead($mode); + + $risData = $risOutput->processArrayDataToRisData($preData); + + $risText = $risOutput->output($risData); + view::Dump($risText); } }//ris output + + if($ac == "ristest") + { + $this->_helper->viewRenderer('ref-ris'); + $submit = $this->_getParam('submit'); + + if(!empty($submit)) + { + $ris = new \Reference\Ris(); + view::Dump($ris->processRis(NULL,$this->_getParam('ristext')),false); + } + } }//文献管理 refAction() diff --git a/application/admin/views/scripts/data/ref-risoutput.phtml b/application/admin/views/scripts/data/ref-risoutput.phtml new file mode 100644 index 00000000..d12726d0 --- /dev/null +++ b/application/admin/views/scripts/data/ref-risoutput.phtml @@ -0,0 +1,50 @@ +headTitle($this->config->title->site); +$this->headTitle('后台管理'); +$this->headTitle()->setSeparator(' - '); +$this->breadcrumb('首页'); +$this->breadcrumb('数据管理'); +$this->breadcrumb('文献管理'); +$this->breadcrumb()->setSeparator(' > '); +$this->theme->AppendPlus($this,'colorbox'); +$this->theme->AppendPlus($this,"uploadify"); +$this->theme->AppendPlus($this,'admin_plugin'); +?> + +
      +
      + partial('data/left.phtml'); ?> +
      +
      +
      + partial('data/ref-nav.phtml',array('ac'=>$this->ac)); ?> +
      + error)) { ?> + error ?> + + msg)) { ?> + msg ?> + +

      RIS导出

      +
      + +
      + years)) { ?> + 按年份 : + years as $k=>$v){ ?> + () + +
      + +
      + +
      + 其它方式:全部 +
      + + +
      +
      + \ No newline at end of file diff --git a/application/module/Reference/Reference.php b/application/module/Reference/Reference.php index 0b8fc73c..a38a9627 100644 --- a/application/module/Reference/Reference.php +++ b/application/module/Reference/Reference.php @@ -575,4 +575,26 @@ class Reference return; } + //获得标签 + public function getTagsByReference($id,$single = false) + { + if(is_numeric($id)) + { + $sql = "SELECT * FROM {$this->table->reference_tag} WHERE id=$id"; + $rs = $this->db->query($sql); + if(!$single) + { + return $rs->fetchAll(); + }else{ + foreach($rows = $rs->fetchAll() as $k=>$v) + { + $rows[$k] = (string)$v['tag']; + } + return $rows; + } + } + + return; + } + } diff --git a/application/module/Reference/RisOutput.php b/application/module/Reference/RisOutput.php new file mode 100644 index 00000000..842b2ba2 --- /dev/null +++ b/application/module/Reference/RisOutput.php @@ -0,0 +1,153 @@ +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + + //$Listener = new Listener(); + //@$this->events()->attachAggregate($Listener); + + $this->table = new \Helpers\Table(); + } + + public function events(\Zend_EventManager_EventCollection $events = NULL) + { + if ($events !== NULL) { + $this->events = $events; + } elseif ($this->events === NULL) { + $this->events = new \Zend_EventManager_EventManager(__CLASS__); + } + return $this->events; + } + + //读取数据 + public function preRead($mode = "all") + { + if($mode == "all") + { + $sql = "SELECT * FROM {$this->table->reference} ORDER BY year DESC,title ASC,id ASC"; + $rs = $this->db->query($sql); + return $rs->fetchAll(); + } + + + }//preRead + + //将数据组成RIS数组格式 + public function processArrayDataToRisData($arrayData,$risPrior = true,$mixAuthor = true,$mixTags = true) + { + if(!is_array($arrayData)) + { + return false; + } + + $risData = array(); + + if($risPrior === true) + { + $risReader = new RISReader(); + } + + $this->ris = new Ris(); + $this->attr = $this->ris->attr; + $this->attr_flip = array_flip($this->ris->attr); + unset($this->ris); + + $this->reference = new Reference(); + + foreach($arrayData as $k=>$v) + { + $risData[$k] = $this->transformToRis($v); + if($mixAuthor === true || $mixTags === true) + { + if($mixAuthor === true) + { + $author = $this->reference->getAuthorByReference($v['id'],true); + if(is_array($author) && count($author)>0) + { + $risData[$k] = array_merge($risData[$k],array("AU"=>$author)); + } + unset($author); + }//mixAuthor + + if($mixTags === true) + { + $tags = $this->reference->getTagsByReference($v['id'],true); + if(is_array($tags) && count($tags) > 0) + { + $risData[$k] = array_merge($risData[$k],array("KW"=>$tags)); + } + unset($tags); + } + } + + if(!is_array($risData[$k]) || count($risData[$k]) < 1) + { + unset($risData[$k]); + } + + unset($arrayData[$k]); + } + + return $risData; + }//processArrayDataToRisData + + //单条记录的整编 + public function transformToRis($record) + { + $arr = array(); + + foreach($record as $k=>$v) + { + if(!empty($v)) + { + if(isset($this->attr_flip[$k])) + { + //echo $k ."-". $this->attr_flip[$k] . '-' .$v; + //echo "
      "; + $arr[$this->attr_flip[$k]] = array(0=>$v); + } + } + } + //echo "
      "; + return $arr; + }//transformToRis + + //输出成文件 + public function output($risData) + { + $risWirte = new RISWriter(); + return @$risWirte->writeRecords($risData); + }//output +} From 838afc1d5dc964217916e6858146c442fc84b32a Mon Sep 17 00:00:00 2001 From: wlx Date: Mon, 4 Nov 2013 12:09:57 +0000 Subject: [PATCH 029/173] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E7=8C=AE?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/views/scripts/data/ref.phtml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/application/admin/views/scripts/data/ref.phtml b/application/admin/views/scripts/data/ref.phtml index 7813e18a..f3b3afcb 100644 --- a/application/admin/views/scripts/data/ref.phtml +++ b/application/admin/views/scripts/data/ref.phtml @@ -75,11 +75,16 @@ table thead tr th {background:#EBF2F6;} $autoindex++;?> - []  + []  + {reference->getAuthorByReference($item['id'],true); echo count($authors) ? join(",",$authors):'未知作者'; ?>}  {未知标题':$item['title'] ?>}  {未知期刊':$item['publisher'] ?>}  {未知年份':$item['year'] ?>}  + From 332556997083314ec7dd67a6d0b3cb060855e50c Mon Sep 17 00:00:00 2001 From: wlx Date: Mon, 4 Nov 2013 13:26:00 +0000 Subject: [PATCH 030/173] =?UTF-8?q?=E4=B8=8D=E8=BE=93=E5=87=BA=E5=B7=B2?= =?UTF-8?q?=E7=BB=8F=E6=9C=89RIS=E5=86=85=E5=AE=B9=E7=9A=84=E6=96=87?= =?UTF-8?q?=E7=8C=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/module/Reference/RisOutput.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/module/Reference/RisOutput.php b/application/module/Reference/RisOutput.php index 842b2ba2..0a95d24d 100644 --- a/application/module/Reference/RisOutput.php +++ b/application/module/Reference/RisOutput.php @@ -56,7 +56,7 @@ class RisOutput { if($mode == "all") { - $sql = "SELECT * FROM {$this->table->reference} ORDER BY year DESC,title ASC,id ASC"; + $sql = "SELECT * FROM {$this->table->reference} where length(ris)<10 ORDER BY year DESC,title ASC,id ASC"; $rs = $this->db->query($sql); return $rs->fetchAll(); } From 3cd2e1676693c71b7dc349aac1ad7e4f818223b2 Mon Sep 17 00:00:00 2001 From: wlx Date: Mon, 4 Nov 2013 13:27:32 +0000 Subject: [PATCH 031/173] =?UTF-8?q?=E4=BC=98=E5=8C=96RIS=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/module/Reference/RisOutput.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/module/Reference/RisOutput.php b/application/module/Reference/RisOutput.php index 0a95d24d..44b7151f 100644 --- a/application/module/Reference/RisOutput.php +++ b/application/module/Reference/RisOutput.php @@ -56,7 +56,7 @@ class RisOutput { if($mode == "all") { - $sql = "SELECT * FROM {$this->table->reference} where length(ris)<10 ORDER BY year DESC,title ASC,id ASC"; + $sql = "SELECT * FROM {$this->table->reference} where length(ris)<10 or ris is null ORDER BY year DESC,title ASC,id ASC"; $rs = $this->db->query($sql); return $rs->fetchAll(); } From 8c3d9cf7609b45f9f6b4b29b5d7f6afcb2f9f585 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Tue, 5 Nov 2013 02:23:49 +0000 Subject: [PATCH 032/173] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=B8=AD=E5=BF=83=E6=96=87=E7=8C=AE=E7=9A=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controllers/DataController.php | 21 +++++++++++-------- .../views/scripts/data/ref-mdref-form.phtml | 1 + .../admin/views/scripts/data/ref.phtml | 4 ++++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index 3ee7db2a..b7675d6d 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -1154,15 +1154,13 @@ class Admin_DataController extends Zend_Controller_Action } $this->view->reference = $reference; + $this->view->page = $this->_getParam('page'); + $this->view->pagelimit = 12; //文献首页 if(empty($ac)) { - $this->view->referenceType = $reference->referenceType(); - - $this->view->page = $this->_getParam('page'); - $this->view->pagelimit = 12; - + $this->view->referenceType = $reference->referenceType(); view::addPaginator($reference->fetchReferences(),$this, $this->view->pagelimit); $this->view->years = $reference->countByYear(); return true; @@ -1170,23 +1168,25 @@ class Admin_DataController extends Zend_Controller_Action else if ($ac == "water") { $this->view->referenceType = $reference->referenceType(); - view::addPaginator($reference->fetchThemeReferences('water'),$this,10); + view::addPaginator($reference->fetchThemeReferences('water'),$this,$this->view->pagelimit); return true; } else if ($ac == "westdc") { $this->view->referenceType = $reference->referenceType(); - view::addPaginator($reference->fetchWestdcReferences(),$this,10); + view::addPaginator($reference->fetchWestdcReferences(),$this,$this->view->pagelimit); return true; } else if ($ac == "todo") { $this->view->referenceType = $reference->referenceType(); - view::addPaginator($reference->fetchTodoReferences(),$this,10); + view::addPaginator($reference->fetchTodoReferences(),$this,$this->view->pagelimit); return true; } unset($this->view->reference); + unset($this->view->page); + unset($this->view->pagelimit); //添加 if($ac == "add") @@ -1411,7 +1411,10 @@ class Admin_DataController extends Zend_Controller_Action $risData = $risOutput->processArrayDataToRisData($preData); $risText = $risOutput->output($risData); - view::Dump($risText); + + echo "
      ";
      +				echo $risText;
      +				echo "
      "; } }//ris output diff --git a/application/admin/views/scripts/data/ref-mdref-form.phtml b/application/admin/views/scripts/data/ref-mdref-form.phtml index 6721ff29..5905972c 100644 --- a/application/admin/views/scripts/data/ref-mdref-form.phtml +++ b/application/admin/views/scripts/data/ref-mdref-form.phtml @@ -15,6 +15,7 @@
      diff --git a/application/admin/views/scripts/data/ref.phtml b/application/admin/views/scripts/data/ref.phtml index f3b3afcb..9670014e 100644 --- a/application/admin/views/scripts/data/ref.phtml +++ b/application/admin/views/scripts/data/ref.phtml @@ -38,6 +38,10 @@ table thead tr th {background:#EBF2F6;} msg ?> + ac == 'westdc'){ ?> + + + years)) { ?> years as $k=>$v){ ?> () From ff2f657cb64b54a240f1cb1586fb66477e7b0537 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Tue, 5 Nov 2013 03:57:01 +0000 Subject: [PATCH 033/173] =?UTF-8?q?=E8=A7=84=E8=8C=83=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8D=E5=92=8Cnamespace=E5=91=BD=E5=90=8D=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=B0=8F=E5=BF=83=E4=B8=BA=E5=A4=A7=E4=BA=9B=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0Application=E7=B1=BB=E7=94=A8=E6=9D=A5?= =?UTF-8?q?=E5=A4=84=E7=90=86=E7=94=B3=E8=AF=B7=E7=9B=B8=E5=85=B3=E4=BA=8B?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/Order/Event/ApplicationEvent.php | 7 +++ .../Order/Handler/ApplicationHandler.php | 36 ++++++++++++++ .../module/Order/Manager/Application.php | 48 +++++++++++++++++++ application/module/Order/Order.php | 8 ++-- .../Order/listener/ApplicationListener.php | 25 ++++++++++ .../module/Order/listener/ManagerEvents.php | 2 +- .../module/Order/listener/ManagerListener.php | 4 +- .../module/Order/listener/OrderEvents.php | 2 +- .../module/Order/listener/OrderListener.php | 8 ++-- .../module/Order/listener/PdfEvents.php | 2 +- .../module/Order/listener/PdfFormEvents.php | 2 +- .../module/Order/mount/ManagerOperate.php | 4 +- .../module/Order/mount/OrderOperate.php | 8 ++-- application/module/Order/mount/PdfForm.php | 6 +-- application/module/Order/mount/PdfOperate.php | 10 ++-- 15 files changed, 144 insertions(+), 28 deletions(-) create mode 100644 application/module/Order/Event/ApplicationEvent.php create mode 100644 application/module/Order/Handler/ApplicationHandler.php create mode 100644 application/module/Order/Manager/Application.php create mode 100644 application/module/Order/listener/ApplicationListener.php diff --git a/application/module/Order/Event/ApplicationEvent.php b/application/module/Order/Event/ApplicationEvent.php new file mode 100644 index 00000000..7865132f --- /dev/null +++ b/application/module/Order/Event/ApplicationEvent.php @@ -0,0 +1,7 @@ +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + $this->table = new Table(); + } + + public function applicationCheckParam(\Zend_EventManager_Event $e) + { + $data = $e->getParam('data'); + + return true; + } + +} diff --git a/application/module/Order/Manager/Application.php b/application/module/Order/Manager/Application.php new file mode 100644 index 00000000..cc1bf6a6 --- /dev/null +++ b/application/module/Order/Manager/Application.php @@ -0,0 +1,48 @@ +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + + $Listener = new Listener(); + @$this->events()->attachAggregate($Listener); + + $this->table = new \Helpers\Table(); + } + + public function events(\Zend_EventManager_EventCollection $events = NULL) + { + if ($events !== NULL) { + $this->events = $events; + } elseif ($this->events === NULL) { + $this->events = new \Zend_EventManager_EventManager(__CLASS__); + } + return $this->events; + } + + //已经通过的所有申请 + public function passed() + { + + } +} \ No newline at end of file diff --git a/application/module/Order/Order.php b/application/module/Order/Order.php index afc15dbe..cf9ba966 100644 --- a/application/module/Order/Order.php +++ b/application/module/Order/Order.php @@ -1,10 +1,10 @@ event = new \Zend_EventManager_EventManager(); + } + + public function attach(\Zend_EventManager_EventCollection $events) + { + $Handler = new Handler(); + //$events->attach('app.checkParam', array($Handler, 'appCheckParam'), 100); + } + + public function detach(\Zend_EventManager_EventCollection $events) + { + + } + +} \ No newline at end of file diff --git a/application/module/Order/listener/ManagerEvents.php b/application/module/Order/listener/ManagerEvents.php index 2fedd65f..c3e370aa 100644 --- a/application/module/Order/listener/ManagerEvents.php +++ b/application/module/Order/listener/ManagerEvents.php @@ -1,5 +1,5 @@ getMessage()); + view::Dump($e->getMessage()); } return true; diff --git a/application/module/Order/mount/PdfForm.php b/application/module/Order/mount/PdfForm.php index 5c83af22..52024d4a 100644 --- a/application/module/Order/mount/PdfForm.php +++ b/application/module/Order/mount/PdfForm.php @@ -1,10 +1,10 @@ Date: Tue, 5 Nov 2013 03:59:35 +0000 Subject: [PATCH 034/173] =?UTF-8?q?=E5=B0=86Order/listener=E6=94=B9?= =?UTF-8?q?=E4=B8=BAOrder/Listener?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/Order/{listener => Listener}/ApplicationListener.php | 0 application/module/Order/{listener => Listener}/ManagerEvents.php | 0 .../module/Order/{listener => Listener}/ManagerListener.php | 0 application/module/Order/{listener => Listener}/OrderEvents.php | 0 application/module/Order/{listener => Listener}/OrderListener.php | 0 application/module/Order/{listener => Listener}/PdfEvents.php | 0 application/module/Order/{listener => Listener}/PdfFormEvents.php | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename application/module/Order/{listener => Listener}/ApplicationListener.php (100%) rename application/module/Order/{listener => Listener}/ManagerEvents.php (100%) rename application/module/Order/{listener => Listener}/ManagerListener.php (100%) rename application/module/Order/{listener => Listener}/OrderEvents.php (100%) rename application/module/Order/{listener => Listener}/OrderListener.php (100%) rename application/module/Order/{listener => Listener}/PdfEvents.php (100%) rename application/module/Order/{listener => Listener}/PdfFormEvents.php (100%) diff --git a/application/module/Order/listener/ApplicationListener.php b/application/module/Order/Listener/ApplicationListener.php similarity index 100% rename from application/module/Order/listener/ApplicationListener.php rename to application/module/Order/Listener/ApplicationListener.php diff --git a/application/module/Order/listener/ManagerEvents.php b/application/module/Order/Listener/ManagerEvents.php similarity index 100% rename from application/module/Order/listener/ManagerEvents.php rename to application/module/Order/Listener/ManagerEvents.php diff --git a/application/module/Order/listener/ManagerListener.php b/application/module/Order/Listener/ManagerListener.php similarity index 100% rename from application/module/Order/listener/ManagerListener.php rename to application/module/Order/Listener/ManagerListener.php diff --git a/application/module/Order/listener/OrderEvents.php b/application/module/Order/Listener/OrderEvents.php similarity index 100% rename from application/module/Order/listener/OrderEvents.php rename to application/module/Order/Listener/OrderEvents.php diff --git a/application/module/Order/listener/OrderListener.php b/application/module/Order/Listener/OrderListener.php similarity index 100% rename from application/module/Order/listener/OrderListener.php rename to application/module/Order/Listener/OrderListener.php diff --git a/application/module/Order/listener/PdfEvents.php b/application/module/Order/Listener/PdfEvents.php similarity index 100% rename from application/module/Order/listener/PdfEvents.php rename to application/module/Order/Listener/PdfEvents.php diff --git a/application/module/Order/listener/PdfFormEvents.php b/application/module/Order/Listener/PdfFormEvents.php similarity index 100% rename from application/module/Order/listener/PdfFormEvents.php rename to application/module/Order/Listener/PdfFormEvents.php From d007786fb1fe8363d8c2a13ce3b815eb0f8f82d7 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Tue, 5 Nov 2013 04:01:05 +0000 Subject: [PATCH 035/173] =?UTF-8?q?=E5=B0=86Order/mount=E6=94=B9=E4=B8=BAO?= =?UTF-8?q?rder/Mount?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/module/Order/{mount => Mount}/ManagerOperate.php | 0 application/module/Order/{mount => Mount}/OrderOperate.php | 0 application/module/Order/{mount => Mount}/PdfForm.php | 0 application/module/Order/{mount => Mount}/PdfOperate.php | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename application/module/Order/{mount => Mount}/ManagerOperate.php (100%) rename application/module/Order/{mount => Mount}/OrderOperate.php (100%) rename application/module/Order/{mount => Mount}/PdfForm.php (100%) rename application/module/Order/{mount => Mount}/PdfOperate.php (100%) diff --git a/application/module/Order/mount/ManagerOperate.php b/application/module/Order/Mount/ManagerOperate.php similarity index 100% rename from application/module/Order/mount/ManagerOperate.php rename to application/module/Order/Mount/ManagerOperate.php diff --git a/application/module/Order/mount/OrderOperate.php b/application/module/Order/Mount/OrderOperate.php similarity index 100% rename from application/module/Order/mount/OrderOperate.php rename to application/module/Order/Mount/OrderOperate.php diff --git a/application/module/Order/mount/PdfForm.php b/application/module/Order/Mount/PdfForm.php similarity index 100% rename from application/module/Order/mount/PdfForm.php rename to application/module/Order/Mount/PdfForm.php diff --git a/application/module/Order/mount/PdfOperate.php b/application/module/Order/Mount/PdfOperate.php similarity index 100% rename from application/module/Order/mount/PdfOperate.php rename to application/module/Order/Mount/PdfOperate.php From ed711d9a3b946b4c0b5437d246b965d96abdbb39 Mon Sep 17 00:00:00 2001 From: wlx Date: Tue, 5 Nov 2013 04:09:26 +0000 Subject: [PATCH 036/173] change mount to Mount --- application/default/controllers/DataController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/default/controllers/DataController.php b/application/default/controllers/DataController.php index 205529d7..5768028c 100755 --- a/application/default/controllers/DataController.php +++ b/application/default/controllers/DataController.php @@ -697,7 +697,7 @@ class DataController extends Zend_Controller_Action //检查特殊数据服务是否存在 private function checkDataService($uuid) { - $order = new \Order\mount\OrderOperate(); + $order = new \Order\Mount\OrderOperate(); $service = $order->getDataService($uuid); if(empty($service)) From 5d80b35553ddac925deacdaf850cfefcc37d481b Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Tue, 5 Nov 2013 07:57:17 +0000 Subject: [PATCH 037/173] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=B7=B2?= =?UTF-8?q?=E9=80=9A=E8=BF=87=E7=9A=84=E6=9C=8D=E5=8A=A1=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E7=9A=84=E6=90=9C=E7=B4=A2=EF=BC=8C=E5=A2=9E=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=97=B6=E7=9A=84=E7=A1=AE=E8=AE=A4=E6=8C=89?= =?UTF-8?q?=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controllers/DownController.php | 18 +++++++-------- .../admin/views/scripts/down/offline.phtml | 14 +++++++++++- .../down/offlineapps-notreceived.phtml | 2 +- .../module/Order/Event/ApplicationEvent.php | 2 +- .../Order/Handler/ApplicationHandler.php | 4 ++-- .../module/Order/Manager/Application.php | 22 +++++++++++++++++-- 6 files changed, 46 insertions(+), 16 deletions(-) diff --git a/application/admin/controllers/DownController.php b/application/admin/controllers/DownController.php index b28592ff..f7d06304 100644 --- a/application/admin/controllers/DownController.php +++ b/application/admin/controllers/DownController.php @@ -4,6 +4,7 @@ use Files\Files; use Files\Output; use Files\Listener\FileListener; use Order\Manager\Offlineapp; +use Order\Manager\Application; use data\DataService; use Mail\Mail; @@ -1137,16 +1138,15 @@ class Admin_DownController extends Zend_Controller_Action ->setBody($objWriter->save('php://output'));*/ } - $select=$this->db->select(); - $select->from('offlineapp')->where('ts_approved is not null')->where('pdflink is not null')->where('status>=0')->order('ts_created 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; - $this->view->page = $this->_getParam('page'); + + $application = new Application(); + + $this->view->q = $application->keyword = $this->_getParam('q'); + $application->filter = $this->_getParam('filter'); + view::addPaginator($application->passed(),$this,20); + + return true; } //在线数据下载情况,仅针对onlineapp表,自2011-9-8开始记录。 function onlineAction() diff --git a/application/admin/views/scripts/down/offline.phtml b/application/admin/views/scripts/down/offline.phtml index 12e44025..17bbb488 100644 --- a/application/admin/views/scripts/down/offline.phtml +++ b/application/admin/views/scripts/down/offline.phtml @@ -27,8 +27,20 @@
      离线数据服务记录
      -添加新的离线服务记录 | 下载所有离线服务记录 | 自动匹配离线下载用户与网站用户 | 下载服务用户邮箱列表 +添加新的离线服务记录 | 下载所有离线服务记录 | 自动匹配离线下载用户与网站用户 | 下载服务用户邮箱列表 | 下载上月服务记录(科技部上报) + +
      +
      +
      + + + + +
      +
      +
      + paginator)): ?> diff --git a/application/admin/views/scripts/down/offlineapps-notreceived.phtml b/application/admin/views/scripts/down/offlineapps-notreceived.phtml index c9e8f0b2..ca1f62eb 100644 --- a/application/admin/views/scripts/down/offlineapps-notreceived.phtml +++ b/application/admin/views/scripts/down/offlineapps-notreceived.phtml @@ -54,7 +54,7 @@ table thead tr th {background:#EBF2F6;color:#444;} diff --git a/application/module/Order/Event/ApplicationEvent.php b/application/module/Order/Event/ApplicationEvent.php index 7865132f..b8031621 100644 --- a/application/module/Order/Event/ApplicationEvent.php +++ b/application/module/Order/Event/ApplicationEvent.php @@ -1,5 +1,5 @@ db->select(); + $select ->from('offlineapp') + ->where('ts_approved is not null') + ->where('pdflink is not null') + ->where('status>=0') + ->order('ts_created desc'); + if(!empty($this->keyword)) + { + $select ->where(" (username LIKE '%{$this->keyword}%' OR + unit LIKE '%{$this->keyword}%' OR + project_id LIKE '%{$this->keyword}%' OR + project_type LIKE '%{$this->keyword}%' OR + project_leader LIKE '%{$this->keyword}%' OR + project LIKE '%{$this->keyword}%' )"); + } + + return $select; } } \ No newline at end of file From 3ef2748dd11c50d1a0f9d4a9084977fd0e7729a6 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Mon, 11 Nov 2013 02:53:34 +0000 Subject: [PATCH 038/173] =?UTF-8?q?Account=20controller=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=E6=97=A0=E6=B3=95=E7=94=9F=E6=88=90?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/default/controllers/AccountController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/default/controllers/AccountController.php b/application/default/controllers/AccountController.php index 78487b85..fe8aa7ba 100755 --- a/application/default/controllers/AccountController.php +++ b/application/default/controllers/AccountController.php @@ -344,7 +344,7 @@ class AccountController extends Zend_Controller_Action if(empty($captchaword)) { - $this->setCaptcha($captchaword); + $this->setCaptcha($captcha); $this->view->error = "请输入验证码"; return true; } From 6cd975a861433402e0eb72007133a69d52cbac18 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Mon, 11 Nov 2013 08:39:55 +0000 Subject: [PATCH 039/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=B3=A8=E5=86=8C=E7=9A=84=E9=82=AE=E4=BB=B6=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=A2=9E=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=93=8D=E4=BD=9C=E7=9A=84=E7=B1=BB=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/AccountController.php | 89 ++--- application/module/Users/Account.php | 332 ++++++++++++++++++ application/module/Users/Event/EditEvent.php | 11 + application/module/Users/Event/LoginEvent.php | 12 + application/module/Users/Event/PwdEvent.php | 13 + .../module/Users/Event/RegisterEvent.php | 13 + application/module/Users/Gravatar.php | 20 ++ .../module/Users/Listener/AccountListener.php | 64 ++++ .../module/Users/Listener/EditListener.php | 35 ++ .../module/Users/Listener/PwdListener.php | 30 ++ application/module/Users/Member.php | 138 ++++++++ .../module/Users/Operation/EditOperate.php | 88 +++++ .../module/Users/Operation/LoginOperate.php | 111 ++++++ .../module/Users/Operation/PwdOperate.php | 94 +++++ .../Users/Operation/RegisterOperate.php | 192 ++++++++++ 15 files changed, 1198 insertions(+), 44 deletions(-) create mode 100644 application/module/Users/Account.php create mode 100644 application/module/Users/Event/EditEvent.php create mode 100644 application/module/Users/Event/LoginEvent.php create mode 100644 application/module/Users/Event/PwdEvent.php create mode 100644 application/module/Users/Event/RegisterEvent.php create mode 100644 application/module/Users/Gravatar.php create mode 100644 application/module/Users/Listener/AccountListener.php create mode 100644 application/module/Users/Listener/EditListener.php create mode 100644 application/module/Users/Listener/PwdListener.php create mode 100644 application/module/Users/Member.php create mode 100644 application/module/Users/Operation/EditOperate.php create mode 100644 application/module/Users/Operation/LoginOperate.php create mode 100644 application/module/Users/Operation/PwdOperate.php create mode 100644 application/module/Users/Operation/RegisterOperate.php diff --git a/application/default/controllers/AccountController.php b/application/default/controllers/AccountController.php index fe8aa7ba..60d8a07f 100755 --- a/application/default/controllers/AccountController.php +++ b/application/default/controllers/AccountController.php @@ -1,4 +1,7 @@ view->pageID = "account-secure"; - include_once("helper/view.php"); include_once("Users.php"); $usr = new Users($this->db); @@ -261,17 +263,18 @@ class AccountController extends Zend_Controller_Action if ($form->getValue('unit')) $u->unit=$form->getValue('unit'); if ($form->getValue('project')) $u->project=$form->getValue('project'); if ($u->save()) { - //发送欢迎邮件 - $mail=new WestdcMailer($this->view->config->smtp); - $body=file_get_contents($this->view->config->register->email->template); - $body=str_replace("[username]",$formData['username'],$body); - $mail->setBodyText($body); - $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); - $mail->addTo($formData['email']); - //中文标题有乱码,在1.5版本中尚未解决 - //ref: http://framework.zend.com/issues/browse/ZF-2532 - $mail->setSubject('欢迎使用中国西部环境与生态数据中心'); - $mail->send(); + + //注册邮件 + $mail_template = "users-register"; + $mail_data = array( + 'name'=>$formData['username'], + ); + + $mail = new Mail(); + + $mail->loadTemplate($mail_template,$mail_data); + $mail->addTo($formData['email'],$formData['username']); + $mail->send(); //自动登录系统 $this->login($formData['username'],$formData['password']); @@ -285,7 +288,6 @@ class AccountController extends Zend_Controller_Action function loginAction() { - include_once("helper/view.php"); $success=false; @@ -536,22 +538,21 @@ class AccountController extends Zend_Controller_Action $sql="update users set activation=? where email=?"; $uid=uniqid(); $db->query($sql,array($uid,$formData['email'])); - $mail=new WestdcMailer($this->view->config->smtp); - $body="尊敬的西部数据中心用户: - 有人提出了针对此用户名的密码重置请求。 - - 用户名:"; - $body.=$username; - $body.=" + + //发邮件 + $mail_template = "users-changepassword"; + $mail_data = array( + 'name'=>$username, + 'url' => view::getHostLink()."/account/fetchpwd/".$username."/".$uid + ); + + $mail = new Mail(); + + $mail->loadTemplate($mail_template,$mail_data); + $mail->addTo($formData['email'],$username); + $mail->send(); + - 若想重置您的密码请打开下面的链接,否则请忽略此邮件,一切如常。 -"; - $body.="http://westdc.westgis.ac.cn/account/fetchpwd/".$username."/".$uid; - $mail->setBodyText($body); - $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); - $mail->addTo($formData['email']); - $mail->setSubject('密码已重置'); - $mail->send(); $this->view->messages[]='请检查您的新邮件中的确认激活链接。'; $this->view->form=false;//do not echo form } else @@ -567,22 +568,22 @@ class AccountController extends Zend_Controller_Action { $sql="update users set salt='',activation='',password=md5('".$tmp_pwd."') where username=? and activation=?"; $db->query($sql,array($login,$key)); - $mail=new WestdcMailer($this->view->config->smtp); - $body="尊敬的西部数据中心用户: - 您的密码已修改。 - - 用户名:"; - $body.=$login; - $body.="密码:".$tmp_pwd; - $body.=" - http://westdc.westgis.ac.cn/account/login"; - $mail->setBodyText($body); - $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); - $mail->addTo($urow->email); - $mail->setSubject('您的新密码'); - $mail->send(); - $this->view->messages[]='请查收您新邮件中的新密码'; - $this->view->form=false;//do not echo form + + //发邮件 + $mail_template = "users-changepassword"; + $mail_data = array( + 'name'=>$login, + 'tmp_pwd' => $tmp_pwd + ); + + $mail = new Mail(); + + $mail->loadTemplate($mail_template,$mail_data); + $mail->addTo($urow->email,$login); + $mail->send(); + + $this->view->messages[]='请查收您新邮件中的新密码'; + $this->view->form=false;//do not echo form } } diff --git a/application/module/Users/Account.php b/application/module/Users/Account.php new file mode 100644 index 00000000..e692f95c --- /dev/null +++ b/application/module/Users/Account.php @@ -0,0 +1,332 @@ +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + + + } + + public function events(\Zend_EventManager_EventCollection $events = NULL) + { + if ($events !== NULL) { + $this->events = $events; + } elseif ($this->events === NULL) { + $this->events = new \Zend_EventManager_EventManager(__CLASS__); + } + return $this->events; + } + + //获取账号信息,数组 + public function getAccountInfo($id = 0) + { + if($id == 0) + { + $id = view::User('id'); + } + $sql = "SELECT * FROM {$this->memberTable} WHERE id=$id"; + $rs = $this->db->query($sql); + return $rs->fetch(); + } + + //注册 + public function register($data) + { + + $params = compact('data'); + $results = $this->events()->trigger('register.checkParam', $this, $params); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + if(!is_array($cache_data)) + { + return array('error'=>$cache_data); + }else{ + return $cache_data; + } + } + + $results = $this->events()->trigger('register.checkUser', $this, $params); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + if(!is_array($cache_data)) + { + return array('error'=>$cache_data); + }else{ + return $cache_data; + } + } + + $loginData = array( + 'username'=>$data['username'], + 'password'=>$data['password'] + ); + + $data['password'] = md5($data['password']); + $data['usertype'] = "member"; + unset($data['confirm_password']); + + $dbh = new dbh(); + + $id = $dbh->insert($this->memberTable,$data,true); + + if(!empty($id) && is_numeric($id)) + { + $this->storeLogin($loginData); + $mb = new Member(); + $mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]); //username, md5(password) + $params = compact('data','id'); + $results = $this->events()->trigger('register.success', $this, $params); + return array("success" => 1); + }else{ + if($id === false) + { + return array('error'=>'服务器开小差了,请稍后再试'); + }else{ + return array('error'=>'服务器处理中遇到错误,请联系管理员'); + } + } + + }//register + + //登陆 + public function login($data) + { + $results = $this->events()->trigger('login.checkParam', $this, compact('data')); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + if(!is_array($cache_data)) + { + return array('error'=>$cache_data); + }else{ + return $cache_data; + } + } + + $state = $this->storeLogin($data); + + $mb = new Member(); + $mb->putcookie($data[$this->FieldUsername],md5($data[$this->FieldPasword])); + + return $state; + }//login + + //storeLogin + public function storeLogin($data) + { + $auth = \Zend_Auth::getInstance(); + $authAdapter = new \Zend_Auth_Adapter_DbTable($this->db); + $authAdapter->setTableName($this->memberTable) + ->setIdentityColumn($this->FieldUsername) + ->setCredentialColumn($this->FieldPasword); + $authAdapter->setIdentity($data[$this->FieldUsername])->setCredential(md5($data[$this->FieldPasword])); + $result = $auth->authenticate($authAdapter); + if ($result->isValid()) { + + $user = $authAdapter->getResultRowObject(null,$this->FieldPasword); + $email = $user->email; + $results = $this->events()->trigger('login.success.createAvatar', $this, compact('email')); + $user->avatar = $results->bottom(); + $auth->getStorage()->write($user); + + $id = $user->id; + @$results = $this->events()->trigger('login.success.updateStatus', $this, compact('id')); + + return array('success'=>1); + } + return array('error'=>'处理中发现错误,请重试'); + } + + //注册信息参数 + public function getParam(\Zend_Controller_Request_Abstract $request) + { + $data = array( + 'username'=>$request->getParam('username'), + 'password'=>$request->getParam('password'), + 'confirm_password'=>$request->getParam('confirm_password'), + 'email'=>$request->getParam('email'), + 'realname'=>$request->getParam('realname') + ); + return $data; + } + + //获取用户账户修改参数 + public function getEditParam(\Zend_Controller_Request_Abstract $request) + { + $type = $request->getParam('type'); + + if($type == "general") + { + $data = array( + 'realname'=>$request->getParam('realname'), + 'signature'=>$request->getParam('signature'), + 'description'=>$request->getParam('description') + ); + } + + if($type == "password") + { + $data = array( + 'password' => $request->getParam('password'), + 'password_new'=>$request->getParam('password_new'), + 'password_confirm'=>$request->getParam('password_confirm') + ); + } + return $data; + } + + //编辑 + public function edit($data,$type) + { + $results = $this->events()->trigger('edit.checkParam', $this, compact('data','type')); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + return $cache_data; + } + + if($type == "general") + { + $data['signature'] = htmlspecialchars($data['signature']); + $data['description'] = htmlspecialchars($data['description']); + }else if($type == "password") + { + $data['password'] = md5($data['password_new']); + unset($data['password_new']); + unset($data['password_confirm']); + }else{ + return "参数错误"; + } + + $dbh = new dbh(); + $uid = view::User('id'); + if($dbh->update($this->memberTable,$data," id=$uid") === true) + { + return true; + }else{ + return false; + } + } + + //找回密码 + public function getMyPassword($email) + { + $results = $this->events()->trigger('pwd.forgot.checkParam', $this, compact('email')); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + return $cache_data; + } + + $sql = "SELECT * FROM {$this->memberTable} WHERE email='$email'"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + + if(!isset($row['username']) || empty($row['username'])) + { + return array('error'=>"此邮箱并未注册",'place'=>'email'); + } + + $salt = md5($email.'---'.$row['username']); + + $sql = "UPDATE {$this->memberTable} SET salt='$salt' WHERE id={$row['id']}"; + $state = $this->db->exec($sql); + + if($state<1) + { + return array('error'=>"处理中出现错误,请重试",'place'=>'email'); + } + + $mail_template = "forgotpassword"; + $mail_data = array( + 'name'=>$row['realname'], + 'link'=> view::getHostLink().'/account/getpassword/salt/'.$salt + ); + + $mail = new Mail(); + + $mail->loadTemplate($mail_template,$mail_data); + $mail->addTo($email,$row['realname']); + $mail->send(); + + return array("success"=>1); + } + + //重置密码 + public function resetPassword($data) + { + $results = $this->events()->trigger('pwd.reset.checkParam', $this, compact('data')); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + return $cache_data; + } + + $sql = "SELECT * FROM {$this->memberTable} WHERE salt=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($data['salt'])); + $row = $sth->fetch(); + + if(!isset($row['username']) || empty($row['username'])) + { + return array('error'=>"您提供的校验码不正确,请重新申请重置密码",'place'=>'confirm_password'); + } + + if($row['username'] !== $data['username']) + { + return array('error'=>"您提供的校验码不正确,请重新申请重置密码",'place'=>'confirm_password'); + } + + $sql = "UPDATE {$this->memberTable} SET password='".md5($data['password'])."',salt='' WHERE id={$row['id']}"; + $this->db->exec($sql); + + $mail_template = "getpassworded"; + $mail_data = array( + 'name'=>$row['realname'], + ); + $mail = new Mail(); + $mail->loadTemplate($mail_template,$mail_data); + $mail->addTo($row['email'],$row['realname']); + $mail->send(); + + return true; + + } + +} \ No newline at end of file diff --git a/application/module/Users/Event/EditEvent.php b/application/module/Users/Event/EditEvent.php new file mode 100644 index 00000000..99488769 --- /dev/null +++ b/application/module/Users/Event/EditEvent.php @@ -0,0 +1,11 @@ +event = new \Zend_EventManager_EventManager(); + + if(empty($type)) + { + $type = "both"; + } + + $this->type = $type; + } + + public function attach(\Zend_EventManager_EventCollection $events) + { + if($this->type == "both") + { + $this->attachRegisterEvents($events); + $this->attachLoginEvents($events); + } + + if($this->type == "register") + { + $this->attachRegisterEvents($events); + } + + if($this->type == "login") + { + $this->attachLoginEvents($events); + } + } + + public function detach(\Zend_EventManager_EventCollection $events) + { + + } + + private function attachRegisterEvents(\Zend_EventManager_EventCollection $events) + { + $_Events = new RegisterOperate(); + $events->attach('register.checkParam', array($_Events, 'checkParam'), 100); + $events->attach('register.checkUser', array($_Events, 'checkUser'), 80); + $events->attach('register.success', array($_Events, 'registerSuccess'), 50); + } + + private function attachLoginEvents(\Zend_EventManager_EventCollection $events) + { + $_Events = new LoginOperate(); + $events->attach('login.checkParam', array($_Events, 'checkParam'), 100); + $events->attach('login.success.updateStatus', array($_Events, 'updateStatus'), 50); + $events->attach('login.success.createAvatar', array($_Events, 'createAvatar'), 50); + } + +} diff --git a/application/module/Users/Listener/EditListener.php b/application/module/Users/Listener/EditListener.php new file mode 100644 index 00000000..bcf2ce56 --- /dev/null +++ b/application/module/Users/Listener/EditListener.php @@ -0,0 +1,35 @@ +event = new \Zend_EventManager_EventManager(); + + if(empty($type)) + { + $type = "both"; + } + + $this->type = $type; + } + + public function attach(\Zend_EventManager_EventCollection $events) + { + $_Events = new EditOperate(); + $events->attach('edit.checkParam', array($_Events, 'checkParam'), 100); + $events->attach('edit.success', array($_Events, 'editSuccess'), 50); + } + + public function detach(\Zend_EventManager_EventCollection $events) + { + + } + +} diff --git a/application/module/Users/Listener/PwdListener.php b/application/module/Users/Listener/PwdListener.php new file mode 100644 index 00000000..c1afb947 --- /dev/null +++ b/application/module/Users/Listener/PwdListener.php @@ -0,0 +1,30 @@ +event = new \Zend_EventManager_EventManager(); + } + + public function attach(\Zend_EventManager_EventCollection $events) + { + $_Events = new PwdOperate(); + $events->attach('pwd.forgot.checkParam', array($_Events, 'forgotPwdCheckParam'), 100); + $events->attach('pwd.forgot.sendmail', array($_Events, 'sendGetPasswordMail'), 50); + $events->attach('pwd.reset.checkParam', array($_Events, 'resetPwdCheckParam'), 100); + $events->attach('pwd.reset.sendmail', array($_Events, 'sendGetPasswordMail'), 50); + } + + public function detach(\Zend_EventManager_EventCollection $events) + { + + } + +} diff --git a/application/module/Users/Member.php b/application/module/Users/Member.php new file mode 100644 index 00000000..fcb2bce2 --- /dev/null +++ b/application/module/Users/Member.php @@ -0,0 +1,138 @@ +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + + if(!empty($_COOKIE['scr'])) + { + $this->scr = $_COOKIE['scr']; + } + if(!empty($_COOKIE['user'])) + { + $this->user= $_COOKIE['user']; + } + } + + + /** + * 检测cookie + */ + public function checkcookie() + { + $uname = $this->user; + $hash = $this->scr; + + if(!empty($uname) && !empty($hash)) + { + if (preg_match("/[<|>|#|$|%|^|*|(|)|{|}|'|\"|;|:]/i",$uname) || preg_match("/[<|>|#|$|%|^|*|(|)|{|}|'|\"|;|:]/i",$hash)) + { + $this->mid=0; + return false; + } + else{ + $sql = "select {$this->FieldUsername} as userid,{$this->FieldPasword} as pwd from {$this->memberTable} where {$this->FieldUsername}='$uname'"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + $scr = $this->makescr($row['userid'],$row['pwd']); + + if($hash == $scr) + { + $this->srpwd=$row['pwd']; + return true; + } + else { + return false; + } + }//cookie安全 + }else { + return false; + }//exit + }//function checkcookie + + /** + * putcookie + * + * 登陆成功后放置cookie,包含安全码 + * + * @param String $uname + * @param String $pwd + * @param Int $time + */ + public function putcookie($uname,$pwd,$time = 604800) + { + try { + $scrString = $this->makescr($uname,$pwd);//加密验证串:防止用户密码被盗;防止伪造cookie。 + + if(!is_numeric($time)) + { + $time = 604800; + } + + setcookie('user',$uname,time()+$time,'/'); + setcookie('scr',$scrString,time()+$time,'/'); + + return true; + } catch (Exception $e) { + return false; + } + + }//function putcookie + + /** + * 生成安全码 + * + * @param String $u + * @param String $p + */ + public function makescr($u,$p) + { + return substr(md5($u.$p.$this->ck),3,20); + } + + /** + * 清除cookie + */ + static function flushcookie() + { + setcookie('user','',time()-99999,'/'); + setcookie('scr','',time()-99999,'/'); + } + + public function getUser() + { + $sql = "SELECT * FROM ".$this->memberTable." m ORDER BY m.id DESC"; + $rs = $this->db->query($sql); + return $rs->fetchAll(); + } + +} \ No newline at end of file diff --git a/application/module/Users/Operation/EditOperate.php b/application/module/Users/Operation/EditOperate.php new file mode 100644 index 00000000..a31a1d71 --- /dev/null +++ b/application/module/Users/Operation/EditOperate.php @@ -0,0 +1,88 @@ +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + } + + public function checkParam(\Zend_EventManager_Event $e){ + + $data = $e->getParam('data'); + $type = $e->getParam('type'); + + if($type == 'general') + { + + if(empty($data['realname'])) + { + return "请输入真实姓名"; + } + + if(mb_strlen($data['realname'],"UTF-8")>10 ) + { + return "姓名不要超过10个字"; + } + } + + if($type == "password") + { + if(strlen($data['password'])>18 || strlen($data['password_new'])>18) + { + return "密码过长"; + } + if(strlen($data['password_new'])<=6 || strlen($data['password_confirm'])<=6) + { + return "密码过短"; + } + if(md5($data['password_new']) != md5($data['password_confirm'])) + { + return "两次输入的密码不同"; + } + + $uid = view::User('id'); + $sql = "SELECT {$this->FieldPasword} FROM {$this->tbl_member} WHERE id=$uid"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + + if(md5($data['password']) != $row[$this->FieldPasword]) + { + return "原密码不正确"; + } + } + + return true; + }//checkParam + + public function editSuccess(\Zend_EventManager_Event $e){ + + $data = $e->getParam('data'); + + + return true; + } + +} \ No newline at end of file diff --git a/application/module/Users/Operation/LoginOperate.php b/application/module/Users/Operation/LoginOperate.php new file mode 100644 index 00000000..7dd145f6 --- /dev/null +++ b/application/module/Users/Operation/LoginOperate.php @@ -0,0 +1,111 @@ +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + } + + public function checkParam(\Zend_EventManager_Event $e){ + + $data = $e->getParam('data'); + + if(!is_array($data)) + { + return "参数错误"; + } + + if(empty($data['username'])) + { + return array('error'=>"请输入用户名",'place'=>'username'); + } + + if(!empty($data['username'])) + { + if(!preg_match("/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/",$data['username'])) + { + return array('error'=>"用户名应当以字母开头,由字母数字和下划线组成,并且长度在5到25个字符之间",'place'=>'username'); + } + } + + if(empty($data['password'])) + { + return array('error'=>"请输入密码",'place'=>'password'); + } + + $sql = "SELECT id,{$this->FieldPasword} FROM {$this->tbl_member} WHERE {$this->FieldUsername}=?"; + $sth = $this->db->prepare($sql); + $rs = $sth->execute(array($data[$this->FieldUsername])); + $row = $sth->fetch(); + + if(isset($row['id']) && !empty($row['id'])) + { + if(strlen($row[$this->FieldPasword]) !== 32) + { + return array('error'=>"您的密码或因安全原因或其他问题已经被重置,请先重置密码再登陆",'place'=>'password'); + } + if($row[$this->FieldPasword] !== md5($data['password'])) + { + return array('error'=>"密码错误",'place'=>'password'); + } + return true; + }else{ + return array('error'=>"用户不存在",'place'=>'username'); + } + + }//checkParam + + public function updateStatus(\Zend_EventManager_Event $e){ + + $id = (int)$e->getParam('id'); + + if(!is_numeric($id)) + { + return false; + } + + $update = array( + $this->FieldLastlogin => date("Y-m-d H:i:s"), + $this->FieldLastloginIp => $_SERVER["REMOTE_ADDR"] + ); + + $dbh = new dbh(); + @$statusUpdate = $dbh->update($this->tbl_member,$update," id=$id "); + + return true; + }//loginSuccess + + public function createAvatar(\Zend_EventManager_Event $e){ + + $email = $e->getParam('email'); + $avatar = new Gravatar(); + return $avatar->Get($email); + + }//loginSuccess + + + +} \ No newline at end of file diff --git a/application/module/Users/Operation/PwdOperate.php b/application/module/Users/Operation/PwdOperate.php new file mode 100644 index 00000000..ae87513f --- /dev/null +++ b/application/module/Users/Operation/PwdOperate.php @@ -0,0 +1,94 @@ +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + } + + public function forgotPwdCheckParam(\Zend_EventManager_Event $e){ + + $email = $e->getParam('email'); + + if(empty($email)) + { + return array('error'=>"请输入电子邮箱,作为找回密码和接受通知的联系方式",'place'=>'email'); + } + + if (!preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$email)) + { + return array('error'=>"请输入正确的电子邮件",'place'=>'email'); + } + + return true; + }//checkParam + + public function sendGetPasswordMail(\Zend_EventManager_Event $e){ + + $email = $e->getParam('email'); + + + return true; + } + + public function resetPwdCheckParam(\Zend_EventManager_Event $e) + { + $data = $e->getParam('data'); + + if(empty($data['username'])) + { + return array('error'=>"请输入用户名",'place'=>'username'); + } + + if(empty($data['password'])) + { + return array('error'=>"请输入密码",'place'=>'password'); + } + + if(strlen($data['password']) < 6) + { + return array('error'=>"密码长度太短,为了安全最少输入6位哦",'place'=>'password'); + } + + if(strlen($data['password']) > 14) + { + return array('error'=>"密码太长,亲您记得住吗?不要超过14位哦",'place'=>'password'); + } + + if(empty($data['confirm_password'])) + { + return array('error'=>"请再次输入密码已确认输入正确",'place'=>'confirm_password'); + } + + if(md5($data['password']) != md5($data['confirm_password'])) + { + return array('error'=>"两次输入的密码不同,请重新输入",'place'=>'confirm_password'); + } + + return true; + } + +} \ No newline at end of file diff --git a/application/module/Users/Operation/RegisterOperate.php b/application/module/Users/Operation/RegisterOperate.php new file mode 100644 index 00000000..8bc1f3d1 --- /dev/null +++ b/application/module/Users/Operation/RegisterOperate.php @@ -0,0 +1,192 @@ +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + } + + public function checkParam(\Zend_EventManager_Event $e){ + + $data = $e->getParam('data'); + + if(!is_array($data)) + { + return "参数错误"; + } + + if(empty($data['username'])) + { + return array('error'=>"请输入用户名",'place'=>'username'); + } + + if(!empty($data['username'])) + { + if(!preg_match("/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/",$data['username'])) + { + return array('error'=>"用户名应当以字母开头,由字母数字和下划线组成,并且长度在5到16个字符之间",'place'=>'username'); + } + } + + if(empty($data['password'])) + { + return array('error'=>"请输入密码",'place'=>'password'); + } + + if(strlen($data['password']) < 6) + { + return array('error'=>"密码长度太短,为了安全最少输入6位",'place'=>'password'); + } + + if(strlen($data['password']) > 14) + { + return array('error'=>"密码太长,请不要超过14位",'place'=>'password'); + } + + if(empty($data['confirm_password'])) + { + return array('error'=>"请再次输入密码已确认输入正确",'place'=>'confirm_password'); + } + + if(md5($data['password']) != md5($data['confirm_password'])) + { + return array('error'=>"两次输入的密码不同,请重新输入",'place'=>'confirm_password'); + } + + if(empty($data['email'])) + { + return array('error'=>"请输入电子邮箱,作为找回密码和接受通知的联系方式",'place'=>'email'); + } + + if (!preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$data['email'])) + { + return array('error'=>"请输入正确的电子邮件,推荐使用QQ邮箱和Gmail邮箱",'place'=>'email'); + } + + if(empty($data['realname'])) + { + return array('error'=>"请输入姓名",'place'=>'realname'); + } + + if(mb_strlen($data['realname'],"UTF-8")>10 ) + { + return array('error'=>"真实姓名请不要超过10个字",'place'=>'realname'); + } + + return true; + }//checkParam + + public function checkUser(\Zend_EventManager_Event $e){ + + $data = $e->getParam('data'); + + if(!is_array($data)) + { + return "用户信息验证失败,请重新尝试"; + } + + $sql = "SELECT id,{$this->FieldUsername},{$this->FieldEmail} FROM ".$this->tbl_member." WHERE {$this->FieldUsername}='{$data['username']}' OR {$this->FieldEmail}='{$data['email']}'"; + + $rs = $this->db->query($sql); + + $row = $rs->fetch(); + + if(isset($row['id']) && !empty($row['id'])) + { + if($row[$this->FieldUsername] == $data['username']) + { + return array('error'=>'您的用户名已经注册过账号,您是否忘记了密码?','place'=>'username'); + } + + if($row[$this->FieldEmail] == $data['email']) + { + return array('error'=>'您的邮箱已经注册过账号,请换一个邮箱','place'=>'email'); + } + + return array('error'=>'您的用户名或邮箱已经使用过,注册新账号请换一个用户名'); + } + + return true; + }//checkUser + + public function registerSuccess(\Zend_EventManager_Event $e){ + + $data = $e->getParam('data'); + + if(!is_array($data)) + { + return false; + } + + $id = $e->getParam('id'); + + if(!is_numeric($id)) + { + return false; + } + + $mail_template = "register"; + $mail_data = array( + 'name'=>$data['realname'], + 'content'=>$this->getMailContent() + ); + + $mail = new Mail(); + + $mail->loadTemplate($mail_template,$mail_data); + $mail->addTo($data['email'],$data['realname']); + $mail->send(); + + return true; + }//registerSuccess + + //邮件内容 + public function getMailContent() + { + $sql = "SELECT v.id,v.title,v.thumb,v.status,v.content,m.realname,m.username FROM tbl_voice v + LEFT JOIN tbl_member m ON v.userid = m.id + WHERE v.status > 0 + ORDER BY v.id DESC + LIMIT 5"; + $rs = $this->db->query($sql); + $latest = $rs->fetchAll(); + + $content = ""; + + foreach($latest as $k=>$v) + { + if($v['thumb'] != '[]') + { + $thumb = json_decode($v['thumb'],true); + $text = mb_strlen($v['content'],"UTF-8") > 100 ? mb_substr($v['content'],0,100,"UTF-8") : $v['content']; + $content .= '

      '.$v['title']. ' / ' .$v['realname'].'
      '.$text.'
      查看播放

      '; + } + } + + return $content; + }//getMailContent(); + +} \ No newline at end of file From 747b356901f04acd944770fedb220d45c3d2ac17 Mon Sep 17 00:00:00 2001 From: wlx Date: Mon, 11 Nov 2013 10:02:29 +0000 Subject: [PATCH 040/173] change template name --- application/default/controllers/AccountController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/default/controllers/AccountController.php b/application/default/controllers/AccountController.php index 60d8a07f..fe979d13 100755 --- a/application/default/controllers/AccountController.php +++ b/application/default/controllers/AccountController.php @@ -265,7 +265,7 @@ class AccountController extends Zend_Controller_Action if ($u->save()) { //注册邮件 - $mail_template = "users-register"; + $mail_template = "member-register-en"; $mail_data = array( 'name'=>$formData['username'], ); From 9260c03a6083aea1cd2ef2b7ca506448f51b898a Mon Sep 17 00:00:00 2001 From: wlx Date: Mon, 11 Nov 2013 10:06:03 +0000 Subject: [PATCH 041/173] change template name --- application/default/controllers/AccountController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/default/controllers/AccountController.php b/application/default/controllers/AccountController.php index fe979d13..2601283e 100755 --- a/application/default/controllers/AccountController.php +++ b/application/default/controllers/AccountController.php @@ -265,7 +265,7 @@ class AccountController extends Zend_Controller_Action if ($u->save()) { //注册邮件 - $mail_template = "member-register-en"; + $mail_template = "member-register"; $mail_data = array( 'name'=>$formData['username'], ); From d7eec24005839ce986d5a6d7979add6cb238744c Mon Sep 17 00:00:00 2001 From: wlx Date: Tue, 12 Nov 2013 07:02:40 +0000 Subject: [PATCH 042/173] =?UTF-8?q?=E9=87=8D=E6=96=B0=E6=95=B4=E7=90=86?= =?UTF-8?q?=E7=9F=A5=E8=AF=86=E7=A7=AF=E7=B4=AF=E5=B9=B3=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/KnowledgeController.php | 147 +++++++++--------- .../views/scripts/knowledge/author.phtml | 29 ++-- .../views/scripts/knowledge/datacenter.phtml | 15 +- .../views/scripts/knowledge/index.phtml | 48 +++--- .../views/scripts/knowledge/navi.phtml | 17 +- .../views/scripts/knowledge/paper.phtml | 6 +- .../views/scripts/knowledge/search-data.phtml | 23 +-- .../views/scripts/knowledge/user.phtml | 21 +-- .../views/scripts/knowledge/water.phtml | 56 +++++++ 9 files changed, 211 insertions(+), 151 deletions(-) create mode 100644 application/default/views/scripts/knowledge/water.phtml diff --git a/application/default/controllers/KnowledgeController.php b/application/default/controllers/KnowledgeController.php index dd6baa2e..4ed1b760 100755 --- a/application/default/controllers/KnowledgeController.php +++ b/application/default/controllers/KnowledgeController.php @@ -15,7 +15,7 @@ class KnowledgeController extends Zend_Controller_Action function datacenterAction() { $siteid="e31f5ea7-a4af-4ae3-9ac1-1a84132c4338";//site uuid from geonetowrk - $sql="select * from mdref mr left join reference r on mr.refid=r.id where mr.uuid=? order by r.id desc"; + $sql="select * from mdref mr left join reference r on mr.refid=r.id where mr.uuid=? order by r.year desc, reference desc"; $sth = $this->db->prepare($sql); $sth->execute(array($siteid)); $rows = $sth->fetchAll(); @@ -26,56 +26,72 @@ class KnowledgeController extends Zend_Controller_Action Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); $this->view->paginator=$paginator; } + function waterAction() + { + $sql="select * from reference where id in (select refid from mdref where uuid in (select uuid from en.normalmetadata)) order by year desc, reference desc"; + $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; + } + function userAction() - { - $sql="select * from reference where id in (select refid from mdref where reftype=1 and uuid in (select uuid from normalmetadata)) order by id desc"; - $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; - } - function authorAction() - { - $sql="select * from reference where id in (select refid from mdref where reftype=0 and uuid in (select uuid from normalmetadata)) order by id desc"; - $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; - } + { + $sql="select * from reference where id in (select refid from mdref where reftype=1 and uuid in (select uuid from normalmetadata)) order by year desc, reference desc"; + $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; + } - function westplanAction() - { - $sql="select distinct array_to_string(array(select author from knl_author t where t.item_id=c.item_id order by place asc),'; ') as author,c.title,c.publisher,c.ts_created,c.ts_issued,c.item_id,c.url from knl_article c where c.url <>'' order by 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(10); - $paginator->setView($this->view); - Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); - $this->view->paginator=$paginator; - } - function searchAction() - { - $key=$this->_request->getParam('q'); - $source=$this->_request->getParam('searchsource'); - if(preg_match("/\"|'|<|>/",$key)) - { - $data=array('<'=>'<','>'=>'>', "\'"=>'’', "\""=>'”'); + function authorAction() + { + $sql="select * from reference where id in (select refid from mdref where reftype=0 and uuid in (select uuid from normalmetadata)) order by year desc, reference desc"; + $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; + } - $patterns = array(); - $replacements = array(); + function westplanAction() + { + $sql="select distinct array_to_string(array(select author from knl_author t where t.item_id=c.item_id order by place asc),'; ') as author,c.title,c.publisher,c.ts_created,c.ts_issued,c.item_id,c.url from knl_article c where c.url <>'' order by 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(10); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); + $this->view->paginator=$paginator; + } + + function searchAction() + { + $key=$this->_request->getParam('q'); + $author = (int)$this->_request->getParam('author'); + $source=$this->_request->getParam('searchsource'); + if(preg_match("/\"|'|<|>/",$key)) + { + $data=array('<'=>'<','>'=>'>', "\'"=>'’', "\""=>'”'); + $patterns = array(); + $replacements = array(); foreach($data as $k=>$v) { $patterns[]='/'.$k.'/i'; @@ -86,12 +102,15 @@ class KnowledgeController extends Zend_Controller_Action $key=preg_replace($patterns, $replacements, $key); } - if (!empty($key) && $source=='datasource') { + if (!empty($key)) { $search=new SimpleSearch($key); $where=$search->sql_expr(array("reference")); - $sql="select * from reference where ".$where." order by id desc"; + $sql="select * from reference where ".$where." order by year desc, reference desc"; + } else if ($author) { + $sql="select * from reference where id in (select a1.id from ref_author a1,ref_author a2 where a1.firstname=a2.firstname and a1.lastname=a2.lastname and a2.id=$author)"; + } $sth = $this->db->prepare($sql); - $sth->execute(); + $sth->execute(); $rows = $sth->fetchAll(); $paginator = Zend_Paginator::factory($rows); $paginator->setCurrentPageNumber($this->_getParam('page')); @@ -102,29 +121,13 @@ class KnowledgeController extends Zend_Controller_Action $this->view->key=$key; $this->view->source=$source; $this->_helper->viewRenderer('search-data'); - } - else if (!empty($key) && $source=='westsource') { - $search=new SimpleSearch($key); - $where=$search->sql_expr(array("c.title","a.author")); - $sql="select distinct a.author,c.title,c.publisher,c.ts_created,c.ts_issued,c.item_id,c.url from knl_article c left join knl_author a on c.item_id=a.item_id where c.url <>'' and a.place=1 and $where order by 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(10); - $paginator->setView($this->view); - Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); - $this->view->paginator=$paginator; - $this->view->key=$key; - $this->view->source=$source; - //$this->_helper->viewRenderer('search-data'); - } - } + + } + function paperAction() { - $id = (int)$this->_request->getParam('id'); - $sql="select * from reference where id=$id"; + $id = (int)$this->_request->getParam('id'); + $sql="select * from reference where id=$id"; $sth = $this->db->prepare($sql); $sth->execute(); $this->view->paper = $sth->fetch(); diff --git a/application/default/views/scripts/knowledge/author.phtml b/application/default/views/scripts/knowledge/author.phtml index 88a92cf9..2ed61408 100644 --- a/application/default/views/scripts/knowledge/author.phtml +++ b/application/default/views/scripts/knowledge/author.phtml @@ -5,7 +5,7 @@ $this->headTitle()->setSeparator(' - '); $this->headLink()->appendStylesheet('/css/mdreview.css'); $this->breadcrumb('首页'); $this->breadcrumb('知识积累'); -$this->breadcrumb('数据作者'); +$this->breadcrumb('作者推荐文献库'); $this->breadcrumb()->setSeparator(' > '); $this->headScript()->appendFile('/js/jquery.colorbox-min.js'); $this->headLink()->appendStylesheet('/css/colorbox.css'); @@ -16,20 +16,23 @@ $this->headLink()->appendStylesheet('/css/colorbox.css');
      -

      数据作者文献库

      +

      作者推荐文献库

      - paginator)): ?> -
        - paginator as $item): ?> -
      • - 下载'; - endif; + paginator)): ?> +
          + paginator as $item): ?> +
        1. 查看'; + if (!empty($item['link'])) : + echo ' 下载'; + else : + if (!empty($item['attid'])) echo ' 下载'; + endif; ?> - 相关数据 -
        2. - -
      + 相关数据 + + +
      diff --git a/application/default/views/scripts/knowledge/datacenter.phtml b/application/default/views/scripts/knowledge/datacenter.phtml index afbf6bb9..d752644a 100644 --- a/application/default/views/scripts/knowledge/datacenter.phtml +++ b/application/default/views/scripts/knowledge/datacenter.phtml @@ -17,16 +17,19 @@ $this->breadcrumb()->setSeparator(' > ');

      数据中心文献库

      paginator)): ?> -
        +
          paginator as $item): ?> -
        1. - 下载'; - endif; +
        2. 查看'; + if (!empty($item['link'])) : + echo ' 下载'; + else : + if (!empty($item['attid'])) echo ' 下载'; + endif; ?>
        3. -
      +
      diff --git a/application/default/views/scripts/knowledge/index.phtml b/application/default/views/scripts/knowledge/index.phtml index 66596a82..a9765cbb 100755 --- a/application/default/views/scripts/knowledge/index.phtml +++ b/application/default/views/scripts/knowledge/index.phtml @@ -10,16 +10,6 @@ $this->breadcrumb()->setSeparator(' > ');
      + \ No newline at end of file From 98985efc84d6201d94040f80eefc77fe131d7353 Mon Sep 17 00:00:00 2001 From: wlx Date: Tue, 12 Nov 2013 12:35:12 +0000 Subject: [PATCH 043/173] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=8C=E4=BD=9C?= =?UTF-8?q?=E8=80=85=E6=96=87=E7=AB=A0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/default/controllers/KnowledgeController.php | 5 +++-- application/default/views/scripts/knowledge/paper.phtml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/application/default/controllers/KnowledgeController.php b/application/default/controllers/KnowledgeController.php index 4ed1b760..db750d94 100755 --- a/application/default/controllers/KnowledgeController.php +++ b/application/default/controllers/KnowledgeController.php @@ -86,6 +86,7 @@ class KnowledgeController extends Zend_Controller_Action { $key=$this->_request->getParam('q'); $author = (int)$this->_request->getParam('author'); + $place = (int)$this->_request->getParam('place'); $source=$this->_request->getParam('searchsource'); if(preg_match("/\"|'|<|>/",$key)) { @@ -106,8 +107,8 @@ class KnowledgeController extends Zend_Controller_Action $search=new SimpleSearch($key); $where=$search->sql_expr(array("reference")); $sql="select * from reference where ".$where." order by year desc, reference desc"; - } else if ($author) { - $sql="select * from reference where id in (select a1.id from ref_author a1,ref_author a2 where a1.firstname=a2.firstname and a1.lastname=a2.lastname and a2.id=$author)"; + } else if ($author && $place) { + $sql="select * from reference where id in (select a1.id from ref_author a1,ref_author a2 where a1.firstname=a2.firstname and a1.lastname=a2.lastname and a2.id=$author and a2.place=$place)"; } $sth = $this->db->prepare($sql); $sth->execute(); diff --git a/application/default/views/scripts/knowledge/paper.phtml b/application/default/views/scripts/knowledge/paper.phtml index a2990679..27313bf1 100644 --- a/application/default/views/scripts/knowledge/paper.phtml +++ b/application/default/views/scripts/knowledge/paper.phtml @@ -24,7 +24,7 @@ $this->headLink()->appendStylesheet('/css/colorbox.css');

      作者


      From 7acc24754dcef78c6e2165b2d634c06cd4f34995 Mon Sep 17 00:00:00 2001 From: wlx Date: Tue, 12 Nov 2013 13:09:02 +0000 Subject: [PATCH 044/173] change literature view --- .../default/views/scripts/data/view.phtml | 46 +++++++++++++++---- .../default/views/scripts/heihe/view.phtml | 43 +++++++++++++---- .../default/views/scripts/hiwater/view.phtml | 43 +++++++++++++---- 3 files changed, 104 insertions(+), 28 deletions(-) diff --git a/application/default/views/scripts/data/view.phtml b/application/default/views/scripts/data/view.phtml index 696e39ed..88c54e7c 100755 --- a/application/default/views/scripts/data/view.phtml +++ b/application/default/views/scripts/data/view.phtml @@ -19,6 +19,7 @@ h3.gs_rt{font-size:110%;} #file-list li li:hover {background-color: #dedede;} #file-list li li li:hover {background-color: #eeeeee;} +render('breadcrumbs.phtml'); ?> metadata;if ($md):?>

      escape($md->title); if ($md->title_en) echo '
      '.$this->escape($md->title_en);?> @@ -48,31 +49,56 @@ if ($md->title_en) echo '
      '.$this->escape($md->title_en);?> ?> (下载引用:RIS格式 | RIS英文格式 | Bibtex格式 | Bibtex英文格式)

      ref) : ?>
      -

      建议参考文献

      +

      相关文献(作者推荐)

        ref as $ref) : - echo '
      1. '.$ref->reference; + echo '
      2. '.$ref->reference; + echo '查看'; if (empty($ref->link)) { - if(!empty($ref->attid)) + if(!empty($ref->attid)) echo '下载'; + }else{ + echo '下载'; + } + echo "
      3. "; + endforeach; + ?> +
      + themeref) :?> + +
      +

      专题文献

      +
        + themeref as $ref) : + echo '
      1. '.$ref->reference; + echo '查看'; + if (empty($ref->link)) + { + if(!empty($ref->attid)) + echo ' | 下载'; }else{ - echo '下载'; + echo ' | 下载'; } echo "
      2. "; endforeach; ?>
      - - userref) : ?> + userref) : ?>
      -

      数据用户发表文献

      +

      数据施引文献

        userref as $ref) : + echo '
      1. '.$ref->reference; + echo '查看'; if (empty($ref->link)) - echo '
      2. '.$ref->reference.'
      3. '; - else - echo '
      4. '.$ref->reference.' 下载
      5. '; + { + if(!empty($ref->attid)) + echo '下载'; + }else{ + echo '下载'; + } + echo ""; endforeach; ?>
      diff --git a/application/default/views/scripts/heihe/view.phtml b/application/default/views/scripts/heihe/view.phtml index 23b3a51b..7e752c00 100755 --- a/application/default/views/scripts/heihe/view.phtml +++ b/application/default/views/scripts/heihe/view.phtml @@ -71,31 +71,56 @@ if ($md->title_en) echo '
      '.$this->escape($md->title_en);?> ?> (下载引用:RIS格式 | RIS英文格式 | Bibtex格式 | Bibtex英文格式)

      ref) : ?>
      -

      建议参考文献

      +

      相关文献(作者推荐)

        ref as $ref) : echo '
      1. '.$ref->reference; + echo '查看'; if (empty($ref->link)) { - if(!empty($ref->attid)) + if(!empty($ref->attid)) echo '下载'; + }else{ + echo '下载'; + } + echo "
      2. "; + endforeach; + ?> +
      + themeref) :?> + +
      +

      专题文献

      +
        + themeref as $ref) : + echo '
      1. '.$ref->reference; + echo '查看'; + if (empty($ref->link)) + { + if(!empty($ref->attid)) + echo ' | 下载'; }else{ - echo '下载'; + echo ' | 下载'; } echo "
      2. "; endforeach; ?>
      - - userref) : ?> + userref) : ?>
      -

      数据用户发表文献

      +

      数据施引文献

        userref as $ref) : + echo '
      1. '.$ref->reference; + echo '查看'; if (empty($ref->link)) - echo '
      2. '.$ref->reference.'
      3. '; - else - echo '
      4. '.$ref->reference.' 下载
      5. '; + { + if(!empty($ref->attid)) + echo '下载'; + }else{ + echo '下载'; + } + echo ""; endforeach; ?>
      diff --git a/application/default/views/scripts/hiwater/view.phtml b/application/default/views/scripts/hiwater/view.phtml index e69fd7d8..2330ecdc 100644 --- a/application/default/views/scripts/hiwater/view.phtml +++ b/application/default/views/scripts/hiwater/view.phtml @@ -69,31 +69,56 @@ if ($md->title_en) echo '
      '.$this->escape($md->title_en);?> ?> (下载引用:RIS格式 | RIS英文格式 | Bibtex格式 | Bibtex英文格式)

      ref) : ?>
      -

      建议参考文献

      +

      相关文献(作者推荐)

        ref as $ref) : echo '
      1. '.$ref->reference; + echo '查看'; if (empty($ref->link)) { - if(!empty($ref->attid)) + if(!empty($ref->attid)) echo '下载'; + }else{ + echo '下载'; + } + echo "
      2. "; + endforeach; + ?> +
      + themeref) :?> + +
      +

      专题文献

      +
        + themeref as $ref) : + echo '
      1. '.$ref->reference; + echo '查看'; + if (empty($ref->link)) + { + if(!empty($ref->attid)) + echo ' | 下载'; }else{ - echo '下载'; + echo ' | 下载'; } echo "
      2. "; endforeach; ?>
      - - userref) : ?> + userref) : ?>
      -

      数据用户发表文献

      +

      数据施引文献

        userref as $ref) : + echo '
      1. '.$ref->reference; + echo '查看'; if (empty($ref->link)) - echo '
      2. '.$ref->reference.'
      3. '; - else - echo '
      4. '.$ref->reference.' 下载
      5. '; + { + if(!empty($ref->attid)) + echo '下载'; + }else{ + echo '下载'; + } + echo ""; endforeach; ?>
      From 7a36469b62ed3d65b409be1887aff623afd30feb Mon Sep 17 00:00:00 2001 From: wlx Date: Wed, 13 Nov 2013 18:16:31 +0000 Subject: [PATCH 045/173] =?UTF-8?q?=E5=8C=BA=E5=88=86=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E4=B8=AD=E5=BF=83=E7=9A=84=E6=96=BD=E5=BC=95=E6=96=87=E7=8C=AE?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/default/views/scripts/knowledge/datacenter.phtml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/application/default/views/scripts/knowledge/datacenter.phtml b/application/default/views/scripts/knowledge/datacenter.phtml index d752644a..29ec7c29 100644 --- a/application/default/views/scripts/knowledge/datacenter.phtml +++ b/application/default/views/scripts/knowledge/datacenter.phtml @@ -19,7 +19,9 @@ $this->breadcrumb()->setSeparator(' > '); paginator)): ?>
        paginator as $item): ?> -
      1. 数据中心施引文献'; + echo $item['reference']; echo ' 查看'; if (!empty($item['link'])) : echo ' 下载'; From 24f253c027be1118a75293e3da477e4ce63c09c6 Mon Sep 17 00:00:00 2001 From: wlx Date: Wed, 13 Nov 2013 18:24:53 +0000 Subject: [PATCH 046/173] fix single author problem --- application/default/views/scripts/knowledge/paper.phtml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/default/views/scripts/knowledge/paper.phtml b/application/default/views/scripts/knowledge/paper.phtml index 27313bf1..354555fa 100644 --- a/application/default/views/scripts/knowledge/paper.phtml +++ b/application/default/views/scripts/knowledge/paper.phtml @@ -20,7 +20,7 @@ $this->headLink()->appendStylesheet('/css/colorbox.css');

        paper['title']; ?>


        - author) > 0) {?> + author) : ?>

        作者

          author as $a) : ?> @@ -28,7 +28,7 @@ $this->headLink()->appendStylesheet('/css/colorbox.css');

        - + paper['abstract']){ ?>

        摘要

        From 2eda7023620a0db9f015d963a998323abd8f73aa Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Thu, 14 Nov 2013 02:49:15 +0000 Subject: [PATCH 047/173] =?UTF-8?q?#563=20=E4=BF=AE=E6=94=B9=E4=BA=86?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E6=97=B6=E5=8D=95=E4=B8=AAauthor=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/module/Reference/Ris.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/application/module/Reference/Ris.php b/application/module/Reference/Ris.php index c9432ddd..7e30ef73 100644 --- a/application/module/Reference/Ris.php +++ b/application/module/Reference/Ris.php @@ -174,10 +174,8 @@ class Ris $results = $this->events()->trigger('checkLoad', $this, compact('ref')); $id = $results->bottom(); - - if ($id > 0) - { + { $this->unsetVar($ref); $this->events()->trigger('deleteAuthor', $this, compact('id')); $this->events()->trigger('deleteTag', $this, compact('id')); @@ -185,8 +183,8 @@ class Ris unset($ref['reference']); $dbh->update($this->table->reference,$ref," id=$id "); - } else { - $ref['reference'] = $this->makeReferenceFlag($ref); + } else { + $ref['reference'] = $this->makeReferenceFlag($ref); $this->unsetVar($ref); $id = $dbh->insert($this->table->reference,$ref,true); } @@ -261,6 +259,11 @@ class Ris } return true; }else{ + if(is_string($author)) + { + $author_splited = $this->splitAuthor($author); + $this->dbh->insert($this->table->reference_author,array('id'=>$id , 'lastname'=>$author_splited['lastname'] , 'firstname'=>$author_splited['firstname'] , 'place'=>0 )); + } return false; } } @@ -275,7 +278,7 @@ class Ris //创建reference 字段 public function makeReferenceFlag($ref){ $str = join(', ',$ref['author']).'. '; - $str .= $ref['title'].'. '; + $str .= $ref['title'].'. '; $str .= $ref['publisher'].', '; isset($ref['year']) ? $str .= $ref['year'].', ':""; isset($ref['volume']) ? $str .= $ref['volume']:""; From 1c147a88c283596ef5bf198f1d5445cf5c6110a4 Mon Sep 17 00:00:00 2001 From: wlx Date: Thu, 14 Nov 2013 06:45:21 +0000 Subject: [PATCH 048/173] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E7=A6=BB=E7=BA=BF=E8=AE=B0=E5=BD=95=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=88=E8=A1=A5=E5=85=85=E9=A1=B9=E7=9B=AE=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controllers/DownController.php | 11 ++++++++--- application/models/OfflinelogForm.php | 19 ++++++++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/application/admin/controllers/DownController.php b/application/admin/controllers/DownController.php index f7d06304..95da2e30 100644 --- a/application/admin/controllers/DownController.php +++ b/application/admin/controllers/DownController.php @@ -875,8 +875,10 @@ class Admin_DownController extends Zend_Controller_Action if ($form->isValid($formdata)) { $uploadedData = $form->getValues(); $pdf = basename($form->pdf->getFileName()); - $sql="insert into offlineapp (username,email,unit,phone,address,postcode,project,pdflink,datalist,ts_created,ts_approved) values(?,?,?,?,?,?,?,?,?,?,now())"; - $this->db->query($sql,array($formdata['username'],$formdata['email'],$formdata['unit'],$formdata['phone'],$formdata['address'],$formdata['postcode'],$formdata['project'],$pdf,$formdata['datalist'],$formdata['ts_approved'])); + $sql="insert into offlineapp (username,email,unit,phone,address,postcode,project,pdflink,datalist,ts_created,ts_approved,project_id,project_title,project_type) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + $this->db->query($sql,array($formdata['username'],$formdata['email'],$formdata['unit'],$formdata['phone'],$formdata['address'],$formdata['postcode'], + $formdata['project'],$pdf,$formdata['datalist'],$formdata['ts_approved']),$formdata['ts_approved'], + $formdata['project_id'],$formdata['project_title'],$formdata['project_type']); $this->messenger->addMessage('提示信息:您已经成功添加该离线服务记录。'); $this->_redirect('/admin/down/offline'); } else { @@ -897,11 +899,14 @@ class Admin_DownController extends Zend_Controller_Action $pdf = basename($form->pdf->getFileName()); $sql="update offlineapp set username=?,email=?,unit=?,phone=?,address=?,postcode=?,project=?,"; if ($form->pdf->isUploaded()) $sql.="pdflink=?,"; - $sql.="datalist=?,ts_approved=? where id=?"; + $sql.="datalist=?,ts_approved=?,project_id=?,project_title=?,project_type=? where id=?"; $param=array($formdata['username'],$formdata['email'],$formdata['unit'],$formdata['phone'],$formdata['address'],$formdata['postcode'],$formdata['project']); if ($form->pdf->isUploaded()) $param[]=$pdf; $param[]=$formdata['datalist']; $param[]=$formdata['ts_approved']; + $param[]=$formdata['project_id']; + $param[]=$formdata['project_title']; + $param[]=$formdata['project_type']; $param[]=$edit; $this->db->query($sql,$param); $this->messenger->addMessage('提示信息:您已经编辑添加该记录。'); diff --git a/application/models/OfflinelogForm.php b/application/models/OfflinelogForm.php index 7ef2ca87..6e9150c6 100644 --- a/application/models/OfflinelogForm.php +++ b/application/models/OfflinelogForm.php @@ -26,6 +26,23 @@ class OfflinelogForm extends Zend_Form $address->setLabel('联系地址')->setRequired(true); $project=new Zend_Form_Element_Textarea('project'); $project->setLabel('用途')->setRequired(true)->setAttrib('rows',2); + $project_id=new Zend_Form_Element_Text('project_id'); + $project_id->setLabel('项目编号'); + $project_title=new Zend_Form_Element_Text('project_title'); + $project_title->setLabel('项目名称'); + $project_type=new Zend_Form_Element_Select('project_type'); + $project_type->setLabel('项目类型'); + $project_type->addMultiOption('','请选择项目类型'); + $project_type->addMultiOption('国家973计划项目课题','国家973计划项目课题'); + $project_type->addMultiOption('国家863计划课题','国家863计划课题'); + $project_type->addMultiOption('国家级科技支撑课题','国家级科技支撑课题'); + $project_type->addMultiOption('国家级科技重大专项','国家级科技重大专项'); + $project_type->addMultiOption('国家级国家重大工程','国家级国家重大工程'); + $project_type->addMultiOption('国家级国家自然科学基金','国家级国家自然科学基金'); + $project_type->addMultiOption('国际合作项目','国际合作项目'); + $project_type->addMultiOption('省部级项目','省部级项目'); + $project_type->addMultiOption('其他项目工程','其他项目工程'); + $datalist=new Zend_Form_Element_Textarea('datalist'); $datalist->setLabel('数据清单')->setRequired(true)->setAttrib('rows',2); $pdf=new Zend_Form_Element_File('pdf'); @@ -42,6 +59,6 @@ class OfflinelogForm extends Zend_Form $submit = new Zend_Form_Element_Submit('submit'); $submit->setAttrib('id', 'submitbutton')->setLabel('添加'); $this->setAttrib('enctype', 'multipart/form-data'); - $this->addElements(array($username,$email,$phone,$unit,$address,$postcode,$pdf,$ts_approved,$project,$datalist,$id,$submit)); + $this->addElements(array($username,$email,$phone,$unit,$address,$postcode,$pdf,$ts_approved,$project_id,$project_title,$project_type,$project,$datalist,$id,$submit)); } } \ No newline at end of file From 2ca99a2de33bce520533f227b1fe08422b4237d2 Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 15 Nov 2013 02:31:03 +0000 Subject: [PATCH 049/173] fix spell error --- application/module/Order/Manager/Offlineapp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/module/Order/Manager/Offlineapp.php b/application/module/Order/Manager/Offlineapp.php index 74325e73..099692d2 100644 --- a/application/module/Order/Manager/Offlineapp.php +++ b/application/module/Order/Manager/Offlineapp.php @@ -3,7 +3,7 @@ namespace Order\Manager; use Helpers\View as view; use Helpers\dbh; -use Order\listener\ManagerListener; +use Order\Listener\ManagerListener; class Offlineapp { From beb002b6487e9d636cf7483eae4f727621cbcabc Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Fri, 15 Nov 2013 03:44:52 +0000 Subject: [PATCH 050/173] =?UTF-8?q?=E4=B8=BACurl=E7=B1=BB=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89=E5=A4=B4=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/module/Helpers/Curl.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/application/module/Helpers/Curl.php b/application/module/Helpers/Curl.php index bc819575..dea71661 100644 --- a/application/module/Helpers/Curl.php +++ b/application/module/Helpers/Curl.php @@ -16,6 +16,8 @@ class Curl 'verifyssl' => true, ), $options); } + + public $H; /** * Send a request to the server, receive a response @@ -69,6 +71,11 @@ class Curl } else { $headers[] = 'Content-Length: 0'; } + + if(!empty($this->H) && is_array($this->H) && count($this->H) > 0) + { + $headers = array_merge($headers,$this->H); + } $this->debug('send '.$httpMethod.' request: '.$url); From 1ccb1300b0262470e21d0289eac89bea8094f432 Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 15 Nov 2013 14:41:56 +0000 Subject: [PATCH 051/173] add ris download function for literatures --- application/default/controllers/ServiceController.php | 6 ++++++ application/default/views/scripts/knowledge/paper.phtml | 3 +++ 2 files changed, 9 insertions(+) diff --git a/application/default/controllers/ServiceController.php b/application/default/controllers/ServiceController.php index 8d2c5af4..4654666a 100644 --- a/application/default/controllers/ServiceController.php +++ b/application/default/controllers/ServiceController.php @@ -1667,6 +1667,8 @@ class ServiceController extends Zend_Controller_Action $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $uuid=$this->_request->getParam('uuid'); + //文献id + $id=(int)$this->_request->getParam('id'); $lang=$this->_request->getParam('lang'); $ris=''; if ($lang=='cn' && !empty($uuid)) @@ -1708,6 +1710,10 @@ class ServiceController extends Zend_Controller_Action $ris.='M3 - doi:'.$row['doi']."\r\n"; $ris.='DO - doi:'.$row['doi']."\r\n"; $ris.='ER -'."\r\n"; + } else if ($id) { + $sql="select ris from reference where id=$id"; + $row=$this->db->fetchRow($sql); + $ris=$row['ris']; } if (!empty($ris)) { diff --git a/application/default/views/scripts/knowledge/paper.phtml b/application/default/views/scripts/knowledge/paper.phtml index 354555fa..d457fdb6 100644 --- a/application/default/views/scripts/knowledge/paper.phtml +++ b/application/default/views/scripts/knowledge/paper.phtml @@ -70,6 +70,9 @@ $this->headLink()->appendStylesheet('/css/colorbox.css'); if (!empty($item['link'])) : echo ' 下载'; endif; + if (!empty($item['ris'])) : + echo ' RIS下载'; + endif; ?> 相关数据(共条) From 2bc695660bb3228ba3e55c816c16eb872775d28f Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 15 Nov 2013 14:46:28 +0000 Subject: [PATCH 052/173] fix var error --- .../default/views/scripts/knowledge/paper.phtml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/application/default/views/scripts/knowledge/paper.phtml b/application/default/views/scripts/knowledge/paper.phtml index d457fdb6..eabc28df 100644 --- a/application/default/views/scripts/knowledge/paper.phtml +++ b/application/default/views/scripts/knowledge/paper.phtml @@ -65,13 +65,9 @@ $this->headLink()->appendStylesheet('/css/colorbox.css'); }else{ echo 'PDF下载'; } - - - if (!empty($item['link'])) : - echo ' 下载'; - endif; - if (!empty($item['ris'])) : - echo ' RIS下载'; + + if (!empty($this->paper['ris'])) : + echo ' RIS下载'; endif; ?> 相关数据(共条) From 9512051737b5eb391b28b4e62c3ee636feed7f9c Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 15 Nov 2013 14:47:36 +0000 Subject: [PATCH 053/173] add css --- application/default/views/scripts/knowledge/paper.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/default/views/scripts/knowledge/paper.phtml b/application/default/views/scripts/knowledge/paper.phtml index eabc28df..e629b8bd 100644 --- a/application/default/views/scripts/knowledge/paper.phtml +++ b/application/default/views/scripts/knowledge/paper.phtml @@ -67,7 +67,7 @@ $this->headLink()->appendStylesheet('/css/colorbox.css'); } if (!empty($this->paper['ris'])) : - echo ' RIS下载'; + echo ' RIS下载'; endif; ?> 相关数据(共条) From cd8fe1ca8788da0776461b1a18fcfeaf93688908 Mon Sep 17 00:00:00 2001 From: wlx Date: Sat, 16 Nov 2013 07:43:30 +0000 Subject: [PATCH 054/173] fix single author could generate reference problem. --- application/module/Reference/Ris.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/application/module/Reference/Ris.php b/application/module/Reference/Ris.php index 7e30ef73..5b6ff16d 100644 --- a/application/module/Reference/Ris.php +++ b/application/module/Reference/Ris.php @@ -277,7 +277,13 @@ class Ris //创建reference 字段 public function makeReferenceFlag($ref){ - $str = join(', ',$ref['author']).'. '; + $str=''; + if(is_array($author) && count($author) > 0) + { + $str .= join(', ',$ref['author']).'. '; + } else if if(is_string($author)) { + $str .= $ref['author'].'. '; + } $str .= $ref['title'].'. '; $str .= $ref['publisher'].', '; isset($ref['year']) ? $str .= $ref['year'].', ':""; From 5de71572bbefe57217d4b5be61992555c65d8e38 Mon Sep 17 00:00:00 2001 From: wlx Date: Sat, 16 Nov 2013 11:14:45 +0000 Subject: [PATCH 055/173] =?UTF-8?q?=E6=9C=89=E6=95=B0=E6=8D=AE=E4=BD=9C?= =?UTF-8?q?=E8=80=85=E6=89=8D=E5=8F=91=E4=BF=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controllers/ReviewController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/admin/controllers/ReviewController.php b/application/admin/controllers/ReviewController.php index 001217bf..5d43ef71 100644 --- a/application/admin/controllers/ReviewController.php +++ b/application/admin/controllers/ReviewController.php @@ -761,7 +761,7 @@ class Admin_ReviewController extends Zend_Controller_Action if (is_numeric($ids)) { $sql="select distinct u.email,m.title,m.uuid from mdstatus s left join metadata m on s.uuid=m.uuid - left join mdauthor a on s.uuid=a.uuid left join users u on a.userid=u.id where s.id=? order by u.email"; + right join mdauthor a on s.uuid=a.uuid left join users u on a.userid=u.id where s.id=? order by u.email"; $rs=$this->db->query($sql,array($ids)); $rows=$rs->fetchAll(); if ($rows) From ff2c52cfebea4d51ede7d08e331489327bec6da5 Mon Sep 17 00:00:00 2001 From: wlx Date: Sat, 16 Nov 2013 11:28:50 +0000 Subject: [PATCH 056/173] fix spell error --- application/module/Reference/Ris.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/module/Reference/Ris.php b/application/module/Reference/Ris.php index 5b6ff16d..cc69cf94 100644 --- a/application/module/Reference/Ris.php +++ b/application/module/Reference/Ris.php @@ -281,7 +281,7 @@ class Ris if(is_array($author) && count($author) > 0) { $str .= join(', ',$ref['author']).'. '; - } else if if(is_string($author)) { + } else if (is_string($author)) { $str .= $ref['author'].'. '; } $str .= $ref['title'].'. '; From afd7f13418730ebcb24e4bd982f04cea3f1daa6f Mon Sep 17 00:00:00 2001 From: wlx Date: Sun, 17 Nov 2013 12:07:15 +0000 Subject: [PATCH 057/173] fix problem when generate the reference --- application/module/Reference/Ris.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/module/Reference/Ris.php b/application/module/Reference/Ris.php index cc69cf94..4b27adc5 100644 --- a/application/module/Reference/Ris.php +++ b/application/module/Reference/Ris.php @@ -278,7 +278,7 @@ class Ris //创建reference 字段 public function makeReferenceFlag($ref){ $str=''; - if(is_array($author) && count($author) > 0) + if(is_array($ref['author']) && count($ref['author']) > 0) { $str .= join(', ',$ref['author']).'. '; } else if (is_string($author)) { From 69d3a94ef808f9356ef58032b0887ce9b79add35 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Tue, 19 Nov 2013 01:56:39 +0000 Subject: [PATCH 058/173] =?UTF-8?q?#566=20=E4=BF=AE=E6=94=B9=E6=9F=A5?= =?UTF-8?q?=E9=87=8D=E6=97=B6=E7=9A=84=E5=8D=95=E5=BC=95=E5=8F=B7bug?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=94=B9Ris=E5=AF=BC=E5=85=A5=E6=97=B6?= =?UTF-8?q?=E4=BD=9C=E8=80=85=E4=B8=BA=E5=AD=97=E7=AC=A6=E4=B8=B2=E6=97=B6?= =?UTF-8?q?=E5=8F=91=E7=94=9F=E9=94=99=E8=AF=AF=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/module/Reference/Handler/RisHandler.php | 7 ++++++- application/module/Reference/Ris.php | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/application/module/Reference/Handler/RisHandler.php b/application/module/Reference/Handler/RisHandler.php index 9de4d5d0..8a820795 100644 --- a/application/module/Reference/Handler/RisHandler.php +++ b/application/module/Reference/Handler/RisHandler.php @@ -36,9 +36,14 @@ class RisHandler implements \Reference\Event\RisEvent $wheresql = array(); + if(preg_match("/\'/",$ref['title'])) + { + $ref['title'] = preg_replace("/\'/","''",$ref['title']); + } + $wheresql[] = " lower(title)=lower('{$ref['title']}') "; $wheresql[] = " year='{$ref['year']}' "; - + //暂时不使用期刊限制 /*if(isset($ref['publisher'])) { diff --git a/application/module/Reference/Ris.php b/application/module/Reference/Ris.php index 4b27adc5..72da0dc3 100644 --- a/application/module/Reference/Ris.php +++ b/application/module/Reference/Ris.php @@ -281,7 +281,7 @@ class Ris if(is_array($ref['author']) && count($ref['author']) > 0) { $str .= join(', ',$ref['author']).'. '; - } else if (is_string($author)) { + } else if (is_string($ref['author'])) { $str .= $ref['author'].'. '; } $str .= $ref['title'].'. '; From 1edecd120a721c7bd202f88dfb20a3381aed2fe3 Mon Sep 17 00:00:00 2001 From: wlx Date: Wed, 20 Nov 2013 09:50:41 +0000 Subject: [PATCH 059/173] =?UTF-8?q?fix=20#567,=20=E9=99=90=E5=AE=9A?= =?UTF-8?q?=E6=96=BD=E5=BC=95=E6=96=87=E7=8C=AE=E7=9A=84=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/default/controllers/DataController.php | 2 +- .../default/controllers/KnowledgeController.php | 11 ++++++++++- application/default/views/scripts/data/view.phtml | 4 ++++ application/default/views/scripts/heihe/view.phtml | 4 ++++ application/default/views/scripts/hiwater/view.phtml | 4 ++++ .../default/views/scripts/knowledge/user.phtml | 6 +++++- application/default/views/scripts/water/view.phtml | 4 ++++ 7 files changed, 32 insertions(+), 3 deletions(-) diff --git a/application/default/controllers/DataController.php b/application/default/controllers/DataController.php index 5768028c..1e34826e 100755 --- a/application/default/controllers/DataController.php +++ b/application/default/controllers/DataController.php @@ -618,7 +618,7 @@ class DataController extends Zend_Controller_Action $sql=$this->db->quoteInto($sql,$uuid); $this->view->themeref=$this->db->fetchAll($sql); //用户发表文献 - $sql="select r.* from reference r left join mdref m on m.refid=r.id where m.uuid=? and m.reftype=1"; + $sql="select r.* from reference r left join mdref m on m.refid=r.id where m.uuid=? and m.reftype=1 order by r.language asc,r.year desc,r.ts_created desc limit 15"; $sql=$this->db->quoteInto($sql,$uuid); $this->view->userref=$this->db->fetchAll($sql); //多篇引用形式:hiwater diff --git a/application/default/controllers/KnowledgeController.php b/application/default/controllers/KnowledgeController.php index db750d94..9e76286c 100755 --- a/application/default/controllers/KnowledgeController.php +++ b/application/default/controllers/KnowledgeController.php @@ -42,7 +42,16 @@ class KnowledgeController extends Zend_Controller_Action function userAction() { - $sql="select * from reference where id in (select refid from mdref where reftype=1 and uuid in (select uuid from normalmetadata)) order by year desc, reference desc"; + $uuid=$this->_request->getParam('uuid'); + if (preg_match('/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/',$uuid)) + { + $sql="select uuid,title from metadata where uuid='$uuid'"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $this->view->md = $sth->fetch(); + $sql="select * from reference where id in (select refid from mdref where reftype=1 and uuid='$uuid') order by year desc, reference desc"; + } else + $sql="select * from reference where id in (select refid from mdref where reftype=1 and uuid in (select uuid from normalmetadata)) order by year desc, reference desc"; $sth = $this->db->prepare($sql); $sth->execute(); $rows = $sth->fetchAll(); diff --git a/application/default/views/scripts/data/view.phtml b/application/default/views/scripts/data/view.phtml index 88c54e7c..6e60839d 100755 --- a/application/default/views/scripts/data/view.phtml +++ b/application/default/views/scripts/data/view.phtml @@ -100,6 +100,10 @@ if ($md->title_en) echo '
        '.$this->escape($md->title_en);?> } echo "
      2. "; endforeach; + if (count($this->userref)==15) + { + echo '更多施引文献'; + } ?>
      diff --git a/application/default/views/scripts/heihe/view.phtml b/application/default/views/scripts/heihe/view.phtml index 7e752c00..5136e386 100755 --- a/application/default/views/scripts/heihe/view.phtml +++ b/application/default/views/scripts/heihe/view.phtml @@ -122,6 +122,10 @@ if ($md->title_en) echo '
      '.$this->escape($md->title_en);?> } echo ""; endforeach; + if (count($this->userref)==15) + { + echo '更多施引文献'; + } ?> diff --git a/application/default/views/scripts/hiwater/view.phtml b/application/default/views/scripts/hiwater/view.phtml index 2330ecdc..5a8a2783 100644 --- a/application/default/views/scripts/hiwater/view.phtml +++ b/application/default/views/scripts/hiwater/view.phtml @@ -120,6 +120,10 @@ if ($md->title_en) echo '
      '.$this->escape($md->title_en);?> } echo ""; endforeach; + if (count($this->userref)==15) + { + echo '更多施引文献'; + } ?> diff --git a/application/default/views/scripts/knowledge/user.phtml b/application/default/views/scripts/knowledge/user.phtml index 08bceb34..d30d8d99 100644 --- a/application/default/views/scripts/knowledge/user.phtml +++ b/application/default/views/scripts/knowledge/user.phtml @@ -16,7 +16,11 @@ $this->headLink()->appendStylesheet('/css/colorbox.css');
      -

      数据施引文献库

      +

      数据施引文献库

      + md) : + echo '

      '.$this->md['title'].'

      '; + endif; + ?>
      paginator)): ?>
        diff --git a/application/default/views/scripts/water/view.phtml b/application/default/views/scripts/water/view.phtml index db5ab149..a548d2bb 100755 --- a/application/default/views/scripts/water/view.phtml +++ b/application/default/views/scripts/water/view.phtml @@ -101,6 +101,10 @@ h3.gs_rt{font-size:110%;} } echo ""; endforeach; + if (count($this->userref)==15) + { + echo '更多施引文献'; + } ?>
      From 6d5397273e9445b9cb801626d761891d71a69534 Mon Sep 17 00:00:00 2001 From: wlx Date: Wed, 20 Nov 2013 09:53:33 +0000 Subject: [PATCH 060/173] =?UTF-8?q?=E4=B8=8D=E9=99=90=E5=88=B6heihe?= =?UTF-8?q?=E4=B8=8A=E7=9A=84order=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/module/Order/Mount/OrderOperate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/module/Order/Mount/OrderOperate.php b/application/module/Order/Mount/OrderOperate.php index 31b528e1..dac905c9 100644 --- a/application/module/Order/Mount/OrderOperate.php +++ b/application/module/Order/Mount/OrderOperate.php @@ -11,7 +11,7 @@ class OrderOperate implements \Order\Listener\OrderEvents //!!!!!!important!!!!! //不同项目使用时是否要修改此项?? - public $tbl_metadata = "heihemetadata"; + public $tbl_metadata = "normalmetadata"; public $tbl_dataorder = "dataorder"; function __construct($db = NULL) From 1c3075584e671d6f24217dcb81de8da37ec4c2b3 Mon Sep 17 00:00:00 2001 From: wlx Date: Wed, 20 Nov 2013 10:10:18 +0000 Subject: [PATCH 061/173] change link css --- application/default/views/scripts/data/view.phtml | 2 +- application/default/views/scripts/heihe/view.phtml | 2 +- application/default/views/scripts/hiwater/view.phtml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/application/default/views/scripts/data/view.phtml b/application/default/views/scripts/data/view.phtml index 6e60839d..99e7d8b8 100755 --- a/application/default/views/scripts/data/view.phtml +++ b/application/default/views/scripts/data/view.phtml @@ -102,7 +102,7 @@ if ($md->title_en) echo '
      '.$this->escape($md->title_en);?> endforeach; if (count($this->userref)==15) { - echo '更多施引文献'; + echo '更多施引文献'; } ?> diff --git a/application/default/views/scripts/heihe/view.phtml b/application/default/views/scripts/heihe/view.phtml index 5136e386..ba55b71c 100755 --- a/application/default/views/scripts/heihe/view.phtml +++ b/application/default/views/scripts/heihe/view.phtml @@ -124,7 +124,7 @@ if ($md->title_en) echo '
      '.$this->escape($md->title_en);?> endforeach; if (count($this->userref)==15) { - echo '更多施引文献'; + echo '更多施引文献'; } ?> diff --git a/application/default/views/scripts/hiwater/view.phtml b/application/default/views/scripts/hiwater/view.phtml index 5a8a2783..7a851a6d 100644 --- a/application/default/views/scripts/hiwater/view.phtml +++ b/application/default/views/scripts/hiwater/view.phtml @@ -122,7 +122,7 @@ if ($md->title_en) echo '
      '.$this->escape($md->title_en);?> endforeach; if (count($this->userref)==15) { - echo '更多施引文献'; + echo '更多施引文献'; } ?> From 608b8f29f4e8e6aaa029b73dfdf25d6c4930ce3e Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Thu, 21 Nov 2013 02:09:45 +0000 Subject: [PATCH 062/173] =?UTF-8?q?=E6=9B=B4=E6=96=B0Users=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/module/Users/Account.php | 49 +++++++++++-- .../module/Users/Listener/AccountListener.php | 4 +- .../module/Users/Listener/EditListener.php | 2 +- .../module/Users/Listener/PwdListener.php | 2 +- application/module/Users/Member.php | 2 +- .../module/Users/Operation/EditOperate.php | 4 +- .../module/Users/Operation/LoginOperate.php | 6 +- .../Users/Operation/RegisterOperate.php | 4 +- application/module/Users/Users.php | 73 +++++++++++++++++++ 9 files changed, 127 insertions(+), 19 deletions(-) create mode 100644 application/module/Users/Users.php diff --git a/application/module/Users/Account.php b/application/module/Users/Account.php index e692f95c..1297d529 100644 --- a/application/module/Users/Account.php +++ b/application/module/Users/Account.php @@ -1,27 +1,35 @@ config = \Zend_Registry::get('config'); + if($initializingListener === TRUE) + { + $this->loadListener(); + } + } + + public function loadListener() + { + //主要操作,账号注册,登录,设置session等 + $AccountListener = new AccountListener(); + @$this->events()->attachAggregate($AccountListener); + //账户编辑 + $EditListener = new EditListener(); + @$this->events()->attachAggregate($EditListener); + + //账户安全性(找回密码) + $PwdListener = new PwdListener(); + @$this->events()->attachAggregate($PwdListener); } public function events(\Zend_EventManager_EventCollection $events = NULL) @@ -60,7 +86,6 @@ class Account extends \Zend_Controller_Plugin_Abstract //注册 public function register($data) { - $params = compact('data'); $results = $this->events()->trigger('register.checkParam', $this, $params); $cache_data = $results->bottom(); @@ -145,6 +170,7 @@ class Account extends \Zend_Controller_Plugin_Abstract }//login //storeLogin + //将登录信息保存在session和cookie中 public function storeLogin($data) { $auth = \Zend_Auth::getInstance(); @@ -152,7 +178,16 @@ class Account extends \Zend_Controller_Plugin_Abstract $authAdapter->setTableName($this->memberTable) ->setIdentityColumn($this->FieldUsername) ->setCredentialColumn($this->FieldPasword); - $authAdapter->setIdentity($data[$this->FieldUsername])->setCredential(md5($data[$this->FieldPasword])); + + if($data[$this->FieldPasword] == 0) + { + $password = "0"; + }else{ + $password = md5($data[$this->FieldPasword]); + } + + $authAdapter->setIdentity($data[$this->FieldUsername])->setCredential($password); + $result = $auth->authenticate($authAdapter); if ($result->isValid()) { diff --git a/application/module/Users/Listener/AccountListener.php b/application/module/Users/Listener/AccountListener.php index 4eabf2c0..04d08596 100644 --- a/application/module/Users/Listener/AccountListener.php +++ b/application/module/Users/Listener/AccountListener.php @@ -1,8 +1,8 @@ FieldLastlogin => date("Y-m-d H:i:s"), - $this->FieldLastloginIp => $_SERVER["REMOTE_ADDR"] + //$this->FieldLastloginIp => $_SERVER["REMOTE_ADDR"] ); $dbh = new dbh(); diff --git a/application/module/Users/Operation/RegisterOperate.php b/application/module/Users/Operation/RegisterOperate.php index 8bc1f3d1..9d3c006a 100644 --- a/application/module/Users/Operation/RegisterOperate.php +++ b/application/module/Users/Operation/RegisterOperate.php @@ -1,8 +1,8 @@ db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->table = new Table(); + + $this->config = \Zend_Registry::get('config'); + + if($accountClass === TRUE) + { + $this->account = new Account(); + } + } + + //通过email地址返回用户信息是否存在 + public function userExists($email = NULL) + { + if(empty($email)) + { + return false; + } + + if(empty($this->account)) + { + $account = new Account(FALSE); + }else{ + $account = $this->account; + } + + $sql = "SELECT * FROM {$account->memberTable} WHERE {$account->FieldEmail}=? LIMIT 1"; + $sth = $this->db->prepare($sql); + $sth->execute(array($email)); + $row = $sth->fetch(); + + unset($account); + + if(isset($row['id']) && !empty($row['id'])) + { + return $row; + }else{ + return false; + } + } + + + + +} \ No newline at end of file From dbe4d9d728b9c2333b6a0acbe63535fd8155d476 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Thu, 21 Nov 2013 02:14:36 +0000 Subject: [PATCH 063/173] =?UTF-8?q?=E6=9B=B4=E6=96=B0Helper\Curl=E5=92=8CH?= =?UTF-8?q?elper\Table=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/module/Helpers/Curl.php | 28 +++++++++++++++++++++------- application/module/Helpers/Table.php | 1 + 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/application/module/Helpers/Curl.php b/application/module/Helpers/Curl.php index dea71661..f801e43d 100644 --- a/application/module/Helpers/Curl.php +++ b/application/module/Helpers/Curl.php @@ -4,21 +4,25 @@ namespace Helpers; class Curl { private $options; - + public $port = 80; + public $H; + public function __construct($options = array()) { - $this->options = array_merge(array( + + } + + public function initOptions($options = array()) + { + $this->options = array_merge(array( 'debug' => false, - 'http_port' => '80', + 'http_port' => $this->port, 'user_agent' => 'Westdc DataService', 'timeout' => 20, 'curlopts' => null, 'verifyssl' => true, ), $options); - } - - public $H; - + } /** * Send a request to the server, receive a response * @@ -88,6 +92,16 @@ class Curl CURLOPT_HTTPHEADER => $headers, CURLOPT_SSL_VERIFYPEER => $options['verifyssl'], ); + + if($this->port === 443) + { + /*$curlOptions += array( + CURLOPT_SSLVERSION => 3, + CURLOPT_SSLCERT => "../application/module/Open/apache.pem", + CURLOPT_SSLKEY => "../application/module/Open/apache.key", + CURLOPT_CAINFO => "../application/module/Open/apache.pem" + );*/ + } if (ini_get('open_basedir') == '' && ini_get('safe_mode') != 'On') { $curlOptions[CURLOPT_FOLLOWLOCATION] = true; diff --git a/application/module/Helpers/Table.php b/application/module/Helpers/Table.php index 69256584..15bab0fb 100644 --- a/application/module/Helpers/Table.php +++ b/application/module/Helpers/Table.php @@ -26,5 +26,6 @@ class Table //开放平台 public $oauth_clients = "oauth_clients"; + public $oauth_token = "oauth_login_token"; public $oauth_access_tokens = "oauth_access_tokens"; } \ No newline at end of file From 580cc39411a90763adbec527616aac9055dab223 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Thu, 21 Nov 2013 03:54:26 +0000 Subject: [PATCH 064/173] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=BC=80?= =?UTF-8?q?=E6=94=BE=E5=B9=B3=E5=8F=B0=E4=B8=ADOauth=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E5=92=8C=E6=9C=8D=E5=8A=A1=E5=99=A8=E7=AB=AF=E9=83=A8?= =?UTF-8?q?=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/module/Open/Client.php | 172 +++++++++++++++++ application/module/Open/Event/AppEvent.php | 10 + application/module/Open/Event/ClientEvent.php | 8 + application/module/Open/Event/OauthEvent.php | 7 + application/module/Open/Event/OpenEvent.php | 7 + .../module/Open/Handler/AppHandler.php | 140 ++++++++++++++ .../module/Open/Handler/ClientHandler.php | 83 ++++++++ .../Handler/ClientTokenHandler/Escience.php | 182 ++++++++++++++++++ .../module/Open/Handler/OauthHandler.php | 46 +++++ .../module/Open/Handler/OpenHandler.php | 46 +++++ .../module/Open/Listener/AppListener.php | 28 +++ .../module/Open/Listener/ClientListener.php | 26 +++ .../module/Open/Listener/OauthListener.php | 25 +++ .../module/Open/Listener/OpenListener.php | 25 +++ application/module/Open/OAuth2.php | 31 +++ application/module/Open/OAuth2/Server.php | 76 ++++++++ application/module/Open/Source.php | 126 ++++++++++++ application/module/Open/server.php | 15 +- 18 files changed, 1039 insertions(+), 14 deletions(-) create mode 100644 application/module/Open/Client.php create mode 100644 application/module/Open/Event/AppEvent.php create mode 100644 application/module/Open/Event/ClientEvent.php create mode 100644 application/module/Open/Event/OauthEvent.php create mode 100644 application/module/Open/Event/OpenEvent.php create mode 100644 application/module/Open/Handler/AppHandler.php create mode 100644 application/module/Open/Handler/ClientHandler.php create mode 100644 application/module/Open/Handler/ClientTokenHandler/Escience.php create mode 100644 application/module/Open/Handler/OauthHandler.php create mode 100644 application/module/Open/Handler/OpenHandler.php create mode 100644 application/module/Open/Listener/AppListener.php create mode 100644 application/module/Open/Listener/ClientListener.php create mode 100644 application/module/Open/Listener/OauthListener.php create mode 100644 application/module/Open/Listener/OpenListener.php create mode 100644 application/module/Open/OAuth2.php create mode 100644 application/module/Open/OAuth2/Server.php create mode 100644 application/module/Open/Source.php diff --git a/application/module/Open/Client.php b/application/module/Open/Client.php new file mode 100644 index 00000000..2bfc6ff6 --- /dev/null +++ b/application/module/Open/Client.php @@ -0,0 +1,172 @@ +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + + $this->table = new \Helpers\Table(); + + $this->target = $target; + + $Listener = new Listener(); + @$this->events()->attachAggregate($Listener); + } + + public function events(\Zend_EventManager_EventCollection $events = NULL) + { + if ($events !== NULL) { + $this->events = $events; + } elseif ($this->events === NULL) { + $this->events = new \Zend_EventManager_EventManager(__CLASS__); + } + return $this->events; + } + + public function initSource() + { + $this->source = new Source('heihedata'); + } + + public function getSource() + { + return $this->source; + } + + //创建获取Code的URL + public function makeRequestCodeUrl($target = NULL) + { + if(empty($this->source)) + { + $this->initSource(); + } + + if(empty($target)) + { + $target = $this->target; + } + + $main_target = $this->source->getTarget($target); + + if($main_target === false) + { + return "此登录接口可能不存在"; + } + + $source = $this->source->getSource($target); + + if($source === false) + { + return "此登录接口暂不可用"; + } + + $main_url = $main_target['code']; + + $param = array( + $source->param['id'] => $source->config['id'], + $source->param['secret'] => $source->config['secret'], + $source->param['callback'] => $source->config['callback'], + $source->param['code_response'] => $main_target['code_response'] + ); + + if(isset($source->config['other'])) + { + $param = array_merge($param,$source->config['other']); + } + + $url = $main_url."?".http_build_query($param); + + return $url; + + } + + //获得token + public function requestToken($code,$target = NULL) + { + if(empty($target)) + { + $target = $this->target; + } + + if(empty($code)) + { + return "未获得您的授权码"; + } + + $main_target = $this->source->getTarget($target); + $client = $this->source->getSource($target); + + if($client === false) + { + return "请求发生错误,登录接口不存在或者可能不再适用"; + } + + $main_url = $main_target['token']; + $param = array( + $client->param['id'] => $client->config['id'], + $client->param['secret'] => $client->config['secret'], + $client->param['grant_type'] => $main_target['grant_type'], + $client->param['callback'] => $client->config['callback'], + $client->param['code'] => $code + ); + + $curl = new Curl(); + $curl->port = 443; + $curl->initOptions(array('verifyssl'=>false)); + $data = $curl->request($main_url,$param,"POST"); + + $cache_data = json_decode($data['response'],true); + + if(!isset($cache_data['expires_in'])) + { + return "未获得授权信息,请重试链接"; + } + + return $cache_data; + + } + + //储存token信息 + public function storageTokenData($type,$token) + { + if(empty($type)) + { + return "接口类型错误"; + } + + if(empty($token)) + { + return "登录信息有误,请重新登录"; + } + + $param = compact("type","token"); + + $results = $this->events()->trigger('tokenStorage', $this, $param); + return $cache_data = $results->bottom(); + + } + + + +} \ No newline at end of file diff --git a/application/module/Open/Event/AppEvent.php b/application/module/Open/Event/AppEvent.php new file mode 100644 index 00000000..9985c74d --- /dev/null +++ b/application/module/Open/Event/AppEvent.php @@ -0,0 +1,10 @@ +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + $this->table = new Table(); + } + + //检查app参数 + public function appCheckParam(\Zend_EventManager_Event $e) + { + $data = $e->getParam('data'); + + if(!is_array($data)) + { + return "参数错误"; + } + + if(empty($data['subject'])) + { + return "请输入应用名称"; + } + + if(empty($data['client_domain'])) + { + return "请填写应用使用的域名,不带www"; + } + + if(empty($data['redirect_uri'])) + { + return "请输入授权成功后的回调地址"; + } + + $sql = "SELECT id FROM {$this->table->oauth_clients} WHERE subject='{$data['subject']}'"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + + if(!empty($row['id'])) + { + return "此应用名称已存在,请重新输入"; + } + + return true; + } + + //处理app参数数据 + public function appProcessData(\Zend_EventManager_Event $e) + { + $data = $e->getParam('data'); + $id = $e->getParam('id'); + + if(empty($id)) + { + $data['client_id'] = $this->create_client_guid(__CLASS__); + $data['client_secret'] = strtoupper(substr(md5($data['client_id'].$data['client_domain'].$data['redirect_uri'].time()),10,24)); + } + $data['user_id'] = view::User('id'); + + return $data; + } + + //创建App成功后 + public function appCreated(\Zend_EventManager_Event $e) + { + $id = $e->getParam('id'); + $data = $e->getParam('data'); + + return true; + } + + //App编辑成功后 + public function appEdited(\Zend_EventManager_Event $e) + { + $id = $e->getParam('id'); + $data = $e->getParam('data'); + + return true; + } + + public function create_client_guid($namespace = '') { + static $guid = ''; + $uid = uniqid("", true); + $data = $namespace; + if(isset($_SERVER['REQUEST_TIME'])) + $data .= $_SERVER['REQUEST_TIME']; + + if(isset($_SERVER['HTTP_USER_AGENT'])) + $data .= $_SERVER['HTTP_USER_AGENT']; + + if(isset($_SERVER['LOCAL_ADDR'])) + $data .= $_SERVER['LOCAL_ADDR']; + + if(isset($_SERVER['LOCAL_PORT'])) + $data .= $_SERVER['LOCAL_PORT']; + + if(isset($_SERVER['REMOTE_ADDR'])) + $data .= $_SERVER['REMOTE_ADDR']; + + if(isset($_SERVER['REMOTE_PORT'])) + $data .= $_SERVER['REMOTE_PORT']; + + $data .= time(); + + $hash = strtoupper(hash('ripemd128', $uid . $guid . md5($data))); + $guid = '' . + substr($hash, 0, 8) . + '-' . + substr($hash, 8, 4) . + '-' . + substr($hash, 12, 4) . + '-' . + substr($hash, 16, 4) . + '-' . + substr($hash, 20, 12) . + ''; + return $guid; + } + +} diff --git a/application/module/Open/Handler/ClientHandler.php b/application/module/Open/Handler/ClientHandler.php new file mode 100644 index 00000000..b3cd8a2f --- /dev/null +++ b/application/module/Open/Handler/ClientHandler.php @@ -0,0 +1,83 @@ +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + $this->table = new Table(); + } + + //获得Handler,type必须与 \Open\Source中同步,否则会出现错误 + // + public function getHandler($type,$data) + { + if($type == 'escience') + { + return new \Open\Handler\ClientTokenHandler\Escience($data); + } + + if($type == 'sina') + { + return new \Open\Handler\ClientTokenHandler\Sina($data); + } + + return false; + } + + //存储token信息 + public function tokenAndDataStorage(\Zend_EventManager_Event $e) + { + $type = $e->getParam('type'); + $data = $e->getParam('token'); + + $handler = $this->getHandler($type,$data); + + if($status = $handler->doit() === true) + { + return true; + }else{ + return $status; + } + } + + //检查用户账户是否存在 + //存在就返回用户信息,不存在返回false + //通用事件,通过各个 TokenHandler中内置Listener直接挂载,不需要引入整个ClientListener + public function userCheck(\Zend_EventManager_Event $e) + { + $email = $e->getParam('email'); + + $user = new Users(); + $current = $user->userExists($email); + + if($current === false) + { + return false; + } + + return $current; + } + +} diff --git a/application/module/Open/Handler/ClientTokenHandler/Escience.php b/application/module/Open/Handler/ClientTokenHandler/Escience.php new file mode 100644 index 00000000..4c13a8e2 --- /dev/null +++ b/application/module/Open/Handler/ClientTokenHandler/Escience.php @@ -0,0 +1,182 @@ +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + $this->table = new Table(); + + //预处理token信息 + $status = $this->preProcess($token); + } + + //考虑加一个接口,每个Token操作类中必须包含此函数 + public function doit() + { + //makeUserStorage在先,必须的 + $status = $this->makeUserStorage(); + + if($status!==true) + { + return $status; + } + + $status = $this->makeTokenStorage(); + + if($status !== true) + { + return $status; + } + + return true; + } + + //预处理 + public function preProcess($tokenData) + { + if(!is_array($tokenData)) + { + return "参数错误"; + } + + $this->userInfo = json_decode($tokenData['userInfo'],true); + + unset($tokenData['userInfo']); + + $this->token = $tokenData; + + return true; + } + + //检查用户信息,如果没有用户自动注册,有用户就自动绑定。 + public function makeUserStorage() + { + $uid = view::User('id'); + + if(is_numeric($uid) && $uid > 0) + { + $this->userid = $uid; + return "您已经登录,无需重复登录"; + } + + if(empty($this->userid)) + { + $current_oauth_email = $this->userInfo['cstnetId']; + + $user = new Users(TRUE); + $current = $user->userExists($current_oauth_email); + + if($current === false) + //自动注册用户 + { + $data = array( + $user->account->FieldUsername => $current_oauth_email, + $user->account->FieldEmail => $current_oauth_email, + $user->account->FieldPasword => 0, + $user->account->FieldRealname => $this->userInfo['truename'], + ); + + $dbh = new dbh(); + + $id = $dbh->insert($user->account->memberTable,$data,true); + + //登录 + $user->account->storeLogin(array( + $user->account->FieldUsername => $data[$user->account->FieldUsername], + $user->account->FieldPasword => $data[$user->account->FieldPasword] + )); + + $this->userid = $id; + + return true; + } + + //帮用户自动登录 + else{ + + $user->account->storeLogin(array( + $user->account->FieldUsername => $current[$user->account->FieldUsername], + $user->account->FieldPasword => $current[$user->account->FieldPasword] + )); + + $this->userid = $current[$user->account->FieldIndex]; + + return true; + } + + } + + } + + //生成写入token表的数据 + //有token记录就更新,没有再插入 + public function makeTokenStorage() + { + $data = array( + 'access_token' => $this->token['access_token'], + 'refresh_token' => $this->token['refresh_token'], + 'expires_in' => $this->token['expires_in'], + 'userid' => $this->userid, + "response_data" => json_encode($this->userInfo,JSON_NUMERIC_CHECK), + "source" => "escience" + ); + + //查看用户用escience登录的记录是否存在 + $sql = "SELECT * FROM {$this->table->oauth_token} WHERE userid={$this->userid} AND source='{$data['source']}' LIMIT 1"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + + $dbh = new dbh(); + + if(isset($row['id'])) + { + $status = $dbh->update($this->table->oauth_token,$data," id={$row['id']} AND userid={$this->userid} "); + if($status) + { + return true; + }else{ + return "更新授权信息时发生错误,请重新登录"; + } + }else{ + $status = $dbh->insert($this->table->oauth_token,$data); + if($status) + { + return true; + }else{ + return "记录授权信息时发生错误,请重新登录"; + } + } + + return true; + } + + +} diff --git a/application/module/Open/Handler/OauthHandler.php b/application/module/Open/Handler/OauthHandler.php new file mode 100644 index 00000000..5a5da972 --- /dev/null +++ b/application/module/Open/Handler/OauthHandler.php @@ -0,0 +1,46 @@ +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + $this->table = new Table(); + } + + public function checkParam(\Zend_EventManager_Event $e) + { + $data = $e->getParam('data'); + + if(!is_array($data)) + { + return "参数错误"; + } + + + + return true; + } + + + +} diff --git a/application/module/Open/Handler/OpenHandler.php b/application/module/Open/Handler/OpenHandler.php new file mode 100644 index 00000000..aa0dc5e0 --- /dev/null +++ b/application/module/Open/Handler/OpenHandler.php @@ -0,0 +1,46 @@ +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + $this->table = new Table(); + } + + public function checkParam(\Zend_EventManager_Event $e) + { + $data = $e->getParam('data'); + + if(!is_array($data)) + { + return "参数错误"; + } + + + + return true; + } + + + +} diff --git a/application/module/Open/Listener/AppListener.php b/application/module/Open/Listener/AppListener.php new file mode 100644 index 00000000..41628b18 --- /dev/null +++ b/application/module/Open/Listener/AppListener.php @@ -0,0 +1,28 @@ +event = new \Zend_EventManager_EventManager(); + } + + public function attach(\Zend_EventManager_EventCollection $events) + { + $Handler = new Handler(); + $events->attach('app.checkParam', array($Handler, 'appCheckParam'), 100); + $events->attach('app.processData', array($Handler, 'appProcessData'), 100); + $events->attach('app.created', array($Handler, 'appCreated'), 100); + $events->attach('app.eidted', array($Handler, 'appEdited'), 100); + } + + public function detach(\Zend_EventManager_EventCollection $events) + { + + } + +} \ No newline at end of file diff --git a/application/module/Open/Listener/ClientListener.php b/application/module/Open/Listener/ClientListener.php new file mode 100644 index 00000000..2ff2ad3e --- /dev/null +++ b/application/module/Open/Listener/ClientListener.php @@ -0,0 +1,26 @@ +event = new \Zend_EventManager_EventManager(); + } + + public function attach(\Zend_EventManager_EventCollection $events) + { + $Handler = new Handler(); + $events->attach('tokenStorage', array($Handler, 'tokenAndDataStorage'), 100); + $events->attach('user.check', array($Handler, 'userCheck'), 100); + } + + public function detach(\Zend_EventManager_EventCollection $events) + { + + } + +} \ No newline at end of file diff --git a/application/module/Open/Listener/OauthListener.php b/application/module/Open/Listener/OauthListener.php new file mode 100644 index 00000000..65056b9d --- /dev/null +++ b/application/module/Open/Listener/OauthListener.php @@ -0,0 +1,25 @@ +event = new \Zend_EventManager_EventManager(); + } + + public function attach(\Zend_EventManager_EventCollection $events) + { + $Handler = new OauthHandler(); + $events->attach('submit.checkParam', array($Handler, 'checkParam'), 100); + } + + public function detach(\Zend_EventManager_EventCollection $events) + { + + } + +} \ No newline at end of file diff --git a/application/module/Open/Listener/OpenListener.php b/application/module/Open/Listener/OpenListener.php new file mode 100644 index 00000000..64a06730 --- /dev/null +++ b/application/module/Open/Listener/OpenListener.php @@ -0,0 +1,25 @@ +event = new \Zend_EventManager_EventManager(); + } + + public function attach(\Zend_EventManager_EventCollection $events) + { + $Handler = new Handler(); + $events->attach('submit.checkParam', array($Handler, 'checkParam'), 100); + } + + public function detach(\Zend_EventManager_EventCollection $events) + { + + } + +} \ No newline at end of file diff --git a/application/module/Open/OAuth2.php b/application/module/Open/OAuth2.php new file mode 100644 index 00000000..f31d6f37 --- /dev/null +++ b/application/module/Open/OAuth2.php @@ -0,0 +1,31 @@ +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + $this->table = new Table(); + + } + + //用户使用谷歌账号登陆 + public function googleClient() + { + + } +} \ No newline at end of file diff --git a/application/module/Open/OAuth2/Server.php b/application/module/Open/OAuth2/Server.php new file mode 100644 index 00000000..05508c18 --- /dev/null +++ b/application/module/Open/OAuth2/Server.php @@ -0,0 +1,76 @@ +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + $this->table = new Table(); + } + + //根据ID或者Client_id获得app的信息 + public function getClientInfo($id) + { + if(empty($id)) + { + return "无效参数"; + } + + if(is_numeric($id)) + { + $field = "id"; + }else{ + $field = "client_id"; + } + + $sql = "SELECT * FROM {$this->table->oauth_clients} WHERE $field=? LIMIT 1"; + $sth = $this->db->prepare($sql); + $sth->execute(array($id)); + $row = $sth->fetch(); + + return $row; + } + + //验证App + public function clientCredentials($client_id,$client_secret) + { + + $client = $this->getClientInfo($client_id); + + if(empty($client['id'])) + { + return "此应用ID未被证实"; + } + + if($client['status'] == -1) + { + return "此应用已关闭"; + } + + if($client['client_secret'] !== $client_secret) + { + return "Invalid client secret"; + } + + return true; + } + + +} \ No newline at end of file diff --git a/application/module/Open/Source.php b/application/module/Open/Source.php new file mode 100644 index 00000000..51e82760 --- /dev/null +++ b/application/module/Open/Source.php @@ -0,0 +1,126 @@ +source = new stdClass(); + $this->target = new stdClass(); + + $this->website = $website; + + $this->initSourceConfig(); + $this->initTarget(); + } + + //获得当前绑定的站点 + public function getCurrentSite(){ + return $this->website; + } + + //设置绑定的站点 + public function setCurrentSite($website){ + $this->website = $website; + $this->initSourceConfig(); + } + + private function initSourceConfig() + { + if(!in_array($this->website,$this->sourceType)) + { + return false; + } + + // Escience + // passport.escience.cn + $this->source->escience = new stdClass(); + $this->source->escience->param = array( + "id" => "client_id", + "secret" => "client_secret", + "code_response" => "response_type", + "grant_type" => "grant_type", + "callback" => "redirect_uri", + "code"=>"code" + ); + + if($this->website == 'westdc'){ + + $this->source->escience->config = array( + 'id' => '71852', + 'secret' => 'ad7gd3jZgbzhQM6vIh9vPnQFZQoTGHZI', + 'index' => 'http://westdc.westgis.ac.cn', + 'callback' => 'http://westdc.westgis.ac.cn/account/callback/type/escience', + 'other' => array( + 'theme'=>'full' + ) + ); + + } + + if($this->website == 'heihedata'){ + + $this->source->escience->config = array( + 'id' => '78969', + 'secret' => 'iTGKdCkUPakA2hza2TJ4XZ4cnwlh8Hqz', + 'index' => 'http://www.heihedata.org', + 'callback' => 'http://www.heihedata.org/account/callback/type/escience', + 'other' => array( + 'theme'=>'full' + ) + ); + + } + + } + + //获得一个源 + public function getSource($type = "") + { + if(empty($type)) + { + return $this->source; + }else{ + if(isset($this->source->$type)) + { + return $this->source->$type; + }else{ + return false; + } + } + } + + //Oauth2登录目标 + private function initTarget(){ + $this->target->escience = array( + 'name' => '中国科技网通行证', + 'code' => 'http://passport.escience.cn/oauth2/authorize', + 'token' => 'https://passport.escience.cn/oauth2/token', + 'code_response' => 'code', + 'grant_type' => 'authorization_code', + ); + } + + //获得Oauth2登录模板 + public function getTarget($type = "") + { + if(empty($type)) + { + return $this->target; + }else{ + if(isset($this->target->$type)) + { + return $this->target->$type; + }else{ + return false; + } + } + } + +} \ No newline at end of file diff --git a/application/module/Open/server.php b/application/module/Open/server.php index ee0b7408..3406b448 100644 --- a/application/module/Open/server.php +++ b/application/module/Open/server.php @@ -29,22 +29,9 @@ class Server extends \Zend_Controller_Plugin_Abstract } } - public function bootstrap() + public function getCode() { - $dsn = "pgsql:dbname={$this->config->db->params->dbname};host={$this->config->db->params->host}"; - $storage = new \OAuth2\Storage\Pdo(array('dsn' => $dsn, 'username' => $this->config->db->params->username, 'password' => $this->config->db->params->password)); - - $server = new \OAuth2\Server($storage); - - $server->addGrantType(new \OAuth2\GrantType\ClientCredentials($storage)); - - $server->addGrantType(new \OAuth2\GrantType\AuthorizationCode($storage)); - - //应用授权 - //$server->handleTokenRequest(OAuth2\Request::createFromGlobals())->send(); - - return $server; } } \ No newline at end of file From 0e11fd37d797d6e968444c9c7256e01611df36a3 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Thu, 21 Nov 2013 03:56:00 +0000 Subject: [PATCH 065/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20\Open\server=20?= =?UTF-8?q?=E4=B8=BA=20\Open\Server?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/module/Open/{server.php => Server.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename application/module/Open/{server.php => Server.php} (100%) diff --git a/application/module/Open/server.php b/application/module/Open/Server.php similarity index 100% rename from application/module/Open/server.php rename to application/module/Open/Server.php From 6ab8c24f949f22bd7066a6306415bc0dc146816b Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Thu, 21 Nov 2013 06:21:22 +0000 Subject: [PATCH 066/173] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86OpenControll?= =?UTF-8?q?er=EF=BC=8C=E5=A2=9E=E5=8A=A0=E4=BA=86accountController?= =?UTF-8?q?=E4=B8=AD=E5=85=B3=E4=BA=8EOauth=E4=BA=A4=E4=BA=92=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/AccountController.php | 47 +++++ .../default/controllers/OpenController.php | 165 ++++++++++++++++++ .../scripts/account/application-add.phtml | 43 +++++ .../views/scripts/account/application.phtml | 25 +++ .../views/scripts/account/callback.phtml | 46 +++++ .../default/views/scripts/account/left.phtml | 1 + .../default/views/scripts/account/login.phtml | 3 + 7 files changed, 330 insertions(+) create mode 100644 application/default/controllers/OpenController.php create mode 100644 application/default/views/scripts/account/application-add.phtml create mode 100644 application/default/views/scripts/account/application.phtml create mode 100644 application/default/views/scripts/account/callback.phtml diff --git a/application/default/controllers/AccountController.php b/application/default/controllers/AccountController.php index 2601283e..cfec11f1 100755 --- a/application/default/controllers/AccountController.php +++ b/application/default/controllers/AccountController.php @@ -1,6 +1,7 @@ _getParam('type'); + $client = new Client(); + $url = $client->makeRequestCodeUrl($type); + + view::Post($this,"为您转入科技网登录入口",$url); + } + + //oauth2登录回调地址 + public function callbackAction() + { + $type = $this->_getParam('type'); + $code = $this->_getParam('code'); + + $client = new Client($type); + + $client->initSource(); + $target = $client->getSource()->getTarget($type); + $this->view->target_name = $target['name']; + + //$token = $client->requestToken($code); + + $token = array( + "expires_in"=>(int)432000, + "refresh_token"=>(string)"eb40e792e05a21e779aa89d71066fa61", + "userInfo"=>(string)'{"passwordType":"password_umt","securityEmail":"liujin834@live.com","cstnetIdStatus":"active","umtId":"10247308","truename":"李建轩","cstnetId":"liujin834@live.com","type":"umt"}', + "access_token"=>(string)"48415c56215f5cd26baabe403864aaf7" + ); + + if(is_string($token)) + { + view::Post($this,$token,'/account/login'); + } + + $status = $client->storageTokenData($type,$token); + + if($status === true) + { + echo ""; + }else{ + echo $status; + } + } } diff --git a/application/default/controllers/OpenController.php b/application/default/controllers/OpenController.php new file mode 100644 index 00000000..65805abe --- /dev/null +++ b/application/default/controllers/OpenController.php @@ -0,0 +1,165 @@ +view->config = $this->config = \Zend_Registry::get('config'); + $this->db = \Zend_Registry::get('db'); + $this->view->theme = new Theme(); + $this->_helper->layout->setLayout('layout-open'); + } + + function indexAction() + { + $this->view->pageID = "open-index"; + } + + //我的应用 + function myappAction() + { + $this->view->pageID = "open-myapp"; + + $app = new App(); + + $user_state = $app->checkinfo(); + if( $user_state !== true) + { + view::post($this,$user_state,"/account/edit"); + } + + $ac = $this->_getParam('ac'); + $id = $this->_getParam('id'); + $submit = $this->_getParam('submit'); + + if(empty($ac)) + { + $this->view->myapp = $app->getUserApp(); + return true; + } + + if($ac == "create") + { + $this->_helper->viewRenderer('myapp-create'); + + $this->view->appStatus = $app->appStatus(); + + if(!empty($id)) + { + $this->view->info = $app->getAppInfo($id); + } + + if(!empty($submit)) + { + if(empty($id)) + { + $status = $app->appCreate(); + }else{ + $this->view->info = $app->getAppCreateParam(); + $status = $app->appCreate($id); + } + + if($status !== true && !is_numeric($status)) + { + $this->view->error = view::Error($status); + }else{ + if(!empty($id)) + view::Post($this,"修改成功!",'/open/myapp/ac/view/id/'.$id); + else + view::Post($this,"添加成功!","/open/myapp/ac/view/id/".$status); + } + + } + return true; + } + + if($ac == "delete") + { + $status = $app->delete($id); + if($status !== true) + { + view::Post($this,$status,"/open/myapp"); + }else{ + view::Post($this,'删除成功',"/open/myapp"); + } + return false; + } + + if($ac == "view") + { + $this->_helper->viewRenderer('myapp-view'); + $this->view->data = $app->getAppInfo($id); + $this->view->appStatus = $app->appStatus(); + return true; + } + + } + + function authenticateAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $data = array( + 'client_id' => $this->_getParam('client_id'), + 'redirect_uri' => $this->_getParam('redirect_uri'), + 'client_secret' => $this->_getParam('client_secret'), + 'host' => $_SERVER['HTTP_HOST'], + 'ip' => $_SERVER['REMOTE_ADDR'] + ); + + $server = new Server(); + + $status = $server->clientCredentials($data['client_id'],$data['client_secret']); + + if($status !== true) + { + echo $status; + }else{ + + } + + } + + function authorizeAction() + { + $submit = $this->_getParam('submit'); + + if(empty($submit)) + { + return true; + } + + $sv = new open\server(); + $server = $sv->bootstrap(); + + $request = OAuth2\Request::createFromGlobals(); + $response = new OAuth2\Response(); + + // validate the authorize request + if (!$server->validateAuthorizeRequest($request, $response)) { + $response->send(); + die; + } + + // print the authorization code if the user has authorized your client + $is_authorized = ($_POST['authorized'] === 'yes'); + $server->handleAuthorizeRequest($request, $response, $is_authorized); + if ($is_authorized) { + // this is only here so that you get to see your code in the cURL request. Otherwise, we'd redirect back to the client + $code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=')+5, 40); + exit("SUCCESS! Authorization Code: $code"); + } + $response->send(); + } + +} + diff --git a/application/default/views/scripts/account/application-add.phtml b/application/default/views/scripts/account/application-add.phtml new file mode 100644 index 00000000..192d78b2 --- /dev/null +++ b/application/default/views/scripts/account/application-add.phtml @@ -0,0 +1,43 @@ +headTitle($this->config->title->site); + $this->headTitle('网站接入'); + $this->headTitle()->setSeparator(' - '); +?> +
      +
      + +
      +
      +

      应用接入

      +
      + msg)) { ?> + msg ?> + + error)) { ?> + error ?> + +
      +
      + +
      + info['name']; ?>" /> +
      +
      +
      + +
      + info['uri']; ?>" /> +
      +
      + +
      + + + +
      + + +
      +
      diff --git a/application/default/views/scripts/account/application.phtml b/application/default/views/scripts/account/application.phtml new file mode 100644 index 00000000..699fad4d --- /dev/null +++ b/application/default/views/scripts/account/application.phtml @@ -0,0 +1,25 @@ +headTitle($this->config->title->site); + $this->headTitle('我的账户'); + $this->headTitle()->setSeparator(' - '); +?> +
      +
      + +
      +
      + 应用接入 +

      应用管理

      +
      + msg)) { ?> + msg ?> + + error)) { ?> + error ?> + + + +
      +
      diff --git a/application/default/views/scripts/account/callback.phtml b/application/default/views/scripts/account/callback.phtml new file mode 100644 index 00000000..2c476ed5 --- /dev/null +++ b/application/default/views/scripts/account/callback.phtml @@ -0,0 +1,46 @@ +headTitle($this->config->title->site); + $this->headTitle('用户登录'); + $this->headTitle()->setSeparator(' - '); + $this->breadcrumb('首页'); + $this->breadcrumb('用户登录'); + $this->breadcrumb()->setSeparator(' > '); +?> + +
      +
      + target_name) ? "":"您已经使用 ".$this->target_name." 账号登录
      " ?> +
      +
      +
      + + +
      + \ No newline at end of file diff --git a/application/default/views/scripts/account/left.phtml b/application/default/views/scripts/account/left.phtml index 8608f255..c219e4d7 100644 --- a/application/default/views/scripts/account/left.phtml +++ b/application/default/views/scripts/account/left.phtml @@ -2,6 +2,7 @@ + diff --git a/application/default/views/scripts/account/login.phtml b/application/default/views/scripts/account/login.phtml index e53bd83d..a362a769 100755 --- a/application/default/views/scripts/account/login.phtml +++ b/application/default/views/scripts/account/login.phtml @@ -64,6 +64,9 @@
      +
      +
      其它账号登录
      +中国科技网通行证
      "; - }else{ - echo $status; - } - } - -} - +view->config = Zend_Registry::get('config'); + $this->_request->setParam('return', $this->_request->getServer('REQUEST_URI')); + $this->db = Zend_Registry::get('db'); + $this->view->messages = $this->messenger->getMessages(); + $this->view->theme = new Theme(); + } + + function indexAction() + { + $this->view->pageID = "account-index"; + + include_once("Users.php"); + $usr = new Users($this->db); + + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $uid = $user->id; + } + + include_once("Avatar.php"); + $avatar = new Avatar(); + $this->view->avatar = $avatar->Get($user->email,140); + + $this->view->info = $usr->getUserInfo($uid); + } + + function editAction() + { + $this->view->pageID = "account-edit"; + + include_once("Users.php"); + $usr = new Users($this->db); + + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $uid = $user->id; + } + + include_once("Avatar.php"); + $avatar = new Avatar(); + $this->view->avatar = $avatar->Get($user->email,140); + + $this->view->projectType = array( + "无" => '', + "国家973计划项目课题" => "国家973计划项目课题", + "国家863计划课题"=>"国家863计划课题", + "国家级科技支撑课题" => "国家级科技支撑课题", + "国家级科技重大专项" => "国家级科技重大专项", + "国家级国家重大工程" => "国家级国家重大工程", + "国家级国家自然科学基金" => "国家级国家自然科学基金", + "国际合作项目"=>"国际合作项目", + "省部级项目" => "省部级项目", + "其他项目工程" => "其他项目工程" + ); + + $submit = $this->_getParam('submit'); + + if(!empty($submit)) + { + $data = $this->AccountEditParamFilter(); + + if($this->db->update("users",$data,"id=$uid")) + { + $this->view->AlertType = "alert-success"; + $this->view->msg = "修改成功!"; + $this->view->jump_url = "/account/edit"; + return true; + }else{ + $this->view->AlertType = "alert-error"; + $this->view->error = "修改失败,请重试"; + $this->view->info = $data; + return true; + } + }else{ + $this->view->info = $usr->getUserInfo($uid); + } + } + + function AccountEditParamFilter(){ + $data = array(); + $data['realname'] = substr(trim($this->_getParam('realname')),0,40); + $data['unit'] = substr(trim($this->_getParam('unit')),0,100); + $data['address'] = substr(trim($this->_getParam('address')),0,100); + $data['phone'] = substr(trim($this->_getParam('phone')),0,15); + $data['postcode'] = substr(trim($this->_getParam('postcode')),0,15); + $data['project_type'] = substr(trim($this->_getParam('project_type')),0,100); + $data['project_id'] = substr(trim($this->_getParam('project_id')),0,40); + $data['project_title'] = substr(trim($this->_getParam('project_title')),0,100); + $data['project'] = substr(trim($this->_getParam('project')),0,600); + + foreach($data as $k=>$v) + { + $data[$k] = $this->StringFilter($v); + } + + return $data; + } + + function StringFilter($string){ + $string = preg_replace ('/<[^>]*>/', ' ', $string); + return $string; + } + + function secureAction() + { + $this->view->pageID = "account-secure"; + + include_once("Users.php"); + $usr = new Users($this->db); + + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $uid = $user->id; + } + + $opt = $this->_getParam('opt'); + $submit = $this->_getParam('submit'); + + if(empty($opt)) + { + $this->view->section = "password"; + if(!empty($submit)) + { + $data = $this->AccountSecureParamFilter(); + + $this->view->AlertType = "alert-error"; + if(strlen($data['password'])>18 || strlen($data['new_password'])>18) + { + $this->view->error = view::Error("密码过长"); + return true; + } + if(strlen($data['new_password'])<=6 || strlen($data['new_password_confrim'])<=6) + { + $this->view->error = view::Error("密码过短,请输入大于6位的密码"); + return true; + } + if(md5($data['new_password']) != md5($data['new_password_confrim'])) + { + $this->view->error = view::Error("两次输入的密码不相同"); + return true; + } + + $sql = "SELECT password FROM users WHERE id=$uid"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + + if(md5($data['password']) != $row['password']) + { + $this->view->error = view::Error("原密码不正确"); + return true; + } + + $data['password'] = md5($data['new_password']); + + unset($data['new_password']); + unset($data['new_password_confrim']); + + if($this->db->update("users",$data,"id=$uid")) + { + view::Post($this,array("content"=>'修改成功!','url'=>'/account/secure')); + return true; + }else{ + $this->view->error = view::Error("修改失败"); + return true; + } + }else{ + $this->view->info = $usr->getUserInfo($uid); + } + }//password + + if($opt == "email") + { + $this->view->section = "email"; + if(!empty($submit)) + { + $email = $this->_getParam('email'); + $password = $this->_getParam('password'); + + if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i",$email)) + { + $this->view->error = view::Error("错误的邮箱格式"); + return true; + } + + $sql = "SELECT password FROM users WHERE id=$uid"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + + if(md5($password) != $row['password']) + { + $this->view->error = view::Error("原密码错误"); + return true; + } + + $data['email'] = $email; + + if($this->db->update("users",$data,"id=$uid")) + { + view::Post($this,array("content"=>'修改成功!','url'=>'/account/secure')); + return true; + }else{ + $this->view->error = view::Error("修改失败"); + return true; + } + }else{ + $this->view->info = $usr->getUserInfo($uid); + } + }//email + } + + function AccountSecureParamFilter(){ + $data = array(); + $data['password'] = trim($this->_getParam('password')); + $data['new_password'] = trim($this->_getParam('new_password')); + $data['new_password_confrim'] = trim($this->_getParam('new_password_confrim')); + foreach($data as $k=>$v) + { + $data[$k] = $this->StringFilter($v); + } + return $data; + } + + function init() + { + $this->messenger=$this->_helper->getHelper('FlashMessenger'); + } + + function postDispatch() + { + //$this->view->messages = $this->messenger->getMessages(); + } + + function registerAction() + { + $form = new RegisterForm(); + $this->view->form = $form; + + if ($this->_request->isPost()) { + $formData = $this->_request->getPost(); + if ($form->isValid($formData)) { + $ut = new UsersTable(); + $u = $ut->createRow(); + $u->username = $form->getValue('username'); + $u->password = $form->getValue('password'); + $u->email=$form->getValue('email'); + if ($form->getValue('realname')) $u->realname=$form->getValue('realname'); + if ($form->getValue('phone')) $u->phone=$form->getValue('phone'); + if ($form->getValue('address')) $u->address=$form->getValue('address'); + if ($form->getValue('unit')) $u->unit=$form->getValue('unit'); + if ($form->getValue('project')) $u->project=$form->getValue('project'); + if ($u->save()) { + + //注册邮件 + $mail_template = "member-register"; + $mail_data = array( + 'name'=>$formData['username'], + ); + + $mail = new Mail(); + + $mail->loadTemplate($mail_template,$mail_data); + $mail->addTo($formData['email'],$formData['username']); + $mail->send(); + + //自动登录系统 + $this->login($formData['username'],$formData['password']); + $this->_redirect('/'); + } + } else { + $form->populate($formData); + } + } + } + + function loginAction() + { + + $success=false; + + $options = array( + 'module' => $this->_request->getModuleName(), + 'controller' => $this->_request->getControllerName(), + 'action' => $this->_request->getActionName(), + ); + + $auth = Zend_Auth::getInstance(); + if ($auth->hasIdentity()) + { + view::Post($this,"您已经登录,无需重复登录",-1); + return true; + } + + $tohref = $this->_request->getParam('href'); + + if(($options['module']=="default" && $options['controller'] == "account" && $options['action'] == "login")) + { + $this->view->href = $_SERVER['REQUEST_URI']; + } + + if($tohref == "/account/login") + { + $this->view->href = $tohref = "/"; + } + + if(!empty($tohref)) + { + $this->view->href = $tohref; + } + + $captcha = $this->loadCaptcha(); + + $submit = $this->_getParam("submit"); + if(!empty($submit)) + { + $username = trim($this->_request->getParam('username')); + $password = trim($this->_request->getParam('password')); + $captchaword = trim($this->_request->getParam('captcha')); + + if(empty($username)) + { + $this->setCaptcha($captcha); + $this->view->error = "请输入用户名"; + return true; + } + + if(empty($password)) + { + $this->setCaptcha($captcha); + $this->view->error = "请输入密码"; + return true; + } + + if(empty($captchaword)) + { + $this->setCaptcha($captcha); + $this->view->error = "请输入验证码"; + return true; + } + + if(!isset($_SESSION['captcha'])) + { + $_SESSION['captcha'] = md5(time()); + } + + if ($captchaword != $_SESSION['captcha']) { + $this->setCaptcha($captcha); + $this->view->error = "验证码错误"; + return true; + } + + if (!$this->login($username,$password)) + { + $this->setCaptcha($captcha); + $this->view->error = "用户名或密码错误"; + $this->view->userid = $username; + return true; + } + else + { + if(!empty($tohref)) + { + view::Post($this,"登录成功,正在跳转",$tohref); + return true; + } + } + }else{ + $this->setCaptcha($captcha); + } + + } + + function loadCaptcha() + { + $captcha = new Zend_Captcha_Image(array( + 'captcha' => 'Image', + 'wordLen' => 4, + 'fontsize'=>16, + 'width' => 100, + 'height' => 38, + 'dotNoiseLevel'=>2, + 'lineNoiseLevel'=>1, + 'timeout' => 300, + 'font' => '../data/fonts/ggbi.ttf', + 'imgDir' => 'vdimg/', + 'imgUrl' => '/vdimg', + )); + return $captcha; + } + + function setCaptcha(Zend_Captcha_Image $captcha,$ajax = false){ + $captcha->generate(); + $_SESSION['captcha'] = $captcha->getWord(); + $url = $captcha->getImgUrl() + .$captcha->getId() + .$captcha->getSuffix(); + if(!$ajax) + { + $this->view->captcha = $url; + }else{ + return $url; + } + } + + function captchaAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $captcha = $this->loadCaptcha(); + $url = $this->setCaptcha($captcha,true); + + echo $url; + return true; + } + + function logoutAction() + { + $auth = Zend_Auth::getInstance(); + $auth->clearIdentity(); + require_once 'member.php'; + $mb=new member(); + member::flushcookie(); + $this->_redirect('/'); + } + + private function default_login($u,$p) + { + $auth = Zend_Auth::getInstance(); + $db=Zend_Registry::get('db'); + + $authAdapter = new Zend_Auth_Adapter_DbTable($db); + $authAdapter->setTableName('users') + ->setIdentityColumn('username') + ->setCredentialColumn('password'); + $authAdapter->setIdentity($u)->setCredential(md5($p)); + $result = $auth->authenticate($authAdapter); + if ($result->isValid()) { + // success: store database row to auth's storage + $data = $authAdapter->getResultRowObject(null,'password'); + + //头像 + include_once("Avatar.php"); + $avatar = new Avatar(); + $data->avatar = $avatar->Get($data->email,40); + + //组ID + include_once("Users.php"); + $usr = new Users($db); + $data->gid = $usr->getGroup($data->id); + + $auth->getStorage()->write($data); + $db->query("update users set ts_last_login=now() where username=?",array($u)); + + if ($this->_request->getParam('remember')) { + $sql="select usertype from users where username='$u'"; + $rs=$db->query($sql); + $row=$rs->fetch(); + //if($row['usertype']!='administrator') + { + require_once 'member.php'; + $mb = new member(); + $mb -> putcookie($u,md5($p)); + } + } + + return true; + }else + { + return false; + } + return false; + } + private function aspnet_login($p,$salt,$password) + { + $p1=implode("\x00",str_split($p))."\x00"; + $ball=base64_decode($salt).$p1; + return trim($password)==base64_encode(sha1($ball,true)); + } + // 首先判断是否存在salt + // 若有salt,则按照aspnet membership加密算法进行判断 + function login($u,$p) + { + $ut= new UsersTable(); + $db=$ut->getAdapter(); + $sql="select password,salt from users where username=?"; + $uq=$db->query($sql,array($u)); + if ($urow=$uq->fetchObject()) + { + if (empty($urow->salt)) + return $this->default_login($u,$p); + else { + //进行判断并进行转换到默认 + if ($this->aspnet_login($p,$urow->salt,$urow->password)) + { + $sql="update users set password=md5(?),salt='' where username=?"; + $db->query($sql,array($p,$u)); + return $this->default_login($u,$p); + } else + return false; + } + } else { + //没有对应的用户,登录失败 + return false; + } + } + function fetchpwdAction() + { + $ut= new UsersTable(); + $db=$ut->getAdapter(); + $form = new LostpwdForm(); + $key=$this->_request->getParam('key'); + $login=$this->_request->getParam('login'); + if (empty($key) && empty($login)) { + $this->view->form = $form; + if ($this->_request->isPost()) { + $formData = $this->_request->getPost(); + if ($form->isValid($formData)) { + $sql="select * from users where email=?"; + $uq=$db->query($sql,array($formData['email'])); + if ($urow=$uq->fetchObject()) + { + //email the url to user + $username=$urow->username; + $sql="update users set activation=? where email=?"; + $uid=uniqid(); + $db->query($sql,array($uid,$formData['email'])); + + //发邮件 + $mail_template = "users-changepassword"; + $mail_data = array( + 'name'=>$username, + 'url' => view::getHostLink()."/account/fetchpwd/".$username."/".$uid + ); + + $mail = new Mail(); + + $mail->loadTemplate($mail_template,$mail_data); + $mail->addTo($formData['email'],$username); + $mail->send(); + + + $this->view->messages[]='请检查您的新邮件中的确认激活链接。'; + $this->view->form=false;//do not echo form + } else + $this->messenger->addMessage('对不起,没有找到对应的电子邮件地址。'); + } + } else + $this->view->messages[]='请输入您的电子邮件地址。您将通过电子邮件收到新密码。'; + } else { + $sql="select * from users where username=? and activation=?"; + $uq=$db->query($sql,array($login,$key)); + $tmp_pwd=uniqid(); + if ($urow=$uq->fetchObject()) + { + $sql="update users set salt='',activation='',password=md5('".$tmp_pwd."') where username=? and activation=?"; + $db->query($sql,array($login,$key)); + + //发邮件 + $mail_template = "users-changepassword"; + $mail_data = array( + 'name'=>$login, + 'tmp_pwd' => $tmp_pwd + ); + + $mail = new Mail(); + + $mail->loadTemplate($mail_template,$mail_data); + $mail->addTo($urow->email,$login); + $mail->send(); + + $this->view->messages[]='请查收您新邮件中的新密码'; + $this->view->form=false;//do not echo form + + } + } + + } //找回密码 + + //OAuth2登录跳转页面 + public function oauth2loginAction() + { + $type = $this->_getParam('type'); + $client = new Client(); + $url = $client->makeRequestCodeUrl($type); + + view::Post($this,"为您转入科技网登录入口",$url); + } + + //oauth2登录回调地址 + public function callbackAction() + { + $type = $this->_getParam('type'); + $code = $this->_getParam('code'); + + $client = new Client($type); + + $client->initSource(); + $target = $client->getSource()->getTarget($type); + $this->view->target_name = $target['name']; + + $token = $client->requestToken($code); + + if(is_string($token)) + { + view::Post($this,$token,'/account/login'); + } + + $status = $client->storageTokenData($type,$token); + + if($status === true) + { + echo ""; + }else{ + echo $status; + } + } + +} + From 580e97cc9d13198e61bce2a8813cb5758162c32f Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 22 Nov 2013 03:16:53 +0000 Subject: [PATCH 068/173] change acl --- application/models/CustomControllerAclManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/models/CustomControllerAclManager.php b/application/models/CustomControllerAclManager.php index 7e275887..60330350 100755 --- a/application/models/CustomControllerAclManager.php +++ b/application/models/CustomControllerAclManager.php @@ -32,7 +32,7 @@ $this->acl->deny(null, 'author'); // add an exception so guests can log in or register // in order to gain privilege - $this->acl->allow('guest', 'account', array('login', + $this->acl->allow('guest', 'account', array('login','oauth2login','callback', 'logout', 'captcha', 'fetchpwd', From 74a5e3f5fc02dfeabb8b6fefb982975712184c76 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Fri, 22 Nov 2013 03:29:30 +0000 Subject: [PATCH 069/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86Oauth?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=97=B6=E5=AF=86=E7=A0=81=E9=87=8D=E5=A4=8D?= =?UTF-8?q?md5=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Handler/ClientTokenHandler/Escience.php | 364 ++++----- application/module/Users/Account.php | 737 +++++++++--------- 2 files changed, 553 insertions(+), 548 deletions(-) diff --git a/application/module/Open/Handler/ClientTokenHandler/Escience.php b/application/module/Open/Handler/ClientTokenHandler/Escience.php index 4c13a8e2..68759322 100644 --- a/application/module/Open/Handler/ClientTokenHandler/Escience.php +++ b/application/module/Open/Handler/ClientTokenHandler/Escience.php @@ -1,182 +1,182 @@ -db = \Zend_Registry::get('db'); - }else{ - $this->db = $db; - } - - $this->config = \Zend_Registry::get('config'); - $this->table = new Table(); - - //预处理token信息 - $status = $this->preProcess($token); - } - - //考虑加一个接口,每个Token操作类中必须包含此函数 - public function doit() - { - //makeUserStorage在先,必须的 - $status = $this->makeUserStorage(); - - if($status!==true) - { - return $status; - } - - $status = $this->makeTokenStorage(); - - if($status !== true) - { - return $status; - } - - return true; - } - - //预处理 - public function preProcess($tokenData) - { - if(!is_array($tokenData)) - { - return "参数错误"; - } - - $this->userInfo = json_decode($tokenData['userInfo'],true); - - unset($tokenData['userInfo']); - - $this->token = $tokenData; - - return true; - } - - //检查用户信息,如果没有用户自动注册,有用户就自动绑定。 - public function makeUserStorage() - { - $uid = view::User('id'); - - if(is_numeric($uid) && $uid > 0) - { - $this->userid = $uid; - return "您已经登录,无需重复登录"; - } - - if(empty($this->userid)) - { - $current_oauth_email = $this->userInfo['cstnetId']; - - $user = new Users(TRUE); - $current = $user->userExists($current_oauth_email); - - if($current === false) - //自动注册用户 - { - $data = array( - $user->account->FieldUsername => $current_oauth_email, - $user->account->FieldEmail => $current_oauth_email, - $user->account->FieldPasword => 0, - $user->account->FieldRealname => $this->userInfo['truename'], - ); - - $dbh = new dbh(); - - $id = $dbh->insert($user->account->memberTable,$data,true); - - //登录 - $user->account->storeLogin(array( - $user->account->FieldUsername => $data[$user->account->FieldUsername], - $user->account->FieldPasword => $data[$user->account->FieldPasword] - )); - - $this->userid = $id; - - return true; - } - - //帮用户自动登录 - else{ - - $user->account->storeLogin(array( - $user->account->FieldUsername => $current[$user->account->FieldUsername], - $user->account->FieldPasword => $current[$user->account->FieldPasword] - )); - - $this->userid = $current[$user->account->FieldIndex]; - - return true; - } - - } - - } - - //生成写入token表的数据 - //有token记录就更新,没有再插入 - public function makeTokenStorage() - { - $data = array( - 'access_token' => $this->token['access_token'], - 'refresh_token' => $this->token['refresh_token'], - 'expires_in' => $this->token['expires_in'], - 'userid' => $this->userid, - "response_data" => json_encode($this->userInfo,JSON_NUMERIC_CHECK), - "source" => "escience" - ); - - //查看用户用escience登录的记录是否存在 - $sql = "SELECT * FROM {$this->table->oauth_token} WHERE userid={$this->userid} AND source='{$data['source']}' LIMIT 1"; - $rs = $this->db->query($sql); - $row = $rs->fetch(); - - $dbh = new dbh(); - - if(isset($row['id'])) - { - $status = $dbh->update($this->table->oauth_token,$data," id={$row['id']} AND userid={$this->userid} "); - if($status) - { - return true; - }else{ - return "更新授权信息时发生错误,请重新登录"; - } - }else{ - $status = $dbh->insert($this->table->oauth_token,$data); - if($status) - { - return true; - }else{ - return "记录授权信息时发生错误,请重新登录"; - } - } - - return true; - } - - -} +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + $this->table = new Table(); + + //预处理token信息 + $status = $this->preProcess($token); + } + + //考虑加一个接口,每个Token操作类中必须包含此函数 + public function doit() + { + //makeUserStorage在先,必须的 + $status = $this->makeUserStorage(); + + if($status!==true) + { + return $status; + } + + $status = $this->makeTokenStorage(); + + if($status !== true) + { + return $status; + } + + return true; + } + + //预处理 + public function preProcess($tokenData) + { + if(!is_array($tokenData)) + { + return "参数错误"; + } + + $this->userInfo = json_decode($tokenData['userInfo'],true); + + unset($tokenData['userInfo']); + + $this->token = $tokenData; + + return true; + } + + //检查用户信息,如果没有用户自动注册,有用户就自动绑定。 + public function makeUserStorage() + { + $uid = view::User('id'); + + if(is_numeric($uid) && $uid > 0) + { + $this->userid = $uid; + return "您已经登录,无需重复登录"; + } + + if(empty($this->userid)) + { + $current_oauth_email = $this->userInfo['cstnetId']; + + $user = new Users(TRUE); + $current = $user->userExists($current_oauth_email); + + if($current === false) + //自动注册用户 + { + $data = array( + $user->account->FieldUsername => $current_oauth_email, + $user->account->FieldEmail => $current_oauth_email, + $user->account->FieldPasword => 0, + $user->account->FieldRealname => $this->userInfo['truename'], + ); + + $dbh = new dbh(); + + $id = $dbh->insert($user->account->memberTable,$data,true); + + //登录 + $user->account->storeLogin(array( + $user->account->FieldUsername => $data[$user->account->FieldUsername], + $user->account->FieldPasword => $data[$user->account->FieldPasword] + )); + + $this->userid = $id; + + return true; + } + + //帮用户自动登录 + else{ + + $user->account->storeLogin(array( + $user->account->FieldUsername => $current[$user->account->FieldUsername], + $user->account->FieldPasword => $current[$user->account->FieldPasword] + ),false); + + $this->userid = $current[$user->account->FieldIndex]; + + return true; + } + + } + + } + + //生成写入token表的数据 + //有token记录就更新,没有再插入 + public function makeTokenStorage() + { + $data = array( + 'access_token' => $this->token['access_token'], + 'refresh_token' => $this->token['refresh_token'], + 'expires_in' => $this->token['expires_in'], + 'userid' => $this->userid, + "response_data" => json_encode($this->userInfo,JSON_NUMERIC_CHECK), + "source" => "escience" + ); + + //查看用户用escience登录的记录是否存在 + $sql = "SELECT * FROM {$this->table->oauth_token} WHERE userid={$this->userid} AND source='{$data['source']}' LIMIT 1"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + + $dbh = new dbh(); + + if(isset($row['id'])) + { + $status = $dbh->update($this->table->oauth_token,$data," id={$row['id']} AND userid={$this->userid} "); + if($status) + { + return true; + }else{ + return "更新授权信息时发生错误,请重新登录"; + } + }else{ + $status = $dbh->insert($this->table->oauth_token,$data); + if($status) + { + return true; + }else{ + return "记录授权信息时发生错误,请重新登录"; + } + } + + return true; + } + + +} diff --git a/application/module/Users/Account.php b/application/module/Users/Account.php index 1297d529..717a34d6 100644 --- a/application/module/Users/Account.php +++ b/application/module/Users/Account.php @@ -1,367 +1,372 @@ -db = \Zend_Registry::get('db'); - }else{ - $this->db = $db; - } - - $this->config = \Zend_Registry::get('config'); - - if($initializingListener === TRUE) - { - $this->loadListener(); - } - } - - public function loadListener() - { - //主要操作,账号注册,登录,设置session等 - $AccountListener = new AccountListener(); - @$this->events()->attachAggregate($AccountListener); - - //账户编辑 - $EditListener = new EditListener(); - @$this->events()->attachAggregate($EditListener); - - //账户安全性(找回密码) - $PwdListener = new PwdListener(); - @$this->events()->attachAggregate($PwdListener); - } - - public function events(\Zend_EventManager_EventCollection $events = NULL) - { - if ($events !== NULL) { - $this->events = $events; - } elseif ($this->events === NULL) { - $this->events = new \Zend_EventManager_EventManager(__CLASS__); - } - return $this->events; - } - - //获取账号信息,数组 - public function getAccountInfo($id = 0) - { - if($id == 0) - { - $id = view::User('id'); - } - $sql = "SELECT * FROM {$this->memberTable} WHERE id=$id"; - $rs = $this->db->query($sql); - return $rs->fetch(); - } - - //注册 - public function register($data) - { - $params = compact('data'); - $results = $this->events()->trigger('register.checkParam', $this, $params); - $cache_data = $results->bottom(); - - if($cache_data !== true) - { - if(!is_array($cache_data)) - { - return array('error'=>$cache_data); - }else{ - return $cache_data; - } - } - - $results = $this->events()->trigger('register.checkUser', $this, $params); - $cache_data = $results->bottom(); - - if($cache_data !== true) - { - if(!is_array($cache_data)) - { - return array('error'=>$cache_data); - }else{ - return $cache_data; - } - } - - $loginData = array( - 'username'=>$data['username'], - 'password'=>$data['password'] - ); - - $data['password'] = md5($data['password']); - $data['usertype'] = "member"; - unset($data['confirm_password']); - - $dbh = new dbh(); - - $id = $dbh->insert($this->memberTable,$data,true); - - if(!empty($id) && is_numeric($id)) - { - $this->storeLogin($loginData); - $mb = new Member(); - $mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]); //username, md5(password) - $params = compact('data','id'); - $results = $this->events()->trigger('register.success', $this, $params); - return array("success" => 1); - }else{ - if($id === false) - { - return array('error'=>'服务器开小差了,请稍后再试'); - }else{ - return array('error'=>'服务器处理中遇到错误,请联系管理员'); - } - } - - }//register - - //登陆 - public function login($data) - { - $results = $this->events()->trigger('login.checkParam', $this, compact('data')); - $cache_data = $results->bottom(); - - if($cache_data !== true) - { - if(!is_array($cache_data)) - { - return array('error'=>$cache_data); - }else{ - return $cache_data; - } - } - - $state = $this->storeLogin($data); - - $mb = new Member(); - $mb->putcookie($data[$this->FieldUsername],md5($data[$this->FieldPasword])); - - return $state; - }//login - - //storeLogin - //将登录信息保存在session和cookie中 - public function storeLogin($data) - { - $auth = \Zend_Auth::getInstance(); - $authAdapter = new \Zend_Auth_Adapter_DbTable($this->db); - $authAdapter->setTableName($this->memberTable) - ->setIdentityColumn($this->FieldUsername) - ->setCredentialColumn($this->FieldPasword); - - if($data[$this->FieldPasword] == 0) - { - $password = "0"; - }else{ - $password = md5($data[$this->FieldPasword]); - } - - $authAdapter->setIdentity($data[$this->FieldUsername])->setCredential($password); - - $result = $auth->authenticate($authAdapter); - if ($result->isValid()) { - - $user = $authAdapter->getResultRowObject(null,$this->FieldPasword); - $email = $user->email; - $results = $this->events()->trigger('login.success.createAvatar', $this, compact('email')); - $user->avatar = $results->bottom(); - $auth->getStorage()->write($user); - - $id = $user->id; - @$results = $this->events()->trigger('login.success.updateStatus', $this, compact('id')); - - return array('success'=>1); - } - return array('error'=>'处理中发现错误,请重试'); - } - - //注册信息参数 - public function getParam(\Zend_Controller_Request_Abstract $request) - { - $data = array( - 'username'=>$request->getParam('username'), - 'password'=>$request->getParam('password'), - 'confirm_password'=>$request->getParam('confirm_password'), - 'email'=>$request->getParam('email'), - 'realname'=>$request->getParam('realname') - ); - return $data; - } - - //获取用户账户修改参数 - public function getEditParam(\Zend_Controller_Request_Abstract $request) - { - $type = $request->getParam('type'); - - if($type == "general") - { - $data = array( - 'realname'=>$request->getParam('realname'), - 'signature'=>$request->getParam('signature'), - 'description'=>$request->getParam('description') - ); - } - - if($type == "password") - { - $data = array( - 'password' => $request->getParam('password'), - 'password_new'=>$request->getParam('password_new'), - 'password_confirm'=>$request->getParam('password_confirm') - ); - } - return $data; - } - - //编辑 - public function edit($data,$type) - { - $results = $this->events()->trigger('edit.checkParam', $this, compact('data','type')); - $cache_data = $results->bottom(); - - if($cache_data !== true) - { - return $cache_data; - } - - if($type == "general") - { - $data['signature'] = htmlspecialchars($data['signature']); - $data['description'] = htmlspecialchars($data['description']); - }else if($type == "password") - { - $data['password'] = md5($data['password_new']); - unset($data['password_new']); - unset($data['password_confirm']); - }else{ - return "参数错误"; - } - - $dbh = new dbh(); - $uid = view::User('id'); - if($dbh->update($this->memberTable,$data," id=$uid") === true) - { - return true; - }else{ - return false; - } - } - - //找回密码 - public function getMyPassword($email) - { - $results = $this->events()->trigger('pwd.forgot.checkParam', $this, compact('email')); - $cache_data = $results->bottom(); - - if($cache_data !== true) - { - return $cache_data; - } - - $sql = "SELECT * FROM {$this->memberTable} WHERE email='$email'"; - $rs = $this->db->query($sql); - $row = $rs->fetch(); - - if(!isset($row['username']) || empty($row['username'])) - { - return array('error'=>"此邮箱并未注册",'place'=>'email'); - } - - $salt = md5($email.'---'.$row['username']); - - $sql = "UPDATE {$this->memberTable} SET salt='$salt' WHERE id={$row['id']}"; - $state = $this->db->exec($sql); - - if($state<1) - { - return array('error'=>"处理中出现错误,请重试",'place'=>'email'); - } - - $mail_template = "forgotpassword"; - $mail_data = array( - 'name'=>$row['realname'], - 'link'=> view::getHostLink().'/account/getpassword/salt/'.$salt - ); - - $mail = new Mail(); - - $mail->loadTemplate($mail_template,$mail_data); - $mail->addTo($email,$row['realname']); - $mail->send(); - - return array("success"=>1); - } - - //重置密码 - public function resetPassword($data) - { - $results = $this->events()->trigger('pwd.reset.checkParam', $this, compact('data')); - $cache_data = $results->bottom(); - - if($cache_data !== true) - { - return $cache_data; - } - - $sql = "SELECT * FROM {$this->memberTable} WHERE salt=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($data['salt'])); - $row = $sth->fetch(); - - if(!isset($row['username']) || empty($row['username'])) - { - return array('error'=>"您提供的校验码不正确,请重新申请重置密码",'place'=>'confirm_password'); - } - - if($row['username'] !== $data['username']) - { - return array('error'=>"您提供的校验码不正确,请重新申请重置密码",'place'=>'confirm_password'); - } - - $sql = "UPDATE {$this->memberTable} SET password='".md5($data['password'])."',salt='' WHERE id={$row['id']}"; - $this->db->exec($sql); - - $mail_template = "getpassworded"; - $mail_data = array( - 'name'=>$row['realname'], - ); - $mail = new Mail(); - $mail->loadTemplate($mail_template,$mail_data); - $mail->addTo($row['email'],$row['realname']); - $mail->send(); - - return true; - - } - +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + + if($initializingListener === TRUE) + { + $this->loadListener(); + } + } + + public function loadListener() + { + //主要操作,账号注册,登录,设置session等 + $AccountListener = new AccountListener(); + @$this->events()->attachAggregate($AccountListener); + + //账户编辑 + $EditListener = new EditListener(); + @$this->events()->attachAggregate($EditListener); + + //账户安全性(找回密码) + $PwdListener = new PwdListener(); + @$this->events()->attachAggregate($PwdListener); + } + + public function events(\Zend_EventManager_EventCollection $events = NULL) + { + if ($events !== NULL) { + $this->events = $events; + } elseif ($this->events === NULL) { + $this->events = new \Zend_EventManager_EventManager(__CLASS__); + } + return $this->events; + } + + //获取账号信息,数组 + public function getAccountInfo($id = 0) + { + if($id == 0) + { + $id = view::User('id'); + } + $sql = "SELECT * FROM {$this->memberTable} WHERE id=$id"; + $rs = $this->db->query($sql); + return $rs->fetch(); + } + + //注册 + public function register($data) + { + $params = compact('data'); + $results = $this->events()->trigger('register.checkParam', $this, $params); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + if(!is_array($cache_data)) + { + return array('error'=>$cache_data); + }else{ + return $cache_data; + } + } + + $results = $this->events()->trigger('register.checkUser', $this, $params); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + if(!is_array($cache_data)) + { + return array('error'=>$cache_data); + }else{ + return $cache_data; + } + } + + $loginData = array( + 'username'=>$data['username'], + 'password'=>$data['password'] + ); + + $data['password'] = md5($data['password']); + $data['usertype'] = "member"; + unset($data['confirm_password']); + + $dbh = new dbh(); + + $id = $dbh->insert($this->memberTable,$data,true); + + if(!empty($id) && is_numeric($id)) + { + $this->storeLogin($loginData); + $mb = new Member(); + $mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]); //username, md5(password) + $params = compact('data','id'); + $results = $this->events()->trigger('register.success', $this, $params); + return array("success" => 1); + }else{ + if($id === false) + { + return array('error'=>'服务器开小差了,请稍后再试'); + }else{ + return array('error'=>'服务器处理中遇到错误,请联系管理员'); + } + } + + }//register + + //登陆 + public function login($data) + { + $results = $this->events()->trigger('login.checkParam', $this, compact('data')); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + if(!is_array($cache_data)) + { + return array('error'=>$cache_data); + }else{ + return $cache_data; + } + } + + $state = $this->storeLogin($data); + + $mb = new Member(); + $mb->putcookie($data[$this->FieldUsername],md5($data[$this->FieldPasword])); + + return $state; + }//login + + //storeLogin + //将登录信息保存在session和cookie中 + public function storeLogin($data,$md5verify = true) + { + $auth = \Zend_Auth::getInstance(); + $authAdapter = new \Zend_Auth_Adapter_DbTable($this->db); + $authAdapter->setTableName($this->memberTable) + ->setIdentityColumn($this->FieldUsername) + ->setCredentialColumn($this->FieldPasword); + + if($data[$this->FieldPasword] == 0) + { + $password = "0"; + }else{ + if($md5verify === false) + { + $password = $data[$this->FieldPasword]; + }else{ + $password = md5($data[$this->FieldPasword]); + } + } + + $authAdapter->setIdentity($data[$this->FieldUsername])->setCredential($password); + + $result = $auth->authenticate($authAdapter); + if ($result->isValid()) { + + $user = $authAdapter->getResultRowObject(null,$this->FieldPasword); + $email = $user->email; + $results = $this->events()->trigger('login.success.createAvatar', $this, compact('email')); + $user->avatar = $results->bottom(); + $auth->getStorage()->write($user); + + $id = $user->id; + @$results = $this->events()->trigger('login.success.updateStatus', $this, compact('id')); + + return array('success'=>1); + } + return array('error'=>'处理中发现错误,请重试'); + } + + //注册信息参数 + public function getParam(\Zend_Controller_Request_Abstract $request) + { + $data = array( + 'username'=>$request->getParam('username'), + 'password'=>$request->getParam('password'), + 'confirm_password'=>$request->getParam('confirm_password'), + 'email'=>$request->getParam('email'), + 'realname'=>$request->getParam('realname') + ); + return $data; + } + + //获取用户账户修改参数 + public function getEditParam(\Zend_Controller_Request_Abstract $request) + { + $type = $request->getParam('type'); + + if($type == "general") + { + $data = array( + 'realname'=>$request->getParam('realname'), + 'signature'=>$request->getParam('signature'), + 'description'=>$request->getParam('description') + ); + } + + if($type == "password") + { + $data = array( + 'password' => $request->getParam('password'), + 'password_new'=>$request->getParam('password_new'), + 'password_confirm'=>$request->getParam('password_confirm') + ); + } + return $data; + } + + //编辑 + public function edit($data,$type) + { + $results = $this->events()->trigger('edit.checkParam', $this, compact('data','type')); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + return $cache_data; + } + + if($type == "general") + { + $data['signature'] = htmlspecialchars($data['signature']); + $data['description'] = htmlspecialchars($data['description']); + }else if($type == "password") + { + $data['password'] = md5($data['password_new']); + unset($data['password_new']); + unset($data['password_confirm']); + }else{ + return "参数错误"; + } + + $dbh = new dbh(); + $uid = view::User('id'); + if($dbh->update($this->memberTable,$data," id=$uid") === true) + { + return true; + }else{ + return false; + } + } + + //找回密码 + public function getMyPassword($email) + { + $results = $this->events()->trigger('pwd.forgot.checkParam', $this, compact('email')); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + return $cache_data; + } + + $sql = "SELECT * FROM {$this->memberTable} WHERE email='$email'"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + + if(!isset($row['username']) || empty($row['username'])) + { + return array('error'=>"此邮箱并未注册",'place'=>'email'); + } + + $salt = md5($email.'---'.$row['username']); + + $sql = "UPDATE {$this->memberTable} SET salt='$salt' WHERE id={$row['id']}"; + $state = $this->db->exec($sql); + + if($state<1) + { + return array('error'=>"处理中出现错误,请重试",'place'=>'email'); + } + + $mail_template = "forgotpassword"; + $mail_data = array( + 'name'=>$row['realname'], + 'link'=> view::getHostLink().'/account/getpassword/salt/'.$salt + ); + + $mail = new Mail(); + + $mail->loadTemplate($mail_template,$mail_data); + $mail->addTo($email,$row['realname']); + $mail->send(); + + return array("success"=>1); + } + + //重置密码 + public function resetPassword($data) + { + $results = $this->events()->trigger('pwd.reset.checkParam', $this, compact('data')); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + return $cache_data; + } + + $sql = "SELECT * FROM {$this->memberTable} WHERE salt=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($data['salt'])); + $row = $sth->fetch(); + + if(!isset($row['username']) || empty($row['username'])) + { + return array('error'=>"您提供的校验码不正确,请重新申请重置密码",'place'=>'confirm_password'); + } + + if($row['username'] !== $data['username']) + { + return array('error'=>"您提供的校验码不正确,请重新申请重置密码",'place'=>'confirm_password'); + } + + $sql = "UPDATE {$this->memberTable} SET password='".md5($data['password'])."',salt='' WHERE id={$row['id']}"; + $this->db->exec($sql); + + $mail_template = "getpassworded"; + $mail_data = array( + 'name'=>$row['realname'], + ); + $mail = new Mail(); + $mail->loadTemplate($mail_template,$mail_data); + $mail->addTo($row['email'],$row['realname']); + $mail->send(); + + return true; + + } + } \ No newline at end of file From eb98d79dfc747c35f9fc32db40cb2a1fdfaa7661 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Tue, 26 Nov 2013 09:40:33 +0000 Subject: [PATCH 070/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E9=87=8D?= =?UTF-8?q?=E7=BD=AE=E7=94=B3=E8=AF=B7=E8=A1=A8=E7=9A=84=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=BF=AE=E6=94=B9=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E4=BB=A3=E7=A0=81=E7=9A=84=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/Order/Manager/Offlineapp.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/application/module/Order/Manager/Offlineapp.php b/application/module/Order/Manager/Offlineapp.php index 099692d2..15a15168 100644 --- a/application/module/Order/Manager/Offlineapp.php +++ b/application/module/Order/Manager/Offlineapp.php @@ -75,15 +75,15 @@ class Offlineapp "; $rs = $this->db->query($sql); return $rs->fetchAll(); - }// - - //判断是否存在wsn数据申请 - public function hasWsnData($id) - { - $sql="select count(d.id) as wsn from dataorder d left join dataservice s on d.uuid=s.uuid where d.offlineappid=$id and s.service_type in (1,2) and position('waterwsn' in s.service_url)>0 and d.selection is not null"; - $rs=$this->db->query($sql); - $row=$rs->fetch(); - return $row['wsn']; + }// + + //判断是否存在wsn数据申请 + public function hasWsnData($id) + { + $sql="select count(d.id) as wsn from dataorder d left join dataservice s on d.uuid=s.uuid where d.offlineappid=$id and s.service_type in (1,2) and position('waterwsn' in s.service_url)>0 and d.selection is not null"; + $rs=$this->db->query($sql); + $row=$rs->fetch(); + return $row['wsn']; } //重置申请表 @@ -100,7 +100,7 @@ class Offlineapp @unlink($row['applicationform']); } - if($this->db->exec("UPDATE offlineapp SET applicationform=NULL WHERE id=$id")>0) + if($this->db->exec("UPDATE offlineapp SET applicationform=NULL,status=2 WHERE id=$id")>0 && $this->db->exec("UPDATE dataorder SET status=2 WHERE offlineappid=$id")) { @$this->events()->trigger('offlineapp.AppFormReseted', $this, compact('id')); return true; From 35c08833553790713ef87d4cd206a41414589a07 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Tue, 26 Nov 2013 10:04:02 +0000 Subject: [PATCH 071/173] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86card.westgis?= =?UTF-8?q?.ac.cn=E7=9A=84=E7=A7=91=E6=8A=80=E7=BD=91=E9=80=9A=E8=A1=8C?= =?UTF-8?q?=E8=AF=81Appkey=E5=92=8CAppsecret?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/module/Open/Source.php | 61 ++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 15 deletions(-) diff --git a/application/module/Open/Source.php b/application/module/Open/Source.php index 51e82760..49730998 100644 --- a/application/module/Open/Source.php +++ b/application/module/Open/Source.php @@ -50,8 +50,13 @@ class Source "code"=>"code" ); - if($this->website == 'westdc'){ + //新浪微博(新浪通行证) + $this->source->sina = new stdClass(); + $this->source->sina->param = array( + ); + + if($this->website == 'westdc'){ $this->source->escience->config = array( 'id' => '71852', 'secret' => 'ad7gd3jZgbzhQM6vIh9vPnQFZQoTGHZI', @@ -61,11 +66,9 @@ class Source 'theme'=>'full' ) ); - } if($this->website == 'heihedata'){ - $this->source->escience->config = array( 'id' => '78969', 'secret' => 'iTGKdCkUPakA2hza2TJ4XZ4cnwlh8Hqz', @@ -75,9 +78,48 @@ class Source 'theme'=>'full' ) ); - } + if($this->website == 'card'){ + $this->source->escience->config = array( + 'id' => '58176', + 'secret' => 'ZM5dEFX5GpJC62IcJ3iajx51T9hzhJkQ', + 'index' => 'http://card.westgis.ac.cn/', + 'callback' => 'http://card.westgis.ac.cn/account/callback/type/escience', + 'other' => array( + 'theme'=>'full' + ) + ); + } + + } + + //Oauth2登录目标 + /* + name : 名称 + code : 获取code的url + token : 获取 token的url + code_response : 获取token时使用的参数值(配合$this->source->OBJECTIVE->param中的code_response使用 + grant_type : 获得token的认证方式,按照oauth2标准,应该是authorization_code + */ + private function initTarget(){ + //中国科技网通行证 + $this->target->escience = array( + 'name' => '中国科技网通行证', + 'code' => 'http://passport.escience.cn/oauth2/authorize', + 'token' => 'https://passport.escience.cn/oauth2/token', + 'code_response' => 'code', + 'grant_type' => 'authorization_code', + ); + + //新浪 + $this->target->sina = array( + 'name' => '新浪微博', + 'code' => 'https://api.weibo.com/oauth2/authorize', + 'token' => '', + 'code_response' => 'code', + 'grant_type' => 'authorization_code' + ); } //获得一个源 @@ -96,17 +138,6 @@ class Source } } - //Oauth2登录目标 - private function initTarget(){ - $this->target->escience = array( - 'name' => '中国科技网通行证', - 'code' => 'http://passport.escience.cn/oauth2/authorize', - 'token' => 'https://passport.escience.cn/oauth2/token', - 'code_response' => 'code', - 'grant_type' => 'authorization_code', - ); - } - //获得Oauth2登录模板 public function getTarget($type = "") { From 5ae05fb85d4581b3843595e329ab3418a4df3ace Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 29 Nov 2013 01:47:32 +0000 Subject: [PATCH 072/173] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=88=90=E6=9E=9C?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E4=B8=AD=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/default/controllers/AboutController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/default/controllers/AboutController.php b/application/default/controllers/AboutController.php index 27f44c3a..647115d9 100755 --- a/application/default/controllers/AboutController.php +++ b/application/default/controllers/AboutController.php @@ -86,7 +86,7 @@ class AboutController extends Zend_Controller_Action $siteid="e31f5ea7-a4af-4ae3-9ac1-1a84132c4338";//site uuid from geonetowrk if(empty($ac)) { - $sql="select * from mdref mr left join reference r on mr.refid=r.id where mr.uuid=? order by r.id desc"; + $sql="select * from mdref mr left join reference r on mr.refid=r.id where mr.uuid=? and mr.reftype=0 order by r.year desc,r.title asc"; $sth = $this->db->prepare($sql); $sth->execute(array($siteid)); $rows = $sth->fetchAll(); From 8f208ef7c5b96ba023ad61ca8465c4c6b959cc9f Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Fri, 29 Nov 2013 02:26:06 +0000 Subject: [PATCH 073/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9curl=E4=B8=AD?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E5=88=9D=E5=A7=8B=E5=8C=96=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/module/Helpers/Curl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/module/Helpers/Curl.php b/application/module/Helpers/Curl.php index f801e43d..b36ad768 100644 --- a/application/module/Helpers/Curl.php +++ b/application/module/Helpers/Curl.php @@ -9,7 +9,7 @@ class Curl public function __construct($options = array()) { - + $this->initOptions($options); } public function initOptions($options = array()) From 7e6ad54e7f31028a1e94be35d0368748a936cb74 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Fri, 13 Dec 2013 08:42:34 +0000 Subject: [PATCH 074/173] submit user account register issue --- .../default/controllers/AccountController.php | 739 +++++------------- .../default/views/scripts/account/login.phtml | 8 - .../views/scripts/account/register.phtml | 100 ++- .../default/views/scripts/index/index.phtml | 7 +- application/module/Helpers/Curl.php | 31 +- application/module/Helpers/MCrypt.php | 46 ++ application/module/Helpers/View.php | 31 + application/module/Users/Account.php | 379 +++++++++ application/module/Users/Event/EditEvent.php | 11 + application/module/Users/Event/LoginEvent.php | 12 + application/module/Users/Event/PwdEvent.php | 13 + .../module/Users/Event/RegisterEvent.php | 13 + application/module/Users/Gravatar.php | 20 + .../module/Users/Listener/AccountListener.php | 64 ++ .../module/Users/Listener/EditListener.php | 35 + .../module/Users/Listener/PwdListener.php | 30 + application/module/Users/Member.php | 138 ++++ .../module/Users/Operation/EditOperate.php | 88 +++ .../module/Users/Operation/LoginOperate.php | 115 +++ .../module/Users/Operation/PwdOperate.php | 94 +++ .../Users/Operation/RegisterOperate.php | 182 +++++ application/module/Users/Users.php | 86 ++ 22 files changed, 1674 insertions(+), 568 deletions(-) create mode 100644 application/module/Helpers/MCrypt.php create mode 100644 application/module/Users/Account.php create mode 100644 application/module/Users/Event/EditEvent.php create mode 100644 application/module/Users/Event/LoginEvent.php create mode 100644 application/module/Users/Event/PwdEvent.php create mode 100644 application/module/Users/Event/RegisterEvent.php create mode 100644 application/module/Users/Gravatar.php create mode 100644 application/module/Users/Listener/AccountListener.php create mode 100644 application/module/Users/Listener/EditListener.php create mode 100644 application/module/Users/Listener/PwdListener.php create mode 100644 application/module/Users/Member.php create mode 100644 application/module/Users/Operation/EditOperate.php create mode 100644 application/module/Users/Operation/LoginOperate.php create mode 100644 application/module/Users/Operation/PwdOperate.php create mode 100644 application/module/Users/Operation/RegisterOperate.php create mode 100644 application/module/Users/Users.php diff --git a/application/default/controllers/AccountController.php b/application/default/controllers/AccountController.php index 40dd9b20..625c8a5d 100755 --- a/application/default/controllers/AccountController.php +++ b/application/default/controllers/AccountController.php @@ -1,305 +1,101 @@ view->config = Zend_Registry::get('config'); $this->_request->setParam('return', $this->_request->getServer('REQUEST_URI')); - $this->db = Zend_Registry::get('db'); - $this->view->messages = $this->messenger->getMessages(); - $this->view->theme = new Theme(); + $this->db=Zend_Registry::get('db'); + $this->view->Theme = new Theme(); } function indexAction() { - $this->view->pageID = "account-index"; - - include_once("Users.php"); - $usr = new Users($this->db); - - $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { - $user = $auth->getIdentity(); - $uid = $user->id; - } - - include_once("Avatar.php"); - $avatar = new Avatar(); - $this->view->avatar = $avatar->Get($user->email,140); - - $this->view->info = $usr->getUserInfo($uid); - } - - function editAction() - { - $this->view->pageID = "account-edit"; - - include_once("Users.php"); - $usr = new Users($this->db); - - $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { - $user = $auth->getIdentity(); - $uid = $user->id; - } - - include_once("Avatar.php"); - $avatar = new Avatar(); - $this->view->avatar = $avatar->Get($user->email,140); - - $this->view->projectType = array( - "无" => '', - "国家973计划项目课题" => "国家973计划项目课题", - "国家863计划课题"=>"国家863计划课题", - "国家级科技支撑课题" => "国家级科技支撑课题", - "国家级科技重大专项" => "国家级科技重大专项", - "国家级国家重大工程" => "国家级国家重大工程", - "国家级国家自然科学基金" => "国家级国家自然科学基金", - "国际合作项目"=>"国际合作项目", - "省部级项目" => "省部级项目", - "其他项目工程" => "其他项目工程" - ); - $submit = $this->_getParam('submit'); + $account = new Account(); + if(!empty($submit)) { - $data = $this->AccountEditParamFilter(); + $data = $account->getEditParam($this->_request); + $Listener = new EditListener(); + @$account->events()->attachAggregate($Listener); + $this->view->section = $type = $this->_getParam('type'); + $status = $account->edit($data,$type); + if($status !== true) + { + $this->view->error = view::Error($status); + }else{ + $this->view->error = view::Error("修改成功","alert-success"); + } + } + + $user = $account->getAccountInfo(); + $av = new Gravatar(); + $this->view->avatar = $av->Get($user['email'],100); + $this->view->user = $user; + } + + function loginAction() + { + $request = new \Zend_Controller_Request_Http(); + if($request->isXmlHttpRequest()) + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); - if($this->db->update("users",$data,"id=$uid")) + $data = $this->_getParam('data'); + if(empty($data)) { - $this->view->AlertType = "alert-success"; - $this->view->msg = "修改成功!"; - $this->view->jump_url = "/account/edit"; - return true; - }else{ - $this->view->AlertType = "alert-error"; - $this->view->error = "修改失败,请重试"; - $this->view->info = $data; + $this->jsonexit(array('error'=>'服务器掉链子了,请重试')); + } + + $data = \Helpers\MCrypt::decrypt($data,"DY7567"); + $data = json_decode($data,true); + + $account = new Account(); + $result = $account->login($data,true); + + if(!empty($result)) + { + $content = json_encode($result,JSON_NUMERIC_CHECK); + echo \Helpers\MCrypt::encrypt($content,"CH6668"); return true; } - }else{ - $this->view->info = $usr->getUserInfo($uid); + + $this->jsonexit(array('error'=>'服务器掉链子了,请重试')); + + return true; } - } - - function AccountEditParamFilter(){ - $data = array(); - $data['realname'] = substr(trim($this->_getParam('realname')),0,40); - $data['unit'] = substr(trim($this->_getParam('unit')),0,100); - $data['address'] = substr(trim($this->_getParam('address')),0,100); - $data['phone'] = substr(trim($this->_getParam('phone')),0,15); - $data['postcode'] = substr(trim($this->_getParam('postcode')),0,15); - $data['project_type'] = substr(trim($this->_getParam('project_type')),0,100); - $data['project_id'] = substr(trim($this->_getParam('project_id')),0,40); - $data['project_title'] = substr(trim($this->_getParam('project_title')),0,100); - $data['project'] = substr(trim($this->_getParam('project')),0,600); - - foreach($data as $k=>$v) - { - $data[$k] = $this->StringFilter($v); - } - - return $data; - } - - function StringFilter($string){ - $string = preg_replace ('/<[^>]*>/', ' ', $string); - return $string; - } - - function secureAction() - { - $this->view->pageID = "account-secure"; - - include_once("helper/view.php"); - include_once("Users.php"); - $usr = new Users($this->db); - - $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { - $user = $auth->getIdentity(); - $uid = $user->id; - } - - $opt = $this->_getParam('opt'); - $submit = $this->_getParam('submit'); - - if(empty($opt)) - { - $this->view->section = "password"; - if(!empty($submit)) - { - $data = $this->AccountSecureParamFilter(); - $this->view->AlertType = "alert-error"; - if(strlen($data['password'])>18 || strlen($data['new_password'])>18) - { - $this->view->error = view::Error("密码过长"); - return true; - } - if(strlen($data['new_password'])<=6 || strlen($data['new_password_confrim'])<=6) - { - $this->view->error = view::Error("密码过短,请输入大于6位的密码"); - return true; - } - if(md5($data['new_password']) != md5($data['new_password_confrim'])) - { - $this->view->error = view::Error("两次输入的密码不相同"); - return true; - } - - $sql = "SELECT password FROM users WHERE id=$uid"; - $rs = $this->db->query($sql); - $row = $rs->fetch(); - - if(md5($data['password']) != $row['password']) - { - $this->view->error = view::Error("原密码不正确"); - return true; - } - - $data['password'] = md5($data['new_password']); - - unset($data['new_password']); - unset($data['new_password_confrim']); - - if($this->db->update("users",$data,"id=$uid")) - { - view::Post($this,array("content"=>'修改成功!','url'=>'/account/secure')); - return true; - }else{ - $this->view->error = view::Error("修改失败"); - return true; - } - }else{ - $this->view->info = $usr->getUserInfo($uid); - } - }//password - - if($opt == "email") - { - $this->view->section = "email"; - if(!empty($submit)) - { - $email = $this->_getParam('email'); - $password = $this->_getParam('password'); - - if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i",$email)) - { - $this->view->error = view::Error("错误的邮箱格式"); - return true; - } - - $sql = "SELECT password FROM users WHERE id=$uid"; - $rs = $this->db->query($sql); - $row = $rs->fetch(); - - if(md5($password) != $row['password']) - { - $this->view->error = view::Error("原密码错误"); - return true; - } - - $data['email'] = $email; - - if($this->db->update("users",$data,"id=$uid")) - { - view::Post($this,array("content"=>'修改成功!','url'=>'/account/secure')); - return true; - }else{ - $this->view->error = view::Error("修改失败"); - return true; - } - }else{ - $this->view->info = $usr->getUserInfo($uid); - } - }//email - } - - function AccountSecureParamFilter(){ - $data = array(); - $data['password'] = trim($this->_getParam('password')); - $data['new_password'] = trim($this->_getParam('new_password')); - $data['new_password_confrim'] = trim($this->_getParam('new_password_confrim')); - foreach($data as $k=>$v) - { - $data[$k] = $this->StringFilter($v); - } - return $data; - } - - function init() - { - $this->messenger=$this->_helper->getHelper('FlashMessenger'); - } - - function postDispatch() - { - //$this->view->messages = $this->messenger->getMessages(); - } - - function registerAction() - { - $form = new RegisterForm(); - $this->view->form = $form; - - if ($this->_request->isPost()) { - $formData = $this->_request->getPost(); - if ($form->isValid($formData)) { - $ut = new UsersTable(); - $u = $ut->createRow(); - $u->username = $form->getValue('username'); - $u->password = $form->getValue('password'); - $u->email=$form->getValue('email'); - if ($form->getValue('realname')) $u->realname=$form->getValue('realname'); - if ($form->getValue('phone')) $u->phone=$form->getValue('phone'); - if ($form->getValue('address')) $u->address=$form->getValue('address'); - if ($form->getValue('unit')) $u->unit=$form->getValue('unit'); - if ($form->getValue('project')) $u->project=$form->getValue('project'); - if ($u->save()) { - //发送欢迎邮件 - $mail=new WestdcMailer($this->view->config->smtp); - $body=file_get_contents($this->view->config->register->email->template); - $body=str_replace("[username]",$formData['username'],$body); - $mail->setBodyText($body); - $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); - $mail->addTo($formData['email']); - //中文标题有乱码,在1.5版本中尚未解决 - //ref: http://framework.zend.com/issues/browse/ZF-2532 - $mail->setSubject('欢迎使用中国西部环境与生态数据中心'); - $mail->send(); - - //自动登录系统 - $this->login($formData['username'],$formData['password']); - $this->_redirect('/'); - } - } else { - $form->populate($formData); - } - } - } - - function loginAction() - { - include_once("helper/view.php"); - - $success=false; + $success=false; $options = array( 'module' => $this->_request->getModuleName(), 'controller' => $this->_request->getControllerName(), 'action' => $this->_request->getActionName(), ); - + $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { - view::Post($this,"您已经登录,无需重复登录",-1); - return true; + if($options['module']=="default" && $options['controller'] == "account" && $options['action'] == "login") + { + $this->_redirect("/"); + }else{ + $this->_redirect($_SERVER['REQUEST_URI']); + } } $tohref = $this->_request->getParam('href'); @@ -309,294 +105,169 @@ class AccountController extends Zend_Controller_Action $this->view->href = $_SERVER['REQUEST_URI']; } - if($tohref == "/account/login") - { - $this->view->href = $tohref = "/"; - } - if(!empty($tohref)) { $this->view->href = $tohref; } - $captcha = $this->loadCaptcha(); - $submit = $this->_getParam("submit"); + if(!empty($submit)) { - $username = trim($this->_request->getParam('username')); - $password = trim($this->_request->getParam('password')); - $captchaword = trim($this->_request->getParam('captcha')); + $data = array( + 'username' => $this->_getParam('username'), + 'password' => $this->_getParam('password') + ); - if(empty($username)) - { - $this->setCaptcha($captcha); - $this->view->error = "请输入用户名"; - return true; - } + $account = new Account(); + $result = $account->login($data); - if(empty($password)) + if(!empty($result)) { - $this->setCaptcha($captcha); - $this->view->error = "请输入密码"; - return true; - } - - if(empty($captchaword)) - { - $this->setCaptcha($captchaword); - $this->view->error = "请输入验证码"; - return true; - } - - if(!isset($_SESSION['captcha'])) - { - $_SESSION['captcha'] = md5(time()); - } - - if ($captchaword != $_SESSION['captcha']) { - $this->setCaptcha($captcha); - $this->view->error = "验证码错误"; - return true; - } - - if (!$this->login($username,$password)) - { - $this->setCaptcha($captcha); - $this->view->error = "用户名或密码错误"; - $this->view->userid = $username; - return true; - } - else - { - if(!empty($tohref)) + if(isset($result['error'])) { - view::Post($this,"登录成功,正在跳转",$tohref); + $this->view->error = $result['error']; return true; } - - if($options['module']=="default" && $options['controller'] == "account" && $options['action'] == "login") + if(isset($result['success'])) { - view::Post($this,"登录成功,正在跳转",'/'); - return true; - }else{ - view::Post($this,"登录成功,正在跳转",$_SERVER['REQUEST_URI']); + $this->_redirect($this->view->href); return true; } + }else{ + $this->view->error = "处理中出现问题"; + return true; } - }else{ - $this->setCaptcha($captcha); } - - } + }//登陆 - function loadCaptcha() - { - $captcha = new Zend_Captcha_Image(array( - 'captcha' => 'Image', - 'wordLen' => 4, - 'fontsize'=>16, - 'width' => 100, - 'height' => 38, - 'dotNoiseLevel'=>2, - 'lineNoiseLevel'=>1, - 'timeout' => 300, - 'font' => '../data/fonts/ggbi.ttf', - 'imgDir' => 'vdimg/', - 'imgUrl' => '/vdimg', - )); - return $captcha; - } - - function setCaptcha(Zend_Captcha_Image $captcha,$ajax = false){ - $captcha->generate(); - $_SESSION['captcha'] = $captcha->getWord(); - $url = $captcha->getImgUrl() - .$captcha->getId() - .$captcha->getSuffix(); - if(!$ajax) - { - $this->view->captcha = $url; - }else{ - return $url; - } - } - - function captchaAction() - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $captcha = $this->loadCaptcha(); - $url = $this->setCaptcha($captcha,true); - - echo $url; - return true; + public function jsonexit($data){ + $this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($data)); + return true; } - function logoutAction() + function registerAction() { - $auth = Zend_Auth::getInstance(); - $auth->clearIdentity(); - require_once 'member.php'; - $mb=new member(); - member::flushcookie(); - $this->_redirect('/'); - } - - private function default_login($u,$p) - { - $auth = Zend_Auth::getInstance(); - $db=Zend_Registry::get('db'); - - $authAdapter = new Zend_Auth_Adapter_DbTable($db); - $authAdapter->setTableName('users') - ->setIdentityColumn('username') - ->setCredentialColumn('password'); - $authAdapter->setIdentity($u)->setCredential(md5($p)); - $result = $auth->authenticate($authAdapter); - if ($result->isValid()) { - // success: store database row to auth's storage - $data = $authAdapter->getResultRowObject(null,'password'); - - //头像 - include_once("Avatar.php"); - $avatar = new Avatar(); - $data->avatar = $avatar->Get($data->email,40); - - //组ID - include_once("Users.php"); - $usr = new Users($db); - $data->gid = $usr->getGroup($data->id); - - $auth->getStorage()->write($data); - $db->query("update users set ts_last_login=now() where username=?",array($u)); - - if ($this->_request->getParam('remember')) { - $sql="select usertype from users where username='$u'"; - $rs=$db->query($sql); - $row=$rs->fetch(); - //if($row['usertype']!='administrator') - { - require_once 'member.php'; - $mb = new member(); - $mb -> putcookie($u,md5($p)); - } - } - - return true; - }else - { - return false; - } - return false; - } - private function aspnet_login($p,$salt,$password) - { - $p1=implode("\x00",str_split($p))."\x00"; - $ball=base64_decode($salt).$p1; - return trim($password)==base64_encode(sha1($ball,true)); - } - // 首先判断是否存在salt - // 若有salt,则按照aspnet membership加密算法进行判断 - function login($u,$p) - { - $ut= new UsersTable(); - $db=$ut->getAdapter(); - $sql="select password,salt from users where username=?"; - $uq=$db->query($sql,array($u)); - if ($urow=$uq->fetchObject()) - { - if (empty($urow->salt)) - return $this->default_login($u,$p); - else { - //进行判断并进行转换到默认 - if ($this->aspnet_login($p,$urow->salt,$urow->password)) - { - $sql="update users set password=md5(?),salt='' where username=?"; - $db->query($sql,array($p,$u)); - return $this->default_login($u,$p); - } else - return false; - } - } else { - //没有对应的用户,登录失败 - return false; - } - } - function fetchpwdAction() - { - $ut= new UsersTable(); - $db=$ut->getAdapter(); - $form = new LostpwdForm(); - $key=$this->_request->getParam('key'); - $login=$this->_request->getParam('login'); - if (empty($key) && empty($login)) { - $this->view->form = $form; - if ($this->_request->isPost()) { - $formData = $this->_request->getPost(); - if ($form->isValid($formData)) { - $sql="select * from users where email=?"; - $uq=$db->query($sql,array($formData['email'])); - if ($urow=$uq->fetchObject()) - { - //email the url to user - $username=$urow->username; - $sql="update users set activation=? where email=?"; - $uid=uniqid(); - $db->query($sql,array($uid,$formData['email'])); - $mail=new WestdcMailer($this->view->config->smtp); - $body="尊敬的西部数据中心用户: - 有人提出了针对此用户名的密码重置请求。 - - 用户名:"; - $body.=$username; - $body.=" - - 若想重置您的密码请打开下面的链接,否则请忽略此邮件,一切如常。 -"; - $body.="http://westdc.westgis.ac.cn/account/fetchpwd/".$username."/".$uid; - $mail->setBodyText($body); - $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); - $mail->addTo($formData['email']); - $mail->setSubject('密码已重置'); - $mail->send(); - $this->view->messages[]='请检查您的新邮件中的确认激活链接。'; - $this->view->form=false;//do not echo form - } else - $this->messenger->addMessage('对不起,没有找到对应的电子邮件地址。'); - } - } else - $this->view->messages[]='请输入您的电子邮件地址。您将通过电子邮件收到新密码。'; - } else { - $sql="select * from users where username=? and activation=?"; - $uq=$db->query($sql,array($login,$key)); - $tmp_pwd=uniqid(); - if ($urow=$uq->fetchObject()) + $request = new \Zend_Controller_Request_Http(); + if($request->isXmlHttpRequest()) + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $account = new Account(); + $data = $account->getParam($this->_request); + + $result = $account->register($data); + + if(!empty($result)) { - $sql="update users set salt='',activation='',password=md5('".$tmp_pwd."') where username=? and activation=?"; - $db->query($sql,array($login,$key)); - $mail=new WestdcMailer($this->view->config->smtp); - $body="尊敬的西部数据中心用户: - 您的密码已修改。 - - 用户名:"; - $body.=$login; - $body.="密码:".$tmp_pwd; - $body.=" - http://westdc.westgis.ac.cn/account/login"; - $mail->setBodyText($body); - $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); - $mail->addTo($urow->email); - $mail->setSubject('您的新密码'); - $mail->send(); - $this->view->messages[]='请查收您新邮件中的新密码'; - $this->view->form=false;//do not echo form - + $this->jsonexit($result); + return true; + } + + $this->jsonexit(array('error'=>'|o| 服务器掉链子了,请重试')); + + return true; + }else{ + //$this->_helper->layout->disableLayout(); + } + + + $success=false; + + $auth = Zend_Auth::getInstance(); + if ($auth->hasIdentity()) + $this->_redirect('/'); + + $submit = $this->_getParam('submit'); + if(!empty($submit)) + { + $account = new Account(); + $this->view->data = $data = $account->getParam($this->_request); + $result = $account->register($data); + + if(!empty($result)) + { + if(isset($result['error'])) + { + $this->view->place = $result['place']; + $this->view->error = $result['error']; + return true; + } + if(isset($result['success'])) + { + $this->_redirect('/'); + return true; + } + }else{ + $this->view->error = "处理中出现问题"; + return true; } } - - } //找回密码 + }//用户注册 + + //退出登录 + function logoutAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $auth = Zend_Auth::getInstance(); + + if ($auth->hasIdentity()) + { + $auth->clearIdentity(); + Users\Member::flushcookie(); + $this->_redirect('/'); + } + } + + //找回密码 + function forgotpasswordAction() + { + $this->_helper->layout->disableLayout(); + + $submit = $this->_getParam('submit'); + + if(!empty($submit)) + { + $email = $this->_getParam('email'); + $account = new Account(); + $status = $account->getMyPassword($email); + if(isset($status['error']) && !empty($status['error'])) + { + $this->view->error = $status['error']; + }else{ + $this->view->msg = "申请成功!请在您的邮箱中查看密码重置邮件"; + } + } + } + + //重置密码 + function getpasswordAction() + { + $this->_helper->layout->disableLayout(); + + $submit = $this->_getParam('submit'); + + if(!empty($submit)) + { + $data = array( + 'username' => $this->_getParam('username'), + 'password' => $this->_getParam('password'), + 'confirm_password' => $this->_getParam('confirm_password'), + 'salt' => $this->_getParam('salt') + ); + $account = new Account(); + $status = $account->resetPassword($data); + if(isset($status['error']) && !empty($status['error'])) + { + $this->view->error = $status['error']; + }else{ + $this->view->msg = "您的密码已经成功更改,请点击这里登陆"; + } + } + }//getpasswordAction() } diff --git a/application/default/views/scripts/account/login.phtml b/application/default/views/scripts/account/login.phtml index e53bd83d..598206ca 100755 --- a/application/default/views/scripts/account/login.phtml +++ b/application/default/views/scripts/account/login.phtml @@ -44,14 +44,6 @@
      -
      - -
      - - - 看不清? -
      -
      diff --git a/application/default/views/scripts/account/register.phtml b/application/default/views/scripts/account/register.phtml index cf161a9b..fb1d8a7a 100755 --- a/application/default/views/scripts/account/register.phtml +++ b/application/default/views/scripts/account/register.phtml @@ -1,19 +1,81 @@ -headTitle($this->config->title->site); - $this->headTitle('用户注册'); - $this->headTitle()->setSeparator(' - '); - $this->headLink()->appendStylesheet('/css/register.css'); - $this->breadcrumb('首页'); - $this->breadcrumb('用户注册'); - $this->breadcrumb()->setSeparator(' > '); -?> -
      -
      -  确认服务条款   -    -  填写基本信息   -    -  注册完成 - form;?> -
      -
      \ No newline at end of file +headTitle($this->config->title->site); + $this->headTitle('用户注册'); + $this->headTitle()->setSeparator(' - '); + $this->headLink()->appendStylesheet('/css/register.css'); + $this->breadcrumb('首页'); + $this->breadcrumb('用户注册'); + $this->breadcrumb()->setSeparator(' > '); +?> +
      + +
      +place)){?> + + \ No newline at end of file diff --git a/application/default/views/scripts/index/index.phtml b/application/default/views/scripts/index/index.phtml index 1867014d..c756d9c3 100755 --- a/application/default/views/scripts/index/index.phtml +++ b/application/default/views/scripts/index/index.phtml @@ -42,9 +42,12 @@

      新闻

      -
      diff --git a/application/module/Helpers/Curl.php b/application/module/Helpers/Curl.php index bc819575..f801e43d 100644 --- a/application/module/Helpers/Curl.php +++ b/application/module/Helpers/Curl.php @@ -4,19 +4,25 @@ namespace Helpers; class Curl { private $options; - + public $port = 80; + public $H; + public function __construct($options = array()) { - $this->options = array_merge(array( + + } + + public function initOptions($options = array()) + { + $this->options = array_merge(array( 'debug' => false, - 'http_port' => '80', + 'http_port' => $this->port, 'user_agent' => 'Westdc DataService', 'timeout' => 20, 'curlopts' => null, 'verifyssl' => true, ), $options); - } - + } /** * Send a request to the server, receive a response * @@ -69,6 +75,11 @@ class Curl } else { $headers[] = 'Content-Length: 0'; } + + if(!empty($this->H) && is_array($this->H) && count($this->H) > 0) + { + $headers = array_merge($headers,$this->H); + } $this->debug('send '.$httpMethod.' request: '.$url); @@ -81,6 +92,16 @@ class Curl CURLOPT_HTTPHEADER => $headers, CURLOPT_SSL_VERIFYPEER => $options['verifyssl'], ); + + if($this->port === 443) + { + /*$curlOptions += array( + CURLOPT_SSLVERSION => 3, + CURLOPT_SSLCERT => "../application/module/Open/apache.pem", + CURLOPT_SSLKEY => "../application/module/Open/apache.key", + CURLOPT_CAINFO => "../application/module/Open/apache.pem" + );*/ + } if (ini_get('open_basedir') == '' && ini_get('safe_mode') != 'On') { $curlOptions[CURLOPT_FOLLOWLOCATION] = true; diff --git a/application/module/Helpers/MCrypt.php b/application/module/Helpers/MCrypt.php new file mode 100644 index 00000000..542d6de2 --- /dev/null +++ b/application/module/Helpers/MCrypt.php @@ -0,0 +1,46 @@ +config = \Zend_Registry::get('config'); + } + + static function encrypt($decrypted, $password, $salt='!kQm*fF3pXe1Kbm%9') { + + $key = hash('SHA256', $salt . $password, true); + + srand(); + + $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND); + + if (strlen($iv_base64 = rtrim(base64_encode($iv), '=')) != 22) return false; + + $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $decrypted . md5($decrypted), MCRYPT_MODE_CBC, $iv)); + + return $iv_base64 . $encrypted; + } + + static function decrypt($encrypted, $password, $salt='!kQm*fF3pXe1Kbm%9') { + + $key = hash('SHA256', $salt . $password, true); + + $iv = base64_decode(substr($encrypted, 0, 22) . '=='); + + $encrypted = substr($encrypted, 22); + + $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, base64_decode($encrypted), MCRYPT_MODE_CBC, $iv), "\0\4"); + + $hash = substr($decrypted, -32); + + $decrypted = substr($decrypted, 0, -32); + + if (md5($decrypted) != $hash) return false; + + return $decrypted; + } + + +} \ No newline at end of file diff --git a/application/module/Helpers/View.php b/application/module/Helpers/View.php index 52d8d287..145cfa63 100644 --- a/application/module/Helpers/View.php +++ b/application/module/Helpers/View.php @@ -84,6 +84,21 @@ class View extends \Zend_Controller_Plugin_Abstract } } + static function setUserStorage($user) + { + $auth = \Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + if(get_class($user) == 'stdClass') + { + $auth->getStorage()->write($user); + return true; + } + } + + return false; + } + static function Dump($data,$exit = true){ echo "
      "."\r\n";
       		var_dump($data);
      @@ -112,6 +127,20 @@ class View extends \Zend_Controller_Plugin_Abstract
       		return true;
       	}
       	
      +	static function JsonOutput(\Zend_Controller_Action $ctl,$data,$json_numeric_check = true)
      +	{
      +		if($json_numeric_check === true)
      +		{
      +			$body = json_encode($data,JSON_NUMERIC_CHECK);
      +		}else{
      +			$body = json_encode($data);
      +		}
      +		$ctl ->getResponse()
      +			 ->setHeader('Content-Type', 'application/json')
      +			 ->appendBody($body);
      +		return true;
      +	}
      +	
       	static function HttpError($ctl,$code = 404){
       		$ctl->getResponse()->setHttpResponseCode($code);
       		$helper = new \Zend_Controller_Action_HelperBroker($ctl);
      @@ -157,4 +186,6 @@ class View extends \Zend_Controller_Plugin_Abstract
       			return true;
       		}
       	}
      +	
      +	
       }
      \ No newline at end of file
      diff --git a/application/module/Users/Account.php b/application/module/Users/Account.php
      new file mode 100644
      index 00000000..f3845214
      --- /dev/null
      +++ b/application/module/Users/Account.php
      @@ -0,0 +1,379 @@
      +db = \Zend_Registry::get('db');
      +		}else{
      +			$this->db = $db;
      +		}
      +		
      +		$this->config = \Zend_Registry::get('config');
      +		
      +		if($initializingListener === TRUE)
      +		{
      +			$this->loadListener();
      +		}
      +	}
      +	
      +	public function loadListener()
      +	{
      +		//主要操作,账号注册,登录,设置session等
      +		$AccountListener = new AccountListener();
      +		@$this->events()->attachAggregate($AccountListener);
      +		
      +		//账户编辑
      +		$EditListener = new EditListener();
      +		@$this->events()->attachAggregate($EditListener);
      +		
      +		//账户安全性(找回密码)
      +		$PwdListener = new PwdListener();
      +		@$this->events()->attachAggregate($PwdListener);
      +	}
      +	
      +	public function events(\Zend_EventManager_EventCollection $events = NULL)
      +    {
      +        if ($events !== NULL) {
      +            $this->events = $events;
      +        } elseif ($this->events === NULL) {
      +            $this->events = new \Zend_EventManager_EventManager(__CLASS__);
      +        }
      +        return $this->events;
      +    }
      +	
      +	//获取账号信息,数组
      +	public function getAccountInfo($id = 0)
      +	{
      +		if($id == 0)
      +		{
      +			$id = view::User('id');
      +		}
      +		$sql = "SELECT * FROM {$this->memberTable} WHERE id=$id";
      +		$rs = $this->db->query($sql);
      +		return $rs->fetch();
      +	}
      +
      +	//注册
      +	public function register($data)
      +	{
      +		$params = compact('data');
      +        $results = $this->events()->trigger('register.checkParam', $this, $params);
      +		$cache_data = $results->bottom();
      +		
      +		if($cache_data !== true)
      +		{
      +			if(!is_array($cache_data))
      +			{
      +				return array('error'=>$cache_data);
      +			}else{
      +				return $cache_data;
      +			}
      +		}
      +		
      +        $results = $this->events()->trigger('register.checkUser', $this, $params);
      +		$cache_data = $results->bottom();
      +		
      +		if($cache_data !== true)
      +		{
      +			if(!is_array($cache_data))
      +			{
      +				return array('error'=>$cache_data);
      +			}else{
      +				return $cache_data;
      +			}
      +		}
      +		
      +		$loginData = array(
      +			'username'=>$data['username'],
      +			'password'=>$data['password']
      +		);
      +		
      +		$data['password'] = md5($data['password']);
      +		$data['usertype'] = "member";
      +		unset($data['confirm_password']);
      +		
      +		$dbh = new dbh();
      +		
      +		$id = $dbh->insert($this->memberTable,$data,true);
      +		
      +		if(!empty($id) && is_numeric($id))
      +		{
      +			$this->storeLogin($loginData);
      +			$mb = new Member();
      +			$mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]); //username, md5(password)
      +			$params = compact('data','id');
      +        	$results = $this->events()->trigger('register.success', $this, $params);
      +			return array("success" => 1);
      +		}else{
      +			if($id === false)
      +			{
      +				return array('error'=>'服务器开小差了,请稍后再试');
      +			}else{
      +				return array('error'=>'服务器处理中遇到错误,请联系管理员');
      +			}
      +		}
      +		
      +	}//register
      +	
      +	//登陆
      +	public function login($data,$return_user_info = false)
      +	{
      +        $results = $this->events()->trigger('login.checkParam', $this, compact('data'));
      +		$cache_data = $results->bottom();
      +		
      +		if($cache_data !== true)
      +		{
      +			if(!is_array($cache_data))
      +			{
      +				return array('error'=>$cache_data);
      +			}else{
      +				return $cache_data;
      +			}
      +		}
      +		
      +		$state = $this->storeLogin($data);
      +		
      +		$mb = new Member();
      +		$mb->putcookie($data[$this->FieldUsername],md5($data[$this->FieldPasword]));
      +			
      +		if(!$return_user_info)
      +			return $state;
      +		else
      +			return view::User();
      +	}//login
      +	
      +	//storeLogin
      +	//将登录信息保存在session和cookie中
      +	public function storeLogin($data,$md5verify = true)
      +	{	
      +		$auth = \Zend_Auth::getInstance();
      +		$authAdapter = new \Zend_Auth_Adapter_DbTable($this->db);
      +		$authAdapter->setTableName($this->memberTable)
      +					->setIdentityColumn($this->FieldUsername)
      +					->setCredentialColumn($this->FieldPasword);
      +		
      +		if(empty($data[$this->FieldPasword]))
      +		{
      +			$password = "0";
      +		}else{
      +			if($md5verify == false)
      +			{
      +				$password = $data[$this->FieldPasword];
      +			}else{
      +				$password = md5($data[$this->FieldPasword]);
      +			}
      +		}
      +		
      +		$authAdapter->setIdentity($data[$this->FieldUsername])->setCredential($password);
      +		
      +		$result = $auth->authenticate($authAdapter);
      +		
      +		if ($result->isValid()) {
      +			
      +			$user = $authAdapter->getResultRowObject(null,$this->FieldPasword);
      +			$email = $user->email;
      +			$results = $this->events()->trigger('login.success.createAvatar', $this, compact('email'));
      +			$user->avatar = $results->bottom();
      +			$auth->getStorage()->write($user);
      +			
      +			$id = $user->id;
      +			@$results = $this->events()->trigger('login.success.updateStatus', $this, compact('id'));
      +			
      +			return array('success'=>1);
      +		}else{
      +			return array("error"=>"登录失败,请重试");
      +		}
      +		
      +		return array('error'=>'处理中发现错误,请重试');
      +	}
      +	
      +	//注册信息参数
      +	public function getParam(\Zend_Controller_Request_Abstract $request)
      +	{
      +		$data = array(
      +			'username'=>$request->getParam('username'),
      +			'password'=>$request->getParam('password'),
      +			'confirm_password'=>$request->getParam('confirm_password'),
      +			'email'=>$request->getParam('email'),
      +			'realname'=>$request->getParam('realname')
      +		);
      +		return $data;
      +	}
      +	
      +	//获取用户账户修改参数
      +	public function getEditParam(\Zend_Controller_Request_Abstract $request)
      +	{
      +		$type = $request->getParam('type');
      +		
      +		if($type == "general")
      +		{
      +			$data = array(
      +				'realname'=>$request->getParam('realname'),
      +				'signature'=>$request->getParam('signature'),
      +				'description'=>$request->getParam('description')
      +			);
      +		}
      +		
      +		if($type == "password")
      +		{
      +			$data = array(
      +				'password' => $request->getParam('password'),
      +				'password_new'=>$request->getParam('password_new'),
      +				'password_confirm'=>$request->getParam('password_confirm')
      +			);
      +		}
      +		return $data;
      +	}
      +	
      +	//编辑
      +	public function edit($data,$type)
      +	{
      +		$results = $this->events()->trigger('edit.checkParam', $this, compact('data','type'));
      +		$cache_data = $results->bottom();
      +		
      +		if($cache_data !== true)
      +		{
      +			return $cache_data;
      +		}
      +		
      +		if($type == "general")
      +		{
      +			$data['signature'] = htmlspecialchars($data['signature']);
      +			$data['description'] = htmlspecialchars($data['description']);
      +		}else if($type == "password")
      +		{
      +			$data['password'] = md5($data['password_new']);
      +			unset($data['password_new']);
      +			unset($data['password_confirm']);
      +		}else{
      +			return "参数错误";
      +		}
      +		
      +		$dbh = new dbh();
      +		$uid = view::User('id');
      +		if($dbh->update($this->memberTable,$data," id=$uid") === true)
      +		{
      +			return true;
      +		}else{
      +			return false;
      +		}
      +	}
      +	
      +	//找回密码
      +	public function getMyPassword($email)
      +	{
      +		$results = $this->events()->trigger('pwd.forgot.checkParam', $this, compact('email'));
      +		$cache_data = $results->bottom();
      +		
      +		if($cache_data !== true)
      +		{
      +			return $cache_data;
      +		}
      +		
      +		$sql = "SELECT * FROM {$this->memberTable} WHERE email='$email'";
      +		$rs = $this->db->query($sql);
      +		$row = $rs->fetch();
      +		
      +		if(!isset($row['username']) || empty($row['username']))
      +		{
      +			return array('error'=>"此邮箱并未注册",'place'=>'email');
      +		}	
      +		
      +		$salt = md5($email.'---'.$row['username']);
      +		
      +		$sql = "UPDATE {$this->memberTable} SET salt='$salt' WHERE id={$row['id']}";
      +		$state = $this->db->exec($sql);
      +		
      +		if($state<1)
      +		{
      +			return array('error'=>"处理中出现错误,请重试",'place'=>'email');
      +		}
      +		
      +		$mail_template = "forgotpassword";
      +		$mail_data = array(
      +			'name'=>$row['realname'],
      +			'link'=> view::getHostLink().'/account/getpassword/salt/'.$salt
      +		);
      +		
      +		$mail = new Mail();
      +		
      +		$mail->loadTemplate($mail_template,$mail_data);
      +		$mail->addTo($email,$row['realname']);
      +		$mail->send();
      +		
      +		return array("success"=>1);
      +	}
      +	
      +	//重置密码
      +	public function resetPassword($data)
      +	{
      +		$results = $this->events()->trigger('pwd.reset.checkParam', $this, compact('data'));
      +		$cache_data = $results->bottom();
      +		
      +		if($cache_data !== true)
      +		{
      +			return $cache_data;
      +		}
      +		
      +		$sql = "SELECT * FROM {$this->memberTable} WHERE salt=?";
      +		$sth = $this->db->prepare($sql);
      +		$sth->execute(array($data['salt']));
      +		$row = $sth->fetch();
      +		
      +		if(!isset($row['username']) || empty($row['username']))
      +		{
      +			return array('error'=>"您提供的校验码不正确,请重新申请重置密码",'place'=>'confirm_password'); 
      +		}
      +		
      +		if($row['username'] !== $data['username'])
      +		{
      +			return array('error'=>"您提供的校验码不正确,请重新申请重置密码",'place'=>'confirm_password');
      +		}
      +		
      +		$sql = "UPDATE {$this->memberTable} SET password='".md5($data['password'])."',salt='' WHERE id={$row['id']}";
      +		$this->db->exec($sql);
      +		
      +		$mail_template = "getpassworded";
      +		$mail_data = array(
      +			'name'=>$row['realname'],
      +		);
      +		$mail = new Mail();
      +		$mail->loadTemplate($mail_template,$mail_data);
      +		$mail->addTo($row['email'],$row['realname']);
      +		$mail->send();
      +		
      +		return true;
      +		
      +	}
      +	
      +}
      \ No newline at end of file
      diff --git a/application/module/Users/Event/EditEvent.php b/application/module/Users/Event/EditEvent.php
      new file mode 100644
      index 00000000..99488769
      --- /dev/null
      +++ b/application/module/Users/Event/EditEvent.php
      @@ -0,0 +1,11 @@
      +event = new \Zend_EventManager_EventManager();
      +		
      +		if(empty($type))
      +		{
      +			$type = "both";
      +		}
      +		
      +		$this->type = $type;
      +	}
      +	
      +	public function attach(\Zend_EventManager_EventCollection $events)
      +    {
      +        if($this->type == "both")
      +		{
      +			$this->attachRegisterEvents($events);
      +			$this->attachLoginEvents($events);
      +		}
      +		
      +		if($this->type == "register")
      +		{
      +			$this->attachRegisterEvents($events);
      +		}
      +		
      +		if($this->type == "login")
      +		{
      +			$this->attachLoginEvents($events);
      +		}
      +    }
      +	
      +	public function detach(\Zend_EventManager_EventCollection $events)
      +	{
      +		
      +	}
      +	
      +	private function attachRegisterEvents(\Zend_EventManager_EventCollection $events)
      +	{
      +		$_Events = new RegisterOperate();
      +		$events->attach('register.checkParam', array($_Events, 'checkParam'), 100);
      +		$events->attach('register.checkUser', array($_Events, 'checkUser'), 80);
      +		$events->attach('register.success', array($_Events, 'registerSuccess'), 50);
      +	}
      +	
      +	private function attachLoginEvents(\Zend_EventManager_EventCollection $events)
      +	{
      +		$_Events = new LoginOperate();
      +		$events->attach('login.checkParam', array($_Events, 'checkParam'), 100);
      +		$events->attach('login.success.updateStatus', array($_Events, 'updateStatus'), 50);
      +		$events->attach('login.success.createAvatar', array($_Events, 'createAvatar'), 50);
      +	}
      +	
      +}
      diff --git a/application/module/Users/Listener/EditListener.php b/application/module/Users/Listener/EditListener.php
      new file mode 100644
      index 00000000..e2a1a5d0
      --- /dev/null
      +++ b/application/module/Users/Listener/EditListener.php
      @@ -0,0 +1,35 @@
      +event = new \Zend_EventManager_EventManager();
      +		
      +		if(empty($type))
      +		{
      +			$type = "both";
      +		}
      +		
      +		$this->type = $type;
      +	}
      +	
      +	public function attach(\Zend_EventManager_EventCollection $events)
      +    {
      +        $_Events = new EditOperate();
      +		$events->attach('edit.checkParam', array($_Events, 'checkParam'), 100);
      +		$events->attach('edit.success', array($_Events, 'editSuccess'), 50);
      +    }
      +	
      +	public function detach(\Zend_EventManager_EventCollection $events)
      +	{
      +		
      +	}
      +	
      +}
      diff --git a/application/module/Users/Listener/PwdListener.php b/application/module/Users/Listener/PwdListener.php
      new file mode 100644
      index 00000000..5d86ae07
      --- /dev/null
      +++ b/application/module/Users/Listener/PwdListener.php
      @@ -0,0 +1,30 @@
      +event = new \Zend_EventManager_EventManager();
      +	}
      +	
      +	public function attach(\Zend_EventManager_EventCollection $events)
      +    {
      +        $_Events = new PwdOperate();
      +		$events->attach('pwd.forgot.checkParam', array($_Events, 'forgotPwdCheckParam'), 100);
      +		$events->attach('pwd.forgot.sendmail', array($_Events, 'sendGetPasswordMail'), 50);
      +		$events->attach('pwd.reset.checkParam', array($_Events, 'resetPwdCheckParam'), 100);
      +		$events->attach('pwd.reset.sendmail', array($_Events, 'sendGetPasswordMail'), 50);
      +    }
      +	
      +	public function detach(\Zend_EventManager_EventCollection $events)
      +	{
      +		
      +	}
      +	
      +}
      diff --git a/application/module/Users/Member.php b/application/module/Users/Member.php
      new file mode 100644
      index 00000000..fcb2bce2
      --- /dev/null
      +++ b/application/module/Users/Member.php
      @@ -0,0 +1,138 @@
      +db = \Zend_Registry::get('db');
      +		}else{
      +			$this->db = $db;
      +		}
      +		
      +		$this->config = \Zend_Registry::get('config');
      +		
      +		if(!empty($_COOKIE['scr']))
      +		{
      +			$this->scr = $_COOKIE['scr'];
      +		}
      +		if(!empty($_COOKIE['user']))
      +		{
      +			$this->user= $_COOKIE['user'];
      +		}	
      +	}
      +
      +	
      +	/**
      +	 * 检测cookie
      +	 */
      +	public function checkcookie()
      +	{
      +		$uname = $this->user;
      +	    $hash  = $this->scr;
      +	    
      +	    if(!empty($uname) && !empty($hash))
      +	    {
      +		    if (preg_match("/[<|>|#|$|%|^|*|(|)|{|}|'|\"|;|:]/i",$uname) || preg_match("/[<|>|#|$|%|^|*|(|)|{|}|'|\"|;|:]/i",$hash))
      +		    {
      +			     $this->mid=0;
      +			     return false;
      +		    }
      +		    else{
      +		    	$sql = "select {$this->FieldUsername} as userid,{$this->FieldPasword} as pwd from {$this->memberTable} where {$this->FieldUsername}='$uname'";
      +		    	$rs  = $this->db->query($sql);
      +		    	$row = $rs->fetch();
      +		    	$scr = $this->makescr($row['userid'],$row['pwd']);
      +		    	
      +		    	if($hash == $scr)
      +		    	{
      +		    		$this->srpwd=$row['pwd'];
      +		    		return true;
      +		    	}
      +		    	else {
      +		    		return false;
      +		    	}	
      +		    }//cookie安全
      +	    }else {
      +	    	return false;
      +	    }//exit
      +	}//function checkcookie
      +	
      +   /**
      +	* putcookie
      +	*
      +	* 登陆成功后放置cookie,包含安全码
      +	*
      +	* @param String $uname
      +	* @param String $pwd
      +	* @param Int 	$time
      +	*/
      +	public function putcookie($uname,$pwd,$time = 604800)
      +	{
      +		try {
      +		    $scrString = $this->makescr($uname,$pwd);//加密验证串:防止用户密码被盗;防止伪造cookie。
      +		    
      +		    if(!is_numeric($time))
      +		    {
      +		    	$time = 604800;
      +		    }
      +		    
      +		    setcookie('user',$uname,time()+$time,'/');
      +		    setcookie('scr',$scrString,time()+$time,'/');
      +		    
      +		    return true;
      +	    } catch (Exception $e) {
      +	    	return false;
      +	    } 
      +
      +	}//function putcookie
      +	
      +	/**
      +	 * 生成安全码
      +	 * 
      +	 * @param String $u
      +	 * @param String $p
      +	 */
      +	public function makescr($u,$p)
      +	{
      +		return substr(md5($u.$p.$this->ck),3,20);
      +	}
      +	
      +	/**
      +	 * 清除cookie
      +	 */
      +	static function flushcookie()
      +	{
      +		setcookie('user','',time()-99999,'/');
      +		setcookie('scr','',time()-99999,'/');
      +	}
      +	
      +	public function getUser()
      +	{
      +		$sql = "SELECT * FROM ".$this->memberTable." m ORDER BY m.id DESC";
      +		$rs = $this->db->query($sql);
      +		return $rs->fetchAll();
      +	}
      +
      +}
      \ No newline at end of file
      diff --git a/application/module/Users/Operation/EditOperate.php b/application/module/Users/Operation/EditOperate.php
      new file mode 100644
      index 00000000..0356ad46
      --- /dev/null
      +++ b/application/module/Users/Operation/EditOperate.php
      @@ -0,0 +1,88 @@
      +db = \Zend_Registry::get('db');
      +		}else{
      +			$this->db = $db;
      +		}
      +		
      +		$this->config = \Zend_Registry::get('config');
      +	}
      +	
      +	public function checkParam(\Zend_EventManager_Event $e){
      +        
      +		$data = $e->getParam('data');
      +		$type = $e->getParam('type');
      +		
      +		if($type == 'general')
      +		{
      +		
      +			if(empty($data['realname']))
      +			{
      +				return "请输入真实姓名";
      +			}
      +			
      +			if(mb_strlen($data['realname'],"UTF-8")>10 )
      +			{
      +				return "姓名不要超过10个字";
      +			}
      +		}
      +		
      +		if($type == "password")
      +		{
      +			if(strlen($data['password'])>18 || strlen($data['password_new'])>18)
      +			{
      +				return "密码过长";
      +			}
      +			if(strlen($data['password_new'])<=6 || strlen($data['password_confirm'])<=6)
      +			{
      +				return "密码过短";
      +			}
      +			if(md5($data['password_new']) != md5($data['password_confirm']))
      +			{
      +				return "两次输入的密码不同";
      +			}
      +			
      +			$uid = view::User('id');
      +			$sql = "SELECT {$this->FieldPasword} FROM {$this->tbl_member} WHERE id=$uid";
      +			$rs = $this->db->query($sql);
      +			$row = $rs->fetch();
      +			
      +			if(md5($data['password']) != $row[$this->FieldPasword])
      +			{
      +				return "原密码不正确";
      +			}
      +		}
      +		
      +		return true;
      +	}//checkParam
      +	
      +	public function editSuccess(\Zend_EventManager_Event $e){
      +        
      +		$data = $e->getParam('data');
      +
      +		
      +		return true;
      +	}
      +	
      +}
      \ No newline at end of file
      diff --git a/application/module/Users/Operation/LoginOperate.php b/application/module/Users/Operation/LoginOperate.php
      new file mode 100644
      index 00000000..8f21200d
      --- /dev/null
      +++ b/application/module/Users/Operation/LoginOperate.php
      @@ -0,0 +1,115 @@
      +db = \Zend_Registry::get('db');
      +		}else{
      +			$this->db = $db;
      +		}
      +		
      +		$this->config = \Zend_Registry::get('config');
      +	}
      +	
      +	public function checkParam(\Zend_EventManager_Event $e){
      +        
      +		$data = $e->getParam('data');
      +
      +		if(!is_array($data))
      +		{
      +			return "参数错误";
      +		}
      +		
      +		if(empty($data['username']))
      +		{
      +			return array('error'=>"请输入用户名",'place'=>'username');
      +		}
      +		
      +		if(!empty($data['username']))
      +		{
      +			if(!preg_match("/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/",$data['username']))
      +			{
      +				return array('error'=>"用户名应当以字母开头,由字母数字和下划线组成,并且长度在5到25个字符之间",'place'=>'username');
      +			}
      +		}
      +		
      +		if(empty($data['password']))
      +		{
      +			return array('error'=>"请输入密码",'place'=>'password');
      +		}
      +		
      +		$sql = "SELECT id,{$this->FieldPasword} FROM {$this->tbl_member} WHERE {$this->FieldUsername}=?";
      +		$sth = $this->db->prepare($sql);
      +		$rs = $sth->execute(array($data[$this->FieldUsername]));
      +		$row = $sth->fetch();
      +		
      +		if(isset($row['id']) && !empty($row['id']))
      +		{
      +			if(strlen($row[$this->FieldPasword]) !== 32)
      +			{
      +				return array('error'=>"您的密码或因安全原因或其他问题已经被重置,请先重置密码再登陆",'place'=>'password');
      +			}
      +			if($row[$this->FieldPasword] !== md5($data['password']))
      +			{
      +				return array('error'=>"密码错误",'place'=>'password');
      +			}
      +			return true;
      +		}else{
      +			return array('error'=>"用户不存在",'place'=>'username');
      +		}
      +		
      +	}//checkParam
      +	
      +	public function updateStatus(\Zend_EventManager_Event $e){
      +		
      +		$id = (int)$e->getParam('id');
      +		
      +		if(!is_numeric($id))
      +		{
      +			return false;
      +		}
      +		
      +		$update = array(
      +			$this->FieldLastlogin => date("Y-m-d H:i:s"),
      +			//$this->FieldLastloginIp => $_SERVER["REMOTE_ADDR"]
      +		);
      +		
      +		$dbh = new dbh();
      +		@$statusUpdate = $dbh->update($this->tbl_member,$update," id=$id ");
      +		
      +		return true;
      +	}//loginSuccess
      +	
      +	public function createAvatar(\Zend_EventManager_Event $e){
      +        
      +		$email = $e->getParam('email');		
      +		$avatar = new Gravatar();
      +		return $avatar->Get($email);
      +		
      +	}//loginSuccess
      +	
      +	//检查token表记录
      +	public function checkOAuthToken()
      +	{
      +		
      +	}
      +	
      +}
      \ No newline at end of file
      diff --git a/application/module/Users/Operation/PwdOperate.php b/application/module/Users/Operation/PwdOperate.php
      new file mode 100644
      index 00000000..ae87513f
      --- /dev/null
      +++ b/application/module/Users/Operation/PwdOperate.php
      @@ -0,0 +1,94 @@
      +db = \Zend_Registry::get('db');
      +		}else{
      +			$this->db = $db;
      +		}
      +		
      +		$this->config = \Zend_Registry::get('config');
      +	}
      +	
      +	public function forgotPwdCheckParam(\Zend_EventManager_Event $e){
      +        
      +		$email = $e->getParam('email');
      +		
      +		if(empty($email))
      +		{
      +			return array('error'=>"请输入电子邮箱,作为找回密码和接受通知的联系方式",'place'=>'email');
      +		}
      +		
      +		if (!preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$email))
      +		{
      +			return array('error'=>"请输入正确的电子邮件",'place'=>'email');
      +		}
      +		
      +		return true;
      +	}//checkParam
      +	
      +	public function sendGetPasswordMail(\Zend_EventManager_Event $e){
      +        
      +		$email = $e->getParam('email');
      +
      +		
      +		return true;
      +	}
      +	
      +	public function resetPwdCheckParam(\Zend_EventManager_Event $e)
      +	{
      +		$data = $e->getParam('data');
      +		
      +		if(empty($data['username']))
      +		{
      +			return array('error'=>"请输入用户名",'place'=>'username');
      +		}
      +		
      +		if(empty($data['password']))
      +		{
      +			return array('error'=>"请输入密码",'place'=>'password');
      +		}
      +		
      +		if(strlen($data['password']) < 6)
      +		{
      +			return array('error'=>"密码长度太短,为了安全最少输入6位哦",'place'=>'password');
      +		}
      +		
      +		if(strlen($data['password']) > 14)
      +		{
      +			return array('error'=>"密码太长,亲您记得住吗?不要超过14位哦",'place'=>'password');
      +		}
      +		
      +		if(empty($data['confirm_password']))
      +		{
      +			return array('error'=>"请再次输入密码已确认输入正确",'place'=>'confirm_password');
      +		}
      +		
      +		if(md5($data['password']) != md5($data['confirm_password']))
      +		{
      +			return array('error'=>"两次输入的密码不同,请重新输入",'place'=>'confirm_password');
      +		}
      +		
      +		return true;
      +	}
      +	
      +}
      \ No newline at end of file
      diff --git a/application/module/Users/Operation/RegisterOperate.php b/application/module/Users/Operation/RegisterOperate.php
      new file mode 100644
      index 00000000..09bdc9dd
      --- /dev/null
      +++ b/application/module/Users/Operation/RegisterOperate.php
      @@ -0,0 +1,182 @@
      +db = \Zend_Registry::get('db');
      +		}else{
      +			$this->db = $db;
      +		}
      +		
      +		$this->config = \Zend_Registry::get('config');
      +	}
      +	
      +	public function checkParam(\Zend_EventManager_Event $e){
      +        
      +		$data = $e->getParam('data');
      +
      +		if(!is_array($data))
      +		{
      +			return "参数错误";
      +		}
      +		
      +		if(empty($data['username']))
      +		{
      +			return array('error'=>"请输入用户名",'place'=>'username');
      +		}
      +		
      +		if(!empty($data['username']))
      +		{
      +			if(!preg_match("/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/",$data['username']))
      +			{
      +				return array('error'=>"用户名应当以字母开头,由字母数字和下划线组成,并且长度在5到16个字符之间",'place'=>'username');
      +			}
      +		}
      +		
      +		if(empty($data['password']))
      +		{
      +			return array('error'=>"请输入密码",'place'=>'password');
      +		}
      +		
      +		if(strlen($data['password']) < 6)
      +		{
      +			return array('error'=>"密码长度太短,为了安全最少输入6位",'place'=>'password');
      +		}
      +		
      +		if(strlen($data['password']) > 14)
      +		{
      +			return array('error'=>"密码太长,请不要超过14位",'place'=>'password');
      +		}
      +		
      +		if(empty($data['confirm_password']))
      +		{
      +			return array('error'=>"请再次输入密码已确认输入正确",'place'=>'confirm_password');
      +		}
      +		
      +		if(md5($data['password']) != md5($data['confirm_password']))
      +		{
      +			return array('error'=>"两次输入的密码不同,请重新输入",'place'=>'confirm_password');
      +		}
      +		
      +		if(empty($data['email']))
      +		{
      +			return array('error'=>"请输入电子邮箱,作为找回密码和接受通知的联系方式",'place'=>'email');
      +		}
      +		
      +		if (!preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$data['email']))
      +		{
      +			return array('error'=>"请输入正确的电子邮件,推荐使用QQ邮箱和Gmail邮箱",'place'=>'email');
      +		}
      +		
      +		if(empty($data['realname']))
      +		{
      +			return array('error'=>"请输入姓名",'place'=>'realname');
      +		}
      +		
      +		if(mb_strlen($data['realname'],"UTF-8")>10 )
      +		{
      +			return array('error'=>"真实姓名请不要超过10个字",'place'=>'realname');
      +		}
      +		
      +		return true;
      +	}//checkParam
      +	
      +	public function checkUser(\Zend_EventManager_Event $e){
      +        
      +		$data = $e->getParam('data');
      +
      +		if(!is_array($data))
      +		{
      +			return "用户信息验证失败,请重新尝试";
      +		}
      +
      +		$sql = "SELECT id,{$this->FieldUsername},{$this->FieldEmail} FROM ".$this->tbl_member." WHERE {$this->FieldUsername}='{$data['username']}' OR {$this->FieldEmail}='{$data['email']}'";
      +		
      +		$rs = $this->db->query($sql);
      +		
      +		$rows = $rs->fetchAll();
      +
      +		if(count($rows) > 1)
      +		{
      +			return array('error'=>'您的用户名和邮箱已经注册过账号,您是否忘记了密码?','place'=>'username');
      +		}
      +		
      +		$row = $rows[0];
      +
      +		if(isset($row['id']) && !empty($row['id']))
      +		{
      +			
      +			if($row[$this->FieldUsername] == $data['username'])
      +			{
      +				return array('error'=>'您的用户名已经注册过账号,您是否忘记了密码?','place'=>'username');
      +			}
      +			
      +			if($row[$this->FieldEmail] == $data['email'])
      +			{
      +				return array('error'=>'您的邮箱已经注册过账号,请换一个邮箱','place'=>'email');
      +			}
      +			
      +			return array('error'=>'您的用户名或邮箱已经使用过,注册新账号请换一个用户名');
      +		}
      +		
      +		return true;
      +	}//checkUser
      +	
      +	public function registerSuccess(\Zend_EventManager_Event $e){
      +        
      +		$data = $e->getParam('data');
      +
      +		if(!is_array($data))
      +		{
      +			return false;
      +		}
      +		
      +		$id = $e->getParam('id');
      +		
      +		if(!is_numeric($id))
      +		{
      +			return false;
      +		}
      +		
      +		$mail_template = "register";
      +		$mail_data = array(
      +			'name'=>$data['realname'],
      +			'content'=>$this->getMailContent()
      +		);
      +		
      +		$mail = new Mail();
      +		
      +		$mail->loadTemplate($mail_template,$mail_data);
      +		$mail->addTo($data['email'],$data['realname']);
      +		$mail->send();
      +		
      +		return true;
      +	}//registerSuccess
      +	
      +	//邮件内容
      +	public function getMailContent()
      +	{
      +		$content = "欢迎注册";
      +		
      +		return $content;
      +	}//getMailContent();
      +	
      +}
      \ No newline at end of file
      diff --git a/application/module/Users/Users.php b/application/module/Users/Users.php
      new file mode 100644
      index 00000000..df3d24a9
      --- /dev/null
      +++ b/application/module/Users/Users.php
      @@ -0,0 +1,86 @@
      +db = \Zend_Registry::get('db');
      +		}else{
      +			$this->db = $db;
      +		}
      +		
      +		$this->table = new Table();
      +		
      +		$this->config = \Zend_Registry::get('config');
      +		
      +		if($accountClass === TRUE)
      +		{
      +			$this->account = new Account();
      +		}
      +	}
      +	
      +	//通过email地址返回用户信息是否存在
      +	public function userExists($email = NULL)
      +	{
      +		if(empty($email))
      +		{
      +			return false;
      +		}
      +		
      +		if(empty($this->account))
      +		{
      +			$account = new Account(FALSE);
      +		}else{
      +			$account = $this->account;
      +		}
      +		
      +		$sql = "SELECT * FROM {$account->memberTable} WHERE {$account->FieldEmail}=? LIMIT 1";
      +		$sth = $this->db->prepare($sql);
      +		$sth->execute(array($email));
      +		$row = $sth->fetch();
      +		
      +		unset($account);
      +		
      +		if(isset($row['id']) && !empty($row['id']))
      +		{
      +			return $row;
      +		}else{
      +			return false;
      +		}
      +	}
      +	
      +	public function storeNewAuthCredential($user)
      +	{
      +		if(get_class($user) != 'stdClass')
      +		{
      +			return false;
      +		}
      +		
      +		$auth = \Zend_Auth::getInstance();
      +
      +		if($auth->getStorage()->write($user))
      +			return true;
      +		else
      +			return false;
      +	}
      +	
      +	
      +}
      \ No newline at end of file
      
      From 02ae9b9d857f1d7bc386799bedf13372e5b02876 Mon Sep 17 00:00:00 2001
      From: wlx 
      Date: Fri, 13 Dec 2013 09:58:54 +0000
      Subject: [PATCH 075/173] change geonetwork url
      
      ---
       application/config.ini | 2 +-
       1 file changed, 1 insertion(+), 1 deletion(-)
      
      diff --git a/application/config.ini b/application/config.ini
      index 44f6a919..37170539 100755
      --- a/application/config.ini
      +++ b/application/config.ini
      @@ -5,7 +5,7 @@ db.params.username = gis
       db.params.password = gispassword
       db.params.dbname = metadata
       
      -geonetwork.url=http://sanjiangyuan.westgis.ac.cn/geonetwork/
      +geonetwork.url=http://www.sanjiangyuan.org.cn/geonetwork/
       geonetwork.adapter = PDO_PGSQL
       geonetwork.params.host = localhost
       geonetwork.params.username = gis
      
      From 7a6f34efcf963203371c48f97ad9e4cbabf143e8 Mon Sep 17 00:00:00 2001
      From: wlx 
      Date: Sat, 14 Dec 2013 04:19:58 +0000
      Subject: [PATCH 076/173] switch ftp url to ftp.sanjiangyuan.org.cn
      
      ---
       .../admin/controllers/DownController.php       | 12 ++++++------
       .../default/controllers/DataController.php     |  6 +++---
       .../default/views/scripts/author/newdata.phtml |  4 ++--
       tools/proftp.php                               | 18 +++++++++---------
       4 files changed, 20 insertions(+), 20 deletions(-)
      
      diff --git a/application/admin/controllers/DownController.php b/application/admin/controllers/DownController.php
      index b28592ff..2061905d 100644
      --- a/application/admin/controllers/DownController.php
      +++ b/application/admin/controllers/DownController.php
      @@ -581,7 +581,7 @@ class Admin_DownController extends Zend_Controller_Action
       				foreach($rs as $data) {
       					if ($data['host']=='ftp1.westgis.ac.cn')
       						$has_ftp1=true;
      -					if ($data['host']=='ftp2.westgis.ac.cn')
      +					if ($data['host']=='ftp.sanjiangyuan.org.cn')
       						$has_ftp2=true;
       					
       					// deal with ftp.westgis.ac.cn, use g6 to add path
      @@ -594,7 +594,7 @@ class Admin_DownController extends Zend_Controller_Action
       					if ($has_ftp1)
       					{
       						$user=(object)array("id"=>$row['userid'],
      -    									"username"=>"westdc_".$row['userid'],
      +    									"username"=>"sjy_".$row['userid'],
           									"password"=>$password,
           									"time"=>date('Y-m-d H:i:s', strtotime('+2 week')),    									
           									//"path"=>$path,
      @@ -621,12 +621,12 @@ class Admin_DownController extends Zend_Controller_Action
       					if ($has_ftp2)
       					{
       						$user=(object)array("id"=>$row['userid'],
      -    									"username"=>"westdc_".$row['userid'],
      +    									"username"=>"sjy_".$row['userid'],
           									"password"=>$password,
           									"time"=>date('Y-m-d H:i:s', strtotime('+2 week')),    									
           									//"path"=>$path,
           									"param"=>"offlineappid=".$finish,
      -    									"host"=>'ftp2.westgis.ac.cn',
      +    									"host"=>'ftp.sanjiangyuan.org.cn',
           									"maxdata"=>$this->view->config->download->max,
           									"datacount"=>1 //represent one offline application
           									);
      @@ -649,10 +649,10 @@ class Admin_DownController extends Zend_Controller_Action
       						$ftphost='ftp://ftp1.westgis.ac.cn';
       					} else if (!$has_ftp1 && $has_ftp2)
       					{
      -						$ftphost='ftp://ftp2.westgis.ac.cn';
      +						$ftphost='ftp://ftp.sanjiangyuan.org.cn';
       					} else if ($has_ftp1 && $has_ftp2)
       					{
      -						$ftphost='ftp://ftp1.westgis.ac.cn 以及 ftp://ftp2.westgis.ac.cn';
      +						$ftphost='ftp://ftp1.westgis.ac.cn 以及 ftp://ftp.sanjiangyuan.org.cn';
       					} 
       					//发送用户邮件进行信息提示和说明
       					$mail = new WestdcMailer($this->view->config->smtp);
      diff --git a/application/default/controllers/DataController.php b/application/default/controllers/DataController.php
      index 007644fd..cdfda5c7 100755
      --- a/application/default/controllers/DataController.php
      +++ b/application/default/controllers/DataController.php
      @@ -1552,16 +1552,16 @@ class DataController extends Zend_Controller_Action
       				$this->view->userpass=$proftp->pwd;
       				$this->view->ftptime=$proftp->time;
       			}    					
      -		} elseif ($data['host']=='ftp2.westgis.ac.cn')
      +		} elseif ($data['host']=='ftp.sanjiangyuan.org.cn')
       		{
       			//添加FTP2帐号信息以及时间控制信息
       			$proftp=new Pureftp();
       			$proftp->db=$this->db;
      -			$this->view->username='westdc_'.$userid;
      +			$this->view->username='sjy_'.$userid;
           		$uu=(object)array("id"=>$userid,
       								"username"=>$this->view->username,
       								"password"=>$this->view->userpass,
      -    							"host"=>'ftp2.westgis.ac.cn',
      +    							"host"=>'ftp.sanjiangyuan.org.cn',
           							"param"=>"onlineappid=".$onlineappid,
           							"maxdata"=>$this->view->config->download->max,
           							"time"=>$this->view->ftptime,
      diff --git a/application/default/views/scripts/author/newdata.phtml b/application/default/views/scripts/author/newdata.phtml
      index b9452845..e5588fe5 100644
      --- a/application/default/views/scripts/author/newdata.phtml
      +++ b/application/default/views/scripts/author/newdata.phtml
      @@ -96,10 +96,10 @@ function getFtp(uuid){
       			{
       				if(data.statu > 0)
       				{
      -					var html = '

      临时FTP帐号信息(此帐号仅对应当前数据集!)

      ftp://ftp2.westgis.ac.cn/

      '+ + var html = '

      临时FTP帐号信息(此帐号仅对应当前数据集!)

      ftp://ftp.sanjiangyuan.org.cn/

      '+ '

      用户名:'+data.user+ '

      密码:'+data.passwd+'

      ' - +'

      或直接点击此链接

      '; + +'

      或直接点击此链接

      '; Alert(html); } } diff --git a/tools/proftp.php b/tools/proftp.php index f7ec1c9e..ab257c05 100644 --- a/tools/proftp.php +++ b/tools/proftp.php @@ -1,5 +1,5 @@ '' and dataorder.selection is null"; + where dataorder.status in (0,5) and dataset.host='ftp.sanjiangyuan.org.cn' and dataset.path<>'' and dataorder.selection is null"; if ($onlineappid>0) $sql.=" and dataorder.onlineappid=".$onlineappid; else if ($offlineappid>0) @@ -36,24 +36,24 @@ { $row = pg_fetch_array($result, $ri); $content.='# path: '.$row['path']."\n"; - $content.='mkdir -p "/home/ftp/westdc_'.$row['userid'].'/'.preg_replace('/^.+[\\\\\\/]/', '', rtrim($row['path'],'/')).'"'."\n"; - $content.='mount --bind "'.$row['path'].'" "/home/ftp/westdc_'.$row['userid'].'/'.preg_replace('/^.+[\\\\\\/]/', '', rtrim($row['path'],'/')).'"'."\n"; + $content.='mkdir -p "/home/ftp/sjy_'.$row['userid'].'/'.preg_replace('/^.+[\\\\\\/]/', '', rtrim($row['path'],'/')).'"'."\n"; + $content.='mount --bind "'.$row['path'].'" "/home/ftp/sjy_'.$row['userid'].'/'.preg_replace('/^.+[\\\\\\/]/', '', rtrim($row['path'],'/')).'"'."\n"; } $sql="select distinct dataorder.userid,dataset.path,dataservice.uuid from dataorder left join dataset on dataorder.uuid=dataset.uuid left join dataservice on dataorder.uuid=dataservice.uuid - where dataorder.status in (0,5) and dataset.host='ftp2.westgis.ac.cn' and dataset.path<>'' and dataorder.selection is not null and dataservice.service_type in (1,2)"; + where dataorder.status in (0,5) and dataset.host='ftp.sanjiangyuan.org.cn' and dataset.path<>'' and dataorder.selection is not null and dataservice.service_type in (1,2)"; if ($onlineappid>0) $sql.=" and dataorder.onlineappid=".$onlineappid; else if ($offlineappid>0) $sql.=" and dataorder.offlineappid=".$offlineappid; $result = pg_query($link, $sql); $numrows = pg_num_rows($result); - $basepath='/disk1/WestDC/wsndata/'; + $basepath='/data/wsndata/'; for($ri = 0; $ri < $numrows; $ri++) { $row = pg_fetch_array($result, $ri); $content.='# path: '.$row['path']."\n"; - $content.='mkdir -p "/home/ftp/westdc_'.$row['userid'].'/wsn_'.$row['userid'].'"'."\n"; - $content.='mount --bind "'.$basepath.'wsn_'.$row['userid'].'" "/home/ftp/westdc_'.$row['userid'].'/wsn_'.$row['userid'].'"'."\n"; + $content.='mkdir -p "/home/ftp/sjy_'.$row['userid'].'/wsn_'.$row['userid'].'"'."\n"; + $content.='mount --bind "'.$basepath.'wsn_'.$row['userid'].'" "/home/ftp/wsjy_'.$row['userid'].'/wsn_'.$row['userid'].'"'."\n"; } $filename='./proftp-user.sh'; From 72f4a0e09ff4c2c44a5c1a2fff8bd76185e94f1c Mon Sep 17 00:00:00 2001 From: wlx Date: Sat, 14 Dec 2013 12:00:44 +0000 Subject: [PATCH 077/173] change ftp url --- application/config.ini | 5 +---- application/default/controllers/AuthorController.php | 8 ++++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/application/config.ini b/application/config.ini index 37170539..b5aa1201 100755 --- a/application/config.ini +++ b/application/config.ini @@ -22,11 +22,8 @@ paths.newsletter=images/newsletter/ logging.file = /var/www/test.westgis.ac.cn/data/logs/debug.log page.limit=10 import.dir=../data/import -title.site=三江源自然保护区数据管理中心 +title.site=三江源生态监测综合数据服务平台 title.data=数据产品与服务 -title.heihe=黑河计划数据管理中心 -title.yrnmr=黄河上游宁蒙河段综合数据平台 -title.glacier=中国冰川资源及其变化调查 title.review=数据评审 title.author=数据作者 title.knowledge=知识积累 diff --git a/application/default/controllers/AuthorController.php b/application/default/controllers/AuthorController.php index bc846292..a4fdeda1 100644 --- a/application/default/controllers/AuthorController.php +++ b/application/default/controllers/AuthorController.php @@ -2376,7 +2376,7 @@ class AuthorController extends Zend_Controller_Action // 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'])); - file_get_contents("http://ftp2.westgis.ac.cn/proftp_upload.php?uuid=".$row['uuid']."&filelist=1"); + file_get_contents("http://ftp.sanjiangyuan.org.cn/proftp_upload.php?uuid=".$row['uuid']."&filelist=1"); // 3. 保存数据评审状态 //导入元数据 @$iso->saveDB($this->db); @@ -2472,10 +2472,10 @@ class AuthorController extends Zend_Controller_Action } //ftp 用户名 - $uname = 'westdc'.$u_id.'upload'; + $uname = 'sjy'.$u_id.'upload'; //ftp路径 - $homedir = "/disk1/WestDC/upload/".$uuid."/"; + $homedir = "/data/upload/".$uuid."/"; //ftp用户表 $ftptable=' pureftp ';//ftp2.westgis.ac.cn $uid = 1002; @@ -2491,7 +2491,7 @@ class AuthorController extends Zend_Controller_Action //$old=umask(0); //@mkdir($homedir,0777); //umask($old); - $page=file_get_contents('http://ftp2.westgis.ac.cn/proftp_upload.php?uuid='.$uuid); + $page=file_get_contents('http://ftp.sanjiangyuan.org.cn/proftp_upload.php?uuid='.$uuid); if (!empty($page)) die($page);//there are errors in visit ftp page From 8d01826db345b1dda8cbdf2e5f3de040f90c8872 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Mon, 16 Dec 2013 02:28:33 +0000 Subject: [PATCH 078/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=9A=84=E7=94=A8=E6=88=B7=E5=90=8D=E9=95=BF=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/module/Users/Operation/LoginOperate.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/module/Users/Operation/LoginOperate.php b/application/module/Users/Operation/LoginOperate.php index 8f21200d..31077007 100644 --- a/application/module/Users/Operation/LoginOperate.php +++ b/application/module/Users/Operation/LoginOperate.php @@ -45,9 +45,9 @@ class LoginOperate implements \Users\Event\LoginEvent if(!empty($data['username'])) { - if(!preg_match("/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/",$data['username'])) + if(!preg_match("/^[a-zA-Z][a-zA-Z0-9_]{2,25}$/",$data['username'])) { - return array('error'=>"用户名应当以字母开头,由字母数字和下划线组成,并且长度在5到25个字符之间",'place'=>'username'); + return array('error'=>"用户名应当以字母开头,由字母数字和下划线组成,并且长度在3到25个字符之间",'place'=>'username'); } } From ac7245e603ac4049fecb5ed50f26be30542dee07 Mon Sep 17 00:00:00 2001 From: wlx Date: Mon, 16 Dec 2013 06:12:38 +0000 Subject: [PATCH 079/173] change ftp url --- application/admin/controllers/DataController.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index ed125cf4..e74caa6f 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -553,9 +553,9 @@ class Admin_DataController extends Zend_Controller_Action if ($host=='ftp1.westgis.ac.cn') { file_get_contents("http://ftp1.westgis.ac.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); - } else if ($host=='ftp2.westgis.ac.cn') + } else if ($host=='ftp.sanjiangyuan.org.cn') { - file_get_contents("http://ftp2.westgis.ac.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); + file_get_contents("http://ftp.sanjiangyuan.org.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); } if($ds) @@ -596,9 +596,9 @@ class Admin_DataController extends Zend_Controller_Action if ($host=='ftp1.westgis.ac.cn') { file_get_contents("http://ftp1.westgis.ac.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); - } else if ($host=='ftp2.westgis.ac.cn') + } else if ($host=='ftp.sanjiangyuan.org.cn') { - file_get_contents("http://ftp2.westgis.ac.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); + file_get_contents("http://ftp.sanjiangyuan.org.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); } if($ds) @@ -627,9 +627,9 @@ class Admin_DataController extends Zend_Controller_Action { file_get_contents("http://ftp1.westgis.ac.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); echo '

      数据目录成功导入!

      '; - } else if ($row['host']=='ftp2.westgis.ac.cn') + } else if ($row['host']=='ftp.sanjiangyuan.org.cn') { - file_get_contents("http://ftp2.westgis.ac.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); + file_get_contents("http://ftp.sanjiangyuan.org.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); echo '

      数据目录成功导入!

      '; } else { echo '

      数据目录未导入!

      '; From 88e29d711e7239f1d240da627bce022da24396f9 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Wed, 18 Dec 2013 02:43:10 +0000 Subject: [PATCH 080/173] =?UTF-8?q?=E5=9C=A8hiwater=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E5=A4=9A=E7=AF=87=E6=96=87=E7=8C=AE=E5=BC=95=E7=94=A8=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E4=B8=AD=E5=8A=A0=E5=85=A5=E4=BA=86=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E5=92=8C=E4=B8=8B=E8=BD=BD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/default/views/scripts/hiwater/view.phtml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/application/default/views/scripts/hiwater/view.phtml b/application/default/views/scripts/hiwater/view.phtml index 7a851a6d..1cf65878 100644 --- a/application/default/views/scripts/hiwater/view.phtml +++ b/application/default/views/scripts/hiwater/view.phtml @@ -46,9 +46,16 @@ if ($md->title_en) echo '
      '.$this->escape($md->title_en);?>
        mcitation as $ref) : if (empty($ref->link)) - echo '
      1. '.$ref->reference.'
      2. '; + { + echo '
      3. '.$ref->reference; + echo '查看'; + if(!empty($ref->attid)) { + echo ' 下载'; + } + echo "
      4. "; + } else - echo '
      5. '.$ref->reference.' 下载
      6. '; + echo '
      7. '.$ref->reference.'查看 下载
      8. '; endforeach; ?>
      From 548369039585adb170331a2a6662957ebacc11a5 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Tue, 24 Dec 2013 09:39:34 +0000 Subject: [PATCH 081/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9form=E5=AE=BD?= =?UTF-8?q?=E5=BA=A6=E8=B6=85=E5=87=BA=E9=A1=B5=E9=9D=A2=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/default/views/scripts/account/edit.phtml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/application/default/views/scripts/account/edit.phtml b/application/default/views/scripts/account/edit.phtml index c37d8411..db4eff44 100755 --- a/application/default/views/scripts/account/edit.phtml +++ b/application/default/views/scripts/account/edit.phtml @@ -53,13 +53,13 @@
      - info['unit']; ?>" class="span8" /> + info['unit']; ?>" class="input-block-level" />
      - info['address']; ?>" class="span8" /> + info['address']; ?>" class="input-block-level" />
      @@ -107,13 +107,13 @@
      - info['project_title']; ?>" class="span8" /> + info['project_title']; ?>" class="input-block-level" />
      - +
      From c2225d4e2169f1343d3930814166a888c354ea04 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Thu, 26 Dec 2013 02:15:41 +0000 Subject: [PATCH 082/173] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E7=9A=84=E7=BB=9F=E4=B8=80=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/views/scripts/data/left.phtml | 4 ++-- application/admin/views/scripts/down/left.phtml | 4 ++-- application/admin/views/scripts/news/left.phtml | 4 ++-- application/admin/views/scripts/stat/left.phtml | 4 ++-- application/admin/views/scripts/sys/left.phtml | 6 +++--- application/admin/views/scripts/user/left.phtml | 4 ++-- application/admin/views/scripts/watermd/left.phtml | 14 +++++++------- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/application/admin/views/scripts/data/left.phtml b/application/admin/views/scripts/data/left.phtml index 5e4684a6..9f3d6c21 100644 --- a/application/admin/views/scripts/data/left.phtml +++ b/application/admin/views/scripts/data/left.phtml @@ -1,5 +1,5 @@ -
        -
      • 数据管理
      • +
      diff --git a/application/module/Helpers/Captcha.php b/application/module/Helpers/Captcha.php new file mode 100644 index 00000000..dc61b759 --- /dev/null +++ b/application/module/Helpers/Captcha.php @@ -0,0 +1,52 @@ +loadCaptcha(); + } + + public function loadCaptcha() + { + $this->captcha = new \Zend_Captcha_Image(array( + 'captcha' => 'Image', + 'wordLen' => 4, + 'fontsize'=>16, + 'width' => 100, + 'height' => 38, + 'dotNoiseLevel'=>2, + 'lineNoiseLevel'=>1, + 'timeout' => 300, + 'font' => '../data/fonts/ggbi.ttf', + 'imgDir' => 'vdimg/', + 'imgUrl' => '/vdimg', + )); + } + + public function setCaptcha(){ + $this->captcha->generate(); + $_SESSION[$this->sessionName] = $this->captcha->getWord(); + $url = $this->captcha->getImgUrl() + .$this->captcha->getId() + .$this->captcha->getSuffix(); + + return $url; + } + + public function isValid($captchaword) + { + if($captchaword == $_SESSION[$this->sessionName]) + { + return true; + }else{ + return false; + } + } + +} \ No newline at end of file diff --git a/application/module/Users/Account.php b/application/module/Users/Account.php index 717a34d6..1e35480b 100644 --- a/application/module/Users/Account.php +++ b/application/module/Users/Account.php @@ -1,372 +1,374 @@ -db = \Zend_Registry::get('db'); - }else{ - $this->db = $db; - } - - $this->config = \Zend_Registry::get('config'); - - if($initializingListener === TRUE) - { - $this->loadListener(); - } - } - - public function loadListener() - { - //主要操作,账号注册,登录,设置session等 - $AccountListener = new AccountListener(); - @$this->events()->attachAggregate($AccountListener); - - //账户编辑 - $EditListener = new EditListener(); - @$this->events()->attachAggregate($EditListener); - - //账户安全性(找回密码) - $PwdListener = new PwdListener(); - @$this->events()->attachAggregate($PwdListener); - } - - public function events(\Zend_EventManager_EventCollection $events = NULL) - { - if ($events !== NULL) { - $this->events = $events; - } elseif ($this->events === NULL) { - $this->events = new \Zend_EventManager_EventManager(__CLASS__); - } - return $this->events; - } - - //获取账号信息,数组 - public function getAccountInfo($id = 0) - { - if($id == 0) - { - $id = view::User('id'); - } - $sql = "SELECT * FROM {$this->memberTable} WHERE id=$id"; - $rs = $this->db->query($sql); - return $rs->fetch(); - } - - //注册 - public function register($data) - { - $params = compact('data'); - $results = $this->events()->trigger('register.checkParam', $this, $params); - $cache_data = $results->bottom(); - - if($cache_data !== true) - { - if(!is_array($cache_data)) - { - return array('error'=>$cache_data); - }else{ - return $cache_data; - } - } - - $results = $this->events()->trigger('register.checkUser', $this, $params); - $cache_data = $results->bottom(); - - if($cache_data !== true) - { - if(!is_array($cache_data)) - { - return array('error'=>$cache_data); - }else{ - return $cache_data; - } - } - - $loginData = array( - 'username'=>$data['username'], - 'password'=>$data['password'] - ); - - $data['password'] = md5($data['password']); - $data['usertype'] = "member"; - unset($data['confirm_password']); - - $dbh = new dbh(); - - $id = $dbh->insert($this->memberTable,$data,true); - - if(!empty($id) && is_numeric($id)) - { - $this->storeLogin($loginData); - $mb = new Member(); - $mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]); //username, md5(password) - $params = compact('data','id'); - $results = $this->events()->trigger('register.success', $this, $params); - return array("success" => 1); - }else{ - if($id === false) - { - return array('error'=>'服务器开小差了,请稍后再试'); - }else{ - return array('error'=>'服务器处理中遇到错误,请联系管理员'); - } - } - - }//register - - //登陆 - public function login($data) - { - $results = $this->events()->trigger('login.checkParam', $this, compact('data')); - $cache_data = $results->bottom(); - - if($cache_data !== true) - { - if(!is_array($cache_data)) - { - return array('error'=>$cache_data); - }else{ - return $cache_data; - } - } - - $state = $this->storeLogin($data); - - $mb = new Member(); - $mb->putcookie($data[$this->FieldUsername],md5($data[$this->FieldPasword])); - - return $state; - }//login - - //storeLogin - //将登录信息保存在session和cookie中 - public function storeLogin($data,$md5verify = true) - { - $auth = \Zend_Auth::getInstance(); - $authAdapter = new \Zend_Auth_Adapter_DbTable($this->db); - $authAdapter->setTableName($this->memberTable) - ->setIdentityColumn($this->FieldUsername) - ->setCredentialColumn($this->FieldPasword); - - if($data[$this->FieldPasword] == 0) - { - $password = "0"; - }else{ - if($md5verify === false) - { - $password = $data[$this->FieldPasword]; - }else{ - $password = md5($data[$this->FieldPasword]); - } - } - - $authAdapter->setIdentity($data[$this->FieldUsername])->setCredential($password); - - $result = $auth->authenticate($authAdapter); - if ($result->isValid()) { - - $user = $authAdapter->getResultRowObject(null,$this->FieldPasword); - $email = $user->email; - $results = $this->events()->trigger('login.success.createAvatar', $this, compact('email')); - $user->avatar = $results->bottom(); - $auth->getStorage()->write($user); - - $id = $user->id; - @$results = $this->events()->trigger('login.success.updateStatus', $this, compact('id')); - - return array('success'=>1); - } - return array('error'=>'处理中发现错误,请重试'); - } - - //注册信息参数 - public function getParam(\Zend_Controller_Request_Abstract $request) - { - $data = array( - 'username'=>$request->getParam('username'), - 'password'=>$request->getParam('password'), - 'confirm_password'=>$request->getParam('confirm_password'), - 'email'=>$request->getParam('email'), - 'realname'=>$request->getParam('realname') - ); - return $data; - } - - //获取用户账户修改参数 - public function getEditParam(\Zend_Controller_Request_Abstract $request) - { - $type = $request->getParam('type'); - - if($type == "general") - { - $data = array( - 'realname'=>$request->getParam('realname'), - 'signature'=>$request->getParam('signature'), - 'description'=>$request->getParam('description') - ); - } - - if($type == "password") - { - $data = array( - 'password' => $request->getParam('password'), - 'password_new'=>$request->getParam('password_new'), - 'password_confirm'=>$request->getParam('password_confirm') - ); - } - return $data; - } - - //编辑 - public function edit($data,$type) - { - $results = $this->events()->trigger('edit.checkParam', $this, compact('data','type')); - $cache_data = $results->bottom(); - - if($cache_data !== true) - { - return $cache_data; - } - - if($type == "general") - { - $data['signature'] = htmlspecialchars($data['signature']); - $data['description'] = htmlspecialchars($data['description']); - }else if($type == "password") - { - $data['password'] = md5($data['password_new']); - unset($data['password_new']); - unset($data['password_confirm']); - }else{ - return "参数错误"; - } - - $dbh = new dbh(); - $uid = view::User('id'); - if($dbh->update($this->memberTable,$data," id=$uid") === true) - { - return true; - }else{ - return false; - } - } - - //找回密码 - public function getMyPassword($email) - { - $results = $this->events()->trigger('pwd.forgot.checkParam', $this, compact('email')); - $cache_data = $results->bottom(); - - if($cache_data !== true) - { - return $cache_data; - } - - $sql = "SELECT * FROM {$this->memberTable} WHERE email='$email'"; - $rs = $this->db->query($sql); - $row = $rs->fetch(); - - if(!isset($row['username']) || empty($row['username'])) - { - return array('error'=>"此邮箱并未注册",'place'=>'email'); - } - - $salt = md5($email.'---'.$row['username']); - - $sql = "UPDATE {$this->memberTable} SET salt='$salt' WHERE id={$row['id']}"; - $state = $this->db->exec($sql); - - if($state<1) - { - return array('error'=>"处理中出现错误,请重试",'place'=>'email'); - } - - $mail_template = "forgotpassword"; - $mail_data = array( - 'name'=>$row['realname'], - 'link'=> view::getHostLink().'/account/getpassword/salt/'.$salt - ); - - $mail = new Mail(); - - $mail->loadTemplate($mail_template,$mail_data); - $mail->addTo($email,$row['realname']); - $mail->send(); - - return array("success"=>1); - } - - //重置密码 - public function resetPassword($data) - { - $results = $this->events()->trigger('pwd.reset.checkParam', $this, compact('data')); - $cache_data = $results->bottom(); - - if($cache_data !== true) - { - return $cache_data; - } - - $sql = "SELECT * FROM {$this->memberTable} WHERE salt=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($data['salt'])); - $row = $sth->fetch(); - - if(!isset($row['username']) || empty($row['username'])) - { - return array('error'=>"您提供的校验码不正确,请重新申请重置密码",'place'=>'confirm_password'); - } - - if($row['username'] !== $data['username']) - { - return array('error'=>"您提供的校验码不正确,请重新申请重置密码",'place'=>'confirm_password'); - } - - $sql = "UPDATE {$this->memberTable} SET password='".md5($data['password'])."',salt='' WHERE id={$row['id']}"; - $this->db->exec($sql); - - $mail_template = "getpassworded"; - $mail_data = array( - 'name'=>$row['realname'], - ); - $mail = new Mail(); - $mail->loadTemplate($mail_template,$mail_data); - $mail->addTo($row['email'],$row['realname']); - $mail->send(); - - return true; - - } - +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + + if($initializingListener === TRUE) + { + $this->loadListener(); + } + } + + public function loadListener() + { + //主要操作,账号注册,登录,设置session等 + $AccountListener = new AccountListener(); + @$this->events()->attachAggregate($AccountListener); + + //账户编辑 + $EditListener = new EditListener(); + @$this->events()->attachAggregate($EditListener); + + //账户安全性(找回密码) + $PwdListener = new PwdListener(); + @$this->events()->attachAggregate($PwdListener); + } + + public function events(\Zend_EventManager_EventCollection $events = NULL) + { + if ($events !== NULL) { + $this->events = $events; + } elseif ($this->events === NULL) { + $this->events = new \Zend_EventManager_EventManager(__CLASS__); + } + return $this->events; + } + + //获取账号信息,数组 + public function getAccountInfo($id = 0) + { + if($id == 0) + { + $id = view::User('id'); + } + $sql = "SELECT * FROM {$this->memberTable} WHERE id=$id"; + $rs = $this->db->query($sql); + return $rs->fetch(); + } + + //注册 + public function register($data) + { + $params = compact('data'); + $results = $this->events()->trigger('register.checkParam', $this, $params); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + if(!is_array($cache_data)) + { + return array('error'=>$cache_data); + }else{ + return $cache_data; + } + } + + $results = $this->events()->trigger('register.checkUser', $this, $params); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + if(!is_array($cache_data)) + { + return array('error'=>$cache_data); + }else{ + return $cache_data; + } + } + + $loginData = array( + 'username'=>$data['username'], + 'password'=>$data['password'] + ); + + $data['password'] = md5($data['password']); + $data['usertype'] = "member"; + unset($data['confirm_password']); + + $dbh = new dbh(); + + $id = $dbh->insert($this->memberTable,$data,true); + + if(!empty($id) && is_numeric($id)) + { + $this->storeLogin($loginData); + $mb = new Member(); + $mb->putcookie($data[$this->FieldUsername],$data[$this->FieldPasword]); //username, md5(password) + $params = compact('data','id'); + $results = $this->events()->trigger('register.success', $this, $params); + return array("success" => 1); + }else{ + if($id === false) + { + return array('error'=>'服务器开小差了,请稍后再试'); + }else{ + return array('error'=>'服务器处理中遇到错误,请联系管理员'); + } + } + + }//register + + //登陆 + public function login($data) + { + $results = $this->events()->trigger('login.checkParam', $this, compact('data')); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + if(!is_array($cache_data)) + { + return array('error'=>$cache_data); + }else{ + return $cache_data; + } + } + + $state = $this->storeLogin($data); + + $mb = new Member(); + $mb->putcookie($data[$this->FieldUsername],md5($data[$this->FieldPasword])); + + return $state; + }//login + + //storeLogin + //将登录信息保存在session和cookie中 + public function storeLogin($data,$md5verify = true) + { + $auth = \Zend_Auth::getInstance(); + $authAdapter = new \Zend_Auth_Adapter_DbTable($this->db); + $authAdapter->setTableName($this->memberTable) + ->setIdentityColumn($this->FieldUsername) + ->setCredentialColumn($this->FieldPasword); + + if($data[$this->FieldPasword] === 0) + { + $password = "0"; + }else{ + if($md5verify == false) + { + $password = $data[$this->FieldPasword]; + }else{ + $password = md5($data[$this->FieldPasword]); + } + } + + $authAdapter->setIdentity($data[$this->FieldUsername])->setCredential($password); + $result = $auth->authenticate($authAdapter); + + if ($result->isValid()) { + + $user = $authAdapter->getResultRowObject(null,$this->FieldPasword); + $email = $user->email; + $results = $this->events()->trigger('login.success.createAvatar', $this, compact('email')); + $user->avatar = $results->bottom(); + $auth->getStorage()->write($user); + + $id = $user->id; + @$results = $this->events()->trigger('login.success.updateStatus', $this, compact('id')); + + return array('success'=>1); + }else{ + return array("error"=>"用户信息验证失败,请重新登录"); + } + return array('error'=>'处理中发现错误,请重试'); + } + + //注册信息参数 + public function getParam(\Zend_Controller_Request_Abstract $request) + { + $data = array( + 'username'=>$request->getParam('username'), + 'password'=>$request->getParam('password'), + 'confirm_password'=>$request->getParam('confirm_password'), + 'email'=>$request->getParam('email'), + 'realname'=>$request->getParam('realname') + ); + return $data; + } + + //获取用户账户修改参数 + public function getEditParam(\Zend_Controller_Request_Abstract $request) + { + $type = $request->getParam('type'); + + if($type == "general") + { + $data = array( + 'realname'=>$request->getParam('realname'), + 'signature'=>$request->getParam('signature'), + 'description'=>$request->getParam('description') + ); + } + + if($type == "password") + { + $data = array( + 'password' => $request->getParam('password'), + 'password_new'=>$request->getParam('password_new'), + 'password_confirm'=>$request->getParam('password_confirm') + ); + } + return $data; + } + + //编辑 + public function edit($data,$type) + { + $results = $this->events()->trigger('edit.checkParam', $this, compact('data','type')); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + return $cache_data; + } + + if($type == "general") + { + $data['signature'] = htmlspecialchars($data['signature']); + $data['description'] = htmlspecialchars($data['description']); + }else if($type == "password") + { + $data['password'] = md5($data['password_new']); + unset($data['password_new']); + unset($data['password_confirm']); + }else{ + return "参数错误"; + } + + $dbh = new dbh(); + $uid = view::User('id'); + if($dbh->update($this->memberTable,$data," id=$uid") === true) + { + return true; + }else{ + return false; + } + } + + //找回密码 + public function getMyPassword($email) + { + $results = $this->events()->trigger('pwd.forgot.checkParam', $this, compact('email')); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + return $cache_data; + } + + $sql = "SELECT * FROM {$this->memberTable} WHERE email='$email'"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + + if(!isset($row['username']) || empty($row['username'])) + { + return array('error'=>"此邮箱并未注册",'place'=>'email'); + } + + $salt = md5($email.'---'.$row['username']); + + $sql = "UPDATE {$this->memberTable} SET salt='$salt' WHERE id={$row['id']}"; + $state = $this->db->exec($sql); + + if($state<1) + { + return array('error'=>"处理中出现错误,请重试",'place'=>'email'); + } + + $mail_template = "forgotpassword"; + $mail_data = array( + 'name'=>$row['realname'], + 'link'=> view::getHostLink().'/account/getpassword/salt/'.$salt + ); + + $mail = new Mail(); + + $mail->loadTemplate($mail_template,$mail_data); + $mail->addTo($email,$row['realname']); + $mail->send(); + + return array("success"=>1); + } + + //重置密码 + public function resetPassword($data) + { + $results = $this->events()->trigger('pwd.reset.checkParam', $this, compact('data')); + $cache_data = $results->bottom(); + + if($cache_data !== true) + { + return $cache_data; + } + + $sql = "SELECT * FROM {$this->memberTable} WHERE salt=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($data['salt'])); + $row = $sth->fetch(); + + if(!isset($row['username']) || empty($row['username'])) + { + return array('error'=>"您提供的校验码不正确,请重新申请重置密码",'place'=>'confirm_password'); + } + + if($row['username'] !== $data['username']) + { + return array('error'=>"您提供的校验码不正确,请重新申请重置密码",'place'=>'confirm_password'); + } + + $sql = "UPDATE {$this->memberTable} SET password='".md5($data['password'])."',salt='' WHERE id={$row['id']}"; + $this->db->exec($sql); + + $mail_template = "getpassworded"; + $mail_data = array( + 'name'=>$row['realname'], + ); + $mail = new Mail(); + $mail->loadTemplate($mail_template,$mail_data); + $mail->addTo($row['email'],$row['realname']); + $mail->send(); + + return true; + + } + } \ No newline at end of file diff --git a/application/module/Users/Member.php b/application/module/Users/Member.php index 9854e6f1..fcb2bce2 100644 --- a/application/module/Users/Member.php +++ b/application/module/Users/Member.php @@ -1,5 +1,5 @@ "用户名应当以字母开头,由字母数字和下划线组成,并且长度在5到25个字符之间",'place'=>'username'); + return array('error'=>"用户名应当以字母开头,由字母数字和下划线组成,并且长度在3到25个字符之间",'place'=>'username'); } } @@ -106,6 +106,10 @@ class LoginOperate implements \Users\Event\LoginEvent }//loginSuccess - + //检查token表记录 + public function checkOAuthToken() + { + + } } \ No newline at end of file From e8aba81d7d85d94a1a0f08dcf89303ee5cacb26f Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Thu, 26 Dec 2013 07:12:59 +0000 Subject: [PATCH 084/173] =?UTF-8?q?=E4=B8=BA=E9=82=AE=E4=BB=B6=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=8A=9F=E8=83=BD=E6=B7=BB=E5=8A=A0=E5=86=97=E9=94=99?= =?UTF-8?q?=E5=88=A4=E6=96=AD=EF=BC=8C=E4=BD=BF=E7=94=A8=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=8C=96=E5=B0=81=E8=A3=85=E7=9A=84=E6=89=BE=E5=9B=9E=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/AccountController.php | 254 +++++------------- .../account/account-resetpassword.phtml | 41 +++ .../views/scripts/account/fetchpwd.phtml | 79 ++++-- application/module/Mail/Mail.php | 7 +- application/module/Users/Account.php | 17 +- .../module/Users/Operation/PwdOperate.php | 9 +- 6 files changed, 187 insertions(+), 220 deletions(-) create mode 100644 application/default/views/scripts/account/account-resetpassword.phtml diff --git a/application/default/controllers/AccountController.php b/application/default/controllers/AccountController.php index 37691bc2..fc35b8bb 100755 --- a/application/default/controllers/AccountController.php +++ b/application/default/controllers/AccountController.php @@ -2,6 +2,7 @@ use Mail\Mail; use Open\Client; use Users\Account; +use Users\Member; use Helpers\Captcha; use Helpers\View as view; @@ -357,211 +358,92 @@ class AccountController extends Zend_Controller_Action $this->view->captcha = $captcha->setCaptcha(); } - function loadCaptcha() + public function captchaAction() { - $captcha = new Zend_Captcha_Image(array( - 'captcha' => 'Image', - 'wordLen' => 4, - 'fontsize'=>16, - 'width' => 100, - 'height' => 38, - 'dotNoiseLevel'=>2, - 'lineNoiseLevel'=>1, - 'timeout' => 300, - 'font' => '../data/fonts/ggbi.ttf', - 'imgDir' => 'vdimg/', - 'imgUrl' => '/vdimg', - )); - return $captcha; - } - - function setCaptcha(Zend_Captcha_Image $captcha,$ajax = false){ - $captcha->generate(); - $_SESSION['captcha'] = $captcha->getWord(); - $url = $captcha->getImgUrl() - .$captcha->getId() - .$captcha->getSuffix(); - if(!$ajax) + if(view::isXmlHttpRequest($this)) { - $this->view->captcha = $url; + $captcha = new Captcha(); + $url = $captcha->setCaptcha(); + echo $url; + return true; }else{ - return $url; + echo "bad request!"; + exit(); } } - - function captchaAction() - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $captcha = $this->loadCaptcha(); - $url = $this->setCaptcha($captcha,true); - - echo $url; - return true; - } - function logoutAction() + public function logoutAction() { $auth = Zend_Auth::getInstance(); $auth->clearIdentity(); - require_once 'member.php'; - $mb=new member(); - member::flushcookie(); + Member::flushcookie(); $this->_redirect('/'); - } - - private function default_login($u,$p) - { - $auth = Zend_Auth::getInstance(); - $db=Zend_Registry::get('db'); - - $authAdapter = new Zend_Auth_Adapter_DbTable($db); - $authAdapter->setTableName('users') - ->setIdentityColumn('username') - ->setCredentialColumn('password'); - $authAdapter->setIdentity($u)->setCredential(md5($p)); - $result = $auth->authenticate($authAdapter); - if ($result->isValid()) { - // success: store database row to auth's storage - $data = $authAdapter->getResultRowObject(null,'password'); - - //头像 - include_once("Avatar.php"); - $avatar = new Avatar(); - $data->avatar = $avatar->Get($data->email,40); - - //组ID - include_once("Users.php"); - $usr = new Users($db); - $data->gid = $usr->getGroup($data->id); - - $auth->getStorage()->write($data); - $db->query("update users set ts_last_login=now() where username=?",array($u)); - - if ($this->_request->getParam('remember')) { - $sql="select usertype from users where username='$u'"; - $rs=$db->query($sql); - $row=$rs->fetch(); - //if($row['usertype']!='administrator') - { - require_once 'member.php'; - $mb = new member(); - $mb -> putcookie($u,md5($p)); - } - } - - return true; - }else - { - return false; - } - return false; - } - private function aspnet_login($p,$salt,$password) - { - $p1=implode("\x00",str_split($p))."\x00"; - $ball=base64_decode($salt).$p1; - return trim($password)==base64_encode(sha1($ball,true)); - } - // 首先判断是否存在salt - // 若有salt,则按照aspnet membership加密算法进行判断 - function login($u,$p) - { - $ut= new UsersTable(); - $db=$ut->getAdapter(); - $sql="select password,salt from users where username=?"; - $uq=$db->query($sql,array($u)); - if ($urow=$uq->fetchObject()) - { - if (empty($urow->salt)) - return $this->default_login($u,$p); - else { - //进行判断并进行转换到默认 - if ($this->aspnet_login($p,$urow->salt,$urow->password)) - { - $sql="update users set password=md5(?),salt='' where username=?"; - $db->query($sql,array($p,$u)); - return $this->default_login($u,$p); - } else - return false; - } - } else { - //没有对应的用户,登录失败 - return false; - } } - function fetchpwdAction() + + public function fetchpwdAction() { - $ut= new UsersTable(); - $db=$ut->getAdapter(); - $form = new LostpwdForm(); - $key=$this->_request->getParam('key'); - $login=$this->_request->getParam('login'); - if (empty($key) && empty($login)) { - $this->view->form = $form; - if ($this->_request->isPost()) { - $formData = $this->_request->getPost(); - if ($form->isValid($formData)) { - $sql="select * from users where email=?"; - $uq=$db->query($sql,array($formData['email'])); - if ($urow=$uq->fetchObject()) - { - //email the url to user - $username=$urow->username; - $sql="update users set activation=? where email=?"; - $uid=uniqid(); - $db->query($sql,array($uid,$formData['email'])); - - //发邮件 - $mail_template = "users-changepassword"; - $mail_data = array( - 'name'=>$username, - 'url' => view::getHostLink()."/account/fetchpwd/".$username."/".$uid - ); - - $mail = new Mail(); - - $mail->loadTemplate($mail_template,$mail_data); - $mail->addTo($formData['email'],$username); - $mail->send(); - + $salt = trim($this->_getParam('salt')); - $this->view->messages[]='请检查您的新邮件中的确认激活链接。'; - $this->view->form=false;//do not echo form - } else - $this->messenger->addMessage('对不起,没有找到对应的电子邮件地址。'); - } - } else - $this->view->messages[]='请输入您的电子邮件地址。您将通过电子邮件收到新密码。'; - } else { - $sql="select * from users where username=? and activation=?"; - $uq=$db->query($sql,array($login,$key)); - $tmp_pwd=uniqid(); - if ($urow=$uq->fetchObject()) + if(empty($salt)) + { + $captcha = new Captcha(); + if(!empty($this->_getParam('submit'))) { - $sql="update users set salt='',activation='',password=md5('".$tmp_pwd."') where username=? and activation=?"; - $db->query($sql,array($login,$key)); + $email = trim($this->_request->getParam('email')); + $captchaword = trim($this->_request->getParam('captcha')); - //发邮件 - $mail_template = "users-changepassword"; - $mail_data = array( - 'name'=>$login, - 'tmp_pwd' => $tmp_pwd - ); + if(!$captcha->isValid($captchaword)) + { + $this->view->error = view::Error("验证码错误"); + $this->view->captcha = $captcha->setCaptcha(); + return true; + } - $mail = new Mail(); + $account = new Account(); + $status = $account->getMyPassword($email); - $mail->loadTemplate($mail_template,$mail_data); - $mail->addTo($urow->email,$login); - $mail->send(); + if(isset($status['error'])) + { + $this->view->error = view::Error($status['error']); + $this->view->captcha = $captcha->setCaptcha(); + return true; + } - $this->view->messages[]='请查收您新邮件中的新密码'; - $this->view->form=false;//do not echo form - - } + view::Post($this,"您的密码重置申请已提交,请在邮箱中查看"); + return true; + }else{ + $this->view->captcha = $captcha->setCaptcha(); + }//提交密码重置申请 } - + + else{ + $this->_helper->viewRenderer('account-resetpassword'); + $this->view->salt = $salt; + if(!empty($this->_getParam('submit'))) + { + $username = trim($this->_request->getParam('username')); + $password = trim($this->_request->getParam('password')); + $confirm_password = trim($this->_request->getParam('confirm_password')); + + $account = new Account(); + $status = $account->resetPassword(array( + 'username' => $username, + 'password' => $password, + 'confirm_password' => $confirm_password, + 'salt' => $salt + )); + + if(isset($status['error'])) + { + $this->view->error = view::Error($status['error']); + return true; + } + + view::Post($this,"您的密码修改成功!请使用新密码登录","/account/login"); + return true; + } + }//修改密码 + } //找回密码 //OAuth2登录跳转页面 diff --git a/application/default/views/scripts/account/account-resetpassword.phtml b/application/default/views/scripts/account/account-resetpassword.phtml new file mode 100644 index 00000000..34e6b0e0 --- /dev/null +++ b/application/default/views/scripts/account/account-resetpassword.phtml @@ -0,0 +1,41 @@ +headTitle($this->config->title->site); + $this->headTitle('用户登录'); + $this->headTitle()->setSeparator(' - '); + $this->breadcrumb('首页'); + $this->breadcrumb('用户登录'); + $this->breadcrumb()->setSeparator(' > '); +?> +
      + error)) { ?> + error ?> + +
      +
      + +
      + +
      +
      +
      + +
      + +
      +
      +
      + +
      + +
      +
      +
      +
      + + + + 登录 注册新用户 +
      +
      + +
      \ No newline at end of file diff --git a/application/default/views/scripts/account/fetchpwd.phtml b/application/default/views/scripts/account/fetchpwd.phtml index fcea22a9..ac41ca95 100644 --- a/application/default/views/scripts/account/fetchpwd.phtml +++ b/application/default/views/scripts/account/fetchpwd.phtml @@ -1,24 +1,55 @@ -headTitle($this->config->title->site); - $this->headTitle('用户登录'); - $this->headTitle()->setSeparator(' - '); - $this->headLink()->appendStylesheet('/css/register.css'); - $this->breadcrumb('首页'); - $this->breadcrumb('找回密码'); - $this->breadcrumb()->setSeparator(' > '); -?> -messages)) : ?> -
      -messages as $info)echo $info; - ?> -
      - -form) : ?> -
      -form;?> -
      - - +headTitle($this->config->title->site); + $this->headTitle('用户登录'); + $this->headTitle()->setSeparator(' - '); + $this->headLink()->appendStylesheet('/css/register.css'); + $this->breadcrumb('首页'); + $this->breadcrumb('找回密码'); + $this->breadcrumb()->setSeparator(' > '); +?> +
      + error)) { ?> + error ?> + +
      +
      + +
      + + 请输入注册时填写的Email地址 +
      +
      +
      + +
      + + + 看不清? +
      +
      +
      +
      + + href)){?> + + + + 登录 注册新用户 +
      +
      + +
      + \ No newline at end of file diff --git a/application/module/Mail/Mail.php b/application/module/Mail/Mail.php index 8736bffb..06288646 100644 --- a/application/module/Mail/Mail.php +++ b/application/module/Mail/Mail.php @@ -121,7 +121,12 @@ class Mail $this->subject = $subject; $this->body = $body; - $this->type = $row['type']; + if(isset($row['type'])) + { + $this->type = $row['type']; + }else{ + $this->type = "text"; + } }//加载模板 diff --git a/application/module/Users/Account.php b/application/module/Users/Account.php index 1e35480b..e5679992 100644 --- a/application/module/Users/Account.php +++ b/application/module/Users/Account.php @@ -22,9 +22,12 @@ class Account extends \Zend_Controller_Plugin_Abstract public $FieldRealname = "realname"; public $RoleMember = "member"; + public $getPwdEmailTemplate = "users-changepassword"; //找回密码的邮件模板名称 + public $PwdChangedEmailTemplate = "users-password-changed"; //密码修改后的邮件模板 private $db; protected $events = NULL; //事件 + private $config; /* 需要挂载的事件分别放在不同的listener中,将各种操作进行模块化细分 @@ -304,7 +307,7 @@ class Account extends \Zend_Controller_Plugin_Abstract return array('error'=>"此邮箱并未注册",'place'=>'email'); } - $salt = md5($email.'---'.$row['username']); + $salt = md5($email.'--'.time().'--'.$row['username']); $sql = "UPDATE {$this->memberTable} SET salt='$salt' WHERE id={$row['id']}"; $state = $this->db->exec($sql); @@ -314,15 +317,15 @@ class Account extends \Zend_Controller_Plugin_Abstract return array('error'=>"处理中出现错误,请重试",'place'=>'email'); } - $mail_template = "forgotpassword"; $mail_data = array( 'name'=>$row['realname'], - 'link'=> view::getHostLink().'/account/getpassword/salt/'.$salt + 'link'=> view::getHostLink().'/account/fetchpwd/?salt='.$salt, + 'site' => $this->config->title->site ); $mail = new Mail(); - $mail->loadTemplate($mail_template,$mail_data); + $mail->loadTemplate($this->getPwdEmailTemplate,$mail_data); $mail->addTo($email,$row['realname']); $mail->send(); @@ -358,12 +361,12 @@ class Account extends \Zend_Controller_Plugin_Abstract $sql = "UPDATE {$this->memberTable} SET password='".md5($data['password'])."',salt='' WHERE id={$row['id']}"; $this->db->exec($sql); - $mail_template = "getpassworded"; $mail_data = array( - 'name'=>$row['realname'], + 'name' => $row['realname'], + 'site' => $this->config->title->site ); $mail = new Mail(); - $mail->loadTemplate($mail_template,$mail_data); + $mail->loadTemplate($this->PwdChangedEmailTemplate,$mail_data); $mail->addTo($row['email'],$row['realname']); $mail->send(); diff --git a/application/module/Users/Operation/PwdOperate.php b/application/module/Users/Operation/PwdOperate.php index ae87513f..27d54184 100644 --- a/application/module/Users/Operation/PwdOperate.php +++ b/application/module/Users/Operation/PwdOperate.php @@ -58,6 +58,11 @@ class PwdOperate implements \Users\Event\PwdEvent { $data = $e->getParam('data'); + if(empty($data['salt'])) + { + return array('error'=>"密钥不正确,请重新申请","place"=>'salt'); + } + if(empty($data['username'])) { return array('error'=>"请输入用户名",'place'=>'username'); @@ -70,12 +75,12 @@ class PwdOperate implements \Users\Event\PwdEvent if(strlen($data['password']) < 6) { - return array('error'=>"密码长度太短,为了安全最少输入6位哦",'place'=>'password'); + return array('error'=>"密码长度太短,为了安全最少输入6位",'place'=>'password'); } if(strlen($data['password']) > 14) { - return array('error'=>"密码太长,亲您记得住吗?不要超过14位哦",'place'=>'password'); + return array('error'=>"密码太长,请不要超过14位",'place'=>'password'); } if(empty($data['confirm_password'])) From b54c72b565b7de776d3a0e70310e5123057a46fa Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Thu, 26 Dec 2013 07:27:27 +0000 Subject: [PATCH 085/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/default/controllers/AccountController.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/application/default/controllers/AccountController.php b/application/default/controllers/AccountController.php index fc35b8bb..264f86ab 100755 --- a/application/default/controllers/AccountController.php +++ b/application/default/controllers/AccountController.php @@ -383,11 +383,12 @@ class AccountController extends Zend_Controller_Action public function fetchpwdAction() { $salt = trim($this->_getParam('salt')); - + $submit = $this->_getParam('submit'); if(empty($salt)) { $captcha = new Captcha(); - if(!empty($this->_getParam('submit'))) + + if(!empty($submit)) { $email = trim($this->_request->getParam('email')); $captchaword = trim($this->_request->getParam('captcha')); From 9a78f04113f660b27ee4e17167dada6d51834155 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Thu, 26 Dec 2013 07:28:27 +0000 Subject: [PATCH 086/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E5=86=99=E6=B3=95=E5=85=BC=E5=AE=B9php5.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/default/controllers/AccountController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/default/controllers/AccountController.php b/application/default/controllers/AccountController.php index 264f86ab..72e52f23 100755 --- a/application/default/controllers/AccountController.php +++ b/application/default/controllers/AccountController.php @@ -420,7 +420,7 @@ class AccountController extends Zend_Controller_Action else{ $this->_helper->viewRenderer('account-resetpassword'); $this->view->salt = $salt; - if(!empty($this->_getParam('submit'))) + if(!empty($submit)) { $username = trim($this->_request->getParam('username')); $password = trim($this->_request->getParam('password')); From 1c6a36d63878c2ac15b0c2abef859ce7b58c8689 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Thu, 26 Dec 2013 07:59:00 +0000 Subject: [PATCH 087/173] =?UTF-8?q?=E5=8F=96=E6=B6=88=E9=BB=91=E6=B2=B3?= =?UTF-8?q?=E4=B8=93=E9=A2=98jiathis=E7=9A=84=E6=B3=A8=E9=87=8A=EF=BC=8C?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E9=87=8D=E5=A4=8D=E8=AE=BF=E9=97=AE=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=A1=B5=E9=9D=A2=E6=97=B6=E7=9A=84=E6=AD=BB=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BF=AE=E6=94=B9=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=E5=9B=BE=E7=89=87=E5=AD=98=E6=94=BE=E8=B7=AF?= =?UTF-8?q?=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/AccountController.php | 11 ++++------- application/default/views/scripts/heihe/view.phtml | 4 ++-- application/module/Helpers/Captcha.php | 12 +++++++++--- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/application/default/controllers/AccountController.php b/application/default/controllers/AccountController.php index 72e52f23..762f3597 100755 --- a/application/default/controllers/AccountController.php +++ b/application/default/controllers/AccountController.php @@ -301,20 +301,17 @@ class AccountController extends Zend_Controller_Action $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { - view::Post($this,"您已经登录,无需重复登录",-1); + view::Post($this,"您已经登录,无需重复登录","/index"); return true; } $tohref = $this->_request->getParam('href'); - if(($options['module']=="default" && $options['controller'] == "account" && $options['action'] == "login")) + if($_SERVER['REQUEST_URI'] !== "/account/login") { $this->view->href = $_SERVER['REQUEST_URI']; - } - - if($tohref == "/account/login") - { - $this->view->href = $tohref = "/"; + }else{ + $this->view->href = "/"; } if(!empty($tohref)) diff --git a/application/default/views/scripts/heihe/view.phtml b/application/default/views/scripts/heihe/view.phtml index ba55b71c..f5a5b84a 100755 --- a/application/default/views/scripts/heihe/view.phtml +++ b/application/default/views/scripts/heihe/view.phtml @@ -479,7 +479,7 @@ endforeach;
      -
      +
      @@ -554,4 +554,4 @@ var bound = {

      没有找到对应的元数据。

      - \ No newline at end of file + \ No newline at end of file diff --git a/application/module/Helpers/Captcha.php b/application/module/Helpers/Captcha.php index dc61b759..43a835b3 100644 --- a/application/module/Helpers/Captcha.php +++ b/application/module/Helpers/Captcha.php @@ -6,6 +6,7 @@ class Captcha extends \Zend_Controller_Plugin_Abstract public $captcha; private $sessionName = "captcha"; + private $imgDir = "images/captcha"; function __construct($db = NULL) { @@ -23,13 +24,18 @@ class Captcha extends \Zend_Controller_Plugin_Abstract 'dotNoiseLevel'=>2, 'lineNoiseLevel'=>1, 'timeout' => 300, - 'font' => '../data/fonts/ggbi.ttf', - 'imgDir' => 'vdimg/', - 'imgUrl' => '/vdimg', + 'font' => '../data/fonts/ggbi.ttf', + 'imgDir' => $this->imgDir, + 'imgUrl' => '/images/captcha', )); } public function setCaptcha(){ + if(!is_dir($this->imgDir)) + { + mkdir($this->imgDir); + } + $this->captcha->generate(); $_SESSION[$this->sessionName] = $this->captcha->getWord(); $url = $this->captcha->getImgUrl() From a1f43ad5749f6e3f2873fa80aa7184e60bc1245d Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Fri, 27 Dec 2013 02:06:40 +0000 Subject: [PATCH 088/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=90=8D=E5=88=A4=E6=96=AD=E7=9A=84=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/module/Users/Operation/LoginOperate.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/module/Users/Operation/LoginOperate.php b/application/module/Users/Operation/LoginOperate.php index a61833f7..336f38f8 100644 --- a/application/module/Users/Operation/LoginOperate.php +++ b/application/module/Users/Operation/LoginOperate.php @@ -45,9 +45,9 @@ class LoginOperate implements \Users\Event\LoginEvent if(!empty($data['username'])) { - if(!preg_match("/^[a-zA-Z][a-zA-Z0-9_]{2,15}$/",$data['username'])) + if(mb_strlen($data['username'])<2) { - return array('error'=>"用户名应当以字母开头,由字母数字和下划线组成,并且长度在3到25个字符之间",'place'=>'username'); + return array('error'=>"用户名长度应该大于两个字符",'place'=>'username'); } } From 0288b30ab6c740e09aa363b4af7700658b74d0d4 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Fri, 27 Dec 2013 02:39:18 +0000 Subject: [PATCH 089/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9AccountController?= =?UTF-8?q?=E4=B8=AD=E8=BF=94=E5=9B=9E=E6=B6=88=E6=81=AF=E7=9A=84bug?= =?UTF-8?q?=EF=BC=8C=E6=8F=90=E4=BA=A4AclManager=E4=B8=AD=E6=9C=89?= =?UTF-8?q?=E5=85=B3=E8=87=AA=E5=8A=A8=E7=99=BB=E5=BD=95=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=EF=BC=8C=E4=BF=AE=E6=94=B9member=E7=B1=BB=E4=B8=AD?= =?UTF-8?q?=E5=85=B3=E9=94=AE=E5=AD=97=E6=94=AF=E6=8C=81php5.5+?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/AccountController.php | 4 +- .../default/views/scripts/account/login.phtml | 17 +------ .../models/CustomControllerAclManager.php | 44 +++++++++---------- application/module/Users/Member.php | 6 +-- 4 files changed, 27 insertions(+), 44 deletions(-) diff --git a/application/default/controllers/AccountController.php b/application/default/controllers/AccountController.php index 762f3597..d5cf52af 100755 --- a/application/default/controllers/AccountController.php +++ b/application/default/controllers/AccountController.php @@ -350,9 +350,11 @@ class AccountController extends Zend_Controller_Action view::Post($this,"登录成功,正在跳转",$tohref); return true; + }else{ + $this->view->captcha = $captcha->setCaptcha(); } - $this->view->captcha = $captcha->setCaptcha(); + } public function captchaAction() diff --git a/application/default/views/scripts/account/login.phtml b/application/default/views/scripts/account/login.phtml index 42874937..ac421001 100755 --- a/application/default/views/scripts/account/login.phtml +++ b/application/default/views/scripts/account/login.phtml @@ -6,21 +6,6 @@ $this->breadcrumb('用户登录'); $this->breadcrumb()->setSeparator(' > '); ?> -
      error)) { ?> @@ -29,7 +14,7 @@
      diff --git a/application/models/CustomControllerAclManager.php b/application/models/CustomControllerAclManager.php index 60330350..0bee8403 100755 --- a/application/models/CustomControllerAclManager.php +++ b/application/models/CustomControllerAclManager.php @@ -1,4 +1,8 @@ auth->hasIdentity()) { - $mb = new member(); - $mb->db=$this->db; - if($mb->checkcookie()) + $member = new Member(); + + if($member->checkcookie()) { - $auth = Zend_Auth::getInstance(); - $authAdapter = new Zend_Auth_Adapter_DbTable($this->db); - $authAdapter->setTableName('users') - ->setIdentityColumn('username') - ->setCredentialColumn('password'); - $authAdapter->setIdentity($mb->user)->setCredential($mb->srpwd); - $result = $auth->authenticate($authAdapter); - if ($result->isValid()) { - $data = $authAdapter->getResultRowObject(null,'password'); - //头像 - include_once("Avatar.php"); - $avatar = new Avatar(); - $data->avatar = $avatar->Get($data->email,40); - - //组ID - include_once("Users.php"); - $usr = new Users($this->db); - $data->gid = $usr->getGroup($data->id); - - $auth->getStorage()->write($data); - $this->db->query("update users set ts_last_login=now() where username=?",array($mb->user)); + $data = array( + 'username' => $member->user, + 'password' => $member->srpwd + ); + + $account = new Account(); + $status = $account->storeLogin($data,false); + + if(isset($status['error'])) + { + $auth = Zend_Auth::getInstance(); + $auth->clearIdentity(); + Member::flushcookie(); } } } diff --git a/application/module/Users/Member.php b/application/module/Users/Member.php index fcb2bce2..c7ad012c 100644 --- a/application/module/Users/Member.php +++ b/application/module/Users/Member.php @@ -3,9 +3,9 @@ namespace Users; class Member { - var $ck='DCC3ER4T8L2EFX94OPDF'; - var $db; //传入PDO对象 - var $mid; //会员ID + public $ck='DCC3ER4T8L2EFX94OPDF'; + public $db; //传入PDO对象 + public $mid; //会员ID public $scr; //cookie 安全码 $_COOKIE['scr'] public $user;//cookie User $_COOKIE['user'] From 1822a361cfe9e69f8795fe5629478a45a4a3cf5b Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Fri, 27 Dec 2013 04:14:03 +0000 Subject: [PATCH 090/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/AccountController.php | 79 ++++----- .../views/scripts/account/register.phtml | 162 ++++++++++++++++-- application/module/Users/Account.php | 25 ++- .../Users/Operation/RegisterOperate.php | 41 ++--- 4 files changed, 207 insertions(+), 100 deletions(-) diff --git a/application/default/controllers/AccountController.php b/application/default/controllers/AccountController.php index d5cf52af..a2fb8f50 100755 --- a/application/default/controllers/AccountController.php +++ b/application/default/controllers/AccountController.php @@ -66,7 +66,7 @@ class AccountController extends Zend_Controller_Action "国家级国家自然科学基金" => "国家级国家自然科学基金", "国际合作项目"=>"国际合作项目", "省部级项目" => "省部级项目", - "其他项目工程" => "其他项目工程" + "其他项目工程" => "其他项目工程", ); $submit = $this->_getParam('submit'); @@ -250,44 +250,31 @@ class AccountController extends Zend_Controller_Action function registerAction() { - $form = new RegisterForm(); - $this->view->form = $form; - - if ($this->_request->isPost()) { - $formData = $this->_request->getPost(); - if ($form->isValid($formData)) { - $ut = new UsersTable(); - $u = $ut->createRow(); - $u->username = $form->getValue('username'); - $u->password = $form->getValue('password'); - $u->email=$form->getValue('email'); - if ($form->getValue('realname')) $u->realname=$form->getValue('realname'); - if ($form->getValue('phone')) $u->phone=$form->getValue('phone'); - if ($form->getValue('address')) $u->address=$form->getValue('address'); - if ($form->getValue('unit')) $u->unit=$form->getValue('unit'); - if ($form->getValue('project')) $u->project=$form->getValue('project'); - if ($u->save()) { - - //注册邮件 - $mail_template = "member-register"; - $mail_data = array( - 'name'=>$formData['username'], - ); - - $mail = new Mail(); - - $mail->loadTemplate($mail_template,$mail_data); - $mail->addTo($formData['email'],$formData['username']); - $mail->send(); - - //自动登录系统 - $this->login($formData['username'],$formData['password']); - $this->_redirect('/'); - } - } else { - $form->populate($formData); - } - } + $order = new \Order\Order(); + + $this->view->projectType = array_merge(array("无"=>""),$order->projectType); + + $submit = $this->_getParam("submit"); + + if(!empty($submit)) + { + $account = new Account(); + $this->view->data = $data = $account->getRegisterParam(); + $status = $account->register($data); + + if(isset($status['error'])) + { + $this->view->error = $status['error']; + if(isset($status['place'])) + { + $this->view->place = $status['place']; + } + }else{ + view::Post($this,"注册成功!","/"); + return true; + } + } + } function loginAction() @@ -328,6 +315,13 @@ class AccountController extends Zend_Controller_Action $password = trim($this->_request->getParam('password')); $captchaword = trim($this->_request->getParam('captcha')); + if($captcha->isValid($captchaword) !== true) + { + $this->view->error = "验证码错误"; + $this->view->captcha = $captcha->setCaptcha(); + return true; + } + $account = new Account(); $status = $account->login(array( 'username' => $username, @@ -341,13 +335,6 @@ class AccountController extends Zend_Controller_Action return true; } - if(!$captcha->isValid($captchaword)) - { - $this->view->error = "验证码错误"; - $this->view->captcha = $captcha->setCaptcha(); - return true; - } - view::Post($this,"登录成功,正在跳转",$tohref); return true; }else{ diff --git a/application/default/views/scripts/account/register.phtml b/application/default/views/scripts/account/register.phtml index cf161a9b..7d6bded9 100755 --- a/application/default/views/scripts/account/register.phtml +++ b/application/default/views/scripts/account/register.phtml @@ -1,19 +1,143 @@ -headTitle($this->config->title->site); - $this->headTitle('用户注册'); - $this->headTitle()->setSeparator(' - '); - $this->headLink()->appendStylesheet('/css/register.css'); - $this->breadcrumb('首页'); - $this->breadcrumb('用户注册'); - $this->breadcrumb()->setSeparator(' > '); -?> -
      -
      -  确认服务条款   -    -  填写基本信息   -    -  注册完成 - form;?> -
      -
      \ No newline at end of file +headTitle($this->config->title->site); + $this->headTitle('用户注册'); + $this->headTitle()->setSeparator(' - '); + $this->headLink()->appendStylesheet('/css/register.css'); + $this->breadcrumb('首页'); + $this->breadcrumb('用户注册'); + $this->breadcrumb()->setSeparator(' > '); +?> +
      + + error)) { ?> + + + + +
      + +
      + " name="username" /> + (必填) +
      +
      +
      + +
      + + (必填) +
      +
      +
      + +
      + + (必填) +
      +
      +
      + +
      + " name="email" /> + (必填) +
      +
      +
      + +
      + " name="realname" /> +
      +
      +
      + +
      + " name="phone" /> +
      +
      +
      + +
      + " name="unit" class="input-block-level" /> +
      +
      +
      + +
      + " name="address" class="input-block-level" /> +
      +
      +
      + +
      + " name="project_id" /> +
      +
      +
      + +
      + " name="project_leader" /> +
      +
      +
      + +
      + +
      +
      +
      + +
      + " name="project_title" class="input-block-level" /> +
      +
      +
      + +
      + " name="project" class="input-block-level" /> +
      +
      +
      + + href)){?> + + + + 忘记密码? +
      + +
      +place)){ ?> + + \ No newline at end of file diff --git a/application/module/Users/Account.php b/application/module/Users/Account.php index e5679992..0f94658e 100644 --- a/application/module/Users/Account.php +++ b/application/module/Users/Account.php @@ -216,14 +216,27 @@ class Account extends \Zend_Controller_Plugin_Abstract } //注册信息参数 - public function getParam(\Zend_Controller_Request_Abstract $request) + public function getRegisterParam(\Zend_Controller_Request_Abstract $request = NULL) { + if(empty($request)) + { + $request = new \Zend_Controller_Request_Http(); + } $data = array( - 'username'=>$request->getParam('username'), - 'password'=>$request->getParam('password'), - 'confirm_password'=>$request->getParam('confirm_password'), - 'email'=>$request->getParam('email'), - 'realname'=>$request->getParam('realname') + 'username'=>trim($request->getParam('username')), + 'password'=>trim($request->getParam('password')), + 'confirm_password'=>trim($request->getParam('confirm_password')), + 'email' => trim($request->getParam('email')), + 'realname' => trim($request->getParam('realname')), + 'phone' => trim($request->getParam('phone')), + 'unit' => trim($request->getParam('unit')), + 'address' => trim($request->getParam('address')), + 'project' => trim($request->getParam('project')), + 'project_id' => trim($request->getParam('project_id')), + 'project_type' => trim($request->getParam('project_type')), + 'project_title' => trim($request->getParam('project_title')), + 'project_leader'=> trim($request->getParam('project_leader')), + 'postcode' => trim($request->getParam('postcode')), ); return $data; } diff --git a/application/module/Users/Operation/RegisterOperate.php b/application/module/Users/Operation/RegisterOperate.php index 9d3c006a..8c98724a 100644 --- a/application/module/Users/Operation/RegisterOperate.php +++ b/application/module/Users/Operation/RegisterOperate.php @@ -7,7 +7,7 @@ use \Helpers\View as view; class RegisterOperate implements \Users\Event\RegisterEvent { private $db; //传入PDO对象 - public $tbl_member = "tbl_member"; + public $tbl_member = "users"; public $FieldUsername = "username"; public $FieldPasword = "password"; public $FieldLastlogin = "ts_last_login"; @@ -45,9 +45,9 @@ class RegisterOperate implements \Users\Event\RegisterEvent if(!empty($data['username'])) { - if(!preg_match("/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/",$data['username'])) + if(!preg_match("/^[a-zA-Z\xa0-\xff_][0-9a-zA-Z\xa0-\xff_]{2,25}$/",$data['username'])) { - return array('error'=>"用户名应当以字母开头,由字母数字和下划线组成,并且长度在5到16个字符之间",'place'=>'username'); + return array('error'=>"用户名只能包含字母汉字数字和下划线,并且长度在2到26个字符之间",'place'=>'username'); } } @@ -86,14 +86,12 @@ class RegisterOperate implements \Users\Event\RegisterEvent return array('error'=>"请输入正确的电子邮件,推荐使用QQ邮箱和Gmail邮箱",'place'=>'email'); } - if(empty($data['realname'])) + if(!empty($data['realname'])) { - return array('error'=>"请输入姓名",'place'=>'realname'); - } - - if(mb_strlen($data['realname'],"UTF-8")>10 ) - { - return array('error'=>"真实姓名请不要超过10个字",'place'=>'realname'); + if(mb_strlen($data['realname'],"UTF-8")>10 ) + { + return array('error'=>"真实姓名请不要超过10个字",'place'=>'realname'); + } } return true; @@ -118,7 +116,7 @@ class RegisterOperate implements \Users\Event\RegisterEvent { if($row[$this->FieldUsername] == $data['username']) { - return array('error'=>'您的用户名已经注册过账号,您是否忘记了密码?','place'=>'username'); + return array('error'=>'您的用户名已经注册过账号,您是否忘记了密码?','place'=>'username'); } if($row[$this->FieldEmail] == $data['email']) @@ -148,10 +146,9 @@ class RegisterOperate implements \Users\Event\RegisterEvent return false; } - $mail_template = "register"; + $mail_template = "member-register"; $mail_data = array( 'name'=>$data['realname'], - 'content'=>$this->getMailContent() ); $mail = new Mail(); @@ -166,25 +163,11 @@ class RegisterOperate implements \Users\Event\RegisterEvent //邮件内容 public function getMailContent() { - $sql = "SELECT v.id,v.title,v.thumb,v.status,v.content,m.realname,m.username FROM tbl_voice v - LEFT JOIN tbl_member m ON v.userid = m.id - WHERE v.status > 0 - ORDER BY v.id DESC - LIMIT 5"; - $rs = $this->db->query($sql); - $latest = $rs->fetchAll(); + $content = ""; - foreach($latest as $k=>$v) - { - if($v['thumb'] != '[]') - { - $thumb = json_decode($v['thumb'],true); - $text = mb_strlen($v['content'],"UTF-8") > 100 ? mb_substr($v['content'],0,100,"UTF-8") : $v['content']; - $content .= '

      '.$v['title']. ' / ' .$v['realname'].'
      '.$text.'
      查看播放

      '; - } - } + return $content; }//getMailContent(); From dd22a0fe70eaafbdef594c7f8a864fe85c2ddaae Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Fri, 27 Dec 2013 05:54:27 +0000 Subject: [PATCH 091/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/default/controllers/AccountController.php | 6 +++--- application/default/views/scripts/account/login.phtml | 4 +--- application/default/views/scripts/account/register.phtml | 4 +--- application/module/Helpers/View.php | 2 +- application/module/Users/Operation/RegisterOperate.php | 2 +- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/application/default/controllers/AccountController.php b/application/default/controllers/AccountController.php index a2fb8f50..10864530 100755 --- a/application/default/controllers/AccountController.php +++ b/application/default/controllers/AccountController.php @@ -264,7 +264,7 @@ class AccountController extends Zend_Controller_Action if(isset($status['error'])) { - $this->view->error = $status['error']; + $this->view->error = view::Error($status['error']); if(isset($status['place'])) { $this->view->place = $status['place']; @@ -317,7 +317,7 @@ class AccountController extends Zend_Controller_Action if($captcha->isValid($captchaword) !== true) { - $this->view->error = "验证码错误"; + $this->view->error = view::Error("验证码错误"); $this->view->captcha = $captcha->setCaptcha(); return true; } @@ -330,7 +330,7 @@ class AccountController extends Zend_Controller_Action if(isset($status['error'])) { - $this->view->error = $status; + $this->view->error = view::Error($status['error']); $this->view->captcha = $captcha->setCaptcha(); return true; } diff --git a/application/default/views/scripts/account/login.phtml b/application/default/views/scripts/account/login.phtml index ac421001..c4e9aa6f 100755 --- a/application/default/views/scripts/account/login.phtml +++ b/application/default/views/scripts/account/login.phtml @@ -13,9 +13,7 @@ 请输入用户名和密码登录
      - + error ?>
      diff --git a/application/default/views/scripts/account/register.phtml b/application/default/views/scripts/account/register.phtml index 7d6bded9..10c57682 100755 --- a/application/default/views/scripts/account/register.phtml +++ b/application/default/views/scripts/account/register.phtml @@ -14,9 +14,7 @@ 请输入您的基本信息进行注册
      - + error ?>
      diff --git a/application/module/Helpers/View.php b/application/module/Helpers/View.php index 783ba487..732468cb 100644 --- a/application/module/Helpers/View.php +++ b/application/module/Helpers/View.php @@ -55,7 +55,7 @@ class View extends \Zend_Controller_Plugin_Abstract $html = '
      '."\r\n"; $html.= '×'."\r\n"; if(!is_array($content)) { - $html.= '

      '.$content.'

      '."\r\n"; + $html.= ''.$content.''."\r\n"; }else{ $html.= '
        '."\r\n"; foreach($content as $v) { diff --git a/application/module/Users/Operation/RegisterOperate.php b/application/module/Users/Operation/RegisterOperate.php index 8c98724a..b9985674 100644 --- a/application/module/Users/Operation/RegisterOperate.php +++ b/application/module/Users/Operation/RegisterOperate.php @@ -83,7 +83,7 @@ class RegisterOperate implements \Users\Event\RegisterEvent if (!preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$data['email'])) { - return array('error'=>"请输入正确的电子邮件,推荐使用QQ邮箱和Gmail邮箱",'place'=>'email'); + return array('error'=>"请输入正确的电子邮件地址",'place'=>'email'); } if(!empty($data['realname'])) From f6b1acc2730fcdbc08336bf70b10b4fd785f02dd Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Fri, 27 Dec 2013 06:21:12 +0000 Subject: [PATCH 092/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=90=8D=E9=95=BF=E5=BA=A6=E5=92=8C=E8=A7=84=E5=88=99=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E7=9A=84=E6=AD=A3=E5=88=99=E8=A1=A8=E8=BE=BE=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/module/Users/Operation/RegisterOperate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/module/Users/Operation/RegisterOperate.php b/application/module/Users/Operation/RegisterOperate.php index b9985674..0c02b560 100644 --- a/application/module/Users/Operation/RegisterOperate.php +++ b/application/module/Users/Operation/RegisterOperate.php @@ -45,7 +45,7 @@ class RegisterOperate implements \Users\Event\RegisterEvent if(!empty($data['username'])) { - if(!preg_match("/^[a-zA-Z\xa0-\xff_][0-9a-zA-Z\xa0-\xff_]{2,25}$/",$data['username'])) + if(!preg_match("/[0-9a-zA-Z\xa0-\xff_]{2,25}/",$data['username'])) { return array('error'=>"用户名只能包含字母汉字数字和下划线,并且长度在2到26个字符之间",'place'=>'username'); } From e2f2b2ae71eae75f5ac47b4e36b360ec153fe9b3 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Fri, 3 Jan 2014 02:22:45 +0000 Subject: [PATCH 093/173] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E8=A3=81?= =?UTF-8?q?=E5=9B=BE=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/module/Files/Thumbnail.php | 363 +++++++++++++++---------- 1 file changed, 217 insertions(+), 146 deletions(-) diff --git a/application/module/Files/Thumbnail.php b/application/module/Files/Thumbnail.php index 6d63fa79..9a98fae7 100644 --- a/application/module/Files/Thumbnail.php +++ b/application/module/Files/Thumbnail.php @@ -9,153 +9,224 @@ namespace Files; */ class Thumbnail { - private $maxWidth; - private $maxHeight; - private $scale; - private $inflate; - private $types; - private $imgLoaders; - private $imgCreators; - private $source; - private $sourceWidth; - private $sourceHeight; - private $sourceMime; - private $thumb; - private $thumbWidth; - private $thumbHeight; - - public function __construct($maxWidth, $maxHeight, $scale = true, $inflate = false) { - $this->maxWidth = $maxWidth; - $this->maxHeight = $maxHeight; - $this->scale = $scale; - $this->inflate = $inflate; - $this->types = array( - 'image/jpeg', - 'image/png', - 'image/gif' - ); - //加载MIME类型图像的函数名称 - $this->imgLoaders = array( - 'image/jpeg' => 'imagecreatefromjpeg', - 'image/png' => 'imagecreatefrompng', - 'image/gif' => 'imagecreatefromgif' - ); - //储存创建MIME类型图片的函数名称 - $this->imgCreators = array( - 'image/jpeg' => 'imagejpeg', - 'image/png' => 'imagepng', - 'image/gif' => 'imagegif' - ); - } - /** - * 文件方式加载图片 - * @param string $image 源图片 - * @return bool - */ - public function loadFile($image){ - if(!$dims = @getimagesize($image)){ - trigger_error("源图片不存在"); - } - if(in_array($dims['mime'], $this->types)){ - $loader = $this->imgLoaders[$dims['mime']]; - $this->source = $loader($image); - if($dims['mime'] == 'image/png' || $dims['mime'] == 'image/gif'){ - imagesavealpha($this->source, true); - } - $this->sourceWidth = $dims[0]; - $this->sourceHeight = $dims[1]; - $this->sourceMime = $dims['mime']; - $this->initThumb(); - return TRUE; - }else{ - trigger_error('不支持'.$dims['mime']."图片类型"); - } - } - /** - * 字符串方式加载图片 - * @param string $image 字符串 - * @param string $mime 图片类型 - * @return type - */ - public function loadData($image,$mime){ - if(in_array($mime, $this->types)){ - if($this->source = @imagecreatefromstring($image)){ - $this->sourceWidth = imagesx($this->source); - $this->sourceHeight = imagesy($this->source); - $this->sourceMime = $mime; - $this->initThumb(); - return TRUE; - }else{ - trigger_error("不能从字符串加载图片"); - } - }else{ - trigger_error("不支持".$mime."图片格式"); - } - } - /** - * 生成缩略图 - * @param string $file 文件名。如果不为空则储存为文件,否则直接输出到浏览器 - */ - public function buildThumb($file = NULL){ - $creator = $this->imgCreators[$this->sourceMime]; - if(isset($file) && $this->thumb !== NULL){ - return $creator($this->thumb,$file); - }else{ - return false; - } - } - /** - * 处理缩放 - */ - public function initThumb(){ - if($this->scale){ - if($this->sourceWidth > $this->sourceHeight){ - $this->thumbWidth = $this->maxWidth; - $this->thumbHeight = floor($this->sourceHeight*($this->maxWidth/$this->sourceWidth)); - }elseif($this->sourceWidth < $this->sourceHeight){ - $this->thumbHeight = $this->maxHeight; - $this->thumbWidth = floor($this->sourceWidth*($this->maxHeight/$this->sourceHeight)); - }else{ - $this->thumbWidth = $this->maxWidth; - $this->thumbHeight = $this->maxHeight; - } - } - - if($this->sourceWidth <= $this->maxWidth && $this->sourceHeight <= $this->maxHeight && $this->inflate == FALSE){ - $this->thumb = NULL; - }else{ - $this->thumb = imagecreatetruecolor($this->thumbWidth, $this->thumbHeight); - if($this->sourceMime == 'image/png' || $this->sourceMime == 'image/gif') - { - - imagealphablending($this->thumb, true); - imagesavealpha($this->thumb, true); - if($this->sourceMime == 'image/gif') - { - $bgcolor=imagecolorallocate($this->thumb,0,0,0); - $transparent = imagecolortransparent($this->thumb,$bgcolor) ; - } - if($this->sourceMime == 'image/png') - { - $transparent = imagecolorallocatealpha($this->thumb, 0, 0, 0, 127); - } - imagefill($this->thumb, 0, 0, $transparent); + private $maxWidth; + private $maxHeight; + private $scale; + private $inflate; + private $types; + private $imgLoaders; + private $imgCreators; + private $source; + private $sourceWidth; + private $sourceHeight; + private $sourceMime; + private $thumb; + private $thumbWidth; + private $thumbHeight; + + public function __construct($maxWidth, $maxHeight, $scale = true, $inflate = false) { + $this->maxWidth = $maxWidth; + $this->maxHeight = $maxHeight; + $this->scale = $scale; + $this->inflate = $inflate; + $this->types = array( + 'image/jpeg', + 'image/png', + 'image/gif' + ); + //加载MIME类型图像的函数名称 + $this->imgLoaders = array( + 'image/jpeg' => 'imagecreatefromjpeg', + 'image/png' => 'imagecreatefrompng', + 'image/gif' => 'imagecreatefromgif' + ); + //储存创建MIME类型图片的函数名称 + $this->imgCreators = array( + 'image/jpeg' => 'imagejpeg', + 'image/png' => 'imagepng', + 'image/gif' => 'imagegif' + ); + } + + /** + * 文件方式加载图片 + * @param string $image 源图片 + * @return bool + */ + public function loadFile($image){ + if(!$dims = @getimagesize($image)){ + trigger_error("源图片不存在"); + } + if(in_array($dims['mime'], $this->types)){ + $loader = $this->imgLoaders[$dims['mime']]; + $this->source = $loader($image); + if($dims['mime'] == 'image/png' || $dims['mime'] == 'image/gif'){ + imagesavealpha($this->source, true); } - imagecopyresampled($this->thumb, $this->source, 0, 0, 0, 0, $this->thumbWidth, $this->thumbHeight, $this->sourceWidth, $this->sourceHeight); - } - } - - public function getMine(){ - return $this->sourceMime; - } - - public function getThumbWidth(){ - return $this->thumbWidth; - } - - public function getThumbHeight(){ - return $this->thumbHeight; - } + $this->sourceWidth = $dims[0]; + $this->sourceHeight = $dims[1]; + $this->sourceMime = $dims['mime']; + $this->initThumb(); + return TRUE; + }else{ + trigger_error('不支持'.$dims['mime']."图片类型"); + } + } + + /** + * 字符串方式加载图片 + * @param string $image 字符串 + * @param string $mime 图片类型 + * @return type + */ + public function loadData($image,$mime){ + if(in_array($mime, $this->types)){ + if($this->source = @imagecreatefromstring($image)){ + $this->sourceWidth = imagesx($this->source); + $this->sourceHeight = imagesy($this->source); + $this->sourceMime = $mime; + $this->initThumb(); + return TRUE; + }else{ + trigger_error("不能从字符串加载图片"); + } + }else{ + trigger_error("不支持".$mime."图片格式"); + } + } + + /** + * 生成缩略图 + * @param string $file 文件名。如果不为空则储存为文件,否则直接输出到浏览器 + */ + public function buildThumb($file = NULL){ + $creator = $this->imgCreators[$this->sourceMime]; + if(isset($file) && $this->thumb !== NULL){ + return $creator($this->thumb,$file); + }else{ + return false; + } + } + + /** + * 处理缩放 + */ + public function initThumb(){ + if($this->scale){ + if($this->sourceWidth > $this->sourceHeight){ + $this->thumbWidth = $this->maxWidth; + $this->thumbHeight = floor($this->sourceHeight*($this->maxWidth/$this->sourceWidth)); + }elseif($this->sourceWidth < $this->sourceHeight){ + $this->thumbHeight = $this->maxHeight; + $this->thumbWidth = floor($this->sourceWidth*($this->maxHeight/$this->sourceHeight)); + }else{ + $this->thumbWidth = $this->maxWidth; + $this->thumbHeight = $this->maxHeight; + } + } + + if($this->sourceWidth <= $this->maxWidth && $this->sourceHeight <= $this->maxHeight && $this->inflate == FALSE){ + $this->thumb = NULL; + }else{ + $this->thumb = imagecreatetruecolor($this->thumbWidth, $this->thumbHeight); + if($this->sourceMime == 'image/png' || $this->sourceMime == 'image/gif') + { + + imagealphablending($this->thumb, true); + imagesavealpha($this->thumb, true); + if($this->sourceMime == 'image/gif') + { + $bgcolor=imagecolorallocate($this->thumb,0,0,0); + $transparent = imagecolortransparent($this->thumb,$bgcolor) ; + } + if($this->sourceMime == 'image/png') + { + $transparent = imagecolorallocatealpha($this->thumb, 0, 0, 0, 127); + } + imagefill($this->thumb, 0, 0, $transparent); + } + imagecopyresampled($this->thumb, $this->source, 0, 0, 0, 0, $this->thumbWidth, $this->thumbHeight, $this->sourceWidth, $this->sourceHeight); + } + } + + public function getMine(){ + return $this->sourceMime; + } + + public function getThumbWidth(){ + return $this->thumbWidth; + } + + public function getThumbHeight(){ + return $this->thumbHeight; + } + + static function cut($source_path, $target_width, $target_height){ + $source_info = getimagesize($source_path); + $source_width = $source_info[0]; + $source_height = $source_info[1]; + $source_mime = $source_info['mime']; + $source_ratio = $source_height / $source_width; + $target_ratio = $target_height / $target_width; + + // 源图过高 + if ($source_ratio > $target_ratio) + { + $cropped_width = $source_width; + $cropped_height = $source_width * $target_ratio; + $source_x = 0; + $source_y = ($source_height - $cropped_height) / 2; + } + // 源图过宽 + elseif ($source_ratio < $target_ratio) + { + $cropped_width = $source_height / $target_ratio; + $cropped_height = $source_height; + $source_x = ($source_width - $cropped_width) / 2; + $source_y = 0; + } + // 源图适中 + else + { + $cropped_width = $source_width; + $cropped_height = $source_height; + $source_x = 0; + $source_y = 0; + } + + switch ($source_mime) + { + case 'image/gif': + $source_image = imagecreatefromgif($source_path); + break; + + case 'image/jpeg': + $source_image = imagecreatefromjpeg($source_path); + break; + + case 'image/png': + $source_image = imagecreatefrompng($source_path); + break; + + default: + return false; + break; + } + + $target_image = imagecreatetruecolor($target_width, $target_height); + $cropped_image = imagecreatetruecolor($cropped_width, $cropped_height); + + // 裁剪 + imagecopy($cropped_image, $source_image, 0, 0, $source_x, $source_y, $cropped_width, $cropped_height); + // 缩放 + imagecopyresampled($target_image, $cropped_image, 0, 0, 0, 0, $target_width, $target_height, $cropped_width, $cropped_height); + + header('Content-Type: image/jpeg'); + imagejpeg($target_image); + imagedestroy($source_image); + imagedestroy($target_image); + imagedestroy($cropped_image); + }//cute } From a6efab68c93e246c93d30d83b3207fb5bafeae6f Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Fri, 3 Jan 2014 06:19:04 +0000 Subject: [PATCH 094/173] =?UTF-8?q?=E4=B8=BAwsn=E6=95=B0=E6=8D=AE=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E6=97=B6=E9=97=B4=E8=8C=83=E5=9B=B4=E7=9A=84=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E5=A6=82=E6=9E=9C=E6=98=AF=E5=A4=9A=E4=B8=AA?= =?UTF-8?q?=E7=82=B9=E7=9A=84=E8=AF=9D=E5=8F=AF=E4=BB=A5=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=89=80=E6=9C=89=E5=8F=98=E9=87=8F=E7=9A=84=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/js/lib/custom/models/dataservice.js | 65 +++++++++++++++++++--- 1 file changed, 56 insertions(+), 9 deletions(-) diff --git a/htdocs/js/lib/custom/models/dataservice.js b/htdocs/js/lib/custom/models/dataservice.js index e7443602..3055af00 100644 --- a/htdocs/js/lib/custom/models/dataservice.js +++ b/htdocs/js/lib/custom/models/dataservice.js @@ -168,6 +168,8 @@ westdc.dataservice.wsn = { this.selects = ""; this.uls = new Array(); + this.count = 0; + this.first = 0; for(i in data.data) { this.input = new Array(); @@ -185,12 +187,32 @@ westdc.dataservice.wsn = { + '' + '
      '; this.uls.push('

      观测点:'+data.data[i].name+'

      可下载的变量: '+ this.input.join("") + this.timemap + '
      '); + + this.count++; + if(this.count == 1) + { + this.first = i; + } + } this.selects = this.uls.join(""); + if(this.count > 1) + { + this.allcontrol = '
      ' + + '
      为所有数据选择时间范围(如果某些数据的时间超出范围请单独再次修改):
      ' + + ' - ' + + '' + + '

      '; + }else{ + this.allcontrol = ""; + } + this.HTML = '
      ' - + '
      查看详细 接收 - 退回 + 退回 上传申请表 重置申请表
      +
      - - - - - - - - + + + + + + + + paginator as $item): ?> - + - - + + @@ -78,6 +84,64 @@ + + + \ No newline at end of file diff --git a/application/default/views/scripts/haihe/index.phtml b/application/default/views/scripts/haihe/index.phtml new file mode 100644 index 00000000..47590f84 --- /dev/null +++ b/application/default/views/scripts/haihe/index.phtml @@ -0,0 +1,18 @@ +headTitle($this->config->title->site); +$this->headTitle($this->config->title->data); +$this->headTitle()->setSeparator(' - '); +$this->headLink()->appendStylesheet('/css/water.css'); +$this->nav[] = array('link'=>"/haihe",'title'=>'海河流域观测数据集'); +?> +render('breadcrumbs.phtml'); ?> +
      +
      +
      +

      info['title'])) echo $this->info['title']; ?>

      +
      姓名单位地址邮编用途数据清单申请时间操作姓名单位地址邮编用途数据清单申请时间操作
      page; ?>">编辑 | 删除 | PDF | 详细 | - 重新通过 + 重新通过 | + 上传签字申请表 + + | 查看签字申请表 +
      + +
      info['body'])) echo $this->info['body'];?>
      +
    +
    +
    diff --git a/application/default/views/scripts/haihe/view.phtml b/application/default/views/scripts/haihe/view.phtml new file mode 100755 index 00000000..8ae014c5 --- /dev/null +++ b/application/default/views/scripts/haihe/view.phtml @@ -0,0 +1,577 @@ +headTitle($this->config->title->site); + $this->headTitle($this->config->title->data); + $this->headTitle($this->metadata->title); + $this->headTitle()->setSeparator(' - '); + $this->breadcrumb('首页'); + $this->breadcrumb(''.$this->config->title->data.''); + $this->breadcrumb('查看元数据'); + $this->breadcrumb()->setSeparator(' > '); + $this->theme->AppendPlus($this,'google_map_v3'); + $this->theme->AppendPlus($this,'colorbox'); + if(!empty($this->dataService)) { + $this->theme->AppendModel($this,"dataservice"); + } +?> + +render('breadcrumbs.phtml'); ?> +metadata;if ($md):?> +

    escape($md->title); +if ($md->title_en) echo '
    '.$this->escape($md->title_en);?> +

    +
    +
    +
    +
    + +

    +

    ',$md->description);?> +

    +
    +
    + mcitation) : ?> +
    +

    本数据要求的多篇文献引用

    +
      + mcitation as $ref) : + echo '
    1. '.$ref->reference; + echo '查看'; + if (empty($ref->link)) + { + if(!empty($ref->attid)) + echo '下载'; + }else{ + echo '下载'; + } + echo "
    2. "; + endforeach; + ?> +
    + + citation) : ?> +
    +

    本数据引用方式数据引用帮助

    +

    datadoi) || !strpos($md->citation,$md->datadoi)) : ?>文章的引用 + escape($md->citation);if (strpos($md->citation,$md->datadoi)) : ?> + (下载引用:RIS格式 | RIS英文格式 | Bibtex格式 | Bibtex英文格式) + +

    + datadoi) && !strpos($md->citation,$md->datadoi)) : ?> +

    数据的引用authors,1,-1).'. '.$md->title.'. '.$md->publisher.', '.(empty($md->ts_published)?$md->publish_year:date('Y',strtotime($md->ts_published))).'. doi:'.$md->doi; + echo ' ['.str_replace('"','',substr($md->author_en,1,-1)).'. '.$md->title_en.'. '.$md->publisher_en.', '.(empty($md->ts_published)?$md->publish_year:date('Y',strtotime($md->ts_published))).'. doi:'.$md->doi.']'; + ?> (下载引用:RIS格式 | RIS英文格式 | Bibtex格式 | Bibtex英文格式)

    + ref) : ?> +
    +

    相关文献(作者推荐)

    +
      + ref as $ref) : + echo '
    1. '.$ref->reference; + echo '查看'; + if (empty($ref->link)) + { + if(!empty($ref->attid)) + echo '下载'; + }else{ + echo '下载'; + } + echo "
    2. "; + endforeach; + ?> +
    + themeref) :?> + +
    +

    专题文献

    +
      + themeref as $ref) : + echo '
    1. '.$ref->reference; + echo '查看'; + if (empty($ref->link)) + { + if(!empty($ref->attid)) + echo ' | 下载'; + }else{ + echo ' | 下载'; + } + echo "
    2. "; + endforeach; + ?> +
    + userref) : ?> +
    +

    数据施引文献

    +
      + userref as $ref) : + echo '
    1. '.$ref->reference; + echo '查看'; + if (empty($ref->link)) + { + if(!empty($ref->attid)) + echo '下载'; + }else{ + echo '下载'; + } + echo "
    2. "; + endforeach; + if (count($this->userref)==15) + { + echo '更多施引文献'; + } + ?> +
    + +
    +

    数据使用声明

    + uselimits) : + foreach($this->uselimits as $uselimit) : + echo '

    '.str_replace(array("\r\n", "\n", "\r"),'

    ',$this->escape($uselimit->uselimit)).'

    '; + endforeach; + ?> + +

    为尊重知识产权、保障数据作者的权益、扩展数据中心的服务、评估数据的应用潜力,请数据使用者在使用数据所产生的研究成果中(包括公开发表的论文、论著、数据产品和未公开发表的研究报告、数据产品等成果),明确注明数据来源和数据作者。对于转载(二次或多次发布)的数据,作者还须注明原始数据来源。

    +

    中文发表的成果参考以下规范注明: 数据来源于黑河计划数据管理中心、寒区旱区科学数据中心(http://westdc.westgis.ac.cn)

    +

    英文发表的成果依据以下规范注明: The data set is provided by Cold and Arid Regions Sciences Data Center at Lanzhou (http://westdc.westgis.ac.cn)

    +

    + + data_archives){ ?> +

    数据相关新闻

    +
      + data_archives as $v){?> +
    • + +
    +
    + + suppinfo || $this->fund) : ?> +

    资助项目

    + fund)) : ?> +
      + fund as $k=>$v) : ?> +
    • (项目编号:) [(No. )]
    • + +
    + suppinfo)) : ?> + '.str_replace(array("\r\n", "\n", "\r"),'

    ',$this->escape($md->suppinfo)).'

    ';?> + +
    + + resources) : ?> +

    相关资源

    + +
    + +
    +
    + keys as $cg){ + if($cg['keytype']=="theme") + $keywords[]=$cg['keyword']; + } + $ev = join(" ",$keywords); + ?> +
    + +
    + + +
    +
      +
      +
      + downhistory) : ?> +

      最近10条服务记录如下:

      +
        + downhistory as $v){ + echo '
      1. '.date("Y-m-d",strtotime($v->ts_created))." ".$v->unit." ".$v->realname; + if (!empty($v->offlineproject)) + echo ' 用途:'.$v->offlineproject; + elseif (!empty($v->onlineproject)) + echo ' 用途:'.$v->onlineproject; + echo '
      2. '; + } + ?> +
      + + 暂时没有服务记录,欢迎您下载使用! + +
      +
      + +
      +
      +
      +
      +
      + status>0 and $md->status<5) : ?> +

      此数据还在评审过程中,我们真切地邀请您参加此数据的评审,以便我们能尽快发布此数据!评审

      + +

      数据评论

      +
      +
      评论加载中
      +
      + hasIdentity()) + { + $user = $auth->getIdentity(); + $name = $user->realname; + $email = $user->email; + }else + { + $name = ""; + $email = ""; + } + ?> +
      +
      + +
      + +
      +
      +
      + +
      + +
      +
      +
      + +
      + e.g. http://westdc.westgis.ac.cn/ +
      +
      +
      + +
      + +
      +
      +
      + +
      + +
      +
      +
      +
      + + + 提交 +
      +
      +
      +
      + +
      +
      +
      +
      + + '学科','place'=>'地点','theme'=>'主题','temporal'=>'时间词','stratum'=>'地层'); +$kt=''; +$i=0; +foreach($this->keys as $cg) : + if ($kt==$cg['keytype']) : + $i+=1; + else : + if (!empty($kt)) echo ''; + $kt=$cg['keytype']; + $i=0; + endif; + if ($i==0) { + ?> + + doi) : ?> +
      • 数据DOI:doi; ?>
      + +
      +
      +

      数据细节文件列表

      +
        + fileformat) : ?> +
      • 格式:fileformat; ?>
      • + +
      • 大小:filesize; ?>MB
      • + downloaded>9) :?> +
      • 下载:downloaded; ?>次
      • + +
      • 浏览:viewed; ?>次
      • + + timebegin)) : ?> +
      • 数据时间范围:timebegin));if (!empty($md->timeend)) echo " 至 ".date('Y-m-d',strtotime($md->timeend)); ?>
      • + + doc)) : ?> + + + attachments) : ?> +
      • 相关文档: + attachments as $k=>$a) : ?> + + + +
      • + +
      • 数据共享方式:datatype) print "离线"; else print "在线(可直接下载)";?>
      • +
      +
      + status>0 and $md->status<5) : ?> + 数据评审 + datatype) : ?> + + 在线下载 + + + dataService)) { ?> + theme->AppendPlus($this,'datepicker'); ?> + + + + + 放入数据篮 + + + + 收藏此数据 + +
      +
      +
      +

      空间位置

      +
      +
      +

      联系信息

      +
      +
        + '资源提供者','custodian'=>'维护者','owner'=>'拥有者','user'=>'用户','distributor'=>'数据服务联系人','originator'=>'创建者','pointOfContact'=>'联系人','principalInvestigator'=>'数据调查与处理者','processor'=>'处理者','publisher'=>'元数据发布者','author'=>'元数据作者'); + $r=''; + $i=0; + foreach($this->authors as $k=>$author) : + if ($author->role!=$r) + { + $r=$author->role; + $i=0; + if ($k>0) echo ''; + echo '
      • '.$party_zh[$author->role].':'; + } + if ($i>0) echo ','; + $i+=1; + if (!empty($author->email) && $r!='principalInvestigator') + echo ''; + echo ''; + if (!empty($author->individual)) + echo $author->individual; + else + echo $author->organisation; + echo ''; + if (!empty($author->email)) echo ''; + if ($k+1==count($this->authors)) echo '
      • '; + endforeach; + ?> +
      +
      +
        +
      • 元数据更新时间:ts_created)); ?>
      • +
      • 下载元数据: + Adobe PDF格式 + OpenOffice odt格式 + Word doc格式 + 查看XML源文件 +
      • + + version->c>0):?> +
      • 版本历史:version->c ?> 个
      • + +
      +
      + +
      +
      +
      分享到
      + +
      + + + + + + + + + +
      + +
      +
      +
      + + + +

      Cannot find the metadata.

      +

      没有找到对应的元数据。

      + + + From 51f3adfa794787c730904b3b4a8639da259403b6 Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 10 Jan 2014 04:09:50 +0000 Subject: [PATCH 105/173] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=B5=B7=E6=B2=B3?= =?UTF-8?q?=E6=A0=87=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/default/controllers/HaiheController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/default/controllers/HaiheController.php b/application/default/controllers/HaiheController.php index 88e38d6f..106b6287 100644 --- a/application/default/controllers/HaiheController.php +++ b/application/default/controllers/HaiheController.php @@ -15,7 +15,7 @@ class HaiheController extends DataController function indexAction() { $archive = new Archive($this->db); - $this->view->info = $archive->getOneArchive('海河流域地表通量、气象要素观测数据集','about'); + $this->view->info = $archive->getOneArchive('海河流域多尺度地表通量与气象要素观测数据集','about'); } function documentAction() From 7871ebfb6af5dc681c2bb2d2c71335f6d80da771 Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 10 Jan 2014 05:01:42 +0000 Subject: [PATCH 106/173] add breadcrump and reference link --- .../default/views/scripts/haihe/document.phtml | 12 +++++++----- application/default/views/scripts/haihe/view.phtml | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/application/default/views/scripts/haihe/document.phtml b/application/default/views/scripts/haihe/document.phtml index bc9de0f4..485bdd71 100644 --- a/application/default/views/scripts/haihe/document.phtml +++ b/application/default/views/scripts/haihe/document.phtml @@ -19,12 +19,14 @@ $this->nav[] = array('link'=>"/haihe",'title'=>'海河流域观测数据集');
        refs as $md) : ?>
      1. 下载'; - } + echo ' 查看'; + if (!empty($md['link'])) : + echo ' 下载'; + else : + if (!empty($md['attid'])) echo ' 下载'; + endif; ?> - [相关数据] + [相关数据]
      diff --git a/application/default/views/scripts/haihe/view.phtml b/application/default/views/scripts/haihe/view.phtml index 8ae014c5..99de4298 100755 --- a/application/default/views/scripts/haihe/view.phtml +++ b/application/default/views/scripts/haihe/view.phtml @@ -12,6 +12,7 @@ if(!empty($this->dataService)) { $this->theme->AppendModel($this,"dataservice"); } + $this->nav[] = array('link'=>"/haihe",'title'=>'海河流域观测数据集'); ?> -
      -partial('stat/left.phtml'); ?> -
      -
      - - -
      -点击列名进行排序 -
      -
      - - - - - - - - - - - - - -
      ID用户离线申请次数在线申请次数总申请次数
      -
      - -
      - \ No newline at end of file diff --git a/application/module/Statistics/User.php b/application/module/Statistics/User.php new file mode 100644 index 00000000..c7b69c04 --- /dev/null +++ b/application/module/Statistics/User.php @@ -0,0 +1,130 @@ +db = \Zend_Registry::get('db'); + }else{ + $this->db = $db; + } + + $this->config = \Zend_Registry::get('config'); + + $this->table = new \Helpers\Table(); + } + + public function ThisYear(){ + return date("Y",time()); + } + + //按年统计新用户 + public function getNewUsersByYear($year = 0) + { + if(empty($year)) + { + $year = $this->ThisYear(); + } + + if($year == -1) + { + $sql = "select count(id),extract(year from ts_created) + from users + group by extract(year from ts_created) + order by date_part"; + }else{ + $sql = "select count(id),extract(year from ts_created) + from users + where extract(year from ts_created)='$year' + group by extract(year from ts_created)"; + } + + $rs = $this->db->query($sql); + $rows = $rs->fetchAll(); + return $rows; + } + + //按月统计新用户 + public function getNewUsersByMonth($year = 0) + { + if(empty($year)) + { + $year = $this->ThisYear(); + } + + $sql = "select count(id),extract(month from ts_created) + from users + where extract(year from ts_created)=$year + group by extract(month from ts_created) + order by date_part"; + + $rs = $this->db->query($sql); + $rows = $rs->fetchAll(); + return $rows; + } + + //月均注册量 + public function getAverageSingupByMonth($year = 0) + { + if(empty($year)) + { + $year = $this->ThisYear(); + } + + $sql = "select round(count(id)/12) as count,extract(year from ts_created) + from users + where extract(year from ts_created)='$year' + group by extract(year from ts_created)"; + + $rs = $this->db->query($sql); + $rows = $rs->fetchAll(); + return $rows; + } + + //总用户量 + public function getTotal($year = 0) + { + if(empty($year)) + { + $year = $this->ThisYear(); + } + + $sql = ""; + + $rs = $this->db->query($sql); + $rows = $rs->fetchAll(); + return $rows; + } + + //平均申请数 + public function getAverageApplicationTimes($times = 1) + { + if(empty($year)) + { + $times = 1; + } + + $sql = ""; + + $rs = $this->db->query($sql); + $rows = $rs->fetchAll(); + return $rows; + } + +} From 7ccd999fd5dd20b0ff4ee45423ec60e56dd5763f Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Mon, 13 Jan 2014 07:16:22 +0000 Subject: [PATCH 112/173] =?UTF-8?q?#569=20=E6=B7=BB=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=8F=91=E5=B8=83=E7=9A=84=E6=83=85=E5=86=B5?= =?UTF-8?q?=E5=8C=BA=E5=88=86=EF=BC=8C=E6=9C=AA=E5=8F=91=E5=B8=83=E6=97=B6?= =?UTF-8?q?doi=E6=A0=87=E9=A2=98=E5=8F=AF=E4=BF=AE=E6=94=B9=EF=BC=8C?= =?UTF-8?q?=E5=B9=B6=E4=B8=94=E8=AF=BB=E5=8F=96=E5=85=83=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9A=84=E6=A0=87=E9=A2=98=E4=BD=9C=E4=B8=BA=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controllers/DataController.php | 5 +++++ application/admin/views/scripts/data/doi-add.phtml | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index b7675d6d..5e36363b 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -4000,6 +4000,11 @@ class Admin_DataController extends Zend_Controller_Action }else{ $this->view->data['doi'] = $metadata['doi']; $this->view->data['info'] = $doi->data_process_out($this->view->data); + if(empty($this->view->data['ts_published'])) + { + $this->view->data['title'] = $metadata['title']; + $this->view->data['title_en'] = $metadata['title_en']; + } } }else{ $this->view->data = $doi->view($uuid); diff --git a/application/admin/views/scripts/data/doi-add.phtml b/application/admin/views/scripts/data/doi-add.phtml index 39ed9c36..7a6a7028 100644 --- a/application/admin/views/scripts/data/doi-add.phtml +++ b/application/admin/views/scripts/data/doi-add.phtml @@ -57,13 +57,15 @@ $this->theme->AppendPlus($this,'colorbox');
      - " /> + data['ts_published']) ? 'readonly="readonly"':""?> + value="data['title']) ? $this->data['title']:"" ?>" />
      - " /> + data['ts_published']) ? 'readonly="readonly"':""?> + value="data['title_en']) ? $this->data['title_en']:"" ?>" />
      From 3967c23ecbc6b6ca854c5ce3d6ae8c667c94ed89 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Mon, 13 Jan 2014 07:28:36 +0000 Subject: [PATCH 113/173] =?UTF-8?q?#569=E5=B0=86=E6=A0=87=E9=A2=98?= =?UTF-8?q?=E8=AE=BE=E4=B8=BA=E9=BB=98=E8=AE=A4=E4=B8=8D=E8=83=BD=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/views/scripts/data/doi-add.phtml | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/application/admin/views/scripts/data/doi-add.phtml b/application/admin/views/scripts/data/doi-add.phtml index 7a6a7028..01ca5041 100644 --- a/application/admin/views/scripts/data/doi-add.phtml +++ b/application/admin/views/scripts/data/doi-add.phtml @@ -29,43 +29,47 @@ $this->theme->AppendPlus($this,'colorbox'); msg)) { ?> msg ?> +
      + +

      提示

      + 如果元数据中标题发生了变更,在DOI中也需要变更时需要在这里点击“提交”按钮才能生效 +
      - " /> + " />
      - " /> + " class="input-block-level" />
      - " /> + " class="input-block-level" />
      - " /> + " class="input-block-level"/>
      - data['ts_published']) ? 'readonly="readonly"':""?> - value="data['title']) ? $this->data['title']:"" ?>" /> + " class="input-block-level"/>
      - data['ts_published']) ? 'readonly="readonly"':""?> - value="data['title_en']) ? $this->data['title_en']:"" ?>" /> + " class="input-block-level" />
      From ed6d450d4a013187bc979375e60667a678f5fc35 Mon Sep 17 00:00:00 2001 From: wlx Date: Tue, 14 Jan 2014 02:16:49 +0000 Subject: [PATCH 114/173] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=B8=BA=E5=88=86?= =?UTF-8?q?=E6=A0=8F=E7=9B=AE=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/HaiheController.php | 60 ++++++++++++++++--- .../default/views/scripts/haihe/base.phtml | 30 ++++++++++ .../views/scripts/haihe/document.phtml | 5 +- .../default/views/scripts/haihe/index.phtml | 6 +- .../default/views/scripts/haihe/navi.phtml | 38 ++++++++++++ 5 files changed, 130 insertions(+), 9 deletions(-) create mode 100644 application/default/views/scripts/haihe/base.phtml create mode 100644 application/default/views/scripts/haihe/navi.phtml diff --git a/application/default/controllers/HaiheController.php b/application/default/controllers/HaiheController.php index 106b6287..d1aed6a2 100644 --- a/application/default/controllers/HaiheController.php +++ b/application/default/controllers/HaiheController.php @@ -20,20 +20,66 @@ class HaiheController extends DataController function documentAction() { - $page=(int)$this->_request->getParam('page'); - if (empty($page)) $page=1; - $offset=$this->limit*($page-1); - $row=$this->db->fetchAll("select count(*) from reference where id in (select refid from mdref where uuid in (select uuid from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='haihe') ))"); - $sum=$row[0]['count']; + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $offset=$this->limit*($page-1); + $row=$this->db->fetchAll("select count(*) from reference where id in (select refid from mdref where uuid in (select uuid from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='haihe') ))"); + $sum=$row[0]['count']; $sql="select * from reference where id in (select refid from mdref where uuid in (select uuid from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='haihe') )) order by reference limit ? offset ?"; $this->view->refs=$this->db->fetchAll($sql,array($this->limit,$offset)); - $this->view->page=new Pagination($sum,$page,$this->limit,"文献"); - $this->view->offset=$offset+1; + $this->view->page=new Pagination($sum,$page,$this->limit,"文献"); + $this->view->offset=$offset+1; + } + + function daxingAction() + { + $this->getmd(array('大兴区')); + $this->_helper->viewRenderer('base'); } + function miyunAction() + { + $this->getmd(array('密云')); + $this->_helper->viewRenderer('base'); + } + + function guantaoAction() + { + $this->getmd(array('馆陶县')); + $this->_helper->viewRenderer('base'); + } + function viewAction() { parent::viewAction(); $this->_helper->viewRenderer('haihe/view'); } + + private function getmd($keyword,$type='theme') + { + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $offset=$this->limit*($page-1); + if (!is_array($keyword)) + { + $keyword=array($keyword); + } + $key="("; + foreach($keyword as $k) + { + $key.="'".$k."',"; + } + $key=substr($key,0,-1); + $key.=")"; + $keyword=$key; + + $state=$this->db->query("select count(m.*) from normalmetadata m left join datasource d on m.uuid=d.uuid left join source s on d.sourceid=s.id where s.code='haihe' and m.id in (select id from keyword where keytype='".$type."' and keyword in ".$keyword.")"); + $row=$state->fetchAll(); + $sum=$row[0]['count']; + //@todo: add order with title + $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='haihe') and id in (select id from keyword where keytype='".$type."' and keyword in ".$keyword.") order by title limit ? offset ?"; + $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); + $this->view->page=new Pagination($sum,$page,$this->limit); + $this->view->offset=$offset+1; + } } \ No newline at end of file diff --git a/application/default/views/scripts/haihe/base.phtml b/application/default/views/scripts/haihe/base.phtml new file mode 100644 index 00000000..4c53ca20 --- /dev/null +++ b/application/default/views/scripts/haihe/base.phtml @@ -0,0 +1,30 @@ +headTitle($this->config->title->site); +$this->headTitle($this->config->title->data); +$this->headTitle()->setSeparator(' - '); +$this->headLink()->appendStylesheet('/css/water.css'); +$this->nav[] = array('link'=>"/haihe",'title'=>'海河流域观测数据集'); +?> +render('breadcrumbs.phtml'); ?> +
      +
      + partial('haihe/navi.phtml'); ?> +
      +
      + info) : ?> +
      + info['body'])) echo $this->info['body'];?> +
      + + metadata) : ?> + page->getNavigation(); ?> +
      +
        + metadata as $md) : ?> +
      1. + +
      +
      + +
      +
      \ No newline at end of file diff --git a/application/default/views/scripts/haihe/document.phtml b/application/default/views/scripts/haihe/document.phtml index 643f3411..370b05ff 100644 --- a/application/default/views/scripts/haihe/document.phtml +++ b/application/default/views/scripts/haihe/document.phtml @@ -10,8 +10,11 @@ $this->nav[] = array('link'=>"/haihe",'title'=>'海河流域观测数据集'); ?> render('breadcrumbs.phtml'); ?>
      -
      +
      + partial('haihe/navi.phtml'); ?> +
      +

      数据相关文献

      refs) : ?> page->getNavigation(); ?> diff --git a/application/default/views/scripts/haihe/index.phtml b/application/default/views/scripts/haihe/index.phtml index 47590f84..11407b57 100644 --- a/application/default/views/scripts/haihe/index.phtml +++ b/application/default/views/scripts/haihe/index.phtml @@ -7,7 +7,11 @@ $this->nav[] = array('link'=>"/haihe",'title'=>'海河流域观测数据集'); ?> render('breadcrumbs.phtml'); ?>
      -
      +
      + partial('haihe/navi.phtml'); ?> +
      + +

      info['title'])) echo $this->info['title']; ?>

      diff --git a/application/default/views/scripts/haihe/navi.phtml b/application/default/views/scripts/haihe/navi.phtml new file mode 100644 index 00000000..ad49c1a3 --- /dev/null +++ b/application/default/views/scripts/haihe/navi.phtml @@ -0,0 +1,38 @@ + \ No newline at end of file From 4f7a2765b30a8286cdf5f4e6062c1484e8b276c8 Mon Sep 17 00:00:00 2001 From: wlx Date: Tue, 14 Jan 2014 02:22:56 +0000 Subject: [PATCH 115/173] fix link problem --- application/default/controllers/HaiheController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/application/default/controllers/HaiheController.php b/application/default/controllers/HaiheController.php index d1aed6a2..5c54b895 100644 --- a/application/default/controllers/HaiheController.php +++ b/application/default/controllers/HaiheController.php @@ -33,19 +33,19 @@ class HaiheController extends DataController function daxingAction() { - $this->getmd(array('大兴区')); + $this->getmd(array('大兴区'),'place'); $this->_helper->viewRenderer('base'); } function miyunAction() { - $this->getmd(array('密云')); + $this->getmd(array('密云'),'place'); $this->_helper->viewRenderer('base'); } function guantaoAction() { - $this->getmd(array('馆陶县')); + $this->getmd(array('馆陶县'),'place'); $this->_helper->viewRenderer('base'); } From 9954be07f905f147e2d294247dfbea0de6315304 Mon Sep 17 00:00:00 2001 From: wlx Date: Thu, 16 Jan 2014 02:42:20 +0000 Subject: [PATCH 116/173] add more link --- application/admin/views/scripts/stat/month.phtml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/application/admin/views/scripts/stat/month.phtml b/application/admin/views/scripts/stat/month.phtml index 3b4b03ac..429cc39f 100644 --- a/application/admin/views/scripts/stat/month.phtml +++ b/application/admin/views/scripts/stat/month.phtml @@ -39,7 +39,10 @@ 2009 2010 2011 - 2012 + 2012 + 2013 + 2014 + 2015
      y.'年按月在线下载条数(有用途记录,且无数据重复)统计';?>
      From b3b09c1839d9ed13dc1053a78137fd9420c365ae Mon Sep 17 00:00:00 2001 From: Li Heng Date: Thu, 16 Jan 2014 03:15:24 +0000 Subject: [PATCH 117/173] =?UTF-8?q?=E6=96=B0=E6=B3=A8=E5=86=8C=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=8C=89=E6=9C=88=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/views/scripts/stat/user-new.phtml | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/application/admin/views/scripts/stat/user-new.phtml b/application/admin/views/scripts/stat/user-new.phtml index bc40c7d5..adcf0a37 100644 --- a/application/admin/views/scripts/stat/user-new.phtml +++ b/application/admin/views/scripts/stat/user-new.phtml @@ -63,6 +63,37 @@
      + + +
      @@ -149,6 +180,7 @@
      +
      From 8f8ffeee43478e1473e45efcb50806f8dfe710df Mon Sep 17 00:00:00 2001 From: wlx Date: Wed, 22 Jan 2014 01:45:38 +0000 Subject: [PATCH 118/173] update glacier theme --- .../default/controllers/GlacierController.php | 249 +++++++++--------- .../default/views/scripts/glacier/base.phtml | 30 +++ .../views/scripts/glacier/browse.phtml | 4 +- .../views/scripts/glacier/category.phtml | 43 --- .../views/scripts/glacier/everestnorth.phtml | 33 --- .../default/views/scripts/glacier/field.phtml | 33 --- .../views/scripts/glacier/frozensoil.phtml | 33 --- .../views/scripts/glacier/geobase.phtml | 34 --- .../views/scripts/glacier/glacier.phtml | 33 --- .../views/scripts/glacier/gongga.phtml | 33 --- .../default/views/scripts/glacier/gps.phtml | 33 --- .../default/views/scripts/glacier/hydro.phtml | 33 --- .../default/views/scripts/glacier/index.phtml | 73 +---- .../views/scripts/glacier/inventory.phtml | 35 --- .../default/views/scripts/glacier/lake.phtml | 34 --- .../default/views/scripts/glacier/lidar.phtml | 35 --- .../views/scripts/glacier/material.phtml | 35 --- .../default/views/scripts/glacier/meteo.phtml | 33 --- .../views/scripts/glacier/movement.phtml | 33 --- .../default/views/scripts/glacier/namco.phtml | 33 --- .../default/views/scripts/glacier/navi.phtml | 11 +- .../views/scripts/glacier/nianchu.phtml | 33 --- .../scripts/glacier/photogrammetry.phtml | 33 --- .../views/scripts/glacier/physical.phtml | 33 --- .../views/scripts/glacier/qilian.phtml | 33 --- .../views/scripts/glacier/quatemary.phtml | 33 --- .../default/views/scripts/glacier/rs.phtml | 33 --- .../views/scripts/glacier/search.phtml | 6 +- .../default/views/scripts/glacier/tag.phtml | 55 ++-- .../default/views/scripts/glacier/thumb.phtml | 57 ++-- .../views/scripts/glacier/tianshan.phtml | 33 --- .../views/scripts/glacier/timeline.phtml | 6 +- .../views/scripts/glacier/timemap.phtml | 8 +- .../views/scripts/glacier/vegetation.phtml | 33 --- .../views/scripts/glacier/yangtze.phtml | 33 --- 35 files changed, 244 insertions(+), 1098 deletions(-) create mode 100644 application/default/views/scripts/glacier/base.phtml delete mode 100755 application/default/views/scripts/glacier/category.phtml delete mode 100644 application/default/views/scripts/glacier/everestnorth.phtml delete mode 100644 application/default/views/scripts/glacier/field.phtml delete mode 100644 application/default/views/scripts/glacier/frozensoil.phtml delete mode 100644 application/default/views/scripts/glacier/geobase.phtml delete mode 100644 application/default/views/scripts/glacier/glacier.phtml delete mode 100644 application/default/views/scripts/glacier/gongga.phtml delete mode 100644 application/default/views/scripts/glacier/gps.phtml delete mode 100644 application/default/views/scripts/glacier/hydro.phtml delete mode 100644 application/default/views/scripts/glacier/inventory.phtml delete mode 100644 application/default/views/scripts/glacier/lake.phtml delete mode 100644 application/default/views/scripts/glacier/lidar.phtml delete mode 100644 application/default/views/scripts/glacier/material.phtml delete mode 100644 application/default/views/scripts/glacier/meteo.phtml delete mode 100644 application/default/views/scripts/glacier/movement.phtml delete mode 100644 application/default/views/scripts/glacier/namco.phtml delete mode 100644 application/default/views/scripts/glacier/nianchu.phtml delete mode 100644 application/default/views/scripts/glacier/photogrammetry.phtml delete mode 100644 application/default/views/scripts/glacier/physical.phtml delete mode 100644 application/default/views/scripts/glacier/qilian.phtml delete mode 100644 application/default/views/scripts/glacier/quatemary.phtml delete mode 100644 application/default/views/scripts/glacier/rs.phtml delete mode 100644 application/default/views/scripts/glacier/tianshan.phtml delete mode 100644 application/default/views/scripts/glacier/vegetation.phtml delete mode 100644 application/default/views/scripts/glacier/yangtze.phtml diff --git a/application/default/controllers/GlacierController.php b/application/default/controllers/GlacierController.php index 719bcdf9..0d36abc4 100644 --- a/application/default/controllers/GlacierController.php +++ b/application/default/controllers/GlacierController.php @@ -25,8 +25,8 @@ class GlacierController extends DataController function indexAction() { - $sql="select m.uuid,m.title,m.id,m.description from normalmetadata m left join thumbnail t on m.id=t.id where m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and length(t.data)>2 order by random() limit 3"; - $this->view->meatdata=$this->db->fetchAll($sql); + $archive = new Archive($this->db); + $this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-项目简介','about'); } /* @@ -78,187 +78,148 @@ class GlacierController extends DataController function geobaseAction() { - $page=(int)$this->_request->getParam('page'); - if (empty($page)) $page=1; - $offset=$this->limit*($page-1); - $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='theme' and (keyword='遥感影像' or keyword='DEM'))"); - $row=$state->fetchAll(); - $sum=$row[0]['count']; - $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='theme' and (keyword='遥感影像' or keyword='DEM')) order by timebegin,title limit ? offset ?"; - $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); - $this->view->page=new Pagination($sum,$page,$this->limit); - $this->view->offset=$offset+1; + $archive = new Archive($this->db); + $this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-基础数据','about'); + $this->getmd(array('遥感影像','DEM')); + $this->_helper->viewRenderer('base'); } function demAction() { $this->getmd('DEM'); + $archive = new Archive($this->db); + $this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-DEM','about'); + $this->_helper->viewRenderer('base'); } function rsAction() { $this->getmd('遥感影像'); + $archive = new Archive($this->db); + $this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-遥感影像','about'); + $this->_helper->viewRenderer('base'); } function inventoryAction() { - $page=(int)$this->_request->getParam('page'); - if (empty($page)) $page=1; - $offset=$this->limit*($page-1); - $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='theme' and (keyword='冰川编目' or keyword='冰湖编目'))"); - $row=$state->fetchAll(); - $sum=$row[0]['count']; - $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='theme' and (keyword='冰川编目' or keyword='冰湖编目')) order by timebegin,title limit ? offset ?"; - $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); - $this->view->page=new Pagination($sum,$page,$this->limit); - $this->view->offset=$offset+1; + $this->getmd(array('冰川编目','冰湖编目')); + $archive = new Archive($this->db); + $this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-冰川冰湖编目','about'); + $this->_helper->viewRenderer('base'); } function glacierAction() { $this->getmd('冰川编目'); + $archive = new Archive($this->db); + $this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-冰川编目','about'); + $this->_helper->viewRenderer('base'); } function lakeAction() { $this->getmd('冰湖编目'); + $archive = new Archive($this->db); + $this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-冰湖编目','about'); + $this->_helper->viewRenderer('base'); } function fieldAction() { - $page=(int)$this->_request->getParam('page'); - if (empty($page)) $page=1; - $offset=$this->limit*($page-1); - $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='theme' - and (keyword='水文' or keyword='流量' or keyword='水质' or keyword='同位素' or keyword='径流' or keyword='水位' or keyword='气象' or keyword='雨量' or keyword='GPS' - or keyword='雷达' or keyword='雷达测厚' or keyword='冰川厚度' or keyword='物质平衡' or keyword='花杆' or keyword='运动速度' or keyword='花杆消融观测' or keyword='冰舌' - or keyword='冰雪物理过程' or keyword='冰温' or keyword='摄影测量' or keyword='照片' or keyword='第四纪' or keyword='冻土' or keyword='植被' ))"); - $row=$state->fetchAll(); - $sum=$row[0]['count']; - $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='theme' and (keyword='水文' or keyword='流量' or keyword='水质' or keyword='同位素' or keyword='径流' or keyword='水位' or keyword='气象' or keyword='雨量' or keyword='GPS' - or keyword='雷达' or keyword='雷达测厚' or keyword='冰川厚度' or keyword='物质平衡' or keyword='花杆' or keyword='运动速度' or keyword='花杆消融观测' or keyword='冰舌' - or keyword='冰雪物理过程' or keyword='冰温' or keyword='摄影测量' or keyword='照片' or keyword='第四纪' or keyword='冻土' or keyword='植被' )) order by timebegin,title limit ? offset ?"; - $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); - $this->view->page=new Pagination($sum,$page,$this->limit); - $this->view->offset=$offset+1; + $this->getmd(array('水文','流量','水质','同位素','径流','水位','气象','雨量','GPS', + '雷达','雷达测厚','冰川厚度','物质平衡','花杆','运动速度','花杆消融观测','冰舌', + '冰雪物理过程','冰温','摄影测量','照片','第四纪','冻土','植被')); + $archive = new Archive($this->db); + $this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-野外考察与定位观测','about'); + $this->_helper->viewRenderer('base'); } function meteoAction() { - $page=(int)$this->_request->getParam('page'); - if (empty($page)) $page=1; - $offset=$this->limit*($page-1); - $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='theme' and (keyword='气象' or keyword='雨量'))"); - $row=$state->fetchAll(); - $sum=$row[0]['count']; - $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='theme' and (keyword='气象' or keyword='雨量')) order by timebegin,title limit ? offset ?"; - $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); - $this->view->page=new Pagination($sum,$page,$this->limit); - $this->view->offset=$offset+1; + $this->getmd(array('气象','雨量')); + $archive = new Archive($this->db); + $this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-气象','about'); + $this->_helper->viewRenderer('base'); } function hydroAction() { - $page=(int)$this->_request->getParam('page'); - if (empty($page)) $page=1; - $offset=$this->limit*($page-1); - $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='theme' and (keyword='水文' or keyword='流量' or keyword='水质' or keyword='同位素' or keyword='径流' or keyword='水位'))"); - $row=$state->fetchAll(); - $sum=$row[0]['count']; - $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='theme' and (keyword='水文' or keyword='流量' or keyword='水质' or keyword='同位素' or keyword='径流' or keyword='水位')) order by timebegin,title limit ? offset ?"; - $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); - $this->view->page=new Pagination($sum,$page,$this->limit); - $this->view->offset=$offset+1; + $this->getmd(array('水文','流量','水质','同位素','径流','水位')); + $archive = new Archive($this->db); + $this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-水文','about'); + $this->_helper->viewRenderer('base'); } function gpsAction() { $this->getmd('GPS','theme'); + $archive = new Archive($this->db); + $this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-GPS','about'); + $this->_helper->viewRenderer('base'); } function lidarAction() { - $page=(int)$this->_request->getParam('page'); - if (empty($page)) $page=1; - $offset=$this->limit*($page-1); - $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='theme' and (keyword='雷达' or keyword='雷达测厚' or keyword='冰川厚度'))"); - $row=$state->fetchAll(); - $sum=$row[0]['count']; - $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='theme' and (keyword='雷达' or keyword='雷达测厚' or keyword='冰川厚度')) order by timebegin,title limit ? offset ?"; - $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); - $this->view->page=new Pagination($sum,$page,$this->limit); - $this->view->offset=$offset+1; + $this->getmd(array('雷达','雷达测厚','冰川厚度')); + $archive = new Archive($this->db); + $this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-雷达测厚','about'); + $this->_helper->viewRenderer('base'); } function materialAction() { - $page=(int)$this->_request->getParam('page'); - if (empty($page)) $page=1; - $offset=$this->limit*($page-1); - $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='theme' and (keyword='物质平衡' or keyword='花杆'))"); - $row=$state->fetchAll(); - $sum=$row[0]['count']; - $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='theme' and (keyword='物质平衡' or keyword='花杆')) order by timebegin,title limit ? offset ?"; - $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); - $this->view->page=new Pagination($sum,$page,$this->limit); - $this->view->offset=$offset+1; + $this->getmd(array('物质平衡','花杆')); + $archive = new Archive($this->db); + $this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-物质平衡','about'); + $this->_helper->viewRenderer('base'); } function movementAction() { - $page=(int)$this->_request->getParam('page'); - if (empty($page)) $page=1; - $offset=$this->limit*($page-1); - $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='theme' and (keyword='运动速度' or keyword='花杆消融观测' or keyword='冰舌'))"); - $row=$state->fetchAll(); - $sum=$row[0]['count']; - $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='theme' and (keyword='运动速度' or keyword='花杆消融观测' or keyword='冰舌')) order by timebegin,title limit ? offset ?"; - $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); - $this->view->page=new Pagination($sum,$page,$this->limit); - $this->view->offset=$offset+1; + $this->getmd(array('运动速度','花杆消融观测','冰舌')); + $archive = new Archive($this->db); + $this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-冰川运动','about'); + $this->_helper->viewRenderer('base'); } function physicalAction() { - $page=(int)$this->_request->getParam('page'); - if (empty($page)) $page=1; - $offset=$this->limit*($page-1); - $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='theme' and (keyword='冰雪物理过程' or keyword='冰温'))"); - $row=$state->fetchAll(); - $sum=$row[0]['count']; - $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='theme' and (keyword='冰雪物理过程' or keyword='冰温')) order by timebegin,title limit ? offset ?"; - $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); - $this->view->page=new Pagination($sum,$page,$this->limit); - $this->view->offset=$offset+1; + $this->getmd(array('冰雪物理过程','冰温')); + $archive = new Archive($this->db); + $this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-冰雪物理过程','about'); + $this->_helper->viewRenderer('base'); } function photogrammetryAction() { - $page=(int)$this->_request->getParam('page'); - if (empty($page)) $page=1; - $offset=$this->limit*($page-1); - $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='theme' and (keyword='摄影测量' or keyword='照片'))"); - $row=$state->fetchAll(); - $sum=$row[0]['count']; - $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='theme' and (keyword='摄影测量' or keyword='照片')) order by timebegin,title limit ? offset ?"; - $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); - $this->view->page=new Pagination($sum,$page,$this->limit); - $this->view->offset=$offset+1; + $this->getmd(array('摄影测量','照片')); + $archive = new Archive($this->db); + $this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-近景摄影测量','about'); + $this->_helper->viewRenderer('base'); } function vegetationAction() { $this->getmd('植被'); + $archive = new Archive($this->db); + $this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-植被调查','about'); + $this->_helper->viewRenderer('base'); } function frozensoilAction() { $this->getmd('冻土'); + $archive = new Archive($this->db); + $this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-冻土调查','about'); + $this->_helper->viewRenderer('base'); } function quatemaryAction() { $this->getmd('第四纪'); + $archive = new Archive($this->db); + $this->view->info = $archive->getOneArchive('中国冰川资源及其变化调查-第四纪','about'); + $this->_helper->viewRenderer('base'); } function listAction() @@ -270,12 +231,13 @@ class GlacierController extends DataController function tagAction() { $key = $this->_request->getParam('key'); + $keytype = $this->_request->getParam('keytype'); $page=(int)$this->_request->getParam('page'); if (empty($page)) $page=1; $offset=$this->limit*($page-1); if (!empty($key)) { $this->view->codename=$key; - $sql=$this->db->quoteInto('select count(id) from keyword where keyword=?',$key); + $sql=$this->db->quoteInto("select count(k.id) from keyword k left join normalmetadata m on k.id=m.id where m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glaicer') and k.keyword=?",$key); $state=$this->db->query($sql); $row=$state->fetchAll(); $sum=$row[0]['count']; @@ -283,17 +245,12 @@ class GlacierController extends DataController $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); $this->view->page=new Pagination($sum,$page,$this->limit); } else { - $state=$this->db->query("select keyword.keyword,count(*) from keyword left join normalmetadata m on keyword.id=m.id where keyword.keytype='place' and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') group by keyword.keyword order by count desc"); - $k1=$state->fetchAll(); - $state=$this->db->query("select k.keyword,count(k.keyword) from keyword k left join normalmetadata m on k.id=m.id where k.keytype='theme' and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') group by k.keyword order by k.keyword"); - $k2=$state->fetchAll(); - $state=$this->db->query("select k.keyword,count(k.keyword) from keyword k left join normalmetadata m on k.id=m.id where k.keytype='discipline' and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') group by k.keyword order by k.keyword"); - $k3=$state->fetchAll(); - $state=$this->db->query("select k.keyword,count(k.keyword) from keyword k left join normalmetadata m on k.id=m.id where k.keytype='stratum' and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') group by k.keyword order by k.keyword"); - $k4=$state->fetchAll(); - $state=$this->db->query("select keyword.keyword,count(*) from keyword left join normalmetadata m on keyword.id=m.id where keyword.keytype='temporal' and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') group by keyword.keyword order by keyword.keyword"); - $k5=$state->fetchAll(); - $this->view->keywords=array('place'=>$k1,'theme'=>$k2,'discipline'=>$k3,'stratum'=>$k4,'temporal'=>$k5); + $sql="select k.keyword,count(*),k.keytype from keyword k left join normalmetadata m on k.id=m.id where length(k.keyword)>0 and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') "; + if (!empty($keytype) && ($keytype=='place' || $keytype=='theme' || $keytype=='discipline'||$keytype=='temporal')) $sql.=" and k.keytype='".$keytype."'"; + $sql.=' group by k.keyword,k.keytype order by k.keytype,k.keyword,count desc'; + $state=$this->db->query($sql); + $this->view->keytype=$keytype; + $this->view->keywords=$state->fetchAll(); } } @@ -376,14 +333,58 @@ class GlacierController extends DataController private function getmd($keyword,$type='theme') { - $page=(int)$this->_request->getParam('page'); - if (empty($page)) $page=1; - $offset=$this->limit*($page-1); - $state=$this->db->query("select count(m.*) from normalmetadata m left join datasource d on m.uuid=d.uuid left join source s on d.sourceid=s.id where s.code='glacier' and m.id in (select id from keyword where keytype='".$type."' and keyword='".$keyword."')"); + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $offset=$this->limit*($page-1); + if (!is_array($keyword)) + { + $keyword=array($keyword); + } + $key="("; + foreach($keyword as $k) + { + $key.="'".$k."',"; + } + $key=substr($key,0,-1); + $key.=")"; + $keyword=$key; + + $state=$this->db->query("select count(m.*) from normalmetadata m left join datasource d on m.uuid=d.uuid left join source s on d.sourceid=s.id where s.code='glacier' and m.id in (select id from keyword where keytype='".$type."' and keyword in ".$keyword.")"); $row=$state->fetchAll(); $sum=$row[0]['count']; //@todo: add order with title - $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='".$type."' and keyword='".$keyword."') order by timebegin,title limit ? offset ?"; + $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keytype='".$type."' and keyword in ".$keyword.") order by timebegin,title limit ? offset ?"; + $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); + $this->view->page=new Pagination($sum,$page,$this->limit); + $this->view->offset=$offset+1; + } + + //获取多项条件并列关系的数据并必须满足limited条件 + //$keyword:字符串或字符串数组 + //$limited:限制字符串 + private function getmdlimited($keyword,$limited) + { + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $offset=$this->limit*($page-1); + if (!is_array($keyword)) + { + $keyword=array($keyword); + } + $key="("; + foreach($keyword as $k) + { + $key.="'".$k."',"; + } + $key=substr($key,0,-1); + $key.=")"; + $keyword=$key; + + $state=$this->db->query("select count(m.*) from normalmetadata m left join datasource d on m.uuid=d.uuid left join source s on d.sourceid=s.id where s.code='glacier' and m.id in (select id from keyword where keyword='".$limited."') and m.id in (select id from keyword where keyword in ".$keyword.")"); + $row=$state->fetchAll(); + $sum=$row[0]['count']; + //@todo: add order with title + $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier') and id in (select id from keyword where keyword='".$limited."') and id in (select id from keyword where keyword in ".$keyword.") order by title limit ? offset ?"; $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); $this->view->page=new Pagination($sum,$page,$this->limit); $this->view->offset=$offset+1; diff --git a/application/default/views/scripts/glacier/base.phtml b/application/default/views/scripts/glacier/base.phtml new file mode 100644 index 00000000..23caa2c3 --- /dev/null +++ b/application/default/views/scripts/glacier/base.phtml @@ -0,0 +1,30 @@ +headTitle($this->config->title->site); +$this->headTitle($this->config->title->data); +$this->headTitle()->setSeparator(' - '); +$this->headLink()->appendStylesheet('/css/water.css'); +$this->nav[] = array('link'=>"/glacier",'title'=>$this->config->title->glacier); +?> +render('breadcrumbs.phtml'); ?> +
      +
      + partial('glacier/navi.phtml'); ?> +
      +
      + info) : ?> +
      + info['body'])) echo $this->info['body'];?> +
      + + metadata) : ?> + page->getNavigation(); ?> +
      +
        + metadata as $md) : ?> +
      1. + +
      +
      + +
      +
      \ No newline at end of file diff --git a/application/default/views/scripts/glacier/browse.phtml b/application/default/views/scripts/glacier/browse.phtml index 1825019c..3d2cb3b8 100755 --- a/application/default/views/scripts/glacier/browse.phtml +++ b/application/default/views/scripts/glacier/browse.phtml @@ -11,10 +11,10 @@ $this->breadcrumb('浏览'); $this->breadcrumb()->setSeparator(' > '); ?>
      -
      +
      partial('glacier/navi.phtml'); ?>
      -
      +
      page->getNavigation(); ?>
      diff --git a/application/default/views/scripts/glacier/category.phtml b/application/default/views/scripts/glacier/category.phtml deleted file mode 100755 index e30bde12..00000000 --- a/application/default/views/scripts/glacier/category.phtml +++ /dev/null @@ -1,43 +0,0 @@ -headTitle($this->config->title->site); - $this->headTitle($this->config->title->data); -$this->headTitle('分类浏览'); -if (!empty($this->codename)) $this->headTitle($this->codename); -$this->headTitle()->setSeparator(' - '); -$this->headLink()->appendStylesheet('/css/water.css'); -$this->breadcrumb('首页'); -$this->breadcrumb(''.$this->config->title->data.''); -$this->breadcrumb(''.$this->config->title->glacier.''); -$this->breadcrumb('分类浏览:'.$this->codename); -$this->breadcrumb()->setSeparator(' > '); -?> -
      -
      - partial('glacier/navi.phtml'); ?> -
      -
      - - - metadata)) : ?> -
      - page->getNavigation(); ?> -
      -
      -
        - metadata as $md) : ?> -
      1. - -
      -
      -
      - page->getNavigation(); ?> -
      - -
      -
      \ No newline at end of file diff --git a/application/default/views/scripts/glacier/everestnorth.phtml b/application/default/views/scripts/glacier/everestnorth.phtml deleted file mode 100644 index 1d531234..00000000 --- a/application/default/views/scripts/glacier/everestnorth.phtml +++ /dev/null @@ -1,33 +0,0 @@ -headTitle($this->config->title->site); -$this->headTitle($this->config->title->data); -$this->headTitle()->setSeparator(' - '); -$this->headLink()->appendStylesheet('/css/water.css'); -$this->breadcrumb('首页'); -$this->breadcrumb(''.$this->config->title->data.''); -$this->breadcrumb(''.$this->config->title->glacier.''); -$this->breadcrumb('珠穆朗玛峰北坡'); -$this->breadcrumb()->setSeparator(' > '); -?> - - - diff --git a/application/default/views/scripts/glacier/field.phtml b/application/default/views/scripts/glacier/field.phtml deleted file mode 100644 index 1f18f4de..00000000 --- a/application/default/views/scripts/glacier/field.phtml +++ /dev/null @@ -1,33 +0,0 @@ -headTitle($this->config->title->site); -$this->headTitle($this->config->title->data); -$this->headTitle()->setSeparator(' - '); -$this->headLink()->appendStylesheet('/css/water.css'); -$this->breadcrumb('首页'); -$this->breadcrumb(''.$this->config->title->data.''); -$this->breadcrumb(''.$this->config->title->glacier.''); -$this->breadcrumb('冰湖编目数据'); -$this->breadcrumb()->setSeparator(' > '); -?> -
      -
      - partial('glacier/navi.phtml'); ?> -
      -
      -
      -

      为了对冰川编目结果进行验证并获得更多的冰川环境信息,项目开展了大量的野外考察。考察范围包括:祁连山、昆仑山-唐古拉山、喜马拉雅山、青藏高原腹地冰川考察、黄河源-念青唐古拉山中段北坡-喜马拉雅山中段。考察内容包括GPS测量、冰川厚度测量、冰川区地形摄影测量、冰川物质平衡测量、冰川区气象水文要素测量、冰湖水位和温度测量等。

      - -
      -
      - metadata) : ?> - page->getNavigation(); ?> -
      -
        - metadata as $md) : ?> -
      1. - -
      -
      - -
      -
      \ No newline at end of file diff --git a/application/default/views/scripts/glacier/frozensoil.phtml b/application/default/views/scripts/glacier/frozensoil.phtml deleted file mode 100644 index 8a984fea..00000000 --- a/application/default/views/scripts/glacier/frozensoil.phtml +++ /dev/null @@ -1,33 +0,0 @@ -headTitle($this->config->title->site); -$this->headTitle($this->config->title->data); -$this->headTitle()->setSeparator(' - '); -$this->headLink()->appendStylesheet('/css/water.css'); -$this->breadcrumb('首页'); -$this->breadcrumb(''.$this->config->title->data.''); -$this->breadcrumb(''.$this->config->title->glacier.''); -$this->breadcrumb('冻土数据'); -$this->breadcrumb()->setSeparator(' > '); -?> -
      -
      - partial('glacier/navi.phtml'); ?> -
      -
      -
      -

      与多年冻土相关的测量数据,包括探地雷达测量的地下冰厚度、冻土层上限等。 -

      -
      -
      - metadata) : ?> - page->getNavigation(); ?> -
      -
        - metadata as $md) : ?> -
      1. - -
      -
      - -
      -
      \ No newline at end of file diff --git a/application/default/views/scripts/glacier/geobase.phtml b/application/default/views/scripts/glacier/geobase.phtml deleted file mode 100644 index 72369e3f..00000000 --- a/application/default/views/scripts/glacier/geobase.phtml +++ /dev/null @@ -1,34 +0,0 @@ -headTitle($this->config->title->site); -$this->headTitle($this->config->title->data); -$this->headTitle()->setSeparator(' - '); -$this->headLink()->appendStylesheet('/css/water.css'); -$this->breadcrumb('首页'); -$this->breadcrumb(''.$this->config->title->data.''); -$this->breadcrumb(''.$this->config->title->glacier.''); -$this->breadcrumb('基础数据'); -$this->breadcrumb()->setSeparator(' > '); -?> -
      -
      - partial('glacier/navi.phtml'); ?> -
      -
      -
      -

      基础数据是指用于开展冰川和冰湖编目的遥感影像、地形图和数字地形模型,由于地形图属国家保密数据,不在共享范围内。

      -

      地形图主要用来地第一次冰川编目数据进行校正,并辅助第二次冰川编目中冰川边界和山脊线的判断。冰川编目中使用和参考的地形图约1105幅,其中1:50,000地形图546幅(航摄制图512幅,陆地摄影测量成果15幅,平板仪测绘及其他地图19幅),1:100,000地形图572幅(航摄制图558幅,平板仪测绘及其他地图14幅),另外还参考了1975年左右的MSS遥感数据地形图7幅。

      - -
      -
      - metadata) : ?> - page->getNavigation(); ?> -
      -
        - metadata as $md) : ?> -
      1. - -
      -
      - -
      -
      \ No newline at end of file diff --git a/application/default/views/scripts/glacier/glacier.phtml b/application/default/views/scripts/glacier/glacier.phtml deleted file mode 100644 index b4c70c2c..00000000 --- a/application/default/views/scripts/glacier/glacier.phtml +++ /dev/null @@ -1,33 +0,0 @@ -headTitle($this->config->title->site); -$this->headTitle($this->config->title->data); -$this->headTitle()->setSeparator(' - '); -$this->headLink()->appendStylesheet('/css/water.css'); -$this->breadcrumb('首页'); -$this->breadcrumb(''.$this->config->title->data.''); -$this->breadcrumb(''.$this->config->title->glacier.''); -$this->breadcrumb('冰川编目数据'); -$this->breadcrumb()->setSeparator(' > '); -?> -
      -
      - partial('glacier/navi.phtml'); ?> -
      -
      -
      -

      冰川编目数据:基于遥感影像解译获得的反应我国2005年前后冰川现状的冰川分布图及其基本属性。除了包括中国全境的冰川编目数据外,还包括祁连山、天山、贡嘎山、纳木错流域、长江源区、年楚河流域和珠穆朗玛峰北坡等典型地区的多年代冰川分布数据。 -

      -
      -
      - metadata) : ?> - page->getNavigation(); ?> -
      -
        - metadata as $md) : ?> -
      1. - -
      -
      - -
      -
      \ No newline at end of file diff --git a/application/default/views/scripts/glacier/gongga.phtml b/application/default/views/scripts/glacier/gongga.phtml deleted file mode 100644 index 91f1585c..00000000 --- a/application/default/views/scripts/glacier/gongga.phtml +++ /dev/null @@ -1,33 +0,0 @@ -headTitle($this->config->title->site); -$this->headTitle($this->config->title->data); -$this->headTitle()->setSeparator(' - '); -$this->headLink()->appendStylesheet('/css/water.css'); -$this->breadcrumb('首页'); -$this->breadcrumb(''.$this->config->title->data.''); -$this->breadcrumb(''.$this->config->title->glacier.''); -$this->breadcrumb('贡嘎山'); -$this->breadcrumb()->setSeparator(' > '); -?> - - - diff --git a/application/default/views/scripts/glacier/gps.phtml b/application/default/views/scripts/glacier/gps.phtml deleted file mode 100644 index 9f86e3f2..00000000 --- a/application/default/views/scripts/glacier/gps.phtml +++ /dev/null @@ -1,33 +0,0 @@ -headTitle($this->config->title->site); -$this->headTitle($this->config->title->data); -$this->headTitle()->setSeparator(' - '); -$this->headLink()->appendStylesheet('/css/water.css'); -$this->breadcrumb('首页'); -$this->breadcrumb(''.$this->config->title->data.''); -$this->breadcrumb(''.$this->config->title->glacier.''); -$this->breadcrumb('GPS测量数据'); -$this->breadcrumb()->setSeparator(' > '); -?> -
      -
      - partial('glacier/navi.phtml'); ?> -
      -
      -
      -

      采用高精度GPS设备在冰川表面或周边地区测量获得的数据,可用来获得冰川高程信息,也可与以前的观测数据相比较获得冰川流动和物质平衡变化信息。

      - -
      -
      - metadata) : ?> - page->getNavigation(); ?> -
      -
        - metadata as $md) : ?> -
      1. - -
      -
      - -
      -
      \ No newline at end of file diff --git a/application/default/views/scripts/glacier/hydro.phtml b/application/default/views/scripts/glacier/hydro.phtml deleted file mode 100644 index 8e50adcd..00000000 --- a/application/default/views/scripts/glacier/hydro.phtml +++ /dev/null @@ -1,33 +0,0 @@ -headTitle($this->config->title->site); -$this->headTitle($this->config->title->data); -$this->headTitle()->setSeparator(' - '); -$this->headLink()->appendStylesheet('/css/water.css'); -$this->breadcrumb('首页'); -$this->breadcrumb(''.$this->config->title->data.''); -$this->breadcrumb(''.$this->config->title->glacier.''); -$this->breadcrumb('水文数据'); -$this->breadcrumb()->setSeparator(' > '); -?> -
      -
      - partial('glacier/navi.phtml'); ?> -
      -
      -
      -

      在冰川下游观测获得的水文数据,观测要素包括径流、水质和水文化学等,也包括部分冰湖的观测数据。

      - -
      -
      - metadata) : ?> - page->getNavigation(); ?> -
      -
        - metadata as $md) : ?> -
      1. - -
      -
      - -
      -
      \ No newline at end of file diff --git a/application/default/views/scripts/glacier/index.phtml b/application/default/views/scripts/glacier/index.phtml index 0592ae59..f6fe0be2 100755 --- a/application/default/views/scripts/glacier/index.phtml +++ b/application/default/views/scripts/glacier/index.phtml @@ -3,73 +3,20 @@ $this->headTitle($this->config->title->site); $this->headTitle($this->config->title->data); $this->headTitle()->setSeparator(' - '); $this->headLink()->appendStylesheet('/css/water.css'); -$this->breadcrumb('首页'); -$this->breadcrumb(''.$this->config->title->data.''); -$this->breadcrumb($this->config->title->glacier); -$this->breadcrumb()->setSeparator(' > '); +$this->nav[] = array('link'=>"/glacier",'title'=>$this->config->title->glacier); ?> +render('breadcrumbs.phtml'); ?>
      -
      - partial('glacier/navi.phtml'); ?> +
      + partial('glacier/navi.phtml'); ?>
      -
      + +
      -

      “中国冰川资源及其变化调查”项目简介

      -

      - 冰川是最敏感、最直接、最易于辩识、长纪录、高分辨的气候变化信息指示器和储存体,冰川变化信息是全球变化中的重要基础性资源。我国是中、低纬度山 地冰川面积最多的国家(占52%),是两极冰盖之外最重要的冰川集结地,冰川变化信息的挖掘、调查、监测、编目是十分重要的基础性工作。 -

      -

      - 始于1978年的第一次冰川编目历时24年,查清了截止到第一次全国航空测量时(西部冰川区约为1960s-1980s)中国冰川资源的基本情况。第一次冰川清查工作在国际和国内产生了重大影响,被国际冰川学会主席誉为建立了一座“冰川和气候变化研究的金矿”。 - 本次冰川资源调查是在中国科技部和中国科学院的联合支持下开展的一次大规模冰川普查,其目标以第一次冰川编目为参考,以2005-2006年为现状 年,以高分辨率遥感数据与地理信息系统技术为基础,深入研究基于遥感的冰川制图方法,结合冰川野外考察考察,获取我国冰川的分布状况,对有观测历史的典型 冰川进行重点监测;并与第一次冰川编目数据进行比较,查明我国冰川资源变化情况;同时,以此调查数据为基础,综合定位监测与相关资料,评估冰川变化对水资 源的影响,为西部水资源开发利用提供决策依据 。 -

      -

      《中国冰川资源及其变化调查》主要研究内容

      -
        -
      1. 第一次冰川编目的数字化:重点开展第一次冰川编目时期冰川及冰湖分布的数字化,为冰川遥感监测提供基础数据。
      2. -
      3. 现状年(2005-2006年)西北干旱区和其它典型区冰川(湖)分布遥感调查:重点开展现状年基于高分辨率遥感影像的冰川与冰湖分布调查,同时,开展研究区部分冰川表面高程和运动速度信息的提取。
      4. -
      5. 遥感冰川制图地面验证、典型冰川厚度测量与冰川变化野外调查:重点开展代表性区域野外调查和典型冰川定位观测,验证遥感解译结果,获取典型监测冰川过程观测数据;开展代表性冰川厚度的雷达测量。
      6. -
      7. 冰川变化对水资源的影响评估:以现有定位观测冰川和区域冰川变化遥感调查数据为基础,评估西北干旱区和其它典型区冰川变化特征及其对水资源的影响。
      8. -
      9. 冰川资源及其变化调查信息共享平台建设:建立冰川资源管理及共享信息系统,为资源共享服务。
      10. -
      -

      《西部冰川变化监测及其影响评估方法研究》主要研究内容

      -
        -
      1. 各类冰川参数的遥感提取方法研究:针对西部三类冰川特点,综合运用现有卫星遥感数据,建立冰川几何尺寸、特征要素、物理特征、表面高程等信息的提取算法,为大范围冰川调查提供适合各类冰川下垫面状况和气候条件的参数提取方法集,提高遥感获取冰川信息的自动化程度。
      2. -
      3. 冰川储量估算与冰川参数遥感提取精度评估:研制或改进冰川厚度测量雷达,对不同类型典型冰川流域不同规模的代表性冰川进行冰川厚度测量,建立适 合不同规模冰川的储量计算公式;开展各典型监测冰川区遥感冰川制图的野外验证、控制点采集与冰川变化的调查,进行遥感提取参数的误差分析与方法验证研究。
      4. -
      5. 流域冰川融水径流估算方法研究:以典型监测冰川长期观测资料为基础,并进行加强观测,同时收集流域出山口径流长期水文气象观测数据,建立适合不同资料条件的简单和复杂冰川融水径流模型,在对比分析基础上,提出适合西部流域尺度的冰川融水径流计算方案。
      6. -
      7. 冰川变化对水资源影响的评估方法及其应用研究:分析典型冰川流域冰川变化的空间特征及其差异;以典型冰川融水径流过程和流域尺度冰川动力响应研 究为基础,研究不同融水径流计算方案、基于冰川动力响应和基于冰川几何尺度转换关系模型对于不同性质冰川流域融水径流年际变化的模拟能力;根据流域融水径 流模型集,剖析冰川变化对冰川径流临界转变的影响及其强度。
      8. -
      +

      info['title'])) echo $this->info['title']; ?>

      +
      + +
      info['body'])) echo $this->info['body'];?>
      -
      - \ No newline at end of file diff --git a/application/default/views/scripts/glacier/inventory.phtml b/application/default/views/scripts/glacier/inventory.phtml deleted file mode 100644 index 96ad5eeb..00000000 --- a/application/default/views/scripts/glacier/inventory.phtml +++ /dev/null @@ -1,35 +0,0 @@ -headTitle($this->config->title->site); -$this->headTitle($this->config->title->data); -$this->headTitle()->setSeparator(' - '); -$this->headLink()->appendStylesheet('/css/water.css'); -$this->breadcrumb('首页'); -$this->breadcrumb(''.$this->config->title->data.''); -$this->breadcrumb(''.$this->config->title->glacier.''); -$this->breadcrumb('冰川冰湖编目数据'); -$this->breadcrumb()->setSeparator(' > '); -?> -
      -
      - partial('glacier/navi.phtml'); ?> -
      -
      -
      -

      冰川编目数据:基于遥感影像解译获得的反应我国2005年前后冰川现状的冰川分布图及其基本属性。除了包括中国全境的冰川编目数据外,还包括祁连山、天山、贡嘎山、纳木错流域、长江源区、年楚河流域和珠穆朗玛峰北坡等典型地区的多年代冰川分布数据。 -

      -

      冰湖编目数据: - 冰湖是指在冰川前端、表面或内部形成的湖泊。冰湖编目是指利用地形图和遥感数据等资料对位于冰川前端和表面的湖泊进行登记的调查行为。

      -
      -
      - metadata) : ?> - page->getNavigation(); ?> -
      -
        - metadata as $md) : ?> -
      1. - -
      -
      - -
      -
      \ No newline at end of file diff --git a/application/default/views/scripts/glacier/lake.phtml b/application/default/views/scripts/glacier/lake.phtml deleted file mode 100644 index 20156b61..00000000 --- a/application/default/views/scripts/glacier/lake.phtml +++ /dev/null @@ -1,34 +0,0 @@ -headTitle($this->config->title->site); -$this->headTitle($this->config->title->data); -$this->headTitle()->setSeparator(' - '); -$this->headLink()->appendStylesheet('/css/water.css'); -$this->breadcrumb('首页'); -$this->breadcrumb(''.$this->config->title->data.''); -$this->breadcrumb(''.$this->config->title->glacier.''); -$this->breadcrumb('冰湖编目数据'); -$this->breadcrumb()->setSeparator(' > '); -?> -
      -
      - partial('glacier/navi.phtml'); ?> -
      -
      -
      -

      冰湖编目数据: - 冰湖是指在冰川前端、表面或内部形成的湖泊。冰湖编目是指利用地形图和遥感数据等资料对位于冰川前端和表面的湖泊进行登记的调查行为。

      - -
      -
      - metadata) : ?> - page->getNavigation(); ?> -
      -
        - metadata as $md) : ?> -
      1. - -
      -
      - -
      -
      \ No newline at end of file diff --git a/application/default/views/scripts/glacier/lidar.phtml b/application/default/views/scripts/glacier/lidar.phtml deleted file mode 100644 index 4086d158..00000000 --- a/application/default/views/scripts/glacier/lidar.phtml +++ /dev/null @@ -1,35 +0,0 @@ -headTitle($this->config->title->site); -$this->headTitle($this->config->title->data); -$this->headTitle()->setSeparator(' - '); -$this->headLink()->appendStylesheet('/css/water.css'); -$this->breadcrumb('首页'); -$this->breadcrumb(''.$this->config->title->data.''); -$this->breadcrumb(''.$this->config->title->glacier.''); -$this->breadcrumb('雷达测厚数据'); -$this->breadcrumb()->setSeparator(' > '); -?> -
      -
      - partial('glacier/navi.phtml'); ?> -
      -
      -
      -

      - 利用冰川测厚雷达获得的反应冰川厚度和冰下地形的野外测量数据,可为冰川厚度分布图和冰下地形图等提供重要的基础资料。同时,利用这些测量资料可以估算冰川的冰储量,为冰川变化响应气候变化提供定量科学依据,而且可以为各种水文模型提供重要的冰下地形参数。 -

      - -
      -
      - metadata) : ?> - page->getNavigation(); ?> -
      -
        - metadata as $md) : ?> -
      1. - -
      -
      - -
      -
      \ No newline at end of file diff --git a/application/default/views/scripts/glacier/material.phtml b/application/default/views/scripts/glacier/material.phtml deleted file mode 100644 index 8b116cc2..00000000 --- a/application/default/views/scripts/glacier/material.phtml +++ /dev/null @@ -1,35 +0,0 @@ -headTitle($this->config->title->site); -$this->headTitle($this->config->title->data); -$this->headTitle()->setSeparator(' - '); -$this->headLink()->appendStylesheet('/css/water.css'); -$this->breadcrumb('首页'); -$this->breadcrumb(''.$this->config->title->data.''); -$this->breadcrumb(''.$this->config->title->glacier.''); -$this->breadcrumb('物质平衡观测数据'); -$this->breadcrumb()->setSeparator(' > '); -?> -
      -
      - partial('glacier/navi.phtml'); ?> -
      -
      -
      -

      - 冰川在一定时间内的物质变化即积累与消融之差。积累大于消融为正平衡,消融大于积累为负平衡。冰川物质平衡野外观测一般包括利用雪坑剖面观测冰川积累量和花杆观测冰川消融量。 -

      - -
      -
      - metadata) : ?> - page->getNavigation(); ?> -
      -
        - metadata as $md) : ?> -
      1. - -
      -
      - -
      -
      \ No newline at end of file diff --git a/application/default/views/scripts/glacier/meteo.phtml b/application/default/views/scripts/glacier/meteo.phtml deleted file mode 100644 index 9ff309a7..00000000 --- a/application/default/views/scripts/glacier/meteo.phtml +++ /dev/null @@ -1,33 +0,0 @@ -headTitle($this->config->title->site); -$this->headTitle($this->config->title->data); -$this->headTitle()->setSeparator(' - '); -$this->headLink()->appendStylesheet('/css/water.css'); -$this->breadcrumb('首页'); -$this->breadcrumb(''.$this->config->title->data.''); -$this->breadcrumb(''.$this->config->title->glacier.''); -$this->breadcrumb('气象数据'); -$this->breadcrumb()->setSeparator(' > '); -?> -
      -
      - partial('glacier/navi.phtml'); ?> -
      -
      -
      -

      在冰川区观测的气象数据,观测要素包括温度、风速、风向、降水等。受观测条件的限制,观测要素和观测时段不能保持完全一致。

      - -
      -
      - metadata) : ?> - page->getNavigation(); ?> -
      -
        - metadata as $md) : ?> -
      1. - -
      -
      - -
      -
      \ No newline at end of file diff --git a/application/default/views/scripts/glacier/movement.phtml b/application/default/views/scripts/glacier/movement.phtml deleted file mode 100644 index 4425b6bf..00000000 --- a/application/default/views/scripts/glacier/movement.phtml +++ /dev/null @@ -1,33 +0,0 @@ -headTitle($this->config->title->site); -$this->headTitle($this->config->title->data); -$this->headTitle()->setSeparator(' - '); -$this->headLink()->appendStylesheet('/css/water.css'); -$this->breadcrumb('首页'); -$this->breadcrumb(''.$this->config->title->data.''); -$this->breadcrumb(''.$this->config->title->glacier.''); -$this->breadcrumb('冰川运动数据'); -$this->breadcrumb()->setSeparator(' > '); -?> -
      -
      - partial('glacier/navi.phtml'); ?> -
      -
      -
      -

      冰川运动观测一般分为冰川表面运动观测和冰川内部运动观测。前者一般采用GPS和花杆等测量方法,后者一般采用挖坑法、冰隧道法和钻孔法。 -

      -
      -
      - metadata) : ?> - page->getNavigation(); ?> -
      -
        - metadata as $md) : ?> -
      1. - -
      -
      - -
      -
      \ No newline at end of file diff --git a/application/default/views/scripts/glacier/namco.phtml b/application/default/views/scripts/glacier/namco.phtml deleted file mode 100644 index b9c72707..00000000 --- a/application/default/views/scripts/glacier/namco.phtml +++ /dev/null @@ -1,33 +0,0 @@ -headTitle($this->config->title->site); -$this->headTitle($this->config->title->data); -$this->headTitle()->setSeparator(' - '); -$this->headLink()->appendStylesheet('/css/water.css'); -$this->breadcrumb('首页'); -$this->breadcrumb(''.$this->config->title->data.''); -$this->breadcrumb(''.$this->config->title->glacier.''); -$this->breadcrumb('纳木错流域'); -$this->breadcrumb()->setSeparator(' > '); -?> - - - diff --git a/application/default/views/scripts/glacier/navi.phtml b/application/default/views/scripts/glacier/navi.phtml index d0a577ee..24d80aeb 100644 --- a/application/default/views/scripts/glacier/navi.phtml +++ b/application/default/views/scripts/glacier/navi.phtml @@ -70,13 +70,6 @@
      -
      - - + \ No newline at end of file diff --git a/application/default/views/scripts/glacier/tianshan.phtml b/application/default/views/scripts/glacier/tianshan.phtml deleted file mode 100644 index 51b4b6f6..00000000 --- a/application/default/views/scripts/glacier/tianshan.phtml +++ /dev/null @@ -1,33 +0,0 @@ -headTitle($this->config->title->site); -$this->headTitle($this->config->title->data); -$this->headTitle()->setSeparator(' - '); -$this->headLink()->appendStylesheet('/css/water.css'); -$this->breadcrumb('首页'); -$this->breadcrumb(''.$this->config->title->data.''); -$this->breadcrumb(''.$this->config->title->glacier.''); -$this->breadcrumb('天山'); -$this->breadcrumb()->setSeparator(' > '); -?> - - - diff --git a/application/default/views/scripts/glacier/timeline.phtml b/application/default/views/scripts/glacier/timeline.phtml index aca2c805..89c7b4e8 100755 --- a/application/default/views/scripts/glacier/timeline.phtml +++ b/application/default/views/scripts/glacier/timeline.phtml @@ -12,12 +12,14 @@ $this->breadcrumb()->setSeparator(' > '); $this->headScript()->appendFile('/js/timeline_var.js'); $this->headScript()->appendFile('/js/timeline_js/timeline-api.js'); $this->headScript()->appendFile('/js/glaciertime.js'); +$this->nav[] = array('link'=>"/glacier/",'title'=>$this->config->title->glacier); +$this->nav[] = array('link'=>"/glacier/timeline",'title'=>'时间轴导航'); ?>
      -
      +
      partial('glacier/navi.phtml'); ?>
      -
      +
      \ No newline at end of file diff --git a/application/default/views/scripts/glacier/timemap.phtml b/application/default/views/scripts/glacier/timemap.phtml index 77c6ff2c..71a0e216 100644 --- a/application/default/views/scripts/glacier/timemap.phtml +++ b/application/default/views/scripts/glacier/timemap.phtml @@ -14,16 +14,18 @@ $this->theme->AppendPlus($this,'colorbox'); $this->headScript()->appendFile('/js/timeline_var.js'); $this->headScript()->appendFile('/js/timeline_js/timeline-api.js'); $this->headScript()->appendFile('/js/timemap.2.0.1/lib/mxn/mxn.js?(googlev3)'); -$this->headScript()->appendFile('/js/timemap.2.0.1/timemap.pack.js'); +$this->headScript()->appendFile('/js/timemap.2.0.1/timemap.pack.js'); +$this->nav[] = array('link'=>"/glacier/",'title'=>$this->config->title->glacier); +$this->nav[] = array('link'=>"/glaicer/timemap",'title'=>'时空导航'); ?>
      -
      +
      partial('glacier/navi.phtml'); ?>
      -
      +
      breadcrumb() ?>
      diff --git a/application/default/views/scripts/glacier/vegetation.phtml b/application/default/views/scripts/glacier/vegetation.phtml deleted file mode 100644 index 3f2258e0..00000000 --- a/application/default/views/scripts/glacier/vegetation.phtml +++ /dev/null @@ -1,33 +0,0 @@ -headTitle($this->config->title->site); -$this->headTitle($this->config->title->data); -$this->headTitle()->setSeparator(' - '); -$this->headLink()->appendStylesheet('/css/water.css'); -$this->breadcrumb('首页'); -$this->breadcrumb(''.$this->config->title->data.''); -$this->breadcrumb(''.$this->config->title->glacier.''); -$this->breadcrumb('植被数据'); -$this->breadcrumb()->setSeparator(' > '); -?> -
      -
      - partial('glacier/navi.phtml'); ?> -
      -
      -
      -

      冰川区附近的植被分布情况调查 -

      -
      -
      - metadata) : ?> - page->getNavigation(); ?> -
      -
        - metadata as $md) : ?> -
      1. - -
      -
      - -
      -
      \ No newline at end of file diff --git a/application/default/views/scripts/glacier/yangtze.phtml b/application/default/views/scripts/glacier/yangtze.phtml deleted file mode 100644 index ffdd5286..00000000 --- a/application/default/views/scripts/glacier/yangtze.phtml +++ /dev/null @@ -1,33 +0,0 @@ -headTitle($this->config->title->site); -$this->headTitle($this->config->title->data); -$this->headTitle()->setSeparator(' - '); -$this->headLink()->appendStylesheet('/css/water.css'); -$this->breadcrumb('首页'); -$this->breadcrumb(''.$this->config->title->data.''); -$this->breadcrumb(''.$this->config->title->glacier.''); -$this->breadcrumb('长江源区'); -$this->breadcrumb()->setSeparator(' > '); -?> - - - From 9818347102b3c44685c9bfdba57979fb5caf01dd Mon Sep 17 00:00:00 2001 From: wlx Date: Wed, 22 Jan 2014 02:55:07 +0000 Subject: [PATCH 119/173] update glacier theme --- .../views/scripts/glacier/search.phtml | 2 +- .../default/views/scripts/glacier/view.phtml | 187 ++++++++++++------ 2 files changed, 126 insertions(+), 63 deletions(-) diff --git a/application/default/views/scripts/glacier/search.phtml b/application/default/views/scripts/glacier/search.phtml index cafc0c2d..5c16a193 100644 --- a/application/default/views/scripts/glacier/search.phtml +++ b/application/default/views/scripts/glacier/search.phtml @@ -14,12 +14,12 @@ $this->breadcrumb()->setSeparator(' > '); $this->nav[] = array('link'=>"/glacier/",'title'=>$this->config->title->glacier); $this->nav[] = array('link'=>"",'title'=>'快速搜索'); ?> +render('breadcrumbs.phtml'); ?>
      partial('glacier/navi.phtml',array('key'=>$this->key)); ?>
      -
      breadcrumb() ?>
      metadata)) : ?> page->getNavigation(); ?>
      diff --git a/application/default/views/scripts/glacier/view.phtml b/application/default/views/scripts/glacier/view.phtml index fc17c688..bb49bc56 100755 --- a/application/default/views/scripts/glacier/view.phtml +++ b/application/default/views/scripts/glacier/view.phtml @@ -4,32 +4,34 @@ $this->headTitle($this->metadata->title); $this->headTitle()->setSeparator(' - '); $this->headLink()->appendStylesheet('/css/water.css'); - $this->breadcrumb('首页'); - $this->breadcrumb(''.$this->config->title->data.''); - $this->breadcrumb(''.$this->config->title->glacier.''); - $this->breadcrumb('查看元数据'); - $this->breadcrumb()->setSeparator(' > '); - $this->headLink()->appendStylesheet('/css/water.css'); $this->theme->AppendPlus($this,'google_map_v3'); $this->theme->AppendPlus($this,'colorbox'); -?> + if(!empty($this->dataService)) { + $this->theme->AppendModel($this,"dataservice"); + } + $this->nav[] = array('link'=>"/glacier/",'title'=>$this->config->title->glacier); + $this->nav[] = array('link'=>"",'title'=>'查看元数据'); +?> +render('breadcrumbs.phtml'); ?> metadata;if ($md):?>
      -
      +
      partial('glacier/navi.phtml'); ?> -
      -
      -
      breadcrumb() ?>
      +
      +

      escape($md->title); if ($md->title_en) echo '
      '.$this->escape($md->title_en);?>


      - -
      -
      + +
      +

      @@ -37,21 +39,11 @@ if ($md->title_en) echo '
      '.$this->escape($md->title_en);?>

      - citation) : ?> -
      -

      本数据引用方式数据引用帮助

      -

      datadoi) || !strpos($md->citation,$md->datadoi)) : ?>文章的引用 - escape($md->citation);?>

      - datadoi) && !strpos($md->citation,$md->datadoi)) : ?> -

      数据的引用authors,1,-1).'. '.$md->title.'. '.$md->publisher.', '.$md->publish_year.'. doi:'.$md->doi; - echo ' ['.substr($md->author_en,1,-1).'. '.$md->title_en.'. '.$md->publisher_en.', '.$md->publish_year.'. doi:'.$md->doi.']'; - ?> (下载引用:RIS格式 | RIS英文格式 | Bibtex格式 | Bibtex英文格式)

      - ref) : ?> + mcitation) : ?>
      -

      建议参考文献

      +

      本数据要求的多篇文献引用

        - ref as $ref) : + mcitation as $ref) : if (empty($ref->link)) echo '
      1. '.$ref->reference.'
      2. '; else @@ -59,17 +51,78 @@ if ($md->title_en) echo '
        '.$this->escape($md->title_en);?> endforeach; ?>
      - - userref) : ?> + + + citation) : ?>
      -

      数据用户发表文献

      +

      本数据引用方式数据引用帮助

      +

      datadoi) || !strpos($md->citation,$md->datadoi)) : ?>文章的引用 + escape($md->citation);if (strpos($md->citation,$md->datadoi)) : ?> + (下载引用:RIS格式 | RIS英文格式 | Bibtex格式 | Bibtex英文格式) + +

      + datadoi) && !strpos($md->citation,$md->datadoi)) : ?> +

      数据的引用authors,1,-1).'. '.$md->title.'. '.$md->publisher.', '.(empty($md->ts_published)?$md->publish_year:date('Y',strtotime($md->ts_published))).'. doi:'.$md->doi; + echo ' ['.str_replace('"','',substr($md->author_en,1,-1)).'. '.$md->title_en.'. '.$md->publisher_en.', '.(empty($md->ts_published)?$md->publish_year:date('Y',strtotime($md->ts_published))).'. doi:'.$md->doi.']'; + ?> (下载引用:RIS格式 | RIS英文格式 | Bibtex格式 | Bibtex英文格式)

      + ref) : ?> +
      +

      相关文献(作者推荐)

      +
        + ref as $ref) : + echo '
      1. '.$ref->reference; + echo '查看'; + if (empty($ref->link)) + { + if(!empty($ref->attid)) + echo '下载'; + }else{ + echo '下载'; + } + echo "
      2. "; + endforeach; + ?> +
      + themeref) :?> + +
      +

      专题文献

      +
        + themeref as $ref) : + echo '
      1. '.$ref->reference; + echo '查看'; + if (empty($ref->link)) + { + if(!empty($ref->attid)) + echo ' | 下载'; + }else{ + echo ' | 下载'; + } + echo "
      2. "; + endforeach; + ?> +
      + userref) : ?> +
      +

      数据施引文献

        userref as $ref) : + echo '
      1. '.$ref->reference; + echo '查看'; if (empty($ref->link)) - echo '
      2. '.$ref->reference.'
      3. '; - else - echo '
      4. '.$ref->reference.' 下载
      5. '; + { + if(!empty($ref->attid)) + echo '下载'; + }else{ + echo '下载'; + } + echo ""; endforeach; + if (count($this->userref)==15) + { + echo '更多施引文献'; + } ?>
      @@ -83,8 +136,8 @@ if ($md->title_en) echo '
      '.$this->escape($md->title_en);?> ?>

      为尊重知识产权、保障数据作者的权益、扩展数据中心的服务、评估数据的应用潜力,请数据使用者在使用数据所产生的研究成果中(包括公开发表的论文、论著、数据产品和未公开发表的研究报告、数据产品等成果),明确注明数据来源和数据作者。对于转载(二次或多次发布)的数据,作者还须注明原始数据来源。

      -

      中文发表的成果参考以下规范注明: 数据来源于国家自然科学基金委员会"中国西部环境与生态科学数据中心"(http://westdc.westgis.ac.cn)

      -

      英文发表的成果依据以下规范注明: The data set is provided by Environmental and Ecological Science Data Center for West China,National Natural Science Foundation of China (http://westdc.westgis.ac.cn)

      +

      中文发表的成果参考以下规范注明: 数据来源于黑河计划数据管理中心、寒区旱区科学数据中心(http://westdc.westgis.ac.cn)

      +

      英文发表的成果依据以下规范注明: The data set is provided by Cold and Arid Regions Sciences Data Center at Lanzhou (http://westdc.westgis.ac.cn)

      data_archives){ ?> @@ -97,18 +150,18 @@ if ($md->title_en) echo '
      '.$this->escape($md->title_en);?>
      - suppinfo || $this->fund) : ?> -

      资助项目

      - fund)) : ?> -
        - fund as $k=>$v) : ?> -
      • (项目编号:) [(No. )]
      • - -
      - suppinfo)) : ?> - '.str_replace(array("\r\n", "\n", "\r"),'

      ',$this->escape($md->suppinfo)).'

      ';?> - -
      + suppinfo || $this->fund) : ?> +

      资助项目

      + fund)) : ?> +
        + fund as $k=>$v) : ?> +
      • (项目编号:) [(No. )]
      • + +
      + suppinfo)) : ?> + '.str_replace(array("\r\n", "\n", "\r"),'

      ',$this->escape($md->suppinfo)).'

      ';?> + +
      resources) : ?>

      相关资源

      @@ -251,7 +304,7 @@ if ($md->title_en) echo '
      '.$this->escape($md->title_en);?>
      -
      +
      @@ -412,7 +476,7 @@ endforeach;
      -
      +
      @@ -444,6 +508,9 @@ $(function() { googleSearch(''); } }); + $('#show-list').click(function(e) { + method.filelist.get($(this).attr('rel')); + }); }); //ajax literature function literature(page){ @@ -460,10 +527,6 @@ function recommend(page){ recommend_get(page,'uuid; ?>'); } -function getFileList(){ - getFileList_h('uuid;?>'); -} - function ajaxpage(page){ ajaxpage_get(page,'uuid; ?>'); } From 622a0331a5684319e1018ab2b3f7aad223889a7f Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Mon, 27 Jan 2014 08:29:18 +0000 Subject: [PATCH 120/173] fixed a bug about upload folder path --- application/module/Files/Files.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/module/Files/Files.php b/application/module/Files/Files.php index f017d4a5..9ec49a2f 100644 --- a/application/module/Files/Files.php +++ b/application/module/Files/Files.php @@ -151,7 +151,7 @@ class Files{ $msg['file_url'] = $file_url; $msg['file_size'] = $file_size; - $msg['db_path'] = $this->config->upload . $dbsave; + $msg['db_path'] = $dbsave; $msg['realname'] = $file_name; $msg['file_ext'] = $file_ext; $msg['file_mime'] = $this->getFileMime($file_path); From fbd1876e15521f4d1717c2ff7635d372c1d37c25 Mon Sep 17 00:00:00 2001 From: wlx Date: Wed, 29 Jan 2014 04:39:36 +0000 Subject: [PATCH 121/173] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=82=AE=E4=BB=B6?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E6=9B=B4?= =?UTF-8?q?=E7=B2=BE=E5=87=86=E6=8F=90=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controllers/DownController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/admin/controllers/DownController.php b/application/admin/controllers/DownController.php index 4fd47712..a371ca04 100644 --- a/application/admin/controllers/DownController.php +++ b/application/admin/controllers/DownController.php @@ -1375,7 +1375,7 @@ class Admin_DownController extends Zend_Controller_Action $sql = "select distinct u.email from dataorder d LEFT JOIN users u on d.userid = u.id - WHERE u.email IS NOT NULL + WHERE u.email IS NOT NULL and d.status in (0,5) and d.ts_approved is not null AND d.uuid=? GROUP BY u.email"; From 5f2f07207a65d9b871c33044208ba43085d150e3 Mon Sep 17 00:00:00 2001 From: wlx Date: Mon, 17 Feb 2014 03:24:32 +0000 Subject: [PATCH 122/173] change url --- .../default/views/scripts/hiwater/list.phtml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/application/default/views/scripts/hiwater/list.phtml b/application/default/views/scripts/hiwater/list.phtml index f2e67d7b..8f25ebdb 100644 --- a/application/default/views/scripts/hiwater/list.phtml +++ b/application/default/views/scripts/hiwater/list.phtml @@ -5,16 +5,16 @@ $this->headTitle()->setSeparator(' - '); $this->headLink()->appendStylesheet('/css/water.css'); $this->breadcrumb('首页'); $this->breadcrumb(''.$this->config->title->data.''); -$this->breadcrumb(''.$this->config->title->heihe.''); +$this->breadcrumb(''.$this->config->title->hiwater.''); $this->breadcrumb('数据列表'); $this->breadcrumb()->setSeparator(' > '); $this->theme->AppendPlus($this,'colorbox'); ?>
      -
      +
      partial('hiwater/navi.phtml'); ?>
      -
      +
      breadcrumb() ?>
      metadata) : ?> @@ -22,12 +22,12 @@ $this->theme->AppendPlus($this,'colorbox');
        metadata as $md) : ?>
      1. - + [缩略图幻灯片] - [PDF版本下载] - [ODT版本下载] - [DOC版本下载] + [PDF版本下载] + [ODT版本下载] + [DOC版本下载]
      2. From 6c3f3bf0c3d232574dc19ebcae29dc580d8c7c77 Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 21 Feb 2014 08:47:39 +0000 Subject: [PATCH 123/173] =?UTF-8?q?=E8=B5=84=E5=8A=A9=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E4=BB=A5=E7=BC=96=E5=8F=B7=E8=BF=9B=E8=A1=8C=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/default/controllers/HeiheController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/application/default/controllers/HeiheController.php b/application/default/controllers/HeiheController.php index 742b59c1..782b3fa6 100644 --- a/application/default/controllers/HeiheController.php +++ b/application/default/controllers/HeiheController.php @@ -1167,7 +1167,10 @@ class HeiheController extends DataController } } else { //提供全部分类列表 - $sql="select f.id,f.title,f.fund_id,f.fund_type,f.ts_created,count(m.id) as datacount,sum(md.filesize) as filesize from fund f left join mdfund m on f.id=m.fid left join metadata md on m.uuid=md.uuid left join heiheproject hp on f.fund_id=hp.code where hp.id is not null and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') group by f.id,f.title,f.fund_id,f.fund_type,f.ts_created order by f.ts_created desc"; + $sql="select f.id,f.title,f.fund_id,f.fund_type,f.ts_created,count(m.id) as datacount,sum(md.filesize) as filesize + from fund f left join mdfund m on f.id=m.fid left join metadata md on m.uuid=md.uuid left join heiheproject hp on f.fund_id=hp.code + where hp.id is not null and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') + group by f.id,f.title,f.fund_id,f.fund_type,f.ts_created order by f.fund_id asc"; $sth = $this->db->prepare($sql); $sth->execute(); $rows = $sth->fetchAll(); From d57090d5bc2f89d1ae4633e2dde150ebe33e4760 Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 21 Feb 2014 08:48:03 +0000 Subject: [PATCH 124/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BA=95=E9=83=A8?= =?UTF-8?q?=E6=96=87=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/default/views/scripts/footer.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/default/views/scripts/footer.phtml b/application/default/views/scripts/footer.phtml index 9be61fdd..92fd1fcb 100755 --- a/application/default/views/scripts/footer.phtml +++ b/application/default/views/scripts/footer.phtml @@ -1,6 +1,6 @@
        pageID)) {?> From 334403081a832d3427221eb67c4ebb8d41855497 Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 21 Feb 2014 08:48:35 +0000 Subject: [PATCH 125/173] =?UTF-8?q?=E5=9C=A8=E5=85=83=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=B5=8F=E8=A7=88=E4=B8=AD=E5=A2=9E=E5=8A=A0=E8=B5=84=E5=8A=A9?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/default/views/scripts/data/view.phtml | 2 +- application/default/views/scripts/glacier/view.phtml | 2 +- application/default/views/scripts/haihe/view.phtml | 2 +- application/default/views/scripts/heihe/view.phtml | 2 +- application/default/views/scripts/hiwater/view.phtml | 2 +- application/default/views/scripts/water/view.phtml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/application/default/views/scripts/data/view.phtml b/application/default/views/scripts/data/view.phtml index 8ae014c5..210e1f28 100755 --- a/application/default/views/scripts/data/view.phtml +++ b/application/default/views/scripts/data/view.phtml @@ -155,7 +155,7 @@ if ($md->title_en) echo '
        '.$this->escape($md->title_en);?> fund)) : ?>
          fund as $k=>$v) : ?> -
        • (项目编号:) [(No. )]
        • +
        • (项目编号:) [(No. )]
        suppinfo)) : ?> diff --git a/application/default/views/scripts/glacier/view.phtml b/application/default/views/scripts/glacier/view.phtml index bb49bc56..34d9053a 100755 --- a/application/default/views/scripts/glacier/view.phtml +++ b/application/default/views/scripts/glacier/view.phtml @@ -155,7 +155,7 @@ if ($md->title_en) echo '
        '.$this->escape($md->title_en);?> fund)) : ?>
          fund as $k=>$v) : ?> -
        • (项目编号:) [(No. )]
        • +
        • (项目编号:) [(No. )]
        suppinfo)) : ?> diff --git a/application/default/views/scripts/haihe/view.phtml b/application/default/views/scripts/haihe/view.phtml index 303632ab..3eff1e69 100755 --- a/application/default/views/scripts/haihe/view.phtml +++ b/application/default/views/scripts/haihe/view.phtml @@ -156,7 +156,7 @@ if ($md->title_en) echo '
        '.$this->escape($md->title_en);?> fund)) : ?>
          fund as $k=>$v) : ?> -
        • (项目编号:) [(No. )]
        • +
        • (项目编号:) [(No. )]
        suppinfo)) : ?> diff --git a/application/default/views/scripts/heihe/view.phtml b/application/default/views/scripts/heihe/view.phtml index f5a5b84a..d93ac569 100755 --- a/application/default/views/scripts/heihe/view.phtml +++ b/application/default/views/scripts/heihe/view.phtml @@ -158,7 +158,7 @@ if ($md->title_en) echo '
        '.$this->escape($md->title_en);?> fund)) : ?>
          fund as $k=>$v) : ?> -
        • (项目编号:) [(No. )]
        • +
        • (项目编号:) [(No. )]
        suppinfo)) : ?> diff --git a/application/default/views/scripts/hiwater/view.phtml b/application/default/views/scripts/hiwater/view.phtml index 1cf65878..ff449a18 100644 --- a/application/default/views/scripts/hiwater/view.phtml +++ b/application/default/views/scripts/hiwater/view.phtml @@ -163,7 +163,7 @@ if ($md->title_en) echo '
        '.$this->escape($md->title_en);?> fund)) : ?>
          fund as $k=>$v) : ?> -
        • (项目编号:) [(No. )]
        • +
        • (项目编号:) [(No. )]
        suppinfo)) : ?> diff --git a/application/default/views/scripts/water/view.phtml b/application/default/views/scripts/water/view.phtml index a548d2bb..e17dd3e4 100755 --- a/application/default/views/scripts/water/view.phtml +++ b/application/default/views/scripts/water/view.phtml @@ -137,7 +137,7 @@ h3.gs_rt{font-size:110%;} fund)) : ?>
          fund as $k=>$v) : ?> -
        • (项目编号:) [(No. )]
        • +
        • (项目编号:) [(No. )]
        suppinfo)) : ?> From f99e98f2c712d552fe571478c0460b5374fb440c Mon Sep 17 00:00:00 2001 From: wlx Date: Tue, 25 Feb 2014 04:11:54 +0000 Subject: [PATCH 126/173] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E7=82=B9=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/doc.xsl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/data/doc.xsl b/data/doc.xsl index 3414eabc..53882637 100644 --- a/data/doc.xsl +++ b/data/doc.xsl @@ -111,6 +111,10 @@
      3. 结束时间:
      +
        +
      1. 日期:
      2. +
        +
    • 本数据的引用

        From 70eb46f5417e208060bc8936121e3d3d1173255e Mon Sep 17 00:00:00 2001 From: wlx Date: Tue, 25 Feb 2014 04:12:57 +0000 Subject: [PATCH 127/173] =?UTF-8?q?=E4=BF=AE=E6=AD=A3docAction=E5=92=8Codt?= =?UTF-8?q?Action=E4=B8=AD=E6=95=B0=E6=8D=AE=E5=BC=95=E7=94=A8=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E7=9A=84=E9=80=BB=E8=BE=91=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/ServiceController.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/application/default/controllers/ServiceController.php b/application/default/controllers/ServiceController.php index a8301e89..1167a21d 100644 --- a/application/default/controllers/ServiceController.php +++ b/application/default/controllers/ServiceController.php @@ -314,11 +314,8 @@ class ServiceController extends Zend_Controller_Action $citation=$row['mcitation']; } else if ($row['citation']) { - if (empty($row['datadoi'])) - { - $citation=$row['citation']; - } - elseif (!strpos($row['citation'],$row['datadoi'])) + $citation=$row['citation']; + if (!empty($row['datadoi']) && !strpos($row['citation'],$row['datadoi'])) { $citation='
      1. 文章引用:'.$row['citation'].'
      2. '; $citation.="
      3. 数据的引用:"; @@ -722,11 +719,8 @@ class ServiceController extends Zend_Controller_Action $cit=$row['mcitation']; } else if ($row['citation']) { - if (empty($row['datadoi'])) - { - $cit=$row['citation']; - } - elseif (!strpos($row['citation'],$row['datadoi'])) + $cit=$row['citation']; + if (!empty($row['datadoi']) && !strpos($row['citation'],$row['datadoi'])) { $cit='文章引用:'.$row['citation']; $cit.="\r\n数据的引用:"; From a8f0424aa6058972b3a12ceb01e2f23675bf0e4d Mon Sep 17 00:00:00 2001 From: wlx Date: Thu, 27 Feb 2014 07:46:10 +0000 Subject: [PATCH 128/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=A7=94=E5=91=98=E4=BC=9A=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controllers/DownController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/admin/controllers/DownController.php b/application/admin/controllers/DownController.php index a371ca04..82f6f0fa 100644 --- a/application/admin/controllers/DownController.php +++ b/application/admin/controllers/DownController.php @@ -375,8 +375,8 @@ class Admin_DownController extends Zend_Controller_Action $mail->setSubject($mailtp->getSubject()); $addrs=array(); $addrs[] = 'nztong@lzb.ac.cn'; - $addrs[] = 'wjian@lzb.ac.cn'; - $addrs[] = 'lixin@lzb.ac.cn'; + $addrs[] = 'wangliangxu@lzb.ac.cn'; + $addrs[] = 'wulizong@lzb.ac.cn'; $mail->addTo($addrs); $mail->addCc($this->view->config->service->email,'西部数据中心服务组'); $mail->createAttachment($filecontent,'application/octet-stream',Zend_Mime::DISPOSITION_ATTACHMENT, Zend_Mime::ENCODING_BASE64, 'offlineapp.pdf'); From 8a4a5c43866e179c92509ff60d6ba2cf7ebfa0c5 Mon Sep 17 00:00:00 2001 From: wlx Date: Thu, 27 Feb 2014 14:11:54 +0000 Subject: [PATCH 129/173] add DCI action --- .../default/controllers/ServiceController.php | 52 ++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/application/default/controllers/ServiceController.php b/application/default/controllers/ServiceController.php index 1167a21d..426c0ccb 100644 --- a/application/default/controllers/ServiceController.php +++ b/application/default/controllers/ServiceController.php @@ -1805,6 +1805,54 @@ class ServiceController extends Zend_Controller_Action public function jsonexit($data){ $this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(json_encode($data,JSON_NUMERIC_CHECK)); return true; - } - + } + + public function dciAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + //must have doi to output dci + $uuid=$this->_request->getParam('uuid'); + + $xml=' + + +
        + '.date("Y-m-d").' + Cold and Arid Regions Science Data Center at Lanzhou + CARD-WDS + '.$uuid.' +
        + + '; + + $sql="select title_en,doi,author_en,ts_published from datadoi where uuid=".$this->db->quote($uuid); + $row=$this->db->fetchRow($sql); + $authors=explode(',',str_replace('"','',substr($row['author_en'],1,-1))); + $i=0; + foreach($authors as $a) + { + $i=$i+1; + $xml.=''; + $xml.=''.$a.''; + } + $xml.=' + + + '.$row['title_en'].' + + + http://card.westgis.ac.cn/data/'.$uuid.' + CARD + '.date('Y',strtotime($row['ts_published'])).' + + + English + + +
        +
        '; + $this->getResponse()->setHeader('Content-Type', 'text/xml') + ->setBody($xml); + } } From 7a9d11a977c9c73e1c4d6f641f7506776d3ef993 Mon Sep 17 00:00:00 2001 From: wlx Date: Mon, 3 Mar 2014 13:34:19 +0000 Subject: [PATCH 130/173] add elements to dci --- .../default/controllers/ServiceController.php | 50 +++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/application/default/controllers/ServiceController.php b/application/default/controllers/ServiceController.php index 426c0ccb..eede4257 100644 --- a/application/default/controllers/ServiceController.php +++ b/application/default/controllers/ServiceController.php @@ -1826,7 +1826,8 @@ class ServiceController extends Zend_Controller_Action '; - $sql="select title_en,doi,author_en,ts_published from datadoi where uuid=".$this->db->quote($uuid); + $sql="select d.title_en,d.doi,author_en,d.ts_published,m.description,m.timebegin,m.timeend + from datadoi d left join en.normalmetadata m on d.uuid=m.uuid where d.uuid=".$this->db->quote($uuid); $row=$this->db->fetchRow($sql); $authors=explode(',',str_replace('"','',substr($row['author_en'],1,-1))); $i=0; @@ -1839,7 +1840,7 @@ class ServiceController extends Zend_Controller_Action $xml.=' - '.$row['title_en'].' + http://card.westgis.ac.cn/data/'.$uuid.' @@ -1849,7 +1850,50 @@ class ServiceController extends Zend_Controller_Action English - + '; + $xml.=''; + $xml.=''; + $sql="select k.keyword from en.keyword k left join en.normalmetadata m on k.id=m.id where k.keytype='theme' and m.uuid=".$this->db->quote($uuid); + $rowk=$this->db->fetchAll($sql); + $xml.=''; + foreach ($rowk as $k) + { + $xml.=''; + } + $xml.=' + '; + if ($row['timebegin']) + { + $xml.=' + '.date('Y-m-d',strtotime($row['timebegin'])).''; + if ($row['timeend'] && (date('Y-m-d',strtotime($row['timebegin']))!=date('Y-m-d',strtotime($row['timeend'])))) $xml.=' + '.$row['timeend'].''; + $xml.=''; + } + $xml.=''; + $sql="select f.* from fund f left join mdfund mf on f.id=mf.fid where mf.uuid=".$this->db->quote($uuid).' order by mf.place asc'; + $rowf=$this->db->fetchAll($sql); + $xml.=''; + foreach ($rowf as $f) + { + $xml.=' + + '.$f['fund_id'].''.$f['fund_type_en'].' + '; + } + $xml.=''; + $sql="select r.* from reference r left join mdref mr on r.id=mr.refid where mr.reftype=1 and r.language<>'zh' and mr.uuid=".$this->db->quote($uuid).' order by mr.place asc'; + $rowc=$this->db->fetchAll($sql); + $xml.=''; + foreach ($rowc as $c) + { + $xml.=' + '.$c['reference'].''; + if ($c['doi']) + $xml.=''.$c['doi'].''; + $xml.=''; + } + $xml.=' '; $this->getResponse()->setHeader('Content-Type', 'text/xml') From 6ffe628c27f98fdbd9474a763fd42201de262600 Mon Sep 17 00:00:00 2001 From: wlx Date: Mon, 3 Mar 2014 13:37:10 +0000 Subject: [PATCH 131/173] =?UTF-8?q?=E6=8F=90=E5=8D=87=E7=A8=B3=E5=AE=9A?= =?UTF-8?q?=E6=80=A7=E5=92=8C=E6=95=88=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/wsndata.php | 270 ++++++++++++++++++++++++---------------------- 1 file changed, 143 insertions(+), 127 deletions(-) diff --git a/tools/wsndata.php b/tools/wsndata.php index bf74c503..44e093b5 100644 --- a/tools/wsndata.php +++ b/tools/wsndata.php @@ -1,5 +1,8 @@ 0)) { die("Error in parameter."); } - $action=@$_GET['action']; - + $action=@$_GET['action']; + if(!empty($action) && $action=='prepare') { $content="php -f /var/www/ftp2.westgis.ac.cn/wsndata.php $uid"; - $filename='wsndata.sh'; - if (!file_put_contents($filename, $content, LOCK_EX)) - { - sleep(1); - if (!file_put_contents($filename, $content, LOCK_EX)) - { - sleep(1); - if (!file_put_contents($filename, $content, LOCK_EX)) - die("error in write wsndatar.sh"); - } - } - } else { - $sql_user = "SELECT * from users_pm_down where starttime is not null and result=-1 and type='down' and uid=$uid"; - $sth_user = $db->query($sql_user); - $rows_user = $sth_user->fetchAll(); - - //有需要生成的数据 - if(!empty($rows_user)) - { - foreach($rows_user as $k=>$v ) - { + $filename='wsndata.sh'; + if (!file_put_contents($filename, $content, LOCK_EX)) + { + sleep(1); + if (!file_put_contents($filename, $content, LOCK_EX)) + { + sleep(1); + if (!file_put_contents($filename, $content, LOCK_EX)) + die("error in write wsndatar.sh"); + } + } + } else { + $sql_user = "SELECT distinct uid,site,variable,starttime,endtime from users_pm_down where starttime is not null and result=-1 and type='down' and uid=$uid"; + $sth_user = $db->query($sql_user); + $rows_user = $sth_user->fetchAll(); + + //有需要生成的数据 + if($rows_user) + { + foreach($rows_user as $k=>$v ) + { //逐个生成 $site = $v['site']; - $variable = $v['variable']; - $start = $v['starttime']; - $end = $v['endtime']; - $uid = $v['uid']; - //计算有多少天 - $days=round((strtotime($end)-strtotime($start))/3600/24)+1; - //获取观测点的名称 - $sql_site= "SELECT fld_name from tbl_site_info where fld_site_id=$site"; - $sth_site = $db->query($sql_site); - $rows_site = $sth_site->fetch(); - $sitename= $rows_site['fld_name']; - //获取用户的邮箱 - $sql_mail= "SELECT email from users where id=$uid"; - $sth_mail = $db->query($sql_mail); - $rows_mail = $sth_mail->fetch(); - if(empty($rows_mail)) - {$rows_mail['email']=="wuadan@lzb.ac.cn";} - //先为该用户创建一个文件夹 - $aimDir_user=$basepath.'wsn_'.$uid; + $variable = $v['variable']; + $start = date('Y-m-d',strtotime($v['starttime'])); + $end = date('Y-m-d',strtotime($v['endtime'])); + $uid = $v['uid']; + + //计算有多少天 + $days=round((strtotime($end)-strtotime($start))/3600/24)+1; + + //获取观测点的名称 + $sql_site= "SELECT fld_name from tbl_site_info where fld_site_id=$site"; + $sth_site = $db->query($sql_site); + $rows_site = $sth_site->fetch(); + $sitename= $rows_site['fld_name']; + + //先为该用户创建一个文件夹 + $aimDir_user=$basepath.'wsn_'.$uid; if (!file_exists($aimDir_user)) { $result = mkdir($aimDir_user); - } - //在该用户文件夹下面再建立一个观测点文件夹 - $aimDir_site=$aimDir_user.DIRECTORY_SEPARATOR.$site; + } + + //在该用户文件夹下面再建立一个观测点文件夹 + $aimDir_site=$aimDir_user.DIRECTORY_SEPARATOR.$sitename; if (!file_exists($aimDir_site)) { $result = mkdir($aimDir_site); - } - - //选择全部变量 - if($variable==-1) - { + } + + //选择全部变量 + if($variable==-1) + { //获取数据 - for ($i = 1; $i <= $days; $i++) + $sql2= "SELECT v.fld_time as time,v.fld_value as value,va.fld_name as variablename FROM tbl_value v left join tbl_variable_info va on v.fld_variable_id=va.fld_variable_id WHERE v.fld_site_id=$site AND v.fld_time>='$start' AND v.fld_time<'$endtime' ORDER BY time "; + $sth2 = $db->query($sql2); + $rows2 = $sth2->fetchAll(); + $endtime=date("Y-m-d",strtotime($start)+24*3600); + $head = "Time,Variable,Value, \n"; + $html=""; + foreach ($rows2 as $k=>$v) { - $endtime=date("Y-m-d 00:00:00",strtotime($start)+24*3600); - $sql2= "SELECT v.fld_time as time,v.fld_value as value,va.fld_name as variablename FROM tbl_value v left join tbl_variable_info va on v.fld_variable_id=va.fld_variable_id WHERE v.fld_site_id=$site AND v.fld_time>='$start' AND v.fld_time<'$endtime' ORDER BY time "; - - $sth2 = $db->query($sql2); - $rows2 = $sth2->fetchAll(); - $datamount=count( $rows2); //组装数据 - $html=""; - foreach($rows2 as $k=>$v) + if ($v['time']>=$start && $v['time']<$endtime) { - $time[$k] = $v['time']; - $value[$k] = $v['value']; - $var[$k] = $v['variablename']; - $html .=$time[$k].",".$var[$k].",".$value[$k]."\n"; - } - - $head = "Time,Variable,Value, \n"; - - //将数据写入文件 - $resulttime=date("Ymd",strtotime($start)); - - $fp = fopen($aimDir_site.DIRECTORY_SEPARATOR.$sitename."_all_".$resulttime.".CSV","a"); //打开csv文件,如果不存在则创建 - fwrite($fp,$head.$html); //写入数据 - fclose($fp); //关闭文件句柄 - - $start = $endtime; - } + $html.=$v['time'].",".$v['variablename'].",".$v['value']."\n"; + } elseif ($v['time']>=$endtime) { + //写入文件 + $resulttime=date("Ymd",strtotime($start)); + $fp = fopen($aimDir_site.DIRECTORY_SEPARATOR.$sitename."_all_".$resulttime.".CSV","w+"); + fwrite($fp,$head.$html); //写入数据 + fclose($fp); //关闭文件句柄 + $start=$endtime; + $endtime=date("Y-m-d",strtotime($start)+24*3600); + $html=$v['time'].",".$v['variablename'].",".$v['value']."\n"; + } + if ($k==count($rows2)) //last record + { + //写入文件 + $resulttime=date("Ymd",strtotime($start)); + $fp = fopen($aimDir_site.DIRECTORY_SEPARATOR.$sitename."_all_".$resulttime.".CSV","w+"); + fwrite($fp,$head.$html); //写入数据 + fclose($fp); //关闭文件句柄 + } + } + print $sitename."\r\n"; $sql_up= "update users_pm_down set result=0 WHERE site=$site and variable=-1 and uid=$uid and result=-1 and type='down'"; - $sth_up = $db->query($sql_up); - } else { - //获取观测变量的名称 + $db->query($sql_up); + } else { + //获取观测变量的名称 $sql3= "SELECT fld_name from tbl_variable_info where fld_variable_id=$variable"; $sth3 = $db->query($sql3); $rows3 = $sth3->fetch(); $varname=$rows3['fld_name']; //获取数据 - $endtime=""; - for ($i = 1; $i <= $days; $i++) + $endtime=date("Y-m-d",strtotime($start)+24*3600); + $sql2= "SELECT v.fld_time as time,v.fld_value as value,va.fld_name as variablename FROM tbl_value v left join tbl_variable_info va on v.fld_variable_id=va.fld_variable_id WHERE v.fld_variable_id=$variable and v.fld_site_id=$site AND v.fld_time>='$start' AND v.fld_time<='$end' ORDER BY time "; + $sth2 = $db->query($sql2); + $rows2 = $sth2->fetchAll(); + $head = "Time,Variable,Value, \n"; + $html=""; + foreach ($rows2 as $k=>$v) { - $endtime=date("Y-m-d H:m:s",strtotime($start)+24*3600); - $sql2= "SELECT v.fld_time as time,v.fld_value as value,va.fld_name as variablename FROM tbl_value v left join tbl_variable_info va on v.fld_variable_id=va.fld_variable_id WHERE v.fld_variable_id =$variable and v.fld_site_id=$site AND v.fld_time>='$start' AND v.fld_time<='$endtime' ORDER BY time "; - - $sth2 = $db->query($sql2); - $rows2 = $sth2->fetchAll(); - $datamount=count( $rows2); //组装数据 - $html=""; - foreach($rows2 as $k=>$v) + if ($v['time']>=$start && $v['time']<$endtime) { - $time[$k] = $v['time']; - $value[$k] = $v['value']; - $var[$k] = $v['variablename']; - $html .=$time[$k].",".$var[$k].",".$value[$k]."\n"; - } - - $head = "Time,Variable,Value, \n"; - //写入文件 - $resulttime=date("Ymd",strtotime($start)); - $fp = fopen($aimDir_site.DIRECTORY_SEPARATOR.$sitename."_".$varname."_".$resulttime.".CSV","a+"); - fwrite($fp,$head.$html); //写入数据 - fclose($fp); //关闭文件句柄 - $start = $endtime; + $html.=$v['time'].",".$v['variablename'].",".$v['value']."\n"; + } elseif ($v['time']>=$endtime) { + //写入文件 + $resulttime=date("Ymd",strtotime($start)); + $fp = fopen($aimDir_site.DIRECTORY_SEPARATOR.$sitename."_".$varname."_".$resulttime.".CSV","w+"); + fwrite($fp,$head.$html); //写入数据 + fclose($fp); //关闭文件句柄 + $start=$endtime; + $endtime=date("Y-m-d",strtotime($start)+24*3600); + $html=$v['time'].",".$v['variablename'].",".$v['value']."\n"; + } + if ($k==count($rows2)) //last record + { + //写入文件 + $resulttime=date("Ymd",strtotime($start)); + $fp = fopen($aimDir_site.DIRECTORY_SEPARATOR.$sitename."_".$varname."_".$resulttime.".CSV","w+"); + fwrite($fp,$head.$html); //写入数据 + fclose($fp); //关闭文件句柄 + } } + print $sitename.'--'.$varname."\r\n"; //给处理的数据做个标记result=0 - $sql_up= "update users_pm_down set result=0 WHERE site=$site and variable=$variable and uid=$uid and result=-1 and type='down'"; - $sth_up = $db->query($sql_up); - } - } - } - } \ No newline at end of file + $sql_up= "update users_pm_down set result=0 WHERE site=$site and variable=$variable and uid=$uid and result=-1 and type='down'"; + $db->query($sql_up); + } + + } + + } + + } From 3db63caac9a95e7a1f06bacd9de355b36b141f41 Mon Sep 17 00:00:00 2001 From: wlx Date: Tue, 4 Mar 2014 16:00:08 +0000 Subject: [PATCH 132/173] change var name --- tools/wsndata.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/wsndata.php b/tools/wsndata.php index 44e093b5..032d2f56 100644 --- a/tools/wsndata.php +++ b/tools/wsndata.php @@ -107,7 +107,7 @@ ini_set('error_log','/tmp/wsn.log'); if($variable==-1) { //获取数据 - $sql2= "SELECT v.fld_time as time,v.fld_value as value,va.fld_name as variablename FROM tbl_value v left join tbl_variable_info va on v.fld_variable_id=va.fld_variable_id WHERE v.fld_site_id=$site AND v.fld_time>='$start' AND v.fld_time<'$endtime' ORDER BY time "; + $sql2= "SELECT v.fld_time as time,v.fld_value as value,va.fld_name as variablename FROM tbl_value v left join tbl_variable_info va on v.fld_variable_id=va.fld_variable_id WHERE v.fld_site_id=$site AND v.fld_time>='$start' AND v.fld_time<'$end' ORDER BY time "; $sth2 = $db->query($sql2); $rows2 = $sth2->fetchAll(); $endtime=date("Y-m-d",strtotime($start)+24*3600); From 06439a430020e26d9570a9503a6ca84c4cec73b7 Mon Sep 17 00:00:00 2001 From: wlx Date: Thu, 6 Mar 2014 07:02:32 +0000 Subject: [PATCH 133/173] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/views/scripts/data/left.phtml | 2 -- application/admin/views/scripts/down/left.phtml | 5 ++--- application/admin/views/scripts/index/index.phtml | 5 ----- application/admin/views/scripts/stat/left.phtml | 8 ++------ application/admin/views/scripts/sys/left.phtml | 3 --- application/admin/views/scripts/user/left.phtml | 1 - 6 files changed, 4 insertions(+), 20 deletions(-) diff --git a/application/admin/views/scripts/data/left.phtml b/application/admin/views/scripts/data/left.phtml index 9f3d6c21..c11dd3f4 100644 --- a/application/admin/views/scripts/data/left.phtml +++ b/application/admin/views/scripts/data/left.phtml @@ -17,7 +17,5 @@
      4. 数据中心通讯管理
      5. 特色推荐
      6. -->
      7. 专题管理
      8. -
      9. 汇交计划
      10. 支持项目
      11. -
      12. DOI
      13. \ No newline at end of file diff --git a/application/admin/views/scripts/down/left.phtml b/application/admin/views/scripts/down/left.phtml index 6ba5d2ab..292331de 100644 --- a/application/admin/views/scripts/down/left.phtml +++ b/application/admin/views/scripts/down/left.phtml @@ -1,9 +1,8 @@ \ No newline at end of file diff --git a/application/admin/views/scripts/index/index.phtml b/application/admin/views/scripts/index/index.phtml index 5e7557ee..eae278e6 100755 --- a/application/admin/views/scripts/index/index.phtml +++ b/application/admin/views/scripts/index/index.phtml @@ -18,11 +18,6 @@ partial('news/left.phtml'); ?> partial('stat/left.phtml'); ?> partial('sys/left.phtml'); ?> -
    • 管理消息
    • 数据FTP测试
    • -
    • 数据恢复进展
    • -
    • 问题数据检查
    • GN地点管理
    • \ No newline at end of file diff --git a/application/admin/views/scripts/user/left.phtml b/application/admin/views/scripts/user/left.phtml index 8086599e..2f62715f 100755 --- a/application/admin/views/scripts/user/left.phtml +++ b/application/admin/views/scripts/user/left.phtml @@ -6,6 +6,5 @@
    • 用户组管理
    • 元数据评审专家库
    • 长时间未登录用户
    • -
    • 数字黑河用户
    • 节日祝贺邮件
    • \ No newline at end of file From 41005148165836e1dd1b71f9d52ccf2fcfda454f Mon Sep 17 00:00:00 2001 From: wlx Date: Thu, 6 Mar 2014 07:32:27 +0000 Subject: [PATCH 134/173] remove unused statstics --- .../admin/controllers/StatController.php | 8 +-- .../admin/views/scripts/stat/index.phtml | 61 +++++++++++++------ .../admin/views/scripts/sys/left.phtml | 1 - 3 files changed, 43 insertions(+), 27 deletions(-) diff --git a/application/admin/controllers/StatController.php b/application/admin/controllers/StatController.php index 9d93243b..4fa24839 100644 --- a/application/admin/controllers/StatController.php +++ b/application/admin/controllers/StatController.php @@ -40,13 +40,7 @@ class Admin_StatController extends Zend_Controller_Action $sql = "select sum(num) as num from (select m.filesize/1024 as num,m.title,d.userid from dataorder d left join metadata m on d.uuid=m.uuid where d.status=0 and m.filesize>0 group by m.title,d.userid,m.filesize) as t"; $res = $this->db->query($sql); $onlinesize = $res->fetch(); - $this->view->onlinesize = $onlinesize; - - $sql="select sum(configvalue::real)/1024/1024/1024 as num from g6ftpusersettings where userid in (select id from g6ftpusers where name like 'westdc%' or name='newwestdc') and configname='StatsDownloaded'"; - $res = $this->db->query($sql); - $onlinesize = $res->fetch(); - $this->view->onlineg6size = $onlinesize; - + $this->view->onlinesize = $onlinesize; }//indexAction 首页 diff --git a/application/admin/views/scripts/stat/index.phtml b/application/admin/views/scripts/stat/index.phtml index 4401f6a7..5d57a7b3 100644 --- a/application/admin/views/scripts/stat/index.phtml +++ b/application/admin/views/scripts/stat/index.phtml @@ -11,19 +11,46 @@ ?>
      partial('stat/left.phtml'); ?> -
        -
      • 概况
      • -
      • 用户总数:stat['alluser']; ?>人
      • -
      • 元数据条数:stat['alldata']; ?>条
      • -
      • 在线数据下载数:stat['onlinedown']; ?>条
      • -
      • 离线数据下载数:stat['offlinedown']; ?>条
      • -
      • 已通过的离线申请:stat['offlinepass']; ?>次
      • -
      • 未完成的离线申请:stat['offlineunfinished']; ?>次
      • -
      • 被拒绝的离线数据:stat['offlinedenied']; ?>条
      • -
      • 有记录的在线下载数:stat['onlineapp']; ?>次
      • -
      +
      +
      概况
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      用户总数:stat['alluser']; ?>人
      元数据条数:stat['alldata']; ?>条
      在线数据下载数:stat['onlinedown']; ?>条
      离线数据下载数:stat['offlinedown']; ?>条
      已通过的离线申请:stat['offlinepass']; ?>次
      未完成的离线申请:stat['offlineunfinished']; ?>次
      被拒绝的离线数据:stat['offlinedenied']; ?>条
      有记录的在线下载数:stat['onlineapp']; ?>次
      +
      +
      数据下载量概况
      @@ -31,23 +58,19 @@ - + - + - + - - - -
      单位:GB
      总下载数据量(估计量,偏大)总下载数据量 allsize['num'],2);?>
      离线下载数据量(从09年4月)离线下载数据量 offlinesize['num'],2);?>
      在线下载数据量(估计量,偏大)在线下载数据量 onlinesize['num'],2);?>
      G6在线下载数据量(精确量)onlineg6size['num'],2);?>
      -
      +
      diff --git a/application/admin/views/scripts/sys/left.phtml b/application/admin/views/scripts/sys/left.phtml index 27a24272..d5c229be 100644 --- a/application/admin/views/scripts/sys/left.phtml +++ b/application/admin/views/scripts/sys/left.phtml @@ -2,6 +2,5 @@

      系统管理

    • 邮件模板管理
    • 管理消息
    • -
    • 数据FTP测试
    • GN地点管理
    • \ No newline at end of file From 325fa858e5ceca9c65bfec7cb351f8a559a7eed2 Mon Sep 17 00:00:00 2001 From: wlx Date: Thu, 6 Mar 2014 07:32:41 +0000 Subject: [PATCH 135/173] remove oauth --- application/default/views/scripts/account/login.phtml | 3 --- 1 file changed, 3 deletions(-) diff --git a/application/default/views/scripts/account/login.phtml b/application/default/views/scripts/account/login.phtml index 9d43984d..1f53d13b 100755 --- a/application/default/views/scripts/account/login.phtml +++ b/application/default/views/scripts/account/login.phtml @@ -39,9 +39,6 @@
      -
      -
      其它账号登录
      -中国科技网通行证
      + + + \ No newline at end of file From 4a0307c1dde015818134a00334e14c94056082d3 Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 21 Mar 2014 01:43:25 +0000 Subject: [PATCH 146/173] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E7=9A=84=E5=90=8D=E7=A7=B0=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/models/ISO19115.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/application/models/ISO19115.php b/application/models/ISO19115.php index 58c4507b..6a349daa 100755 --- a/application/models/ISO19115.php +++ b/application/models/ISO19115.php @@ -209,8 +209,14 @@ class ISO19115 //处理在线资源 if ($this->onlineresource) foreach($this->onlineresource as $resource) { - $sql="insert into onlineresource (uuid,linkage,protocol,name,description) values(?,?,?,?,?)"; - $db->query($sql,array($this->uuid,$resource['linkage'],$resource['protocol'],$resource['name'],$resource['description'])); + if ($resource['name']) + { + $sql="insert into onlineresource (uuid,linkage,protocol,name,description) values(?,?,?,?,?)"; + $db->query($sql,array($this->uuid,$resource['linkage'],$resource['protocol'],$resource['name'],$resource['description'])); + } else { + $sql="insert into onlineresource (uuid,linkage,protocol,description) values(?,?,?,?)"; + $db->query($sql,array($this->uuid,$resource['linkage'],$resource['protocol'],$resource['description'])); + } } //处理缩略图 if (!empty($this->thumbnail)) { From 3ca3469e408624f5736d91494bb31d39301bd0e3 Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 21 Mar 2014 01:45:19 +0000 Subject: [PATCH 147/173] fix var name --- application/models/ISO19115.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/models/ISO19115.php b/application/models/ISO19115.php index 6a349daa..69d4033a 100755 --- a/application/models/ISO19115.php +++ b/application/models/ISO19115.php @@ -209,7 +209,7 @@ class ISO19115 //处理在线资源 if ($this->onlineresource) foreach($this->onlineresource as $resource) { - if ($resource['name']) + if (isset($resource['name']) && resource['name']) { $sql="insert into onlineresource (uuid,linkage,protocol,name,description) values(?,?,?,?,?)"; $db->query($sql,array($this->uuid,$resource['linkage'],$resource['protocol'],$resource['name'],$resource['description'])); From 3f2aa11842945fe5a97a3695f91d91d2939bc090 Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 21 Mar 2014 01:46:29 +0000 Subject: [PATCH 148/173] fix var error --- application/models/ISO19115.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/models/ISO19115.php b/application/models/ISO19115.php index 69d4033a..67e45f0a 100755 --- a/application/models/ISO19115.php +++ b/application/models/ISO19115.php @@ -209,7 +209,7 @@ class ISO19115 //处理在线资源 if ($this->onlineresource) foreach($this->onlineresource as $resource) { - if (isset($resource['name']) && resource['name']) + if (isset($resource['name']) && $resource['name']) { $sql="insert into onlineresource (uuid,linkage,protocol,name,description) values(?,?,?,?,?)"; $db->query($sql,array($this->uuid,$resource['linkage'],$resource['protocol'],$resource['name'],$resource['description'])); From 6618361e630d4f100cff39d0d9256c927154e566 Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 21 Mar 2014 01:58:57 +0000 Subject: [PATCH 149/173] comment error --- application/admin/controllers/DataController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index 2b8ad926..fa720948 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -2641,7 +2641,7 @@ class Admin_DataController extends Zend_Controller_Action { //同步元数据 $iso=new ISO19115(); - $iso->saveDB($this->db,$row['xml']); + @$iso->saveDB($this->db,$row['xml']); //email to admin $mail=new WestdcMailer($this->view->config->smtp); $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); @@ -2667,7 +2667,7 @@ class Admin_DataController extends Zend_Controller_Action unset($mailtp); //email to author $mail=new WestdcMailer($this->view->config->smtp); - $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); + $mail->setFrom($this->view->config->service->email,'数据服务组'); $mailtp=new EmailText($this->db,"version-commit-author",array( 'user' => $user->username, 'uuid' => $row['uuid'], @@ -2721,7 +2721,7 @@ class Admin_DataController extends Zend_Controller_Action unset($mailtp); //email to author $mail=new WestdcMailer($this->view->config->smtp); - $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); + $mail->setFrom($this->view->config->service->email,'数据服务组'); $mailtp=new EmailText($this->db,"version-commit-author",array( 'user' => $user->username, 'uuid' => $row['uuid'], @@ -2787,7 +2787,7 @@ class Admin_DataController extends Zend_Controller_Action //email to admin & author $mail=new WestdcMailer($this->view->config->smtp); - $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); + $mail->setFrom($this->view->config->service->email,'数据服务组'); $mailtp=new EmailText($this->db,"metadata-release",array( 'user' => $user->username, 'uuid' => $row['uuid'], From d35547febf6cf72e801fab4295e24b5a9f261170 Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 21 Mar 2014 02:03:58 +0000 Subject: [PATCH 150/173] set debug on --- application/admin/controllers/DataController.php | 4 ++-- application/models/ISO19115.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index fa720948..2e79888c 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -14,7 +14,7 @@ class Admin_DataController extends Zend_Controller_Action $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 = 1; //1:debug, 0:release $this->debug_email='wangliangxu@lzb.ac.cn'; $this->view->theme = new Theme(); $this->_helper->layout->setLayout('administry'); @@ -2641,7 +2641,7 @@ class Admin_DataController extends Zend_Controller_Action { //同步元数据 $iso=new ISO19115(); - @$iso->saveDB($this->db,$row['xml']); + $iso->saveDB($this->db,$row['xml']); //email to admin $mail=new WestdcMailer($this->view->config->smtp); $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); diff --git a/application/models/ISO19115.php b/application/models/ISO19115.php index 67e45f0a..d41ecad2 100755 --- a/application/models/ISO19115.php +++ b/application/models/ISO19115.php @@ -175,7 +175,7 @@ class ISO19115 //删除所有未用到的responsible数据 $sql="delete from responsible where id not in (select distinct(resid) from role)"; $db->query($sql); - @$this->view->config = Zend_Registry::get('config'); + $this->view->config = Zend_Registry::get('config'); //if (!empty($this->doi)) $row->doi=$this->doi; //生成空白统计数据,可以转移到数据库端处理(todo) From 8d23d7c0c05504e214d498399122366734441c86 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Fri, 21 Mar 2014 02:10:03 +0000 Subject: [PATCH 151/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=82=AE=E7=AE=B1?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/config.ini | 316 ++++++++++++++++++++--------------------- 1 file changed, 158 insertions(+), 158 deletions(-) diff --git a/application/config.ini b/application/config.ini index 80467303..413d0798 100755 --- a/application/config.ini +++ b/application/config.ini @@ -1,158 +1,158 @@ -[general] -db.adapter = PDO_PGSQL -db.params.host = localhost -db.params.username = gis -db.params.password = gispassword -db.params.dbname = metadata - -geonetwork.url=http://www.sanjiangyuan.org.cn/geonetwork/ -geonetwork.adapter = PDO_PGSQL -geonetwork.params.host = localhost -geonetwork.params.username = gis -geonetwork.params.password = gispassword -geonetwork.params.dbname = geonetwork - -google.maps.api=ABQIAAAACD-MqkkoOm60o_dvwdcKVhRBSKpgcP88GYi6r2Of16IkMX_4YhSBQsywCi4J2_fh4nBuWmK7gyRjLg -bing.api=4BC90E1E9ED351ECE0D9FB71509BC3CC1264340C -bigthumb.path=../geonetwork/data/ -temp.path=/tmp/ -upload=../data/upload/ - -paths.newsletter=images/newsletter/ -logging.file = /var/www/test.westgis.ac.cn/data/logs/debug.log -page.limit=10 -import.dir=../data/import -title.site=三江源生态监测综合数据服务平台 -title.data=数据产品与服务 -title.review=数据评审 -title.author=数据作者 -title.knowledge=知识积累 -supportemail=sjydata@126.com -reportemail=westdc-report-subscribe@lists.westgis.ac.cn - -smtp.username=sjydata@126.com -smtp.password=xiningpwd126 -smtp.host=smtp.126.com -smtp.ssl=SSL -smtp.auth=login -smtp.name=数据中心服务组 - -ftp.user=newwestdc -ftp.password=westdcforsmall -download.max=5 //最多同时申请下载个数 -page.max=10 //每页显示条目数 -offline.template=../data/offline.pdf -offline.heihetemplate=../data/heihe.pdf -offline.security=../data/security.pdf -offline.water_template=../data/water_offline.pdf -offline.font=../data/simhei.ttf -offline.savepath=../data/offlineapp -service.email=sjydata@126.com -offline.email.template=../data/offline-email.txt -offline.email.start_template=../data/offline-start-email.txt -offline.email.finish_template=../data/offline-finish-email.txt -offline.email.deny_template=../data/offline-deny-email.txt -register.email.template=../data/register-email.txt -westdc.xsl=../data/ISO19115.xsl - -routes.accout.route = "account/fetchpwd/:login/:key" -routes.accout.defaults.controller = "account" -routes.accout.defaults.action = "fetchpwd" - -routes.tag.route = "data/tag/:key" -routes.tag.defaults.controller = "data" -routes.tag.defaults.action = "tag" - -routes.netkites1.type = "Zend_Controller_Router_Route_Static" -routes.netkites1.route = "knowledge/netkites" -routes.netkites1.defaults.controller = netkites -routes.netkites1.defaults.action = index - -routes.netkites.route = "knowledge/netkites/:action/*" -routes.netkites.defaults.controller = netkites - -routes.dataid.route = "data/:id" -routes.dataid.defaults.controller = "data" -routes.dataid.defaults.action = "view" -routes.dataid.reqs.id = "\d+" - -routes.dataxmluuid.route = "data/xml/:uuid" -routes.dataxmluuid.defaults.controller = "data" -routes.dataxmluuid.defaults.action = "xml" -routes.dataxmluuid.reqs.uuid = "[[:xdigit:]]{8}(-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}" - -routes.datauuid.route = "data/:uuid" -routes.datauuid.defaults.controller = "data" -routes.datauuid.defaults.action = "view" -routes.datauuid.reqs.uuid = "[[:xdigit:]]{8}(-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}" - -routes.datacat.route = "data/category/:code" -routes.datacat.defaults.controller = "data" -routes.datacat.defaults.action = "category" -routes.datacat.reqs.code = "\d+" - -routes.dataseriesplace.route = "data/series/:id/:keyword" -routes.dataseriesplace.defaults.controller = "data" -routes.dataseriesplace.defaults.action = "series" -//routes.dataseries.reqs.code = "\d+" - -routes.dataseries.route = "data/series/:id" -routes.dataseries.defaults.controller = "data" -routes.dataseries.defaults.action = "series" - -routes.wateruuid.route = "water/:uuid" -routes.wateruuid.defaults.controller = "water" -routes.wateruuid.defaults.action = "view" -routes.wateruuid.reqs.uuid = "[[:xdigit:]]{8}(-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}" - -routes.watertag.route = "water/tag/:key" -routes.watertag.defaults.controller = "water" -routes.watertag.defaults.action = "tag" - -routes.mddoc.route = "data/wiki/:title" -routes.mddoc.defaults.controller = "metainfo" -routes.mddoc.defaults.action = "index" - -routes.mdfile.route = "filelist/uuid/:uuid" -routes.mdfile.defaults.controller = "filelist" -routes.mdfile.defaults.action = "index" - -routes.adminofflineapp.route = admin/down/offlineapp/:page -routes.adminofflineapp.defaults.module = admin -routes.adminofflineapp.defaults.controller = down -routes.adminofflineapp.defaults.action = offlineapp -routes.adminofflineapp.defaults.page = 1 -routes.adminofflineapp.reqs.page = \d+ - -routes.admindatasetcd.route = admin/data/datasetcd/:page -routes.admindatasetcd.defaults.module = admin -routes.admindatasetcd.defaults.controller = data -routes.admindatasetcd.defaults.action = datasetcd -routes.admindatasetcd.defaults.page = 1 -routes.admindatasetcd.reqs.page = \d+ - -routes.adminmd.route = admin/data/md/:page -routes.adminmd.defaults.module = admin -routes.adminmd.defaults.controller = data -routes.adminmd.defaults.action = md -routes.adminmd.defaults.page = 1 -routes.adminmd.reqs.page = \d+ - -routes.admincomment.route = admin/data/comment/:page -routes.admincomment.defaults.module = admin -routes.admincomment.defaults.controller = data -routes.admincomment.defaults.action = comment -routes.admincomment.defaults.page = 1 -routes.admincomment.reqs.page = \d+ - -routes.adminoffline.route = admin/data/offline/:page -routes.adminoffline.defaults.module = admin -routes.adminoffline.defaults.controller = data -routes.adminoffline.defaults.action = offline -routes.adminoffline.defaults.page = 1 -routes.adminoffline.reqs.page = \d+ - -routes.news.route = archives/:ptype/:type/:page -routes.news.defaults.controller = archives -routes.news.defaults.action = list -routes.news.defaults.page = 1 +[general] +db.adapter = PDO_PGSQL +db.params.host = localhost +db.params.username = gis +db.params.password = gispassword +db.params.dbname = metadata + +geonetwork.url=http://www.sanjiangyuan.org.cn/geonetwork/ +geonetwork.adapter = PDO_PGSQL +geonetwork.params.host = localhost +geonetwork.params.username = gis +geonetwork.params.password = gispassword +geonetwork.params.dbname = geonetwork + +google.maps.api=ABQIAAAACD-MqkkoOm60o_dvwdcKVhRBSKpgcP88GYi6r2Of16IkMX_4YhSBQsywCi4J2_fh4nBuWmK7gyRjLg +bing.api=4BC90E1E9ED351ECE0D9FB71509BC3CC1264340C +bigthumb.path=../geonetwork/data/ +temp.path=/tmp/ +upload=../data/upload/ + +paths.newsletter=images/newsletter/ +logging.file = /var/www/test.westgis.ac.cn/data/logs/debug.log +page.limit=10 +import.dir=../data/import +title.site=三江源生态监测综合数据服务平台 +title.data=数据产品与服务 +title.review=数据评审 +title.author=数据作者 +title.knowledge=知识积累 +supportemail=sjydata@126.com +reportemail=westdc-report-subscribe@lists.westgis.ac.cn + +smtp.username=sjy@qherc.org +smtp.password=qherc@123 +smtp.host=smtp.exmail.qq.com +smtp.ssl=SSL +smtp.auth=login +smtp.name=三江源生态监测综合数据服务平台 + +ftp.user=newwestdc +ftp.password=westdcforsmall +download.max=5 //最多同时申请下载个数 +page.max=10 //每页显示条目数 +offline.template=../data/offline.pdf +offline.heihetemplate=../data/heihe.pdf +offline.security=../data/security.pdf +offline.water_template=../data/water_offline.pdf +offline.font=../data/simhei.ttf +offline.savepath=../data/offlineapp +service.email=sjydata@126.com +offline.email.template=../data/offline-email.txt +offline.email.start_template=../data/offline-start-email.txt +offline.email.finish_template=../data/offline-finish-email.txt +offline.email.deny_template=../data/offline-deny-email.txt +register.email.template=../data/register-email.txt +westdc.xsl=../data/ISO19115.xsl + +routes.accout.route = "account/fetchpwd/:login/:key" +routes.accout.defaults.controller = "account" +routes.accout.defaults.action = "fetchpwd" + +routes.tag.route = "data/tag/:key" +routes.tag.defaults.controller = "data" +routes.tag.defaults.action = "tag" + +routes.netkites1.type = "Zend_Controller_Router_Route_Static" +routes.netkites1.route = "knowledge/netkites" +routes.netkites1.defaults.controller = netkites +routes.netkites1.defaults.action = index + +routes.netkites.route = "knowledge/netkites/:action/*" +routes.netkites.defaults.controller = netkites + +routes.dataid.route = "data/:id" +routes.dataid.defaults.controller = "data" +routes.dataid.defaults.action = "view" +routes.dataid.reqs.id = "\d+" + +routes.dataxmluuid.route = "data/xml/:uuid" +routes.dataxmluuid.defaults.controller = "data" +routes.dataxmluuid.defaults.action = "xml" +routes.dataxmluuid.reqs.uuid = "[[:xdigit:]]{8}(-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}" + +routes.datauuid.route = "data/:uuid" +routes.datauuid.defaults.controller = "data" +routes.datauuid.defaults.action = "view" +routes.datauuid.reqs.uuid = "[[:xdigit:]]{8}(-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}" + +routes.datacat.route = "data/category/:code" +routes.datacat.defaults.controller = "data" +routes.datacat.defaults.action = "category" +routes.datacat.reqs.code = "\d+" + +routes.dataseriesplace.route = "data/series/:id/:keyword" +routes.dataseriesplace.defaults.controller = "data" +routes.dataseriesplace.defaults.action = "series" +//routes.dataseries.reqs.code = "\d+" + +routes.dataseries.route = "data/series/:id" +routes.dataseries.defaults.controller = "data" +routes.dataseries.defaults.action = "series" + +routes.wateruuid.route = "water/:uuid" +routes.wateruuid.defaults.controller = "water" +routes.wateruuid.defaults.action = "view" +routes.wateruuid.reqs.uuid = "[[:xdigit:]]{8}(-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}" + +routes.watertag.route = "water/tag/:key" +routes.watertag.defaults.controller = "water" +routes.watertag.defaults.action = "tag" + +routes.mddoc.route = "data/wiki/:title" +routes.mddoc.defaults.controller = "metainfo" +routes.mddoc.defaults.action = "index" + +routes.mdfile.route = "filelist/uuid/:uuid" +routes.mdfile.defaults.controller = "filelist" +routes.mdfile.defaults.action = "index" + +routes.adminofflineapp.route = admin/down/offlineapp/:page +routes.adminofflineapp.defaults.module = admin +routes.adminofflineapp.defaults.controller = down +routes.adminofflineapp.defaults.action = offlineapp +routes.adminofflineapp.defaults.page = 1 +routes.adminofflineapp.reqs.page = \d+ + +routes.admindatasetcd.route = admin/data/datasetcd/:page +routes.admindatasetcd.defaults.module = admin +routes.admindatasetcd.defaults.controller = data +routes.admindatasetcd.defaults.action = datasetcd +routes.admindatasetcd.defaults.page = 1 +routes.admindatasetcd.reqs.page = \d+ + +routes.adminmd.route = admin/data/md/:page +routes.adminmd.defaults.module = admin +routes.adminmd.defaults.controller = data +routes.adminmd.defaults.action = md +routes.adminmd.defaults.page = 1 +routes.adminmd.reqs.page = \d+ + +routes.admincomment.route = admin/data/comment/:page +routes.admincomment.defaults.module = admin +routes.admincomment.defaults.controller = data +routes.admincomment.defaults.action = comment +routes.admincomment.defaults.page = 1 +routes.admincomment.reqs.page = \d+ + +routes.adminoffline.route = admin/data/offline/:page +routes.adminoffline.defaults.module = admin +routes.adminoffline.defaults.controller = data +routes.adminoffline.defaults.action = offline +routes.adminoffline.defaults.page = 1 +routes.adminoffline.reqs.page = \d+ + +routes.news.route = archives/:ptype/:type/:page +routes.news.defaults.controller = archives +routes.news.defaults.action = list +routes.news.defaults.page = 1 From 68e445d4ff293fefdb05c55e771f50c3f22fbd86 Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 21 Mar 2014 02:12:03 +0000 Subject: [PATCH 152/173] change config --- application/config.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/config.ini b/application/config.ini index 413d0798..c58652a4 100755 --- a/application/config.ini +++ b/application/config.ini @@ -27,7 +27,7 @@ title.data=数据产品与服务 title.review=数据评审 title.author=数据作者 title.knowledge=知识积累 -supportemail=sjydata@126.com +supportemail=sjy@qherc.org reportemail=westdc-report-subscribe@lists.westgis.ac.cn smtp.username=sjy@qherc.org From 54d6aa8f28515fe9191cc09db32132ad8f15da5b Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 21 Mar 2014 02:14:20 +0000 Subject: [PATCH 153/173] change config --- application/config.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/config.ini b/application/config.ini index c58652a4..0e6385a3 100755 --- a/application/config.ini +++ b/application/config.ini @@ -47,7 +47,7 @@ offline.security=../data/security.pdf offline.water_template=../data/water_offline.pdf offline.font=../data/simhei.ttf offline.savepath=../data/offlineapp -service.email=sjydata@126.com +service.email=sjy@qherc.org offline.email.template=../data/offline-email.txt offline.email.start_template=../data/offline-start-email.txt offline.email.finish_template=../data/offline-finish-email.txt From 45ed720fe37a64d0d51a202cd77d6450c40e2fd5 Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 21 Mar 2014 02:16:27 +0000 Subject: [PATCH 154/173] add new class --- application/models/ISO19115.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/models/ISO19115.php b/application/models/ISO19115.php index d41ecad2..95411588 100755 --- a/application/models/ISO19115.php +++ b/application/models/ISO19115.php @@ -175,6 +175,7 @@ class ISO19115 //删除所有未用到的responsible数据 $sql="delete from responsible where id not in (select distinct(resid) from role)"; $db->query($sql); + $this->view=new \stdClass; $this->view->config = Zend_Registry::get('config'); //if (!empty($this->doi)) $row->doi=$this->doi; From 2b01533e7551816b5b5ce584d5d06f7d4e768dd5 Mon Sep 17 00:00:00 2001 From: Li Heng Date: Fri, 21 Mar 2014 02:43:15 +0000 Subject: [PATCH 155/173] =?UTF-8?q?=09=E5=88=86=E5=B9=B3=E5=8F=B0=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E5=9C=B0=E5=9D=80=E6=9B=B4=E6=94=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/default/views/scripts/index/index.phtml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/application/default/views/scripts/index/index.phtml b/application/default/views/scripts/index/index.phtml index c756d9c3..929ee88f 100755 --- a/application/default/views/scripts/index/index.phtml +++ b/application/default/views/scripts/index/index.phtml @@ -86,7 +86,7 @@
      -

      青海省草原总站

      +

      青海省草原总站

      @@ -113,7 +113,7 @@
      -

      青海省林业调查规划院

      +

      青海省林业调查规划院

      @@ -129,7 +129,7 @@
      -

      青海省水文水资源局

      +

      青海省水文水资源局

      From a14d2319d9868cebe3f2b1008edb3c237f653a8f Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 21 Mar 2014 04:43:15 +0000 Subject: [PATCH 156/173] set debug off --- application/admin/controllers/DataController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index 2e79888c..08c03bae 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -14,7 +14,7 @@ class Admin_DataController extends Zend_Controller_Action $this->view->config = Zend_Registry::get('config'); $this->messenger=$this->_helper->getHelper('FlashMessenger'); $this->view->messages = $this->messenger->getMessages(); - $this->debug = 1; //1:debug, 0:release + $this->debug = 0; //1:debug, 0:release $this->debug_email='wangliangxu@lzb.ac.cn'; $this->view->theme = new Theme(); $this->_helper->layout->setLayout('administry'); From fa9e604755a80b27e65b64c4ad93f50115cac6a9 Mon Sep 17 00:00:00 2001 From: Li Heng Date: Fri, 21 Mar 2014 06:24:33 +0000 Subject: [PATCH 157/173] =?UTF-8?q?=09=E6=B7=BB=E5=8A=A0=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E6=9D=BF=E5=88=A0=E9=99=A4=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controllers/SysController.php | 151 ++++++++++-------- 1 file changed, 81 insertions(+), 70 deletions(-) diff --git a/application/admin/controllers/SysController.php b/application/admin/controllers/SysController.php index b1faf9bc..f3ae2804 100644 --- a/application/admin/controllers/SysController.php +++ b/application/admin/controllers/SysController.php @@ -1,4 +1,6 @@ db->query($sql); + view::Post($this,'模板已删除',-1); + return; + + } + else if($ac=='test'&& !empty($id)) { if(!empty($submit)) @@ -424,10 +435,10 @@ class Admin_SysController extends Zend_Controller_Action if ($ac=='' || $ac=='online') { $sql = "SELECT m.title,m.uuid,ds.host,ds.path, - floor(t.filesize/1024/1024*100)/100 as filesize, - t.filecount from metadata m + floor(t.filesize/1024/1024*100)/100 as filesize, + t.filecount from metadata m LEFT JOIN mdstatus s ON m.uuid=s.uuid - LEFT JOIN dataset ds ON m.uuid=ds.uuid + LEFT JOIN dataset ds ON m.uuid=ds.uuid left join (select dsid,count(id) as filecount,sum(filesize) as filesize from datafile group by dsid) as t on ds.id=t.dsid where s.status>4 and m.datatype=0 and ds.host='ftp1.westgis.ac.cn' ORDER BY m.id DESC"; @@ -440,15 +451,15 @@ class Admin_SysController extends Zend_Controller_Action $paginator->setItemCountPerPage($pages); $paginator->setView($this->view); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml'); - $this->view->paginator=$paginator; + $this->view->paginator=$paginator; $ac='online'; } else if ($ac=='heihe') { $sql = "SELECT m.title,m.uuid,ds.host,ds.path, - floor(t.filesize/1024/1024*100)/100 as filesize, - t.filecount from metadata m + floor(t.filesize/1024/1024*100)/100 as filesize, + t.filecount from metadata m LEFT JOIN mdstatus s ON m.uuid=s.uuid - LEFT JOIN dataset ds ON m.uuid=ds.uuid + LEFT JOIN dataset ds ON m.uuid=ds.uuid left join (select dsid,count(id) as filecount,sum(filesize) as filesize from datafile group by dsid) as t on ds.id=t.dsid left join datasource on datasource.uuid=m.uuid left join source on datasource.sourceid=source.id @@ -466,15 +477,15 @@ class Admin_SysController extends Zend_Controller_Action $this->view->paginator=$paginator; } else if ($ac=='water') { - $sql = "SELECT m.title,m.uuid,ds.host,ds.path, - floor(t.filesize/1024/1024*100)/100 as filesize, - t.filecount from metadata m - LEFT JOIN mdstatus s ON m.uuid=s.uuid - LEFT JOIN dataset ds ON m.uuid=ds.uuid - left join (select dsid,count(id) as filecount,sum(filesize) as filesize from datafile group by dsid) as t on ds.id=t.dsid - left join datasource on datasource.uuid=m.uuid - left join source on datasource.sourceid=source.id - where s.status>4 and m.datatype=1 and ds.host='ftp1.westgis.ac.cn' and source.code='water' + $sql = "SELECT m.title,m.uuid,ds.host,ds.path, + floor(t.filesize/1024/1024*100)/100 as filesize, + t.filecount from metadata m + LEFT JOIN mdstatus s ON m.uuid=s.uuid + LEFT JOIN dataset ds ON m.uuid=ds.uuid + left join (select dsid,count(id) as filecount,sum(filesize) as filesize from datafile group by dsid) as t on ds.id=t.dsid + left join datasource on datasource.uuid=m.uuid + left join source on datasource.sourceid=source.id + where s.status>4 and m.datatype=1 and ds.host='ftp1.westgis.ac.cn' and source.code='water' ORDER BY m.title DESC"; $sth = $this->db->prepare($sql); $sth->execute(); @@ -489,7 +500,7 @@ class Admin_SysController extends Zend_Controller_Action } else if ($ac=='heihe1') { $sql = "SELECT m.title,m.uuid,ds.host,ds.path, - floor(t.filesize/1024/1024*100)/100 as filesize, + floor(t.filesize/1024/1024*100)/100 as filesize, t.filecount from metadata m LEFT JOIN mdstatus s ON m.uuid=s.uuid LEFT JOIN dataset ds ON m.uuid=ds.uuid @@ -511,11 +522,11 @@ class Admin_SysController extends Zend_Controller_Action } else if ($ac=='hiwater') { $sql = "SELECT m.title,m.uuid,ds.host,ds.path, - floor(t.filesize/1024/1024*100)/100 as filesize, + floor(t.filesize/1024/1024*100)/100 as filesize, t.filecount from metadata m LEFT JOIN mdstatus s ON m.uuid=s.uuid LEFT JOIN dataset ds ON m.uuid=ds.uuid - left join (select dsid,count(id) as filecount,sum(filesize) as filesize from datafile group by dsid) as t on ds.id=t.dsid + left join (select dsid,count(id) as filecount,sum(filesize) as filesize from datafile group by dsid) as t on ds.id=t.dsid left join datasource on datasource.uuid=m.uuid left join source on datasource.sourceid=source.id where ds.host='ftp1.westgis.ac.cn' and source.code='hiwater' @@ -533,10 +544,10 @@ class Admin_SysController extends Zend_Controller_Action }else if ($ac=='westee') { $sql = "SELECT m.title,m.uuid,ds.host,ds.path, - floor(t.filesize/1024/1024*100)/100 as filesize, + floor(t.filesize/1024/1024*100)/100 as filesize, t.filecount from metadata m LEFT JOIN mdstatus s ON m.uuid=s.uuid - LEFT JOIN dataset ds ON m.uuid=ds.uuid + LEFT JOIN dataset ds ON m.uuid=ds.uuid left join (select dsid,count(id) as filecount,sum(filesize) as filesize from datafile group by dsid) as t on ds.id=t.dsid where ds.host='ftp1.westgis.ac.cn' and m.uuid in (select uuid from westeemd) ORDER BY m.title DESC"; @@ -553,10 +564,10 @@ class Admin_SysController extends Zend_Controller_Action }else if ($ac=='other') { $sql = "SELECT m.title,m.uuid,ds.host,ds.path, - floor(t.filesize/1024/1024*100)/100 as filesize, + floor(t.filesize/1024/1024*100)/100 as filesize, t.filecount from metadata m LEFT JOIN mdstatus s ON m.uuid=s.uuid - LEFT JOIN dataset ds ON m.uuid=ds.uuid + LEFT JOIN dataset ds ON m.uuid=ds.uuid left join (select dsid,count(id) as filecount,sum(filesize) as filesize from datafile group by dsid) as t on ds.id=t.dsid where ds.host='ftp1.westgis.ac.cn' and m.uuid not in (select uuid from datasource) and m.uuid not in (select uuid from westeemd) ORDER BY m.title DESC"; @@ -573,7 +584,7 @@ class Admin_SysController extends Zend_Controller_Action } $this->view->activeID="btn-".$ac; } - + function problemAction() { $pages=20; @@ -581,7 +592,7 @@ class Admin_SysController extends Zend_Controller_Action if ($ac=='' || $ac=='ref') { $sql = "SELECT m.title,m.uuid,m.citation,g.id as gid from metadata m - LEFT JOIN mdstatus s ON m.uuid=s.uuid + LEFT JOIN mdstatus s ON m.uuid=s.uuid left join geonetworkmetadata g on g.uuid=m.uuid where s.status>4 and m.citation like '%??%' ORDER BY m.id DESC"; @@ -594,16 +605,16 @@ class Admin_SysController extends Zend_Controller_Action $paginator->setItemCountPerPage($pages); $paginator->setView($this->view); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml'); - $this->view->paginator=$paginator; - $this->_helper->viewRenderer('problem-ref'); + $this->view->paginator=$paginator; + $this->_helper->viewRenderer('problem-ref'); $ac='ref'; } else if ($ac=='file') { - $sql = "SELECT m.title,m.uuid,m.filesize,ds.host,ds.path from metadata m - LEFT JOIN mdstatus s ON m.uuid=s.uuid - LEFT JOIN dataset ds ON m.uuid=ds.uuid - where s.status>4 and ds.id not in (select distinct dsid from datafile) - group by m.title,m.uuid,ds.host,ds.path,m.filesize + $sql = "SELECT m.title,m.uuid,m.filesize,ds.host,ds.path from metadata m + LEFT JOIN mdstatus s ON m.uuid=s.uuid + LEFT JOIN dataset ds ON m.uuid=ds.uuid + where s.status>4 and ds.id not in (select distinct dsid from datafile) + group by m.title,m.uuid,ds.host,ds.path,m.filesize ORDER BY m.title DESC;"; $sth = $this->db->prepare($sql); $sth->execute(); @@ -617,18 +628,18 @@ class Admin_SysController extends Zend_Controller_Action $this->view->paginator=$paginator; } else if ($ac=='tiny') { - $sql = "SELECT m.title,m.uuid,ds.host,ds.path, - floor(sum(datafile.filesize)/1024/1024*100)/100 as filesize, - count(datafile.id) as filecount - from metadata m - LEFT JOIN mdstatus s ON m.uuid=s.uuid - LEFT JOIN dataset ds ON m.uuid=ds.uuid - left join datasource on datasource.uuid=m.uuid - left join datafile on ds.id=datafile.dsid - left join source on datasource.sourceid=source.id - where s.status>4 and ds.id in (select t.dsid from (select dsid,count(id) as filecount,sum(filesize) as filesize from datafile group by dsid) as t -where t.filesize<1024*5) - group by m.title,m.uuid,ds.host,ds.path + $sql = "SELECT m.title,m.uuid,ds.host,ds.path, + floor(sum(datafile.filesize)/1024/1024*100)/100 as filesize, + count(datafile.id) as filecount + from metadata m + LEFT JOIN mdstatus s ON m.uuid=s.uuid + LEFT JOIN dataset ds ON m.uuid=ds.uuid + left join datasource on datasource.uuid=m.uuid + left join datafile on ds.id=datafile.dsid + left join source on datasource.sourceid=source.id + where s.status>4 and ds.id in (select t.dsid from (select dsid,count(id) as filecount,sum(filesize) as filesize from datafile group by dsid) as t +where t.filesize<1024*5) + group by m.title,m.uuid,ds.host,ds.path ORDER BY m.title DESC;"; $sth = $this->db->prepare($sql); $sth->execute(); @@ -642,14 +653,14 @@ where t.filesize<1024*5) $this->view->paginator=$paginator; } else if ($ac=='heihefund') { - $sql = "SELECT m.title,m.uuid,g.id as gid - from metadata m - LEFT JOIN mdstatus s ON m.uuid=s.uuid - left join datasource on datasource.uuid=m.uuid - left join source on datasource.sourceid=source.id -left join mdfund mf on mf.uuid=m.uuid -left join geonetworkmetadata g on m.uuid=g.uuid - where s.status>4 and source.code='heihe' and mf.fid is null + $sql = "SELECT m.title,m.uuid,g.id as gid + from metadata m + LEFT JOIN mdstatus s ON m.uuid=s.uuid + left join datasource on datasource.uuid=m.uuid + left join source on datasource.sourceid=source.id +left join mdfund mf on mf.uuid=m.uuid +left join geonetworkmetadata g on m.uuid=g.uuid + where s.status>4 and source.code='heihe' and mf.fid is null ORDER BY m.title DESC;"; $sth = $this->db->prepare($sql); $sth->execute(); @@ -660,19 +671,19 @@ left join geonetworkmetadata g on m.uuid=g.uuid $paginator->setItemCountPerPage($pages); $paginator->setView($this->view); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml'); - $this->view->paginator=$paginator; + $this->view->paginator=$paginator; $this->_helper->viewRenderer('problem-md'); } else if ($ac=='noemail') { - $sql = "SELECT distinct m.title,m.uuid,g.id as gid - from metadata m - LEFT JOIN mdstatus s ON m.uuid=s.uuid -left join role on role.uuid=m.uuid -left join geonetworkmetadata g on m.uuid=g.uuid - where m.datatype=1 and s.status>4 and m.uuid not in ( -select role.uuid from role left join responsible res on role.resid=res.id -where res.email is not null and role.role in ('resourceProvider','owner','pointOfContact','custodian') -) + $sql = "SELECT distinct m.title,m.uuid,g.id as gid + from metadata m + LEFT JOIN mdstatus s ON m.uuid=s.uuid +left join role on role.uuid=m.uuid +left join geonetworkmetadata g on m.uuid=g.uuid + where m.datatype=1 and s.status>4 and m.uuid not in ( +select role.uuid from role left join responsible res on role.resid=res.id +where res.email is not null and role.role in ('resourceProvider','owner','pointOfContact','custodian') +) ORDER BY m.title DESC;"; $sth = $this->db->prepare($sql); $sth->execute(); @@ -683,16 +694,16 @@ where res.email is not null and role.role in ('resourceProvider','owner','pointO $paginator->setItemCountPerPage($pages); $paginator->setView($this->view); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml'); - $this->view->paginator=$paginator; + $this->view->paginator=$paginator; $this->_helper->viewRenderer('problem-md'); } else if ($ac=='unmoved') { - $sql = "SELECT distinct m.title,m.uuid,g.id as gid - from metadata m -LEFT JOIN mdstatus s ON m.uuid=s.uuid -left join geonetworkmetadata g on m.uuid=g.uuid -left join dataset ds on ds.uuid=m.uuid - where s.status>4 and ds.path like '%upload%' + $sql = "SELECT distinct m.title,m.uuid,g.id as gid + from metadata m +LEFT JOIN mdstatus s ON m.uuid=s.uuid +left join geonetworkmetadata g on m.uuid=g.uuid +left join dataset ds on ds.uuid=m.uuid + where s.status>4 and ds.path like '%upload%' ORDER BY m.title DESC;"; $sth = $this->db->prepare($sql); $sth->execute(); @@ -703,7 +714,7 @@ left join dataset ds on ds.uuid=m.uuid $paginator->setItemCountPerPage($pages); $paginator->setView($this->view); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml'); - $this->view->paginator=$paginator; + $this->view->paginator=$paginator; $this->_helper->viewRenderer('problem-md'); } $this->view->activeID="btn-".$ac; From 4678531450562cfba6fae2d44a6595533c692dac Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Fri, 21 Mar 2014 08:23:36 +0000 Subject: [PATCH 158/173] =?UTF-8?q?=E5=BC=80=E5=90=AFdebug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controllers/DataController.php | 8398 ++++++++--------- 1 file changed, 4199 insertions(+), 4199 deletions(-) diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index 08c03bae..0a86b025 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -1,4199 +1,4199 @@ -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() - { - //其他连接 - } - - //提供和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"; - $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=trim($this->_request->getParam('uuid')); - if ($source=="geonetwork" && empty($uuid) ) { - //从geonetwork向WESTDC同步 - //对所有的新数据增加评审状态 - $sql="insert into mdstatus (uuid,status,ts_accepted,userid) select uuid,1,now(),? - from geonetworkmetadata gn where uuid not in (select uuid from mdstatus)"; - $userid = Zend_Auth::getInstance()->getIdentity()->id; - $this->db->query($sql,array($userid)); - $sql="select uuid,data,source 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='e3ad32dc-f573-11e0-aa7b-b768cfd88d80'"; - $sql="delete from metadata where uuid in (select uuid from watergn)"; - $this->db->query($sql); - $sql="delete from responsible where id not in (select distinct(resid) from role)"; - $this->db->query($sql); - //对所有的新数据增加评审状态 - $sql="insert into mdstatus (uuid,status,ts_accepted,userid) select uuid,1,now(),? - from watergn where uuid not in (select uuid from mdstatus)"; - $userid = Zend_Auth::getInstance()->getIdentity()->id; - $this->db->query($sql,array($userid)); - //同步黑河遥感实验的元数据 - $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 ($source=="glacier" && empty($uuid) ) { - //首先删除所有的对应专题数据 - $sql="delete from metadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier')"; - $this->db->query($sql); - $sql="delete from responsible where id not in (select distinct(resid) from role)"; - $this->db->query($sql); - //对所有的新数据增加评审状态 - /*$sql="insert into mdstatus (uuid,status,ts_accepted,userid) select uuid,1,now(),? - from watergn where uuid not in (select uuid from mdstatus)"; - $userid = Zend_Auth::getInstance()->getIdentity()->id; - $this->db->query($sql,array($userid));*/ - //同步专题元数据 - $sql="select uuid,data,source from geonetworkmetadata where schemaid='iso19115' and uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier')"; - $rs=$this->db->fetchAll($sql); - foreach($rs as $gmd) { - $this->import($gmd->data); - //source in unused now. - //$this->db->query("update metadata set source=? where uuid=?",array($gmd->source,$gmd->uuid)); - } - $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); - } - $this->view->msg='成功同步WESTDC元数据到GEONETWORK!'; - } elseif (!empty($uuid) && isset($_POST['gnsubmit'])) { - //同步单条元数据到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).")"; - } - $this->db->exec($sql); - $this->view->msg='成功同步元数据:'.$uuid; - } else $this->view->msg='不存在此元数据:'.$uuid; - } elseif (!empty($uuid) && isset($_POST['watersubmit'])) { - //同步单条元数据 - $sql=$this->db->quoteInto("select data,source from watergn where uuid=?",$uuid); - if ($rs=$this->db->fetchRow($sql)) { - $this->import($rs->data); - $this->db->query("update metadata set source=? where uuid=?",array($rs->source,$uuid)); - $this->view->msg='成功同步元数据:'.$uuid; - } else $this->view->msg='不存在此元数据:'.$uuid; - } elseif ($list=='westdc') { - $sql="select uuid,title from metadata where uuid not in (select uuid from geonetworkmetadata where schemaid='iso19115')"; - $this->view->metadata=$this->db->query($sql); - } elseif ($list=='geonetwork') { - $sql="select id,uuid,(regexp_matches(data,'(.*)'))[1] as title from geonetworkmetadata - where uuid not in (select uuid from metadata)"; - $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=='geonetwork') { - //dblink view中删除多条有问题,暂时用单条删除替代 - //$sql="delete from geonetworkmetadata where uuid not in (select uuid from metadata)"; - $sql="select uuid from geonetworkmetadata where uuid not in (select uuid from metadata)"; - $rows=$this->db->fetchAll($sql); - foreach($rows as $row) - { - $this->db->exec($this->db->quoteInto("delete from geonetworkmetadata where uuid=?",$row->uuid)); - } - $this->view->msg='已删除GEONETWORK中多出的元数据!'; - } 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"; - $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=encode(digest(md5('$row->password'),'sha1'),'hex'),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',encode(digest(md5('$row->password'),'sha1'),'hex'),'$row->email')"; - $this->db->query($sql); - } - } - $this->view->msg='已成功同步帐号!'; - } elseif (!empty($uuid) && (isset($_POST['submit']) || (!isset($_POST['gnsubmit']) && !isset($_POST['watersubmit'])))) { - //同步单条元数据 - $sql=$this->db->quoteInto("select data,source from geonetworkmetadata where uuid=?",$uuid); - if ($rs=$this->db->fetchRow($sql)) { - $this->import($rs->data); - $this->db->exec($this->db->quoteInto("update metadata set source=? where uuid='$uuid'",$rs->source)); - $userid = Zend_Auth::getInstance()->getIdentity()->id; - $this->db->query("insert into mdstatus (uuid,status,ts_accepted,userid) select uuid,1,now(),? - from geonetworkmetadata gn where uuid not in (select uuid from mdstatus) and uuid=?",array($userid,$uuid)); - $this->view->msg='成功同步元数据:'.$uuid; - //update search document - $search=new Search(); - $sql="select * from xunsearch where uuid=?"; - $sth = $this->db->prepare($sql); - $sth->setFetchMode(Zend_Db::FETCH_ASSOC); - $sth->execute(array($uuid)); - $data = $sth->fetch(); - $search->update($data); - - } else $this->view->msg='不存在此元数据:'.$uuid; - } - } - - function datasetcdAction() - { - $add=(int)$this->_getParam('add'); - $edit=(int)$this->_getParam('edit'); - $delete=(int)$this->_getParam('delete'); - set_time_limit(0); - 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; - } - - /* - * - * 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'); - - - if ($delete) - { - $sql="delete from metadata where uuid=?"; - try { - $this->db->query("delete from mdstatus where uuid=?",array($delete)); - $this->db->query("delete from mdauthor where uuid=?",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 normalmetadata 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 metadata 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 metadata 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 '

      数据目录成功导入!

      '; - } else if ($row['host']=='ftp.sanjiangyuan.org.cn') - { - file_get_contents("http://ftp.sanjiangyuan.org.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); - echo '

      数据目录成功导入!

      '; - } else { - echo '

      数据目录未导入!

      '; - } - } - - }//datasetAction存档管理 - - /* - * commentAction() - * 反馈管理 - * ALTER TABLE comments ADD COLUMN reply integer NOT NULL DEFAULT 0; - */ - function commentAction() - { - $delete=(int)$this->_getParam('delete'); - $uuid = $this->_getParam('uuid'); - $reply = $this->_getParam('reply'); - $replylist = $this->_getParam('replylist'); - $delreply = $this->_getParam('delreply'); - - 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"); - } - - if($reply) - { - - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $body = $this->_getParam('content'); - if(empty($body)) - { - $data = array('error'=>"请输入回复内容"); - $this->jsonexit($data); - return true; - } - - $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { - $user = $auth->getIdentity(); - $uid = $user->id; - $email = $user->email; - } - - $ipaddr = $_SERVER['REMOTE_ADDR']; - - $sql = "INSERT INTO comments (uuid,author,reply,userid,content,email,ip) VALUES (?,?,?,?,?,?,?)"; - $sth = $this->db->prepare($sql); - $rs = $sth->execute(array($uuid,$user->username,$reply,$uid,$body,$email,$ipaddr)); - - if($rs) - { - $sql="select c.author,c.email,c.uuid from comments c where c.id=?"; - $sth=$this->db->prepare($sql); - $sth->execute(array($reply)); - $row=$sth->fetch(); - - $mail=new WestdcMailer($this->view->config->smtp); - $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); - $mailtp=new EmailText($this->db,"comment-admin-reply",array( - 'user' => $row['author'], - 'uuid' => $row['uuid'], - 'email'=> $row['email'] - )); - $mail->setBodyText($mailtp->getBody()); - $mail->setSubject($mailtp->getSubject()); - $mail->addTo($row['email']); - $mail->addCc($this->view->config->service->email); - @$mail->send(); - - $data = array('status'=>1,'msg'=>'回复成功!'); - $this->jsonexit($data); - return true; - }else{ - $data = array('error'=>"回复失败,请重试"); - $this->jsonexit($data); - return true; - } - return true; - } - - if($uuid) - { - $sql = "SELECT c.*,md.title,md.uuid FROM comments c - LEFT JOIN metadata md ON md.uuid=c.uuid - WHERE c.uuid=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($uuid)); - $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; - - $sql = "SELECT title FROM metadata WHERE uuid=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($uuid)); - $row = $sth->fetch(); - - $this->view->title = $row['title']; - - return true; - } - - if($replylist) - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $sql = "SELECT cr.id,cr.content as body,cr.reply,u.username,cr.ts_created FROM comments cr - LEFT JOIN users u ON cr.userid=u.id WHERE cr.reply=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($replylist)); - $rows = $sth->fetchAll(); - - $this->jsonexit($rows); - return true; - - } - - if($delreply) - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $sql = "DELETE FROM comments WHERE id=?"; - $sth = $this->db->prepare($sql); - $rs = $sth->execute(array($delreply)); - - if($rs) - { - $this->jsonexit( - array('deleted'=>1) - ); - return true; - }else{ - $this->jsonexit( - array('error'=> '处理中出现错误,请重新尝试') - ); - return true; - } - - - } - - - $sql = "SELECT cm.*,md.title,(SELECT count(id) as counts FROM comments cms WHERE cms.reply=cm.id AND cms.reply!=0) as reply_count FROM comments cm - LEFT JOIN metadata md ON md.uuid=cm.uuid - WHERE cm.reply=0 - ORDER BY cm.ts_created DESC,cm.id DESC"; - - $sth = $this->db->query($sql); - $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; - - }//comment - - - 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'); - $import=(int)$this->_getParam('import'); - $show = $this->_getParam('show'); - - if ($add) { - $type = $this->_getParam('type'); - if($type == 'dc') - { - $this->_helper->viewRenderer('referenceadd'); - $this->view->type = "dc"; - }else{ - $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,reftype) values(?,?,?)"; - $this->db->query($sql,array(trim($formdata['uuid']),$row['id'],$formdata['reftype'])); - $this->messenger->addMessage('提示信息:您已经成功添加该数据文献。'); - $this->_redirect('/admin/data/reference/show/'.$formdata['uuid']); - }else { - $form->populate($formdata); - } - } else { - if ($uuid) - { - $formdata['uuid']=$uuid; - $form->populate($formdata); - } - } - $this->view->form=$form; - $this->_helper->viewRenderer('referenceadd'); - } - } //添加 - - else if($show){ - $sql = "select mr.id as mdid,mr.refid,r.reference,md.title,md.uuid,mr.place FROM mdref mr - left join metadata md on md.uuid=mr.uuid - left join reference r on r.id=mr.refid - where mr.uuid='$show'; - "; - $rs = $this->db->query($sql); - $rows = $rs->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; - - } //按UUID查看 - - elseif ($edit){ - $form=new ReferenceForm(); - if ($this->_request->isPost()) { - $formdata=$this->_request->getPost(); - if ($form->isValid($formdata)) { - $sql="select id from reference where reference=? order by id desc"; - $rs=$this->db->query($sql,array($formdata['reference'])); - $row = $rs->fetch(); - if ($row['id']!='') - { - //更新文献信息 - $sql="update mdref set refid=?,reftype=? where uuid=? and id=?"; - $td = $this->db->query($sql,array($row['id'],$formdata['reftype'],$formdata['uuid'],$edit)); - $sql="update reference set reference=?,link=? where id=?"; - $this->db->query($sql,array($formdata['reference'],$formdata['link'],$row['id'])); - if($td) - { - $this->messenger->addMessage('提示信息:您已经编辑该数据文献。'); - $this->_redirect('/admin/data/reference/show/'.$formdata['uuid']); - } - }else - { - $sql = "INSERT INTO reference (reference,link) VALUES ('".$formdata['reference']."','".$formdata['link']."') RETURNING id"; - $sth = $this->db->prepare($sql); - if($sth->execute()) - { - $row = $sth->fetch(PDO::FETCH_ASSOC); - $sql="update mdref set refid=?,reftype=? where uuid=? and id=?"; - $td = $this->db->query($sql,array($row['id'],$formdata['reftype'],$formdata['uuid'],$edit)); - $this->messenger->addMessage('提示信息:您已经编辑该数据文献。'); - $this->_redirect('/admin/data/reference/show/'.$formdata['uuid']); - }else - { - $this->messenger->addMessage('提示信息:文献创建失败,请重试'); - $this->_redirect('/admin/data/reference/edit/'.$edit); - } - } - } else { - $form->populate($formdata); - } - } else { - $sql="select m.uuid,r.reference,r.link,m.reftype from reference r left join mdref m on r.id=m.refid where m.id=?"; - $formdata=$this->db->fetchRow($sql,array($edit)); - $form->populate($formdata); - } - $this->view->form=$form; - $this->_helper->viewRenderer('referenceadd'); - } //编辑相关文献 - - elseif ($delete) { - $sql = "select uuid from mdref where id=$delete"; - $rs = $this->db->query($sql); - $row = $rs->fetch(); - $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/show/'.$row['uuid']); - } //删除相关文献 - - elseif ($import) { - if ($this->_request->isPost()) { - if ($_FILES["ref"]["error"] == UPLOAD_ERR_OK) { - $tmp_name = $_FILES["ref"]["tmp_name"]; - $fp = fopen($tmp_name, "rb"); - $ref=fread($fp, filesize($tmp_name)); - fclose($fp); - $lines=explode("\n",$ref); - foreach($lines as $line) - { - $data=explode(";",$line); - if (count($data)==2) - $link=''; - else - $link=$data[2]; - $link=$this->db->quote($link); - $sql="insert into reference (reference,link) values(?,".$link.")"; - try { - $this->db->exec($this->db->quoteInto($sql,trim($data[1]))); - } catch (Exception $e) {} - $sql="select id from reference where reference=?"; - $row=$this->db->fetchRow($this->db->quoteInto($sql,trim($data[1]))); - $sql="insert into mdref (uuid,refid) values(?,".$row['id'].")"; - try { - $this->db->exec($this->db->quoteInto($sql,trim($data[0]))); - } catch (Exception $e) {} - } - }//end if - } - $this->_helper->viewRenderer('referenceimport'); - } //引用 - - 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{ - $sql="select m.title as mdtitle,m.uuid,mr.id as mdid,mr.refid,mr.place,r.reference - from mdref mr right join metadata m on mr.uuid=m.uuid - left join reference r on mr.refid=r.id - order by m.ts_created desc,mr.place"; - $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.phtml'); - $this->view->paginator=$paginator; - - }//列表 - } - - //文献管理 - public function refAction() - { - $this->view->ac = $ac = $this->_getParam('ac'); - $submit = $this->_getParam('submit'); - $keyword = $this->view->q = trim($this->_getParam('q')); - $order = $this->view->search_order = trim($this->_getParam('order')); - $sort = $this->view->search_sort = trim($this->_getParam('sort')); - $field = $this->view->search_field = $this->_getParam('field'); - - $reference = new Reference(); - - if(!empty($keyword)) - { - $reference->keyword = $keyword; - } - - if(!empty($field)) - { - $reference->field = $field; - } - - if(!empty($order)) - { - $reference->order = $order; - } - - if(!empty($sort)) - { - $reference->sort = $sort; - } - - $this->view->reference = $reference; - $this->view->page = $this->_getParam('page'); - $this->view->pagelimit = 12; - - //文献首页 - if(empty($ac)) - { - $this->view->referenceType = $reference->referenceType(); - view::addPaginator($reference->fetchReferences(),$this, $this->view->pagelimit); - $this->view->years = $reference->countByYear(); - return true; - } - else if ($ac == "water") - { - $this->view->referenceType = $reference->referenceType(); - view::addPaginator($reference->fetchThemeReferences('water'),$this,$this->view->pagelimit); - return true; - } - else if ($ac == "westdc") - { - $this->view->referenceType = $reference->referenceType(); - view::addPaginator($reference->fetchWestdcReferences(),$this,$this->view->pagelimit); - return true; - } - else if ($ac == "todo") - { - $this->view->referenceType = $reference->referenceType(); - view::addPaginator($reference->fetchTodoReferences(),$this,$this->view->pagelimit); - return true; - } - - unset($this->view->reference); - unset($this->view->page); - unset($this->view->pagelimit); - - //添加 - if($ac == "add") - { - $this->_helper->viewRenderer('ref-add'); - $id = $this->_getParam('id'); - $attid = $this->_getParam('attid'); - - if(!empty($submit)) - { - $this->view->data = $reference->getReferenceParam(); - $attid = $this->view->data['attid']; - - if(empty($id) || !is_numeric($id)) - { - $status = $reference->reference(); - }else{ - $status = $reference->reference($id); - } - - if($status !== true) - { - $this->view->error = view::Error($status); - }else{ - if(!empty($id)) - { - $msg = "文献修改成功!"; - view::Post($this,$msg,-2); - return true; - }else{ - $msg = "文献添加成功!"; - view::Post($this,$msg,"/admin/data/ref/ac/add"); - return true; - } - } - }else{ - $this->view->data = array(); - if(!empty($id) && is_numeric($id)) - { - $this->view->data = $reference->getOneReferenceData($id); - } - } - - if(!empty($attid)) - { - $files = new Files(); - $attfile = $files->getOne($attid); - $this->view->data['attid'] = $attid; - $this->view->data['file'] = $attfile; - } - - return true; - } - - //上传pdf - if($ac == "pdfupload") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $autoread = false; - if($this->_getParam('multi')) - { - $autoread = true; - } - $statu = $reference->uploadReferencePdf($_FILES['Filedata'],$autoread); - $this->jsonexit($statu); - return true; - } - - //删除已上传的文件 - if($ac == "delete") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $statu = $reference->deleteReferenceAttchment($this->_getParam('attid')); - $this->jsonexit($statu); - return true; - } - - //批量上传 - if($ac == "multiupload") - { - $this->_helper->viewRenderer('ref-multiupload'); - return true; - } - - //文件管理 - if($ac == "files") - { - $this->_helper->viewRenderer('ref-files'); - view::addPaginator($reference->getReferenceFiles(),$this,10); - return true; - } - - //删除文献 - if($ac == "deleteref") - { - $refid = $this->_getParam('id'); - if($reference->deleteReference($refid)) - { - view::Post($this,"删除成功!",-1); - }else{ - view::Post($this,"删除失败!",-1); - } - return true; - } - - //相关数据 - if($ac == "data") - { - $refid = $this->view->refid = $this->_getParam('id'); - if(view::isXmlHttpRequest($this)){ - $this->jsonexit($reference->getDataByReference($refid)); - return true; - }else{ - $this->_helper->viewRenderer('ref-metadatas'); - $this->view->referenceType = $reference->referenceType(); - view::addPaginator($reference->getDataByReference($refid),$this,10); - return true; - } - } - - //添加数据文献 - if($ac == "mdref" && view::isXmlHttpRequest($this)) - { - $mdrefid = $this->_getParam('id'); - $status = $reference->makeMdref($mdrefid); - if($status !== true) - { - $this->jsonexit(array('error'=>$status)); - }else{ - $this->jsonexit(array('success' => 1)); - } - return true; - } - - //移除数据文献 - if($ac == "delmdref") - { - $mdrefid = $this->_getParam('id'); - $status = $reference->delMdref($mdrefid); - if($status === true) - { - view::Post($this,"移除成功",-1); - }else{ - view::Post($this,$status,-1); - } - return true; - } - - //ris - if($ac == "ris") - { - $this->_helper->viewRenderer('ref-ris'); - $submit = $this->_getParam('submit'); - - if(!empty($submit)) - { - $ris = new \Reference\Ris(); - $this->view->data = $ris->loadout(); - try{ - $ris->pushToDataTable($this->view->data); - }catch(Exception $e) - { - view::Dump($e->getMessage(),false); - } - } - } - - //ris更新单篇 - if($ac == "singleris") - { - $this->_helper->viewRenderer('ref-singleris'); - $id = (int)$this->_getParam('id'); - $this->view->ristext = $this->_getParam('ristext'); - - if($id < 1) - { - view::Post($this,"参数错误!",-1); - return true; - } - - $this->view->referenceData = $reference->getOneReferenceData($id); - - if(!empty($submit)) - { - $ris = new Ris(); - $data = $ris->loadout(); - - if(count($data) < 1) - { - view::Post($this,"输入的RIS信息有误".'查看详细',-1); - return true; - } - - if($ris->updateWithRis($id,$data[0]) === true) - { - view::Post($this,"编辑成功!".'查看详细',-2); - return true; - }else{ - view::Post($this,"编辑失败!".'查看详细',-1); - return true; - } - } - - return true; - }//ris单篇更新 - - //ris导出 - if($ac == "risoutput") - { - $this->_helper->viewRenderer('ref-risoutput'); - $this->view->years = $reference->countByYear(); - - if(!empty($submit)) - { - $mode = $this->_getParam('mode'); - - $risOutput = new RisOutput(); - $preData = $risOutput->preRead($mode); - - $risData = $risOutput->processArrayDataToRisData($preData); - - $risText = $risOutput->output($risData); - - echo "
      ";
      -				echo $risText;
      -				echo "
      "; - } - }//ris output - - if($ac == "ristest") - { - $this->_helper->viewRenderer('ref-ris'); - $submit = $this->_getParam('submit'); - - if(!empty($submit)) - { - $ris = new \Reference\Ris(); - view::Dump($ris->processRis(NULL,$this->_getParam('ristext')),false); - } - } - - - }//文献管理 refAction() - - /* - * 删除元数据,删除前有确认 - */ - 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('/data'); - } 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='已成功处理数据目录信息!'; - } - }//datafileimportAction - - - function sourceAction() - { - $do = $this->_request->getParam('do'); - $uuid = $this->_request->getParam('uuid'); - $id = $this->_request->getParam('id'); - $q = $this->_request->getParam('q'); - $search = $this->_request->getParam('search'); - - if ($do == 'add') { - - $redirect = "/admin/data/source/"; - - if(!empty($_POST['submit'])) - { - try{ - $title = $this->_request->getParam('title'); - $uuid = $this->_request->getParam('uuid'); - $code = $this->_request->getParam('code'); - $description = $this->_request->getParam('description'); - $has_pages = $this->_request->getParam('has_pages'); - $has_agreement = $this->_request->getParam('has_agreement'); - - $data = array( - 'title' => $title, - 'uuid' => $uuid, - 'code' => $code, - 'description' => $description, - 'has_pages' => $has_pages, - 'has_agreement' => $has_agreement - ); - - if($this->db->insert('source',$data)) - { - $this->messenger->addMessage('添加来源信息成功'); - $this->_redirect($redirect); - } - }catch(Exception $e){ - $this->messenger->addMessage('添加来源信息失败:'.$e->getMessage()); - $this->_redirect('/admin/data/source/do/add'); - } - - } - - $this->_helper->viewRenderer('sourceadd'); - }// 添加项目来源 - - else if($do == 'edit' && !empty($id)) - { - - if(!empty($_POST['submit'])) - { - try{ - $title = $this->_request->getParam('title'); - $uuid = $this->_request->getParam('uuid'); - $code = $this->_request->getParam('code'); - $description = $this->_request->getParam('description'); - $has_pages = $this->_request->getParam('has_pages'); - $has_agreement = $this->_request->getParam('has_agreement'); - - $sql = "update source set title='$title',uuid='$uuid',code='$code',description='$description',has_pages='$has_pages',has_agreement='$has_agreement' where id='$id'"; - - if($this->db->exec($sql)) - { - $this->messenger->addMessage('修改来源信息成功'); - $this->_redirect("/admin/data/source/do/edit/id/$id"); - } - }catch(Exception $e){ - $this->messenger->addMessage('修改来源信息失败:'.$e->getMessage()); - $this->_redirect("/admin/data/source/do/edit/id/$id"); - } - - } - - $sql = "select * from source where id='$id'"; - $rs = $this->db->query($sql); - $row = $rs->fetch(); - - $this->view->info = $row; - - $this->_helper->viewRenderer('sourceadd'); - - }// 编辑单条信息 - - else if($do == 'datasource' && !empty($uuid)) - { - $redirect = "/admin/data/source/do/datasource/uuid/$uuid"; - - $this->view->uuid = $uuid; - $sql = "select md.title,ds.id,ds.sourceid,s.title as stitle,s.code from metadata md - left join datasource ds on ds.uuid=md.uuid - left join source s on s.id=ds.sourceid - where md.uuid='$uuid'"; - $rs = $this->db->query($sql); - $row = $rs->fetch(); - - $this->view->info = $row; - - if(!empty($_POST['submit'])) - { - $sourceid = $this->_request->getParam('sourceid'); - if(empty($sourceid)) - { - $this->messenger->addMessage('请选择项目来源'); - $this->_redirect($redirect); - } - - $sql=""; - if(empty($row['id'])) - { - $sql = "insert into datasource (uuid,sourceid) values ('$uuid','$sourceid')"; - }else - { - $sql = "update datasource set uuid='$uuid',sourceid='$sourceid' where id='{$row['id']}'"; - } - try{ - if($this->db->exec($sql)) - { - $this->messenger->addMessage('修改项目来源成功'); - $this->_redirect($redirect); - } - else - { - $this->messenger->addMessage('修改项目来源失败'); - $this->_redirect($redirect); - } - }catch (Exception $e){ - $this->messenger->addMessage('修改项目来源失败:'.$e->getMessage()); - $this->_redirect($redirect); - } - - } - - - $wheresql = array(); - - if(!empty($q) && !empty($search)) - { - $this->view->q = $q; - $wheresql[] = " title like '%$q%' "; - } - - if(count($wheresql>0))$wheresql = join(' and ',$wheresql); - else $wheresql=''; - - if($wheresql!='') - { - $wheresql = 'where '.$wheresql; - } - - $sql = "select * from source $wheresql order by id desc"; - $rs = $this->db->query($sql); - $rows = $rs->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; - - $this->_helper->viewRenderer('sourceselect'); - }// 为元数据选择项目来源 - - else if($do == 'del' && !empty($id)) - { - $redirect = "/admin/data/source/"; - $sql = "delete from source where id='$id'"; - try{ - if($this->db->exec($sql)) - { - $this->messenger->addMessage('删除成功'); - $this->_redirect($redirect); - }else{ - $this->messenger->addMessage('删除失败,可能该数据已不存在'); - $this->_redirect($redirect); - } - }catch (Exception $e){ - $this->messenger->addMessage('删除失败:'.$e->getMessage()); - $this->_redirect($redirect); - } - }// 删除项目来源 - - else if($do == 'fetch' && !empty($id)) - { - - $wheresql = array(); - - $wheresql[] = " ds.sourceid='$id' "; - - if(!empty($q) && !empty($search)) - { - $this->view->q = $q; - $wheresql[] = " title like '%$q%' "; - } - - if(count($wheresql>0))$wheresql = join(' and ',$wheresql); - else $wheresql=''; - - if($wheresql!='') - { - $wheresql = 'where '.$wheresql; - } - - $sql = "select md.title,md.uuid,ds.id,ds.sourceid,s.title as stitle,s.code from metadata md - left join datasource ds on ds.uuid=md.uuid - left join source s on s.id=ds.sourceid - $wheresql - order by id desc"; - $rs = $this->db->query($sql); - $rows = $rs->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; - - $this->_helper->viewRenderer('sourcefetchone'); - - }//查看某项目来源中的所有元数据 - - else if($do == 'delsource' && !empty($id)) - { - $redirect = "/admin/data/source/do/datasource/uuid/$uuid"; - - $sql = "delete from datasource where id='$id'"; - - try{ - if($this->db->exec($sql)) - { - $this->messenger->addMessage('删除成功'); - $this->_redirect($redirect); - }else{ - $this->messenger->addMessage('删除失败,可能该数据已不存在'); - $this->_redirect($redirect); - } - }catch (Exception $e){ - $this->messenger->addMessage('删除失败:'.$e->getMessage()); - $this->_redirect($redirect); - } - - - }// 清除元数据来源记录 - elseif ($do=='sync') { //同步数据来源到metadata表 - $redirect = "/admin/data/source/"; - $sql = "update metadata m set source=s.uuid from source s right join datasource d on s.id=d.sourceid where m.uuid=d.uuid"; - if($this->db->exec($sql)) - { - $this->messenger->addMessage('成功同步数据来源'); - $this->_redirect($redirect); - }else{ - $this->messenger->addMessage('同步数据来源失败'); - $this->_redirect($redirect); - } - } - - else - { - $wheresql = array(); - - if(!empty($q) && !empty($search)) - { - $this->view->q = $q; - $wheresql[] = " title like '%$q%' "; - } - - if(count($wheresql>0))$wheresql = join(' and ',$wheresql); - else $wheresql=''; - - if($wheresql!='') - { - $wheresql = 'where '.$wheresql; - } - - $sql = "select * from source $wheresql order by id desc"; - $rs = $this->db->query($sql); - $rows = $rs->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; - }// 项目来源管理 - - - }//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'); - $uuid = $this->_request->getParam('uuid'); - $mdtitle = $this->_request->getParam('mdtitle'); - $mdattdel = $this->_request->getParam('mdattdel'); - $attupdate = $this->_getParam('attupdate'); - - if(!empty($uuid)&&!empty($mdtitle)) - { - $this->view->uuid= $uuid; - $this->view->mdtitle=$mdtitle; - } - - if($add) - { - $this->_helper->viewRenderer('attachmentsadd'); - if(!empty($uuid)) - { - $this->view->uuid = $uuid; - } - }//附件添加 - - elseif($attupdate) - { - $submit = $this->_getParam('submit'); - if(!empty($submit)) - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $id = $this->_getParam('attupdate'); - - $files=new Files(); - $msg = $files -> upload($_FILES['Filedata'],empty($uuid)?'file/':'md/',true); - - if(empty($msg['error'])) - { - $msg['error']=""; - $filename = $msg['db_path']; - $filesize = $msg['file_size']; - $filedesc = $this->_request->getParam('filedesc'); - $filetype = 'md'; - $realname = $msg['realname']; - - - $sql = "UPDATE attachments SET filename=?,filetype=?,filesize=?,realname=? WHERE id=?"; - $sth = $this->db->prepare($sql); - $ds = $sth->execute(array($filename,$filetype,$filesize,$realname,$id)); - - if($ds) - { - $msg['html'] = $realname.'['. round($filesize/1024,2) .' kb]'; - $msg['ok']= 1; - echo Zend_Json::encode($msg); - exit(); - }else{ - @unlink($filename); - $data = array("error"=>'附件上传失败:写入附件表出错'); - $this->jsonexit($data); - return true; - } - }else{ - @unlink($filename); - $data = array("error"=>'附件上传失败:'.$msg['error']); - $this->jsonexit($data); - return true; - } - - - $data = array("error"=>"处理中出现错误".$id); - $this->jsonexit($data); - return true; - }else{ - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer('attachments-update'); - $id = $this->_getParam('attupdate'); - $this->view->id = $id; - } - - }//附件文件更新 - - else if($mdattdel) - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - - $sql = "delete from mdattach where uuid=? AND id=?"; - $sth = $this->db->prepare($sql); - $ds = $sth->execute(array($uuid,$mdattdel)); - if($ds) - { - $data = array("status"=>1); //操作状态代码 : 1=>成功 2=>失败 - $this->jsonexit($data); - return true; - }else{ - $data = array("error"=>"处理中出现错误"); - $this->jsonexit($data); - return true; - } - } - - else if($delete) - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - - //需要删除文件,通过Zend_Registry::get('upload')获得上传文件的根目录 - - $basepath = $this->view->config->upload; - - //从数据库获取文件路径 - - $info = $this->getFileinfo($delete); - - $filepath = $basepath.$info['filename']; - - $sql = "SELECT * FROM mdattach WHERE id=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($delete)); - $rows = $sth->fetchAll(); - - if(count($rows)>0) - { - $data = array("error"=>'删除失败!该文件有元数据附件信息,不能直接删除',"status"=>0); - $this->jsonexit($data); - return true; - } - - $sql = "SELECT * FROM mdreviewattach WHERE attachid=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($delete)); - $rows = $sth->fetchAll(); - - if(count($rows)>0) - { - $data = array("error"=>'删除失败!该文件有对应评审附件信息,不能直接删除',"status"=>0); - $this->jsonexit($data); - return true; - } - - $sql = "SELECT link FROM reference WHERE link!=''"; - $sth = $this->db->prepare($sql); - $sth->execute(); - $rows = $sth->fetchAll(); - - $ids = array(); - foreach($rows as $k=>$v) - { - if(preg_match("/service/i",$v['link'])) - { - $ids[] = str_replace("/service/attach/id/","",$v['link']); - } - unset($rows[$k]); - } - unset($rows); - - if(in_array($delete,$ids)) - { - $data = array("error"=>'删除失败!该文件有对应文献附件信息,不能直接删除',"status"=>0); - $this->jsonexit($data); - return true; - } - - if(unlink($filepath)) - { - $sql = "delete from attachments where id='$delete'"; - if($this->db->exec($sql)>0) - { - $data = array("status"=>1); - $this->jsonexit($data); - return true; - } - } - else - { - $sql = "delete from attachments where id='$delete'"; - if($this->db->exec($sql)>0) - { - $data = array("error"=>'文件删除失败,仅删除数据库记录,请手动删除文件:'.$info['filename'],"status"=>0); - $this->jsonexit($data); - return true; - } - } - - }//删除 - - 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 if ($down>0) - { - - $sql = "select * from attachments where id='$down'"; - - $re = $this->db->query($sql); - - $row = $re->fetch(); - - $file = new files(); - - $fullPath = $this->view->config->upload.$row['filename']; - - - // Parse Info / Get Extension - $fsize = filesize($fullPath); - $path_parts = pathinfo($fullPath); - $ext = strtolower($path_parts["extension"]); - - // Determine Content Type - switch ($ext) { - case "pdf": $ctype="application/pdf"; break; - case "exe": $ctype="application/octet-stream"; break; - case "zip": $ctype="application/zip"; break; - case "doc": $ctype="application/msword"; break; - case "xls": $ctype="application/vnd.ms-excel"; break; - case "ppt": $ctype="application/vnd.ms-powerpoint"; break; - case "gif": $ctype="image/gif"; break; - case "png": $ctype="image/png"; break; - case "jpeg": - case "jpg": $ctype="image/jpg"; break; - default: $ctype="application/force-download"; - } - - $content=file_get_contents($fullPath); - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $this->getResponse()->setHeader('Content-Type', 'application/octet-stream') - ->setHeader('Content-Disposition','attachment; filename="'.basename($fullPath).'"') - ->setHeader('Content-Length', $fsize) - ->setHeader('Content-Type','application/force-download') - ->setHeader('Content-Type','application/download') - ->setHeader('Content-Type',$ctype) - ->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); - - //$sql = "update attachments set downtimes=downtimes+1 where id='$down'"; - //$this->db->exec($sql); - - }//附件下载 - - else - { - - $sql="select * from attachments order by id desc"; - $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 附件 - - function uploadAction(){ - $this->_helper->layout()->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $uuid = $this->_getParam('uuid'); - - try{ - $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { - $user = $auth->getIdentity(); - $userid = $user->id; - } - - if(empty($userid)||!is_numeric($userid)){ - $msg['error'] = "请先登录"; - echo Zend_Json::encode($msg); - exit(); - } - - if($user->usertype!='administrator') - { - $msg['error'] = "您无权使用此功能"; - echo Zend_Json::encode($msg); - exit(); - } - - $files=new Files(); - $msg = $files -> upload($_FILES['Filedata'],empty($uuid)?'file/':'md/',true); - - if(empty($msg['error'])) - { - $msg['error']=""; - $filename = $msg['db_path']; - $filesize = $msg['file_size']; - $filedesc = $this->_request->getParam('filedesc'); - $filetype = 'md'; - $realname = $msg['realname']; - - - $sql = "insert into attachments (filename,filetype,filedesc,userid,filesize,realname) values ('$filename','$filetype','$filedesc','$userid','$filesize','$realname') RETURNING id"; - $sth = $this->db->prepare($sql); - $sth->execute(); - $att = $sth->fetch(PDO::FETCH_ASSOC); - $msg['attid'] = $attid = $att['id']; - - $sql = "insert into mdattach (uuid,id) values ('$uuid','$attid')"; - if(empty($uuid) || $this->db->exec($sql)) - { - $msg['html'] = $realname.'['. round($filesize/1024,2) .' kb]
      '; - echo Zend_Json::encode($msg); - exit(); - }else{ - $msg['error'] = '附件上传失败:写入附件表出错'; - @unlink($filename); - echo Zend_Json::encode($msg); - exit(); - } - - - }else{ - $msg['error'] = '附件上传失败:'.$msg['error']; - @unlink($filename); - echo Zend_Json::encode($msg); - exit(); - } - - }catch(Exception $e){ - $msg['error'] = "错误:".$e->getMessage(); - echo Zend_Json::encode($msg); - exit(); - } - }// uploadAction ajax上传附件 - - function getattsAction(){ - - $this->_helper->layout()->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $uuid = $this->_request->getParam('uuid'); - - if($uuid!='') - { - $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { - $user = $auth->getIdentity(); - $userid = $user->id; - $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' - ORDER BY a.ts_created ASC"; - $rs = $this->db->query($sql); - $atts = $rs->fetchAll(); - - echo Zend_Json::encode($atts); - exit(); - }else - { - exit(); - } - }else{ - exit(); - } - //不输出错误 - }//获取附件 - - - /* - 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,g.id as gid FROM mdversion v - LEFT JOIN metadata md ON md.uuid=v.uuid - left join users u on v.userid=u.id - left join geonetworkmetadata g on md.uuid=g.uuid - 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,u.id 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'].'/service/doc/uuid/'.$row['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/'.$row['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" || $ac=="diff1") - { - $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(); - if ($ac=='diff') - { - $sql = "SELECT v.* FROM mdversion v - WHERE v.uuid=? and v.ts_created<=(select ts_created from mdversion where id=?) - ORDER BY v.ts_created DESC - LIMIT ?"; - $sth = $this->db->prepare($sql); - $sth -> execute(array($row['uuid'],$id,2)); - } else { - $sql = "SELECT v.* FROM mdversion v - WHERE v.uuid=? and (v.id=? or (v.ts_created<(select ts_created from mdversion where id=?) and changelog is not null)) - ORDER BY v.ts_created DESC - LIMIT ?"; - $sth = $this->db->prepare($sql); - $sth -> execute(array($row['uuid'],$id,$id,2)); - } - - $rows = $sth->fetchAll(); - - if(count($rows)<2) - { - $this->view->error = "对比失败:之前没有版本可以对比"; - return true; - } - - $this->view->info = $row; - $this->view->data = $rows; - - } - - - }//versionAction 版本控制 - - - /* - * authorAction() 数据作者 - * - * param string $ac //动作 - =add 添加 - =edit 编辑 - =update 更新 - =del 删除 - =list 列出所有数据作者 - - * param string $uuid //UUID - * - * return view|application-json - */ - public function authorAction(){ - - $ac = $this->_getParam('ac'); - $uuid = $this->_getParam('uuid'); - - if(empty($ac) && empty($uuid)) - { - - $keywords = $this->_request->getParam('q'); - if(!empty($keywords)) - $this->view->q = $keywords; - - $sql = "select md.id,md.title,md.uuid,count(a.userid) as c from metadata md - right JOIN mdauthor a ON md.uuid=a.uuid - "; - - if(!empty($keywords)) - { - $search=new SimpleSearch($keywords); - $where=$search->sql_expr(array("md.title")); - $sql.=' and ('.$where.")"; - } - - $sql .= "GROUP by md.id,md.title,md.uuid,md.ts_created - ORDER BY md.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 == 'add') - { - - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $username = $this->_getParam('username'); - $uuid = $this->_getParam('uuid'); - - if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid)) - { - $data = array("error"=>"uuid参数错误"); - $this->jsonexit($data); - return true; - } - - if(empty($username)) - { - $data = array("error"=>'请输入要添加为该数据作者的用户名'); - $this->jsonexit($data); - return true; - } - - $sql = "SELECT * FROM users WHERE username=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($username)); - $row = $sth->fetch(); - - if(empty($row['id']) || !isset($row['id'])) - { - $data = array("error"=>'您输入的用户名无任何对应用户'); - $this->jsonexit($data); - return true; - } - - $uid = $row['id']; - - $sql = "SELECT * FROM mdauthor WHERE userid=? AND uuid=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($row['id'],$uuid)); - $row = $sth->fetch(); - - if(!empty($row['id']) && $row['status']==1) - { - $data = array("error"=>'该用户已经是此数据的作者'); - $this->jsonexit($data); - return true; - } - - if(!empty($row['id']) && in_array($row['status'],array(0,-1)) ) - { - $sql = "UPDATE mdauthor SET status=1 WHERE uuid=? AND userid=?"; - $sth = $this->db->prepare($sql); - $ds = $sth->execute(array($uuid,$uid)); - if($ds) - { - $data = array("msg"=>'该用户已被提升为数据作者','added'=>1); - $this->jsonexit($data); - return true; - }else{ - $data = array("error"=>'处理中出现错误'); - $this->jsonexit($data); - return true; - } - } - - if(empty($row['id'])) - { - $sql = "INSERT INTO mdauthor (uuid,userid,status) VALUES (?,?,?)"; - $sth = $this->db->prepare($sql); - $ds = $sth->execute(array($uuid,$uid,1)); - if($ds) - { - $data = array("msg"=>'该用户已被添加为数据作者','added'=>1); - $this->jsonexit($data); - return true; - }else{ - $data = array("error"=>"处理中出现错误"); - $this->jsonexit($data); - return true; - } - } - - - $data = array("error"=>"处理中出现错误"); - $this->jsonexit($data); - return true; - - }//ajax 添加作者 - - - else if(($ac == "edit" || $ac=="") && !empty($uuid)) - { - - $window = $this->_getParam('window'); - - if($window == "iframe") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer('author-edit-iframe'); - }else{ - $this->_helper->viewRenderer('author-edit'); - } - - $sql = "SELECT a.*,md.title,u.realname,u.username FROM mdauthor a - LEFT JOIN metadata md ON a.uuid=md.uuid - LEFT JOIN users u ON a.userid=u.id - WHERE md.uuid=? - ORDER BY a.id DESC - "; - - $sth = $this->db->prepare($sql); - $sth->execute(array($uuid)); - $rows = $sth->fetchAll(); - - $this->view->authors = $rows; - - }// 作者管理弹窗 - - else if($ac == "del") - { - - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $id = $this->_getParam('id'); - - $sql = "DELETE FROM mdauthor WHERE id=?"; - $sth = $this->db->prepare($sql); - $ds = $sth->execute(array($id)); - if($ds) - { - $data = array("deleted"=>$id); - $this->jsonexit($data); - return true; - }else{ - $data = array("error"=>"处理中出现错误"); - $this->jsonexit($data); - return true; - } - - - }//移除作者 - - else if($ac == 'update') - { - - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $id = $this->_getParam('id'); - - $sql = "UPDATE mdauthor SET status=1 WHERE id=?"; - $sth = $this->db->prepare($sql); - $ds = $sth->execute(array($id)); - if($ds) - { - $data = array("updated"=>$id,'msg'=>'认证成功!'); - $this->jsonexit($data); - return true; - }else{ - $data = array("error"=>"处理中出现错误"); - $this->jsonexit($data); - return true; - } - - - }//认证作者 - - else if($ac =="list") - { - $this->_helper->viewRenderer('author-list'); - - $sql = "SELECT u.id,u.realname,u.email,count(a.id) as d FROM mdauthor a - LEFT JOIN users u ON a.userid=u.id - WHERE a.status>0 - GROUP BY u.id,u.realname,u.email - ORDER BY u.id 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 == "userdatas") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $id = $this->_getParam('id'); - - $sql = "SELECT md.title,md.uuid FROM mdauthor a - LEFT JOIN metadata md ON a.uuid=md.uuid - WHERE a.userid=? AND a.status>0 - ORDER BY a.ts_created"; - $sth = $this->db->prepare($sql); - $sth->execute(array($id)); - $rows = $sth->fetchAll(); - - $data = array("datas"=>$rows); - $this->jsonexit($data); - return true; - - }//用户数据 - - else if($ac == "datas") - { - $this->_helper->viewRenderer('author-datas'); - - $keywords = $this->_request->getParam('q'); - if(!empty($keywords)) - $this->view->q = $keywords; - - $sql = "select md.id,md.title,md.uuid,count(a.userid) as c from metadata md - left JOIN mdauthor a ON md.uuid=a.uuid - "; - - if(!empty($keywords)) - { - $search=new SimpleSearch($keywords); - $where=$search->sql_expr(array("md.title")); - $sql.=' WHERE '.$where; - } - - $sql .= "GROUP by md.id,md.title,md.uuid,md.ts_created - ORDER BY md.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; - - } - - }//authorAction() 数据作者管理 - - - //newdataAction() 新建元数据 - public 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(); - if($auth->hasIdentity()) - { - $user = $auth->getIdentity(); - $u_id = $user->id; - } - - //在geonetwork中查看单条数据 - if (!empty($id) && empty($ac)) - { - $this->view->url='metadata.show?id='.$id; - $this->_helper->viewRenderer('newdata-view'); - } - //查看所有的未提交数据列表 - else if((empty($ac) && empty($uuid))|| $ac=='list') - { - $sql = "SELECT (regexp_matches(gn.data,'(.*)'))[1] as title,gn.id,gn.uuid,u.username,u.realname FROM geonetworkmetadata gn left join users u on gn.owner=u.id - WHERE gn.uuid not in (select uuid from metadata) - order by gn.id 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=="import") - { - $this->_helper->viewRenderer('newdata-import'); - } - //从模板新建元数据 - else if($ac=="add-by-template") - { - $keywords = $this->_request->getParam('q'); - $sql="select id,(regexp_matches(data,'(.*)'))[1] as title,(owner-$u_id) as isowner from metadata where istemplate='y' and schemaid='iso19115'"; - if(!empty($keywords)) - { - $this->view->q = $keywords; - $search=new Search($keywords); - $where=$search->sql_expr(array("data")); - $sql.=' and '.$where; - } - $sql.=" order by changedate desc"; - $sth = $this->wdb->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('newdata-add'); - } - - else if($ac=="add-by-data") - { - $keywords = $this->_request->getParam('q'); - $sql = "SELECT md.title,md.uuid,md.description,gn.id as gid FROM normalmetadata md - left join geonetworkmetadata gn on md.uuid=gn.uuid - WHERE gn.id is not null"; - if(!empty($keywords)) - { - $this->view->q = $keywords; - $search=new Search($keywords); - $where=$search->sql_expr(array("md.title","md.description")); - $sql.=' and '.$where; - } - $sql.=" order by md.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(10); - $paginator->setView($this->view); - Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); - $this->view->paginator=$paginator; - $this->_helper->viewRenderer('newdata-add-bydata'); - } - //元数据格式检查 - else if ($ac=="validate") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $data = ""; - $id = $this->_request->getParam('id'); - $sql="select uuid,data from geonetworkmetadata where id=?"; - $sth=$this->db->prepare($sql); - $sth->execute(array($id)); - $row=$sth->fetch(); - - $iso=new ISO19115(); - @$iso->loadXML($row['data']); - if ($iso->validate()) - { - $data=array("error"=>"元数据中发现错误。
      ".implode("
      ",$iso->error)); - $this->jsonexit($data); - return true; - } else { - $data=array("error"=>"元数据中没有发现错误。
      "); - $this->jsonexit($data); - return true; - } - } - //提交数据 - else if($ac=="commit") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $data = ""; - $id = $this->_request->getParam('id'); - try{ - 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. 权限认定:当前用户必须和其owner相同 - // 数据应当没有评审状态,没有作者信息 - $sql="select uuid,data from geonetworkmetadata where id=?"; - $sth=$this->db->prepare($sql); - $sth->execute(array($id)); - $row=$sth->fetch(); - if (empty($row)) - { - $data = array("error"=>'无权限修改数据'); - $this->jsonexit($data); - return true; - } - - // 保存数据作者信息 - - // 2. 保存变化记录 save changelog & userid for the latest version - $sql = "UPDATE mdversion SET changelog=?,userid=? WHERE id in (select v.id from mdversion v left join geonetworkmetadata g on v.uuid=g.uuid where g.id=? order by v.ts_created desc limit 1)"; - $this->db->query($sql,array($changelog,$u_id,$id)); - - // 3. 保存数据评审状态 - //导入元数据 - $iso=new ISO19115(); - @$iso->saveDB($this->db,$row['data']); - //进入评审库 - $sql="insert into mdstatus (uuid,status,userid) select uuid,0,? from geonetworkmetadata 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(); - - $data = array("commited"=>1,"error"=>'该版本已经成功提交,请等待数据中心进一步处理!'); - $this->jsonexit($data); - return true; - }catch(Exception $e) { - $sql="delete from mdstatus where uuid in (select uuid from geonetworkmetadata where id=?)"; - $this->db->query($sql,array($id)); - $msg = "提交失败,请确认权限后重试"; - if($this->debug>0) - {$msg .= $e->getMessage();} - $data = array("error"=>$msg); - $this->jsonexit($data); - return true; - } - } - - }// newdataAction() 新建元数据 - - /* - * projectsAction() 数据汇交计划 - * - * - * - * - */ - function projectAction() - { - include_once("Heihe.php"); - $heihe = new Heihe($this->db); - - $this->view->input_NameDefaultVal = "专家姓名"; - $this->view->input_EmailDefaultVal = "专家email"; - - $projectTable = $heihe->tbl_heiheproject; - - $ac = $this->_getParam('ac'); - - if(empty($ac) || $ac == "index") - { - $this->_helper->viewRenderer('project'); - - //Search Link - $this->view->searchLink = "/admin/heihe/project/ac/index/"; - - $q = $this->_getParam('q'); - - $wheresql = array(); - - if(!empty($q)) - { - $wheresql[] = " (title LIKE '%$q%' OR - code LIKE '%$q%' OR - name LIKE '%$q%' OR - email LIKE '%$q%')"; - $this->view->searchKeyword = $q; - } - - if(count($wheresql)>0) - { - $wheresql = join(" AND ",$wheresql); - }else{ - $wheresql = ""; - } - - if(!empty($wheresql)) - { - $wheresql = " WHERE ".$wheresql; - } - - $sql = "SELECT * FROM $projectTable $wheresql - ORDER BY id ASC"; - $sth = $this->db->query($sql); - $rows = $sth->fetchAll(); - - foreach ($rows as $k=>$v) - { - $rows[$k]['status_alias'] = $heihe->getStatus($v['status']); - } - - $this->view->Count = count($rows); - - $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; - - $this->view->project_status = $heihe->project_status; - - return true; - }//ac == index - - //邀请专家 - if($ac == "invite") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $pid = $this->_getParam('id'); - $name = $this->_getParam('name'); - $email = $this->_getParam('email'); - - if(!is_numeric($pid)) - { - $this->jsonexit(array("error"=>"参数错误")); - return true; - } - - if(empty($name) || $name == $this->view->input_NameDefaultVal) - { - $this->jsonexit(array("error"=>"请输入专家姓名")); - return true; - } - - if(empty($email) || $email == $this->view->input_EmailDefaultVal) - { - $this->jsonexit(array("error"=>"请输入专家Email")); - return true; - } - - $code = $heihe->makeValidation($email); - - $expert_data = array( - "name"=>$name, //专家姓名 - "email"=>$email, //专家email - "created"=>date("Y-m-d H:i:s",time()), //邀请时间 - "validation"=>$code, //验证码 - ); - - $rs = $heihe->expertAdd($pid,$expert_data); - - if($rs > 0) - { - $this->sendMailToExpert($pid,$name,$email,$code);// 最后再加入一个非0的数字型参数即可使用调试邮箱发送 - $this->jsonexit(array("msg"=>"专家邀请成功!","invited"=>1)); - return true; - }else if($rs==-1){ - $this->jsonexit(array("error"=>"该专家已经邀请过")); - return true; - }else{ - $this->jsonexit(array("error"=>"邀请失败,请重试")); - return true; - } - - return true; - }// 邀请专家 - - if($ac == "showexpert") - { - - $this->_helper->layout->setLayout('layout-iframe'); - $this->_helper->viewRenderer('project-showexpert'); - - $pid = $this->_getParam('id'); - - if(empty($pid) || !is_numeric($pid)) - { - $this->view->error = "参数错误"; - return true; - } - - $this->view->pid = $pid; - - $experts = $heihe->expertRead($pid); - - if(!is_array($experts)) - { - $this->view->error = "此项目还没有邀请专家"; - return true; - } - - foreach($experts as $k=>$v) - { - $experts[$k]['url'] = $heihe->makeInviteLink($pid,$v['validation']); - } - - $this->view->experts = $experts; - - return true; - }//ac == showexpert 查看跟踪专家 - - if($ac == "remove") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $pid = $this->_getParam('id'); - $del = $this->_getParam('del'); - - if(!empty($del) && !empty($pid)) - { - - $rs = $heihe->expertRemove($pid,$del); - - if($rs) - { - $this->jsonexit(array("deleted"=>1)); - return true; - }else{ - $this->jsonexit(array("error"=>"删除失败,请重试")); - return true; - } - - }else{ - $this->jsonexit(array("error"=>"参数错误,请刷新")); - return true; - } - - }//ac == remove 删除专家 - - if($ac == "upload") - { - $this->_helper->layout->setLayout('layout-iframe'); - $this->_helper->viewRenderer('project-upload'); - - $submit = $this->_getParam('submit'); - - $pid = $this->_getParam('pid'); - - if(empty($pid) || !is_numeric($pid)) - { - $this->view->error = "参数错误"; - return true; - } - - $this->view->pid = $pid; - - $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { - $user = $auth->getIdentity(); - $uid = $user->id; - } - - if(!empty($submit) && empty($this->view->error)) - { - - $files=new files(); - $msg = $files -> upload($this->view->config->upload,$_FILES['Filedata'],'heihe'); - - if(empty($msg['error'])) - { - $msg['error']=""; - $filename = $msg['db_path']; - $filesize = $msg['file_size']; - $filedesc = $this->_request->getParam('filedesc'); - $filetype = $msg['file_type']; - $realname = $msg['realname']; - - if(!empty($row['attachid'])) - { - $sql = "SELECT * FROM attachments WHERE id={$row['attachid']}"; - $sth = $this->db->query($sql); - $attach = $sth->fetch(); - $this->db->exec("DELETE FROM attachments WHERE id={$row['attachid']} AND filetype='heihe'"); - @unlink($this->view->config->upload.$attach['filename']); - } - - $sql = " INSERT INTO attachments (filename,filetype,filedesc,userid,filesize,realname) values - ('$filename','heihe','$filedesc','$uid','$filesize','$realname') RETURNING id"; - $sth = $this->db->prepare($sql); - $sth->execute(); - $att = $sth->fetch(PDO::FETCH_ASSOC); - $msg['attid'] = $attid = $att['id']; - - $sql = "UPDATE heiheproject SET attachid=$attid WHERE id=$pid"; - $sth = $this->db->exec($sql); - - if($sth) - { - $this->view->message = "上传成功"; - }else{ - @unlink($filename); - $this->view->error = '附件上传失败:写入附件表出错'; - return true; - } - }else{ - @unlink($filename); - $this->view->error = "附件上传失败".$msg['error']; - return true; - } - } - - $sql = "SELECT * FROM heiheproject WHERE id=$pid"; - $sth = $this->db->query($sql); - $row = $sth->fetch(); - - if(!empty($row['attachid'])) - { - $sql = "SELECT * FROM attachments WHERE id = {$row['attachid']}"; - $sth = $this->db->query($sql); - $this->view->att = $sth->fetch(); - } - - return true; - }//ac == upload - - //改变状态 - if($ac == "changestatus") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $project = $this->_getParam('p'); - $status = $this->_getParam('s'); - - if(!is_numeric($status)) - { - $this->jsonexit(array('error'=>'参数错误')); - return true; - } - - $code = $heihe->ChangeStatus($project,$status); - - if($code > 0) - { - $this->jsonexit( - array( - 'msg'=>'修改成功!', - 'status'=>$heihe->getStatus($status) - ) - ); - return true; - }else{ - $this->jsonexit(array('error'=>'参数错误')); - return true; - } - - }//ac == "changestatus" - - }//projectsAction() - - public function fundAction() - { - $this->_helper->layout->setLayout('administry'); - $ac = $this->_getParam('ac'); - $submit = $this->_getParam('submit'); - $this->view->q = $keyword = $this->_getParam('q'); - - include_once("helper/view.php"); - include_once("data/Fund.php"); - $fund = new Fund($this->db); - - $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { - $user = $auth->getIdentity(); - $uid = $user->id; - } - - if($ac=='index' || empty($ac)) - { - $uuid = $this->_getParam('uuid'); - if(empty($uuid)) - { - $rows = $fund->fetch(NULL,true,0,$keyword); - view::addPaginator($rows,$this,10); - }else{ - include('data/Metadata.php'); - $md = new Metadata($this->db); - $this->view->md = $md->view($uuid); - $rows = $fund->fetch($uuid); - view::addPaginator($rows,$this,10); - } - return true; - } - - if($ac == 'datalist') - { - $this->_helper->viewRenderer('fund-data-list'); - $this->view->q = $q = $this->_getParam('q'); - $rows = $fund->fetchFromData(true,0,$q); - view::addPaginator($rows,$this,10); - return true; - } - - if($ac == 'dataview') - { - $this->_helper->viewRenderer('fund-data-view'); - $this->view->q = $q = $this->_getParam('q'); - $id = $this->_getParam('id'); - $this->view->fund = $fund->view($id); - $rows = $fund->fetchFromData($id,0,$q); - view::addPaginator($rows,$this,10); - return true; - } - - if($ac == "add") - { - $this->_helper->viewRenderer('fund-add'); - if(!empty($submit)) - { - $data = $fund->_getParams($this->_request); - $data['userid'] = $uid; - - if($fund->add($data) == true) - { - $this->view->AlertType = "alert-success"; - $this->view->msg = "添加成功!"; - $this->view->jump_url = "/admin/data/fund/"; - return true; - }else{ - $this->view->data = $data; - $this->view->error = "添加失败,请重试"; - return true; - } - } - return true; - }//add - - if($ac == "edit") - { - $this->_helper->viewRenderer('fund-add'); - $id = $this->_getParam('id'); - - if(empty($id)) - { - $this->view->AlertType = "alert-error"; - $this->view->msg = "参数错误"; - $this->view->jump_url = "/admin/data/fund/"; - } - - if(!empty($submit)) - { - $data = $fund->_getParams($this->_request); - $data['userid'] = $uid; - if($fund->update($data,$id) == true) - { - $this->view->AlertType = "alert-success"; - $this->view->msg = "修改成功!"; - $this->view->jump_url = "/admin/data/fund/"; - return true; - }else{ - $this->view->data = $data; - $this->view->error = "修改失败,请重试"; - return true; - } - }else{ - $this->view->data = $fund->view($id); - } - return true; - }//edit - - if($ac == "del") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $id = $this->_getParam('id'); - - if(empty($id)) - { - $this->jsonexit(array('error'=>'参数错误')); - return true; - } - - if($fund->delete($id) == true) - { - $this->jsonexit(array('success'=>$id)); - return true; - }else{ - $this->jsonexit(array('error'=>'删除失败')); - return true; - } - - }//del - - if($ac == "formd") - { - $uuid = $this->_getParam('uuid'); - - if(empty($uuid)) - { - $this->view->AlertType = "alert-error"; - $this->view->msg = "参数错误"; - $this->view->jump_url = "/admin/data/fund/"; - } - - $id = $this->_getParam('id'); - $order = $this->_getParam('order'); - - if(!empty($id)) - { - if($fund->addToMdfund($uuid,$id,$order)) - { - $this->view->AlertType = "alert-success"; - $this->view->error = "添加成功!可以继续选择并添加"; - }else{ - $this->view->AlertType = "alert-error"; - $this->view->error = "添加失败!该数据可能已被添加"; - } - } - - $mfid = $this->_getParam('mfid'); - - if(!empty($mfid)) - { - if($fund->changeorder($mfid,$order)) - { - $this->view->AlertType = "alert-success"; - $this->view->error = "排序修改成功!"; - }else{ - $this->view->AlertType = "alert-error"; - $this->view->error = "排序修改失败!"; - } - $rows = $fund->fetch($uuid); - }else{ - $this->view->ct = "ct"; - $rows = $fund->fetch($uuid,false,0,$this->_getParam('q')); - } - - include('data/Metadata.php'); - $md = new Metadata($this->db); - $this->view->md = $md->view($uuid); - - view::addPaginator($rows,$this,10); - - return true; - }//formd - - if($ac == "mdfunddel") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $id = $this->_getParam('id'); - - if(empty($id)) - { - $this->jsonexit(array('error'=>'参数错误')); - return true; - } - - if($fund->mfdelete($id) == true) - { - $this->jsonexit(array('success'=>$id)); - return true; - }else{ - $this->jsonexit(array('error'=>'删除失败')); - return true; - } - }//mdfunddel - - if($ac == "data") - { - $this->_helper->viewRenderer('fund-data'); - - $id = $this->_getParam('id'); - $del = $this->_getParam('del'); - $this->view->info = $fund->view($id); - - if(!empty($del)) - { - $s = $fund->dataRelationDelete($del); - if($s) - { - $this->view->error = view::Error("删除成功!","alert-sccuess"); - }else{ - $this->view->error = view::Error("删除失败!","alert-error"); - } - } - - $rows = $fund->getData($id,$keyword); - view::addPaginator($rows,$this,10); - } - - }//fund - - public function doiAction() - { - $ac = $this->_getParam('ac'); - $submit = $this->_getParam('submit'); - $uuid = $this->_getParam('uuid'); - $q=$this->_getParam('q'); - - include_once("data/Doi.php"); - $doi = new Doi($this->db); - include_once("helper/view.php"); - - if( empty($ac) || $ac == "index") - { - if(empty($uuid)) - { - $rows = $doi->fetch(0,$q); - view::addPaginator($rows,$this,10); - }else{ - $this->_redirect('/admin/data/doi/ac/edit/?uuid='.$uuid); - return true; - } - return true; - }//index - - else if($ac == "add") - { - $this->_helper->viewRenderer('doi-add'); - - }//add - - else if($ac == "edit") - { - $this->_helper->viewRenderer('doi-add'); - $id = $this->_getParam('id'); - if(empty($uuid) && empty($id)) - { - view::Msg('alert-error',"参数错误",-1); - return false; - } - - if(empty($submit)){ - if(!empty($uuid)) - { - $this->view->uuid = $uuid; - $this->view->data = $doi->view($uuid); - include('data/Metadata.php'); - $md = new Metadata($this->db); - $metadata = $md->view($uuid); - if(empty($this->view->data)) - { - $this->view->data = array( - 'uuid'=>$uuid, - 'title'=>$metadata['title'], - 'doi'=>$metadata['doi'], - 'url'=>"http://" . $_SERVER['HTTP_HOST'].'/data/'.$uuid, - 'publisher'=>'寒区旱区科学数据中心', - 'title_en'=>$metadata['title_en'], - 'publisher_en'=>'Cold and Arid Regions Science Data Center at Lanzhou', - ); - }else{ - $this->view->data['doi'] = $metadata['doi']; - $this->view->data['info'] = $doi->data_process_out($this->view->data); - if(empty($this->view->data['ts_published'])) - { - $this->view->data['title'] = $metadata['title']; - $this->view->data['title_en'] = $metadata['title_en']; - } - } - }else{ - $this->view->data = $doi->view($uuid); - $this->view->data['info'] = $doi->data_process_out($this->view->data); - } - }else{ - $data = $doi->_getParams($this->_request); - $this->view->data = $data; - $info = $doi->checkinfo($data['info']); - if(!is_array($info)){ - $this->view->error = view::Error($info); - return true; - }else{ - $data['info'] = $info; - $data['info'] = $doi->sksort($data['info'],"order",SORT_ASC); - } - $state = $doi->update($data,$uuid); - if($state) - { - $this->view->msg = view::Msg('alert-success',"修改成功!",'/admin/data/doi/uuid/'.$uuid); - return false; - }else{ - $this->view->error = view::Error("修改失败"); - return false; - } - } - }//edit - - else if($ac == "del") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $id = $this->_getParam('id'); - - if(empty($id)) - { - $this->jsonexit(array('error'=>'参数错误')); - return true; - } - - if($doi->delete($id) == true) - { - $this->jsonexit(array('success'=>$id)); - return true; - }else{ - $this->jsonexit(array('error'=>'删除失败')); - return true; - } - - }//del - else if ($ac=="convert") //转换为chinadoi所需元数据格式 - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $sql="select d.*,m.description from datadoi d left join metadata m on d.uuid=m.uuid where d.uuid='$uuid'"; - $row=$this->db->fetchRow($sql); - $timestamp=date('YmdHis'); - $authors=explode(',',substr($row['authors'],1,-1)); - $orgs=explode(',',substr($row['organization'],1,-1)); - $doi=' - - '.$timestamp.' - '.$timestamp.' - - ISTIC - tuy@istic.ac.cn - - ISTIC - - - - - '; - foreach($authors as $k=>$v) - { - $doi.=''.$v.''; - $doi.=''.$orgs[$k].''; - } - $doi.=' - - <![CDATA['.$row['title'].']]> - - '; - $doi.=''; - $doi.=''.$row['publisher'].''; - $doi.=' - '.$row['doi'].' - '.$timestamp.' - - '; - $doi.=' - - -'; - $this->getResponse()->setHeader('Content-Type', 'text/xml')->setHeader('Content-Disposition','attachment; filename="'.$row['uuid'].'.xml"') - ->setHeader('Content-Type','application/force-download')->setBody($doi); - $this->db->query('update datadoi set ts_submitted=now() where uuid=?',array($uuid)); - } - else if ($ac=="verified") //成功申请 - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $row=$this->db->fetchRow("select * from datadoi where uuid='$uuid'"); - $content=@file_get_contents("http://dx.doi.org/".$row['doi']); - if (strpos($content,$row['doi'])!==false) //成功申请 - { - $sql="update datadoi set ts_published=now() where uuid=? and ts_published is null"; - $this->db->query($sql,array($uuid)); - $this->jsonexit(array('success'=>'成功申请')); - } else - $this->jsonexit(array('success'=>'该DOI验证失败,请检查!')); - return true; - } - }//doi - - //发送邀请专家的邮件 - public function sendMailToExpert($pid,$name,$email,$code,$test=0) - { - include_once("Heihe.php"); - $heihe = new Heihe($this->db); - $url = $heihe->makeInviteLink($pid,$code); - - include_once("EmailText.php"); - $mailtp=new EmailText($this->db,"expert-invite",array( - 'name' => $name, - 'url' => $url, - )); - - echo $mailtp->getBody(); - echo $mailtp->getSubject(); - if($test == 0) - { - include_once("WestdcMailer.php"); - $mail=new WestdcMailer($this->view->config->smtp); - $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); - $mail->setBodyText($mailtp->getBody()); - $mail->setSubject($mailtp->getSubject()); - $mail->addTo($email); - $mail->send(); - }else{ - $mail_config = array( - 'ssl' => 'ssl', - 'port' => 465, - 'auth' => 'login', - 'username' => 'la5c@qq.com', - 'password' => '' - ); - $transport = new Zend_Mail_Transport_Smtp('smtp.qq.com', $mail_config); - Zend_Mail::setDefaultTransport($transport); - - $mail=new Zend_Mail(); - $mail->setBodyText($mailtp->getBody()); - $mail->setFrom('la5c@qq.com','Jack'); - $mail->addTo("la5c@qq.com"); - $mail->setSubject($mailtp->getSubject()); - $mail->send(); - } - }//发送邀请邮件 - - /* - 获得单个文件的信息 - 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数据到数据库 - */ - private function import($xml) - { - $iso=new ISO19115(); - $iso->saveDB($this->db,$xml); - } - - /* - * jsonexit() 退出并返回json数据 - * - * param array $data 要返回的JSON数据,可以是任意数组 - * - * return JSON-response - */ - public function jsonexit($data){ - $this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(json_encode($data,JSON_NUMERIC_CHECK)); - return true; - }//jsonexit() 退出并返回json数据 -} +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 = 1; //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() + { + //其他连接 + } + + //提供和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"; + $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=trim($this->_request->getParam('uuid')); + if ($source=="geonetwork" && empty($uuid) ) { + //从geonetwork向WESTDC同步 + //对所有的新数据增加评审状态 + $sql="insert into mdstatus (uuid,status,ts_accepted,userid) select uuid,1,now(),? + from geonetworkmetadata gn where uuid not in (select uuid from mdstatus)"; + $userid = Zend_Auth::getInstance()->getIdentity()->id; + $this->db->query($sql,array($userid)); + $sql="select uuid,data,source 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='e3ad32dc-f573-11e0-aa7b-b768cfd88d80'"; + $sql="delete from metadata where uuid in (select uuid from watergn)"; + $this->db->query($sql); + $sql="delete from responsible where id not in (select distinct(resid) from role)"; + $this->db->query($sql); + //对所有的新数据增加评审状态 + $sql="insert into mdstatus (uuid,status,ts_accepted,userid) select uuid,1,now(),? + from watergn where uuid not in (select uuid from mdstatus)"; + $userid = Zend_Auth::getInstance()->getIdentity()->id; + $this->db->query($sql,array($userid)); + //同步黑河遥感实验的元数据 + $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 ($source=="glacier" && empty($uuid) ) { + //首先删除所有的对应专题数据 + $sql="delete from metadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier')"; + $this->db->query($sql); + $sql="delete from responsible where id not in (select distinct(resid) from role)"; + $this->db->query($sql); + //对所有的新数据增加评审状态 + /*$sql="insert into mdstatus (uuid,status,ts_accepted,userid) select uuid,1,now(),? + from watergn where uuid not in (select uuid from mdstatus)"; + $userid = Zend_Auth::getInstance()->getIdentity()->id; + $this->db->query($sql,array($userid));*/ + //同步专题元数据 + $sql="select uuid,data,source from geonetworkmetadata where schemaid='iso19115' and uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier')"; + $rs=$this->db->fetchAll($sql); + foreach($rs as $gmd) { + $this->import($gmd->data); + //source in unused now. + //$this->db->query("update metadata set source=? where uuid=?",array($gmd->source,$gmd->uuid)); + } + $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); + } + $this->view->msg='成功同步WESTDC元数据到GEONETWORK!'; + } elseif (!empty($uuid) && isset($_POST['gnsubmit'])) { + //同步单条元数据到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).")"; + } + $this->db->exec($sql); + $this->view->msg='成功同步元数据:'.$uuid; + } else $this->view->msg='不存在此元数据:'.$uuid; + } elseif (!empty($uuid) && isset($_POST['watersubmit'])) { + //同步单条元数据 + $sql=$this->db->quoteInto("select data,source from watergn where uuid=?",$uuid); + if ($rs=$this->db->fetchRow($sql)) { + $this->import($rs->data); + $this->db->query("update metadata set source=? where uuid=?",array($rs->source,$uuid)); + $this->view->msg='成功同步元数据:'.$uuid; + } else $this->view->msg='不存在此元数据:'.$uuid; + } elseif ($list=='westdc') { + $sql="select uuid,title from metadata where uuid not in (select uuid from geonetworkmetadata where schemaid='iso19115')"; + $this->view->metadata=$this->db->query($sql); + } elseif ($list=='geonetwork') { + $sql="select id,uuid,(regexp_matches(data,'(.*)'))[1] as title from geonetworkmetadata + where uuid not in (select uuid from metadata)"; + $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=='geonetwork') { + //dblink view中删除多条有问题,暂时用单条删除替代 + //$sql="delete from geonetworkmetadata where uuid not in (select uuid from metadata)"; + $sql="select uuid from geonetworkmetadata where uuid not in (select uuid from metadata)"; + $rows=$this->db->fetchAll($sql); + foreach($rows as $row) + { + $this->db->exec($this->db->quoteInto("delete from geonetworkmetadata where uuid=?",$row->uuid)); + } + $this->view->msg='已删除GEONETWORK中多出的元数据!'; + } 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"; + $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=encode(digest(md5('$row->password'),'sha1'),'hex'),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',encode(digest(md5('$row->password'),'sha1'),'hex'),'$row->email')"; + $this->db->query($sql); + } + } + $this->view->msg='已成功同步帐号!'; + } elseif (!empty($uuid) && (isset($_POST['submit']) || (!isset($_POST['gnsubmit']) && !isset($_POST['watersubmit'])))) { + //同步单条元数据 + $sql=$this->db->quoteInto("select data,source from geonetworkmetadata where uuid=?",$uuid); + if ($rs=$this->db->fetchRow($sql)) { + $this->import($rs->data); + $this->db->exec($this->db->quoteInto("update metadata set source=? where uuid='$uuid'",$rs->source)); + $userid = Zend_Auth::getInstance()->getIdentity()->id; + $this->db->query("insert into mdstatus (uuid,status,ts_accepted,userid) select uuid,1,now(),? + from geonetworkmetadata gn where uuid not in (select uuid from mdstatus) and uuid=?",array($userid,$uuid)); + $this->view->msg='成功同步元数据:'.$uuid; + //update search document + $search=new Search(); + $sql="select * from xunsearch where uuid=?"; + $sth = $this->db->prepare($sql); + $sth->setFetchMode(Zend_Db::FETCH_ASSOC); + $sth->execute(array($uuid)); + $data = $sth->fetch(); + $search->update($data); + + } else $this->view->msg='不存在此元数据:'.$uuid; + } + } + + function datasetcdAction() + { + $add=(int)$this->_getParam('add'); + $edit=(int)$this->_getParam('edit'); + $delete=(int)$this->_getParam('delete'); + set_time_limit(0); + 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; + } + + /* + * + * 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'); + + + if ($delete) + { + $sql="delete from metadata where uuid=?"; + try { + $this->db->query("delete from mdstatus where uuid=?",array($delete)); + $this->db->query("delete from mdauthor where uuid=?",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 normalmetadata 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 metadata 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 metadata 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 '

      数据目录成功导入!

      '; + } else if ($row['host']=='ftp.sanjiangyuan.org.cn') + { + file_get_contents("http://ftp.sanjiangyuan.org.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); + echo '

      数据目录成功导入!

      '; + } else { + echo '

      数据目录未导入!

      '; + } + } + + }//datasetAction存档管理 + + /* + * commentAction() + * 反馈管理 + * ALTER TABLE comments ADD COLUMN reply integer NOT NULL DEFAULT 0; + */ + function commentAction() + { + $delete=(int)$this->_getParam('delete'); + $uuid = $this->_getParam('uuid'); + $reply = $this->_getParam('reply'); + $replylist = $this->_getParam('replylist'); + $delreply = $this->_getParam('delreply'); + + 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"); + } + + if($reply) + { + + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $body = $this->_getParam('content'); + if(empty($body)) + { + $data = array('error'=>"请输入回复内容"); + $this->jsonexit($data); + return true; + } + + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $uid = $user->id; + $email = $user->email; + } + + $ipaddr = $_SERVER['REMOTE_ADDR']; + + $sql = "INSERT INTO comments (uuid,author,reply,userid,content,email,ip) VALUES (?,?,?,?,?,?,?)"; + $sth = $this->db->prepare($sql); + $rs = $sth->execute(array($uuid,$user->username,$reply,$uid,$body,$email,$ipaddr)); + + if($rs) + { + $sql="select c.author,c.email,c.uuid from comments c where c.id=?"; + $sth=$this->db->prepare($sql); + $sth->execute(array($reply)); + $row=$sth->fetch(); + + $mail=new WestdcMailer($this->view->config->smtp); + $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); + $mailtp=new EmailText($this->db,"comment-admin-reply",array( + 'user' => $row['author'], + 'uuid' => $row['uuid'], + 'email'=> $row['email'] + )); + $mail->setBodyText($mailtp->getBody()); + $mail->setSubject($mailtp->getSubject()); + $mail->addTo($row['email']); + $mail->addCc($this->view->config->service->email); + @$mail->send(); + + $data = array('status'=>1,'msg'=>'回复成功!'); + $this->jsonexit($data); + return true; + }else{ + $data = array('error'=>"回复失败,请重试"); + $this->jsonexit($data); + return true; + } + return true; + } + + if($uuid) + { + $sql = "SELECT c.*,md.title,md.uuid FROM comments c + LEFT JOIN metadata md ON md.uuid=c.uuid + WHERE c.uuid=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($uuid)); + $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; + + $sql = "SELECT title FROM metadata WHERE uuid=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($uuid)); + $row = $sth->fetch(); + + $this->view->title = $row['title']; + + return true; + } + + if($replylist) + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $sql = "SELECT cr.id,cr.content as body,cr.reply,u.username,cr.ts_created FROM comments cr + LEFT JOIN users u ON cr.userid=u.id WHERE cr.reply=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($replylist)); + $rows = $sth->fetchAll(); + + $this->jsonexit($rows); + return true; + + } + + if($delreply) + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $sql = "DELETE FROM comments WHERE id=?"; + $sth = $this->db->prepare($sql); + $rs = $sth->execute(array($delreply)); + + if($rs) + { + $this->jsonexit( + array('deleted'=>1) + ); + return true; + }else{ + $this->jsonexit( + array('error'=> '处理中出现错误,请重新尝试') + ); + return true; + } + + + } + + + $sql = "SELECT cm.*,md.title,(SELECT count(id) as counts FROM comments cms WHERE cms.reply=cm.id AND cms.reply!=0) as reply_count FROM comments cm + LEFT JOIN metadata md ON md.uuid=cm.uuid + WHERE cm.reply=0 + ORDER BY cm.ts_created DESC,cm.id DESC"; + + $sth = $this->db->query($sql); + $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; + + }//comment + + + 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'); + $import=(int)$this->_getParam('import'); + $show = $this->_getParam('show'); + + if ($add) { + $type = $this->_getParam('type'); + if($type == 'dc') + { + $this->_helper->viewRenderer('referenceadd'); + $this->view->type = "dc"; + }else{ + $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,reftype) values(?,?,?)"; + $this->db->query($sql,array(trim($formdata['uuid']),$row['id'],$formdata['reftype'])); + $this->messenger->addMessage('提示信息:您已经成功添加该数据文献。'); + $this->_redirect('/admin/data/reference/show/'.$formdata['uuid']); + }else { + $form->populate($formdata); + } + } else { + if ($uuid) + { + $formdata['uuid']=$uuid; + $form->populate($formdata); + } + } + $this->view->form=$form; + $this->_helper->viewRenderer('referenceadd'); + } + } //添加 + + else if($show){ + $sql = "select mr.id as mdid,mr.refid,r.reference,md.title,md.uuid,mr.place FROM mdref mr + left join metadata md on md.uuid=mr.uuid + left join reference r on r.id=mr.refid + where mr.uuid='$show'; + "; + $rs = $this->db->query($sql); + $rows = $rs->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; + + } //按UUID查看 + + elseif ($edit){ + $form=new ReferenceForm(); + if ($this->_request->isPost()) { + $formdata=$this->_request->getPost(); + if ($form->isValid($formdata)) { + $sql="select id from reference where reference=? order by id desc"; + $rs=$this->db->query($sql,array($formdata['reference'])); + $row = $rs->fetch(); + if ($row['id']!='') + { + //更新文献信息 + $sql="update mdref set refid=?,reftype=? where uuid=? and id=?"; + $td = $this->db->query($sql,array($row['id'],$formdata['reftype'],$formdata['uuid'],$edit)); + $sql="update reference set reference=?,link=? where id=?"; + $this->db->query($sql,array($formdata['reference'],$formdata['link'],$row['id'])); + if($td) + { + $this->messenger->addMessage('提示信息:您已经编辑该数据文献。'); + $this->_redirect('/admin/data/reference/show/'.$formdata['uuid']); + } + }else + { + $sql = "INSERT INTO reference (reference,link) VALUES ('".$formdata['reference']."','".$formdata['link']."') RETURNING id"; + $sth = $this->db->prepare($sql); + if($sth->execute()) + { + $row = $sth->fetch(PDO::FETCH_ASSOC); + $sql="update mdref set refid=?,reftype=? where uuid=? and id=?"; + $td = $this->db->query($sql,array($row['id'],$formdata['reftype'],$formdata['uuid'],$edit)); + $this->messenger->addMessage('提示信息:您已经编辑该数据文献。'); + $this->_redirect('/admin/data/reference/show/'.$formdata['uuid']); + }else + { + $this->messenger->addMessage('提示信息:文献创建失败,请重试'); + $this->_redirect('/admin/data/reference/edit/'.$edit); + } + } + } else { + $form->populate($formdata); + } + } else { + $sql="select m.uuid,r.reference,r.link,m.reftype from reference r left join mdref m on r.id=m.refid where m.id=?"; + $formdata=$this->db->fetchRow($sql,array($edit)); + $form->populate($formdata); + } + $this->view->form=$form; + $this->_helper->viewRenderer('referenceadd'); + } //编辑相关文献 + + elseif ($delete) { + $sql = "select uuid from mdref where id=$delete"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + $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/show/'.$row['uuid']); + } //删除相关文献 + + elseif ($import) { + if ($this->_request->isPost()) { + if ($_FILES["ref"]["error"] == UPLOAD_ERR_OK) { + $tmp_name = $_FILES["ref"]["tmp_name"]; + $fp = fopen($tmp_name, "rb"); + $ref=fread($fp, filesize($tmp_name)); + fclose($fp); + $lines=explode("\n",$ref); + foreach($lines as $line) + { + $data=explode(";",$line); + if (count($data)==2) + $link=''; + else + $link=$data[2]; + $link=$this->db->quote($link); + $sql="insert into reference (reference,link) values(?,".$link.")"; + try { + $this->db->exec($this->db->quoteInto($sql,trim($data[1]))); + } catch (Exception $e) {} + $sql="select id from reference where reference=?"; + $row=$this->db->fetchRow($this->db->quoteInto($sql,trim($data[1]))); + $sql="insert into mdref (uuid,refid) values(?,".$row['id'].")"; + try { + $this->db->exec($this->db->quoteInto($sql,trim($data[0]))); + } catch (Exception $e) {} + } + }//end if + } + $this->_helper->viewRenderer('referenceimport'); + } //引用 + + 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{ + $sql="select m.title as mdtitle,m.uuid,mr.id as mdid,mr.refid,mr.place,r.reference + from mdref mr right join metadata m on mr.uuid=m.uuid + left join reference r on mr.refid=r.id + order by m.ts_created desc,mr.place"; + $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.phtml'); + $this->view->paginator=$paginator; + + }//列表 + } + + //文献管理 + public function refAction() + { + $this->view->ac = $ac = $this->_getParam('ac'); + $submit = $this->_getParam('submit'); + $keyword = $this->view->q = trim($this->_getParam('q')); + $order = $this->view->search_order = trim($this->_getParam('order')); + $sort = $this->view->search_sort = trim($this->_getParam('sort')); + $field = $this->view->search_field = $this->_getParam('field'); + + $reference = new Reference(); + + if(!empty($keyword)) + { + $reference->keyword = $keyword; + } + + if(!empty($field)) + { + $reference->field = $field; + } + + if(!empty($order)) + { + $reference->order = $order; + } + + if(!empty($sort)) + { + $reference->sort = $sort; + } + + $this->view->reference = $reference; + $this->view->page = $this->_getParam('page'); + $this->view->pagelimit = 12; + + //文献首页 + if(empty($ac)) + { + $this->view->referenceType = $reference->referenceType(); + view::addPaginator($reference->fetchReferences(),$this, $this->view->pagelimit); + $this->view->years = $reference->countByYear(); + return true; + } + else if ($ac == "water") + { + $this->view->referenceType = $reference->referenceType(); + view::addPaginator($reference->fetchThemeReferences('water'),$this,$this->view->pagelimit); + return true; + } + else if ($ac == "westdc") + { + $this->view->referenceType = $reference->referenceType(); + view::addPaginator($reference->fetchWestdcReferences(),$this,$this->view->pagelimit); + return true; + } + else if ($ac == "todo") + { + $this->view->referenceType = $reference->referenceType(); + view::addPaginator($reference->fetchTodoReferences(),$this,$this->view->pagelimit); + return true; + } + + unset($this->view->reference); + unset($this->view->page); + unset($this->view->pagelimit); + + //添加 + if($ac == "add") + { + $this->_helper->viewRenderer('ref-add'); + $id = $this->_getParam('id'); + $attid = $this->_getParam('attid'); + + if(!empty($submit)) + { + $this->view->data = $reference->getReferenceParam(); + $attid = $this->view->data['attid']; + + if(empty($id) || !is_numeric($id)) + { + $status = $reference->reference(); + }else{ + $status = $reference->reference($id); + } + + if($status !== true) + { + $this->view->error = view::Error($status); + }else{ + if(!empty($id)) + { + $msg = "文献修改成功!"; + view::Post($this,$msg,-2); + return true; + }else{ + $msg = "文献添加成功!"; + view::Post($this,$msg,"/admin/data/ref/ac/add"); + return true; + } + } + }else{ + $this->view->data = array(); + if(!empty($id) && is_numeric($id)) + { + $this->view->data = $reference->getOneReferenceData($id); + } + } + + if(!empty($attid)) + { + $files = new Files(); + $attfile = $files->getOne($attid); + $this->view->data['attid'] = $attid; + $this->view->data['file'] = $attfile; + } + + return true; + } + + //上传pdf + if($ac == "pdfupload") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $autoread = false; + if($this->_getParam('multi')) + { + $autoread = true; + } + $statu = $reference->uploadReferencePdf($_FILES['Filedata'],$autoread); + $this->jsonexit($statu); + return true; + } + + //删除已上传的文件 + if($ac == "delete") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $statu = $reference->deleteReferenceAttchment($this->_getParam('attid')); + $this->jsonexit($statu); + return true; + } + + //批量上传 + if($ac == "multiupload") + { + $this->_helper->viewRenderer('ref-multiupload'); + return true; + } + + //文件管理 + if($ac == "files") + { + $this->_helper->viewRenderer('ref-files'); + view::addPaginator($reference->getReferenceFiles(),$this,10); + return true; + } + + //删除文献 + if($ac == "deleteref") + { + $refid = $this->_getParam('id'); + if($reference->deleteReference($refid)) + { + view::Post($this,"删除成功!",-1); + }else{ + view::Post($this,"删除失败!",-1); + } + return true; + } + + //相关数据 + if($ac == "data") + { + $refid = $this->view->refid = $this->_getParam('id'); + if(view::isXmlHttpRequest($this)){ + $this->jsonexit($reference->getDataByReference($refid)); + return true; + }else{ + $this->_helper->viewRenderer('ref-metadatas'); + $this->view->referenceType = $reference->referenceType(); + view::addPaginator($reference->getDataByReference($refid),$this,10); + return true; + } + } + + //添加数据文献 + if($ac == "mdref" && view::isXmlHttpRequest($this)) + { + $mdrefid = $this->_getParam('id'); + $status = $reference->makeMdref($mdrefid); + if($status !== true) + { + $this->jsonexit(array('error'=>$status)); + }else{ + $this->jsonexit(array('success' => 1)); + } + return true; + } + + //移除数据文献 + if($ac == "delmdref") + { + $mdrefid = $this->_getParam('id'); + $status = $reference->delMdref($mdrefid); + if($status === true) + { + view::Post($this,"移除成功",-1); + }else{ + view::Post($this,$status,-1); + } + return true; + } + + //ris + if($ac == "ris") + { + $this->_helper->viewRenderer('ref-ris'); + $submit = $this->_getParam('submit'); + + if(!empty($submit)) + { + $ris = new \Reference\Ris(); + $this->view->data = $ris->loadout(); + try{ + $ris->pushToDataTable($this->view->data); + }catch(Exception $e) + { + view::Dump($e->getMessage(),false); + } + } + } + + //ris更新单篇 + if($ac == "singleris") + { + $this->_helper->viewRenderer('ref-singleris'); + $id = (int)$this->_getParam('id'); + $this->view->ristext = $this->_getParam('ristext'); + + if($id < 1) + { + view::Post($this,"参数错误!",-1); + return true; + } + + $this->view->referenceData = $reference->getOneReferenceData($id); + + if(!empty($submit)) + { + $ris = new Ris(); + $data = $ris->loadout(); + + if(count($data) < 1) + { + view::Post($this,"输入的RIS信息有误".'查看详细',-1); + return true; + } + + if($ris->updateWithRis($id,$data[0]) === true) + { + view::Post($this,"编辑成功!".'查看详细',-2); + return true; + }else{ + view::Post($this,"编辑失败!".'查看详细',-1); + return true; + } + } + + return true; + }//ris单篇更新 + + //ris导出 + if($ac == "risoutput") + { + $this->_helper->viewRenderer('ref-risoutput'); + $this->view->years = $reference->countByYear(); + + if(!empty($submit)) + { + $mode = $this->_getParam('mode'); + + $risOutput = new RisOutput(); + $preData = $risOutput->preRead($mode); + + $risData = $risOutput->processArrayDataToRisData($preData); + + $risText = $risOutput->output($risData); + + echo "
      ";
      +				echo $risText;
      +				echo "
      "; + } + }//ris output + + if($ac == "ristest") + { + $this->_helper->viewRenderer('ref-ris'); + $submit = $this->_getParam('submit'); + + if(!empty($submit)) + { + $ris = new \Reference\Ris(); + view::Dump($ris->processRis(NULL,$this->_getParam('ristext')),false); + } + } + + + }//文献管理 refAction() + + /* + * 删除元数据,删除前有确认 + */ + 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('/data'); + } 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='已成功处理数据目录信息!'; + } + }//datafileimportAction + + + function sourceAction() + { + $do = $this->_request->getParam('do'); + $uuid = $this->_request->getParam('uuid'); + $id = $this->_request->getParam('id'); + $q = $this->_request->getParam('q'); + $search = $this->_request->getParam('search'); + + if ($do == 'add') { + + $redirect = "/admin/data/source/"; + + if(!empty($_POST['submit'])) + { + try{ + $title = $this->_request->getParam('title'); + $uuid = $this->_request->getParam('uuid'); + $code = $this->_request->getParam('code'); + $description = $this->_request->getParam('description'); + $has_pages = $this->_request->getParam('has_pages'); + $has_agreement = $this->_request->getParam('has_agreement'); + + $data = array( + 'title' => $title, + 'uuid' => $uuid, + 'code' => $code, + 'description' => $description, + 'has_pages' => $has_pages, + 'has_agreement' => $has_agreement + ); + + if($this->db->insert('source',$data)) + { + $this->messenger->addMessage('添加来源信息成功'); + $this->_redirect($redirect); + } + }catch(Exception $e){ + $this->messenger->addMessage('添加来源信息失败:'.$e->getMessage()); + $this->_redirect('/admin/data/source/do/add'); + } + + } + + $this->_helper->viewRenderer('sourceadd'); + }// 添加项目来源 + + else if($do == 'edit' && !empty($id)) + { + + if(!empty($_POST['submit'])) + { + try{ + $title = $this->_request->getParam('title'); + $uuid = $this->_request->getParam('uuid'); + $code = $this->_request->getParam('code'); + $description = $this->_request->getParam('description'); + $has_pages = $this->_request->getParam('has_pages'); + $has_agreement = $this->_request->getParam('has_agreement'); + + $sql = "update source set title='$title',uuid='$uuid',code='$code',description='$description',has_pages='$has_pages',has_agreement='$has_agreement' where id='$id'"; + + if($this->db->exec($sql)) + { + $this->messenger->addMessage('修改来源信息成功'); + $this->_redirect("/admin/data/source/do/edit/id/$id"); + } + }catch(Exception $e){ + $this->messenger->addMessage('修改来源信息失败:'.$e->getMessage()); + $this->_redirect("/admin/data/source/do/edit/id/$id"); + } + + } + + $sql = "select * from source where id='$id'"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + + $this->view->info = $row; + + $this->_helper->viewRenderer('sourceadd'); + + }// 编辑单条信息 + + else if($do == 'datasource' && !empty($uuid)) + { + $redirect = "/admin/data/source/do/datasource/uuid/$uuid"; + + $this->view->uuid = $uuid; + $sql = "select md.title,ds.id,ds.sourceid,s.title as stitle,s.code from metadata md + left join datasource ds on ds.uuid=md.uuid + left join source s on s.id=ds.sourceid + where md.uuid='$uuid'"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + + $this->view->info = $row; + + if(!empty($_POST['submit'])) + { + $sourceid = $this->_request->getParam('sourceid'); + if(empty($sourceid)) + { + $this->messenger->addMessage('请选择项目来源'); + $this->_redirect($redirect); + } + + $sql=""; + if(empty($row['id'])) + { + $sql = "insert into datasource (uuid,sourceid) values ('$uuid','$sourceid')"; + }else + { + $sql = "update datasource set uuid='$uuid',sourceid='$sourceid' where id='{$row['id']}'"; + } + try{ + if($this->db->exec($sql)) + { + $this->messenger->addMessage('修改项目来源成功'); + $this->_redirect($redirect); + } + else + { + $this->messenger->addMessage('修改项目来源失败'); + $this->_redirect($redirect); + } + }catch (Exception $e){ + $this->messenger->addMessage('修改项目来源失败:'.$e->getMessage()); + $this->_redirect($redirect); + } + + } + + + $wheresql = array(); + + if(!empty($q) && !empty($search)) + { + $this->view->q = $q; + $wheresql[] = " title like '%$q%' "; + } + + if(count($wheresql>0))$wheresql = join(' and ',$wheresql); + else $wheresql=''; + + if($wheresql!='') + { + $wheresql = 'where '.$wheresql; + } + + $sql = "select * from source $wheresql order by id desc"; + $rs = $this->db->query($sql); + $rows = $rs->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; + + $this->_helper->viewRenderer('sourceselect'); + }// 为元数据选择项目来源 + + else if($do == 'del' && !empty($id)) + { + $redirect = "/admin/data/source/"; + $sql = "delete from source where id='$id'"; + try{ + if($this->db->exec($sql)) + { + $this->messenger->addMessage('删除成功'); + $this->_redirect($redirect); + }else{ + $this->messenger->addMessage('删除失败,可能该数据已不存在'); + $this->_redirect($redirect); + } + }catch (Exception $e){ + $this->messenger->addMessage('删除失败:'.$e->getMessage()); + $this->_redirect($redirect); + } + }// 删除项目来源 + + else if($do == 'fetch' && !empty($id)) + { + + $wheresql = array(); + + $wheresql[] = " ds.sourceid='$id' "; + + if(!empty($q) && !empty($search)) + { + $this->view->q = $q; + $wheresql[] = " title like '%$q%' "; + } + + if(count($wheresql>0))$wheresql = join(' and ',$wheresql); + else $wheresql=''; + + if($wheresql!='') + { + $wheresql = 'where '.$wheresql; + } + + $sql = "select md.title,md.uuid,ds.id,ds.sourceid,s.title as stitle,s.code from metadata md + left join datasource ds on ds.uuid=md.uuid + left join source s on s.id=ds.sourceid + $wheresql + order by id desc"; + $rs = $this->db->query($sql); + $rows = $rs->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; + + $this->_helper->viewRenderer('sourcefetchone'); + + }//查看某项目来源中的所有元数据 + + else if($do == 'delsource' && !empty($id)) + { + $redirect = "/admin/data/source/do/datasource/uuid/$uuid"; + + $sql = "delete from datasource where id='$id'"; + + try{ + if($this->db->exec($sql)) + { + $this->messenger->addMessage('删除成功'); + $this->_redirect($redirect); + }else{ + $this->messenger->addMessage('删除失败,可能该数据已不存在'); + $this->_redirect($redirect); + } + }catch (Exception $e){ + $this->messenger->addMessage('删除失败:'.$e->getMessage()); + $this->_redirect($redirect); + } + + + }// 清除元数据来源记录 + elseif ($do=='sync') { //同步数据来源到metadata表 + $redirect = "/admin/data/source/"; + $sql = "update metadata m set source=s.uuid from source s right join datasource d on s.id=d.sourceid where m.uuid=d.uuid"; + if($this->db->exec($sql)) + { + $this->messenger->addMessage('成功同步数据来源'); + $this->_redirect($redirect); + }else{ + $this->messenger->addMessage('同步数据来源失败'); + $this->_redirect($redirect); + } + } + + else + { + $wheresql = array(); + + if(!empty($q) && !empty($search)) + { + $this->view->q = $q; + $wheresql[] = " title like '%$q%' "; + } + + if(count($wheresql>0))$wheresql = join(' and ',$wheresql); + else $wheresql=''; + + if($wheresql!='') + { + $wheresql = 'where '.$wheresql; + } + + $sql = "select * from source $wheresql order by id desc"; + $rs = $this->db->query($sql); + $rows = $rs->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; + }// 项目来源管理 + + + }//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'); + $uuid = $this->_request->getParam('uuid'); + $mdtitle = $this->_request->getParam('mdtitle'); + $mdattdel = $this->_request->getParam('mdattdel'); + $attupdate = $this->_getParam('attupdate'); + + if(!empty($uuid)&&!empty($mdtitle)) + { + $this->view->uuid= $uuid; + $this->view->mdtitle=$mdtitle; + } + + if($add) + { + $this->_helper->viewRenderer('attachmentsadd'); + if(!empty($uuid)) + { + $this->view->uuid = $uuid; + } + }//附件添加 + + elseif($attupdate) + { + $submit = $this->_getParam('submit'); + if(!empty($submit)) + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $id = $this->_getParam('attupdate'); + + $files=new Files(); + $msg = $files -> upload($_FILES['Filedata'],empty($uuid)?'file/':'md/',true); + + if(empty($msg['error'])) + { + $msg['error']=""; + $filename = $msg['db_path']; + $filesize = $msg['file_size']; + $filedesc = $this->_request->getParam('filedesc'); + $filetype = 'md'; + $realname = $msg['realname']; + + + $sql = "UPDATE attachments SET filename=?,filetype=?,filesize=?,realname=? WHERE id=?"; + $sth = $this->db->prepare($sql); + $ds = $sth->execute(array($filename,$filetype,$filesize,$realname,$id)); + + if($ds) + { + $msg['html'] = $realname.'['. round($filesize/1024,2) .' kb]'; + $msg['ok']= 1; + echo Zend_Json::encode($msg); + exit(); + }else{ + @unlink($filename); + $data = array("error"=>'附件上传失败:写入附件表出错'); + $this->jsonexit($data); + return true; + } + }else{ + @unlink($filename); + $data = array("error"=>'附件上传失败:'.$msg['error']); + $this->jsonexit($data); + return true; + } + + + $data = array("error"=>"处理中出现错误".$id); + $this->jsonexit($data); + return true; + }else{ + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer('attachments-update'); + $id = $this->_getParam('attupdate'); + $this->view->id = $id; + } + + }//附件文件更新 + + else if($mdattdel) + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + + $sql = "delete from mdattach where uuid=? AND id=?"; + $sth = $this->db->prepare($sql); + $ds = $sth->execute(array($uuid,$mdattdel)); + if($ds) + { + $data = array("status"=>1); //操作状态代码 : 1=>成功 2=>失败 + $this->jsonexit($data); + return true; + }else{ + $data = array("error"=>"处理中出现错误"); + $this->jsonexit($data); + return true; + } + } + + else if($delete) + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + + //需要删除文件,通过Zend_Registry::get('upload')获得上传文件的根目录 + + $basepath = $this->view->config->upload; + + //从数据库获取文件路径 + + $info = $this->getFileinfo($delete); + + $filepath = $basepath.$info['filename']; + + $sql = "SELECT * FROM mdattach WHERE id=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($delete)); + $rows = $sth->fetchAll(); + + if(count($rows)>0) + { + $data = array("error"=>'删除失败!该文件有元数据附件信息,不能直接删除',"status"=>0); + $this->jsonexit($data); + return true; + } + + $sql = "SELECT * FROM mdreviewattach WHERE attachid=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($delete)); + $rows = $sth->fetchAll(); + + if(count($rows)>0) + { + $data = array("error"=>'删除失败!该文件有对应评审附件信息,不能直接删除',"status"=>0); + $this->jsonexit($data); + return true; + } + + $sql = "SELECT link FROM reference WHERE link!=''"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $rows = $sth->fetchAll(); + + $ids = array(); + foreach($rows as $k=>$v) + { + if(preg_match("/service/i",$v['link'])) + { + $ids[] = str_replace("/service/attach/id/","",$v['link']); + } + unset($rows[$k]); + } + unset($rows); + + if(in_array($delete,$ids)) + { + $data = array("error"=>'删除失败!该文件有对应文献附件信息,不能直接删除',"status"=>0); + $this->jsonexit($data); + return true; + } + + if(unlink($filepath)) + { + $sql = "delete from attachments where id='$delete'"; + if($this->db->exec($sql)>0) + { + $data = array("status"=>1); + $this->jsonexit($data); + return true; + } + } + else + { + $sql = "delete from attachments where id='$delete'"; + if($this->db->exec($sql)>0) + { + $data = array("error"=>'文件删除失败,仅删除数据库记录,请手动删除文件:'.$info['filename'],"status"=>0); + $this->jsonexit($data); + return true; + } + } + + }//删除 + + 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 if ($down>0) + { + + $sql = "select * from attachments where id='$down'"; + + $re = $this->db->query($sql); + + $row = $re->fetch(); + + $file = new files(); + + $fullPath = $this->view->config->upload.$row['filename']; + + + // Parse Info / Get Extension + $fsize = filesize($fullPath); + $path_parts = pathinfo($fullPath); + $ext = strtolower($path_parts["extension"]); + + // Determine Content Type + switch ($ext) { + case "pdf": $ctype="application/pdf"; break; + case "exe": $ctype="application/octet-stream"; break; + case "zip": $ctype="application/zip"; break; + case "doc": $ctype="application/msword"; break; + case "xls": $ctype="application/vnd.ms-excel"; break; + case "ppt": $ctype="application/vnd.ms-powerpoint"; break; + case "gif": $ctype="image/gif"; break; + case "png": $ctype="image/png"; break; + case "jpeg": + case "jpg": $ctype="image/jpg"; break; + default: $ctype="application/force-download"; + } + + $content=file_get_contents($fullPath); + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $this->getResponse()->setHeader('Content-Type', 'application/octet-stream') + ->setHeader('Content-Disposition','attachment; filename="'.basename($fullPath).'"') + ->setHeader('Content-Length', $fsize) + ->setHeader('Content-Type','application/force-download') + ->setHeader('Content-Type','application/download') + ->setHeader('Content-Type',$ctype) + ->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); + + //$sql = "update attachments set downtimes=downtimes+1 where id='$down'"; + //$this->db->exec($sql); + + }//附件下载 + + else + { + + $sql="select * from attachments order by id desc"; + $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 附件 + + function uploadAction(){ + $this->_helper->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $uuid = $this->_getParam('uuid'); + + try{ + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $userid = $user->id; + } + + if(empty($userid)||!is_numeric($userid)){ + $msg['error'] = "请先登录"; + echo Zend_Json::encode($msg); + exit(); + } + + if($user->usertype!='administrator') + { + $msg['error'] = "您无权使用此功能"; + echo Zend_Json::encode($msg); + exit(); + } + + $files=new Files(); + $msg = $files -> upload($_FILES['Filedata'],empty($uuid)?'file/':'md/',true); + + if(empty($msg['error'])) + { + $msg['error']=""; + $filename = $msg['db_path']; + $filesize = $msg['file_size']; + $filedesc = $this->_request->getParam('filedesc'); + $filetype = 'md'; + $realname = $msg['realname']; + + + $sql = "insert into attachments (filename,filetype,filedesc,userid,filesize,realname) values ('$filename','$filetype','$filedesc','$userid','$filesize','$realname') RETURNING id"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $att = $sth->fetch(PDO::FETCH_ASSOC); + $msg['attid'] = $attid = $att['id']; + + $sql = "insert into mdattach (uuid,id) values ('$uuid','$attid')"; + if(empty($uuid) || $this->db->exec($sql)) + { + $msg['html'] = $realname.'['. round($filesize/1024,2) .' kb]
      '; + echo Zend_Json::encode($msg); + exit(); + }else{ + $msg['error'] = '附件上传失败:写入附件表出错'; + @unlink($filename); + echo Zend_Json::encode($msg); + exit(); + } + + + }else{ + $msg['error'] = '附件上传失败:'.$msg['error']; + @unlink($filename); + echo Zend_Json::encode($msg); + exit(); + } + + }catch(Exception $e){ + $msg['error'] = "错误:".$e->getMessage(); + echo Zend_Json::encode($msg); + exit(); + } + }// uploadAction ajax上传附件 + + function getattsAction(){ + + $this->_helper->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $uuid = $this->_request->getParam('uuid'); + + if($uuid!='') + { + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $userid = $user->id; + $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' + ORDER BY a.ts_created ASC"; + $rs = $this->db->query($sql); + $atts = $rs->fetchAll(); + + echo Zend_Json::encode($atts); + exit(); + }else + { + exit(); + } + }else{ + exit(); + } + //不输出错误 + }//获取附件 + + + /* + 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,g.id as gid FROM mdversion v + LEFT JOIN metadata md ON md.uuid=v.uuid + left join users u on v.userid=u.id + left join geonetworkmetadata g on md.uuid=g.uuid + 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,u.id 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'].'/service/doc/uuid/'.$row['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/'.$row['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" || $ac=="diff1") + { + $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(); + if ($ac=='diff') + { + $sql = "SELECT v.* FROM mdversion v + WHERE v.uuid=? and v.ts_created<=(select ts_created from mdversion where id=?) + ORDER BY v.ts_created DESC + LIMIT ?"; + $sth = $this->db->prepare($sql); + $sth -> execute(array($row['uuid'],$id,2)); + } else { + $sql = "SELECT v.* FROM mdversion v + WHERE v.uuid=? and (v.id=? or (v.ts_created<(select ts_created from mdversion where id=?) and changelog is not null)) + ORDER BY v.ts_created DESC + LIMIT ?"; + $sth = $this->db->prepare($sql); + $sth -> execute(array($row['uuid'],$id,$id,2)); + } + + $rows = $sth->fetchAll(); + + if(count($rows)<2) + { + $this->view->error = "对比失败:之前没有版本可以对比"; + return true; + } + + $this->view->info = $row; + $this->view->data = $rows; + + } + + + }//versionAction 版本控制 + + + /* + * authorAction() 数据作者 + * + * param string $ac //动作 + =add 添加 + =edit 编辑 + =update 更新 + =del 删除 + =list 列出所有数据作者 + + * param string $uuid //UUID + * + * return view|application-json + */ + public function authorAction(){ + + $ac = $this->_getParam('ac'); + $uuid = $this->_getParam('uuid'); + + if(empty($ac) && empty($uuid)) + { + + $keywords = $this->_request->getParam('q'); + if(!empty($keywords)) + $this->view->q = $keywords; + + $sql = "select md.id,md.title,md.uuid,count(a.userid) as c from metadata md + right JOIN mdauthor a ON md.uuid=a.uuid + "; + + if(!empty($keywords)) + { + $search=new SimpleSearch($keywords); + $where=$search->sql_expr(array("md.title")); + $sql.=' and ('.$where.")"; + } + + $sql .= "GROUP by md.id,md.title,md.uuid,md.ts_created + ORDER BY md.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 == 'add') + { + + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $username = $this->_getParam('username'); + $uuid = $this->_getParam('uuid'); + + if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid)) + { + $data = array("error"=>"uuid参数错误"); + $this->jsonexit($data); + return true; + } + + if(empty($username)) + { + $data = array("error"=>'请输入要添加为该数据作者的用户名'); + $this->jsonexit($data); + return true; + } + + $sql = "SELECT * FROM users WHERE username=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($username)); + $row = $sth->fetch(); + + if(empty($row['id']) || !isset($row['id'])) + { + $data = array("error"=>'您输入的用户名无任何对应用户'); + $this->jsonexit($data); + return true; + } + + $uid = $row['id']; + + $sql = "SELECT * FROM mdauthor WHERE userid=? AND uuid=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($row['id'],$uuid)); + $row = $sth->fetch(); + + if(!empty($row['id']) && $row['status']==1) + { + $data = array("error"=>'该用户已经是此数据的作者'); + $this->jsonexit($data); + return true; + } + + if(!empty($row['id']) && in_array($row['status'],array(0,-1)) ) + { + $sql = "UPDATE mdauthor SET status=1 WHERE uuid=? AND userid=?"; + $sth = $this->db->prepare($sql); + $ds = $sth->execute(array($uuid,$uid)); + if($ds) + { + $data = array("msg"=>'该用户已被提升为数据作者','added'=>1); + $this->jsonexit($data); + return true; + }else{ + $data = array("error"=>'处理中出现错误'); + $this->jsonexit($data); + return true; + } + } + + if(empty($row['id'])) + { + $sql = "INSERT INTO mdauthor (uuid,userid,status) VALUES (?,?,?)"; + $sth = $this->db->prepare($sql); + $ds = $sth->execute(array($uuid,$uid,1)); + if($ds) + { + $data = array("msg"=>'该用户已被添加为数据作者','added'=>1); + $this->jsonexit($data); + return true; + }else{ + $data = array("error"=>"处理中出现错误"); + $this->jsonexit($data); + return true; + } + } + + + $data = array("error"=>"处理中出现错误"); + $this->jsonexit($data); + return true; + + }//ajax 添加作者 + + + else if(($ac == "edit" || $ac=="") && !empty($uuid)) + { + + $window = $this->_getParam('window'); + + if($window == "iframe") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer('author-edit-iframe'); + }else{ + $this->_helper->viewRenderer('author-edit'); + } + + $sql = "SELECT a.*,md.title,u.realname,u.username FROM mdauthor a + LEFT JOIN metadata md ON a.uuid=md.uuid + LEFT JOIN users u ON a.userid=u.id + WHERE md.uuid=? + ORDER BY a.id DESC + "; + + $sth = $this->db->prepare($sql); + $sth->execute(array($uuid)); + $rows = $sth->fetchAll(); + + $this->view->authors = $rows; + + }// 作者管理弹窗 + + else if($ac == "del") + { + + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $id = $this->_getParam('id'); + + $sql = "DELETE FROM mdauthor WHERE id=?"; + $sth = $this->db->prepare($sql); + $ds = $sth->execute(array($id)); + if($ds) + { + $data = array("deleted"=>$id); + $this->jsonexit($data); + return true; + }else{ + $data = array("error"=>"处理中出现错误"); + $this->jsonexit($data); + return true; + } + + + }//移除作者 + + else if($ac == 'update') + { + + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $id = $this->_getParam('id'); + + $sql = "UPDATE mdauthor SET status=1 WHERE id=?"; + $sth = $this->db->prepare($sql); + $ds = $sth->execute(array($id)); + if($ds) + { + $data = array("updated"=>$id,'msg'=>'认证成功!'); + $this->jsonexit($data); + return true; + }else{ + $data = array("error"=>"处理中出现错误"); + $this->jsonexit($data); + return true; + } + + + }//认证作者 + + else if($ac =="list") + { + $this->_helper->viewRenderer('author-list'); + + $sql = "SELECT u.id,u.realname,u.email,count(a.id) as d FROM mdauthor a + LEFT JOIN users u ON a.userid=u.id + WHERE a.status>0 + GROUP BY u.id,u.realname,u.email + ORDER BY u.id 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 == "userdatas") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $id = $this->_getParam('id'); + + $sql = "SELECT md.title,md.uuid FROM mdauthor a + LEFT JOIN metadata md ON a.uuid=md.uuid + WHERE a.userid=? AND a.status>0 + ORDER BY a.ts_created"; + $sth = $this->db->prepare($sql); + $sth->execute(array($id)); + $rows = $sth->fetchAll(); + + $data = array("datas"=>$rows); + $this->jsonexit($data); + return true; + + }//用户数据 + + else if($ac == "datas") + { + $this->_helper->viewRenderer('author-datas'); + + $keywords = $this->_request->getParam('q'); + if(!empty($keywords)) + $this->view->q = $keywords; + + $sql = "select md.id,md.title,md.uuid,count(a.userid) as c from metadata md + left JOIN mdauthor a ON md.uuid=a.uuid + "; + + if(!empty($keywords)) + { + $search=new SimpleSearch($keywords); + $where=$search->sql_expr(array("md.title")); + $sql.=' WHERE '.$where; + } + + $sql .= "GROUP by md.id,md.title,md.uuid,md.ts_created + ORDER BY md.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; + + } + + }//authorAction() 数据作者管理 + + + //newdataAction() 新建元数据 + public 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(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $u_id = $user->id; + } + + //在geonetwork中查看单条数据 + if (!empty($id) && empty($ac)) + { + $this->view->url='metadata.show?id='.$id; + $this->_helper->viewRenderer('newdata-view'); + } + //查看所有的未提交数据列表 + else if((empty($ac) && empty($uuid))|| $ac=='list') + { + $sql = "SELECT (regexp_matches(gn.data,'(.*)'))[1] as title,gn.id,gn.uuid,u.username,u.realname FROM geonetworkmetadata gn left join users u on gn.owner=u.id + WHERE gn.uuid not in (select uuid from metadata) + order by gn.id 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=="import") + { + $this->_helper->viewRenderer('newdata-import'); + } + //从模板新建元数据 + else if($ac=="add-by-template") + { + $keywords = $this->_request->getParam('q'); + $sql="select id,(regexp_matches(data,'(.*)'))[1] as title,(owner-$u_id) as isowner from metadata where istemplate='y' and schemaid='iso19115'"; + if(!empty($keywords)) + { + $this->view->q = $keywords; + $search=new Search($keywords); + $where=$search->sql_expr(array("data")); + $sql.=' and '.$where; + } + $sql.=" order by changedate desc"; + $sth = $this->wdb->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('newdata-add'); + } + + else if($ac=="add-by-data") + { + $keywords = $this->_request->getParam('q'); + $sql = "SELECT md.title,md.uuid,md.description,gn.id as gid FROM normalmetadata md + left join geonetworkmetadata gn on md.uuid=gn.uuid + WHERE gn.id is not null"; + if(!empty($keywords)) + { + $this->view->q = $keywords; + $search=new Search($keywords); + $where=$search->sql_expr(array("md.title","md.description")); + $sql.=' and '.$where; + } + $sql.=" order by md.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(10); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); + $this->view->paginator=$paginator; + $this->_helper->viewRenderer('newdata-add-bydata'); + } + //元数据格式检查 + else if ($ac=="validate") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $data = ""; + $id = $this->_request->getParam('id'); + $sql="select uuid,data from geonetworkmetadata where id=?"; + $sth=$this->db->prepare($sql); + $sth->execute(array($id)); + $row=$sth->fetch(); + + $iso=new ISO19115(); + @$iso->loadXML($row['data']); + if ($iso->validate()) + { + $data=array("error"=>"元数据中发现错误。
      ".implode("
      ",$iso->error)); + $this->jsonexit($data); + return true; + } else { + $data=array("error"=>"元数据中没有发现错误。
      "); + $this->jsonexit($data); + return true; + } + } + //提交数据 + else if($ac=="commit") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $data = ""; + $id = $this->_request->getParam('id'); + try{ + 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. 权限认定:当前用户必须和其owner相同 + // 数据应当没有评审状态,没有作者信息 + $sql="select uuid,data from geonetworkmetadata where id=?"; + $sth=$this->db->prepare($sql); + $sth->execute(array($id)); + $row=$sth->fetch(); + if (empty($row)) + { + $data = array("error"=>'无权限修改数据'); + $this->jsonexit($data); + return true; + } + + // 保存数据作者信息 + + // 2. 保存变化记录 save changelog & userid for the latest version + $sql = "UPDATE mdversion SET changelog=?,userid=? WHERE id in (select v.id from mdversion v left join geonetworkmetadata g on v.uuid=g.uuid where g.id=? order by v.ts_created desc limit 1)"; + $this->db->query($sql,array($changelog,$u_id,$id)); + + // 3. 保存数据评审状态 + //导入元数据 + $iso=new ISO19115(); + @$iso->saveDB($this->db,$row['data']); + //进入评审库 + $sql="insert into mdstatus (uuid,status,userid) select uuid,0,? from geonetworkmetadata 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(); + + $data = array("commited"=>1,"error"=>'该版本已经成功提交,请等待数据中心进一步处理!'); + $this->jsonexit($data); + return true; + }catch(Exception $e) { + $sql="delete from mdstatus where uuid in (select uuid from geonetworkmetadata where id=?)"; + $this->db->query($sql,array($id)); + $msg = "提交失败,请确认权限后重试"; + if($this->debug>0) + {$msg .= $e->getMessage();} + $data = array("error"=>$msg); + $this->jsonexit($data); + return true; + } + } + + }// newdataAction() 新建元数据 + + /* + * projectsAction() 数据汇交计划 + * + * + * + * + */ + function projectAction() + { + include_once("Heihe.php"); + $heihe = new Heihe($this->db); + + $this->view->input_NameDefaultVal = "专家姓名"; + $this->view->input_EmailDefaultVal = "专家email"; + + $projectTable = $heihe->tbl_heiheproject; + + $ac = $this->_getParam('ac'); + + if(empty($ac) || $ac == "index") + { + $this->_helper->viewRenderer('project'); + + //Search Link + $this->view->searchLink = "/admin/heihe/project/ac/index/"; + + $q = $this->_getParam('q'); + + $wheresql = array(); + + if(!empty($q)) + { + $wheresql[] = " (title LIKE '%$q%' OR + code LIKE '%$q%' OR + name LIKE '%$q%' OR + email LIKE '%$q%')"; + $this->view->searchKeyword = $q; + } + + if(count($wheresql)>0) + { + $wheresql = join(" AND ",$wheresql); + }else{ + $wheresql = ""; + } + + if(!empty($wheresql)) + { + $wheresql = " WHERE ".$wheresql; + } + + $sql = "SELECT * FROM $projectTable $wheresql + ORDER BY id ASC"; + $sth = $this->db->query($sql); + $rows = $sth->fetchAll(); + + foreach ($rows as $k=>$v) + { + $rows[$k]['status_alias'] = $heihe->getStatus($v['status']); + } + + $this->view->Count = count($rows); + + $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; + + $this->view->project_status = $heihe->project_status; + + return true; + }//ac == index + + //邀请专家 + if($ac == "invite") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $pid = $this->_getParam('id'); + $name = $this->_getParam('name'); + $email = $this->_getParam('email'); + + if(!is_numeric($pid)) + { + $this->jsonexit(array("error"=>"参数错误")); + return true; + } + + if(empty($name) || $name == $this->view->input_NameDefaultVal) + { + $this->jsonexit(array("error"=>"请输入专家姓名")); + return true; + } + + if(empty($email) || $email == $this->view->input_EmailDefaultVal) + { + $this->jsonexit(array("error"=>"请输入专家Email")); + return true; + } + + $code = $heihe->makeValidation($email); + + $expert_data = array( + "name"=>$name, //专家姓名 + "email"=>$email, //专家email + "created"=>date("Y-m-d H:i:s",time()), //邀请时间 + "validation"=>$code, //验证码 + ); + + $rs = $heihe->expertAdd($pid,$expert_data); + + if($rs > 0) + { + $this->sendMailToExpert($pid,$name,$email,$code);// 最后再加入一个非0的数字型参数即可使用调试邮箱发送 + $this->jsonexit(array("msg"=>"专家邀请成功!","invited"=>1)); + return true; + }else if($rs==-1){ + $this->jsonexit(array("error"=>"该专家已经邀请过")); + return true; + }else{ + $this->jsonexit(array("error"=>"邀请失败,请重试")); + return true; + } + + return true; + }// 邀请专家 + + if($ac == "showexpert") + { + + $this->_helper->layout->setLayout('layout-iframe'); + $this->_helper->viewRenderer('project-showexpert'); + + $pid = $this->_getParam('id'); + + if(empty($pid) || !is_numeric($pid)) + { + $this->view->error = "参数错误"; + return true; + } + + $this->view->pid = $pid; + + $experts = $heihe->expertRead($pid); + + if(!is_array($experts)) + { + $this->view->error = "此项目还没有邀请专家"; + return true; + } + + foreach($experts as $k=>$v) + { + $experts[$k]['url'] = $heihe->makeInviteLink($pid,$v['validation']); + } + + $this->view->experts = $experts; + + return true; + }//ac == showexpert 查看跟踪专家 + + if($ac == "remove") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $pid = $this->_getParam('id'); + $del = $this->_getParam('del'); + + if(!empty($del) && !empty($pid)) + { + + $rs = $heihe->expertRemove($pid,$del); + + if($rs) + { + $this->jsonexit(array("deleted"=>1)); + return true; + }else{ + $this->jsonexit(array("error"=>"删除失败,请重试")); + return true; + } + + }else{ + $this->jsonexit(array("error"=>"参数错误,请刷新")); + return true; + } + + }//ac == remove 删除专家 + + if($ac == "upload") + { + $this->_helper->layout->setLayout('layout-iframe'); + $this->_helper->viewRenderer('project-upload'); + + $submit = $this->_getParam('submit'); + + $pid = $this->_getParam('pid'); + + if(empty($pid) || !is_numeric($pid)) + { + $this->view->error = "参数错误"; + return true; + } + + $this->view->pid = $pid; + + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $uid = $user->id; + } + + if(!empty($submit) && empty($this->view->error)) + { + + $files=new files(); + $msg = $files -> upload($this->view->config->upload,$_FILES['Filedata'],'heihe'); + + if(empty($msg['error'])) + { + $msg['error']=""; + $filename = $msg['db_path']; + $filesize = $msg['file_size']; + $filedesc = $this->_request->getParam('filedesc'); + $filetype = $msg['file_type']; + $realname = $msg['realname']; + + if(!empty($row['attachid'])) + { + $sql = "SELECT * FROM attachments WHERE id={$row['attachid']}"; + $sth = $this->db->query($sql); + $attach = $sth->fetch(); + $this->db->exec("DELETE FROM attachments WHERE id={$row['attachid']} AND filetype='heihe'"); + @unlink($this->view->config->upload.$attach['filename']); + } + + $sql = " INSERT INTO attachments (filename,filetype,filedesc,userid,filesize,realname) values + ('$filename','heihe','$filedesc','$uid','$filesize','$realname') RETURNING id"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $att = $sth->fetch(PDO::FETCH_ASSOC); + $msg['attid'] = $attid = $att['id']; + + $sql = "UPDATE heiheproject SET attachid=$attid WHERE id=$pid"; + $sth = $this->db->exec($sql); + + if($sth) + { + $this->view->message = "上传成功"; + }else{ + @unlink($filename); + $this->view->error = '附件上传失败:写入附件表出错'; + return true; + } + }else{ + @unlink($filename); + $this->view->error = "附件上传失败".$msg['error']; + return true; + } + } + + $sql = "SELECT * FROM heiheproject WHERE id=$pid"; + $sth = $this->db->query($sql); + $row = $sth->fetch(); + + if(!empty($row['attachid'])) + { + $sql = "SELECT * FROM attachments WHERE id = {$row['attachid']}"; + $sth = $this->db->query($sql); + $this->view->att = $sth->fetch(); + } + + return true; + }//ac == upload + + //改变状态 + if($ac == "changestatus") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $project = $this->_getParam('p'); + $status = $this->_getParam('s'); + + if(!is_numeric($status)) + { + $this->jsonexit(array('error'=>'参数错误')); + return true; + } + + $code = $heihe->ChangeStatus($project,$status); + + if($code > 0) + { + $this->jsonexit( + array( + 'msg'=>'修改成功!', + 'status'=>$heihe->getStatus($status) + ) + ); + return true; + }else{ + $this->jsonexit(array('error'=>'参数错误')); + return true; + } + + }//ac == "changestatus" + + }//projectsAction() + + public function fundAction() + { + $this->_helper->layout->setLayout('administry'); + $ac = $this->_getParam('ac'); + $submit = $this->_getParam('submit'); + $this->view->q = $keyword = $this->_getParam('q'); + + include_once("helper/view.php"); + include_once("data/Fund.php"); + $fund = new Fund($this->db); + + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $uid = $user->id; + } + + if($ac=='index' || empty($ac)) + { + $uuid = $this->_getParam('uuid'); + if(empty($uuid)) + { + $rows = $fund->fetch(NULL,true,0,$keyword); + view::addPaginator($rows,$this,10); + }else{ + include('data/Metadata.php'); + $md = new Metadata($this->db); + $this->view->md = $md->view($uuid); + $rows = $fund->fetch($uuid); + view::addPaginator($rows,$this,10); + } + return true; + } + + if($ac == 'datalist') + { + $this->_helper->viewRenderer('fund-data-list'); + $this->view->q = $q = $this->_getParam('q'); + $rows = $fund->fetchFromData(true,0,$q); + view::addPaginator($rows,$this,10); + return true; + } + + if($ac == 'dataview') + { + $this->_helper->viewRenderer('fund-data-view'); + $this->view->q = $q = $this->_getParam('q'); + $id = $this->_getParam('id'); + $this->view->fund = $fund->view($id); + $rows = $fund->fetchFromData($id,0,$q); + view::addPaginator($rows,$this,10); + return true; + } + + if($ac == "add") + { + $this->_helper->viewRenderer('fund-add'); + if(!empty($submit)) + { + $data = $fund->_getParams($this->_request); + $data['userid'] = $uid; + + if($fund->add($data) == true) + { + $this->view->AlertType = "alert-success"; + $this->view->msg = "添加成功!"; + $this->view->jump_url = "/admin/data/fund/"; + return true; + }else{ + $this->view->data = $data; + $this->view->error = "添加失败,请重试"; + return true; + } + } + return true; + }//add + + if($ac == "edit") + { + $this->_helper->viewRenderer('fund-add'); + $id = $this->_getParam('id'); + + if(empty($id)) + { + $this->view->AlertType = "alert-error"; + $this->view->msg = "参数错误"; + $this->view->jump_url = "/admin/data/fund/"; + } + + if(!empty($submit)) + { + $data = $fund->_getParams($this->_request); + $data['userid'] = $uid; + if($fund->update($data,$id) == true) + { + $this->view->AlertType = "alert-success"; + $this->view->msg = "修改成功!"; + $this->view->jump_url = "/admin/data/fund/"; + return true; + }else{ + $this->view->data = $data; + $this->view->error = "修改失败,请重试"; + return true; + } + }else{ + $this->view->data = $fund->view($id); + } + return true; + }//edit + + if($ac == "del") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $id = $this->_getParam('id'); + + if(empty($id)) + { + $this->jsonexit(array('error'=>'参数错误')); + return true; + } + + if($fund->delete($id) == true) + { + $this->jsonexit(array('success'=>$id)); + return true; + }else{ + $this->jsonexit(array('error'=>'删除失败')); + return true; + } + + }//del + + if($ac == "formd") + { + $uuid = $this->_getParam('uuid'); + + if(empty($uuid)) + { + $this->view->AlertType = "alert-error"; + $this->view->msg = "参数错误"; + $this->view->jump_url = "/admin/data/fund/"; + } + + $id = $this->_getParam('id'); + $order = $this->_getParam('order'); + + if(!empty($id)) + { + if($fund->addToMdfund($uuid,$id,$order)) + { + $this->view->AlertType = "alert-success"; + $this->view->error = "添加成功!可以继续选择并添加"; + }else{ + $this->view->AlertType = "alert-error"; + $this->view->error = "添加失败!该数据可能已被添加"; + } + } + + $mfid = $this->_getParam('mfid'); + + if(!empty($mfid)) + { + if($fund->changeorder($mfid,$order)) + { + $this->view->AlertType = "alert-success"; + $this->view->error = "排序修改成功!"; + }else{ + $this->view->AlertType = "alert-error"; + $this->view->error = "排序修改失败!"; + } + $rows = $fund->fetch($uuid); + }else{ + $this->view->ct = "ct"; + $rows = $fund->fetch($uuid,false,0,$this->_getParam('q')); + } + + include('data/Metadata.php'); + $md = new Metadata($this->db); + $this->view->md = $md->view($uuid); + + view::addPaginator($rows,$this,10); + + return true; + }//formd + + if($ac == "mdfunddel") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $id = $this->_getParam('id'); + + if(empty($id)) + { + $this->jsonexit(array('error'=>'参数错误')); + return true; + } + + if($fund->mfdelete($id) == true) + { + $this->jsonexit(array('success'=>$id)); + return true; + }else{ + $this->jsonexit(array('error'=>'删除失败')); + return true; + } + }//mdfunddel + + if($ac == "data") + { + $this->_helper->viewRenderer('fund-data'); + + $id = $this->_getParam('id'); + $del = $this->_getParam('del'); + $this->view->info = $fund->view($id); + + if(!empty($del)) + { + $s = $fund->dataRelationDelete($del); + if($s) + { + $this->view->error = view::Error("删除成功!","alert-sccuess"); + }else{ + $this->view->error = view::Error("删除失败!","alert-error"); + } + } + + $rows = $fund->getData($id,$keyword); + view::addPaginator($rows,$this,10); + } + + }//fund + + public function doiAction() + { + $ac = $this->_getParam('ac'); + $submit = $this->_getParam('submit'); + $uuid = $this->_getParam('uuid'); + $q=$this->_getParam('q'); + + include_once("data/Doi.php"); + $doi = new Doi($this->db); + include_once("helper/view.php"); + + if( empty($ac) || $ac == "index") + { + if(empty($uuid)) + { + $rows = $doi->fetch(0,$q); + view::addPaginator($rows,$this,10); + }else{ + $this->_redirect('/admin/data/doi/ac/edit/?uuid='.$uuid); + return true; + } + return true; + }//index + + else if($ac == "add") + { + $this->_helper->viewRenderer('doi-add'); + + }//add + + else if($ac == "edit") + { + $this->_helper->viewRenderer('doi-add'); + $id = $this->_getParam('id'); + if(empty($uuid) && empty($id)) + { + view::Msg('alert-error',"参数错误",-1); + return false; + } + + if(empty($submit)){ + if(!empty($uuid)) + { + $this->view->uuid = $uuid; + $this->view->data = $doi->view($uuid); + include('data/Metadata.php'); + $md = new Metadata($this->db); + $metadata = $md->view($uuid); + if(empty($this->view->data)) + { + $this->view->data = array( + 'uuid'=>$uuid, + 'title'=>$metadata['title'], + 'doi'=>$metadata['doi'], + 'url'=>"http://" . $_SERVER['HTTP_HOST'].'/data/'.$uuid, + 'publisher'=>'寒区旱区科学数据中心', + 'title_en'=>$metadata['title_en'], + 'publisher_en'=>'Cold and Arid Regions Science Data Center at Lanzhou', + ); + }else{ + $this->view->data['doi'] = $metadata['doi']; + $this->view->data['info'] = $doi->data_process_out($this->view->data); + if(empty($this->view->data['ts_published'])) + { + $this->view->data['title'] = $metadata['title']; + $this->view->data['title_en'] = $metadata['title_en']; + } + } + }else{ + $this->view->data = $doi->view($uuid); + $this->view->data['info'] = $doi->data_process_out($this->view->data); + } + }else{ + $data = $doi->_getParams($this->_request); + $this->view->data = $data; + $info = $doi->checkinfo($data['info']); + if(!is_array($info)){ + $this->view->error = view::Error($info); + return true; + }else{ + $data['info'] = $info; + $data['info'] = $doi->sksort($data['info'],"order",SORT_ASC); + } + $state = $doi->update($data,$uuid); + if($state) + { + $this->view->msg = view::Msg('alert-success',"修改成功!",'/admin/data/doi/uuid/'.$uuid); + return false; + }else{ + $this->view->error = view::Error("修改失败"); + return false; + } + } + }//edit + + else if($ac == "del") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $id = $this->_getParam('id'); + + if(empty($id)) + { + $this->jsonexit(array('error'=>'参数错误')); + return true; + } + + if($doi->delete($id) == true) + { + $this->jsonexit(array('success'=>$id)); + return true; + }else{ + $this->jsonexit(array('error'=>'删除失败')); + return true; + } + + }//del + else if ($ac=="convert") //转换为chinadoi所需元数据格式 + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $sql="select d.*,m.description from datadoi d left join metadata m on d.uuid=m.uuid where d.uuid='$uuid'"; + $row=$this->db->fetchRow($sql); + $timestamp=date('YmdHis'); + $authors=explode(',',substr($row['authors'],1,-1)); + $orgs=explode(',',substr($row['organization'],1,-1)); + $doi=' + + '.$timestamp.' + '.$timestamp.' + + ISTIC + tuy@istic.ac.cn + + ISTIC + + + + + '; + foreach($authors as $k=>$v) + { + $doi.=''.$v.''; + $doi.=''.$orgs[$k].''; + } + $doi.=' + + <![CDATA['.$row['title'].']]> + + '; + $doi.=''; + $doi.=''.$row['publisher'].''; + $doi.=' + '.$row['doi'].' + '.$timestamp.' + + '; + $doi.=' + + +'; + $this->getResponse()->setHeader('Content-Type', 'text/xml')->setHeader('Content-Disposition','attachment; filename="'.$row['uuid'].'.xml"') + ->setHeader('Content-Type','application/force-download')->setBody($doi); + $this->db->query('update datadoi set ts_submitted=now() where uuid=?',array($uuid)); + } + else if ($ac=="verified") //成功申请 + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $row=$this->db->fetchRow("select * from datadoi where uuid='$uuid'"); + $content=@file_get_contents("http://dx.doi.org/".$row['doi']); + if (strpos($content,$row['doi'])!==false) //成功申请 + { + $sql="update datadoi set ts_published=now() where uuid=? and ts_published is null"; + $this->db->query($sql,array($uuid)); + $this->jsonexit(array('success'=>'成功申请')); + } else + $this->jsonexit(array('success'=>'该DOI验证失败,请检查!')); + return true; + } + }//doi + + //发送邀请专家的邮件 + public function sendMailToExpert($pid,$name,$email,$code,$test=0) + { + include_once("Heihe.php"); + $heihe = new Heihe($this->db); + $url = $heihe->makeInviteLink($pid,$code); + + include_once("EmailText.php"); + $mailtp=new EmailText($this->db,"expert-invite",array( + 'name' => $name, + 'url' => $url, + )); + + echo $mailtp->getBody(); + echo $mailtp->getSubject(); + if($test == 0) + { + include_once("WestdcMailer.php"); + $mail=new WestdcMailer($this->view->config->smtp); + $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); + $mail->setBodyText($mailtp->getBody()); + $mail->setSubject($mailtp->getSubject()); + $mail->addTo($email); + $mail->send(); + }else{ + $mail_config = array( + 'ssl' => 'ssl', + 'port' => 465, + 'auth' => 'login', + 'username' => 'la5c@qq.com', + 'password' => '' + ); + $transport = new Zend_Mail_Transport_Smtp('smtp.qq.com', $mail_config); + Zend_Mail::setDefaultTransport($transport); + + $mail=new Zend_Mail(); + $mail->setBodyText($mailtp->getBody()); + $mail->setFrom('la5c@qq.com','Jack'); + $mail->addTo("la5c@qq.com"); + $mail->setSubject($mailtp->getSubject()); + $mail->send(); + } + }//发送邀请邮件 + + /* + 获得单个文件的信息 + 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数据到数据库 + */ + private function import($xml) + { + $iso=new ISO19115(); + $iso->saveDB($this->db,$xml); + } + + /* + * jsonexit() 退出并返回json数据 + * + * param array $data 要返回的JSON数据,可以是任意数组 + * + * return JSON-response + */ + public function jsonexit($data){ + $this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(json_encode($data,JSON_NUMERIC_CHECK)); + return true; + }//jsonexit() 退出并返回json数据 +} From 609e5713c4a61280c344a403cc26072ce4e4ab18 Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 21 Mar 2014 10:19:04 +0000 Subject: [PATCH 159/173] change email to gmail --- application/config.ini | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/application/config.ini b/application/config.ini index 0e6385a3..a4096aca 100755 --- a/application/config.ini +++ b/application/config.ini @@ -27,12 +27,12 @@ title.data=数据产品与服务 title.review=数据评审 title.author=数据作者 title.knowledge=知识积累 -supportemail=sjy@qherc.org +supportemail=sjy@mygis.org reportemail=westdc-report-subscribe@lists.westgis.ac.cn -smtp.username=sjy@qherc.org +smtp.username=sjy@mygis.org smtp.password=qherc@123 -smtp.host=smtp.exmail.qq.com +smtp.host=smtp.gmail.com smtp.ssl=SSL smtp.auth=login smtp.name=三江源生态监测综合数据服务平台 @@ -47,7 +47,7 @@ offline.security=../data/security.pdf offline.water_template=../data/water_offline.pdf offline.font=../data/simhei.ttf offline.savepath=../data/offlineapp -service.email=sjy@qherc.org +service.email=sjy@mygis.org offline.email.template=../data/offline-email.txt offline.email.start_template=../data/offline-start-email.txt offline.email.finish_template=../data/offline-finish-email.txt From 72c353f435e0fd42fec07afb31adfb27bec346db Mon Sep 17 00:00:00 2001 From: wlx Date: Fri, 21 Mar 2014 15:37:14 +0000 Subject: [PATCH 160/173] set debug off --- application/admin/controllers/DataController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index 0a86b025..cf25d676 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -14,7 +14,7 @@ class Admin_DataController extends Zend_Controller_Action $this->view->config = Zend_Registry::get('config'); $this->messenger=$this->_helper->getHelper('FlashMessenger'); $this->view->messages = $this->messenger->getMessages(); - $this->debug = 1; //1:debug, 0:release + $this->debug = 0; //1:debug, 0:release $this->debug_email='wangliangxu@lzb.ac.cn'; $this->view->theme = new Theme(); $this->_helper->layout->setLayout('administry'); From 4381b008ae795b923f25023614f5a7699be704a3 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Tue, 25 Mar 2014 09:21:28 +0000 Subject: [PATCH 161/173] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E5=88=B0geonetwork=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controllers/UserController.php | 35 +++++++ .../admin/views/scripts/user/adminlist.phtml | 91 ++++++++++--------- application/module/Helpers/PDO.php | 45 +++++++++ 3 files changed, 126 insertions(+), 45 deletions(-) create mode 100644 application/module/Helpers/PDO.php diff --git a/application/admin/controllers/UserController.php b/application/admin/controllers/UserController.php index 9106f7c7..49817eb4 100755 --- a/application/admin/controllers/UserController.php +++ b/application/admin/controllers/UserController.php @@ -1,4 +1,6 @@ from('users') ->where('usertype = ?', 'administrator') ->order('users.id desc'); + + $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; + + $ac = $this->_getParam('ac'); + + if($ac == 'sync') + { + $sql = "SELECT id FROM users WHERE usertype='administrator'"; + $rs = $this->db->query($sql); + $ids = $rs->fetchAll(); + + $data = array(); + foreach($ids as $v) + { + $data[] = $v['id']; + } + unset($ids); + + $ids = join(",",$data); + + $gn_sql = "update users set profile='Administrator' where id in ($ids)"; + $gn_db = new PDO(array( + 'host'=> $this->view->config->geonetwork->params->host, + 'port' => 5432, + 'user' => $this->view->config->geonetwork->params->username, + 'pwd' => $this->view->config->geonetwork->params->password , + 'db' => $this->view->config->geonetwork->params->dbname + )); + + $gn_db->exec($gn_sql); + + view::Post($this,"同步成功!",-1); + } } function showAction() diff --git a/application/admin/views/scripts/user/adminlist.phtml b/application/admin/views/scripts/user/adminlist.phtml index 115fc724..3606ba74 100755 --- a/application/admin/views/scripts/user/adminlist.phtml +++ b/application/admin/views/scripts/user/adminlist.phtml @@ -1,46 +1,47 @@ -headTitle($this->config->title->site); - $this->headTitle('后台管理'); - $this->headTitle()->setSeparator(' - '); - $this->headLink()->appendStylesheet('/css/admin.css'); - $this->breadcrumb('首页'); - $this->breadcrumb('后台首页'); - $this->breadcrumb('用户管理'); - $this->breadcrumb()->setSeparator(' > '); -?> -
      -partial('user/left.phtml'); ?> -
      - -
      -
      管理员列表
      - - - - - - - - - - - -paginator)): ?> - -paginator as $item): ?> - - - - - - - - - - - -
      用户名电子邮箱用户类型真实姓名电话操作
      -'>查看详细 -
      - +headTitle($this->config->title->site); + $this->headTitle('后台管理'); + $this->headTitle()->setSeparator(' - '); + $this->headLink()->appendStylesheet('/css/admin.css'); + $this->breadcrumb('首页'); + $this->breadcrumb('后台首页'); + $this->breadcrumb('用户管理'); + $this->breadcrumb()->setSeparator(' > '); +?> +
      +partial('user/left.phtml'); ?> +
      + +
      +
      管理员列表
      + + + + + + + + + + + + +paginator)): ?> + +paginator as $item): ?> + + + + + + + + + + + +
      用户名电子邮箱用户类型真实姓名电话操作
      +'>查看详细 +
      +
      \ No newline at end of file diff --git a/application/module/Helpers/PDO.php b/application/module/Helpers/PDO.php new file mode 100644 index 00000000..d41733c4 --- /dev/null +++ b/application/module/Helpers/PDO.php @@ -0,0 +1,45 @@ +config_local_path); + $dsn = "pgsql:host={$config_local->db->hostname};" + ."port=5432;" + ."dbname={$config_local->db->database};" + ."user={$config_local->db->username};" + ."password={$config_local->db->password}"; + parent::__construct($dsn); + } + + else{ + + if(is_string($DSN)) + { + parent::__construct($DSN); + } + + else{ + $dsn = "pgsql:host={$DSN['host']};" + ."port={$DSN['port']};" + ."dbname={$DSN['db']};" + ."user={$DSN['user']};" + ."password={$DSN['pwd']}"; + parent::__construct($dsn); + } + + } + } + +} \ No newline at end of file From f74c9bde98da24d5e4d3678d63536308bbe38d1c Mon Sep 17 00:00:00 2001 From: wlx Date: Tue, 25 Mar 2014 13:58:59 +0000 Subject: [PATCH 162/173] =?UTF-8?q?=E7=A1=AE=E4=BF=9D=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E7=9A=84=E5=AE=8C=E6=95=B4=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controllers/UserController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/admin/controllers/UserController.php b/application/admin/controllers/UserController.php index 49817eb4..a0567082 100755 --- a/application/admin/controllers/UserController.php +++ b/application/admin/controllers/UserController.php @@ -154,6 +154,7 @@ class Admin_UserController extends Zend_Controller_Action 'db' => $this->view->config->geonetwork->params->dbname )); + $gn_db->exec("update users set profile='Editor' where id>1 and profile='Administrator'"); $gn_db->exec($gn_sql); view::Post($this,"同步成功!",-1); From ef9948332ec8f727cbea1bb87e7210cb6d61538d Mon Sep 17 00:00:00 2001 From: wlx Date: Wed, 26 Mar 2014 02:20:49 +0000 Subject: [PATCH 163/173] =?UTF-8?q?=E5=8F=96=E6=B6=88=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E9=97=B4=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controllers/DataController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index cf25d676..ad0cc603 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -2310,6 +2310,7 @@ class Admin_DataController extends Zend_Controller_Action $ac = $this->_request->getParam('ac'); $uuid = $this->_request->getParam('uuid'); + set_time_limit(0); $auth = Zend_Auth::getInstance(); if($auth->hasIdentity()) From 8eda0c4498bfd663e3489d88cea952cc7bf61360 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Mon, 12 May 2014 02:56:55 +0000 Subject: [PATCH 164/173] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=AF=E8=A7=86?= =?UTF-8?q?=E5=8C=96=E7=9B=B8=E5=85=B3js=E5=92=8C=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E7=A9=BA=E9=97=B4=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/DataController.php | 4589 +++++++++-------- .../default/controllers/VisualController.php | 762 +++ .../default/views/scripts/visual/data.phtml | 174 + .../default/views/scripts/visual/index.phtml | 162 + application/models/Theme.php | 382 +- .../adapters/standalone-framework.js | 18 + htdocs/js/lib/highstock/highcharts-3d.js | 41 + htdocs/js/lib/highstock/highcharts-more.js | 51 + htdocs/js/lib/highstock/highstock.js | 383 ++ .../js/lib/highstock/modules/canvas-tools.js | 133 + htdocs/js/lib/highstock/modules/data.js | 16 + htdocs/js/lib/highstock/modules/drilldown.js | 14 + htdocs/js/lib/highstock/modules/exporting.js | 22 + htdocs/js/lib/highstock/modules/funnel.js | 13 + htdocs/js/lib/highstock/modules/heatmap.js | 21 + .../highstock/modules/no-data-to-display.js | 12 + .../js/lib/highstock/modules/solid-gauge.js | 13 + htdocs/js/lib/highstock/themes/dark-blue.js | 254 + htdocs/js/lib/highstock/themes/dark-green.js | 255 + htdocs/js/lib/highstock/themes/dark-unica.js | 213 + htdocs/js/lib/highstock/themes/gray.js | 257 + htdocs/js/lib/highstock/themes/grid-light.js | 74 + htdocs/js/lib/highstock/themes/grid.js | 103 + .../js/lib/highstock/themes/sand-signika.js | 101 + htdocs/js/lib/highstock/themes/skies.js | 89 + 25 files changed, 5670 insertions(+), 2482 deletions(-) create mode 100644 application/default/controllers/VisualController.php create mode 100644 application/default/views/scripts/visual/data.phtml create mode 100644 application/default/views/scripts/visual/index.phtml create mode 100644 htdocs/js/lib/highstock/adapters/standalone-framework.js create mode 100644 htdocs/js/lib/highstock/highcharts-3d.js create mode 100644 htdocs/js/lib/highstock/highcharts-more.js create mode 100644 htdocs/js/lib/highstock/highstock.js create mode 100644 htdocs/js/lib/highstock/modules/canvas-tools.js create mode 100644 htdocs/js/lib/highstock/modules/data.js create mode 100644 htdocs/js/lib/highstock/modules/drilldown.js create mode 100644 htdocs/js/lib/highstock/modules/exporting.js create mode 100644 htdocs/js/lib/highstock/modules/funnel.js create mode 100644 htdocs/js/lib/highstock/modules/heatmap.js create mode 100644 htdocs/js/lib/highstock/modules/no-data-to-display.js create mode 100644 htdocs/js/lib/highstock/modules/solid-gauge.js create mode 100644 htdocs/js/lib/highstock/themes/dark-blue.js create mode 100644 htdocs/js/lib/highstock/themes/dark-green.js create mode 100644 htdocs/js/lib/highstock/themes/dark-unica.js create mode 100644 htdocs/js/lib/highstock/themes/gray.js create mode 100644 htdocs/js/lib/highstock/themes/grid-light.js create mode 100644 htdocs/js/lib/highstock/themes/grid.js create mode 100644 htdocs/js/lib/highstock/themes/sand-signika.js create mode 100644 htdocs/js/lib/highstock/themes/skies.js diff --git a/application/default/controllers/DataController.php b/application/default/controllers/DataController.php index 9b8cf928..357d12ef 100755 --- a/application/default/controllers/DataController.php +++ b/application/default/controllers/DataController.php @@ -1,613 +1,613 @@ -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->view->theme = new Theme(); - $this->view->main_nav_pageID = "data"; - - $this->view->nav = array( - array('link'=>'/','title'=>''), - array('link'=>'/data','title'=>$this->view->config->title->data), - ); - } - function indexAction() - { - //序列 - $state=$this->db->query('select s.id,s.name,count(*) as count from series s,dataseries d where d.sid=s.id and length(s.name)>2 group by s.id,s.name order by count desc limit 15'); - $this->view->serie=$state->fetchAll(); - //分类 - $state=$this->db->query('select c.code,name,name_zh,count(*) from category c,categorycode cc where c.code=cc.code group by c.code,cc.name,cc.name_zh'); - $this->view->category=$state->fetchAll(); - //关键词 - $state=$this->db->query("select keyword,count(*) from keyword right join normalmetadata on keyword.id=normalmetadata.id where keytype='place' group by keyword order by count desc limit 20"); - $k1=$state->fetchAll(); - $state=$this->db->query("select keyword,count(*) from keyword right join normalmetadata on keyword.id=normalmetadata.id where keytype='theme' group by keyword order by count desc limit 20"); - //$state=$this->db->query("select k.keyword,count(k.keyword) from keyword k left join normalmetadata m on k.id=m.id where k.keytype='theme' and (m.uuid in (select uuid from dataorder group by uuid order by count(uuid) desc limit 20)) group by k.keyword order by count(k.keyword) desc limit 20"); - $k2=$state->fetchAll(); - $state=$this->db->query("select keyword,count(*) from keyword right join normalmetadata on keyword.id=normalmetadata.id where keytype='discipline' group by keyword order by count desc limit 20"); - $k3=$state->fetchAll(); - $state=$this->db->query("select keyword,count(*) from keyword right join normalmetadata on keyword.id=normalmetadata.id where keytype='stratum' group by keyword order by count desc limit 20"); - $k4=$state->fetchAll(); - $state=$this->db->query("select keyword,count(*) from keyword right join normalmetadata on keyword.id=normalmetadata.id where keytype='temporal' group by keyword order by count desc limit 20"); - //$state=$this->db->query("select k.keyword,count(k.keyword) from keyword k left join normalmetadata m on k.id=m.id where k.keytype='temporal' and (m.uuid in (select uuid from dataorder group by uuid order by count(uuid) desc limit 20)) group by k.keyword order by count(k.keyword) desc limit 20"); - $k5=$state->fetchAll(); - $this->view->keywords=array('place'=>$k1,'theme'=>$k2,'discipline'=>$k3,'stratum'=>$k4,'temporal'=>$k5); - //最新10个入库数据 - $state=$this->db->query('select id,uuid,title from normalmetadata order by id desc limit 10'); - $this->view->metadata = $state->fetchAll(); - //特色数据 - - //服务 - $l=new mydir($this->view->config->paths->newsletter,"newsletter_*.pdf"); - $this->view->newsletter=$l->getLast(); - $name=basename($this->view->newsletter,'.pdf'); - list(,$this->view->newsletterno)=explode("_",$name); - - $this->view->addHelperPath('helper','Zend_View_Helper_'); - $form=new MaillistForm(); - $form->submit->setLabel('输入邮件地址,订阅数据通讯列表'); - - $this->view->form=$form; - if ($this->_request->isPost()) { - //发送邮件 - $formData=$this->_request->getPost(); - if ($form->isValid($formData)) { - $mail=new WestdcMailer($this->view->config->smtp); - $mail->setFrom($formData['email']); - $mail->setBodyText("."); - $mail->setSubject('subscribe'); - $mail->addTo($this->view->config->reportemail); - $mail->send(); - $this->messenger->addMessage('订阅成功,请检查您的邮件!'); - $this->_redirect('/data/'); - } - } else { - $auth = Zend_Auth::getInstance(); - if ($auth->hasIdentity()) { - $user=$auth->getIdentity(); - $formData['email']=$user->email; - $form->populate($formData); - } - } - $searchform=new SearchForm(); - $this->view->searchform=$searchform; - - //其他连接 - } - function onlinelistAction() - { - $page=(int)$this->_request->getParam('page'); - if (empty($page)) $page=1; - $limit=30; - $offset=$limit*($page-1); - $state=$this->db->query('select count(*) from normalmetadata where datatype=0'); - $row=$state->fetchAll(); - $sum=$row[0]['count']; - $select=$this->db->select(); - $select->from('normalmetadata','*')->where('datatype=0')->order('title')->limitPage($page,$limit); - $this->view->metadata = $this->db->fetchAll($select); - $this->view->page=new Pagination($sum,$page,$limit); - } - function offlinelistAction() - { - $page=(int)$this->_request->getParam('page'); - if (empty($page)) $page=1; - $limit=30; - $offset=$limit*($page-1); - $state=$this->db->query('select count(*) from normalmetadata where datatype=1'); - $row=$state->fetchAll(); - $sum=$row[0]['count']; - $select=$this->db->select(); - $select->from('normalmetadata','*')->where('datatype=1')->order('title')->limitPage($page,$limit); - $this->view->metadata = $this->db->fetchAll($select); - $this->view->page=new Pagination($sum,$page,$limit); - } - //展示最近20条离线神情记录情况 - function offlineappAction() - { - $sql="select * from offlineapp where ts_approved is not null and pdflink<>'' and status>=0 order by ts_created desc limit 20"; - $this->view->rows=$this->db->fetchAll($sql); - } - function requestAction() - { - $archives=new Archive($this->db); - $this->view->item=$archives->getOneArchive('如何申请数据','help'); - } - function submitAction() - { - $archives=new Archive($this->db); - $this->view->item=$archives->getOneArchive('如何发布数据','help'); - } - function serviceAction() - { - } - function newsletterAction() - { - $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); - $form=new MaillistForm(); - $this->view->form=$form; - $form->submit->setLabel('输入邮件地址,订阅数据通讯列表'); - if ($this->_request->isPost()) { - //发送邮件 - $formData=$this->_request->getPost(); - if ($form->isValid($formData)) { - //$mail=new Zend_Mail('utf-8'); - $mail=new WestdcMailer($this->view->config->smtp); - $mail->setFrom($formData['email']); - $mail->setBodyText("."); - $mail->setSubject('subscribe'); - $mail->addTo($this->view->config->reportemail); - /* - $tr=new Zend_Mail_Transport_Smtp($this->view->config->smtp->host, - array('ssl' => $this->view->config->smtp->ssl, - 'auth'=>$this->view->config->smtp->auth, - 'username'=>$this->view->config->smtp->username, - 'password'=>$this->view->config->smtp->password)); - $mail->send($tr); - */ - $mail->send(); - $this->messenger->addMessage('订阅成功,请检查您的邮件!'); - $this->_redirect('/data/newsletter'); - } - } else { - $auth = Zend_Auth::getInstance(); - if ($auth->hasIdentity()) { - $user=$auth->getIdentity(); - $formData['email']=$user->email; - $form->populate($formData); - } - } - } - function featureAction() - { - $sql="select * from datafeature order by id desc"; - $this->view->feature=$this->db->fetchAll($sql); - } - - function datasetcdAction() - { - $cd=new DatasetcdTable(); - $this->view->rows=$cd->fetchAll(); - } - /* - * 数据浏览 - */ - function browseAction() - { - $page=(int)$this->_request->getParam('page'); - if (empty($page)) $page=1; - $limit=10; - $offset=$limit*($page-1); - $state=$this->db->query('select count(*) from metadata'); - $row=$state->fetchAll(); - $sum=$row[0]['count']; - $select=$this->db->select(); - $select->from('metadata','*')->order('id desc')->limitPage($page,$limit); - $this->view->metadata = $this->db->fetchAll($select); - $this->view->page=new Pagination($sum,$page,$limit); - } - function tagAction() - { - $id = (int)$this->_request->getParam('id'); - $key = $this->_request->getParam('key'); - $keytype = $this->_request->getParam('keytype'); - $page=(int)$this->_request->getParam('page'); - if (empty($page)) $page=1; - $limit=10; - $offset=$limit*($page-1); - $sql='select keyword,count(*),keytype from keyword right join normalmetadata on keyword.id=normalmetadata.id '; - if (!empty($keytype) && ($keytype=='place' || $keytype=='theme' || $keytype=='discipline'||$keytype=='temporal')) $sql.=" where keytype='".$keytype."'"; - $sql.=' group by keyword,keytype order by keytype,keyword,count desc'; - $state=$this->db->query($sql); - $this->view->keywords=$state->fetchAll(); - - if ($id>0 or !empty($key)) { - if (empty($key)) { - $where=$this->db->quoteInto('id = ?',$id); - $row=$md->fetchRow($where); - $key=$row->name; - } - $this->view->codename=$key; - $sql=$this->db->quoteInto('select count(m.id) from normalmetadata m,keyword k where m.id=k.id and k.keyword=?',$key); - - $state=$this->db->query($sql); - $row=$state->fetchAll(); - $sum=$row[0]['count']; - $select=$this->db->select(); - $select->from('normalmetadata','*')->join('keyword','normalmetadata.id=keyword.id')->where('keyword.keyword=?',$key)->order('normalmetadata.title')->limitPage($page,$limit); - //$sql=$db->quoteInto('select m.* from metadata m,keyword k where m.id=k.id and k.keyword=?',$key); - //$state=$db->query($sql); - $this->view->metadata=$this->db->fetchAll($select); - $this->view->page=new Pagination($sum,$page,$limit); - } - } - /* - * 数据集序列浏览 - */ - function seriesAction() - { - $id = $this->_request->getParam('id'); - if (empty($id)) $id=0; - if (!is_numeric($id)) - { - $name=$id; - $id=''; - } - $keyword=$this->_request->getParam('keyword'); - if (empty($id)) { - if (!empty($name)) - { - $where=$this->db->quoteInto('name = ?',$name); - $row=$this->db->fetchRow("select * from series where ".$where); - } - } else { - $where=$this->db->quoteInto('id = ?',$id); - $row=$this->db->fetchRow("select * from series where ".$where); - } - if (!empty($id) or !empty($name)) - { - if (!$row) $this->_redirect('/data'); - $id=$row['id']; - } - $page=(int)$this->_request->getParam('page'); - if (empty($page)) $page=1; - $limit=10; - $offset=$limit*($page-1); - $state=$this->db->query('select s.id,name,count(*) from series s,dataseries d where d.sid=s.id group by s.id,s.name'); - $this->view->serie=$state->fetchAll(); - if ($id>0) { - //$where=$this->db->quoteInto('id = ?',$id); - //$row=$this->db->fetchRow("select * from series where ".$where); - $this->view->codename=$row['name']; - if (!empty($keyword)) - { - $sql='select count(m.id) as count from normalmetadata m,dataseries d,keyword k where m.id=d.id and m.id=k.id and d.sid=? and k.keyword=?'; - $row=$this->db->fetchAll($sql,array($id,$keyword)); - $this->view->codename.="【关键词:".$keyword."】"; - }else{ - $sql='select count(m.id) as count from normalmetadata m,dataseries d where m.id=d.id and d.sid=?'; - $row=$this->db->fetchAll($sql,array($id)); - } - $sum=$row[0]['count']; - $select=$this->db->select(); - $select->from('normalmetadata','*')->join('dataseries','normalmetadata.id=dataseries.id')->where('dataseries.sid=?',$id)->order('normalmetadata.title')->limitPage($page,$limit); - if (!empty($keyword)) $select->join('keyword','keyword.id=normalmetadata.id')->where('keyword.keyword=?',$keyword); - $this->view->metadata=$this->db->fetchAll($select); - $this->view->page=new Pagination($sum,$page,$limit); - //$this->view->showtools=($sum>$page)?true:false; - //$this->view->form=new SearchForm(); - $sql=$this->db->quoteInto("select keyword,count(*) as count from (select t.keyword,t.id from keyword t left join dataseries d on t.id=d.id where t.keytype='place' and d.sid=?) as f group by keyword order by count desc limit 30",$id); - $state=$this->db->query($sql); - $row=$state->fetchAll(); - $this->view->places=$row; - $this->view->seriesid=$id; - } else { - //提供全部数据集序列列表 - } - } - /* - * 分类浏览模式 - */ - function categoryAction() - { - $page = $this->_request->getParam('page'); - $code = (int)$this->_request->getParam('code'); - $state=$this->db->query('select c.code,name,name_zh,count(*) from category c,categorycode cc where c.code=cc.code group by c.code,cc.name,cc.name_zh'); - $this->view->category=$state->fetchAll(); - if ($code>0 && $code<20) { - $where=$this->db->quoteInto('code = ?',$code); - $row=$this->db->fetchRow("select * from categorycode where ".$where); - $this->view->codename=(empty($row['name_zh'])?$row['name']:$row['name_zh']); - $sql='select count(m.id) from normalmetadata m left join category c on m.id=c.id where c.code=?'; - $row=$this->db->fetchRow($sql,array($code)); - $sum=$row['count']; - $select=$this->db->select(); - $select->from('normalmetadata as m','*')->joinLeft('category as c','m.id=c.id')->where('c.code=?',$code)->order('m.title')->limitPage($page,$this->limit); - $this->view->metadata=$this->db->fetchAll($select); - $this->view->page=new Pagination($sum,$page,$this->limit); - } else { - //提供全部分类列表 - } - } - /* - * 时间浏览方式 - * todo:实现xml的缓存,基于时间的缓存(每天)?基于元数据修改的缓存,每次导入后都重新生成一次。 - */ - function timelineAction() - { - $fn="time1.xml"; - $rows=$this->db->fetchAll("select ts_created from normalmetadata order by ts_created desc limit 1"); - $last_update=strtotime($rows[0]['ts_created']); - if (!file_exists($fn) || (filemtime($fn)<$last_update)) - { - $dateformat="M j Y"; - $md = new MetadataTable(); - $db=$md->getAdapter(); - $state=$db->query('select id,uuid,description,title,timebegin,timeend from normalmetadata where timebegin is not null order by timebegin'); - $rows=$state->fetchAll(); - $timexml=''; - foreach($rows as $row) { - $timexml.=''; - $desc_length=mb_strlen($row['description'],"UTF-8"); - $desc=mb_substr($row['description'],0,($desc_length>300)?300:$desc_length,"UTF-8"); - if ($desc_length>300) $desc.=" ..."; - $timexml.=htmlspecialchars($desc); - $timexml.="\n"; - } - $timexml.=''; - $fp=fopen($fn,'w'); - fwrite($fp,$timexml); - fclose($fp); - } - //$this->_helper->layout->disableLayout(); - } - /* - * todo:空间浏览 - */ - function mapAction() - { - //use json & openlayers? - $id=(int)$this->_request->getParam('id'); - if ($id>0) $this->view->params="/id/$id"; - } - /* - * 产生geojson数据 - */ - function jsonAction() - { - $md=new MetadataTable(); - $db=$md->getAdapter(); - $id = (int)$this->_request->getParam('id'); - $where=''; - if (!empty($id)) { $where=' where id='.$id; } - $sql='select id,uuid,west,south,north,east,title from normalmetadata'.$where; - $state=$db->query($sql); - $rows=$state->fetchAll(); - $geomd=new GeoMetaData(); - foreach($rows as $row){ - if ($id) - $box=new GeoBox($row['west'],$row['south'],$row['east'],$row['north']); - else - $box=new GeoBoxLine($row['west'],$row['south'],$row['east'],$row['north']); - $feature=new Geofeature(); - $feature->id=$row['id']; - $feature->addProperties('title',$row['title']); - $feature->addProperties('uuid',$row['uuid']); - $feature->addProperties('id',$row['id']); - $feature->geometry=$box; - $geomd->addFeature($feature); - } - $this->_helper->json($geomd); - } - /* - * 时空动态浏览 - */ - function timemapAction() - { - $sql='select id,uuid,west,south,north,east,title,timebegin,timeend from normalmetadata where timebegin is not null'; - $this->view->rows=$this->db->fetchAll($sql); - } - /* - * 返回XML源文件 - */ - function xmlAction() - { - $uuid=$this->_request->getParam('uuid'); - $row=$this->db->fetchRow("select xml.data from xml left join metadata on xml.id=metadata.id where metadata.uuid=?",array($uuid)); - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $this->getResponse()->setHeader('Content-Type', 'text/xml') - ->setBody($row['data']); - } - function detailAction() - { - $id=(int)$this->_request->getParam('id'); - $xml=new XmlTable(); - $db=$xml->getAdapter(); - $where=$db->quoteInto('id=?',$id); - $order='id desc'; - $row=$xml->fetchRow($where,$order); - // Load the XML source - $xml = new DOMDocument; - $xml->loadXML($row->data); - $xsl = new DOMDocument; - $xsl->load($this->view->config->westdc->xsl); - // Configure the transformer - $proc = new XSLTProcessor; - $proc->importStyleSheet($xsl); // attach the xsl rules - $this->view->xml=$proc->transformToXML($xml); - //$this->_helper->layout->disableLayout(); - //$this->_helper->viewRenderer->setNoRender(); - //$this->getResponse()->setHeader('Content-Type', 'text/html') - // ->setBody($proc->transformToXML($xml)); - } - function feedAction() - { - $feedArray = array( - 'title' => '中国西部环境与生态科学数据中心', - 'link' => 'http://'.$_SERVER['SERVER_NAME'].'/data/feed', - 'description' => '共享西部计划产生的数据', - 'language' => 'zh-CN', - 'charset' => 'utf-8', - 'published' => time(), - //'generator' => 'Zend Framework Zend_Feed', - 'entries' => array() - ); - $sql="select * from normalmetadata order by ts_created desc"; - $rs=$this->db->fetchAll($sql); - $feedArray['published']=strtotime($rs[0]['ts_created']); - foreach($rs as $r) - { - $feedArray['entries'][] = array( - 'title' => $r['title'], - 'link' => 'http://'.$_SERVER['SERVER_NAME'].'/data/' . $r['uuid'], - 'guid' => 'http://'.$_SERVER['SERVER_NAME'].'/data/' . $r['uuid'], - //'content'=>$r['description'], - 'description' => $r['description'], - 'lastUpdate' => strtotime($r['ts_created']) - ); - } - $feed = Zend_Feed::importArray($feedArray,'rss'); - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $feed->send(); - } - /* - * todo: search - */ - function searchAction() - { - $this->view->addHelperPath('helper','Zend_View_Helper_'); - $form=new SearchForm(); - $this->view->form=$form; - //$form->submit->setLabel('快速搜索'); - $key=$this->_request->getParam('q'); - if (!empty($key)) { - //$formData=$this->_request->getPost(); - //include_once("bcspamblock.php"); - //if ($form->isValid($formData)) { - $page=@(int)$this->_request->getParam('page'); - if (empty($page)) $page=1; - $offset=$this->limit*($page-1); - $search=new Search($key); - $where=$search->sql_expr(array("title","description")); - $row=$this->db->fetchAll("select count(*) from normalmetadata where ".$where); - $sum=$row[0]['count']; - $sql="select uuid,title,id,description from normalmetadata where ".$where." order by title limit ? offset ?"; - $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); - $this->view->page=new Pagination($sum,$page,$this->limit); - $this->view->key=$key; - } - } - /* - * todo: 高级搜索 - */ - function advancesearchAction() - { - $this->view->addHelperPath('helper','Zend_View_Helper_'); - //$form=new SearchForm(); - //$this->view->form=$form; - - $md=new MetadataTable(); - $db=$md->getAdapter(); - $page=(int)$this->_request->getParam('page'); - if (empty($page)) $page=1; - $limit=10; - $offset=$limit*($page-1); - $key=$this->_request->getParam('q'); - $n=(int)$this->_request->getParam('n'); - $s=(int)$this->_request->getParam('s'); - $e=(int)$this->_request->getParam('e'); - $w=(int)$this->_request->getParam('w'); - if (!(empty($n) && empty($key))) { - if (empty($n)) $n=90; - if (empty($s)) $s=-90; - if (empty($e)) $e=180; - if (empty($w)) $w=-180; - $start=$this->_request->getParam('start'); - $end=$this->_request->getParam('end'); - if (!empty($key)) { - $sql='select count(*) from normalmetadata where east? and north? and (title ilike ? or description ilike ?)'; - $row=$db->fetchAll($sql,array($e,$w,$n,$s,'%'.$key.'%','%'.$key.'%')); - } else { - $sql='select count(*) from normalmetadata where east? and north?'; - $row=$db->fetchAll($sql,array($e,$w,$n,$s)); - } - $sum=$row[0]['count']; - $select=$db->select(); - $select->from('normalmetadata','*')->where('eastwhere('west>?',$w)->where('northwhere('south>?',$s); - if (!empty($key)) $select->where('(title ilike ? or description ilike ?)','%'.$key.'%'); - $select->order('title')->limit($limit,$offset); - $this->view->metadata = $db->fetchAll($select); - $this->view->page=new Pagination($sum,$page); - $this->view->key=$key; - } - } - /* - * 根据id或uuid来查看元数据 - * id为一组数字,uuid为唯一标识符 - */ - function viewAction() - { - $id = (int)$this->_request->getParam('id'); - $sql="select m.*,s.status,g.id as gid,t.filename,i.doi as datadoi,i.authors,i.author_en,i.publisher,i.publisher_en, date_part('year',i.ts_published) as publish_year from normalmetadata m left join mdstatus s on m.uuid=s.uuid - left join thumbnail t on t.id=m.id left join geonetworkmetadata g on m.uuid=g.uuid left join datadoi i on i.uuid=m.uuid where "; - if (empty($id)) { - $uuid = $this->_request->getParam('uuid'); - if (empty($uuid)) $this->_redirect('/data'); - $where=$this->db->quoteInto('m.uuid = ?',$uuid); - } else { - $where=$this->db->quoteInto('m.id = ?',$id); - } - $sql.=$where; - $this->db->setFetchMode(Zend_Db::FETCH_OBJ); - $row=$this->db->fetchRow($sql); - if (!$row) $this->_redirect('/data'); - $id=$row->id; - $uuid=$row->uuid; - $this->view->metadata=$row; - //提前对表格进行预处理 - $wiki=new WikiFormat(); - $this->view->metadata->description=$wiki->parseTable($this->view->escape($row->description)); - //处理外部链接 - $this->view->metadata->description=preg_replace('/\[\s*(http:\/\/.+?)\s+(.*?)\]/m','$2',$this->view->metadata->description); - $this->view->thumburl='/gndata/'.sprintf('%05d',floor(($row->gid+0.1)/100)*100).'-'.sprintf('%05d',ceil(($row->gid+0.1)/100)*100-1)."/".$row->gid; - $this->view->thumburl.='/public/'.str_replace('_s.','.',$row->filename); - if (is_numeric($row->projection)) - { - $sql="select proj4text from spatial_ref_sys where auth_srid=?"; - $rs=$this->db->fetchRow($sql,array((int)$row->projection)); - if ($rs) $this->view->projection=$rs->proj4text; - } - - $sql = "select * from keyword where id=? order by keytype,ts_created"; - $sth = $this->db->prepare($sql); - $rs = $sth->execute(array($id)); - $this->view->keys = $sth->fetchAll(PDO::FETCH_BOTH); - - $sql='select c.code,cc.name,cc.name_zh from category c,categorycode cc where c.code=cc.code and c.id= ?'; - $state=$this->db->query($sql,array($id)); - $this->view->category=$state->fetchAll(); - $sql='select s.name,s.id from dataseries d, series s where d.sid=s.id and d.id= ?'; - $state=$this->db->query($sql,array($id)); - $this->view->series=$state->fetchAll(); - $sql=$this->db->quoteInto("select count(*) as count from dataorder where uuid=?",$uuid); - $row=$this->db->fetchRow($sql); - $this->view->downloaded=$row->count; - //update the viewed times - $sql="update mdstat set viewed=viewed+1 where uuid=?"; - $this->db->query($sql,array($uuid)); - $sql=$this->db->quoteInto("select viewed from mdstat where uuid=?",$uuid); - $row=$this->db->fetchRow($sql); - $this->view->viewed=$row->viewed; - //数据文档 - $sql="select linkage from onlineresource where uuid=? and description='数据说明文档'"; - $sql=$this->db->quoteInto($sql,$uuid); - $row=$this->db->fetchRow($sql); - if ($row) $this->view->doc=$row->linkage; - //相关资源 - $sql="select * from onlineresource where uuid=? and (linkage not like '%sanjiangyuan.org.cn%') and name<>'元数据地址'"; - $sql=$this->db->quoteInto($sql,$uuid); - $this->view->resources=$this->db->fetchAll($sql); - //相关文献:作者建议 - $sql="select r.* from reference r left join mdref m on m.refid=r.id where m.uuid=? and m.reftype=0 order by m.place"; - $sql=$this->db->quoteInto($sql,$uuid); +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->view->theme = new Theme(); + $this->view->main_nav_pageID = "data"; + + $this->view->nav = array( + array('link'=>'/','title'=>''), + array('link'=>'/data','title'=>$this->view->config->title->data), + ); + } + function indexAction() + { + //序列 + $state=$this->db->query('select s.id,s.name,count(*) as count from series s,dataseries d where d.sid=s.id and length(s.name)>2 group by s.id,s.name order by count desc limit 15'); + $this->view->serie=$state->fetchAll(); + //分类 + $state=$this->db->query('select c.code,name,name_zh,count(*) from category c,categorycode cc where c.code=cc.code group by c.code,cc.name,cc.name_zh'); + $this->view->category=$state->fetchAll(); + //关键词 + $state=$this->db->query("select keyword,count(*) from keyword right join normalmetadata on keyword.id=normalmetadata.id where keytype='place' group by keyword order by count desc limit 20"); + $k1=$state->fetchAll(); + $state=$this->db->query("select keyword,count(*) from keyword right join normalmetadata on keyword.id=normalmetadata.id where keytype='theme' group by keyword order by count desc limit 20"); + //$state=$this->db->query("select k.keyword,count(k.keyword) from keyword k left join normalmetadata m on k.id=m.id where k.keytype='theme' and (m.uuid in (select uuid from dataorder group by uuid order by count(uuid) desc limit 20)) group by k.keyword order by count(k.keyword) desc limit 20"); + $k2=$state->fetchAll(); + $state=$this->db->query("select keyword,count(*) from keyword right join normalmetadata on keyword.id=normalmetadata.id where keytype='discipline' group by keyword order by count desc limit 20"); + $k3=$state->fetchAll(); + $state=$this->db->query("select keyword,count(*) from keyword right join normalmetadata on keyword.id=normalmetadata.id where keytype='stratum' group by keyword order by count desc limit 20"); + $k4=$state->fetchAll(); + $state=$this->db->query("select keyword,count(*) from keyword right join normalmetadata on keyword.id=normalmetadata.id where keytype='temporal' group by keyword order by count desc limit 20"); + //$state=$this->db->query("select k.keyword,count(k.keyword) from keyword k left join normalmetadata m on k.id=m.id where k.keytype='temporal' and (m.uuid in (select uuid from dataorder group by uuid order by count(uuid) desc limit 20)) group by k.keyword order by count(k.keyword) desc limit 20"); + $k5=$state->fetchAll(); + $this->view->keywords=array('place'=>$k1,'theme'=>$k2,'discipline'=>$k3,'stratum'=>$k4,'temporal'=>$k5); + //最新10个入库数据 + $state=$this->db->query('select id,uuid,title from normalmetadata order by id desc limit 10'); + $this->view->metadata = $state->fetchAll(); + //特色数据 + + //服务 + $l=new mydir($this->view->config->paths->newsletter,"newsletter_*.pdf"); + $this->view->newsletter=$l->getLast(); + $name=basename($this->view->newsletter,'.pdf'); + list(,$this->view->newsletterno)=explode("_",$name); + + $this->view->addHelperPath('helper','Zend_View_Helper_'); + $form=new MaillistForm(); + $form->submit->setLabel('输入邮件地址,订阅数据通讯列表'); + + $this->view->form=$form; + if ($this->_request->isPost()) { + //发送邮件 + $formData=$this->_request->getPost(); + if ($form->isValid($formData)) { + $mail=new WestdcMailer($this->view->config->smtp); + $mail->setFrom($formData['email']); + $mail->setBodyText("."); + $mail->setSubject('subscribe'); + $mail->addTo($this->view->config->reportemail); + $mail->send(); + $this->messenger->addMessage('订阅成功,请检查您的邮件!'); + $this->_redirect('/data/'); + } + } else { + $auth = Zend_Auth::getInstance(); + if ($auth->hasIdentity()) { + $user=$auth->getIdentity(); + $formData['email']=$user->email; + $form->populate($formData); + } + } + $searchform=new SearchForm(); + $this->view->searchform=$searchform; + + //其他连接 + } + function onlinelistAction() + { + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $limit=30; + $offset=$limit*($page-1); + $state=$this->db->query('select count(*) from normalmetadata where datatype=0'); + $row=$state->fetchAll(); + $sum=$row[0]['count']; + $select=$this->db->select(); + $select->from('normalmetadata','*')->where('datatype=0')->order('title')->limitPage($page,$limit); + $this->view->metadata = $this->db->fetchAll($select); + $this->view->page=new Pagination($sum,$page,$limit); + } + function offlinelistAction() + { + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $limit=30; + $offset=$limit*($page-1); + $state=$this->db->query('select count(*) from normalmetadata where datatype=1'); + $row=$state->fetchAll(); + $sum=$row[0]['count']; + $select=$this->db->select(); + $select->from('normalmetadata','*')->where('datatype=1')->order('title')->limitPage($page,$limit); + $this->view->metadata = $this->db->fetchAll($select); + $this->view->page=new Pagination($sum,$page,$limit); + } + //展示最近20条离线神情记录情况 + function offlineappAction() + { + $sql="select * from offlineapp where ts_approved is not null and pdflink<>'' and status>=0 order by ts_created desc limit 20"; + $this->view->rows=$this->db->fetchAll($sql); + } + function requestAction() + { + $archives=new Archive($this->db); + $this->view->item=$archives->getOneArchive('如何申请数据','help'); + } + function submitAction() + { + $archives=new Archive($this->db); + $this->view->item=$archives->getOneArchive('如何发布数据','help'); + } + function serviceAction() + { + } + function newsletterAction() + { + $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); + $form=new MaillistForm(); + $this->view->form=$form; + $form->submit->setLabel('输入邮件地址,订阅数据通讯列表'); + if ($this->_request->isPost()) { + //发送邮件 + $formData=$this->_request->getPost(); + if ($form->isValid($formData)) { + //$mail=new Zend_Mail('utf-8'); + $mail=new WestdcMailer($this->view->config->smtp); + $mail->setFrom($formData['email']); + $mail->setBodyText("."); + $mail->setSubject('subscribe'); + $mail->addTo($this->view->config->reportemail); + /* + $tr=new Zend_Mail_Transport_Smtp($this->view->config->smtp->host, + array('ssl' => $this->view->config->smtp->ssl, + 'auth'=>$this->view->config->smtp->auth, + 'username'=>$this->view->config->smtp->username, + 'password'=>$this->view->config->smtp->password)); + $mail->send($tr); + */ + $mail->send(); + $this->messenger->addMessage('订阅成功,请检查您的邮件!'); + $this->_redirect('/data/newsletter'); + } + } else { + $auth = Zend_Auth::getInstance(); + if ($auth->hasIdentity()) { + $user=$auth->getIdentity(); + $formData['email']=$user->email; + $form->populate($formData); + } + } + } + function featureAction() + { + $sql="select * from datafeature order by id desc"; + $this->view->feature=$this->db->fetchAll($sql); + } + + function datasetcdAction() + { + $cd=new DatasetcdTable(); + $this->view->rows=$cd->fetchAll(); + } + /* + * 数据浏览 + */ + function browseAction() + { + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $limit=10; + $offset=$limit*($page-1); + $state=$this->db->query('select count(*) from metadata'); + $row=$state->fetchAll(); + $sum=$row[0]['count']; + $select=$this->db->select(); + $select->from('metadata','*')->order('id desc')->limitPage($page,$limit); + $this->view->metadata = $this->db->fetchAll($select); + $this->view->page=new Pagination($sum,$page,$limit); + } + function tagAction() + { + $id = (int)$this->_request->getParam('id'); + $key = $this->_request->getParam('key'); + $keytype = $this->_request->getParam('keytype'); + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $limit=10; + $offset=$limit*($page-1); + $sql='select keyword,count(*),keytype from keyword right join normalmetadata on keyword.id=normalmetadata.id '; + if (!empty($keytype) && ($keytype=='place' || $keytype=='theme' || $keytype=='discipline'||$keytype=='temporal')) $sql.=" where keytype='".$keytype."'"; + $sql.=' group by keyword,keytype order by keytype,keyword,count desc'; + $state=$this->db->query($sql); + $this->view->keywords=$state->fetchAll(); + + if ($id>0 or !empty($key)) { + if (empty($key)) { + $where=$this->db->quoteInto('id = ?',$id); + $row=$md->fetchRow($where); + $key=$row->name; + } + $this->view->codename=$key; + $sql=$this->db->quoteInto('select count(m.id) from normalmetadata m,keyword k where m.id=k.id and k.keyword=?',$key); + + $state=$this->db->query($sql); + $row=$state->fetchAll(); + $sum=$row[0]['count']; + $select=$this->db->select(); + $select->from('normalmetadata','*')->join('keyword','normalmetadata.id=keyword.id')->where('keyword.keyword=?',$key)->order('normalmetadata.title')->limitPage($page,$limit); + //$sql=$db->quoteInto('select m.* from metadata m,keyword k where m.id=k.id and k.keyword=?',$key); + //$state=$db->query($sql); + $this->view->metadata=$this->db->fetchAll($select); + $this->view->page=new Pagination($sum,$page,$limit); + } + } + /* + * 数据集序列浏览 + */ + function seriesAction() + { + $id = $this->_request->getParam('id'); + if (empty($id)) $id=0; + if (!is_numeric($id)) + { + $name=$id; + $id=''; + } + $keyword=$this->_request->getParam('keyword'); + if (empty($id)) { + if (!empty($name)) + { + $where=$this->db->quoteInto('name = ?',$name); + $row=$this->db->fetchRow("select * from series where ".$where); + } + } else { + $where=$this->db->quoteInto('id = ?',$id); + $row=$this->db->fetchRow("select * from series where ".$where); + } + if (!empty($id) or !empty($name)) + { + if (!$row) $this->_redirect('/data'); + $id=$row['id']; + } + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $limit=10; + $offset=$limit*($page-1); + $state=$this->db->query('select s.id,name,count(*) from series s,dataseries d where d.sid=s.id group by s.id,s.name'); + $this->view->serie=$state->fetchAll(); + if ($id>0) { + //$where=$this->db->quoteInto('id = ?',$id); + //$row=$this->db->fetchRow("select * from series where ".$where); + $this->view->codename=$row['name']; + if (!empty($keyword)) + { + $sql='select count(m.id) as count from normalmetadata m,dataseries d,keyword k where m.id=d.id and m.id=k.id and d.sid=? and k.keyword=?'; + $row=$this->db->fetchAll($sql,array($id,$keyword)); + $this->view->codename.="【关键词:".$keyword."】"; + }else{ + $sql='select count(m.id) as count from normalmetadata m,dataseries d where m.id=d.id and d.sid=?'; + $row=$this->db->fetchAll($sql,array($id)); + } + $sum=$row[0]['count']; + $select=$this->db->select(); + $select->from('normalmetadata','*')->join('dataseries','normalmetadata.id=dataseries.id')->where('dataseries.sid=?',$id)->order('normalmetadata.title')->limitPage($page,$limit); + if (!empty($keyword)) $select->join('keyword','keyword.id=normalmetadata.id')->where('keyword.keyword=?',$keyword); + $this->view->metadata=$this->db->fetchAll($select); + $this->view->page=new Pagination($sum,$page,$limit); + //$this->view->showtools=($sum>$page)?true:false; + //$this->view->form=new SearchForm(); + $sql=$this->db->quoteInto("select keyword,count(*) as count from (select t.keyword,t.id from keyword t left join dataseries d on t.id=d.id where t.keytype='place' and d.sid=?) as f group by keyword order by count desc limit 30",$id); + $state=$this->db->query($sql); + $row=$state->fetchAll(); + $this->view->places=$row; + $this->view->seriesid=$id; + } else { + //提供全部数据集序列列表 + } + } + /* + * 分类浏览模式 + */ + function categoryAction() + { + $page = $this->_request->getParam('page'); + $code = (int)$this->_request->getParam('code'); + $state=$this->db->query('select c.code,name,name_zh,count(*) from category c,categorycode cc where c.code=cc.code group by c.code,cc.name,cc.name_zh'); + $this->view->category=$state->fetchAll(); + if ($code>0 && $code<20) { + $where=$this->db->quoteInto('code = ?',$code); + $row=$this->db->fetchRow("select * from categorycode where ".$where); + $this->view->codename=(empty($row['name_zh'])?$row['name']:$row['name_zh']); + $sql='select count(m.id) from normalmetadata m left join category c on m.id=c.id where c.code=?'; + $row=$this->db->fetchRow($sql,array($code)); + $sum=$row['count']; + $select=$this->db->select(); + $select->from('normalmetadata as m','*')->joinLeft('category as c','m.id=c.id')->where('c.code=?',$code)->order('m.title')->limitPage($page,$this->limit); + $this->view->metadata=$this->db->fetchAll($select); + $this->view->page=new Pagination($sum,$page,$this->limit); + } else { + //提供全部分类列表 + } + } + /* + * 时间浏览方式 + * todo:实现xml的缓存,基于时间的缓存(每天)?基于元数据修改的缓存,每次导入后都重新生成一次。 + */ + function timelineAction() + { + $fn="time1.xml"; + $rows=$this->db->fetchAll("select ts_created from normalmetadata order by ts_created desc limit 1"); + $last_update=strtotime($rows[0]['ts_created']); + if (!file_exists($fn) || (filemtime($fn)<$last_update)) + { + $dateformat="M j Y"; + $md = new MetadataTable(); + $db=$md->getAdapter(); + $state=$db->query('select id,uuid,description,title,timebegin,timeend from normalmetadata where timebegin is not null order by timebegin'); + $rows=$state->fetchAll(); + $timexml=''; + foreach($rows as $row) { + $timexml.=''; + $desc_length=mb_strlen($row['description'],"UTF-8"); + $desc=mb_substr($row['description'],0,($desc_length>300)?300:$desc_length,"UTF-8"); + if ($desc_length>300) $desc.=" ..."; + $timexml.=htmlspecialchars($desc); + $timexml.="\n"; + } + $timexml.=''; + $fp=fopen($fn,'w'); + fwrite($fp,$timexml); + fclose($fp); + } + //$this->_helper->layout->disableLayout(); + } + /* + * todo:空间浏览 + */ + function mapAction() + { + //use json & openlayers? + $id=(int)$this->_request->getParam('id'); + if ($id>0) $this->view->params="/id/$id"; + } + /* + * 产生geojson数据 + */ + function jsonAction() + { + $md=new MetadataTable(); + $db=$md->getAdapter(); + $id = (int)$this->_request->getParam('id'); + $where=''; + if (!empty($id)) { $where=' where id='.$id; } + $sql='select id,uuid,west,south,north,east,title from normalmetadata'.$where; + $state=$db->query($sql); + $rows=$state->fetchAll(); + $geomd=new GeoMetaData(); + foreach($rows as $row){ + if ($id) + $box=new GeoBox($row['west'],$row['south'],$row['east'],$row['north']); + else + $box=new GeoBoxLine($row['west'],$row['south'],$row['east'],$row['north']); + $feature=new Geofeature(); + $feature->id=$row['id']; + $feature->addProperties('title',$row['title']); + $feature->addProperties('uuid',$row['uuid']); + $feature->addProperties('id',$row['id']); + $feature->geometry=$box; + $geomd->addFeature($feature); + } + $this->_helper->json($geomd); + } + /* + * 时空动态浏览 + */ + function timemapAction() + { + $sql='select id,uuid,west,south,north,east,title,timebegin,timeend from normalmetadata where timebegin is not null'; + $this->view->rows=$this->db->fetchAll($sql); + } + /* + * 返回XML源文件 + */ + function xmlAction() + { + $uuid=$this->_request->getParam('uuid'); + $row=$this->db->fetchRow("select xml.data from xml left join metadata on xml.id=metadata.id where metadata.uuid=?",array($uuid)); + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $this->getResponse()->setHeader('Content-Type', 'text/xml') + ->setBody($row['data']); + } + function detailAction() + { + $id=(int)$this->_request->getParam('id'); + $xml=new XmlTable(); + $db=$xml->getAdapter(); + $where=$db->quoteInto('id=?',$id); + $order='id desc'; + $row=$xml->fetchRow($where,$order); + // Load the XML source + $xml = new DOMDocument; + $xml->loadXML($row->data); + $xsl = new DOMDocument; + $xsl->load($this->view->config->westdc->xsl); + // Configure the transformer + $proc = new XSLTProcessor; + $proc->importStyleSheet($xsl); // attach the xsl rules + $this->view->xml=$proc->transformToXML($xml); + //$this->_helper->layout->disableLayout(); + //$this->_helper->viewRenderer->setNoRender(); + //$this->getResponse()->setHeader('Content-Type', 'text/html') + // ->setBody($proc->transformToXML($xml)); + } + function feedAction() + { + $feedArray = array( + 'title' => '中国西部环境与生态科学数据中心', + 'link' => 'http://'.$_SERVER['SERVER_NAME'].'/data/feed', + 'description' => '共享西部计划产生的数据', + 'language' => 'zh-CN', + 'charset' => 'utf-8', + 'published' => time(), + //'generator' => 'Zend Framework Zend_Feed', + 'entries' => array() + ); + $sql="select * from normalmetadata order by ts_created desc"; + $rs=$this->db->fetchAll($sql); + $feedArray['published']=strtotime($rs[0]['ts_created']); + foreach($rs as $r) + { + $feedArray['entries'][] = array( + 'title' => $r['title'], + 'link' => 'http://'.$_SERVER['SERVER_NAME'].'/data/' . $r['uuid'], + 'guid' => 'http://'.$_SERVER['SERVER_NAME'].'/data/' . $r['uuid'], + //'content'=>$r['description'], + 'description' => $r['description'], + 'lastUpdate' => strtotime($r['ts_created']) + ); + } + $feed = Zend_Feed::importArray($feedArray,'rss'); + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $feed->send(); + } + /* + * todo: search + */ + function searchAction() + { + $this->view->addHelperPath('helper','Zend_View_Helper_'); + $form=new SearchForm(); + $this->view->form=$form; + //$form->submit->setLabel('快速搜索'); + $key=$this->_request->getParam('q'); + if (!empty($key)) { + //$formData=$this->_request->getPost(); + //include_once("bcspamblock.php"); + //if ($form->isValid($formData)) { + $page=@(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $offset=$this->limit*($page-1); + $search=new Search($key); + $where=$search->sql_expr(array("title","description")); + $row=$this->db->fetchAll("select count(*) from normalmetadata where ".$where); + $sum=$row[0]['count']; + $sql="select uuid,title,id,description from normalmetadata where ".$where." order by title limit ? offset ?"; + $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); + $this->view->page=new Pagination($sum,$page,$this->limit); + $this->view->key=$key; + } + } + /* + * todo: 高级搜索 + */ + function advancesearchAction() + { + $this->view->addHelperPath('helper','Zend_View_Helper_'); + //$form=new SearchForm(); + //$this->view->form=$form; + + $md=new MetadataTable(); + $db=$md->getAdapter(); + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $limit=10; + $offset=$limit*($page-1); + $key=$this->_request->getParam('q'); + $n=(int)$this->_request->getParam('n'); + $s=(int)$this->_request->getParam('s'); + $e=(int)$this->_request->getParam('e'); + $w=(int)$this->_request->getParam('w'); + if (!(empty($n) && empty($key))) { + if (empty($n)) $n=90; + if (empty($s)) $s=-90; + if (empty($e)) $e=180; + if (empty($w)) $w=-180; + $start=$this->_request->getParam('start'); + $end=$this->_request->getParam('end'); + if (!empty($key)) { + $sql='select count(*) from normalmetadata where east? and north? and (title ilike ? or description ilike ?)'; + $row=$db->fetchAll($sql,array($e,$w,$n,$s,'%'.$key.'%','%'.$key.'%')); + } else { + $sql='select count(*) from normalmetadata where east? and north?'; + $row=$db->fetchAll($sql,array($e,$w,$n,$s)); + } + $sum=$row[0]['count']; + $select=$db->select(); + $select->from('normalmetadata','*')->where('eastwhere('west>?',$w)->where('northwhere('south>?',$s); + if (!empty($key)) $select->where('(title ilike ? or description ilike ?)','%'.$key.'%'); + $select->order('title')->limit($limit,$offset); + $this->view->metadata = $db->fetchAll($select); + $this->view->page=new Pagination($sum,$page); + $this->view->key=$key; + } + } + /* + * 根据id或uuid来查看元数据 + * id为一组数字,uuid为唯一标识符 + */ + function viewAction() + { + $id = (int)$this->_request->getParam('id'); + $sql="select m.*,s.status,g.id as gid,t.filename,i.doi as datadoi,i.authors,i.author_en,i.publisher,i.publisher_en, date_part('year',i.ts_published) as publish_year from normalmetadata m left join mdstatus s on m.uuid=s.uuid + left join thumbnail t on t.id=m.id left join geonetworkmetadata g on m.uuid=g.uuid left join datadoi i on i.uuid=m.uuid where "; + if (empty($id)) { + $uuid = $this->_request->getParam('uuid'); + if (empty($uuid)) $this->_redirect('/data'); + $where=$this->db->quoteInto('m.uuid = ?',$uuid); + } else { + $where=$this->db->quoteInto('m.id = ?',$id); + } + $sql.=$where; + $this->db->setFetchMode(Zend_Db::FETCH_OBJ); + $row=$this->db->fetchRow($sql); + if (!$row) $this->_redirect('/data'); + $id=$row->id; + $uuid=$row->uuid; + $this->view->metadata=$row; + //提前对表格进行预处理 + $wiki=new WikiFormat(); + $this->view->metadata->description=$wiki->parseTable($this->view->escape($row->description)); + //处理外部链接 + $this->view->metadata->description=preg_replace('/\[\s*(http:\/\/.+?)\s+(.*?)\]/m','$2',$this->view->metadata->description); + $this->view->thumburl='/gndata/'.sprintf('%05d',floor(($row->gid+0.1)/100)*100).'-'.sprintf('%05d',ceil(($row->gid+0.1)/100)*100-1)."/".$row->gid; + $this->view->thumburl.='/public/'.str_replace('_s.','.',$row->filename); + if (is_numeric($row->projection)) + { + $sql="select proj4text from spatial_ref_sys where auth_srid=?"; + $rs=$this->db->fetchRow($sql,array((int)$row->projection)); + if ($rs) $this->view->projection=$rs->proj4text; + } + + $sql = "select * from keyword where id=? order by keytype,ts_created"; + $sth = $this->db->prepare($sql); + $rs = $sth->execute(array($id)); + $this->view->keys = $sth->fetchAll(PDO::FETCH_BOTH); + + $sql='select c.code,cc.name,cc.name_zh from category c,categorycode cc where c.code=cc.code and c.id= ?'; + $state=$this->db->query($sql,array($id)); + $this->view->category=$state->fetchAll(); + $sql='select s.name,s.id from dataseries d, series s where d.sid=s.id and d.id= ?'; + $state=$this->db->query($sql,array($id)); + $this->view->series=$state->fetchAll(); + $sql=$this->db->quoteInto("select count(*) as count from dataorder where uuid=?",$uuid); + $row=$this->db->fetchRow($sql); + $this->view->downloaded=$row->count; + //update the viewed times + $sql="update mdstat set viewed=viewed+1 where uuid=?"; + $this->db->query($sql,array($uuid)); + $sql=$this->db->quoteInto("select viewed from mdstat where uuid=?",$uuid); + $row=$this->db->fetchRow($sql); + $this->view->viewed=$row->viewed; + //数据文档 + $sql="select linkage from onlineresource where uuid=? and description='数据说明文档'"; + $sql=$this->db->quoteInto($sql,$uuid); + $row=$this->db->fetchRow($sql); + if ($row) $this->view->doc=$row->linkage; + //相关资源 + $sql="select * from onlineresource where uuid=? and (linkage not like '%sanjiangyuan.org.cn%') and name<>'元数据地址'"; + $sql=$this->db->quoteInto($sql,$uuid); + $this->view->resources=$this->db->fetchAll($sql); + //相关文献:作者建议 + $sql="select r.* from reference r left join mdref m on m.refid=r.id where m.uuid=? and m.reftype=0 order by m.place"; + $sql=$this->db->quoteInto($sql,$uuid); $this->view->ref=$this->db->fetchAll($sql); //数据的参考文献 $sql="select r.* from reference r left join mdref m on m.refid=r.id where m.uuid=? and m.reftype=2 order by m.place"; @@ -617,1696 +617,1697 @@ class DataController extends Zend_Controller_Action $sql="select r.* from reference r left join mdref m on m.refid=r.id where m.uuid=? and m.reftype=4 order by m.place"; $sql=$this->db->quoteInto($sql,$uuid); $this->view->themeref=$this->db->fetchAll($sql); - //用户发表文献 - $sql="select r.* from reference r left join mdref m on m.refid=r.id where m.uuid=? and m.reftype=1 order by r.language asc,r.year desc,r.ts_created desc limit 15"; - $sql=$this->db->quoteInto($sql,$uuid); - $this->view->userref=$this->db->fetchAll($sql); - //多篇引用形式:hiwater - $sql="select r.* from reference r left join mdref m on m.refid=r.id where m.uuid=? and m.reftype=3 order by m.place"; - $sql=$this->db->quoteInto($sql,$uuid); - $this->view->mcitation=$this->db->fetchAll($sql); - //相关用户 - $sql="select p.email,p.individual,p.organisation,r.role from role r left join responsible p on r.resid=p.id where r.uuid=? order by r.role,r.id"; - $this->view->authors=$this->db->fetchAll($sql,array($uuid)); - //数据限制信息 - $sql="select u.* from uselimit u left join mdlimit m on u.id=m.lid where m.uuid=?"; - $this->view->uselimits=$this->db->fetchAll($sql,array($uuid)); - //相关下载 - $sql = "select d.uuid,count(distinct(d.userid)) as downtimes,m.title from dataorder d left join metadata m on d.uuid=m.uuid where d.userid in ( - select distinct(userid) from dataorder where uuid=? and status in (0,5) - ) and d.uuid<>? and length(m.title)>2 group by d.uuid,m.title order by count(distinct(d.userid)) desc limit 10;"; - $this->view->downlists = $this->db->fetchAll($sql,array($uuid,$uuid)); - //相关文献 - $sql="select a.*,array_to_string(array(select author from knl_author t where t.item_id=a.item_id order by place asc),'; ') as author from knl_article a where ("; - foreach($this->view->keys as $k) - { - if ($k['keytype']=='theme') - { - $sql.=" a.title like '%".$k['keyword']."%' or "; - } - } - $sql.=" 1<>1) order by a.ts_created desc limit 10"; - $this->view->literature=$this->db->fetchAll($sql); - //相关元数据,根据同名关键词实现 - $sql="select distinct(md.uuid),md.title from keyword kw left join normalmetadata md on kw.id=md.id where kw.keyword in (select k.keyword from keyword k left join metadata m on k.id=m.id where m.id=? and k.keytype='theme') and kw.id<>? limit 10"; - $this->view->related=$this->db->fetchAll($sql,array($id,$id)); - //用户下载记录 - $sql = "select o.ts_created,m.uuid,u.realname,u.unit,oa.project as onlineproject, fa.project as offlineproject - from dataorder as o left join metadata as m on o.uuid = m.uuid left join users as u on o.userid=u.id - left join onlineapp oa on o.onlineappid=oa.id left join offlineapp fa on o.offlineappid=fa.id - where m.uuid = '$uuid' and (o.status=0 or o.status=5) and u.realname IS NOT NULL order by o.ts_created desc limit 10"; - $this->view->downhistory=$this->db->fetchAll($sql); - //数据附件 - $sql = $this->db->quoteInto("select m.id,a.realname from mdattach m left join attachments a on m.id=a.id where m.uuid=?",$uuid); - $this->view->attachments = $this->db->fetchAll($sql); - //数据版本 - $sql = "SELECT count(id) as c FROM mdversion WHERE uuid=? AND changelog IS NOT NULL"; - $sth = $this->db->prepare($sql); - $sth->execute(array($uuid)); - $row = $sth->fetch(); - $this->view->version = $row; - $archives = new Archive($this->db); - $data_archives = $archives->getArchiveByUUID($uuid); - if(!empty($data_archives)) - { - foreach($data_archives as $k=>$v) - { - $data_archives[$k]['url'] = $archives->getArchiveUrlByCid($v['id']); - } - } - $this->view->data_archives = $data_archives; - //支持项目 - include_once("data/Fund.php"); - $fund = new Fund($this->db); - $this->view->fund = $fund->fetch($uuid); - - //判断特殊数据服务 - $this->view->dataService= $this->checkDataService($uuid); - - //自动跳转 - $sql="select s.* from datasource d left join source s on d.sourceid=s.id where d.uuid=?"; - $row=$this->db->fetchRow($this->db->quoteInto($sql,$uuid)); - $jump=$this->_request->getParam('jump'); - if ($jump=="") $jump=1;//默认跳转 - if (@$row->has_pages && ($jump==1)) - { - $this->_helper->viewRenderer($row->code.'/view',null,true); - } - } //viewAction - - //检查特殊数据服务是否存在 - private function checkDataService($uuid) - { - $order = new \Order\Mount\OrderOperate(); - $service = $order->getDataService($uuid); - - if(empty($service)) - { - return NULL; - }else{ - if($order->checkOrderHas($uuid)) - { - return NULL; - }else{ - return $service; - } - } - }//checkDataService - - //特殊数据服务 - public function dataserviceAction() - { - - $uuid = $this->_getParam('uuid'); - - if(empty($uuid)) - { - $this->jsonexit(array("error"=>"参数错误")); - } - - $dataservice = new \data\DataService(); - $info = $dataservice->get($uuid); - - - //暂时只有wsn - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $data = array( - "type"=>"wsn", //服务类型 - "info"=>$info, //信息 dataservice 表中的字段 - "callback"=>"westdc.dataservice.wsn.request()", //成功后的js回调函数 - ); - - $data['data'] = $dataservice->getWsnData("site",$uuid); - - if(empty($data['data'])) - { - $this->jsonexit(array("error"=>'数据接口错误,请联系管理员')); - return true; - } - - if(!is_array($data['data'])) - { - $this->jsonexit(array("error"=>$data['data'])); - return true; - } - - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $this->jsonexit($data); - } - // WSN end - - } - - public function wsnAction() - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $type = $this->_getParam('type'); - $uuid = $this->_getParam("uuid"); - - $dataservice = new DataService(); - - if($type == 'var') - { - $sites = array( - "chk"=>$this->_getParam("siteid") - ); - - $info = $dataservice->get($uuid); - - $data = array( - "type"=>"wsn", //服务类型 - "info"=>$info, //信息 dataservice 表中的字段 - "callback"=>"westdc.dataservice.wsn.Submit()", //成功后的js回调函数 - ); - + //用户发表文献 + $sql="select r.* from reference r left join mdref m on m.refid=r.id where m.uuid=? and m.reftype=1 order by r.language asc,r.year desc,r.ts_created desc limit 15"; + $sql=$this->db->quoteInto($sql,$uuid); + $this->view->userref=$this->db->fetchAll($sql); + //多篇引用形式:hiwater + $sql="select r.* from reference r left join mdref m on m.refid=r.id where m.uuid=? and m.reftype=3 order by m.place"; + $sql=$this->db->quoteInto($sql,$uuid); + $this->view->mcitation=$this->db->fetchAll($sql); + //相关用户 + $sql="select p.email,p.individual,p.organisation,r.role from role r left join responsible p on r.resid=p.id where r.uuid=? order by r.role,r.id"; + $this->view->authors=$this->db->fetchAll($sql,array($uuid)); + //数据限制信息 + $sql="select u.* from uselimit u left join mdlimit m on u.id=m.lid where m.uuid=?"; + $this->view->uselimits=$this->db->fetchAll($sql,array($uuid)); + //相关下载 + $sql = "select d.uuid,count(distinct(d.userid)) as downtimes,m.title from dataorder d left join metadata m on d.uuid=m.uuid where d.userid in ( + select distinct(userid) from dataorder where uuid=? and status in (0,5) + ) and d.uuid<>? and length(m.title)>2 group by d.uuid,m.title order by count(distinct(d.userid)) desc limit 10;"; + $this->view->downlists = $this->db->fetchAll($sql,array($uuid,$uuid)); + //相关文献 + $sql="select a.*,array_to_string(array(select author from knl_author t where t.item_id=a.item_id order by place asc),'; ') as author from knl_article a where ("; + foreach($this->view->keys as $k) + { + if ($k['keytype']=='theme') + { + $sql.=" a.title like '%".$k['keyword']."%' or "; + } + } + $sql.=" 1<>1) order by a.ts_created desc limit 10"; + $this->view->literature=$this->db->fetchAll($sql); + //相关元数据,根据同名关键词实现 + $sql="select distinct(md.uuid),md.title from keyword kw left join normalmetadata md on kw.id=md.id where kw.keyword in (select k.keyword from keyword k left join metadata m on k.id=m.id where m.id=? and k.keytype='theme') and kw.id<>? limit 10"; + $this->view->related=$this->db->fetchAll($sql,array($id,$id)); + //用户下载记录 + $sql = "select o.ts_created,m.uuid,u.realname,u.unit,oa.project as onlineproject, fa.project as offlineproject + from dataorder as o left join metadata as m on o.uuid = m.uuid left join users as u on o.userid=u.id + left join onlineapp oa on o.onlineappid=oa.id left join offlineapp fa on o.offlineappid=fa.id + where m.uuid = '$uuid' and (o.status=0 or o.status=5) and u.realname IS NOT NULL order by o.ts_created desc limit 10"; + $this->view->downhistory=$this->db->fetchAll($sql); + //数据附件 + $sql = $this->db->quoteInto("select m.id,a.realname from mdattach m left join attachments a on m.id=a.id where m.uuid=?",$uuid); + $this->view->attachments = $this->db->fetchAll($sql); + //数据版本 + $sql = "SELECT count(id) as c FROM mdversion WHERE uuid=? AND changelog IS NOT NULL"; + $sth = $this->db->prepare($sql); + $sth->execute(array($uuid)); + $row = $sth->fetch(); + $this->view->version = $row; + $archives = new Archive($this->db); + $data_archives = $archives->getArchiveByUUID($uuid); + if(!empty($data_archives)) + { + foreach($data_archives as $k=>$v) + { + $data_archives[$k]['url'] = $archives->getArchiveUrlByCid($v['id']); + } + } + $this->view->data_archives = $data_archives; + //支持项目 + include_once("data/Fund.php"); + $fund = new Fund($this->db); + $this->view->fund = $fund->fetch($uuid); + + //判断特殊数据服务 + $this->view->dataService= $this->checkDataService($uuid); + + //自动跳转 + $sql="select s.* from datasource d left join source s on d.sourceid=s.id where d.uuid=?"; + $row=$this->db->fetchRow($this->db->quoteInto($sql,$uuid)); + $jump=$this->_request->getParam('jump'); + if ($jump=="") $jump=1;//默认跳转 + if (@$row->has_pages && ($jump==1)) + { + $this->_helper->viewRenderer($row->code.'/view',null,true); + } + } //viewAction + + //检查特殊数据服务是否存在 + private function checkDataService($uuid) + { + $order = new \Order\Mount\OrderOperate(); + $service = $order->getDataService($uuid); + + if(empty($service)) + { + return NULL; + }else{ + if($order->checkOrderHas($uuid)) + { + return NULL; + }else{ + return $service; + } + } + }//checkDataService + + //特殊数据服务 + public function dataserviceAction() + { + + $uuid = $this->_getParam('uuid'); + + if(empty($uuid)) + { + $this->jsonexit(array("error"=>"参数错误")); + } + + $dataservice = new \data\DataService(); + $info = $dataservice->get($uuid); + + + //暂时只有wsn + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $data = array( + "type"=>"wsn", //服务类型 + "info"=>$info, //信息 dataservice 表中的字段 + "callback"=>"westdc.dataservice.wsn.request()", //成功后的js回调函数 + ); + + $data['data'] = $dataservice->getWsnData("site",$uuid); + + if(empty($data['data'])) + { + $this->jsonexit(array("error"=>'数据接口错误,请联系管理员')); + return true; + } + + if(!is_array($data['data'])) + { + $this->jsonexit(array("error"=>$data['data'])); + return true; + } + + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $this->jsonexit($data); + } + // WSN end + + } + + public function wsnAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $type = $this->_getParam('type'); + $uuid = $this->_getParam("uuid"); + + $dataservice = new DataService(); + + if($type == 'var') + { + $sites = array( + "chk"=>$this->_getParam("siteid") + ); + + $info = $dataservice->get($uuid); + + $data = array( + "type"=>"wsn", //服务类型 + "info"=>$info, //信息 dataservice 表中的字段 + "callback"=>"westdc.dataservice.wsn.Submit()", //成功后的js回调函数 + ); + $data['data'] = $dataservice->getWsnData("var",$uuid,$sites); - - if(empty($data['data'])) - { - $this->jsonexit(array("error"=>'数据接口错误,请联系管理员')); - return true; - } - - if(!is_array($data['data'])) - { - $this->jsonexit(array("error"=>$data['data'])); - return true; - } - - $this->jsonexit($data); - return true; - } - - if($type == "submit") - { - $info = $dataservice->get($uuid); - $param = array( - "site" => $this->_getParam("site"), - ); - - $data = array( - "type"=>"wsn", //服务类型 - "info"=>$info, //信息 dataservice 表中的字段 - "callback"=>"westdc.dataservice.wsn.Submited()", //成功后的js回调函数 - ); - + + if(empty($data['data'])) + { + $this->jsonexit(array("error"=>'数据接口错误,请联系管理员')); + return true; + } + + if(!is_array($data['data'])) + { + $this->jsonexit(array("error"=>$data['data'])); + return true; + } + + $this->jsonexit($data); + return true; + } + + if($type == "submit") + { + $info = $dataservice->get($uuid); + $param = array( + "site" => $this->_getParam("site"), + ); + + $data = array( + "type"=>"wsn", //服务类型 + "info"=>$info, //信息 dataservice 表中的字段 + "callback"=>"westdc.dataservice.wsn.Submited()", //成功后的js回调函数 + ); + $data['data'] = $dataservice->getWsnData("submit",$uuid,$param); - - - if(empty($data['data'])) - { - $this->jsonexit(array("error"=>'数据接口错误,请联系管理员')); - return true; - } - - if(!is_array($data['data'])) - { - $this->jsonexit(array("error"=>$data['data'])); - return true; - } - - $order = new Order(); - $status = $order->addOrder($uuid,json_encode($data['data']['site'],JSON_NUMERIC_CHECK)); - if($status !== true) - { - $this->jsonexit(array("error"=>$status)); - return true; - } - - $this->jsonexit($data); - return true; - } - } - - - - /* - getversionAction() 获取数据版本 - */ - function getversionAction(){ - - $ac = $this->_getParam('ac'); - $uuid = $this->_getParam('uuid'); - - if($ac == 'list') - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $sql = "SELECT v.changelog,v.ts_created,u.username FROM mdversion v - LEFT JOIN users u ON v.userid=u.id - WHERE v.uuid=? AND v.changelog IS NOT NULL - ORDER BY v.ts_created DESC"; - - $sth = $this->db->prepare($sql); - $sth->execute(array($uuid)); - $rows = $sth->fetchAll(); - - if($rows) - { - foreach($rows as $k=>$v) - { - $rows[$k]['ts_created'] = date("Y-m-d H:i",strtotime($v['ts_created'])); - $rows[$k]['changelog'] = str_replace("\n","

      ",$v['changelog']); - } - $data = array("list"=>$rows); - $this->jsonexit($data); - return true; - }else{ - $data = array("error"=>"处理中出现错误"); - $this->jsonexit($data); - return true; - } - } - - }//getversionAction() - - function replace($string){ - $patterns = array("/\"/i","/\'/i"); - $replacements = array("“","‘"); - ksort($patterns); - ksort($replacements); - return preg_replace($patterns, $replacements, $string); - }//引号替换 - - - function postcommentAction(){ - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - try{ - $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { - $user = $auth->getIdentity(); - $userid = $user->id; - }else - { - $userid=0; - } - - $author = mb_substr($this->replace(trim($this->_request->getParam('author'))),0,30,'UTF-8'); - $email = mb_substr($this->replace(trim($this->_request->getParam('email'))),0,60,'UTF-8'); - $url = mb_substr($this->replace(trim($this->_request->getParam('url'))),0,60,'UTF-8'); - $content = $this->replace(trim($this->_request->getParam('content'))); - $vdcode = mb_substr($this->replace(trim($this->_request->getParam('vdcode'))),0,4,'UTF-8'); - - if(empty($author)) - { - echo "请输入您的名字"; - exit(); - } - - if(strlen($author)<3) exit("姓名长度不得少于2个汉字 :)"); - - if(empty($email)) - { - echo "请输入您的电子邮箱地址"; - exit(); - } - - if(strlen($email)<4) exit("Email长度太短,请填写正确的Email :)"); - - if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i",$email)) - { - echo "Email格式不正确"; - exit(); - } - - if(strlen($content)<5) exit("评论长度不得少于3个汉字 :)"); - - if(preg_match("/script/i",$content)) - { - $content = preg_replace("/script/i","script",$content); - } - - if(preg_match("/<|>/",$content)) - { - $data=array( - '<'=>'<', - '>'=>'>', - ); - - $patterns = array(); - $replacements = array(); - foreach($data as $k=>$v) - { - $patterns[]='/'.$k.'/i'; - $replacements[]=$v; - } - ksort($patterns); - ksort($replacements); - $content=preg_replace($patterns, $replacements, $content); - if(!empty($url)) - { - $url=preg_replace($patterns, $replacements, $url); - } - } - - if(preg_match("/script/i",$url)) - { - $url = preg_replace("/script/i","script",$url); - } - - if(!preg_match("/http:\/\//",$url)) - { - $url = "http://".$url; - } - - $uuid = trim($this->_request->getParam('uuid')); - - if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid)) - { - echo "参数错误!"; - exit(); - } - - if(strtolower($vdcode) != $_SESSION['vdcodes']) - { - echo "验证码错误,请重新输入"; - exit(); - } - - - $data = array( - 'uuid' => $uuid, - 'uid' => $userid, - 'author' => $author, - 'email' => $email, - 'url' => $url, - 'ip' => $_SERVER['REMOTE_ADDR'], - 'content' => $content, - 'agent' => $_SERVER['HTTP_USER_AGENT'], - 'type' => 'comment' - ); - - $sql = "INSERT INTO comments (author,email,url,ip,content,agent,type,uuid,userid) VALUES (?,?,?,?,?,?,?,?,?)"; - $sth = $this->db->prepare($sql); - $exec = $sth->execute(array($data['author'],$data['email'],$data['url'],$data['ip'],$data['content'],$data['agent'],$data['type'],$data['uuid'],$data['uid'])); - - if($exec) - { - $sql = "SELECT u.email FROM mdauthor au - LEFT JOIN users u on au.userid=u.id - WHERE au.uuid='$uuid'"; - $sth = $this->db->query($sql); - $rows = $sth->fetchAll(); - - @$mailtp=new EmailText( - $this->db, - 'data-comment-note', - array( - 'user' =>$user->username, - 'uuid' =>$data['uuid'], - 'title' =>$this->replace(trim($this->_request->getParam('mdtitle'))), - 'content'=>$content - ) - ); - @$mail=new WestdcMailer($this->view->config->smtp); - @$mail->setBodyText($mailtp->getBody()); - @$mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); - @$mail->addTo($this->view->config->service->email); - if(is_array($rows) && count($rows)>0) - { - foreach($rows as $v) - { - @$mail->addTo($v['email']); - } - } - @$mail->setSubject($mailtp->getSubject()); - @$mail->send(); - $msg = "用户".$user->username."对元数据《".$this->replace(trim($this->_request->getParam('mdtitle')))."》进行了评论,点击查看"; - include_once("message.php"); - message::post($this->db,0,-1,"收到新数据评论",$msg); - echo "评论成功"; - exit(); - }else - { - echo "评论失败,请重试 :)"; - exit(); - } - }catch(Exception $e){ - echo "出错了,请稍后再试"; - exit(); - } - }//ajax评论 - - - /* - * 数据评论,根据UUID读取 - */ - function commentAction() - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $uuid=$this->_request->getParam('uuid'); - if (empty($uuid)) die(); - $sql="select * from comments where uuid=? AND reply=0 order by id desc"; - $comments=$this->db->fetchAll($sql,array($uuid)); - - $paginator = Zend_Paginator::factory($comments); - $paginator->setCurrentPageNumber($this->_getParam('page')); - $paginator->setItemCountPerPage(5); - $paginator->setView($this->view); - Zend_View_Helper_PaginationControl::setDefaultViewPartial('data/pagination_ajax.phtml'); - - include_once("Avatar.php"); - $avatar = new Avatar(); - if ($paginator) - { - foreach($paginator as $c) - { - //$author=$this->view->escape($c['author']); - $sql = "SELECT cr.id,cr.content as body,cr.reply,u.username,cr.ts_created,u.usertype,u.email as email, - (SELECT au.uuid FROM mdauthor au WHERE au.userid=u.id AND au.uuid='$uuid') as uuid - FROM comments cr - LEFT JOIN users u ON cr.userid=u.id - WHERE cr.reply=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($c['id'])); - $replys = $sth->fetchAll(); - $replyhtml = ""; - if(!empty($replys) || count($replys)>0) - { - foreach($replys as $v) - { - $usertype = ""; - $color = ""; - if($v['usertype'] == "administrator") - { - $usertype = "[管理员]"; - $color="#009d00"; - } - if($v['uuid'] == $uuid) - { - $usertype = "[数据作者]"; - $color="#add2e9"; - } - if(!empty($color)) - { - $color = 'background:'.$color.';color:#FFFFFF;'; - } - $img = $avatar->Get($v['email'],48); - $replyhtml .=' -

      - - - -
      - 回复于'.date('Y-m-d H:i:s',strtotime($v['ts_created'])).' -
      '.$v['username'].' '.$usertype.'
      - '.$v['body'].' -
      -
      - '; - - } - } - - $img = $avatar->Get($c['email'],64); - //$img = ''; - - $author = $c['author']; - $author = ($c['url'])?''.$author.'':$author; - $author = ''.$author.""; - $time = '发表于'.date('Y-m-d H:i:s',strtotime($c['ts_created'])).''; - print ' -
      - -
      - '.$time.' -

      '.$c['author'].'

      - '.$c['content'].' - '.$replyhtml.' -
      -
      - '; - } - echo '
      '.$paginator.'
      '; - }//else echo "
    • No comments.
    • "; - }//评论列表 - - /** - * 判断用户是否填写了申请信息 - * @param string $uuid - * @param int $userid - */ - function todownloadAction() { - - $this->view->pageID = "account-dataorder"; - - $this->_helper->viewRenderer('onlineapp-download'); - - $this->view->uuid = $uuid = $this->_request->getParam('uuid'); - - $auth = Zend_Auth::getInstance(); - if (!$auth->hasIdentity()) - { - $this->view->AlertType = "alert-error"; - $this->view->msg = "请先登录您的账户后进行下载,页面将自动跳转"; - $this->view->jump_url = '/account/login/?href=/data/todownload/uuid/'.$uuid; - return true; - } - - if(empty($uuid)) - { - $this->view->AlertType = "alert-error"; - $this->view->msg = "参数错误!"; - $this->view->jump_url = "/data"; - return true; - } - - $this->view->projectType = array( - "请选择项目类型" => "", - "国家973计划项目课题" => "国家973计划项目课题", - "国家863计划课题"=>"国家863计划课题", - "国家级科技支撑课题" => "国家级科技支撑课题", - "国家级科技重大专项" => "国家级科技重大专项", - "国家级国家重大工程" => "国家级国家重大工程", - "国家级国家自然科学基金" => "国家级国家自然科学基金", - "国际合作项目"=>"国际合作项目", - "省部级项目" => "省部级项目", - "其他项目工程" => "其他项目工程", - ); - - $userid = Zend_Auth::getInstance()->getIdentity()->id; - - $submit = $this->_getParam('submit'); - if(!empty($submit)){ - - $datas = array(); - $datas['realname'] = $this->_request->getParam('realname'); - $datas['unit'] = $this->_request->getParam('unit'); - $datas['phone'] = $this->_request->getParam('phone'); - $datas['address'] = $this->_request->getParam('address'); - $datas['postcode'] = $this->_request->getParam('postcode'); - $datas['email'] = $this->_request->getParam('email'); - $datas['project'] = $this->_request->getParam('project'); - $datas['project_id'] = $this->_request->getParam('project_id'); - $datas['project_type'] = $this->_request->getParam('project_type'); - $datas['project_title'] = $this->_request->getParam('project_title'); - $datas['project_leader']= $this->_request->getParam('project_leader'); - - $this->view->info = $datas; - - $this->view->AlertType = "alert-error"; - - foreach($datas as $k=>$v) - { - if(empty($v)) - { - $this->view->error = "每一项内容都需要填写"; - return true; - } - } - - if(!is_numeric($datas['postcode'])) - { - $this->view->error = "联系电话和邮政编码请填写数字"; - return true; - } - - if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i",$datas['email'])) - { - $this->view->error = "请填写正确的email地址"; - return true; - } - - if(mb_strlen($datas['project'],"utf-8")<8) - { - $this->view->error = "项目介绍内容不少于8个字符"; - return true; - } - - if(preg_match('/^\d+$/',$datas['project'])) - { - $this->view->error = "请输入有意义的项目介绍内容"; - return true; - } - - $data = array( - 'userid' => $userid, - 'username' => $datas['realname'], - 'unit' => $datas['unit'], - 'phone' => $datas['phone'], - 'address' => $datas['address'], - 'postcode' => $datas['postcode'], - 'project' => $datas['project'], - 'uuid' =>$uuid, - 'email' =>$datas['email'], - 'project_id'=>$datas['project_id'], - 'project_title'=>$datas['project_title'], - 'project_type'=>$datas['project_type'], - 'project_leader'=>$datas['project_leader'] - ); - - if($this->db->insert('onlineapp',$data)) - { - $select = "select id from onlineapp where userid='$userid' order by id desc"; - $re=$this->db->query($select); - $row=$re->fetch(); - - $this->view->AlertType = "alert-success"; - $this->view->jump_url = '/data/download/uuid/'.$uuid.'/onlineappid/'.$row['id']; - $this->view->msg = "您的信息已经提交成功,可以进行下载。请等待页面自动跳转,view->jump_url."\">或点击这里进入下载页面"; - - $msg = "用户{$data['username']} 填写了在线数据申请表 查看详细"; - $title = "用户 {$data['username']} 申请了在线下载数据"; - include_once("message.php"); - message::post($this->db,0,-1,$title,$msg); - - return true; - } - else { - $this->view->AlertType = "alert-error"; - $this->view->error = "申请失败,请稍后重新尝试"; - $this->view->info = $data; - return true; - } - - return true; - }else{ - - $testsql="select * from onlineapp where userid='$userid' and uuid='$uuid' order by id desc"; - $result=$this->db->query($testsql); - $rows = $result->fetch(); - if (empty($rows['id'])) - { - include_once("Users.php"); - $usr = new Users($this->db); - $this->view->info = $usr->getUserInfo($userid); - return true; - } - else - { - $datas['realname'] = $rows['username']; - $datas['unit'] = $rows['unit']; - $datas['phone'] = $rows['phone']; - $datas['address'] = $rows['address']; - $datas['postcode'] = $rows['postcode']; - $datas['email'] = $rows['email']; - $datas['project'] = $rows['project']; - $datas['project_id'] = $rows['project_id']; - $datas['project_type'] = $rows['project_type']; - $datas['project_title'] = $rows['project_title']; - $datas['project_leader'] = $rows['project_leader']; - $this->view->info = $datas; - return true; - } - } - - return true; - - $userid=Zend_Auth::getInstance()->getIdentity()->id; - - $datas = array(); - $submited = $this->_request->getParam('submited'); - $datas['username'] = $this->_request->getParam('username'); - $datas['unit'] = $this->_request->getParam('unit'); - $datas['phone'] = $this->_request->getParam('phone'); - $datas['address'] = $this->_request->getParam('address'); - $datas['postcode'] = $this->_request->getParam('postcode'); - $datas['email'] = $this->_request->getParam('email'); - $datas['project'] = $this->_request->getParam('project'); - $datas['project_id'] = $this->_request->getParam('projectid'); - $datas['project_type'] = $this->_request->getParam('projecttype'); - $datas['project_title'] = $this->_request->getParam('projecttitle'); - $datas['project_leader'] = $this->_request->getParam('projectleader'); - - - - $form=$this->creatform($datas); - - if (!empty($submited) && $ft==0){ - - foreach($datas as $k=>$v) - { - if($v == '') - { - echo $form.''; - exit(); - } - } - - if(!is_numeric($datas['postcode'])) - { - echo $form.''; - exit(); - } - - if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i",$datas['email'])) - { - echo $form.''; - exit(); - } - - if(mb_strlen($datas['project'],"utf-8")<8) - { - echo $form.''; - exit(); - } - - if(preg_match('/^\d+$/',$datas['project'])) - { - echo $form.''; - exit(); - } - - $data = array( - 'userid' => $userid, - 'username' => $datas['username'], - 'unit' => $datas['unit'], - 'phone' => $datas['phone'], - 'address' => $datas['address'], - 'postcode' => $datas['postcode'], - 'project' => $datas['project'], - 'uuid' =>$uuid, - 'email' =>$datas['email'], - 'project_id'=>$datas['project_id'], - 'project_title'=>$datas['project_title'], - 'project_type'=>$datas['project_type'], - 'project_leader'=>$datas['project_leader'] - ); - - if($this->db->insert('onlineapp',$data)) - { - $select = "select id from onlineapp where userid='$userid' order by id desc"; - $re=$this->db->query($select); - $row=$re->fetch(); - echo "您的信息已经提交成功,可以进行下载。
      - 如果页面没有自动跳转,请点击这里进入下载页面 - "; - $msg = "用户{$data['username']} 填写了在线数据申请表 查看详细"; - $title = "用户 {$data['username']} 申请了在线下载数据"; - include_once("message.php"); - message::post($this->db,0,-1,$title,$msg); - exit(); - } - else { - echo $form.''; - exit(); - } - - }else if( $ft==1 ) - { - $testsql="select * from onlineapp where userid='$userid' and uuid='$uuid' order by id desc"; - $result=$this->db->query($testsql); - $rows = $result->fetch(); - if (empty($rows['id'])) - { - $sql="select * from users where id='$userid'"; - $result=$this->db->query($sql); - $rows = $result->fetch(); - - $datas['username'] = $rows['realname']; - $datas['unit'] = $rows['unit']; - $datas['phone'] = $rows['phone']; - $datas['address'] = $rows['address']; - $datas['postcode'] = $rows['postcode']; - $datas['email'] = $rows['email']; - $datas['project'] = $rows['project']; - $datas['project_id'] = $rows['project_id']; - $datas['project_type'] = $rows['project_type']; - $datas['project_title'] = $rows['project_title']; - $datas['project_leader'] = $rows['project_leader']; - echo $this->creatform($datas); - exit(); - } - else - { - $datas['username'] = $rows['username']; - $datas['unit'] = $rows['unit']; - $datas['phone'] = $rows['phone']; - $datas['address'] = $rows['address']; - $datas['postcode'] = $rows['postcode']; - $datas['email'] = $rows['email']; - $datas['project'] = $rows['project']; - $datas['project_id'] = $rows['project_id']; - $datas['project_type'] = $rows['project_type']; - $datas['project_title'] = $rows['project_title']; - $datas['project_leader'] = $rows['project_leader']; - echo $this->creatform($datas); - exit(); - } - } - - } - - /* - * 数据下载,根据UUID进行判断 - * 一次只下载一个数据(一个元数据项) - */ - function downloadAction() - { - $uuid=$this->_request->getParam('uuid'); - $onlineappid=$this->_request->getParam('onlineappid'); - $this->view->pageID = "account-dataorder"; - - if (empty($uuid)) $this->_redirect('/data'); - - $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { - $user = $auth->getIdentity(); - $userid = $user->id; - } - - $testsql="select id,has_send_mail from onlineapp where userid='$userid' and uuid='$uuid' order by id desc"; - $result=$this->db->query($testsql); - $rows = $result->fetch(); - $has_send_mail=$rows['has_send_mail']; - if (empty($rows['id'])) - { - $this->_redirect('/data/'.$uuid); - } - else - { - $sql="select onlineappid,id from dataorder where status=0 and userid='$userid' and uuid='$uuid' order by id desc"; - $re=$this->db->query($sql); - $row=$re->fetch(); - if(empty($row['onlineappid'])) - { - $data = array( - 'userid' => $userid, - 'uuid' => $uuid, - 'onlineappid'=> $onlineappid, - 'ts_approved'=>'now()', - ); - try {$this->db->insert('dataorder',$data);} catch (Exception $e) {} - }else - { - $sql="update dataorder set onlineappid='$onlineappid',ts_approved=now() where id='{$row['id']}'"; - try {$this->db->exec($sql);} catch (Exception $e) {} - } - } - - - $sql=$this->db->quoteInto("select * from dataset o left join metadata m on o.uuid=m.uuid left join mdstatus s on m.uuid=s.uuid where s.status>4 and m.datatype=0 and m.uuid=?",$uuid); - $data=$this->db->fetchRow($sql); - $updateftp=$updateftp1=false; - $this->view->md=$data; - $this->view->userpass=md5('westdc'.rand(1000,9999)); - $this->view->ftptime=date('Y-m-d H:i:s', strtotime('+1 week')); - $sql=$this->db->quoteInto("select * from ftpuser where userid=?",$userid); - $row=$this->db->fetchRow($sql); - $datacount=$row['datacount']; - if ($data['host']=='ftp.westgis.ac.cn') - { - //添加FTP帐号信息以及时间控制信息 - $updateftp=true; - $g6=new G6ftp(); - $g6->db=$this->db; - //不进行判断,每个元数据中的下载地址都对应一个虚拟路径 - $path[]=$data['path']; - $this->view->username='westdc'.$userid; - $uu=(object)array("id"=>$userid, - "username"=>$this->view->username, - "password"=>$this->view->userpass, - "path"=>$path, - "maxdata"=>$this->view->config->download->max, - "time"=>$this->view->ftptime, - "datacount"=>$datacount); - if ($g6->createuser($uu)) { - $this->view->userpass=$g6->pwd; - $this->view->ftptime=$g6->time; - } else { - $this->messenger->addMessage('错误:您正在进行下载的在线数据数已经超过系统允许的最大值,请在下面点击“完成”或“取消”对应的在线数据下载!'); - $this->_redirect('/data/order'); - } - } elseif ($data['host']=='ftp1.westgis.ac.cn') - { - //添加FTP1帐号信息以及时间控制信息 - $proftp=new Proftp(); - $proftp->db=$this->db; - //proftp离线用户名和g6的用户名稍有不同 - $this->view->username='westdc_'.$userid; - $uu=(object)array("id"=>$userid, - "username"=>$this->view->username, - "password"=>$this->view->userpass, - "host"=>'ftp1.westgis.ac.cn', - "param"=>"onlineappid=".$onlineappid, - "maxdata"=>$this->view->config->download->max, - "time"=>$this->view->ftptime, - "datacount"=>$datacount); - if ($proftp->createuser($uu)) - { - $this->view->userpass=$proftp->pwd; - $this->view->ftptime=$proftp->time; - } - } elseif ($data['host']=='ftp.sanjiangyuan.org.cn') - { - //添加FTP2帐号信息以及时间控制信息 - $proftp=new Pureftp(); - $proftp->db=$this->db; - $this->view->username='sjy_'.$userid; - $uu=(object)array("id"=>$userid, - "username"=>$this->view->username, - "password"=>$this->view->userpass, - "host"=>'ftp.sanjiangyuan.org.cn', - "param"=>"onlineappid=".$onlineappid, - "maxdata"=>$this->view->config->download->max, - "time"=>$this->view->ftptime, - "datacount"=>$datacount); - if ($proftp->createuser($uu)) - { - $this->view->userpass=$proftp->pwd; - $this->view->ftptime=$proftp->time; - } - } - $ftpurl='ftp://'.$this->view->username.'@'.$data['host']; - if ($data['host']=='ftp.westgis.ac.cn') $ftpurl.=$data['path']; - - //设置输出 - //if ($updateftp || $updateftp1) $this->view->userpass=$password; - $this->view->ftpurl=$ftpurl; - //更新下载记录 - //todo: 尝试添加一个RULE:若有对应数据存在,则不插入( userid,uuid,status=0,ts_approved:null) - /*$sql="select * from dataorder where userid=? and uuid=? and status=0 and (ts_approved is null)"; - $u=$this->db->fetchRow($sql,array($userid,$uuid)); - if (empty($u)) { - $sql="insert into dataorder (userid,uuid,ts_created) values(?,?,now())"; - $this->db->query($sql,array($userid,$uuid)); - }*/ - if (!empty($ftpurl) && !$has_send_mail) - { - $data = array( - "uuid"=>$uuid, - "title"=>$this->view->md['title']."(".$this->view->md['filesize']."MB)", - "user"=>$user->username, - "ftpuser"=>$this->view->username, - "ftppwd"=>$this->view->userpass, - "ftptime"=>$this->view->ftptime, - "ftpurl"=>$this->view->ftpurl, - "note"=>$updateftp?'BTW:请注意登陆后要手工进入对应的目录!':'' - ); - $mailtp=new EmailText($this->db,'online-download',$data); - $mail=new WestdcMailer($this->view->config->smtp); - $mail->setBodyText($mailtp->getBody()); - $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); - $mail->addTo($user->email); - $mail->setSubject($mailtp->getSubject()); - @$mail->send(); - $sql="update onlineapp set has_send_mail=true where id=?"; - $sth=$this->db->prepare($sql); - $sth->execute(array($onlineappid)); - } - } - /* - * 离线申请(可以包括在线数据),在无数据参数时,则显示已有列表 - */ - function orderAction() - { - $this->view->pageID = "account-dataorder"; - $ac = $this->_request->getParam('ac'); - - $uuid = $this->_request->getParam('uuid'); - - $del = $this->_request->getParam('del'); - $apply = $this->_request->getParam('apply'); - $finish = $this->_request->getParam('finish'); - $cancel = $this->_request->getParam('cancel'); - $wsn = $this->_request->getParam('wsn'); - $pdf = $this->_request->getParam('pdf'); - $selections = $this->_request->getParam('data'); - - //if (empty($uuid)) $this->_redirect('/data'); - $userid = view::User('id'); - - //添加到数据篮 - if ($uuid) - { - //存在历史遗留问题,原来的数据并不能保证唯一 - - $order = new Order(); - $state = $order->addOrder($uuid); - - if($state !== true) - { - if(!is_array($state)) - { - $this->view->msg = view::Msg('alert-error',$state); - }else{ - $service_type = $order->serviceTypeTest($state['service_type']); - if($service_type !== false) - { - view::Post($this,$service_type,$state['service_url']."?href=".urlencode(view::getHostLink()."/data/order/")."&uuid=".$state['uuid']."&uid=".$userid); - }else{ - $this->view->msg = view::Msg('alert-error',"无法申请:此元数据的数据类型未知"); - } - } - }else{ - $this->view->msg = view::Msg('alert-success',"添加成功!您可以继续浏览数据或是继续提交申请表"); - } - - if (empty($ac)) $ac='offline1'; - - } - - elseif ($selections) - { - if(empty($uuid)) - { - $this->view->msg = view::Msg('alert-error',"无法申请:参数出错,请通过正确的途径访问"); - } - - $order = new Order(); - $state = $order->addOrder($uuid,$selections); - - if($state !== true) - { - $this->view->msg = view::Msg('alert-error',$state); - }else{ - $this->view->msg = view::Msg('alert-success',"添加成功!您可以继续浏览数据或是继续提交申请表"); - } - - if (empty($ac)) $ac='offline1'; - } - - //删除申请 - elseif ($del) { - $order = new Order(); - $state = $order->del($del); - if($state !== true) - { - $this->view->msg = view::Msg('alert-error',$state); - }else{ - $this->view->msg = view::Msg('alert-success',"数据申请取消成功"); - } - $this->_redirect('/data/order'); - } - - //提交申请 - elseif ($apply) { - if($apply == "all" || !is_numeric($apply)) - { - $apply = -1; - } - $order = new Order(); - $state = $order->apply($apply); - if($state !== true) - { - $this->view->msg = view::Msg('alert-error',$state); - }else{ - $this->view->msg = view::Msg('alert-success',"提交成功,您可以点击“提交离线申请”来生成PDF申请表"); - } - if (empty($ac)) $ac='offline2'; - } - - //完成 - elseif ($finish) { - if ($finish=='all') { - $sql=$this->db->quoteInto("update dataorder set ts_approved=now() where status=0 and userid=?",$userid); - $this->db->query($sql); - $sql="update ftpuser set datacount=0 where userid=?"; - $this->db->query($sql,array($userid)); - } else { - $sql="update dataorder set ts_approved=now() where status=0 and userid=? and id=?"; - $this->db->query($sql,array($userid,(int)$finish)); - $sql="update ftpuser set datacount=datacount-1 where userid=? and datacount>0"; - $this->db->query($sql,array($userid)); - } - } - - elseif($wsn) - { - $this->_helper->viewRenderer('order-wsn'); - - return true; - } - - elseif ($cancel) { - if ($cancel=='all') { - $sql=$this->db->quoteInto("update dataorder set ts_approved=now(),status=-1 where status=0 and userid=?",$userid); - $this->db->query($sql); - $sql="update ftpuser set datacount=0 where userid=?"; - $this->db->query($sql,array($userid)); - } else { - $sql="update dataorder set ts_approved=now(),status=-1 where status in (0,1,2) and userid=? and id=?"; - $this->db->query($sql,array($userid,(int)$cancel)); - $sql="update ftpuser set datacount=datacount-1 where userid=? and datacount>0"; - $this->db->query($sql,array($userid)); - } - if (empty($ac)) $ac='offline2'; - } - - //生成PDF离线申请文件 - elseif ($pdf) { - - //用户信息可以从SESSION中读取?离线申请信息 - //$sql="select * from users where id=?"; - $order = new Order(); - $rows = $order->getOrderItemForPdf(); - $this->view->projectType = $order->projectType; - - if ($rows) { - $this->_helper->viewRenderer('pdf'); - - $this->view->data2 = $rows; - - if ($this->_request->isPost()) { - - $this->view->formData = $formData = $this->_request->getPost(); - - $datalist=''; - foreach($rows as $i=>$row) - { - $datalist.=($i+1).". ".$row['title'].";"; - } - $formData['datalist'] = $datalist; - - if (@$formData['save']) { - - $order->setPdfData($rows); - - $s = $order->SaveOrder($formData); - - if($s !== true) - { - $this->view->error = view::Msg('alert-error',$s); - return true; - } - - //不能修改顺序 - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - return true; - } elseif ($formData['submit']) { - //生成PDF - $order->setPdfData($rows); - $s = $order->SubmitOrder($formData); - - if($s !== true) - { - $this->view->error = view::Msg('alert-error',$s); - return true; - } - - $this->view->msg = view::Msg('alert-success','提示信息:您的离线申请已经提交,请在线上传PDF的签字版PDF文件。',0); - if (empty($ac)) $ac='offline3'; - } - } else { - $sql="select u.* from users u left join offlineapp o on u.id=o.userid where u.id=? ORDER BY o.id DESC"; - $row=$this->db->fetchRow($sql,array($userid)); - $this->view->formData = $row; - } - } else{ - $this->view->msg=view::Msg('alert-error',"错误:您还没有提交任何离线申请的数据,或您的数据申请已经提交(等待处理过程中)!",0); - } - return true; - }//pdf - - if($ac == "commitapplicationform") - { - $offlineappid = $this->_getParam('offlineappid'); - - if(!is_numeric($offlineappid) || $offlineappid < 1) - { - view::Post($this,"参数错误",-1); - return true; - } - - $order = new Order(); - $status = $order->commitApplicationForm($offlineappid); - - if( $status !== true) - { - view::Post($this,$status,-1); - }else{ - view::Post($this,"申请已提交,请等待管理员接收并通过数据所有者审核",'/data/order/ac/offline3'); - } - - return true; - } - - //index - $this->view->ac = $ac; - $this->_helper->viewRenderer('order'); - if ($ac=='' || $ac=='online') - { - $this->view->tabID='order-online'; - } else if ($ac=='offline1') { - $this->view->tabID='order-offline1'; - } else if ($ac=='offline2') { - $this->view->tabID='order-offline2'; - } else if ($ac=='offline3') { - $this->view->tabID='order-offline3'; - } else if ($ac=='offline4') { - $this->view->tabID='order-offline4'; - } - //显示已经申请的数据,包括已经提交的申请和未提交的申请,还有已经处理完成的申请,正在进行的在线数据下载 - $sql="select d.*,m.title,m.datatype,off.applicationform from dataorder d - left join metadata m on d.uuid=m.uuid - left join offlineapp off ON off.id = d.offlineappid - where d.userid=? order by d.status,d.ts_created desc"; - $rows=$this->db->fetchAll($sql,array($userid)); - - $showorders = array(); - $counts = array( - 'onlineapp' => 0, - 'offline1' => 0, - 'offline2' => 0, - 'offline3' => 0, - 'offline4' => 0 - ); - - if(count($rows) > 0) { - foreach($rows as $k=>$v) - { - switch($v['status']) { - case 0: - $counts['onlineapp'] ++; - break; - case 1: - $counts['offline1'] ++; - break; - case 2: - $counts['offline2'] ++; - break; - case 3: - $counts['offline3'] ++; - break; - case 4: - $counts['offline3'] ++; - break; - case 5: - $counts['offline4'] ++; - break; - } - switch($ac){ - default : - if($v['status'] == 0 && !empty($v['ts_approved']))$showorders[] = $rows[$k]; - break; - case 'online' : - if($v['status'] == 0 && !empty($v['ts_approved']))$showorders[] = $rows[$k]; - break; - case 'offline1' : - if($v['status'] == 1) $showorders[] = $rows[$k]; - break; - case 'offline2' : + + + if(empty($data['data'])) + { + $this->jsonexit(array("error"=>'数据接口错误,请联系管理员')); + return true; + } + + if(!is_array($data['data'])) + { + $this->jsonexit(array("error"=>$data['data'])); + return true; + } + + $order = new Order(); + $status = $order->addOrder($uuid,json_encode($data['data']['site'],JSON_NUMERIC_CHECK)); + if($status !== true) + { + $this->jsonexit(array("error"=>$status)); + return true; + } + + $this->jsonexit($data); + return true; + } + } + + + + /* + getversionAction() 获取数据版本 + */ + function getversionAction(){ + + $ac = $this->_getParam('ac'); + $uuid = $this->_getParam('uuid'); + + if($ac == 'list') + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $sql = "SELECT v.changelog,v.ts_created,u.username FROM mdversion v + LEFT JOIN users u ON v.userid=u.id + WHERE v.uuid=? AND v.changelog IS NOT NULL + ORDER BY v.ts_created DESC"; + + $sth = $this->db->prepare($sql); + $sth->execute(array($uuid)); + $rows = $sth->fetchAll(); + + if($rows) + { + foreach($rows as $k=>$v) + { + $rows[$k]['ts_created'] = date("Y-m-d H:i",strtotime($v['ts_created'])); + $rows[$k]['changelog'] = str_replace("\n","

      ",$v['changelog']); + } + $data = array("list"=>$rows); + $this->jsonexit($data); + return true; + }else{ + $data = array("error"=>"处理中出现错误"); + $this->jsonexit($data); + return true; + } + } + + }//getversionAction() + + function replace($string){ + $patterns = array("/\"/i","/\'/i"); + $replacements = array("“","‘"); + ksort($patterns); + ksort($replacements); + return preg_replace($patterns, $replacements, $string); + }//引号替换 + + + function postcommentAction(){ + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + try{ + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $userid = $user->id; + }else + { + $userid=0; + } + + $author = mb_substr($this->replace(trim($this->_request->getParam('author'))),0,30,'UTF-8'); + $email = mb_substr($this->replace(trim($this->_request->getParam('email'))),0,60,'UTF-8'); + $url = mb_substr($this->replace(trim($this->_request->getParam('url'))),0,60,'UTF-8'); + $content = $this->replace(trim($this->_request->getParam('content'))); + $vdcode = mb_substr($this->replace(trim($this->_request->getParam('vdcode'))),0,4,'UTF-8'); + + if(empty($author)) + { + echo "请输入您的名字"; + exit(); + } + + if(strlen($author)<3) exit("姓名长度不得少于2个汉字 :)"); + + if(empty($email)) + { + echo "请输入您的电子邮箱地址"; + exit(); + } + + if(strlen($email)<4) exit("Email长度太短,请填写正确的Email :)"); + + if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i",$email)) + { + echo "Email格式不正确"; + exit(); + } + + if(strlen($content)<5) exit("评论长度不得少于3个汉字 :)"); + + if(preg_match("/script/i",$content)) + { + $content = preg_replace("/script/i","script",$content); + } + + if(preg_match("/<|>/",$content)) + { + $data=array( + '<'=>'<', + '>'=>'>', + ); + + $patterns = array(); + $replacements = array(); + foreach($data as $k=>$v) + { + $patterns[]='/'.$k.'/i'; + $replacements[]=$v; + } + ksort($patterns); + ksort($replacements); + $content=preg_replace($patterns, $replacements, $content); + if(!empty($url)) + { + $url=preg_replace($patterns, $replacements, $url); + } + } + + if(preg_match("/script/i",$url)) + { + $url = preg_replace("/script/i","script",$url); + } + + if(!preg_match("/http:\/\//",$url)) + { + $url = "http://".$url; + } + + $uuid = trim($this->_request->getParam('uuid')); + + if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid)) + { + echo "参数错误!"; + exit(); + } + + if(strtolower($vdcode) != $_SESSION['vdcodes']) + { + echo "验证码错误,请重新输入"; + exit(); + } + + + $data = array( + 'uuid' => $uuid, + 'uid' => $userid, + 'author' => $author, + 'email' => $email, + 'url' => $url, + 'ip' => $_SERVER['REMOTE_ADDR'], + 'content' => $content, + 'agent' => $_SERVER['HTTP_USER_AGENT'], + 'type' => 'comment' + ); + + $sql = "INSERT INTO comments (author,email,url,ip,content,agent,type,uuid,userid) VALUES (?,?,?,?,?,?,?,?,?)"; + $sth = $this->db->prepare($sql); + $exec = $sth->execute(array($data['author'],$data['email'],$data['url'],$data['ip'],$data['content'],$data['agent'],$data['type'],$data['uuid'],$data['uid'])); + + if($exec) + { + $sql = "SELECT u.email FROM mdauthor au + LEFT JOIN users u on au.userid=u.id + WHERE au.uuid='$uuid'"; + $sth = $this->db->query($sql); + $rows = $sth->fetchAll(); + + @$mailtp=new EmailText( + $this->db, + 'data-comment-note', + array( + 'user' =>$user->username, + 'uuid' =>$data['uuid'], + 'title' =>$this->replace(trim($this->_request->getParam('mdtitle'))), + 'content'=>$content + ) + ); + @$mail=new WestdcMailer($this->view->config->smtp); + @$mail->setBodyText($mailtp->getBody()); + @$mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); + @$mail->addTo($this->view->config->service->email); + if(is_array($rows) && count($rows)>0) + { + foreach($rows as $v) + { + @$mail->addTo($v['email']); + } + } + @$mail->setSubject($mailtp->getSubject()); + @$mail->send(); + $msg = "用户".$user->username."对元数据《".$this->replace(trim($this->_request->getParam('mdtitle')))."》进行了评论,点击查看"; + include_once("message.php"); + message::post($this->db,0,-1,"收到新数据评论",$msg); + echo "评论成功"; + exit(); + }else + { + echo "评论失败,请重试 :)"; + exit(); + } + }catch(Exception $e){ + echo "出错了,请稍后再试"; + exit(); + } + }//ajax评论 + + + /* + * 数据评论,根据UUID读取 + */ + function commentAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $uuid=$this->_request->getParam('uuid'); + if (empty($uuid)) die(); + $sql="select * from comments where uuid=? AND reply=0 order by id desc"; + $comments=$this->db->fetchAll($sql,array($uuid)); + + $paginator = Zend_Paginator::factory($comments); + $paginator->setCurrentPageNumber($this->_getParam('page')); + $paginator->setItemCountPerPage(5); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('data/pagination_ajax.phtml'); + + include_once("Avatar.php"); + $avatar = new Avatar(); + if ($paginator) + { + foreach($paginator as $c) + { + //$author=$this->view->escape($c['author']); + $sql = "SELECT cr.id,cr.content as body,cr.reply,u.username,cr.ts_created,u.usertype,u.email as email, + (SELECT au.uuid FROM mdauthor au WHERE au.userid=u.id AND au.uuid='$uuid') as uuid + FROM comments cr + LEFT JOIN users u ON cr.userid=u.id + WHERE cr.reply=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($c['id'])); + $replys = $sth->fetchAll(); + $replyhtml = ""; + if(!empty($replys) || count($replys)>0) + { + foreach($replys as $v) + { + $usertype = ""; + $color = ""; + if($v['usertype'] == "administrator") + { + $usertype = "[管理员]"; + $color="#009d00"; + } + if($v['uuid'] == $uuid) + { + $usertype = "[数据作者]"; + $color="#add2e9"; + } + if(!empty($color)) + { + $color = 'background:'.$color.';color:#FFFFFF;'; + } + $img = $avatar->Get($v['email'],48); + $replyhtml .=' +

      + + + +
      + 回复于'.date('Y-m-d H:i:s',strtotime($v['ts_created'])).' +
      '.$v['username'].' '.$usertype.'
      + '.$v['body'].' +
      +
      + '; + + } + } + + $img = $avatar->Get($c['email'],64); + //$img = ''; + + $author = $c['author']; + $author = ($c['url'])?''.$author.'':$author; + $author = ''.$author.""; + $time = '发表于'.date('Y-m-d H:i:s',strtotime($c['ts_created'])).''; + print ' +
      + +
      + '.$time.' +

      '.$c['author'].'

      + '.$c['content'].' + '.$replyhtml.' +
      +
      + '; + } + echo '
      '.$paginator.'
      '; + }//else echo "
    • No comments.
    • "; + }//评论列表 + + /** + * 判断用户是否填写了申请信息 + * @param string $uuid + * @param int $userid + */ + function todownloadAction() { + + $this->view->pageID = "account-dataorder"; + + $this->_helper->viewRenderer('onlineapp-download'); + + $this->view->uuid = $uuid = $this->_request->getParam('uuid'); + + $auth = Zend_Auth::getInstance(); + if (!$auth->hasIdentity()) + { + $this->view->AlertType = "alert-error"; + $this->view->msg = "请先登录您的账户后进行下载,页面将自动跳转"; + $this->view->jump_url = '/account/login/?href=/data/todownload/uuid/'.$uuid; + return true; + } + + if(empty($uuid)) + { + $this->view->AlertType = "alert-error"; + $this->view->msg = "参数错误!"; + $this->view->jump_url = "/data"; + return true; + } + + $this->view->projectType = array( + "请选择项目类型" => "", + "国家973计划项目课题" => "国家973计划项目课题", + "国家863计划课题"=>"国家863计划课题", + "国家级科技支撑课题" => "国家级科技支撑课题", + "国家级科技重大专项" => "国家级科技重大专项", + "国家级国家重大工程" => "国家级国家重大工程", + "国家级国家自然科学基金" => "国家级国家自然科学基金", + "国际合作项目"=>"国际合作项目", + "省部级项目" => "省部级项目", + "其他项目工程" => "其他项目工程", + ); + + $userid = Zend_Auth::getInstance()->getIdentity()->id; + + $submit = $this->_getParam('submit'); + if(!empty($submit)){ + + $datas = array(); + $datas['realname'] = $this->_request->getParam('realname'); + $datas['unit'] = $this->_request->getParam('unit'); + $datas['phone'] = $this->_request->getParam('phone'); + $datas['address'] = $this->_request->getParam('address'); + $datas['postcode'] = $this->_request->getParam('postcode'); + $datas['email'] = $this->_request->getParam('email'); + $datas['project'] = $this->_request->getParam('project'); + $datas['project_id'] = $this->_request->getParam('project_id'); + $datas['project_type'] = $this->_request->getParam('project_type'); + $datas['project_title'] = $this->_request->getParam('project_title'); + $datas['project_leader']= $this->_request->getParam('project_leader'); + + $this->view->info = $datas; + + $this->view->AlertType = "alert-error"; + + foreach($datas as $k=>$v) + { + if(empty($v)) + { + $this->view->error = "每一项内容都需要填写"; + return true; + } + } + + if(!is_numeric($datas['postcode'])) + { + $this->view->error = "联系电话和邮政编码请填写数字"; + return true; + } + + if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i",$datas['email'])) + { + $this->view->error = "请填写正确的email地址"; + return true; + } + + if(mb_strlen($datas['project'],"utf-8")<8) + { + $this->view->error = "项目介绍内容不少于8个字符"; + return true; + } + + if(preg_match('/^\d+$/',$datas['project'])) + { + $this->view->error = "请输入有意义的项目介绍内容"; + return true; + } + + $data = array( + 'userid' => $userid, + 'username' => $datas['realname'], + 'unit' => $datas['unit'], + 'phone' => $datas['phone'], + 'address' => $datas['address'], + 'postcode' => $datas['postcode'], + 'project' => $datas['project'], + 'uuid' =>$uuid, + 'email' =>$datas['email'], + 'project_id'=>$datas['project_id'], + 'project_title'=>$datas['project_title'], + 'project_type'=>$datas['project_type'], + 'project_leader'=>$datas['project_leader'] + ); + + if($this->db->insert('onlineapp',$data)) + { + $select = "select id from onlineapp where userid='$userid' order by id desc"; + $re=$this->db->query($select); + $row=$re->fetch(); + + $this->view->AlertType = "alert-success"; + $this->view->jump_url = '/data/download/uuid/'.$uuid.'/onlineappid/'.$row['id']; + $this->view->msg = "您的信息已经提交成功,可以进行下载。请等待页面自动跳转,view->jump_url."\">或点击这里进入下载页面"; + + $msg = "用户{$data['username']} 填写了在线数据申请表 查看详细"; + $title = "用户 {$data['username']} 申请了在线下载数据"; + include_once("message.php"); + message::post($this->db,0,-1,$title,$msg); + + return true; + } + else { + $this->view->AlertType = "alert-error"; + $this->view->error = "申请失败,请稍后重新尝试"; + $this->view->info = $data; + return true; + } + + return true; + }else{ + + $testsql="select * from onlineapp where userid='$userid' and uuid='$uuid' order by id desc"; + $result=$this->db->query($testsql); + $rows = $result->fetch(); + if (empty($rows['id'])) + { + include_once("Users.php"); + $usr = new Users($this->db); + $this->view->info = $usr->getUserInfo($userid); + return true; + } + else + { + $datas['realname'] = $rows['username']; + $datas['unit'] = $rows['unit']; + $datas['phone'] = $rows['phone']; + $datas['address'] = $rows['address']; + $datas['postcode'] = $rows['postcode']; + $datas['email'] = $rows['email']; + $datas['project'] = $rows['project']; + $datas['project_id'] = $rows['project_id']; + $datas['project_type'] = $rows['project_type']; + $datas['project_title'] = $rows['project_title']; + $datas['project_leader'] = $rows['project_leader']; + $this->view->info = $datas; + return true; + } + } + + return true; + + $userid=Zend_Auth::getInstance()->getIdentity()->id; + + $datas = array(); + $submited = $this->_request->getParam('submited'); + $datas['username'] = $this->_request->getParam('username'); + $datas['unit'] = $this->_request->getParam('unit'); + $datas['phone'] = $this->_request->getParam('phone'); + $datas['address'] = $this->_request->getParam('address'); + $datas['postcode'] = $this->_request->getParam('postcode'); + $datas['email'] = $this->_request->getParam('email'); + $datas['project'] = $this->_request->getParam('project'); + $datas['project_id'] = $this->_request->getParam('projectid'); + $datas['project_type'] = $this->_request->getParam('projecttype'); + $datas['project_title'] = $this->_request->getParam('projecttitle'); + $datas['project_leader'] = $this->_request->getParam('projectleader'); + + + + $form=$this->creatform($datas); + + if (!empty($submited) && $ft==0){ + + foreach($datas as $k=>$v) + { + if($v == '') + { + echo $form.''; + exit(); + } + } + + if(!is_numeric($datas['postcode'])) + { + echo $form.''; + exit(); + } + + if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i",$datas['email'])) + { + echo $form.''; + exit(); + } + + if(mb_strlen($datas['project'],"utf-8")<8) + { + echo $form.''; + exit(); + } + + if(preg_match('/^\d+$/',$datas['project'])) + { + echo $form.''; + exit(); + } + + $data = array( + 'userid' => $userid, + 'username' => $datas['username'], + 'unit' => $datas['unit'], + 'phone' => $datas['phone'], + 'address' => $datas['address'], + 'postcode' => $datas['postcode'], + 'project' => $datas['project'], + 'uuid' =>$uuid, + 'email' =>$datas['email'], + 'project_id'=>$datas['project_id'], + 'project_title'=>$datas['project_title'], + 'project_type'=>$datas['project_type'], + 'project_leader'=>$datas['project_leader'] + ); + + if($this->db->insert('onlineapp',$data)) + { + $select = "select id from onlineapp where userid='$userid' order by id desc"; + $re=$this->db->query($select); + $row=$re->fetch(); + echo "您的信息已经提交成功,可以进行下载。
      + 如果页面没有自动跳转,请点击这里进入下载页面 + "; + $msg = "用户{$data['username']} 填写了在线数据申请表 查看详细"; + $title = "用户 {$data['username']} 申请了在线下载数据"; + include_once("message.php"); + message::post($this->db,0,-1,$title,$msg); + exit(); + } + else { + echo $form.''; + exit(); + } + + }else if( $ft==1 ) + { + $testsql="select * from onlineapp where userid='$userid' and uuid='$uuid' order by id desc"; + $result=$this->db->query($testsql); + $rows = $result->fetch(); + if (empty($rows['id'])) + { + $sql="select * from users where id='$userid'"; + $result=$this->db->query($sql); + $rows = $result->fetch(); + + $datas['username'] = $rows['realname']; + $datas['unit'] = $rows['unit']; + $datas['phone'] = $rows['phone']; + $datas['address'] = $rows['address']; + $datas['postcode'] = $rows['postcode']; + $datas['email'] = $rows['email']; + $datas['project'] = $rows['project']; + $datas['project_id'] = $rows['project_id']; + $datas['project_type'] = $rows['project_type']; + $datas['project_title'] = $rows['project_title']; + $datas['project_leader'] = $rows['project_leader']; + echo $this->creatform($datas); + exit(); + } + else + { + $datas['username'] = $rows['username']; + $datas['unit'] = $rows['unit']; + $datas['phone'] = $rows['phone']; + $datas['address'] = $rows['address']; + $datas['postcode'] = $rows['postcode']; + $datas['email'] = $rows['email']; + $datas['project'] = $rows['project']; + $datas['project_id'] = $rows['project_id']; + $datas['project_type'] = $rows['project_type']; + $datas['project_title'] = $rows['project_title']; + $datas['project_leader'] = $rows['project_leader']; + echo $this->creatform($datas); + exit(); + } + } + + } + + /* + * 数据下载,根据UUID进行判断 + * 一次只下载一个数据(一个元数据项) + */ + function downloadAction() + { + $uuid=$this->_request->getParam('uuid'); + $onlineappid=$this->_request->getParam('onlineappid'); + $this->view->pageID = "account-dataorder"; + + if (empty($uuid)) $this->_redirect('/data'); + + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $userid = $user->id; + } + + $testsql="select id,has_send_mail from onlineapp where userid='$userid' and uuid='$uuid' order by id desc"; + $result=$this->db->query($testsql); + $rows = $result->fetch(); + $has_send_mail=$rows['has_send_mail']; + if (empty($rows['id'])) + { + $this->_redirect('/data/'.$uuid); + } + else + { + $sql="select onlineappid,id from dataorder where status=0 and userid='$userid' and uuid='$uuid' order by id desc"; + $re=$this->db->query($sql); + $row=$re->fetch(); + if(empty($row['onlineappid'])) + { + $data = array( + 'userid' => $userid, + 'uuid' => $uuid, + 'onlineappid'=> $onlineappid, + 'ts_approved'=>'now()', + ); + try {$this->db->insert('dataorder',$data);} catch (Exception $e) {} + }else + { + $sql="update dataorder set onlineappid='$onlineappid',ts_approved=now() where id='{$row['id']}'"; + try {$this->db->exec($sql);} catch (Exception $e) {} + } + } + + + $sql=$this->db->quoteInto("select * from dataset o left join metadata m on o.uuid=m.uuid left join mdstatus s on m.uuid=s.uuid where s.status>4 and m.datatype=0 and m.uuid=?",$uuid); + $data=$this->db->fetchRow($sql); + $updateftp=$updateftp1=false; + $this->view->md=$data; + $this->view->userpass=md5('westdc'.rand(1000,9999)); + $this->view->ftptime=date('Y-m-d H:i:s', strtotime('+1 week')); + $sql=$this->db->quoteInto("select * from ftpuser where userid=?",$userid); + $row=$this->db->fetchRow($sql); + $datacount=$row['datacount']; + if ($data['host']=='ftp.westgis.ac.cn') + { + //添加FTP帐号信息以及时间控制信息 + $updateftp=true; + $g6=new G6ftp(); + $g6->db=$this->db; + //不进行判断,每个元数据中的下载地址都对应一个虚拟路径 + $path[]=$data['path']; + $this->view->username='westdc'.$userid; + $uu=(object)array("id"=>$userid, + "username"=>$this->view->username, + "password"=>$this->view->userpass, + "path"=>$path, + "maxdata"=>$this->view->config->download->max, + "time"=>$this->view->ftptime, + "datacount"=>$datacount); + if ($g6->createuser($uu)) { + $this->view->userpass=$g6->pwd; + $this->view->ftptime=$g6->time; + } else { + $this->messenger->addMessage('错误:您正在进行下载的在线数据数已经超过系统允许的最大值,请在下面点击“完成”或“取消”对应的在线数据下载!'); + $this->_redirect('/data/order'); + } + } elseif ($data['host']=='ftp1.westgis.ac.cn') + { + //添加FTP1帐号信息以及时间控制信息 + $proftp=new Proftp(); + $proftp->db=$this->db; + //proftp离线用户名和g6的用户名稍有不同 + $this->view->username='westdc_'.$userid; + $uu=(object)array("id"=>$userid, + "username"=>$this->view->username, + "password"=>$this->view->userpass, + "host"=>'ftp1.westgis.ac.cn', + "param"=>"onlineappid=".$onlineappid, + "maxdata"=>$this->view->config->download->max, + "time"=>$this->view->ftptime, + "datacount"=>$datacount); + if ($proftp->createuser($uu)) + { + $this->view->userpass=$proftp->pwd; + $this->view->ftptime=$proftp->time; + } + } elseif ($data['host']=='ftp.sanjiangyuan.org.cn') + { + //添加FTP2帐号信息以及时间控制信息 + $proftp=new Pureftp(); + $proftp->db=$this->db; + $this->view->username='sjy_'.$userid; + $uu=(object)array("id"=>$userid, + "username"=>$this->view->username, + "password"=>$this->view->userpass, + "host"=>'ftp.sanjiangyuan.org.cn', + "param"=>"onlineappid=".$onlineappid, + "maxdata"=>$this->view->config->download->max, + "time"=>$this->view->ftptime, + "datacount"=>$datacount); + if ($proftp->createuser($uu)) + { + $this->view->userpass=$proftp->pwd; + $this->view->ftptime=$proftp->time; + } + } + $ftpurl='ftp://'.$this->view->username.'@'.$data['host']; + if ($data['host']=='ftp.westgis.ac.cn') $ftpurl.=$data['path']; + + //设置输出 + //if ($updateftp || $updateftp1) $this->view->userpass=$password; + $this->view->ftpurl=$ftpurl; + //更新下载记录 + //todo: 尝试添加一个RULE:若有对应数据存在,则不插入( userid,uuid,status=0,ts_approved:null) + /*$sql="select * from dataorder where userid=? and uuid=? and status=0 and (ts_approved is null)"; + $u=$this->db->fetchRow($sql,array($userid,$uuid)); + if (empty($u)) { + $sql="insert into dataorder (userid,uuid,ts_created) values(?,?,now())"; + $this->db->query($sql,array($userid,$uuid)); + }*/ + if (!empty($ftpurl) && !$has_send_mail) + { + $data = array( + "uuid"=>$uuid, + "title"=>$this->view->md['title']."(".$this->view->md['filesize']."MB)", + "user"=>$user->username, + "ftpuser"=>$this->view->username, + "ftppwd"=>$this->view->userpass, + "ftptime"=>$this->view->ftptime, + "ftpurl"=>$this->view->ftpurl, + "note"=>$updateftp?'BTW:请注意登陆后要手工进入对应的目录!':'' + ); + $mailtp=new EmailText($this->db,'online-download',$data); + $mail=new WestdcMailer($this->view->config->smtp); + $mail->setBodyText($mailtp->getBody()); + $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); + $mail->addTo($user->email); + $mail->setSubject($mailtp->getSubject()); + @$mail->send(); + $sql="update onlineapp set has_send_mail=true where id=?"; + $sth=$this->db->prepare($sql); + $sth->execute(array($onlineappid)); + } + } + /* + * 离线申请(可以包括在线数据),在无数据参数时,则显示已有列表 + */ + function orderAction() + { + $this->view->pageID = "account-dataorder"; + $ac = $this->_request->getParam('ac'); + + $uuid = $this->_request->getParam('uuid'); + + $del = $this->_request->getParam('del'); + $apply = $this->_request->getParam('apply'); + $finish = $this->_request->getParam('finish'); + $cancel = $this->_request->getParam('cancel'); + $wsn = $this->_request->getParam('wsn'); + $pdf = $this->_request->getParam('pdf'); + $selections = $this->_request->getParam('data'); + + //if (empty($uuid)) $this->_redirect('/data'); + $userid = view::User('id'); + + //添加到数据篮 + if ($uuid) + { + //存在历史遗留问题,原来的数据并不能保证唯一 + + $order = new Order(); + $state = $order->addOrder($uuid); + + if($state !== true) + { + if(!is_array($state)) + { + $this->view->msg = view::Msg('alert-error',$state); + }else{ + $service_type = $order->serviceTypeTest($state['service_type']); + if($service_type !== false) + { + view::Post($this,$service_type,$state['service_url']."?href=".urlencode(view::getHostLink()."/data/order/")."&uuid=".$state['uuid']."&uid=".$userid); + }else{ + $this->view->msg = view::Msg('alert-error',"无法申请:此元数据的数据类型未知"); + } + } + }else{ + $this->view->msg = view::Msg('alert-success',"添加成功!您可以继续浏览数据或是继续提交申请表"); + } + + if (empty($ac)) $ac='offline1'; + + } + + elseif ($selections) + { + if(empty($uuid)) + { + $this->view->msg = view::Msg('alert-error',"无法申请:参数出错,请通过正确的途径访问"); + } + + $order = new Order(); + $state = $order->addOrder($uuid,$selections); + + if($state !== true) + { + $this->view->msg = view::Msg('alert-error',$state); + }else{ + $this->view->msg = view::Msg('alert-success',"添加成功!您可以继续浏览数据或是继续提交申请表"); + } + + if (empty($ac)) $ac='offline1'; + } + + //删除申请 + elseif ($del) { + $order = new Order(); + $state = $order->del($del); + if($state !== true) + { + $this->view->msg = view::Msg('alert-error',$state); + }else{ + $this->view->msg = view::Msg('alert-success',"数据申请取消成功"); + } + $this->_redirect('/data/order'); + } + + //提交申请 + elseif ($apply) { + if($apply == "all" || !is_numeric($apply)) + { + $apply = -1; + } + $order = new Order(); + $state = $order->apply($apply); + if($state !== true) + { + $this->view->msg = view::Msg('alert-error',$state); + }else{ + $this->view->msg = view::Msg('alert-success',"提交成功,您可以点击“提交离线申请”来生成PDF申请表"); + } + if (empty($ac)) $ac='offline2'; + } + + //完成 + elseif ($finish) { + if ($finish=='all') { + $sql=$this->db->quoteInto("update dataorder set ts_approved=now() where status=0 and userid=?",$userid); + $this->db->query($sql); + $sql="update ftpuser set datacount=0 where userid=?"; + $this->db->query($sql,array($userid)); + } else { + $sql="update dataorder set ts_approved=now() where status=0 and userid=? and id=?"; + $this->db->query($sql,array($userid,(int)$finish)); + $sql="update ftpuser set datacount=datacount-1 where userid=? and datacount>0"; + $this->db->query($sql,array($userid)); + } + } + + elseif($wsn) + { + $this->_helper->viewRenderer('order-wsn'); + + return true; + } + + elseif ($cancel) { + if ($cancel=='all') { + $sql=$this->db->quoteInto("update dataorder set ts_approved=now(),status=-1 where status=0 and userid=?",$userid); + $this->db->query($sql); + $sql="update ftpuser set datacount=0 where userid=?"; + $this->db->query($sql,array($userid)); + } else { + $sql="update dataorder set ts_approved=now(),status=-1 where status in (0,1,2) and userid=? and id=?"; + $this->db->query($sql,array($userid,(int)$cancel)); + $sql="update ftpuser set datacount=datacount-1 where userid=? and datacount>0"; + $this->db->query($sql,array($userid)); + } + if (empty($ac)) $ac='offline2'; + } + + //生成PDF离线申请文件 + elseif ($pdf) { + + //用户信息可以从SESSION中读取?离线申请信息 + //$sql="select * from users where id=?"; + $order = new Order(); + $rows = $order->getOrderItemForPdf(); + $this->view->projectType = $order->projectType; + + if ($rows) { + $this->_helper->viewRenderer('pdf'); + + $this->view->data2 = $rows; + + if ($this->_request->isPost()) { + + $this->view->formData = $formData = $this->_request->getPost(); + + $datalist=''; + foreach($rows as $i=>$row) + { + $datalist.=($i+1).". ".$row['title'].";"; + } + $formData['datalist'] = $datalist; + + if (@$formData['save']) { + + $order->setPdfData($rows); + + $s = $order->SaveOrder($formData); + + if($s !== true) + { + $this->view->error = view::Msg('alert-error',$s); + return true; + } + + //不能修改顺序 + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + return true; + } elseif ($formData['submit']) { + //生成PDF + $order->setPdfData($rows); + $s = $order->SubmitOrder($formData); + + if($s !== true) + { + $this->view->error = view::Msg('alert-error',$s); + return true; + } + + $this->view->msg = view::Msg('alert-success','提示信息:您的离线申请已经提交,请在线上传PDF的签字版PDF文件。',0); + if (empty($ac)) $ac='offline3'; + } + } else { + $sql="select u.* from users u left join offlineapp o on u.id=o.userid where u.id=? ORDER BY o.id DESC"; + $row=$this->db->fetchRow($sql,array($userid)); + $this->view->formData = $row; + } + } else{ + $this->view->msg=view::Msg('alert-error',"错误:您还没有提交任何离线申请的数据,或您的数据申请已经提交(等待处理过程中)!",0); + } + return true; + }//pdf + + if($ac == "commitapplicationform") + { + $offlineappid = $this->_getParam('offlineappid'); + + if(!is_numeric($offlineappid) || $offlineappid < 1) + { + view::Post($this,"参数错误",-1); + return true; + } + + $order = new Order(); + $status = $order->commitApplicationForm($offlineappid); + + if( $status !== true) + { + view::Post($this,$status,-1); + }else{ + view::Post($this,"申请已提交,请等待管理员接收并通过数据所有者审核",'/data/order/ac/offline3'); + } + + return true; + } + + //index + $this->view->ac = $ac; + $this->_helper->viewRenderer('order'); + if ($ac=='' || $ac=='online') + { + $this->view->tabID='order-online'; + } else if ($ac=='offline1') { + $this->view->tabID='order-offline1'; + } else if ($ac=='offline2') { + $this->view->tabID='order-offline2'; + } else if ($ac=='offline3') { + $this->view->tabID='order-offline3'; + } else if ($ac=='offline4') { + $this->view->tabID='order-offline4'; + } + //显示已经申请的数据,包括已经提交的申请和未提交的申请,还有已经处理完成的申请,正在进行的在线数据下载 + $sql="select d.*,m.title,m.datatype,off.applicationform from dataorder d + left join metadata m on d.uuid=m.uuid + left join offlineapp off ON off.id = d.offlineappid + where d.userid=? order by d.status,d.ts_created desc"; + $rows=$this->db->fetchAll($sql,array($userid)); + + $showorders = array(); + $counts = array( + 'onlineapp' => 0, + 'offline1' => 0, + 'offline2' => 0, + 'offline3' => 0, + 'offline4' => 0 + ); + + if(count($rows) > 0) { + foreach($rows as $k=>$v) + { + switch($v['status']) { + case 0: + $counts['onlineapp'] ++; + break; + case 1: + $counts['offline1'] ++; + break; + case 2: + $counts['offline2'] ++; + break; + case 3: + $counts['offline3'] ++; + break; + case 4: + $counts['offline3'] ++; + break; + case 5: + $counts['offline4'] ++; + break; + } + switch($ac){ + default : + if($v['status'] == 0 && !empty($v['ts_approved']))$showorders[] = $rows[$k]; + break; + case 'online' : + if($v['status'] == 0 && !empty($v['ts_approved']))$showorders[] = $rows[$k]; + break; + case 'offline1' : + if($v['status'] == 1) $showorders[] = $rows[$k]; + break; + case 'offline2' : if($v['status'] == 2) { - $showorders[] = $rows[$k]; - $this->view->offlineappid = $v['offlineappid']; - $this->view->applicationform = $v['applicationform']; + $showorders[] = $rows[$k]; + $this->view->offlineappid = $v['offlineappid']; + $this->view->applicationform = $v['applicationform']; $this->view->offlineappstatus = $v['status']; - } - break; - case 'offline3' : + } + break; + case 'offline3' : if($v['status'] == 3 || $v['status'] == 4) { - $showorders[] = $rows[$k]; - $this->view->offlineappid = $v['offlineappid']; - $this->view->applicationform = $v['applicationform']; + $showorders[] = $rows[$k]; + $this->view->offlineappid = $v['offlineappid']; + $this->view->applicationform = $v['applicationform']; $this->view->offlineappstatus = $v['status']; - } - break; - case 'offline4' : - if($v['status'] == 5) $showorders[] = $rows[$k]; - break; - } - } - } - - $this->view->counts = $counts; - view::addPaginator($showorders,$this,10); - - } - - /* - * 查看数据缩略图 - */ - function thumbAction() - { - $page=(int)$this->_request->getParam('page'); - if (empty($page)) $page=1; - $offset=$this->limit*($page-1); - $state=$this->db->query("select count(*) from normalmetadata"); - $row=$state->fetchAll(); - $sum=$row[0]['count']; - $select=$this->db->select(); - $select->from('normalmetadata as m','m.*') - ->order('m.title desc')->limitPage($page,9); - $this->view->metadata = $this->db->fetchAll($select); - $this->view->page=new Pagination($sum,$page,$this->limit); - } - - /* - *附件下载 - */ - function attachAction(){ - - $uuid = $this->_request->getParam('uuid'); - - if(!empty($uuid)) - { - - $sql="select * from mdattach m left join attachments a on m.id=a.id where m.uuid='$uuid'"; - $re=$this->db->query($sql); - $atts = $re->fetch(); - - if(empty($atts['id'])) - { - $this->_redirect("/data/$uuid"); - }//没有附件 - - $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { - /* - $user = $auth->getIdentity(); - $userid = $user->id; - $sql = "select d.* from dataorder d - left join users u on u.id=d.userid - left join metadata m on m.uuid=d.uuid - where (d.status=5 and d.userid='$userid' and d.uuid='$uuid') or u.usertype='administrator'"; - $re= $this->db->query($sql); - $row=$re->fetch(); - if(!empty($row['uuid'])) - { - $this->messenger->addMessage('您没有权限下载该附件'); - $this->_redirect("/data"); - } - else - {*/ - //由于涉及多个文件下载,所以将附件添加到zip压缩文件再输出 - - $sql="select * from mdattach m left join attachments a on m.id=a.id where m.uuid='$uuid'"; - $re=$this->db->query($sql); - $atts = $re->fetchAll(); - - $zip = new ZipArchive(); - $url=$this->view->config->upload."tmp/attachments_$uuid.zip";//创建临时文件 - $opened=$zip->open($url, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE); - if( $opened !== true ){ - die("cannot open {$url} for writing."); - } - - $updates = array(); //统计被下载的附件ID - - foreach ($atts as $k=>$v) - { - if (is_file($this->view->config->upload.$v['filename'])) { - $updates[]=$v['id']; - $zip->addFile($this->view->config->upload.$v['filename'],'/'.basename($v['filename'])); - } - } - $zip->close(); - - //更新统计 - $ids=join(',',$updates); - $sql = "update attachments set downtimes=downtimes+1 where id in ($ids)"; - @$this->db->exec($sql); - - - //输出下载 - $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); - // } - }//end if - else - { - $this->messenger->addMessage('您没有权限下载该附件'); - $this->_redirect("/data/$uuid"); - }//未登陆 - }//end if - else - { - $this->messenger->addMessage('您没有权限下载该附件'); - $this->_redirect("/data/$uuid"); - }//无权限 - - } - - - /* - * 西部计划项目及其数据产出 - */ - public function westeeAction() - { - //$sql="select w.*,m.uuid from westee w left join westeemd m on w.id=m.eeid order by w.id"; - $sql="select * from westee order by id"; - $this->view->westee=$this->db->fetchAll($sql); - $sql="select w.eeid,m.title,m.uuid from westeemd w left join metadata m on w.uuid=m.uuid order by w.eeid"; - $this->view->westeemd=$this->db->fetchAll($sql); - } - - public function pingbackAction() - { - $this->_helper->ViewRenderer->setNoRender(); - $this->_helper->layout->disableLayout(); - $server = new Zend_XmlRpc_Server(); - $server->setClass('PingbackRpc', 'pingback'); - echo $server->handle(); - } - - public function pingtestAction() - { - $this->_helper->ViewRenderer->setNoRender(); - $this->_helper->layout->disableLayout(); - $client = new Zend_XmlRpc_Client('http://test.westgis.ac.cn/data/pingback'); - $arg1 = 'http://wlx.westgis.ac.cn/567/'; - $arg2 = 'http://test.westgis.ac.cn/data/487591d0-d437-4114-b810-cbef7c4ee4b2'; - //$result = $client->call('pingback.ping', array($arg1, $arg2)); - $test = $client->getProxy('pingback'); - $test->ping($arg1,$arg2); - //var_dump($result); - } - public function outputAction() - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $sql="select title,datatype,filesize,id from normalmetadata"; - $md=$this->db->fetchAll($sql); - foreach($md as $m) - { - print $m["title"].","; - print ($m["datatype"]?"内部":"公开").","; - print ($m["filesize"]==1?" ":$m["filesize"]).","; - $sql1="select keyword from keyword where id=".$m["id"]." and keytype='place'"; - $kd=$this->db->fetchAll($sql1); - foreach ($kd as $p) print $p["keyword"]." "; - print ","; - $sql1="select keyword from keyword where id=".$m["id"]." and keytype='temporal'"; - $kd=$this->db->fetchAll($sql1); - foreach ($kd as $p) print $p["keyword"]." "; - print ","; - print "
      "; - } - - } - - - public function jsonexit($data){ - $this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(json_encode($data,JSON_NUMERIC_CHECK)); - return true; - } - function organizationAction() - { - $page = $this->_request->getParam('page'); - $name = $this->_request->getParam('name'); - $state=$this->db->query("select distinct responsible.organisation from responsible left join role on role.resid=responsible.id where role.role in ('pointOfContact','resourceProvider','owner')"); - $this->view->organisation=$state->fetchAll(); - if (!empty($name)) { - $this->view->codename=$name; - $sql="select distinct m.* from normalmetadata m left join role r on m.uuid=r.uuid left join responsible s on r.resid=s.id where r.role in ('pointOfContact','resourceProvider','owner') and s.organisation=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($name)); - $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; - } else { - //提供全部分类列表 - } - } - function fundAction() - { - $id = (int)$this->_request->getParam('id'); - if (!empty($id)) { - $sql="select * from fund where id=?"; - $this->view->fund=$this->db->fetchRow($sql,array($id)); - if ($this->view->fund) { - $sql="select distinct m.* from normalmetadata m left join mdfund mf on m.uuid=mf.uuid where mf.fid=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($id)); - $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; - } - } else { - //提供全部分类列表 - $sql="select f.id,f.title,f.fund_id,f.fund_type,f.ts_created,count(m.id) as datacount,sum(md.filesize) as filesize from fund f left join mdfund m on f.id=m.fid left join metadata md on m.uuid=md.uuid where m.id is not null group by f.id,f.title,f.fund_id,f.fund_type,f.ts_created order by datacount desc,f.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(10); - $paginator->setView($this->view); - Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); - $this->view->paginator=$paginator; - $this->_helper->viewRenderer('fund-list'); - } - } - - //实现基于DOI信息的浏览 - function doiAction() - { - $ac = $this->_request->getParam('ac'); - if ($ac=='unready') { - //列出没有DOI的数据 - $sql="select m.* from normalmetadata m where length(m.doi)<3 and m.uuid not in (select uuid from datadoi) order by m.ts_created desc"; - $this->view->pageID='doi-unready'; - } else if ($ac=='prepare') { - //列出有DOI但还未进行提交申请的数据 - $sql="select m.* from normalmetadata m where length(m.doi)>3 and m.uuid not in (select uuid from datadoi) order by m.ts_created desc"; - $this->view->pageID='doi-prepare'; - } else if ($ac=='unsubmit') { - //列出有DOI并计划提交申请的数据 - $sql="select m.*,d.doi as datadoi,date(d.ts_created) as ts_created from normalmetadata m left join datadoi d on m.uuid=d.uuid where length(m.doi)>3 and d.ts_created is not null and d.ts_submitted is null order by d.ts_created desc"; - $this->view->pageID='doi-unsubmit'; - } else if ($ac=='submit') { - //列出有DOI并计划提交申请的数据 - $sql="select m.*,d.doi as datadoi,date(d.ts_submitted) as ts_submitted from normalmetadata m left join datadoi d on m.uuid=d.uuid where length(m.doi)>3 and d.ts_submitted is not null and d.ts_published is null order by d.ts_submitted desc,d.ts_created desc"; - $this->view->pageID='doi-submit'; - } else if ($ac=='publish' || empty($ac)) { - //默认:列出最新发布的DOI数据 - $sql="select m.*,d.doi as datadoi,date(d.ts_submitted) as ts_submitted,date(d.ts_published) as ts_published from normalmetadata m left join datadoi d on m.uuid=d.uuid where length(m.doi)>3 and d.ts_published is not null order by d.ts_published desc,d.ts_submitted desc,d.ts_created desc"; - $this->view->pageID='doi-publish'; - } - $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; - } - - //基于数据作者的浏览(包括认证后的数据作者以及未认证的数据作者) - function authorAction() - { - $ac = $this->_request->getParam('ac'); - $id = (int)$this->_request->getParam('id'); - if ($ac=='verified') { - //已经认证过的数据作者 - $this->view->pageID='author-verified'; - $this->view->ac='verified'; - if ($id) { - //列出作者的数据 - $sql="select username,realname from users where id=?"; - $this->view->author=$this->db->fetchRow($sql,array($id)); - $sql="select m.* from normalmetadata m left join mdauthor a on a.uuid=m.uuid where a.userid=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($id)); - $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; - } else { - //已经认证过的数据作者 - $sql="select u.username,u.realname,u.id,count(u.id) as count from mdauthor a left join users u on a.userid=u.id where a.status=1 and a.uuid in (select uuid from normalmetadata) group by u.id,u.username,u.realname"; - $sth = $this->db->prepare($sql); - $sth->execute(); - $rows = $sth->fetchAll(); - $paginator = Zend_Paginator::factory($rows); - $paginator->setCurrentPageNumber($this->_getParam('page')); - $paginator->setItemCountPerPage(50); - $paginator->setView($this->view); - Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); - $this->view->paginator=$paginator; - } - } else if ($ac=='unverified' || empty($ac)) { - //未认证的数据作者 - $this->view->pageID='author-unverified'; - $this->view->ac='unverified'; - if ($id) { - //列出数据 - $sql="select individual as username from responsible where id=?"; - $this->view->author=$this->db->fetchRow($sql,array($id)); - $sql="select distinct m.* from normalmetadata m left join role r on m.uuid=r.uuid left join responsible s on r.resid=s.id where r.role in ('pointOfContact','resourceProvider','owner') and s.id=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($id)); - $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; - } else { - //列出所有作者 - $sql="select distinct responsible.individual as username,responsible.id from responsible left join role on role.resid=responsible.id where role.role in ('pointOfContact','resourceProvider','owner')"; - $sth = $this->db->prepare($sql); - $sth->execute(); - $rows = $sth->fetchAll(); - $paginator = Zend_Paginator::factory($rows); - $paginator->setCurrentPageNumber($this->_getParam('page')); - $paginator->setItemCountPerPage(50); - $paginator->setView($this->view); - Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); - $this->view->paginator=$paginator; - } - } - } - - function listAction() - { - $sql="select m.uuid,m.title,m.citation,m.doi,d.doi as datadoi,d.ts_published,d.authors,d.publisher,date_part('year',d.ts_published) as publish_year from normalmetadata m -left join mdstatus s on m.uuid=s.uuid -left join datadoi d on d.uuid=m.uuid -where s.status>4 -and m.uuid not in -(select d.uuid from datasource d left join source s on d.sourceid=s.id -where s.code in ('heihe','water','hiwater','westee')) -order by m.title"; - $this->view->metadata=$this->db->fetchAll($sql); - $sql="select m.uuid,m.title,m.citation,m.doi,d.doi as datadoi,d.ts_published,d.authors,d.publisher,date_part('year',d.ts_published) as publish_year - from normalmetadata m left join datadoi d on d.uuid=m.uuid left join mdstatus s on m.uuid=s.uuid where s.status>4 and m.title like '黑河综合遥感联合试验%' order by title"; - $this->view->water=$this->db->fetchAll($sql); - $sql="select m.uuid,m.title,m.citation ,m.doi,d.doi as datadoi,d.ts_published,d.authors,d.publisher,date_part('year',d.ts_published) as publish_year - from normalmetadata m left join datadoi d on d.uuid=m.uuid left join mdstatus s on m.uuid=s.uuid where s.status>0 and m.title like '黑河生态水文遥感试验%' order by title"; - $this->view->hiwater=$this->db->fetchAll($sql); - $sql="select m.uuid,m.title,m.citation ,m.doi,d.doi as datadoi,d.ts_published,d.authors,d.publisher,date_part('year',d.ts_published) as publish_year - from normalmetadata m left join datadoi d on d.uuid=m.uuid left join mdstatus s on m.uuid=s.uuid left join datasource ds on ds.uuid=m.uuid left join source sr on ds.sourceid=sr.id where sr.code='heihe' and s.status>0 and m.title not like '黑河生态水文遥感试验%' order by title"; - $this->view->heihe=$this->db->fetchAll($sql); - $sql="select m.uuid,m.title,m.citation ,m.doi,d.doi as datadoi,d.ts_published,d.authors,d.publisher,date_part('year',d.ts_published) as publish_year - from normalmetadata m left join datadoi d on d.uuid=m.uuid left join mdstatus s on m.uuid=s.uuid left join datasource ds on ds.uuid=m.uuid left join source sr on ds.sourceid=sr.id where sr.code='westee' and s.status>4 order by title"; - $this->view->westee=$this->db->fetchAll($sql); - - } -} - + } + break; + case 'offline4' : + if($v['status'] == 5) $showorders[] = $rows[$k]; + break; + } + } + } + + $this->view->counts = $counts; + view::addPaginator($showorders,$this,10); + + } + + /* + * 查看数据缩略图 + */ + function thumbAction() + { + $page=(int)$this->_request->getParam('page'); + if (empty($page)) $page=1; + $offset=$this->limit*($page-1); + $state=$this->db->query("select count(*) from normalmetadata"); + $row=$state->fetchAll(); + $sum=$row[0]['count']; + $select=$this->db->select(); + $select->from('normalmetadata as m','m.*') + ->order('m.title desc')->limitPage($page,9); + $this->view->metadata = $this->db->fetchAll($select); + $this->view->page=new Pagination($sum,$page,$this->limit); + } + + /* + *附件下载 + */ + function attachAction(){ + + $uuid = $this->_request->getParam('uuid'); + + if(!empty($uuid)) + { + + $sql="select * from mdattach m left join attachments a on m.id=a.id where m.uuid='$uuid'"; + $re=$this->db->query($sql); + $atts = $re->fetch(); + + if(empty($atts['id'])) + { + $this->_redirect("/data/$uuid"); + }//没有附件 + + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + /* + $user = $auth->getIdentity(); + $userid = $user->id; + $sql = "select d.* from dataorder d + left join users u on u.id=d.userid + left join metadata m on m.uuid=d.uuid + where (d.status=5 and d.userid='$userid' and d.uuid='$uuid') or u.usertype='administrator'"; + $re= $this->db->query($sql); + $row=$re->fetch(); + if(!empty($row['uuid'])) + { + $this->messenger->addMessage('您没有权限下载该附件'); + $this->_redirect("/data"); + } + else + {*/ + //由于涉及多个文件下载,所以将附件添加到zip压缩文件再输出 + + $sql="select * from mdattach m left join attachments a on m.id=a.id where m.uuid='$uuid'"; + $re=$this->db->query($sql); + $atts = $re->fetchAll(); + + $zip = new ZipArchive(); + $url=$this->view->config->upload."tmp/attachments_$uuid.zip";//创建临时文件 + $opened=$zip->open($url, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE); + if( $opened !== true ){ + die("cannot open {$url} for writing."); + } + + $updates = array(); //统计被下载的附件ID + + foreach ($atts as $k=>$v) + { + if (is_file($this->view->config->upload.$v['filename'])) { + $updates[]=$v['id']; + $zip->addFile($this->view->config->upload.$v['filename'],'/'.basename($v['filename'])); + } + } + $zip->close(); + + //更新统计 + $ids=join(',',$updates); + $sql = "update attachments set downtimes=downtimes+1 where id in ($ids)"; + @$this->db->exec($sql); + + + //输出下载 + $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); + // } + }//end if + else + { + $this->messenger->addMessage('您没有权限下载该附件'); + $this->_redirect("/data/$uuid"); + }//未登陆 + }//end if + else + { + $this->messenger->addMessage('您没有权限下载该附件'); + $this->_redirect("/data/$uuid"); + }//无权限 + + } + + + /* + * 西部计划项目及其数据产出 + */ + public function westeeAction() + { + //$sql="select w.*,m.uuid from westee w left join westeemd m on w.id=m.eeid order by w.id"; + $sql="select * from westee order by id"; + $this->view->westee=$this->db->fetchAll($sql); + $sql="select w.eeid,m.title,m.uuid from westeemd w left join metadata m on w.uuid=m.uuid order by w.eeid"; + $this->view->westeemd=$this->db->fetchAll($sql); + } + + public function pingbackAction() + { + $this->_helper->ViewRenderer->setNoRender(); + $this->_helper->layout->disableLayout(); + $server = new Zend_XmlRpc_Server(); + $server->setClass('PingbackRpc', 'pingback'); + echo $server->handle(); + } + + public function pingtestAction() + { + $this->_helper->ViewRenderer->setNoRender(); + $this->_helper->layout->disableLayout(); + $client = new Zend_XmlRpc_Client('http://test.westgis.ac.cn/data/pingback'); + $arg1 = 'http://wlx.westgis.ac.cn/567/'; + $arg2 = 'http://test.westgis.ac.cn/data/487591d0-d437-4114-b810-cbef7c4ee4b2'; + //$result = $client->call('pingback.ping', array($arg1, $arg2)); + $test = $client->getProxy('pingback'); + $test->ping($arg1,$arg2); + //var_dump($result); + } + public function outputAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $sql="select title,datatype,filesize,id from normalmetadata"; + $md=$this->db->fetchAll($sql); + foreach($md as $m) + { + print $m["title"].","; + print ($m["datatype"]?"内部":"公开").","; + print ($m["filesize"]==1?" ":$m["filesize"]).","; + $sql1="select keyword from keyword where id=".$m["id"]." and keytype='place'"; + $kd=$this->db->fetchAll($sql1); + foreach ($kd as $p) print $p["keyword"]." "; + print ","; + $sql1="select keyword from keyword where id=".$m["id"]." and keytype='temporal'"; + $kd=$this->db->fetchAll($sql1); + foreach ($kd as $p) print $p["keyword"]." "; + print ","; + print "
      "; + } + + } + + + public function jsonexit($data){ + $this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(json_encode($data,JSON_NUMERIC_CHECK)); + return true; + } + + public function organizationAction() + { + $page = $this->_request->getParam('page'); + $name = $this->_request->getParam('name'); + $state=$this->db->query("select distinct responsible.organisation from responsible left join role on role.resid=responsible.id where role.role in ('pointOfContact','resourceProvider','owner')"); + $this->view->organisation=$state->fetchAll(); + if (!empty($name)) { + $this->view->codename=$name; + $sql="select distinct m.* from normalmetadata m left join role r on m.uuid=r.uuid left join responsible s on r.resid=s.id where r.role in ('pointOfContact','resourceProvider','owner') and s.organisation=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($name)); + $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; + } else { + //提供全部分类列表 + } + } + function fundAction() + { + $id = (int)$this->_request->getParam('id'); + if (!empty($id)) { + $sql="select * from fund where id=?"; + $this->view->fund=$this->db->fetchRow($sql,array($id)); + if ($this->view->fund) { + $sql="select distinct m.* from normalmetadata m left join mdfund mf on m.uuid=mf.uuid where mf.fid=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($id)); + $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; + } + } else { + //提供全部分类列表 + $sql="select f.id,f.title,f.fund_id,f.fund_type,f.ts_created,count(m.id) as datacount,sum(md.filesize) as filesize from fund f left join mdfund m on f.id=m.fid left join metadata md on m.uuid=md.uuid where m.id is not null group by f.id,f.title,f.fund_id,f.fund_type,f.ts_created order by datacount desc,f.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(10); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); + $this->view->paginator=$paginator; + $this->_helper->viewRenderer('fund-list'); + } + } + + //实现基于DOI信息的浏览 + function doiAction() + { + $ac = $this->_request->getParam('ac'); + if ($ac=='unready') { + //列出没有DOI的数据 + $sql="select m.* from normalmetadata m where length(m.doi)<3 and m.uuid not in (select uuid from datadoi) order by m.ts_created desc"; + $this->view->pageID='doi-unready'; + } else if ($ac=='prepare') { + //列出有DOI但还未进行提交申请的数据 + $sql="select m.* from normalmetadata m where length(m.doi)>3 and m.uuid not in (select uuid from datadoi) order by m.ts_created desc"; + $this->view->pageID='doi-prepare'; + } else if ($ac=='unsubmit') { + //列出有DOI并计划提交申请的数据 + $sql="select m.*,d.doi as datadoi,date(d.ts_created) as ts_created from normalmetadata m left join datadoi d on m.uuid=d.uuid where length(m.doi)>3 and d.ts_created is not null and d.ts_submitted is null order by d.ts_created desc"; + $this->view->pageID='doi-unsubmit'; + } else if ($ac=='submit') { + //列出有DOI并计划提交申请的数据 + $sql="select m.*,d.doi as datadoi,date(d.ts_submitted) as ts_submitted from normalmetadata m left join datadoi d on m.uuid=d.uuid where length(m.doi)>3 and d.ts_submitted is not null and d.ts_published is null order by d.ts_submitted desc,d.ts_created desc"; + $this->view->pageID='doi-submit'; + } else if ($ac=='publish' || empty($ac)) { + //默认:列出最新发布的DOI数据 + $sql="select m.*,d.doi as datadoi,date(d.ts_submitted) as ts_submitted,date(d.ts_published) as ts_published from normalmetadata m left join datadoi d on m.uuid=d.uuid where length(m.doi)>3 and d.ts_published is not null order by d.ts_published desc,d.ts_submitted desc,d.ts_created desc"; + $this->view->pageID='doi-publish'; + } + $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; + } + + //基于数据作者的浏览(包括认证后的数据作者以及未认证的数据作者) + function authorAction() + { + $ac = $this->_request->getParam('ac'); + $id = (int)$this->_request->getParam('id'); + if ($ac=='verified') { + //已经认证过的数据作者 + $this->view->pageID='author-verified'; + $this->view->ac='verified'; + if ($id) { + //列出作者的数据 + $sql="select username,realname from users where id=?"; + $this->view->author=$this->db->fetchRow($sql,array($id)); + $sql="select m.* from normalmetadata m left join mdauthor a on a.uuid=m.uuid where a.userid=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($id)); + $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; + } else { + //已经认证过的数据作者 + $sql="select u.username,u.realname,u.id,count(u.id) as count from mdauthor a left join users u on a.userid=u.id where a.status=1 and a.uuid in (select uuid from normalmetadata) group by u.id,u.username,u.realname"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $rows = $sth->fetchAll(); + $paginator = Zend_Paginator::factory($rows); + $paginator->setCurrentPageNumber($this->_getParam('page')); + $paginator->setItemCountPerPage(50); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); + $this->view->paginator=$paginator; + } + } else if ($ac=='unverified' || empty($ac)) { + //未认证的数据作者 + $this->view->pageID='author-unverified'; + $this->view->ac='unverified'; + if ($id) { + //列出数据 + $sql="select individual as username from responsible where id=?"; + $this->view->author=$this->db->fetchRow($sql,array($id)); + $sql="select distinct m.* from normalmetadata m left join role r on m.uuid=r.uuid left join responsible s on r.resid=s.id where r.role in ('pointOfContact','resourceProvider','owner') and s.id=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($id)); + $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; + } else { + //列出所有作者 + $sql="select distinct responsible.individual as username,responsible.id from responsible left join role on role.resid=responsible.id where role.role in ('pointOfContact','resourceProvider','owner')"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $rows = $sth->fetchAll(); + $paginator = Zend_Paginator::factory($rows); + $paginator->setCurrentPageNumber($this->_getParam('page')); + $paginator->setItemCountPerPage(50); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); + $this->view->paginator=$paginator; + } + } + } + + function listAction() + { + $sql="select m.uuid,m.title,m.citation,m.doi,d.doi as datadoi,d.ts_published,d.authors,d.publisher,date_part('year',d.ts_published) as publish_year from normalmetadata m +left join mdstatus s on m.uuid=s.uuid +left join datadoi d on d.uuid=m.uuid +where s.status>4 +and m.uuid not in +(select d.uuid from datasource d left join source s on d.sourceid=s.id +where s.code in ('heihe','water','hiwater','westee')) +order by m.title"; + $this->view->metadata=$this->db->fetchAll($sql); + $sql="select m.uuid,m.title,m.citation,m.doi,d.doi as datadoi,d.ts_published,d.authors,d.publisher,date_part('year',d.ts_published) as publish_year + from normalmetadata m left join datadoi d on d.uuid=m.uuid left join mdstatus s on m.uuid=s.uuid where s.status>4 and m.title like '黑河综合遥感联合试验%' order by title"; + $this->view->water=$this->db->fetchAll($sql); + $sql="select m.uuid,m.title,m.citation ,m.doi,d.doi as datadoi,d.ts_published,d.authors,d.publisher,date_part('year',d.ts_published) as publish_year + from normalmetadata m left join datadoi d on d.uuid=m.uuid left join mdstatus s on m.uuid=s.uuid where s.status>0 and m.title like '黑河生态水文遥感试验%' order by title"; + $this->view->hiwater=$this->db->fetchAll($sql); + $sql="select m.uuid,m.title,m.citation ,m.doi,d.doi as datadoi,d.ts_published,d.authors,d.publisher,date_part('year',d.ts_published) as publish_year + from normalmetadata m left join datadoi d on d.uuid=m.uuid left join mdstatus s on m.uuid=s.uuid left join datasource ds on ds.uuid=m.uuid left join source sr on ds.sourceid=sr.id where sr.code='heihe' and s.status>0 and m.title not like '黑河生态水文遥感试验%' order by title"; + $this->view->heihe=$this->db->fetchAll($sql); + $sql="select m.uuid,m.title,m.citation ,m.doi,d.doi as datadoi,d.ts_published,d.authors,d.publisher,date_part('year',d.ts_published) as publish_year + from normalmetadata m left join datadoi d on d.uuid=m.uuid left join mdstatus s on m.uuid=s.uuid left join datasource ds on ds.uuid=m.uuid left join source sr on ds.sourceid=sr.id where sr.code='westee' and s.status>4 order by title"; + $this->view->westee=$this->db->fetchAll($sql); + + } +} + diff --git a/application/default/controllers/VisualController.php b/application/default/controllers/VisualController.php new file mode 100644 index 00000000..b1653095 --- /dev/null +++ b/application/default/controllers/VisualController.php @@ -0,0 +1,762 @@ +view->config = Zend_Registry::get('config'); + $this->db=Zend_Registry::get('db'); + $this->dbh = new PDO("pgsql:dbname=qinghaihu;host=localhost", "gis", "gispassword" ); + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $this->uid = $user->id; + }else{ + $this->_redirect('/account/login?href=/data/visual'); + } + } + + function indexAction() + { + + } + + + /**************************************************************** + + 气象数据 + + *****************************************************************/ + + + /* + * getMeteorologyValueByStation 按站点查询变量 + * + * param int $sid 站点编号 + * param string $field 变量类型 + * + * return array + */ + function getMeteorologyValueByStation($sid,$field) + { + + $sql = "select id,station_id as sid,date,$field as v from daily_meteorological_data where station_id=$sid ORDER BY date ASC"; + + $sth = $this->dbh->prepare($sql); + $sth->execute(); + $temp = $sth->fetchAll(); + + $dataSet = array(); + + foreach ($temp as $k=>$v) + { + $dataSet[] = array(strtotime($v['date'])*1000,$v['v']); + } + unset($temp); + + return $dataSet; + + }// getMeteorologyValueByStation 按站点查询变量 + + + + /* + * createMeteorologyDataSet 创建气象数据 + * + * param int $sid 站点id + * param string $valuetype 请求变量类型 + * param String $labe 单位 + * param int $round 数据精确度(小数点后位数) + * + * return array + */ + function createMeteorologyDataSet($sid,$valuetype,$label,$round=1) + { + if(empty($label)) + { + $label=""; + } + + $varField = array( + 'temperature' => 'avg_air_temperature', //日平均气温 + 'windspeed' => 'avg_wind_speed', //日平均风速 + 'precipitation' => 'sum_precipitation', //日合计降水量 + 'sunshine' => 'sunshine_hours' //日照小时数 + ); + + $data = array( + "name"=>"站点:$sid", + "data"=>$this->getMeteorologyValueByStation($sid,$varField[$valuetype]), + "tooltip"=>array( + "valueDecimals"=> $round, + "valueSuffix"=> $label + ) + ); + + return $data; + }// createMeteorologyDataSet 创建气象数据 + + + /* + * getMeteorologyDataByStationId 获得变量值 + * + * param string $valuetype 变量类型 + * param string $label 单位 + * param int $sid 可选,为空则查询所有站点 + * param int $round 数值精确度,小数点后位数 + * + * return array + */ + function getMeteorologyDataByStationId($valuetype,$label,$sid=0,$round=1) + { + if(empty($sid)) + { + $sql = "select station_id as sid from daily_meteorological_data group by station_id"; + + $sth = $this->dbh->prepare($sql); + $sth->execute(); + $stations = $sth->fetchAll(); + + $data = array(); + + foreach ($stations as $v) + { + $data[] = $this->createMeteorologyDataSet($v['sid'],$valuetype,$label,$round); + } + + return $data; + } + + else + { + return $this->createMeteorologyDataSet($sid,$valuetype,$label,$round=1); + } + + + }//getMeteorologyDataByStationId 获得气象数据变量值 + + + + + + + + + /********************************************************** + + 水文数据 + + ***********************************************************/ + + + /* + * getHydrologyValueByStation 按站点查询变量 + * + * param int $sid 站点编号 + * param string $table 变量类型 + * + * return array + */ + function getHydrologyValueByStation($sid,$t) + { + + $field = array(); //查询字段 + $order = array(); + + if(is_array($t['time'])) + { + foreach ($t['time'] as $v) + { + $field[] = $v; + $order[] = $v.' ASC'; + } + }else{ + $field[] = $t['time']; + $order[] = $t['time'].' ASC'; + } + $t['field'] .= " as v"; + $field[] = $t['field']; + $field[] = $t['sf']; + + $field = join(",",$field); //拼接 + $order = join(',',$order); + + + $sql = "select $field from {$t['table']} where {$t['sf']}='$sid' ORDER BY $order"; + + $sth = $this->dbh->prepare($sql); + $sth->execute(); + $temp = $sth->fetchAll(); + + $dataSet = array(); + + foreach ($temp as $k=>$v) + { + $time = 0; + if(!empty($v['dt'])) + { + $time = strtotime($v['dt']); + } + if(!empty($v['yr']) && !empty($v['mth'])) + { + $time = strtotime($v['yr'].'-'.$v['mth'].'-'.'01 00:00:00'); + } + if(!empty($v['yr']) && empty($v['mth'])) + { + $time = strtotime($v['yr'].'-01-01 00:00:00'); + } + $dataSet[] = array($time*1000,$v['v']); + } + unset($temp); + + return $dataSet; + + }// getHydrologyValueByStation 按站点查询变量 + + + + /* + * createHydrologyDataSet 创建水文数据 + * + * param int $sid 站点编号 + * param string $valuetype 变量类型 + * param string $label 单位 + * param int $round 数值精确度,小数点后位数 + * + * return array + */ + function createHydrologyDataSet($sid,$valuetype,$label,$round){ + + if(empty($label)) + { + $label=''; + } + + $varTable = array( + "dp"=>array( + "table"=>"hy_dp_c", //表名 + "field"=>"p", //值字段 + "sf"=>"stcd", //站点id字段 + "time"=>array("dt") //时间字段,数组 + ), //日降水量 + "mtp"=>array( + "table"=>"hy_mtp_e", + "field"=>"p", + "sf"=>"stcd", + "time"=>array('yr','mth') + ), //月降水量 + "yrp"=>array( + "table"=>"hy_yrp_f", + "field"=>"p", + "sf"=>"stcd", + "time"=>array("yr") + ), //年降水量 + "dq"=>array( + "table"=>"hy_dq_c", + "field"=>"avq", + "sf"=>"stcd", + "time"=>array("dt") + ), //日平均流量 + "mtq"=>array( + "table"=>"hy_mtq_e", + "field"=>"avq", + "sf"=>"stcd", + "time"=>array('yr','mth') + ), //月平均流量 + "yrq"=>array( + "table"=>"hy_yrq_f", + "field"=>"avq", + "sf"=>"stcd", + "time"=>array('yr') + ) //年平均流量 + );//$varTable + + $data = array( + "name"=>"站点:$sid", + "data"=>$this->getHydrologyValueByStation($sid,$varTable[$valuetype]), + "tooltip"=>array( + "valueDecimals"=> $round, + "valueSuffix"=> $label + ) + ); + + return $data; + + }//createHydrologyDataSet 创建水文数据 + + + /* + * getHydrologyDataByStationId 获得水文数据变量值 + * + * param string $valuetype 变量类型 + * param string $label 单位 + * param int $sid 站点编号,默认为空,空值将列出所有站点变量值 + * param int $round 数值精确度,小数点后位数 + * + * return array + */ + function getHydrologyDataByStationId($valuetype,$label,$sid=0,$round=1){ + + if(empty($sid)) + { + //降水 + $p = array('dp','mtp','yrp'); + $q = array('dq','mtq','yrq'); + if(in_array($valuetype,$p)) + { + $sql = "select stcd from hy_dp_c group by stcd"; + } + if(in_array($valuetype,$q)) + { + $sql = "select stcd from hy_dq_c group by stcd"; + } + + $sth = $this->dbh->prepare($sql); + $sth->execute(); + $stations = $sth->fetchAll(); + + $data = array(); + + foreach ($stations as $v) + { + $data[] = $this->createHydrologyDataSet($v['stcd'],$valuetype,$label,$round); + } + + return $data; + + }//所有站点 + + + if(is_array($sid)) + { + foreach($sid as $v) + { + + } + }//多个指定站点 + + + else + { + + }//单个站点 + + } + //getHydrologyDataByStationId() 获得水文数据变量值 + + + /**************************** + + 环境监测数据 + + *****************************/ + + /* + * createAmbientDataSet 创建环境监测数据 + * + * param int $sid 站点编号、名称 + * param string $valuetype 变量类型 + * param string $label 单位 + * param int $round 数值精确度,小数点后位数 + * + * return array + */ + function createAmbientDataSet($sid,$valuetype,$label,$round=4){ + + if(empty($label)) + { + $label=''; + } + + $data = array( + "name"=>"站点:$sid", + "data"=>$this->getAmbientValueByStation($sid,$valuetype), + "tooltip"=>array( + "valueDecimals"=> $round, + "valueSuffix"=> $label + ) + ); + + return $data; + + }//createAmbientDataSet 创建环境监测数据的数据 + + /* + * getAmbientValueByStation 按站点查询变量 + * + * param int $sid 站点编号 + * param string $table 变量类型 + * + * return array + */ + function getAmbientValueByStation($sid,$t) + { + + $field = array(); //查询字段 + + $field[] = 'id'; + $field[] = '"position"'; + $field[] = 'dt'; + $field[] = $t.' as v'; + + $field = join(",",$field); //拼接 + + + $sql = "select $field from ambient_air where \"position\"='$sid' ORDER BY dt ASC"; + + $sth = $this->dbh->prepare($sql); + $sth->execute(); + $temp = $sth->fetchAll(); + + $dataSet = array(); + + foreach ($temp as $k=>$v) + { + $time = 0; + if(!empty($v['dt'])) + { + $time = strtotime($v['dt']); + } + if(!empty($v['yr']) && !empty($v['mth'])) + { + $time = strtotime($v['yr'].'-'.$v['mth'].'-'.'01 00:00:00'); + } + if(!empty($v['yr']) && empty($v['mth'])) + { + $time = strtotime($v['yr'].'-01-01 00:00:00'); + } + $dataSet[] = array($time*1000,$v['v']); + } + unset($temp); + + return $dataSet; + + }// getAmbientValueByStation 按站点查询变量 + + /* + * getAmbientDataByStationId 获得环境监测数据变量 + * + * param string $valuetype 变量类型 + * param string $label 单位 + * param int $sid 站点编号,默认为空,空值将列出所有站点变量值 + * param int $round 数值精确度,小数点后位数 + * + * return array + */ + function getAmbientDataByStationId($valuetype,$label,$sid=0,$round=4){ + + if(empty($sid)) + { + //降水 + $p = array('tsp','pm10','so2','no2'); + + if(in_array($valuetype,$p)) + { + $sql = "select \"position\" from ambient_air group by \"position\""; + } + + $sth = $this->dbh->prepare($sql); + $sth->execute(); + $stations = $sth->fetchAll(); + + $data = array(); + + foreach ($stations as $v) + { + $data[] = $this->createAmbientDataSet($v['position'],$valuetype,$label,$round); + } + + return $data; + + }//所有站点 + + + if(is_array($sid)) + { + + }//多个指定站点 + + + else + { + + }//单个站点 + + } + //getAmbientDataByStationId() 获得环境监测数据变量的值 + + + + + //******************************************************** + + /* + * dataAction() ajax获取数据 + * + * param string $ac //请求的数据类型 + * param string $dt //请求的数据来源(气象,水文) + * + * return view + */ + function dataAction() + { + + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $ac = $this->_request->getParam('ac'); + $base = $this->_request->getParam('dt'); + + if(!in_array($base,array('meteorology','hydrology','ambient'))) + { + $data = array( + "error"=>"参数错误" + ); + + $this->jsonexit($data); + return true; + } + + $datas = array(); + $label = ""; + $title = ""; + $range = 0; + $type = "line"; + + if($base == "meteorology") + { + if($ac=='temperature') + { + + $title = "日平均温度"; + $label = "℃"; + $type = "line"; + + $datas = $this->getMeteorologyDataByStationId($ac,$label); + + }//日平均温度 + + if($ac == 'windspeed') + { + + $title = "日平均风速"; + $label = "m/s"; + $type = "line"; + + $datas = $this->getMeteorologyDataByStationId($ac,$label); + + }//日平均风速 m/s + + if($ac == 'precipitation') + { + + $title = "日合计降水量"; + $label = "mm"; + $type = "line"; + + $datas = $this->getMeteorologyDataByStationId($ac,$label); + + }//日合计降水量 mm + + if($ac == 'sunshine') + { + + $title = "日照小时数"; + $label = "h"; + $type = "line"; + + $datas = $this->getMeteorologyDataByStationId($ac,$label); + + }//日照小时数 h + + }//气象数据 + + + if($base == 'hydrology') + { + if($ac == 'dp') + { + $title = "日降水量"; + $label = "mm"; + $type = "line"; + + $datas = $this->getHydrologyDataByStationId($ac,$label); + + }//日降水量 + + if($ac == 'mtp') + { + $title = "月均降水"; + $label = "mm"; + $type = "line"; + + $datas = $this->getHydrologyDataByStationId($ac,$label); + }//月均降水 + + if($ac == 'yrp') + { + $title = "年均降水"; + $label = "mm"; + $type = "line"; + + $datas = $this->getHydrologyDataByStationId($ac,$label); + }//年均降水 + + if($ac == 'dq') + { + $title = "日均流量"; + $label = "mm"; + $type = "line"; + + $datas = $this->getHydrologyDataByStationId($ac,$label); + } + + if($ac == 'mtq') + { + $title = "月均流量"; + $label = "mm"; + $type = "line"; + + $datas = $this->getHydrologyDataByStationId($ac,$label); + } + + if($ac == 'yrq') + { + $title = "年均流量"; + $label = "mm"; + $type = "line"; + + $datas = $this->getHydrologyDataByStationId($ac,$label); + } + + + }//水文数据 + + + if($base=="ambient") + { + if($ac=='tsp') + { + $title = "总悬浮颗粒物"; + $label=""; + $type = "column"; + $range = 6; + $datas = $this->getAmbientDataByStationId($ac,$label); + } + + if($ac=='pm10') + { + $title = "可吸入颗粒物"; + $label=""; + $type = "column"; + $range = 6; + $datas = $this->getAmbientDataByStationId($ac,$label); + } + + if($ac=='so2') + { + $title = "二氧化硫"; + $label=""; + $type = "column"; + $range = 6; + $datas = $this->getAmbientDataByStationId($ac,$label); + } + + if($ac=='no2') + { + $title = "二氧化氮"; + $label=""; + $type = "column"; + $range = 6; + $datas = $this->getAmbientDataByStationId($ac,$label); + } + }//环境监测数据 + + if(empty($range)) + { + $range = 0; + } + + $data = array( + "label"=>$label, + "title"=>$title, + "type"=>$type, + "range"=>$range, + "datas"=>$datas + ); + + $this->jsonexit($data); + return true; + + }//dataAction() Ajax获取数据 + + + + + + function utcMsTime($time=''){ + if(empty($time)) + return (time()+8*3600)*1000; + else + return $time*1000; + } + + /* + * jsonexit() 退出并返回json数据 + * + * param array $data 要返回的JSON数据,可以是任意数组 + * + * return application/JSON + */ + public function jsonexit($data){ + $this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(json_encode($data,JSON_NUMERIC_CHECK)); + return true; + }//jsonexit() 退出并返回json数据 + +} + + +/* + 数据模型 + "data"=>array( + + //第一条曲线 + "data1"=>array( + "title"=>"5米风速", + "unit"=>"m/s", + "sensor"=>"传感器XXX", + "sensor_type"=>"传感器类型", + "datas"=>array( + array($this->utcMsTime(),26.0), + array($this->utcMsTime()+3600*1000,28.1), + array($this->utcMsTime()+7200*1000,30.9), + array($this->utcMsTime()+10800*1000,32.0), + array($this->utcMsTime()+12800*1000,28.0), + array($this->utcMsTime()+13800*1000,22.0) + ) + ), + + + //第二条曲线 + "data2"=>array( + "title"=>"10米风速", + "unit"=>"m/s", + "sensor"=>"传感器XXX", + "sensor_type"=>"传感器类型", + "datas"=>array( + array($this->utcMsTime(),26.0), + array($this->utcMsTime()+5600*1000,22.1), + array($this->utcMsTime()+8200*1000,35.9), + array($this->utcMsTime()+11800*1000,32.0), + array($this->utcMsTime()+13900*1000,22.0), + array($this->utcMsTime()+16800*1000,21.0) + ) + ), + + //第三条....... + ) + + */ + diff --git a/application/default/views/scripts/visual/data.phtml b/application/default/views/scripts/visual/data.phtml new file mode 100644 index 00000000..5bf9f199 --- /dev/null +++ b/application/default/views/scripts/visual/data.phtml @@ -0,0 +1,174 @@ +headTitle($this->config->title->site); +$this->headTitle($this->config->title->author); +$this->headTitle()->setSeparator(' - '); +$this->headScript()->appendFile('/js/jquery.colorbox-min.js'); +$this->headLink()->appendStylesheet('/css/colorbox.css'); +$this->headScript()->appendFile('/static/js/highcharts/highcharts.js'); +$this->headScript()->appendFile('/static/js/highcharts/modules/exporting.js'); +$this->breadcrumb('首页'); +$this->breadcrumb('数据可视化'); +$this->breadcrumb()->setSeparator(' > '); +?> + + + + + +
      +
      +
      + +
      + + \ No newline at end of file diff --git a/application/default/views/scripts/visual/index.phtml b/application/default/views/scripts/visual/index.phtml new file mode 100644 index 00000000..d4ddb661 --- /dev/null +++ b/application/default/views/scripts/visual/index.phtml @@ -0,0 +1,162 @@ +headTitle($this->config->title->site); +$this->headTitle($this->config->title->data); +$this->headTitle()->setSeparator(' - '); +$theme = new Theme; +$theme->appendPlus($this,'highstock'); +$this->breadcrumb('首页'); +$this->breadcrumb('数据与服务'); +$this->breadcrumb('数据可视化'); +$this->breadcrumb()->setSeparator(' > '); +?> + + +
      + +
      +
      + +
      + + \ No newline at end of file diff --git a/application/models/Theme.php b/application/models/Theme.php index 244a75bc..50324775 100644 --- a/application/models/Theme.php +++ b/application/models/Theme.php @@ -1,188 +1,194 @@ -_init_plus(); - } - - //初始化插件 - function _init_plus() - { - $this->plus = array( - - /**********Jquery公共库******/ - - //Jquery - 'jquery'=>array( - $this->ScriptKey => array( - '/js/lib/jquery.lasted.js' - ) - ), - - //Jquery UI - 'jquery_ui'=>array( - $this->ScriptKey => array( - '/js/lib/jquery.lasted.js', - '/js/lib/jquery.ui/jquery-ui.lasted.js' - ), - $this->CSSKey =>array( - '/js/lib/jquery.ui/jquery-ui.lasted.css' - ) - ), - - /********* Bootstrap ******/ - 'bootstrap'=>array( - $this->ScriptKey => array( - '/js/lib/bootstrap/js/bootstrap.min.js', - ), - $this->CSSKey =>array( - '/js/lib/bootstrap/css/bootstrap.min.css', - '/js/lib/bootstrap/css/bootstrap-responsive.min.css' - ) - ), - - - /********Jquery 插件********/ - - //colorbox - 'colorbox' => array( - $this->ScriptKey => array( - '/js/lib/jquery.colorbox/jquery.colorbox-min.js' - ), - $this->CSSKey => array( - '/js/lib/jquery.colorbox/style2/colorbox.css' - ) - ), - - //inputbg - 'inputbg' => array( - $this->ScriptKey => array( - '/js/lib/custom/jquery.inputbg.js' - ) - ), - - //loadinglayer - 'loadinglayer' => array( - $this->ScriptKey => array( - '/js/lib/custom/jquery.loadinglayer.js' - ) - ), - - //admin_plugin - 'admin_plugin' => array( - $this->ScriptKey => array( - '/js/lib/custom/admin_plugin.js' - ) - ), - - 'jplayer' => array( - $this->ScriptKey => array( - '/js/lib/jplayer/jquery.jplayer.min.js' - ) - ), - - //slides - 'slides' => array( - $this->ScriptKey => array( - '/js/lib/jquery.slides.min.js' - ) - ), - - 'datatable' => array( - $this->ScriptKey => array( - '/js/lib/jquery.datatable/jquery.dataTables.min.js' - ), - $this->CSSKey => array( - '/js/lib/jquery.datatable/datatable.css' - ) - ), - - 'masonry' => array( - $this->ScriptKey => array( - '/js/lib/jquery.masonry.min.js' - ), - ), - - 'uploadify' => array( - $this->ScriptKey => array( - '/js/lib/uploadify/jquery.uploadify.min.js' - ), - $this->CSSKey => array( - '/js/lib/uploadify/uploadify.css' - ), - ), - - 'datepicker' => array( - $this->ScriptKey => array( - '/js/lib/datepicker/jquery-ui-1.10.3.custom.min.js' - ), - $this->CSSKey => array( - '/js/lib/datepicker/jquery-ui-1.10.3.custom.min.css' - ) - ), - - /*********谷歌地图*********/ - - //Google Map API v3 - 'google_map_v3'=>array( - $this->ScriptKey => array( - 'http://maps.google.com/maps/api/js?sensor=false&language=zh-cn' - ) - ), - - //Google Map API v3 - KeyDragZone - 'google_map_keydragzone' => array( - $this->ScriptKey => array( - '/js/lib/google-map/keydragzoom.js' - ) - ), - - );//插件列表 - - }// _init_plus() - - //前台添加插件 - function AppendPlus($render,$plus_name){ - - $plus_name = strtolower($plus_name); - - $plusing = $this->plus; - - if(!empty($plusing[$plus_name][$this->ScriptKey])) - { - foreach($plusing[$plus_name][$this->ScriptKey] as $k=>$v) - { - $render->headScript()->appendFile($v); - } - } - - if(!empty($plusing[$plus_name][$this->CSSKey])) - { - foreach($plusing[$plus_name][$this->CSSKey] as $k=>$v) - { - $render->headLink()->appendStylesheet($v); - } - } - - }// AppendPlus - - //加载页面中的JS - function AppendModel($render,$model) - { - - $model = trim($model); - - $render->headScript()->appendFile("/js/lib/custom/models/".$model.".js"); - - }// -} +_init_plus(); + } + + //初始化插件 + function _init_plus() + { + $this->plus = array( + + /**********Jquery公共库******/ + + //Jquery + 'jquery'=>array( + $this->ScriptKey => array( + '/js/lib/jquery.lasted.js' + ) + ), + + //Jquery UI + 'jquery_ui'=>array( + $this->ScriptKey => array( + '/js/lib/jquery.lasted.js', + '/js/lib/jquery.ui/jquery-ui.lasted.js' + ), + $this->CSSKey =>array( + '/js/lib/jquery.ui/jquery-ui.lasted.css' + ) + ), + + /********* Bootstrap ******/ + 'bootstrap'=>array( + $this->ScriptKey => array( + '/js/lib/bootstrap/js/bootstrap.min.js', + ), + $this->CSSKey =>array( + '/js/lib/bootstrap/css/bootstrap.min.css', + '/js/lib/bootstrap/css/bootstrap-responsive.min.css' + ) + ), + + + /********Jquery 插件********/ + + //colorbox + 'colorbox' => array( + $this->ScriptKey => array( + '/js/lib/jquery.colorbox/jquery.colorbox-min.js' + ), + $this->CSSKey => array( + '/js/lib/jquery.colorbox/style2/colorbox.css' + ) + ), + + //inputbg + 'inputbg' => array( + $this->ScriptKey => array( + '/js/lib/custom/jquery.inputbg.js' + ) + ), + + //loadinglayer + 'loadinglayer' => array( + $this->ScriptKey => array( + '/js/lib/custom/jquery.loadinglayer.js' + ) + ), + + //admin_plugin + 'admin_plugin' => array( + $this->ScriptKey => array( + '/js/lib/custom/admin_plugin.js' + ) + ), + + 'jplayer' => array( + $this->ScriptKey => array( + '/js/lib/jplayer/jquery.jplayer.min.js' + ) + ), + + //slides + 'slides' => array( + $this->ScriptKey => array( + '/js/lib/jquery.slides.min.js' + ) + ), + + 'datatable' => array( + $this->ScriptKey => array( + '/js/lib/jquery.datatable/jquery.dataTables.min.js' + ), + $this->CSSKey => array( + '/js/lib/jquery.datatable/datatable.css' + ) + ), + + 'masonry' => array( + $this->ScriptKey => array( + '/js/lib/jquery.masonry.min.js' + ), + ), + + 'uploadify' => array( + $this->ScriptKey => array( + '/js/lib/uploadify/jquery.uploadify.min.js' + ), + $this->CSSKey => array( + '/js/lib/uploadify/uploadify.css' + ), + ), + + 'datepicker' => array( + $this->ScriptKey => array( + '/js/lib/datepicker/jquery-ui-1.10.3.custom.min.js' + ), + $this->CSSKey => array( + '/js/lib/datepicker/jquery-ui-1.10.3.custom.min.css' + ) + ), + + 'highstock' => array( + $this->ScriptKey => array( + '/js/lib/highstock/highstock.js' + ) + ), + + /*********谷歌地图*********/ + + //Google Map API v3 + 'google_map_v3'=>array( + $this->ScriptKey => array( + 'http://maps.google.com/maps/api/js?sensor=false&language=zh-cn' + ) + ), + + //Google Map API v3 - KeyDragZone + 'google_map_keydragzone' => array( + $this->ScriptKey => array( + '/js/lib/google-map/keydragzoom.js' + ) + ), + + );//插件列表 + + }// _init_plus() + + //前台添加插件 + function AppendPlus($render,$plus_name){ + + $plus_name = strtolower($plus_name); + + $plusing = $this->plus; + + if(!empty($plusing[$plus_name][$this->ScriptKey])) + { + foreach($plusing[$plus_name][$this->ScriptKey] as $k=>$v) + { + $render->headScript()->appendFile($v); + } + } + + if(!empty($plusing[$plus_name][$this->CSSKey])) + { + foreach($plusing[$plus_name][$this->CSSKey] as $k=>$v) + { + $render->headLink()->appendStylesheet($v); + } + } + + }// AppendPlus + + //加载页面中的JS + function AppendModel($render,$model) + { + + $model = trim($model); + + $render->headScript()->appendFile("/js/lib/custom/models/".$model.".js"); + + }// +} diff --git a/htdocs/js/lib/highstock/adapters/standalone-framework.js b/htdocs/js/lib/highstock/adapters/standalone-framework.js new file mode 100644 index 00000000..8545f8a8 --- /dev/null +++ b/htdocs/js/lib/highstock/adapters/standalone-framework.js @@ -0,0 +1,18 @@ +/* + Highstock JS v2.0.1 (2014-04-24) + + Standalone Highcharts Framework + + License: MIT License +*/ +var HighchartsAdapter=function(){function o(c){function b(b,a,d){b.removeEventListener(a,d,!1)}function d(b,a,d){d=b.HCProxiedMethods[d.toString()];b.detachEvent("on"+a,d)}function a(a,c){var f=a.HCEvents,i,g,k,j;if(a.removeEventListener)i=b;else if(a.attachEvent)i=d;else return;c?(g={},g[c]=!0):g=f;for(j in g)if(f[j])for(k=f[j].length;k--;)i(a,j,f[j][k])}c.HCExtended||Highcharts.extend(c,{HCExtended:!0,HCEvents:{},bind:function(b,a){var d=this,c=this.HCEvents,g;if(d.addEventListener)d.addEventListener(b, +a,!1);else if(d.attachEvent){g=function(b){b.target=b.srcElement||window;a.call(d,b)};if(!d.HCProxiedMethods)d.HCProxiedMethods={};d.HCProxiedMethods[a.toString()]=g;d.attachEvent("on"+b,g)}c[b]===r&&(c[b]=[]);c[b].push(a)},unbind:function(c,h){var f,i;c?(f=this.HCEvents[c]||[],h?(i=HighchartsAdapter.inArray(h,f),i>-1&&(f.splice(i,1),this.HCEvents[c]=f),this.removeEventListener?b(this,c,h):this.attachEvent&&d(this,c,h)):(a(this,c),this.HCEvents[c]=[])):(a(this),this.HCEvents={})},trigger:function(b, +a){var d=this.HCEvents[b]||[],c=d.length,g,k,j;k=function(){a.defaultPrevented=!0};for(g=0;g=a.duration+this.startTime){this.now=this.end; +this.pos=this.state=1;this.update();b=this.options.curAnim[this.prop]=!0;for(h in a.curAnim)a.curAnim[h]!==!0&&(b=!1);b&&a.complete&&a.complete.call(e);a=!1}else e=c-this.startTime,this.state=e/a.duration,this.pos=a.easing(e,0,1,a.duration),this.now=this.start+(this.end-this.start)*this.pos,this.update(),a=!0;return a}};this.animate=function(b,d,a){var e,h="",f,i,g;b.stopAnimation=!1;if(typeof a!=="object"||a===null)e=arguments,a={duration:e[2],easing:e[3],complete:e[4]};if(typeof a.duration!=="number")a.duration= +400;a.easing=Math[a.easing]||Math.easeInOutSine;a.curAnim=Highcharts.extend({},d);for(g in d)i=new n(b,a,g),f=null,g==="d"?(i.paths=c.init(b,b.d,d.d),i.toD=d.d,e=0,f=1):b.attr?e=b.attr(g):(e=parseFloat(HighchartsAdapter._getStyle(b,g))||0,g!=="opacity"&&(h="px")),f||(f=parseFloat(d[g])),i.custom(e,f,h)}},_getStyle:function(c,b){return window.getComputedStyle(c,void 0).getPropertyValue(b)},getScript:function(c,b){var d=l.getElementsByTagName("head")[0],a=l.createElement("script");a.type="text/javascript"; +a.src=c;a.onload=b;d.appendChild(a)},inArray:function(c,b){return b.indexOf?b.indexOf(c):p.indexOf.call(b,c)},adapterRun:function(c,b){return parseInt(HighchartsAdapter._getStyle(c,b),10)},grep:function(c,b){return p.filter.call(c,b)},map:function(c,b){for(var d=[],a=0,e=c.length;af&&c-f>m/2+1.0E-4?(j=j.concat(z(e,a,b,d,f,f+m/2,h,i)),j=j.concat(z(e,a,b,d,f+m/2,c,h,i))):cm/2+1.0E-4?(j=j.concat(z(e,a,b, +d,f,f-m/2,h,i)),j=j.concat(z(e,a,b,d,f-m/2,c,h,i))):(j=c-f,["C",e+b*l(f)-b*D*j*k(f)+h,a+d*k(f)+d*D*j*l(f)+i,e+b*l(c)+b*D*j*k(c)+h,a+d*k(c)-d*D*j*l(c)+i,e+b*l(c)+h,a+d*k(c)+i])}function F(e){if(this.chart.is3d()){var a=this.chart.options.plotOptions.column.grouping;a!==void 0&&!a&&this.group.zIndex!==void 0&&this.group.attr({zIndex:this.group.zIndex*10});if(this.userOptions.borderColor===void 0)this.options.borderColor=this.color;c.each(this.data,function(a){var d=a.options.borderColor||a.color||a.series.userOptions.borderColor; +a.options.borderColor=d;a.borderColor=d;a.pointAttr[""].stroke=d;a.pointAttr.hover.stroke=d;a.pointAttr.select.stroke=d})}e.apply(this,[].slice.call(arguments,1))}var m=Math.PI,n=m/180,k=Math.sin,l=Math.cos,C=Math.round,D=4*(Math.sqrt(2)-1)/3/(m/2);c.SVGRenderer.prototype.toLinePath=function(e,a){var b=[];c.each(e,function(a){b.push("L",a.x,a.y)});b[0]="M";a&&b.push("Z");return b};c.SVGRenderer.prototype.cuboid=function(e){var a=this.g(),e=this.cuboidPath(e);a.front=this.path(e[0]).attr({zIndex:e[3], +"stroke-linejoin":"round"}).add(a);a.top=this.path(e[1]).attr({zIndex:e[4],"stroke-linejoin":"round"}).add(a);a.side=this.path(e[2]).attr({zIndex:e[5],"stroke-linejoin":"round"}).add(a);a.fillSetter=function(a){var d=c.Color(a).brighten(0.1).get(),e=c.Color(a).brighten(-0.1).get();this.front.attr({fill:a});this.top.attr({fill:d});this.side.attr({fill:e});this.color=a;return this};a.opacitySetter=function(a){this.front.attr({opacity:a});this.top.attr({opacity:a});this.side.attr({opacity:a});return this}; +a.attr=function(a){a.shapeArgs||a.x?(a=this.renderer.cuboidPath(a.shapeArgs||a),this.front.attr({d:a[0],zIndex:a[3]}),this.top.attr({d:a[1],zIndex:a[4]}),this.side.attr({d:a[2],zIndex:a[5]})):c.SVGElement.prototype.attr.call(this,a);return this};a.animate=function(a,d,e){a.x&&a.y?(a=this.renderer.cuboidPath(a),this.front.attr({zIndex:a[3]}).animate({d:a[0]},d,e),this.top.attr({zIndex:a[4]}).animate({d:a[1]},d,e),this.side.attr({zIndex:a[5]}).animate({d:a[2]},d,e)):a.opacity?(this.front.animate(a, +d,e),this.top.animate(a,d,e),this.side.animate(a,d,e)):c.SVGElement.prototype.animate.call(this,a,d,e);return this};a.destroy=function(){this.front.destroy();this.top.destroy();this.side.destroy();return null};a.attr({zIndex:-e[3]});return a};c.SVGRenderer.prototype.cuboidPath=function(e){var a=e.x,b=e.y,d=e.z,c=e.height,g=e.width,h=e.depth,i=e.alpha,j=e.beta,a=[{x:a,y:b,z:d},{x:a+g,y:b,z:d},{x:a+g,y:b+c,z:d},{x:a,y:b+c,z:d},{x:a,y:b+c,z:d+h},{x:a+g,y:b+c,z:d+h},{x:a+g,y:b,z:d+h},{x:a,y:b,z:d+h}], +a=x(a,i,j,e.origin),e=["M",a[0].x,a[0].y,"L",a[7].x,a[7].y,"L",a[6].x,a[6].y,"L",a[1].x,a[1].y,"Z"],b=["M",a[3].x,a[3].y,"L",a[2].x,a[2].y,"L",a[5].x,a[5].y,"L",a[4].x,a[4].y,"Z"],d=["M",a[1].x,a[1].y,"L",a[2].x,a[2].y,"L",a[5].x,a[5].y,"L",a[6].x,a[6].y,"Z"],c=["M",a[0].x,a[0].y,"L",a[7].x,a[7].y,"L",a[4].x,a[4].y,"L",a[3].x,a[3].y,"Z"];return[["M",a[0].x,a[0].y,"L",a[1].x,a[1].y,"L",a[2].x,a[2].y,"L",a[3].x,a[3].y,"Z"],a[7].ya[2].y?b:[],a[6].x>a[1].x?d:a[7].x0?(a[0].z+a[7].z+a[6].z+a[1].z)/4:(a[3].z+a[2].z+a[5].z+a[4].z)/4,i>0?(a[1].z+a[2].z+a[5].z+a[6].z)/4:(a[0].z+a[7].z+a[4].z+a[3].z)/4]};c.SVGRenderer.prototype.arc3d=function(e){e.alpha*=n;e.beta*=n;var a=this.g(),b=this.arc3dPath(e),d=a.renderer,f=b.zAll*100;a.shapeArgs=e;a.side1=d.path(b.side2).attr({zIndex:b.zSide2}).add(a);a.side2=d.path(b.side1).attr({zIndex:b.zSide1}).add(a);a.inn=d.path(b.inn).attr({zIndex:b.zInn}).add(a);a.out=d.path(b.out).attr({zIndex:b.zOut}).add(a); +a.top=d.path(b.top).attr({zIndex:b.zTop}).add(a);a.fillSetter=function(a){this.color=a;var b=c.Color(a).brighten(-0.1).get();this.side1.attr({fill:b});this.side2.attr({fill:b});this.inn.attr({fill:b});this.out.attr({fill:b});this.top.attr({fill:a});return this};a.animate=function(a,b,d){c.SVGElement.prototype.animate.call(this,a,b,d);if(a.x&&a.y)b=this.renderer,a=c.splat(a)[0],a.alpha*=n,a.beta*=n,b=b.arc3dPath(a),this.shapeArgs=a,this.inn.attr({d:b.inn,zIndex:b.zInn}),this.out.attr({d:b.out,zIndex:b.zOut}), +this.side1.attr({d:b.side1,zIndex:b.zSide2}),this.side2.attr({d:b.side2,zIndex:b.zSide1}),this.top.attr({d:b.top,zIndex:b.zTop}),this.attr({fill:this.color}),this.attr({zIndex:b.zAll*100});return this};a.zIndex=f;a.attr({zIndex:f});return a};c.SVGRenderer.prototype.arc3dPath=function(e){var a=e.x,b=e.y,d=e.start,c=e.end-1.0E-5,g=e.r,h=e.innerR,i=e.depth,j=e.alpha,o=e.beta,t=l(d),y=k(d),v=l(c),n=k(c),q=g*l(o),r=g*l(j),u=h*l(o),s=h*l(j),A=i*k(o),B=i*k(j),i=["M",a+q*t,b+r*y],i=i.concat(z(a,b,q,r,d,c, +0,0)),i=i.concat(["L",a+u*v,b+s*n]),i=i.concat(z(a,b,u,s,c,d,0,0)),i=i.concat(["Z"]),e=(e.start+e.end)/2,e=k(o)*l(e)+k(-j)*k(-e),p=o>0?m/2:0,w=j>0?0:m/2,p=d>-p?d:c>-p?-p:d,x=c0?4:-1}).css({stroke:i.color}).add(); +else{var q={x:m,y:n,z:o+1,width:l,height:k+i.size,depth:j.size,alpha:f,beta:g,origin:d};this.backFrame?this.backFrame.animate(q):this.backFrame=b.cuboid(q).attr({fill:j.color,zIndex:-3}).css({stroke:j.color}).add();this.axisLine&&this.axisLine.hide();a={x:(a.yAxis[0].opposite?l:0)+m-h.size,y:n,z:0,width:h.size,height:k+i.size,depth:o+j.size,alpha:f,beta:g,origin:d};this.sideFrame?this.sideFrame.animate(a):this.sideFrame=b.cuboid(a).attr({fill:h.color,zIndex:-2}).css({stroke:h.color}).add()}}});c.wrap(c.Axis.prototype, +"getPlotLinePath",function(c){var a=c.apply(this,[].slice.call(arguments,1));if(!this.chart.is3d())return a;if(a===null)return a;var b=this.chart,d=b.options.chart.options3d,f=d.depth;d.origin={x:b.plotLeft+b.plotWidth/2,y:b.plotTop+b.plotHeight/2,z:f,vd:d.viewDistance};var a=[{x:a[1],y:a[2],z:this.horiz||this.opposite?f:0},{x:a[1],y:a[2],z:f},{x:a[4],y:a[5],z:f},{x:a[4],y:a[5],z:this.horiz||this.opposite?0:f}],f=b.options.inverted?d.beta:d.alpha,g=b.options.inverted?d.alpha:d.beta;g*=b.yAxis[0].opposite? +-1:1;a=x(a,f,g,d.origin);return a=this.chart.renderer.toLinePath(a,!1)});c.wrap(c.Tick.prototype,"getMarkPath",function(c){var a=c.apply(this,[].slice.call(arguments,1));if(!this.axis.chart.is3d())return a;var b=this.axis.chart,d=b.options.chart.options3d,f={x:b.plotLeft+b.plotWidth/2,y:b.plotTop+b.plotHeight/2,z:d.depth,vd:d.viewDistance},a=[{x:a[1],y:a[2],z:0},{x:a[4],y:a[5],z:0}],g=b.inverted?d.beta:d.alpha,d=b.inverted?d.alpha:d.beta;d*=b.yAxis[0].opposite?-1:1;a=x(a,g,d,f);return a=["M",a[0].x, +a[0].y,"L",a[1].x,a[1].y]});c.wrap(c.Tick.prototype,"getLabelPosition",function(c){var a=c.apply(this,[].slice.call(arguments,1));if(!this.axis.chart.is3d())return a;var b=this.axis.chart,d=b.options.chart.options3d,f={x:b.plotLeft+b.plotWidth/2,y:b.plotTop+b.plotHeight/2,z:d.depth,vd:d.viewDistance},g=b.inverted?d.beta:d.alpha,d=b.inverted?d.alpha:d.beta;d*=b.yAxis[0].opposite?-1:1;return a=x([{x:a.x,y:a.y,z:0}],g,d,f)[0]});c.wrap(c.Axis.prototype,"drawCrosshair",function(c){var a=arguments;this.chart.is3d()&& +a[2]&&(a[2]={plotX:a[2].plotXold||a[2].plotX,plotY:a[2].plotYold||a[2].plotY});c.apply(this,[].slice.call(a,1))});c.wrap(c.seriesTypes.column.prototype,"translate",function(e){e.apply(this,[].slice.call(arguments,1));if(this.chart.is3d()){var a=this.chart,b=a.options,d=b.plotOptions[this.chart.options.chart.type],b=b.chart.options3d,f=d.depth||25,g={x:a.plotWidth/2,y:a.plotHeight/2,z:b.depth,vd:b.viewDistance},h=b.alpha,i=b.beta*(a.yAxis[0].opposite?-1:1),j=(d.stacking?this.options.stack||0:this._i)* +(f+(d.groupZPadding||1));d.grouping!==!1&&(j=0);j+=d.groupZPadding||1;c.each(this.data,function(a){var b=a.shapeArgs,c=a.tooltipPos;a.shapeType="cuboid";b.alpha=h;b.beta=i;b.z=j;b.origin=g;b.depth=f;c=x([{x:c[0],y:c[1],z:j}],h,i,g)[0];a.tooltipPos=[c.x,c.y]})}});c.wrap(c.seriesTypes.column.prototype,"animate",function(e){if(this.chart.is3d()){var a=arguments[1],b=this.yAxis,d=this,f=this.yAxis.reversed;if(c.svg)a?c.each(d.data,function(a){a.height=a.shapeArgs.height;a.shapeArgs.height=1;if(!f)a.shapeArgs.y= +a.stackY?a.plotY+b.translate(a.stackY):a.plotY+(a.negative?-a.height:a.height)}):(c.each(d.data,function(a){a.shapeArgs.height=a.height;if(!f)a.shapeArgs.y=a.plotY-(a.negative?a.height:0);a.graphic&&a.graphic.animate(a.shapeArgs,d.options.animation)}),d.animate=null)}else e.apply(this,[].slice.call(arguments,1))});c.wrap(c.seriesTypes.column.prototype,"init",function(c){c.apply(this,[].slice.call(arguments,1));if(this.chart.is3d()){var a=this.chart.options.plotOptions.column.grouping,b=this.chart.options.plotOptions.column.stacking, +d=this.options.zIndex;if(!d&&(a===void 0||a)&&b){a=this.chart.retrieveStacks();b=this.options.stack||0;for(d=0;d0?k(h)*e:0),-c*(1-l(g))*k(b)+(k(b)>0?k(g)*e:0));a.dataLabel&&a.dataLabel.attr({x:a.dataLabel.connX+-c*(1-l(h))*l(b)+(l(b)>0?l(h)*e:0)-a.dataLabel.width/2,y:a.dataLabel.connY+-c*(1-l(g))*k(b)+(k(b)>0?k(g)*e:0)-a.dataLabel.height/2})})});c.wrap(c.seriesTypes.pie.prototype,"addPoint",function(c){c.apply(this,[].slice.call(arguments,1));this.chart.is3d()&&this.update()});c.wrap(c.seriesTypes.pie.prototype,"animate",function(e){if(this.chart.is3d()){var a=arguments[1],b=this.options.animation,d= +this.center,f=this.group,g=this.markerGroup;if(c.svg)if(b===!0&&(b={}),a){if(this.oldtranslateX=f.translateX,this.oldtranslateY=f.translateY,a={translateX:d[0],translateY:d[1],scaleX:0.001,scaleY:0.001},f.attr(a),g)g.attrSetters=f.attrSetters,g.attr(a)}else a={translateX:this.oldtranslateX,translateY:this.oldtranslateY,scaleX:1,scaleY:1},f.animate(a,b),g&&g.animate(a,b),this.animate=null}else e.apply(this,[].slice.call(arguments,1))});c.wrap(c.seriesTypes.scatter.prototype,"translate",function(e){e.apply(this, +[].slice.call(arguments,1));if(this.chart.is3d()){var a=this.chart,b=this.chart.options.chart.options3d,d=b.alpha,f=b.beta,g={x:a.inverted?a.plotHeight/2:a.plotWidth/2,y:a.inverted?a.plotWidth/2:a.plotHeight/2,z:b.depth,vd:b.viewDistance},b=b.depth,h=a.options.zAxis||{min:0,max:b},i=b/(h.max-h.min);c.each(this.data,function(a){var b={x:a.plotX,y:a.plotY,z:(a.z-h.min)*i},b=x([b],d,f,g)[0];a.plotXold=a.plotX;a.plotYold=a.plotY;a.plotX=b.x;a.plotY=b.y;a.plotZ=b.z})}});c.wrap(c.seriesTypes.scatter.prototype, +"init",function(c){var a=c.apply(this,[].slice.call(arguments,1));if(this.chart.is3d())this.pointArrayMap=["x","y","z"],this.tooltipOptions.pointFormat=this.userOptions.tooltip?this.userOptions.tooltip.pointFormat||"x: {point.x}
      y: {point.y}
      z: {point.z}
      ":"x: {point.x}
      y: {point.y}
      z: {point.z}
      ";return a});if(c.VMLRenderer)c.setOptions({animate:!1}),c.VMLRenderer.prototype.cuboid=c.SVGRenderer.prototype.cuboid,c.VMLRenderer.prototype.cuboidPath= +c.SVGRenderer.prototype.cuboidPath,c.VMLRenderer.prototype.toLinePath=c.SVGRenderer.prototype.toLinePath,c.VMLRenderer.prototype.createElement3D=c.SVGRenderer.prototype.createElement3D,c.VMLRenderer.prototype.arc3d=function(e){e=c.SVGRenderer.prototype.arc3d.call(this,e);e.css({zIndex:e.zIndex});return e},c.VMLRenderer.prototype.arc3dPath=c.SVGRenderer.prototype.arc3dPath,c.Chart.prototype.renderSeries=function(){for(var c,a=this.series.length;a--;)c=this.series[a],c.translate(),c.setTooltipPoints&& +c.setTooltipPoints(),c.render()},c.wrap(c.Axis.prototype,"render",function(c){c.apply(this,[].slice.call(arguments,1));this.sideFrame&&(this.sideFrame.css({zIndex:0}),this.sideFrame.front.attr({fill:this.sideFrame.color}));this.bottomFrame&&(this.bottomFrame.css({zIndex:1}),this.bottomFrame.front.attr({fill:this.bottomFrame.color}));this.backFrame&&(this.backFrame.css({zIndex:0}),this.backFrame.front.attr({fill:this.backFrame.color}))})})(Highcharts); diff --git a/htdocs/js/lib/highstock/highcharts-more.js b/htdocs/js/lib/highstock/highcharts-more.js new file mode 100644 index 00000000..3cc51350 --- /dev/null +++ b/htdocs/js/lib/highstock/highcharts-more.js @@ -0,0 +1,51 @@ +/* + Highcharts JS v4.0.1 (2014-04-24) + + (c) 2009-2014 Torstein Honsi + + License: www.highcharts.com/license +*/ +(function(m,C){function K(a,b,c){this.init.call(this,a,b,c)}var O=m.arrayMin,P=m.arrayMax,s=m.each,F=m.extend,o=m.merge,Q=m.map,q=m.pick,x=m.pInt,p=m.getOptions().plotOptions,h=m.seriesTypes,u=m.extendClass,L=m.splat,r=m.wrap,M=m.Axis,y=m.Tick,H=m.Point,R=m.Pointer,S=m.CenteredSeriesMixin,z=m.TrackerMixin,t=m.Series,v=Math,D=v.round,A=v.floor,T=v.max,U=m.Color,w=function(){};F(K.prototype,{init:function(a,b,c){var d=this,e=d.defaultOptions;d.chart=b;if(b.angular)e.background={};d.options=a=o(e,a); +(a=a.background)&&s([].concat(L(a)).reverse(),function(a){var g=a.backgroundColor,a=o(d.defaultBackgroundOptions,a);if(g)a.backgroundColor=g;a.color=a.backgroundColor;c.options.plotBands.unshift(a)})},defaultOptions:{center:["50%","50%"],size:"85%",startAngle:0},defaultBackgroundOptions:{shape:"circle",borderWidth:1,borderColor:"silver",backgroundColor:{linearGradient:{x1:0,y1:0,x2:0,y2:1},stops:[[0,"#FFF"],[1,"#DDD"]]},from:Number.MIN_VALUE,innerRadius:0,to:Number.MAX_VALUE,outerRadius:"105%"}}); +var G=M.prototype,y=y.prototype,V={getOffset:w,redraw:function(){this.isDirty=!1},render:function(){this.isDirty=!1},setScale:w,setCategories:w,setTitle:w},N={isRadial:!0,defaultRadialGaugeOptions:{labels:{align:"center",x:0,y:null},minorGridLineWidth:0,minorTickInterval:"auto",minorTickLength:10,minorTickPosition:"inside",minorTickWidth:1,tickLength:10,tickPosition:"inside",tickWidth:2,title:{rotation:0},zIndex:2},defaultRadialXOptions:{gridLineWidth:1,labels:{align:null,distance:15,x:0,y:null}, +maxPadding:0,minPadding:0,showLastLabel:!1,tickLength:0},defaultRadialYOptions:{gridLineInterpolation:"circle",labels:{align:"right",x:-3,y:-2},showLastLabel:!1,title:{x:4,text:null,rotation:90}},setOptions:function(a){a=this.options=o(this.defaultOptions,this.defaultRadialOptions,a);if(!a.plotBands)a.plotBands=[]},getOffset:function(){G.getOffset.call(this);this.chart.axisOffset[this.side]=0;this.center=this.pane.center=S.getCenter.call(this.pane)},getLinePath:function(a,b){var c=this.center,b=q(b, +c[2]/2-this.offset);return this.chart.renderer.symbols.arc(this.left+c[0],this.top+c[1],b,b,{start:this.startAngleRad,end:this.endAngleRad,open:!0,innerR:0})},setAxisTranslation:function(){G.setAxisTranslation.call(this);if(this.center)this.transA=this.isCircular?(this.endAngleRad-this.startAngleRad)/(this.max-this.min||1):this.center[2]/2/(this.max-this.min||1),this.minPixelPadding=this.isXAxis?this.transA*this.minPointOffset:0},beforeSetTickPositions:function(){this.autoConnect&&(this.max+=this.categories&& +1||this.pointRange||this.closestPointRange||0)},setAxisSize:function(){G.setAxisSize.call(this);if(this.isRadial){this.center=this.pane.center=m.CenteredSeriesMixin.getCenter.call(this.pane);if(this.isCircular)this.sector=this.endAngleRad-this.startAngleRad;this.len=this.width=this.height=this.center[2]*q(this.sector,1)/2}},getPosition:function(a,b){return this.postTranslate(this.isCircular?this.translate(a):0,q(this.isCircular?b:this.translate(a),this.center[2]/2)-this.offset)},postTranslate:function(a, +b){var c=this.chart,d=this.center,a=this.startAngleRad+a;return{x:c.plotLeft+d[0]+Math.cos(a)*b,y:c.plotTop+d[1]+Math.sin(a)*b}},getPlotBandPath:function(a,b,c){var d=this.center,e=this.startAngleRad,f=d[2]/2,g=[q(c.outerRadius,"100%"),c.innerRadius,q(c.thickness,10)],k=/%$/,l,n=this.isCircular;this.options.gridLineInterpolation==="polygon"?d=this.getPlotLinePath(a).concat(this.getPlotLinePath(b,!0)):(n||(g[0]=this.translate(a),g[1]=this.translate(b)),g=Q(g,function(a){k.test(a)&&(a=x(a,10)*f/100); +return a}),c.shape==="circle"||!n?(a=-Math.PI/2,b=Math.PI*1.5,l=!0):(a=e+this.translate(a),b=e+this.translate(b)),d=this.chart.renderer.symbols.arc(this.left+d[0],this.top+d[1],g[0],g[0],{start:a,end:b,innerR:q(g[1],g[0]-g[2]),open:l}));return d},getPlotLinePath:function(a,b){var c=this,d=c.center,e=c.chart,f=c.getPosition(a),g,k,l;c.isCircular?l=["M",d[0]+e.plotLeft,d[1]+e.plotTop,"L",f.x,f.y]:c.options.gridLineInterpolation==="circle"?(a=c.translate(a))&&(l=c.getLinePath(0,a)):(s(e.xAxis,function(a){a.pane=== +c.pane&&(g=a)}),l=[],a=c.translate(a),d=g.tickPositions,g.autoConnect&&(d=d.concat([d[0]])),b&&(d=[].concat(d).reverse()),s(d,function(f,c){k=g.getPosition(f,a);l.push(c?"L":"M",k.x,k.y)}));return l},getTitlePosition:function(){var a=this.center,b=this.chart,c=this.options.title;return{x:b.plotLeft+a[0]+(c.x||0),y:b.plotTop+a[1]-{high:0.5,middle:0.25,low:0}[c.align]*a[2]+(c.y||0)}}};r(G,"init",function(a,b,c){var i;var d=b.angular,e=b.polar,f=c.isX,g=d&&f,k,l;l=b.options;var n=c.pane||0;if(d){if(F(this, +g?V:N),k=!f)this.defaultRadialOptions=this.defaultRadialGaugeOptions}else if(e)F(this,N),this.defaultRadialOptions=(k=f)?this.defaultRadialXOptions:o(this.defaultYAxisOptions,this.defaultRadialYOptions);a.call(this,b,c);if(!g&&(d||e)){a=this.options;if(!b.panes)b.panes=[];this.pane=(i=b.panes[n]=b.panes[n]||new K(L(l.pane)[n],b,this),n=i);n=n.options;b.inverted=!1;l.chart.zoomType=null;this.startAngleRad=b=(n.startAngle-90)*Math.PI/180;this.endAngleRad=l=(q(n.endAngle,n.startAngle+360)-90)*Math.PI/ +180;this.offset=a.offset||0;if((this.isCircular=k)&&c.max===C&&l-b===2*Math.PI)this.autoConnect=!0}});r(y,"getPosition",function(a,b,c,d,e){var f=this.axis;return f.getPosition?f.getPosition(c):a.call(this,b,c,d,e)});r(y,"getLabelPosition",function(a,b,c,d,e,f,g,k,l){var n=this.axis,j=f.y,i=f.align,h=(n.translate(this.pos)+n.startAngleRad+Math.PI/2)/Math.PI*180%360;n.isRadial?(a=n.getPosition(this.pos,n.center[2]/2+q(f.distance,-25)),f.rotation==="auto"?d.attr({rotation:h}):j===null&&(j=n.chart.renderer.fontMetrics(d.styles.fontSize).b- +d.getBBox().height/2),i===null&&(i=n.isCircular?h>20&&h<160?"left":h>200&&h<340?"right":"center":"center",d.attr({align:i})),a.x+=f.x,a.y+=j):a=a.call(this,b,c,d,e,f,g,k,l);return a});r(y,"getMarkPath",function(a,b,c,d,e,f,g){var k=this.axis;k.isRadial?(a=k.getPosition(this.pos,k.center[2]/2+d),b=["M",b,c,"L",a.x,a.y]):b=a.call(this,b,c,d,e,f,g);return b});p.arearange=o(p.area,{lineWidth:1,marker:null,threshold:null,tooltip:{pointFormat:' {series.name}: {point.low} - {point.high}
      '}, +trackByArea:!0,dataLabels:{verticalAlign:null,xLow:0,xHigh:0,yLow:0,yHigh:0},states:{hover:{halo:!1}}});h.arearange=u(h.area,{type:"arearange",pointArrayMap:["low","high"],toYData:function(a){return[a.low,a.high]},pointValKey:"low",getSegments:function(){var a=this;s(a.points,function(b){if(!a.options.connectNulls&&(b.low===null||b.high===null))b.y=null;else if(b.low===null&&b.high!==null)b.y=b.high});t.prototype.getSegments.call(this)},translate:function(){var a=this.yAxis;h.area.prototype.translate.apply(this); +s(this.points,function(b){var c=b.low,d=b.high,e=b.plotY;d===null&&c===null?b.y=null:c===null?(b.plotLow=b.plotY=null,b.plotHigh=a.translate(d,0,1,0,1)):d===null?(b.plotLow=e,b.plotHigh=null):(b.plotLow=e,b.plotHigh=a.translate(d,0,1,0,1))})},getSegmentPath:function(a){var b,c=[],d=a.length,e=t.prototype.getSegmentPath,f,g;g=this.options;var k=g.step;for(b=HighchartsAdapter.grep(a,function(a){return a.plotLow!==null});d--;)f=a[d],f.plotHigh!==null&&c.push({plotX:f.plotX,plotY:f.plotHigh});a=e.call(this, +b);if(k)k===!0&&(k="left"),g.step={left:"right",center:"center",right:"left"}[k];c=e.call(this,c);g.step=k;g=[].concat(a,c);c[0]="L";this.areaPath=this.areaPath.concat(a,c);return g},drawDataLabels:function(){var a=this.data,b=a.length,c,d=[],e=t.prototype,f=this.options.dataLabels,g,k=this.chart.inverted;if(f.enabled||this._hasPointLabels){for(c=b;c--;)g=a[c],g.y=g.high,g._plotY=g.plotY,g.plotY=g.plotHigh,d[c]=g.dataLabel,g.dataLabel=g.dataLabelUpper,g.below=!1,k?(f.align="left",f.x=f.xHigh):f.y= +f.yHigh;e.drawDataLabels&&e.drawDataLabels.apply(this,arguments);for(c=b;c--;)g=a[c],g.dataLabelUpper=g.dataLabel,g.dataLabel=d[c],g.y=g.low,g.plotY=g._plotY,g.below=!0,k?(f.align="right",f.x=f.xLow):f.y=f.yLow;e.drawDataLabels&&e.drawDataLabels.apply(this,arguments)}},alignDataLabel:function(){h.column.prototype.alignDataLabel.apply(this,arguments)},getSymbol:h.column.prototype.getSymbol,drawPoints:w});p.areasplinerange=o(p.arearange);h.areasplinerange=u(h.arearange,{type:"areasplinerange",getPointSpline:h.spline.prototype.getPointSpline}); +(function(){var a=h.column.prototype;p.columnrange=o(p.column,p.arearange,{lineWidth:1,pointRange:null});h.columnrange=u(h.arearange,{type:"columnrange",translate:function(){var b=this,c=b.yAxis,d;a.translate.apply(b);s(b.points,function(a){var f=a.shapeArgs,g=b.options.minPointLength,k;a.tooltipPos=null;a.plotHigh=d=c.translate(a.high,0,1,0,1);a.plotLow=a.plotY;k=d;a=a.plotY-d;a {series.name}
      Maximum: {point.high}
      Upper quartile: {point.q3}
      Median: {point.median}
      Lower quartile: {point.q1}
      Minimum: {point.low}
      '}, +whiskerLength:"50%",whiskerWidth:2});h.boxplot=u(h.column,{type:"boxplot",pointArrayMap:["low","q1","median","q3","high"],toYData:function(a){return[a.low,a.q1,a.median,a.q3,a.high]},pointValKey:"high",pointAttrToOptions:{fill:"fillColor",stroke:"color","stroke-width":"lineWidth"},drawDataLabels:w,translate:function(){var a=this.yAxis,b=this.pointArrayMap;h.column.prototype.translate.apply(this);s(this.points,function(c){s(b,function(b){c[b]!==null&&(c[b+"Plot"]=a.translate(c[b],0,1,0,1))})})},drawPoints:function(){var a= +this,b=a.points,c=a.options,d=a.chart.renderer,e,f,g,k,l,n,j,i,h,m,p,I,r,o,J,u,w,t,v,x,z,y,E=a.doQuartiles!==!1,B=parseInt(a.options.whiskerLength,10)/100;s(b,function(b){h=b.graphic;z=b.shapeArgs;p={};o={};u={};y=b.color||a.color;if(b.plotY!==C)if(e=b.pointAttr[b.selected?"selected":""],w=z.width,t=A(z.x),v=t+w,x=D(w/2),f=A(E?b.q1Plot:b.lowPlot),g=A(E?b.q3Plot:b.lowPlot),k=A(b.highPlot),l=A(b.lowPlot),p.stroke=b.stemColor||c.stemColor||y,p["stroke-width"]=q(b.stemWidth,c.stemWidth,c.lineWidth),p.dashstyle= +b.stemDashStyle||c.stemDashStyle,o.stroke=b.whiskerColor||c.whiskerColor||y,o["stroke-width"]=q(b.whiskerWidth,c.whiskerWidth,c.lineWidth),u.stroke=b.medianColor||c.medianColor||y,u["stroke-width"]=q(b.medianWidth,c.medianWidth,c.lineWidth),u["stroke-linecap"]="round",j=p["stroke-width"]%2/2,i=t+x+j,m=["M",i,g,"L",i,k,"M",i,f,"L",i,l],E&&(j=e["stroke-width"]%2/2,i=A(i)+j,f=A(f)+j,g=A(g)+j,t+=j,v+=j,I=["M",t,g,"L",t,f,"L",v,f,"L",v,g,"L",t,g,"z"]),B&&(j=o["stroke-width"]%2/2,k+=j,l+=j,r=["M",i-x*B, +k,"L",i+x*B,k,"M",i-x*B,l,"L",i+x*B,l]),j=u["stroke-width"]%2/2,n=D(b.medianPlot)+j,J=["M",t,n,"L",v,n],h)b.stem.animate({d:m}),B&&b.whiskers.animate({d:r}),E&&b.box.animate({d:I}),b.medianShape.animate({d:J});else{b.graphic=h=d.g().add(a.group);b.stem=d.path(m).attr(p).add(h);if(B)b.whiskers=d.path(r).attr(o).add(h);if(E)b.box=d.path(I).attr(e).add(h);b.medianShape=d.path(J).attr(u).add(h)}})}});p.errorbar=o(p.boxplot,{color:"#000000",grouping:!1,linkedTo:":previous",tooltip:{pointFormat:' {series.name}: {point.low} - {point.high}
      '}, +whiskerWidth:null});h.errorbar=u(h.boxplot,{type:"errorbar",pointArrayMap:["low","high"],toYData:function(a){return[a.low,a.high]},pointValKey:"high",doQuartiles:!1,drawDataLabels:h.arearange?h.arearange.prototype.drawDataLabels:w,getColumnMetrics:function(){return this.linkedParent&&this.linkedParent.columnMetrics||h.column.prototype.getColumnMetrics.call(this)}});p.waterfall=o(p.column,{lineWidth:1,lineColor:"#333",dashStyle:"dot",borderColor:"#333"});h.waterfall=u(h.column,{type:"waterfall",upColorProp:"fill", +pointArrayMap:["low","y"],pointValKey:"y",init:function(a,b){b.stacking=!0;h.column.prototype.init.call(this,a,b)},translate:function(){var a=this.yAxis,b,c,d,e,f,g,k,l,n;b=this.options.threshold;h.column.prototype.translate.apply(this);l=b;d=this.points;for(c=0,b=d.length;c0&&!a.color)a.pointAttr=d,a.color=c})},getGraphPath:function(){var a=this.data,b=a.length, +c=D(this.options.lineWidth+this.borderWidth)%2/2,d=[],e,f,g;for(g=1;g0?(k[f]-a)/(b- +a):0.5,n&&g>=0&&(g=Math.sqrt(g)),l.push(v.ceil(c+g*(d-c))/2);this.radii=l},animate:function(a){var b=this.options.animation;if(!a)s(this.points,function(a){var d=a.graphic,a=a.shapeArgs;d&&a&&(d.attr("r",1),d.animate({r:a.r},b))}),this.animate=null},translate:function(){var a,b=this.data,c,d,e=this.radii;h.scatter.prototype.translate.call(this);for(a=b.length;a--;)c=b[a],d=e?e[a]:0,c.negative=c.z<(this.options.zThreshold||0),d>=this.minPxSize/2?(c.shapeType="circle",c.shapeArgs={x:c.plotX,y:c.plotY, +r:d},c.dlBox={x:c.plotX-d,y:c.plotY-d,width:2*d,height:2*d}):c.shapeArgs=c.plotY=c.dlBox=C},drawLegendSymbol:function(a,b){var c=x(a.itemStyle.fontSize)/2;b.legendSymbol=this.chart.renderer.circle(c,a.baseline-c,c).attr({zIndex:3}).add(b.legendGroup);b.legendSymbol.isMarker=!0},drawPoints:h.column.prototype.drawPoints,alignDataLabel:h.column.prototype.alignDataLabel});M.prototype.beforePadding=function(){var a=this,b=this.len,c=this.chart,d=0,e=b,f=this.isXAxis,g=f?"xData":"yData",k=this.min,l={}, +n=v.min(c.plotWidth,c.plotHeight),j=Number.MAX_VALUE,i=-Number.MAX_VALUE,h=this.max-k,m=b/h,p=[];this.tickPositions&&(s(this.series,function(b){var g=b.options;if(b.bubblePadding&&(b.visible||!c.options.chart.ignoreHiddenSeries))if(a.allowZoomOutside=!0,p.push(b),f)s(["minSize","maxSize"],function(a){var b=g[a],f=/%$/.test(b),b=x(b);l[a]=f?n*b/100:b}),b.minPxSize=l.minSize,b=b.zData,b.length&&(j=v.min(j,v.max(O(b),g.displayNegative===!1?g.zThreshold:-Number.MAX_VALUE)),i=v.max(i,P(b)))}),s(p,function(a){var b= +a[g],c=b.length,n;f&&a.getRadii(j,i,l.minSize,l.maxSize);if(h>0)for(;c--;)typeof b[c]==="number"&&(n=a.radii[c],d=Math.min((b[c]-k)*m-n,d),e=Math.max((b[c]-k)*m+n,e))}),p.length&&h>0&&q(this.options.min,this.userMin)===C&&q(this.options.max,this.userMax)===C&&(e-=b,m*=(b+d-e)/b,this.min+=d/m,this.max+=e/m))};(function(){function a(a,b,c){a.call(this,b,c);if(this.chart.polar)this.closeSegment=function(a){var b=this.xAxis.center;a.push("L",b[0],b[1])},this.closedStacks=!0}function b(a,b){var c=this.chart, +d=this.options.animation,e=this.group,j=this.markerGroup,i=this.xAxis.center,h=c.plotLeft,m=c.plotTop;if(c.polar){if(c.renderer.isSVG)d===!0&&(d={}),b?(c={translateX:i[0]+h,translateY:i[1]+m,scaleX:0.001,scaleY:0.001},e.attr(c),j&&j.attr(c)):(c={translateX:h,translateY:m,scaleX:1,scaleY:1},e.animate(c,d),j&&j.animate(c,d),this.animate=null)}else a.call(this,b)}var c=t.prototype,d=R.prototype,e;c.toXY=function(a){var b,c=this.chart,d=a.plotX;b=a.plotY;a.rectPlotX=d;a.rectPlotY=b;d=(d/Math.PI*180+this.xAxis.pane.options.startAngle)% +360;d<0&&(d+=360);a.clientX=d;b=this.xAxis.postTranslate(a.plotX,this.yAxis.len-b);a.plotX=a.polarPlotX=b.x-c.plotLeft;a.plotY=a.polarPlotY=b.y-c.plotTop};c.orderTooltipPoints=function(a){if(this.chart.polar&&(a.sort(function(a,b){return a.clientX-b.clientX}),a[0]))a[0].wrappedClientX=a[0].clientX+360,a.push(a[0])};h.area&&r(h.area.prototype,"init",a);h.areaspline&&r(h.areaspline.prototype,"init",a);h.spline&&r(h.spline.prototype,"getPointSpline",function(a,b,c,d){var e,j,i,h,m,p,o;if(this.chart.polar){e= +c.plotX;j=c.plotY;a=b[d-1];i=b[d+1];this.connectEnds&&(a||(a=b[b.length-2]),i||(i=b[1]));if(a&&i)h=a.plotX,m=a.plotY,b=i.plotX,p=i.plotY,h=(1.5*e+h)/2.5,m=(1.5*j+m)/2.5,i=(1.5*e+b)/2.5,o=(1.5*j+p)/2.5,b=Math.sqrt(Math.pow(h-e,2)+Math.pow(m-j,2)),p=Math.sqrt(Math.pow(i-e,2)+Math.pow(o-j,2)),h=Math.atan2(m-j,h-e),m=Math.atan2(o-j,i-e),o=Math.PI/2+(h+m)/2,Math.abs(h-o)>Math.PI/2&&(o-=Math.PI),h=e+Math.cos(o)*b,m=j+Math.sin(o)*b,i=e+Math.cos(Math.PI+o)*p,o=j+Math.sin(Math.PI+o)*p,c.rightContX=i,c.rightContY= +o;d?(c=["C",a.rightContX||a.plotX,a.rightContY||a.plotY,h||e,m||j,e,j],a.rightContX=a.rightContY=null):c=["M",e,j]}else c=a.call(this,b,c,d);return c});r(c,"translate",function(a){a.call(this);if(this.chart.polar&&!this.preventPostTranslate)for(var a=this.points,b=a.length;b--;)this.toXY(a[b])});r(c,"getSegmentPath",function(a,b){var c=this.points;if(this.chart.polar&&this.options.connectEnds!==!1&&b[b.length-1]===c[c.length-1]&&c[0].y!==null)this.connectEnds=!0,b=[].concat(b,[c[0]]);return a.call(this, +b)});r(c,"animate",b);r(c,"setTooltipPoints",function(a,b){this.chart.polar&&F(this.xAxis,{tooltipLen:360});return a.call(this,b)});if(h.column)e=h.column.prototype,r(e,"animate",b),r(e,"translate",function(a){var b=this.xAxis,c=this.yAxis.len,d=b.center,e=b.startAngleRad,h=this.chart.renderer,i,m;this.preventPostTranslate=!0;a.call(this);if(b.isRadial){b=this.points;for(m=b.length;m--;)i=b[m],a=i.barX+e,i.shapeType="path",i.shapeArgs={d:h.symbols.arc(d[0],d[1],c-i.plotY,null,{start:a,end:a+i.pointWidth, +innerR:c-q(i.yBottom,c)})},this.toXY(i),i.tooltipPos=[i.plotX,i.plotY],i.ttBelow=i.plotY>d[1]}}),r(e,"alignDataLabel",function(a,b,d,e,h,j){if(this.chart.polar){a=b.rectPlotX/Math.PI*180;if(e.align===null)e.align=a>20&&a<160?"left":a>200&&a<340?"right":"center";if(e.verticalAlign===null)e.verticalAlign=a<45||a>315?"bottom":a>135&&a<225?"top":"middle";c.alignDataLabel.call(this,b,d,e,h,j)}else a.call(this,b,d,e,h,j)});r(d,"getIndex",function(a,b){var c,d=this.chart,e;d.polar?(e=d.xAxis[0].center,c= +b.chartX-e[0]-d.plotLeft,d=b.chartY-e[1]-d.plotTop,c=180-Math.round(Math.atan2(c,d)/Math.PI*180)):c=a.call(this,b);return c});r(d,"getCoordinates",function(a,b){var c=this.chart,d={xAxis:[],yAxis:[]};c.polar?s(c.axes,function(a){var e=a.isXAxis,f=a.center,h=b.chartX-f[0]-c.plotLeft,f=b.chartY-f[1]-c.plotTop;d[e?"xAxis":"yAxis"].push({axis:a,value:a.translate(e?Math.PI-Math.atan2(h,f):Math.sqrt(Math.pow(h,2)+Math.pow(f,2)),!0)})}):d=a.call(this,b);return d})})()})(Highcharts); diff --git a/htdocs/js/lib/highstock/highstock.js b/htdocs/js/lib/highstock/highstock.js new file mode 100644 index 00000000..31242af1 --- /dev/null +++ b/htdocs/js/lib/highstock/highstock.js @@ -0,0 +1,383 @@ +/* + Highstock JS v2.0.1 (2014-04-24) + + (c) 2009-2014 Torstein Honsi + + License: www.highcharts.com/license +*/ +(function(){function v(a,b){var c;a||(a={});for(c in b)a[c]=b[c];return a}function y(){var a,b=arguments,c,d={},e=function(a,b){var c,d;typeof a!=="object"&&(a={});for(d in b)b.hasOwnProperty(d)&&(c=b[d],a[d]=c&&typeof c==="object"&&Object.prototype.toString.call(c)!=="[object Array]"&&d!=="renderTo"&&typeof c.nodeType!=="number"?e(a[d]||{},c):b[d]);return a};b[0]===!0&&(d=b[1],b=Array.prototype.slice.call(b,2));c=b.length;for(a=0;a3?c.length%3:0;return e+(g?c.substr(0,g)+d:"")+c.substr(g).replace(/(\d{3})(?=\d)/g,"$1"+d)+(f?b+M(a-c).toFixed(f).slice(2):"")}function Qa(a,b){return Array((b||2)+1-String(a).length).join(0)+a}function O(a, +b,c){var d=a[b];a[b]=function(){var a=Array.prototype.slice.call(arguments);a.unshift(d);return c.apply(this,a)}}function Ja(a,b){for(var c="{",d=!1,e,f,g,h,i,k=[];(c=a.indexOf(c))!==-1;){e=a.slice(0,c);if(d){f=e.split(":");g=f.shift().split(".");i=g.length;e=b;for(h=0;h-1?h.thousandsSep:""))):e=ua(f,e)}k.push(e);a=a.slice(c+1);c=(d=!d)? +"}":"{"}k.push(a);return k.join("")}function rb(a){return V.pow(10,S(V.log(a)/V.LN10))}function sb(a,b,c,d){var e,c=o(c,1);e=a/c;b||(b=[1,2,2.5,5,10],d&&d.allowDecimals===!1&&(c===1?b=[1,2,5,10]:c<=0.1&&(b=[1/c])));for(d=0;dc&&(c=a[b]);return c}function Ka(a,b){for(var c in a)a[c]&&a[c]!==b&&a[c].destroy&&a[c].destroy(),delete a[c]}function Sa(a){hb||(hb=$(Ta));a&&hb.appendChild(a);hb.innerHTML=""}function qa(a,b){var c="Highcharts error #"+a+": www.highcharts.com/errors/"+a;if(b)throw c;else X.console&&console.log(c)}function ha(a){return parseFloat(a.toPrecision(14))}function Ya(a,b){Ca=o(a,b.animation)}function Mb(){var a= +F.global.useUTC,b=a?"getUTC":"get",c=a?"setUTC":"set";La=(a&&F.global.timezoneOffset||0)*6E4;ib=a?Date.UTC:function(a,b,c,g,h,i){return(new Date(a,b,o(c,1),o(g,0),o(h,0),o(i,0))).getTime()};ub=b+"Minutes";vb=b+"Hours";wb=b+"Day";Ua=b+"Date";jb=b+"Month";kb=b+"FullYear";Nb=c+"Minutes";Ob=c+"Hours";xb=c+"Date";Pb=c+"Month";Qb=c+"FullYear"}function Z(){}function Za(a,b,c,d){this.axis=a;this.pos=b;this.type=c||"";this.isNew=!0;!c&&!d&&this.addLabel()}function L(){this.init.apply(this,arguments)}function va(){this.init.apply(this, +arguments)}function Rb(a,b,c,d,e){var f=a.chart.inverted;this.axis=a;this.isNegative=c;this.options=b;this.x=d;this.total=null;this.points={};this.stack=e;this.alignOptions={align:b.align||(f?c?"left":"right":"center"),verticalAlign:b.verticalAlign||(f?"middle":c?"bottom":"top"),y:o(b.y,f?4:c?14:-6),x:o(b.x,f?c?-6:6:0)};this.textAlign=b.textAlign||(f?c?"right":"left":"center")}function yb(a){var b=a.options,c=b.navigator,d=c.enabled,b=b.scrollbar,e=b.enabled,f=d?c.height:0,g=e?b.height:0;this.handles= +[];this.scrollbarButtons=[];this.elementsToDestroy=[];this.chart=a;this.setBaseSeries();this.height=f;this.scrollbarHeight=g;this.scrollbarEnabled=e;this.navigatorEnabled=d;this.navigatorOptions=c;this.scrollbarOptions=b;this.outlineHeight=f+g;this.init()}function zb(a){this.init(a)}var r,B=document,X=window,V=Math,s=V.round,S=V.floor,Va=V.ceil,w=V.max,z=V.min,M=V.abs,da=V.cos,ia=V.sin,ra=V.PI,Ma=ra*2/360,Da=navigator.userAgent,Sb=X.opera,Ha=/msie/i.test(Da)&&!Sb,lb=B.documentMode===8,mb=/AppleWebKit/.test(Da), +$a=/Firefox/.test(Da),cb=/(Mobile|Android|Windows Phone)/.test(Da),Ea="http://www.w3.org/2000/svg",ca=!!B.createElementNS&&!!B.createElementNS(Ea,"svg").createSVGRect,Yb=$a&&parseInt(Da.split("Firefox/")[1],10)<4,ja=!ca&&!Ha&&!!B.createElement("canvas").getContext,Wa,ab,Tb={},Ab=0,hb,F,ua,Ca,Bb,H,na=function(){},aa=[],db=0,Ta="div",Y="none",Zb=/^[0-9]+$/,$b="stroke-width",ib,La,ub,vb,wb,Ua,jb,kb,Nb,Ob,xb,Pb,Qb,C={},P=X.Highcharts=X.Highcharts?qa(16,!0):{};ua=function(a,b,c){if(!t(b)||isNaN(b))return"Invalid date"; +var a=o(a,"%Y-%m-%d %H:%M:%S"),d=new Date(b-La),e,f=d[vb](),g=d[wb](),h=d[Ua](),i=d[jb](),k=d[kb](),j=F.lang,l=j.weekdays,d=v({a:l[g].substr(0,3),A:l[g],d:Qa(h),e:h,b:j.shortMonths[i],B:j.months[i],m:Qa(i+1),y:k.toString().substr(2,2),Y:k,H:Qa(f),I:Qa(f%12||12),l:f%12||12,M:Qa(d[ub]()),p:f<12?"AM":"PM",P:f<12?"am":"pm",S:Qa(d.getSeconds()),L:Qa(s(b%1E3),3)},P.dateFormats);for(e in d)for(;a.indexOf("%"+e)!==-1;)a=a.replace("%"+e,typeof d[e]==="function"?d[e](b):d[e]);return c?a.substr(0,1).toUpperCase()+ +a.substr(1):a};Lb.prototype={wrapColor:function(a){if(this.color>=a)this.color=0},wrapSymbol:function(a){if(this.symbol>=a)this.symbol=0}};H=Kb("millisecond",1,"second",1E3,"minute",6E4,"hour",36E5,"day",864E5,"week",6048E5,"month",26784E5,"year",31556952E3);Bb={init:function(a,b,c){var b=b||"",d=a.shift,e=b.indexOf("C")>-1,f=e?7:3,g,b=b.split(" "),c=[].concat(c),h,i,k=function(a){for(g=a.length;g--;)a[g]==="M"&&a.splice(g+1,0,a[g+1],a[g+2],a[g+1],a[g+2])};e&&(k(b),k(c));a.isArea&&(h=b.splice(b.length- +6,6),i=c.splice(c.length-6,6));if(d<=c.length/f&&b.length===c.length)for(;d--;)c=[].concat(c).splice(0,f).concat(c);a.shift=0;if(b.length)for(a=c.length;b.length{point.key}
      ',pointFormat:' {series.name}: {point.y}
      ',shadow:!0,snap:cb?25:10,style:{color:"#333333",cursor:"default",fontSize:"12px",padding:"8px",whiteSpace:"nowrap"}},credits:{enabled:!0,text:"Highcharts.com",href:"http://www.highcharts.com",position:{align:"right", +x:-10,verticalAlign:"bottom",y:-5},style:{cursor:"pointer",color:"#909090",fontSize:"9px"}}};var T=F.plotOptions,J=T.line;Mb();var dc=/rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]?(?:\.[0-9]+)?)\s*\)/,ec=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/,fc=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/,Fa=function(a){var b=[],c,d;(function(a){a&&a.stops?d=xa(a.stops,function(a){return Fa(a[1])}):(c=dc.exec(a))?b=[I(c[1]),I(c[2]),I(c[3]),parseFloat(c[4], +10)]:(c=ec.exec(a))?b=[I(c[1],16),I(c[2],16),I(c[3],16),1]:(c=fc.exec(a))&&(b=[I(c[1]),I(c[2]),I(c[3]),1])})(a);return{get:function(c){var f;d?(f=y(a),f.stops=[].concat(f.stops),q(d,function(a,b){f.stops[b]=[f.stops[b][0],a.get(c)]})):f=b&&!isNaN(b[0])?c==="rgb"?"rgb("+b[0]+","+b[1]+","+b[2]+")":c==="a"?b[3]:"rgba("+b.join(",")+")":a;return f},brighten:function(a){if(d)q(d,function(b){b.brighten(a)});else if(la(a)&&a!==0){var c;for(c=0;c<3;c++)b[c]+=I(a*255),b[c]<0&&(b[c]=0),b[c]>255&&(b[c]=255)}return this}, +rgba:b,setOpacity:function(a){b[3]=a;return this}}};Z.prototype={init:function(a,b){this.element=b==="span"?$(b):B.createElementNS(Ea,b);this.renderer=a},opacity:1,animate:function(a,b,c){b=o(b,Ca,!0);eb(this);if(b){b=y(b,{});if(c)b.complete=c;ob(this,a,b)}else this.attr(a),c&&c()},colorGradient:function(a,b,c){var d=this.renderer,e,f,g,h,i,k,j,l,m,n,p=[];a.linearGradient?f="linearGradient":a.radialGradient&&(f="radialGradient");if(f){g=a[f];h=d.gradients;k=a.stops;m=c.radialReference;Pa(g)&&(a[f]= +g={x1:g[0],y1:g[1],x2:g[2],y2:g[3],gradientUnits:"userSpaceOnUse"});f==="radialGradient"&&m&&!t(g.gradientUnits)&&(g=y(g,{cx:m[0]-m[2]/2+g.cx*m[2],cy:m[1]-m[2]/2+g.cy*m[2],r:g.r*m[2],gradientUnits:"userSpaceOnUse"}));for(n in g)n!=="id"&&p.push(n,g[n]);for(n in k)p.push(k[n]);p=p.join(",");h[p]?a=h[p].attr("id"):(g.id=a="highcharts-"+Ab++,h[p]=i=d.createElement(f).attr(g).add(d.defs),i.stops=[],q(k,function(a){a[1].indexOf("rgba")===0?(e=Fa(a[1]),j=e.get("rgb"),l=e.get("a")):(j=a[1],l=1);a=d.createElement("stop").attr({offset:a[0], +"stop-color":j,"stop-opacity":l}).add(i);i.stops.push(a)}));c.setAttribute(b,"url("+d.url+"#"+a+")")}},attr:function(a,b){var c,d,e=this.element,f,g=this,h;typeof a==="string"&&b!==r&&(c=a,a={},a[c]=b);if(typeof a==="string")g=(this[a+"Getter"]||this._defaultGetter).call(this,a,e);else{for(c in a){d=a[c];h=!1;this.symbolName&&/^(x|y|width|height|r|start|end|innerR|anchorX|anchorY)/.test(c)&&(f||(this.symbolAttr(a),f=!0),h=!0);if(this.rotation&&(c==="x"||c==="y"))this.doTransform=!0;h||(this[c+"Setter"]|| +this._defaultSetter).call(this,d,c,e);this.shadows&&/^(width|height|visibility|x|y|d|transform|cx|cy|r)$/.test(c)&&this.updateShadows(c,d)}if(this.doTransform)this.updateTransform(),this.doTransform=!1}return g},updateShadows:function(a,b){for(var c=this.shadows,d=c.length;d--;)c[d].setAttribute(a,a==="height"?w(b-(c[d].cutHeight||0),0):a==="d"?this.d:b)},addClass:function(a){var b=this.element,c=W(b,"class")||"";c.indexOf(a)===-1&&W(b,"class",c+" "+a);return this},symbolAttr:function(a){var b=this; +q("x,y,r,start,end,width,height,innerR,anchorX,anchorY".split(","),function(c){b[c]=o(a[c],b[c])});b.attr({d:b.renderer.symbols[b.symbolName](b.x,b.y,b.width,b.height,b)})},clip:function(a){return this.attr("clip-path",a?"url("+this.renderer.url+"#"+a.id+")":Y)},crisp:function(a){var b,c={},d,e=a.strokeWidth||this.strokeWidth||this.attr&&this.attr("stroke-width")||0;d=s(e)%2/2;a.x=S(a.x||this.x||0)+d;a.y=S(a.y||this.y||0)+d;a.width=S((a.width||this.width||0)-2*d);a.height=S((a.height||this.height|| +0)-2*d);a.strokeWidth=e;for(b in a)this[b]!==a[b]&&(this[b]=c[b]=a[b]);return c},css:function(a){var b=this.styles,c={},d=this.element,e,f,g="";e=!b;if(a&&a.color)a.fill=a.color;if(b)for(f in a)a[f]!==b[f]&&(c[f]=a[f],e=!0);if(e){e=this.textWidth=a&&a.width&&d.nodeName.toLowerCase()==="text"&&I(a.width);b&&(a=v(b,c));this.styles=a;e&&(ja||!ca&&this.renderer.forExport)&&delete a.width;if(Ha&&!ca)E(this.element,a);else{b=function(a,b){return"-"+b.toLowerCase()};for(f in a)g+=f.replace(/([A-Z])/g,b)+ +":"+a[f]+";";W(d,"style",g)}e&&this.added&&this.renderer.buildText(this)}return this},on:function(a,b){var c=this,d=c.element;ab&&a==="click"?(d.ontouchstart=function(a){c.touchEventFired=Date.now();a.preventDefault();b.call(d,a)},d.onclick=function(a){(Da.indexOf("Android")===-1||Date.now()-(c.touchEventFired||0)>1100)&&b.call(d,a)}):d["on"+a]=b;return this},setRadialReference:function(a){this.element.radialReference=a;return this},translate:function(a,b){return this.attr({translateX:a,translateY:b})}, +invert:function(){this.inverted=!0;this.updateTransform();return this},updateTransform:function(){var a=this.translateX||0,b=this.translateY||0,c=this.scaleX,d=this.scaleY,e=this.inverted,f=this.rotation,g=this.element;e&&(a+=this.attr("width"),b+=this.attr("height"));a=["translate("+a+","+b+")"];e?a.push("rotate(90) scale(-1,1)"):f&&a.push("rotate("+f+" "+(g.getAttribute("x")||0)+" "+(g.getAttribute("y")||0)+")");(t(c)||t(d))&&a.push("scale("+o(c,1)+" "+o(d,1)+")");a.length&&g.setAttribute("transform", +a.join(" "))},toFront:function(){var a=this.element;a.parentNode.appendChild(a);return this},align:function(a,b,c){var d,e,f,g,h={};e=this.renderer;f=e.alignedObjects;if(a){if(this.alignOptions=a,this.alignByTranslate=b,!c||Oa(c))this.alignTo=d=c||"renderer",pa(f,this),f.push(this),c=null}else a=this.alignOptions,b=this.alignByTranslate,d=this.alignTo;c=o(c,e[d],e);d=a.align;e=a.verticalAlign;f=(c.x||0)+(a.x||0);g=(c.y||0)+(a.y||0);if(d==="right"||d==="center")f+=(c.width-(a.width||0))/{right:1,center:2}[d]; +h[b?"translateX":"x"]=s(f);if(e==="bottom"||e==="middle")g+=(c.height-(a.height||0))/({bottom:1,middle:2}[e]||1);h[b?"translateY":"y"]=s(g);this[this.placed?"animate":"attr"](h);this.placed=!0;this.alignAttr=h;return this},getBBox:function(){var a=this.bBox,b=this.renderer,c,d,e=this.rotation;c=this.element;var f=this.styles,g=e*Ma;d=this.textStr;var h;if(d===""||Zb.test(d))h="num."+d.toString().length+(f?"|"+f.fontSize+"|"+f.fontFamily:"");h&&(a=b.cache[h]);if(!a){if(c.namespaceURI===Ea||b.forExport){try{a= +c.getBBox?v({},c.getBBox()):{width:c.offsetWidth,height:c.offsetHeight}}catch(i){}if(!a||a.width<0)a={width:0,height:0}}else a=this.htmlGetBBox();if(b.isSVG){c=a.width;d=a.height;if(Ha&&f&&f.fontSize==="11px"&&d.toPrecision(3)==="16.9")a.height=d=14;if(e)a.width=M(d*ia(g))+M(c*da(g)),a.height=M(d*da(g))+M(c*ia(g))}this.bBox=a;h&&(b.cache[h]=a)}return a},show:function(a){return a&&this.element.namespaceURI===Ea?(this.element.removeAttribute("visibility"),this):this.attr({visibility:a?"inherit":"visible"})}, +hide:function(){return this.attr({visibility:"hidden"})},fadeOut:function(a){var b=this;b.animate({opacity:0},{duration:a||150,complete:function(){b.hide()}})},add:function(a){var b=this.renderer,c=a||b,d=c.element||b.box,e=this.element,f=this.zIndex,g,h;if(a)this.parentGroup=a;this.parentInverted=a&&a.inverted;this.textStr!==void 0&&b.buildText(this);if(f)c.handleZ=!0,f=I(f);if(c.handleZ){a=d.childNodes;for(g=0;gf||!t(f)&&t(c))){d.insertBefore(e, +b);h=!0;break}}h||d.appendChild(e);this.added=!0;if(this.onAdd)this.onAdd();return this},safeRemoveChild:function(a){var b=a.parentNode;b&&b.removeChild(a)},destroy:function(){var a=this,b=a.element||{},c=a.shadows,d=a.renderer.isSVG&&b.nodeName==="SPAN"&&a.parentGroup,e,f;b.onclick=b.onmouseout=b.onmouseover=b.onmousemove=b.point=null;eb(a);if(a.clipPath)a.clipPath=a.clipPath.destroy();if(a.stops){for(f=0;f/,i=/<.*href="(http[^"]+)".*>/,l&&!a.added&&this.box.appendChild(b),e=f?e.replace(/<(b|strong)>/g,'').replace(/<(i|em)>/g,'').replace(//g, +"").split(//g):[e],e[e.length-1]===""&&e.pop(),q(e,function(e,f){var g,m=0,e=e.replace(//g,"|||");g=e.split("|||");q(g,function(e){if(e!==""||g.length===1){var n={},u=B.createElementNS(Ea,"tspan"),o;h.test(e)&&(o=e.match(h)[1].replace(/(;| |^)color([ :])/,"$1fill$2"),W(u,"style",o));i.test(e)&&!d&&(W(u,"onclick",'location.href="'+e.match(i)[1]+'"'),E(u,{cursor:"pointer"}));e=(e.replace(/<(.|\n)*?>/g,"")||" ").replace(/</g,"<").replace(/>/g, +">");if(e!==" "){u.appendChild(B.createTextNode(e));if(m)n.dx=0;else if(f&&k!==null)n.x=k;W(u,n);!m&&f&&(!ca&&d&&E(u,{display:"block"}),W(u,"dy",p(u),mb&&u.offsetHeight));b.appendChild(u);m++;if(l)for(var e=e.replace(/([^\^])-/g,"$1- ").split(" "),n=e.length>1&&j.whiteSpace!=="nowrap",q,r,D=a._clipHeight,t=[],s=p(),w=1;n&&(e.length||t.length);)delete a.bBox,q=a.getBBox(),r=q.width,!ca&&c.forExport&&(r=c.measureSpanWidth(u.firstChild.data,a.styles)),q=r>l,!q||e.length===1?(e=t,t=[],e.length&&(w++, +D&&w*s>D?(e=["..."],a.attr("title",a.textStr)):(u=B.createElementNS(Ea,"tspan"),W(u,{dy:s,x:k}),o&&W(u,"style",o),b.appendChild(u),r>l&&(l=r)))):(u.removeChild(u.firstChild),t.unshift(e.pop())),e.length&&u.appendChild(B.createTextNode(e.join(" ").replace(/- /g,"-")))}}})}))},button:function(a,b,c,d,e,f,g,h,i){var k=this.label(a,b,c,i,null,null,null,null,"button"),j=0,l,m,n,p,u,o,a={x1:0,y1:0,x2:0,y2:1},e=y({"stroke-width":1,stroke:"#CCCCCC",fill:{linearGradient:a,stops:[[0,"#FEFEFE"],[1,"#F6F6F6"]]}, +r:2,padding:5,style:{color:"black"}},e);n=e.style;delete e.style;f=y(e,{stroke:"#68A",fill:{linearGradient:a,stops:[[0,"#FFF"],[1,"#ACF"]]}},f);p=f.style;delete f.style;g=y(e,{stroke:"#68A",fill:{linearGradient:a,stops:[[0,"#9BD"],[1,"#CDF"]]}},g);u=g.style;delete g.style;h=y(e,{style:{color:"#CCC"}},h);o=h.style;delete h.style;A(k.element,Ha?"mouseover":"mouseenter",function(){j!==3&&k.attr(f).css(p)});A(k.element,Ha?"mouseout":"mouseleave",function(){j!==3&&(l=[e,f,g][j],m=[n,p,u][j],k.attr(l).css(m))}); +k.setState=function(a){(k.state=j=a)?a===2?k.attr(g).css(u):a===3&&k.attr(h).css(o):k.attr(e).css(n)};return k.on("click",function(){j!==3&&d.call(k)}).attr(e).css(v({cursor:"default"},n))},crispLine:function(a,b){a[1]===a[4]&&(a[1]=a[4]=s(a[1])-b%2/2);a[2]===a[5]&&(a[2]=a[5]=s(a[2])+b%2/2);return a},path:function(a){var b={fill:Y};Pa(a)?b.d=a:fa(a)&&v(b,a);return this.createElement("path").attr(b)},circle:function(a,b,c){a=fa(a)?a:{x:a,y:b,r:c};b=this.createElement("circle");b.xSetter=function(a){this.element.setAttribute("cx", +a)};b.ySetter=function(a){this.element.setAttribute("cy",a)};return b.attr(a)},arc:function(a,b,c,d,e,f){if(fa(a))b=a.y,c=a.r,d=a.innerR,e=a.start,f=a.end,a=a.x;a=this.symbol("arc",a||0,b||0,c||0,c||0,{innerR:d||0,start:e||0,end:f||0});a.r=c;return a},rect:function(a,b,c,d,e,f){var e=fa(a)?a.r:e,g=this.createElement("rect"),a=fa(a)?a:a===r?{}:{x:a,y:b,width:w(c,0),height:w(d,0)};if(f!==r)a.strokeWidth=f,a=g.crisp(a);if(e)a.r=e;g.rSetter=function(a){W(this.element,{rx:a,ry:a})};return g.attr(a)},setSize:function(a, +b,c){var d=this.alignedObjects,e=d.length;this.width=a;this.height=b;for(this.boxWrapper[o(c,!0)?"animate":"attr"]({width:a,height:b});e--;)d[e].align()},g:function(a){var b=this.createElement("g");return t(a)?b.attr({"class":"highcharts-"+a}):b},image:function(a,b,c,d,e){var f={preserveAspectRatio:Y};arguments.length>1&&v(f,{x:b,y:c,width:d,height:e});f=this.createElement("image").attr(f);f.element.setAttributeNS?f.element.setAttributeNS("http://www.w3.org/1999/xlink","href",a):f.element.setAttribute("hc-svg-href", +a);return f},symbol:function(a,b,c,d,e,f){var g,h=this.symbols[a],h=h&&h(s(b),s(c),d,e,f),i=/^url\((.*?)\)$/,k,j;if(h)g=this.path(h),v(g,{symbolName:a,x:b,y:c,width:d,height:e}),f&&v(g,f);else if(i.test(a))j=function(a,b){a.element&&(a.attr({width:b[0],height:b[1]}),a.alignByTranslate||a.translate(s((d-b[0])/2),s((e-b[1])/2)))},k=a.match(i)[1],a=Tb[k],g=this.image(k).attr({x:b,y:c}),g.isImg=!0,a?j(g,a):(g.attr({width:0,height:0}),$("img",{onload:function(){j(g,Tb[k]=[this.width,this.height])},src:k})); +return g},symbols:{circle:function(a,b,c,d){var e=0.166*c;return["M",a+c/2,b,"C",a+c+e,b,a+c+e,b+d,a+c/2,b+d,"C",a-e,b+d,a-e,b,a+c/2,b,"Z"]},square:function(a,b,c,d){return["M",a,b,"L",a+c,b,a+c,b+d,a,b+d,"Z"]},triangle:function(a,b,c,d){return["M",a+c/2,b,"L",a+c,b+d,a,b+d,"Z"]},"triangle-down":function(a,b,c,d){return["M",a,b,"L",a+c,b,a+c/2,b+d,"Z"]},diamond:function(a,b,c,d){return["M",a+c/2,b,"L",a+c,b+d/2,a+c/2,b+d,a,b+d/2,"Z"]},arc:function(a,b,c,d,e){var f=e.start,c=e.r||c||d,g=e.end-0.001, +d=e.innerR,h=e.open,i=da(f),k=ia(f),j=da(g),g=ia(g),e=e.end-fc&&i>b+g&&ib+g&&id&&h>a+g&&ha+g&&hl&&/[ \-]/.test(b.textContent||b.innerText))E(b,{width:l+"px",display:"block",whiteSpace:"normal"}),i=l;this.getSpanCorrection(i,j,h,k,g)}E(b,{left:e+(this.xCorr||0)+"px",top:f+(this.yCorr||0)+"px"});if(mb)j=b.offsetHeight;this.cTT=m}}else this.alignOnAdd=!0},setSpanRotation:function(a,b,c){var d={},e=Ha?"-ms-transform":mb?"-webkit-transform":$a?"MozTransform":Sb?"-o-transform":"";d[e]=d.transform="rotate("+a+"deg)";d[e+($a?"Origin":"-origin")]=d.transformOrigin= +b*100+"% "+c+"px";E(this.element,d)},getSpanCorrection:function(a,b,c){this.xCorr=-a*c;this.yCorr=-b}});v(ka.prototype,{html:function(a,b,c){var d=this.createElement("span"),e=d.element,f=d.renderer;d.textSetter=function(a){a!==e.innerHTML&&delete this.bBox;e.innerHTML=this.textStr=a};d.xSetter=d.ySetter=d.alignSetter=d.rotationSetter=function(a,b){b==="align"&&(b="textAlign");d[b]=a;d.htmlUpdateTransform()};d.attr({text:a,x:s(b),y:s(c)}).css({position:"absolute",whiteSpace:"nowrap",fontFamily:this.style.fontFamily, +fontSize:this.style.fontSize});d.css=d.htmlCss;if(f.isSVG)d.add=function(a){var b,c=f.box.parentNode,k=[];if(this.parentGroup=a){if(b=a.div,!b){for(;a;)k.push(a),a=a.parentGroup;q(k.reverse(),function(a){var d;b=a.div=a.div||$(Ta,{className:W(a.element,"class")},{position:"absolute",left:(a.translateX||0)+"px",top:(a.translateY||0)+"px"},b||c);d=b.style;v(a,{translateXSetter:function(b,c){d.left=b+"px";a[c]=b;a.doTransform=!0},translateYSetter:function(b,c){d.top=b+"px";a[c]=b;a.doTransform=!0},visibilitySetter:function(a, +b){d[b]=a}})})}}else b=c;b.appendChild(e);d.added=!0;d.alignOnAdd&&d.htmlUpdateTransform();return d};return d}});var fb,ea;if(!ca&&!ja)P.VMLElement=ea={init:function(a,b){var c=["<",b,' filled="f" stroked="f"'],d=["position: ","absolute",";"],e=b===Ta;(b==="shape"||e)&&d.push("left:0;top:0;width:1px;height:1px;");d.push("visibility: ",e?"hidden":"visible");c.push(' style="',d.join(""),'"/>');if(b)c=e||b==="span"||b==="img"?c.join(""):a.prepVML(c),this.element=$(c);this.renderer=a},add:function(a){var b= +this.renderer,c=this.element,d=b.box,d=a?a.element||a:d;a&&a.inverted&&b.invertChild(c,d);d.appendChild(c);this.added=!0;this.alignOnAdd&&!this.deferUpdateTransform&&this.updateTransform();if(this.onAdd)this.onAdd();return this},updateTransform:Z.prototype.htmlUpdateTransform,setSpanRotation:function(){var a=this.rotation,b=da(a*Ma),c=ia(a*Ma);E(this.element,{filter:a?["progid:DXImageTransform.Microsoft.Matrix(M11=",b,", M12=",-c,", M21=",c,", M22=",b,", sizingMethod='auto expand')"].join(""):Y})}, +getSpanCorrection:function(a,b,c,d,e){var f=d?da(d*Ma):1,g=d?ia(d*Ma):0,h=o(this.elemHeight,this.element.offsetHeight),i;this.xCorr=f<0&&-a;this.yCorr=g<0&&-h;i=f*g<0;this.xCorr+=g*b*(i?1-c:c);this.yCorr-=f*b*(d?i?c:1-c:1);e&&e!=="left"&&(this.xCorr-=a*c*(f<0?-1:1),d&&(this.yCorr-=h*c*(g<0?-1:1)),E(this.element,{textAlign:e}))},pathToVML:function(a){for(var b=a.length,c=[];b--;)if(la(a[b]))c[b]=s(a[b]*10)-5;else if(a[b]==="Z")c[b]="x";else if(c[b]=a[b],a.isArc&&(a[b]==="wa"||a[b]==="at"))c[b+5]=== +c[b+7]&&(c[b+7]+=a[b+7]>a[b+5]?1:-1),c[b+6]===c[b+8]&&(c[b+8]+=a[b+8]>a[b+6]?1:-1);return c.join(" ")||"x"},clip:function(a){var b=this,c;a?(c=a.members,pa(c,b),c.push(b),b.destroyClip=function(){pa(c,b)},a=a.getCSS(b)):(b.destroyClip&&b.destroyClip(),a={clip:lb?"inherit":"rect(auto)"});return b.css(a)},css:Z.prototype.htmlCss,safeRemoveChild:function(a){a.parentNode&&Sa(a)},destroy:function(){this.destroyClip&&this.destroyClip();return Z.prototype.destroy.apply(this)},on:function(a,b){this.element["on"+ +a]=function(){var a=X.event;a.target=a.srcElement;b(a)};return this},cutOffPath:function(a,b){var c,a=a.split(/[ ,]/);c=a.length;if(c===9||c===11)a[c-4]=a[c-2]=I(a[c-2])-10*b;return a.join(" ")},shadow:function(a,b,c){var d=[],e,f=this.element,g=this.renderer,h,i=f.style,k,j=f.path,l,m,n,p;j&&typeof j.value!=="string"&&(j="x");m=j;if(a){n=o(a.width,3);p=(a.opacity||0.15)/n;for(e=1;e<=3;e++){l=n*2+1-2*e;c&&(m=this.cutOffPath(j.value,l+0.5));k=[''];h=$(g.prepVML(k),null,{left:I(i.left)+o(a.offsetX,1),top:I(i.top)+o(a.offsetY,1)});if(c)h.cutOff=l+1;k=[''];$(g.prepVML(k),null,null,h);b?b.element.appendChild(h):f.parentNode.insertBefore(h,f);d.push(h)}this.shadows=d}return this},updateShadows:na,setAttr:function(a,b){lb?this.element[a]=b:this.element.setAttribute(a,b)},classSetter:function(a){this.element.className=a},dashstyleSetter:function(a, +b,c){(c.getElementsByTagName("stroke")[0]||$(this.renderer.prepVML([""]),null,null,c))[b]=a||"solid";this[b]=a},dSetter:function(a,b,c){var d=this.shadows,a=a||[];this.d=a.join(" ");c.path=a=this.pathToVML(a);if(d)for(c=d.length;c--;)d[c].path=d[c].cutOff?this.cutOffPath(a,d[c].cutOff):a;this.setAttr(b,a)},fillSetter:function(a,b,c){var d=c.nodeName;if(d==="SPAN")c.style.color=a;else if(d!=="IMG")c.filled=a!==Y,this.setAttr("fillcolor",this.renderer.color(a,c,b,this))},opacitySetter:na,rotationSetter:function(a, +b,c){c=c.style;this[b]=c[b]=a;c.left=-s(ia(a*Ma)+1)+"px";c.top=s(da(a*Ma))+"px"},strokeSetter:function(a,b,c){this.setAttr("strokecolor",this.renderer.color(a,c,b))},"stroke-widthSetter":function(a,b,c){c.stroked=!!a;this[b]=a;la(a)&&(a+="px");this.setAttr("strokeweight",a)},titleSetter:function(a,b){this.setAttr(b,a)},visibilitySetter:function(a,b,c){a==="inherit"&&(a="visible");this.shadows&&q(this.shadows,function(c){c.style[b]=a});c.nodeName==="DIV"&&(a=a==="hidden"?"-999em":0,lb||(c.style[b]= +a?"visible":"hidden"),b="top");c.style[b]=a},xSetter:function(a,b,c){this[b]=a;b==="x"?b="left":b==="y"&&(b="top");this.updateClipping?(this[b]=a,this.updateClipping()):c.style[b]=a},zIndexSetter:function(a,b,c){c.style[b]=a}},ea=ga(Z,ea),ea.prototype.ySetter=ea.prototype.widthSetter=ea.prototype.heightSetter=ea.prototype.xSetter,ea={Element:ea,isIE8:Da.indexOf("MSIE 8.0")>-1,init:function(a,b,c,d){var e;this.alignedObjects=[];d=this.createElement(Ta).css(v(this.getStyle(d),{position:"relative"})); +e=d.element;a.appendChild(d.element);this.isVML=!0;this.box=e;this.boxWrapper=d;this.cache={};this.setSize(b,c,!1);if(!B.namespaces.hcv){B.namespaces.add("hcv","urn:schemas-microsoft-com:vml");try{B.createStyleSheet().cssText="hcv\\:fill, hcv\\:path, hcv\\:shape, hcv\\:stroke{ behavior:url(#default#VML); display: inline-block; } "}catch(f){B.styleSheets[0].cssText+="hcv\\:fill, hcv\\:path, hcv\\:shape, hcv\\:stroke{ behavior:url(#default#VML); display: inline-block; } "}}},isHidden:function(){return!this.box.offsetWidth}, +clipRect:function(a,b,c,d){var e=this.createElement(),f=fa(a);return v(e,{members:[],left:(f?a.x:a)+1,top:(f?a.y:b)+1,width:(f?a.width:c)-1,height:(f?a.height:d)-1,getCSS:function(a){var b=a.element,c=b.nodeName,a=a.inverted,d=this.top-(c==="shape"?b.offsetTop:0),e=this.left,b=e+this.width,f=d+this.height,d={clip:"rect("+s(a?e:d)+"px,"+s(a?f:b)+"px,"+s(a?b:f)+"px,"+s(a?d:e)+"px)"};!a&&lb&&c==="DIV"&&v(d,{width:b+"px",height:f+"px"});return d},updateClipping:function(){q(e.members,function(a){a.element&& +a.css(e.getCSS(a))})}})},color:function(a,b,c,d){var e=this,f,g=/^rgba/,h,i,k=Y;a&&a.linearGradient?i="gradient":a&&a.radialGradient&&(i="pattern");if(i){var j,l,m=a.linearGradient||a.radialGradient,n,p,u,o,G,x="",a=a.stops,r,t=[],s=function(){h=[''];$(e.prepVML(h),null,null,b)};n=a[0];r=a[a.length-1];n[0]>0&&a.unshift([0,n[1]]);r[0]<1&&a.push([1,r[1]]);q(a,function(a,b){g.test(a[1])?(f= +Fa(a[1]),j=f.get("rgb"),l=f.get("a")):(j=a[1],l=1);t.push(a[0]*100+"% "+j);b?(u=l,o=j):(p=l,G=j)});if(c==="fill")if(i==="gradient")c=m.x1||m[0]||0,a=m.y1||m[1]||0,n=m.x2||m[2]||0,m=m.y2||m[3]||0,x='angle="'+(90-V.atan((m-a)/(n-c))*180/ra)+'"',s();else{var k=m.r,w=k*2,v=k*2,y=m.cx,D=m.cy,U=b.radialReference,z,k=function(){U&&(z=d.getBBox(),y+=(U[0]-z.x)/z.width-0.5,D+=(U[1]-z.y)/z.height-0.5,w*=U[2]/z.width,v*=U[2]/z.height);x='src="'+F.global.VMLRadialGradientURL+'" size="'+w+","+v+'" origin="0.5,0.5" position="'+ +y+","+D+'" color2="'+G+'" ';s()};d.added?k():d.onAdd=k;k=o}else k=j}else if(g.test(a)&&b.tagName!=="IMG")f=Fa(a),h=["<",c,' opacity="',f.get("a"),'"/>'],$(this.prepVML(h),null,null,b),k=f.get("rgb");else{k=b.getElementsByTagName(c);if(k.length)k[0].opacity=1,k[0].type="solid";k=a}return k},prepVML:function(a){var b=this.isIE8,a=a.join("");b?(a=a.replace("/>",' xmlns="urn:schemas-microsoft-com:vml" />'),a=a.indexOf('style="')===-1?a.replace("/>",' style="display:inline-block;behavior:url(#default#VML);" />'): +a.replace('style="','style="display:inline-block;behavior:url(#default#VML);')):a=a.replace("<","1&&f.attr({x:b,y:c,width:d,height:e});return f},createElement:function(a){return a==="rect"?this.symbol(a):ka.prototype.createElement.call(this,a)},invertChild:function(a,b){var c=this,d=b.style,e=a.tagName==="IMG"&&a.style;E(a,{flip:"x",left:I(d.width)-(e?I(e.top):1),top:I(d.height)-(e?I(e.left):1),rotation:-90});q(a.childNodes,function(b){c.invertChild(b,a)})},symbols:{arc:function(a,b,c,d,e){var f=e.start,g=e.end,h=e.r||c|| +d,c=e.innerR,d=da(f),i=ia(f),k=da(g),j=ia(g);if(g-f===0)return["x"];f=["wa",a-h,b-h,a+h,b+h,a+h*d,b+h*i,a+h*k,b+h*j];e.open&&!c&&f.push("e","M",a,b);f.push("at",a-c,b-c,a+c,b+c,a+c*k,b+c*j,a+c*d,b+c*i,"x","e");f.isArc=!0;return f},circle:function(a,b,c,d,e){e&&(c=d=2*e.r);e&&e.isCircle&&(a-=c/2,b-=d/2);return["wa",a,b,a+c,b+d,a+c,b+d/2,a+c,b+d/2,"e"]},rect:function(a,b,c,d,e){return ka.prototype.symbols[!t(e)||!e.r?"square":"callout"].call(0,a,b,c,d,e)}}},P.VMLRenderer=fb=function(){this.init.apply(this, +arguments)},fb.prototype=y(ka.prototype,ea),Wa=fb;ka.prototype.measureSpanWidth=function(a,b){var c=B.createElement("span"),d;d=B.createTextNode(a);c.appendChild(d);E(c,b);this.box.appendChild(c);d=c.offsetWidth;Sa(c);return d};var Vb;if(ja)P.CanVGRenderer=ea=function(){Ea="http://www.w3.org/1999/xhtml"},ea.prototype.symbols={},Vb=function(){function a(){var a=b.length,d;for(d=0;dl[p]?l[p]=g+k:m||(c=!1);if(m){l=(m=d.justifyToPlot)?d.pos:0;m=m?l+d.len:d.chart.chartWidth;do a+=e?1:-1,n=d.ticks[i[a]];while(i[a]&&(!n||n.label.line!==p));d=n&& +n.label.xy&&n.label.xy.x+n.getLabelSides()[e?0:1];e&&!h||f&&h?g+jd&&(c=!1)):g+k>m&&(g=m-k,n&&g+j0&&b.height>0){f=y({align:c&&j&&"center",x:c?!j&&4:10,verticalAlign:!c&&j&&"middle",y:c?j?16:10:j?6:-4,rotation:c&&!j&&90},f);if(!g){r={align:f.textAlign||f.align,rotation:f.rotation};if(t(G))r.zIndex=G;a.label=g=s.text(f.text,0,0,f.useHTML).attr(r).css(f.style).add()}b=[p[1],p[4],o(p[6],p[1])];p=[p[2],p[5],o(p[7],p[2])];c=Ra(b);j=Ra(p);g.align(f,!1,{x:c,y:j,width:Ba(b)-c,height:Ba(p)-j});g.show()}else g&& +g.hide();return a},destroy:function(){pa(this.axis.plotLinesAndBands,this);delete this.axis;Ka(this)}};L.prototype={defaultOptions:{dateTimeLabelFormats:{millisecond:"%H:%M:%S.%L",second:"%H:%M:%S",minute:"%H:%M",hour:"%H:%M",day:"%e. %b",week:"%e. %b",month:"%b '%y",year:"%Y"},endOnTick:!1,gridLineColor:"#C0C0C0",labels:Q,lineColor:"#C0D0E0",lineWidth:1,minPadding:0.01,maxPadding:0.01,minorGridLineColor:"#E0E0E0",minorGridLineWidth:1,minorTickColor:"#A0A0A0",minorTickLength:2,minorTickPosition:"outside", +startOfWeek:1,startOnTick:!1,tickColor:"#C0D0E0",tickLength:10,tickmarkPlacement:"between",tickPixelInterval:100,tickPosition:"outside",tickWidth:1,title:{align:"middle",style:{color:"#707070"}},type:"linear"},defaultYAxisOptions:{endOnTick:!0,gridLineWidth:1,tickPixelInterval:72,showLastLabel:!0,labels:{x:-8,y:3},lineWidth:0,maxPadding:0.05,minPadding:0.05,startOnTick:!0,tickWidth:0,title:{rotation:270,text:"Values"},stackLabels:{enabled:!1,formatter:function(){return Ia(this.total,-1)},style:Q.style}}, +defaultLeftAxisOptions:{labels:{x:-15,y:null},title:{rotation:270}},defaultRightAxisOptions:{labels:{x:15,y:null},title:{rotation:90}},defaultBottomAxisOptions:{labels:{x:0,y:20},title:{rotation:0}},defaultTopAxisOptions:{labels:{x:0,y:-15},title:{rotation:0}},init:function(a,b){var c=b.isX;this.horiz=a.inverted?!c:c;this.coll=(this.isXAxis=c)?"xAxis":"yAxis";this.opposite=b.opposite;this.side=b.side||(this.horiz?this.opposite?0:2:this.opposite?1:3);this.setOptions(b);var d=this.options,e=d.type; +this.labelFormatter=d.labels.formatter||this.defaultLabelFormatter;this.userOptions=b;this.minPixelPadding=0;this.chart=a;this.reversed=d.reversed;this.zoomEnabled=d.zoomEnabled!==!1;this.categories=d.categories||e==="category";this.names=[];this.isLog=e==="logarithmic";this.isDatetimeAxis=e==="datetime";this.isLinked=t(d.linkedTo);this.tickmarkOffset=this.categories&&d.tickmarkPlacement==="between"?0.5:0;this.ticks={};this.labelEdge=[];this.minorTicks={};this.plotLinesAndBands=[];this.alternateBands= +{};this.len=0;this.minRange=this.userMinRange=d.minRange||d.maxZoom;this.range=d.range;this.offset=d.offset||0;this.stacks={};this.oldStacks={};this.min=this.max=null;this.crosshair=o(d.crosshair,ma(a.options.tooltip.crosshairs)[c?0:1],!1);var f,d=this.options.events;wa(this,a.axes)===-1&&(c&&!this.isColorAxis?a.axes.splice(a.xAxis.length,0,this):a.axes.push(this),a[this.coll].push(this));this.series=this.series||[];if(a.inverted&&c&&this.reversed===r)this.reversed=!0;this.removePlotLine=this.removePlotBand= +this.removePlotBandOrLine;for(f in d)A(this,f,d[f]);if(this.isLog)this.val2lin=Ga,this.lin2val=oa},setOptions:function(a){this.options=y(this.defaultOptions,this.isXAxis?{}:this.defaultYAxisOptions,[this.defaultTopAxisOptions,this.defaultRightAxisOptions,this.defaultBottomAxisOptions,this.defaultLeftAxisOptions][this.side],y(F[this.coll],a))},defaultLabelFormatter:function(){var a=this.axis,b=this.value,c=a.categories,d=this.dateTimeLabelFormat,e=F.lang.numericSymbols,f=e&&e.length,g,h=a.options.labels.format, +a=a.isLog?b:a.tickInterval;if(h)g=Ja(h,this);else if(c)g=b;else if(d)g=ua(d,b);else if(f&&a>=1E3)for(;f--&&g===r;)c=Math.pow(1E3,f+1),a>=c&&e[f]!==null&&(g=Ia(b/c,-1)+e[f]);g===r&&(g=M(b)>=1E4?Ia(b,0):Ia(b,-1,r,""));return g},getSeriesExtremes:function(){var a=this,b=a.chart;a.hasVisibleSeries=!1;a.dataMin=a.dataMax=null;a.buildStacks&&a.buildStacks();q(a.series,function(c){if(c.visible||!b.options.chart.ignoreHiddenSeries){var d;d=c.options.threshold;var e;a.hasVisibleSeries=!0;a.isLog&&d<=0&&(d= +null);if(a.isXAxis){if(d=c.xData,d.length)a.dataMin=z(o(a.dataMin,d[0]),Ra(d)),a.dataMax=w(o(a.dataMax,d[0]),Ba(d))}else{c.getExtremes();e=c.dataMax;c=c.dataMin;if(t(c)&&t(e))a.dataMin=z(o(a.dataMin,c),c),a.dataMax=w(o(a.dataMax,e),e);if(t(d))if(a.dataMin>=d)a.dataMin=d,a.ignoreMinPadding=!0;else if(a.dataMaxg+this.width)m=!0}else if(a=g,c=l-this.right,ih+this.height)m=!0;return m&&!d?null:f.renderer.crispLine(["M",a,i,"L",c,k],b||1)},getLinearTickPositions:function(a,b,c){var d,e=ha(S(b/a)*a),f=ha(Va(c/a)*a),g=[];if(b===c&&la(b))return[b];for(b=e;b<=f;){g.push(b);b=ha(b+ +a);if(b===d)break;d=b}return g},getMinorTickPositions:function(){var a=this.options,b=this.tickPositions,c=this.minorTickInterval,d=[],e;if(this.isLog){e=b.length;for(a=1;a=this.minRange,f,g,h,i,k;if(this.isXAxis&&this.minRange===r&&!this.isLog)t(a.min)||t(a.max)?this.minRange=null:(q(this.series,function(a){i=a.xData;for(g=k=a.xIncrement?1:i.length-1;g>0;g--)if(h=i[g]-i[g-1],f===r||hc&&(h=0);d=w(d,h);f=w(f,Oa(k)?0:h/2);g=w(g,k==="on"?0:h);!a.noSharedTooltip&&t(n)&&(e=t(e)?z(e,n):n)}),h=b.ordinalSlope&& +e?b.ordinalSlope/e:1,b.minPointOffset=f*=h,b.pointRangePadding=g*=h,b.pointRange=z(d,c),b.closestPointRange=e;if(a)b.oldTransA=k;b.translationSlope=b.transA=k=b.len/(c+g||1);b.transB=b.horiz?b.left:b.bottom;b.minPixelPadding=k*f},setTickPositions:function(a){var b=this,c=b.chart,d=b.options,e=b.isLog,f=b.isDatetimeAxis,g=b.isXAxis,h=b.isLinked,i=b.options.tickPositioner,k=d.maxPadding,j=d.minPadding,l=d.tickInterval,m=d.minTickInterval,n=d.tickPixelInterval,p,u=b.categories;h?(b.linkedParent=c[b.coll][d.linkedTo], +c=b.linkedParent.getExtremes(),b.min=o(c.min,c.dataMin),b.max=o(c.max,c.dataMax),d.type!==b.linkedParent.options.type&&qa(11,1)):(b.min=o(b.userMin,d.min,b.dataMin),b.max=o(b.userMax,d.max,b.dataMax));if(e)!a&&z(b.min,o(b.dataMin,b.min))<=0&&qa(10,1),b.min=ha(Ga(b.min)),b.max=ha(Ga(b.max));if(b.range&&t(b.max))b.userMin=b.min=w(b.min,b.max-b.range),b.userMax=b.max,b.range=null;b.beforePadding&&b.beforePadding();b.adjustForMinRange();if(!u&&!b.axisPointRange&&!b.usePercentage&&!h&&t(b.min)&&t(b.max)&& +(c=b.max-b.min)){if(!t(d.min)&&!t(b.userMin)&&j&&(b.dataMin<0||!b.ignoreMinPadding))b.min-=c*j;if(!t(d.max)&&!t(b.userMax)&&k&&(b.dataMax>0||!b.ignoreMaxPadding))b.max+=c*k}if(la(d.floor))b.min=w(b.min,d.floor);if(la(d.ceiling))b.max=z(b.max,d.ceiling);b.min===b.max||b.min===void 0||b.max===void 0?b.tickInterval=1:h&&!l&&n===b.linkedParent.options.tickPixelInterval?b.tickInterval=b.linkedParent.tickInterval:(b.tickInterval=o(l,u?1:(b.max-b.min)*n/w(b.len,n)),!t(l)&&b.lenw(2*b.len,200)&&qa(19,!0),a=f?b.getTimeTicks(b.normalizeTimeTickInterval(b.tickInterval,d.units),b.min,b.max,d.startOfWeek,b.ordinalPositions,b.closestPointRange,!0):e?b.getLogTickPositions(b.tickInterval,b.min,b.max):b.getLinearTickPositions(b.tickInterval,b.min,b.max),p&& +a.splice(1,a.length-2),b.tickPositions=a;if(!h)e=a[0],f=a[a.length-1],h=b.minPointOffset||0,d.startOnTick?b.min=e:b.min-h>e&&a.shift(),d.endOnTick?b.max=f:b.max+h1E13?1:0.001,b.min-=d,b.max+=d)},setMaxTicks:function(){var a=this.chart,b=a.maxTicks||{},c=this.tickPositions,d=this._maxTicksKey=[this.coll,this.pos,this.len].join("-");if(!this.isLinked&&!this.isDatetimeAxis&&c&&c.length>(b[d]||0)&&this.options.alignTicks!==!1)b[d]=c.length;a.maxTicks=b},adjustTickAmount:function(){var a= +this._maxTicksKey,b=this.tickPositions,c=this.chart.maxTicks;if(c&&c[a]&&!this.isDatetimeAxis&&!this.categories&&!this.isLinked&&this.options.alignTicks!==!1&&this.min!==r){var d=this.tickAmount,e=b.length;this.tickAmount=a=c[a];if(e=w(d,o(e.max,d))&&(b=r));this.displayBtn=a!==r||b!==r;this.setExtremes(a,b,!1,r, +{trigger:"zoom"});return!0},setAxisSize:function(){var a=this.chart,b=this.options,c=b.offsetLeft||0,d=this.horiz,e=o(b.width,a.plotWidth-c+(b.offsetRight||0)),f=o(b.height,a.plotHeight),g=o(b.top,a.plotTop),b=o(b.left,a.plotLeft+c),c=/%$/;c.test(f)&&(f=parseInt(f,10)/100*a.plotHeight);c.test(g)&&(g=parseInt(g,10)/100*a.plotHeight+a.plotTop);this.left=b;this.top=g;this.width=e;this.height=f;this.bottom=a.chartHeight-f-g;this.right=a.chartWidth-e-b;this.len=w(d?e:f,0);this.pos=d?b:g},getExtremes:function(){var a= +this.isLog;return{min:a?ha(oa(this.min)):this.min,max:a?ha(oa(this.max)):this.max,dataMin:this.dataMin,dataMax:this.dataMax,userMin:this.userMin,userMax:this.userMax}},getThreshold:function(a){var b=this.isLog,c=b?oa(this.min):this.min,b=b?oa(this.max):this.max;c>a||a===null?a=c:b15&&a<165?"right":a>195&&a<345?"left":"center"},getOffset:function(){var a=this,b=a.chart,c=b.renderer,d=a.options, +e=a.tickPositions,f=a.ticks,g=a.horiz,h=a.side,i=b.inverted?[1,0,3,2][h]:h,k,j=0,l,m=0,n=d.title,p=d.labels,u=0,Db=b.axisOffset,G=b.clipOffset,x=[-1,1,1,-1][h],s,v=1,y=o(p.maxStaggerLines,5),z,A,B,D,U=h===2?c.fontMetrics(p.style.fontSize).b:0;a.hasData=k=a.hasVisibleSeries||t(a.min)&&t(a.max)&&!!e;a.showAxis=b=k||o(d.showEmpty,!0);a.staggerLines=a.horiz&&p.staggerLines;if(!a.axisGroup)a.gridGroup=c.g("grid").attr({zIndex:d.gridZIndex||1}).add(),a.axisGroup=c.g("axis").attr({zIndex:d.zIndex||2}).add(), +a.labelGroup=c.g("axis-labels").attr({zIndex:p.zIndex||7}).addClass("highcharts-"+a.coll.toLowerCase()+"-labels").add();if(k||a.isLinked){a.labelAlign=o(p.align||a.autoLabelAlign(p.rotation));q(e,function(b){f[b]?f[b].addLabel():f[b]=new Za(a,b)});if(a.horiz&&!a.staggerLines&&y&&!p.rotation){for(s=a.reversed?[].concat(e).reverse():e;v1)a.staggerLines=v}q(e,function(b){if(h===0||h===2||{1:"left",3:"right"}[h]===a.labelAlign)u=w(f[b].getLabelSize(),u)});if(a.staggerLines)u*=a.staggerLines,a.labelOffset=u}else for(s in f)f[s].destroy(),delete f[s];if(n&&n.text&&n.enabled!==!1){if(!a.axisTitle)a.axisTitle=c.text(n.text,0,0,n.useHTML).attr({zIndex:7,rotation:n.rotation||0,align:n.textAlign||{low:"left",middle:"center",high:"right"}[n.align]}).addClass("highcharts-"+this.coll.toLowerCase()+"-title").css(n.style).add(a.axisGroup), +a.axisTitle.isNew=!0;if(b)j=a.axisTitle.getBBox()[g?"height":"width"],m=o(n.margin,g?5:10),l=n.offset;a.axisTitle[b?"show":"hide"]()}a.offset=x*o(d.offset,Db[h]);a.axisTitleMargin=o(l,u+m+(u&&x*d.labels[g?"y":"x"]-U));Db[h]=w(Db[h],a.axisTitleMargin+j+x*a.offset);G[i]=w(G[i],S(d.lineWidth/2)*2)},getLinePath:function(a){var b=this.chart,c=this.opposite,d=this.offset,e=this.horiz,f=this.left+(c?this.width:0)+d,d=b.chartHeight-this.bottom-(c?this.height:0)+d;c&&(a*=-1);return b.renderer.crispLine(["M", +e?this.left:f,e?d:this.top,"L",e?b.chartWidth-this.right:f,e?d:b.chartHeight-this.bottom],a)},getTitlePosition:function(){var a=this.horiz,b=this.left,c=this.top,d=this.len,e=this.options.title,f=a?b:c,g=this.opposite,h=this.offset,i=I(e.style.fontSize||12),d={low:f+(a?0:d),middle:f+d/2,high:f+(a?d:0)}[e.align],b=(a?c+this.height:b)+(a?1:-1)*(g?-1:1)*this.axisTitleMargin+(this.side===2?i:0);return{x:a?d:b+(g?this.width:0)+h+(e.x||0),y:a?b-(g?this.height:0)+h:d+(e.y||0)}},render:function(){var a=this, +b=a.horiz,c=a.reversed,d=a.chart,e=d.renderer,f=a.options,g=a.isLog,h=a.isLinked,i=a.tickPositions,k,j=a.axisTitle,l=a.ticks,m=a.minorTicks,n=a.alternateBands,p=f.stackLabels,u=f.alternateGridColor,o=a.tickmarkOffset,G=f.lineWidth,x=d.hasRendered&&t(a.oldMin)&&!isNaN(a.oldMin),s=a.hasData,w=a.showAxis,v,y=f.labels.overflow,z=a.justifyLabels=b&&y!==!1,A;a.labelEdge.length=0;a.justifyToPlot=y==="justify";q([l,m,n],function(a){for(var b in a)a[b].isActive=!1});if(s||h)if(a.minorTickInterval&&!a.categories&& +q(a.getMinorTickPositions(),function(b){m[b]||(m[b]=new Za(a,b,"minor"));x&&m[b].isNew&&m[b].render(null,!0);m[b].render(null,!1,1)}),i.length&&(k=i.slice(),(b&&c||!b&&!c)&&k.reverse(),z&&(k=k.slice(1).concat([k[0]])),q(k,function(b,c){z&&(c=c===k.length-1?0:c+1);if(!h||b>=a.min&&b<=a.max)l[b]||(l[b]=new Za(a,b)),x&&l[b].isNew&&l[b].render(c,!0,0.1),l[b].render(c,!1,1)}),o&&a.min===0&&(l[-1]||(l[-1]=new Za(a,-1,null,!0)),l[-1].render(-1))),u&&q(i,function(b,c){if(c%2===0&&b=H.second&&(i.setMilliseconds(0),i.setSeconds(k>=H.minute?0:j*S(i.getSeconds()/j)));if(k>=H.minute)i[Nb](k>= +H.hour?0:j*S(i[ub]()/j));if(k>=H.hour)i[Ob](k>=H.day?0:j*S(i[vb]()/j));if(k>=H.day)i[xb](k>=H.month?1:j*S(i[Ua]()/j));k>=H.month&&(i[Pb](k>=H.year?0:j*S(i[jb]()/j)),h=i[kb]());k>=H.year&&(h-=h%j,i[Qb](h));if(k===H.week)i[xb](i[Ua]()-i[wb]()+o(d,1));b=1;La&&(i=new Date(i.getTime()+La));h=i[kb]();for(var d=i.getTime(),l=i[jb](),m=i[Ua](),n=g?La:(864E5+i.getTimezoneOffset()*6E4)%864E5;d=0.5)a=s(a),g=this.getLinearTickPositions(a,b,c);else if(a>=0.08)for(var f=S(b),h,i,k,j,l,e=a>0.3?[1,2,4]:a>0.15?[1,2,4,6,8]:[1,2,3,4,5,6,7,8,9];fb&&(!d|| +j<=c)&&g.push(j),j>c&&(l=!0),j=k}else if(b=oa(b),c=oa(c),a=e[d?"minorTickInterval":"tickInterval"],a=o(a==="auto"?null:a,this._minorAutoInterval,(c-b)*(e.tickPixelInterval/(d?5:1))/((d?f/this.tickPositions.length:f)||1)),a=sb(a,null,rb(a)),g=xa(this.getLinearTickPositions(a,b,c),Ga),!d)this._minorAutoInterval=a/5;if(!d)this.tickInterval=a;return g};var Hb=P.Tooltip=function(){this.init.apply(this,arguments)};Hb.prototype={init:function(a,b){var c=b.borderWidth,d=b.style,e=I(d.padding);this.chart= +a;this.options=b;this.crosshairs=[];this.now={x:0,y:0};this.isHidden=!0;this.label=a.renderer.label("",0,0,b.shape||"callout",null,null,b.useHTML,null,"tooltip").attr({padding:e,fill:b.backgroundColor,"stroke-width":c,r:b.borderRadius,zIndex:8}).css(d).css({padding:0}).add().attr({y:-9999});ja||this.label.shadow(b.shadow);this.shared=b.shared},destroy:function(){if(this.label)this.label=this.label.destroy();clearTimeout(this.hideTimer);clearTimeout(this.tooltipTimeout)},move:function(a,b,c,d){var e= +this,f=e.now,g=e.options.animation!==!1&&!e.isHidden,h=e.followPointer||e.len>1;v(f,{x:g?(2*f.x+a)/3:a,y:g?(f.y+b)/2:b,anchorX:h?r:g?(2*f.anchorX+c)/3:c,anchorY:h?r:g?(f.anchorY+d)/2:d});e.label.attr(f);if(g&&(M(a-f.x)>1||M(b-f.y)>1))clearTimeout(this.tooltipTimeout),this.tooltipTimeout=setTimeout(function(){e&&e.move(a,b,c,d)},32)},hide:function(){var a=this,b;clearTimeout(this.hideTimer);if(!this.isHidden)b=this.chart.hoverPoints,this.hideTimer=setTimeout(function(){a.label.fadeOut();a.isHidden= +!0},o(this.options.hideDelay,500)),b&&q(b,function(a){a.setState()}),this.chart.hoverPoints=null},getAnchor:function(a,b){var c,d=this.chart,e=d.inverted,f=d.plotTop,g=0,h=0,i,a=ma(a);c=a[0].tooltipPos;this.followPointer&&b&&(b.chartX===r&&(b=d.pointer.normalize(b)),c=[b.chartX-d.plotLeft,b.chartY-f]);c||(q(a,function(a){i=a.series.yAxis;g+=a.plotX;h+=(a.plotLow?(a.plotLow+a.plotHigh)/2:a.plotY)+(!e&&i?i.top-f:0)}),g/=a.length,h/=a.length,c=[e?d.plotWidth-h:g,this.shared&&!e&&a.length>1&&b?b.chartY- +f:e?d.plotHeight-g:h]);return xa(c,s)},getPosition:function(a,b,c){var d=this.chart,e=this.distance,f={},g,h=["y",d.chartHeight,b,c.plotY+d.plotTop],i=["x",d.chartWidth,a,c.plotX+d.plotLeft],k=c.ttBelow||d.inverted&&!c.negative||!d.inverted&&c.negative,j=function(a,b,c,d){var g=cb-e)return!1;else f[a]=db-c/2?b-c-2:d-c/2},m=function(a){var b=h;h=i; +i=b;g=a},n=function(){j.apply(0,h)!==!1?l.apply(0,i)===!1&&!g&&(m(!0),n()):g?f.x=f.y=0:(m(!0),n())};(d.inverted||this.len>1)&&m();n();return f},defaultFormatter:function(a){var b=this.points||ma(this),c=b[0].series,d;d=[a.tooltipHeaderFormatter(b[0])];q(b,function(a){c=a.series;d.push(c.tooltipFormatter&&c.tooltipFormatter(a)||a.point.tooltipFormatter(c.tooltipOptions.pointFormat))});d.push(a.options.footerFormat||"");return d.join("")},refresh:function(a,b){var c=this.chart,d=this.label,e=this.options, +f,g,h={},i,k=[];i=e.formatter||this.defaultFormatter;var h=c.hoverPoints,j,l=this.shared;clearTimeout(this.hideTimer);this.followPointer=ma(a)[0].series.tooltipOptions.followPointer;g=this.getAnchor(a,b);f=g[0];g=g[1];l&&(!a.series||!a.series.noSharedTooltip)?(c.hoverPoints=a,h&&q(h,function(a){a.setState()}),q(a,function(a){a.setState("hover");k.push(a.getLabelConfig())}),h={x:a[0].category,y:a[0].y},h.points=k,this.len=k.length,a=a[0]):h=a.getLabelConfig();i=i.call(h,this);h=a.series;this.distance= +o(h.tooltipOptions.distance,16);i===!1?this.hide():(this.isHidden&&(eb(d),d.attr("opacity",1).show()),d.attr({text:i}),j=e.borderColor||a.color||h.color||"#606060",d.attr({stroke:j}),this.updatePosition({plotX:f,plotY:g,negative:a.negative,ttBelow:a.ttBelow}),this.isHidden=!1);N(c,"tooltipRefresh",{text:i,x:f+c.plotLeft,y:g+c.plotTop,borderColor:j})},updatePosition:function(a){var b=this.chart,c=this.label,c=(this.options.positioner||this.getPosition).call(this,c.width,c.height,a);this.move(s(c.x), +s(c.y),a.plotX+b.plotLeft,a.plotY+b.plotTop)},tooltipHeaderFormatter:function(a){var b=a.series,c=b.tooltipOptions,d=c.dateTimeLabelFormats,e=c.xDateFormat,f=b.xAxis,g=f&&f.options.type==="datetime"&&la(a.key),c=c.headerFormat,f=f&&f.closestPointRange,h;if(g&&!e){if(f)for(h in H){if(H[h]>=f||H[h]<=H.day&&a.key%H[h]>0){e=d[h];break}}else e=d.day;e=e||d.year}g&&e&&(c=c.replace("{point.key}","{point.key:"+e+"}"));return Ja(c,{point:a,series:b})}};var sa;ab=B.documentElement.ontouchstart!==r;var Xa=P.Pointer= +function(a,b){this.init(a,b)};Xa.prototype={init:function(a,b){var c=b.chart,d=c.events,e=ja?"":c.zoomType,c=a.inverted,f;this.options=b;this.chart=a;this.zoomX=f=/x/.test(e);this.zoomY=e=/y/.test(e);this.zoomHor=f&&!c||e&&c;this.zoomVert=e&&!c||f&&c;this.hasZoom=f||e;this.runChartClick=d&&!!d.click;this.pinchDown=[];this.lastValidTouch={};if(P.Tooltip&&b.tooltip.enabled)a.tooltip=new Hb(a,b.tooltip),this.followTouchMove=b.tooltip.followTouchMove;this.setDOMEvents()},normalize:function(a,b){var c, +d,a=a||window.event,a=cc(a);if(!a.target)a.target=a.srcElement;d=a.touches?a.touches.length?a.touches.item(0):a.changedTouches[0]:a;if(!b)this.chartPosition=b=bc(this.chart.container);d.pageX===r?(c=w(a.x,a.clientX-b.left),d=a.y):(c=d.pageX-b.left,d=d.pageY-b.top);return v(a,{chartX:s(c),chartY:s(d)})},getCoordinates:function(a){var b={xAxis:[],yAxis:[]};q(this.chart.axes,function(c){b[c.isXAxis?"xAxis":"yAxis"].push({axis:c,value:c.toValue(a[c.horiz?"chartX":"chartY"])})});return b},getIndex:function(a){var b= +this.chart;return b.inverted?b.plotHeight+b.plotTop-a.chartY:a.chartX-b.plotLeft},runPointActions:function(a){var b=this.chart,c=b.series,d=b.tooltip,e,f,g=b.hoverPoint,h=b.hoverSeries,i,k,j=b.chartWidth,l=this.getIndex(a);if(d&&this.options.tooltip.shared&&(!h||!h.noSharedTooltip)){f=[];i=c.length;for(k=0;kj&&f.splice(i,1);if(f.length&&f[0].clientX!==this.hoverX)d.refresh(f,a),this.hoverX=f[0].clientX}c=h&&h.tooltipOptions.followPointer;if(h&&h.tracker&&!c){if((e=h.tooltipPoints[l])&&e!==g)e.onMouseOver(a)}else d&&c&&!d.isHidden&&(h=d.getAnchor([{}],a),d.updatePosition({plotX:h[0],plotY:h[1]}));if(d&&!this._onDocumentMouseMove)this._onDocumentMouseMove=function(a){if(aa[sa])aa[sa].pointer.onDocumentMouseMove(a)},A(B,"mousemove",this._onDocumentMouseMove); +q(b.axes,function(b){b.drawCrosshair(a,o(e,g))})},reset:function(a){var b=this.chart,c=b.hoverSeries,d=b.hoverPoint,e=b.tooltip,f=e&&e.shared?b.hoverPoints:d;(a=a&&e&&f)&&ma(f)[0].plotX===r&&(a=!1);if(a)e.refresh(f),d&&d.setState(d.state,!0);else{if(d)d.onMouseOut();if(c)c.onMouseOut();e&&e.hide();if(this._onDocumentMouseMove)R(B,"mousemove",this._onDocumentMouseMove),this._onDocumentMouseMove=null;q(b.axes,function(a){a.hideCrosshair()});this.hoverX=null}},scaleGroups:function(a,b){var c=this.chart, +d;q(c.series,function(e){d=a||e.getPlotBox();e.xAxis&&e.xAxis.zoomEnabled&&(e.group.attr(d),e.markerGroup&&(e.markerGroup.attr(d),e.markerGroup.clip(b?c.clipRect:null)),e.dataLabelsGroup&&e.dataLabelsGroup.attr(d))});c.clipRect.attr(b||c.clipBox)},dragStart:function(a){var b=this.chart;b.mouseIsDown=a.type;b.cancelClick=!1;b.mouseDownX=this.mouseDownX=a.chartX;b.mouseDownY=this.mouseDownY=a.chartY},drag:function(a){var b=this.chart,c=b.options.chart,d=a.chartX,e=a.chartY,f=this.zoomHor,g=this.zoomVert, +h=b.plotLeft,i=b.plotTop,k=b.plotWidth,j=b.plotHeight,l,m=this.mouseDownX,n=this.mouseDownY;dh+k&&(d=h+k);ei+j&&(e=i+j);this.hasDragged=Math.sqrt(Math.pow(m-d,2)+Math.pow(n-e,2));if(this.hasDragged>10){l=b.isInsidePlot(m-h,n-i);if(b.hasCartesianSeries&&(this.zoomX||this.zoomY)&&l&&!this.selectionMarker)this.selectionMarker=b.renderer.rect(h,i,f?1:k,g?1:j,0).attr({fill:c.selectionMarkerFill||"rgba(69,114,167,0.25)",zIndex:7}).add();this.selectionMarker&&f&&(d-=m,this.selectionMarker.attr({width:M(d), +x:(d>0?0:d)+m}));this.selectionMarker&&g&&(d=e-n,this.selectionMarker.attr({height:M(d),y:(d>0?0:d)+n}));l&&!this.selectionMarker&&c.panning&&b.pan(a,c.panning)}},drop:function(a){var b=this.chart,c=this.hasPinched;if(this.selectionMarker){var d={xAxis:[],yAxis:[],originalEvent:a.originalEvent||a},a=this.selectionMarker,e=a.attr?a.attr("x"):a.x,f=a.attr?a.attr("y"):a.y,g=a.attr?a.attr("width"):a.width,h=a.attr?a.attr("height"):a.height,i;if(this.hasDragged||c)q(b.axes,function(a){if(a.zoomEnabled){var b= +a.horiz,c=a.toValue(b?e:f),b=a.toValue(b?e+g:f+h);!isNaN(c)&&!isNaN(b)&&(d[a.coll].push({axis:a,min:z(c,b),max:w(c,b)}),i=!0)}}),i&&N(b,"selection",d,function(a){b.zoom(v(a,c?{animation:!1}:null))});this.selectionMarker=this.selectionMarker.destroy();c&&this.scaleGroups()}if(b)E(b.container,{cursor:b._cursor}),b.cancelClick=this.hasDragged>10,b.mouseIsDown=this.hasDragged=this.hasPinched=!1,this.pinchDown=[]},onContainerMouseDown:function(a){a=this.normalize(a);a.preventDefault&&a.preventDefault(); +this.dragStart(a)},onDocumentMouseUp:function(a){aa[sa]&&aa[sa].pointer.drop(a)},onDocumentMouseMove:function(a){var b=this.chart,c=this.chartPosition,d=b.hoverSeries,a=this.normalize(a,c);c&&d&&!this.inClass(a.target,"highcharts-tracker")&&!b.isInsidePlot(a.chartX-b.plotLeft,a.chartY-b.plotTop)&&this.reset()},onContainerMouseLeave:function(){var a=aa[sa];if(a)a.pointer.reset(),a.pointer.chartPosition=null},onContainerMouseMove:function(a){var b=this.chart;sa=b.index;a=this.normalize(a);b.mouseIsDown=== +"mousedown"&&this.drag(a);(this.inClass(a.target,"highcharts-tracker")||b.isInsidePlot(a.chartX-b.plotLeft,a.chartY-b.plotTop))&&!b.openMenu&&this.runPointActions(a)},inClass:function(a,b){for(var c;a;){if(c=W(a,"class"))if(c.indexOf(b)!==-1)return!0;else if(c.indexOf("highcharts-container")!==-1)return!1;a=a.parentNode}},onTrackerMouseOut:function(a){var b=this.chart.hoverSeries,c=(a=a.relatedTarget||a.toElement)&&a.point&&a.point.series;if(b&&!b.options.stickyTracking&&!this.inClass(a,"highcharts-tooltip")&& +c!==b)b.onMouseOut()},onContainerClick:function(a){var b=this.chart,c=b.hoverPoint,d=b.plotLeft,e=b.plotTop,a=this.normalize(a);a.cancelBubble=!0;b.cancelClick||(c&&this.inClass(a.target,"highcharts-tracker")?(N(c.series,"click",v(a,{point:c})),b.hoverPoint&&c.firePointEvent("click",a)):(v(a,this.getCoordinates(a)),b.isInsidePlot(a.chartX-d,a.chartY-e)&&N(b,"click",a)))},setDOMEvents:function(){var a=this,b=a.chart.container;b.onmousedown=function(b){a.onContainerMouseDown(b)};b.onmousemove=function(b){a.onContainerMouseMove(b)}; +b.onclick=function(b){a.onContainerClick(b)};A(b,"mouseleave",a.onContainerMouseLeave);db===1&&A(B,"mouseup",a.onDocumentMouseUp);if(ab)b.ontouchstart=function(b){a.onContainerTouchStart(b)},b.ontouchmove=function(b){a.onContainerTouchMove(b)},db===1&&A(B,"touchend",a.onDocumentTouchEnd)},destroy:function(){var a;R(this.chart.container,"mouseleave",this.onContainerMouseLeave);db||(R(B,"mouseup",this.onDocumentMouseUp),R(B,"touchend",this.onDocumentTouchEnd));clearInterval(this.tooltipTimeout);for(a in this)this[a]= +null}};v(P.Pointer.prototype,{pinchTranslate:function(a,b,c,d,e,f){(this.zoomHor||this.pinchHor)&&this.pinchTranslateDirection(!0,a,b,c,d,e,f);(this.zoomVert||this.pinchVert)&&this.pinchTranslateDirection(!1,a,b,c,d,e,f)},pinchTranslateDirection:function(a,b,c,d,e,f,g,h){var i=this.chart,k=a?"x":"y",j=a?"X":"Y",l="chart"+j,m=a?"width":"height",n=i["plot"+(a?"Left":"Top")],p,u,o=h||1,q=i.inverted,x=i.bounds[a?"h":"v"],r=b.length===1,s=b[0][l],t=c[0][l],w=!r&&b[1][l],v=!r&&c[1][l],y,c=function(){!r&& +M(s-w)>20&&(o=h||M(t-v)/M(s-w));u=(n-t)/o+s;p=i["plot"+(a?"Width":"Height")]/o};c();b=u;bx.max&&(b=x.max-p,y=!0);y?(t-=0.8*(t-g[k][0]),r||(v-=0.8*(v-g[k][1])),c()):g[k]=[t,v];q||(f[k]=u-n,f[m]=p);f=q?1/o:o;e[m]=p;e[k]=b;d[q?a?"scaleY":"scaleX":"scale"+j]=o;d["translate"+j]=f*n+(t-f*s)},pinch:function(a){var b=this,c=b.chart,d=b.pinchDown,e=b.followTouchMove,f=a.touches,g=f.length,h=b.lastValidTouch,i=b.hasZoom,k=b.selectionMarker,j={},l=g===1&&(b.inClass(a.target,"highcharts-tracker")&& +c.runTrackerClick||c.runChartClick),m={};(i||e)&&!l&&a.preventDefault();xa(f,function(a){return b.normalize(a)});if(a.type==="touchstart")q(f,function(a,b){d[b]={chartX:a.chartX,chartY:a.chartY}}),h.x=[d[0].chartX,d[1]&&d[1].chartX],h.y=[d[0].chartY,d[1]&&d[1].chartY],q(c.axes,function(a){if(a.zoomEnabled){var b=c.bounds[a.horiz?"h":"v"],d=a.minPixelPadding,e=a.toPixels(a.dataMin),f=a.toPixels(a.dataMax),g=z(e,f),e=w(e,f);b.min=z(a.pos,g-d);b.max=w(a.pos+a.len,e+d)}});else if(d.length){if(!k)b.selectionMarker= +k=v({destroy:na},c.plotBox);b.pinchTranslate(d,f,j,k,m,h);b.hasPinched=i;b.scaleGroups(j,m);!i&&e&&g===1&&this.runPointActions(b.normalize(a))}},onContainerTouchStart:function(a){var b=this.chart;sa=b.index;a.touches.length===1?(a=this.normalize(a),b.isInsidePlot(a.chartX-b.plotLeft,a.chartY-b.plotTop)?(this.runPointActions(a),this.pinch(a)):this.reset()):a.touches.length===2&&this.pinch(a)},onContainerTouchMove:function(a){(a.touches.length===1||a.touches.length===2)&&this.pinch(a)},onDocumentTouchEnd:function(a){aa[sa]&& +aa[sa].pointer.drop(a)}});if(X.PointerEvent||X.MSPointerEvent){var ya={},Ib=!!X.PointerEvent,gc=function(){var a,b=[];b.item=function(a){return this[a]};for(a in ya)ya.hasOwnProperty(a)&&b.push({pageX:ya[a].pageX,pageY:ya[a].pageY,target:ya[a].target});return b},Jb=function(a,b,c,d){a=a.originalEvent||a;if((a.pointerType==="touch"||a.pointerType===a.MSPOINTER_TYPE_TOUCH)&&aa[sa])d(a),d=aa[sa].pointer,d[b]({type:c,target:a.currentTarget,preventDefault:na,touches:gc()})};v(Xa.prototype,{onContainerPointerDown:function(a){Jb(a, +"onContainerTouchStart","touchstart",function(a){ya[a.pointerId]={pageX:a.pageX,pageY:a.pageY,target:a.currentTarget}})},onContainerPointerMove:function(a){Jb(a,"onContainerTouchMove","touchmove",function(a){ya[a.pointerId]={pageX:a.pageX,pageY:a.pageY};if(!ya[a.pointerId].target)ya[a.pointerId].target=a.currentTarget})},onDocumentPointerUp:function(a){Jb(a,"onContainerTouchEnd","touchend",function(a){delete ya[a.pointerId]})},batchMSEvents:function(a){a(this.chart.container,Ib?"pointerdown":"MSPointerDown", +this.onContainerPointerDown);a(this.chart.container,Ib?"pointermove":"MSPointerMove",this.onContainerPointerMove);a(B,Ib?"pointerup":"MSPointerUp",this.onDocumentPointerUp)}});O(Xa.prototype,"init",function(a,b,c){a.call(this,b,c);(this.hasZoom||this.followTouchMove)&&E(b.container,{"-ms-touch-action":Y,"touch-action":Y})});O(Xa.prototype,"setDOMEvents",function(a){a.apply(this);(this.hasZoom||this.followTouchMove)&&this.batchMSEvents(A)});O(Xa.prototype,"destroy",function(a){this.batchMSEvents(R); +a.call(this)})}var pb=P.Legend=function(a,b){this.init(a,b)};pb.prototype={init:function(a,b){var c=this,d=b.itemStyle,e=o(b.padding,8),f=b.itemMarginTop||0;this.options=b;if(b.enabled)c.baseline=I(d.fontSize)+3+f,c.itemStyle=d,c.itemHiddenStyle=y(d,b.itemHiddenStyle),c.itemMarginTop=f,c.padding=e,c.initialItemX=e,c.initialItemY=e-5,c.maxItemWidth=0,c.chart=a,c.itemHeight=0,c.lastLineHeight=0,c.symbolWidth=o(b.symbolWidth,16),c.pages=[],c.render(),A(c.chart,"endResize",function(){c.positionCheckboxes()})}, +colorizeItem:function(a,b){var c=this.options,d=a.legendItem,e=a.legendLine,f=a.legendSymbol,g=this.itemHiddenStyle.color,c=b?c.itemStyle.color:g,h=b?a.legendColor||a.color||"#CCC":g,g=a.options&&a.options.marker,i={fill:h},k;d&&d.css({fill:c,color:c});e&&e.attr({stroke:h});if(f){if(g&&f.isMarker)for(k in i.stroke=h,g=a.convertAttribs(g),g)d=g[k],d!==r&&(i[k]=d);f.attr(i)}},positionItem:function(a){var b=this.options,c=b.symbolPadding,b=!b.rtl,d=a._legendItemPos,e=d[0],d=d[1],f=a.checkbox;a.legendGroup&& +a.legendGroup.translate(b?e:this.legendWidth-e-2*c-4,d);if(f)f.x=e,f.y=d},destroyItem:function(a){var b=a.checkbox;q(["legendItem","legendLine","legendSymbol","legendGroup"],function(b){a[b]&&(a[b]=a[b].destroy())});b&&Sa(a.checkbox)},destroy:function(){var a=this.group,b=this.box;if(b)this.box=b.destroy();if(a)this.group=a.destroy()},positionCheckboxes:function(a){var b=this.group.alignAttr,c,d=this.clipHeight||this.legendHeight;if(b)c=b.translateY,q(this.allItems,function(e){var f=e.checkbox,g; +f&&(g=c+f.y+(a||0)+3,E(f,{left:b.translateX+e.checkboxOffset+f.x-20+"px",top:g+"px",display:g>c-6&&g(m||b.chartWidth-2*k-u-d.x))this.itemX=u,this.itemY+= +p+this.lastLineHeight+n,this.lastLineHeight=0;this.maxItemWidth=w(this.maxItemWidth,f);this.lastItemY=p+this.itemY+n;this.lastLineHeight=w(g,this.lastLineHeight);a._legendItemPos=[this.itemX,this.itemY];e?this.itemX+=f:(this.itemY+=p+g+n,this.lastLineHeight=g);this.offsetWidth=m||w((e?this.itemX-u-j:f)+k,this.offsetWidth)},getAllItems:function(){var a=[];q(this.chart.series,function(b){var c=b.options;if(o(c.showInLegend,!t(c.linkedTo)?r:!1,!0))a=a.concat(b.legendItems||(c.legendType==="point"?b.data: +b))});return a},render:function(){var a=this,b=a.chart,c=b.renderer,d=a.group,e,f,g,h,i=a.box,k=a.options,j=a.padding,l=k.borderWidth,m=k.backgroundColor;a.itemX=a.initialItemX;a.itemY=a.initialItemY;a.offsetWidth=0;a.lastItemY=0;if(!d)a.group=d=c.g("legend").attr({zIndex:7}).add(),a.contentGroup=c.g().attr({zIndex:1}).add(d),a.scrollGroup=c.g().add(a.contentGroup);a.renderTitle();e=a.getAllItems();tb(e,function(a,b){return(a.options&&a.options.legendIndex||0)-(b.options&&b.options.legendIndex||0)}); +k.reversed&&e.reverse();a.allItems=e;a.display=f=!!e.length;q(e,function(b){a.renderItem(b)});g=k.width||a.offsetWidth;h=a.lastItemY+a.lastLineHeight+a.titleHeight;h=a.handleOverflow(h);if(l||m){g+=j;h+=j;if(i){if(g>0&&h>0)i[i.isNew?"attr":"animate"](i.crisp({width:g,height:h})),i.isNew=!1}else a.box=i=c.rect(0,0,g,h,k.borderRadius,l||0).attr({stroke:k.borderColor,"stroke-width":l||0,fill:m||Y}).add(d).shadow(k.shadow),i.isNew=!0;i[f?"show":"hide"]()}a.legendWidth=g;a.legendHeight=h;q(e,function(b){a.positionItem(b)}); +f&&d.align(v({width:g,height:h},k),!0,"spacingBox");b.isResizing||this.positionCheckboxes()},handleOverflow:function(a){var b=this,c=this.chart,d=c.renderer,e=this.options,f=e.y,f=c.spacingBox.height+(e.verticalAlign==="top"?-f:f)-this.padding,g=e.maxHeight,h,i=this.clipRect,k=e.navigation,j=o(k.animation,!0),l=k.arrowSize||12,m=this.nav,n=this.pages,p,u=this.allItems;e.layout==="horizontal"&&(f/=2);g&&(f=z(f,g));n.length=0;if(a>f&&!e.useHTML){this.clipHeight=h=f-20-this.titleHeight-this.padding; +this.currentPage=o(this.currentPage,1);this.fullHeight=a;q(u,function(a,b){var c=a._legendItemPos[1],d=s(a.legendItem.getBBox().height),e=n.length;if(!e||c-n[e-1]>h&&(p||c)!==n[e-1])n.push(p||c),e++;b===u.length-1&&c+d-n[e-1]>h&&n.push(c);c!==p&&(p=c)});if(!i)i=b.clipRect=d.clipRect(0,this.padding,9999,0),b.contentGroup.clip(i);i.attr({height:h});if(!m)this.nav=m=d.g().attr({zIndex:1}).add(this.group),this.up=d.symbol("triangle",0,0,l,l).on("click",function(){b.scroll(-1,j)}).add(m),this.pager=d.text("", +15,10).css(k.style).add(m),this.down=d.symbol("triangle-down",0,0,l,l).on("click",function(){b.scroll(1,j)}).add(m);b.scroll(0);a=f}else if(m)i.attr({height:c.chartHeight}),m.hide(),this.scrollGroup.attr({translateY:1}),this.clipHeight=0;return a},scroll:function(a,b){var c=this.pages,d=c.length,e=this.currentPage+a,f=this.clipHeight,g=this.options.navigation,h=g.activeColor,g=g.inactiveColor,i=this.pager,k=this.padding;e>d&&(e=d);if(e>0)b!==r&&Ya(b,this.chart),this.nav.attr({translateX:k,translateY:f+ +this.padding+7+this.titleHeight,visibility:"visible"}),this.up.attr({fill:e===1?g:h}).css({cursor:e===1?"default":"pointer"}),i.attr({text:e+"/"+d}),this.down.attr({x:18+this.pager.getBBox().width,fill:e===d?g:h}).css({cursor:e===d?"default":"pointer"}),c=-c[e-1]+this.initialItemY,this.scrollGroup.animate({translateY:c}),this.currentPage=e,this.positionCheckboxes(c)}};Q=P.LegendSymbolMixin={drawRectangle:function(a,b){var c=a.options.symbolHeight||12;b.legendSymbol=this.chart.renderer.rect(0,a.baseline- +5-c/2,a.symbolWidth,c,a.options.symbolRadius||0).attr({zIndex:3}).add(b.legendGroup)},drawLineMarker:function(a){var b=this.options,c=b.marker,d;d=a.symbolWidth;var e=this.chart.renderer,f=this.legendGroup,a=a.baseline-s(e.fontMetrics(a.options.itemStyle.fontSize).b*0.3),g;if(b.lineWidth){g={"stroke-width":b.lineWidth};if(b.dashStyle)g.dashstyle=b.dashStyle;this.legendLine=e.path(["M",0,a,"L",d,a]).attr(g).add(f)}if(c&&c.enabled!==!1)b=c.radius,this.legendSymbol=d=e.symbol(this.symbol,d/2-b,a-b,2* +b,2*b).add(f),d.isMarker=!0}};(/Trident\/7\.0/.test(Da)||$a)&&O(pb.prototype,"positionItem",function(a,b){var c=this,d=function(){b._legendItemPos&&a.call(c,b)};d();setTimeout(d)});va.prototype={init:function(a,b){var c,d=a.series;a.series=null;c=y(F,a);c.series=a.series=d;this.userOptions=a;d=c.chart;this.margin=this.splashArray("margin",d);this.spacing=this.splashArray("spacing",d);var e=d.events;this.bounds={h:{},v:{}};this.callback=b;this.isResizing=0;this.options=c;this.axes=[];this.series=[]; +this.hasCartesianSeries=d.showAxes;var f=this,g;f.index=aa.length;aa.push(f);db++;d.reflow!==!1&&A(f,"load",function(){f.initReflow()});if(e)for(g in e)A(f,g,e[g]);f.xAxis=[];f.yAxis=[];f.animation=ja?!1:o(d.animation,!0);f.pointCount=0;f.counters=new Lb;f.firstRender()},initSeries:function(a){var b=this.options.chart;(b=C[a.type||b.type||b.defaultSeriesType])||qa(17,!0);b=new b;b.init(this,a);return b},isInsidePlot:function(a,b,c){var d=c?b:a,a=c?a:b;return d>=0&&d<=this.plotWidth&&a>=0&&a<=this.plotHeight}, +adjustTickAmounts:function(){this.options.chart.alignTicks!==!1&&q(this.axes,function(a){a.adjustTickAmount()});this.maxTicks=null},redraw:function(a){var b=this.axes,c=this.series,d=this.pointer,e=this.legend,f=this.isDirtyLegend,g,h,i=this.isDirtyBox,k=c.length,j=k,l=this.renderer,m=l.isHidden(),n=[];Ya(a,this);m&&this.cloneRenderTo();for(this.layOutTitles();j--;)if(a=c[j],a.options.stacking&&(g=!0,a.isDirty)){h=!0;break}if(h)for(j=k;j--;)if(a=c[j],a.options.stacking)a.isDirty=!0;q(c,function(a){a.isDirty&& +a.options.legendType==="point"&&(f=!0)});if(f&&e.options.enabled)e.render(),this.isDirtyLegend=!1;g&&this.getStacks();if(this.hasCartesianSeries){if(!this.isResizing)this.maxTicks=null,q(b,function(a){a.setScale()});this.adjustTickAmounts();this.getMargins();q(b,function(a){a.isDirty&&(i=!0)});q(b,function(a){if(a.isDirtyExtremes)a.isDirtyExtremes=!1,n.push(function(){N(a,"afterSetExtremes",v(a.eventArgs,a.getExtremes()));delete a.eventArgs});(i||g)&&a.redraw()})}i&&this.drawChartBox();q(c,function(a){a.isDirty&& +a.visible&&(!a.isCartesian||a.xAxis)&&a.redraw()});d&&d.reset(!0);l.draw();N(this,"redraw");m&&this.cloneRenderTo(!0);q(n,function(a){a.call()})},get:function(a){var b=this.axes,c=this.series,d,e;for(d=0;d19?this.containerHeight:400))},cloneRenderTo:function(a){var b=this.renderToClone,c=this.container;a?b&&(this.renderTo.appendChild(c),Sa(b),delete this.renderToClone):(c&&c.parentNode===this.renderTo&&this.renderTo.removeChild(c), +this.renderToClone=b=this.renderTo.cloneNode(0),E(b,{position:"absolute",top:"-9999px",display:"block"}),b.style.setProperty&&b.style.setProperty("display","block","important"),B.body.appendChild(b),c&&b.appendChild(c))},getContainer:function(){var a,b=this.options.chart,c,d,e;this.renderTo=a=b.renderTo;e="highcharts-"+Ab++;if(Oa(a))this.renderTo=a=B.getElementById(a);a||qa(13,!0);c=I(W(a,"data-highcharts-chart"));!isNaN(c)&&aa[c]&&aa[c].hasRendered&&aa[c].destroy();W(a,"data-highcharts-chart",this.index); +a.innerHTML="";!b.skipClone&&!a.offsetWidth&&this.cloneRenderTo();this.getChartSize();c=this.chartWidth;d=this.chartHeight;this.container=a=$(Ta,{className:"highcharts-container"+(b.className?" "+b.className:""),id:e},v({position:"relative",overflow:"hidden",width:c+"px",height:d+"px",textAlign:"left",lineHeight:"normal",zIndex:0,"-webkit-tap-highlight-color":"rgba(0,0,0,0)"},b.style),this.renderToClone||a);this._cursor=a.style.cursor;this.renderer=b.forExport?new ka(a,c,d,b.style,!0):new Wa(a,c, +d,b.style);ja&&this.renderer.create(this,a,c,d)},getMargins:function(){var a=this.spacing,b,c=this.legend,d=this.margin,e=this.options.legend,f=o(e.margin,20),g=e.x,h=e.y,i=e.align,k=e.verticalAlign,j=this.titleOffset;this.resetMargins();b=this.axisOffset;if(j&&!t(d[0]))this.plotTop=w(this.plotTop,j+this.options.title.margin+a[0]);if(c.display&&!e.floating)if(i==="right"){if(!t(d[1]))this.marginRight=w(this.marginRight,c.legendWidth-g+f+a[1])}else if(i==="left"){if(!t(d[3]))this.plotLeft=w(this.plotLeft, +c.legendWidth+g+f+a[3])}else if(k==="top"){if(!t(d[0]))this.plotTop=w(this.plotTop,c.legendHeight+h+f+a[0])}else if(k==="bottom"&&!t(d[2]))this.marginBottom=w(this.marginBottom,c.legendHeight-h+f+a[2]);this.extraBottomMargin&&(this.marginBottom+=this.extraBottomMargin);this.extraTopMargin&&(this.plotTop+=this.extraTopMargin);this.hasCartesianSeries&&q(this.axes,function(a){a.getOffset()});t(d[3])||(this.plotLeft+=b[3]);t(d[0])||(this.plotTop+=b[0]);t(d[2])||(this.marginBottom+=b[2]);t(d[1])||(this.marginRight+= +b[1]);this.setChartSize()},reflow:function(a){var b=this,c=b.options.chart,d=b.renderTo,e=c.width||nb(d,"width"),f=c.height||nb(d,"height"),c=a?a.target:X,d=function(){if(b.container)b.setSize(e,f,!1),b.hasUserSize=null};if(!b.hasUserSize&&e&&f&&(c===X||c===B)){if(e!==b.containerWidth||f!==b.containerHeight)clearTimeout(b.reflowTimeout),a?b.reflowTimeout=setTimeout(d,100):d();b.containerWidth=e;b.containerHeight=f}},initReflow:function(){var a=this,b=function(b){a.reflow(b)};A(X,"resize",b);A(a,"destroy", +function(){R(X,"resize",b)})},setSize:function(a,b,c){var d=this,e,f,g;d.isResizing+=1;g=function(){d&&N(d,"endResize",null,function(){d.isResizing-=1})};Ya(c,d);d.oldChartHeight=d.chartHeight;d.oldChartWidth=d.chartWidth;if(t(a))d.chartWidth=e=w(0,s(a)),d.hasUserSize=!!e;if(t(b))d.chartHeight=f=w(0,s(b));(Ca?ob:E)(d.container,{width:e+"px",height:f+"px"},Ca);d.setChartSize(!0);d.renderer.setSize(e,f,c);d.maxTicks=null;q(d.axes,function(a){a.isDirty=!0;a.setScale()});q(d.series,function(a){a.isDirty= +!0});d.isDirtyLegend=!0;d.isDirtyBox=!0;d.layOutTitles();d.getMargins();d.redraw(c);d.oldChartHeight=null;N(d,"resize");Ca===!1?g():setTimeout(g,Ca&&Ca.duration||500)},setChartSize:function(a){var b=this.inverted,c=this.renderer,d=this.chartWidth,e=this.chartHeight,f=this.options.chart,g=this.spacing,h=this.clipOffset,i,k,j,l;this.plotLeft=i=s(this.plotLeft);this.plotTop=k=s(this.plotTop);this.plotWidth=j=w(0,s(d-i-this.marginRight));this.plotHeight=l=w(0,s(e-k-this.marginBottom));this.plotSizeX= +b?l:j;this.plotSizeY=b?j:l;this.plotBorderWidth=f.plotBorderWidth||0;this.spacingBox=c.spacingBox={x:g[3],y:g[0],width:d-g[3]-g[1],height:e-g[0]-g[2]};this.plotBox=c.plotBox={x:i,y:k,width:j,height:l};d=2*S(this.plotBorderWidth/2);b=Va(w(d,h[3])/2);c=Va(w(d,h[0])/2);this.clipBox={x:b,y:c,width:S(this.plotSizeX-w(d,h[1])/2-b),height:S(this.plotSizeY-w(d,h[2])/2-c)};a||q(this.axes,function(a){a.setAxisSize();a.setAxisTranslation()})},resetMargins:function(){var a=this.spacing,b=this.margin;this.plotTop= +o(b[0],a[0]);this.marginRight=o(b[1],a[1]);this.marginBottom=o(b[2],a[2]);this.plotLeft=o(b[3],a[3]);this.axisOffset=[0,0,0,0];this.clipOffset=[0,0,0,0]},drawChartBox:function(){var a=this.options.chart,b=this.renderer,c=this.chartWidth,d=this.chartHeight,e=this.chartBackground,f=this.plotBackground,g=this.plotBorder,h=this.plotBGImage,i=a.borderWidth||0,k=a.backgroundColor,j=a.plotBackgroundColor,l=a.plotBackgroundImage,m=a.plotBorderWidth||0,n,p=this.plotLeft,u=this.plotTop,o=this.plotWidth,q=this.plotHeight, +x=this.plotBox,r=this.clipRect,s=this.clipBox;n=i+(a.shadow?8:0);if(i||k)if(e)e.animate(e.crisp({width:c-n,height:d-n}));else{e={fill:k||Y};if(i)e.stroke=a.borderColor,e["stroke-width"]=i;this.chartBackground=b.rect(n/2,n/2,c-n,d-n,a.borderRadius,i).attr(e).addClass("highcharts-background").add().shadow(a.shadow)}if(j)f?f.animate(x):this.plotBackground=b.rect(p,u,o,q,0).attr({fill:j}).add().shadow(a.plotShadow);if(l)h?h.animate(x):this.plotBGImage=b.image(l,p,u,o,q).add();r?r.animate({width:s.width, +height:s.height}):this.clipRect=b.clipRect(s);if(m)g?g.animate(g.crisp({x:p,y:u,width:o,height:q})):this.plotBorder=b.rect(p,u,o,q,0,-m).attr({stroke:a.plotBorderColor,"stroke-width":m,fill:Y,zIndex:1}).add();this.isDirtyBox=!1},propFromSeries:function(){var a=this,b=a.options.chart,c,d=a.options.series,e,f;q(["inverted","angular","polar"],function(g){c=C[b.type||b.defaultSeriesType];f=a[g]||b[g]||c&&c.prototype[g];for(e=d&&d.length;!f&&e--;)(c=C[d[e].type])&&c.prototype[g]&&(f=!0);a[g]=f})},linkSeries:function(){var a= +this,b=a.series;q(b,function(a){a.linkedSeries.length=0});q(b,function(b){var d=b.options.linkedTo;if(Oa(d)&&(d=d===":previous"?a.series[b.index-1]:a.get(d)))d.linkedSeries.push(b),b.linkedParent=d})},renderSeries:function(){q(this.series,function(a){a.translate();a.setTooltipPoints&&a.setTooltipPoints();a.render()})},render:function(){var a=this,b=a.axes,c=a.renderer,d=a.options,e=d.labels,f=d.credits,g;a.setTitle();a.legend=new pb(a,d.legend);a.getStacks();q(b,function(a){a.setScale()});a.getMargins(); +a.maxTicks=null;q(b,function(a){a.setTickPositions(!0);a.setMaxTicks()});a.adjustTickAmounts();a.getMargins();a.drawChartBox();a.hasCartesianSeries&&q(b,function(a){a.render()});if(!a.seriesGroup)a.seriesGroup=c.g("series-group").attr({zIndex:3}).add();a.renderSeries();e.items&&q(e.items,function(b){var d=v(e.style,b.style),f=I(d.left)+a.plotLeft,g=I(d.top)+a.plotTop+12;delete d.left;delete d.top;c.text(b.html,f,g).attr({zIndex:2}).css(d).add()});if(f.enabled&&!a.credits)g=f.href,a.credits=c.text(f.text, +0,0).on("click",function(){if(g)location.href=g}).attr({align:f.position.align,zIndex:8}).css(f.style).add().align(f.position);a.hasRendered=!0},destroy:function(){var a=this,b=a.axes,c=a.series,d=a.container,e,f=d&&d.parentNode;N(a,"destroy");aa[a.index]=r;db--;a.renderTo.removeAttribute("data-highcharts-chart");R(a);for(e=b.length;e--;)b[e]=b[e].destroy();for(e=c.length;e--;)c[e]=c[e].destroy();q("title,subtitle,chartBackground,plotBackground,plotBGImage,plotBorder,seriesGroup,clipRect,credits,pointer,scroller,rangeSelector,legend,resetZoomButton,tooltip,renderer".split(","), +function(b){var c=a[b];c&&c.destroy&&(a[b]=c.destroy())});if(d)d.innerHTML="",R(d),f&&Sa(d);for(e in a)delete a[e]},isReadyToRender:function(){var a=this;return!ca&&X==X.top&&B.readyState!=="complete"||ja&&!X.canvg?(ja?Vb.push(function(){a.firstRender()},a.options.global.canvasToolsURL):B.attachEvent("onreadystatechange",function(){B.detachEvent("onreadystatechange",a.firstRender);B.readyState==="complete"&&a.firstRender()}),!1):!0},firstRender:function(){var a=this,b=a.options,c=a.callback;if(a.isReadyToRender()){a.getContainer(); +N(a,"init");a.resetMargins();a.setChartSize();a.propFromSeries();a.getAxes();q(b.series||[],function(b){a.initSeries(b)});a.linkSeries();N(a,"beforeRender");if(P.Pointer)a.pointer=new Xa(a,b);a.render();a.renderer.draw();c&&c.apply(a,[a]);q(a.callbacks,function(b){b.apply(a,[a])});a.cloneRenderTo(!0);N(a,"load")}},splashArray:function(a,b){var c=b[a],c=fa(c)?c:[c,c,c,c];return[o(b[a+"Top"],c[0]),o(b[a+"Right"],c[1]),o(b[a+"Bottom"],c[2]),o(b[a+"Left"],c[3])]}};va.prototype.callbacks=[];ea=P.CenteredSeriesMixin= +{getCenter:function(){var a=this.options,b=this.chart,c=2*(a.slicedOffset||0),d,e=b.plotWidth-2*c,f=b.plotHeight-2*c,b=a.center,a=[o(b[0],"50%"),o(b[1],"50%"),a.size||"100%",a.innerSize||0],g=z(e,f),h;return xa(a,function(a,b){h=/%$/.test(a);d=b<2||b===2&&h;return(h?[e,f,g,g][b]*I(a)/100:a)+(d?c:0)})}};var za=function(){};za.prototype={init:function(a,b,c){this.series=a;this.applyOptions(b,c);this.pointAttr={};if(a.options.colorByPoint&&(b=a.options.colors||a.chart.options.colors,this.color=this.color|| +b[a.colorCounter++],a.colorCounter===b.length))a.colorCounter=0;a.chart.pointCount++;return this},applyOptions:function(a,b){var c=this.series,d=c.pointValKey,a=za.prototype.optionsToObject.call(this,a);v(this,a);this.options=this.options?v(this.options,a):a;if(d)this.y=this[d];if(this.x===r&&c)this.x=b===r?c.autoIncrement():b;return this},optionsToObject:function(a){var b={},c=this.series,d=c.pointArrayMap||["y"],e=d.length,f=0,g=0;if(typeof a==="number"||a===null)b[d[0]]=a;else if(Pa(a)){if(a.length> +e){c=typeof a[0];if(c==="string")b.name=a[0];else if(c==="number")b.x=a[0];f++}for(;ga+1&&b.push(d.slice(a+1,g)),a=g):g===e-1&&b.push(d.slice(a+1,g+1))});this.segments=b},setOptions:function(a){var b=this.chart,c=b.options.plotOptions,b=b.userOptions||{},d=b.plotOptions||{},e=c[this.type];this.userOptions= +a;c=y(e,c.series,a);this.tooltipOptions=y(F.tooltip,F.plotOptions[this.type].tooltip,b.tooltip,d.series&&d.series.tooltip,d[this.type]&&d[this.type].tooltip,a.tooltip);e.marker===null&&delete c.marker;return c},getColor:function(){var a=this.options,b=this.userOptions,c=this.chart.options.colors,d=this.chart.counters,e;e=a.color||T[this.type].color;if(!e&&!a.colorByPoint)t(b._colorIndex)?a=b._colorIndex:(b._colorIndex=d.color,a=d.color++),e=c[a];this.color=e;d.wrapColor(c.length)},getSymbol:function(){var a= +this.userOptions,b=this.options.marker,c=this.chart,d=c.options.symbols,c=c.counters;this.symbol=b.symbol;if(!this.symbol)t(a._symbolIndex)?a=a._symbolIndex:(a._symbolIndex=c.symbol,a=c.symbol++),this.symbol=d[a];if(/^url/.test(this.symbol))b.radius=0;c.wrapSymbol(d.length)},drawLegendSymbol:Q.drawLineMarker,setData:function(a,b,c,d){var e=this,f=e.points,g=f&&f.length||0,h,i=e.options,k=e.chart,j=null,l=e.xAxis,m=l&&!!l.categories,n=e.tooltipPoints,p=i.turboThreshold,u=this.xData,s=this.yData,G= +(h=e.pointArrayMap)&&h.length,a=a||[];h=a.length;b=o(b,!0);if(d!==!1&&h&&g===h&&!e.cropped&&!e.hasGroupedData)q(a,function(a,b){f[b].update(a,!1)});else{e.xIncrement=null;e.pointRange=m?1:i.pointRange;e.colorCounter=0;q(this.parallelArrays,function(a){e[a+"Data"].length=0});if(p&&h>p){for(c=0;j===null&&ck||this.forceCrop))if(m=h.min,n=h.max,b[d-1]n)b=[],c=[];else if(b[0]n)e=this.cropData(this.xData,this.yData,m,n),b=e.xData,c=e.yData,e=e.start,f=!0,j=b.length;for(d=b.length-1;d>=0;d--)a=b[d]-b[d-1],!f&&b[d]>m&&b[d]0&&(g===r||a=c){f=w(0,i-h);break}for(;id){g=i+h;break}return{xData:a.slice(f,g),yData:b.slice(f,g),start:f,end:g}},generatePoints:function(){var a=this.options.data,b=this.data,c,d=this.processedXData,e=this.processedYData,f=this.pointClass,g=d.length,h=this.cropStart||0,i,k=this.hasGroupedData, +j,l=[],m;if(!b&&!k)b=[],b.length=a.length,b=this.data=b;for(m=0;m0),k=this.getExtremesFromAll||this.cropped||(c[l+1]||k)>=g&&(c[l-1]||k)<=h,i&&k)if(i=j.length)for(;i--;)j[i]!==null&&(e[f++]=j[i]);else e[f++]=j;this.dataMin=o(void 0,Ra(e));this.dataMax=o(void 0,Ba(e))},translate:function(){this.processedXData||this.processData();this.generatePoints();for(var a=this.options,b=a.stacking,c=this.xAxis,d=c.categories,e=this.yAxis,f=this.points,g=f.length,h=!!this.modifyValue,i=a.pointPlacement, +k=i==="between"||la(i),j=a.threshold,a=0;a0||k))g.graphic=c.renderer.symbol(i,d-h,e-h,2*h,2*h).attr(a).add(n)}else if(j)g.graphic=j.destroy()},convertAttribs:function(a,b,c,d){var e=this.pointAttrToOptions,f,g,h={},a=a||{},b=b||{},c=c||{},d=d||{};for(f in e)g=e[f],h[f]=o(a[g],b[f],c[f],d[f]);return h},getAttribs:function(){var a=this,b=a.options, +c=T[a.type].marker?b.marker:b,d=c.states,e=d.hover,f,g=a.color;f={stroke:g,fill:g};var h=a.points||[],i,k=[],j,l=a.pointAttrToOptions;j=a.hasPointSpecificOptions;var m=b.negativeColor,n=c.lineColor,p=c.fillColor;i=b.turboThreshold;var u;b.marker?(e.radius=e.radius||c.radius+2,e.lineWidth=e.lineWidth||c.lineWidth+1):e.color=e.color||Fa(e.color||g).brighten(e.brightness).get();k[""]=a.convertAttribs(c,f);q(["hover","select"],function(b){k[b]=a.convertAttribs(d[b],k[""])});a.pointAttr=k;g=h.length;if(!i|| +g1?b=b.concat(c):d.push(e[0])});a.singlePoints=d;return a.graphPath=b},drawGraph:function(){var a=this,b=this.options,c=[["graph",b.lineColor||this.color]],d=b.lineWidth,e=b.dashStyle,f=b.linecap!=="square",g=this.getGraphPath(),h=b.negativeColor;h&&c.push(["graphNeg",h]);q(c,function(c,h){var j=c[0],l=a[j];if(l)eb(l),l.animate({d:g});else if(d&&g.length)l={stroke:c[1],"stroke-width":d,fill:Y,zIndex:1},e?l.dashstyle=e:f&&(l["stroke-linecap"]= +l["stroke-linejoin"]="round"),a[j]=a.chart.renderer.path(g).attr(l).add(a.group).shadow(!h&&b.shadow)})},clipNeg:function(){var a=this.options,b=this.chart,c=b.renderer,d=a.negativeColor||a.negativeFillColor,e,f=this.graph,g=this.area,h=this.posClip,i=this.negClip;e=b.chartWidth;var k=b.chartHeight,j=w(e,k),l=this.yAxis;if(d&&(f||g)){d=s(l.toPixels(a.threshold||0,!0));d<0&&(j-=d);a={x:0,y:0,width:j,height:d};j={x:0,y:d,width:j,height:j};if(b.inverted)a.height=j.y=b.plotWidth-d,c.isVML&&(a={x:b.plotWidth- +d-b.plotLeft,y:0,width:e,height:k},j={x:d+b.plotLeft-e,y:0,width:b.plotLeft+d,height:e});l.reversed?(b=j,e=a):(b=a,e=j);h?(h.animate(b),i.animate(e)):(this.posClip=h=c.clipRect(b),this.negClip=i=c.clipRect(e),f&&this.graphNeg&&(f.clip(h),this.graphNeg.clip(i)),g&&(g.clip(h),this.areaNeg.clip(i)))}},invertGroups:function(){function a(){var a={width:b.yAxis.len,height:b.xAxis.len};q(["group","markerGroup"],function(c){b[c]&&b[c].attr(a).invert()})}var b=this,c=b.chart;if(b.xAxis)A(c,"resize",a),A(b, +"destroy",function(){R(c,"resize",a)}),a(),b.invertGroups=a},plotGroup:function(a,b,c,d,e){var f=this[a],g=!f;g&&(this[a]=f=this.chart.renderer.g(b).attr({visibility:c,zIndex:d||0.1}).add(e));f[g?"attr":"animate"](this.getPlotBox());return f},getPlotBox:function(){var a=this.chart,b=this.xAxis,c=this.yAxis;if(a.inverted)b=c,c=this.xAxis;return{translateX:b?b.left:a.plotLeft,translateY:c?c.top:a.plotTop,scaleX:1,scaleY:1}},render:function(){var a=this,b=a.chart,c,d=a.options,e=(c=d.animation)&&!!a.animate&& +b.renderer.isSVG&&o(c.duration,500)||0,f=a.visible?"visible":"hidden",g=d.zIndex,h=a.hasRendered,i=b.seriesGroup;c=a.plotGroup("group","series",f,g,i);a.markerGroup=a.plotGroup("markerGroup","markers",f,g,i);e&&a.animate(!0);a.getAttribs();c.inverted=a.isCartesian?b.inverted:!1;a.drawGraph&&(a.drawGraph(),a.clipNeg());a.drawDataLabels&&a.drawDataLabels();a.visible&&a.drawPoints();a.drawTracker&&a.options.enableMouseTracking!==!1&&a.drawTracker();b.inverted&&a.invertGroups();d.clip!==!1&&!a.sharedClipKey&& +!h&&c.clip(b.clipRect);e&&a.animate();if(!h)e?a.animationTimeout=setTimeout(function(){a.afterAnimate()},e):a.afterAnimate();a.isDirty=a.isDirtyData=!1;a.hasRendered=!0},redraw:function(){var a=this.chart,b=this.isDirtyData,c=this.group,d=this.xAxis,e=this.yAxis;c&&(a.inverted&&c.attr({width:a.plotWidth,height:a.plotHeight}),c.animate({translateX:o(d&&d.left,a.plotLeft),translateY:o(e&&e.top,a.plotTop)}));this.translate();this.setTooltipPoints&&this.setTooltipPoints(!0);this.render();b&&N(this,"updatedData")}}; +Rb.prototype={destroy:function(){Ka(this,this.axis)},render:function(a){var b=this.options,c=b.format,c=c?Ja(c,this):b.formatter.call(this);this.label?this.label.attr({text:c,visibility:"hidden"}):this.label=this.axis.chart.renderer.text(c,null,null,b.useHTML).css(b.style).attr({align:this.textAlign,rotation:b.rotation,visibility:"hidden"}).add(a)},setOffset:function(a,b){var c=this.axis,d=c.chart,e=d.inverted,f=this.isNegative,g=c.translate(c.usePercentage?100:this.total,0,0,0,1),c=c.translate(0), +c=M(g-c),h=d.xAxis[0].translate(this.x)+a,i=d.plotHeight,f={x:e?f?g:g-c:h,y:e?i-h-b:f?i-g-c:i-g,width:e?c:b,height:e?b:c};if(e=this.label)e.align(this.alignOptions,null,f),f=e.alignAttr,e[this.options.crop===!1||d.isInsidePlot(f.x,f.y)?"show":"hide"](!0)}};L.prototype.buildStacks=function(){var a=this.series,b=o(this.options.reversedStacks,!0),c=a.length;if(!this.isXAxis){for(this.usePercentage=!1;c--;)a[b?c:a.length-c-1].setStackedPoints();if(this.usePercentage)for(c=0;cg;)h--;this.updateParallelArrays(d,"splice",h,0,0);this.updateParallelArrays(d,h);if(k)k[g]=d.name;l.splice(h,0,a);m&&(this.data.splice(h,0,null),this.processData());e.legendType==="point"&&this.generatePoints();c&&(f[0]&&f[0].remove?f[0].remove(!1): +(f.shift(),this.updateParallelArrays(d,"shift"),l.shift()));this.isDirtyData=this.isDirty=!0;b&&(this.getAttribs(),i.redraw())},remove:function(a,b){var c=this,d=c.chart,a=o(a,!0);if(!c.isRemoving)c.isRemoving=!0,N(c,"remove",null,function(){c.destroy();d.isDirtyLegend=d.isDirtyBox=!0;d.linkSeries();a&&d.redraw(b)});c.isRemoving=!1},update:function(a,b){var c=this.chart,d=this.type,e=C[d].prototype,f,a=y(this.userOptions,{animation:!1,index:this.index,pointStart:this.xData[0]},{data:this.options.data}, +a);this.remove(!1);for(f in e)e.hasOwnProperty(f)&&(this[f]=r);v(this,C[a.type||d].prototype);this.init(c,a);o(b,!0)&&c.redraw(!1)}});v(L.prototype,{update:function(a,b){var c=this.chart,a=c.options[this.coll][this.options.index]=y(this.userOptions,a);this.destroy(!0);this._addedPlotLB=r;this.init(c,v(a,{events:r}));c.isDirtyBox=!0;o(b,!0)&&c.redraw()},remove:function(a){for(var b=this.chart,c=this.coll,d=this.series,e=d.length;e--;)d[e]&&d[e].remove(!1);pa(b.axes,this);pa(b[c],this);b.options[c].splice(this.options.index, +1);q(b[c],function(a,b){a.options.index=b});this.destroy();b.isDirtyBox=!0;o(a,!0)&&b.redraw()},setTitle:function(a,b){this.update({title:a},b)},setCategories:function(a,b){this.update({categories:a},b)}});var Aa=ga(K);C.line=Aa;T.area=y(J,{threshold:0});var ta=ga(K,{type:"area",getSegments:function(){var a=[],b=[],c=[],d=this.xAxis,e=this.yAxis,f=e.stacks[this.stackKey],g={},h,i,k=this.points,j=this.options.connectNulls,l,m,n;if(this.options.stacking&&!this.cropped){for(m=0;m=0;d--)g=o(a[d].yBottom,f),da&&i>e?(i=w(a,e),j=2*e-i):ig&&j>e?(j=w(g,e),i=2*e-j):j0.5*a.xAxis.len?0:1),e=a.yAxis,f=a.translatedThreshold= +e.getThreshold(c.threshold),g=o(c.minPointLength,5),c=a.getColumnMetrics(),h=c.width,i=a.barW=Va(w(h,1+2*d)),k=a.pointXOffset=c.offset,j=-(d%2?0.5:0),l=d%2?0.5:1;b.renderer.isVML&&b.inverted&&(l+=1);K.prototype.translate.apply(a);q(a.points,function(c){var d=o(c.yBottom,f),p=z(w(-999-d,c.plotY),e.len+999+d),u=c.plotX+k,q=i,r=z(p,d),x;x=w(p,d)-r;M(x)g?d-g:f-(e.translate(c.y,0,1,0,1)<=f?g:0)));c.barX=u;c.pointWidth=h;c.tooltipPos=b.inverted?[e.len-p,a.xAxis.len-u-q/2]:[u+q/2, +p];d=M(u)<0.5;q=s(u+q)+j;u=s(u)+j;q-=u;p=M(r)<0.5;x=s(r+x)+l;r=s(r)+l;x-=r;d&&(u+=1,q-=1);p&&(r-=1,x+=1);c.shapeType="rect";c.shapeArgs={x:u,y:r,width:q,height:x}})},getSymbol:na,drawLegendSymbol:Q.drawRectangle,drawGraph:na,drawPoints:function(){var a=this,b=this.chart,c=a.options,d=b.renderer,e=c.animationLimit||250,f,g,h;q(a.points,function(i){var k=i.plotY,j=i.graphic;if(k!==r&&!isNaN(k)&&i.y!==null)f=i.shapeArgs,h=t(a.borderWidth)?{"stroke-width":a.borderWidth}:{},g=i.pointAttr[i.selected?"select": +""]||a.pointAttr[""],j?(eb(j),j.attr(h)[b.pointCount {series.name}
      ',pointFormat:"x: {point.x}
      y: {point.y}
      "},stickyTracking:!1}); +ta=ga(K,{type:"scatter",sorted:!1,requireSorting:!1,noSharedTooltip:!0,trackerGroups:["markerGroup"],takeOrdinalPosition:!1,singularTooltips:!0,drawGraph:function(){this.options.lineWidth&&K.prototype.drawGraph.call(this)}});C.scatter=ta;T.pie=y(J,{borderColor:"#FFFFFF",borderWidth:1,center:[null,null],clip:!1,colorByPoint:!0,dataLabels:{distance:30,enabled:!0,formatter:function(){return this.point.name}},ignoreHiddenPoint:!0,legendType:"point",marker:null,size:null,showInLegend:!1,slicedOffset:10, +states:{hover:{brightness:0.1,shadow:!1}},stickyTracking:!1,tooltip:{followPointer:!0}});J={type:"pie",isCartesian:!1,pointClass:ga(za,{init:function(){za.prototype.init.apply(this,arguments);var a=this,b;if(a.y<0)a.y=null;v(a,{visible:a.visible!==!1,name:o(a.name,"Slice")});b=function(b){a.slice(b.type==="select")};A(a,"select",b);A(a,"unselect",b);return a},setVisible:function(a){var b=this,c=b.series,d=c.chart;b.visible=b.options.visible=a=a===r?!b.visible:a;c.options.data[wa(b,c.data)]=b.options; +q(["graphic","dataLabel","connector","shadowGroup"],function(c){if(b[c])b[c][a?"show":"hide"](!0)});b.legendItem&&d.legend.colorizeItem(b,a);if(!c.isDirty&&c.options.ignoreHiddenPoint)c.isDirty=!0,d.redraw()},slice:function(a,b,c){var d=this.series;Ya(c,d.chart);o(b,!0);this.sliced=this.options.sliced=a=t(a)?a:!this.sliced;d.options.data[wa(this,d.data)]=this.options;a=a?this.slicedTranslation:{translateX:0,translateY:0};this.graphic.animate(a);this.shadowGroup&&this.shadowGroup.animate(a)},haloPath:function(a){var b= +this.shapeArgs,c=this.series.chart;return this.series.chart.renderer.symbols.arc(c.plotLeft+b.x,c.plotTop+b.y,b.r+a,b.r+a,{innerR:this.shapeArgs.r,start:b.start,end:b.end})}}),requireSorting:!1,noSharedTooltip:!0,trackerGroups:["group","dataLabelsGroup"],axisTypes:[],pointAttrToOptions:{stroke:"borderColor","stroke-width":"borderWidth",fill:"color"},singularTooltips:!0,getColor:na,animate:function(a){var b=this,c=b.points,d=b.startAngleRad;if(!a)q(c,function(a){var c=a.graphic,a=a.shapeArgs;c&&(c.attr({r:b.center[3]/ +2,start:d,end:d}),c.animate({r:a.r,start:a.start,end:a.end},b.options.animation))}),b.animate=null},setData:function(a,b,c,d){K.prototype.setData.call(this,a,!1,c,d);this.processData();this.generatePoints();o(b,!0)&&this.chart.redraw(c)},generatePoints:function(){var a,b=0,c,d,e,f=this.options.ignoreHiddenPoint;K.prototype.generatePoints.call(this);c=this.points;d=c.length;for(a=0;a0?e.y/b*100:0,e.total=b},translate:function(a){this.generatePoints(); +var b=0,c=this.options,d=c.slicedOffset,e=d+c.borderWidth,f,g,h,i=c.startAngle||0,k=this.startAngleRad=ra/180*(i-90),i=(this.endAngleRad=ra/180*(o(c.endAngle,i+360)-90))-k,j=this.points,l=c.dataLabels.distance,c=c.ignoreHiddenPoint,m,n=j.length,p;if(!a)this.center=a=this.getCenter();this.getX=function(b,c){h=V.asin(z((b-a[1])/(a[2]/2+l),1));return a[0]+(c?-1:1)*da(h)*(a[2]/2+l)};for(m=0;m1.5*ra?h-=2*ra:h<-ra/2&&(h+=2*ra);p.slicedTranslation={translateX:s(da(h)*d),translateY:s(ia(h)*d)};f=da(h)*a[2]/2;g=ia(h)*a[2]/2;p.tooltipPos=[a[0]+f*0.7,a[1]+g*0.7];p.half=h<-ra/2||h>ra/2?1:0;p.angle=h;e=z(e,l/2);p.labelPos=[a[0]+f+da(h)*l,a[1]+g+ia(h)*l,a[0]+f+da(h)*e,a[1]+g+ia(h)*e,a[0]+f,a[1]+g,l<0?"center":p.half?"right":"left",h]}},drawGraph:null,drawPoints:function(){var a=this,b=a.chart.renderer,c,d,e=a.options.shadow, +f,g;if(e&&!a.shadowGroup)a.shadowGroup=b.g("shadow").add(a.group);q(a.points,function(h){d=h.graphic;g=h.shapeArgs;f=h.shadowGroup;if(e&&!f)f=h.shadowGroup=b.g("shadow").add(a.shadowGroup);c=h.sliced?h.slicedTranslation:{translateX:0,translateY:0};f&&f.attr(c);d?d.animate(v(g,c)):h.graphic=d=b[h.shapeType](g).setRadialReference(a.center).attr(h.pointAttr[h.selected?"select":""]).attr({"stroke-linejoin":"round"}).attr(c).add(a.group).shadow(e,f);h.visible!==void 0&&h.setVisible(h.visible)})},sortByAngle:function(a, +b){a.sort(function(a,d){return a.angle!==void 0&&(d.angle-a.angle)*b})},drawLegendSymbol:Q.drawRectangle,getCenter:ea.getCenter,getSymbol:na};J=ga(K,J);C.pie=J;K.prototype.drawDataLabels=function(){var a=this,b=a.options,c=b.cursor,d=b.dataLabels,e=a.points,f,g,h,i;if(d.enabled||a._hasPointLabels)a.dlProcessOptions&&a.dlProcessOptions(d),i=a.plotGroup("dataLabelsGroup","data-labels","hidden",d.zIndex||6),!a.hasRendered&&o(d.defer,!0)&&(i.attr({opacity:0}),A(a,"afterAnimate",function(){a.dataLabelsGroup.show()[b.animation? +"animate":"attr"]({opacity:1},{duration:200})})),g=d,q(e,function(b){var e,l=b.dataLabel,m,n,p=b.connector,u=!0;f=b.options&&b.options.dataLabels;e=o(f&&f.enabled,g.enabled);if(l&&!e)b.dataLabel=l.destroy();else if(e){d=y(g,f);e=d.rotation;m=b.getLabelConfig();h=d.format?Ja(d.format,m):d.formatter.call(m,d);d.style.color=o(d.color,d.style.color,a.color,"black");if(l)if(t(h))l.attr({text:h}),u=!1;else{if(b.dataLabel=l=l.destroy(),p)b.connector=p.destroy()}else if(t(h)){l={fill:d.backgroundColor,stroke:d.borderColor, +"stroke-width":d.borderWidth,r:d.borderRadius||0,rotation:e,padding:d.padding,zIndex:1};for(n in l)l[n]===r&&delete l[n];l=b.dataLabel=a.chart.renderer[e?"text":"label"](h,0,-999,null,null,null,d.useHTML).attr(l).css(v(d.style,c&&{cursor:c})).add(i).shadow(d.shadow)}l&&a.alignDataLabel(b,l,d,null,u)}})};K.prototype.alignDataLabel=function(a,b,c,d,e){var f=this.chart,g=f.inverted,h=o(a.plotX,-999),i=o(a.plotY,-999),k=b.getBBox();if(a=this.visible&&(a.series.forceDL||f.isInsidePlot(h,s(i),g)||d&&f.isInsidePlot(h, +g?d.x+1:d.y+d.height-1,g)))d=v({x:g?f.plotWidth-i:h,y:s(g?f.plotHeight-h:i),width:0,height:0},d),v(c,{width:k.width,height:k.height}),c.rotation?(g={align:c.align,x:d.x+c.x+d.width/2,y:d.y+c.y+d.height/2},b[e?"attr":"animate"](g)):(b.align(c,null,d),g=b.alignAttr,o(c.overflow,"justify")==="justify"?this.justifyDataLabel(b,c,g,k,d,e):o(c.crop,!0)&&(a=f.isInsidePlot(g.x,g.y)&&f.isInsidePlot(g.x+k.width,g.y+k.height)));if(!a)b.attr({y:-999}),b.placed=!1};K.prototype.justifyDataLabel=function(a,b,c,d, +e,f){var g=this.chart,h=b.align,i=b.verticalAlign,k,j;k=c.x;if(k<0)h==="right"?b.align="left":b.x=-k,j=!0;k=c.x+d.width;if(k>g.plotWidth)h==="left"?b.align="right":b.x=g.plotWidth-k,j=!0;k=c.y;if(k<0)i==="bottom"?b.verticalAlign="top":b.y=-k,j=!0;k=c.y+d.height;if(k>g.plotHeight)i==="top"?b.verticalAlign="bottom":b.y=g.plotHeight-k,j=!0;if(j)a.placed=!f,a.align(b,null,e)};if(C.pie)C.pie.prototype.drawDataLabels=function(){var a=this,b=a.data,c,d=a.chart,e=a.options.dataLabels,f=o(e.connectorPadding, +10),g=o(e.connectorWidth,1),h=d.plotWidth,d=d.plotHeight,i,k,j=o(e.softConnector,!0),l=e.distance,m=a.center,n=m[2]/2,p=m[1],u=l>0,r,G,x,t,v=[[],[]],y,z,A,B,D,U=[0,0,0,0],I=function(a,b){return b.y-a.y};if(a.visible&&(e.enabled||a._hasPointLabels)){K.prototype.drawDataLabels.apply(a);q(b,function(a){a.dataLabel&&a.visible&&v[a.half].push(a)});for(B=0;!t&&b[B];)t=b[B]&&b[B].dataLabel&&(b[B].dataLabel.getBBox().height||21),B++;for(B=2;B--;){var b=[],H=[],C=v[B],E=C.length,F;a.sortByAngle(C,B-0.5);if(l> +0){for(D=p-n-l;D<=p+n+l;D+=t)b.push(D);G=b.length;if(E>G){c=[].concat(C);c.sort(I);for(D=E;D--;)c[D].rank=D;for(D=E;D--;)C[D].rank>=G&&C.splice(D,1);E=C.length}for(D=0;D0){if(G=H.pop(),F=G.i, +z=G.y,c>z&&b[F+1]!==null||ch-f&&(U[1]=w(s(y+G-h+f),U[1])),z-t/2<0?U[0]=w(s(-z+t/2),U[0]):z+t/2>d&&(U[2]=w(s(z+t/2-d),U[2]))}}if(Ba(U)===0||this.verifyDataLabelOverflow(U))this.placeDataLabels(),u&&g&&q(this.points,function(b){i= +b.connector;x=b.labelPos;if((r=b.dataLabel)&&r._pos)A=r._attr.visibility,y=r.connX,z=r.connY,k=j?["M",y+(x[6]==="left"?5:-5),z,"C",y,z,2*x[2]-x[4],2*x[3]-x[5],x[2],x[3],"L",x[4],x[5]]:["M",y+(x[6]==="left"?5:-5),z,"L",x[2],x[3],"L",x[4],x[5]],i?(i.animate({d:k}),i.attr("visibility",A)):b.connector=i=a.chart.renderer.path(k).attr({"stroke-width":g,stroke:e.connectorColor||b.color||"#606060",visibility:A}).add(a.dataLabelsGroup);else if(i)b.connector=i.destroy()})}},C.pie.prototype.placeDataLabels= +function(){q(this.points,function(a){var a=a.dataLabel,b;if(a)(b=a._pos)?(a.attr(a._attr),a[a.moved?"animate":"attr"](b),a.moved=!0):a&&a.attr({y:-999})})},C.pie.prototype.alignDataLabel=na,C.pie.prototype.verifyDataLabelOverflow=function(a){var b=this.center,c=this.options,d=c.center,e=c=c.minSize||80,f;d[0]!==null?e=w(b[2]-w(a[1],a[3]),c):(e=w(b[2]-a[1]-a[3],c),b[0]+=(a[3]-a[1])/2);d[1]!==null?e=w(z(e,b[2]-w(a[0],a[2])),c):(e=w(z(e,b[2]-a[0]-a[2]),c),b[1]+=(a[0]-a[2])/2);eo(this.translatedThreshold,f.plotSizeY),k=o(c.inside,!!this.options.stacking);if(h&&(d=y(h),g&&(d={x:f.plotWidth-d.y-d.height,y:f.plotHeight-d.x-d.width,width:d.height,height:d.width}),!k))g?(d.x+=i?0:d.width,d.width=0):(d.y+=i?d.height:0, +d.height=0);c.align=o(c.align,!g||k?"center":i?"right":"left");c.verticalAlign=o(c.verticalAlign,g||k?"middle":i?"top":"bottom");K.prototype.alignDataLabel.call(this,a,b,c,d,e)};var gb=P.TrackerMixin={drawTrackerPoint:function(){var a=this,b=a.chart,c=b.pointer,d=a.options.cursor,e=d&&{cursor:d},f=function(c){var d=c.target,e;if(b.hoverSeries!==a)a.onMouseOver();for(;d&&!e;)e=d.point,d=d.parentNode;if(e!==r&&e!==b.hoverPoint)e.onMouseOver(c)};q(a.points,function(a){if(a.graphic)a.graphic.element.point= +a;if(a.dataLabel)a.dataLabel.element.point=a});if(!a._hasTracking)q(a.trackerGroups,function(b){if(a[b]&&(a[b].addClass("highcharts-tracker").on("mouseover",f).on("mouseout",function(a){c.onTrackerMouseOut(a)}).css(e),ab))a[b].on("touchstart",f)}),a._hasTracking=!0},drawTrackerGraph:function(){var a=this,b=a.options,c=b.trackByArea,d=[].concat(c?a.areaPath:a.graphPath),e=d.length,f=a.chart,g=f.pointer,h=f.renderer,i=f.options.tooltip.snap,k=a.tracker,j=b.cursor,l=j&&{cursor:j},j=a.singlePoints,m, +n=function(){if(f.hoverSeries!==a)a.onMouseOver()},p="rgba(192,192,192,"+(ca?1.0E-4:0.002)+")";if(e&&!c)for(m=e+1;m--;)d[m]==="M"&&d.splice(m+1,0,d[m+1]-i,d[m+2],"L"),(m&&d[m]==="M"||m===e)&&d.splice(m,0,"L",d[m-2]+i,d[m-1]);for(m=0;mz(j.dataMin,j.min)&&i=f.min&&c<=f.max){h=b[i+1];c=d===r?0:d+1;for(d=b[i+1]?z(w(0,S((e.clientX+(h?h.wrappedClientX||h.clientX:g))/2)),g):g;c>=0&&c<=d;)k[c++]=e}this.tooltipPoints=k}},show:function(){this.setVisible(!0)}, +hide:function(){this.setVisible(!1)},select:function(a){this.selected=a=a===r?!this.selected:a;if(this.checkbox)this.checkbox.checked=a;N(this,a?"select":"unselect")},drawTracker:gb.drawTrackerGraph});O(K.prototype,"init",function(a){var b;a.apply(this,Array.prototype.slice.call(arguments,1));(b=this.xAxis)&&b.options.ordinal&&A(this,"updatedData",function(){delete b.ordinalIndex})});O(L.prototype,"getTimeTicks",function(a,b,c,d,e,f,g,h){var i=0,k=0,j,l={},m,n,p,o=[],q=-Number.MAX_VALUE,s=this.options.tickPixelInterval; +if(!this.options.ordinal||!f||f.length<3||c===r)return a.call(this,b,c,d,e);for(n=f.length;kd;f[k]g*5||p){if(f[k]>q){for(j=a.call(this,b,f[i],f[k],e);j.length&&j[0]<=q;)j.shift();j.length&&(q=j[j.length-1]);o=o.concat(j)}i=k+1}if(p)break}a=j.info;if(h&&a.unitRange<=H.hour){k=o.length-1;for(i=1;id?a-1:a;for(x=void 0;h--;)i=k[h],d=x-i,x&&d2){d=b[1]-b[0];for(g=a-1;g--&&!c;)b[g+1]-b[g]!==d&&(c=!0);if(!this.options.keepOrdinalPadding&&(b[0]-f>d||e-b[b.length-1]>d))c=!0}c?(this.ordinalPositions=b,c=this.val2lin(w(f,b[0]),!0),d=this.val2lin(z(e,b[b.length-1]),!0),this.ordinalSlope=e=(e-f)/(d-c),this.ordinalOffset=f-c*e):this.ordinalPositions=this.ordinalSlope=this.ordinalOffset=r}this.groupIntervalFactor=null},val2lin:function(a,b){var c= +this.ordinalPositions;if(c){var d=c.length,e,f;for(e=d;e--;)if(c[e]===a){f=e;break}for(e=d-1;e--;)if(a>c[e]||e===0){c=(a-c[e])/(c[e+1]-c[e]);f=e+c;break}return b?f:this.ordinalSlope*(f||0)+this.ordinalOffset}else return a},lin2val:function(a,b){var c=this.ordinalPositions;if(c){var d=this.ordinalSlope,e=this.ordinalOffset,f=c.length-1,g,h;if(b)a<0?a=c[0]:a>f?a=c[f]:(f=S(a),h=a-f);else for(;f--;)if(g=d*f+e,a>=g){d=d*(f+1)+e;h=(a-g)/(d-g);break}return h!==r&&c[f]!==r?c[f]+(h?h*(c[f+1]-c[f]):0):a}else return a}, +getExtendedPositions:function(){var a=this.chart,b=this.series[0].currentDataGrouping,c=this.ordinalIndex,d=b?b.count+b.unitName:"raw",e=this.getExtremes(),f,g;if(!c)c=this.ordinalIndex={};if(!c[d])f={series:[],getExtremes:function(){return{min:e.dataMin,max:e.dataMax}},options:{ordinal:!0},val2lin:L.prototype.val2lin},q(this.series,function(c){g={xAxis:f,xData:c.xData,chart:a,destroyGroupedData:na};g.options={dataGrouping:b?{enabled:!0,forced:!0,approximation:"open",units:[[b.unitName,[b.count]]]}: +{enabled:!1}};c.processData.apply(g);f.series.push(g)}),this.beforeSetTickPositions.apply(f),c[d]=f.ordinalPositions;return c[d]},getGroupIntervalFactor:function(a,b,c){var d=0,c=c.processedXData,e=c.length,f=[],g=this.groupIntervalFactor;if(!g){for(;d1)j&&q(j,function(a){a.setState()}),f<0?(j=m,p=c.ordinalPositions?c:m):(j=c.ordinalPositions?c:m,p=m),m=p.ordinalPositions,h>m[m.length-1]&&m.push(h), +this.fixedRange=k-i,f=c.toFixedRange(null,null,l.apply(j,[n.apply(j,[i,!0])+f,!0]),l.apply(p,[n.apply(p,[k,!0])+f,!0])),f.min>=z(g.dataMin,i)&&f.max<=w(h,k)&&c.setExtremes(f.min,f.max,!0,!1,{trigger:"pan"}),this.mouseDownX=d,E(this.container,{cursor:"move"})}else e=!0}else e=!0;e&&a.apply(this,Array.prototype.slice.call(arguments,1))});O(K.prototype,"getSegments",function(a){var b,c=this.options.gapSize,d=this.xAxis;a.apply(this,Array.prototype.slice.call(arguments,1));if(c)b=this.segments,q(b,function(a, +f){for(var g=a.length-1;g--;)a[g+1].x-a[g].x>d.closestPointRange*c&&b.splice(f+1,0,a.splice(g+1,a.length-g))})});var ba=K.prototype,J=Hb.prototype,hc=ba.processData,ic=ba.generatePoints,jc=ba.destroy,kc=J.tooltipHeaderFormatter,lc={approximation:"average",groupPixelWidth:2,dateTimeLabelFormats:Kb("millisecond",["%A, %b %e, %H:%M:%S.%L","%A, %b %e, %H:%M:%S.%L","-%H:%M:%S.%L"],"second",["%A, %b %e, %H:%M:%S","%A, %b %e, %H:%M:%S","-%H:%M:%S"],"minute",["%A, %b %e, %H:%M","%A, %b %e, %H:%M","-%H:%M"], +"hour",["%A, %b %e, %H:%M","%A, %b %e, %H:%M","-%H:%M"],"day",["%A, %b %e, %Y","%A, %b %e","-%A, %b %e, %Y"],"week",["Week from %A, %b %e, %Y","%A, %b %e","-%A, %b %e, %Y"],"month",["%B %Y","%B","-%B %Y"],"year",["%Y","%Y","-%Y"])},Wb={line:{},spline:{},area:{},areaspline:{},column:{approximation:"sum",groupPixelWidth:10},arearange:{approximation:"range"},areasplinerange:{approximation:"range"},columnrange:{approximation:"range",groupPixelWidth:10},candlestick:{approximation:"ohlc",groupPixelWidth:10}, +ohlc:{approximation:"ohlc",groupPixelWidth:5}},Xb=[["millisecond",[1,2,5,10,20,25,50,100,200,500]],["second",[1,2,5,10,15,30]],["minute",[1,2,5,10,15,30]],["hour",[1,2,3,4,6,8,12]],["day",[1]],["week",[1]],["month",[1,3,6]],["year",null]],Na={sum:function(a){var b=a.length,c;if(!b&&a.hasNulls)c=null;else if(b)for(c=0;b--;)c+=a[b];return c},average:function(a){var b=a.length,a=Na.sum(a);typeof a==="number"&&b&&(a/=b);return a},open:function(a){return a.length?a[0]:a.hasNulls?null:r},high:function(a){return a.length? +Ba(a):a.hasNulls?null:r},low:function(a){return a.length?Ra(a):a.hasNulls?null:r},close:function(a){return a.length?a[a.length-1]:a.hasNulls?null:r},ohlc:function(a,b,c,d){a=Na.open(a);b=Na.high(b);c=Na.low(c);d=Na.close(d);if(typeof a==="number"||typeof b==="number"||typeof c==="number"||typeof d==="number")return[a,b,c,d]},range:function(a,b){a=Na.low(a);b=Na.high(b);if(typeof a==="number"||typeof b==="number")return[a,b]}};ba.groupData=function(a,b,c,d){var e=this.data,f=this.options.data,g=[], +h=[],i=a.length,k,j,l=!!b,m=[[],[],[],[]],d=typeof d==="function"?d:Na[d],n=this.pointArrayMap,p=n&&n.length,o;for(o=0;o<=i;o++)if(a[o]>=c[0])break;for(;o<=i;o++){for(;c[1]!==r&&a[o]>=c[1]||o===i;)if(k=c.shift(),j=d.apply(0,m),j!==r&&(g.push(k),h.push(j)),m[0]=[],m[1]=[],m[2]=[],m[3]=[],o===i)break;if(o===i)break;if(n){k=this.cropStart+o;k=e&&e[k]||this.pointClass.prototype.applyOptions.apply({series:this},[f[k]]);var q;for(j=0;j0;)f[c]+=h/2;f[0]=d}this.currentDataGrouping=k.info;if(b.pointRange===null)this.pointRange=k.info.totalRange;this.closestPointRange=k.info.totalRange;if(t(f[0])&& +f[0]=g.closestPointRange||H[h]<=H.day&&a.key%H[h]>0){e=d[h][0];break}e=ua(e,a.key);f&&(e+=ua(f,a.key+b.totalRange-1));a=c.headerFormat.replace("{point.key}",e)}else a=kc.call(this,a);return a};ba.destroy=function(){for(var a=this.groupedData||[],b=a.length;b--;)a[b]&&a[b].destroy();jc.apply(this)}; +O(ba,"setOptions",function(a,b){var c=a.call(this,b),d=this.type,e=this.chart.options.plotOptions,f=T[d].dataGrouping;if(Wb[d])f||(f=y(lc,Wb[d])),c.dataGrouping=y(f,e.series&&e.series.dataGrouping,e[d].dataGrouping,b.dataGrouping);if(this.chart.options._stock)this.requireSorting=!0;return c});O(L.prototype,"setScale",function(a){a.call(this);q(this.series,function(a){a.hasProcessed=!1})});L.prototype.getGroupPixelWidth=function(){var a=this.series,b=a.length,c,d=0,e=!1,f;for(c=b;c--;)(f=a[c].options.dataGrouping)&& +(d=w(d,f.groupPixelWidth));for(c=b;c--;)if((f=a[c].options.dataGrouping)&&a[c].hasProcessed)if(b=(a[c].processedXData||a[c].data).length,a[c].groupPixelWidth||b>this.chart.plotSizeX/d||b&&f.forced)e=!0;return e?d:0};T.ohlc=y(T.column,{lineWidth:1,tooltip:{pointFormat:' {series.name}
      Open: {point.open}
      High: {point.high}
      Low: {point.low}
      Close: {point.close}
      '},states:{hover:{lineWidth:3}},threshold:null});J=ga(C.column,{type:"ohlc", +pointArrayMap:["open","high","low","close"],toYData:function(a){return[a.open,a.high,a.low,a.close]},pointValKey:"high",pointAttrToOptions:{stroke:"color","stroke-width":"lineWidth"},upColorProp:"stroke",getAttribs:function(){C.column.prototype.getAttribs.apply(this,arguments);var a=this.options,b=a.states,a=a.upColor||this.color,c=y(this.pointAttr),d=this.upColorProp;c[""][d]=a;c.hover[d]=b.hover.upColor||a;c.select[d]=b.select.upColor||a;q(this.points,function(a){if(a.open"},threshold:null,y:-30});C.flags=ga(C.column,{type:"flags",sorted:!1,noSharedTooltip:!0,takeOrdinalPosition:!1,trackerGroups:["markerGroup"],forceCrop:!0,init:K.prototype.init,pointAttrToOptions:{fill:"fillColor",stroke:"color","stroke-width":"lineWidth",r:"radius"},translate:function(){C.column.prototype.translate.apply(this);var a=this.chart,b=this.points,c=b.length-1,d,e,f=this.options.onSeries, +f=(d=f&&a.get(f))&&d.options.step,g=d&&d.points,h=g&&g.length,i=this.xAxis,k=i.getExtremes(),j,l,m;if(d&&d.visible&&h){d=d.currentDataGrouping;l=g[h-1].x+(d?d.totalRange:0);for(b.sort(function(a,b){return a.x-b.x});h--&&b[c];)if(d=b[c],j=g[h],j.x<=d.x&&j.plotY!==r){if(d.x<=l)d.plotY=j.plotY,j.x=k.min&&c.x<=k.max?c.plotY=a.chartHeight-i.bottom-(i.opposite?i.height: +0)+i.offset-a.plotTop:c.shapeArgs={};if((e=b[d-1])&&e.plotX===c.plotX){if(e.stackIndex===r)e.stackIndex=0;c.stackIndex=e.stackIndex+1}})},drawPoints:function(){var a,b=this.pointAttr[""],c=this.points,d=this.chart.renderer,e,f,g=this.options,h=g.y,i,k,j,l,m=g.lineWidth%2/2,n,o;for(k=c.length;k--;)if(j=c[k],a=j.plotX>this.xAxis.len,e=j.plotX+(a?m:-m),l=j.stackIndex,i=j.options.shape||g.shape,f=j.plotY,f!==r&&(f=j.plotY+h+m-(l!==r&&l*g.stackDistance)),n=l?r:j.plotX+m,o=l?r:j.plotY,l=j.graphic,f!==r&& +e>=0&&!a)a=j.pointAttr[j.selected?"select":""]||b,l?l.attr({x:e,y:f,r:a.r,anchorX:n,anchorY:o}):j.graphic=d.label(j.options.title||g.title||"A",e,f,i,n,o,g.useHTML).css(y(g.style,j.style)).attr(a).attr({align:i==="flag"?"left":"center",width:g.width,height:g.height}).add(this.markerGroup).shadow(g.shadow),j.tooltipPos=[e,f];else if(l)j.graphic=l.destroy()},drawTracker:function(){var a=this.points;gb.drawTrackerPoint.apply(this);q(a,function(b){var c=b.graphic;c&&A(c.element,"mouseover",function(){if(b.stackIndex> +0&&!b.raised)b._y=c.y,c.attr({y:b._y-8}),b.raised=!0;q(a,function(a){if(a!==b&&a.raised&&a.graphic)a.graphic.attr({y:a._y}),a.raised=!1})})})},animate:na});qb.flag=function(a,b,c,d,e){var f=e&&e.anchorX||a,e=e&&e.anchorY||b;return["M",f,e,"L",a,b+d,a,b,a+c,b,a+c,b+d,a,b+d,"M",f,e,"Z"]};q(["circle","square"],function(a){qb[a+"pin"]=function(b,c,d,e,f){var g=f&&f.anchorX,f=f&&f.anchorY,b=qb[a](b,c,d,e);g&&f&&b.push("M",g,c>f?c:c+e,"L",g,f);return b}});Wa===P.VMLRenderer&&q(["flag","circlepin","squarepin"], +function(a){fb.prototype.symbols[a]=qb[a]});J=[].concat(Xb);J[4]=["day",[1,2,3,4]];J[5]=["week",[1,2,3]];v(F,{navigator:{handles:{backgroundColor:"#ebe7e8",borderColor:"#b2b1b6"},height:40,margin:25,maskFill:"rgba(128,179,236,0.3)",maskInside:!0,outlineColor:"#b2b1b6",outlineWidth:1,series:{type:C.areaspline===r?"line":"areaspline",color:"#4572A7",compare:null,fillOpacity:0.05,dataGrouping:{approximation:"average",enabled:!0,groupPixelWidth:2,smoothed:!0,units:J},dataLabels:{enabled:!1,zIndex:2}, +id:"highcharts-navigator-series",lineColor:"#4572A7",lineWidth:1,marker:{enabled:!1},pointRange:0,shadow:!1,threshold:null},xAxis:{tickWidth:0,lineWidth:0,gridLineColor:"#EEE",gridLineWidth:1,tickPixelInterval:200,labels:{align:"left",style:{color:"#888"},x:3,y:-4},crosshair:!1},yAxis:{gridLineWidth:0,startOnTick:!1,endOnTick:!1,minPadding:0.1,maxPadding:0.1,labels:{enabled:!1},crosshair:!1,title:{text:null},tickWidth:0}},scrollbar:{height:cb?20:14,barBackgroundColor:"#bfc8d1",barBorderRadius:0,barBorderWidth:1, +barBorderColor:"#bfc8d1",buttonArrowColor:"#666",buttonBackgroundColor:"#ebe7e8",buttonBorderColor:"#bbb",buttonBorderRadius:0,buttonBorderWidth:1,minWidth:6,rifleColor:"#666",trackBackgroundColor:"#eeeeee",trackBorderColor:"#eeeeee",trackBorderWidth:1,liveRedraw:ca&&!cb}});yb.prototype={drawHandle:function(a,b){var c=this.chart,d=c.renderer,e=this.elementsToDestroy,f=this.handles,g=this.navigatorOptions.handles,g={fill:g.backgroundColor,stroke:g.borderColor,"stroke-width":1},h;this.rendered||(f[b]= +d.g("navigator-handle-"+["left","right"][b]).css({cursor:"e-resize"}).attr({zIndex:4-b}).add(),h=d.rect(-4.5,0,9,16,0,1).attr(g).add(f[b]),e.push(h),h=d.path(["M",-1.5,4,"L",-1.5,12,"M",0.5,4,"L",0.5,12]).attr(g).add(f[b]),e.push(h));f[b][c.isResizing?"animate":"attr"]({translateX:this.scrollerLeft+this.scrollbarHeight+parseInt(a,10),translateY:this.top+this.height/2-8})},drawScrollbarButton:function(a){var b=this.chart.renderer,c=this.elementsToDestroy,d=this.scrollbarButtons,e=this.scrollbarHeight, +f=this.scrollbarOptions,g;this.rendered||(d[a]=b.g().add(this.scrollbarGroup),g=b.rect(-0.5,-0.5,e+1,e+1,f.buttonBorderRadius,f.buttonBorderWidth).attr({stroke:f.buttonBorderColor,"stroke-width":f.buttonBorderWidth,fill:f.buttonBackgroundColor}).add(d[a]),c.push(g),g=b.path(["M",e/2+(a?-1:1),e/2-3,"L",e/2+(a?-1:1),e/2+3,e/2+(a?2:-2),e/2]).attr({fill:f.buttonArrowColor}).add(d[a]),c.push(g));a&&d[a].attr({translateX:this.scrollerWidth-e})},render:function(a,b,c,d){var e=this.chart,f=e.renderer,g,h, +i,k,j=this.scrollbarGroup,l=this.navigatorGroup,m=this.scrollbar,l=this.xAxis,n=this.scrollbarTrack,p=this.scrollbarHeight,q=this.scrollbarEnabled,r=this.navigatorOptions,t=this.scrollbarOptions,x=t.minWidth,v=this.height,y=this.top,A=this.navigatorEnabled,B=r.outlineWidth,C=B/2,F=0,D=this.outlineHeight,I=t.barBorderRadius,H=t.barBorderWidth,E=y+C,J;if(!isNaN(a)){this.navigatorLeft=g=o(l.left,e.plotLeft+p);this.navigatorWidth=h=o(l.len,e.plotWidth-2*p);this.scrollerLeft=i=g-p;this.scrollerWidth=k= +k=h+2*p;l.getExtremes&&(J=this.getUnionExtremes(!0))&&(J.dataMin!==l.min||J.dataMax!==l.max)&&l.setExtremes(J.dataMin,J.dataMax,!0,!1);c=o(c,l.translate(a));d=o(d,l.translate(b));if(isNaN(c)||M(c)===Infinity)c=0,d=k;if(!(l.translate(d,!0)-l.translate(c,!0)12?"visible":"hidden"})[e]({d:["M",x-3,p/4,"L",x-3,2*p/3,"M",x,p/4,"L",x,2*p/3,"M",x+3,p/4,"L",x+3,2*p/3]});this.scrollbarPad=F;this.rendered=!0}}},addEvents:function(){var a=this.chart.container, +b=this.mouseDownHandler,c=this.mouseMoveHandler,d=this.mouseUpHandler,e;e=[[a,"mousedown",b],[a,"mousemove",c],[document,"mouseup",d]];ab&&e.push([a,"touchstart",b],[a,"touchmove",c],[document,"touchend",d]);q(e,function(a){A.apply(null,a)});this._events=e},removeEvents:function(){q(this._events,function(a){R.apply(null,a)});this._events=r;this.navigatorEnabled&&this.baseSeries&&R(this.baseSeries,"updatedData",this.updatedDataHandler)},init:function(){var a=this,b=a.chart,c,d,e=a.scrollbarHeight, +f=a.navigatorOptions,g=a.height,h=a.top,i,k,j=document.body.style,l,m=a.baseSeries;a.mouseDownHandler=function(d){var d=b.pointer.normalize(d),e=a.zoomedMin,f=a.zoomedMax,h=a.top,k=a.scrollbarHeight,m=a.scrollerLeft,n=a.scrollerWidth,o=a.navigatorLeft,p=a.navigatorWidth,q=a.scrollbarPad,r=a.range,s=d.chartX,t=d.chartY,d=b.xAxis[0],v,w=cb?10:7;if(t>h&&to+e-q&&sm&&sm+n-k?e+r*0.2:s=p)f=p-r,v=c.dataMax;if(f!==e)a.fixedWidth=r,e=c.toFixedRange(f,f+r,null,v),d.setExtremes(e.min,e.max,!0,!1,{trigger:"navigator"})}};a.mouseMoveHandler=function(c){var d=a.scrollbarHeight,e=a.navigatorLeft, +f=a.navigatorWidth,g=a.scrollerLeft,h=a.scrollerWidth,j=a.range,l;if(c.pageX!==0)c=b.pointer.normalize(c),l=c.chartX,lg+h-d&&(l=g+h-d),a.grabbedLeft?(k=!0,a.render(0,0,l-e,a.otherHandlePos)):a.grabbedRight?(k=!0,a.render(0,0,a.otherHandlePos,l-e)):a.grabbedCenter&&(k=!0,lf+i-j&&(l=f+i-j),a.render(0,0,l-i,l-i+j)),k&&a.scrollbarOptions.liveRedraw&&setTimeout(function(){a.mouseUpHandler(c)},0)};a.mouseUpHandler=function(d){var e,f;if(k){if(a.zoomedMin===a.otherHandlePos)e=a.fixedExtreme; +else if(a.zoomedMax===a.otherHandlePos)f=a.fixedExtreme;e=c.toFixedRange(a.zoomedMin,a.zoomedMax,e,f);b.xAxis[0].setExtremes(e.min,e.max,!0,!1,{trigger:"navigator",triggerOp:"navigator-drag",DOMEvent:d})}if(d.type!=="mousemove")a.grabbedLeft=a.grabbedRight=a.grabbedCenter=a.fixedWidth=a.fixedExtreme=a.otherHandlePos=k=i=null,j.cursor=l||""};var n=b.xAxis.length,p=b.yAxis.length;b.extraBottomMargin=a.outlineHeight+f.margin;a.navigatorEnabled?(a.xAxis=c=new L(b,y({ordinal:m&&m.xAxis.options.ordinal}, +f.xAxis,{id:"navigator-x-axis",isX:!0,type:"datetime",index:n,height:g,offset:0,offsetLeft:e,offsetRight:-e,keepOrdinalPadding:!0,startOnTick:!1,endOnTick:!1,minPadding:0,maxPadding:0,zoomEnabled:!1})),a.yAxis=d=new L(b,y(f.yAxis,{id:"navigator-y-axis",alignTicks:!1,height:g,offset:0,index:p,zoomEnabled:!1})),m||f.series.data?a.addBaseSeries():b.series.length===0&&O(b,"redraw",function(c,d){if(b.series.length>0&&!a.series)a.setBaseSeries(),b.redraw=c;c.call(b,d)})):a.xAxis=c={translate:function(a, +c){var d=b.xAxis[0].getExtremes(),f=b.plotWidth-2*e,g=d.dataMin,d=d.dataMax-g;return c?a*d/f+g:f*(a-g)/d},toFixedRange:L.prototype.toFixedRange};O(b,"getMargins",function(b){var e=this.legend,f=e.options;b.call(this);a.top=h=a.navigatorOptions.top||this.chartHeight-a.height-a.scrollbarHeight-this.spacing[2]-(f.verticalAlign==="bottom"&&f.enabled&&!f.floating?e.legendHeight+o(f.margin,10):0);if(c&&d)c.options.top=d.options.top=h,c.setAxisSize(),d.setAxisSize()});a.addEvents()},getUnionExtremes:function(a){var b= +this.chart.xAxis[0],c=this.xAxis,d=c.options;if(!a||b.dataMin!==null)return{dataMin:o(d&&d.min,(t(b.dataMin)&&t(c.dataMin)?z:o)(b.dataMin,c.dataMin)),dataMax:o(d&&d.max,(t(b.dataMax)&&t(c.dataMax)?w:o)(b.dataMax,c.dataMax))}},setBaseSeries:function(a){var b=this.chart,a=a||b.options.navigator.baseSeries;this.series&&this.series.remove();this.baseSeries=b.series[a]||typeof a==="string"&&b.get(a)||b.series[0];this.xAxis&&this.addBaseSeries()},addBaseSeries:function(){var a=this.baseSeries,b=a?a.options: +{},c=b.data,d=this.navigatorOptions.series,e;e=d.data;this.hasNavigatorData=!!e;b=y(b,d,{enableMouseTracking:!1,group:"nav",padXAxis:!1,xAxis:"navigator-x-axis",yAxis:"navigator-y-axis",name:"Navigator",showInLegend:!1,isInternal:!0,visible:!0});b.data=e||c;this.series=this.chart.initSeries(b);if(a&&this.navigatorOptions.adaptToUpdatedData!==!1)A(a,"updatedData",this.updatedDataHandler),a.userOptions.events=v(a.userOptions.event,{updatedData:this.updatedDataHandler})},updatedDataHandler:function(){var a= +this.chart.scroller,b=a.baseSeries,c=b.xAxis,d=c.getExtremes(),e=d.min,f=d.max,g=d.dataMin,d=d.dataMax,h=f-e,i,k,j,l,m,n=a.series;i=n.xData;var o=!!c.setExtremes;k=f>=i[i.length-1]-(this.closestPointRange||0);i=e<=g;if(!a.hasNavigatorData)n.options.pointStart=b.xData[0],n.setData(b.options.data,!1),m=!0;i&&(l=g,j=l+h);k&&(j=d,i||(l=w(j-h,n.xData[0])));o&&(i||k)?isNaN(l)||c.setExtremes(l,j,!0,!1,{trigger:"updatedData"}):(m&&this.chart.redraw(!1),a.render(w(e,g),z(f,d)))},destroy:function(){this.removeEvents(); +q([this.xAxis,this.yAxis,this.leftShade,this.rightShade,this.outline,this.scrollbarTrack,this.scrollbarRifles,this.scrollbarGroup,this.scrollbar],function(a){a&&a.destroy&&a.destroy()});this.xAxis=this.yAxis=this.leftShade=this.rightShade=this.outline=this.scrollbarTrack=this.scrollbarRifles=this.scrollbarGroup=this.scrollbar=null;q([this.scrollbarButtons,this.handles,this.elementsToDestroy],function(a){Ka(a)})}};P.Scroller=yb;O(L.prototype,"zoom",function(a,b,c){var d=this.chart,e=d.options,f=e.chart.zoomType, +g=e.navigator,e=e.rangeSelector,h;if(this.isXAxis&&(g&&g.enabled||e&&e.enabled))if(f==="x")d.resetZoomButton="blocked";else if(f==="y")h=!1;else if(f==="xy")d=this.previousZoom,t(b)?this.previousZoom=[this.min,this.max]:d&&(b=d[0],c=d[1],delete this.previousZoom);return h!==r?h:a.call(this,b,c)});O(va.prototype,"init",function(a,b,c){A(this,"beforeRender",function(){var a=this.options;if(a.navigator.enabled||a.scrollbar.enabled)this.scroller=new yb(this)});a.call(this,b,c)});O(K.prototype,"addPoint", +function(a,b,c,d,e){var f=this.options.turboThreshold;f&&this.xData.length>f&&fa(b)&&!Pa(b)&&this.chart.scroller&&qa(20,!0);a.call(this,b,c,d,e)});v(F,{rangeSelector:{buttonTheme:{width:28,height:18,fill:"#f7f7f7",padding:2,r:0,"stroke-width":0,style:{color:"#444",cursor:"pointer",fontWeight:"normal"},zIndex:7,states:{hover:{fill:"#e7e7e7"},select:{fill:"#e7f0f9",style:{color:"black",fontWeight:"bold"}}}},inputPosition:{align:"right"},labelStyle:{color:"#666"}}});F.lang=y(F.lang,{rangeSelectorZoom:"Zoom", +rangeSelectorFrom:"From",rangeSelectorTo:"To"});zb.prototype={clickButton:function(a,b){var c=this,d=c.selected,e=c.chart,f=c.buttons,g=c.buttonOptions[a],h=e.xAxis[0],i=e.scroller&&e.scroller.getUnionExtremes()||h||{},k=i.dataMin,j=i.dataMax,l,m=h&&s(z(h.max,o(j,h.max))),n=new Date(m),p=g.type,u=g.count,i=g._range,t;if(!(k===null||j===null||a===c.selected)){if(p==="month"||p==="year")l={month:"Month",year:"FullYear"}[p],n["set"+l](n["get"+l]()-u),l=n.getTime(),k=o(k,Number.MIN_VALUE),isNaN(l)||l< +k?(l=k,m=z(l+i,j)):i=m-l;else if(i)l=w(m-i,k),m=z(l+i,j);else if(p==="ytd")if(h){if(j===r)k=Number.MAX_VALUE,j=Number.MIN_VALUE,q(e.series,function(a){a=a.xData;k=z(a[0],k);j=w(a[a.length-1],j)}),b=!1;m=new Date(j);t=m.getFullYear();l=t=w(k||0,Date.UTC(t,0,1));m=m.getTime();m=z(j||m,m)}else{A(e,"beforeRender",function(){c.clickButton(a)});return}else p==="all"&&h&&(l=k,m=j);f[d]&&f[d].setState(0);f[a]&&f[a].setState(2);e.fixedRange=i;h?h.setExtremes(l,m,o(b,1),0,{trigger:"rangeSelectorButton",rangeSelectorButton:g}): +(d=e.options.xAxis,d[0]=y(d[0],{range:i,min:t}));c.setSelected(a)}},setSelected:function(a){this.selected=this.options.selected=a},defaultButtons:[{type:"month",count:1,text:"1m"},{type:"month",count:3,text:"3m"},{type:"month",count:6,text:"6m"},{type:"ytd",text:"YTD"},{type:"year",count:1,text:"1y"},{type:"all",text:"All"}],init:function(a){var b=this,c=a.options.rangeSelector,d=c.buttons||[].concat(b.defaultButtons),e=c.selected,f=b.blurInputs=function(){var a=b.minInput,c=b.maxInput;a&&a.blur(); +c&&c.blur()};b.chart=a;b.options=c;b.buttons=[];a.extraTopMargin=35;b.buttonOptions=d;A(a.container,"mousedown",f);A(a,"resize",f);q(d,b.computeButtonRange);e!==r&&d[e]&&this.clickButton(e,!1);A(a,"load",function(){A(a.xAxis[0],"afterSetExtremes",function(){b.updateButtonStates(!0)})})},updateButtonStates:function(a){var b=this,c=this.chart,d=c.xAxis[0],e=c.scroller&&c.scroller.getUnionExtremes()||d,f=e.dataMin,g=e.dataMax,h=b.selected,i=b.buttons;a&&c.fixedRange!==s(d.max-d.min)&&(i[h]&&i[h].setState(0), +b.setSelected(null));q(b.buttonOptions,function(a,c){var e=a._range,m=e>g-f,n=e=g-f&&i[c].state!==2,q=a.type==="ytd"&&ua("%Y",f)===ua("%Y",g);e===s(d.max-d.min)&&c!==h?(b.setSelected(c),i[c].setState(2)):m||n||o||q?i[c].setState(3):i[c].state===3&&i[c].setState(0)})},computeButtonRange:function(a){var b=a.type,c=a.count||1,d={millisecond:1,second:1E3,minute:6E4,hour:36E5,day:864E5,week:6048E5};if(d[b])a._range=d[b]*c;else if(b==="month"||b==="year")a._range= +{month:30,year:365}[b]*864E5*c},setInputValue:function(a,b){var c=this.chart.options.rangeSelector;if(t(b))this[a+"Input"].HCTime=b;this[a+"Input"].value=ua(c.inputEditDateFormat||"%Y-%m-%d",this[a+"Input"].HCTime);this[a+"DateBox"].attr({text:ua(c.inputDateFormat||"%b %e, %Y",this[a+"Input"].HCTime)})},drawInput:function(a){var b=this,c=b.chart,d=c.renderer.style,e=c.renderer,f=c.options.rangeSelector,g=b.div,h=a==="min",i,k,j,l=this.inputGroup;this[a+"Label"]=k=e.label(F.lang[h?"rangeSelectorFrom": +"rangeSelectorTo"],this.inputGroup.offset).attr({padding:2}).css(y(d,f.labelStyle)).add(l);l.offset+=k.width+5;this[a+"DateBox"]=j=e.label("",l.offset).attr({padding:2,width:f.inputBoxWidth||90,height:f.inputBoxHeight||17,stroke:f.inputBoxBorderColor||"silver","stroke-width":1}).css(y({textAlign:"center",color:"#444"},d,f.inputStyle)).on("click",function(){b[a+"Input"].focus()}).add(l);l.offset+=j.width+(h?10:0);this[a+"Input"]=i=$("input",{name:a,className:"highcharts-range-selector",type:"text"}, +v({position:"absolute",border:0,width:"1px",height:"1px",padding:0,textAlign:"center",fontSize:d.fontSize,fontFamily:d.fontFamily,top:c.plotTop+"px"},f.inputStyle),g);i.onfocus=function(){E(this,{left:l.translateX+j.x+"px",top:l.translateY+"px",width:j.width-2+"px",height:j.height-2+"px",border:"2px solid silver"})};i.onblur=function(){E(this,{border:0,width:"1px",height:"1px"});b.setInputValue(a)};i.onchange=function(){var a=i.value,d=(f.inputDateParser||Date.parse)(a),e=c.xAxis[0],g=e.dataMin,j= +e.dataMax;isNaN(d)&&(d=a.split("-"),d=Date.UTC(I(d[0]),I(d[1])-1,I(d[2])));isNaN(d)||(F.global.useUTC||(d+=(new Date).getTimezoneOffset()*6E4),h?d>b.maxInput.HCTime?d=r:dj&&(d=j),d!==r&&c.xAxis[0].setExtremes(h?d:e.min,h?e.max:d,r,r,{trigger:"rangeSelectorInput"}))}},render:function(a,b){var c=this,d=c.chart,e=d.renderer,f=d.container,g=d.options,h=g.exporting&&g.navigation&&g.navigation.buttonOptions,i=g.rangeSelector,k=c.buttons,g=F.lang,j=c.div,j=c.inputGroup, +l=i.buttonTheme,m=i.inputEnabled!==!1,n=l&&l.states,p=d.plotLeft,r;if(!c.rendered&&(c.zoomText=e.text(g.rangeSelectorZoom,p,d.plotTop-20).css(i.labelStyle).add(),r=p+c.zoomText.getBBox().width+5,q(c.buttonOptions,function(a,b){k[b]=e.button(a.text,r,d.plotTop-35,function(){c.clickButton(b);c.isActive=!0},l,n&&n.hover,n&&n.select).css({textAlign:"center"}).add();r+=k[b].width+o(i.buttonSpacing,5);c.selected===b&&k[b].setState(2)}),c.updateButtonStates(),m))c.div=j=$("div",null,{position:"relative", +height:0,zIndex:1}),f.parentNode.insertBefore(j,f),c.inputGroup=j=e.g("input-group").add(),j.offset=0,c.drawInput("min"),c.drawInput("max");m&&(f=d.plotTop-45,j.align(v({y:f,width:j.offset,x:h&&f<(h.y||0)+h.height-d.spacing[0]?-40:0},i.inputPosition),!0,d.spacingBox),c.setInputValue("min",a),c.setInputValue("max",b));c.rendered=!0},destroy:function(){var a=this.minInput,b=this.maxInput,c=this.chart,d=this.blurInputs,e;R(c.container,"mousedown",d);R(c,"resize",d);Ka(this.buttons);if(a)a.onfocus=a.onblur= +a.onchange=null;if(b)b.onfocus=b.onblur=b.onchange=null;for(e in this)this[e]&&e!=="chart"&&(this[e].destroy?this[e].destroy():this[e].nodeType&&Sa(this[e])),this[e]=null}};L.prototype.toFixedRange=function(a,b,c,d){var e=this.chart&&this.chart.fixedRange,a=o(c,this.translate(a,!0)),b=o(d,this.translate(b,!0)),c=e&&(b-a)/e;c>0.7&&c<1.3&&(d?a=b-e:b=a+e);return{min:a,max:b}};O(va.prototype,"init",function(a,b,c){A(this,"init",function(){if(this.options.rangeSelector.enabled)this.rangeSelector=new zb(this)}); +a.call(this,b,c)});P.RangeSelector=zb;va.prototype.callbacks.push(function(a){function b(){f=a.xAxis[0].getExtremes();g.render(f.min,f.max)}function c(){f=a.xAxis[0].getExtremes();isNaN(f.min)||h.render(f.min,f.max)}function d(a){a.triggerOp!=="navigator-drag"&&g.render(a.min,a.max)}function e(a){h.render(a.min,a.max)}var f,g=a.scroller,h=a.rangeSelector;g&&(A(a.xAxis[0],"afterSetExtremes",d),O(a,"drawChartBox",function(a){var c=this.isDirtyBox;a.call(this);c&&b()}),b());h&&(A(a.xAxis[0],"afterSetExtremes", +e),A(a,"resize",c),c());A(a,"destroy",function(){g&&R(a.xAxis[0],"afterSetExtremes",d);h&&(R(a,"resize",c),R(a.xAxis[0],"afterSetExtremes",e))})});P.StockChart=function(a,b){var c=a.series,d,e=o(a.navigator&&a.navigator.enabled,!0)?{startOnTick:!1,endOnTick:!1}:null,f={marker:{enabled:!1,radius:2},states:{hover:{lineWidth:2}}},g={shadow:!1,borderWidth:0};a.xAxis=xa(ma(a.xAxis||{}),function(a){return y({minPadding:0,maxPadding:0,ordinal:!0,title:{text:null},labels:{overflow:"justify"},showLastLabel:!0}, +a,{type:"datetime",categories:null},e)});a.yAxis=xa(ma(a.yAxis||{}),function(a){d=o(a.opposite,!0);return y({labels:{y:-2},opposite:d,showLastLabel:!1,title:{text:null}},a)});a.series=null;a=y({chart:{panning:!0,pinchType:"x"},navigator:{enabled:!0},scrollbar:{enabled:!0},rangeSelector:{enabled:!0},title:{text:null,style:{fontSize:"16px"}},tooltip:{shared:!0,crosshairs:!0},legend:{enabled:!1},plotOptions:{line:f,spline:f,area:f,areaspline:f,arearange:f,areasplinerange:f,column:g,columnrange:g,candlestick:g, +ohlc:g}},a,{_stock:!0,chart:{inverted:!1}});a.series=c;return new va(a,b)};O(Xa.prototype,"init",function(a,b,c){var d=c.chart.pinchType||"";a.call(this,b,c);this.pinchX=this.pinchHor=d.indexOf("x")!==-1;this.pinchY=this.pinchVert=d.indexOf("y")!==-1;this.hasZoom=this.hasZoom||this.pinchHor||this.pinchVert});O(L.prototype,"autoLabelAlign",function(a){if(this.chart.options._stock&&this.coll==="yAxis"&&wa(this,this.chart.yAxis)===0){if(this.options.labels.x===15)this.options.labels.x=0;return"right"}return a.call(this)}); +L.prototype.getPlotLinePath=function(a,b,c,d,e){var f=this,g=this.isLinked&&!this.series?this.linkedParent.series:this.series,h=f.chart,i=h.renderer,k=f.left,j=f.top,l,m,n,p,r=[],v,w;v=f.isXAxis?t(f.options.yAxis)?[h.yAxis[f.options.yAxis]]:xa(g,function(a){return a.yAxis}):t(f.options.xAxis)?[h.xAxis[f.options.xAxis]]:xa(g,function(a){return a.xAxis});q(f.isXAxis?h.yAxis:h.xAxis,function(a){if(t(a.options.id)?a.options.id.indexOf("navigator")===-1:1){var b=a.isXAxis?"yAxis":"xAxis",b=t(a.options[b])? +h[b][a.options[b]]:h[b][0];f===b&&v.push(a)}});w=v.length?[]:[f];q(v,function(a){wa(a,w)===-1&&w.push(a)});e=o(e,f.translate(a,null,null,c));isNaN(e)||(f.horiz?q(w,function(a){m=a.top;p=m+a.len;l=n=s(e+f.transB);(l>=k&&l<=k+f.width||d)&&r.push("M",l,m,"L",n,p)}):q(w,function(a){l=a.left;n=l+a.width;m=p=s(j+f.height-e);(m>=j&&m<=j+f.height||d)&&r.push("M",l,m,"L",n,p)}));if(r.length>0)return i.crispPolyLine(r,b||1)};L.prototype.getPlotBandPath=function(a,b){var c=this.getPlotLinePath(b),d=this.getPlotLinePath(a), +e=[],f;if(d&&c)for(f=0;fk+this.height)this.hideCrosshair();else{!n&&!f.formatter&&(this.isDatetimeAxis&&(p="%b %d, %Y"),n="{value"+(p?":"+p:"")+"}");j.attr({text:n? +Ja(n,{value:c[g]}):f.formatter.call(this,c[g]),x:l,y:m,visibility:"visible"});c=j.getBBox();if(b){if(this.options.tickPosition==="inside"&&!h||this.options.tickPosition!=="inside"&&h)m=j.y-c.height}else m=j.y-c.height/2;b?(d=i-c.x,e=i+this.width-c.x):(d=this.labelAlign==="left"?i:0,e=this.labelAlign==="right"?i+this.width:a.chartWidth);j.translateX=e&&(l-=j.translateX+c.width-e);j.attr({x:l,y:m,visibility:"visible"})}}});var mc=ba.init,nc=ba.processData, +oc=za.prototype.tooltipFormatter;ba.init=function(){mc.apply(this,arguments);this.setCompare(this.options.compare)};ba.setCompare=function(a){this.modifyValue=a==="value"||a==="percent"?function(b,c){var d=this.compareValue;if(b!==r&&(b=a==="value"?b-d:b=100*(b/d)-100,c))c.change=b;return b}:null;if(this.chart.hasRendered)this.isDirty=!0};ba.processData=function(){var a=0,b,c,d;nc.apply(this,arguments);if(this.xAxis&&this.processedYData){b=this.processedXData;c=this.processedYData;for(d=c.length;a< +d;a++)if(typeof c[a]==="number"&&b[a]>=this.xAxis.min){this.compareValue=c[a];break}}};O(ba,"getExtremes",function(a){a.call(this);if(this.modifyValue)this.dataMax=this.modifyValue(this.dataMax),this.dataMin=this.modifyValue(this.dataMin)});L.prototype.setCompare=function(a,b){this.isXAxis||(q(this.series,function(b){b.setCompare(a)}),o(b,!0)&&this.chart.redraw())};za.prototype.tooltipFormatter=function(a){a=a.replace("{point.change}",(this.change>0?"+":"")+Ia(this.change,o(this.series.tooltipOptions.changeDecimals, +2)));return oc.apply(this,[a])};O(K.prototype,"render",function(a){if(this.isCartesian&&this.chart.options._stock)this.clipBox?this.chart[this.sharedClipKey]&&this.chart[this.sharedClipKey].attr({width:this.xAxis.len,height:this.yAxis.len}):(this.clipBox=y(this.chart.clipBox),this.clipBox.width=this.xAxis.len,this.clipBox.height=this.yAxis.len);a.call(this)});v(P,{Axis:L,Chart:va,Color:Fa,Point:za,Tick:Za,Renderer:Wa,Series:K,SVGElement:Z,SVGRenderer:ka,arrayMin:Ra,arrayMax:Ba,charts:aa,dateFormat:ua, +format:Ja,pathAnim:Bb,getOptions:function(){return F},hasBidiBug:Yb,isTouchDevice:cb,numberFormat:Ia,seriesTypes:C,setOptions:function(a){F=y(!0,F,a);Mb();return F},addEvent:A,removeEvent:R,createElement:$,discardElement:Sa,css:E,each:q,extend:v,map:xa,merge:y,pick:o,splat:ma,extendClass:ga,pInt:I,wrap:O,svg:ca,canvas:ja,vml:!ca&&!ja,product:"Highstock",version:"2.0.1"})})(); diff --git a/htdocs/js/lib/highstock/modules/canvas-tools.js b/htdocs/js/lib/highstock/modules/canvas-tools.js new file mode 100644 index 00000000..b015ce6a --- /dev/null +++ b/htdocs/js/lib/highstock/modules/canvas-tools.js @@ -0,0 +1,133 @@ +/* + A class to parse color values + @author Stoyan Stefanov + @link http://www.phpied.com/rgb-color-parser-in-javascript/ + Use it if you like it + + canvg.js - Javascript SVG parser and renderer on Canvas + MIT Licensed + Gabe Lerner (gabelerner@gmail.com) + http://code.google.com/p/canvg/ + + Requires: rgbcolor.js - http://www.phpied.com/rgb-color-parser-in-javascript/ + + Highstock JS v2.0.1 (2014-04-24) + CanVGRenderer Extension module + + (c) 2011-2012 Torstein Honsi, Erik Olsson + + License: www.highcharts.com/license +*/ +function RGBColor(m){this.ok=!1;m.charAt(0)=="#"&&(m=m.substr(1,6));var m=m.replace(/ /g,""),m=m.toLowerCase(),a={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"00ffff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000000",blanchedalmond:"ffebcd",blue:"0000ff",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"00ffff",darkblue:"00008b", +darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dodgerblue:"1e90ff",feldspar:"d19275",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"ff00ff", +gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgrey:"d3d3d3",lightgreen:"90ee90",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa", +lightslateblue:"8470ff",lightslategray:"778899",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"00ff00",limegreen:"32cd32",linen:"faf0e6",magenta:"ff00ff",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370d8",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080", +oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"d87093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",red:"ff0000",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd", +slategray:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",violetred:"d02090",wheat:"f5deb3",white:"ffffff",whitesmoke:"f5f5f5",yellow:"ffff00",yellowgreen:"9acd32"},c;for(c in a)m==c&&(m=a[c]);var d=[{re:/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,example:["rgb(123, 234, 45)","rgb(255,234,245)"],process:function(b){return[parseInt(b[1]),parseInt(b[2]),parseInt(b[3])]}},{re:/^(\w{2})(\w{2})(\w{2})$/, +example:["#00ff00","336699"],process:function(b){return[parseInt(b[1],16),parseInt(b[2],16),parseInt(b[3],16)]}},{re:/^(\w{1})(\w{1})(\w{1})$/,example:["#fb0","f0f"],process:function(b){return[parseInt(b[1]+b[1],16),parseInt(b[2]+b[2],16),parseInt(b[3]+b[3],16)]}}];for(c=0;c255?255:this.r;this.g=this.g<0||isNaN(this.g)?0: +this.g>255?255:this.g;this.b=this.b<0||isNaN(this.b)?0:this.b>255?255:this.b;this.toRGB=function(){return"rgb("+this.r+", "+this.g+", "+this.b+")"};this.toHex=function(){var b=this.r.toString(16),a=this.g.toString(16),d=this.b.toString(16);b.length==1&&(b="0"+b);a.length==1&&(a="0"+a);d.length==1&&(d="0"+d);return"#"+b+a+d};this.getHelpXML=function(){for(var b=[],k=0;k "+o.toRGB()+" -> "+o.toHex());l.appendChild(n);l.appendChild(q);c.appendChild(l)}catch(p){}return c}} +if(!window.console)window.console={},window.console.log=function(){},window.console.dir=function(){};if(!Array.prototype.indexOf)Array.prototype.indexOf=function(m){for(var a=0;a]*>/,""),d=new ActiveXObject("Microsoft.XMLDOM");d.async="false";d.loadXML(a);return d}};a.Property=function(c,d){this.name=c;this.value=d;this.hasValue=function(){return this.value!=null&&this.value!==""};this.numValue=function(){if(!this.hasValue())return 0;var b=parseFloat(this.value);(this.value+"").match(/%$/)&& +(b/=100);return b};this.valueOrDefault=function(b){return this.hasValue()?this.value:b};this.numValueOrDefault=function(b){return this.hasValue()?this.numValue():b};var b=this;this.Color={addOpacity:function(d){var c=b.value;if(d!=null&&d!=""){var f=new RGBColor(b.value);f.ok&&(c="rgba("+f.r+", "+f.g+", "+f.b+", "+d+")")}return new a.Property(b.name,c)}};this.Definition={getDefinition:function(){var d=b.value.replace(/^(url\()?#([^\)]+)\)?$/,"$2");return a.Definitions[d]},isUrl:function(){return b.value.indexOf("url(")== +0},getFillStyle:function(b){var d=this.getDefinition();return d!=null&&d.createGradient?d.createGradient(a.ctx,b):d!=null&&d.createPattern?d.createPattern(a.ctx,b):null}};this.Length={DPI:function(){return 96},EM:function(b){var d=12,c=new a.Property("fontSize",a.Font.Parse(a.ctx.font).fontSize);c.hasValue()&&(d=c.Length.toPixels(b));return d},toPixels:function(d){if(!b.hasValue())return 0;var c=b.value+"";return c.match(/em$/)?b.numValue()*this.EM(d):c.match(/ex$/)?b.numValue()*this.EM(d)/2:c.match(/px$/)? +b.numValue():c.match(/pt$/)?b.numValue()*1.25:c.match(/pc$/)?b.numValue()*15:c.match(/cm$/)?b.numValue()*this.DPI(d)/2.54:c.match(/mm$/)?b.numValue()*this.DPI(d)/25.4:c.match(/in$/)?b.numValue()*this.DPI(d):c.match(/%$/)?b.numValue()*a.ViewPort.ComputeSize(d):b.numValue()}};this.Time={toMilliseconds:function(){if(!b.hasValue())return 0;var a=b.value+"";if(a.match(/s$/))return b.numValue()*1E3;a.match(/ms$/);return b.numValue()}};this.Angle={toRadians:function(){if(!b.hasValue())return 0;var a=b.value+ +"";return a.match(/deg$/)?b.numValue()*(Math.PI/180):a.match(/grad$/)?b.numValue()*(Math.PI/200):a.match(/rad$/)?b.numValue():b.numValue()*(Math.PI/180)}}};a.Font=new function(){this.Styles=["normal","italic","oblique","inherit"];this.Variants=["normal","small-caps","inherit"];this.Weights="normal,bold,bolder,lighter,100,200,300,400,500,600,700,800,900,inherit".split(",");this.CreateFont=function(d,b,c,e,f,g){g=g!=null?this.Parse(g):this.CreateFont("","","","","",a.ctx.font);return{fontFamily:f|| +g.fontFamily,fontSize:e||g.fontSize,fontStyle:d||g.fontStyle,fontWeight:c||g.fontWeight,fontVariant:b||g.fontVariant,toString:function(){return[this.fontStyle,this.fontVariant,this.fontWeight,this.fontSize,this.fontFamily].join(" ")}}};var c=this;this.Parse=function(d){for(var b={},d=a.trim(a.compressSpaces(d||"")).split(" "),k=!1,e=!1,f=!1,g=!1,j="",h=0;hthis.x2)this.x2=b}if(a!=null){if(isNaN(this.y1)||isNaN(this.y2))this.y2=this.y1=a;if(athis.y2)this.y2=a}};this.addX=function(b){this.addPoint(b,null)};this.addY=function(b){this.addPoint(null,b)};this.addBoundingBox=function(b){this.addPoint(b.x1,b.y1);this.addPoint(b.x2,b.y2)};this.addQuadraticCurve=function(b,a,d,c,k,l){d=b+2/3*(d-b);c=a+2/3*(c- +a);this.addBezierCurve(b,a,d,d+1/3*(k-b),c,c+1/3*(l-a),k,l)};this.addBezierCurve=function(b,a,d,c,k,l,o,n){var q=[b,a],p=[d,c],t=[k,l],m=[o,n];this.addPoint(q[0],q[1]);this.addPoint(m[0],m[1]);for(i=0;i<=1;i++)b=function(b){return Math.pow(1-b,3)*q[i]+3*Math.pow(1-b,2)*b*p[i]+3*(1-b)*Math.pow(b,2)*t[i]+Math.pow(b,3)*m[i]},a=6*q[i]-12*p[i]+6*t[i],d=-3*q[i]+9*p[i]-9*t[i]+3*m[i],c=3*p[i]-3*q[i],d==0?a!=0&&(a=-c/a,0=this.tokens.length-1};this.isCommandOrEnd=function(){return this.isEnd()? +!0:this.tokens[this.i+1].match(/^[A-Za-z]$/)!=null};this.isRelativeCommand=function(){return this.command==this.command.toLowerCase()};this.getToken=function(){this.i+=1;return this.tokens[this.i]};this.getScalar=function(){return parseFloat(this.getToken())};this.nextCommand=function(){this.previousCommand=this.command;this.command=this.getToken()};this.getPoint=function(){return this.makeAbsolute(new a.Point(this.getScalar(),this.getScalar()))};this.getAsControlPoint=function(){var b=this.getPoint(); +return this.control=b};this.getAsCurrentPoint=function(){var b=this.getPoint();return this.current=b};this.getReflectedControlPoint=function(){return this.previousCommand.toLowerCase()!="c"&&this.previousCommand.toLowerCase()!="s"?this.current:new a.Point(2*this.current.x-this.control.x,2*this.current.y-this.control.y)};this.makeAbsolute=function(b){if(this.isRelativeCommand())b.x=this.current.x+b.x,b.y=this.current.y+b.y;return b};this.addMarker=function(b,a,d){d!=null&&this.angles.length>0&&this.angles[this.angles.length- +1]==null&&(this.angles[this.angles.length-1]=this.points[this.points.length-1].angleTo(d));this.addMarkerAngle(b,a==null?null:a.angleTo(b))};this.addMarkerAngle=function(b,a){this.points.push(b);this.angles.push(a)};this.getMarkerPoints=function(){return this.points};this.getMarkerAngles=function(){for(var b=0;b1&&(h*=Math.sqrt(q),l*=Math.sqrt(q));o=(o==j?-1:1)*Math.sqrt((Math.pow(h,2)*Math.pow(l,2)-Math.pow(h,2)*Math.pow(n.y,2)-Math.pow(l,2)*Math.pow(n.x,2))/(Math.pow(h,2)*Math.pow(n.y,2)+Math.pow(l,2)*Math.pow(n.x,2)));isNaN(o)&&(o=0);var p=new a.Point(o*h*n.y/l,o*-l*n.x/h),g=new a.Point((g.x+e.x)/2+Math.cos(f)* +p.x-Math.sin(f)*p.y,(g.y+e.y)/2+Math.sin(f)*p.x+Math.cos(f)*p.y),m=function(b,a){return(b[0]*a[0]+b[1]*a[1])/(Math.sqrt(Math.pow(b[0],2)+Math.pow(b[1],2))*Math.sqrt(Math.pow(a[0],2)+Math.pow(a[1],2)))},s=function(b,a){return(b[0]*a[1]=1&&(n=0);j==0&&n>0&&(n-=2*Math.PI);j==1&&n<0&&(n+=2*Math.PI);q=new a.Point(g.x-h*Math.cos((o+n)/ +2),g.y-l*Math.sin((o+n)/2));b.addMarkerAngle(q,(o+n)/2+(j==0?1:-1)*Math.PI/2);b.addMarkerAngle(e,n+(j==0?1:-1)*Math.PI/2);c.addPoint(e.x,e.y);d!=null&&(m=h>l?h:l,e=h>l?1:h/l,h=h>l?l/h:1,d.translate(g.x,g.y),d.rotate(f),d.scale(e,h),d.arc(0,0,m,o,o+n,1-j),d.scale(1/e,1/h),d.rotate(-f),d.translate(-g.x,-g.y))}break;case "Z":d!=null&&d.closePath(),b.current=b.start}return c};this.getMarkers=function(){for(var a=this.PathParser.getMarkerPoints(),b=this.PathParser.getMarkerAngles(),c=[],e=0;ethis.maxDuration)if(this.attribute("repeatCount").value=="indefinite")this.duration=0;else return this.attribute("fill").valueOrDefault("remove")=="remove"&&!this.removed?(this.removed=!0,this.getProperty().value=this.initialValue,!0):!1;this.duration+=a;a=!1;if(this.begin0&&b[c-1]!=" "&&c0&&b[c-1]!=" "&&(c==b.length-1||b[c+1]==" "))g="initial";typeof a.glyphs[e]!="undefined"&&(f=a.glyphs[e][g],f==null&&a.glyphs[e].type=="glyph"&&(f=a.glyphs[e]))}else f=a.glyphs[e];if(f==null)f=a.missingGlyph;return f};this.renderChildren=function(c){var b=this.parent.style("font-family").Definition.getDefinition();if(b!=null){var k=this.parent.style("font-size").numValueOrDefault(a.Font.Parse(a.ctx.font).fontSize), +e=this.parent.style("font-style").valueOrDefault(a.Font.Parse(a.ctx.font).fontStyle),f=this.getText();b.isRTL&&(f=f.split("").reverse().join(""));for(var g=a.ToNumberArray(this.parent.attribute("dx").value),j=0;j0?c.childNodes[0].nodeValue:c.text;this.getText=function(){return this.text}};a.Element.tspan.prototype=new a.Element.TextElementBase;a.Element.tref=function(c){this.base=a.Element.TextElementBase;this.base(c);this.getText=function(){var a=this.attribute("xlink:href").Definition.getDefinition();if(a!=null)return a.children[0].getText()}};a.Element.tref.prototype=new a.Element.TextElementBase; +a.Element.a=function(c){this.base=a.Element.TextElementBase;this.base(c);this.hasText=!0;for(var d=0;d1?c.childNodes[1].nodeValue: +""),c=c.replace(/(\/\*([^*]|[\r\n]|(\*+([^*\/]|[\r\n])))*\*+\/)|(^[\s]*\/\/.*)/gm,""),c=a.compressSpaces(c),c=c.split("}"),d=0;d0){l=g[j].indexOf("url");h=g[j].indexOf(")",l);l=g[j].substr(l+5,h-l-6);l=a.parseXml(a.ajax(l)).getElementsByTagName("font");for(h=0;h=e&&c<=h&&!j&&k!==""&&(k=b.split(f),m(k,function(b,a){a>=i&&a<=g&&(d[a-i]||(d[a-i]=[]),d[a-i][o]=b)}),o+=1)}),this.dataFound())},parseTable:function(){var a=this.options,b=a.table,c=this.columns,d=a.startRow||0,e=a.endRow||Number.MAX_VALUE,h=a.startColumn||0,i=a.endColumn||Number.MAX_VALUE;b&&(typeof b==="string"&&(b=document.getElementById(b)),m(b.getElementsByTagName("tr"),function(a, +b){b>=d&&b<=e&&m(a.children,function(a,e){if((a.tagName==="TD"||a.tagName==="TH")&&e>=h&&e<=i)c[e-h]||(c[e-h]=[]),c[e-h][b-d]=a.innerHTML})}),this.dataFound())},parseGoogleSpreadsheet:function(){var a=this,b=this.options,c=b.googleSpreadsheetKey,d=this.columns,e=b.startRow||0,h=b.endRow||Number.MAX_VALUE,i=b.startColumn||0,g=b.endColumn||Number.MAX_VALUE,f,k;c&&jQuery.ajax({dataType:"json",url:"https://spreadsheets.google.com/feeds/cells/"+c+"/"+(b.googleSpreadsheetWorksheet||"od6")+"/public/values?alt=json-in-script&callback=?", +error:b.error,success:function(b){var b=b.feed.entry,c,j=b.length,m=0,n=0,l;for(l=0;l=i&&l<=g)d[l-i]=[],d[l-i].length=Math.min(n,h-e);for(l=0;l=i&&k<=g&&f>=e&&f<=h)d[k-i][f-e]=c.content.$t;a.dataFound()}})},findHeaderRow:function(){m(this.columns,function(){});this.headerRow=0},trim:function(a){return typeof a==="string"?a.replace(/^\s+|\s+$/g,""):a},parseTypes:function(){for(var a= +this.columns,b=a.length,c,d,e,h;b--;)for(c=a[b].length;c--;)d=a[b][c],e=parseFloat(d),h=this.trim(d),h==e?(a[b][c]=e,e>31536E6?a[b].isDatetime=!0:a[b].isNumeric=!0):(d=this.parseDate(d),b===0&&typeof d==="number"&&!isNaN(d)?(a[b][c]=d,a[b].isDatetime=!0):a[b][c]=h===""?null:h)},dateFormats:{"YYYY-mm-dd":{regex:"^([0-9]{4})-([0-9]{2})-([0-9]{2})$",parser:function(a){return Date.UTC(+a[1],a[2]-1,+a[3])}}},parseDate:function(a){var b=this.options.parseDate,c,d,e;b&&(c=b(a));if(typeof a==="string")for(d in this.dateFormats)b= +this.dateFormats[d],(e=a.match(b.regex))&&(c=b.parser(e));return c},rowsToColumns:function(a){var b,c,d,e,h;if(a){h=[];c=a.length;for(b=0;b1&&(b=a.shift(),this.headerRow===0&&b.shift(),b.isDatetime?c="datetime":b.isNumeric|| +(c="category"));for(g=0;g1&&i[f].push(a[g+1][f]!==void 0?a[g+1][f]:null),e>2&&i[f].push(a[g+2][f]!==void 0?a[g+2][f]:null),e>3&&i[f].push(a[g+3][f]!==void 0?a[g+3][f]:null),e>4&&i[f].push(a[g+4][f]!==void 0?a[g+4][f]:null);h[k]={name:a[g].name,data:i};g+= +e}d.complete({xAxis:{type:c},series:h})}}});j.Data=n;j.data=function(a,b){return new n(a,b)};j.wrap(j.Chart.prototype,"init",function(a,b,c){var d=this;b&&b.data?j.data(j.extend(b.data,{complete:function(e){b.hasOwnProperty("series")&&(typeof b.series==="object"?m(b.series,function(a,c){b.series[c]=j.merge(a,e.series[c])}):delete b.series);b=j.merge(e,b);a.call(d,b,c)}}),b):a.call(d,b,c)})})(Highcharts); diff --git a/htdocs/js/lib/highstock/modules/drilldown.js b/htdocs/js/lib/highstock/modules/drilldown.js new file mode 100644 index 00000000..6f147802 --- /dev/null +++ b/htdocs/js/lib/highstock/modules/drilldown.js @@ -0,0 +1,14 @@ +(function(g){function s(a,b,d){return"rgba("+[Math.round(a[0]+(b[0]-a[0])*d),Math.round(a[1]+(b[1]-a[1])*d),Math.round(a[2]+(b[2]-a[2])*d),a[3]+(b[3]-a[3])*d].join(",")+")"}var t=function(){},o=g.getOptions(),i=g.each,p=g.extend,x=g.format,q=g.wrap,l=g.Chart,n=g.seriesTypes,u=n.pie,m=n.column,v=HighchartsAdapter.fireEvent,y=HighchartsAdapter.inArray;p(o.lang,{drillUpText:"◁ Back to {series.name}"});o.drilldown={activeAxisLabelStyle:{cursor:"pointer",color:"#0d233a",fontWeight:"bold",textDecoration:"underline"}, +activeDataLabelStyle:{cursor:"pointer",color:"#0d233a",fontWeight:"bold",textDecoration:"underline"},animation:{duration:500},drillUpButton:{position:{align:"right",x:-10,y:10}}};g.SVGRenderer.prototype.Element.prototype.fadeIn=function(a){this.attr({opacity:0.1,visibility:"inherit"}).animate({opacity:1},a||{duration:250})};l.prototype.addSeriesAsDrilldown=function(a,b){this.addSingleSeriesAsDrilldown(a,b);this.applyDrilldown()};l.prototype.addSingleSeriesAsDrilldown=function(a,b){var d=a.series, +c=d.xAxis,f=d.yAxis,h;h=a.color||d.color;var e,w=[],g=[],k;k=d.levelNumber||0;b=p({color:h},b);e=y(a,d.points);i(d.chart.series,function(a){if(a.xAxis===c)w.push(a),g.push(a.userOptions),a.levelNumber=a.levelNumber||0});h={levelNumber:k,seriesOptions:d.userOptions,levelSeriesOptions:g,levelSeries:w,shapeArgs:a.shapeArgs,bBox:a.graphic.getBBox(),color:h,lowerSeriesOptions:b,pointOptions:d.options.data[e],pointIndex:e,oldExtremes:{xMin:c&&c.userMin,xMax:c&&c.userMax,yMin:f&&f.userMin,yMax:f&&f.userMax}}; +if(!this.drilldownLevels)this.drilldownLevels=[];this.drilldownLevels.push(h);h=h.lowerSeries=this.addSeries(b,!1);h.levelNumber=k+1;if(c)c.oldPos=c.pos,c.userMin=c.userMax=null,f.userMin=f.userMax=null;if(d.type===h.type)h.animate=h.animateDrilldown||t,h.options.animation=!0};l.prototype.applyDrilldown=function(){var a=this.drilldownLevels,b=a[a.length-1].levelNumber;i(this.drilldownLevels,function(a){a.levelNumber===b&&i(a.levelSeries,function(a){a.levelNumber===b&&a.remove(!1)})});this.redraw(); +this.showDrillUpButton()};l.prototype.getDrilldownBackText=function(){var a=this.drilldownLevels[this.drilldownLevels.length-1];a.series=a.seriesOptions;return x(this.options.lang.drillUpText,a)};l.prototype.showDrillUpButton=function(){var a=this,b=this.getDrilldownBackText(),d=a.options.drilldown.drillUpButton,c,f;this.drillUpButton?this.drillUpButton.attr({text:b}).align():(f=(c=d.theme)&&c.states,this.drillUpButton=this.renderer.button(b,null,null,function(){a.drillUp()},c,f&&f.hover,f&&f.select).attr({align:d.position.align, +zIndex:9}).add().align(d.position,!1,d.relativeTo||"plotBox"))};l.prototype.drillUp=function(){for(var a=this,b=a.drilldownLevels,d=b[b.length-1].levelNumber,c=b.length,f=a.series,h=f.length,e,g,j,k,l=function(b){var c;i(f,function(a){a.userOptions===b&&(c=a)});c=c||a.addSeries(b,!1);if(c.type===g.type&&c.animateDrillupTo)c.animate=c.animateDrillupTo;b===e.seriesOptions&&(j=c)};c--;)if(e=b[c],e.levelNumber===d){b.pop();g=e.lowerSeries;if(!g.chart)for(;h--;)if(f[h].options.id===e.lowerSeriesOptions.id){g= +f[h];break}g.xData=[];i(e.levelSeriesOptions,l);v(a,"drillup",{seriesOptions:e.seriesOptions});if(j.type===g.type)j.drilldownLevel=e,j.options.animation=a.options.drilldown.animation,g.animateDrillupFrom&&g.animateDrillupFrom(e);j.levelNumber=d;g.remove(!1);if(j.xAxis)k=e.oldExtremes,j.xAxis.setExtremes(k.xMin,k.xMax,!1),j.yAxis.setExtremes(k.yMin,k.yMax,!1)}this.redraw();this.drilldownLevels.length===0?this.drillUpButton=this.drillUpButton.destroy():this.drillUpButton.attr({text:this.getDrilldownBackText()}).align()}; +m.prototype.supportsDrilldown=!0;m.prototype.animateDrillupTo=function(a){if(!a){var b=this,d=b.drilldownLevel;i(this.points,function(a){a.graphic.hide();a.dataLabel&&a.dataLabel.hide();a.connector&&a.connector.hide()});setTimeout(function(){i(b.points,function(a,b){var h=b===(d&&d.pointIndex)?"show":"fadeIn",e=h==="show"?!0:void 0;a.graphic[h](e);if(a.dataLabel)a.dataLabel[h](e);if(a.connector)a.connector[h](e)})},Math.max(this.chart.options.drilldown.animation.duration-50,0));this.animate=t}};m.prototype.animateDrilldown= +function(a){var b=this,d=this.chart.drilldownLevels,c=this.chart.drilldownLevels[this.chart.drilldownLevels.length-1].shapeArgs,f=this.chart.options.drilldown.animation;if(!a)i(d,function(a){if(b.userOptions===a.lowerSeriesOptions)c=a.shapeArgs}),c.x+=this.xAxis.oldPos-this.xAxis.pos,i(this.points,function(a){a.graphic&&a.graphic.attr(c).animate(a.shapeArgs,f);a.dataLabel&&a.dataLabel.fadeIn(f)}),this.animate=null};m.prototype.animateDrillupFrom=function(a){var b=this.chart.options.drilldown.animation, +d=this.group,c=this;i(c.trackerGroups,function(a){if(c[a])c[a].on("mouseover")});delete this.group;i(this.points,function(c){var h=c.graphic,e=g.Color(c.color).rgba,i=g.Color(a.color).rgba,j=function(){h.destroy();d&&(d=d.destroy())};h&&(delete c.graphic,b?h.animate(a.shapeArgs,g.merge(b,{step:function(a,b){b.prop==="start"&&e.length===4&&i.length===4&&this.attr({fill:s(e,i,b.pos)})},complete:j})):(h.attr(a.shapeArgs),j()))})};u&&p(u.prototype,{supportsDrilldown:!0,animateDrillupTo:m.prototype.animateDrillupTo, +animateDrillupFrom:m.prototype.animateDrillupFrom,animateDrilldown:function(a){var b=this.chart.drilldownLevels[this.chart.drilldownLevels.length-1],d=this.chart.options.drilldown.animation,c=b.shapeArgs,f=c.start,h=(c.end-f)/this.points.length,e=g.Color(b.color).rgba;if(!a)i(this.points,function(a,b){var i=g.Color(a.color).rgba;a.graphic.attr(g.merge(c,{start:f+b*h,end:f+(b+1)*h}))[d?"animate":"attr"](a.shapeArgs,g.merge(d,{step:function(a,b){b.prop==="start"&&e.length===4&&i.length===4&&this.attr({fill:s(e, +i,b.pos)})}}))}),this.animate=null}});g.Point.prototype.doDrilldown=function(a){for(var b=this.series.chart,d=b.options.drilldown,c=(d.series||[]).length,f;c--&&!f;)d.series[c].id===this.drilldown&&(f=d.series[c]);v(b,"drilldown",{point:this,seriesOptions:f});f&&(a?b.addSingleSeriesAsDrilldown(this,f):b.addSeriesAsDrilldown(this,f))};q(g.Point.prototype,"init",function(a,b,d,c){var f=a.call(this,b,d,c),h=b.chart,e=(a=b.xAxis&&b.xAxis.ticks[c])&&a.label;if(f.drilldown){if(g.addEvent(f,"click",function(){f.doDrilldown()}), +e){if(!e._basicStyle)e._basicStyle=e.element.getAttribute("style");e.addClass("highcharts-drilldown-axis-label").css(h.options.drilldown.activeAxisLabelStyle).on("click",function(){i(e.ddPoints,function(a){a.doDrilldown&&a.doDrilldown(!0)});h.applyDrilldown()});if(!e.ddPoints)e.ddPoints=[];e.ddPoints.push(f)}}else e&&e._basicStyle&&e.element.setAttribute("style",e._basicStyle);return f});q(g.Series.prototype,"drawDataLabels",function(a){var b=this.chart.options.drilldown.activeDataLabelStyle;a.call(this); +i(this.points,function(a){if(a.drilldown&&a.dataLabel)a.dataLabel.attr({"class":"highcharts-drilldown-data-label"}).css(b).on("click",function(){a.doDrilldown()})})});var r,o=function(a){a.call(this);i(this.points,function(a){a.drilldown&&a.graphic&&a.graphic.attr({"class":"highcharts-drilldown-point"}).css({cursor:"pointer"})})};for(r in n)n[r].prototype.supportsDrilldown&&q(n[r].prototype,"drawTracker",o)})(Highcharts); diff --git a/htdocs/js/lib/highstock/modules/exporting.js b/htdocs/js/lib/highstock/modules/exporting.js new file mode 100644 index 00000000..b2bcc506 --- /dev/null +++ b/htdocs/js/lib/highstock/modules/exporting.js @@ -0,0 +1,22 @@ +/* + Highstock JS v2.0.1 (2014-04-24) + Exporting module + + (c) 2010-2014 Torstein Honsi + + License: www.highcharts.com/license +*/ +(function(f){var A=f.Chart,t=f.addEvent,B=f.removeEvent,l=f.createElement,o=f.discardElement,v=f.css,k=f.merge,r=f.each,p=f.extend,D=Math.max,j=document,C=window,E=f.isTouchDevice,F=f.Renderer.prototype.symbols,s=f.getOptions(),y;p(s.lang,{printChart:"Print chart",downloadPNG:"Download PNG image",downloadJPEG:"Download JPEG image",downloadPDF:"Download PDF document",downloadSVG:"Download SVG vector image",contextButtonTitle:"Chart context menu"});s.navigation={menuStyle:{border:"1px solid #A0A0A0", +background:"#FFFFFF",padding:"5px 0"},menuItemStyle:{padding:"0 10px",background:"none",color:"#303030",fontSize:E?"14px":"11px"},menuItemHoverStyle:{background:"#4572A5",color:"#FFFFFF"},buttonOptions:{symbolFill:"#E0E0E0",symbolSize:14,symbolStroke:"#666",symbolStrokeWidth:3,symbolX:12.5,symbolY:10.5,align:"right",buttonSpacing:3,height:22,theme:{fill:"white",stroke:"none"},verticalAlign:"top",width:24}};s.exporting={type:"image/png",url:"http://export.highcharts.com/",buttons:{contextButton:{menuClassName:"highcharts-contextmenu", +symbol:"menu",_titleKey:"contextButtonTitle",menuItems:[{textKey:"printChart",onclick:function(){this.print()}},{separator:!0},{textKey:"downloadPNG",onclick:function(){this.exportChart()}},{textKey:"downloadJPEG",onclick:function(){this.exportChart({type:"image/jpeg"})}},{textKey:"downloadPDF",onclick:function(){this.exportChart({type:"application/pdf"})}},{textKey:"downloadSVG",onclick:function(){this.exportChart({type:"image/svg+xml"})}}]}}};f.post=function(b,a,d){var c,b=l("form",k({method:"post", +action:b,enctype:"multipart/form-data"},d),{display:"none"},j.body);for(c in a)l("input",{type:"hidden",name:c,value:a[c]},null,b);b.submit();o(b)};p(A.prototype,{getSVG:function(b){var a=this,d,c,z,h,g=k(a.options,b);if(!j.createElementNS)j.createElementNS=function(a,b){return j.createElement(b)};b=l("div",null,{position:"absolute",top:"-9999em",width:a.chartWidth+"px",height:a.chartHeight+"px"},j.body);c=a.renderTo.style.width;h=a.renderTo.style.height;c=g.exporting.sourceWidth||g.chart.width|| +/px$/.test(c)&&parseInt(c,10)||600;h=g.exporting.sourceHeight||g.chart.height||/px$/.test(h)&&parseInt(h,10)||400;p(g.chart,{animation:!1,renderTo:b,forExport:!0,width:c,height:h});g.exporting.enabled=!1;g.series=[];r(a.series,function(a){z=k(a.options,{animation:!1,showCheckbox:!1,visible:a.visible});z.isInternal||g.series.push(z)});d=new f.Chart(g,a.callback);r(["xAxis","yAxis"],function(b){r(a[b],function(a,c){var g=d[b][c],f=a.getExtremes(),h=f.userMin,f=f.userMax;g&&(h!==void 0||f!==void 0)&& +g.setExtremes(h,f,!0,!1)})});c=d.container.innerHTML;g=null;d.destroy();o(b);c=c.replace(/zIndex="[^"]+"/g,"").replace(/isShadow="[^"]+"/g,"").replace(/symbolName="[^"]+"/g,"").replace(/jQuery[0-9]+="[^"]+"/g,"").replace(/url\([^#]+#/g,"url(#").replace(/.*?$/,"").replace(/ /g," ").replace(/­/g,"­").replace(//g,'xlink:href="$1"/>').replace(/id=([^" >]+)/g,'id="$1"').replace(/class=([^" >]+)/g,'class="$1"').replace(/ transform /g," ").replace(/:(path|rect)/g,"$1").replace(/style="([^"]+)"/g,function(a){return a.toLowerCase()});return c=c.replace(/(url\(#highcharts-[0-9]+)"/g,"$1").replace(/"/g,"'")},exportChart:function(b,a){var b=b||{},d=this.options.exporting,d=this.getSVG(k({chart:{borderRadius:0}},d.chartOptions,a,{exporting:{sourceWidth:b.sourceWidth|| +d.sourceWidth,sourceHeight:b.sourceHeight||d.sourceHeight}})),b=k(this.options.exporting,b);f.post(b.url,{filename:b.filename||"chart",type:b.type,width:b.width||0,scale:b.scale||2,svg:d},b.formAttributes)},print:function(){var b=this,a=b.container,d=[],c=a.parentNode,f=j.body,h=f.childNodes;if(!b.isPrinting)b.isPrinting=!0,r(h,function(a,b){if(a.nodeType===1)d[b]=a.style.display,a.style.display="none"}),f.appendChild(a),C.focus(),C.print(),setTimeout(function(){c.appendChild(a);r(h,function(a,b){if(a.nodeType=== +1)a.style.display=d[b]});b.isPrinting=!1},1E3)},contextMenu:function(b,a,d,c,f,h,g){var e=this,k=e.options.navigation,q=k.menuItemStyle,m=e.chartWidth,n=e.chartHeight,j="cache-"+b,i=e[j],u=D(f,h),w,x,o,s=function(a){e.pointer.inClass(a.target,b)||x()};if(!i)e[j]=i=l("div",{className:b},{position:"absolute",zIndex:1E3,padding:u+"px"},e.container),w=l("div",null,p({MozBoxShadow:"3px 3px 10px #888",WebkitBoxShadow:"3px 3px 10px #888",boxShadow:"3px 3px 10px #888"},k.menuStyle),i),x=function(){v(i,{display:"none"}); +g&&g.setState(0);e.openMenu=!1},t(i,"mouseleave",function(){o=setTimeout(x,500)}),t(i,"mouseenter",function(){clearTimeout(o)}),t(document,"mouseup",s),t(e,"destroy",function(){B(document,"mouseup",s)}),r(a,function(a){if(a){var b=a.separator?l("hr",null,null,w):l("div",{onmouseover:function(){v(this,k.menuItemHoverStyle)},onmouseout:function(){v(this,q)},onclick:function(){x();a.onclick.apply(e,arguments)},innerHTML:a.text||e.options.lang[a.textKey]},p({cursor:"pointer"},q),w);e.exportDivElements.push(b)}}), +e.exportDivElements.push(w,i),e.exportMenuWidth=i.offsetWidth,e.exportMenuHeight=i.offsetHeight;a={display:"block"};d+e.exportMenuWidth>m?a.right=m-d-f-u+"px":a.left=d-u+"px";c+h+e.exportMenuHeight>n&&g.alignOptions.verticalAlign!=="top"?a.bottom=n-c-u+"px":a.top=c+h-u+"px";v(i,a);e.openMenu=!0},addButton:function(b){var a=this,d=a.renderer,c=k(a.options.navigation.buttonOptions,b),j=c.onclick,h=c.menuItems,g,e,l={stroke:c.symbolStroke,fill:c.symbolFill},q=c.symbolSize||12;if(!a.btnCount)a.btnCount= +0;if(!a.exportDivElements)a.exportDivElements=[],a.exportSVGElements=[];if(c.enabled!==!1){var m=c.theme,n=m.states,o=n&&n.hover,n=n&&n.select,i;delete m.states;j?i=function(){j.apply(a,arguments)}:h&&(i=function(){a.contextMenu(e.menuClassName,h,e.translateX,e.translateY,e.width,e.height,e);e.setState(2)});c.text&&c.symbol?m.paddingLeft=f.pick(m.paddingLeft,25):c.text||p(m,{width:c.width,height:c.height,padding:0});e=d.button(c.text,0,0,i,m,o,n).attr({title:a.options.lang[c._titleKey],"stroke-linecap":"round"}); +e.menuClassName=b.menuClassName||"highcharts-menu-"+a.btnCount++;c.symbol&&(g=d.symbol(c.symbol,c.symbolX-q/2,c.symbolY-q/2,q,q).attr(p(l,{"stroke-width":c.symbolStrokeWidth||1,zIndex:1})).add(e));e.add().align(p(c,{width:e.width,x:f.pick(c.x,y)}),!0,"spacingBox");y+=(e.width+c.buttonSpacing)*(c.align==="right"?-1:1);a.exportSVGElements.push(e,g)}},destroyExport:function(b){var b=b.target,a,d;for(a=0;ae-t||e===t?s:s+(q-s)*((e-t-j)/(e-t))};this.getX=function(j,a){return h+(a?-1:1)*(r(g?n-j:j)/2+c.dataLabels.distance)};this.center=[h,d,e];this.centerX=h;A(a,function(a){B+=a.y}); +A(a,function(a){m=null;y=B?a.y/B:0;l=d-e/2+o*e;i=l+y*e;k=r(l);z=h-k/2;C=z+k;k=r(i);p=h-k/2;u=p+k;l>w?(z=p=h-s/2,C=u=h+s/2):i>w&&(m=i,k=r(w),p=h-k/2,u=p+k,i=w);g&&(l=e-l,i=e-i,m=m?e-m:null);x=["M",z,l,"L",C,l,u,i];m&&x.push(u,m,p,m);x.push(p,i,"Z");a.shapeType="path";a.shapeArgs={d:x};a.percentage=y*100;a.plotX=h;a.plotY=(l+(m||i))/2;a.tooltipPos=[h,a.plotY];a.slice=D;a.half=v;o+=y})},drawPoints:function(){var a=this,b=a.options,f=a.chart.renderer;A(a.data,function(c){var g=c.graphic,d=c.shapeArgs; +g?g.animate(d):c.graphic=f.path(d).attr({fill:c.color,stroke:b.borderColor,"stroke-width":b.borderWidth}).add(a.group)})},sortByAngle:function(a){a.sort(function(a,b){return a.plotY-b.plotY})},drawDataLabels:function(){var a=this.data,b=this.options.dataLabels.distance,f,c,g,d=a.length,n,o;for(this.center[2]-=2*b;d--;)g=a[d],c=(f=g.half)?1:-1,o=g.plotY,n=this.getX(o,f),g.labelPos=[0,o,n+(b-5)*c,o,n+b*c,o,f?"right":"left",0];q.pie.prototype.drawDataLabels.call(this)}});d.plotOptions.pyramid=b.merge(d.plotOptions.funnel, +{neckWidth:"0%",neckHeight:"0%",reversed:!0});b.seriesTypes.pyramid=b.extendClass(b.seriesTypes.funnel,{type:"pyramid"})})(Highcharts); diff --git a/htdocs/js/lib/highstock/modules/heatmap.js b/htdocs/js/lib/highstock/modules/heatmap.js new file mode 100644 index 00000000..7eb7f6d9 --- /dev/null +++ b/htdocs/js/lib/highstock/modules/heatmap.js @@ -0,0 +1,21 @@ +/* + Highstock JS v2.0.1 (2014-04-24) + + (c) 2011-2014 Torstein Honsi + + License: www.highcharts.com/license +*/ +(function(g){var j=g.Axis,x=g.Chart,o=g.Color,y=g.Legend,s=g.LegendSymbolMixin,t=g.Series,u=g.getOptions(),k=g.each,p=g.extend,z=g.extendClass,l=g.merge,q=g.pick,v=g.numberFormat,m=g.seriesTypes,w=g.wrap,n=function(){},r=g.ColorAxis=function(){this.isColorAxis=!0;this.init.apply(this,arguments)};p(r.prototype,j.prototype);p(r.prototype,{defaultColorAxisOptions:{lineWidth:0,gridLineWidth:1,tickPixelInterval:72,startOnTick:!0,endOnTick:!0,offset:0,marker:{animation:{duration:50},color:"gray",width:0.01}, +labels:{overflow:"justify"},minColor:"#EFEFFF",maxColor:"#003875",tickLength:5},init:function(b,a){var d=b.options.legend.layout!=="vertical",c;c=l(this.defaultColorAxisOptions,{side:d?2:1,reversed:!d},a,{isX:d,opposite:!d,showEmpty:!1,title:null,isColor:!0});j.prototype.init.call(this,b,c);a.dataClasses&&this.initDataClasses(a);this.initStops(a);this.isXAxis=!0;this.horiz=d;this.zoomEnabled=!1},tweenColors:function(b,a,d){var c=a.rgba[3]!==1||b.rgba[3]!==1;return(c?"rgba(":"rgb(")+Math.round(a.rgba[0]+ +(b.rgba[0]-a.rgba[0])*(1-d))+","+Math.round(a.rgba[1]+(b.rgba[1]-a.rgba[1])*(1-d))+","+Math.round(a.rgba[2]+(b.rgba[2]-a.rgba[2])*(1-d))+(c?","+(a.rgba[3]+(b.rgba[3]-a.rgba[3])*(1-d)):"")+")"},initDataClasses:function(b){var a=this,d=this.chart,c,e=0,h=this.options;this.dataClasses=c=[];k(b.dataClasses,function(f,i){var g,f=l(f);c.push(f);if(!f.color)h.dataClassColor==="category"?(g=d.options.colors,f.color=g[e++],e===g.length&&(e=0)):f.color=a.tweenColors(o(h.minColor),o(h.maxColor),i/(b.dataClasses.length- +1))})},initStops:function(b){this.stops=b.stops||[[0,this.options.minColor],[1,this.options.maxColor]];k(this.stops,function(a){a.color=o(a[1])})},setOptions:function(b){j.prototype.setOptions.call(this,b);this.options.crosshair=this.options.marker;this.coll="colorAxis"},setAxisSize:function(){var b=this.legendSymbol,a=this.chart,d,c,e;if(b)this.left=d=b.attr("x"),this.top=c=b.attr("y"),this.width=e=b.attr("width"),this.height=b=b.attr("height"),this.right=a.chartWidth-d-e,this.bottom=a.chartHeight- +c-b,this.len=this.horiz?e:b,this.pos=this.horiz?d:c},toColor:function(b,a){var d,c=this.stops,e,h=this.dataClasses,f,i;if(h)for(i=h.length;i--;){if(f=h[i],e=f.from,c=f.to,(e===void 0||b>=e)&&(c===void 0||b<=c)){d=f.color;if(a)a.dataClass=i;break}}else{this.isLog&&(b=this.val2lin(b));d=1-(this.max-b)/(this.max-this.min);for(i=c.length;i--;)if(d>c[i][0])break;e=c[i]||c[i+1];c=c[i+1]||e;d=1-(c[0]-d)/(c[0]-e[0]||1);d=this.tweenColors(e.color,c.color,d)}return d},getOffset:function(){var b=this.legendGroup; +if(b&&(j.prototype.getOffset.call(this),!this.axisGroup.parentGroup))this.axisGroup.add(b),this.gridGroup.add(b),this.labelGroup.add(b),this.added=!0},setLegendColor:function(){var b,a=this.options;b=this.horiz?[0,0,1,0]:[0,0,0,1];this.legendColor={linearGradient:{x1:b[0],y1:b[1],x2:b[2],y2:b[3]},stops:a.stops||[[0,a.minColor],[1,a.maxColor]]}},drawLegendSymbol:function(b,a){var d=b.padding,c=b.options,e=this.horiz,h=q(c.symbolWidth,e?200:12),f=q(c.symbolHeight,e?12:200),c=q(c.labelPadding,e?10:30); +this.setLegendColor();a.legendSymbol=this.chart.renderer.rect(0,b.baseline-11,h,f).attr({zIndex:1}).add(a.legendGroup);a.legendSymbol.getBBox();this.legendItemWidth=h+d+(e?0:c);this.legendItemHeight=f+d+(e?c:0)},setState:n,visible:!0,setVisible:n,getSeriesExtremes:function(){var b;if(this.series.length)b=this.series[0],this.dataMin=b.valueMin,this.dataMax=b.valueMax},drawCrosshair:function(b,a){var d=!this.cross,c=a&&a.plotX,e=a&&a.plotY,h,f=this.pos,i=this.len;if(a)h=this.toPixels(a.value),hf+i&&(h=f+i+2),a.plotX=h,a.plotY=this.len-h,j.prototype.drawCrosshair.call(this,b,a),a.plotX=c,a.plotY=e,!d&&this.cross&&this.cross.attr({fill:this.crosshair.color}).add(this.labelGroup)},getPlotLinePath:function(b,a,d,c,e){return e?this.horiz?["M",e-4,this.top-6,"L",e+4,this.top-6,e,this.top,"Z"]:["M",this.left,e,"L",this.left-6,e+6,this.left-6,e-6,"Z"]:j.prototype.getPlotLinePath.call(this,b,a,d,c)},update:function(b,a){k(this.series,function(a){a.isDirtyData=!0});j.prototype.update.call(this, +b,a);this.legendItem&&(this.setLegendColor(),this.chart.legend.colorizeItem(this,!0))},getDataClassLegendSymbols:function(){var b=this,a=this.chart,d=[],c=a.options.legend,e=c.valueDecimals,h=c.valueSuffix||"",f;k(this.dataClasses,function(c,g){var j=!0,l=c.from,m=c.to;f="";l===void 0?f="< ":m===void 0&&(f="> ");l!==void 0&&(f+=v(l,e)+h);l!==void 0&&m!==void 0&&(f+=" - ");m!==void 0&&(f+=v(m,e)+h);d.push(p({chart:a,name:f,options:{},drawLegendSymbol:s.drawRectangle,visible:!0,setState:n,setVisible:function(){j= +this.visible=!j;k(b.series,function(a){k(a.points,function(a){a.dataClass===g&&a.setVisible(j)})});a.legend.colorizeItem(this,j)}},c))});return d},name:""});w(x.prototype,"getAxes",function(b){var a=this.options.colorAxis;b.call(this);this.colorAxis=[];a&&new r(this,a)});w(y.prototype,"getAllItems",function(b){var a=[],d=this.chart.colorAxis[0];d&&(d.options.dataClasses?a=a.concat(d.getDataClassLegendSymbols()):a.push(d),k(d.series,function(a){a.options.showInLegend=!1}));return a.concat(b.call(this))}); +g={pointAttrToOptions:{stroke:"borderColor","stroke-width":"borderWidth",fill:"color",dashstyle:"dashStyle"},pointArrayMap:["value"],axisTypes:["xAxis","yAxis","colorAxis"],optionalAxis:"colorAxis",trackerGroups:["group","markerGroup","dataLabelsGroup"],getSymbol:n,parallelArrays:["x","y","value"],translateColors:function(){var b=this,a=this.options.nullColor,d=this.colorAxis;k(this.data,function(c){var e=c.value;if(e=e===null?a:d?d.toColor(e,c):c.color||b.color)c.color=e})}};u.plotOptions.heatmap= +l(u.plotOptions.scatter,{animation:!1,borderWidth:0,nullColor:"#F8F8F8",dataLabels:{format:"{point.value}",verticalAlign:"middle",crop:!1,overflow:!1,style:{color:"white",fontWeight:"bold",textShadow:"0 0 5px black"}},marker:null,tooltip:{pointFormat:"{point.x}, {point.y}: {point.value}
      "},states:{normal:{animation:!0},hover:{brightness:0.2}}});m.heatmap=z(m.scatter,l(g,{type:"heatmap",pointArrayMap:["y","value"],hasPointSpecificOptions:!0,supportsDrilldown:!0,getExtremesFromAll:!0,init:function(){m.scatter.prototype.init.apply(this, +arguments);this.pointRange=this.options.colsize||1;this.yAxis.axisPointRange=this.options.rowsize||1},translate:function(){var b=this.options,a=this.xAxis,d=this.yAxis;this.generatePoints();k(this.points,function(c){var e=(b.colsize||1)/2,h=(b.rowsize||1)/2,f=Math.round(a.len-a.translate(c.x-e,0,1,0,1)),e=Math.round(a.len-a.translate(c.x+e,0,1,0,1)),g=Math.round(d.translate(c.y-h,0,1,0,1)),h=Math.round(d.translate(c.y+h,0,1,0,1));c.plotX=(f+e)/2;c.plotY=(g+h)/2;c.shapeType="rect";c.shapeArgs={x:Math.min(f, +e),y:Math.min(g,h),width:Math.abs(e-f),height:Math.abs(h-g)}});this.translateColors()},drawPoints:m.column.prototype.drawPoints,animate:n,getBox:n,drawLegendSymbol:s.drawRectangle,getExtremes:function(){t.prototype.getExtremes.call(this,this.valueData);this.valueMin=this.dataMin;this.valueMax=this.dataMax;t.prototype.getExtremes.call(this)}}))})(Highcharts); diff --git a/htdocs/js/lib/highstock/modules/no-data-to-display.js b/htdocs/js/lib/highstock/modules/no-data-to-display.js new file mode 100644 index 00000000..27eb0bde --- /dev/null +++ b/htdocs/js/lib/highstock/modules/no-data-to-display.js @@ -0,0 +1,12 @@ +/* + Highstock JS v2.0.1 (2014-04-24) + Plugin for displaying a message when there is no data visible in chart. + + (c) 2010-2014 Highsoft AS + Author: Oystein Moseng + + License: www.highcharts.com/license +*/ +(function(c){function f(){return!!this.points.length}function g(){this.hasData()?this.hideNoData():this.showNoData()}var d=c.seriesTypes,e=c.Chart.prototype,h=c.getOptions(),i=c.extend;i(h.lang,{noData:"No data to display"});h.noData={position:{x:0,y:0,align:"center",verticalAlign:"middle"},attr:{},style:{fontWeight:"bold",fontSize:"12px",color:"#60606a"}};if(d.pie)d.pie.prototype.hasData=f;if(d.gauge)d.gauge.prototype.hasData=f;if(d.waterfall)d.waterfall.prototype.hasData=f;c.Series.prototype.hasData= +function(){return this.dataMax!==void 0&&this.dataMin!==void 0};e.showNoData=function(a){var b=this.options,a=a||b.lang.noData,b=b.noData;if(!this.noDataLabel)this.noDataLabel=this.renderer.label(a,0,0,null,null,null,null,null,"no-data").attr(b.attr).css(b.style).add(),this.noDataLabel.align(i(this.noDataLabel.getBBox(),b.position),!1,"plotBox")};e.hideNoData=function(){if(this.noDataLabel)this.noDataLabel=this.noDataLabel.destroy()};e.hasData=function(){for(var a=this.series,b=a.length;b--;)if(a[b].hasData()&& +!a[b].options.isInternal)return!0;return!1};e.callbacks.push(function(a){c.addEvent(a,"load",g);c.addEvent(a,"redraw",g)})})(Highcharts); diff --git a/htdocs/js/lib/highstock/modules/solid-gauge.js b/htdocs/js/lib/highstock/modules/solid-gauge.js new file mode 100644 index 00000000..41597e15 --- /dev/null +++ b/htdocs/js/lib/highstock/modules/solid-gauge.js @@ -0,0 +1,13 @@ +/* + Highstock JS v2.0.1 (2014-04-24) + Solid angular gauge module + + (c) 2010-2014 Torstein Honsi + + License: www.highcharts.com/license +*/ +(function(a){var l=a.getOptions().plotOptions,o=a.pInt,p=a.pick,j=a.each,m;l.solidgauge=a.merge(l.gauge,{colorByPoint:!0});m={initDataClasses:function(b){var h=this,e=this.chart,c,k=0,f=this.options;this.dataClasses=c=[];j(b.dataClasses,function(g,d){var i,g=a.merge(g);c.push(g);if(!g.color)f.dataClassColor==="category"?(i=e.options.colors,g.color=i[k++],k===i.length&&(k=0)):g.color=h.tweenColors(a.Color(f.minColor),a.Color(f.maxColor),d/(b.dataClasses.length-1))})},initStops:function(b){this.stops= +b.stops||[[0,this.options.minColor],[1,this.options.maxColor]];j(this.stops,function(b){b.color=a.Color(b[1])})},toColor:function(b,h){var e,c=this.stops,a,f=this.dataClasses,g,d;if(f)for(d=f.length;d--;){if(g=f[d],a=g.from,c=g.to,(a===void 0||b>=a)&&(c===void 0||b<=c)){e=g.color;if(h)h.dataClass=d;break}}else{this.isLog&&(b=this.val2lin(b));e=1-(this.max-b)/(this.max-this.min);for(d=c.length;d--;)if(e>c[d][0])break;a=c[d]||c[d+1];c=c[d+1]||a;e=1-(c[0]-e)/(c[0]-a[0]||1);e=this.tweenColors(a.color, +c.color,e)}return e},tweenColors:function(b,a,e){var c=a.rgba[3]!==1||b.rgba[3]!==1;return b.rgba.length===0||a.rgba.length===0?"none":(c?"rgba(":"rgb(")+Math.round(a.rgba[0]+(b.rgba[0]-a.rgba[0])*(1-e))+","+Math.round(a.rgba[1]+(b.rgba[1]-a.rgba[1])*(1-e))+","+Math.round(a.rgba[2]+(b.rgba[2]-a.rgba[2])*(1-e))+(c?","+(a.rgba[3]+(b.rgba[3]-a.rgba[3])*(1-e)):"")+")"}};a.seriesTypes.solidgauge=a.extendClass(a.seriesTypes.gauge,{type:"solidgauge",bindAxes:function(){var b;a.seriesTypes.gauge.prototype.bindAxes.call(this); +b=this.yAxis;a.extend(b,m);b.options.dataClasses&&b.initDataClasses(b.options);b.initStops(b.options)},drawPoints:function(){var b=this,h=b.yAxis,e=h.center,c=b.options,k=b.chart.renderer;a.each(b.points,function(f){var g=f.graphic,d=h.startAngleRad+h.translate(f.y,null,null,null,!0),i=o(p(c.radius,100))*e[2]/200,l=o(p(c.innerRadius,60))*e[2]/200,n=h.toColor(f.y,f),j;if(n!=="none")j=f.color,f.color=n;c.wrap===!1&&(d=Math.max(h.startAngleRad,Math.min(h.endAngleRad,d)));d=d*180/Math.PI;d={x:e[0],y:e[1], +r:i,innerR:l,start:h.startAngleRad,end:d/(180/Math.PI)};g?(i=d.d,g.attr({fill:f.color}).animate(d,{step:function(b,c){g.attr("fill",m.tweenColors(a.Color(j),a.Color(n),c.pos))}}),d.d=i):f.graphic=k.arc(d).attr({stroke:c.borderColor||"none","stroke-width":c.borderWidth||0,fill:f.color}).add(b.group)})},animate:null})})(Highcharts); diff --git a/htdocs/js/lib/highstock/themes/dark-blue.js b/htdocs/js/lib/highstock/themes/dark-blue.js new file mode 100644 index 00000000..7cf7138a --- /dev/null +++ b/htdocs/js/lib/highstock/themes/dark-blue.js @@ -0,0 +1,254 @@ +/** + * Dark blue theme for Highcharts JS + * @author Torstein Honsi + */ + +Highcharts.theme = { + colors: ["#DDDF0D", "#55BF3B", "#DF5353", "#7798BF", "#aaeeee", "#ff0066", "#eeaaee", + "#55BF3B", "#DF5353", "#7798BF", "#aaeeee"], + chart: { + backgroundColor: { + linearGradient: { x1: 0, y1: 0, x2: 1, y2: 1 }, + stops: [ + [0, 'rgb(48, 48, 96)'], + [1, 'rgb(0, 0, 0)'] + ] + }, + borderColor: '#000000', + borderWidth: 2, + className: 'dark-container', + plotBackgroundColor: 'rgba(255, 255, 255, .1)', + plotBorderColor: '#CCCCCC', + plotBorderWidth: 1 + }, + title: { + style: { + color: '#C0C0C0', + font: 'bold 16px "Trebuchet MS", Verdana, sans-serif' + } + }, + subtitle: { + style: { + color: '#666666', + font: 'bold 12px "Trebuchet MS", Verdana, sans-serif' + } + }, + xAxis: { + gridLineColor: '#333333', + gridLineWidth: 1, + labels: { + style: { + color: '#A0A0A0' + } + }, + lineColor: '#A0A0A0', + tickColor: '#A0A0A0', + title: { + style: { + color: '#CCC', + fontWeight: 'bold', + fontSize: '12px', + fontFamily: 'Trebuchet MS, Verdana, sans-serif' + + } + } + }, + yAxis: { + gridLineColor: '#333333', + labels: { + style: { + color: '#A0A0A0' + } + }, + lineColor: '#A0A0A0', + minorTickInterval: null, + tickColor: '#A0A0A0', + tickWidth: 1, + title: { + style: { + color: '#CCC', + fontWeight: 'bold', + fontSize: '12px', + fontFamily: 'Trebuchet MS, Verdana, sans-serif' + } + } + }, + tooltip: { + backgroundColor: 'rgba(0, 0, 0, 0.75)', + style: { + color: '#F0F0F0' + } + }, + toolbar: { + itemStyle: { + color: 'silver' + } + }, + plotOptions: { + line: { + dataLabels: { + color: '#CCC' + }, + marker: { + lineColor: '#333' + } + }, + spline: { + marker: { + lineColor: '#333' + } + }, + scatter: { + marker: { + lineColor: '#333' + } + }, + candlestick: { + lineColor: 'white' + } + }, + legend: { + itemStyle: { + font: '9pt Trebuchet MS, Verdana, sans-serif', + color: '#A0A0A0' + }, + itemHoverStyle: { + color: '#FFF' + }, + itemHiddenStyle: { + color: '#444' + } + }, + credits: { + style: { + color: '#666' + } + }, + labels: { + style: { + color: '#CCC' + } + }, + + navigation: { + buttonOptions: { + symbolStroke: '#DDDDDD', + hoverSymbolStroke: '#FFFFFF', + theme: { + fill: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0.4, '#606060'], + [0.6, '#333333'] + ] + }, + stroke: '#000000' + } + } + }, + + // scroll charts + rangeSelector: { + buttonTheme: { + fill: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0.4, '#888'], + [0.6, '#555'] + ] + }, + stroke: '#000000', + style: { + color: '#CCC', + fontWeight: 'bold' + }, + states: { + hover: { + fill: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0.4, '#BBB'], + [0.6, '#888'] + ] + }, + stroke: '#000000', + style: { + color: 'white' + } + }, + select: { + fill: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0.1, '#000'], + [0.3, '#333'] + ] + }, + stroke: '#000000', + style: { + color: 'yellow' + } + } + } + }, + inputStyle: { + backgroundColor: '#333', + color: 'silver' + }, + labelStyle: { + color: 'silver' + } + }, + + navigator: { + handles: { + backgroundColor: '#666', + borderColor: '#AAA' + }, + outlineColor: '#CCC', + maskFill: 'rgba(16, 16, 16, 0.5)', + series: { + color: '#7798BF', + lineColor: '#A6C7ED' + } + }, + + scrollbar: { + barBackgroundColor: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0.4, '#888'], + [0.6, '#555'] + ] + }, + barBorderColor: '#CCC', + buttonArrowColor: '#CCC', + buttonBackgroundColor: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0.4, '#888'], + [0.6, '#555'] + ] + }, + buttonBorderColor: '#CCC', + rifleColor: '#FFF', + trackBackgroundColor: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0, '#000'], + [1, '#333'] + ] + }, + trackBorderColor: '#666' + }, + + // special colors for some of the + legendBackgroundColor: 'rgba(0, 0, 0, 0.5)', + background2: 'rgb(35, 35, 70)', + dataLabelsColor: '#444', + textColor: '#C0C0C0', + maskColor: 'rgba(255,255,255,0.3)' +}; + +// Apply the theme +var highchartsOptions = Highcharts.setOptions(Highcharts.theme); diff --git a/htdocs/js/lib/highstock/themes/dark-green.js b/htdocs/js/lib/highstock/themes/dark-green.js new file mode 100644 index 00000000..4a7ad586 --- /dev/null +++ b/htdocs/js/lib/highstock/themes/dark-green.js @@ -0,0 +1,255 @@ +/** + * Dark blue theme for Highcharts JS + * @author Torstein Honsi + */ + +Highcharts.theme = { + colors: ["#DDDF0D", "#55BF3B", "#DF5353", "#7798BF", "#aaeeee", "#ff0066", "#eeaaee", + "#55BF3B", "#DF5353", "#7798BF", "#aaeeee"], + chart: { + backgroundColor: { + linearGradient: [0, 0, 250, 500], + stops: [ + [0, 'rgb(48, 96, 48)'], + [1, 'rgb(0, 0, 0)'] + ] + }, + borderColor: '#000000', + borderWidth: 2, + className: 'dark-container', + plotBackgroundColor: 'rgba(255, 255, 255, .1)', + plotBorderColor: '#CCCCCC', + plotBorderWidth: 1 + }, + title: { + style: { + color: '#C0C0C0', + font: 'bold 16px "Trebuchet MS", Verdana, sans-serif' + } + }, + subtitle: { + style: { + color: '#666666', + font: 'bold 12px "Trebuchet MS", Verdana, sans-serif' + } + }, + xAxis: { + gridLineColor: '#333333', + gridLineWidth: 1, + labels: { + style: { + color: '#A0A0A0' + } + }, + lineColor: '#A0A0A0', + tickColor: '#A0A0A0', + title: { + style: { + color: '#CCC', + fontWeight: 'bold', + fontSize: '12px', + fontFamily: 'Trebuchet MS, Verdana, sans-serif' + + } + } + }, + yAxis: { + gridLineColor: '#333333', + labels: { + style: { + color: '#A0A0A0' + } + }, + lineColor: '#A0A0A0', + minorTickInterval: null, + tickColor: '#A0A0A0', + tickWidth: 1, + title: { + style: { + color: '#CCC', + fontWeight: 'bold', + fontSize: '12px', + fontFamily: 'Trebuchet MS, Verdana, sans-serif' + } + } + }, + tooltip: { + backgroundColor: 'rgba(0, 0, 0, 0.75)', + style: { + color: '#F0F0F0' + } + }, + toolbar: { + itemStyle: { + color: 'silver' + } + }, + plotOptions: { + line: { + dataLabels: { + color: '#CCC' + }, + marker: { + lineColor: '#333' + } + }, + spline: { + marker: { + lineColor: '#333' + } + }, + scatter: { + marker: { + lineColor: '#333' + } + }, + candlestick: { + lineColor: 'white' + } + }, + legend: { + itemStyle: { + font: '9pt Trebuchet MS, Verdana, sans-serif', + color: '#A0A0A0' + }, + itemHoverStyle: { + color: '#FFF' + }, + itemHiddenStyle: { + color: '#444' + } + }, + credits: { + style: { + color: '#666' + } + }, + labels: { + style: { + color: '#CCC' + } + }, + + + navigation: { + buttonOptions: { + symbolStroke: '#DDDDDD', + hoverSymbolStroke: '#FFFFFF', + theme: { + fill: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0.4, '#606060'], + [0.6, '#333333'] + ] + }, + stroke: '#000000' + } + } + }, + + // scroll charts + rangeSelector: { + buttonTheme: { + fill: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0.4, '#888'], + [0.6, '#555'] + ] + }, + stroke: '#000000', + style: { + color: '#CCC', + fontWeight: 'bold' + }, + states: { + hover: { + fill: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0.4, '#BBB'], + [0.6, '#888'] + ] + }, + stroke: '#000000', + style: { + color: 'white' + } + }, + select: { + fill: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0.1, '#000'], + [0.3, '#333'] + ] + }, + stroke: '#000000', + style: { + color: 'yellow' + } + } + } + }, + inputStyle: { + backgroundColor: '#333', + color: 'silver' + }, + labelStyle: { + color: 'silver' + } + }, + + navigator: { + handles: { + backgroundColor: '#666', + borderColor: '#AAA' + }, + outlineColor: '#CCC', + maskFill: 'rgba(16, 16, 16, 0.5)', + series: { + color: '#7798BF', + lineColor: '#A6C7ED' + } + }, + + scrollbar: { + barBackgroundColor: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0.4, '#888'], + [0.6, '#555'] + ] + }, + barBorderColor: '#CCC', + buttonArrowColor: '#CCC', + buttonBackgroundColor: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0.4, '#888'], + [0.6, '#555'] + ] + }, + buttonBorderColor: '#CCC', + rifleColor: '#FFF', + trackBackgroundColor: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0, '#000'], + [1, '#333'] + ] + }, + trackBorderColor: '#666' + }, + + // special colors for some of the + legendBackgroundColor: 'rgba(0, 0, 0, 0.5)', + background2: 'rgb(35, 35, 70)', + dataLabelsColor: '#444', + textColor: '#C0C0C0', + maskColor: 'rgba(255,255,255,0.3)' +}; + +// Apply the theme +var highchartsOptions = Highcharts.setOptions(Highcharts.theme); diff --git a/htdocs/js/lib/highstock/themes/dark-unica.js b/htdocs/js/lib/highstock/themes/dark-unica.js new file mode 100644 index 00000000..4f1f8df5 --- /dev/null +++ b/htdocs/js/lib/highstock/themes/dark-unica.js @@ -0,0 +1,213 @@ +/** + * Dark theme for Highcharts JS + * @author Torstein Honsi + */ + +// Load the fonts +Highcharts.createElement('link', { + href: 'http://fonts.googleapis.com/css?family=Unica+One', + rel: 'stylesheet', + type: 'text/css' +}, null, document.getElementsByTagName('head')[0]); + +Highcharts.theme = { + colors: ["#2b908f", "#90ee7e", "#f45b5b", "#7798BF", "#aaeeee", "#ff0066", "#eeaaee", + "#55BF3B", "#DF5353", "#7798BF", "#aaeeee"], + chart: { + backgroundColor: { + linearGradient: { x1: 0, y1: 0, x2: 1, y2: 1 }, + stops: [ + [0, '#2a2a2b'], + [1, '#3e3e40'] + ] + }, + style: { + fontFamily: "'Unica One', sans-serif" + }, + plotBorderColor: '#606063' + }, + title: { + style: { + color: '#E0E0E3', + textTransform: 'uppercase', + fontSize: '20px' + } + }, + subtitle: { + style: { + color: '#E0E0E3', + textTransform: 'uppercase' + } + }, + xAxis: { + gridLineColor: '#707073', + labels: { + style: { + color: '#E0E0E3' + } + }, + lineColor: '#707073', + minorGridLineColor: '#505053', + tickColor: '#707073', + title: { + style: { + color: '#A0A0A3' + + } + } + }, + yAxis: { + gridLineColor: '#707073', + labels: { + style: { + color: '#E0E0E3' + } + }, + lineColor: '#707073', + minorGridLineColor: '#505053', + tickColor: '#707073', + tickWidth: 1, + title: { + style: { + color: '#A0A0A3' + } + } + }, + tooltip: { + backgroundColor: 'rgba(0, 0, 0, 0.85)', + style: { + color: '#F0F0F0' + } + }, + plotOptions: { + series: { + dataLabels: { + color: '#B0B0B3' + }, + marker: { + lineColor: '#333' + } + }, + boxplot: { + fillColor: '#505053' + }, + candlestick: { + lineColor: 'white' + }, + errorbar: { + color: 'white' + } + }, + legend: { + itemStyle: { + color: '#E0E0E3' + }, + itemHoverStyle: { + color: '#FFF' + }, + itemHiddenStyle: { + color: '#606063' + } + }, + credits: { + style: { + color: '#666' + } + }, + labels: { + style: { + color: '#707073' + } + }, + + drilldown: { + activeAxisLabelStyle: { + color: '#F0F0F3' + }, + activeDataLabelStyle: { + color: '#F0F0F3' + } + }, + + navigation: { + buttonOptions: { + symbolStroke: '#DDDDDD', + theme: { + fill: '#505053' + } + } + }, + + // scroll charts + rangeSelector: { + buttonTheme: { + fill: '#505053', + stroke: '#000000', + style: { + color: '#CCC' + }, + states: { + hover: { + fill: '#707073', + stroke: '#000000', + style: { + color: 'white' + } + }, + select: { + fill: '#000003', + stroke: '#000000', + style: { + color: 'white' + } + } + } + }, + inputBoxBorderColor: '#505053', + inputStyle: { + backgroundColor: '#333', + color: 'silver' + }, + labelStyle: { + color: 'silver' + } + }, + + navigator: { + handles: { + backgroundColor: '#666', + borderColor: '#AAA' + }, + outlineColor: '#CCC', + maskFill: 'rgba(255,255,255,0.1)', + series: { + color: '#7798BF', + lineColor: '#A6C7ED' + }, + xAxis: { + gridLineColor: '#505053' + } + }, + + scrollbar: { + barBackgroundColor: '#808083', + barBorderColor: '#808083', + buttonArrowColor: '#CCC', + buttonBackgroundColor: '#606063', + buttonBorderColor: '#606063', + rifleColor: '#FFF', + trackBackgroundColor: '#404043', + trackBorderColor: '#404043' + }, + + // special colors for some of the + legendBackgroundColor: 'rgba(0, 0, 0, 0.5)', + background2: '#505053', + dataLabelsColor: '#B0B0B3', + textColor: '#C0C0C0', + contrastTextColor: '#F0F0F3', + maskColor: 'rgba(255,255,255,0.3)' +}; + +// Apply the theme +Highcharts.setOptions(Highcharts.theme); diff --git a/htdocs/js/lib/highstock/themes/gray.js b/htdocs/js/lib/highstock/themes/gray.js new file mode 100644 index 00000000..d9a40169 --- /dev/null +++ b/htdocs/js/lib/highstock/themes/gray.js @@ -0,0 +1,257 @@ +/** + * Gray theme for Highcharts JS + * @author Torstein Honsi + */ + +Highcharts.theme = { + colors: ["#DDDF0D", "#7798BF", "#55BF3B", "#DF5353", "#aaeeee", "#ff0066", "#eeaaee", + "#55BF3B", "#DF5353", "#7798BF", "#aaeeee"], + chart: { + backgroundColor: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0, 'rgb(96, 96, 96)'], + [1, 'rgb(16, 16, 16)'] + ] + }, + borderWidth: 0, + borderRadius: 0, + plotBackgroundColor: null, + plotShadow: false, + plotBorderWidth: 0 + }, + title: { + style: { + color: '#FFF', + font: '16px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif' + } + }, + subtitle: { + style: { + color: '#DDD', + font: '12px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif' + } + }, + xAxis: { + gridLineWidth: 0, + lineColor: '#999', + tickColor: '#999', + labels: { + style: { + color: '#999', + fontWeight: 'bold' + } + }, + title: { + style: { + color: '#AAA', + font: 'bold 12px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif' + } + } + }, + yAxis: { + alternateGridColor: null, + minorTickInterval: null, + gridLineColor: 'rgba(255, 255, 255, .1)', + minorGridLineColor: 'rgba(255,255,255,0.07)', + lineWidth: 0, + tickWidth: 0, + labels: { + style: { + color: '#999', + fontWeight: 'bold' + } + }, + title: { + style: { + color: '#AAA', + font: 'bold 12px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif' + } + } + }, + legend: { + itemStyle: { + color: '#CCC' + }, + itemHoverStyle: { + color: '#FFF' + }, + itemHiddenStyle: { + color: '#333' + } + }, + labels: { + style: { + color: '#CCC' + } + }, + tooltip: { + backgroundColor: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0, 'rgba(96, 96, 96, .8)'], + [1, 'rgba(16, 16, 16, .8)'] + ] + }, + borderWidth: 0, + style: { + color: '#FFF' + } + }, + + + plotOptions: { + series: { + nullColor: '#444444' + }, + line: { + dataLabels: { + color: '#CCC' + }, + marker: { + lineColor: '#333' + } + }, + spline: { + marker: { + lineColor: '#333' + } + }, + scatter: { + marker: { + lineColor: '#333' + } + }, + candlestick: { + lineColor: 'white' + } + }, + + toolbar: { + itemStyle: { + color: '#CCC' + } + }, + + navigation: { + buttonOptions: { + symbolStroke: '#DDDDDD', + hoverSymbolStroke: '#FFFFFF', + theme: { + fill: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0.4, '#606060'], + [0.6, '#333333'] + ] + }, + stroke: '#000000' + } + } + }, + + // scroll charts + rangeSelector: { + buttonTheme: { + fill: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0.4, '#888'], + [0.6, '#555'] + ] + }, + stroke: '#000000', + style: { + color: '#CCC', + fontWeight: 'bold' + }, + states: { + hover: { + fill: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0.4, '#BBB'], + [0.6, '#888'] + ] + }, + stroke: '#000000', + style: { + color: 'white' + } + }, + select: { + fill: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0.1, '#000'], + [0.3, '#333'] + ] + }, + stroke: '#000000', + style: { + color: 'yellow' + } + } + } + }, + inputStyle: { + backgroundColor: '#333', + color: 'silver' + }, + labelStyle: { + color: 'silver' + } + }, + + navigator: { + handles: { + backgroundColor: '#666', + borderColor: '#AAA' + }, + outlineColor: '#CCC', + maskFill: 'rgba(16, 16, 16, 0.5)', + series: { + color: '#7798BF', + lineColor: '#A6C7ED' + } + }, + + scrollbar: { + barBackgroundColor: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0.4, '#888'], + [0.6, '#555'] + ] + }, + barBorderColor: '#CCC', + buttonArrowColor: '#CCC', + buttonBackgroundColor: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0.4, '#888'], + [0.6, '#555'] + ] + }, + buttonBorderColor: '#CCC', + rifleColor: '#FFF', + trackBackgroundColor: { + linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, + stops: [ + [0, '#000'], + [1, '#333'] + ] + }, + trackBorderColor: '#666' + }, + + // special colors for some of the demo examples + legendBackgroundColor: 'rgba(48, 48, 48, 0.8)', + background2: 'rgb(70, 70, 70)', + dataLabelsColor: '#444', + textColor: '#E0E0E0', + maskColor: 'rgba(255,255,255,0.3)' +}; + +// Apply the theme +var highchartsOptions = Highcharts.setOptions(Highcharts.theme); diff --git a/htdocs/js/lib/highstock/themes/grid-light.js b/htdocs/js/lib/highstock/themes/grid-light.js new file mode 100644 index 00000000..acf53aec --- /dev/null +++ b/htdocs/js/lib/highstock/themes/grid-light.js @@ -0,0 +1,74 @@ +/** + * Grid-light theme for Highcharts JS + * @author Torstein Honsi + */ + +// Load the fonts +Highcharts.createElement('link', { + href: 'http://fonts.googleapis.com/css?family=Dosis:400,600', + rel: 'stylesheet', + type: 'text/css' +}, null, document.getElementsByTagName('head')[0]); + +Highcharts.theme = { + colors: ["#7cb5ec", "#f7a35c", "#90ee7e", "#7798BF", "#aaeeee", "#ff0066", "#eeaaee", + "#55BF3B", "#DF5353", "#7798BF", "#aaeeee"], + chart: { + backgroundColor: null, + style: { + fontFamily: "Dosis, sans-serif" + } + }, + title: { + style: { + fontSize: '16px', + fontWeight: 'bold', + textTransform: 'uppercase' + } + }, + tooltip: { + borderWidth: 0, + backgroundColor: 'rgba(219,219,216,0.8)', + shadow: false + }, + legend: { + itemStyle: { + fontWeight: 'bold', + fontSize: '13px' + } + }, + xAxis: { + gridLineWidth: 1, + labels: { + style: { + fontSize: '12px' + } + } + }, + yAxis: { + minorTickInterval: 'auto', + title: { + style: { + textTransform: 'uppercase' + } + }, + labels: { + style: { + fontSize: '12px' + } + } + }, + plotOptions: { + candlestick: { + lineColor: '#404048' + } + }, + + + // General + background2: '#F0F0EA' + +}; + +// Apply the theme +Highcharts.setOptions(Highcharts.theme); diff --git a/htdocs/js/lib/highstock/themes/grid.js b/htdocs/js/lib/highstock/themes/grid.js new file mode 100644 index 00000000..70342f5e --- /dev/null +++ b/htdocs/js/lib/highstock/themes/grid.js @@ -0,0 +1,103 @@ +/** + * Grid theme for Highcharts JS + * @author Torstein Honsi + */ + +Highcharts.theme = { + colors: ['#058DC7', '#50B432', '#ED561B', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263', '#6AF9C4'], + chart: { + backgroundColor: { + linearGradient: { x1: 0, y1: 0, x2: 1, y2: 1 }, + stops: [ + [0, 'rgb(255, 255, 255)'], + [1, 'rgb(240, 240, 255)'] + ] + }, + borderWidth: 2, + plotBackgroundColor: 'rgba(255, 255, 255, .9)', + plotShadow: true, + plotBorderWidth: 1 + }, + title: { + style: { + color: '#000', + font: 'bold 16px "Trebuchet MS", Verdana, sans-serif' + } + }, + subtitle: { + style: { + color: '#666666', + font: 'bold 12px "Trebuchet MS", Verdana, sans-serif' + } + }, + xAxis: { + gridLineWidth: 1, + lineColor: '#000', + tickColor: '#000', + labels: { + style: { + color: '#000', + font: '11px Trebuchet MS, Verdana, sans-serif' + } + }, + title: { + style: { + color: '#333', + fontWeight: 'bold', + fontSize: '12px', + fontFamily: 'Trebuchet MS, Verdana, sans-serif' + + } + } + }, + yAxis: { + minorTickInterval: 'auto', + lineColor: '#000', + lineWidth: 1, + tickWidth: 1, + tickColor: '#000', + labels: { + style: { + color: '#000', + font: '11px Trebuchet MS, Verdana, sans-serif' + } + }, + title: { + style: { + color: '#333', + fontWeight: 'bold', + fontSize: '12px', + fontFamily: 'Trebuchet MS, Verdana, sans-serif' + } + } + }, + legend: { + itemStyle: { + font: '9pt Trebuchet MS, Verdana, sans-serif', + color: 'black' + + }, + itemHoverStyle: { + color: '#039' + }, + itemHiddenStyle: { + color: 'gray' + } + }, + labels: { + style: { + color: '#99b' + } + }, + + navigation: { + buttonOptions: { + theme: { + stroke: '#CCCCCC' + } + } + } +}; + +// Apply the theme +var highchartsOptions = Highcharts.setOptions(Highcharts.theme); diff --git a/htdocs/js/lib/highstock/themes/sand-signika.js b/htdocs/js/lib/highstock/themes/sand-signika.js new file mode 100644 index 00000000..27198331 --- /dev/null +++ b/htdocs/js/lib/highstock/themes/sand-signika.js @@ -0,0 +1,101 @@ +/** + * Sand-Signika theme for Highcharts JS + * @author Torstein Honsi + */ + +// Load the fonts +Highcharts.createElement('link', { + href: 'http://fonts.googleapis.com/css?family=Signika:400,700', + rel: 'stylesheet', + type: 'text/css' +}, null, document.getElementsByTagName('head')[0]); + +// Add the background image to the container +Highcharts.wrap(Highcharts.Chart.prototype, 'getContainer', function (proceed) { + proceed.call(this); + this.container.style.background = 'url(http://www.highcharts.com/samples/graphics/sand.png)'; +}); + + +Highcharts.theme = { + colors: ["#f45b5b", "#8085e9", "#8d4654", "#7798BF", "#aaeeee", "#ff0066", "#eeaaee", + "#55BF3B", "#DF5353", "#7798BF", "#aaeeee"], + chart: { + backgroundColor: null, + style: { + fontFamily: "Signika, serif" + } + }, + title: { + style: { + color: 'black', + fontSize: '16px', + fontWeight: 'bold' + } + }, + subtitle: { + style: { + color: 'black' + } + }, + tooltip: { + borderWidth: 0 + }, + legend: { + itemStyle: { + fontWeight: 'bold', + fontSize: '13px' + } + }, + xAxis: { + labels: { + style: { + color: '#6e6e70' + } + } + }, + yAxis: { + labels: { + style: { + color: '#6e6e70' + } + } + }, + plotOptions: { + series: { + shadow: true + }, + candlestick: { + lineColor: '#404048' + } + }, + + // Highstock specific + navigator: { + xAxis: { + gridLineColor: '#D0D0D8' + } + }, + rangeSelector: { + buttonTheme: { + fill: 'white', + stroke: '#C0C0C8', + 'stroke-width': 1, + states: { + select: { + fill: '#D0D0D8' + } + } + } + }, + scrollbar: { + trackBorderColor: '#C0C0C8' + }, + + // General + background2: '#E0E0E8' + +}; + +// Apply the theme +Highcharts.setOptions(Highcharts.theme); diff --git a/htdocs/js/lib/highstock/themes/skies.js b/htdocs/js/lib/highstock/themes/skies.js new file mode 100644 index 00000000..d58b1f24 --- /dev/null +++ b/htdocs/js/lib/highstock/themes/skies.js @@ -0,0 +1,89 @@ +/** + * Skies theme for Highcharts JS + * @author Torstein Honsi + */ + +Highcharts.theme = { + colors: ["#514F78", "#42A07B", "#9B5E4A", "#72727F", "#1F949A", "#82914E", "#86777F", "#42A07B"], + chart: { + className: 'skies', + borderWidth: 0, + plotShadow: true, + plotBackgroundImage: 'http://www.highcharts.com/demo/gfx/skies.jpg', + plotBackgroundColor: { + linearGradient: [0, 0, 250, 500], + stops: [ + [0, 'rgba(255, 255, 255, 1)'], + [1, 'rgba(255, 255, 255, 0)'] + ] + }, + plotBorderWidth: 1 + }, + title: { + style: { + color: '#3E576F', + font: '16px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif' + } + }, + subtitle: { + style: { + color: '#6D869F', + font: '12px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif' + } + }, + xAxis: { + gridLineWidth: 0, + lineColor: '#C0D0E0', + tickColor: '#C0D0E0', + labels: { + style: { + color: '#666', + fontWeight: 'bold' + } + }, + title: { + style: { + color: '#666', + font: '12px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif' + } + } + }, + yAxis: { + alternateGridColor: 'rgba(255, 255, 255, .5)', + lineColor: '#C0D0E0', + tickColor: '#C0D0E0', + tickWidth: 1, + labels: { + style: { + color: '#666', + fontWeight: 'bold' + } + }, + title: { + style: { + color: '#666', + font: '12px Lucida Grande, Lucida Sans Unicode, Verdana, Arial, Helvetica, sans-serif' + } + } + }, + legend: { + itemStyle: { + font: '9pt Trebuchet MS, Verdana, sans-serif', + color: '#3E576F' + }, + itemHoverStyle: { + color: 'black' + }, + itemHiddenStyle: { + color: 'silver' + } + }, + labels: { + style: { + color: '#3E576F' + } + } +}; + +// Apply the theme +var highchartsOptions = Highcharts.setOptions(Highcharts.theme); From ae7ef85ae710137c287ac00c8de8a851b3e704f1 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Mon, 12 May 2014 06:53:21 +0000 Subject: [PATCH 165/173] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=8F=AF=E8=A7=86=E5=8C=96=E6=A1=86=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/VisualController.php | 470 +----------------- .../default/views/scripts/visual/index.phtml | 328 ++++++------ .../Westdc/Visual/Event/RecordEvent.php | 13 + application/module/Westdc/Visual/Factory.php | 35 ++ .../Westdc/Visual/Listener/RecordListener.php | 35 ++ .../module/Westdc/Visual/Reader/Sc.php | 33 ++ application/module/Westdc/Visual/Record.php | 16 + .../module/Westdc/Visual/RecordInterface.php | 7 + 8 files changed, 308 insertions(+), 629 deletions(-) create mode 100644 application/module/Westdc/Visual/Event/RecordEvent.php create mode 100644 application/module/Westdc/Visual/Factory.php create mode 100644 application/module/Westdc/Visual/Listener/RecordListener.php create mode 100644 application/module/Westdc/Visual/Reader/Sc.php create mode 100644 application/module/Westdc/Visual/Record.php create mode 100644 application/module/Westdc/Visual/RecordInterface.php diff --git a/application/default/controllers/VisualController.php b/application/default/controllers/VisualController.php index b1653095..c733af74 100644 --- a/application/default/controllers/VisualController.php +++ b/application/default/controllers/VisualController.php @@ -7,487 +7,21 @@ class VisualController extends Zend_Controller_Action { $this->view->config = Zend_Registry::get('config'); $this->db=Zend_Registry::get('db'); - $this->dbh = new PDO("pgsql:dbname=qinghaihu;host=localhost", "gis", "gispassword" ); + $auth = Zend_Auth::getInstance(); if($auth->hasIdentity()) { $user = $auth->getIdentity(); $this->uid = $user->id; }else{ - $this->_redirect('/account/login?href=/data/visual'); + $this->_redirect('/account/login?href=/visual'); } } function indexAction() { - } - - - /**************************************************************** - - 气象数据 - - *****************************************************************/ - - - /* - * getMeteorologyValueByStation 按站点查询变量 - * - * param int $sid 站点编号 - * param string $field 变量类型 - * - * return array - */ - function getMeteorologyValueByStation($sid,$field) - { - - $sql = "select id,station_id as sid,date,$field as v from daily_meteorological_data where station_id=$sid ORDER BY date ASC"; - - $sth = $this->dbh->prepare($sql); - $sth->execute(); - $temp = $sth->fetchAll(); - - $dataSet = array(); - - foreach ($temp as $k=>$v) - { - $dataSet[] = array(strtotime($v['date'])*1000,$v['v']); - } - unset($temp); - - return $dataSet; - - }// getMeteorologyValueByStation 按站点查询变量 - - - - /* - * createMeteorologyDataSet 创建气象数据 - * - * param int $sid 站点id - * param string $valuetype 请求变量类型 - * param String $labe 单位 - * param int $round 数据精确度(小数点后位数) - * - * return array - */ - function createMeteorologyDataSet($sid,$valuetype,$label,$round=1) - { - if(empty($label)) - { - $label=""; - } - - $varField = array( - 'temperature' => 'avg_air_temperature', //日平均气温 - 'windspeed' => 'avg_wind_speed', //日平均风速 - 'precipitation' => 'sum_precipitation', //日合计降水量 - 'sunshine' => 'sunshine_hours' //日照小时数 - ); - - $data = array( - "name"=>"站点:$sid", - "data"=>$this->getMeteorologyValueByStation($sid,$varField[$valuetype]), - "tooltip"=>array( - "valueDecimals"=> $round, - "valueSuffix"=> $label - ) - ); - - return $data; - }// createMeteorologyDataSet 创建气象数据 - - - /* - * getMeteorologyDataByStationId 获得变量值 - * - * param string $valuetype 变量类型 - * param string $label 单位 - * param int $sid 可选,为空则查询所有站点 - * param int $round 数值精确度,小数点后位数 - * - * return array - */ - function getMeteorologyDataByStationId($valuetype,$label,$sid=0,$round=1) - { - if(empty($sid)) - { - $sql = "select station_id as sid from daily_meteorological_data group by station_id"; - - $sth = $this->dbh->prepare($sql); - $sth->execute(); - $stations = $sth->fetchAll(); - - $data = array(); - - foreach ($stations as $v) - { - $data[] = $this->createMeteorologyDataSet($v['sid'],$valuetype,$label,$round); - } - - return $data; - } - - else - { - return $this->createMeteorologyDataSet($sid,$valuetype,$label,$round=1); - } - - - }//getMeteorologyDataByStationId 获得气象数据变量值 - - - - - - - - - /********************************************************** - - 水文数据 - - ***********************************************************/ - - - /* - * getHydrologyValueByStation 按站点查询变量 - * - * param int $sid 站点编号 - * param string $table 变量类型 - * - * return array - */ - function getHydrologyValueByStation($sid,$t) - { - - $field = array(); //查询字段 - $order = array(); - - if(is_array($t['time'])) - { - foreach ($t['time'] as $v) - { - $field[] = $v; - $order[] = $v.' ASC'; - } - }else{ - $field[] = $t['time']; - $order[] = $t['time'].' ASC'; - } - $t['field'] .= " as v"; - $field[] = $t['field']; - $field[] = $t['sf']; - - $field = join(",",$field); //拼接 - $order = join(',',$order); - - - $sql = "select $field from {$t['table']} where {$t['sf']}='$sid' ORDER BY $order"; - - $sth = $this->dbh->prepare($sql); - $sth->execute(); - $temp = $sth->fetchAll(); - - $dataSet = array(); - - foreach ($temp as $k=>$v) - { - $time = 0; - if(!empty($v['dt'])) - { - $time = strtotime($v['dt']); - } - if(!empty($v['yr']) && !empty($v['mth'])) - { - $time = strtotime($v['yr'].'-'.$v['mth'].'-'.'01 00:00:00'); - } - if(!empty($v['yr']) && empty($v['mth'])) - { - $time = strtotime($v['yr'].'-01-01 00:00:00'); - } - $dataSet[] = array($time*1000,$v['v']); - } - unset($temp); - - return $dataSet; - - }// getHydrologyValueByStation 按站点查询变量 - - - - /* - * createHydrologyDataSet 创建水文数据 - * - * param int $sid 站点编号 - * param string $valuetype 变量类型 - * param string $label 单位 - * param int $round 数值精确度,小数点后位数 - * - * return array - */ - function createHydrologyDataSet($sid,$valuetype,$label,$round){ - - if(empty($label)) - { - $label=''; - } - - $varTable = array( - "dp"=>array( - "table"=>"hy_dp_c", //表名 - "field"=>"p", //值字段 - "sf"=>"stcd", //站点id字段 - "time"=>array("dt") //时间字段,数组 - ), //日降水量 - "mtp"=>array( - "table"=>"hy_mtp_e", - "field"=>"p", - "sf"=>"stcd", - "time"=>array('yr','mth') - ), //月降水量 - "yrp"=>array( - "table"=>"hy_yrp_f", - "field"=>"p", - "sf"=>"stcd", - "time"=>array("yr") - ), //年降水量 - "dq"=>array( - "table"=>"hy_dq_c", - "field"=>"avq", - "sf"=>"stcd", - "time"=>array("dt") - ), //日平均流量 - "mtq"=>array( - "table"=>"hy_mtq_e", - "field"=>"avq", - "sf"=>"stcd", - "time"=>array('yr','mth') - ), //月平均流量 - "yrq"=>array( - "table"=>"hy_yrq_f", - "field"=>"avq", - "sf"=>"stcd", - "time"=>array('yr') - ) //年平均流量 - );//$varTable - - $data = array( - "name"=>"站点:$sid", - "data"=>$this->getHydrologyValueByStation($sid,$varTable[$valuetype]), - "tooltip"=>array( - "valueDecimals"=> $round, - "valueSuffix"=> $label - ) - ); - - return $data; - - }//createHydrologyDataSet 创建水文数据 - - - /* - * getHydrologyDataByStationId 获得水文数据变量值 - * - * param string $valuetype 变量类型 - * param string $label 单位 - * param int $sid 站点编号,默认为空,空值将列出所有站点变量值 - * param int $round 数值精确度,小数点后位数 - * - * return array - */ - function getHydrologyDataByStationId($valuetype,$label,$sid=0,$round=1){ - - if(empty($sid)) - { - //降水 - $p = array('dp','mtp','yrp'); - $q = array('dq','mtq','yrq'); - if(in_array($valuetype,$p)) - { - $sql = "select stcd from hy_dp_c group by stcd"; - } - if(in_array($valuetype,$q)) - { - $sql = "select stcd from hy_dq_c group by stcd"; - } - - $sth = $this->dbh->prepare($sql); - $sth->execute(); - $stations = $sth->fetchAll(); - - $data = array(); - - foreach ($stations as $v) - { - $data[] = $this->createHydrologyDataSet($v['stcd'],$valuetype,$label,$round); - } - - return $data; - - }//所有站点 - - - if(is_array($sid)) - { - foreach($sid as $v) - { - - } - }//多个指定站点 - - - else - { - - }//单个站点 - } - //getHydrologyDataByStationId() 获得水文数据变量值 - - - /**************************** - - 环境监测数据 - - *****************************/ - - /* - * createAmbientDataSet 创建环境监测数据 - * - * param int $sid 站点编号、名称 - * param string $valuetype 变量类型 - * param string $label 单位 - * param int $round 数值精确度,小数点后位数 - * - * return array - */ - function createAmbientDataSet($sid,$valuetype,$label,$round=4){ - - if(empty($label)) - { - $label=''; - } - - $data = array( - "name"=>"站点:$sid", - "data"=>$this->getAmbientValueByStation($sid,$valuetype), - "tooltip"=>array( - "valueDecimals"=> $round, - "valueSuffix"=> $label - ) - ); - - return $data; - - }//createAmbientDataSet 创建环境监测数据的数据 - - /* - * getAmbientValueByStation 按站点查询变量 - * - * param int $sid 站点编号 - * param string $table 变量类型 - * - * return array - */ - function getAmbientValueByStation($sid,$t) - { - - $field = array(); //查询字段 - - $field[] = 'id'; - $field[] = '"position"'; - $field[] = 'dt'; - $field[] = $t.' as v'; - - $field = join(",",$field); //拼接 - - - $sql = "select $field from ambient_air where \"position\"='$sid' ORDER BY dt ASC"; - - $sth = $this->dbh->prepare($sql); - $sth->execute(); - $temp = $sth->fetchAll(); - - $dataSet = array(); - - foreach ($temp as $k=>$v) - { - $time = 0; - if(!empty($v['dt'])) - { - $time = strtotime($v['dt']); - } - if(!empty($v['yr']) && !empty($v['mth'])) - { - $time = strtotime($v['yr'].'-'.$v['mth'].'-'.'01 00:00:00'); - } - if(!empty($v['yr']) && empty($v['mth'])) - { - $time = strtotime($v['yr'].'-01-01 00:00:00'); - } - $dataSet[] = array($time*1000,$v['v']); - } - unset($temp); - - return $dataSet; - - }// getAmbientValueByStation 按站点查询变量 - - /* - * getAmbientDataByStationId 获得环境监测数据变量 - * - * param string $valuetype 变量类型 - * param string $label 单位 - * param int $sid 站点编号,默认为空,空值将列出所有站点变量值 - * param int $round 数值精确度,小数点后位数 - * - * return array - */ - function getAmbientDataByStationId($valuetype,$label,$sid=0,$round=4){ - - if(empty($sid)) - { - //降水 - $p = array('tsp','pm10','so2','no2'); - - if(in_array($valuetype,$p)) - { - $sql = "select \"position\" from ambient_air group by \"position\""; - } - - $sth = $this->dbh->prepare($sql); - $sth->execute(); - $stations = $sth->fetchAll(); - - $data = array(); - - foreach ($stations as $v) - { - $data[] = $this->createAmbientDataSet($v['position'],$valuetype,$label,$round); - } - - return $data; - - }//所有站点 - - - if(is_array($sid)) - { - - }//多个指定站点 - - - else - { - - }//单个站点 - - } - //getAmbientDataByStationId() 获得环境监测数据变量的值 - - //******************************************************** diff --git a/application/default/views/scripts/visual/index.phtml b/application/default/views/scripts/visual/index.phtml index d4ddb661..9150f933 100644 --- a/application/default/views/scripts/visual/index.phtml +++ b/application/default/views/scripts/visual/index.phtml @@ -1,162 +1,168 @@ -headTitle($this->config->title->site); -$this->headTitle($this->config->title->data); -$this->headTitle()->setSeparator(' - '); -$theme = new Theme; -$theme->appendPlus($this,'highstock'); -$this->breadcrumb('
      首页'); -$this->breadcrumb('数据与服务'); -$this->breadcrumb('数据可视化'); -$this->breadcrumb()->setSeparator(' > '); -?> - - -
      - -
      -
      - -
      - - \ No newline at end of file diff --git a/application/module/Westdc/Visual/Event/RecordEvent.php b/application/module/Westdc/Visual/Event/RecordEvent.php new file mode 100644 index 00000000..31513adb --- /dev/null +++ b/application/module/Westdc/Visual/Event/RecordEvent.php @@ -0,0 +1,13 @@ +_Events = Factory::Handle($recordType); + } + + public function attach(EventManagerInterface $events) + { + $this->listeners[] = $events->attach('submit.checkParam', array($this->_Events, 'checkParam'), 100); + $this->listeners[] = $events->attach('submit.processData', array($this->_Events, 'processData'), 100); + $this->listeners[] = $events->attach('submit.recordPosted', array($this->_Events, 'recordPosted'), 100); + $this->listeners[] = $events->attach('submit.recordChanged', array($this->_Events, 'recordChanged'), 100); + } + + public function detach(EventManagerInterface $events) + { + foreach ($this->listeners as $index => $listener) { + if ($events->detach($listener)) { + unset($this->listeners[$index]); + } + } + } + +} diff --git a/application/module/Westdc/Visual/Reader/Sc.php b/application/module/Westdc/Visual/Reader/Sc.php new file mode 100644 index 00000000..061cf556 --- /dev/null +++ b/application/module/Westdc/Visual/Reader/Sc.php @@ -0,0 +1,33 @@ +initParams(); + } + + public function initParams() + { + $this->sql->fetchAll = ""; + $mode = ""; + } + + public function fetch($id) + { + + } + + public function getParam() + { + + } +} \ No newline at end of file diff --git a/application/module/Westdc/Visual/Record.php b/application/module/Westdc/Visual/Record.php new file mode 100644 index 00000000..40a4fd16 --- /dev/null +++ b/application/module/Westdc/Visual/Record.php @@ -0,0 +1,16 @@ + Date: Wed, 21 May 2014 09:26:15 +0000 Subject: [PATCH 166/173] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=8F=AF=E8=A7=86=E5=8C=96=E7=9B=B8=E5=85=B3=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/VisualController.php | 254 ++---------------- .../default/views/scripts/visual/index.phtml | 221 ++++++--------- application/module/Westdc/Visual/Factory.php | 8 +- .../module/Westdc/Visual/Reader/Sc.php | 52 +++- .../Westdc/Visual/Reader/SoilMoisture.php | 81 ++++++ application/module/Westdc/Visual/Record.php | 25 +- .../module/Westdc/Visual/RecordInterface.php | 2 +- 7 files changed, 260 insertions(+), 383 deletions(-) create mode 100644 application/module/Westdc/Visual/Reader/SoilMoisture.php diff --git a/application/default/controllers/VisualController.php b/application/default/controllers/VisualController.php index c733af74..cb3a0e11 100644 --- a/application/default/controllers/VisualController.php +++ b/application/default/controllers/VisualController.php @@ -1,4 +1,5 @@ _getParam("dataset"); + + if(empty($record_type)) + return true; + + $sc = Factory::Bootstrap($record_type); } @@ -36,207 +42,29 @@ class VisualController extends Zend_Controller_Action */ function dataAction() { - - $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); + $this->_helper->layout->disableLayout(); - $ac = $this->_request->getParam('ac'); - $base = $this->_request->getParam('dt'); + $record_type = $this->_getParam("dataset"); + $record_subset = $this->_getParam("subdataset"); - if(!in_array($base,array('meteorology','hydrology','ambient'))) - { - $data = array( - "error"=>"参数错误" - ); - - $this->jsonexit($data); + if(empty($record_type)) return true; + + $record = Factory::Bootstrap($record_type); + + if(!empty($record_subset)) + { + $record->subset = $record_subset; } + $data = $record->outPut(); - $datas = array(); - $label = ""; - $title = ""; - $range = 0; - $type = "line"; - - if($base == "meteorology") - { - if($ac=='temperature') - { - - $title = "日平均温度"; - $label = "℃"; - $type = "line"; - - $datas = $this->getMeteorologyDataByStationId($ac,$label); - - }//日平均温度 - - if($ac == 'windspeed') - { - - $title = "日平均风速"; - $label = "m/s"; - $type = "line"; - - $datas = $this->getMeteorologyDataByStationId($ac,$label); - - }//日平均风速 m/s - - if($ac == 'precipitation') - { - - $title = "日合计降水量"; - $label = "mm"; - $type = "line"; - - $datas = $this->getMeteorologyDataByStationId($ac,$label); - - }//日合计降水量 mm - - if($ac == 'sunshine') - { - - $title = "日照小时数"; - $label = "h"; - $type = "line"; - - $datas = $this->getMeteorologyDataByStationId($ac,$label); - - }//日照小时数 h - - }//气象数据 - - - if($base == 'hydrology') - { - if($ac == 'dp') - { - $title = "日降水量"; - $label = "mm"; - $type = "line"; - - $datas = $this->getHydrologyDataByStationId($ac,$label); - - }//日降水量 - - if($ac == 'mtp') - { - $title = "月均降水"; - $label = "mm"; - $type = "line"; - - $datas = $this->getHydrologyDataByStationId($ac,$label); - }//月均降水 - - if($ac == 'yrp') - { - $title = "年均降水"; - $label = "mm"; - $type = "line"; - - $datas = $this->getHydrologyDataByStationId($ac,$label); - }//年均降水 - - if($ac == 'dq') - { - $title = "日均流量"; - $label = "mm"; - $type = "line"; - - $datas = $this->getHydrologyDataByStationId($ac,$label); - } - - if($ac == 'mtq') - { - $title = "月均流量"; - $label = "mm"; - $type = "line"; - - $datas = $this->getHydrologyDataByStationId($ac,$label); - } - - if($ac == 'yrq') - { - $title = "年均流量"; - $label = "mm"; - $type = "line"; - - $datas = $this->getHydrologyDataByStationId($ac,$label); - } - - - }//水文数据 - - - if($base=="ambient") - { - if($ac=='tsp') - { - $title = "总悬浮颗粒物"; - $label=""; - $type = "column"; - $range = 6; - $datas = $this->getAmbientDataByStationId($ac,$label); - } - - if($ac=='pm10') - { - $title = "可吸入颗粒物"; - $label=""; - $type = "column"; - $range = 6; - $datas = $this->getAmbientDataByStationId($ac,$label); - } - - if($ac=='so2') - { - $title = "二氧化硫"; - $label=""; - $type = "column"; - $range = 6; - $datas = $this->getAmbientDataByStationId($ac,$label); - } - - if($ac=='no2') - { - $title = "二氧化氮"; - $label=""; - $type = "column"; - $range = 6; - $datas = $this->getAmbientDataByStationId($ac,$label); - } - }//环境监测数据 - - if(empty($range)) - { - $range = 0; - } - - $data = array( - "label"=>$label, - "title"=>$title, - "type"=>$type, - "range"=>$range, - "datas"=>$datas - ); - $this->jsonexit($data); return true; }//dataAction() Ajax获取数据 - - - - function utcMsTime($time=''){ - if(empty($time)) - return (time()+8*3600)*1000; - else - return $time*1000; - } - /* * jsonexit() 退出并返回json数据 * @@ -249,48 +77,4 @@ class VisualController extends Zend_Controller_Action return true; }//jsonexit() 退出并返回json数据 -} - - -/* - 数据模型 - "data"=>array( - - //第一条曲线 - "data1"=>array( - "title"=>"5米风速", - "unit"=>"m/s", - "sensor"=>"传感器XXX", - "sensor_type"=>"传感器类型", - "datas"=>array( - array($this->utcMsTime(),26.0), - array($this->utcMsTime()+3600*1000,28.1), - array($this->utcMsTime()+7200*1000,30.9), - array($this->utcMsTime()+10800*1000,32.0), - array($this->utcMsTime()+12800*1000,28.0), - array($this->utcMsTime()+13800*1000,22.0) - ) - ), - - - //第二条曲线 - "data2"=>array( - "title"=>"10米风速", - "unit"=>"m/s", - "sensor"=>"传感器XXX", - "sensor_type"=>"传感器类型", - "datas"=>array( - array($this->utcMsTime(),26.0), - array($this->utcMsTime()+5600*1000,22.1), - array($this->utcMsTime()+8200*1000,35.9), - array($this->utcMsTime()+11800*1000,32.0), - array($this->utcMsTime()+13900*1000,22.0), - array($this->utcMsTime()+16800*1000,21.0) - ) - ), - - //第三条....... - ) - - */ - +} \ No newline at end of file diff --git a/application/default/views/scripts/visual/index.phtml b/application/default/views/scripts/visual/index.phtml index 9150f933..4f0b7e12 100644 --- a/application/default/views/scripts/visual/index.phtml +++ b/application/default/views/scripts/visual/index.phtml @@ -11,158 +11,109 @@ $this->breadcrumb()->setSeparator(' > '); ?> \ No newline at end of file diff --git a/application/module/Westdc/Visual/Factory.php b/application/module/Westdc/Visual/Factory.php index 3c11d1f0..cbb6b570 100644 --- a/application/module/Westdc/Visual/Factory.php +++ b/application/module/Westdc/Visual/Factory.php @@ -1,9 +1,9 @@ -+initParams(); } - public function initParams() + public $subset; + + public function getData() { - $this->sql->fetchAll = ""; - $mode = ""; + $sql = "SELECT * FROM datasands + ORDER BY + year ASC, + month ASC + "; + + $rs = $this->db->query($sql); + return $rs; + } - public function fetch($id) + public function switchDataset() { + if(empty($this->subset)) + { + $this->subset = "avg_sand"; + return; + } + switch($this->subset){ + case "avg": + $this->subset = "avg_sand"; + break; + case "max" : + $this->subset = "max_sand"; + break; + case "min" : + $this->subset = "min_sand"; + break; + } + + return; } - public function getParam() + public function outPut() { + $this->switchDataset(); + $rs = $this->getData(); + + $data = array(); + + while($row = $rs->fetch()) + { + $row['utctime'] = $this->utcMsTime(mktime(0,0,0,$row['month'],0,$row['year'])); + $data[] = array($row['utctime'],$row[$this->subset]); + } + + return $data; } + } \ No newline at end of file diff --git a/application/module/Westdc/Visual/Reader/SoilMoisture.php b/application/module/Westdc/Visual/Reader/SoilMoisture.php new file mode 100644 index 00000000..cba4bf79 --- /dev/null +++ b/application/module/Westdc/Visual/Reader/SoilMoisture.php @@ -0,0 +1,81 @@ +switchDataset(); + + $sql = "SELECT * FROM data_watercontent + WHERE + $this->subset > 0 + ORDER BY + extract(day from \"timestamp\"), + extract(month from \"timestamp\"), + extract(year from \"timestamp\") + "; + + $rs = $this->db->query($sql); + return $rs; + + } + + public function switchDataset() + { + if(empty($this->subset)) + { + $this->subset = "20cm"; + return; + } + + switch($this->subset){ + case "10cm": + $this->subset = "vwc_avg10"; + break; + case "20cm" : + $this->subset = "vwc_avg20"; + break; + case "30cm" : + $this->subset = "vwc_avg30"; + break; + case "40cm" : + $this->subset = "vwc_avg40"; + break; + case "50cm" : + $this->subset = "vwc_avg50"; + break; + } + + return; + } + + public function outPut() + { + + $rs = $this->getData(); + + $data = array(); + + while($row = $rs->fetch()) + { + $row['utctime'] = $this->utcMsTime(strtotime($row['timestamp'])); + $data[] = array($row['utctime'],$row[$this->subset]); + } + + return $data; + } + +} \ No newline at end of file diff --git a/application/module/Westdc/Visual/Record.php b/application/module/Westdc/Visual/Record.php index 40a4fd16..9077b612 100644 --- a/application/module/Westdc/Visual/Record.php +++ b/application/module/Westdc/Visual/Record.php @@ -6,11 +6,34 @@ class Record function __construct($recordType) { - + $this->db = \Zend_Registry::get('db'); + } + + public function makeSql($table,$index,$fieldValue,$fieldTime) + { + $sql = "SELECT + \"$index\" as \"index\", \"$fieldValue\" as \"value\", \"$fieldTime\" as \"time\" + FROM \"$table\" + ORDER BY + extract(year from \"$fieldTime\") ASC, + extract(month from \"$fieldTime\") ASC, + extract(day from \"$fieldTime\") ASC, + extract(hour from \"$fieldTime\") ASC + "; + + $rs = $this->db->query($sql); + return $rs; } public function prepareData() { } + + public function utcMsTime($time=''){ + if(empty($time)) + return (time()+8*3600)*1000; + else + return $time*1000; + } } \ No newline at end of file diff --git a/application/module/Westdc/Visual/RecordInterface.php b/application/module/Westdc/Visual/RecordInterface.php index e1a5c85c..870b34cf 100644 --- a/application/module/Westdc/Visual/RecordInterface.php +++ b/application/module/Westdc/Visual/RecordInterface.php @@ -3,5 +3,5 @@ namespace Westdc\Visual; interface RecordInterface { - + public function outPut(); } \ No newline at end of file From 483da847cde7d9e83a4506cf3d313f9dcc07b9cc Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Wed, 21 May 2014 09:57:28 +0000 Subject: [PATCH 167/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/Westdc/Visual/Reader/Sc.php | 26 +++++++------- .../Westdc/Visual/Reader/SoilMoisture.php | 36 +++++++++---------- application/module/Westdc/Visual/Record.php | 1 - .../module/Westdc/Visual/RecordInterface.php | 1 + 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/application/module/Westdc/Visual/Reader/Sc.php b/application/module/Westdc/Visual/Reader/Sc.php index 2136968c..c78309fd 100644 --- a/application/module/Westdc/Visual/Reader/Sc.php +++ b/application/module/Westdc/Visual/Reader/Sc.php @@ -15,19 +15,6 @@ class Sc extends Record implements RecordInterface public $subset; - public function getData() - { - $sql = "SELECT * FROM datasands - ORDER BY - year ASC, - month ASC - "; - - $rs = $this->db->query($sql); - return $rs; - - } - public function switchDataset() { if(empty($this->subset)) @@ -51,6 +38,19 @@ class Sc extends Record implements RecordInterface return; } + public function getData() + { + $sql = "SELECT * FROM datasands + ORDER BY + year ASC, + month ASC + "; + + $rs = $this->db->query($sql); + return $rs; + + } + public function outPut() { $this->switchDataset(); diff --git a/application/module/Westdc/Visual/Reader/SoilMoisture.php b/application/module/Westdc/Visual/Reader/SoilMoisture.php index cba4bf79..1b68b0e3 100644 --- a/application/module/Westdc/Visual/Reader/SoilMoisture.php +++ b/application/module/Westdc/Visual/Reader/SoilMoisture.php @@ -15,24 +15,6 @@ class SoilMoisture extends Record implements RecordInterface public $subset; - public function getData() - { - $this->switchDataset(); - - $sql = "SELECT * FROM data_watercontent - WHERE - $this->subset > 0 - ORDER BY - extract(day from \"timestamp\"), - extract(month from \"timestamp\"), - extract(year from \"timestamp\") - "; - - $rs = $this->db->query($sql); - return $rs; - - } - public function switchDataset() { if(empty($this->subset)) @@ -62,6 +44,24 @@ class SoilMoisture extends Record implements RecordInterface return; } + public function getData() + { + $this->switchDataset(); + + $sql = "SELECT * FROM data_watercontent + WHERE + $this->subset > 0 + ORDER BY + extract(year from \"timestamp\"), + extract(month from \"timestamp\"), + extract(day from \"timestamp\") + "; + //exit($sql); + $rs = $this->db->query($sql); + return $rs; + + } + public function outPut() { diff --git a/application/module/Westdc/Visual/Record.php b/application/module/Westdc/Visual/Record.php index 9077b612..14f02205 100644 --- a/application/module/Westdc/Visual/Record.php +++ b/application/module/Westdc/Visual/Record.php @@ -18,7 +18,6 @@ class Record extract(year from \"$fieldTime\") ASC, extract(month from \"$fieldTime\") ASC, extract(day from \"$fieldTime\") ASC, - extract(hour from \"$fieldTime\") ASC "; $rs = $this->db->query($sql); diff --git a/application/module/Westdc/Visual/RecordInterface.php b/application/module/Westdc/Visual/RecordInterface.php index 870b34cf..d2351c3a 100644 --- a/application/module/Westdc/Visual/RecordInterface.php +++ b/application/module/Westdc/Visual/RecordInterface.php @@ -4,4 +4,5 @@ namespace Westdc\Visual; interface RecordInterface { public function outPut(); + public function getData(); } \ No newline at end of file From c986d6c535f24412e8599b630acadd8e5bbe633b Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Thu, 22 May 2014 02:44:18 +0000 Subject: [PATCH 168/173] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=8F=AF=E8=A7=86=E5=8C=96=E5=91=BD=E5=90=8D=E7=A9=BA=E9=97=B4?= =?UTF-8?q?=E5=86=85=E9=83=A8=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/Westdc/Visual/Reader/Sc.php | 2 +- .../Westdc/Visual/Reader/SoilMoisture.php | 7 +++--- application/module/Westdc/Visual/Record.php | 24 +++++++++++++------ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/application/module/Westdc/Visual/Reader/Sc.php b/application/module/Westdc/Visual/Reader/Sc.php index c78309fd..a568a905 100644 --- a/application/module/Westdc/Visual/Reader/Sc.php +++ b/application/module/Westdc/Visual/Reader/Sc.php @@ -40,7 +40,7 @@ class Sc extends Record implements RecordInterface public function getData() { - $sql = "SELECT * FROM datasands + $sql = "SELECT * FROM data_sands ORDER BY year ASC, month ASC diff --git a/application/module/Westdc/Visual/Reader/SoilMoisture.php b/application/module/Westdc/Visual/Reader/SoilMoisture.php index 1b68b0e3..bd63fe3e 100644 --- a/application/module/Westdc/Visual/Reader/SoilMoisture.php +++ b/application/module/Westdc/Visual/Reader/SoilMoisture.php @@ -52,9 +52,10 @@ class SoilMoisture extends Record implements RecordInterface WHERE $this->subset > 0 ORDER BY - extract(year from \"timestamp\"), - extract(month from \"timestamp\"), - extract(day from \"timestamp\") + extract(year from \"timestamp\") ASC, + extract(month from \"timestamp\") ASC, + extract(day from \"timestamp\") ASC, + extract(hour from \"timestamp\") ASC "; //exit($sql); $rs = $this->db->query($sql); diff --git a/application/module/Westdc/Visual/Record.php b/application/module/Westdc/Visual/Record.php index 14f02205..0b390e30 100644 --- a/application/module/Westdc/Visual/Record.php +++ b/application/module/Westdc/Visual/Record.php @@ -3,10 +3,25 @@ namespace Westdc\Visual; class Record { - + + public $db; + function __construct($recordType) { - $this->db = \Zend_Registry::get('db'); + $this->initDatabase(); + } + + public function initDatabase() + { + $config = \Zend_Registry::get('config'); + + $dsn = "pgsql:host={$config->visual_db->hostname};" + ."port={$config->visual_db->port};" + ."dbname={$config->visual_db->database};" + ."user={$config->visual_db->username};" + ."password={$config->visual_db->password}"; + + $this->db = new \PDO($dsn); } public function makeSql($table,$index,$fieldValue,$fieldTime) @@ -24,11 +39,6 @@ class Record return $rs; } - public function prepareData() - { - - } - public function utcMsTime($time=''){ if(empty($time)) return (time()+8*3600)*1000; From a8df49bff7471a558b7914348ae40549651970cf Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Thu, 22 May 2014 08:59:35 +0000 Subject: [PATCH 169/173] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E5=8F=AF=E8=A7=86?= =?UTF-8?q?=E5=8C=96=E7=9A=84=E9=93=BE=E6=8E=A5=E5=9C=B0=E5=9D=80=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E6=95=B0=E6=8D=AE=E9=9B=86=E7=9A=84?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/views/scripts/data/index.phtml | 69 ++++++++-------- .../default/views/scripts/visual/index.phtml | 82 +++++++++++-------- .../module/Westdc/Visual/Reader/Sc.php | 2 +- 3 files changed, 83 insertions(+), 70 deletions(-) diff --git a/application/default/views/scripts/data/index.phtml b/application/default/views/scripts/data/index.phtml index c589d345..c4ab8b53 100755 --- a/application/default/views/scripts/data/index.phtml +++ b/application/default/views/scripts/data/index.phtml @@ -8,81 +8,81 @@ $this->headTitle()->setSeparator(' - '); .fieldlist ul li:hover{color:#FFF;background:#0088CC;border-radius: 6px 6px 6px 6px;} .fieldlist ul li:hover a{color:#FFF; text-decoration:none;} .news_list ul li{line-height:24px;} - -
      -
      -

      特色导航

      - + + '地点关键词','theme'=>'主题关键词','discipline'=>'学科关键词','stratum'=>'地层关键词','temporal'=>'时间关键词'); + $keytypezh=array('place'=>'地点关键词','theme'=>'主题关键词','discipline'=>'学科关键词','stratum'=>'地层关键词','temporal'=>'时间关键词'); $type='theme'; -?> -
      -

      +?> +
      +

        keywords[$type] as $cg) : ?>
      • '>()
      -
      +
      -
      -

      +
      +

        keywords[$type] as $cg) : ?>
      • '>()
      -
      -
      -
      +
      +
      +
      -
      -

      +?> +
      +

        keywords[$type] as $cg) : ?>
      • '>()
      -
      +
      -
      -

      +
      +

        keywords[$type] as $cg) : ?>
      • '>()
      -
      +
      @@ -94,7 +94,7 @@ $this->headTitle()->setSeparator(' - ');
    • '>()
    • -
      +

       数据服务

      @@ -102,6 +102,7 @@ $this->headTitle()->setSeparator(' - ');
    • -   离线数据服务记录(最近20个)
    • -   如何从数据中心申请数据
    • -   如何在数据中心发布数据
    • +
    • -   数据可视化
    • diff --git a/application/default/views/scripts/visual/index.phtml b/application/default/views/scripts/visual/index.phtml index 4f0b7e12..9282928f 100644 --- a/application/default/views/scripts/visual/index.phtml +++ b/application/default/views/scripts/visual/index.phtml @@ -10,36 +10,52 @@ $this->breadcrumb('数据可视化'); $this->breadcrumb()->setSeparator(' > '); ?>
      -
      + -
      +
      - + + 清除图像 +
      @@ -94,19 +110,15 @@ $(function() { }); }); + + $(".control-btn-cls").click(function(e) { + for(i in chart.series) + { + chart.series[i].remove(); + } + }); }); - -function onDataReceived(data) -{ - chart.addSeries({ - name: 'Sediment Concentration', - data: data, - type : 'column' - }); - alert(chart.series[0].name) -} - $( document ).ajaxSend(function() { $('#loading').css('display','none'); }); diff --git a/application/module/Westdc/Visual/Reader/Sc.php b/application/module/Westdc/Visual/Reader/Sc.php index a568a905..49b2f1f5 100644 --- a/application/module/Westdc/Visual/Reader/Sc.php +++ b/application/module/Westdc/Visual/Reader/Sc.php @@ -39,7 +39,7 @@ class Sc extends Record implements RecordInterface } public function getData() - { + { $sql = "SELECT * FROM data_sands ORDER BY year ASC, From 12b8b26338209ff4a9a142cdef85f9c5b21c38a2 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Fri, 23 May 2014 07:41:52 +0000 Subject: [PATCH 170/173] =?UTF-8?q?=E5=A2=9E=E5=8A=A009=E5=B9=B4=E5=90=AB?= =?UTF-8?q?=E6=B2=99=E9=87=8F=E6=95=B0=E6=8D=AE=E5=8F=AF=E8=A7=86=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/views/scripts/visual/index.phtml | 17 +++-- .../module/Westdc/Visual/Reader/Sc2009.php | 71 +++++++++++++++++++ 2 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 application/module/Westdc/Visual/Reader/Sc2009.php diff --git a/application/default/views/scripts/visual/index.phtml b/application/default/views/scripts/visual/index.phtml index 9282928f..1e3e474b 100644 --- a/application/default/views/scripts/visual/index.phtml +++ b/application/default/views/scripts/visual/index.phtml @@ -16,19 +16,28 @@ $this->breadcrumb()->setSeparator(' > ');
      diff --git a/application/module/Westdc/Visual/Reader/Sc2009.php b/application/module/Westdc/Visual/Reader/Sc2009.php new file mode 100644 index 00000000..3cd9c522 --- /dev/null +++ b/application/module/Westdc/Visual/Reader/Sc2009.php @@ -0,0 +1,71 @@ +subset)) + { + $this->subset = "avg_sand"; + return; + } + + switch($this->subset){ + case "avg": + $this->subset = "avg_sand"; + break; + case "max" : + $this->subset = "max_sand"; + break; + case "min" : + $this->subset = "min_sand"; + break; + } + + return; + } + + public function getData() + { + $sql = "SELECT * FROM data_sands2009 + ORDER BY + year ASC, + month ASC + "; + + $rs = $this->db->query($sql); + return $rs; + + } + + public function outPut() + { + $this->switchDataset(); + + $rs = $this->getData(); + + $data = array(); + + while($row = $rs->fetch()) + { + $row['utctime'] = $this->utcMsTime(mktime(0,0,0,$row['month'],0,$row['year'])); + $data[] = array($row['utctime'],$row[$this->subset]); + } + + return $data; + } + +} \ No newline at end of file From b9a9e44746849ebd9346ad2e73a33b70aedd66f6 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Sun, 25 May 2014 02:18:41 +0000 Subject: [PATCH 171/173] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Westdc/Visual/Reader/SoilMoisture.php | 161 +++++++++--------- 1 file changed, 80 insertions(+), 81 deletions(-) diff --git a/application/module/Westdc/Visual/Reader/SoilMoisture.php b/application/module/Westdc/Visual/Reader/SoilMoisture.php index bd63fe3e..0b363a0e 100644 --- a/application/module/Westdc/Visual/Reader/SoilMoisture.php +++ b/application/module/Westdc/Visual/Reader/SoilMoisture.php @@ -1,82 +1,81 @@ -subset)) - { - $this->subset = "20cm"; - return; - } - - switch($this->subset){ - case "10cm": - $this->subset = "vwc_avg10"; - break; - case "20cm" : - $this->subset = "vwc_avg20"; - break; - case "30cm" : - $this->subset = "vwc_avg30"; - break; - case "40cm" : - $this->subset = "vwc_avg40"; - break; - case "50cm" : - $this->subset = "vwc_avg50"; - break; - } - - return; - } - - public function getData() - { - $this->switchDataset(); - - $sql = "SELECT * FROM data_watercontent - WHERE - $this->subset > 0 - ORDER BY - extract(year from \"timestamp\") ASC, - extract(month from \"timestamp\") ASC, - extract(day from \"timestamp\") ASC, - extract(hour from \"timestamp\") ASC - "; - //exit($sql); - $rs = $this->db->query($sql); - return $rs; - - } - - public function outPut() - { - - $rs = $this->getData(); - - $data = array(); - - while($row = $rs->fetch()) - { - $row['utctime'] = $this->utcMsTime(strtotime($row['timestamp'])); - $data[] = array($row['utctime'],$row[$this->subset]); - } - - return $data; - } - +subset)) + { + $this->subset = "20cm"; + return; + } + + switch($this->subset){ + case "10cm": + $this->subset = "vwc_avg10"; + break; + case "20cm" : + $this->subset = "vwc_avg20"; + break; + case "30cm" : + $this->subset = "vwc_avg30"; + break; + case "40cm" : + $this->subset = "vwc_avg40"; + break; + case "50cm" : + $this->subset = "vwc_avg50"; + break; + } + + return; + } + + public function getData() + { + $this->switchDataset(); + + $sql = "SELECT * FROM data_watercontent + WHERE + $this->subset > 0 + ORDER BY + extract(year from \"timestamp\") ASC, + extract(month from \"timestamp\") ASC, + extract(day from \"timestamp\") ASC, + extract(hour from \"timestamp\") ASC + "; + //exit($sql); + $rs = $this->db->query($sql); + return $rs; + + } + + public function outPut() + { + + $rs = $this->getData(); + + $data = array(); + + while($row = $rs->fetch()) + { + $row['utctime'] = $this->utcMsTime(strtotime($row['timestamp'])); + $data[] = array($row['utctime'],$row[$this->subset]); + } + + return $data; + } + } \ No newline at end of file From 4120cda7aa6599c657b3a2f071fde04f7d752c1a Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Mon, 26 May 2014 03:38:36 +0000 Subject: [PATCH 172/173] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=AF=E8=A7=86?= =?UTF-8?q?=E5=8C=96=E8=A6=81=E7=B4=A0=E5=90=8E=E5=8F=B0=E7=AE=A1=E7=90=86?= =?UTF-8?q?=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 | 8416 +++++++++-------- .../admin/views/scripts/data/left.phtml | 1 + application/admin/views/scripts/data/md.phtml | 3 +- .../admin/views/scripts/data/visual-add.phtml | 45 + .../admin/views/scripts/data/visual.phtml | 20 + .../Westdc/Visual/Handle/VisualHandle.php | 43 + .../Westdc/Visual/Listener/VisualListener.php | 27 + application/module/Westdc/Visual/Visual.php | 86 + 8 files changed, 4440 insertions(+), 4201 deletions(-) create mode 100644 application/admin/views/scripts/data/visual-add.phtml create mode 100644 application/admin/views/scripts/data/visual.phtml create mode 100644 application/module/Westdc/Visual/Handle/VisualHandle.php create mode 100644 application/module/Westdc/Visual/Listener/VisualListener.php create mode 100644 application/module/Westdc/Visual/Visual.php diff --git a/application/admin/controllers/DataController.php b/application/admin/controllers/DataController.php index ad0cc603..500ce89a 100755 --- a/application/admin/controllers/DataController.php +++ b/application/admin/controllers/DataController.php @@ -1,4200 +1,4216 @@ -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() - { - //其他连接 - } - - //提供和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"; - $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=trim($this->_request->getParam('uuid')); - if ($source=="geonetwork" && empty($uuid) ) { - //从geonetwork向WESTDC同步 - //对所有的新数据增加评审状态 - $sql="insert into mdstatus (uuid,status,ts_accepted,userid) select uuid,1,now(),? - from geonetworkmetadata gn where uuid not in (select uuid from mdstatus)"; - $userid = Zend_Auth::getInstance()->getIdentity()->id; - $this->db->query($sql,array($userid)); - $sql="select uuid,data,source 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='e3ad32dc-f573-11e0-aa7b-b768cfd88d80'"; - $sql="delete from metadata where uuid in (select uuid from watergn)"; - $this->db->query($sql); - $sql="delete from responsible where id not in (select distinct(resid) from role)"; - $this->db->query($sql); - //对所有的新数据增加评审状态 - $sql="insert into mdstatus (uuid,status,ts_accepted,userid) select uuid,1,now(),? - from watergn where uuid not in (select uuid from mdstatus)"; - $userid = Zend_Auth::getInstance()->getIdentity()->id; - $this->db->query($sql,array($userid)); - //同步黑河遥感实验的元数据 - $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 ($source=="glacier" && empty($uuid) ) { - //首先删除所有的对应专题数据 - $sql="delete from metadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier')"; - $this->db->query($sql); - $sql="delete from responsible where id not in (select distinct(resid) from role)"; - $this->db->query($sql); - //对所有的新数据增加评审状态 - /*$sql="insert into mdstatus (uuid,status,ts_accepted,userid) select uuid,1,now(),? - from watergn where uuid not in (select uuid from mdstatus)"; - $userid = Zend_Auth::getInstance()->getIdentity()->id; - $this->db->query($sql,array($userid));*/ - //同步专题元数据 - $sql="select uuid,data,source from geonetworkmetadata where schemaid='iso19115' and uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier')"; - $rs=$this->db->fetchAll($sql); - foreach($rs as $gmd) { - $this->import($gmd->data); - //source in unused now. - //$this->db->query("update metadata set source=? where uuid=?",array($gmd->source,$gmd->uuid)); - } - $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); - } - $this->view->msg='成功同步WESTDC元数据到GEONETWORK!'; - } elseif (!empty($uuid) && isset($_POST['gnsubmit'])) { - //同步单条元数据到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).")"; - } - $this->db->exec($sql); - $this->view->msg='成功同步元数据:'.$uuid; - } else $this->view->msg='不存在此元数据:'.$uuid; - } elseif (!empty($uuid) && isset($_POST['watersubmit'])) { - //同步单条元数据 - $sql=$this->db->quoteInto("select data,source from watergn where uuid=?",$uuid); - if ($rs=$this->db->fetchRow($sql)) { - $this->import($rs->data); - $this->db->query("update metadata set source=? where uuid=?",array($rs->source,$uuid)); - $this->view->msg='成功同步元数据:'.$uuid; - } else $this->view->msg='不存在此元数据:'.$uuid; - } elseif ($list=='westdc') { - $sql="select uuid,title from metadata where uuid not in (select uuid from geonetworkmetadata where schemaid='iso19115')"; - $this->view->metadata=$this->db->query($sql); - } elseif ($list=='geonetwork') { - $sql="select id,uuid,(regexp_matches(data,'(.*)'))[1] as title from geonetworkmetadata - where uuid not in (select uuid from metadata)"; - $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=='geonetwork') { - //dblink view中删除多条有问题,暂时用单条删除替代 - //$sql="delete from geonetworkmetadata where uuid not in (select uuid from metadata)"; - $sql="select uuid from geonetworkmetadata where uuid not in (select uuid from metadata)"; - $rows=$this->db->fetchAll($sql); - foreach($rows as $row) - { - $this->db->exec($this->db->quoteInto("delete from geonetworkmetadata where uuid=?",$row->uuid)); - } - $this->view->msg='已删除GEONETWORK中多出的元数据!'; - } 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"; - $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=encode(digest(md5('$row->password'),'sha1'),'hex'),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',encode(digest(md5('$row->password'),'sha1'),'hex'),'$row->email')"; - $this->db->query($sql); - } - } - $this->view->msg='已成功同步帐号!'; - } elseif (!empty($uuid) && (isset($_POST['submit']) || (!isset($_POST['gnsubmit']) && !isset($_POST['watersubmit'])))) { - //同步单条元数据 - $sql=$this->db->quoteInto("select data,source from geonetworkmetadata where uuid=?",$uuid); - if ($rs=$this->db->fetchRow($sql)) { - $this->import($rs->data); - $this->db->exec($this->db->quoteInto("update metadata set source=? where uuid='$uuid'",$rs->source)); - $userid = Zend_Auth::getInstance()->getIdentity()->id; - $this->db->query("insert into mdstatus (uuid,status,ts_accepted,userid) select uuid,1,now(),? - from geonetworkmetadata gn where uuid not in (select uuid from mdstatus) and uuid=?",array($userid,$uuid)); - $this->view->msg='成功同步元数据:'.$uuid; - //update search document - $search=new Search(); - $sql="select * from xunsearch where uuid=?"; - $sth = $this->db->prepare($sql); - $sth->setFetchMode(Zend_Db::FETCH_ASSOC); - $sth->execute(array($uuid)); - $data = $sth->fetch(); - $search->update($data); - - } else $this->view->msg='不存在此元数据:'.$uuid; - } - } - - function datasetcdAction() - { - $add=(int)$this->_getParam('add'); - $edit=(int)$this->_getParam('edit'); - $delete=(int)$this->_getParam('delete'); - set_time_limit(0); - 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; - } - - /* - * - * 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'); - - - if ($delete) - { - $sql="delete from metadata where uuid=?"; - try { - $this->db->query("delete from mdstatus where uuid=?",array($delete)); - $this->db->query("delete from mdauthor where uuid=?",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 normalmetadata 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 metadata 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 metadata 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 '

      数据目录成功导入!

      '; - } else if ($row['host']=='ftp.sanjiangyuan.org.cn') - { - file_get_contents("http://ftp.sanjiangyuan.org.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); - echo '

      数据目录成功导入!

      '; - } else { - echo '

      数据目录未导入!

      '; - } - } - - }//datasetAction存档管理 - - /* - * commentAction() - * 反馈管理 - * ALTER TABLE comments ADD COLUMN reply integer NOT NULL DEFAULT 0; - */ - function commentAction() - { - $delete=(int)$this->_getParam('delete'); - $uuid = $this->_getParam('uuid'); - $reply = $this->_getParam('reply'); - $replylist = $this->_getParam('replylist'); - $delreply = $this->_getParam('delreply'); - - 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"); - } - - if($reply) - { - - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $body = $this->_getParam('content'); - if(empty($body)) - { - $data = array('error'=>"请输入回复内容"); - $this->jsonexit($data); - return true; - } - - $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { - $user = $auth->getIdentity(); - $uid = $user->id; - $email = $user->email; - } - - $ipaddr = $_SERVER['REMOTE_ADDR']; - - $sql = "INSERT INTO comments (uuid,author,reply,userid,content,email,ip) VALUES (?,?,?,?,?,?,?)"; - $sth = $this->db->prepare($sql); - $rs = $sth->execute(array($uuid,$user->username,$reply,$uid,$body,$email,$ipaddr)); - - if($rs) - { - $sql="select c.author,c.email,c.uuid from comments c where c.id=?"; - $sth=$this->db->prepare($sql); - $sth->execute(array($reply)); - $row=$sth->fetch(); - - $mail=new WestdcMailer($this->view->config->smtp); - $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); - $mailtp=new EmailText($this->db,"comment-admin-reply",array( - 'user' => $row['author'], - 'uuid' => $row['uuid'], - 'email'=> $row['email'] - )); - $mail->setBodyText($mailtp->getBody()); - $mail->setSubject($mailtp->getSubject()); - $mail->addTo($row['email']); - $mail->addCc($this->view->config->service->email); - @$mail->send(); - - $data = array('status'=>1,'msg'=>'回复成功!'); - $this->jsonexit($data); - return true; - }else{ - $data = array('error'=>"回复失败,请重试"); - $this->jsonexit($data); - return true; - } - return true; - } - - if($uuid) - { - $sql = "SELECT c.*,md.title,md.uuid FROM comments c - LEFT JOIN metadata md ON md.uuid=c.uuid - WHERE c.uuid=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($uuid)); - $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; - - $sql = "SELECT title FROM metadata WHERE uuid=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($uuid)); - $row = $sth->fetch(); - - $this->view->title = $row['title']; - - return true; - } - - if($replylist) - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $sql = "SELECT cr.id,cr.content as body,cr.reply,u.username,cr.ts_created FROM comments cr - LEFT JOIN users u ON cr.userid=u.id WHERE cr.reply=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($replylist)); - $rows = $sth->fetchAll(); - - $this->jsonexit($rows); - return true; - - } - - if($delreply) - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $sql = "DELETE FROM comments WHERE id=?"; - $sth = $this->db->prepare($sql); - $rs = $sth->execute(array($delreply)); - - if($rs) - { - $this->jsonexit( - array('deleted'=>1) - ); - return true; - }else{ - $this->jsonexit( - array('error'=> '处理中出现错误,请重新尝试') - ); - return true; - } - - - } - - - $sql = "SELECT cm.*,md.title,(SELECT count(id) as counts FROM comments cms WHERE cms.reply=cm.id AND cms.reply!=0) as reply_count FROM comments cm - LEFT JOIN metadata md ON md.uuid=cm.uuid - WHERE cm.reply=0 - ORDER BY cm.ts_created DESC,cm.id DESC"; - - $sth = $this->db->query($sql); - $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; - - }//comment - - - 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'); - $import=(int)$this->_getParam('import'); - $show = $this->_getParam('show'); - - if ($add) { - $type = $this->_getParam('type'); - if($type == 'dc') - { - $this->_helper->viewRenderer('referenceadd'); - $this->view->type = "dc"; - }else{ - $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,reftype) values(?,?,?)"; - $this->db->query($sql,array(trim($formdata['uuid']),$row['id'],$formdata['reftype'])); - $this->messenger->addMessage('提示信息:您已经成功添加该数据文献。'); - $this->_redirect('/admin/data/reference/show/'.$formdata['uuid']); - }else { - $form->populate($formdata); - } - } else { - if ($uuid) - { - $formdata['uuid']=$uuid; - $form->populate($formdata); - } - } - $this->view->form=$form; - $this->_helper->viewRenderer('referenceadd'); - } - } //添加 - - else if($show){ - $sql = "select mr.id as mdid,mr.refid,r.reference,md.title,md.uuid,mr.place FROM mdref mr - left join metadata md on md.uuid=mr.uuid - left join reference r on r.id=mr.refid - where mr.uuid='$show'; - "; - $rs = $this->db->query($sql); - $rows = $rs->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; - - } //按UUID查看 - - elseif ($edit){ - $form=new ReferenceForm(); - if ($this->_request->isPost()) { - $formdata=$this->_request->getPost(); - if ($form->isValid($formdata)) { - $sql="select id from reference where reference=? order by id desc"; - $rs=$this->db->query($sql,array($formdata['reference'])); - $row = $rs->fetch(); - if ($row['id']!='') - { - //更新文献信息 - $sql="update mdref set refid=?,reftype=? where uuid=? and id=?"; - $td = $this->db->query($sql,array($row['id'],$formdata['reftype'],$formdata['uuid'],$edit)); - $sql="update reference set reference=?,link=? where id=?"; - $this->db->query($sql,array($formdata['reference'],$formdata['link'],$row['id'])); - if($td) - { - $this->messenger->addMessage('提示信息:您已经编辑该数据文献。'); - $this->_redirect('/admin/data/reference/show/'.$formdata['uuid']); - } - }else - { - $sql = "INSERT INTO reference (reference,link) VALUES ('".$formdata['reference']."','".$formdata['link']."') RETURNING id"; - $sth = $this->db->prepare($sql); - if($sth->execute()) - { - $row = $sth->fetch(PDO::FETCH_ASSOC); - $sql="update mdref set refid=?,reftype=? where uuid=? and id=?"; - $td = $this->db->query($sql,array($row['id'],$formdata['reftype'],$formdata['uuid'],$edit)); - $this->messenger->addMessage('提示信息:您已经编辑该数据文献。'); - $this->_redirect('/admin/data/reference/show/'.$formdata['uuid']); - }else - { - $this->messenger->addMessage('提示信息:文献创建失败,请重试'); - $this->_redirect('/admin/data/reference/edit/'.$edit); - } - } - } else { - $form->populate($formdata); - } - } else { - $sql="select m.uuid,r.reference,r.link,m.reftype from reference r left join mdref m on r.id=m.refid where m.id=?"; - $formdata=$this->db->fetchRow($sql,array($edit)); - $form->populate($formdata); - } - $this->view->form=$form; - $this->_helper->viewRenderer('referenceadd'); - } //编辑相关文献 - - elseif ($delete) { - $sql = "select uuid from mdref where id=$delete"; - $rs = $this->db->query($sql); - $row = $rs->fetch(); - $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/show/'.$row['uuid']); - } //删除相关文献 - - elseif ($import) { - if ($this->_request->isPost()) { - if ($_FILES["ref"]["error"] == UPLOAD_ERR_OK) { - $tmp_name = $_FILES["ref"]["tmp_name"]; - $fp = fopen($tmp_name, "rb"); - $ref=fread($fp, filesize($tmp_name)); - fclose($fp); - $lines=explode("\n",$ref); - foreach($lines as $line) - { - $data=explode(";",$line); - if (count($data)==2) - $link=''; - else - $link=$data[2]; - $link=$this->db->quote($link); - $sql="insert into reference (reference,link) values(?,".$link.")"; - try { - $this->db->exec($this->db->quoteInto($sql,trim($data[1]))); - } catch (Exception $e) {} - $sql="select id from reference where reference=?"; - $row=$this->db->fetchRow($this->db->quoteInto($sql,trim($data[1]))); - $sql="insert into mdref (uuid,refid) values(?,".$row['id'].")"; - try { - $this->db->exec($this->db->quoteInto($sql,trim($data[0]))); - } catch (Exception $e) {} - } - }//end if - } - $this->_helper->viewRenderer('referenceimport'); - } //引用 - - 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{ - $sql="select m.title as mdtitle,m.uuid,mr.id as mdid,mr.refid,mr.place,r.reference - from mdref mr right join metadata m on mr.uuid=m.uuid - left join reference r on mr.refid=r.id - order by m.ts_created desc,mr.place"; - $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.phtml'); - $this->view->paginator=$paginator; - - }//列表 - } - - //文献管理 - public function refAction() - { - $this->view->ac = $ac = $this->_getParam('ac'); - $submit = $this->_getParam('submit'); - $keyword = $this->view->q = trim($this->_getParam('q')); - $order = $this->view->search_order = trim($this->_getParam('order')); - $sort = $this->view->search_sort = trim($this->_getParam('sort')); - $field = $this->view->search_field = $this->_getParam('field'); - - $reference = new Reference(); - - if(!empty($keyword)) - { - $reference->keyword = $keyword; - } - - if(!empty($field)) - { - $reference->field = $field; - } - - if(!empty($order)) - { - $reference->order = $order; - } - - if(!empty($sort)) - { - $reference->sort = $sort; - } - - $this->view->reference = $reference; - $this->view->page = $this->_getParam('page'); - $this->view->pagelimit = 12; - - //文献首页 - if(empty($ac)) - { - $this->view->referenceType = $reference->referenceType(); - view::addPaginator($reference->fetchReferences(),$this, $this->view->pagelimit); - $this->view->years = $reference->countByYear(); - return true; - } - else if ($ac == "water") - { - $this->view->referenceType = $reference->referenceType(); - view::addPaginator($reference->fetchThemeReferences('water'),$this,$this->view->pagelimit); - return true; - } - else if ($ac == "westdc") - { - $this->view->referenceType = $reference->referenceType(); - view::addPaginator($reference->fetchWestdcReferences(),$this,$this->view->pagelimit); - return true; - } - else if ($ac == "todo") - { - $this->view->referenceType = $reference->referenceType(); - view::addPaginator($reference->fetchTodoReferences(),$this,$this->view->pagelimit); - return true; - } - - unset($this->view->reference); - unset($this->view->page); - unset($this->view->pagelimit); - - //添加 - if($ac == "add") - { - $this->_helper->viewRenderer('ref-add'); - $id = $this->_getParam('id'); - $attid = $this->_getParam('attid'); - - if(!empty($submit)) - { - $this->view->data = $reference->getReferenceParam(); - $attid = $this->view->data['attid']; - - if(empty($id) || !is_numeric($id)) - { - $status = $reference->reference(); - }else{ - $status = $reference->reference($id); - } - - if($status !== true) - { - $this->view->error = view::Error($status); - }else{ - if(!empty($id)) - { - $msg = "文献修改成功!"; - view::Post($this,$msg,-2); - return true; - }else{ - $msg = "文献添加成功!"; - view::Post($this,$msg,"/admin/data/ref/ac/add"); - return true; - } - } - }else{ - $this->view->data = array(); - if(!empty($id) && is_numeric($id)) - { - $this->view->data = $reference->getOneReferenceData($id); - } - } - - if(!empty($attid)) - { - $files = new Files(); - $attfile = $files->getOne($attid); - $this->view->data['attid'] = $attid; - $this->view->data['file'] = $attfile; - } - - return true; - } - - //上传pdf - if($ac == "pdfupload") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $autoread = false; - if($this->_getParam('multi')) - { - $autoread = true; - } - $statu = $reference->uploadReferencePdf($_FILES['Filedata'],$autoread); - $this->jsonexit($statu); - return true; - } - - //删除已上传的文件 - if($ac == "delete") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $statu = $reference->deleteReferenceAttchment($this->_getParam('attid')); - $this->jsonexit($statu); - return true; - } - - //批量上传 - if($ac == "multiupload") - { - $this->_helper->viewRenderer('ref-multiupload'); - return true; - } - - //文件管理 - if($ac == "files") - { - $this->_helper->viewRenderer('ref-files'); - view::addPaginator($reference->getReferenceFiles(),$this,10); - return true; - } - - //删除文献 - if($ac == "deleteref") - { - $refid = $this->_getParam('id'); - if($reference->deleteReference($refid)) - { - view::Post($this,"删除成功!",-1); - }else{ - view::Post($this,"删除失败!",-1); - } - return true; - } - - //相关数据 - if($ac == "data") - { - $refid = $this->view->refid = $this->_getParam('id'); - if(view::isXmlHttpRequest($this)){ - $this->jsonexit($reference->getDataByReference($refid)); - return true; - }else{ - $this->_helper->viewRenderer('ref-metadatas'); - $this->view->referenceType = $reference->referenceType(); - view::addPaginator($reference->getDataByReference($refid),$this,10); - return true; - } - } - - //添加数据文献 - if($ac == "mdref" && view::isXmlHttpRequest($this)) - { - $mdrefid = $this->_getParam('id'); - $status = $reference->makeMdref($mdrefid); - if($status !== true) - { - $this->jsonexit(array('error'=>$status)); - }else{ - $this->jsonexit(array('success' => 1)); - } - return true; - } - - //移除数据文献 - if($ac == "delmdref") - { - $mdrefid = $this->_getParam('id'); - $status = $reference->delMdref($mdrefid); - if($status === true) - { - view::Post($this,"移除成功",-1); - }else{ - view::Post($this,$status,-1); - } - return true; - } - - //ris - if($ac == "ris") - { - $this->_helper->viewRenderer('ref-ris'); - $submit = $this->_getParam('submit'); - - if(!empty($submit)) - { - $ris = new \Reference\Ris(); - $this->view->data = $ris->loadout(); - try{ - $ris->pushToDataTable($this->view->data); - }catch(Exception $e) - { - view::Dump($e->getMessage(),false); - } - } - } - - //ris更新单篇 - if($ac == "singleris") - { - $this->_helper->viewRenderer('ref-singleris'); - $id = (int)$this->_getParam('id'); - $this->view->ristext = $this->_getParam('ristext'); - - if($id < 1) - { - view::Post($this,"参数错误!",-1); - return true; - } - - $this->view->referenceData = $reference->getOneReferenceData($id); - - if(!empty($submit)) - { - $ris = new Ris(); - $data = $ris->loadout(); - - if(count($data) < 1) - { - view::Post($this,"输入的RIS信息有误".'查看详细',-1); - return true; - } - - if($ris->updateWithRis($id,$data[0]) === true) - { - view::Post($this,"编辑成功!".'查看详细',-2); - return true; - }else{ - view::Post($this,"编辑失败!".'查看详细',-1); - return true; - } - } - - return true; - }//ris单篇更新 - - //ris导出 - if($ac == "risoutput") - { - $this->_helper->viewRenderer('ref-risoutput'); - $this->view->years = $reference->countByYear(); - - if(!empty($submit)) - { - $mode = $this->_getParam('mode'); - - $risOutput = new RisOutput(); - $preData = $risOutput->preRead($mode); - - $risData = $risOutput->processArrayDataToRisData($preData); - - $risText = $risOutput->output($risData); - - echo "
      ";
      -				echo $risText;
      -				echo "
      "; - } - }//ris output - - if($ac == "ristest") - { - $this->_helper->viewRenderer('ref-ris'); - $submit = $this->_getParam('submit'); - - if(!empty($submit)) - { - $ris = new \Reference\Ris(); - view::Dump($ris->processRis(NULL,$this->_getParam('ristext')),false); - } - } - - - }//文献管理 refAction() - - /* - * 删除元数据,删除前有确认 - */ - 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('/data'); - } 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='已成功处理数据目录信息!'; - } - }//datafileimportAction - - - function sourceAction() - { - $do = $this->_request->getParam('do'); - $uuid = $this->_request->getParam('uuid'); - $id = $this->_request->getParam('id'); - $q = $this->_request->getParam('q'); - $search = $this->_request->getParam('search'); - - if ($do == 'add') { - - $redirect = "/admin/data/source/"; - - if(!empty($_POST['submit'])) - { - try{ - $title = $this->_request->getParam('title'); - $uuid = $this->_request->getParam('uuid'); - $code = $this->_request->getParam('code'); - $description = $this->_request->getParam('description'); - $has_pages = $this->_request->getParam('has_pages'); - $has_agreement = $this->_request->getParam('has_agreement'); - - $data = array( - 'title' => $title, - 'uuid' => $uuid, - 'code' => $code, - 'description' => $description, - 'has_pages' => $has_pages, - 'has_agreement' => $has_agreement - ); - - if($this->db->insert('source',$data)) - { - $this->messenger->addMessage('添加来源信息成功'); - $this->_redirect($redirect); - } - }catch(Exception $e){ - $this->messenger->addMessage('添加来源信息失败:'.$e->getMessage()); - $this->_redirect('/admin/data/source/do/add'); - } - - } - - $this->_helper->viewRenderer('sourceadd'); - }// 添加项目来源 - - else if($do == 'edit' && !empty($id)) - { - - if(!empty($_POST['submit'])) - { - try{ - $title = $this->_request->getParam('title'); - $uuid = $this->_request->getParam('uuid'); - $code = $this->_request->getParam('code'); - $description = $this->_request->getParam('description'); - $has_pages = $this->_request->getParam('has_pages'); - $has_agreement = $this->_request->getParam('has_agreement'); - - $sql = "update source set title='$title',uuid='$uuid',code='$code',description='$description',has_pages='$has_pages',has_agreement='$has_agreement' where id='$id'"; - - if($this->db->exec($sql)) - { - $this->messenger->addMessage('修改来源信息成功'); - $this->_redirect("/admin/data/source/do/edit/id/$id"); - } - }catch(Exception $e){ - $this->messenger->addMessage('修改来源信息失败:'.$e->getMessage()); - $this->_redirect("/admin/data/source/do/edit/id/$id"); - } - - } - - $sql = "select * from source where id='$id'"; - $rs = $this->db->query($sql); - $row = $rs->fetch(); - - $this->view->info = $row; - - $this->_helper->viewRenderer('sourceadd'); - - }// 编辑单条信息 - - else if($do == 'datasource' && !empty($uuid)) - { - $redirect = "/admin/data/source/do/datasource/uuid/$uuid"; - - $this->view->uuid = $uuid; - $sql = "select md.title,ds.id,ds.sourceid,s.title as stitle,s.code from metadata md - left join datasource ds on ds.uuid=md.uuid - left join source s on s.id=ds.sourceid - where md.uuid='$uuid'"; - $rs = $this->db->query($sql); - $row = $rs->fetch(); - - $this->view->info = $row; - - if(!empty($_POST['submit'])) - { - $sourceid = $this->_request->getParam('sourceid'); - if(empty($sourceid)) - { - $this->messenger->addMessage('请选择项目来源'); - $this->_redirect($redirect); - } - - $sql=""; - if(empty($row['id'])) - { - $sql = "insert into datasource (uuid,sourceid) values ('$uuid','$sourceid')"; - }else - { - $sql = "update datasource set uuid='$uuid',sourceid='$sourceid' where id='{$row['id']}'"; - } - try{ - if($this->db->exec($sql)) - { - $this->messenger->addMessage('修改项目来源成功'); - $this->_redirect($redirect); - } - else - { - $this->messenger->addMessage('修改项目来源失败'); - $this->_redirect($redirect); - } - }catch (Exception $e){ - $this->messenger->addMessage('修改项目来源失败:'.$e->getMessage()); - $this->_redirect($redirect); - } - - } - - - $wheresql = array(); - - if(!empty($q) && !empty($search)) - { - $this->view->q = $q; - $wheresql[] = " title like '%$q%' "; - } - - if(count($wheresql>0))$wheresql = join(' and ',$wheresql); - else $wheresql=''; - - if($wheresql!='') - { - $wheresql = 'where '.$wheresql; - } - - $sql = "select * from source $wheresql order by id desc"; - $rs = $this->db->query($sql); - $rows = $rs->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; - - $this->_helper->viewRenderer('sourceselect'); - }// 为元数据选择项目来源 - - else if($do == 'del' && !empty($id)) - { - $redirect = "/admin/data/source/"; - $sql = "delete from source where id='$id'"; - try{ - if($this->db->exec($sql)) - { - $this->messenger->addMessage('删除成功'); - $this->_redirect($redirect); - }else{ - $this->messenger->addMessage('删除失败,可能该数据已不存在'); - $this->_redirect($redirect); - } - }catch (Exception $e){ - $this->messenger->addMessage('删除失败:'.$e->getMessage()); - $this->_redirect($redirect); - } - }// 删除项目来源 - - else if($do == 'fetch' && !empty($id)) - { - - $wheresql = array(); - - $wheresql[] = " ds.sourceid='$id' "; - - if(!empty($q) && !empty($search)) - { - $this->view->q = $q; - $wheresql[] = " title like '%$q%' "; - } - - if(count($wheresql>0))$wheresql = join(' and ',$wheresql); - else $wheresql=''; - - if($wheresql!='') - { - $wheresql = 'where '.$wheresql; - } - - $sql = "select md.title,md.uuid,ds.id,ds.sourceid,s.title as stitle,s.code from metadata md - left join datasource ds on ds.uuid=md.uuid - left join source s on s.id=ds.sourceid - $wheresql - order by id desc"; - $rs = $this->db->query($sql); - $rows = $rs->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; - - $this->_helper->viewRenderer('sourcefetchone'); - - }//查看某项目来源中的所有元数据 - - else if($do == 'delsource' && !empty($id)) - { - $redirect = "/admin/data/source/do/datasource/uuid/$uuid"; - - $sql = "delete from datasource where id='$id'"; - - try{ - if($this->db->exec($sql)) - { - $this->messenger->addMessage('删除成功'); - $this->_redirect($redirect); - }else{ - $this->messenger->addMessage('删除失败,可能该数据已不存在'); - $this->_redirect($redirect); - } - }catch (Exception $e){ - $this->messenger->addMessage('删除失败:'.$e->getMessage()); - $this->_redirect($redirect); - } - - - }// 清除元数据来源记录 - elseif ($do=='sync') { //同步数据来源到metadata表 - $redirect = "/admin/data/source/"; - $sql = "update metadata m set source=s.uuid from source s right join datasource d on s.id=d.sourceid where m.uuid=d.uuid"; - if($this->db->exec($sql)) - { - $this->messenger->addMessage('成功同步数据来源'); - $this->_redirect($redirect); - }else{ - $this->messenger->addMessage('同步数据来源失败'); - $this->_redirect($redirect); - } - } - - else - { - $wheresql = array(); - - if(!empty($q) && !empty($search)) - { - $this->view->q = $q; - $wheresql[] = " title like '%$q%' "; - } - - if(count($wheresql>0))$wheresql = join(' and ',$wheresql); - else $wheresql=''; - - if($wheresql!='') - { - $wheresql = 'where '.$wheresql; - } - - $sql = "select * from source $wheresql order by id desc"; - $rs = $this->db->query($sql); - $rows = $rs->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; - }// 项目来源管理 - - - }//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'); - $uuid = $this->_request->getParam('uuid'); - $mdtitle = $this->_request->getParam('mdtitle'); - $mdattdel = $this->_request->getParam('mdattdel'); - $attupdate = $this->_getParam('attupdate'); - - if(!empty($uuid)&&!empty($mdtitle)) - { - $this->view->uuid= $uuid; - $this->view->mdtitle=$mdtitle; - } - - if($add) - { - $this->_helper->viewRenderer('attachmentsadd'); - if(!empty($uuid)) - { - $this->view->uuid = $uuid; - } - }//附件添加 - - elseif($attupdate) - { - $submit = $this->_getParam('submit'); - if(!empty($submit)) - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $id = $this->_getParam('attupdate'); - - $files=new Files(); - $msg = $files -> upload($_FILES['Filedata'],empty($uuid)?'file/':'md/',true); - - if(empty($msg['error'])) - { - $msg['error']=""; - $filename = $msg['db_path']; - $filesize = $msg['file_size']; - $filedesc = $this->_request->getParam('filedesc'); - $filetype = 'md'; - $realname = $msg['realname']; - - - $sql = "UPDATE attachments SET filename=?,filetype=?,filesize=?,realname=? WHERE id=?"; - $sth = $this->db->prepare($sql); - $ds = $sth->execute(array($filename,$filetype,$filesize,$realname,$id)); - - if($ds) - { - $msg['html'] = $realname.'['. round($filesize/1024,2) .' kb]'; - $msg['ok']= 1; - echo Zend_Json::encode($msg); - exit(); - }else{ - @unlink($filename); - $data = array("error"=>'附件上传失败:写入附件表出错'); - $this->jsonexit($data); - return true; - } - }else{ - @unlink($filename); - $data = array("error"=>'附件上传失败:'.$msg['error']); - $this->jsonexit($data); - return true; - } - - - $data = array("error"=>"处理中出现错误".$id); - $this->jsonexit($data); - return true; - }else{ - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer('attachments-update'); - $id = $this->_getParam('attupdate'); - $this->view->id = $id; - } - - }//附件文件更新 - - else if($mdattdel) - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - - $sql = "delete from mdattach where uuid=? AND id=?"; - $sth = $this->db->prepare($sql); - $ds = $sth->execute(array($uuid,$mdattdel)); - if($ds) - { - $data = array("status"=>1); //操作状态代码 : 1=>成功 2=>失败 - $this->jsonexit($data); - return true; - }else{ - $data = array("error"=>"处理中出现错误"); - $this->jsonexit($data); - return true; - } - } - - else if($delete) - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - - //需要删除文件,通过Zend_Registry::get('upload')获得上传文件的根目录 - - $basepath = $this->view->config->upload; - - //从数据库获取文件路径 - - $info = $this->getFileinfo($delete); - - $filepath = $basepath.$info['filename']; - - $sql = "SELECT * FROM mdattach WHERE id=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($delete)); - $rows = $sth->fetchAll(); - - if(count($rows)>0) - { - $data = array("error"=>'删除失败!该文件有元数据附件信息,不能直接删除',"status"=>0); - $this->jsonexit($data); - return true; - } - - $sql = "SELECT * FROM mdreviewattach WHERE attachid=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($delete)); - $rows = $sth->fetchAll(); - - if(count($rows)>0) - { - $data = array("error"=>'删除失败!该文件有对应评审附件信息,不能直接删除',"status"=>0); - $this->jsonexit($data); - return true; - } - - $sql = "SELECT link FROM reference WHERE link!=''"; - $sth = $this->db->prepare($sql); - $sth->execute(); - $rows = $sth->fetchAll(); - - $ids = array(); - foreach($rows as $k=>$v) - { - if(preg_match("/service/i",$v['link'])) - { - $ids[] = str_replace("/service/attach/id/","",$v['link']); - } - unset($rows[$k]); - } - unset($rows); - - if(in_array($delete,$ids)) - { - $data = array("error"=>'删除失败!该文件有对应文献附件信息,不能直接删除',"status"=>0); - $this->jsonexit($data); - return true; - } - - if(unlink($filepath)) - { - $sql = "delete from attachments where id='$delete'"; - if($this->db->exec($sql)>0) - { - $data = array("status"=>1); - $this->jsonexit($data); - return true; - } - } - else - { - $sql = "delete from attachments where id='$delete'"; - if($this->db->exec($sql)>0) - { - $data = array("error"=>'文件删除失败,仅删除数据库记录,请手动删除文件:'.$info['filename'],"status"=>0); - $this->jsonexit($data); - return true; - } - } - - }//删除 - - 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 if ($down>0) - { - - $sql = "select * from attachments where id='$down'"; - - $re = $this->db->query($sql); - - $row = $re->fetch(); - - $file = new files(); - - $fullPath = $this->view->config->upload.$row['filename']; - - - // Parse Info / Get Extension - $fsize = filesize($fullPath); - $path_parts = pathinfo($fullPath); - $ext = strtolower($path_parts["extension"]); - - // Determine Content Type - switch ($ext) { - case "pdf": $ctype="application/pdf"; break; - case "exe": $ctype="application/octet-stream"; break; - case "zip": $ctype="application/zip"; break; - case "doc": $ctype="application/msword"; break; - case "xls": $ctype="application/vnd.ms-excel"; break; - case "ppt": $ctype="application/vnd.ms-powerpoint"; break; - case "gif": $ctype="image/gif"; break; - case "png": $ctype="image/png"; break; - case "jpeg": - case "jpg": $ctype="image/jpg"; break; - default: $ctype="application/force-download"; - } - - $content=file_get_contents($fullPath); - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $this->getResponse()->setHeader('Content-Type', 'application/octet-stream') - ->setHeader('Content-Disposition','attachment; filename="'.basename($fullPath).'"') - ->setHeader('Content-Length', $fsize) - ->setHeader('Content-Type','application/force-download') - ->setHeader('Content-Type','application/download') - ->setHeader('Content-Type',$ctype) - ->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); - - //$sql = "update attachments set downtimes=downtimes+1 where id='$down'"; - //$this->db->exec($sql); - - }//附件下载 - - else - { - - $sql="select * from attachments order by id desc"; - $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 附件 - - function uploadAction(){ - $this->_helper->layout()->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $uuid = $this->_getParam('uuid'); - - try{ - $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { - $user = $auth->getIdentity(); - $userid = $user->id; - } - - if(empty($userid)||!is_numeric($userid)){ - $msg['error'] = "请先登录"; - echo Zend_Json::encode($msg); - exit(); - } - - if($user->usertype!='administrator') - { - $msg['error'] = "您无权使用此功能"; - echo Zend_Json::encode($msg); - exit(); - } - - $files=new Files(); - $msg = $files -> upload($_FILES['Filedata'],empty($uuid)?'file/':'md/',true); - - if(empty($msg['error'])) - { - $msg['error']=""; - $filename = $msg['db_path']; - $filesize = $msg['file_size']; - $filedesc = $this->_request->getParam('filedesc'); - $filetype = 'md'; - $realname = $msg['realname']; - - - $sql = "insert into attachments (filename,filetype,filedesc,userid,filesize,realname) values ('$filename','$filetype','$filedesc','$userid','$filesize','$realname') RETURNING id"; - $sth = $this->db->prepare($sql); - $sth->execute(); - $att = $sth->fetch(PDO::FETCH_ASSOC); - $msg['attid'] = $attid = $att['id']; - - $sql = "insert into mdattach (uuid,id) values ('$uuid','$attid')"; - if(empty($uuid) || $this->db->exec($sql)) - { - $msg['html'] = $realname.'['. round($filesize/1024,2) .' kb]
      '; - echo Zend_Json::encode($msg); - exit(); - }else{ - $msg['error'] = '附件上传失败:写入附件表出错'; - @unlink($filename); - echo Zend_Json::encode($msg); - exit(); - } - - - }else{ - $msg['error'] = '附件上传失败:'.$msg['error']; - @unlink($filename); - echo Zend_Json::encode($msg); - exit(); - } - - }catch(Exception $e){ - $msg['error'] = "错误:".$e->getMessage(); - echo Zend_Json::encode($msg); - exit(); - } - }// uploadAction ajax上传附件 - - function getattsAction(){ - - $this->_helper->layout()->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $uuid = $this->_request->getParam('uuid'); - - if($uuid!='') - { - $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { - $user = $auth->getIdentity(); - $userid = $user->id; - $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' - ORDER BY a.ts_created ASC"; - $rs = $this->db->query($sql); - $atts = $rs->fetchAll(); - - echo Zend_Json::encode($atts); - exit(); - }else - { - exit(); - } - }else{ - exit(); - } - //不输出错误 - }//获取附件 - - - /* - versionAction 版本管理 - */ - - public function versionAction(){ - - $ac = $this->_request->getParam('ac'); - $uuid = $this->_request->getParam('uuid'); - set_time_limit(0); - - $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,g.id as gid FROM mdversion v - LEFT JOIN metadata md ON md.uuid=v.uuid - left join users u on v.userid=u.id - left join geonetworkmetadata g on md.uuid=g.uuid - 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,u.id 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'].'/service/doc/uuid/'.$row['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/'.$row['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" || $ac=="diff1") - { - $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(); - if ($ac=='diff') - { - $sql = "SELECT v.* FROM mdversion v - WHERE v.uuid=? and v.ts_created<=(select ts_created from mdversion where id=?) - ORDER BY v.ts_created DESC - LIMIT ?"; - $sth = $this->db->prepare($sql); - $sth -> execute(array($row['uuid'],$id,2)); - } else { - $sql = "SELECT v.* FROM mdversion v - WHERE v.uuid=? and (v.id=? or (v.ts_created<(select ts_created from mdversion where id=?) and changelog is not null)) - ORDER BY v.ts_created DESC - LIMIT ?"; - $sth = $this->db->prepare($sql); - $sth -> execute(array($row['uuid'],$id,$id,2)); - } - - $rows = $sth->fetchAll(); - - if(count($rows)<2) - { - $this->view->error = "对比失败:之前没有版本可以对比"; - return true; - } - - $this->view->info = $row; - $this->view->data = $rows; - - } - - - }//versionAction 版本控制 - - - /* - * authorAction() 数据作者 - * - * param string $ac //动作 - =add 添加 - =edit 编辑 - =update 更新 - =del 删除 - =list 列出所有数据作者 - - * param string $uuid //UUID - * - * return view|application-json - */ - public function authorAction(){ - - $ac = $this->_getParam('ac'); - $uuid = $this->_getParam('uuid'); - - if(empty($ac) && empty($uuid)) - { - - $keywords = $this->_request->getParam('q'); - if(!empty($keywords)) - $this->view->q = $keywords; - - $sql = "select md.id,md.title,md.uuid,count(a.userid) as c from metadata md - right JOIN mdauthor a ON md.uuid=a.uuid - "; - - if(!empty($keywords)) - { - $search=new SimpleSearch($keywords); - $where=$search->sql_expr(array("md.title")); - $sql.=' and ('.$where.")"; - } - - $sql .= "GROUP by md.id,md.title,md.uuid,md.ts_created - ORDER BY md.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 == 'add') - { - - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $username = $this->_getParam('username'); - $uuid = $this->_getParam('uuid'); - - if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid)) - { - $data = array("error"=>"uuid参数错误"); - $this->jsonexit($data); - return true; - } - - if(empty($username)) - { - $data = array("error"=>'请输入要添加为该数据作者的用户名'); - $this->jsonexit($data); - return true; - } - - $sql = "SELECT * FROM users WHERE username=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($username)); - $row = $sth->fetch(); - - if(empty($row['id']) || !isset($row['id'])) - { - $data = array("error"=>'您输入的用户名无任何对应用户'); - $this->jsonexit($data); - return true; - } - - $uid = $row['id']; - - $sql = "SELECT * FROM mdauthor WHERE userid=? AND uuid=?"; - $sth = $this->db->prepare($sql); - $sth->execute(array($row['id'],$uuid)); - $row = $sth->fetch(); - - if(!empty($row['id']) && $row['status']==1) - { - $data = array("error"=>'该用户已经是此数据的作者'); - $this->jsonexit($data); - return true; - } - - if(!empty($row['id']) && in_array($row['status'],array(0,-1)) ) - { - $sql = "UPDATE mdauthor SET status=1 WHERE uuid=? AND userid=?"; - $sth = $this->db->prepare($sql); - $ds = $sth->execute(array($uuid,$uid)); - if($ds) - { - $data = array("msg"=>'该用户已被提升为数据作者','added'=>1); - $this->jsonexit($data); - return true; - }else{ - $data = array("error"=>'处理中出现错误'); - $this->jsonexit($data); - return true; - } - } - - if(empty($row['id'])) - { - $sql = "INSERT INTO mdauthor (uuid,userid,status) VALUES (?,?,?)"; - $sth = $this->db->prepare($sql); - $ds = $sth->execute(array($uuid,$uid,1)); - if($ds) - { - $data = array("msg"=>'该用户已被添加为数据作者','added'=>1); - $this->jsonexit($data); - return true; - }else{ - $data = array("error"=>"处理中出现错误"); - $this->jsonexit($data); - return true; - } - } - - - $data = array("error"=>"处理中出现错误"); - $this->jsonexit($data); - return true; - - }//ajax 添加作者 - - - else if(($ac == "edit" || $ac=="") && !empty($uuid)) - { - - $window = $this->_getParam('window'); - - if($window == "iframe") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer('author-edit-iframe'); - }else{ - $this->_helper->viewRenderer('author-edit'); - } - - $sql = "SELECT a.*,md.title,u.realname,u.username FROM mdauthor a - LEFT JOIN metadata md ON a.uuid=md.uuid - LEFT JOIN users u ON a.userid=u.id - WHERE md.uuid=? - ORDER BY a.id DESC - "; - - $sth = $this->db->prepare($sql); - $sth->execute(array($uuid)); - $rows = $sth->fetchAll(); - - $this->view->authors = $rows; - - }// 作者管理弹窗 - - else if($ac == "del") - { - - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $id = $this->_getParam('id'); - - $sql = "DELETE FROM mdauthor WHERE id=?"; - $sth = $this->db->prepare($sql); - $ds = $sth->execute(array($id)); - if($ds) - { - $data = array("deleted"=>$id); - $this->jsonexit($data); - return true; - }else{ - $data = array("error"=>"处理中出现错误"); - $this->jsonexit($data); - return true; - } - - - }//移除作者 - - else if($ac == 'update') - { - - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $id = $this->_getParam('id'); - - $sql = "UPDATE mdauthor SET status=1 WHERE id=?"; - $sth = $this->db->prepare($sql); - $ds = $sth->execute(array($id)); - if($ds) - { - $data = array("updated"=>$id,'msg'=>'认证成功!'); - $this->jsonexit($data); - return true; - }else{ - $data = array("error"=>"处理中出现错误"); - $this->jsonexit($data); - return true; - } - - - }//认证作者 - - else if($ac =="list") - { - $this->_helper->viewRenderer('author-list'); - - $sql = "SELECT u.id,u.realname,u.email,count(a.id) as d FROM mdauthor a - LEFT JOIN users u ON a.userid=u.id - WHERE a.status>0 - GROUP BY u.id,u.realname,u.email - ORDER BY u.id 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 == "userdatas") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $id = $this->_getParam('id'); - - $sql = "SELECT md.title,md.uuid FROM mdauthor a - LEFT JOIN metadata md ON a.uuid=md.uuid - WHERE a.userid=? AND a.status>0 - ORDER BY a.ts_created"; - $sth = $this->db->prepare($sql); - $sth->execute(array($id)); - $rows = $sth->fetchAll(); - - $data = array("datas"=>$rows); - $this->jsonexit($data); - return true; - - }//用户数据 - - else if($ac == "datas") - { - $this->_helper->viewRenderer('author-datas'); - - $keywords = $this->_request->getParam('q'); - if(!empty($keywords)) - $this->view->q = $keywords; - - $sql = "select md.id,md.title,md.uuid,count(a.userid) as c from metadata md - left JOIN mdauthor a ON md.uuid=a.uuid - "; - - if(!empty($keywords)) - { - $search=new SimpleSearch($keywords); - $where=$search->sql_expr(array("md.title")); - $sql.=' WHERE '.$where; - } - - $sql .= "GROUP by md.id,md.title,md.uuid,md.ts_created - ORDER BY md.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; - - } - - }//authorAction() 数据作者管理 - - - //newdataAction() 新建元数据 - public 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(); - if($auth->hasIdentity()) - { - $user = $auth->getIdentity(); - $u_id = $user->id; - } - - //在geonetwork中查看单条数据 - if (!empty($id) && empty($ac)) - { - $this->view->url='metadata.show?id='.$id; - $this->_helper->viewRenderer('newdata-view'); - } - //查看所有的未提交数据列表 - else if((empty($ac) && empty($uuid))|| $ac=='list') - { - $sql = "SELECT (regexp_matches(gn.data,'(.*)'))[1] as title,gn.id,gn.uuid,u.username,u.realname FROM geonetworkmetadata gn left join users u on gn.owner=u.id - WHERE gn.uuid not in (select uuid from metadata) - order by gn.id 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=="import") - { - $this->_helper->viewRenderer('newdata-import'); - } - //从模板新建元数据 - else if($ac=="add-by-template") - { - $keywords = $this->_request->getParam('q'); - $sql="select id,(regexp_matches(data,'(.*)'))[1] as title,(owner-$u_id) as isowner from metadata where istemplate='y' and schemaid='iso19115'"; - if(!empty($keywords)) - { - $this->view->q = $keywords; - $search=new Search($keywords); - $where=$search->sql_expr(array("data")); - $sql.=' and '.$where; - } - $sql.=" order by changedate desc"; - $sth = $this->wdb->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('newdata-add'); - } - - else if($ac=="add-by-data") - { - $keywords = $this->_request->getParam('q'); - $sql = "SELECT md.title,md.uuid,md.description,gn.id as gid FROM normalmetadata md - left join geonetworkmetadata gn on md.uuid=gn.uuid - WHERE gn.id is not null"; - if(!empty($keywords)) - { - $this->view->q = $keywords; - $search=new Search($keywords); - $where=$search->sql_expr(array("md.title","md.description")); - $sql.=' and '.$where; - } - $sql.=" order by md.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(10); - $paginator->setView($this->view); - Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); - $this->view->paginator=$paginator; - $this->_helper->viewRenderer('newdata-add-bydata'); - } - //元数据格式检查 - else if ($ac=="validate") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $data = ""; - $id = $this->_request->getParam('id'); - $sql="select uuid,data from geonetworkmetadata where id=?"; - $sth=$this->db->prepare($sql); - $sth->execute(array($id)); - $row=$sth->fetch(); - - $iso=new ISO19115(); - @$iso->loadXML($row['data']); - if ($iso->validate()) - { - $data=array("error"=>"元数据中发现错误。
      ".implode("
      ",$iso->error)); - $this->jsonexit($data); - return true; - } else { - $data=array("error"=>"元数据中没有发现错误。
      "); - $this->jsonexit($data); - return true; - } - } - //提交数据 - else if($ac=="commit") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $data = ""; - $id = $this->_request->getParam('id'); - try{ - 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. 权限认定:当前用户必须和其owner相同 - // 数据应当没有评审状态,没有作者信息 - $sql="select uuid,data from geonetworkmetadata where id=?"; - $sth=$this->db->prepare($sql); - $sth->execute(array($id)); - $row=$sth->fetch(); - if (empty($row)) - { - $data = array("error"=>'无权限修改数据'); - $this->jsonexit($data); - return true; - } - - // 保存数据作者信息 - - // 2. 保存变化记录 save changelog & userid for the latest version - $sql = "UPDATE mdversion SET changelog=?,userid=? WHERE id in (select v.id from mdversion v left join geonetworkmetadata g on v.uuid=g.uuid where g.id=? order by v.ts_created desc limit 1)"; - $this->db->query($sql,array($changelog,$u_id,$id)); - - // 3. 保存数据评审状态 - //导入元数据 - $iso=new ISO19115(); - @$iso->saveDB($this->db,$row['data']); - //进入评审库 - $sql="insert into mdstatus (uuid,status,userid) select uuid,0,? from geonetworkmetadata 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(); - - $data = array("commited"=>1,"error"=>'该版本已经成功提交,请等待数据中心进一步处理!'); - $this->jsonexit($data); - return true; - }catch(Exception $e) { - $sql="delete from mdstatus where uuid in (select uuid from geonetworkmetadata where id=?)"; - $this->db->query($sql,array($id)); - $msg = "提交失败,请确认权限后重试"; - if($this->debug>0) - {$msg .= $e->getMessage();} - $data = array("error"=>$msg); - $this->jsonexit($data); - return true; - } - } - - }// newdataAction() 新建元数据 - - /* - * projectsAction() 数据汇交计划 - * - * - * - * - */ - function projectAction() - { - include_once("Heihe.php"); - $heihe = new Heihe($this->db); - - $this->view->input_NameDefaultVal = "专家姓名"; - $this->view->input_EmailDefaultVal = "专家email"; - - $projectTable = $heihe->tbl_heiheproject; - - $ac = $this->_getParam('ac'); - - if(empty($ac) || $ac == "index") - { - $this->_helper->viewRenderer('project'); - - //Search Link - $this->view->searchLink = "/admin/heihe/project/ac/index/"; - - $q = $this->_getParam('q'); - - $wheresql = array(); - - if(!empty($q)) - { - $wheresql[] = " (title LIKE '%$q%' OR - code LIKE '%$q%' OR - name LIKE '%$q%' OR - email LIKE '%$q%')"; - $this->view->searchKeyword = $q; - } - - if(count($wheresql)>0) - { - $wheresql = join(" AND ",$wheresql); - }else{ - $wheresql = ""; - } - - if(!empty($wheresql)) - { - $wheresql = " WHERE ".$wheresql; - } - - $sql = "SELECT * FROM $projectTable $wheresql - ORDER BY id ASC"; - $sth = $this->db->query($sql); - $rows = $sth->fetchAll(); - - foreach ($rows as $k=>$v) - { - $rows[$k]['status_alias'] = $heihe->getStatus($v['status']); - } - - $this->view->Count = count($rows); - - $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; - - $this->view->project_status = $heihe->project_status; - - return true; - }//ac == index - - //邀请专家 - if($ac == "invite") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $pid = $this->_getParam('id'); - $name = $this->_getParam('name'); - $email = $this->_getParam('email'); - - if(!is_numeric($pid)) - { - $this->jsonexit(array("error"=>"参数错误")); - return true; - } - - if(empty($name) || $name == $this->view->input_NameDefaultVal) - { - $this->jsonexit(array("error"=>"请输入专家姓名")); - return true; - } - - if(empty($email) || $email == $this->view->input_EmailDefaultVal) - { - $this->jsonexit(array("error"=>"请输入专家Email")); - return true; - } - - $code = $heihe->makeValidation($email); - - $expert_data = array( - "name"=>$name, //专家姓名 - "email"=>$email, //专家email - "created"=>date("Y-m-d H:i:s",time()), //邀请时间 - "validation"=>$code, //验证码 - ); - - $rs = $heihe->expertAdd($pid,$expert_data); - - if($rs > 0) - { - $this->sendMailToExpert($pid,$name,$email,$code);// 最后再加入一个非0的数字型参数即可使用调试邮箱发送 - $this->jsonexit(array("msg"=>"专家邀请成功!","invited"=>1)); - return true; - }else if($rs==-1){ - $this->jsonexit(array("error"=>"该专家已经邀请过")); - return true; - }else{ - $this->jsonexit(array("error"=>"邀请失败,请重试")); - return true; - } - - return true; - }// 邀请专家 - - if($ac == "showexpert") - { - - $this->_helper->layout->setLayout('layout-iframe'); - $this->_helper->viewRenderer('project-showexpert'); - - $pid = $this->_getParam('id'); - - if(empty($pid) || !is_numeric($pid)) - { - $this->view->error = "参数错误"; - return true; - } - - $this->view->pid = $pid; - - $experts = $heihe->expertRead($pid); - - if(!is_array($experts)) - { - $this->view->error = "此项目还没有邀请专家"; - return true; - } - - foreach($experts as $k=>$v) - { - $experts[$k]['url'] = $heihe->makeInviteLink($pid,$v['validation']); - } - - $this->view->experts = $experts; - - return true; - }//ac == showexpert 查看跟踪专家 - - if($ac == "remove") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $pid = $this->_getParam('id'); - $del = $this->_getParam('del'); - - if(!empty($del) && !empty($pid)) - { - - $rs = $heihe->expertRemove($pid,$del); - - if($rs) - { - $this->jsonexit(array("deleted"=>1)); - return true; - }else{ - $this->jsonexit(array("error"=>"删除失败,请重试")); - return true; - } - - }else{ - $this->jsonexit(array("error"=>"参数错误,请刷新")); - return true; - } - - }//ac == remove 删除专家 - - if($ac == "upload") - { - $this->_helper->layout->setLayout('layout-iframe'); - $this->_helper->viewRenderer('project-upload'); - - $submit = $this->_getParam('submit'); - - $pid = $this->_getParam('pid'); - - if(empty($pid) || !is_numeric($pid)) - { - $this->view->error = "参数错误"; - return true; - } - - $this->view->pid = $pid; - - $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { - $user = $auth->getIdentity(); - $uid = $user->id; - } - - if(!empty($submit) && empty($this->view->error)) - { - - $files=new files(); - $msg = $files -> upload($this->view->config->upload,$_FILES['Filedata'],'heihe'); - - if(empty($msg['error'])) - { - $msg['error']=""; - $filename = $msg['db_path']; - $filesize = $msg['file_size']; - $filedesc = $this->_request->getParam('filedesc'); - $filetype = $msg['file_type']; - $realname = $msg['realname']; - - if(!empty($row['attachid'])) - { - $sql = "SELECT * FROM attachments WHERE id={$row['attachid']}"; - $sth = $this->db->query($sql); - $attach = $sth->fetch(); - $this->db->exec("DELETE FROM attachments WHERE id={$row['attachid']} AND filetype='heihe'"); - @unlink($this->view->config->upload.$attach['filename']); - } - - $sql = " INSERT INTO attachments (filename,filetype,filedesc,userid,filesize,realname) values - ('$filename','heihe','$filedesc','$uid','$filesize','$realname') RETURNING id"; - $sth = $this->db->prepare($sql); - $sth->execute(); - $att = $sth->fetch(PDO::FETCH_ASSOC); - $msg['attid'] = $attid = $att['id']; - - $sql = "UPDATE heiheproject SET attachid=$attid WHERE id=$pid"; - $sth = $this->db->exec($sql); - - if($sth) - { - $this->view->message = "上传成功"; - }else{ - @unlink($filename); - $this->view->error = '附件上传失败:写入附件表出错'; - return true; - } - }else{ - @unlink($filename); - $this->view->error = "附件上传失败".$msg['error']; - return true; - } - } - - $sql = "SELECT * FROM heiheproject WHERE id=$pid"; - $sth = $this->db->query($sql); - $row = $sth->fetch(); - - if(!empty($row['attachid'])) - { - $sql = "SELECT * FROM attachments WHERE id = {$row['attachid']}"; - $sth = $this->db->query($sql); - $this->view->att = $sth->fetch(); - } - - return true; - }//ac == upload - - //改变状态 - if($ac == "changestatus") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $project = $this->_getParam('p'); - $status = $this->_getParam('s'); - - if(!is_numeric($status)) - { - $this->jsonexit(array('error'=>'参数错误')); - return true; - } - - $code = $heihe->ChangeStatus($project,$status); - - if($code > 0) - { - $this->jsonexit( - array( - 'msg'=>'修改成功!', - 'status'=>$heihe->getStatus($status) - ) - ); - return true; - }else{ - $this->jsonexit(array('error'=>'参数错误')); - return true; - } - - }//ac == "changestatus" - - }//projectsAction() - - public function fundAction() - { - $this->_helper->layout->setLayout('administry'); - $ac = $this->_getParam('ac'); - $submit = $this->_getParam('submit'); - $this->view->q = $keyword = $this->_getParam('q'); - - include_once("helper/view.php"); - include_once("data/Fund.php"); - $fund = new Fund($this->db); - - $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { - $user = $auth->getIdentity(); - $uid = $user->id; - } - - if($ac=='index' || empty($ac)) - { - $uuid = $this->_getParam('uuid'); - if(empty($uuid)) - { - $rows = $fund->fetch(NULL,true,0,$keyword); - view::addPaginator($rows,$this,10); - }else{ - include('data/Metadata.php'); - $md = new Metadata($this->db); - $this->view->md = $md->view($uuid); - $rows = $fund->fetch($uuid); - view::addPaginator($rows,$this,10); - } - return true; - } - - if($ac == 'datalist') - { - $this->_helper->viewRenderer('fund-data-list'); - $this->view->q = $q = $this->_getParam('q'); - $rows = $fund->fetchFromData(true,0,$q); - view::addPaginator($rows,$this,10); - return true; - } - - if($ac == 'dataview') - { - $this->_helper->viewRenderer('fund-data-view'); - $this->view->q = $q = $this->_getParam('q'); - $id = $this->_getParam('id'); - $this->view->fund = $fund->view($id); - $rows = $fund->fetchFromData($id,0,$q); - view::addPaginator($rows,$this,10); - return true; - } - - if($ac == "add") - { - $this->_helper->viewRenderer('fund-add'); - if(!empty($submit)) - { - $data = $fund->_getParams($this->_request); - $data['userid'] = $uid; - - if($fund->add($data) == true) - { - $this->view->AlertType = "alert-success"; - $this->view->msg = "添加成功!"; - $this->view->jump_url = "/admin/data/fund/"; - return true; - }else{ - $this->view->data = $data; - $this->view->error = "添加失败,请重试"; - return true; - } - } - return true; - }//add - - if($ac == "edit") - { - $this->_helper->viewRenderer('fund-add'); - $id = $this->_getParam('id'); - - if(empty($id)) - { - $this->view->AlertType = "alert-error"; - $this->view->msg = "参数错误"; - $this->view->jump_url = "/admin/data/fund/"; - } - - if(!empty($submit)) - { - $data = $fund->_getParams($this->_request); - $data['userid'] = $uid; - if($fund->update($data,$id) == true) - { - $this->view->AlertType = "alert-success"; - $this->view->msg = "修改成功!"; - $this->view->jump_url = "/admin/data/fund/"; - return true; - }else{ - $this->view->data = $data; - $this->view->error = "修改失败,请重试"; - return true; - } - }else{ - $this->view->data = $fund->view($id); - } - return true; - }//edit - - if($ac == "del") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $id = $this->_getParam('id'); - - if(empty($id)) - { - $this->jsonexit(array('error'=>'参数错误')); - return true; - } - - if($fund->delete($id) == true) - { - $this->jsonexit(array('success'=>$id)); - return true; - }else{ - $this->jsonexit(array('error'=>'删除失败')); - return true; - } - - }//del - - if($ac == "formd") - { - $uuid = $this->_getParam('uuid'); - - if(empty($uuid)) - { - $this->view->AlertType = "alert-error"; - $this->view->msg = "参数错误"; - $this->view->jump_url = "/admin/data/fund/"; - } - - $id = $this->_getParam('id'); - $order = $this->_getParam('order'); - - if(!empty($id)) - { - if($fund->addToMdfund($uuid,$id,$order)) - { - $this->view->AlertType = "alert-success"; - $this->view->error = "添加成功!可以继续选择并添加"; - }else{ - $this->view->AlertType = "alert-error"; - $this->view->error = "添加失败!该数据可能已被添加"; - } - } - - $mfid = $this->_getParam('mfid'); - - if(!empty($mfid)) - { - if($fund->changeorder($mfid,$order)) - { - $this->view->AlertType = "alert-success"; - $this->view->error = "排序修改成功!"; - }else{ - $this->view->AlertType = "alert-error"; - $this->view->error = "排序修改失败!"; - } - $rows = $fund->fetch($uuid); - }else{ - $this->view->ct = "ct"; - $rows = $fund->fetch($uuid,false,0,$this->_getParam('q')); - } - - include('data/Metadata.php'); - $md = new Metadata($this->db); - $this->view->md = $md->view($uuid); - - view::addPaginator($rows,$this,10); - - return true; - }//formd - - if($ac == "mdfunddel") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $id = $this->_getParam('id'); - - if(empty($id)) - { - $this->jsonexit(array('error'=>'参数错误')); - return true; - } - - if($fund->mfdelete($id) == true) - { - $this->jsonexit(array('success'=>$id)); - return true; - }else{ - $this->jsonexit(array('error'=>'删除失败')); - return true; - } - }//mdfunddel - - if($ac == "data") - { - $this->_helper->viewRenderer('fund-data'); - - $id = $this->_getParam('id'); - $del = $this->_getParam('del'); - $this->view->info = $fund->view($id); - - if(!empty($del)) - { - $s = $fund->dataRelationDelete($del); - if($s) - { - $this->view->error = view::Error("删除成功!","alert-sccuess"); - }else{ - $this->view->error = view::Error("删除失败!","alert-error"); - } - } - - $rows = $fund->getData($id,$keyword); - view::addPaginator($rows,$this,10); - } - - }//fund - - public function doiAction() - { - $ac = $this->_getParam('ac'); - $submit = $this->_getParam('submit'); - $uuid = $this->_getParam('uuid'); - $q=$this->_getParam('q'); - - include_once("data/Doi.php"); - $doi = new Doi($this->db); - include_once("helper/view.php"); - - if( empty($ac) || $ac == "index") - { - if(empty($uuid)) - { - $rows = $doi->fetch(0,$q); - view::addPaginator($rows,$this,10); - }else{ - $this->_redirect('/admin/data/doi/ac/edit/?uuid='.$uuid); - return true; - } - return true; - }//index - - else if($ac == "add") - { - $this->_helper->viewRenderer('doi-add'); - - }//add - - else if($ac == "edit") - { - $this->_helper->viewRenderer('doi-add'); - $id = $this->_getParam('id'); - if(empty($uuid) && empty($id)) - { - view::Msg('alert-error',"参数错误",-1); - return false; - } - - if(empty($submit)){ - if(!empty($uuid)) - { - $this->view->uuid = $uuid; - $this->view->data = $doi->view($uuid); - include('data/Metadata.php'); - $md = new Metadata($this->db); - $metadata = $md->view($uuid); - if(empty($this->view->data)) - { - $this->view->data = array( - 'uuid'=>$uuid, - 'title'=>$metadata['title'], - 'doi'=>$metadata['doi'], - 'url'=>"http://" . $_SERVER['HTTP_HOST'].'/data/'.$uuid, - 'publisher'=>'寒区旱区科学数据中心', - 'title_en'=>$metadata['title_en'], - 'publisher_en'=>'Cold and Arid Regions Science Data Center at Lanzhou', - ); - }else{ - $this->view->data['doi'] = $metadata['doi']; - $this->view->data['info'] = $doi->data_process_out($this->view->data); - if(empty($this->view->data['ts_published'])) - { - $this->view->data['title'] = $metadata['title']; - $this->view->data['title_en'] = $metadata['title_en']; - } - } - }else{ - $this->view->data = $doi->view($uuid); - $this->view->data['info'] = $doi->data_process_out($this->view->data); - } - }else{ - $data = $doi->_getParams($this->_request); - $this->view->data = $data; - $info = $doi->checkinfo($data['info']); - if(!is_array($info)){ - $this->view->error = view::Error($info); - return true; - }else{ - $data['info'] = $info; - $data['info'] = $doi->sksort($data['info'],"order",SORT_ASC); - } - $state = $doi->update($data,$uuid); - if($state) - { - $this->view->msg = view::Msg('alert-success',"修改成功!",'/admin/data/doi/uuid/'.$uuid); - return false; - }else{ - $this->view->error = view::Error("修改失败"); - return false; - } - } - }//edit - - else if($ac == "del") - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - - $id = $this->_getParam('id'); - - if(empty($id)) - { - $this->jsonexit(array('error'=>'参数错误')); - return true; - } - - if($doi->delete($id) == true) - { - $this->jsonexit(array('success'=>$id)); - return true; - }else{ - $this->jsonexit(array('error'=>'删除失败')); - return true; - } - - }//del - else if ($ac=="convert") //转换为chinadoi所需元数据格式 - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $sql="select d.*,m.description from datadoi d left join metadata m on d.uuid=m.uuid where d.uuid='$uuid'"; - $row=$this->db->fetchRow($sql); - $timestamp=date('YmdHis'); - $authors=explode(',',substr($row['authors'],1,-1)); - $orgs=explode(',',substr($row['organization'],1,-1)); - $doi=' - - '.$timestamp.' - '.$timestamp.' - - ISTIC - tuy@istic.ac.cn - - ISTIC - - - - - '; - foreach($authors as $k=>$v) - { - $doi.=''.$v.''; - $doi.=''.$orgs[$k].''; - } - $doi.=' - - <![CDATA['.$row['title'].']]> - - '; - $doi.=''; - $doi.=''.$row['publisher'].''; - $doi.=' - '.$row['doi'].' - '.$timestamp.' - - '; - $doi.=' - - -'; - $this->getResponse()->setHeader('Content-Type', 'text/xml')->setHeader('Content-Disposition','attachment; filename="'.$row['uuid'].'.xml"') - ->setHeader('Content-Type','application/force-download')->setBody($doi); - $this->db->query('update datadoi set ts_submitted=now() where uuid=?',array($uuid)); - } - else if ($ac=="verified") //成功申请 - { - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $row=$this->db->fetchRow("select * from datadoi where uuid='$uuid'"); - $content=@file_get_contents("http://dx.doi.org/".$row['doi']); - if (strpos($content,$row['doi'])!==false) //成功申请 - { - $sql="update datadoi set ts_published=now() where uuid=? and ts_published is null"; - $this->db->query($sql,array($uuid)); - $this->jsonexit(array('success'=>'成功申请')); - } else - $this->jsonexit(array('success'=>'该DOI验证失败,请检查!')); - return true; - } - }//doi - - //发送邀请专家的邮件 - public function sendMailToExpert($pid,$name,$email,$code,$test=0) - { - include_once("Heihe.php"); - $heihe = new Heihe($this->db); - $url = $heihe->makeInviteLink($pid,$code); - - include_once("EmailText.php"); - $mailtp=new EmailText($this->db,"expert-invite",array( - 'name' => $name, - 'url' => $url, - )); - - echo $mailtp->getBody(); - echo $mailtp->getSubject(); - if($test == 0) - { - include_once("WestdcMailer.php"); - $mail=new WestdcMailer($this->view->config->smtp); - $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); - $mail->setBodyText($mailtp->getBody()); - $mail->setSubject($mailtp->getSubject()); - $mail->addTo($email); - $mail->send(); - }else{ - $mail_config = array( - 'ssl' => 'ssl', - 'port' => 465, - 'auth' => 'login', - 'username' => 'la5c@qq.com', - 'password' => '' - ); - $transport = new Zend_Mail_Transport_Smtp('smtp.qq.com', $mail_config); - Zend_Mail::setDefaultTransport($transport); - - $mail=new Zend_Mail(); - $mail->setBodyText($mailtp->getBody()); - $mail->setFrom('la5c@qq.com','Jack'); - $mail->addTo("la5c@qq.com"); - $mail->setSubject($mailtp->getSubject()); - $mail->send(); - } - }//发送邀请邮件 - - /* - 获得单个文件的信息 - 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数据到数据库 - */ - private function import($xml) - { - $iso=new ISO19115(); - $iso->saveDB($this->db,$xml); - } - - /* - * jsonexit() 退出并返回json数据 - * - * param array $data 要返回的JSON数据,可以是任意数组 - * - * return JSON-response - */ - public function jsonexit($data){ - $this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(json_encode($data,JSON_NUMERIC_CHECK)); - return true; - }//jsonexit() 退出并返回json数据 -} +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() + { + //其他连接 + } + + //提供和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"; + $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=trim($this->_request->getParam('uuid')); + if ($source=="geonetwork" && empty($uuid) ) { + //从geonetwork向WESTDC同步 + //对所有的新数据增加评审状态 + $sql="insert into mdstatus (uuid,status,ts_accepted,userid) select uuid,1,now(),? + from geonetworkmetadata gn where uuid not in (select uuid from mdstatus)"; + $userid = Zend_Auth::getInstance()->getIdentity()->id; + $this->db->query($sql,array($userid)); + $sql="select uuid,data,source 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='e3ad32dc-f573-11e0-aa7b-b768cfd88d80'"; + $sql="delete from metadata where uuid in (select uuid from watergn)"; + $this->db->query($sql); + $sql="delete from responsible where id not in (select distinct(resid) from role)"; + $this->db->query($sql); + //对所有的新数据增加评审状态 + $sql="insert into mdstatus (uuid,status,ts_accepted,userid) select uuid,1,now(),? + from watergn where uuid not in (select uuid from mdstatus)"; + $userid = Zend_Auth::getInstance()->getIdentity()->id; + $this->db->query($sql,array($userid)); + //同步黑河遥感实验的元数据 + $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 ($source=="glacier" && empty($uuid) ) { + //首先删除所有的对应专题数据 + $sql="delete from metadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier')"; + $this->db->query($sql); + $sql="delete from responsible where id not in (select distinct(resid) from role)"; + $this->db->query($sql); + //对所有的新数据增加评审状态 + /*$sql="insert into mdstatus (uuid,status,ts_accepted,userid) select uuid,1,now(),? + from watergn where uuid not in (select uuid from mdstatus)"; + $userid = Zend_Auth::getInstance()->getIdentity()->id; + $this->db->query($sql,array($userid));*/ + //同步专题元数据 + $sql="select uuid,data,source from geonetworkmetadata where schemaid='iso19115' and uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='glacier')"; + $rs=$this->db->fetchAll($sql); + foreach($rs as $gmd) { + $this->import($gmd->data); + //source in unused now. + //$this->db->query("update metadata set source=? where uuid=?",array($gmd->source,$gmd->uuid)); + } + $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); + } + $this->view->msg='成功同步WESTDC元数据到GEONETWORK!'; + } elseif (!empty($uuid) && isset($_POST['gnsubmit'])) { + //同步单条元数据到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).")"; + } + $this->db->exec($sql); + $this->view->msg='成功同步元数据:'.$uuid; + } else $this->view->msg='不存在此元数据:'.$uuid; + } elseif (!empty($uuid) && isset($_POST['watersubmit'])) { + //同步单条元数据 + $sql=$this->db->quoteInto("select data,source from watergn where uuid=?",$uuid); + if ($rs=$this->db->fetchRow($sql)) { + $this->import($rs->data); + $this->db->query("update metadata set source=? where uuid=?",array($rs->source,$uuid)); + $this->view->msg='成功同步元数据:'.$uuid; + } else $this->view->msg='不存在此元数据:'.$uuid; + } elseif ($list=='westdc') { + $sql="select uuid,title from metadata where uuid not in (select uuid from geonetworkmetadata where schemaid='iso19115')"; + $this->view->metadata=$this->db->query($sql); + } elseif ($list=='geonetwork') { + $sql="select id,uuid,(regexp_matches(data,'(.*)'))[1] as title from geonetworkmetadata + where uuid not in (select uuid from metadata)"; + $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=='geonetwork') { + //dblink view中删除多条有问题,暂时用单条删除替代 + //$sql="delete from geonetworkmetadata where uuid not in (select uuid from metadata)"; + $sql="select uuid from geonetworkmetadata where uuid not in (select uuid from metadata)"; + $rows=$this->db->fetchAll($sql); + foreach($rows as $row) + { + $this->db->exec($this->db->quoteInto("delete from geonetworkmetadata where uuid=?",$row->uuid)); + } + $this->view->msg='已删除GEONETWORK中多出的元数据!'; + } 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"; + $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=encode(digest(md5('$row->password'),'sha1'),'hex'),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',encode(digest(md5('$row->password'),'sha1'),'hex'),'$row->email')"; + $this->db->query($sql); + } + } + $this->view->msg='已成功同步帐号!'; + } elseif (!empty($uuid) && (isset($_POST['submit']) || (!isset($_POST['gnsubmit']) && !isset($_POST['watersubmit'])))) { + //同步单条元数据 + $sql=$this->db->quoteInto("select data,source from geonetworkmetadata where uuid=?",$uuid); + if ($rs=$this->db->fetchRow($sql)) { + $this->import($rs->data); + $this->db->exec($this->db->quoteInto("update metadata set source=? where uuid='$uuid'",$rs->source)); + $userid = Zend_Auth::getInstance()->getIdentity()->id; + $this->db->query("insert into mdstatus (uuid,status,ts_accepted,userid) select uuid,1,now(),? + from geonetworkmetadata gn where uuid not in (select uuid from mdstatus) and uuid=?",array($userid,$uuid)); + $this->view->msg='成功同步元数据:'.$uuid; + //update search document + $search=new Search(); + $sql="select * from xunsearch where uuid=?"; + $sth = $this->db->prepare($sql); + $sth->setFetchMode(Zend_Db::FETCH_ASSOC); + $sth->execute(array($uuid)); + $data = $sth->fetch(); + $search->update($data); + + } else $this->view->msg='不存在此元数据:'.$uuid; + } + } + + function datasetcdAction() + { + $add=(int)$this->_getParam('add'); + $edit=(int)$this->_getParam('edit'); + $delete=(int)$this->_getParam('delete'); + set_time_limit(0); + 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; + } + + /* + * + * 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'); + + + if ($delete) + { + $sql="delete from metadata where uuid=?"; + try { + $this->db->query("delete from mdstatus where uuid=?",array($delete)); + $this->db->query("delete from mdauthor where uuid=?",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 normalmetadata 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 metadata 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 metadata 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 '

      数据目录成功导入!

      '; + } else if ($row['host']=='ftp.sanjiangyuan.org.cn') + { + file_get_contents("http://ftp.sanjiangyuan.org.cn/proftp_upload.php?uuid=".$uuid."&filelist=1"); + echo '

      数据目录成功导入!

      '; + } else { + echo '

      数据目录未导入!

      '; + } + } + + }//datasetAction存档管理 + + /* + * commentAction() + * 反馈管理 + * ALTER TABLE comments ADD COLUMN reply integer NOT NULL DEFAULT 0; + */ + function commentAction() + { + $delete=(int)$this->_getParam('delete'); + $uuid = $this->_getParam('uuid'); + $reply = $this->_getParam('reply'); + $replylist = $this->_getParam('replylist'); + $delreply = $this->_getParam('delreply'); + + 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"); + } + + if($reply) + { + + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $body = $this->_getParam('content'); + if(empty($body)) + { + $data = array('error'=>"请输入回复内容"); + $this->jsonexit($data); + return true; + } + + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $uid = $user->id; + $email = $user->email; + } + + $ipaddr = $_SERVER['REMOTE_ADDR']; + + $sql = "INSERT INTO comments (uuid,author,reply,userid,content,email,ip) VALUES (?,?,?,?,?,?,?)"; + $sth = $this->db->prepare($sql); + $rs = $sth->execute(array($uuid,$user->username,$reply,$uid,$body,$email,$ipaddr)); + + if($rs) + { + $sql="select c.author,c.email,c.uuid from comments c where c.id=?"; + $sth=$this->db->prepare($sql); + $sth->execute(array($reply)); + $row=$sth->fetch(); + + $mail=new WestdcMailer($this->view->config->smtp); + $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); + $mailtp=new EmailText($this->db,"comment-admin-reply",array( + 'user' => $row['author'], + 'uuid' => $row['uuid'], + 'email'=> $row['email'] + )); + $mail->setBodyText($mailtp->getBody()); + $mail->setSubject($mailtp->getSubject()); + $mail->addTo($row['email']); + $mail->addCc($this->view->config->service->email); + @$mail->send(); + + $data = array('status'=>1,'msg'=>'回复成功!'); + $this->jsonexit($data); + return true; + }else{ + $data = array('error'=>"回复失败,请重试"); + $this->jsonexit($data); + return true; + } + return true; + } + + if($uuid) + { + $sql = "SELECT c.*,md.title,md.uuid FROM comments c + LEFT JOIN metadata md ON md.uuid=c.uuid + WHERE c.uuid=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($uuid)); + $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; + + $sql = "SELECT title FROM metadata WHERE uuid=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($uuid)); + $row = $sth->fetch(); + + $this->view->title = $row['title']; + + return true; + } + + if($replylist) + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $sql = "SELECT cr.id,cr.content as body,cr.reply,u.username,cr.ts_created FROM comments cr + LEFT JOIN users u ON cr.userid=u.id WHERE cr.reply=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($replylist)); + $rows = $sth->fetchAll(); + + $this->jsonexit($rows); + return true; + + } + + if($delreply) + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $sql = "DELETE FROM comments WHERE id=?"; + $sth = $this->db->prepare($sql); + $rs = $sth->execute(array($delreply)); + + if($rs) + { + $this->jsonexit( + array('deleted'=>1) + ); + return true; + }else{ + $this->jsonexit( + array('error'=> '处理中出现错误,请重新尝试') + ); + return true; + } + + + } + + + $sql = "SELECT cm.*,md.title,(SELECT count(id) as counts FROM comments cms WHERE cms.reply=cm.id AND cms.reply!=0) as reply_count FROM comments cm + LEFT JOIN metadata md ON md.uuid=cm.uuid + WHERE cm.reply=0 + ORDER BY cm.ts_created DESC,cm.id DESC"; + + $sth = $this->db->query($sql); + $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; + + }//comment + + + 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'); + $import=(int)$this->_getParam('import'); + $show = $this->_getParam('show'); + + if ($add) { + $type = $this->_getParam('type'); + if($type == 'dc') + { + $this->_helper->viewRenderer('referenceadd'); + $this->view->type = "dc"; + }else{ + $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,reftype) values(?,?,?)"; + $this->db->query($sql,array(trim($formdata['uuid']),$row['id'],$formdata['reftype'])); + $this->messenger->addMessage('提示信息:您已经成功添加该数据文献。'); + $this->_redirect('/admin/data/reference/show/'.$formdata['uuid']); + }else { + $form->populate($formdata); + } + } else { + if ($uuid) + { + $formdata['uuid']=$uuid; + $form->populate($formdata); + } + } + $this->view->form=$form; + $this->_helper->viewRenderer('referenceadd'); + } + } //添加 + + else if($show){ + $sql = "select mr.id as mdid,mr.refid,r.reference,md.title,md.uuid,mr.place FROM mdref mr + left join metadata md on md.uuid=mr.uuid + left join reference r on r.id=mr.refid + where mr.uuid='$show'; + "; + $rs = $this->db->query($sql); + $rows = $rs->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; + + } //按UUID查看 + + elseif ($edit){ + $form=new ReferenceForm(); + if ($this->_request->isPost()) { + $formdata=$this->_request->getPost(); + if ($form->isValid($formdata)) { + $sql="select id from reference where reference=? order by id desc"; + $rs=$this->db->query($sql,array($formdata['reference'])); + $row = $rs->fetch(); + if ($row['id']!='') + { + //更新文献信息 + $sql="update mdref set refid=?,reftype=? where uuid=? and id=?"; + $td = $this->db->query($sql,array($row['id'],$formdata['reftype'],$formdata['uuid'],$edit)); + $sql="update reference set reference=?,link=? where id=?"; + $this->db->query($sql,array($formdata['reference'],$formdata['link'],$row['id'])); + if($td) + { + $this->messenger->addMessage('提示信息:您已经编辑该数据文献。'); + $this->_redirect('/admin/data/reference/show/'.$formdata['uuid']); + } + }else + { + $sql = "INSERT INTO reference (reference,link) VALUES ('".$formdata['reference']."','".$formdata['link']."') RETURNING id"; + $sth = $this->db->prepare($sql); + if($sth->execute()) + { + $row = $sth->fetch(PDO::FETCH_ASSOC); + $sql="update mdref set refid=?,reftype=? where uuid=? and id=?"; + $td = $this->db->query($sql,array($row['id'],$formdata['reftype'],$formdata['uuid'],$edit)); + $this->messenger->addMessage('提示信息:您已经编辑该数据文献。'); + $this->_redirect('/admin/data/reference/show/'.$formdata['uuid']); + }else + { + $this->messenger->addMessage('提示信息:文献创建失败,请重试'); + $this->_redirect('/admin/data/reference/edit/'.$edit); + } + } + } else { + $form->populate($formdata); + } + } else { + $sql="select m.uuid,r.reference,r.link,m.reftype from reference r left join mdref m on r.id=m.refid where m.id=?"; + $formdata=$this->db->fetchRow($sql,array($edit)); + $form->populate($formdata); + } + $this->view->form=$form; + $this->_helper->viewRenderer('referenceadd'); + } //编辑相关文献 + + elseif ($delete) { + $sql = "select uuid from mdref where id=$delete"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + $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/show/'.$row['uuid']); + } //删除相关文献 + + elseif ($import) { + if ($this->_request->isPost()) { + if ($_FILES["ref"]["error"] == UPLOAD_ERR_OK) { + $tmp_name = $_FILES["ref"]["tmp_name"]; + $fp = fopen($tmp_name, "rb"); + $ref=fread($fp, filesize($tmp_name)); + fclose($fp); + $lines=explode("\n",$ref); + foreach($lines as $line) + { + $data=explode(";",$line); + if (count($data)==2) + $link=''; + else + $link=$data[2]; + $link=$this->db->quote($link); + $sql="insert into reference (reference,link) values(?,".$link.")"; + try { + $this->db->exec($this->db->quoteInto($sql,trim($data[1]))); + } catch (Exception $e) {} + $sql="select id from reference where reference=?"; + $row=$this->db->fetchRow($this->db->quoteInto($sql,trim($data[1]))); + $sql="insert into mdref (uuid,refid) values(?,".$row['id'].")"; + try { + $this->db->exec($this->db->quoteInto($sql,trim($data[0]))); + } catch (Exception $e) {} + } + }//end if + } + $this->_helper->viewRenderer('referenceimport'); + } //引用 + + 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{ + $sql="select m.title as mdtitle,m.uuid,mr.id as mdid,mr.refid,mr.place,r.reference + from mdref mr right join metadata m on mr.uuid=m.uuid + left join reference r on mr.refid=r.id + order by m.ts_created desc,mr.place"; + $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.phtml'); + $this->view->paginator=$paginator; + + }//列表 + } + + //文献管理 + public function refAction() + { + $this->view->ac = $ac = $this->_getParam('ac'); + $submit = $this->_getParam('submit'); + $keyword = $this->view->q = trim($this->_getParam('q')); + $order = $this->view->search_order = trim($this->_getParam('order')); + $sort = $this->view->search_sort = trim($this->_getParam('sort')); + $field = $this->view->search_field = $this->_getParam('field'); + + $reference = new Reference(); + + if(!empty($keyword)) + { + $reference->keyword = $keyword; + } + + if(!empty($field)) + { + $reference->field = $field; + } + + if(!empty($order)) + { + $reference->order = $order; + } + + if(!empty($sort)) + { + $reference->sort = $sort; + } + + $this->view->reference = $reference; + $this->view->page = $this->_getParam('page'); + $this->view->pagelimit = 12; + + //文献首页 + if(empty($ac)) + { + $this->view->referenceType = $reference->referenceType(); + view::addPaginator($reference->fetchReferences(),$this, $this->view->pagelimit); + $this->view->years = $reference->countByYear(); + return true; + } + else if ($ac == "water") + { + $this->view->referenceType = $reference->referenceType(); + view::addPaginator($reference->fetchThemeReferences('water'),$this,$this->view->pagelimit); + return true; + } + else if ($ac == "westdc") + { + $this->view->referenceType = $reference->referenceType(); + view::addPaginator($reference->fetchWestdcReferences(),$this,$this->view->pagelimit); + return true; + } + else if ($ac == "todo") + { + $this->view->referenceType = $reference->referenceType(); + view::addPaginator($reference->fetchTodoReferences(),$this,$this->view->pagelimit); + return true; + } + + unset($this->view->reference); + unset($this->view->page); + unset($this->view->pagelimit); + + //添加 + if($ac == "add") + { + $this->_helper->viewRenderer('ref-add'); + $id = $this->_getParam('id'); + $attid = $this->_getParam('attid'); + + if(!empty($submit)) + { + $this->view->data = $reference->getReferenceParam(); + $attid = $this->view->data['attid']; + + if(empty($id) || !is_numeric($id)) + { + $status = $reference->reference(); + }else{ + $status = $reference->reference($id); + } + + if($status !== true) + { + $this->view->error = view::Error($status); + }else{ + if(!empty($id)) + { + $msg = "文献修改成功!"; + view::Post($this,$msg,-2); + return true; + }else{ + $msg = "文献添加成功!"; + view::Post($this,$msg,"/admin/data/ref/ac/add"); + return true; + } + } + }else{ + $this->view->data = array(); + if(!empty($id) && is_numeric($id)) + { + $this->view->data = $reference->getOneReferenceData($id); + } + } + + if(!empty($attid)) + { + $files = new Files(); + $attfile = $files->getOne($attid); + $this->view->data['attid'] = $attid; + $this->view->data['file'] = $attfile; + } + + return true; + } + + //上传pdf + if($ac == "pdfupload") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $autoread = false; + if($this->_getParam('multi')) + { + $autoread = true; + } + $statu = $reference->uploadReferencePdf($_FILES['Filedata'],$autoread); + $this->jsonexit($statu); + return true; + } + + //删除已上传的文件 + if($ac == "delete") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $statu = $reference->deleteReferenceAttchment($this->_getParam('attid')); + $this->jsonexit($statu); + return true; + } + + //批量上传 + if($ac == "multiupload") + { + $this->_helper->viewRenderer('ref-multiupload'); + return true; + } + + //文件管理 + if($ac == "files") + { + $this->_helper->viewRenderer('ref-files'); + view::addPaginator($reference->getReferenceFiles(),$this,10); + return true; + } + + //删除文献 + if($ac == "deleteref") + { + $refid = $this->_getParam('id'); + if($reference->deleteReference($refid)) + { + view::Post($this,"删除成功!",-1); + }else{ + view::Post($this,"删除失败!",-1); + } + return true; + } + + //相关数据 + if($ac == "data") + { + $refid = $this->view->refid = $this->_getParam('id'); + if(view::isXmlHttpRequest($this)){ + $this->jsonexit($reference->getDataByReference($refid)); + return true; + }else{ + $this->_helper->viewRenderer('ref-metadatas'); + $this->view->referenceType = $reference->referenceType(); + view::addPaginator($reference->getDataByReference($refid),$this,10); + return true; + } + } + + //添加数据文献 + if($ac == "mdref" && view::isXmlHttpRequest($this)) + { + $mdrefid = $this->_getParam('id'); + $status = $reference->makeMdref($mdrefid); + if($status !== true) + { + $this->jsonexit(array('error'=>$status)); + }else{ + $this->jsonexit(array('success' => 1)); + } + return true; + } + + //移除数据文献 + if($ac == "delmdref") + { + $mdrefid = $this->_getParam('id'); + $status = $reference->delMdref($mdrefid); + if($status === true) + { + view::Post($this,"移除成功",-1); + }else{ + view::Post($this,$status,-1); + } + return true; + } + + //ris + if($ac == "ris") + { + $this->_helper->viewRenderer('ref-ris'); + $submit = $this->_getParam('submit'); + + if(!empty($submit)) + { + $ris = new \Reference\Ris(); + $this->view->data = $ris->loadout(); + try{ + $ris->pushToDataTable($this->view->data); + }catch(Exception $e) + { + view::Dump($e->getMessage(),false); + } + } + } + + //ris更新单篇 + if($ac == "singleris") + { + $this->_helper->viewRenderer('ref-singleris'); + $id = (int)$this->_getParam('id'); + $this->view->ristext = $this->_getParam('ristext'); + + if($id < 1) + { + view::Post($this,"参数错误!",-1); + return true; + } + + $this->view->referenceData = $reference->getOneReferenceData($id); + + if(!empty($submit)) + { + $ris = new Ris(); + $data = $ris->loadout(); + + if(count($data) < 1) + { + view::Post($this,"输入的RIS信息有误".'查看详细',-1); + return true; + } + + if($ris->updateWithRis($id,$data[0]) === true) + { + view::Post($this,"编辑成功!".'查看详细',-2); + return true; + }else{ + view::Post($this,"编辑失败!".'查看详细',-1); + return true; + } + } + + return true; + }//ris单篇更新 + + //ris导出 + if($ac == "risoutput") + { + $this->_helper->viewRenderer('ref-risoutput'); + $this->view->years = $reference->countByYear(); + + if(!empty($submit)) + { + $mode = $this->_getParam('mode'); + + $risOutput = new RisOutput(); + $preData = $risOutput->preRead($mode); + + $risData = $risOutput->processArrayDataToRisData($preData); + + $risText = $risOutput->output($risData); + + echo "
      ";
      +				echo $risText;
      +				echo "
      "; + } + }//ris output + + if($ac == "ristest") + { + $this->_helper->viewRenderer('ref-ris'); + $submit = $this->_getParam('submit'); + + if(!empty($submit)) + { + $ris = new \Reference\Ris(); + view::Dump($ris->processRis(NULL,$this->_getParam('ristext')),false); + } + } + + + }//文献管理 refAction() + + /* + * 删除元数据,删除前有确认 + */ + 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('/data'); + } 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='已成功处理数据目录信息!'; + } + }//datafileimportAction + + + function sourceAction() + { + $do = $this->_request->getParam('do'); + $uuid = $this->_request->getParam('uuid'); + $id = $this->_request->getParam('id'); + $q = $this->_request->getParam('q'); + $search = $this->_request->getParam('search'); + + if ($do == 'add') { + + $redirect = "/admin/data/source/"; + + if(!empty($_POST['submit'])) + { + try{ + $title = $this->_request->getParam('title'); + $uuid = $this->_request->getParam('uuid'); + $code = $this->_request->getParam('code'); + $description = $this->_request->getParam('description'); + $has_pages = $this->_request->getParam('has_pages'); + $has_agreement = $this->_request->getParam('has_agreement'); + + $data = array( + 'title' => $title, + 'uuid' => $uuid, + 'code' => $code, + 'description' => $description, + 'has_pages' => $has_pages, + 'has_agreement' => $has_agreement + ); + + if($this->db->insert('source',$data)) + { + $this->messenger->addMessage('添加来源信息成功'); + $this->_redirect($redirect); + } + }catch(Exception $e){ + $this->messenger->addMessage('添加来源信息失败:'.$e->getMessage()); + $this->_redirect('/admin/data/source/do/add'); + } + + } + + $this->_helper->viewRenderer('sourceadd'); + }// 添加项目来源 + + else if($do == 'edit' && !empty($id)) + { + + if(!empty($_POST['submit'])) + { + try{ + $title = $this->_request->getParam('title'); + $uuid = $this->_request->getParam('uuid'); + $code = $this->_request->getParam('code'); + $description = $this->_request->getParam('description'); + $has_pages = $this->_request->getParam('has_pages'); + $has_agreement = $this->_request->getParam('has_agreement'); + + $sql = "update source set title='$title',uuid='$uuid',code='$code',description='$description',has_pages='$has_pages',has_agreement='$has_agreement' where id='$id'"; + + if($this->db->exec($sql)) + { + $this->messenger->addMessage('修改来源信息成功'); + $this->_redirect("/admin/data/source/do/edit/id/$id"); + } + }catch(Exception $e){ + $this->messenger->addMessage('修改来源信息失败:'.$e->getMessage()); + $this->_redirect("/admin/data/source/do/edit/id/$id"); + } + + } + + $sql = "select * from source where id='$id'"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + + $this->view->info = $row; + + $this->_helper->viewRenderer('sourceadd'); + + }// 编辑单条信息 + + else if($do == 'datasource' && !empty($uuid)) + { + $redirect = "/admin/data/source/do/datasource/uuid/$uuid"; + + $this->view->uuid = $uuid; + $sql = "select md.title,ds.id,ds.sourceid,s.title as stitle,s.code from metadata md + left join datasource ds on ds.uuid=md.uuid + left join source s on s.id=ds.sourceid + where md.uuid='$uuid'"; + $rs = $this->db->query($sql); + $row = $rs->fetch(); + + $this->view->info = $row; + + if(!empty($_POST['submit'])) + { + $sourceid = $this->_request->getParam('sourceid'); + if(empty($sourceid)) + { + $this->messenger->addMessage('请选择项目来源'); + $this->_redirect($redirect); + } + + $sql=""; + if(empty($row['id'])) + { + $sql = "insert into datasource (uuid,sourceid) values ('$uuid','$sourceid')"; + }else + { + $sql = "update datasource set uuid='$uuid',sourceid='$sourceid' where id='{$row['id']}'"; + } + try{ + if($this->db->exec($sql)) + { + $this->messenger->addMessage('修改项目来源成功'); + $this->_redirect($redirect); + } + else + { + $this->messenger->addMessage('修改项目来源失败'); + $this->_redirect($redirect); + } + }catch (Exception $e){ + $this->messenger->addMessage('修改项目来源失败:'.$e->getMessage()); + $this->_redirect($redirect); + } + + } + + + $wheresql = array(); + + if(!empty($q) && !empty($search)) + { + $this->view->q = $q; + $wheresql[] = " title like '%$q%' "; + } + + if(count($wheresql>0))$wheresql = join(' and ',$wheresql); + else $wheresql=''; + + if($wheresql!='') + { + $wheresql = 'where '.$wheresql; + } + + $sql = "select * from source $wheresql order by id desc"; + $rs = $this->db->query($sql); + $rows = $rs->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; + + $this->_helper->viewRenderer('sourceselect'); + }// 为元数据选择项目来源 + + else if($do == 'del' && !empty($id)) + { + $redirect = "/admin/data/source/"; + $sql = "delete from source where id='$id'"; + try{ + if($this->db->exec($sql)) + { + $this->messenger->addMessage('删除成功'); + $this->_redirect($redirect); + }else{ + $this->messenger->addMessage('删除失败,可能该数据已不存在'); + $this->_redirect($redirect); + } + }catch (Exception $e){ + $this->messenger->addMessage('删除失败:'.$e->getMessage()); + $this->_redirect($redirect); + } + }// 删除项目来源 + + else if($do == 'fetch' && !empty($id)) + { + + $wheresql = array(); + + $wheresql[] = " ds.sourceid='$id' "; + + if(!empty($q) && !empty($search)) + { + $this->view->q = $q; + $wheresql[] = " title like '%$q%' "; + } + + if(count($wheresql>0))$wheresql = join(' and ',$wheresql); + else $wheresql=''; + + if($wheresql!='') + { + $wheresql = 'where '.$wheresql; + } + + $sql = "select md.title,md.uuid,ds.id,ds.sourceid,s.title as stitle,s.code from metadata md + left join datasource ds on ds.uuid=md.uuid + left join source s on s.id=ds.sourceid + $wheresql + order by id desc"; + $rs = $this->db->query($sql); + $rows = $rs->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; + + $this->_helper->viewRenderer('sourcefetchone'); + + }//查看某项目来源中的所有元数据 + + else if($do == 'delsource' && !empty($id)) + { + $redirect = "/admin/data/source/do/datasource/uuid/$uuid"; + + $sql = "delete from datasource where id='$id'"; + + try{ + if($this->db->exec($sql)) + { + $this->messenger->addMessage('删除成功'); + $this->_redirect($redirect); + }else{ + $this->messenger->addMessage('删除失败,可能该数据已不存在'); + $this->_redirect($redirect); + } + }catch (Exception $e){ + $this->messenger->addMessage('删除失败:'.$e->getMessage()); + $this->_redirect($redirect); + } + + + }// 清除元数据来源记录 + elseif ($do=='sync') { //同步数据来源到metadata表 + $redirect = "/admin/data/source/"; + $sql = "update metadata m set source=s.uuid from source s right join datasource d on s.id=d.sourceid where m.uuid=d.uuid"; + if($this->db->exec($sql)) + { + $this->messenger->addMessage('成功同步数据来源'); + $this->_redirect($redirect); + }else{ + $this->messenger->addMessage('同步数据来源失败'); + $this->_redirect($redirect); + } + } + + else + { + $wheresql = array(); + + if(!empty($q) && !empty($search)) + { + $this->view->q = $q; + $wheresql[] = " title like '%$q%' "; + } + + if(count($wheresql>0))$wheresql = join(' and ',$wheresql); + else $wheresql=''; + + if($wheresql!='') + { + $wheresql = 'where '.$wheresql; + } + + $sql = "select * from source $wheresql order by id desc"; + $rs = $this->db->query($sql); + $rows = $rs->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; + }// 项目来源管理 + + + }//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'); + $uuid = $this->_request->getParam('uuid'); + $mdtitle = $this->_request->getParam('mdtitle'); + $mdattdel = $this->_request->getParam('mdattdel'); + $attupdate = $this->_getParam('attupdate'); + + if(!empty($uuid)&&!empty($mdtitle)) + { + $this->view->uuid= $uuid; + $this->view->mdtitle=$mdtitle; + } + + if($add) + { + $this->_helper->viewRenderer('attachmentsadd'); + if(!empty($uuid)) + { + $this->view->uuid = $uuid; + } + }//附件添加 + + elseif($attupdate) + { + $submit = $this->_getParam('submit'); + if(!empty($submit)) + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $id = $this->_getParam('attupdate'); + + $files=new Files(); + $msg = $files -> upload($_FILES['Filedata'],empty($uuid)?'file/':'md/',true); + + if(empty($msg['error'])) + { + $msg['error']=""; + $filename = $msg['db_path']; + $filesize = $msg['file_size']; + $filedesc = $this->_request->getParam('filedesc'); + $filetype = 'md'; + $realname = $msg['realname']; + + + $sql = "UPDATE attachments SET filename=?,filetype=?,filesize=?,realname=? WHERE id=?"; + $sth = $this->db->prepare($sql); + $ds = $sth->execute(array($filename,$filetype,$filesize,$realname,$id)); + + if($ds) + { + $msg['html'] = $realname.'['. round($filesize/1024,2) .' kb]'; + $msg['ok']= 1; + echo Zend_Json::encode($msg); + exit(); + }else{ + @unlink($filename); + $data = array("error"=>'附件上传失败:写入附件表出错'); + $this->jsonexit($data); + return true; + } + }else{ + @unlink($filename); + $data = array("error"=>'附件上传失败:'.$msg['error']); + $this->jsonexit($data); + return true; + } + + + $data = array("error"=>"处理中出现错误".$id); + $this->jsonexit($data); + return true; + }else{ + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer('attachments-update'); + $id = $this->_getParam('attupdate'); + $this->view->id = $id; + } + + }//附件文件更新 + + else if($mdattdel) + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + + $sql = "delete from mdattach where uuid=? AND id=?"; + $sth = $this->db->prepare($sql); + $ds = $sth->execute(array($uuid,$mdattdel)); + if($ds) + { + $data = array("status"=>1); //操作状态代码 : 1=>成功 2=>失败 + $this->jsonexit($data); + return true; + }else{ + $data = array("error"=>"处理中出现错误"); + $this->jsonexit($data); + return true; + } + } + + else if($delete) + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + + //需要删除文件,通过Zend_Registry::get('upload')获得上传文件的根目录 + + $basepath = $this->view->config->upload; + + //从数据库获取文件路径 + + $info = $this->getFileinfo($delete); + + $filepath = $basepath.$info['filename']; + + $sql = "SELECT * FROM mdattach WHERE id=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($delete)); + $rows = $sth->fetchAll(); + + if(count($rows)>0) + { + $data = array("error"=>'删除失败!该文件有元数据附件信息,不能直接删除',"status"=>0); + $this->jsonexit($data); + return true; + } + + $sql = "SELECT * FROM mdreviewattach WHERE attachid=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($delete)); + $rows = $sth->fetchAll(); + + if(count($rows)>0) + { + $data = array("error"=>'删除失败!该文件有对应评审附件信息,不能直接删除',"status"=>0); + $this->jsonexit($data); + return true; + } + + $sql = "SELECT link FROM reference WHERE link!=''"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $rows = $sth->fetchAll(); + + $ids = array(); + foreach($rows as $k=>$v) + { + if(preg_match("/service/i",$v['link'])) + { + $ids[] = str_replace("/service/attach/id/","",$v['link']); + } + unset($rows[$k]); + } + unset($rows); + + if(in_array($delete,$ids)) + { + $data = array("error"=>'删除失败!该文件有对应文献附件信息,不能直接删除',"status"=>0); + $this->jsonexit($data); + return true; + } + + if(unlink($filepath)) + { + $sql = "delete from attachments where id='$delete'"; + if($this->db->exec($sql)>0) + { + $data = array("status"=>1); + $this->jsonexit($data); + return true; + } + } + else + { + $sql = "delete from attachments where id='$delete'"; + if($this->db->exec($sql)>0) + { + $data = array("error"=>'文件删除失败,仅删除数据库记录,请手动删除文件:'.$info['filename'],"status"=>0); + $this->jsonexit($data); + return true; + } + } + + }//删除 + + 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 if ($down>0) + { + + $sql = "select * from attachments where id='$down'"; + + $re = $this->db->query($sql); + + $row = $re->fetch(); + + $file = new files(); + + $fullPath = $this->view->config->upload.$row['filename']; + + + // Parse Info / Get Extension + $fsize = filesize($fullPath); + $path_parts = pathinfo($fullPath); + $ext = strtolower($path_parts["extension"]); + + // Determine Content Type + switch ($ext) { + case "pdf": $ctype="application/pdf"; break; + case "exe": $ctype="application/octet-stream"; break; + case "zip": $ctype="application/zip"; break; + case "doc": $ctype="application/msword"; break; + case "xls": $ctype="application/vnd.ms-excel"; break; + case "ppt": $ctype="application/vnd.ms-powerpoint"; break; + case "gif": $ctype="image/gif"; break; + case "png": $ctype="image/png"; break; + case "jpeg": + case "jpg": $ctype="image/jpg"; break; + default: $ctype="application/force-download"; + } + + $content=file_get_contents($fullPath); + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $this->getResponse()->setHeader('Content-Type', 'application/octet-stream') + ->setHeader('Content-Disposition','attachment; filename="'.basename($fullPath).'"') + ->setHeader('Content-Length', $fsize) + ->setHeader('Content-Type','application/force-download') + ->setHeader('Content-Type','application/download') + ->setHeader('Content-Type',$ctype) + ->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); + + //$sql = "update attachments set downtimes=downtimes+1 where id='$down'"; + //$this->db->exec($sql); + + }//附件下载 + + else + { + + $sql="select * from attachments order by id desc"; + $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 附件 + + function uploadAction(){ + $this->_helper->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $uuid = $this->_getParam('uuid'); + + try{ + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $userid = $user->id; + } + + if(empty($userid)||!is_numeric($userid)){ + $msg['error'] = "请先登录"; + echo Zend_Json::encode($msg); + exit(); + } + + if($user->usertype!='administrator') + { + $msg['error'] = "您无权使用此功能"; + echo Zend_Json::encode($msg); + exit(); + } + + $files=new Files(); + $msg = $files -> upload($_FILES['Filedata'],empty($uuid)?'file/':'md/',true); + + if(empty($msg['error'])) + { + $msg['error']=""; + $filename = $msg['db_path']; + $filesize = $msg['file_size']; + $filedesc = $this->_request->getParam('filedesc'); + $filetype = 'md'; + $realname = $msg['realname']; + + + $sql = "insert into attachments (filename,filetype,filedesc,userid,filesize,realname) values ('$filename','$filetype','$filedesc','$userid','$filesize','$realname') RETURNING id"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $att = $sth->fetch(PDO::FETCH_ASSOC); + $msg['attid'] = $attid = $att['id']; + + $sql = "insert into mdattach (uuid,id) values ('$uuid','$attid')"; + if(empty($uuid) || $this->db->exec($sql)) + { + $msg['html'] = $realname.'['. round($filesize/1024,2) .' kb]
      '; + echo Zend_Json::encode($msg); + exit(); + }else{ + $msg['error'] = '附件上传失败:写入附件表出错'; + @unlink($filename); + echo Zend_Json::encode($msg); + exit(); + } + + + }else{ + $msg['error'] = '附件上传失败:'.$msg['error']; + @unlink($filename); + echo Zend_Json::encode($msg); + exit(); + } + + }catch(Exception $e){ + $msg['error'] = "错误:".$e->getMessage(); + echo Zend_Json::encode($msg); + exit(); + } + }// uploadAction ajax上传附件 + + function getattsAction(){ + + $this->_helper->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $uuid = $this->_request->getParam('uuid'); + + if($uuid!='') + { + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $userid = $user->id; + $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' + ORDER BY a.ts_created ASC"; + $rs = $this->db->query($sql); + $atts = $rs->fetchAll(); + + echo Zend_Json::encode($atts); + exit(); + }else + { + exit(); + } + }else{ + exit(); + } + //不输出错误 + }//获取附件 + + + /* + versionAction 版本管理 + */ + + public function versionAction(){ + + $ac = $this->_request->getParam('ac'); + $uuid = $this->_request->getParam('uuid'); + set_time_limit(0); + + $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,g.id as gid FROM mdversion v + LEFT JOIN metadata md ON md.uuid=v.uuid + left join users u on v.userid=u.id + left join geonetworkmetadata g on md.uuid=g.uuid + 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,u.id 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'].'/service/doc/uuid/'.$row['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/'.$row['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" || $ac=="diff1") + { + $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(); + if ($ac=='diff') + { + $sql = "SELECT v.* FROM mdversion v + WHERE v.uuid=? and v.ts_created<=(select ts_created from mdversion where id=?) + ORDER BY v.ts_created DESC + LIMIT ?"; + $sth = $this->db->prepare($sql); + $sth -> execute(array($row['uuid'],$id,2)); + } else { + $sql = "SELECT v.* FROM mdversion v + WHERE v.uuid=? and (v.id=? or (v.ts_created<(select ts_created from mdversion where id=?) and changelog is not null)) + ORDER BY v.ts_created DESC + LIMIT ?"; + $sth = $this->db->prepare($sql); + $sth -> execute(array($row['uuid'],$id,$id,2)); + } + + $rows = $sth->fetchAll(); + + if(count($rows)<2) + { + $this->view->error = "对比失败:之前没有版本可以对比"; + return true; + } + + $this->view->info = $row; + $this->view->data = $rows; + + } + + + }//versionAction 版本控制 + + + /* + * authorAction() 数据作者 + * + * param string $ac //动作 + =add 添加 + =edit 编辑 + =update 更新 + =del 删除 + =list 列出所有数据作者 + + * param string $uuid //UUID + * + * return view|application-json + */ + public function authorAction(){ + + $ac = $this->_getParam('ac'); + $uuid = $this->_getParam('uuid'); + + if(empty($ac) && empty($uuid)) + { + + $keywords = $this->_request->getParam('q'); + if(!empty($keywords)) + $this->view->q = $keywords; + + $sql = "select md.id,md.title,md.uuid,count(a.userid) as c from metadata md + right JOIN mdauthor a ON md.uuid=a.uuid + "; + + if(!empty($keywords)) + { + $search=new SimpleSearch($keywords); + $where=$search->sql_expr(array("md.title")); + $sql.=' and ('.$where.")"; + } + + $sql .= "GROUP by md.id,md.title,md.uuid,md.ts_created + ORDER BY md.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 == 'add') + { + + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $username = $this->_getParam('username'); + $uuid = $this->_getParam('uuid'); + + if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid)) + { + $data = array("error"=>"uuid参数错误"); + $this->jsonexit($data); + return true; + } + + if(empty($username)) + { + $data = array("error"=>'请输入要添加为该数据作者的用户名'); + $this->jsonexit($data); + return true; + } + + $sql = "SELECT * FROM users WHERE username=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($username)); + $row = $sth->fetch(); + + if(empty($row['id']) || !isset($row['id'])) + { + $data = array("error"=>'您输入的用户名无任何对应用户'); + $this->jsonexit($data); + return true; + } + + $uid = $row['id']; + + $sql = "SELECT * FROM mdauthor WHERE userid=? AND uuid=?"; + $sth = $this->db->prepare($sql); + $sth->execute(array($row['id'],$uuid)); + $row = $sth->fetch(); + + if(!empty($row['id']) && $row['status']==1) + { + $data = array("error"=>'该用户已经是此数据的作者'); + $this->jsonexit($data); + return true; + } + + if(!empty($row['id']) && in_array($row['status'],array(0,-1)) ) + { + $sql = "UPDATE mdauthor SET status=1 WHERE uuid=? AND userid=?"; + $sth = $this->db->prepare($sql); + $ds = $sth->execute(array($uuid,$uid)); + if($ds) + { + $data = array("msg"=>'该用户已被提升为数据作者','added'=>1); + $this->jsonexit($data); + return true; + }else{ + $data = array("error"=>'处理中出现错误'); + $this->jsonexit($data); + return true; + } + } + + if(empty($row['id'])) + { + $sql = "INSERT INTO mdauthor (uuid,userid,status) VALUES (?,?,?)"; + $sth = $this->db->prepare($sql); + $ds = $sth->execute(array($uuid,$uid,1)); + if($ds) + { + $data = array("msg"=>'该用户已被添加为数据作者','added'=>1); + $this->jsonexit($data); + return true; + }else{ + $data = array("error"=>"处理中出现错误"); + $this->jsonexit($data); + return true; + } + } + + + $data = array("error"=>"处理中出现错误"); + $this->jsonexit($data); + return true; + + }//ajax 添加作者 + + + else if(($ac == "edit" || $ac=="") && !empty($uuid)) + { + + $window = $this->_getParam('window'); + + if($window == "iframe") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer('author-edit-iframe'); + }else{ + $this->_helper->viewRenderer('author-edit'); + } + + $sql = "SELECT a.*,md.title,u.realname,u.username FROM mdauthor a + LEFT JOIN metadata md ON a.uuid=md.uuid + LEFT JOIN users u ON a.userid=u.id + WHERE md.uuid=? + ORDER BY a.id DESC + "; + + $sth = $this->db->prepare($sql); + $sth->execute(array($uuid)); + $rows = $sth->fetchAll(); + + $this->view->authors = $rows; + + }// 作者管理弹窗 + + else if($ac == "del") + { + + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $id = $this->_getParam('id'); + + $sql = "DELETE FROM mdauthor WHERE id=?"; + $sth = $this->db->prepare($sql); + $ds = $sth->execute(array($id)); + if($ds) + { + $data = array("deleted"=>$id); + $this->jsonexit($data); + return true; + }else{ + $data = array("error"=>"处理中出现错误"); + $this->jsonexit($data); + return true; + } + + + }//移除作者 + + else if($ac == 'update') + { + + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $id = $this->_getParam('id'); + + $sql = "UPDATE mdauthor SET status=1 WHERE id=?"; + $sth = $this->db->prepare($sql); + $ds = $sth->execute(array($id)); + if($ds) + { + $data = array("updated"=>$id,'msg'=>'认证成功!'); + $this->jsonexit($data); + return true; + }else{ + $data = array("error"=>"处理中出现错误"); + $this->jsonexit($data); + return true; + } + + + }//认证作者 + + else if($ac =="list") + { + $this->_helper->viewRenderer('author-list'); + + $sql = "SELECT u.id,u.realname,u.email,count(a.id) as d FROM mdauthor a + LEFT JOIN users u ON a.userid=u.id + WHERE a.status>0 + GROUP BY u.id,u.realname,u.email + ORDER BY u.id 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 == "userdatas") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $id = $this->_getParam('id'); + + $sql = "SELECT md.title,md.uuid FROM mdauthor a + LEFT JOIN metadata md ON a.uuid=md.uuid + WHERE a.userid=? AND a.status>0 + ORDER BY a.ts_created"; + $sth = $this->db->prepare($sql); + $sth->execute(array($id)); + $rows = $sth->fetchAll(); + + $data = array("datas"=>$rows); + $this->jsonexit($data); + return true; + + }//用户数据 + + else if($ac == "datas") + { + $this->_helper->viewRenderer('author-datas'); + + $keywords = $this->_request->getParam('q'); + if(!empty($keywords)) + $this->view->q = $keywords; + + $sql = "select md.id,md.title,md.uuid,count(a.userid) as c from metadata md + left JOIN mdauthor a ON md.uuid=a.uuid + "; + + if(!empty($keywords)) + { + $search=new SimpleSearch($keywords); + $where=$search->sql_expr(array("md.title")); + $sql.=' WHERE '.$where; + } + + $sql .= "GROUP by md.id,md.title,md.uuid,md.ts_created + ORDER BY md.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; + + } + + }//authorAction() 数据作者管理 + + + //newdataAction() 新建元数据 + public 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(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $u_id = $user->id; + } + + //在geonetwork中查看单条数据 + if (!empty($id) && empty($ac)) + { + $this->view->url='metadata.show?id='.$id; + $this->_helper->viewRenderer('newdata-view'); + } + //查看所有的未提交数据列表 + else if((empty($ac) && empty($uuid))|| $ac=='list') + { + $sql = "SELECT (regexp_matches(gn.data,'(.*)'))[1] as title,gn.id,gn.uuid,u.username,u.realname FROM geonetworkmetadata gn left join users u on gn.owner=u.id + WHERE gn.uuid not in (select uuid from metadata) + order by gn.id 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=="import") + { + $this->_helper->viewRenderer('newdata-import'); + } + //从模板新建元数据 + else if($ac=="add-by-template") + { + $keywords = $this->_request->getParam('q'); + $sql="select id,(regexp_matches(data,'(.*)'))[1] as title,(owner-$u_id) as isowner from metadata where istemplate='y' and schemaid='iso19115'"; + if(!empty($keywords)) + { + $this->view->q = $keywords; + $search=new Search($keywords); + $where=$search->sql_expr(array("data")); + $sql.=' and '.$where; + } + $sql.=" order by changedate desc"; + $sth = $this->wdb->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('newdata-add'); + } + + else if($ac=="add-by-data") + { + $keywords = $this->_request->getParam('q'); + $sql = "SELECT md.title,md.uuid,md.description,gn.id as gid FROM normalmetadata md + left join geonetworkmetadata gn on md.uuid=gn.uuid + WHERE gn.id is not null"; + if(!empty($keywords)) + { + $this->view->q = $keywords; + $search=new Search($keywords); + $where=$search->sql_expr(array("md.title","md.description")); + $sql.=' and '.$where; + } + $sql.=" order by md.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(10); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); + $this->view->paginator=$paginator; + $this->_helper->viewRenderer('newdata-add-bydata'); + } + //元数据格式检查 + else if ($ac=="validate") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $data = ""; + $id = $this->_request->getParam('id'); + $sql="select uuid,data from geonetworkmetadata where id=?"; + $sth=$this->db->prepare($sql); + $sth->execute(array($id)); + $row=$sth->fetch(); + + $iso=new ISO19115(); + @$iso->loadXML($row['data']); + if ($iso->validate()) + { + $data=array("error"=>"元数据中发现错误。
      ".implode("
      ",$iso->error)); + $this->jsonexit($data); + return true; + } else { + $data=array("error"=>"元数据中没有发现错误。
      "); + $this->jsonexit($data); + return true; + } + } + //提交数据 + else if($ac=="commit") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $data = ""; + $id = $this->_request->getParam('id'); + try{ + 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. 权限认定:当前用户必须和其owner相同 + // 数据应当没有评审状态,没有作者信息 + $sql="select uuid,data from geonetworkmetadata where id=?"; + $sth=$this->db->prepare($sql); + $sth->execute(array($id)); + $row=$sth->fetch(); + if (empty($row)) + { + $data = array("error"=>'无权限修改数据'); + $this->jsonexit($data); + return true; + } + + // 保存数据作者信息 + + // 2. 保存变化记录 save changelog & userid for the latest version + $sql = "UPDATE mdversion SET changelog=?,userid=? WHERE id in (select v.id from mdversion v left join geonetworkmetadata g on v.uuid=g.uuid where g.id=? order by v.ts_created desc limit 1)"; + $this->db->query($sql,array($changelog,$u_id,$id)); + + // 3. 保存数据评审状态 + //导入元数据 + $iso=new ISO19115(); + @$iso->saveDB($this->db,$row['data']); + //进入评审库 + $sql="insert into mdstatus (uuid,status,userid) select uuid,0,? from geonetworkmetadata 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(); + + $data = array("commited"=>1,"error"=>'该版本已经成功提交,请等待数据中心进一步处理!'); + $this->jsonexit($data); + return true; + }catch(Exception $e) { + $sql="delete from mdstatus where uuid in (select uuid from geonetworkmetadata where id=?)"; + $this->db->query($sql,array($id)); + $msg = "提交失败,请确认权限后重试"; + if($this->debug>0) + {$msg .= $e->getMessage();} + $data = array("error"=>$msg); + $this->jsonexit($data); + return true; + } + } + + }// newdataAction() 新建元数据 + + /* + * projectsAction() 数据汇交计划 + * + * + * + * + */ + function projectAction() + { + include_once("Heihe.php"); + $heihe = new Heihe($this->db); + + $this->view->input_NameDefaultVal = "专家姓名"; + $this->view->input_EmailDefaultVal = "专家email"; + + $projectTable = $heihe->tbl_heiheproject; + + $ac = $this->_getParam('ac'); + + if(empty($ac) || $ac == "index") + { + $this->_helper->viewRenderer('project'); + + //Search Link + $this->view->searchLink = "/admin/heihe/project/ac/index/"; + + $q = $this->_getParam('q'); + + $wheresql = array(); + + if(!empty($q)) + { + $wheresql[] = " (title LIKE '%$q%' OR + code LIKE '%$q%' OR + name LIKE '%$q%' OR + email LIKE '%$q%')"; + $this->view->searchKeyword = $q; + } + + if(count($wheresql)>0) + { + $wheresql = join(" AND ",$wheresql); + }else{ + $wheresql = ""; + } + + if(!empty($wheresql)) + { + $wheresql = " WHERE ".$wheresql; + } + + $sql = "SELECT * FROM $projectTable $wheresql + ORDER BY id ASC"; + $sth = $this->db->query($sql); + $rows = $sth->fetchAll(); + + foreach ($rows as $k=>$v) + { + $rows[$k]['status_alias'] = $heihe->getStatus($v['status']); + } + + $this->view->Count = count($rows); + + $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; + + $this->view->project_status = $heihe->project_status; + + return true; + }//ac == index + + //邀请专家 + if($ac == "invite") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $pid = $this->_getParam('id'); + $name = $this->_getParam('name'); + $email = $this->_getParam('email'); + + if(!is_numeric($pid)) + { + $this->jsonexit(array("error"=>"参数错误")); + return true; + } + + if(empty($name) || $name == $this->view->input_NameDefaultVal) + { + $this->jsonexit(array("error"=>"请输入专家姓名")); + return true; + } + + if(empty($email) || $email == $this->view->input_EmailDefaultVal) + { + $this->jsonexit(array("error"=>"请输入专家Email")); + return true; + } + + $code = $heihe->makeValidation($email); + + $expert_data = array( + "name"=>$name, //专家姓名 + "email"=>$email, //专家email + "created"=>date("Y-m-d H:i:s",time()), //邀请时间 + "validation"=>$code, //验证码 + ); + + $rs = $heihe->expertAdd($pid,$expert_data); + + if($rs > 0) + { + $this->sendMailToExpert($pid,$name,$email,$code);// 最后再加入一个非0的数字型参数即可使用调试邮箱发送 + $this->jsonexit(array("msg"=>"专家邀请成功!","invited"=>1)); + return true; + }else if($rs==-1){ + $this->jsonexit(array("error"=>"该专家已经邀请过")); + return true; + }else{ + $this->jsonexit(array("error"=>"邀请失败,请重试")); + return true; + } + + return true; + }// 邀请专家 + + if($ac == "showexpert") + { + + $this->_helper->layout->setLayout('layout-iframe'); + $this->_helper->viewRenderer('project-showexpert'); + + $pid = $this->_getParam('id'); + + if(empty($pid) || !is_numeric($pid)) + { + $this->view->error = "参数错误"; + return true; + } + + $this->view->pid = $pid; + + $experts = $heihe->expertRead($pid); + + if(!is_array($experts)) + { + $this->view->error = "此项目还没有邀请专家"; + return true; + } + + foreach($experts as $k=>$v) + { + $experts[$k]['url'] = $heihe->makeInviteLink($pid,$v['validation']); + } + + $this->view->experts = $experts; + + return true; + }//ac == showexpert 查看跟踪专家 + + if($ac == "remove") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $pid = $this->_getParam('id'); + $del = $this->_getParam('del'); + + if(!empty($del) && !empty($pid)) + { + + $rs = $heihe->expertRemove($pid,$del); + + if($rs) + { + $this->jsonexit(array("deleted"=>1)); + return true; + }else{ + $this->jsonexit(array("error"=>"删除失败,请重试")); + return true; + } + + }else{ + $this->jsonexit(array("error"=>"参数错误,请刷新")); + return true; + } + + }//ac == remove 删除专家 + + if($ac == "upload") + { + $this->_helper->layout->setLayout('layout-iframe'); + $this->_helper->viewRenderer('project-upload'); + + $submit = $this->_getParam('submit'); + + $pid = $this->_getParam('pid'); + + if(empty($pid) || !is_numeric($pid)) + { + $this->view->error = "参数错误"; + return true; + } + + $this->view->pid = $pid; + + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $uid = $user->id; + } + + if(!empty($submit) && empty($this->view->error)) + { + + $files=new files(); + $msg = $files -> upload($this->view->config->upload,$_FILES['Filedata'],'heihe'); + + if(empty($msg['error'])) + { + $msg['error']=""; + $filename = $msg['db_path']; + $filesize = $msg['file_size']; + $filedesc = $this->_request->getParam('filedesc'); + $filetype = $msg['file_type']; + $realname = $msg['realname']; + + if(!empty($row['attachid'])) + { + $sql = "SELECT * FROM attachments WHERE id={$row['attachid']}"; + $sth = $this->db->query($sql); + $attach = $sth->fetch(); + $this->db->exec("DELETE FROM attachments WHERE id={$row['attachid']} AND filetype='heihe'"); + @unlink($this->view->config->upload.$attach['filename']); + } + + $sql = " INSERT INTO attachments (filename,filetype,filedesc,userid,filesize,realname) values + ('$filename','heihe','$filedesc','$uid','$filesize','$realname') RETURNING id"; + $sth = $this->db->prepare($sql); + $sth->execute(); + $att = $sth->fetch(PDO::FETCH_ASSOC); + $msg['attid'] = $attid = $att['id']; + + $sql = "UPDATE heiheproject SET attachid=$attid WHERE id=$pid"; + $sth = $this->db->exec($sql); + + if($sth) + { + $this->view->message = "上传成功"; + }else{ + @unlink($filename); + $this->view->error = '附件上传失败:写入附件表出错'; + return true; + } + }else{ + @unlink($filename); + $this->view->error = "附件上传失败".$msg['error']; + return true; + } + } + + $sql = "SELECT * FROM heiheproject WHERE id=$pid"; + $sth = $this->db->query($sql); + $row = $sth->fetch(); + + if(!empty($row['attachid'])) + { + $sql = "SELECT * FROM attachments WHERE id = {$row['attachid']}"; + $sth = $this->db->query($sql); + $this->view->att = $sth->fetch(); + } + + return true; + }//ac == upload + + //改变状态 + if($ac == "changestatus") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $project = $this->_getParam('p'); + $status = $this->_getParam('s'); + + if(!is_numeric($status)) + { + $this->jsonexit(array('error'=>'参数错误')); + return true; + } + + $code = $heihe->ChangeStatus($project,$status); + + if($code > 0) + { + $this->jsonexit( + array( + 'msg'=>'修改成功!', + 'status'=>$heihe->getStatus($status) + ) + ); + return true; + }else{ + $this->jsonexit(array('error'=>'参数错误')); + return true; + } + + }//ac == "changestatus" + + }//projectsAction() + + public function fundAction() + { + $this->_helper->layout->setLayout('administry'); + $ac = $this->_getParam('ac'); + $submit = $this->_getParam('submit'); + $this->view->q = $keyword = $this->_getParam('q'); + + include_once("helper/view.php"); + include_once("data/Fund.php"); + $fund = new Fund($this->db); + + $auth = Zend_Auth::getInstance(); + if($auth->hasIdentity()) + { + $user = $auth->getIdentity(); + $uid = $user->id; + } + + if($ac=='index' || empty($ac)) + { + $uuid = $this->_getParam('uuid'); + if(empty($uuid)) + { + $rows = $fund->fetch(NULL,true,0,$keyword); + view::addPaginator($rows,$this,10); + }else{ + include('data/Metadata.php'); + $md = new Metadata($this->db); + $this->view->md = $md->view($uuid); + $rows = $fund->fetch($uuid); + view::addPaginator($rows,$this,10); + } + return true; + } + + if($ac == 'datalist') + { + $this->_helper->viewRenderer('fund-data-list'); + $this->view->q = $q = $this->_getParam('q'); + $rows = $fund->fetchFromData(true,0,$q); + view::addPaginator($rows,$this,10); + return true; + } + + if($ac == 'dataview') + { + $this->_helper->viewRenderer('fund-data-view'); + $this->view->q = $q = $this->_getParam('q'); + $id = $this->_getParam('id'); + $this->view->fund = $fund->view($id); + $rows = $fund->fetchFromData($id,0,$q); + view::addPaginator($rows,$this,10); + return true; + } + + if($ac == "add") + { + $this->_helper->viewRenderer('fund-add'); + if(!empty($submit)) + { + $data = $fund->_getParams($this->_request); + $data['userid'] = $uid; + + if($fund->add($data) == true) + { + $this->view->AlertType = "alert-success"; + $this->view->msg = "添加成功!"; + $this->view->jump_url = "/admin/data/fund/"; + return true; + }else{ + $this->view->data = $data; + $this->view->error = "添加失败,请重试"; + return true; + } + } + return true; + }//add + + if($ac == "edit") + { + $this->_helper->viewRenderer('fund-add'); + $id = $this->_getParam('id'); + + if(empty($id)) + { + $this->view->AlertType = "alert-error"; + $this->view->msg = "参数错误"; + $this->view->jump_url = "/admin/data/fund/"; + } + + if(!empty($submit)) + { + $data = $fund->_getParams($this->_request); + $data['userid'] = $uid; + if($fund->update($data,$id) == true) + { + $this->view->AlertType = "alert-success"; + $this->view->msg = "修改成功!"; + $this->view->jump_url = "/admin/data/fund/"; + return true; + }else{ + $this->view->data = $data; + $this->view->error = "修改失败,请重试"; + return true; + } + }else{ + $this->view->data = $fund->view($id); + } + return true; + }//edit + + if($ac == "del") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $id = $this->_getParam('id'); + + if(empty($id)) + { + $this->jsonexit(array('error'=>'参数错误')); + return true; + } + + if($fund->delete($id) == true) + { + $this->jsonexit(array('success'=>$id)); + return true; + }else{ + $this->jsonexit(array('error'=>'删除失败')); + return true; + } + + }//del + + if($ac == "formd") + { + $uuid = $this->_getParam('uuid'); + + if(empty($uuid)) + { + $this->view->AlertType = "alert-error"; + $this->view->msg = "参数错误"; + $this->view->jump_url = "/admin/data/fund/"; + } + + $id = $this->_getParam('id'); + $order = $this->_getParam('order'); + + if(!empty($id)) + { + if($fund->addToMdfund($uuid,$id,$order)) + { + $this->view->AlertType = "alert-success"; + $this->view->error = "添加成功!可以继续选择并添加"; + }else{ + $this->view->AlertType = "alert-error"; + $this->view->error = "添加失败!该数据可能已被添加"; + } + } + + $mfid = $this->_getParam('mfid'); + + if(!empty($mfid)) + { + if($fund->changeorder($mfid,$order)) + { + $this->view->AlertType = "alert-success"; + $this->view->error = "排序修改成功!"; + }else{ + $this->view->AlertType = "alert-error"; + $this->view->error = "排序修改失败!"; + } + $rows = $fund->fetch($uuid); + }else{ + $this->view->ct = "ct"; + $rows = $fund->fetch($uuid,false,0,$this->_getParam('q')); + } + + include('data/Metadata.php'); + $md = new Metadata($this->db); + $this->view->md = $md->view($uuid); + + view::addPaginator($rows,$this,10); + + return true; + }//formd + + if($ac == "mdfunddel") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $id = $this->_getParam('id'); + + if(empty($id)) + { + $this->jsonexit(array('error'=>'参数错误')); + return true; + } + + if($fund->mfdelete($id) == true) + { + $this->jsonexit(array('success'=>$id)); + return true; + }else{ + $this->jsonexit(array('error'=>'删除失败')); + return true; + } + }//mdfunddel + + if($ac == "data") + { + $this->_helper->viewRenderer('fund-data'); + + $id = $this->_getParam('id'); + $del = $this->_getParam('del'); + $this->view->info = $fund->view($id); + + if(!empty($del)) + { + $s = $fund->dataRelationDelete($del); + if($s) + { + $this->view->error = view::Error("删除成功!","alert-sccuess"); + }else{ + $this->view->error = view::Error("删除失败!","alert-error"); + } + } + + $rows = $fund->getData($id,$keyword); + view::addPaginator($rows,$this,10); + } + + }//fund + + public function visualAction() + { + $uuid = $this->_getParam('uuid'); + $submit = $this->_getParam('submit'); + + if(!empty($uuid)) + { + $this->_helper->viewRenderer('visual-add'); + $this->view->data = ['uuid' => $uuid]; + if(empty($submit)) + return true; + + + } + } + + public function doiAction() + { + $ac = $this->_getParam('ac'); + $submit = $this->_getParam('submit'); + $uuid = $this->_getParam('uuid'); + $q=$this->_getParam('q'); + + include_once("data/Doi.php"); + $doi = new Doi($this->db); + include_once("helper/view.php"); + + if( empty($ac) || $ac == "index") + { + if(empty($uuid)) + { + $rows = $doi->fetch(0,$q); + view::addPaginator($rows,$this,10); + }else{ + $this->_redirect('/admin/data/doi/ac/edit/?uuid='.$uuid); + return true; + } + return true; + }//index + + else if($ac == "add") + { + $this->_helper->viewRenderer('doi-add'); + + }//add + + else if($ac == "edit") + { + $this->_helper->viewRenderer('doi-add'); + $id = $this->_getParam('id'); + if(empty($uuid) && empty($id)) + { + view::Msg('alert-error',"参数错误",-1); + return false; + } + + if(empty($submit)){ + if(!empty($uuid)) + { + $this->view->uuid = $uuid; + $this->view->data = $doi->view($uuid); + include('data/Metadata.php'); + $md = new Metadata($this->db); + $metadata = $md->view($uuid); + if(empty($this->view->data)) + { + $this->view->data = array( + 'uuid'=>$uuid, + 'title'=>$metadata['title'], + 'doi'=>$metadata['doi'], + 'url'=>"http://" . $_SERVER['HTTP_HOST'].'/data/'.$uuid, + 'publisher'=>'寒区旱区科学数据中心', + 'title_en'=>$metadata['title_en'], + 'publisher_en'=>'Cold and Arid Regions Science Data Center at Lanzhou', + ); + }else{ + $this->view->data['doi'] = $metadata['doi']; + $this->view->data['info'] = $doi->data_process_out($this->view->data); + if(empty($this->view->data['ts_published'])) + { + $this->view->data['title'] = $metadata['title']; + $this->view->data['title_en'] = $metadata['title_en']; + } + } + }else{ + $this->view->data = $doi->view($uuid); + $this->view->data['info'] = $doi->data_process_out($this->view->data); + } + }else{ + $data = $doi->_getParams($this->_request); + $this->view->data = $data; + $info = $doi->checkinfo($data['info']); + if(!is_array($info)){ + $this->view->error = view::Error($info); + return true; + }else{ + $data['info'] = $info; + $data['info'] = $doi->sksort($data['info'],"order",SORT_ASC); + } + $state = $doi->update($data,$uuid); + if($state) + { + $this->view->msg = view::Msg('alert-success',"修改成功!",'/admin/data/doi/uuid/'.$uuid); + return false; + }else{ + $this->view->error = view::Error("修改失败"); + return false; + } + } + }//edit + + else if($ac == "del") + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + + $id = $this->_getParam('id'); + + if(empty($id)) + { + $this->jsonexit(array('error'=>'参数错误')); + return true; + } + + if($doi->delete($id) == true) + { + $this->jsonexit(array('success'=>$id)); + return true; + }else{ + $this->jsonexit(array('error'=>'删除失败')); + return true; + } + + }//del + else if ($ac=="convert") //转换为chinadoi所需元数据格式 + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $sql="select d.*,m.description from datadoi d left join metadata m on d.uuid=m.uuid where d.uuid='$uuid'"; + $row=$this->db->fetchRow($sql); + $timestamp=date('YmdHis'); + $authors=explode(',',substr($row['authors'],1,-1)); + $orgs=explode(',',substr($row['organization'],1,-1)); + $doi=' + + '.$timestamp.' + '.$timestamp.' + + ISTIC + tuy@istic.ac.cn + + ISTIC + + + + + '; + foreach($authors as $k=>$v) + { + $doi.=''.$v.''; + $doi.=''.$orgs[$k].''; + } + $doi.=' + + <![CDATA['.$row['title'].']]> + + '; + $doi.=''; + $doi.=''.$row['publisher'].''; + $doi.=' + '.$row['doi'].' + '.$timestamp.' + + '; + $doi.=' + + +'; + $this->getResponse()->setHeader('Content-Type', 'text/xml')->setHeader('Content-Disposition','attachment; filename="'.$row['uuid'].'.xml"') + ->setHeader('Content-Type','application/force-download')->setBody($doi); + $this->db->query('update datadoi set ts_submitted=now() where uuid=?',array($uuid)); + } + else if ($ac=="verified") //成功申请 + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $row=$this->db->fetchRow("select * from datadoi where uuid='$uuid'"); + $content=@file_get_contents("http://dx.doi.org/".$row['doi']); + if (strpos($content,$row['doi'])!==false) //成功申请 + { + $sql="update datadoi set ts_published=now() where uuid=? and ts_published is null"; + $this->db->query($sql,array($uuid)); + $this->jsonexit(array('success'=>'成功申请')); + } else + $this->jsonexit(array('success'=>'该DOI验证失败,请检查!')); + return true; + } + }//doi + + //发送邀请专家的邮件 + public function sendMailToExpert($pid,$name,$email,$code,$test=0) + { + include_once("Heihe.php"); + $heihe = new Heihe($this->db); + $url = $heihe->makeInviteLink($pid,$code); + + include_once("EmailText.php"); + $mailtp=new EmailText($this->db,"expert-invite",array( + 'name' => $name, + 'url' => $url, + )); + + echo $mailtp->getBody(); + echo $mailtp->getSubject(); + if($test == 0) + { + include_once("WestdcMailer.php"); + $mail=new WestdcMailer($this->view->config->smtp); + $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); + $mail->setBodyText($mailtp->getBody()); + $mail->setSubject($mailtp->getSubject()); + $mail->addTo($email); + $mail->send(); + }else{ + $mail_config = array( + 'ssl' => 'ssl', + 'port' => 465, + 'auth' => 'login', + 'username' => 'la5c@qq.com', + 'password' => '' + ); + $transport = new Zend_Mail_Transport_Smtp('smtp.qq.com', $mail_config); + Zend_Mail::setDefaultTransport($transport); + + $mail=new Zend_Mail(); + $mail->setBodyText($mailtp->getBody()); + $mail->setFrom('la5c@qq.com','Jack'); + $mail->addTo("la5c@qq.com"); + $mail->setSubject($mailtp->getSubject()); + $mail->send(); + } + }//发送邀请邮件 + + /* + 获得单个文件的信息 + 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数据到数据库 + */ + private function import($xml) + { + $iso=new ISO19115(); + $iso->saveDB($this->db,$xml); + } + + /* + * jsonexit() 退出并返回json数据 + * + * param array $data 要返回的JSON数据,可以是任意数组 + * + * return JSON-response + */ + public function jsonexit($data){ + $this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(json_encode($data,JSON_NUMERIC_CHECK)); + return true; + }//jsonexit() 退出并返回json数据 +} diff --git a/application/admin/views/scripts/data/left.phtml b/application/admin/views/scripts/data/left.phtml index c11dd3f4..c2e4447d 100644 --- a/application/admin/views/scripts/data/left.phtml +++ b/application/admin/views/scripts/data/left.phtml @@ -18,4 +18,5 @@
    • 特色推荐
    • -->
    • 专题管理
    • 支持项目
    • +
    • 可视化数据
    • \ No newline at end of file diff --git a/application/admin/views/scripts/data/md.phtml b/application/admin/views/scripts/data/md.phtml index b44a4935..5a25f514 100644 --- a/application/admin/views/scripts/data/md.phtml +++ b/application/admin/views/scripts/data/md.phtml @@ -66,7 +66,8 @@ 邮件通知 | 支持项目 | - DOI + DOI | + 数据可视化

      数据贡献者:

      diff --git a/application/admin/views/scripts/data/visual-add.phtml b/application/admin/views/scripts/data/visual-add.phtml new file mode 100644 index 00000000..02726a20 --- /dev/null +++ b/application/admin/views/scripts/data/visual-add.phtml @@ -0,0 +1,45 @@ +headTitle($this->config->title->site); + $this->headTitle('后台管理'); + $this->headTitle()->setSeparator(' - '); + $this->breadcrumb('首页'); + $this->breadcrumb('后台首页'); + $this->breadcrumb('数据管理'); + $this->breadcrumb('同步GEONETWORK元数据'); + $this->breadcrumb()->setSeparator(' > '); +?> +
      +
      + partial('data/left.phtml'); ?> +
      + +
      +

      添加可视化要素

      +
      +
      +
      + +
      + +
      +
      +
      + +
      + +
      +
      +
      +
      + + +
      +
      +
      +
      +
      + diff --git a/application/admin/views/scripts/data/visual.phtml b/application/admin/views/scripts/data/visual.phtml new file mode 100644 index 00000000..ad30c23d --- /dev/null +++ b/application/admin/views/scripts/data/visual.phtml @@ -0,0 +1,20 @@ +headTitle($this->config->title->site); + $this->headTitle('后台管理'); + $this->headTitle()->setSeparator(' - '); + $this->headLink()->appendStylesheet('/css/admin.css'); + $this->breadcrumb('首页'); + $this->breadcrumb('后台首页'); + $this->breadcrumb('数据管理'); + $this->breadcrumb('同步GEONETWORK元数据'); + $this->breadcrumb()->setSeparator(' > '); +?> +
      +
      + partial('data/left.phtml'); ?> +
      + +
      + +
      +
      diff --git a/application/module/Westdc/Visual/Handle/VisualHandle.php b/application/module/Westdc/Visual/Handle/VisualHandle.php new file mode 100644 index 00000000..566e92e3 --- /dev/null +++ b/application/module/Westdc/Visual/Handle/VisualHandle.php @@ -0,0 +1,43 @@ +db = \Zend_Registry::get('db'); + + + $this->config = \Zend_Registry::get('config'); + $this->table = new Table(); + } + + public function deleteAuthor(\Zend_EventManager_Event $e) + { + $id = $e->getParam('id'); + + $ref = new Reference(); + + return $ref->deleteReferenceAuthor($id); + } + + public function deleteTag(\Zend_EventManager_Event $e) + { + $id = $e->getParam('id'); + + $ref = new Reference(); + + return $ref->deleteReferenceTag($id); + } +} \ No newline at end of file diff --git a/application/module/Westdc/Visual/Listener/VisualListener.php b/application/module/Westdc/Visual/Listener/VisualListener.php new file mode 100644 index 00000000..b5bcf3f5 --- /dev/null +++ b/application/module/Westdc/Visual/Listener/VisualListener.php @@ -0,0 +1,27 @@ +event = new \Zend_EventManager_EventManager(); + } + + public function attach(\Zend_EventManager_EventCollection $events) + { + $Handler = new ReferenceHandler(); + $events->attach('submit.checkParam', array($Handler, 'checkReferenceParam'), 100); + $events->attach('submit.processData', array($Handler, 'processReferenceData'), 100); + $events->attach('submit.recordPosted', array($Handler, 'recordPosted'), 100); + $events->attach('submit.recordChanged', array($Handler, 'recordChanged'), 100); + } + + public function detach(\Zend_EventManager_EventCollection $events) + { + + } + +} diff --git a/application/module/Westdc/Visual/Visual.php b/application/module/Westdc/Visual/Visual.php new file mode 100644 index 00000000..e97bfae8 --- /dev/null +++ b/application/module/Westdc/Visual/Visual.php @@ -0,0 +1,86 @@ +db = \Zend_Registry::get('db'); + $Listener = new Listener(); + @$this->getEventManager()->attachAggregate($Listener); + + } + + public function getEventManager(\Zend_EventManager_EventCollection $events = NULL) + { + if ($events !== NULL) { + $this->events = $events; + } elseif ($this->events === NULL) { + $this->events = new \Zend_EventManager_EventManager(__CLASS__); + } + return $this->events; + } + + //添加 + public function add($data,$id = 0) + { + $params = compact('data'); + $results = $this->getEventManager()->trigger('submit.checkParam', $this, $params); + $cache_data = $results->last(); + + if($cache_data !== true) + { + return $cache_data; + } + + $results = $this->getEventManager()->trigger('submit.processData', $this, $params); + $data = $results->last(); + + $dbh = new dbh(); + + if(empty($id)) + { + $id = $dbh->insert($this->mainTable,$data,true); + + if(!empty($id) && is_numeric($id)) + { + $this->getEventManager()->trigger('submit.recordPosted', $this, $params); + return true; + }else{ + if($id === false) + { + return '服务器开小差了,请稍后再试'; + }else{ + return '服务器处理中遇到错误,请联系管理员'; + } + } + }//add + + else{ + if(!$dbh->update($this->mainTable,$data," id=$id ",true)) + { + $this->getEventManager()->trigger('submit.recordChanged', $this, $params); + return "修改失败!请重试"; + }else{ + return true; + } + }//edit + + }// add() + + //删除 + public function del($id) + { + if(!is_numeric($id) || empty($id) || $id< 0) + { + return false; + } + + $sql = "DELETE FROM {$this->mainTable} WHERE id=$id"; + return $this->db->exec($sql); + } +} \ No newline at end of file From be99136c68bc4a8d4b9841504ab26f8c4ba0b507 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Tue, 27 May 2014 02:51:38 +0000 Subject: [PATCH 173/173] change visual-add.phtml --- application/admin/views/scripts/data/visual-add.phtml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/application/admin/views/scripts/data/visual-add.phtml b/application/admin/views/scripts/data/visual-add.phtml index 02726a20..f2d2f890 100644 --- a/application/admin/views/scripts/data/visual-add.phtml +++ b/application/admin/views/scripts/data/visual-add.phtml @@ -40,6 +40,12 @@