<?php

/*
 * ----------------------------------------------------
 * 程序名称: 牛叉广告管理系统(NiuXams)
 * 程序功能: 实现专业的广告投放、管理和统计等管理系统！
 * 程序开发: 牛叉软件(NiuXSoft.com)
 * 版权所有: [NiuXams] (C)2013-2099 NiuXSoft.com
 * 官方网站: www.niuxsoft.com  Email: niuxsoft@163.com
 * ----------------------------------------------------
 * 使用条款:
 * 1.为构建创新型经济社会,请尊重保护知识产权！
 * 2.该软件个人非商业用途免费使用.
 * 3.免费使用禁止修改版权信息和官方推广链接.
 * 4.禁止任何衍生版本.禁止任何非法修改源代码贩卖.
 * ----------------------------------------------------
 */

defined('NIUX_INCLUDED') or exit('Access Denied.');
$title = '今日统计';
$query = "SELECT COUNT(DISTINCT ip,sw,sh,ua),COUNT(DISTINCT ip) FROM ${cfg_dbprefix}counter WHERE DATE(time)=CURDATE();";
$result = $nxsql->oneRowVal($query);
$num_UV = $result[0];
$num_IP = $result[1];
$query = "SELECT COUNT(DISTINCT ip,sw,sh,ua) FROM ${cfg_dbprefix}counter WHERE asn=asn1 AND DATE(time)=CURDATE();";
$result = $nxsql->oneRowVal($query);
$num_NUV = $result;
$query = "SELECT COUNT(DISTINCT ur),COUNT(DISTINCT ip,sw,sh,ua,time),COUNT(*) FROM ${cfg_dbprefix}counter WHERE ac=1 AND DATE(time)=CURDATE();";
$result = $nxsql->oneRowVal($query);
$num_P = $result[0];
$num_PV = $result[1];
$num_SHOW = $result[2];
$query = "SELECT COUNT(DISTINCT c.ip,c.sw,c.sh,c.ua,c.time),COUNT(c.id) FROM ${cfg_dbprefix}counter AS c INNER JOIN ${cfg_dbprefix}gg AS g ON g.id=c.ggid WHERE g.type=0 AND c.ac=1 AND c.ggwh<9 AND DATE(c.time)=CURDATE();";
$result = $nxsql->oneRowVal($query);
$num_NPV = $result[0];
$num_NSHOW = $result[1];
$query = "SELECT COUNT(DISTINCT ip,ggwid,ggid,ggsn,ggsn1,ggsn2,ur,fr,sw,sh,ua,time) FROM ${cfg_dbprefix}counter WHERE ac=2 AND DATE(time)=CURDATE();";
$result = $nxsql->oneRowVal($query);
$num_CK = $result;
$hour_UV = array();
$max_UV = 1;
$query = "SELECT COUNT(DISTINCT ip,sw,sh,ua),EXTRACT(HOUR FROM time) FROM ${cfg_dbprefix}counter WHERE DATE(time)=CURDATE() GROUP BY EXTRACT(HOUR FROM time);";
if ($result = $nxsql->query($query)) {
    while ($row = $result->fetch_row()) {
        $max_UV = max($row[0], $max_UV);
        $hour_UV[$row[1]] = $row[0];
    }
    $result->close();
}
$list_UV = '';
for ($i = 0; $i <= 23; $i++) {
    empty($hour_UV[$i]) && $hour_UV[$i] = 0;
    $list_UV .= '<td><span class="ui-state-error" style="display: inline-block; width: 99%; height: ' . ceil((200 / $max_UV) * $hour_UV[$i]) . 'px;" title="' . $hour_UV[$i] . '"></span></td>';
}
$hour_SHOW = array();
$max_SHOW = 1;
$query = "SELECT COUNT(*),EXTRACT(HOUR FROM time) FROM ${cfg_dbprefix}counter WHERE ac=1 AND DATE(time)=CURDATE() GROUP BY EXTRACT(HOUR FROM time);";
if ($result = $nxsql->query($query)) {
    while ($row = $result->fetch_row()) {
        $max_SHOW = max($row[0], $max_SHOW);
        $hour_SHOW[$row[1]] = $row[0];
    }
    $result->close();
}
$list_SHOW = '';
for ($i = 0; $i <= 23; $i++) {
    empty($hour_SHOW[$i]) && $hour_SHOW[$i] = 0;
    $list_SHOW .= '<td><span class="ui-state-error" style="display: inline-block; width: 99%; height: ' . ceil((200 / $max_SHOW) * $hour_SHOW[$i]) . 'px;" title="' . $hour_SHOW[$i] . '"></span></td>';
}
$hour_CK = array();
$max_CK = 1;
$query = "SELECT COUNT(DISTINCT ip,ggwid,ggid,ggsn,ggsn1,ggsn2,ur,fr,sw,sh,ua,time),EXTRACT(HOUR FROM time) FROM ${cfg_dbprefix}counter WHERE ac=2 AND DATE(time)=CURDATE() GROUP BY EXTRACT(HOUR FROM time);";
if ($result = $nxsql->query($query)) {
    while ($row = $result->fetch_row()) {
        $max_CK = max($row[0], $max_CK);
        $hour_CK[$row[1]] = $row[0];
    }
    $result->close();
}
$list_CK = '';
for ($i = 0; $i <= 23; $i++) {
    empty($hour_CK[$i]) && $hour_CK[$i] = 0;
    $list_CK .= '<td><span class="ui-state-error" style="display: inline-block; width: 99%; height: ' . ceil((200 / $max_CK) * $hour_CK[$i]) . 'px;" title="' . $hour_CK[$i] . '"></span></td>';
}
$top_ur_s = '';
$query = "SELECT COUNT(*) AS Number,ur FROM ${cfg_dbprefix}counter WHERE ac=1 AND DATE(time)=CURDATE() GROUP BY ur ORDER BY Number DESC LIMIT 10;";
if ($result = $nxsql->query($query)) {
    while ($row = $result->fetch_row()) {
        $top_ur_s .= '<tr><td><a href="' . htmlspecialchars($row[1]) . '" title="' . htmlspecialchars($row[1]) . '" target="_blank">' . substr(htmlspecialchars($row[1]), -75, 75) . '</a></td><td>' . $row[0] . '</td></tr>';
    }
    $result->close();
}
$top_ur_c = '';
$query = "SELECT COUNT(DISTINCT ip,ggwid,ggid,ggsn,ggsn1,ggsn2,ur,fr,sw,sh,ua,time) AS Number,ur FROM ${cfg_dbprefix}counter WHERE ac=2 AND DATE(time)=CURDATE() GROUP BY ur ORDER BY Number DESC LIMIT 10;";
if ($result = $nxsql->query($query)) {
    while ($row = $result->fetch_row()) {
        $top_ur_c .= '<tr><td><a href="' . htmlspecialchars($row[1]) . '" title="' . htmlspecialchars($row[1]) . '" target="_blank">' . substr(htmlspecialchars($row[1]), -75, 75) . '</a></td><td>' . $row[0] . '</td></tr>';
    }
    $result->close();
}
$top_fr_s = '';
$query = "SELECT COUNT(*) AS Number,fr FROM ${cfg_dbprefix}counter WHERE ac=1 AND DATE(time)=CURDATE() GROUP BY fr ORDER BY Number DESC LIMIT 10;";
if ($result = $nxsql->query($query)) {
    while ($row = $result->fetch_row()) {
        $top_fr_s .= '<tr><td>' . ($row[1] ? '<a href="' . htmlspecialchars($row[1]) . '" title="' . htmlspecialchars($row[1]) . '" target="_blank">' . substr(htmlspecialchars($row[1]), -75, 75) . '</a>' : '直接访问') . '</td><td>' . $row[0] . '</td></tr>';
    }
    $result->close();
}
$top_fr_c = '';
$query = "SELECT COUNT(DISTINCT ip,ggwid,ggid,ggsn,ggsn1,ggsn2,ur,fr,sw,sh,ua,time) AS Number,fr FROM ${cfg_dbprefix}counter WHERE ac=2 AND DATE(time)=CURDATE() GROUP BY fr ORDER BY Number DESC LIMIT 10;";
if ($result = $nxsql->query($query)) {
    while ($row = $result->fetch_row()) {
        $top_fr_c .= '<tr><td>' . ($row[1] ? '<a href="' . htmlspecialchars($row[1]) . '" title="' . htmlspecialchars($row[1]) . '" target="_blank">' . substr(htmlspecialchars($row[1]), -75, 75) . '</a>' : '直接访问') . '</td><td>' . $row[0] . '</td></tr>';
    }
    $result->close();
}
$top_ggw_s = '';
$query = "SELECT COUNT(*) AS Number,ggwid FROM ${cfg_dbprefix}counter WHERE ac=1 AND DATE(time)=CURDATE() GROUP BY ggwid ORDER BY Number DESC LIMIT 10;";
if ($result = $nxsql->query($query)) {
    while ($row = $result->fetch_row()) {
        $top_ggw_s .= '<tr><td>' . $cfg_forum . '-' . $row[1] . '</td><td>' . $row[0] . '</td></tr>';
    }
    $result->close();
}
$top_ggw_c = '';
$query = "SELECT COUNT(DISTINCT ip,ggwid,ggid,ggsn,ggsn1,ggsn2,ur,fr,sw,sh,ua,time) AS Number,ggwid FROM ${cfg_dbprefix}counter WHERE ac=2 AND DATE(time)=CURDATE() GROUP BY ggwid ORDER BY Number DESC LIMIT 10;";
if ($result = $nxsql->query($query)) {
    while ($row = $result->fetch_row()) {
        $top_ggw_c .= '<tr><td>' . $cfg_forum . '-' . $row[1] . '</td><td>' . $row[0] . '</td></tr>';
    }
    $result->close();
}
$top_gg_s = '';
$query = "SELECT COUNT(*) AS Number,ggid FROM ${cfg_dbprefix}counter WHERE ac=1 AND DATE(time)=CURDATE() GROUP BY ggid ORDER BY Number DESC LIMIT 10;";
if ($result = $nxsql->query($query)) {
    while ($row = $result->fetch_row()) {
        $top_gg_s .= '<tr><td>' . $cfg_thread . '-' . $row[1] . '</td><td>' . $row[0] . '</td></tr>';
    }
    $result->close();
}
$top_gg_c = '';
$query = "SELECT COUNT(DISTINCT ip,ggwid,ggid,ggsn,ggsn1,ggsn2,ur,fr,sw,sh,ua,time) AS Number,ggid FROM ${cfg_dbprefix}counter WHERE ac=2 AND DATE(time)=CURDATE() GROUP BY ggid ORDER BY Number DESC LIMIT 10;";
if ($result = $nxsql->query($query)) {
    while ($row = $result->fetch_row()) {
        $top_gg_c .= '<tr><td>' . $cfg_thread . '-' . $row[1] . '</td><td>' . $row[0] . '</td></tr>';
    }
    $result->close();
}
$top_sc_s = '';
$query = "SELECT COUNT(*) AS Number,sw,sh FROM ${cfg_dbprefix}counter WHERE ac=1 AND DATE(time)=CURDATE() GROUP BY sw,sh ORDER BY Number DESC LIMIT 10;";
if ($result = $nxsql->query($query)) {
    while ($row = $result->fetch_row()) {
        $top_sc_s .= '<tr><td>' . $row[1] . '*' . $row[2] . '</td><td>' . $row[0] . '</td></tr>';
    }
    $result->close();
}
$top_sc_c = '';
$query = "SELECT COUNT(DISTINCT ip,ggwid,ggid,ggsn,ggsn1,ggsn2,ur,fr,sw,sh,ua,time) AS Number,sw,sh FROM ${cfg_dbprefix}counter WHERE ac=2 AND DATE(time)=CURDATE() GROUP BY sw,sh ORDER BY Number DESC LIMIT 10;";
if ($result = $nxsql->query($query)) {
    while ($row = $result->fetch_row()) {
        $top_sc_c .= '<tr><td>' . $row[1] . '*' . $row[2] . '</td><td>' . $row[0] . '</td></tr>';
    }
    $result->close();
}
$top_b_s = '';
$query = "SELECT COUNT(*) AS Number,bn,bv FROM ${cfg_dbprefix}counter WHERE ac=1 AND DATE(time)=CURDATE() GROUP BY bn,bv ORDER BY Number DESC LIMIT 10;";
if ($result = $nxsql->query($query)) {
    while ($row = $result->fetch_row()) {
        $top_b_s .= '<tr><td>' . $row[1] . '：' . $row[2] . '</td><td>' . $row[0] . '</td></tr>';
    }
    $result->close();
}
$top_b_c = '';
$query = "SELECT COUNT(DISTINCT ip,ggwid,ggid,ggsn,ggsn1,ggsn2,ur,fr,sw,sh,ua,time) AS Number,bn,bv FROM ${cfg_dbprefix}counter WHERE ac=2 AND DATE(time)=CURDATE() GROUP BY bn,bv ORDER BY Number DESC LIMIT 10;";
if ($result = $nxsql->query($query)) {
    while ($row = $result->fetch_row()) {
        $top_b_c .= '<tr><td>' . $row[1] . '：' . $row[2] . '</td><td>' . $row[0] . '</td></tr>';
    }
    $result->close();
}
$top_os_s = '';
$query = "SELECT COUNT(*) AS Number,os FROM ${cfg_dbprefix}counter WHERE ac=1 AND DATE(time)=CURDATE() GROUP BY os ORDER BY Number DESC LIMIT 10;";
if ($result = $nxsql->query($query)) {
    while ($row = $result->fetch_row()) {
        $top_os_s .= '<tr><td>' . $row[1] . '</td><td>' . $row[0] . '</td></tr>';
    }
    $result->close();
}
$top_os_c = '';
$query = "SELECT COUNT(DISTINCT ip,ggwid,ggid,ggsn,ggsn1,ggsn2,ur,fr,sw,sh,ua,time) AS Number,os FROM ${cfg_dbprefix}counter WHERE ac=2 AND DATE(time)=CURDATE() GROUP BY os ORDER BY Number DESC LIMIT 10;";
if ($result = $nxsql->query($query)) {
    while ($row = $result->fetch_row()) {
        $top_os_c .= '<tr><td>' . $row[1] . '</td><td>' . $row[0] . '</td></tr>';
    }
    $result->close();
}
$top_la_s = '';
$query = "SELECT COUNT(*) AS Number,la FROM ${cfg_dbprefix}counter WHERE ac=1 AND DATE(time)=CURDATE() GROUP BY la ORDER BY Number DESC LIMIT 5;";
if ($result = $nxsql->query($query)) {
    while ($row = $result->fetch_row()) {
        $top_la_s .= '<tr><td>' . $row[1] . '</td><td>' . $row[0] . '</td></tr>';
    }
    $result->close();
}
$top_la_c = '';
$query = "SELECT COUNT(DISTINCT ip,ggwid,ggid,ggsn,ggsn1,ggsn2,ur,fr,sw,sh,ua,time) AS Number,la FROM ${cfg_dbprefix}counter WHERE ac=2 AND DATE(time)=CURDATE() GROUP BY la ORDER BY Number DESC LIMIT 5;";
if ($result = $nxsql->query($query)) {
    while ($row = $result->fetch_row()) {
        $top_la_c .= '<tr><td>' . $row[1] . '</td><td>' . $row[0] . '</td></tr>';
    }
    $result->close();
}