<%@ Page Language="C#" MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="true"
    Inherits="PowerEasy.Module.General.WebSite.Admin.Accessories.MailListSend" Title="发送邮件列表"
    ValidateRequest="false" CodeBehind="MailListSend.aspx.cs" Async="true" %>

<asp:Content ID="Content1" ContentPlaceHolderID="CphNavigation" runat="Server">
    <pe:ExtendedSiteMapPath ID="SmpNavigator" SiteMapProvider="AdminMapProvider" runat="server" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="CphContent" runat="Server">
<asp:PlaceHolder runat="server" ID="PhSendMail">
    <script type="text/javascript">
        function SelectUser()
        {            
            var newwin = window.open('../User/UserNameList.aspx?TypeSelect=UserList&Default='+ escape(document.getElementById(<%="'" +TxtUserName.ClientID + "'" %>).value),'UserNameList','width=670,height=400,resizable=0,scrollbars=yes');
            newwin.focus();
        }
        
        function DoPostBack(value)
        {
            document.getElementById('<%=TxtUserName.ClientID%>').value=value;
        }
        
        function CheckAllById(id,count,item){
            if(item){
                var checkedCout=0;
                for(var i=1;i<=count;i++){
                    if(document.getElementById(id+"_"+i).checked){
                        checkedCout++;
                    }else{
                        break;
                    }
                }
                if(checkedCout==count){
                    document.getElementById(id+"_0").checked=true;
                }else{
                    document.getElementById(id+"_0").checked=false;
                }
            }else{
                for(var i=1;i<=count;i++){
                    document.getElementById(id+"_"+i).checked = document.getElementById(id+"_0").checked
                }
            }
        }

    </script>

    <table width="100%" border="0" cellpadding="2" cellspacing="1" class="border">
        <tr>
            <td align="center" colspan="3" class="spacingtitle">
                <b>邮件发送</b>
            </td>
        </tr>
        <tr class="tdbg">
            <td width="15%" align="right" class="tdbgleft">
                <strong>收件人选择：</strong>
            </td>
            <td style="text-align: left" colspan="3">
                <table>
                    <tr>
                        <td>
                            <asp:RadioButton ID="RadUserType0" runat="server" GroupName="UserType" Text="所有会员"
                                Checked="True" />
                        </td>
                        <td>
                        </td>
                    </tr>
                    <tr>
                        <td valign="top">
                            <asp:RadioButton ID="RadUserType1" runat="server" GroupName="UserType" Text="指定会员组" />
                        </td>
                        <td>
                            <asp:CheckBoxList ID="ChklUserGroupList" runat="server" RepeatColumns="5" RepeatDirection="Horizontal"
                                Width="100%">
                            </asp:CheckBoxList>
                        </td>
                    </tr>
                    <tr>
                        <td valign="top">
                            <asp:RadioButton ID="RadUserType2" runat="server" GroupName="UserType" Text="指定用户名" />
                        </td>
                        <td>
                            <asp:TextBox ID="TxtUserName" runat="server" Width="260px"></asp:TextBox>
                            <span style="color: blue"><=【</span><span style='cursor: pointer;' onclick="SelectUser();"><span
                                style="color: green">会员列表</span></span><span style="color: blue">】</span>多个用户名间请用<span
                                    style="color: blue">英文的逗号</span>分隔
                        </td>
                    </tr>
                    <tr>
                        <td valign="top">
                            <asp:RadioButton ID="RadUserType3" runat="server" GroupName="UserType" Text="指定会员Email" />
                        </td>
                        <td>
                            <asp:TextBox ID="TxtEmails" runat="server" Width="260px"></asp:TextBox>
                            多个Email间请用<span style="color: blue">英文的逗号</span>分隔
                        </td>
                    </tr>
                    <tr>
                        <td valign="top">
                            <asp:RadioButton ID="RadUserType4" runat="server" GroupName="UserType" Text="邮件订阅用户" />
                        </td>
                        <td>
                            <asp:CheckBoxList ID="cblSubscriptionItems" runat="server" DataTextField="Name" DataValueField="Id"
                                RepeatDirection="Horizontal" RepeatColumns="4" Width="100%">
                            </asp:CheckBoxList>
                            <asp:HyperLink ID="hlAddSubscriptionItem" runat="server" Visible="false" NavigateUrl="./MailSubscriptionConfig.aspx"
                                ForeColor="Green">请先添加订阅项!</asp:HyperLink>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr class="tdbg">
            <td align="right" class="tdbgleft">
                <strong>邮件主题：</strong>
            </td>
            <td colspan="3">
                <asp:TextBox ID="TxtSubject" runat="server" Width="390px"></asp:TextBox>
                <pe:RequiredFieldValidator ID="ValrSubject" runat="server" ControlToValidate="TxtSubject"
                    Display="Dynamic" ErrorMessage="邮件主题不能为空！"></pe:RequiredFieldValidator>
            </td>
        </tr>
        <tr class="tdbg">
            <td align="right" class="tdbgleft">
                <strong>邮件内容：</strong>
            </td>
            <td>
                <pe:CKeditor Height="220px" Width="600px" ID="EditorContent" runat="server" Toolbar="Simple"
                   LinkUpload="true" ImageUpload="true" FlashUpload="true" ModuleName="email" FileRecord="true">
                </pe:CKeditor>
                <pe:CKeditorValidator ID="CKeditorValidator1" runat="server" ControlToValidate="EditorContent"
                    Display="Dynamic" ErrorMessage="邮件内容不能为空！"></pe:CKeditorValidator>
            </td>
        </tr>
        <tr class="tdbg">
            <td align="right" class="tdbgleft">
               <strong>邮件内容中可用标签变量说明：</strong>
            </td>
            <td>
                <table id="taglist">
                <tr>
                 <td><a target="_self">{$UserName}</a>：用户名</td>
                 <td><a target="_self">{$UserId}</a>：会员ID</td>
                 <td><a target="_self">{$Email}</a>：电子邮箱</td>
                </tr>
                <tr>
                 <td><a target="_self">{$GroupId}</a>：会员组ID</td>
                 <td><a target="_self">{$GroupName}</a>：会员组名称</td>
                 <td><a target="_self">{$RegTime}</a>：注册时间</td>
                </tr>
                <tr>
                 <td><a target="_self">{$LogOnTimes}</a>：登录次数</td>
                 <td><a target="_self">{$ConsumeExp}</a>：用户消费积分</td>
                 <td><a target="_self">{$UserPoint}</a>：用户点券数</td>
                </tr>
                <tr>
                 <td><a target="_self">{$ConsumeMoney}</a>：消费的金额</td>
                 <td><a target="_self">{$ConsumePoint}</a>：消费的点券数</td>
                 <td><a target="_self">{$AlipayUserID}</a>：支付宝用户ID</td>
                </tr>
                <tr>
                 <td><a target="_self">{$EndDays}</a>：有效期剩余天数</td>
                 <td><a target="_self">{$GetPasswordTime}</a>：上一次取回密码时间</td>
                 <td><a target="_self">{$JoinTime}</a>：加入某会员组的时间</td>
                </tr>
                <tr>
                 <td><a target="_self">{$LastAddPointTime}</a>：最后赠送点券时间</td>
                 <td><a target="_self">{$LastLogOnTime}</a>：最后登录时间</td>
                 <td><a target="_self">{$LastLockoutTime}</a>：上次被锁定的时间</td>
                </tr>
                <tr>
                 <td><a target="_self">{$LastPresentTime}</a>：最后赠送积分时间</td>
                 <td><a target="_self">{$LastLogOnIP}</a>：最后登录IP</td>
                 <td><a target="_self">{$PostItems}</a>：添加的信息数</td>
                </tr>
                <tr>
                 <td><a target="_self">{$DelItems}</a>：被删除的信息数</td>
                 <td><a target="_self">{$RejectItems}</a>：被退稿的信息数</td>
                 <td><a target="_self">{$PassedItems}</a>：审核通过的信息数</td>
                </tr>
                <tr>
                 <td><a target="_self">{$UserExp}</a>：会员积分数</td>
                 <td><a target="_self">{$Question}</a>：密码提示问题</td>
                 <td><%--<a target="_self">{$HonorType}</a>：会员头衔--%></td>
                </tr>
               </table>  
            </td>
        </tr>
        <tr class="tdbg">
            <td align="right" class="tdbgleft">
                <strong>邮件附件</strong>
            </td>
            <td colspan="3">
                <input type="button" value="添加附件" onclick="addAttachmentToList()" id="btnAdd" name="btnAdd" />
                <div id="attachmentList">
                </div>
            </td>
        </tr>
        <tr class="tdbg">
            <td align="right" class="tdbgleft">
                <strong>发送格式：</strong>
            </td>
            <td colspan="3">
                <asp:CheckBox ID="chkIsBodyHtml" runat="server" Text="正文是否以HTML格式发送" Checked="true" />
            </td>
        </tr>
        <tr class="tdbg">
            <td align="right" class="tdbgleft">
                <strong>发件人：</strong>
            </td>
            <td colspan="3">
                <asp:TextBox ID="TxtSenderName" runat="server" Width="350px"></asp:TextBox>
            </td>
        </tr>
        <tr class="tdbg">
            <td align="right" class="tdbgleft">
                <strong>回复Email：</strong>
            </td>
            <td colspan="3">
                <asp:TextBox ID="TxtSenderEmail" runat="server" Width="350px"></asp:TextBox>
                <asp:RegularExpressionValidator ID="ValeSenderEmail" runat="server" ControlToValidate="TxtSenderEmail"
                    Display="Dynamic" ErrorMessage="回复Email不是有效的Email地址！" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
            </td>
        </tr>
        <tr class="tdbg">
            <td align="right" class="tdbgleft">
                <strong>邮件优先级：</strong>
            </td>
            <td colspan="3">
                <asp:RadioButtonList ID="RadlPriority" runat="server" RepeatDirection="Horizontal">
                    <asp:ListItem Value="2">高</asp:ListItem>
                    <asp:ListItem Selected="True" Value="0">普通</asp:ListItem>
                    <asp:ListItem Value="1">低</asp:ListItem>
                </asp:RadioButtonList>
            </td>
        </tr>
        <tr class="tdbgbottom">
            <td colspan="3">
                <asp:Button ID="BtnSend" runat="server" Text="发送" OnClick="BtnSend_Click" />
                &nbsp;&nbsp; &nbsp;
                <input id="Reset1" type="reset" class="inputbutton" value="清除" onclick="return Reset1_onclick()" />
            </td>
        </tr>
    </table>

    <script type="text/javascript">
        function Reset1_onclick() {
            var TxtSubject = document.getElementById('<%=TxtSubject.ClientID %>');
            var TxtSenderEmail = document.getElementById('<%=TxtSenderEmail.ClientID %>');
            TxtSubject.value = '';
            TxtSenderEmail.value = '';
            <%=EditorContent.ClientID %>$$ckeditor$$obj.setData('');
            
        }
    </script>

    <script type="text/javascript">
        var nodeIndex = 0;

        function addAttachmentToList() {
            var fileButton = '';
            if (nodeIndex > 0) {
                fileButton = '<span id="span' + nodeIndex + '"><br /><input type="file" size="50" name="file" />';
            }
            else {
                fileButton = '<span id="span' + nodeIndex + '"><input type="file" size="50" name="file" />';
            }
            fileButton += '\n<input type="button" class="inputbutton" value="删除" OnClick="delAttachment(' + nodeIndex + ')" /></span>';
            insertHtml("beforeEnd", document.getElementById('attachmentList'), fileButton);
            nodeIndex += 1;
        }

        function delAttachment(nodeIndex) {
            var o = document.getElementById("span" + nodeIndex);
            if (o) {
                o.parentNode.removeChild(o);
            }
        }

        function insertHtml(where, el, html) {
            where = where.toLowerCase();
            if (el.insertAdjacentHTML) {
                switch (where) {
                    case "beforebegin":
                        el.insertAdjacentHTML('BeforeBegin', html);
                        return el.previousSibling;
                    case "afterbegin":
                        el.insertAdjacentHTML('AfterBegin', html);
                        return el.firstChild;
                    case "beforeend":
                        el.insertAdjacentHTML('BeforeEnd', html);
                        return el.lastChild;
                    case "afterend":
                        el.insertAdjacentHTML('AfterEnd', html);
                        return el.nextSibling;
                }
                throw 'Illegal insertion point -> "' + where + '"';
            }
            var range = el.ownerDocument.createRange();
            var frag;
            switch (where) {
                case "beforebegin":
                    range.setStartBefore(el);
                    frag = range.createContextualFragment(html);
                    el.parentNode.insertBefore(frag, el);
                    return el.previousSibling;
                case "afterbegin":
                    if (el.firstChild) {
                        range.setStartBefore(el.firstChild);
                        frag = range.createContextualFragment(html);
                        el.insertBefore(frag, el.firstChild);
                        return el.firstChild;
                    } else {
                        el.innerHTML = html;
                        return el.firstChild;
                    }
                case "beforeend":
                    if (el.lastChild) {
                        range.setStartAfter(el.lastChild);
                        frag = range.createContextualFragment(html);
                        el.appendChild(frag);
                        return el.lastChild;
                    } else {
                        el.innerHTML = html;
                        return el.lastChild;
                    }
                case "afterend":
                    range.setStartAfter(el);
                    frag = range.createContextualFragment(html);
                    el.parentNode.insertBefore(frag, el.nextSibling);
                    return el.nextSibling;
            }
            throw 'Illegal insertion point -> "' + where + '"';
        }
    </script>
    <script type="text/javascript">
        var a_list = $("#taglist a").mouseup(function() { 
        <%=EditorContent.ClientID%>$$ckeditor$$obj.insertText(this.innerHTML);
        });
    </script>
</asp:PlaceHolder>
<asp:PlaceHolder runat="server" ID="PhSendMailStatus" Visible="false">
   
    <div id="cartoon" style="margin-left: 20%; margin-top: 2%; display: none">
            <img id="CreateHtmlImage" src="../../Admin/Images/sendmail.gif" alt="" />
        </div>
        <div id="Div1" style="margin-left: auto; margin-right: auto; margin-bottom: 20px;
            width: 80%;">
            <div id="ExeTime" style="float: left;">
            </div>
        </div>
        <div id="plan" style="margin-left: auto; margin-right: auto; margin-bottom: 20px;
            width: 80%; background-color: #FFFFFF; border-bottom: #000000 1px solid; border-left: #000000 1px solid;
            border-right: #000000 1px solid; border-top: #000000 1px solid; display: none;">
            <div id="pb" style="text-align: center; background-color: Green; color: White; clear: both;
                height: 22px; display: none;">
            </div>
        </div>
        <div style="margin-left: 45%;">
        <asp:Button ID="BtnStopSend" runat="server" CssClass="inputbutton" Text="任务中止" OnClick="BtnStopSend_OnClick" />
        </div>
        <div id="Message" style="margin-left: 5%;">
        </div>
        <div id="ErrorMessage" style="margin-left: 5%;">
        </div>
    <script language="javascript" type="text/javascript">
        var timeout;
        $(function () {
            sendstatus();
        });

        function sendstatus()
        {
            $.post('<%=BasePath %>ajax.aspx?HandlerName=AdminAjaxHandler', "<?xml version='1.0' encoding='utf-8'?><root><type>getsendmailprogress</type></root>", function (xml) {
                var status = $("status", xml).text();
                if (status == "true") {
                    var Completed = $("Completed", xml).text();
                    $("#cartoon").show();
                    $("#plan").show();
                    $("#pb").show();
                    $("#Message").show();
                    var ExecutionTime = $("ExecutionTime", xml).text();
                    var Message = $("Message", xml).text();
                    $("#ExeTime").html("执行时间：" + ExecutionTime);
                    if (Completed == "true") {
                        $("#pb").css("width", "100%");
                        $("#pb").html("发送邮件完毕！");
                        var ErrMessage = $("ErrMessage", xml).text();
                        $("#ErrorMessage").html(ErrMessage);
                        $("#Message").html(Message);
                        $("#ErrorMessage").show();
                        $("input[name$='BtnStopSend']").attr("value", "完  成");
                        $("#CreateHtmlImage").attr("src", "../../Admin/Images/accomplish.gif");
                    } else {
                        $("#ErrorMessage").hide();
                        var Count = $("Count", xml).text();
                        var Progress = $("Progress", xml).text();
                        $("#pb").css("width", Progress);
                        $("#pb").html(Progress);
                        $("#Message").html(Message);
                        timeout = setTimeout("sendstatus()", 5000);
                    }
                } else {
                    $("#Message").html("当前没有采集任务在执行！");
                    $("#cartoon").hide();
                    $("#plan").hide();
                    $("#pb").hide();
                    $("#ExeTime").html("");
                }
            });
        }
    </script>
</asp:PlaceHolder>
</asp:Content>
