<?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.');
$cfg_autoTj && tj();
$title = '历史统计';
$query = "SELECT COUNT(*),MAX(time),MIN(time),SUM(num01),SUM(num02),SUM(num03),SUM(num04),SUM(num05),SUM(num06),SUM(num07),SUM(num08),SUM(num09) FROM ${cfg_dbprefix}statistics_01 WHERE hour=24;";
$result = $nxsql->oneRowVal($query);
$num_day = $result[0];
$max_day = $result[1];
$min_day = $result[2];
$num_UV = $result[3];
$num_IP = $result[4];
$num_NUV = $result[5];
$num_P = $result[6];
$num_PV = $result[7];
$num_SHOW = $result[8];
$num_NPV = $result[9];
$num_NSHOW = $result[10];
$num_CK = $result[11];
$desc = empty($_GET['desc']) ? 'DESC' : '';
$limit = empty($_GET['limit']) ? 7 : (intval($_GET['limit']) ? abs(intval($_GET['limit'])) : 7);
$page = empty($_GET['page']) ? 1 : (intval($_GET['page']) ? abs(intval($_GET['page'])) : 1);
$search = empty($_GET['search']) ? '' : substr(insql($_GET['search']), 0, 255);
$searchSql = $search ? " AND (time LIKE '%{$search}%' OR id LIKE '%{$search}%')" : '';
$order = empty($_GET['order']) ? 'time' : substr(insql($_GET['order']), 0, 8);
$query = "SELECT COUNT(id) FROM ${cfg_dbprefix}statistics_01 WHERE hour=24$searchSql;";
$total = $nxsql->oneRowVal($query);
$pages = ceil($total / $limit);
$page > $pages && $page = $pages;
$begin = $page * $limit - $limit;
$query = "SELECT * FROM ${cfg_dbprefix}statistics_01 WHERE hour=24$searchSql ORDER BY $order $desc LIMIT $begin, $limit;";
$maxriqi = 1;
$list = '';
if ($total) {
    if ($result = $nxsql->query($query)) {
        while ($row = $result->fetch_row()) {
            $riqi = substr($row[1], 0, 10);
            $maxriqi = max($riqi, $maxriqi);
            $list .= '<tr>';
            $list .= '<td class="ui-widget-content tc"><a href="javascript:void(0)" class="' . $riqi . '" title="按此显示' . $riqi . '日小时统计">' . $riqi . '</a></td>';
            $list .= '<td class="ui-widget-content tc">' . $row[3] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[5] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . ($row[3] - $row[5]) . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[4] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[6] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[7] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[8] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[9] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[10] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[11] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . round($row[11] / ($row[8] ? $row[8] : 1), 4) * 100 . '%</td>';
            $list .= '<td class="ui-widget-content tc">' . round($row[11] / ($row[3] ? $row[3] : 1), 4) * 100 . '%</td>';
            $list .= '</tr>';
        }
        $result->close();
    }
}
$subPageNums = $page < 1000 ? 10 : ($page < 10000 ? 7 : 5);
$subPageLink = 'tj_gg_history.php?desc=' . ($desc ? '' : 1) . '&limit=' . $limit . '&order=' . $order . '&search=' . $search . '&page=';
$fenye = new Fenye($total, $limit, $page, $subPageNums, $subPageLink, 6);
