<?php

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

require_once './common_init.php';
require_once './data/config_gg.php';
require_once './lib/func_gg.php';

$menu = empty($_POST['menu']) ? '' : $_POST['menu'];
if ($menu == 'real_del_ggcl') {
    $ids = empty($_POST['ids']) ? '' : inSql($_POST['ids']);
    $ids || die('什么冤什么仇，让我删空气？');
    $good_ids = '';
    $id_array = explode(' ', $ids);
    foreach ($id_array as $id) {
        if (preg_match('/^([0-9]){1,10}$/', $id)) {
            $good_ids .= '\'' . $id . '\',';
        }
    }
    $good_ids = rtrim($good_ids, ',');
    $good_ids || die('什么冤什么仇，让我删空气？？');
    if ($adminPowerLB == 1) {
        $query = "SELECT g.id,g.gid "
                . "FROM ${cfg_dbprefix}ggcl AS g "
                . "INNER JOIN ${cfg_dbprefix}lei AS l ON g.lei_id=l.id "
                . "INNER JOIN ${cfg_dbprefix}zu AS z ON g.zu_id=z.id "
                . "WHERE g.recycle=1 AND g.id in (${good_ids}) AND l.type=2 AND z.type=2 AND l.lb_id=${adminLBID} AND z.lb_id=${adminLBID};";
    } elseif ($adminPowerLB == 0) {
        $query = "SELECT g.id,g.gid "
                . "FROM ${cfg_dbprefix}ggcl AS g "
                . "WHERE g.recycle=1 AND g.id in (${good_ids}) AND g.admin_id='${adminID}';";
    } else {
        $query = "SELECT g.id,g.gid "
                . "FROM ${cfg_dbprefix}ggcl AS g "
                . "WHERE g.recycle=1 AND g.id in (${good_ids});";
    }
    $good_ids = '';
    if ($result = $nxsql->query($query)) {
        while ($row = $result->fetch_row()) {
            $path = ROOT_DIR . $cfg_output . '/' . $cfg_book . '-' . $row[0] . '.jsrecycle';
            unlink($path) or die($row[0] . ' 彻底删除错误！');
            $good_ids .= '\'' . $row[0] . '\',';
        }
        $result->close();
        $good_ids = rtrim($good_ids, ',');
        $good_ids || die('出错啦！合法输入为空！没有任何策略被彻底删除！');
        $query = "DELETE FROM `${cfg_dbprefix}ggcl` WHERE recycle=1 AND id in (${good_ids});";
        $nxsql->query($query);
        $nxsql->errno && die('更新数据库发生错误： (' . $nxsql->errno . ') ' . $nxsql->error);
        $nxsql->inLog('彻底删除策略' . $good_ids);
        exit('1');
    }
    exit('没有任何策略被彻底删除！');
}
