<?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 name LIKE '%{$search}%' OR operate LIKE '%{$search}%' OR file LIKE '%{$search}%' OR ua LIKE '%{$search}%'" : '';
$order = empty($_GET['order']) ? 'id' : substr(insql($_GET['order']), 0, 8);
$query = "SELECT COUNT(id) FROM ${cfg_dbprefix}admin_log$searchSql;";
$total = $nxsql->oneRowVal($query);
$pages = ceil($total / $limit);
$page > $pages && $page = $pages;
$begin = $page * $limit - $limit;
$query = "SELECT * FROM ${cfg_dbprefix}admin_log$searchSql ORDER BY $order $desc LIMIT $begin, $limit;";
$list = '';
if ($total) {
    if ($result = $nxsql->query($query)) {
        while ($row = $result->fetch_row()) {
            $c = new Client($row[9]);
            $list .= '<tr>';
            $list .= '<td class="ui-widget-content tc">' . $row[0] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[5] . '</td>';
            $list .= '<td class="ui-widget-content plr"><span title="' . htmlspecialchars($row[1]) . '">' . ($hide ? htmlspecialchars($row[1]) : htmlspecialchars(cutStr($row[1], 10))) . '</span></td>';
            $list .= '<td class="ui-widget-content plr"><span title="' . htmlspecialchars($row[2]) . '">' . ($hide ? htmlspecialchars($row[2]) : htmlspecialchars(cutStr($row[2], 16))) . '</span></td>';
            $list .= '<td class="ui-widget-content plr"><span title="' . htmlspecialchars($row[3]) . '">' . ($hide ? htmlspecialchars($row[3]) : htmlspecialchars(cutStr($row[3], 10))) . '</span></td>';
            $list .= '<td class="ui-widget-content tc">' . ($row[4] ? '成功' : '失败') . '</td>';
            $list .= '<td class="ui-widget-content tc">' . long2ip($row[6]) . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $row[7] . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $c->os . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $c->bn . '</td>';
            $list .= '<td class="ui-widget-content tc">' . $c->bv . '</td>';
            $list .= '<td class="ui-widget-content plr"><a href="' . htmlspecialchars($row[8]) . '" title="' . htmlspecialchars($row[8]) . '" target="_blank">' . ($hide ? htmlspecialchars($row[8]) : '..' . htmlspecialchars(substr($row[8], -10, 10))) . '</a></td>';
            $list .= '<td class="ui-widget-content plr"><span title="' . htmlspecialchars($row[9]) . '">' . ($hide ? htmlspecialchars($row[9]) : '..' . htmlspecialchars(substr($row[9], -14, 14))) . '</span></td>';
            $list .= '</tr>';
        }
        $result->close();
    }
}
$subPageNums = $page < 1000 ? 10 : ($page < 10000 ? 7 : 5);
$subPageLink = 'tj_op_log.php?desc=' . ($desc ? '' : 1) . '&hide=' . $hide . '&limit=' . $limit . '&order=' . $order . '&search=' . $search . '&page=';
$fenye = new Fenye($total, $limit, $page, $subPageNums, $subPageLink, 6);
