diff --git a/application/default/controllers/DataController.php b/application/default/controllers/DataController.php index cd4cc72e..bde2888b 100755 --- a/application/default/controllers/DataController.php +++ b/application/default/controllers/DataController.php @@ -1,157 +1,167 @@ db=Zend_Registry::get('db'); - $this->view->config = Zend_Registry::get('config'); - $this->messenger=$this->_helper->getHelper('FlashMessenger'); - $this->view->messages = $this->messenger->getMessages(); +class DataController extends Zend_Controller_Action { + private $limit = 10; + + function preDispatch () { + $this->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), + 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(); + 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); + $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 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); + + 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 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 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 submitAction () { + $archives = new Archive($this->db); + $this->view->item = $archives->getOneArchive('如何发布数据', 'help'); } - function serviceAction() - { + + 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; + + 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); - /* + 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, @@ -159,271 +169,272 @@ class DataController extends Zend_Controller_Action '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); - } - } + $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 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 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 normalmetadata'); - $row=$state->fetchAll(); - $sum=$row[0]['count']; - $select=$this->db->select(); - $select->from('normalmetadata','*')->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(); + 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 normalmetadata'); + $row = $state->fetchAll(); + $sum = $row[0]['count']; + $select = $this->db->select(); + $select->from('normalmetadata', '*')->order('id desc')->limitPage($page, $limit); + $this->view->metadata = $this->db->fetchAll($select); + $this->view->page = new Pagination($sum, $page, $limit); + } - 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 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 as m', '*') + ->join('keyword', 'm.id=keyword.id') + ->join('mdstat as ms', 'ms.uuid=m.uuid', 'viewed') + ->where('keyword.keyword=?', $key) + ->order('m.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 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() - { + 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 { - //提供全部分类列表 - } - } - /* + $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); - } + 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 extentAction() - { - //use json & openlayers? - $id=(int)$this->_request->getParam('id'); - if ($id>0) $this->view->params="/id/$id"; - } - /* + function extentAction () { + //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 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); - } - /* + 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 + 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; @@ -431,203 +442,223 @@ class DataController extends Zend_Controller_Action // 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->view->xml = $proc->transformToXML($xml); + //$this->_helper->layout->disableLayout(); + //$this->_helper->viewRenderer->setNoRender(); //$this->getResponse()->setHeader('Content-Type', 'text/html') - // ->setBody($proc->transformToXML($xml)); - } + // ->setBody($proc->transformToXML($xml)); + } - /* + /* * 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; - } - } - /* + 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; + 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; - } - } - /* + $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 + 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; - } - + 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"; - $sql=$this->db->quoteInto($sql,$uuid); - $this->view->dataref=$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=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 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"; + $sql = $this->db->quoteInto($sql, $uuid); + $this->view->dataref = $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=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); + $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 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); + $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); + $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"; @@ -637,10 +668,8 @@ class DataController extends Zend_Controller_Action $this->view->version = $row; $archives = new Archive($this->db); $data_archives = $archives->getArchiveByUUID($uuid); - if(!empty($data_archives)) - { - foreach($data_archives as $k=>$v) - { + if (!empty($data_archives)) { + foreach ($data_archives as $k => $v) { $data_archives[$k]['url'] = $archives->getArchiveUrlByCid($v['id']); } } @@ -649,191 +678,191 @@ class DataController extends Zend_Controller_Action include_once("data/Fund.php"); $fund = new Fund($this->db); $this->view->fund = $fund->fetch($uuid); - + $visual = new \Westdc\Visual\Visual; $this->view->visual = $visual->getVisualVars($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 - + $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) - { + private function checkDataService ($uuid) { $order = new \Order\Mount\OrderOperate(); $service = $order->getDataService($uuid); - - if(empty($service)) - { + + if (empty($service)) { return NULL; - }else{ - if($order->checkOrderHas($uuid)) - { + } else { + if ($order->checkOrderHas($uuid)) { return NULL; - }else{ + } else { return $service; } } }//checkDataService - + //特殊数据服务 - public function dataserviceAction() - { - + public function dataserviceAction () { + $uuid = $this->_getParam('uuid'); - - if(empty($uuid)) - { - $this->jsonexit(array("error"=>"参数错误")); + + 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回调函数 + "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"=>'数据接口错误,请联系管理员')); + + $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'])); + + 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() - { + + 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') - { + + if ($type == 'var') { $sites = array( - "chk"=>$this->_getParam("siteid") + "chk" => $this->_getParam("siteid") ); - + $info = $dataservice->get($uuid); - + $data = array( - "type"=>"wsn", //服务类型 - "info"=>$info, //信息 dataservice 表中的字段 - "callback"=>"westdc.dataservice.wsn.Submit()", //成功后的js回调函数 + "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"=>'数据接口错误,请联系管理员')); + + $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'])); + + if (!is_array($data['data'])) { + $this->jsonexit(array("error" => $data['data'])); + return true; } - + $this->jsonexit($data); + return true; } - - if($type == "submit") - { + + 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回调函数 + "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"=>'数据接口错误,请联系管理员')); + + $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'])); + + 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)); + $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(){ - + function getversionAction () { + $ac = $this->_getParam('ac'); $uuid = $this->_getParam('uuid'); - - if($ac == 'list') - { + + 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 @@ -842,220 +871,214 @@ class DataController extends Zend_Controller_Action $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']); + + 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); + $data = array("list" => $rows); $this->jsonexit($data); + return true; - }else{ - $data = array("error"=>"处理中出现错误"); + } else { + $data = array("error" => "处理中出现错误"); $this->jsonexit($data); + return true; } } - + }//getversionAction() - - function replace($string){ - $patterns = array("/\"/i","/\'/i"); - $replacements = array("“","‘"); + + function replace ($string) { + $patterns = array( + "/\"/i", + "/\'/i" + ); + $replacements = array( + "“", + "‘" + ); ksort($patterns); ksort($replacements); + return preg_replace($patterns, $replacements, $string); }//引号替换 - - - function postcommentAction(){ + + + 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( - '<'=>'<', - '>'=>'>', - ); + try { + $auth = Zend_Auth::getInstance(); + if ($auth->hasIdentity()) { + $user = $auth->getIdentity(); + $userid = $user->id; + } else { + $userid = 0; + } - $patterns = array(); - $replacements = array(); - foreach($data as $k=>$v) - { - $patterns[]='/'.$k.'/i'; - $replacements[]=$v; + $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(); } - ksort($patterns); - ksort($replacements); - $content=preg_replace($patterns, $replacements, $content); - if(!empty($url)) - { - $url=preg_replace($patterns, $replacements, $url); + + if (strlen($author) < 3) exit("姓名长度不得少于2个汉字 :)"); + + if (empty($email)) { + echo "请输入您的电子邮箱地址"; + exit(); } - } - - 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']); + + 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); } } - @$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(); + + 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){ + catch (Exception $e) { echo "出错了,请稍后再试"; exit(); } }//ajax评论 - - + + /* * 数据评论,根据UUID读取 */ - function commentAction() - { + 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)); - + $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) - { + 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 @@ -1066,781 +1089,739 @@ class DataController extends Zend_Controller_Action $sth->execute(array($c['id'])); $replys = $sth->fetchAll(); $replyhtml = ""; - if(!empty($replys) || count($replys)>0) - { - foreach($replys as $v) - { + if (!empty($replys) || count($replys) > 0) { + foreach ($replys as $v) { $usertype = ""; $color = ""; - if($v['usertype'] == "administrator") - { + if ($v['usertype'] == "administrator") { $usertype = "[管理员]"; - $color="#009d00"; + $color = "#009d00"; } - if($v['uuid'] == $uuid) - { + if ($v['uuid'] == $uuid) { $usertype = "[数据作者]"; - $color="#add2e9"; + $color = "#add2e9"; } - if(!empty($color)) - { - $color = 'background:'.$color.';color:#FFFFFF;'; + if (!empty($color)) { + $color = 'background:' . $color . ';color:#FFFFFF;'; } - $img = $avatar->Get($v['email'],48); - $replyhtml .=' + $img = $avatar->Get($v['email'], 48); + $replyhtml .= '

- +
- 回复于'.date('Y-m-d H:i:s',strtotime($v['ts_created'])).' -
'.$v['username'].' '.$usertype.'
- '.$v['body'].' + 回复于' . date('Y-m-d H:i:s', strtotime($v['ts_created'])) . ' +
' . $v['username'] . ' ' . $usertype . '
+ ' . $v['body'] . '
'; } } - - $img = $avatar->Get($c['email'],64); + + $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'])).''; + $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.' + ' . $time . ' +

' . $c['author'] . '

+ ' . $c['content'] . ' + ' . $replyhtml . '
'; } - echo '
'.$paginator.'
'; + echo '
' . $paginator . '
'; }//else echo "
  • No comments.
  • "; }//评论列表 - + /** - * 判断用户是否填写了申请信息 - * @param string $uuid - * @param int $userid - */ - function todownloadAction() { - + * 判断用户是否填写了申请信息 + * @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'); - + + $this->view->uuid = $uuid = $this->_request->getParam('uuid'); + $auth = Zend_Auth::getInstance(); - if (!$auth->hasIdentity()) - { + if (!$auth->hasIdentity()) { $this->view->AlertType = "alert-error"; $this->view->msg = "请先登录您的账户后进行下载,页面将自动跳转"; - $this->view->jump_url = '/account/login/?href=/data/todownload/uuid/'.$uuid; + $this->view->jump_url = '/account/login/?href=/data/todownload/uuid/' . $uuid; + return true; } - if(empty($uuid)) - { + 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计划课题", - "国家级科技支撑课题" => "国家级科技支撑课题", - "国家级科技重大专项" => "国家级科技重大专项", - "国家级国家重大工程" => "国家级国家重大工程", - "国家级国家自然科学基金" => "国家级国家自然科学基金", - "国际合作项目"=>"国际合作项目", - "省部级项目" => "省部级项目", - "其他项目工程" => "其他项目工程", - ); - + "请选择项目类型" => "", + "国家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'); - + 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)) - { + + foreach ($datas as $k => $v) { + if (empty($v)) { $this->view->error = "每一项内容都需要填写"; + return true; } } - - if(!is_numeric($datas['postcode'])) - { + + if (!is_numeric($datas['postcode'])) { $this->view->error = "联系电话和邮政编码请填写数字"; + return true; } - - if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i",$datas['email'])) - { + + 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) - { + + if (mb_strlen($datas['project'], "utf-8") < 8) { $this->view->error = "项目介绍内容不少于8个字符"; + return true; } - - if(preg_match('/^\d+$/',$datas['project'])) - { + + 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)) - { + '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(); - + $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."\">或点击这里进入下载页面"; - + $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); - + message::post($this->db, 0, -1, $title, $msg); + return true; - } - else { + } 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); + } 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'])) - { + 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']; + } 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.''; + + $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.''; + + if (!is_numeric($datas['postcode'])) { + echo $form . ''; exit(); } - - if(!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i",$datas['email'])) - { - echo $form.''; + + 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.''; + + if (mb_strlen($datas['project'], "utf-8") < 8) { + echo $form . ''; exit(); } - - if(preg_match('/^\d+$/',$datas['project'])) - { - echo $form.''; + + 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)) - { + '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(); + $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); + message::post($this->db, 0, -1, $title, $msg); + exit(); + } else { + echo $form . ''; 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); + + } 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); + 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']; + + $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(); } - 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'); + function downloadAction () { + $uuid = $this->_request->getParam('uuid'); + $onlineappid = $this->_request->getParam('onlineappid'); $this->view->pageID = "account-dataorder"; - - if (empty($uuid)) $this->_redirect('/data'); - + + if (empty($uuid)) $this->_redirect('/data'); + $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { + 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); + + $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'])) - { + $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) {} + '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; - //更新下载记录 + $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) - { + }*/ + 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:请注意登陆后要手工进入对应的目录!':'' + "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); + $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->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); + $sql = "update onlineapp set has_send_mail=true where id=?"; + $sth = $this->db->prepare($sql); $sth->execute(array($onlineappid)); } } - /* + + /* * 离线申请(可以包括在线数据),在无数据参数时,则显示已有列表 */ - function orderAction() - { + function orderAction () { $this->view->pageID = "account-dataorder"; $ac = $this->_request->getParam('ac'); - - $uuid = $this->_request->getParam('uuid'); - - $del = $this->_request->getParam('del'); + + $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 (empty($uuid)) $this->_redirect('/data'); + $userid = view::User('id'); + //添加到数据篮 - if ($uuid) - { - //存在历史遗留问题,原来的数据并不能保证唯一 - + 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{ + + 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',"无法申请:此元数据的数据类型未知"); + 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',"添加成功!您可以继续浏览数据或是继续提交申请表"); + } 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',"无法申请:参数出错,请通过正确的途径访问"); + + 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',"添加成功!您可以继续浏览数据或是继续提交申请表"); + $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'; - } - - //删除申请 + + 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',"数据申请取消成功"); + if ($state !== true) { + $this->view->msg = view::Msg('alert-error', $state); + } else { + $this->view->msg = view::Msg('alert-success', "数据申请取消成功"); } - $this->_redirect('/data/order'); - } - - //提交申请 + $this->_redirect('/data/order'); + } //提交申请 elseif ($apply) { - if($apply == "all" || !is_numeric($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(); + $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) { + + if ($rows) { $this->_helper->viewRenderer('pdf'); - - $this->view->data2 = $rows; - + + $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'].";"; + $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); + + 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); + + 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'; + $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; + $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); + } else { + $this->view->msg = view::Msg('alert-error', "错误:您还没有提交任何离线申请的数据,或您的数据申请已经提交(等待处理过程中)!", 0); } + return true; - }//pdf - - if($ac == "commitapplicationform") - { + }//pdf + + if ($ac == "commitapplicationform") { $offlineappid = $this->_getParam('offlineappid'); - - if(!is_numeric($offlineappid) || $offlineappid < 1) - { - view::Post($this,"参数错误",-1); + + 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'); + + 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'; + 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 + $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)); - + $rows = $this->db->fetchAll($sql, array($userid)); + $showorders = array(); $counts = array( 'onlineapp' => 0, @@ -1849,43 +1830,41 @@ class DataController extends Zend_Controller_Action 'offline3' => 0, 'offline4' => 0 ); - - if(count($rows) > 0) { - foreach($rows as $k=>$v) - { - switch($v['status']) { + + if (count($rows) > 0) { + foreach ($rows as $k => $v) { + switch ($v['status']) { case 0: - $counts['onlineapp'] ++; + $counts['onlineapp']++; break; case 1: - $counts['offline1'] ++; + $counts['offline1']++; break; case 2: - $counts['offline2'] ++; + $counts['offline2']++; break; case 3: - $counts['offline3'] ++; + $counts['offline3']++; break; case 4: - $counts['offline3'] ++; + $counts['offline3']++; break; case 5: - $counts['offline4'] ++; + $counts['offline4']++; break; } - switch($ac){ + switch ($ac) { default : - if($v['status'] == 0 && !empty($v['ts_approved']))$showorders[] = $rows[$k]; + 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]; + if ($v['status'] == 0 && !empty($v['ts_approved'])) $showorders[] = $rows[$k]; break; case 'offline1' : - if($v['status'] == 1) $showorders[] = $rows[$k]; + if ($v['status'] == 1) $showorders[] = $rows[$k]; break; case 'offline2' : - if($v['status'] == 2) - { + if ($v['status'] == 2) { $showorders[] = $rows[$k]; $this->view->offlineappid = $v['offlineappid']; $this->view->applicationform = $v['applicationform']; @@ -1893,8 +1872,7 @@ class DataController extends Zend_Controller_Action } break; case 'offline3' : - if($v['status'] == 3 || $v['status'] == 4) - { + if ($v['status'] == 3 || $v['status'] == 4) { $showorders[] = $rows[$k]; $this->view->offlineappid = $v['offlineappid']; $this->view->applicationform = $v['applicationform']; @@ -1902,61 +1880,56 @@ class DataController extends Zend_Controller_Action } break; case 'offline4' : - if($v['status'] == 5) $showorders[] = $rows[$k]; + if ($v['status'] == 5) $showorders[] = $rows[$k]; break; } } } - + $this->view->counts = $counts; - view::addPaginator($showorders,$this,10); + 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 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(){ - + 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); + + 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"); + + if (empty($atts['id'])) { + $this->_redirect("/data/$uuid"); }//没有附件 - + $auth = Zend_Auth::getInstance(); - if($auth->hasIdentity()) - { + if ($auth->hasIdentity()) { /* $user = $auth->getIdentity(); $userid = $user->id; - $sql = "select d.* from dataorder d + $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'"; @@ -1969,162 +1942,148 @@ class DataController extends Zend_Controller_Action } 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压缩文件再输出 - $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."); + $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'])); } - - $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); - // } + } + $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 - { + else { $this->messenger->addMessage('您没有权限下载该附件'); $this->_redirect("/data/$uuid"); - }//未登陆 + }//未登陆 }//end if - else - { + else { $this->messenger->addMessage('您没有权限下载该附件'); $this->_redirect("/data/$uuid"); }//无权限 - + } - - /* + + /* * 西部计划项目及其数据产出 - */ - public function westeeAction() - { + */ + 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); - } + $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 pingbackAction () { + $this->_helper->ViewRenderer->setNoRender(); + $this->_helper->layout->disableLayout(); + $server = new Zend_XmlRpc_Server(); + $server->setClass('PingbackRpc', 'pingback'); + echo $server->handle(); + } - public function pingtestAction() - { + 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); + $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() - { + + 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); + $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)); + $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=?"; + $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(); @@ -2133,11 +2092,11 @@ class DataController 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; } - } 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"; + } 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(); @@ -2146,32 +2105,31 @@ class DataController 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; $this->_helper->viewRenderer('fund-list'); - } - } - + } + } + //实现基于DOI信息的浏览 - function doiAction() - { - $ac = $this->_request->getParam('ac'); - if ($ac=='unready') { - //列出没有DOI的数据 - $sql="select m.* from normalmetadata m where m.uuid not in (select uuid from datadoi) order by m.ts_created desc"; - $this->view->pageID='doi-unready'; - } 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 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 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 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'; - } + function doiAction () { + $ac = $this->_request->getParam('ac'); + if ($ac == 'unready') { + //列出没有DOI的数据 + $sql = "select m.* from normalmetadata m where m.uuid not in (select uuid from datadoi) order by m.ts_created desc"; + $this->view->pageID = 'doi-unready'; + } 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 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 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 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(); @@ -2180,82 +2138,80 @@ class DataController extends Zend_Controller_Action $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; - } - } + $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 + //基于数据作者的浏览(包括认证后的数据作者以及未认证的数据作者) + 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 @@ -2263,52 +2219,50 @@ 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 + $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 + $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 + $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 + $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); + $this->view->westee = $this->db->fetchAll($sql); } - + //可视化数据 - public function visualAction() - { + public function visualAction () { $visual = new \Westdc\Visual\Visual; - view::addPaginator($visual->getVisualMetadata(),$this,10); + view::addPaginator($visual->getVisualMetadata(), $this, 10); + return true; } - public function landuseAction() - { + + public function landuseAction () { $ac = $this->_request->getParam('ac'); - if (!empty($ac) && ($ac=='compare')) - { + if (!empty($ac) && ($ac == 'compare')) { $this->_helper->viewRenderer('landuse-compare'); } } - public function mapAction() - { + + public function mapAction () { $uuid = $this->_request->getParam('uuid'); - $sql="select d.*,m.title,m.description from datamap d left join normalmetadata m on d.uuid=m.uuid where d.status=1"; - if (!empty($uuid) && \Helpers\Uuid::test($uuid) !== false) - { - $sql.=" and d.uuid='$uuid'"; + $sql = "select d.*,m.title,m.description from datamap d left join normalmetadata m on d.uuid=m.uuid where d.status=1"; + if (!empty($uuid) && \Helpers\Uuid::test($uuid) !== false) { + $sql .= " and d.uuid='$uuid'"; $sth = $this->db->prepare($sql); $rs = $sth->execute(); $this->view->map = $sth->fetch(); } else { $sth = $this->db->prepare($sql); $rs = $sth->execute(); - view::addPaginator($sth->fetchAll(),$this,10); + view::addPaginator($sth->fetchAll(), $this, 10); $this->_helper->viewRenderer('map-list'); } }