<?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;
    }
    select {
        width: 20em;
    }
    .text {
        width: 40em;
        font-size: 1em;
        padding: .6em;
    }
    .tip {
        margin-left: 12px;
        padding: .3em;
        display: inline-block;
    }
    #ggContent {
        height: 15em;
        width: 60em;
    }
    #clear{
        top: -2.6em;
        left: -.6em;
    }
    #ggWidth, #ggHeight {
        width: 5em;
    }
    label{
        display: block;
    }
    .dialogText{
        font-size: 1em;
        padding: .3em;
    }
    #textContent{
        width: 95%;
        height: 4em;
    }
    #textSize{
        width: 2em;
    }
    #sizeUnit{
        width: 4.2em;
    }
    #textLink{
        width: 95%;
    }
    #imgUrl,#imgAlt,#imgLink{
        width: 95%;
    }
    #imgW,#imgH{
        width: 3em;
    }
    #fileUrl{
        width: 95%;
    }
    #flashW,#flashH{
        width: 3em;
    }
    #ajaxList,ajaxListUp{
        margin: .6em 0;
    }
    #ajaxList table th,#ajaxListUp table th{
        border-width:0px 1px 0px 0px;
        font-size:1.2em;
        line-height:2em;
    }
    #ajaxList table td,#ajaxListUp table td{
        border-width:0px 1px 1px 0px;
        font-size: 1em;
        line-height: 1.8em;
        overflow: hidden;
    }
    .yulan{
        cursor: pointer;
    }
    .ui-tooltip {
        max-width: 1200px;
        word-break: break-all;
    }
</style>
<script>
    $(function () {
        var obj = $("#ggContent").get(0);
        $("#ggTitle").val(unescape($("#ggTitle").val()));
        $("#ggContent").val(unescape($("#ggContent").val()));
        $("#clear").click(function () {
            $("#ggContent").val('');
        });
        function show_hrefDiv() {
            if ($("input[name='type']:checked").val() == 1 && $("input[name='tj']:checked").val() == 1) {
                $("#href_div").show();
            } else {
                $("#href_div").hide();
            }
        }
        show_hrefDiv();
        $("input[name='type']").click(function () {
            show_hrefDiv();
        });
        $("input[name='tj']").click(function () {
            show_hrefDiv();
        });
        $("#dialog_textGG").dialog({
            autoOpen: false,
            width: 400,
            modal: true,
            buttons: {
                "生成原代码": function () {
                    var code = '<a href="' + $("#textLink").val() + '" target="'
                            + $("input[name='textTag']:checked").val() + '" style="font-size: '
                            + $("#textSize").val() + $("#sizeUnit option:selected").val()
                            + ';">' + $("#textContent").val() + '</a>';
                    codeInsert(obj, code);
                    $(this).dialog("close");
                },
                "取消": function () {
                    $(this).dialog("close");
                }
            }
        });
        $("#textGG").click(function () {
            $("#dialog_textGG").dialog("open");
        });
        $("#dialog_imgGG").dialog({
            autoOpen: false,
            width: 400,
            modal: true,
            buttons: {
                "生成原代码": function () {
                    var code = '<a href="' + $("#imgLink").val() + '" target="'
                            + $("input[name='imgTag']:checked").val() + '"><img src="' + $("#imgUrl").val()
                            + '" alt="' + $("#imgAlt").val() + '" border="0" width="'
                            + $("#imgW").val() + '" height="' + $("#imgH").val() + '" /></a>';
                    codeInsert(obj, code);
                    $(this).dialog("close");
                },
                "取消": function () {
                    $(this).dialog("close");
                }
            }
        });
        $("#imgGG").click(function () {
            $("#dialog_imgGG").dialog("open");
        });
        $("#dialog_flashGG").dialog({
            autoOpen: false,
            width: 400,
            modal: true,
            buttons: {
                "生成原代码": function () {
                    var code = '<embed src="' + $("#fileUrl").val() + '" quality="high" width="'
                            + $("#flashW").val() + '" height="' + $("#flashH").val()
                            + '" align="middle" type="application/x-shockwave-flash"></embed>';
                    codeInsert(obj, code);
                    $(this).dialog("close");
                },
                "取消": function () {
                    $(this).dialog("close");
                }
            }
        });
        $("#flashGG").click(function () {
            $("#dialog_flashGG").dialog("open");
        });
        $("#dialog_ggTemp").dialog({
            autoOpen: false,
            width: 600,
            modal: true,
            position: {my: "center", at: "top", of: window}
        });
        $("#ggTemp").click(function () {
            $("#ajaxList").load("gg_template_list.php?menu=ajax", function () {
                $(".ajaxButton").button();
            });
            $("#dialog_ggTemp").dialog("open");
        });
        $(document).tooltip({
            items: "[data-dm],[title],[data-url]",
            content: function () {
                var element = $(this);
                if (element.is("[title]")) {
                    return element.attr("title").replace(/\n/igm, "<br>");
                } else if (element.is("[data-dm]")) {
                    return htmlspecialchars(element.attr("data-dm")).replace(/\n/igm, "<br>").replace(/\s/igm, "&nbsp;");
                } else if (element.is("[data-url]")) {
                    if (element.attr("data-url").match(/\.(gif|jpeg|jpg|png|bmp)$/ig)) {
                        return '<img src="' + element.attr("data-url") + '">';
                    } else if (element.attr("data-url").match(/\.(swf)$/ig)) {
                        return '<embed src="' + element.attr("data-url") + '" quality="high" align="middle" type="application/x-shockwave-flash"></embed>';
                    }
                }
            }
        });
        $(document).on("click", ".yulan", function () {
            var code = $(this).parent().next().children("button").val();
            var myWin = window.open();
            myWin.document.write(code);
        });
        $(document).on("click", ".charu", function () {
            var code = $(this).val();
            codeInsert(obj, code);
            $("#dialog_ggTemp").dialog("close");
        });
        $(document).on("click", ".firstPage", function () {
            $("#ajaxList").load("gg_template_list.php?menu=ajax", function () {
                $(".ajaxButton").button();
            });
        });
        $(document).on("click", ".prePage", function () {
            $("#ajaxList").load("gg_template_list.php?menu=ajax&page=" + $(this).val(), function () {
                $(".ajaxButton").button();
            });
        });
        $(document).on("click", ".nexPage", function () {
            $("#ajaxList").load("gg_template_list.php?menu=ajax&page=" + $(this).val(), function () {
                $(".ajaxButton").button();
            });
        });
        $(document).on("click", ".pages", function () {
            $("#ajaxList").load("gg_template_list.php?menu=ajax&page=" + $(this).val(), function () {
                $(".ajaxButton").button();
            });
        });
        $("#dialog_Up").dialog({
            autoOpen: false,
            width: 600,
            modal: true,
            position: {my: "center", at: "top", of: window}
        });
        $("#selectImgs,#selectUps").click(function () {
            $("#ajaxListUp").load("upload_list.php?menu=ajax", function () {
                $(".ajaxButton").button();
            });
            $("#dialog_Up").dialog("open");
        });
        $(document).on("click", ".charuup", function () {
            var url = $(this).val(), w = $(this).parent().prev().prev().text(), h = $(this).parent().prev().text();
            $("#fileUrl").val(url);
            $("#imgUrl").val(url);
            $("#imgW").val(w);
            $("#imgH").val(h);
            $("#flashW").val(w);
            $("#flashH").val(h);
            $("#dialog_Up").dialog("close");
        });
        $(document).on("click", ".firstPageup", function () {
            $("#ajaxListUp").load("upload_list.php?menu=ajax", function () {
                $(".ajaxButton").button();
            });
        });
        $(document).on("click", ".prePageup", function () {
            $("#ajaxListUp").load("upload_list.php?menu=ajax&page=" + $(this).val(), function () {
                $(".ajaxButton").button();
            });
        });
        $(document).on("click", ".nexPageup", function () {
            $("#ajaxListUp").load("upload_list.php?menu=ajax&page=" + $(this).val(), function () {
                $(".ajaxButton").button();
            });
        });
        $(document).on("click", ".pagesup", function () {
            $("#ajaxListUp").load("upload_list.php?menu=ajax&page=" + $(this).val(), function () {
                $(".ajaxButton").button();
            });
        });
        $("#yuLan").click(function () {
            var myWin = window.open();
            myWin.document.write($("#ggContent").val());
        });
        $("#submit").click(function () {
            if (checkInput('#ggTitle', /^.{1,80}$/) && checkInput('#ggContent', /^[\s\S]{1,10000}$/)
                    && checkInput('#ggWidth', /^\d{0,5}$/) && checkInput('#ggHeight', /^\d{0,5}$/) && checkInput('#ggHref', /^.{0,255}$/)) {
                var id = <?php echo $id ?>, recycle = <?php echo $recycle ?>, copy = '<?php echo $copy ?>';
                if (id && !recycle && !copy && !confirm('修改即刻生效！您确定要修改吗？'))
                    return false;
                loading();
                setCoo('lei1', $("#ggLei option:selected").val(), 120);
                setCoo('zu1', $("#ggZu option:selected").val(), 120);
                setCoo('ggTj', $("input[name='tj']:checked").val(), 120);
                $.ajax({
                    type: "POST",
                    url: location.href,
                    data: {
                        menu: "submit",
                        id: id,
                        ggTitle: escape($("#ggTitle").val()),
                        ggType: $("input[name='type']:checked").val(),
                        ggContent: escape($("#ggContent").val()),
                        ggWidth: $("#ggWidth").val(),
                        ggHeight: $("#ggHeight").val(),
                        ggLei: $("#ggLei").val(),
                        ggZu: $("#ggZu").val(),
                        ggTj: $("input[name='tj']:checked").val(),
                        ggHref: $("#ggHref").val(),
                        ggYb: $("input[name='yb']:checked").val()
                    },
                    success: function (msg) {
                        loaded();
                        if (msg == "1") {
                            dialog('恭喜你，添加广告成功！是否继续添加广告？', 1, location.href);
                        } else if (msg == "2") {
                            dialog('恭喜你，修改广告成功！是否继续修改广告？', 1, location.href);
                        } else {
                            dialog(msg);
                        }
                    }
                });
            }
        });
        $("#reset").click(function () {
            window.location.reload(true);
        });
    });
</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>
            <input class="text fl ui-widget-content ui-corner-all" id="ggTitle" value="<?php echo $ggTitle ?>" placeholder="不超过80个汉字">
            <span class="tip clear">* 不超过80个汉字</span>
        </div>
        <div class="plr ptb">
            <h3 class="fl">广告类型</h3>
            <p class="buttonset fl">
                <input type="radio" id="type1" value="0" name="type"<?php echo ($ggType ? '' : ' checked="checked"') ?>><label for="type1">固定占位</label>
                <input type="radio" id="type2" value="1" name="type"<?php echo ($ggType ? ' checked="checked"' : '') ?>><label for="type2">非固定占位</label>
            </p>
            <span class="tip clear">固定占位：占有网页内容的部分固定位置来展现广告。非固定占位：不是固定占位的广告，如，漂浮、弹窗等。</span>
        </div>
        <div class="plr ptb">
            <h3 class="fl">广告源代码</h3>
            <textarea class="text fl ui-widget-content ui-corner-all" id="ggContent" placeholder="不超过10000字符"><?php echo $ggContent ?></textarea>
            <span class="tip clear">* 支持HTML/Javascript代码</span>
            <span class="ui-icon ui-icon-circle-close rePos" id="clear" style="cursor: pointer;" title="清空"></span>
        </div>
        <div class="plr ptb clear">
            <h3 class="fl">工具</h3>
            <button type="button" class="button" id="textGG">文字</button>
            <button type="button" class="button" id="imgGG">图片</button>
            <button type="button" class="button" id="flashGG">flash</button>
            <button type="button" class="button" id="ggTemp">模板</button>
            <button type="button" class="button" id="yuLan" title="有些智能广告在虚拟页面是不显示的。">预览</button>
            <span class="tip clear">&nbsp;</span>
        </div>
        <div class="plr ptb">
            <h3 class="fl">广告展示尺寸</h3>
            <input class="text ui-widget-content ui-corner-all" id="ggWidth" value="<?php echo $ggWidth ?>" placeholder="小于6位数"><span>宽度(px)</span> &times;
            <input class="text ui-widget-content ui-corner-all" id="ggHeight" value="<?php echo $ggHeight ?>" placeholder="小于6位数"><span>高度(px)</span>
            <span class="tip clear">&nbsp;</span>
        </div>
        <div class="plr ptb">
            <h3 class="fl">广告分类</h3>
            <p class="fl">
                <select class="selectmenu" id="ggLei"><?php echo $ggLeiSelectList ?></select>
            </p>
            <span class="tip clear">&nbsp;</span>
        </div>
        <div class="plr ptb">
            <h3 class="fl">广告分组</h3>
            <p class="fl">
                <select class="selectmenu" id="ggZu"><?php echo $ggZuSelectList ?></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="tj1" value="0" name="tj"<?php echo ($ggTj ? '' : ' checked="checked"') ?>><label for="tj1">关闭统计</label>
                <input type="radio" id="tj2" value="1" name="tj"<?php echo ($ggTj ? ' checked="checked"' : '') ?>><label for="tj2">开启统计</label>
            </p>
            <span class="tip clear">&nbsp;</span>
        </div>
        <div class="plr ptb hide" id="href_div">
            <h3 class="fl">监听点击去向</h3>
            <input class="text fl ui-widget-content ui-corner-all" id="ggHref" value="<?php echo htmlspecialchars($ggHref) ?>" placeholder="链接的href或iframe的src或id主体特征。不能有特殊字符，不超过255个字符">
            <span class="tip clear">&nbsp;非固定占位广告点击统计需要填写链接的href或iframe的src或id主体特征。</span>
        </div>
        <div class="plr ptb">
            <h3 class="fl">广告异步加载</h3>
            <p class="buttonset fl">
                <input type="radio" id="yb1" value="0" name="yb"<?php echo ($ggYb ? '' : ' checked="checked"') ?>><label for="yb1">自动</label>
                <input type="radio" id="yb2" value="1" name="yb"<?php echo ($ggYb ? ' checked="checked"' : '') ?>><label for="yb2">强制</label>
            </p>
            <span class="ui-icon ui-icon-help fl mlr" style="cursor: pointer;" title="自动异步加载：广告源代码不包含script代码，异步加载。否则同步加载！
                  强制异步加载：广告源代码包含script代码但确定不包含document.write语句，并且广告商允许异步加载，可强制异步加载。
                  广告商代码本身异步加载：请选自动！
                  广告列表-展现-鼠标滑过：正常显示，没有变空白的可确定不包含document.write语句！"></span>
            <span class="tip clear">&nbsp;</span>
        </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>

<div id="dialog_textGG" title="创建文字广告：" class="hide">
    <p class="mtb">
        <label>文字内容：</label>
        <textarea class="dialogText ui-widget-content ui-corner-all" id="textContent"></textarea>
    </p>
    <p class="mtb">
        <label>文字大小：</label>
        <input id="textSize" value="1" class="dialogText ui-widget-content ui-corner-all">
        <select class="dialogText ui-widget-content ui-corner-all" id="sizeUnit">
            <option value="em">em</option>
            <option value="px">px</option>
            <option value="pt">pt</option>
        </select>
    </p>
    <p class="mtb">
        <label>点击链接：</label>
        <input id="textLink" value="http://" class="dialogText ui-widget-content ui-corner-all">
    </p>
    <p class="buttonset mtb">
        <label>目标窗口：</label>
        <input type="radio" id="textTag1" value="_blank" name="textTag" checked="checked"><label for="textTag1">新窗口</label>
        <input type="radio" id="textTag2" value="_self" name="textTag"><label for="textTag2">原窗口</label>
    </p>
</div>

<div id="dialog_imgGG" title="创建图片广告：" class="hide">
    <p class="mtb">
        <label>图片文件：</label>
        <input id="imgUrl" class="dialogText ui-widget-content ui-corner-all">
        <iframe id="imgUp" class="dialogText ui-widget-content ui-corner-all" src="upload.php" frameborder="0" scrolling="no" height="40px" width="95%"></iframe>
        <button class="button" id="selectImgs">图库中选择</button>
    </p>
    <p class="mtb">
        <label>图片尺寸：</label>
        <input id="imgW" class="dialogText ui-widget-content ui-corner-all">宽&times;
        <input id="imgH" class="dialogText ui-widget-content ui-corner-all">高(px)
    </p>
    <p class="mtb">
        <label>图片描述：</label>
        <input id="imgAlt" class="dialogText ui-widget-content ui-corner-all">
    </p>
    <p class="mtb">
        <label>点击链接：</label>
        <input id="imgLink" value="http://" class="dialogText ui-widget-content ui-corner-all">
    </p>
    <p class="buttonset mtb">
        <label>目标窗口：</label>
        <input type="radio" id="imgTag1" value="_blank" name="imgTag" checked="checked"><label for="imgTag1">新窗口</label>
        <input type="radio" id="imgTag2" value="_self" name="imgTag"><label for="imgTag2">原窗口</label>
    </p>
</div>

<div id="dialog_flashGG" title="创建flash广告：" class="hide">
    <p class="mtb">
        <label>flash文件：</label>
        <input id="fileUrl" class="dialogText ui-widget-content ui-corner-all">
        <iframe id="flashUp" class="dialogText ui-widget-content ui-corner-all" src="upload.php" frameborder="0" scrolling="no" height="40px" width="95%"></iframe>
        <button class="button" id="selectUps">素材库中选择</button>
    </p>
    <p class="mtb">
        <label>flash尺寸：</label>
        <input id="flashW" class="dialogText ui-widget-content ui-corner-all">宽&times;
        <input id="flashH" class="dialogText ui-widget-content ui-corner-all">高(px)
    </p>
</div>

<div id="dialog_ggTemp" title="广告模版：" class="hide">
    <div id="ajaxList"></div>
</div>

<div id="dialog_Up" title="上传文件：" class="hide">
    <div id="ajaxListUp"></div>
</div>
<?php
require './mo_foot.php';
