<%@ Page Language="C#" AutoEventWireup="true" Inherits="System_SubSys_SetSub, QianboCMS" EnableEventValidation="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>创建分站</title>
    <link href="../Css/layout.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../../Js/jquery.js"></script>
    <script type="text/javascript" src="../../Js/lhgdialog/lhgdialog.min.js?self=true"></script>
    <script src="../../Js/Common.js" type="text/javascript"></script>
    <script language="javascript">
        function EWEBeditor_Create(s_ID, s_Style) {
            document.write('<input type="hidden" name="' + s_ID + '" value="">'
                + '<iframe id="' + s_ID + '__Iframe" src="../../Editor/eWebEditor/eWebEditor.htm?id=' + s_ID + '&style=' + s_Style + '" width="0" height="0" style="display: none;" frameborder="0" scrolling="no"></iframe>');
        }
        function EWEBeditor_ShowDialog(s_ID, s_Type, s_Mode, s_LinkID_SavePathFileName, s_LinkID_SaveFileName, s_LinkID_OriginalFileName) {
            var editor = document.getElementById(s_ID + '__Iframe').contentWindow;
            editor.openUploadDialog(s_Type, s_Mode, s_LinkID_SavePathFileName, s_LinkID_SaveFileName, s_LinkID_OriginalFileName)
        }
        EWEBeditor_Create("eWebEditor1", "standard650");
    </script>
    <script language="javascript" type="text/javascript">
        function SetModel() {
            $('lbStyle').options.length = 0;
            var modelCount = document.getElementsByName("chkModel").length;
            var obj = document.getElementsByName("chkModel");
            var modelIdStr = "";
            for (var i = 0; i < modelCount; i++) {
                if (obj[i].checked == true) {
                    modelIdStr += obj[i].value + ","
                }
            }
            System_SubSys_SetSub.GetStyle(modelIdStr + "0", CallbackStyle);
        }
        function CallbackStyle(result) {
            if (result.value == null) {
                return;
            }
            var count = result.value.Rows.length;
            for (var i = 0; i < count; i++) {
                var text = result.value.Rows[i]["Name"];
                var val = result.value.Rows[i]["StyleID"];
                $('lbStyle').options.add(new Option(text, val));
            }
        }
        function SetLabel() {
            $('lbLabel').options.length = 0;
            var modelCount = document.getElementsByName("chkModel").length;
            var obj = document.getElementsByName("chkModel");
            var modelIdStr = "";
            for (var i = 0; i < modelCount; i++) {
                if (obj[i].checked == true) {
                    modelIdStr += obj[i].value + ",";
                }
            }
            System_SubSys_SetSub.GetLabel(modelIdStr + "-2", CallbackLabel);
        }
        function CallbackLabel(result) {
            if (result.value == null) {
                return;
            }
            var count = result.value.Rows.length;
            for (var i = 0; i < count; i++) {
                var text = result.value.Rows[i]["Name"].replace("{Qianbo_", "").replace("}", "");
                var val = result.value.Rows[i]["LabelCategoryID"];
                $('lbLabel').options.add(new Option(text, val));
            }
        }
        function SiteEnName() {
            $("txtDomain").value = $("txtSiteEnName").value + $("txtDomainNone").value;
        }
    </script>
</head>

<body>
    <div id="Layer1" style="position: absolute; width: 100%; height: 100%; z-index: 1; background-color: #cccccc; layer-background-color: #FF0000; border: 1px none #000000; filter: alpha(opacity=50); border: 0px solid #ffffff; display: none;">
        <table width="100%" height="100%" cellpadding="0" cellspacing="0">
            <tr>
                <td align="center" style="line-height: 200%;" height="100%">正在创建分站，请稍候…</td>
            </tr>
        </table>
    </div>
    <form id="form1" runat="server">
        <table align="center" cellpadding="0" cellspacing="1" class="wzdh">
            <tr>
                <td style="padding-left: 10px;">
                    <img src="../Images/Skin/Default/you.gif" align="absmiddle" />
                    您现在的位置：<a href="../SystemInfo.aspx">后台管理</a> &gt;&gt; 设置分站
				</td>
            </tr>
        </table>
        <table align="center" cellpadding="0" cellspacing="1" class="border">
            <tr>
                <td class="wzlist"><a href="SiteList.aspx">分站列表</a></td>
            </tr>
        </table>
        <table cellpadding="0" cellspacing="1" align="center" class="cd">
            <tr align='center'>
                <td id='TabTitle0' onclick="ShowTabs(0)" class="title6">站点设置</td>
                <td id='TabTitle1' onclick="ShowTabs(1)" class="title5">数据库设置</td>
                <td id='TabTitle2' onclick="ShowTabs(2);" class="title5">管理员设置</td>
                <td id='TabTitle3' onclick="ShowTabs(3);" class="title5">模板模型设置</td>
                <td id='TabTitle4' onclick="ShowTabs(4);" class="title5">样式设置</td>
                <td id='TabTitle5' onclick="ShowTabs(5);" class="title5">标签设置</td>
                <td id='TabTitle6' onclick="ShowTabs(6);" class="title5">表单设置</td>
                <td>&nbsp;</td>
            </tr>
        </table>
        <table cellpadding="0" cellspacing="1" class="editborder" align="center">
            <tbody id="Tabs0">
                <tr>
                    <td class="bqleft">站点中文名：</td>
                    <td class="bqright">
                        <asp:TextBox ID="txtSiteName" runat="server"></asp:TextBox>
                        <input id="btnAutoEnName" type="button" value="自动获取英文名" class="btn" onclick="GetEnName()" />
                        <span style="color: red;">* 如开通武汉分站，输入武汉即可。</span>
					</td>
                </tr>
                <tr>
                    <td class="bqleft">站点英文名/域名：</td>
                    <td class="bqright">
                        <asp:TextBox ID="txtSiteEnName" runat="server" Columns="10" onchange="SiteEnName();"></asp:TextBox>
                        <asp:TextBox ID="txtDomain" runat="server" Columns="15"></asp:TextBox>
                        <asp:TextBox ID="txtDomainNone" runat="server" Columns="15" Style="display: none;"></asp:TextBox>
                        <span style="color: red;">*</span>
                        首字母：<asp:TextBox ID="txtSiteChar" runat="server" Width="40px"></asp:TextBox>
                        <input id="Button2" class="btn" type="button" value="检查英文名是否重复" onclick="ChkEnName();" />
					</td>
                </tr>
                <tr>
                    <td class="bqleft">分站Logo：</td>
                    <td class="bqright">
                        <asp:TextBox ID="txtLogo" runat="server" Width="355px"></asp:TextBox>
                        <input id="Button1" class="btn" type="button" value="选择图片" onclick="EWEBeditor_ShowDialog('eWebEditor1', 'image', '0', 'txtLogo', '', '')" />
                        <asp:TextBox ID="FilePicPath" runat="server" Style="display: none;" Text="logos|0"></asp:TextBox>
					</td>
                </tr>
                <tr>
                    <td class="bqleft">排序值：</td>
                    <td class="bqright">
                        <asp:TextBox ID="txtSiteSort" runat="server" Text="999"></asp:TextBox>
					</td>
                </tr>
                <tr>
                    <td class="bqleft">备注：</td>
                    <td class="bqright">
                        <asp:TextBox ID="txtSiteRemark" runat="server" TextMode="MultiLine" Height="100px" Width="400px"></asp:TextBox>
					</td>
                </tr>
            </tbody>
            <tbody id="Tabs1" style="display: none;">
                <tr>
                    <td class="bqleft">数据库服务器IP：</td>
                    <td class="bqright">
                        <asp:TextBox ID="txtServerIp" runat="server" Style="width: 150px;">(local)</asp:TextBox>
                        <span style="color: red;">*</span>
					</td>
                </tr>
                <tr>
                    <td class="bqleft">创建数据库帐号：</td>
                    <td class="bqright">
                        <asp:TextBox ID="txtUserName" runat="server" Style="width: 150px;">sa</asp:TextBox>
                        <span style="color: red;">* 该帐号、密码仅作为创建数据库之用</span>
					</td>
                </tr>
                <tr>
                    <td class="bqleft">创建数据库密码：</td>
                    <td class="bqright">
                        <asp:TextBox ID="txtPass" runat="server" TextMode="Password" Style="width: 150px;">123456</asp:TextBox>
                        <input id="btnTest" class="btn" type="button" value="测试连接" onclick="conn();" />
                        <label id="loading" style="display: none;">正在测试连接，请稍候…</label>
					</td>
                </tr>
                <tr>
                    <td class="bqleft">访问数据库帐号：</td>
                    <td class="bqright">
                        <asp:TextBox ID="txtCallName" runat="server" Style="width: 150px;"></asp:TextBox>
                        <input id="Button3" class="btn" type="button" value="检查是否重复" onclick="CheckSqlLogin();" />
                        <span style="color: red;">*</span>
					</td>
                </tr>
                <tr>
                    <td class="bqleft">访问数据库密码：</td>
                    <td class="bqright">
                        <asp:TextBox ID="txtCallPass" runat="server" TextMode="Password" Style="width: 150px;"></asp:TextBox>
                        <span style="color: red;">*</span>
					</td>
                </tr>
                <tr id="trDbName">
                    <td class="bqleft">新数据库名称：</td>
                    <td class="bqright">
                        <asp:TextBox ID="txtDbName" runat="server" Style="width: 150px;"></asp:TextBox>
                        <input id="Button5" class="btn" type="button" value="检查是否重复" onclick="CheckDataBase();" />
                        <span style="color: red;">*</span>
					</td>
                </tr>
            </tbody>
            <tbody id="Tabs2" style="display: none;">
                <!--
                <tr>
					<td class="bqleft">管理组：</td>
					<td class="bqright">
						<asp:DropDownList ID="DDlistGroup" runat="server"></asp:DropDownList>
					</td>
                </tr>
				-->
                <tr>
                    <td class="bqleft">管理员登录名：</td>
                    <td class="bqright">
                        <asp:TextBox ID="txtAdmLoginName" runat="server" Style="width: 150px;"></asp:TextBox>
                        <input id="Button4" class="btn" type="button" value="检查是否重复" onclick="CheckAdminLogin();" />
                        <font color="red">* 若不添加管理员，请留空。</font>
					</td>
                </tr>
                <tr>
                    <td class="bqleft">密码：</td>
                    <td class="bqright">
                        <asp:TextBox ID="txtAdmPass" runat="server" TextMode="Password" Style="width: 150px;"></asp:TextBox>
                        密码长度请保持在6个字符以上
					</td>
                </tr>
                <tr>
                    <td class="bqleft">重复密码：</td>
                    <td class="bqright">
                        <asp:TextBox ID="txtAdmPassCfm" runat="server" TextMode="Password" Style="width: 150px;"></asp:TextBox>
                        必须与密码一致
					</td>
                </tr>
                <tr>
                    <td class="bqleft">真实姓名：</td>
                    <td class="bqright">
                        <asp:TextBox ID="txtAdmRealName" runat="server" Style="width: 150px;"></asp:TextBox>
					</td>
                </tr>
                <tr>
                    <td class="bqleft">联系方式：</td>
                    <td class="bqright">
                        <asp:TextBox ID="txtAdmContact" runat="server" Columns="35"></asp:TextBox>
					</td>
                </tr>
            </tbody>
            <script type="text/javascript">
                var jq = jQuery.noConflict();
                jQuery(function () {
                    jQuery('#btnSelectTemplate').click(function () {
                        jQuery.dialog({
                            id: 'txtSelectTemplate',
                            lock: true,
                            title: '选择模板',
                            content: "url:SelectTemplate.aspx",
                            width: 800,
                            height: 500
                        });
                    });
                });
            </script>
            <tbody id="Tabs3" style="display: none;">
                <tr>
                    <td class="bqleft">模板设置：</td>
                    <td class="bqright">
                        <asp:TextBox ID="txtTemplate" name="txtTemplate" runat="server" Width="200px"></asp:TextBox>
                        <input id="btnSelectTemplate" class="btn" type="button" value="选择模板" />
					</td>
                </tr>
                <tr>
                    <td class="bqleft">模型设置：</td>
                    <td class="bqright" id="tdCheckAllModel">
                        <asp:Repeater runat="server" ID="repModel">
                            <ItemTemplate>
                                <input id="chkModel" name="chkModel" type="checkbox" value='<%# Eval("ModelId") %>' onclick="SetModel(); SetLabel()" />
                                <asp:Literal runat="server" ID="ltName" Text='<%# Eval("ModelName") %>'></asp:Literal>
                            </ItemTemplate>
                        </asp:Repeater>
                        <asp:CheckBox ID="chkIsSubCreModel" runat="server" Text="允许分站自建模型" />
                        <br />
                        <input id="checkAll" type="checkbox" onclick="checkedAll()" />全选
					</td>
                </tr>
            </tbody>
            <tbody id="Tabs4" style="display: none;">
                <tr>
                    <td class="bqleft">选择样式：</td>
                    <td class="bqright">
                        <asp:ListBox ID="lbStyle" name="lbStyle" runat="server" Height="351px" SelectionMode="Multiple" Width="250px"></asp:ListBox>
                        <br />
                        按住Ctrl键可多选
					</td>
                </tr>
            </tbody>
            <tbody id="Tabs5" style="display: none;">
                <tr>
                    <td class="bqleft">选择标签：</td>
                    <td class="bqright">
                        <asp:ListBox ID="lbLabel" name="lbLabel" runat="server" Height="351px" SelectionMode="Multiple" Width="250px"></asp:ListBox>
                        <br />
                        按住Ctrl键可多选
					</td>
                </tr>
            </tbody>
            <tbody id="Tabs6" style="display: none;">
                <tr>
                    <td class="bqleft">选择表单：</td>
                    <td class="bqright">
                        <asp:ListBox ID="lbCustomForm" name="lbLabel" runat="server" Height="351px" SelectionMode="Multiple" Width="250px"></asp:ListBox>
                        <br />
                        按住Ctrl键可多选
					</td>
                </tr>
            </tbody>
            <tr>
                <td class="bqleft"></td>
                <td class="bqright">
                    <asp:Button ID="btnOk" runat="server" CssClass="btn" Text="确定" OnClientClick="return Chk();" OnClick="btnOk_Click" />
                    <input id="Reset1" class="btn" type="reset" value="重置" />
                    <asp:HiddenField ID="ChId" runat="server" />
                </td>
            </tr>
        </table>
        <asp:Literal ID="LitInfo" runat="server"></asp:Literal>
    </form>
</body>
</html>
<script type="text/javascript">
    var loading = $("loading");
    var btn = $("btnTest");
    function conn() {
        var pass = $("txtPass");
        var ip = $("txtServerIp");
        var uid = $("txtUserName");
        if (ip.value == "") {
            alert('请输入数据库服务器IP！');
            ip.focus();
            return false;
        }
        if (uid.value == "") {
            alert('请输入用户名！');
            uid.focus();
            return false;
        }
        loading.style.display = "";
        btn.disabled = "disabled";
        System_SubSys_SetSub.CanConnect("Server=" + ip.value + ";uid=" + uid.value + ";pwd=" + pass.value, CallBack);
    }
    function CallBack(res) {
        loading.style.display = "none";
        btn.disabled = "";
        if (res.value == "true") {
            alert("数据库连接成功！");
        }
        else {
            alert("数据库连接失败！");
        }
    }
    function Chk() {
        var ip = $("txtServerIp");
        var uname = $("txtUserName");
        var dbName = $("txtDbName");
        var siteName = $("txtSiteName")
        var enname = $("txtSiteEnName")
        if (siteName.value == "") {
            alert('请输入站点中文名！');
            return false;
        }
        if (enname.value == "") {
            alert("请输入站点英文名！");
            return false;
        }
        var patt = /[0-9]+/;
        if (!patt.test($("txtSiteSort").value)) {
            alert("排序值必须为数字字符！");
            return false;
        }
        if (ip.value == "") {
            alert('请输入数据库服务器IP！');
            return false;
        }
        if (uname.value == "") {
            alert('请输入数据库用户名！');
            return false;
        }
        if (dbName.value == "") {
            alert("请输入新数据库名称！");
            return false;
        }
        if ($("txtCallName").value == "") {
            alert("访问数据库名称不能为空！")
            $("txtCallName").focus();
            return false;
        }
        if ($("txtCallPass").value == "") {
            alert("访问数据库密码不能为空！");
            $("txtCallPass").focus();
            return false;
        }
        if ($("txtAdmLoginName").value != "") {
            if ($("txtAdmPass").value.length < 6) {
                alert("密码长度请保持在6个字符以上！");
                return false;
            }
            if ($("txtAdmPass").value != $("txtAdmPassCfm").value) {
                alert("两次输入的管理员密码不一样，请重新输入！");
                return false;
            }
            if ($("txtAdmRealName").value == "") {
                alert("请填写真实姓名！");
                $("txtAdmRealName").focus();
                return false;
            }
        }
        Layer1.style.display = "";
        form1.style.display = "none";
        return true;
    }
    function GetEnName() {
        System_SubSys_SetSub.GetEnName($("txtSiteName").value, EnName_CallBack);
        System_SubSys_SetSub.GetFirstChar($("txtSiteName").value, EnChar_CallBack);
    }
    function EnName_CallBack(res) {
        $("txtSiteEnName").value = res.value;
        $("txtDomain").value = res.value + $("txtDomainNone").value;
    }
    function EnChar_CallBack(res) {
        $("txtSiteChar").value = res.value;
    }
    function ChkEnName() {
        if ($("txtSiteEnName").value == "") {
            alert("请输入英文名！");
            return false;
        }
        System_SubSys_SetSub.CheckEnName($("txtSiteEnName").value, Chk_EnName);
    }
    function Chk_EnName(res) {
        if (res.value == "true")
            alert("英文名已存在！");
        if (res.value == "false")
            alert("英文名可以使用！");
    }
    function checkedAll() {
        template = "";
        var s = document.getElementById("tdCheckAllModel").getElementsByTagName("INPUT");
        for (var i = 0; i < s.length; i++) {
            if (s[i].type == "checkbox") {
                s[i].checked = document.getElementById("checkAll").checked;
            }
        }
        SetModel();
        SetLabel();
    }
    function CheckSqlLogin() {
        var callname = $("txtCallName").value;
        var ip = $("txtServerIp").value;
        var uid = $("txtUserName").value;
        var pass = $("txtPass").value;
        if (callname.length == 0 || ip.length == 0 || uid.length == 0 || pass.length == 0) {
            alert("数据库服务器IP、创建数据库帐号、创建数据库密码、访问数据库帐号不能为空！");
            return false;
        }
        System_SubSys_SetSub.CheckSqlLogin(callname, ip, uid, pass, Call_Back_SqlLogin);
    }
    function Call_Back_SqlLogin(res) {
        if (res.value == "True") {
            alert("访问数据库帐号可以创建！");
        }
        else {
            alert("访问数据库帐号已存在！");
        }
    }
    function CheckAdminLogin() {
        var adminname = $("txtAdmLoginName").value;
        if (adminname.length == 0) {
            alert("请输入分站管理员登录名！");
            return false;
        }
        System_SubSys_SetSub.CheckAdminLogin(adminname, Call_Back_SqlAdmin);
    }
    function Call_Back_SqlAdmin(res) {
        if (res.value == "True") {
            alert("分站管理员登录名已存在，请重新输入！");
        }
        else {
            alert("分站管理员登录名可以使用！");
        }
    }
    function CheckDataBase() {
        var name = $("txtDbName").value;
        var ip = $("txtServerIp").value;
        var uid = $("txtUserName").value;
        var pass = $("txtPass").value;
        if (name.length == 0 || ip.length == 0 || uid.length == 0 || pass.length == 0) {
            alert("数据库服务器IP、创建数据库帐号、创建数据库密码、新数据库名称不能为空！");
            return false;
        }
        System_SubSys_SetSub.CheckDataBase(name, ip, uid, pass, Call_Back_Database);
    }
    function Call_Back_Database(res) {
        if (res.value == "True") {
            alert("数据库名称可以创建！");
        }
        else {
            alert("数据库名称已存在！");
        }
    }
</script>