debug = 1; $this->view->pageID = "heihe-".$this->_request->getActionName(); } function indexAction() { $sql="select m.uuid,m.title,m.id,m.description from normalmetadata m left join thumbnail t on m.id=t.id where m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and length(t.data)>2 order by random() limit 3"; $this->view->meatdata=$this->db->fetchAll($sql); } /* * 数据浏览 */ function browseAction() { $page=(int)$this->_request->getParam('page'); if (empty($page)) $page=1; $offset=$this->limit*($page-1); $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') "); $row=$state->fetchAll(); $sum=$row[0]['count']; $select=$this->db->select(); $select->from('normalmetadata','*')->where(" uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') ")->order('title desc')->limitPage($page,$this->limit); $this->view->metadata = $this->db->fetchAll($select); $this->view->page=new Pagination($sum,$page,$this->limit); $this->view->offset=$offset+1; } 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 where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') "); $row=$state->fetchAll(); $sum=$row[0]['count']; $select=$this->db->select(); $select->from('normalmetadata as m','m.*') ->where(" uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') ") ->order('m.title desc')->limitPage($page,$this->limit); $this->view->metadata = $this->db->fetchAll($select); $this->view->page=new Pagination($sum,$page,$this->limit); } function documentAction() { $page=(int)$this->_request->getParam('page'); if (empty($page)) $page=1; $offset=$this->limit*($page-1); $row=$this->db->fetchAll("select count(*) from reference where id in (select refid from mdref where uuid in (select uuid from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') ))"); $sum=$row[0]['count']; $sql="select * from reference where id in (select refid from mdref where uuid in (select uuid from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') )) order by reference limit ? offset ?"; $this->view->refs=$this->db->fetchAll($sql,array($this->limit,$offset)); $this->view->page=new Pagination($sum,$page,$this->limit,"文献"); $this->view->offset=$offset+1; } function baseAction() { $page=(int)$this->_request->getParam('page'); if (empty($page)) $page=1; $offset=$this->limit*($page-1); $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='theme' and (keyword='冰川' or keyword='沙漠' or keyword='地貌' or keyword='植被' or keyword='草场' or keyword='沙漠化' or keyword='基础地理' or keyword='遥感影像' or keyword='水文地质' or keyword='社会经济' or keyword='人口' or keyword='SWAT' or keyword='NPP' or keyword='WRF' or keyword='辐射' or keyword='NEP'))"); $row=$state->fetchAll(); $sum=$row[0]['count']; $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='theme' and (keyword='冰川' or keyword='沙漠' or keyword='地貌' or keyword='植被' or keyword='草场' or keyword='沙漠化' or keyword='基础地理' or keyword='遥感影像' or keyword='水文地质' or keyword='社会经济' or keyword='人口' or keyword='SWAT' or keyword='NPP' or keyword='WRF' or keyword='辐射' or keyword='NEP')) order by timebegin,title limit ? offset ?"; $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); $this->view->page=new Pagination($sum,$page,$this->limit); $this->view->offset=$offset+1; } function geobaseAction() { $this->getmd('基础地理'); } function coreAction() { $page=(int)$this->_request->getParam('page'); if (empty($page)) $page=1; $offset=$this->limit*($page-1); $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='theme' and (keyword='DEM' or keyword='土地利用' or keyword='土壤' or keyword='气象' or keyword='水文观测' or keyword='灌溉' or keyword='试验'))"); $row=$state->fetchAll(); $sum=$row[0]['count']; $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='theme' and (keyword='DEM' or keyword='土地利用' or keyword='土壤' or keyword='气象' or keyword='水文观测' or keyword='灌溉' or keyword='试验')) order by timebegin,title limit ? offset ?"; $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); $this->view->page=new Pagination($sum,$page,$this->limit); $this->view->offset=$offset+1; } function demAction() { $this->getmd('DEM'); } function rsAction() { $this->getmd('遥感影像'); } function waterAction() { $this->getmd('水文地质'); } function modelAction() { $page=(int)$this->_request->getParam('page'); if (empty($page)) $page=1; $offset=$this->limit*($page-1); $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='theme' and (keyword='WRF' or keyword='NPP' or keyword='SWAT' or keyword='NEP' or keyword='辐射'))"); $row=$state->fetchAll(); $sum=$row[0]['count']; $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='theme' and (keyword='WRF' or keyword='NPP' or keyword='SWAT' or keyword='NEP' or keyword='辐射')) order by timebegin,title limit ? offset ?"; $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); $this->view->page=new Pagination($sum,$page,$this->limit); $this->view->offset=$offset+1; } function economicAction() { $page=(int)$this->_request->getParam('page'); if (empty($page)) $page=1; $offset=$this->limit*($page-1); $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='theme' and (keyword='人口' or keyword='社会经济'))"); $row=$state->fetchAll(); $sum=$row[0]['count']; $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='theme' and (keyword='人口' or keyword='社会经济')) order by timebegin,title limit ? offset ?"; $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); $this->view->page=new Pagination($sum,$page,$this->limit); $this->view->offset=$offset+1; } function landsurfaceAction() { $page=(int)$this->_request->getParam('page'); if (empty($page)) $page=1; $offset=$this->limit*($page-1); $state=$this->db->query("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='theme' and (keyword='冰川' or keyword='沙漠' or keyword='地貌' or keyword='植被' or keyword='草场' or keyword='沙漠化'))"); $row=$state->fetchAll(); $sum=$row[0]['count']; $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='theme' and (keyword='冰川' or keyword='沙漠' or keyword='地貌' or keyword='植被' or keyword='草场' or keyword='沙漠化')) order by timebegin,title limit ? offset ?"; $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); $this->view->page=new Pagination($sum,$page,$this->limit); $this->view->offset=$offset+1; } function landuseAction() { $this->getmd('土地利用','theme'); } function soilAction() { $this->getmd('土壤','theme'); } function meteoAction() { $this->getmd('气象','theme'); } function hydroAction() { $this->getmd('水文观测','theme'); } function irragationAction() { $this->getmd('灌溉','theme'); } function obsAction() { $this->getmd('试验','theme'); } function listAction() { $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') order by timebegin,title"; $this->view->metadata=$this->db->fetchAll($sql); } function tagAction() { $key = $this->_request->getParam('key'); $page=(int)$this->_request->getParam('page'); if (empty($page)) $page=1; $offset=$this->limit*($page-1); if (!empty($key)) { $this->view->codename=$key; $sql=$this->db->quoteInto('select count(id) from keyword where keyword=?',$key); $state=$this->db->query($sql); $row=$state->fetchAll(); $sum=$row[0]['count']; $sql="select uuid,title,id,description from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keyword='".$key."') order by timebegin,title limit ? offset ?"; $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); $this->view->page=new Pagination($sum,$page,$this->limit); } else { $state=$this->db->query("select keyword.keyword,count(*) from keyword left join normalmetadata m on keyword.id=m.id where keyword.keytype='place' and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') group by keyword.keyword order by count desc"); $k1=$state->fetchAll(); $state=$this->db->query("select k.keyword,count(k.keyword) from keyword k left join normalmetadata m on k.id=m.id where k.keytype='theme' and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') group by k.keyword order by k.keyword"); $k2=$state->fetchAll(); $state=$this->db->query("select k.keyword,count(k.keyword) from keyword k left join normalmetadata m on k.id=m.id where k.keytype='discipline' and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') group by k.keyword order by k.keyword"); $k3=$state->fetchAll(); $state=$this->db->query("select k.keyword,count(k.keyword) from keyword k left join normalmetadata m on k.id=m.id where k.keytype='stratum' and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') group by k.keyword order by k.keyword"); $k4=$state->fetchAll(); $state=$this->db->query("select keyword.keyword,count(*) from keyword left join normalmetadata m on keyword.id=m.id where keyword.keytype='temporal' and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') group by keyword.keyword order by keyword.keyword"); $k5=$state->fetchAll(); $this->view->keywords=array('place'=>$k1,'theme'=>$k2,'discipline'=>$k3,'stratum'=>$k4,'temporal'=>$k5); } } 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)) { $search=new Search($key); $where=$search->sql_expr(array("title","description")); $page=@(int)$this->_request->getParam('page'); if (empty($page)) $page=1; $offset=$this->limit*($page-1); $row=$this->db->fetchAll("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and ".$where); $sum=$row[0]['count']; $sql="select uuid,title,id,description from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and ".$where." order by timebegin,title limit ? offset ?"; $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); $this->view->page=new Pagination($sum,$page,$this->limit); $this->view->key=$key; $this->view->offset=$offset+1; } } function timemapAction() { $sql="select id,uuid,west,south,north,east,title,timebegin,timeend from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and timebegin is not null"; $this->view->rows=$this->db->fetchAll($sql); } function timelineAction() { $fn="heihetime.xml"; $rows=$this->db->fetchAll("select ts_created from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') 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"; $rows=$this->db->fetchAll("select id,uuid,description,title,timebegin,timeend from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and timebegin is not null order by timebegin,title"); $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 categoryAction() { $code = (int)$this->_request->getParam('code'); $this->view->code = $code; $page=(int)$this->_request->getParam('page'); if (empty($page)) $page=1; $offset=$this->limit*($page-1); $this->view->category=$this->db->fetchAll("select c.code,name,name_zh,count(*) from category c left join normalmetadata m on c.id=m.id,categorycode cc where c.code=cc.code and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') group by c.code,cc.name,cc.name_zh"); if ($code>0 && $code<20) { $row=$this->db->fetchAll("select count(*) from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from category where code=".$code.")"); $sum=$row[0]['count']; $sql="select uuid,title,description,id from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select distinct id from category where code=".$code.") order by timebegin,title limit ? offset ?"; $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); $this->view->page=new Pagination($sum,$page,$this->limit); $this->view->offset=$offset+1; $row=$this->db->fetchRow("select name,name_zh from categorycode where code=?",$code); $this->view->codename=(empty($row['name_zh'])?$row['name']:$row['name_zh']); } else { //提供全部分类列表 } } private function getmd($keyword,$type='theme') { $page=(int)$this->_request->getParam('page'); if (empty($page)) $page=1; $offset=$this->limit*($page-1); $state=$this->db->query("select count(m.*) from normalmetadata m left join datasource d on m.uuid=d.uuid left join source s on d.sourceid=s.id where s.code='heihe' and m.id in (select id from keyword where keytype='".$type."' and keyword='".$keyword."')"); $row=$state->fetchAll(); $sum=$row[0]['count']; //@todo: add order with title $sql="select uuid,title from normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='heihe') and id in (select id from keyword where keytype='".$type."' and keyword='".$keyword."') order by timebegin,title limit ? offset ?"; $this->view->metadata=$this->db->fetchAll($sql,array($this->limit,$offset)); $this->view->page=new Pagination($sum,$page,$this->limit); $this->view->offset=$offset+1; } /* * submitAction() //数据汇交 * * param string $ac //动作 * param int $id //数据模版ID * param int $group //geonetwork页面跳转参数 * * return view */ function submitAction(){ $ac = $this->_getParam('ac'); $id = $this->_request->getParam('id'); $this->wdb=Zend_Db::factory($this->view->config->geonetwork); $auth = Zend_Auth::getInstance(); if($auth->hasIdentity()) { $user = $auth->getIdentity(); $u_id = $user->id; $this->view->isadmin=false; if ($user->usertype=='administrator') $this->view->isadmin=true; } if(empty($ac) || $ac == "index") { $this->_helper->viewRenderer('submit-index'); return true; } //新建元数据 if($ac == "newdata") { $do = $this->_getParam('do'); if(empty($do)) { $this->_helper->viewRenderer('submit-newdata'); $keywords = $this->_request->getParam('q'); $sql="select id,(regexp_matches(data,'(.*)'))[1] as title,(owner-".$u_id.") as isowner from metadata where istemplate='y' and schemaid='iso19115'"; if(!empty($keywords)) { $this->view->q = $keywords; $search=new Search($keywords); $where=$search->sql_expr(array("data")); $sql.=' and '.$where; } $sql.=" order by changedate desc"; $sth = $this->wdb->prepare($sql); $sth->execute(); $rows = $sth->fetchAll(); $paginator = Zend_Paginator::factory($rows); $paginator->setCurrentPageNumber($this->_getParam('page')); $paginator->setItemCountPerPage(10); $paginator->setView($this->view); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); $this->view->paginator=$paginator; return true; } if($do == "add") { $this->_helper->viewRenderer('submit-newdata-add'); $this->view->pageNav = "newdata-add"; $keywords = $this->_request->getParam('q'); $sql = "SELECT md.title,md.uuid,md.description,gn.id as gid FROM normalmetadata md left join geonetworkmetadata gn on md.uuid=gn.uuid WHERE gn.id is not null"; if(!empty($keywords)) { $this->view->q = $keywords; $search=new Search($keywords); $where=$search->sql_expr(array("md.title","md.description")); $sql.=' and '.$where; } $sql.=" order by md.ts_created desc"; $sth = $this->db->prepare($sql); $sth->execute(); $rows = $sth->fetchAll(); $paginator = Zend_Paginator::factory($rows); $paginator->setCurrentPageNumber($this->_getParam('page')); $paginator->setItemCountPerPage(10); $paginator->setView($this->view); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); $this->view->paginator=$paginator; return true; } return true; }//newdata //未提交数据 if($ac == "unsubmit") { $do = $this->_getParam('do'); //未提交的数据列表 if(empty($do) || $do=="index") { $this->_helper->viewRenderer('submit-unsubmit'); $sql = "SELECT (regexp_matches(gn.data,'(.*)'))[1] as title,gn.id,gn.uuid FROM geonetworkmetadata gn WHERE gn.uuid not in (select uuid from metadata) and gn.owner=? order by gn.id desc "; $sth = $this->db->prepare($sql); $sth->execute(array($u_id)); $rows = $sth->fetchAll(); $paginator = Zend_Paginator::factory($rows); $paginator->setCurrentPageNumber($this->_getParam('page')); $paginator->setItemCountPerPage(15); $paginator->setView($this->view); Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); $this->view->paginator=$paginator; return true; }//index //提交 if($do=="commit") { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $data = ""; $id = $this->_request->getParam('id'); try{ if(empty($id) || !is_numeric($id)) { $data = array("error"=>"参数错误"); $this->jsonexit($data); return true; } $changelog = $this->_request->getParam('changelog'); if(empty($changelog)) { $data = array("error"=>'请输入变更信息'); $this->jsonexit($data); return true; } // 1. 权限认定:当前用户必须和其owner相同 // 数据应当没有评审状态,没有作者信息 $sql="select gn.id from geonetworkmetadata gn left join mdstatus s on gn.uuid=s.uuid left join mdauthor a on s.uuid=a.uuid where (s.id is not null or a.id is not null) and gn.id=?"; $sth=$this->db->prepare($sql); $sth->execute(array($id)); $row=$sth->fetch(); if (!empty($row)) { $data = array("error"=>'错误的入口'); $this->jsonexit($data); return true; } $sql="select uuid,data as xml from metadata where id=? and owner=?"; $sth=$this->wdb->prepare($sql); $sth->execute(array($id,$u_id)); $row=$sth->fetch(); if (empty($row)) { $data = array("error"=>'无权限修改数据'); $this->jsonexit($data); return true; }else{ $uuid = $row['uuid']; } //检查元数据错误 $iso=new ISO19115(); @$iso->loadXML($row['xml']); if ($iso->validate()) { $data=array("error"=>"元数据导入过程中发现错误。
".implode("
",$iso->error)); $this->jsonexit($data); return true; } $messages = array(); // 保存数据作者信息 $sql="insert into mdauthor (uuid,userid,ts_activated,status) values(?,?,now(),1)"; $sth=$this->db->query($sql,array($row['uuid'],$u_id)); // 2. 保存变化记录 save changelog & userid for the latest version $sql = "UPDATE mdversion SET changelog=?,userid=? WHERE id in (select id from mdversion where uuid=? order by ts_created desc limit 1)"; $this->db->query($sql,array($changelog,$u_id,$row['uuid'])); file_get_contents("http://ftp1.westgis.ac.cn/proftp_upload.php?uuid=".$row['uuid']."&filelist=1"); //自动添加数据分类为黑河 $sql="insert into datasource (uuid,sourceid) values(?,1)"; $sth=$this->db->prepare($sql); try{$sth->execute(array($uuid));}catch(Exception $e) {} // 3. 保存数据评审状态 //导入元数据 $iso->saveDB($this->db); //进入评审库 $sql="insert into mdstatus (uuid,status,userid) values(?,?,?)"; $this->db->query($sql,array($uuid,0,$u_id)); //email to admin $mail=new WestdcMailer($this->view->config->smtp); $mail->setFrom($this->view->config->service->email,'数据服务组'); $mailtp=new EmailText($this->db,"metadata-new-admin",array( 'user' => $user->username, 'uuid' => $iso->uuid, 'email'=> $user->email, //元数据标题 'title'=> $iso->resTitle, )); $mail->setBodyText($mailtp->getBody()); $mail->setSubject($mailtp->getSubject()); $mail->addTo($this->view->config->service->email); $mail->send(); unset($mail); unset($mailtp); //email to author $mail=new WestdcMailer($this->view->config->smtp); $mail->setFrom($this->view->config->service->email,'数据服务组'); $mailtp=new EmailText($this->db,"heihe-new-author",array( 'user' => $user->username, 'uuid' => $iso->uuid, 'email'=> $user->email, //元数据标题 'title'=> $iso->resTitle, )); $mail->setBodyText($mailtp->getBody()); $mail->setSubject($mailtp->getSubject()); $mail->addTo($user->email); $mail->addCc($this->view->config->service->email); @$mail->send(); $data = array("commited"=>1,"error"=>'该版本已经成功提交,请等待数据中心进一步处理!'); $this->jsonexit($data); return true; }catch(Exception $e) { $sql="delete from mdstatus where uuid in (select uuid from geonetworkmetadata where id=?)"; $this->db->query($sql,array($id)); $sql="delete from mdauthor where userid=? and uuid in (select uuid from geonetworkmetadata where id=?)"; $this->db->query($sql,array($u_id,$id)); $msg = "提交失败,请确认权限后重试"; if($this->debug>0) {$msg .= $e->getMessage();} $data = array("error"=>$msg); $this->jsonexit($data); return true; } }//commit return true; }//unsubmit //FTP else if($ac == "ftp") { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $uuid = $this->_getParam('uuid'); $this->view->uuid = $uuid; if(empty($uuid) || !preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid)) { $data = array( 'error'=>"参数错误" ); $this->jsonexit($data); return true; } //安全检查: uuid必须是当前用户且为新建数据 $sql="select * from geonetworkmetadata where uuid=? and uuid not in (select uuid from metadata) and owner=?"; $sth=$this->db->prepare($sql); $sth->execute(array($uuid,$u_id)); $row=$sth->fetch(); if (empty($row)) { $data = array( 'error'=>"参数错误" ); $this->jsonexit($data); return true; } //ftp 用户名 $uname = 'westdc'.$u_id.'upload'; //ftp路径 $homedir = "/disk1/WestDC/upload/".$uuid."/"; $sql = "SELECT * FROM proftpusers WHERE userid='$uname' ORDER BY pkid DESC"; $sth = $this->db->prepare($sql); $sth->execute(); $row = $sth->fetch(); //create directory for upload //server is not localhost, so we need a trick //$old=umask(0); //@mkdir($homedir,0777); //umask($old); $page=file_get_contents('http://ftp1.westgis.ac.cn/proftp_upload.php?uuid='.$uuid); if (!empty($page)) die($page);//there are errors in visit ftp page if(!empty($row['pkid'])) { if(preg_match("/.*".$uuid.".*/",$row['homedir'])) { $data = array( 'statu'=>1, 'user'=>$row['userid'], 'passwd'=>$row['passwd'] ); $this->jsonexit($data); return true; }else{ $uid = 109; $gid = 1002; $passwd = $this->genRandomString(16); //$sql = "UPDATE proftpusers SET passwd=?,uid=?,gid=?,homedir=? WHERE userid=?"; //$sth = $this->db->prepare($sql); //$rs = $sth->execute(array($passwd,$uid,$gid,$homedir,$uname)); $sql="update proftpusers SET passwd='".$passwd."',uid=".$uid.",gid=".$gid.",homedir='".$homedir."' WHERE userid='".$uname."'"; $rs=$this->db->query($sql); if($rs) { $data = array( 'statu'=>1, 'user'=>$uname, 'passwd'=>$passwd ); $this->jsonexit($data); return true; }else{ $data = array( 'error'=>"FTP信息更新失败,请重试" ); $this->jsonexit($data); return true; } } } else{ $uid = 109; $gid = 1002; $passwd = $this->genRandomString(16); //$sql = "INSERT INTO proftpusers (userid,passwd,uid,gid,homedir) VALUES (?,?,?,?,?)"; //$sth = $this->db->prepare($sql); //$rs = $sth->execute(array($uname,$passwd,$uid,$gid,$homedir)); $sql="insert into proftpusers (userid,passwd,uid,gid,homedir) values('".$uname."','".$passwd."',109,1002,'".$homedir."')"; $rs=$this->db->query($sql); if($rs) { $data = array( 'statu'=>1, 'user'=>$uname, 'passwd'=>$passwd ); $this->jsonexit($data); return true; }else{ $data = array( 'error'=>"FTP信息更新失败,请重试" ); $this->jsonexit($data); return true; } }//end if }//ftp }//function submitAction() /* * projectsAction() 数据汇交计划 * * * * */ function projectsAction() { $ac = $this->_getParam('ac'); $invite = $this->_getParam('invite'); $heihe = new Heihe($this->db); $auth = Zend_Auth::getInstance(); if($auth->hasIdentity()) { $user = $auth->getIdentity(); $uid = $user->id; $this->view->user_email = $user_email = $user->email; } $this->view->page = $this->_getParam('page'); $this->view->pageLimit = 15; include_once("helper/view.php"); if(empty($ac) || $ac == "index" || $ac == 'my') { $this->_helper->viewRenderer('project-index'); //Search Link $this->view->searchLink = "/heihe/projects/ac/index/"; $q = $this->_getParam('q'); $wheresql = array(); if(!empty($q)) { if(!preg_match("/^[\x{4e00}-\x{9fa5}A-Za-z0-9_]+$/u",$q)) { $this->view->error = "输入的搜索条件有误,只允许输入汉字、数字、字母"; return true; } $wheresql[] = " (title LIKE '%$q%' OR code LIKE '%$q%' OR name LIKE '%$q%')"; $this->view->searchKeyword = $q; } if($ac == "my") { $wheresql[] = " email='$user_email' "; } if(count($wheresql)>0) { $wheresql = join(" AND ",$wheresql); }else{ $wheresql = ""; } if(!empty($wheresql)) { $wheresql = " WHERE ".$wheresql; } $sql = "SELECT * FROM heiheproject $wheresql ORDER BY id DESC"; $sth = $this->db->query($sql); $rows = $sth->fetchAll(); foreach ($rows as $k=>$v) { $rows[$k]['status'] = $heihe->getStatus($v['status']); } view::addPaginator($rows,$this->view,$this->_request); }//ac == index if($ac == "submitting") { $this->_helper->viewRenderer('project-index'); $sql = "SELECT * FROM heiheproject WHERE status=1"; $sth = $this->db->query($sql); $rows = $sth->fetchAll(); foreach ($rows as $k=>$v) { $rows[$k]['status'] = $heihe->getStatus($v['status']); } view::addPaginator($rows,$this->view,$this->_request); }//ac == submitting 正在提交 if($ac == "unsubmit") { $this->_helper->viewRenderer('project-index'); $sql = "SELECT * FROM heiheproject WHERE status=0"; $sth = $this->db->query($sql); $rows = $sth->fetchAll(); foreach ($rows as $k=>$v) { $rows[$k]['status'] = $heihe->getStatus($v['status']); } view::addPaginator($rows,$this->view,$this->_request); }//ac == unsubmit 未提交 if($ac == "submit") { $this->_helper->viewRenderer('project-index'); $sql = "SELECT * FROM heiheproject WHERE status>0"; $sth = $this->db->query($sql); $rows = $sth->fetchAll(); foreach ($rows as $k=>$v) { $rows[$k]['status'] = $heihe->getStatus($v['status']); } view::addPaginator($rows,$this->view,$this->_request); }//ac == submit 已提交 if($ac == "upload") { $this->_helper->layout->setLayout('layout-iframe'); $this->_helper->viewRenderer('project-upload'); $submit = $this->_getParam('submit'); $pid = $this->_getParam('pid'); if(empty($pid) || !is_numeric($pid)) { $this->view->error = "参数错误"; return true; } $this->view->pid = $pid; if(empty($uid)) { $this->view->error = "请先登录"; return true; } $sql = "SELECT * FROM heiheproject WHERE id=$pid"; $sth = $this->db->query($sql); $row = $sth->fetch(); if($row['email']!= $user_email) { $this->view->error = "您没有权限进行此操作"; return true; } if(!empty($submit) && empty($this->view->error)) { $files=new files(); $msg = $files -> upload($this->view->config->upload,$_FILES['Filedata'],'heihe'); if(empty($msg['error'])) { $msg['error']=""; $filename = $msg['db_path']; $filesize = $msg['file_size']; $filedesc = $this->_request->getParam('filedesc'); $filetype = $msg['file_type']; $realname = $msg['realname']; if(!empty($row['attachid'])) { $sql = "SELECT * FROM attachments WHERE id={$row['attachid']}"; $sth = $this->db->query($sql); $attach = $sth->fetch(); $this->db->exec("DELETE FROM attachments WHERE id={$row['attachid']} AND filetype='heihe'"); @unlink($this->view->config->upload.$attach['filename']); } $sql = " INSERT INTO attachments (filename,filetype,filedesc,userid,filesize,realname) values ('$filename','heihe','$filedesc','$uid','$filesize','$realname') RETURNING id"; $sth = $this->db->prepare($sql); $sth->execute(); $att = $sth->fetch(PDO::FETCH_ASSOC); $msg['attid'] = $attid = $att['id']; $sql = "UPDATE heiheproject SET attachid=$attid WHERE id=$pid"; $sth = $this->db->exec($sql); if($sth) { $this->view->message = "上传成功"; }else{ @unlink($filename); $this->view->error = '附件上传失败:写入附件表出错'; return true; } }else{ @unlink($filename); $this->view->error = "附件上传失败".$msg['error']; return true; } } $sql = "SELECT * FROM heiheproject WHERE id=$pid"; $sth = $this->db->query($sql); $row = $sth->fetch(); $sql = "SELECT * FROM attachments WHERE id = {$row['attachid']}"; $sth = $this->db->query($sql); $this->view->att = $sth->fetch(); return true; } if(!empty($invite)) { $this->_helper->viewRenderer('project-invite'); $pid = $this->_getParam('pid'); $level = $heihe->expertActive($pid,$invite,$user_email); if($level>100) { $this->view->error = "数据中心对您的邀请已经确认!感谢您的支持"; return true; }else{ $this->view->error = $heihe->expertActiveError($level); return true; } }//专家邀请链接 }//projectsAction() function genRandomString($len) { $chars = array( "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ); $charsLen = count($chars) - 1; shuffle($chars); // 将数组打乱 $output = ""; for ($i=0; $i<$len; $i++) { $output .= $chars[mt_rand(0, $charsLen)]; } return $output; } function chmodr($path, $filemode) { if (!is_dir($path)) return chmod($path, $filemode); $dh = opendir($path); while (($file = readdir($dh)) !== false) { if($file != '.' && $file != '..') { $fullpath = $path.'/'.$file; if(is_link($fullpath)) return FALSE; elseif(!is_dir($fullpath) && !chmod($fullpath, $filemode)) return FALSE; elseif(!$this->chmodr($fullpath, $filemode)) return FALSE; } } closedir($dh); if(chmod($path, $filemode)) return TRUE; else return FALSE; } //成为作者后的后继处理工作 private function author_first($uuid,$author) { $sql="insert into mdversion (xml,ts_created,uuid,changelog,userid) select x.data,m.ts_created,?,?,? from metadata m left join xml x on m.id=x.id left join mdversion v on m.uuid=v.uuid where m.uuid=? and v.changelog is null"; $sth=$this->db->prepare($sql); try { $sth->execute(array($uuid,'初始版本 version 1.0',$author,$uuid)); } catch(Exception $e){ // do nothing here. // 说明之前已经有对应数据 } $this->wdb=Zend_Db::factory($this->view->config->geonetwork); $sql="update metadata set owner=? where uuid=?"; $sth=$this->wdb->prepare($sql); $sth->execute(array($author,$uuid)); } }