$row=$this->db->fetchAll("select count(*) from reference where language<>'zh' and id in (select refid from mdref where uuid in (select m.uuid from en.normalmetadata m left join datasource d on m.uuid=d.uuid left join source s on s.id=d.sourceid where s.code='water'))");
$sum=$row[0]['count'];
$sql="select * from reference where language<>'zh' and id in (select refid from mdref where uuid in (select m.uuid from normalmetadata m left join datasource d on m.uuid=d.uuid left join source s on s.id=d.sourceid where s.code='water')) order by reference limit ? offset ?";
$state=$this->db->query("select count(*) from en.normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='water') and id in (select id from en.keyword where keytype='theme' and keyword ilike '%microwave radiometer') and id in (select id from en.keyword where keytype='theme' and keyword='airborne remote sensing')");
$row=$state->fetchAll();
$sum=$row[0]['count'];
$sql="select uuid,title from en.normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='water') and id in (select id from en.keyword where keytype='theme' and keyword ilike '%microwave radiometer') and id in (select id from en.keyword where keytype='theme' and keyword='airborne remote sensing') order by timebegin,title limit ? offset ?";
$state=$this->db->query("select count(*) from en.normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='water') and id in (select id from en.keyword where keytype='theme' and keyword='lidar') and id in (select id from en.keyword where keytype='theme' and keyword='airborne remote sensing')");
$row=$state->fetchAll();
$sum=$row[0]['count'];
$sql="select uuid,title from en.normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='water') and id in (select id from en.keyword where keytype='theme' and keyword='lidar') and id in (select id from en.keyword where keytype='theme' and keyword='airborne remote sensing') order by timebegin,title limit ? offset ?";
$state=$this->db->query("select count(*) from en.normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='water') and id in (select id from en.keyword where keytype='theme' and keyword='Wide-angle Infrared Dual-mode line/area Array Scanner,WiDAS') and id in (select id from en.keyword where keytype='theme' and keyword='airborne remote sensing')");
$row=$state->fetchAll();
$sum=$row[0]['count'];
$sql="select uuid,title from en.normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='water') and id in (select id from en.keyword where keytype='theme' and keyword='Wide-angle Infrared Dual-mode line/area Array Scanner,WiDAS') and id in (select id from en.keyword where keytype='theme' and keyword='airborne remote sensing') order by timebegin,title limit ? offset ?";
$state=$this->db->query("select count(*) from en.normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='water') and id in (select id from en.keyword where keytype='theme' and keyword='SWPHI') and id in (select id from en.keyword where keytype='theme' and keyword='airborne remote sensing')");
$row=$state->fetchAll();
$sum=$row[0]['count'];
$sql="select uuid,title from en.normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='water') and id in (select id from en.keyword where keytype='theme' and keyword='SWPHI') and id in (select id from en.keyword where keytype='theme' and keyword='airborne remote sensing') order by timebegin,title limit ? offset ?";
$sql=$this->db->quoteInto("select count(k.id) from en.keyword k left join en.normalmetadata m on k.id=m.id where length(k.keyword)>0 and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='water') and k.keyword=?",$key);
$state=$this->db->query($sql);
$row=$state->fetchAll();
$sum=$row[0]['count'];
$sql="select uuid,title,id,description from en.normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='water') and id in (select id from en.keyword where keyword='".$key."') order by timebegin,title limit ? offset ?";
$sql="select k.keyword,count(*),k.keytype from en.keyword k left join en.normalmetadata m on k.id=m.id where length(k.keyword)>0 and m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='water') ";
if(!empty($keytype)&&($keytype=='place'||$keytype=='theme'||$keytype=='discipline'||$keytype=='temporal'))$sql.=" and k.keytype='".$keytype."'";
$sql.=' group by k.keyword,k.keytype order by k.keytype,k.keyword,count desc';
$row=$this->db->fetchAll("select count(*) from en.normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='water') and ".$where);
$sql="select uuid,title,id,description from en.normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='water') and ".$where." order by timebegin,title limit ? offset ?";
$sql="select id,uuid,west,south,north,east,title,timebegin,timeend from en.normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='water') and timebegin is not null and timebegin::date>date('2007-01-01')";
$rows=$this->db->fetchAll("select ts_created from en.normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='water') order by ts_created desc limit 1");
$rows=$this->db->fetchAll("select id,uuid,description,title,timebegin,timeend from en.normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='water') and timebegin is not null order by timebegin,title");
$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='water') and id in (select id from category where code=".$code.")");
$sum=$row[0]['count'];
$this->view->category=$this->db->fetchAll('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');
if($code>0&&$code<20){
$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='water') and id in (select distinct id from category where code=".$code.") order by timebegin,title limit ? offset ?";
$state=$this->db->query("select count(m.*) from en.normalmetadata m left join datasource d on m.uuid=d.uuid left join source s on d.sourceid=s.id where s.code='water' and m.id in (select id from en.keyword where keytype='".$type."' and keyword in ".$keyword.")");
$row=$state->fetchAll();
$sum=$row[0]['count'];
//@todo: add order with title
$sql="select uuid,title from en.normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='water') and id in (select id from en.keyword where keytype='".$type."' and keyword in ".$keyword.") order by title limit ? offset ?";
$state=$this->db->query("select count(m.*) from en.normalmetadata m left join datasource d on m.uuid=d.uuid left join source s on d.sourceid=s.id where s.code='water' and m.id in (select id from en.keyword where keyword='".$limited."') and m.id in (select id from en.keyword where keyword in ".$keyword.")");
$row=$state->fetchAll();
$sum=$row[0]['count'];
//@todo: add order with title
$sql="select uuid,title from en.normalmetadata where uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='water') and id in (select id from en.keyword where keyword='".$limited."') and id in (select id from en.keyword where keyword in ".$keyword.") order by title limit ? offset ?";
$sql="select m.* from normalmetadata m left join mdauthor a on a.uuid=m.uuid where m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='hiwater') and a.userid=?";
$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.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='hiwater') and a.status=1 and a.uuid in (select uuid from normalmetadata) group by u.id,u.username,u.realname";
$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.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='hiwater') and r.role in ('pointOfContact','resourceProvider','owner') and s.id=?";
$sql="select distinct responsible.individual as username,responsible.id from responsible left join role on role.resid=responsible.id where role.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='hiwater') and role.role in ('pointOfContact','resourceProvider','owner')";
$state=$this->db->query("select distinct responsible.organisation from en.responsible left join en.role on role.resid=responsible.id where role.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='hiwater') and role.role in ('pointOfContact','resourceProvider','owner')");
$this->view->organisation=$state->fetchAll();
if(!empty($name)){
$this->view->codename=$name;
$sql="select distinct m.* from en.normalmetadata m left join en.role r on m.uuid=r.uuid left join en.responsible s on r.resid=s.id where m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code='hiwater') and r.role in ('pointOfContact','resourceProvider','owner') and s.organisation=?";