2011-09-20 09:12:02 +00:00
< ? php
class Admin_StatController extends Zend_Controller_Action
{
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 ();
2013-01-08 03:37:24 +00:00
$this -> view -> theme = new Theme ();
2011-09-20 09:12:02 +00:00
}
function postDispatch ()
{
$this -> view -> messages = $this -> messenger -> getMessages ();
}
function indexAction ()
{
2011-12-07 07:23:03 +00:00
$sql = " select (select count(id) from users) as alluser,
( select count ( id ) from normalmetadata ) as alldata ,
( select count ( id ) as num from dataorder where status = 0 ) as onlinedown ,
( select count ( id ) as num from dataorder where status = 5 ) as offlinedown ,
2011-12-23 05:36:58 +00:00
( select count ( id ) as num from offlineapp where ts_approved is not null ) as offlinepass ,
( select count ( id ) as num from offlineapp where ts_approved is null ) as offlineunfinished ,
2011-12-07 07:23:03 +00:00
( select count ( id ) as num from dataorder where offlineappid > 0 and status =- 1 ) as offlinedenied ,
( select count ( id ) as num from onlineapp ) as onlineapp " ;
$this -> view -> stat = $this -> db -> fetchRow ( $sql );
2011-09-21 07:49:27 +00:00
//下载量统计
2011-09-24 13:39:02 +00:00
$sql = " select sum(num) as num from (select m.filesize/1024 as num,m.title,d.userid from dataorder d left join metadata m on d.uuid=m.uuid where (d.status=0 or d.status=5) and m.filesize>0 group by m.title,d.userid,m.filesize) as t " ;
2011-09-21 07:49:27 +00:00
$res = $this -> db -> query ( $sql );
$allsize = $res -> fetch ();
$this -> view -> allsize = $allsize ;
2011-09-30 06:56:24 +00:00
2011-09-24 13:39:02 +00:00
$sql = " select sum(num) as num from (select m.filesize/1024 as num,m.title,d.userid from dataorder d left join metadata m on d.uuid=m.uuid where d.status=5 and m.filesize>0 group by m.title,d.userid,m.filesize) as t " ;
2011-09-21 07:49:27 +00:00
$res = $this -> db -> query ( $sql );
$offlinesize = $res -> fetch ();
$this -> view -> offlinesize = $offlinesize ;
2011-09-30 06:56:24 +00:00
2011-09-24 13:39:02 +00:00
$sql = " select sum(num) as num from (select m.filesize/1024 as num,m.title,d.userid from dataorder d left join metadata m on d.uuid=m.uuid where d.status=0 and m.filesize>0 group by m.title,d.userid,m.filesize) as t " ;
2011-09-21 07:49:27 +00:00
$res = $this -> db -> query ( $sql );
$onlinesize = $res -> fetch ();
2011-09-30 06:56:24 +00:00
$this -> view -> onlinesize = $onlinesize ;
2011-09-24 14:07:33 +00:00
$sql = " select sum(configvalue::real)/1024/1024/1024 as num from g6ftpusersettings where userid in (select id from g6ftpusers where name like 'westdc%' or name='newwestdc') and configname='StatsDownloaded' " ;
$res = $this -> db -> query ( $sql );
$onlinesize = $res -> fetch ();
2011-09-30 06:56:24 +00:00
$this -> view -> onlineg6size = $onlinesize ;
2011-09-20 09:12:02 +00:00
} //indexAction 首页
2011-12-07 07:23:03 +00:00
function unitAction ()
{
2013-01-07 09:31:21 +00:00
$ac = $this -> _getParam ( 'ac' );
2011-12-23 03:53:08 +00:00
$y = ( int ) $this -> _request -> getParam ( 'y' );
2011-12-21 08:09:48 +00:00
2011-12-23 03:53:08 +00:00
if ( ! empty ( $y ))
2011-12-21 08:09:48 +00:00
{
$n = date ( " Y " , time ());
if ( $y < 2004 || $y > $n )
{
$y = $n ;
}
}
2013-01-07 09:31:21 +00:00
$this -> view -> y = $y ;
2011-12-21 08:09:48 +00:00
//各单位下载情况, 统计的离线申请数据条数, 需要有对应的dataorder记录
/* $sql = " select count(d.id) as num,o.unit from dataorder d
2013-01-07 09:31:21 +00:00
left join offlineapp o on o . id = d . offlineappid
where d . offlineappid > 0 and o . unit is not null and d . status > 4 " ;*/
//各单位下载情况,统计的离线申请数据次数
$sql = " select count(o.id) as num,o.unit from offlineapp o
where o . unit is not null " ;
2011-12-21 08:09:48 +00:00
if ( $y )
$sql .= " and extract(year from o.ts_created)=' $y ' " ;
$sql .= " group by o.unit " ;
2011-12-07 10:00:58 +00:00
$fe = $this -> db -> query ( $sql );
$unitoffline = $fe -> fetchAll ();
2011-12-08 03:46:35 +00:00
//各单位在线下载情况
$sql = " select count(d.id) as num,o.unit from dataorder d
left join onlineapp o on o . id = d . onlineappid
2013-01-07 09:31:21 +00:00
where d . onlineappid > 0 and o . unit is not null " ;
2011-12-21 08:09:48 +00:00
if ( $y )
$sql .= " and extract(year from o.ts_created)=' $y ' " ;
$sql .= " group by o.unit " ;
2011-12-08 03:46:35 +00:00
$fe = $this -> db -> query ( $sql );
$unitonline = $fe -> fetchAll ();
2013-01-07 09:31:21 +00:00
$units = array ();
foreach ( $unitonline as $k => $v )
{
if ( isset ( $v [ 'num' ]))
{
$units [ $v [ 'unit' ]][ 'online' ] = $v [ 'num' ];
}
}
foreach ( $unitoffline as $k => $v )
{
if ( isset ( $v [ 'num' ]))
{
$units [ $v [ 'unit' ]][ 'offline' ] = $v [ 'num' ];
}
}
$index = 1 ;
foreach ( $units as $k => $v )
{
if ( ! isset ( $v [ 'online' ]))
{
$units [ $k ][ 'online' ] = 0 ;
}
if ( ! isset ( $v [ 'offline' ]))
{
$units [ $k ][ 'offline' ] = 0 ;
}
$units [ $k ][ 'total' ] = $units [ $k ][ 'online' ] + $units [ $k ][ 'offline' ];
$units [ $k ][ 'index' ] = $index ++ ;
}
2011-12-08 03:46:35 +00:00
2013-01-07 09:31:21 +00:00
if ( $ac == " out " )
{
$type = $this -> _getParam ( 'type' );
if ( empty ( $type ) || $type == " csv " )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
2011-12-08 03:46:35 +00:00
2013-01-09 08:49:46 +00:00
include_once ( " Stat.php " );
$stat = new Stat ( $this -> db );
$head = array ( " id " , " 单位名称 " , " 离线申请次数 " , " 在线申请次数 " , " 总申请次数 " );
$content = array ();
2013-01-07 09:31:21 +00:00
foreach ( $units as $k => $v )
{
2013-01-09 08:49:46 +00:00
$content [] = array (
$v [ 'index' ],
$k ,
$v [ 'offline' ],
$v [ 'online' ],
$v [ 'total' ]
);
unset ( $units [ $k ]);
2013-01-07 09:31:21 +00:00
}
2013-01-09 08:49:46 +00:00
array_unshift ( $content , $head );
$stat -> Download ( " westdc-download-status.csv " , $content , " csv " );
exit ();
2013-01-07 09:31:21 +00:00
}
2013-01-08 08:23:48 +00:00
2013-01-07 09:31:21 +00:00
}
2011-12-07 10:00:58 +00:00
2013-01-07 09:31:21 +00:00
$this -> view -> units = $units ;
2011-12-07 07:23:03 +00:00
} //分单位统计
2013-01-08 08:23:48 +00:00
//按用户统计
function userAction (){
$ac = $this -> _getParam ( 'ac' );
if ( $ac == " get " )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
include_once ( " Stat.php " );
$stat = new Stat ( $this -> db );
$rows = $stat -> UserDataorder ();
$down = $this -> _getParam ( 'down' );
if ( empty ( $down ))
{
$this -> jsonexit ( array ( " aaData " => $rows ));
return true ;
}
if ( $down == " csv " )
{
$this -> _helper -> layout -> disableLayout ();
$this -> _helper -> viewRenderer -> setNoRender ();
2013-01-09 08:49:46 +00:00
$head = array ( " id " , " 姓名 " , " 离线申请次数 " , " 在线申请次数 " , " 总申请次数 " );
2013-01-08 08:23:48 +00:00
2013-01-09 08:49:46 +00:00
array_unshift ( $rows , $head );
$stat -> Download ( " westdc-download-status.csv " , $rows , " csv " );
exit ();
2013-01-08 08:23:48 +00:00
}
}
} //userAction()
2013-01-09 08:49:46 +00:00
2011-12-07 07:23:03 +00:00
function monthAction (){
2011-12-23 03:53:08 +00:00
$y = ( int ) $this -> _request -> getParam ( 'y' );
2011-12-07 07:23:03 +00:00
2011-12-23 03:53:08 +00:00
if ( ! empty ( $y ))
2011-12-07 07:23:03 +00:00
{
$n = date ( " Y " , time ());
if ( $y < 2004 || $y > $n )
{
$y = $n ;
}
}
$this -> view -> y = $y ;
2013-01-07 09:31:21 +00:00
$sql = " select count(extract(month from ts_created)) as c,extract(month from ts_created) as m,extract(year from ts_created) as y from onlineapp
where id in ( select distinct ( onlineappid ) from dataorder ) " ;
2011-12-23 03:45:04 +00:00
if ( $y )
$sql .= " and extract(year from ts_created)=' $y ' " ;
$sql .= " group by extract(month from ts_created),extract(year from ts_created)
2011-12-07 07:23:03 +00:00
order by extract ( year from ts_created ), extract ( month from ts_created ) " ;
$rs = $this -> db -> query ( $sql );
$rows = $rs -> fetchAll ();
$this -> view -> data = $rows ;
2013-01-07 09:31:21 +00:00
$sql = " select count(extract(month from ts_created)) as c,extract(month from ts_created) as m,extract(year from ts_created) as y from dataorder
where status = 0 " ;
2011-12-23 04:18:50 +00:00
if ( $y )
$sql .= " and extract(year from ts_created)=' $y ' " ;
$sql .= " group by extract(month from ts_created),extract(year from ts_created)
order by extract ( year from ts_created ), extract ( month from ts_created ) " ;
$rs = $this -> db -> query ( $sql );
$rows = $rs -> fetchAll ();
$this -> view -> online = $rows ;
2011-12-07 07:23:03 +00:00
2013-01-07 09:31:21 +00:00
$sql = " select count(extract(month from ts_created)) as c,extract(month from ts_created) as m,extract(year from ts_created) as y from offlineapp
where ts_approved is not null " ;
2011-12-23 03:45:04 +00:00
if ( $y )
$sql .= " and extract(year from ts_created)=' $y ' " ;
$sql .= " group by extract(month from ts_created),extract(year from ts_created)
2011-12-07 07:23:03 +00:00
order by extract ( year from ts_created ), extract ( month from ts_created ) " ;
$rs = $this -> db -> query ( $sql );
$rows = $rs -> fetchAll ();
if ( count ( $rows ) <= 0 )
{
$this -> view -> offline = " " ;
}
$this -> view -> offline = $rows ;
2011-12-23 03:45:04 +00:00
$sql = " select count(extract(month from ts_created)) as c,extract(month from ts_created) as m,extract(year from ts_created) as y from users " ;
2013-01-07 09:31:21 +00:00
if ( $y )
2011-12-23 03:45:04 +00:00
$sql .= " where extract(year from ts_created)=' $y ' " ;
$sql .= " group by extract(month from ts_created),extract(year from ts_created)
2011-12-07 07:23:03 +00:00
order by extract ( year from ts_created ), extract ( month from ts_created ) " ;
$rs = $this -> db -> query ( $sql );
$rows = $rs -> fetchAll ();
if ( count ( $rows ) <= 0 )
{
$this -> view -> newuser = " " ;
}
$this -> view -> newuser = $rows ;
} //按月份统计
2011-10-31 07:17:35 +00:00
2011-09-20 09:12:02 +00:00
function awstatswebAction ()
{
} //awstats web 统计
function awstatsftpAction ()
{
} //awstats ftp 统计
function webalizerAction ()
{
} //webalizer 统计
2011-09-21 02:37:56 +00:00
function waterAction ()
{
2011-12-07 07:23:03 +00:00
$sql = " select count(k.keyword) as num,d.status,k.keyword from dataorder d left join metadata m on d.uuid=m.uuid
left join keyword k on m . id = k . id
where ( d . status = 5 or d . status =- 1 ) and m . source = '0595169a-279e-4b95-819f-129d0ba4280d'
and ( k . keyword = '航空遥感' or k . keyword = '卫星遥感' or k . keyword = '气象水文' or k . keyword = '上游寒区水文试验区' or k . keyword = '森林水文试验区' or k . keyword = '中游干旱区水文试验区' )
2011-10-24 06:09:40 +00:00
group by k . keyword , d . status order by k . keyword desc , d . status desc " ;
2011-09-21 02:37:56 +00:00
$re = $this -> db -> query ( $sql );
$type = $re -> fetchAll (); //按分类
$this -> view -> type = $type ;
$sql = " select count(extract(month from o.ts_created)) as c,extract(month from o.ts_created) as m,extract(year from o.ts_created) as y
from offlineapp o left join dataorder d on d . offlineappid = o . id left join metadata m on m . uuid = d . uuid
where m . source = '0595169a-279e-4b95-819f-129d0ba4280d' and ( d . status = 3 or d . status = 5 or d . status =- 1 )
group by extract ( month from o . ts_created ), extract ( year from o . ts_created )
order by extract ( year from o . ts_created ), extract ( month from o . ts_created ) " ;
$re = $this -> db -> query ( $sql );
$month = $re -> fetchAll ();
$this -> view -> month = $month ;
2011-12-07 07:23:03 +00:00
$sql = " select
extract ( year from o . ts_created ) as y , extract ( month from o . ts_created ) as m ,
count ( extract ( month from o . ts_created )) as c
from
( select distinct ( o . id ), o . ts_created
from offlineapp o where o . datalist like '%黑河综合遥感联合试验%' ) as o
group by extract ( month from o . ts_created ), extract ( year from o . ts_created )
2011-09-21 02:37:56 +00:00
order by extract ( year from o . ts_created ), extract ( month from o . ts_created ) " ;
$re = $this -> db -> query ( $sql );
$order = $re -> fetchAll ();
$this -> view -> order = $order ;
$sql = " select (sum(m.filesize)/1024) as n from dataorder d left join metadata m on d.uuid=m.uuid
where d . status = 5 and m . source = '0595169a-279e-4b95-819f-129d0ba4280d' " ;
$re = $this -> db -> query ( $sql );
$num = $re -> fetchAll ();
$this -> view -> num = $num ;
$sql = " select count(lower(o.unit)) as c,lower(o.unit) as u
from offlineapp o left join dataorder d on d . offlineappid = o . id left join metadata m on m . uuid = d . uuid
where m . source = '0595169a-279e-4b95-819f-129d0ba4280d' and ( d . status = 5 )
group by lower ( o . unit )
order by lower ( o . unit ) " ;
$re = $this -> db -> query ( $sql );
$units = $re -> fetchAll ();
$this -> view -> units = $units ;
$sql = " select count(t.unit) as c,t.unit from
( select distinct ( o . id ), o . unit
from offlineapp o left join dataorder d on d . offlineappid = o . id left join metadata m on m . uuid = d . uuid
where m . source = '0595169a-279e-4b95-819f-129d0ba4280d' and ( d . status = 5 )
) as t
group by t . unit " ;
$re = $this -> db -> query ( $sql );
$ounit = $re -> fetchAll ();
$this -> view -> ounit = $ounit ;
2011-09-30 06:56:24 +00:00
//water 项目按月统计下载量
$sql = " select (sum(m.filesize)/1024) as n,extract(month from d.ts_created) as m,extract(year from d.ts_created) as y from dataorder d left join metadata m on d.uuid=m.uuid
where d . status = 5 and m . source = '0595169a-279e-4b95-819f-129d0ba4280d'
group by extract ( month from d . ts_created ), extract ( year from d . ts_created )
order by extract ( year from d . ts_created ), extract ( month from d . ts_created ) " ;
$re = $this -> db -> query ( $sql );
$dm = $re -> fetchAll ();
$this -> view -> dm = $dm ;
2011-09-21 02:37:56 +00:00
} //WATER项目
2011-12-07 07:23:03 +00:00
2013-01-08 08:23:48 +00:00
public function jsonexit ( $data ){
$this -> getResponse () -> setHeader ( 'Content-Type' , 'application/json' ) -> appendBody ( json_encode ( $data , JSON_NUMERIC_CHECK ));
return true ;
} //jsonexit() 退出并返回json数据
2011-09-20 09:12:02 +00:00
}