<?php

//1.1.2.2用户登录VPN次数小时段汇总
require '../../include/init.inc.php';
$width = $height = $start_date = $end_date = $top = $search = '';
$_GET['start_date'] = empty($_GET['start_date']) ? date("Y-m-d", time() - 86400) : $_GET['start_date'];
$_GET['end_date'] = empty($_GET['end_date']) ? date("Y-m-d", time()) : $_GET['end_date'];
$_GET['width'] = empty($_GET['width']) ? 800 : $_GET['width'];
$_GET['height'] = empty($_GET['height']) ? 720 : $_GET['height'];
extract($_GET, EXTR_IF_EXISTS);
if ($search) {
    $count = VpnCount::getUserLoginHoursCount($start_date, $end_date, $width, $height);
    $jpg = $count[0]['IMAGE'];
    if (!empty($jpg)) {
        $filename = 'loginTimesHoursCount.png';
        $file = file_put_contents(ADMIN_BASE_RIMAGE . $filename, $jpg);
        //打开文件准备写入
        $imgurl = ADMIN_URL_RIMAGE . $filename . '?' . microtime(true);
        $img = "<center><img src=\"{$imgurl}\"></center>";
    } else {
        if (count($count) > 0) {
            $img = "无数据!";
        } else {
            $img = "图片加载失败";
        }
    }
    exit($img);
} else {
    $img = "请点击\"检索\"按钮进行查询";
}
Template::assign('img', $img);
 * Date: 2015/7/13
 * Time: 16:29
 * 用户VPN流量汇总
 */
require '../../include/init.inc.php';
$start_date = $end_date = $top = "";
$_POST['start_date'] = empty($_POST['start_date']) ? date("Y-m-d", time() - 86400) : $_POST['start_date'];
$_POST['end_date'] = empty($_POST['end_date']) ? date("Y-m-d", time()) : $_POST['end_date'];
$_POST['top'] = empty($_POST['top']) ? 20 : $_POST['top'];
extract($_POST, EXTR_IF_EXISTS);
//获取用户流量汇总
$list = VpnFlow::getUserVpnTotalFlow($start_date, $end_date, $top);
//用户vpn流量明细
$userFlowDetail = VpnFlow::getUserVpnFlowDetail($start_date, $end_date);
//获取用户总时长
$userLoginTimes = VpnCount::getTopUserLoginAllTimeCountDetail($start_date, $end_date);
foreach ($list as &$item) {
    $uname = $item['VPN_USER'];
    $i = 0;
    $tempRe = '';
    foreach ($userFlowDetail as $uItem) {
        if ($uname == $uItem['VPN_USER']) {
            if ($i > 4) {
                break;
            }
            $tempRe .= $uItem['DEST_IP'] . "(" . $uItem['TOTALBYTES'] . "MB)  ";
            $i++;
        }
    }
    $item['REMARKS'] = $tempRe;
    foreach ($userLoginTimes as $tItem) {
            $file = file_put_contents(ADMIN_BASE_RIMAGE . $filename, $jpg);
            //打开文件准备写入
            $imgurl = ADMIN_URL_RIMAGE . $filename . '?' . microtime(true);
            $img = "<center><img src=\"{$imgurl}\"></center>";
        } else {
            if (count($count) > 0) {
                $img = "无数据!";
            } else {
                $img = "图片加载失败";
            }
        }
        $list = array();
        if (empty($usercount)) {
            $list = VpnCount::getTopUserLoginAllTimeCountDetail($start_date, $end_date);
        } else {
            $list = VpnCount::getTopUserLoginAllTimeCountDetail($start_date, $end_date, $usercount);
        }
        foreach ($list as &$item) {
            $item['TIMES'] = number_format($item['TIMES']);
        }
        $res = array();
        $res['img'] = $img;
        $res['list'] = $list;
        $res = json_encode($res);
        exit($res);
    }
} else {
    //$img = "请点击\"检索\"按钮进行查询,图片生成时间预计5秒内,请不要重复检索";
    $img = "请点击\"检索\"按钮进行查询";
}
Template::assign('img', $img);