<?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 = '广告日志';
$hide = empty($_GET['hide']) ? 0 : 1;
$desc = empty($_GET['desc']) ? 'DESC' : '';
$limit = empty($_GET['limit']) ? 30 : (intval($_GET['limit']) ? abs(intval($_GET['limit'])) : 30);
$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 ? " WHERE id LIKE '%{$search}%' OR ggwid LIKE '%{$search}%' OR ggid LIKE '%{$search}%' OR ua LIKE '%{$search}%'" : '';
$order = empty($_GET['order']) ? 'id' : substr(insql($_GET['order']), 0, 8);
$query = "SELECT COUNT(id) FROM ${cfg_dbprefix}counter$searchSql;";
$total = $nxsql->oneRowVal($query);
$pages = ceil($total / $limit);
$page > $pages && $page = $pages;
$begin = $page * $limit - $limit;
$query = "SELECT * FROM ${cfg_dbprefix}counter$searchSql ORDER BY $order $desc LIMIT $begin, $limit;";
$list = '';
if ($total) {
    if ($result = $nxsql->query($query)) {
        while ($row = $result->fetch_row()) {
            $list .= '<tr>';
            $list .= '<td class="ui-widget-content tc">' . $row[0] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[1] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . ($row[2] == 1 ? '展示' : '点击') . '</td>';
            $list .= '<td class="ui-widget-content tc">' . long2ip($row[3]) . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[4] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[5] . '</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 plr"><a href="' . htmlspecialchars($row[9]) . '" title="' . htmlspecialchars($row[9]) . '" target="_blank">' . ($hide ? htmlspecialchars($row[9]) : '..' . htmlspecialchars(substr($row[9], -25, 25))) . '</a></td>';
            $list .= '<td class="ui-widget-content plr"><a class="url" href="' . htmlspecialchars($row[10]) . '" title="' . htmlspecialchars($row[10]) . '" target="_blank">' . ($hide ? htmlspecialchars($row[10]) : '..' . htmlspecialchars(substr($row[10], -25, 25))) . '</a></td>';
            $list .= '<td class="ui-widget-content tc">' . $row[11] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[12] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[13] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[14] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[15] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[16] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[17] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[18] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[19] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[20] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[21] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[22] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[23] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . ($row[24] ? '支持' : '不支持') . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[25] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[26] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[27] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[28] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[29] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[30] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[31] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[32] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[33] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[34] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[35] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[36] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[37] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[38] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[39] . '</td>';
            $list .= '<td class="ui-widget-content plr"><span title="' . htmlspecialchars($row[40]) . '">' . ($hide ? htmlspecialchars($row[40]) : '..' . htmlspecialchars(substr($row[40], -40, 40))) . '</span></td>';
            $list .= '</tr>';
        }
        $result->close();
    }
}
$subPageNums = $page < 1000 ? 10 : ($page < 10000 ? 7 : 5);
$subPageLink = 'tj_gg_log.php?desc=' . ($desc ? '' : 1) . '&hide=' . $hide . '&limit=' . $limit . '&order=' . $order . '&search=' . $search . '&page=';
$fenye = new Fenye($total, $limit, $page, $subPageNums, $subPageLink, 6);

