<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="selectSendEmail.aspx.cs" Inherits="ZYDN.Web.system.Email.selectSendEmail" %>

<!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 rel="stylesheet" type="text/css" href="../skins/CSS/main.css" />
    <link rel="stylesheet" type="text/css" href="../skins/CSS/Sys.css" />
     <style type="text/css">
         table{border="0" cellpadding="0" cellspacing="0"}
         .biaotouTd{font-size:12px;font-weight:bold; text-align:left;height:20px; boder:1px #cccccc solid;  background-color:#A8C1DD; color:#01439a; line-height:20px; border-right:1px #cccccc solid; border-left:1px #cccccc solid;padding-left:5px;}
        .oushutd{border-top:1px #cccccc solid; font-size:12px; text-align:left;color:#01439a; line-height:20px;background-color:#F0F5FB;padding-left:5px;padding-right:5px;}
        .jishutd{border-top:1px #cccccc solid;text-align:left; line-height:20px;font-size:12px;background-color:#FFFFFF;padding-left:5px;padding-right:5px;}
    </style>
    <script language="javascript" type="text/javascript" src="../JS/JFramework.js"></script>
    <script language="javascript" type="text/javascript" src="../JS/Sys.js"></script>
    <script language="javascript" type="text/javascript">
    var uList;
    var tID="";
    var objAjax=new JAjax();
    var jObj
    var isStop=0;
    var isEr=0;

      //选择时间 
    function selDate(obj)
    {
       obj.value=openSelectDate();
    }
    //选择模板
    function selectTemp(obj)
    {
        tID=obj.value;
     }
     
     
      //选择收信人
     function SelectUserInfo()
     {
       var getTxt=openSelectUser('all',null);
       if(getTxt!=null)
       {
          document.getElementById("Muser").value=getTxt;
       }
     }
     
     
     
     
     //发送邮件
     function checkNull(type)
     {
       if(tID==null||tID==""||tID==0)
       {
            alert("请选择要使用的邮件模板");
            return;
       }
       
       switch (type)
       {
       //发送给指定用户组用户
       case 1:
         outEmailGroup()
          break;
          //发送给指定用户
       case 2:
          outEmailUser();
          break;
       //发送给位未登陆用户
       case 3:
            outEmailLogin();
            break;
       //发给全部用户
       case 4:
           outEmailAll();
          break;
           case 5:
          outEmailTimeLogin();
          break;
       }
     }
      function outEmailTimeLogin(){//发送给什么时候登录的用户
          var txt=document.getElementById("NTime").value;
          if(txt==""||txt==null)
          {
            alert("请指定时间");
            return;
          }
           var objResponse=new JHttpResponse();
            objResponse.write("Time",txt);
           var out=objAjax.getText("post","SpoolerPage.aspx?type=sdEmailByTimeLogin",objResponse,null);
            if (out.indexOf(c1)!=-1){
              uList=comminute(out,c1,c2);
            }else{
              alert(erStr(out));
            }
            outEmail();
    }

    function outEmailAll(){//发给全部用户
          
            var out=objAjax.getText("post","SpoolerPage.aspx?type=sdEmailByAll",null,null);
            if (out.indexOf(c1)!=-1){
              uList=comminute(out,c1,c2);
            }else{
              alert(erStr(out));
            }
           outEmail();
           return;

    }

     function outEmailLogin(){  //发送给位未登陆用户
            var txt=document.getElementById("NDay").value;
            if(txt==""||txt==null)
            {
              alert("请指定天数")
              return;
            }
            var objResponse=new JHttpResponse();
            objResponse.write("TimeNum",txt);
            var out=objAjax.getText("post","SpoolerPage.aspx?type=sdEmailByNoLogin",objResponse,null);
            if (out.indexOf(c1)!=-1){
              uList=comminute(out,c1,c2);
            }else{
              alert(erStr(out));
            }
            outEmail();
     }
   
     function outEmailUser(){ //发送给指定用户
          var txt=document.getElementById("Muser").value;
          if(txt==""||txt==null)
          {
            alert("请指定用户");
            return;
          }
          var objResponse=new JHttpResponse();
          objResponse.write("userList",txt);
          var out=objAjax.getText("post","SpoolerPage.aspx?type=sdEmailByUser",objResponse,null);
         // alert(out);
          if (out.indexOf(c1)!=-1){
              uList=comminute(out,c1,c2);
          }else{
               alert(erStr(out));
          }
          outEmail();
     }
   
     function outEmailGroup(){ //发送给指定用户组用户
      //获取选中组的ID查找出用户编号
          var dx=document.getElementsByName("che");
          var groupid="-1";
          for(var i=0;i<dx.length;i++)
          {
            if(dx[i].checked==true)
            {
                groupid=dx[i].value;
                break;
             }
          }
          if (groupid=="-1"){
               alert("请选择一个用户组") 
          }
                   
            var objResponse=new JHttpResponse();
            objResponse.write("GroupID",groupid);	
            var out=objAjax.getText("post","SpoolerPage.aspx?type=sdEmailByGroup",objResponse,null);
            if (out.indexOf(c1)!=-1){
                uList=comminute(out,c1,c2);
            }else{
                alert(erStr(out));
            }
            outEmail();
     }
     
   
     
     
      function loadPage(){
            var option=new optionClass();
        	option.titleObj=document.getElementsByName("optionTitle");
			var objBody=document.getElementsByName("optionBody");
			option.bodyObj=objBody;
			//document.getElementById("div2").style.top="-339px";
			option.create(); 
			for (var i=0;i<objBody.length;i++){
			    objBody[i].style.height="220px";
			    objBody[i].style.width="600px";
			    objBody[i].style.overflow="auto";
			}
			loadBodyclick();
		    writeFettleLeft("提示:该功能用于选择发送邮件对象") //状态栏提示
        }
        
        
            
 
        function outEmail(){
            var obj=$("outEailDiv");
            obj.style.display="";
            jObj=$("msgText");
            $("optionDiv").style.display="none";
            setTimeout("sendMail(0)",100);
        }
        
        function mailEnd(){
            if (isEr>0){ 
                
                return;
            }
            $("outEailDiv").style.display="none";
            $("optionDiv").style.display="";
        }
        
        
        function  sendMail(x){
            if (x>=uList.length-1){
                alert("发送完成,\n 发送中发生"+ isEr +"项错误 ");
                mailEnd();
                return;
            }
            
            if (isStop==1){
                alert("用户终止,\n 发送中发生"+ isEr +"项错误");
                mailEnd();
                return;
            }
            
            var uid=uList[x][0];
            var uName=uList[x][1];
            var y=(x+1)/(uList.length-1)*100;
            y=Math.floor(y);
            jObj.innerHTML="一共要发送"+(uList.length-1)+"封EMAIL, 已发送"+(x+1)+"封,完成了 "+  y +"%<BR>正在发送:"+uName;
            
           var objResponse=new JHttpResponse();
	       objResponse.write("uName",uName);	
	       objResponse.write("tempID",tID);	
	       objResponse.write("EMAIL",uList[x][2]);	
    	   var out=objAjax.getText("post","SpoolerPage.aspx?type=outMail",objResponse,null);
    	   if (out!="1"){
    	        isEr++;
    	        $("errDiv").innerHTML="给"+uName+" 的EMAIL发送失败,EMAIL地址为:"+uList[x][2]+"<br>错误信息如下:<br>"+out+"<hr>"+$("errDiv").innerHTML;
    	   }
           // alert("发送");
            setTimeout("sendMail("+(x+1)+")",200);
        }
        
    </script>
</head>
<body onload="loadPage()">
    <form id="form1" runat="server">
     <div style="position: absolute; top: 1px; left: 0px; width:580px;" id="optionDiv">
         <div style="width:605px; position: absolute; left: 10px; top: 0px; z-index:2; overflow:auto;" >
              <div name="optionTitle" id="optionTitle">指定组</div>
              <div name="optionTitle" id="optionTitle">指定用户</div>
              <div name="optionTitle" id="optionTitle">未登录用户</div>
              <div name="optionTitle" id="optionTitle">所有用户</div>
              <div name="optionTitle" id="optionTitle">已登录用户</div>
         </div>
         <div style="overflow: hidden; width:605px; height: auto; position: absolute; top: 25px;z-index:1;" >
           <div name="optionBody" id="optionBody">
                 
                    <table>
                        <tr><td style="height:10px;" colspan="2"></td></tr>
                        <tr>
                            <td style=" width:70px;" >&nbsp;选择模板:</td>
                            <td style=" width:530px;">
                                <select name="TName" id="TName" class="select" onchange="selectTemp(this)">
                                <option value="0">选择已有的模板</option>
                                
                                <asp:Repeater ID="mban1" runat="server">
                                   <ItemTemplate>
                                        <option value="<%# DataBinder.Eval(Container, "DataItem.id")%>" ><%# DataBinder.Eval(Container, "DataItem.tempName")%></option>
                                   </ItemTemplate>
                                 </asp:Repeater>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td class="oushutd" style=" width:70px;">&nbsp;选择组:</td>
                            <td class="oushutd" style=" width:530px;"><div style="text-align:left;" id="setGroup">
                            
                                <asp:Repeater ID="userGroup" runat="server">
                                   <ItemTemplate>
                                   <input value="<%# DataBinder.Eval(Container, "DataItem.id")%>" type='radio' title=" <%# DataBinder.Eval(Container, "DataItem.groupname")%>" name='che'/><%# DataBinder.Eval(Container, "DataItem.groupname")%>  
                                   </ItemTemplate>
                                </asp:Repeater>
                            
                            </div></td>
                        </tr>
                        <tr><td colspan="2" class="jishutd"><input type="button" class="button" name="" id="" value=" 发 送 " onClick="checkNull(1);"/></td></tr>
                    </table>
               
           </div>
           <div name="optionBody" id="optionBody">
                
                    <table>
                          <tr><td style="height:10px;" colspan="2"></td></tr>
                         <tr>
                            <td style=" width:70px;" >&nbsp;选择模板:</td>
                            <td style=" width:530px;">
                            <select name="TName" id="Select1" class="select"  onchange="selectTemp(this)">
                            <option value="0">选择已有的模板</option>
                              <asp:Repeater ID="mBan2" runat="server">
                                   <ItemTemplate>
                                        <option value="<%# DataBinder.Eval(Container, "DataItem.id")%>" ><%# DataBinder.Eval(Container, "DataItem.tempName")%></option>
                                   </ItemTemplate>
                                 </asp:Repeater>
                            </select>
                            </td>
                        </tr>
                        <tr>
                            <td class="oushutd" style=" width:70px;">&nbsp;用户名:</td>
                            <td class="oushutd" style="width: 530px"><input type="text" name="Muser" id="Muser" style="width: 283px" /><font class="red">*</font><a href="#" onClick="SelectUserInfo()" style="color:Red;">选择收信人</a></td>
                        </tr>
                        <tr><td colspan="2" class="jishutd"><input type="button" class="button" name="" id="Button1" value=" 发 送 " onClick="checkNull(2);"/></td></tr>
                    </table>
                
           </div>
           <div name="optionBody" id="optionBody">
                    <table>
                         <tr><td style="height:10px;" colspan="2"></td></tr>
                        <tr>
                            <td style="width:70px;">&nbsp;选择模板:</td>
                            <td >
                                <select name="TName" id="Select2" class="select"  onchange="selectTemp(this)">
                                    <option value="0">选择已有的模板</option>
                                      <asp:Repeater ID="mBan3" runat="server">
                                           <ItemTemplate>
                                                <option value="<%# DataBinder.Eval(Container, "DataItem.id")%>" ><%# DataBinder.Eval(Container, "DataItem.tempName")%></option>
                                           </ItemTemplate>
                                     </asp:Repeater>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td class="oushutd" style="width:70px;">&nbsp;发送给:</td>
                            <td class="oushutd" style=" width:530px;"><input type="text" size="3" name="NDay" id="NDay" /> 天未登录的用户</td>
                        </tr>
                        <tr class="jishutd"><td colspan="2" class="jishutd"><input type="button" class="button" name="" id="Button2" value=" 发 送 " onClick="checkNull(3);"/></td></tr>
                    </table>
               
           </div>
           <div name="optionBody" id="optionBody">
                  <table>
                        <tr><td style="height:10px;" colspan="2"></td></tr>
                        <tr>
                            <td style="width:70px;">&nbsp;选择模板:</td>
                            <td style=" width:530px;">
                            <select name="TName" id="Select4" class="select"  onchange="selectTemp(this)">
                            <option value="0">选择已有的模板</option>
                              <asp:Repeater ID="mBan4" runat="server">
                                   <ItemTemplate>
                                        <option value="<%# DataBinder.Eval(Container, "DataItem.id")%>" ><%# DataBinder.Eval(Container, "DataItem.tempName")%></option>
                                   </ItemTemplate>
                                 </asp:Repeater>
                            </select>
                            </td>
                        </tr>
                        <tr><td class="oushutd" colspan="2"><input type="button" class="button" name="" id="Button3" value=" 发 送 " onClick="checkNull(4);"/></td></tr>
                    </table>
                
           </div>
           <div name="optionBody" id="optionBody">
                  <table>
                        <tr><td style="height:10px;" colspan="2"></td></tr>
                        <tr>
                            <td style="width:70px;" class="jishutd">&nbsp;选择模板:</td>
                            <td style=" width:530px;" class="jishutd">
                            <select name="TName" id="Select3" class="select"  onchange="selectTemp(this)">
                            <option value="0">选择已有的模板</option>
                              <asp:Repeater ID="mBan5" runat="server">
                                   <ItemTemplate>
                                        <option value="<%# DataBinder.Eval(Container, "DataItem.id")%>" ><%# DataBinder.Eval(Container, "DataItem.tempName")%></option>
                                   </ItemTemplate>
                                 </asp:Repeater>
                            </select>
                            </td>
                        </tr>
                        <tr>
                            <td class="oushutd" style="width:70px;">发送给</td>
                            <td class="oushutd" style="width: 530px"><input type="text" name="NTime" id="NTime" onclick="selDate(this)" style="width: 127px" readonly="readOnly" /> 时间之后登录的用户</td></tr>
                        <tr><td colspan="2" class="jishutd"><input type="button" class="button" name="" id="Button4" value=" 发 送 " onClick="checkNull(5);"/></td></tr>
                    </table>
           </div>
           <div><input id="dd" type="hidden" /></div>
         </div>
     </div>
     <div  id="outEailDiv" style="display:none;width:90%; height:100%; padding:15px;">
     <div id="msgText" style="height:50px;width:450px;"></div>
     <div id="errDiv" style="height:110px; width:480px; overflow:auto;"></div>
     <div style="width:350px; text-align:center;" ><input type="button"  value="停止" onclick="isStop=1;"/></div>
     </div>
      </form>
</body>
</html>
  