<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%option explicit%>
<!--#include file="../Conn.asp"-->
<!--#include file="../Task/TaskConfig.asp"-->
<!--#include file="../HSK_Cls/HSK.MemberCls.asp"-->
<!--#include file="../HSK_Cls/HSK.Label.CommonCls.asp"-->
<%
'****************************************************
' 发送手机短信功能页
'****************************************************
Dim KSCls
Set KSCls = New User_SMSSend
KSCls.HSK_Run()
Set KSCls = Nothing

Class User_SMSSend
        Private KS,KSUser
		Private CurrentPage,totalPut
		Private RS,MaxPerPage
		Private TempStr,SqlStr
		
		Private Sub Class_Initialize()
			MaxPerPage =20
		  Set KS=New PublicCls
		  Set KSUser = New UserCls
		End Sub
        Private Sub Class_Terminate()
		 Set KS=Nothing
		 Set KSUser=Nothing
		 Call CloseConn()
		End Sub
		%>
		<!--#include file="../HSK_Cls/UserFunction.asp"-->
		<%
       Public Sub loadMain()

		IF Cbool(KSUser.UserLoginChecked)=false Then
		  Response.Write "<script>top.location.href='Login';</script>"
		  Exit Sub
		End If
		Call KSUser.Head()
		 If KS.S("page") <> "" Then
			  CurrentPage = CInt(KS.S("page"))
		Else
			  CurrentPage = 1
		End If
%>
		<div class="tabs">	
			<ul>
				<li<%If KS.S("Action")="" then response.write " class='select'"%>><a href="SMS_Send.asp">发送手机短信</a></li>
              	<li<%If lcase(KS.S("Action"))="list" then response.write " class='select'"%>><a href="SMS_Send.asp?Action=List">短信发送记录</a></li>
			</ul>
		</div>
        
		<%
		Select Case KS.LoseHtml(KS.S("Action"))
		 Case "List"  Call SMSList()
		 Case Else  Call Main()
		End Select
	   End Sub

	   Sub Main()
		Call KSUser.InnerLocation("发送手机短信")
		IF SMS_Send_Enabled <> 1 Then
			KS.AlertHintScript "抱歉！发送手机短信功能暂时关闭，具体恢复时间请留意平台最新公告消息。"
		End IF
	    %>
<script type="text/javascript">
function ismobile(s)
{
   var p = /^(013|015|13|14|014|15|018|18)\d{9}$/;
   if(s.match(p) != null){
  return true;
  }
  return false;
}

function Confirm(){
var UserName = document.myform.UserName.value ;
if (UserName=="")
{
alert('请输入接收用户名!');
document.myform.UserName.focus();
return false;
}
if (document.myform.Content.value==""){
 alert('请输入发送内容!');
 document.myform.Content.focus();
 return false; }
if (document.myform.Content.value.length>document.getElementById('ChrNum').innerText){
 alert('抱歉！一次最多只能发送' + document.getElementById('ChrNum').innerText + '个字！');
 document.myform.Content.focus();
 return false; }

if (document.myform.SecurityCode.value==""){
 alert('请输入安全密码!');
 document.myform.SecurityCode.focus();
 return false;
 }
 
if(confirm("确定要发送吗？")){SendSMS();}
}

function SendSMS(){
	var ajaxchk;
	var ajaxstr;
	var Content = document.myform.Content.value;
	if(document.myform.IsSignature.checked){
		Content = Content + document.myform.Signature.value;
	}
	document.myform.Sendbt.disabled = true;
	$.ajax({type:"get",url:"/Plus/Ajax_SMS.asp",data:"Action=SendSMS&UserName=" + document.myform.UserName.value + "&Content=" + escape(Content) + "&Flag=SMS_Send&N=100&M=1&C=" + document.myform.SecurityCode.value + "&anticache=" + Math.floor(Math.random()*1000),cache:false,dataType:"html",success:function(d){
	var s=unescape(d);
	ajaxchk=s.split('|')[0];
	ajaxstr=s.split('|')[1];
	if (ajaxstr!=null){
		if (ajaxchk=='ok'){alert(ajaxstr);window.location.href="?Action=List";}
		else{alert(ajaxstr);document.myform.Sendbt.disabled = false;}
	}
} });
}
</script>
<table class=border width="100%" border="0" align="center" cellpadding="2" cellspacing="1">
  <tr> 
    <td height="24" class="chargetitle" align="center"><b>发送手机短信<span class="orange">（<%=KS.GetN(SMS_Price,2)%>元/条）</span></b></td>
  </tr>
</table>
<br />
<form name="myform" method="post" action="" onsubmit="return false;">
    <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1">
      <tr class=tdbg>
          <td align="right">接收人用户名：</td>
          <td><input class="textbox" type="text" name="UserName" id="UserName" size="30" maxlength="30" value="<%=KS.S("UserName")%>" /></td>
      </tr>
      <tr class="tdbg">
        <td align="right">发送短信内容：</td>
        <td>
          <textarea name="Content" id="Content" cols="50" rows="4" onkeyup="checkLength();" onblur="checkLength();"></textarea>
          <br />
          <select name="HaoPingYu" id="HaoPingYu" onChange="myform.Content.value=this.options[this.selectedIndex].text;checkLength()">
            <option selected="selected">==可在这里快速选择常用的语句==</option>
                  <option>你好！已经支付了，请尽快发货！</option>
                  <option>你好！已经发货了，请尽快收货并好评！</option>
                  <option>你好！已经好评了，请审核！ </option>
                  <option>你好！请尽快拍下宝贝和支付！谢谢！</option>
                  <option>你好！收货时间已经到了，请上线收货，谢谢！</option>
                  <option>你好！记得复制好评内容带字好评呀！</option>
                  <option>你好！记得明天这个时候再上来收货和好评呀！</option>
                  <option>你好！记得过二天后才可以收货和好评呀！</option>
                  <option>你好！记得过三天后才可以收货和好评呀！</option>
                  <option>—————————————————————————————</option>
                  <option>==如果您觉得那些比较常用的语句，也可以反馈给管理员加上==</option>
           </select>
		  <br>
		  您可以输入<span id="ChrNum">70</span>个字发送 &nbsp; 现已填写的字数：
          <INPUT class="textbox" id="TxtNum" value="0" size="3" name="TxtNum" readonly="readonly" /> 个</td>
      </tr>
      <tr class=tdbg>
        <td align="right">附上短信签名：</td>
        <td><label><input type="checkbox" name="IsSignature" id="IsSignature" value="1" checked="checked" disabled="disabled"><input type="text" class="textbox" size="50" name="Signature" id="Signature" onchange="checkLength()" value="——平台用户：<%=KSUser.UserName%> 给您发的短信" /></label></td>
      </tr>
     <tr class=tdbg>
      <td align=right>安全密码：</td>
      <td><input class="textbox" style="width:100px;" type="password" id="SecurityCode" maxlength="16" name="SecurityCode" value="" title="安全密码主要用于资金流转、账户安全二层保护作用。&#13;&#10;注：安全密码不是登录密码" /></td>
     </tr>
      <tr>
        <td colspan=2 height="50" align="center">
			<button class="pn" id="Sendbt" name="Sendbt" type="submit" onclick="Confirm()"><strong>OK, 发 送</strong></button>
		</td>
	  </tr>
	<% IF Hour(Now)>21 Or Hour(Now)<7 Then %>
      <tr class=tdbg>
      <td align="left" colspan="2" height="40" style="border:1px #FC6 solid; background:url(/style/images/msg_bg.png) #FFFFF4 no-repeat 10px -690px; color:red; padding-left:50px">
提示：如果发送失败，可能原因是：由于平台手机短信网关运营商有规定每晚22点至次日7点期间暂停短信发送，主要出于短信安全监控和履行国家规定非盈利网站运营的一些规定。请您明早7点后再发送，谢谢！</td>
      </tr>
	<% End IF %>
	</table>
 </form>
<script type="text/javascript">
<!--
function checkChrNum(){ document.getElementById('ChrNum').innerText = 70 - document.getElementById('Signature').value.length - <%=Len(KS.Setting(0)) + 2%>;}
function checkLength(){ document.getElementById('TxtNum').value = document.getElementById('Content').value.length; checkChrNum();}
checkChrNum();
-->
</script>
	   <%
	   	IF Round(KSUser.GetUserInfo("Money"),2) < SMS_Price Then 
			KS.AlertHistory "温馨提示！你当前资金不足，请先充值再来发送短信！","-1"
		End IF
	   End Sub
	   
	   
	   Sub SMSList()
		Call KSUser.InnerLocation("短信发送记录")
%>
				<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1" class="border">
					<tr class=titlename align=middle>
					  <td width=120 height="25">发送编号</td>
					  <td width=100>接收手机号</td>
					  <td width=60>发送类型</td>
					  <td width=146>发送时间</td>
					  <td width=60>发送状态</td>
					  <td width=60>短信费用</td>
					  <td width=170>短信内容</td>
					</tr>
					<%  SqlStr="Select * From Log_SMS Where UserName='" & KSUser.UserName &"' order by id desc"
						 Set RS=Server.createobject("adodb.recordset")
						 RS.open SqlStr,conn,1,1

						 If RS.EOF And RS.BOF Then
								  Response.Write "<tr class='tdbg'><td align=center height=25 colspan=7 valign=top>还没有任何发送记录!</td></tr>"
								 Else
									totalPut = RS.RecordCount
						
											If CurrentPage < 1 Then
												CurrentPage = 1
											End If
			
								If (CurrentPage - 1) * MaxPerPage > totalPut Then
									If (totalPut Mod MaxPerPage) = 0 Then
										CurrentPage = totalPut \ MaxPerPage
									Else
										CurrentPage = totalPut \ MaxPerPage + 1
									End If
								End If
			
								If CurrentPage = 1 Then
									Call ShowContent
								Else
									If (CurrentPage - 1) * MaxPerPage < totalPut Then
										RS.Move (CurrentPage - 1) * MaxPerPage
										Call ShowContent
									Else
										CurrentPage = 1
										Call ShowContent
									End If
								End If
				End If
						 %>
					
          </table>
		  <%
		  Call KS.ShowPage(totalput, MaxPerPage, "", CurrentPage,false,true)%>
		  <%
  End Sub
    
  Sub ShowContent()
     on error resume next
     Dim I,totalmoney,Content
     Do While Not rs.eof
	 Content = KS.IIF(Instr(rs("Content"), "验证码是：")>0, KS.reReplace(rs("Content"), "验证码是：\w+", 2, "验证码是：****"), KS.HTMLEncode(rs("Content")))
	%>
    <tr class=tdbg onMouseOver="this.className='tdbgmouseover'" onMouseOut="this.className='tdbg'">
      <td  class="splittd" align=middle><%=rs("OrderID")%></td>
      <td  class="splittd" align=middle><%=rs("Mobile")%></td>
	  <td  class="splittd" align=middle>
	  <% Select Case rs("SendType")
	      Case 0:Response.WRite "立即"
		  Case 1:Response.Write "定时"
		 End Select	
	   %></td>
      <td  class="splittd" align=center><%= rs("AddDate")%></td>
      <td  class="splittd" align=center><% Select Case rs("Status")
	      Case 0:Response.WRite "成功"
		  Case 1:Response.Write "<font color=red>失败</font>"
		 End Select	
	   %></td>
      <td  class="splittd" align=center><% =formatnumber(rs("PayMoney"),2,-1)%></td>
      <td  class="splittd" align=middle><span title="<%=Content%>"><%=Left(Content,13)%></span></td>
    </tr>
	<%
	I = I + 1
	RS.MoveNext
	If I >= MaxPerPage Then Exit Do
	loop
End Sub
  
End Class
%> 
