function closeyh()
{
    global $datadir;
    global $ggwthread;
    $pattern = '|(/\\*begin atyh\\*/)(.+?)(/\\*end atyh\\*/)|is';
    if ($dh = opendir($datadir)) {
        while (($file = readdir($dh)) !== false) {
            if ($file != "." && $file != "..") {
                if (strpos($file, $ggwthread) !== false && strpos($file, '.js') !== false) {
                    $ggwdm = insou1(file_get_contents($datadir . '/' . $file));
                    if (preg_match($pattern, $ggwdm)) {
                        $ggwdm = preg_replace($pattern, '', $ggwdm);
                        file_put_contents($datadir . '/' . $file, $ggwdm);
                    }
                }
            }
        }
        closedir($dh);
    }
}
            if ($value == $xggclzu . "\r\n") {
                die('名称重复!换名再来!');
            }
            if ($value == $yggclzu . "\r\n") {
                $zulist .= $xggclzu . "\r\n";
            } else {
                $zulist .= $value;
            }
        }
        file_put_contents($datadir . '/ggclzulist.php', $zulist) or die($datadir . '/ggclzulist.php 禁止写入!');
        $content = file_get_contents($datadir . '/ggcllist.php');
        $array = explode("\r\n", $content);
        array_shift($array);
        array_pop($array);
        foreach ($array as $gid) {
            $ggcld = insou1(file($datadir . '/' . $gid . '.php'));
            if ($ggcld[31] == $yggclzu . "\r\n") {
                $ggcld[31] = $xggclzu . "\r\n";
                file_put_contents($datadir . '/' . $gid . '.php', $ggcld);
            }
        }
    }
    $conn = new mysql();
    $conn->inoplog('修改广告策略类/组', ($xggcllei ? $yggcllei . ':' . $xggcllei . '|' : '') . ($xggclzu ? $yggclzu . ':' . $xggclzu : ''), 1, getname());
    die('1');
}
//////////////////////
if ($menu == 'editdelleizu') {
    $leiv = insql($_REQUEST['leiv']);
    $zuv = insql($_REQUEST['zuv']);
    $newggclleiv = '<?php exit();?>' . "\r\n" . $leiv;
            if ($arrayggwd[3] == '') {
                $sql = "SELECT MIN(gww) AS minw FROM {$Pre}niuxams_counter WHERE ac=1 AND gwid='{$duangwid}' AND url NOT LIKE '%previewgg.php?gid=%' AND referer NOT LIKE '%previewgg.php?gid=%'";
                $arrayggwd[3] = $conn->getFieldsVal($sql, 'minw');
            }
            if ($arrayggwd[4] == '') {
                $sql = "SELECT MIN(gwh) AS minh FROM {$Pre}niuxams_counter WHERE ac=1 AND gwid='{$duangwid}' AND url NOT LIKE '%previewgg.php?gid=%' AND referer NOT LIKE '%previewgg.php?gid=%'";
                $arrayggwd[4] = $conn->getFieldsVal($sql, 'minh');
            }
            if ($arrayggwd[3] && $arrayggwd[4]) {
                $yhggz = '';
                foreach ($arrayyhggz as $line) {
                    $nameoffile = explode('.', $line);
                    if ($nameoffile[1] <= $arrayggwd[3] * 1.01 && $nameoffile[1] >= $arrayggwd[3] * 0.8 && $nameoffile[2] <= $arrayggwd[4] * 1.01 && $nameoffile[2] >= $arrayggwd[4] * 0.8) {
                        $yhggz .= '"' . $line . '",';
                    }
                }
                $yhggz = rtrim($yhggz, ',');
                if ($yhggz) {
                    $js = 'if("undefined"==typeof NiuXGGed)var NiuXsC=function(d,f,e){var g=new Date;g.setDate(g.getDate()+e);document.cookie=d+"="+f+(null==e?"":";expires="+g.toGMTString())+";path=/"},NiuXrC=function(d){var f=document.cookie;if(0<f.length){var e=f.indexOf(d+"=");if(-1!=e)return e=e+d.length+1,d=f.indexOf(";",e),-1==d&&(d=f.length),parseInt(f.substring(e,d))}return 0},NiuXcC=function(d,f,e){var g=NiuXrC(d);if(g)return NiuXsC(d,g+1,e),g+1;NiuXsC(d,f,e);return f},NiuXGGed="",a=NiuXcC("niuxamsy",1),b=NiuXcC("niuxamsy30",
1,30);if("function"==typeof NiuXcC){var a=NiuXrC("niuxamsy"),b=NiuXrC("niuxamsy30"),i=NiuXcC(ggwid,1);if(a==b&&1<a&&1<i){var c=[' . $yhggz . '];for(x in c)if(-1==NiuXGGed.indexOf(c[x])&&2>NiuXcC(c[x],1)){opz=amsurl+datadir+c[x]+\'"></script>\';NiuXGGed+=c[x];break}}};';
                    $pattern = '|(/\\*end ggcl\\*/)(.*?)(/\\*begin bjgg\\*/)|is';
                    $ggwdm = insou1(file_get_contents($datadir . '/' . $gwid . '.js'));
                    $ggwdm = preg_replace($pattern, '${1}' . "/*begin atyh*/\r\n" . $js . "\r\n/*end atyh*/" . '$3', $ggwdm);
                    file_put_contents($datadir . '/' . $gwid . '.js', $ggwdm);
                }
            }
        }
    }
}
file_put_contents($timefile, '<?php echo 1;?>');
die('1');
function ggwtojs($gid, $xzggcl, $ggwwidth, $ggwheight, $bjgg, $ggwclass)
{
    global $amsurl;
    global $datadir;
    $js = "var opz=\"\",opfz=\"\",qz=11,ggwid=\"{$gid}\",atyh=0,amsdir=\"{$amsurl}\",datadir=\"{$datadir}/\",amsurl='<script charset=\"utf-8\" language=\"JavaScript\" type=\"text/javascript\" src=\"'+amsdir;\r\n";
    $ggwwidthjs = is_numeric($ggwwidth) ? 'fdiv.style.width="' . $ggwwidth . 'px";' : '';
    $ggwheightjs = is_numeric($ggwheight) ? 'fdiv.style.height="' . $ggwheight . 'px";' : '';
    if ((is_numeric($ggwwidth) || is_numeric($ggwheight)) && $ggwclass == '1') {
        $js = $js . 'var fdiv=document.scripts[document.scripts.length-1].parentNode;if(fdiv.className.indexOf(ggwid)>-1){' . $ggwwidthjs . '' . $ggwheightjs . 'fdiv.style.overflow="hidden";}' . "\r\n";
    }
    $arrayggcl = explode('. ', $xzggcl);
    $size = count($arrayggcl) - 1;
    for ($i = 0; $i < $size; $i++) {
        if ($arrayggcl[$i]) {
            $ggcljs = insou1(file_get_contents($datadir . '/' . $arrayggcl[$i] . '.js'));
            $js = $js . '/*begin ' . $arrayggcl[$i] . '*/' . "\r\n" . $ggcljs . "\r\n" . '/*end ' . $arrayggcl[$i] . '*/' . "\r\n";
        }
    }
    $js = $js . '/*end ggcl*//*begin bjgg*/' . "\r\n";
    if ($bjgg && $ggwclass == '1') {
        $bjggjs = insou1(file_get_contents($datadir . '/' . $bjgg . '.js'));
        $js = $js . 'if(!opz){' . "\r\n" . '/*begin ' . $bjgg . '*/' . "\r\n" . $bjggjs . "\r\n" . '/*end ' . $bjgg . '*/' . "\r\n" . '}document.write(opz+opfz);';
    } elseif ($bjgg && $ggwclass == '2') {
        $bjggjs = insou1(file_get_contents($datadir . '/' . $bjgg . '.js'));
        $js = $js . 'if(!opfz){' . "\r\n" . '/*begin ' . $bjgg . '*/' . "\r\n" . $bjggjs . "\r\n" . '/*end ' . $bjgg . '*/' . "\r\n" . '}document.write(opz+opfz);';
    } else {
        $js = $js . 'document.write(opz+opfz);';
    }
    return $js;
}
    $arraygid = explode(' ', $gids);
    $file = $datadir . '/ggrecyclelist.php';
    $content = file_get_contents($file);
    foreach ($arraygid as $gid) {
        if (strlen($gid) == strlen($thread) + 15) {
            $path = $datadir . '/' . $gid . '.jsrecycle';
            $path1 = $datadir . '/' . $gid . '.phprecycle';
            unlink($path) or die($gid . '删除错误!');
            unlink($path1) or die($gid . '删除错误!');
            $content = str_replace($gid . "\r\n", '', $content);
            $pattern = '|(/\\*begin ' . $gid . '\\*/)(.+?)(/\\*end ' . $gid . '\\*/)|is';
            if ($dh = opendir($datadir)) {
                while (($file2 = readdir($dh)) !== false) {
                    if ($file2 != "." && $file2 != "..") {
                        if (strpos($file2, $ggwthread) !== false && strpos($file2, '.js') !== false) {
                            $ggwdm = insou1(file_get_contents($datadir . '/' . $file2));
                            if (preg_match($pattern, $ggwdm)) {
                                $ggwdm = preg_replace($pattern, '', $ggwdm);
                                file_put_contents($datadir . '/' . $file2, $ggwdm);
                            }
                        }
                    }
                }
                closedir($dh);
            }
        }
    }
    file_put_contents($file, $content);
    $conn->inoplog('彻底删除广告', $gids, 1, getname());
    die('1');
}
                $subdata = str_replace("\$subadmin['{$key}'][0] = '{$value['0']}'", "\$subadmin['{$key}'][0] = '{$sublgpassword}'", $subdata);
            }
            $subdata = str_replace("\$subadmin['{$key}'][1] = '{$value['1']}'", "\$subadmin['{$key}'][1] = '{$yhzselect}'", $subdata);
            file_put_contents('subadmin.php', $subdata) or die('出错啦!subadmin.php无法修改!请将程序目录和文件的文件权限设置属性0755或0777。');
            $conn = new mysql();
            $conn->inoplog('修改管理员', $sublgname, 1, getname());
            die('1');
        }
    }
    die('貌似没找到你要修改的管理员!');
    /////////////////////
} elseif ($_REQUEST['menu'] == 'delsub') {
    /////////////////////
    $sublgname = htmlspecialchars(insql($_REQUEST['sublgname']));
    $subdata = '';
    $subarr = insou1(file('subadmin.php'));
    foreach ($subarr as $value) {
        if (strpos($value, "\$subadmin['{$sublgname}']") === false) {
            $subdata .= $value;
        }
    }
    $subdata = rtrim($subdata);
    file_put_contents('subadmin.php', $subdata) or die('出错啦!subadmin.php无法修改!请将程序目录和文件的文件权限设置属性0755或0777。');
    $conn = new mysql();
    $conn->inoplog('删除管理员', $sublgname, 1, getname());
    die('1');
    /////////////////////
} elseif ($_REQUEST['menu'] == 'addyhz') {
    /////////////////////
    $rank = htmlspecialchars(insql($_REQUEST['rank']));
    $yhzname = htmlspecialchars(insql($_REQUEST['yhzname']));
$focontent = file($fofile);
array_shift($focontent);
$fodata = '';
$fo_list = '';
$fosortable = '';
foreach ($focontent as $value) {
    $value = rtrim($value);
    $nameurl = explode(' ', $value);
    if ($nameurl[0] && $nameurl[1]) {
        $fodata .= '<a class="button" href="' . htmlspecialchars($nameurl[1]) . '">' . htmlspecialchars($nameurl[0]) . '</a>&nbsp;';
        $fo_list .= '<option value="' . htmlspecialchars($nameurl[1]) . '" title="' . htmlspecialchars($nameurl[1]) . '">' . htmlspecialchars(cutstr($nameurl[0], 10)) . '</option>';
        $fosortable .= '<li class="val ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s" title="可上下移动"></span><span class="ui-icon ui-icon-close" title="删除此项"></span>' . htmlspecialchars($nameurl[0]) . '<input type="hidden" value="' . htmlspecialchars($nameurl[1]) . '" /></li>';
    }
}
if (cforr() != '1') {
    $ggdata = insou1(file_get_contents($datadir . '/maingg.htm'));
    $mainggdata = '<div class="cc ui-widget-content ui-corner-all" id="ggdiv"><p class="tt ui-widget-header ui-corner-all">赞助商链接(<a href="http://www.niuxsoft.com/ad/" target="_blank">说明</a>)</p><div class="cp twoem" id="gg">' . $ggdata . '</div></div>';
}
$title = '系统主页';
require 'mo.head.php';
?>
<style>
.twoem{
	line-height: 2em;
}
.threeem{
	line-height: 3em;
}
label.tip {
	display:inline-block;
	width:30%;
/* 程序功能: 快速低成本建立自己网站的广告管理、智能投放系统!
/* 程序开发: 牛叉软件(NiuXSoft.Com)
/* 版权所有: [NiuXams] (C)2013-2099 NiuXSoft.Com
/* 官方网站: niuxsoft.com  Email: niuxsoft@163.com
/* ---------------------------------------------------- */
/* 使用条款:
/* 1.该软件个人非商业用途免费使用.
/* 2.免费使用禁止修改版权信息和官方推广链接.
/* 3.禁止任何衍生版本.
/* ---------------------------------------------------- */
require 'common.php';
if (cforr() != '1') {
    $timefile = $datadir . '/gt.' . md5('ggupday') . '.php';
    if (file_exists($timefile)) {
        $lasttime = filemtime($timefile);
    } else {
        $lasttime = time() - 7 * 24 * 60 * 60;
    }
    $passtime = time() - $lasttime;
    if (floor($passtime / (24 * 60 * 60)) > 1) {
        $maingg = file_get_contents($cloudurl . 'gg/maingg.htm') or die('失败!');
        file_put_contents($datadir . '/maingg.htm', insou1($maingg));
        $logingg = file_get_contents($cloudurl . 'gg/logingg.htm') or die('失败!!');
        file_put_contents($datadir . '/logingg.htm', insou1($logingg));
        file_put_contents($timefile, '<?php echo 1;?>');
        die('1');
    } else {
        die('0');
    }
}
die('0');
/* 1.该软件个人非商业用途免费使用.
/* 2.免费使用禁止修改版权信息和官方推广链接.
/* 3.禁止任何衍生版本.
/* ---------------------------------------------------- */
define('NIUXAMS_ACCESS', 'updata');
require 'common.php';
if (!preg_match("/^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\$/", getip()) || stripos($_SERVER['SERVER_NAME'], '127.0.0.1') !== false || stripos($_SERVER['SERVER_NAME'], 'localhost') !== false) {
    die('在线升级功能不对内网测试用户开放,请上传到外网服务器或主机使用本功能!');
}
ini_set("default_socket_timeout", 300);
$lastver = file_get_contents($cloudurl . 'updata_ver.htm') or die('云端连接失败!云端地址错误或php函数限制或云端忙!');
if (NIUXAMS_VER >= $lastver) {
    die('当前使用版本已经是最新版本,无需升级!');
}
$content = file_get_contents($cloudurl . 'updata.php?domain=' . $_SERVER['SERVER_NAME'] . '&amsurl=' . $amsurl) or die('获取最新文件列表失败,云端不可连接!');
$lines = explode("\r\n", insou1($content));
if (count($lines) < 4) {
    die($content);
}
foreach ($lines as $line_num => $line) {
    $dirmd5 = explode(' ', $line);
    if ($dirmd5[0] && $dirmd5[1] && md5_file($dirmd5[0]) != $dirmd5[1]) {
        if (!file_exists(dirname($dirmd5[0]))) {
            mkdir(dirname($dirmd5[0]), 0777, true);
        }
        $fdata = file_get_contents($cloudurl . 'updata.php?menu=downfile&f=' . $dirmd5[0]) or die('获取最新更新文件失败,云端不可连接!');
        file_put_contents($dirmd5[0], insou1($fdata)) or die('升级出错啦!无法替换原文件!请将程序目录和所有文件的文件权限设置属性0755或0777。');
    }
}
include 'updata_run.php';
die('1');