<?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.');
$hide = empty($_GET['hide']) ? 0 : 1;
$desc = empty($_GET['desc']) ? 'DESC' : '';
$limit = empty($_GET['limit']) ? $defLimit : (intval($_GET['limit']) ? abs(intval($_GET['limit'])) : $defLimit);
$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 (id LIKE '%{$search}%' OR filename LIKE '%{$search}%' OR type LIKE '%{$search}%')" : '';
$order = empty($_GET['order']) ? 'id' : substr(insql($_GET['order']), 0, 8);
if ($adminPowerLB == 1) {
    $query = "SELECT COUNT(id) FROM `${cfg_dbprefix}upload` WHERE lb_id=${adminLBID}$searchSql;";
} elseif ($adminPowerLB == 0) {
    $query = "SELECT COUNT(id) FROM `${cfg_dbprefix}upload` WHERE admin_id=${adminID}$searchSql;";
} else {
    $query = "SELECT COUNT(id) FROM `${cfg_dbprefix}upload` WHERE filename<>''$searchSql;";
}
$total = $nxsql->oneRowVal($query);
$pages = ceil($total / $limit);
$page > $pages && $page = $pages;
$begin = $page * $limit - $limit;
if ($adminPowerLB == 1) {
    $query = "SELECT id,filename,type,size,width,height,time FROM `${cfg_dbprefix}upload` WHERE lb_id=${adminLBID}$searchSql ORDER BY $order $desc LIMIT $begin, $limit;";
} elseif ($adminPowerLB == 0) {
    $query = "SELECT id,filename,type,size,width,height,time FROM `${cfg_dbprefix}upload` WHERE admin_id=${adminID}$searchSql ORDER BY $order $desc LIMIT $begin, $limit;";
} else {
    $query = "SELECT id,filename,type,size,width,height,time FROM `${cfg_dbprefix}upload` WHERE filename<>''$searchSql ORDER BY $order $desc LIMIT $begin, $limit;";
}
