<?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.');
require './mo_head.php';
?>
<style>
    h3 {
        width: 14em;
        padding: .3em;
    }
    .text {
        font-size: 1em;
        padding: .6em;
    }
    .tip {
        margin-left: 12px;
        padding: .3em;
        display: inline-block;
    }
    .list table th{
        border-width:0px 1px 0px 0px;
        font-size:1.2em;
        line-height:2em;
    }
    .list table td{
        border-width:0px 1px 1px 0px;
        font-size: 1em;
        line-height: 1em;
        overflow: hidden;
    }
    .ui-tooltip {
        max-width: 1200px;
        word-break: break-all;
    }
    #time_content li {
        position: relative;
        margin: 0 1px 1px 1px;
        width: 22em;
        height: 2.2em;
    }
    #time_content li span {
        position: absolute;
        margin-top: .45em;
        margin-left: .9em;
    }
    #time_content li span.ui-icon-close {
        margin-left: 0;
        cursor: pointer;
    }
    #time_content li select.text, #visitor_num, #limit_gg_num{
        padding: .3em;
        font-size: 1em;
    }
</style>
<script>
    $(function () {
        $("#tabs").tabs();
        show_tab_highlight();
        function show_tab_highlight() {
            if ($("#time_content").html()) {
                $("#tabs li").eq(1).addClass("ui-state-highlight");
            } else {
                $("#tabs li").eq(1).removeClass("ui-state-highlight");
            }
            if (($("#limit_gg_num").val() && $("#limit_gg").val() != 0) || ($("#visitor_num").val() && $("#limit_visitor").val() != 0)) {
                $("#xzgg table tr").size() < 3 && $("#tabs li").eq(2).addClass("ui-state-highlight");
            } else {
                $("#tabs li").eq(2).removeClass("ui-state-highlight");
            }
            if ($("#os_content").val() && $("#os_content").val()[0] != 0) {
                $("#tabs li").eq(3).addClass("ui-state-highlight");
            } else {
                $("#tabs li").eq(3).removeClass("ui-state-highlight");
            }
            if ($("#screen_content").val() && $("#screen_content").val()[0] != 0) {
                $("#tabs li").eq(4).addClass("ui-state-highlight");
            } else {
                $("#tabs li").eq(4).removeClass("ui-state-highlight");
            }
            if ($("#browser_content").val() && $("#browser_content").val()[0] != 0) {
                $("#tabs li").eq(5).addClass("ui-state-highlight");
            } else {
                $("#tabs li").eq(5).removeClass("ui-state-highlight");
            }
            if ($("#lang_content").val() && $("#lang_content").val()[0] != 0) {
                $("#tabs li").eq(6).addClass("ui-state-highlight");
            } else {
                $("#tabs li").eq(6).removeClass("ui-state-highlight");
            }
            if ($("#referer_content").val()) {
                $("#tabs li").eq(7).addClass("ui-state-highlight");
            } else {
                $("#tabs li").eq(7).removeClass("ui-state-highlight");
            }
            if ($("#url_content").val()) {
                $("#tabs li").eq(8).addClass("ui-state-highlight");
            } else {
                $("#tabs li").eq(8).removeClass("ui-state-highlight");
            }
            if ($("#local_content").val()) {
                $("#tabs li").eq(9).addClass("ui-state-highlight");
            } else {
                $("#tabs li").eq(9).removeClass("ui-state-highlight");
            }
            if ($("#ua_content").val()) {
                $("#tabs li").eq(10).addClass("ui-state-highlight");
            } else {
                $("#tabs li").eq(10).removeClass("ui-state-highlight");
            }
        }
        function init_ajax_ui() {
            $(".button").button();
            $(".lei1").selectmenu({
                change: function (event, data) {
                    setCoo("lei1", $(this).val(), 120);
                    $("#listgg").load("gg_list.php?menu=ajax&wllx=" + $("input[name='wllx']:checked").val(), function () {
                        init_ajax_ui();
                    });
                }
            });
            $(".zu1").selectmenu({
                change: function (event, data) {
                    setCoo("zu1", $(this).val(), 120);
                    $("#listgg").load("gg_list.php?menu=ajax&wllx=" + $("input[name='wllx']:checked").val(), function () {
                        init_ajax_ui();
                    });
                }
            });
        }
        function show_slideInterval() {
            if ($("#rotate_cl").val() == 5) {
                $("#slideTimeDiv").show();
            } else {
                $("#slideTimeDiv").hide();
            }
        }
        function show_wlqzDiv() {
            if ($("#rotate_cl").val() == 2) {
                $(".wlqzDiv").show();
            } else {
                $(".wlqzDiv").hide();
            }
        }
        $("#wllx_0").click(function () {
            $("#ggclWeightDiv").show();
            show_slideInterval();
            show_wlqzDiv();
            show_rotate();
            $(".wlqz").selectmenu();
            $("#listgg").load("gg_list.php?menu=ajax&wllx=0", function () {
                init_ajax_ui();
            });
        });
        $("#wllx_1").click(function () {
            $("#ggclWeightDiv").hide();
            show_slideInterval();
            show_wlqzDiv();
            show_rotate();
            $(".wlqz").selectmenu();
            $("#listgg").load("gg_list.php?menu=ajax&wllx=1", function () {
                init_ajax_ui();
            });
        });
        if ($("#wllx_0").attr("checked")) {
            $("#wllx_0").click();
        }
        if ($("#wllx_1").attr("checked")) {
            $("#wllx_1").click();
        }
        $("#fromggk").click(function () {
            $("#listgg").toggle();
        });
        $(document).on("click", ".firstPage", function () {
            $("#listgg").load("gg_list.php?menu=ajax&wllx=" + $("input[name='wllx']:checked").val(), function () {
                init_ajax_ui();
            });
        });
        $(document).on("click", ".prePage", function () {
            $("#listgg").load("gg_list.php?menu=ajax&wllx=" + $("input[name='wllx']:checked").val() + "&page=" + $(this).val(), function () {
                init_ajax_ui();
            });
        });
        $(document).on("click", ".nexPage", function () {
            $("#listgg").load("gg_list.php?menu=ajax&wllx=" + $("input[name='wllx']:checked").val() + "&page=" + $(this).val(), function () {
                init_ajax_ui();
            });
        });
        $(document).on("click", ".pages", function () {
            $("#listgg").load("gg_list.php?menu=ajax&wllx=" + $("input[name='wllx']:checked").val() + "&page=" + $(this).val(), function () {
                init_ajax_ui();
            });
        });
        function show_rotate() {
            if ($("#xzgg table tr").size() >= 3) {
                $("#rotate_div").show();
                $("#limit_div").hide();
            } else {
                $("#rotate_div").hide();
                $("#limit_div").show();
            }
        }
        $(document).on("click", ".selectgg", function () {
            $(this).parent().parent().clone().appendTo("#xzgg table");
            $("#xzgg table tr:last").children("td").eq(0).replaceWith('<td class="ui-widget-content tc"><button type="button" class="button delselectgg" title="' + $(this).val() + '" value="' + $(this).val() + '">移除</button></td>');
            $("#xzgg table tr:last").children("td").eq(8).after('<td class="ui-widget-content tc"><div class="wlqzDiv"><select class="wlqz short" name="wlqz"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5" selected="selected">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select></div></td>');
            $(".button").button();
            $(".wlqz").selectmenu();
            show_rotate();
            show_wlqzDiv();
        });
        $(document).on("click", ".delselectgg", function () {
            $(this).parent().parent().remove();
            show_rotate();
        });
        $(document).tooltip({
            content: function () {
                var element = $(this);
                if (element.is(".gg_preview")) {
                    return element.attr("title");
                } else if (element.is(".gg_source")) {
                    return htmlspecialchars(element.attr("title")).replace(/\n/igm, "<br>").replace(/\s/igm, "&nbsp;");
                } else {
                    return element.attr("title").replace(/</igm, "&lt;").replace(/>/igm, "&gt;").replace(/\n/igm, "<br>");
                }
            }
        });
        $("#rotate_cl").selectmenu({
            change: function (event, data) {
                if (data.item.value == 2) {
                    $(".wlqzDiv").show();
                    $("#slideTimeDiv").hide();
                } else if (data.item.value == 5) {
                    $(".wlqzDiv").hide();
                    $("#slideTimeDiv").show();
                } else {
                    $(".wlqzDiv").hide();
                    $("#slideTimeDiv").hide();
                }
            }
        });
        $("#time_select").selectmenu({
            change: function (event, data) {
                var nowDate = new Date(), nowYear = parseInt(nowDate.getFullYear()), nianfen = '', yuefen = '', riqi = '', xingqi = '', xiaoshi = '';
                for (var i = 0; i < 10; i++) {
                    nianfen += '<option value="' + (nowYear + i) + '">' + (nowYear + i) + '</option>';
                }
                for (var i = 1; i < 13; i++) {
                    yuefen += '<option value="' + i + '">' + i + '</option>';
                }
                for (var i = 1; i < 32; i++) {
                    riqi += '<option value="' + i + '">' + i + '</option>';
                }
                for (var i = 1; i < 8; i++) {
                    xingqi += '<option value="' + i + '">' + i + '</option>';
                }
                for (var i = 0; i < 24; i++) {
                    xiaoshi += '<option value="' + i + '">' + i + '</option>';
                }
                switch (parseInt(data.item.value)) {
                    case 1:
                        $("#time_content").append('<li class="ui-state-default"><p class="nianfen"><span class="ui-icon ui-icon-arrowthick-2-n-s" title="可上下移动"></span><span class="ui-icon ui-icon-close" title="删除"></span><strong style="margin-left:2em;">年份：</strong><select class="ksnian text ui-widget-content ui-corner-all" name="ksnian">' + nianfen + '</select>至<select class="jsnian text ui-widget-content ui-corner-all" name="jsnian">' + nianfen + '</select></p></li>');
                        break;
                    case 2:
                        $("#time_content").append('<li class="ui-state-default"><p class="yuefen"><span class="ui-icon ui-icon-arrowthick-2-n-s" title="可上下移动"></span><span class="ui-icon ui-icon-close" title="删除"></span><strong style="margin-left:4em;">月份：</strong><select class="ksyue text ui-widget-content ui-corner-all" name="ksyue">' + yuefen + '</select>至<select class="jsyue text ui-widget-content ui-corner-all" name="jsyue">' + yuefen + '</select></p></li>');
                        break;
                    case 3:
                        $("#time_content").append('<li class="ui-state-default"><p class="riqi"><span class="ui-icon ui-icon-arrowthick-2-n-s" title="可上下移动"></span><span class="ui-icon ui-icon-close" title="删除"></span><strong style="margin-left:6em;">日期：</strong><select class="ksriqi text ui-widget-content ui-corner-all" name="ksriqi">' + riqi + '</select>至<select class="jsriqi text ui-widget-content ui-corner-all" name="jsriqi">' + riqi + '</select></p></li>');
                        break;
                    case 4:
                        $("#time_content").append('<li class="ui-state-default"><p class="xingqi"><span class="ui-icon ui-icon-arrowthick-2-n-s" title="可上下移动"></span><span class="ui-icon ui-icon-close" title="删除"></span><strong style="margin-left:8em;">星期：</strong><select class="ksxingqi text ui-widget-content ui-corner-all" name="ksxingqi">' + xingqi + '</select>至<select class="jsxingqi text ui-widget-content ui-corner-all" name="jsxingqi">' + xingqi + '</select></p></li>');
                        break;
                    case 5:
                        $("#time_content").append('<li class="ui-state-default"><p class="xiaoshi"><span class="ui-icon ui-icon-arrowthick-2-n-s" title="可上下移动"></span><span class="ui-icon ui-icon-close" title="删除"></span><strong style="margin-left:10em;">小时：</strong><select class="ksxiaoshi text ui-widget-content ui-corner-all" name="ksxiaoshi">' + xiaoshi + '</select>至<select class="jsxiaoshi text ui-widget-content ui-corner-all" name="jsxiaoshi">' + xiaoshi + '</select></p></li>');
                        break;
                }
                $(this).children("option").first().attr("selected", "selected");
            }
        });
        $("#time_content").sortable({
            placeholder: "ui-state-highlight"
        });
        $(document).on("click", ".ui-icon-close", function () {
            $(this).parent().parent().hide("drop", 100, function () {
                $(this).remove();
            });
        });
        $("#reset").click(function () {
            window.location.reload(true);
        });
        $("#submit").click(function () {
            if (checkInput("#ggclTitle", /^.{1,80}$/) && checkInput("#ggclExplain", /^.{0,80}$/)
                    && checkInput("#slide_interval", /^\d{0,3}$/) && checkInput("#limit_gg_num", /^\d{0,10}$/)
                    && checkInput("#visitor_num", /^\d{0,3}$/)) {
                if ($("#xzgg table tr").eq(1).html()) {
                    $("#xzgg").next("span").removeClass("ui-state-error");
                } else {
                    $("#fromggk").focus();
                    $("#xzgg").next("span").addClass("ui-state-error");
                    return false;
                }
                var id = <?php echo $id ?>, recycle = <?php echo $recycle ?>, copy = '<?php echo $copy ?>',
                        xzggs = "",
                        time_content = "",
                        os_arr = $("#os_content").val() || [],
                        screen_arr = $("#screen_content").val() || [],
                        browser_arr = $("#browser_content").val() || [],
                        lang_arr = $("#lang_content").val() || [],
                        os_content = os_arr.join(", "),
                        screen_content = screen_arr.join(", "),
                        browser_content = browser_arr.join(", "),
                        lang_content = lang_arr.join(", ");
                if (id && !recycle && !copy && !confirm('修改即刻生效！您确定要修改吗？'))
                    return false;
                $(".delselectgg").each(function () {
                    xzggs += $(this).val() + ", " + $(this).parent().parent().children("td").eq(9).children("div").children("select").val() + ". ";
                });
                $("#time_content").children("li").children("p").each(function () {
                    time_content += $(this).attr("class") + ", " + $(this).children("select").eq(0).val() + "-" + $(this).children("select").eq(1).val() + ". ";
                });
                loading();
                setCoo('lei2', $("#ggclLei").val(), 120);
                setCoo('zu2', $("#ggclZu").val(), 120);
                $.ajax({
                    type: "POST",
                    url: location.href,
                    data: {
                        menu: "submit",
                        id: id,
                        ggclTitle: $("#ggclTitle").val(),
                        ggclExplain: $("#ggclExplain").val(),
                        ggclLei: $("#ggclLei").val(),
                        ggclZu: $("#ggclZu").val(),
                        wllx: $("input[name='wllx']:checked").val(),
                        ggclWeight: $("#ggclWeight").val(),
                        xzggs: xzggs,
                        rotate_cl: $("#rotate_cl").val(),
                        slide_interval: $("#slide_interval").val(),
                        time_cl: $("#time_cl").val(),
                        time_content: time_content,
                        limit_gg: $("#limit_gg").val(),
                        limit_gg_num: $("#limit_gg_num").val(),
                        limit_visitor: $("#limit_visitor").val(),
                        visitor_num: $("#visitor_num").val(),
                        os_cl: $("#os_cl").val(),
                        os_content: os_content,
                        screen_cl: $("#screen_cl").val(),
                        screen_content: screen_content,
                        browser_cl: $("#browser_cl").val(),
                        browser_content: browser_content,
                        lang_cl: $("#lang_cl").val(),
                        lang_content: lang_content,
                        referer_cl: $("#referer_cl").val(),
                        referer_content: $("#referer_content").val(),
                        url_cl: $("#url_cl").val(),
                        url_content: $("#url_content").val(),
                        local_cl: $("#local_cl").val(),
                        local_content: $("#local_content").val(),
                        ua_cl: $("#ua_cl").val(),
                        ua_content: $("#ua_content").val()
                    },
                    success: function (msg) {
                        loaded();
                        if (msg == "1") {
                            dialog('恭喜你，添加广告策略成功！是否继续添加广告策略？', 1, location.href);
                        } else if (msg == "2") {
                            dialog('恭喜你，修改广告策略成功！是否继续修改广告策略？', 1, location.href);
                        } else {
                            dialog(msg);
                        }
                    }
                });
            }
        });
    });
</script>
<div class="fullScreen">
    <h2 class="ptb hd ui-widget-content"><?php echo $title . ($id ? ' ID：' . $id : '') ?></h2>
    <form>
        <div class="plr ptb">
            <h3 class="fl">广告策略名称</h3>
            <p class="fl">
                <input class="text large fl ui-widget-content ui-corner-all" id="ggclTitle" value="<?php echo htmlspecialchars($ggclTitle) ?>" placeholder="不超过80个汉字">
            </p>
            <span class="tip clear">* 不超过80个汉字</span>
        </div>
        <div class="plr ptb">
            <h3 class="fl">广告策略说明</h3>
            <p class="fl">
                <input class="text large fl ui-widget-content ui-corner-all" id="ggclExplain" value="<?php echo htmlspecialchars($ggclExplain) ?>" placeholder="不超过80个汉字">
            </p>
            <span class="tip clear">&nbsp;</span>
        </div>
        <div class="plr ptb">
            <h3 class="fl">广告策略分类</h3>
            <p class="fl">
                <select class="selectmenu long" id="ggclLei"><?php echo $ggclLeiSelectList ?></select>
            </p>
            <span class="tip clear">&nbsp;</span>
        </div>
        <div class="plr ptb">
            <h3 class="fl">广告策略分组</h3>
            <p class="fl">
                <select class="selectmenu long" id="ggclZu"><?php echo $ggclZuSelectList ?></select>
            </p>
            <span class="tip clear">&nbsp;</span>
        </div>
        <div class="plr ptb">
            <h3 class="fl">投放广告类型</h3>
            <p class="buttonset fl">
                <input type="radio" id="wllx_0" value="0" name="wllx"<?php echo ($ggclType ? '' : ' checked="checked"') ?>><label for="wllx_0">固定占位</label>
                <input type="radio" id="wllx_1" value="1" name="wllx"<?php echo ($ggclType ? ' checked="checked"' : '') ?>><label for="wllx_1">非固定占位</label>
            </p>
            <span class="tip clear">固定占位：占有网页内容的部分固定位置来展现广告。非固定占位：不是固定占位的广告，如，漂浮、弹窗等。</span>
        </div>
        <div class="plr ptb hide" id="ggclWeightDiv">
            <h3 class="fl">策略权重</h3>
            <p class="fl">
                <select class="selectmenu short" id="ggclWeight"><?php
for ($i = 1; $i <= 10; $i++) {
    if ($i == $ggclWeight) {
        echo '<option value="' . $i . '" selected="selected">' . $i . '</option>';
    } else {
        echo '<option value="' . $i . '">' . $i . '</option>';
    }
}
?></select>
            </p>
            <span class="tip clear">用于广告位内广告策略之间竞争最终播放广告的资格。优先顺序10级>9级>...>2级>1级，权重相同按其在广告位排位顺序决定优先。</span>
        </div>
        <div class="plr ptb">
            <h3 class="fl">投放广告</h3>
            <div class="list fl" id="xzgg">
                <table width="100%" border="0" cellspacing="0" cellpadding="0" class="ui-widget-content" style="border-width:1px 0px 0px 1px;">
                    <tr>
                        <th class="ui-widget-header" scope="col" style="width: 4.8em;">操作</th>
                        <th class="ui-widget-header" scope="col" style="width: 4em;">编号</th>
                        <th class="ui-widget-header" scope="col" style="width: 18em;">广告名称（停留查看代码/点击预览）</th>
                        <th class="ui-widget-header" scope="col" style="width: 3em;">修改</th>
                        <th class="ui-widget-header" scope="col" style="width: 3em;">展现</th>
                        <th class="ui-widget-header" scope="col" style="width: 4em;">宽(px)</th>
                        <th class="ui-widget-header" scope="col" style="width: 4em;">高(px)</th>
                        <th class="ui-widget-header" scope="col" style="width: 8em;">分类</th>
                        <th class="ui-widget-header" scope="col" style="width: 8em;">分组</th>
                        <th class="ui-widget-header" scope="col" style="width: 4.8em;">比例</th>
                    </tr>
                    <?php
                    if ($gg) {
                        $gg_array = explode('. ', $gg);
                        $size = count($gg_array) - 1;
                        $list = '';
                        for ($i = 0; $i < $size; $i++) {
                            if ($gg_array[$i]) {
                                $gid_qz = explode(', ', $gg_array[$i]);
                                list($gg_gid, $gg_id) = explode(' / ', $gid_qz[0]);
                                $query = "SELECT g.id,g.title,g.content,g.gid,g.tj,g.yb,g.type,g.width,g.height,g.admin_id,g.time,l.name,z.name "
                                        . "FROM ${cfg_dbprefix}gg AS g "
                                        . "LEFT JOIN ${cfg_dbprefix}lei AS l ON g.lei_id=l.id "
                                        . "LEFT JOIN ${cfg_dbprefix}zu AS z ON g.zu_id=z.id "
                                        . "WHERE g.id=${gg_id};";
                                $row = $nxsql->oneRowVal($query);
                                $wlqzSelect = '';
                                for ($k = 1; $k <= 10; $k++) {
                                    if ($k == $gid_qz[1]) {
                                        $wlqzSelect .= '<option value="' . $k . '" selected="selected">' . $k . '</option>';
                                    } else {
                                        $wlqzSelect .= '<option value="' . $k . '">' . $k . '</option>';
                                    }
                                }
                                $list .= '<tr>';
                                $list .= '<td class="ui-widget-content tc"><button type="button" class="button delselectgg" title="' . $gid_qz[0] . '" value="' . $gid_qz[0] . '">移除</button></td>';
                                $list .= '<td class="ui-widget-content tc">' . $row[0] . '</td>';
                                $list .= '<td class="ui-widget-content plr"><a href="gg_preview.php?id=' . $row[0] . '" target="_blank" class="gg_source" title="' . htmlspecialchars(cutStr(unescape($row[2]), 3000)) . '">' . htmlspecialchars(cutStr(unescape($row[1]), 36)) . '</a></td>';
                                $list .= '<td class="ui-widget-content tc"><a href="gg_edit.php?id=' . $row[0] . '" target="_blank" title="' . htmlspecialchars(cutStr(unescape($row[1]), 255)) . '">修改</a></td>';
                                $list .= '<td class="ui-widget-content tc"><span title="' . htmlspecialchars(cutStr(unescape($row[2]), 10000)) . '" class="gg_preview">' . ($row[6] ? '非固定' : '固定') . '</span></td>';
                                $list .= '<td class="ui-widget-content tc">' . ($row [7] ? $row [7] : '-') . '</td>';
                                $list .= '<td class="ui-widget-content tc">' . ($row [8] ? $row [8] : '-') . '</td>';
                                $list .= '<td class="ui-widget-content plr"><span title="' . htmlspecialchars($row [11]) . '">' . htmlspecialchars(cutStr($row [11], 14)) . '</span></td>';
                                $list .= '<td class="ui-widget-content plr"><span title="' . htmlspecialchars($row [12]) . '">' . htmlspecialchars(cutStr($row [12], 14)) . '</span></td>';
                                $list .= '<td class="ui-widget-content tc"><div class="wlqzDiv"><select class="wlqz short" name="wlqz">' . $wlqzSelect . '</select></div></td>';
                                $list .= '</tr>';
                            }
                        }
                        echo $list;
                    }
                    ?> 
                </table>
            </div>
            <span class="tip clear">*</span>
        </div>
        <div class="plr ptb">
            <h3 class="fl">&nbsp;</h3>
            <div class="fl">
                <button type="button" class="button" id="fromggk">从广告库中选择</button>
                <div class="list hide" id="listgg"></div>
            </div>
            <div class="clear"></div>
        </div>

        <div id="tabs">
            <ul>
                <li><a href="#tabs-1">轮换策略</a></li>
                <li><a href="#tabs-2">时间策略</a></li>
                <li><a href="#tabs-3">限数策略</a></li>
                <li><a href="#tabs-4">操作系统策略</a></li>
                <li><a href="#tabs-5">分辨率策略</a></li>
                <li><a href="#tabs-6">浏览器策略</a></li>
                <li><a href="#tabs-7">语言策略</a></li>
                <li><a href="#tabs-8">来源策略</a></li>
                <li><a href="#tabs-9">网址策略</a></li>
                <li><a href="#tabs-10">地域策略</a></li>
                <li><a href="#tabs-11">高级策略</a></li>
            </ul>
            <div id="tabs-1">
                <p>广告个数>1时有效</p>
                <div class="hide" id="rotate_div">
                    <h3 class="fl tr">广告轮换：</h3>
                    <div class="fl">
                        <select id="rotate_cl" class="mid">
                            <option value="1">均匀随机</option>
                            <option value="2"<?php echo $rotate_cl == 2 ? ' selected="selected"' : '' ?>>手动比例</option>
                            <option value="0"<?php echo $rotate_cl == 0 ? ' selected="selected"' : '' ?>>免费版本不支持</option>
                            <option value="4"<?php echo $rotate_cl == 4 ? ' selected="selected"' : '' ?>>同时投放</option>
                            <option value="5"<?php echo $rotate_cl == 5 ? ' selected="selected"' : '' ?>>幻灯片</option>
                        </select>
                        <div class="ptb hide" id="slideTimeDiv">
                            幻灯片间隔：<input id="slide_interval" value="<?php echo $slide_interval ?>" class="text ui-widget-content ui-corner-all short" placeholder="小于4位数">秒
                            <span class="tip" style="color:#E00">警告：本功能采用iframe播放广告，对于明确表示禁止使用iframe播放的广告禁止使用本功能！以免被判断作弊！</span>
                        </div>
                    </div>
                    <div class="clear"></div>
                </div>
            </div>
            <div id="tabs-2">
                <div>
                    <h3 class="fl tr">投放时间：</h3>
                    <div class="fl">
                        <select id="time_cl" class="selectmenu mid">
                            <option value="0">包括</option>
                            <option value="1"<?php echo $time_cl ? ' selected="selected"' : '' ?>>不包括</option>
                        </select>
                    </div>
                    <ul class="fl" id="time_content"><?php
                    if ($time_content) {
                        $time_array = explode('. ', $time_content);
                        $size = count($time_array) - 1;
                        for ($i = 0; $i < $size; $i++) {
                            if ($time_array[$i]) {
                                $time_content_array = explode(', ', $time_array[$i]);
                                $time_begin_end = explode('-', $time_content_array[1]);
                                if ($time_content_array[0] == 'nianfen') {
                                    $nianfen_begin = '';
                                    $nianfen_end = '';
                                    for ($j = 0; $j < 10; $j++) {
                                        if (date("Y", time()) + $j == $time_begin_end[0]) {
                                            $nianfen_begin .= '<option value="' . (date("Y", time()) + $j) . '" selected="selected">' . (date("Y", time()) + $j) . '</option>';
                                        } else {
                                            $nianfen_begin .= '<option value="' . (date("Y", time()) + $j) . '">' . (date("Y", time()) + $j) . '</option>';
                                        }
                                        if (date("Y", time()) + $j == $time_begin_end[1]) {
                                            $nianfen_end .= '<option value="' . (date("Y", time()) + $j) . '" selected="selected">' . (date("Y", time()) + $j) . '</option>';
                                        } else {
                                            $nianfen_end .= '<option value="' . (date("Y", time()) + $j) . '">' . (date("Y", time()) + $j) . '</option>';
                                        }
                                    }
                                    echo '<li class="ui-state-default"><p class="nianfen"><span class="ui-icon ui-icon-arrowthick-2-n-s" title="可上下移动"></span><span class="ui-icon ui-icon-close" title="删除"></span><strong style="margin-left:2em;">年份：</strong><select class="ksnian text ui-widget-content ui-corner-all" name="ksnian">' . $nianfen_begin . '</select>至<select class="jsnian text ui-widget-content ui-corner-all" name="jsnian">' . $nianfen_end . '</select></p></li>';
                                } elseif ($time_content_array[0] == 'yuefen') {
                                    $yuefen_begin = '';
                                    $yuefen_end = '';
                                    for ($j = 1; $j < 13; $j++) {
                                        if ($j == $time_begin_end[0]) {
                                            $yuefen_begin .= '<option value="' . $j . '" selected="selected">' . $j . '</option>';
                                        } else {
                                            $yuefen_begin .= '<option value="' . $j . '">' . $j . '</option>';
                                        }
                                        if ($j == $time_begin_end[1]) {
                                            $yuefen_end .= '<option value="' . $j . '" selected="selected">' . $j . '</option>';
                                        } else {
                                            $yuefen_end .= '<option value="' . $j . '">' . $j . '</option>';
                                        }
                                    }
                                    echo '<li class="ui-state-default"><p class="yuefen"><span class="ui-icon ui-icon-arrowthick-2-n-s" title="可上下移动"></span><span class="ui-icon ui-icon-close" title="删除"></span><strong style="margin-left:4em;">月份：</strong><select class="ksyue text ui-widget-content ui-corner-all" name="ksyue">' . $yuefen_begin . '</select>至<select class="jsyue text ui-widget-content ui-corner-all" name="jsyue">' . $yuefen_end . '</select></p></li>';
                                } elseif ($time_content_array[0] == 'riqi') {
                                    $riqi_begin = '';
                                    $riqi_end = '';
                                    for ($j = 1; $j < 32; $j++) {
                                        if ($j == $time_begin_end[0]) {
                                            $riqi_begin .= '<option value="' . $j . '" selected="selected">' . $j . '</option>';
                                        } else {
                                            $riqi_begin .= '<option value="' . $j . '">' . $j . '</option>';
                                        }
                                        if ($j == $time_begin_end[1]) {
                                            $riqi_end .= '<option value="' . $j . '" selected="selected">' . $j . '</option>';
                                        } else {
                                            $riqi_end .= '<option value="' . $j . '">' . $j . '</option>';
                                        }
                                    }
                                    echo '<li class="ui-state-default"><p class="riqi"><span class="ui-icon ui-icon-arrowthick-2-n-s" title="可上下移动"></span><span class="ui-icon ui-icon-close" title="删除"></span><strong style="margin-left:6em;">日期：</strong><select class="ksriqi text ui-widget-content ui-corner-all" name="ksriqi">' . $riqi_begin . '</select>至<select class="jsriqi text ui-widget-content ui-corner-all" name="jsriqi">' . $riqi_end . '</select></p></li>';
                                } elseif ($time_content_array[0] == 'xingqi') {
                                    $xingqi_begin = '';
                                    $xingqi_end = '';
                                    for ($j = 1; $j < 8; $j++) {
                                        if ($j == $time_begin_end[0]) {
                                            $xingqi_begin .= '<option value="' . $j . '" selected="selected">' . $j . '</option>';
                                        } else {
                                            $xingqi_begin .= '<option value="' . $j . '">' . $j . '</option>';
                                        }
                                        if ($j == $time_begin_end[1]) {
                                            $xingqi_end .= '<option value="' . $j . '" selected="selected">' . $j . '</option>';
                                        } else {
                                            $xingqi_end .= '<option value="' . $j . '">' . $j . '</option>';
                                        }
                                    }
                                    echo '<li class="ui-state-default"><p class="xingqi"><span class="ui-icon ui-icon-arrowthick-2-n-s" title="可上下移动"></span><span class="ui-icon ui-icon-close" title="删除"></span><strong style="margin-left:8em;">星期：</strong><select class="ksxingqi text ui-widget-content ui-corner-all" name="ksxingqi">' . $xingqi_begin . '</select>至<select class="jsxingqi text ui-widget-content ui-corner-all" name="jsxingqi">' . $xingqi_end . '</select></p></li>';
                                } elseif ($time_content_array[0] == 'xiaoshi') {
                                    $xiaoshi_begin = '';
                                    $xiaoshi_end = '';
                                    for ($j = 0; $j < 24; $j++) {
                                        if ($j == $time_begin_end[0]) {
                                            $xiaoshi_begin .= '<option value="' . $j . '" selected="selected">' . $j . '</option>';
                                        } else {
                                            $xiaoshi_begin .= '<option value="' . $j . '">' . $j . '</option>';
                                        }
                                        if ($j == $time_begin_end[1]) {
                                            $xiaoshi_end .= '<option value="' . $j . '" selected="selected">' . $j . '</option>';
                                        } else {
                                            $xiaoshi_end .= '<option value="' . $j . '">' . $j . '</option>';
                                        }
                                    }
                                    echo '<li class="ui-state-default"><p class="xiaoshi"><span class="ui-icon ui-icon-arrowthick-2-n-s" title="可上下移动"></span><span class="ui-icon ui-icon-close" title="删除"></span><strong style="margin-left:10em;">小时：</strong><select class="ksxiaoshi text ui-widget-content ui-corner-all" name="ksxiaoshi">' . $xiaoshi_begin . '</select>至<select class="jsxiaoshi text ui-widget-content ui-corner-all" name="jsxiaoshi">' . $xiaoshi_end . '</select></p></li>';
                                }
                            }
                        }
                    }
                    ?></ul>
                    <div class="fl">
                        <select id="time_select" class="selectmenu mid">
                            <option value="0">操作</option>
                            <option value="1">加年份</option>
                            <option value="2">加月份</option>
                            <option value="3">加日期</option>
                            <option value="4">加星期</option>
                            <option value="5">加小时</option>
                        </select>
                    </div>
                    <div class="clear"></div>
                </div>
            </div>
            <div id="tabs-3">
                <p>广告个数=1时有效</p>
                <div id="limit_div">
                    <div>
                        <h3 class="fl tr">限制投放次数：</h3>
                        <div class="fl">
                            <select id="limit_gg" class="selectmenu mid">
                                <option value="0">请选择</option>
                                <option value="1"<?php echo $limit_gg == 1 ? ' selected="selected"' : '' ?>>总共</option>
                                <option value="2"<?php echo $limit_gg == 2 ? ' selected="selected"' : '' ?>>每月</option>
                                <option value="3"<?php echo $limit_gg == 3 ? ' selected="selected"' : '' ?>>每周</option>
                                <option value="4"<?php echo $limit_gg == 4 ? ' selected="selected"' : '' ?>>每天</option>
                            </select>
                        </div>
                        <div class="fl">
                            展现<input id="limit_gg_num" value="<?php echo $limit_gg_num ?>" class="short ui-widget-content ui-corner-all" placeholder="小于10位数">次
                        </div>
                        <span class="tip fl">不填为不限制</span>
                        <div class="clear"></div>
                    </div>
                    <hr class="hd mtb ui-widget-content">
                    <div>
                        <h3 class="fl tr">限制对独立访客的展现次数：</h3>
                        <div class="fl">
                            <select id="limit_visitor" class="selectmenu mid">
                                <option value="0">请选择</option>
                                <option value="1"<?php echo $limit_visitor == 1 ? ' selected="selected"' : '' ?>>每天</option>
                                <option value="2"<?php echo $limit_visitor == 2 ? ' selected="selected"' : '' ?>>小时</option>
                                <option value="3"<?php echo $limit_visitor == 3 ? ' selected="selected"' : '' ?>>30分钟</option>
                                <option value="4"<?php echo $limit_visitor == 4 ? ' selected="selected"' : '' ?>>10分钟</option>
                                <option value="5"<?php echo $limit_visitor == 5 ? ' selected="selected"' : '' ?>>每分钟</option>
                            </select>
                        </div>
                        <div class="fl">
                            最多展现<input id="visitor_num" value="<?php echo $visitor_num ?>" class="short ui-widget-content ui-corner-all" placeholder="小于4位数">次
                        </div>
                        <span class="tip fl">不填为不限制</span>
                        <div class="clear"></div>
                    </div>
                </div>
            </div>
            <div id="tabs-4">
                <div>
                    <h3 class="fl tr">投放操作系统：</h3>
                    <div class="fl">
                        <select id="os_cl" class="selectmenu mid">
                            <option value="0">包括</option>
                            <option value="1"<?php echo $os_cl ? ' selected="selected"' : '' ?>>不包括</option>
                        </select>
                    </div>
                    <div class="fl">
                        <select id="os_content" size="12" multiple="multiple" class="text ui-widget-content ui-corner-all">
                            <?php
                            $os_array = explode(', ', $os_content);
                            $os_all = array('Windows', 'Windows Phone', 'Mac', 'iOS', 'iPhone', 'iPad', 'iPod', 'Android', 'BlackBerry', 'Linux', 'Unix', '0');
                            foreach ($os_all as $osval) {
                                if (in_array($osval, $os_array)) {
                                    echo '<option value ="' . $osval . '" selected>' . ($osval == '0' ? '取消' : $osval) . '</option>';
                                } else {
                                    echo '<option value ="' . $osval . '">' . ($osval == '0' ? '取消' : $osval) . '</option>';
                                }
                            }
                            ?> 
                        </select>
                    </div>
                    <span class="tip fl">可按Ctrl或Shift键进行多选或取消选择。</span>
                    <div class="clear"></div>
                </div>
            </div>
            <div id="tabs-5">
                <div>
                    <h3 class="fl tr">投放分辨率：</h3>
                    <div class="fl">
                        <select id="screen_cl" class="selectmenu mid">
                            <option value="0">包括</option>
                            <option value="1"<?php echo $screen_cl ? ' selected="selected"' : '' ?>>不包括</option>
                        </select>
                    </div>
                    <div class="fl">
                        <select id="screen_content" size="19" multiple="multiple" class="text ui-widget-content ui-corner-all">
                            <?php
                            $screen_array = explode(', ', $screen_content);
                            $screen_all = array('320*480', '640*480', '800*600', '1024*768', '1152*864', '1280*720', '1280*768', '1280*800', '1280*960', '1280*1024', '1360*768', '1366*768', '1400*1050', '1440*900', '1600*900', '1680*1050', '1920*1080', '1920*1200', '0');
                            foreach ($screen_all as $screenval) {
                                if (in_array($screenval, $screen_array)) {
                                    echo '<option value ="' . $screenval . '" selected>' . ($screenval == '0' ? '取消' : $screenval) . '</option>';
                                } else {
                                    echo '<option value ="' . $screenval . '">' . ($screenval == '0' ? '取消' : $screenval) . '</option>';
                                }
                            }
                            ?> 
                        </select>
                    </div>
                    <span class="tip fl">可按Ctrl或Shift键进行多选或取消选择。</span>
                    <div class="clear"></div>
                </div>
            </div>
            <div id="tabs-6">
                <div>
                    <h3 class="fl tr">投放浏览器：</h3>
                    <div class="fl">
                        <select id="browser_cl" class="selectmenu mid">
                            <option value="0">包括</option>
                            <option value="1"<?php echo $browser_cl ? ' selected="selected"' : '' ?>>不包括</option>
                        </select>
                    </div>
                    <div class="fl">
                        <select id="browser_content" size="14" multiple="multiple" class="text ui-widget-content ui-corner-all">
                            <?php
                            $browser_array = explode(', ', $browser_content);
                            $browser_all = array('Internet Explorer 6', 'Internet Explorer 7', 'Internet Explorer 8', 'Internet Explorer 9', 'Internet Explorer 10', 'Internet Explorer 11', 'Edge', 'IEMobile', 'Chrome', 'Safari', 'Firefox', 'Mozilla', 'Opera', '0');
                            foreach ($browser_all as $browserval) {
                                if (in_array($browserval, $browser_array)) {
                                    echo '<option value ="' . $browserval . '" selected>' . ($browserval == '0' ? '取消' : $browserval) . '</option>';
                                } else {
                                    echo '<option value ="' . $browserval . '">' . ($browserval == '0' ? '取消' : $browserval) . '</option>';
                                }
                            }
                            ?> 
                        </select>
                    </div>
                    <span class="tip fl">可按Ctrl或Shift键进行多选或取消选择。</span>
                    <div class="clear"></div>
                </div>
            </div>
            <div id="tabs-7">
                <div>
                    <h3 class="fl tr">投放语言：</h3>
                    <div class="fl">
                        <select id="lang_cl" class="selectmenu mid">
                            <option value="0">包括</option>
                            <option value="1"<?php echo $lang_cl ? ' selected="selected"' : '' ?>>不包括</option>
                        </select>
                    </div>
                    <div class="fl">
                        <select id="lang_content" size="6" multiple="multiple" class="text ui-widget-content ui-corner-all">
                            <?php
                            $lang_array = explode(', ', $lang_content);
                            $lang_all = array('zh-cn', 'zh-tw', 'en', 'jp', 'ko', '0');
                            $lang_allShow = array('中文(简体)', '中文(繁体)', '英语', '日语', '韩语', '取消');
                            $i = 0;
                            foreach ($lang_all as $langval) {
                                if (in_array($langval, $lang_array)) {
                                    echo '<option value ="' . $langval . '" selected>' . $lang_allShow[$i] . '</option>';
                                } else {
                                    echo '<option value ="' . $langval . '">' . $lang_allShow[$i] . '</option>';
                                }
                                $i++;
                            }
                            ?> 
                        </select>
                    </div>
                    <span class="tip fl">可按Ctrl或Shift键进行多选或取消选择。</span>
                    <div class="clear"></div>
                </div>
            </div>
            <div id="tabs-8">
                <div>
                    <h3 class="fl tr">投放来源：</h3>
                    <div class="fl">
                        <select id="referer_cl" class="selectmenu mid">
                            <option value="0">包括</option>
                            <option value="1"<?php echo $referer_cl ? ' selected="selected"' : '' ?>>不包括</option>
                        </select>
                    </div>
                    <div class="fl">
                        <textarea id="referer_content" cols="50" rows="6" class="text ui-widget-content ui-corner-all"><?php echo htmlspecialchars($referer_content) ?></textarea>
                    </div>
                    <span class="tip fl">说明信息：<br>来源域用来定位来自特定域名的访客。<br>每行输入一个域名，以回车换行。<br>输入(direct)表示直达。<br>例如：输入niuxsoft.com域名，则只<br>对从niuxsoft.com来的访客展现广告。</span>
                    <div class="clear"></div>
                </div>
            </div>
            <div id="tabs-9">
                <div>
                    <h3 class="fl tr">投放网址：</h3>
                    <div class="fl">
                        <select id="url_cl" class="selectmenu mid">
                            <option value="0">包括</option>
                            <option value="1"<?php echo $url_cl ? ' selected="selected"' : '' ?>>不包括</option>
                        </select>
                    </div>
                    <div class="fl">
                        <textarea id="url_content" cols="50" rows="6" class="text ui-widget-content ui-corner-all"><?php echo htmlspecialchars($url_content) ?></textarea>
                    </div>
                    <span class="tip fl">说明信息：<br>投放网址用来定位访问特定页面的访客。<br>每行输入一个url，以回车换行。<br>例如：输入栏目news，则只在url中含<br>有news的栏目页面上展现广告。</span>
                    <div class="clear"></div>
                </div>
            </div>
            <div id="tabs-10">
                <div>
                    <h3 class="fl tr">投放地域：</h3>
                    <div class="fl">
                        <select id="local_cl" class="selectmenu mid">
                            <option value="0">包括</option>
                            <option value="1"<?php echo $local_cl ? ' selected="selected"' : '' ?>>不包括</option>
                        </select>
                    </div>
                    <div class="fl">
                        <textarea id="local_content" cols="50" rows="6" class="text ui-widget-content ui-corner-all"><?php echo htmlspecialchars($local_content) ?></textarea>
                    </div>
                    <span class="tip fl">说明信息：<br>每行输入一个地域，以回车换行。<br>例如：输入深圳，则只对深圳访客<br>投放广告。地域只能是 省、市。</span>
                    <div class="clear"></div>
                </div>
            </div>
            <div id="tabs-11">
                <div>
                    <h3 class="fl tr">投放用户UA：</h3>
                    <div class="fl">
                        <select id="ua_cl" class="selectmenu mid">
                            <option value="0">包括</option>
                            <option value="1"<?php echo $ua_cl ? ' selected="selected"' : '' ?>>不包括</option>
                        </select>
                    </div>
                    <div class="fl">
                        <textarea id="ua_content" cols="50" rows="6" class="text ui-widget-content ui-corner-all"><?php echo htmlspecialchars($ua_content) ?></textarea>
                    </div>
                    <span class="tip fl">说明信息：<br>UA用户网关高级设置。<br>每行输入一个特征字符串，以回车换行。<br></span>
                    <div class="clear"></div>
                </div>
            </div>
        </div>
        <div class="ptb hd ui-widget-content"></div>
        <div class="plr ptb">
            <h3 class="fl"></h3>
            <button type="button" class="button" id="submit"> 完 成 </button>
            <button type="button" class="button" id="reset"> 重 置 </button>
            <span class="tip clear"></span>
        </div>
    </form>
</div>
<?php
require './mo_foot.php';
