添加了按用户统计的视图页面,整理下载功能
This commit is contained in:
parent
6ee39b2908
commit
115ecc7872
|
@ -133,35 +133,29 @@ class Admin_StatController extends Zend_Controller_Action
|
|||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
|
||||
if(strpos($_SERVER["HTTP_USER_AGENT"],"Windows"))
|
||||
{
|
||||
$content = "\xEF\xBB\xBF";
|
||||
}else{
|
||||
$content = "";
|
||||
}
|
||||
$content .= "id,单位名称,离线申请次数,在线申请次数,总申请次数"."\r\n";
|
||||
include_once("Stat.php");
|
||||
$stat = new Stat($this->db);
|
||||
|
||||
$head = array("id","单位名称","离线申请次数","在线申请次数","总申请次数");
|
||||
|
||||
$content = array();
|
||||
|
||||
foreach($units as $k=>$v)
|
||||
{
|
||||
if(strpos($k,","))
|
||||
{
|
||||
$k = str_replace(",",",",$k);
|
||||
}
|
||||
$content .= $v['index'].",".$k.",".$v['offline'].",".$v['online'].",".$v['total']."\r\n";
|
||||
$content[] = array(
|
||||
$v['index'],
|
||||
$k,
|
||||
$v['offline'],
|
||||
$v['online'],
|
||||
$v['total']
|
||||
);
|
||||
unset($units[$k]);
|
||||
}
|
||||
|
||||
$this->getResponse()->setHeader('Content-Type', 'text/csv')
|
||||
->setHeader('Content-Disposition','attachment; filename="westdc-download-status.csv"')
|
||||
->setHeader('Content-Length', strlen($content))
|
||||
->setHeader('Content-Type','application/force-download')
|
||||
->setHeader('Content-Type','application/download')
|
||||
->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);
|
||||
return true;
|
||||
array_unshift($content,$head);
|
||||
|
||||
$stat->Download("westdc-download-status.csv",$content,"csv");
|
||||
exit();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -199,47 +193,19 @@ class Admin_StatController extends Zend_Controller_Action
|
|||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
|
||||
if(strpos($_SERVER["HTTP_USER_AGENT"],"Windows"))
|
||||
{
|
||||
$content = "\xEF\xBB\xBF";
|
||||
}else{
|
||||
$content = "";
|
||||
}
|
||||
$content .= "id,姓名,离线申请次数,在线申请次数,总申请次数"."\r\n";
|
||||
$head = array("id","姓名","离线申请次数","在线申请次数","总申请次数");
|
||||
|
||||
foreach($rows as $k=>$v)
|
||||
{
|
||||
if(strpos($k,","))
|
||||
{
|
||||
$k = str_replace(",",",",$k);
|
||||
}
|
||||
$content .= $v['userid'].",".$v['realname'].",".$v['offline'].",".$v['online'].",".$v['total']."\r\n";
|
||||
}
|
||||
|
||||
$this->csvDownload($content);
|
||||
|
||||
return true;
|
||||
|
||||
array_unshift($rows,$head);
|
||||
|
||||
$stat->Download("westdc-download-status.csv",$rows,"csv");
|
||||
exit();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}//userAction()
|
||||
|
||||
function csvDownload($content){
|
||||
$this->getResponse()->setHeader('Content-Type', 'text/csv')
|
||||
->setHeader('Content-Disposition','attachment; filename="westdc-download-status.csv"')
|
||||
->setHeader('Content-Length', strlen($content))
|
||||
->setHeader('Content-Type','application/force-download')
|
||||
->setHeader('Content-Type','application/download')
|
||||
->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);
|
||||
}
|
||||
|
||||
|
||||
function monthAction(){
|
||||
|
||||
$y = (int)$this->_request->getParam('y');
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
$this->headTitle($this->config->title->site);
|
||||
$this->headTitle('后台管理');
|
||||
$this->headTitle()->setSeparator(' - ');
|
||||
$this->headLink()->appendStylesheet('/css/admin.css');
|
||||
$this->theme->AppendPlus($this,'jquery');
|
||||
$this->theme->AppendPlus($this,'colorbox');
|
||||
$this->theme->AppendPlus($this,'datatable');
|
||||
$this->breadcrumb('<a href="/">首页</a>');
|
||||
$this->breadcrumb('<a href="/admin">后台首页</a>');
|
||||
$this->breadcrumb()->setSeparator(' > ');
|
||||
?>
|
||||
<style>
|
||||
.charts{margin:30px 0px;}
|
||||
.charts .title{color:#003366;}
|
||||
.cp {line-height:24px;}
|
||||
.cp ul li{float:left;margin:0px 0px;}
|
||||
.cp a{color:#4bb2c5;line-height:24px;padding:5px;}
|
||||
.cp a.active,.cp a:hover{color:#FFF;background:#4bb2c5;}
|
||||
</style>
|
||||
<div id="leftPanel">
|
||||
<?= $this->partial('stat/left.phtml'); ?>
|
||||
</div>
|
||||
<div id="rightPanel">
|
||||
|
||||
<div class="cp">
|
||||
<li>
|
||||
<a href="/admin/stat/user/ac/get/down/csv">导出csv格式</a>
|
||||
</li>
|
||||
</div>
|
||||
<div id="unitdata">
|
||||
<b>点击列名进行排序</b>
|
||||
</div>
|
||||
<div class="dataTables_wrapper">
|
||||
<table id="datatable" class="table table-bordered table-striped table_vam dataTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>用户</th>
|
||||
<th>离线申请次数</th>
|
||||
<th>在线申请次数</th>
|
||||
<th>总申请次数</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#datatable').dataTable( {
|
||||
"bProcessing": true,
|
||||
"sAjaxSource": "/admin/stat/user/ac/get",
|
||||
"aoColumns": [
|
||||
{ "mData": "userid" },
|
||||
{ "mData": "realname" },
|
||||
{ "mData": "offline" },
|
||||
{ "mData": "online" },
|
||||
{ "mData": "total" }
|
||||
],
|
||||
"sPaginationType": "full_numbers"
|
||||
});
|
||||
} );
|
||||
</script>
|
|
@ -21,9 +21,10 @@ class Stat
|
|||
public function UserDataorder(){
|
||||
|
||||
$dataorder = $this->tbl_dataorder;
|
||||
$sql = "SELECT d.userid,u.realname,count(d.id) as total
|
||||
$sql = "SELECT d.userid,u.realname
|
||||
,(SELECT count(dd.id) as offline FROM $dataorder dd WHERE dd.userid=d.userid AND (dd.offlineappid > 0 AND dd.onlineappid < 0) GROUP BY dd.userid) as offline
|
||||
,(SELECT count(dd.id) as online FROM $dataorder dd WHERE dd.userid=d.userid AND (dd.offlineappid < 0 AND dd.onlineappid > 0) GROUP BY dd.userid) as online
|
||||
,count(d.id) as total
|
||||
FROM $dataorder d
|
||||
LEFT JOIN users u ON u.id=d.userid
|
||||
WHERE (d.offlineappid > 0 OR d.onlineappid > 0)
|
||||
|
@ -34,4 +35,183 @@ class Stat
|
|||
|
||||
}
|
||||
|
||||
//输出下载
|
||||
public function Download($filename,$content,$filetype="JSON",$zfmvc=""){
|
||||
|
||||
if(empty($filename) || empty($content) || empty($filetype))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$filetype = strtolower($filetype);
|
||||
|
||||
//支持的输出类型
|
||||
$functions = array(
|
||||
"json"=>"JsonOutPut",
|
||||
"xml"=>"XMLOutPut",
|
||||
"csv"=>"CSVOutPut",
|
||||
);
|
||||
|
||||
$file_type_functions = array();
|
||||
foreach($functions as $k=>$v)
|
||||
{
|
||||
$file_type_functions[] = $k;
|
||||
}
|
||||
|
||||
if(!in_array($filetype,$file_type_functions))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$output_body = $this->$functions[$filetype]($content);
|
||||
|
||||
$this->pushDownload($output_body,$filename,$filetype,$zfmvc);
|
||||
|
||||
}//Download
|
||||
|
||||
//输出JSON内容
|
||||
public function JsonOutPut($content,$numeric = true){
|
||||
|
||||
if($numeric == true)
|
||||
{
|
||||
return json_encode($data,JSON_NUMERIC_CHECK);
|
||||
}else{
|
||||
return json_encode($data);
|
||||
}
|
||||
|
||||
}//JsonOutPut()
|
||||
|
||||
//输出XML内容
|
||||
public function XMLOutPut($content){
|
||||
|
||||
|
||||
}//JsonOutPut()
|
||||
|
||||
//输出CSV内容
|
||||
public function CSVOutPut($data,$head = ""){
|
||||
|
||||
$split = ",";
|
||||
|
||||
$content = "";
|
||||
|
||||
//如果是windows,输出一个BOM头
|
||||
if(strpos($_SERVER["HTTP_USER_AGENT"],"Windows"))
|
||||
{
|
||||
$content = "\xEF\xBB\xBF";
|
||||
}else{
|
||||
$content = "";
|
||||
}
|
||||
|
||||
if(!empty($head))
|
||||
{
|
||||
$content .= join($split,$head)."\r\n";
|
||||
}
|
||||
|
||||
|
||||
foreach($data as $k=>$v)
|
||||
{
|
||||
|
||||
foreach($v as $kk=>$vv)
|
||||
{
|
||||
if(strpos($vv,","))
|
||||
{
|
||||
$v[$kk] = "\"".$vv."\"";
|
||||
}
|
||||
}
|
||||
|
||||
$content .= join($split,$v)."\r\n";
|
||||
}
|
||||
|
||||
return $content;
|
||||
}//JsonOutPut()
|
||||
|
||||
//输出下载
|
||||
public function pushDownload($content,$filename,$type="",$zfmvc="")
|
||||
{
|
||||
if(headers_sent())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(empty($filename) || empty($content))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$content_type = $this->ContentTypes($type);
|
||||
$fsize = strlen($content);
|
||||
|
||||
//没有在zf controller 中使用
|
||||
if(empty($zfmvc))
|
||||
{
|
||||
|
||||
header('Content-Description: File Transfer');
|
||||
header("Cache-Control: private",false);
|
||||
header("Content-Type: ".$content_type);
|
||||
header("Content-Disposition: attachment; filename=\"".$filename."\";" );
|
||||
header("Content-Transfer-Encoding: binary\n");
|
||||
header("Expires: 0");
|
||||
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
|
||||
header("Pragma: public");
|
||||
header("Content-Length: ".$fsize);
|
||||
ob_clean();
|
||||
flush();
|
||||
|
||||
echo $content;
|
||||
|
||||
exit();
|
||||
}else{
|
||||
$zfmvc->getResponse()->setHeader('Content-Type', $content_type)
|
||||
->setHeader('Content-Disposition','attachment; filename="'.$filename.'"')
|
||||
->setHeader('Content-Length', strlen($content))
|
||||
->setHeader('Content-Type','application/force-download')
|
||||
->setHeader('Content-Type','application/download')
|
||||
->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);
|
||||
exit();
|
||||
}
|
||||
|
||||
}//pushDownload
|
||||
|
||||
//Content-Type
|
||||
public function ContentTypes($ext){
|
||||
|
||||
$ext = strtolower($ext);
|
||||
|
||||
$def = "application/force-download";
|
||||
|
||||
if(empty($ext))
|
||||
{
|
||||
return $def;
|
||||
}
|
||||
|
||||
$content_types = array(
|
||||
"csv" => "text/csv",
|
||||
"pdf"=>"application/pdf",
|
||||
"exe"=>"application/octet-stream",
|
||||
"gzip"=>"application/zip",
|
||||
"doc"=>"application/msword",
|
||||
"xls"=>"application/vnd.ms-excel",
|
||||
"ppt"=>"application/vnd.ms-powerpoint",
|
||||
"gif"=>"image/gif",
|
||||
"png"=>"image/png",
|
||||
"jpeg"=>"image/jpg",
|
||||
"jpg"=>"image/jpg",
|
||||
"xml"=>"text/xml",
|
||||
"xsl"=>"text/xml"
|
||||
);
|
||||
|
||||
if(!isset($content_types[$ext]))
|
||||
{
|
||||
return $def;
|
||||
}else{
|
||||
return $content_types[$ext];
|
||||
}
|
||||
|
||||
}//ContentTypes
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue