<!--#include file="Inc.asp"-->
<!--#include file="Inc/Page_Cls.asp"-->
<!--#include file="inc/ubb_Cls.asp"-->
<%
Dim Action,AllSmsSize
If Not BBS94KK.FoundUser Then BBS94KK.GoToErr(20)
BBS94KK.Position=BBS94KK.Position&" → <a href=""UserInfo.asp"">用户控制面版</a>"
BBS94KK.Head "处理信件"
ShowMySmsInfo()
Action=Lcase(Request("Action"))
If Len(Action)>10 Then BBS94KK.GoToErr(1)
Select Case Action
Case"save"
	SaveSms
Case"del"
	Del
Case"delall"
	DelAll
Case"write"
	WriteSms
Case Else
	ReadSms
End Select
BBS94KK.Footer()
Set BBS94KK=Nothing


Sub Del
	Dim ID,I,Rs
	ID=BBS94KK.CheckNum(request("ID"))
	Set Rs=BBS94KK.Execute("Select MyName,Name From[KK_sms] where ID="&ID&" And (Name='"&BBS94KK.MyName&"' or MyName='"&BBS94kk.MyName&"')")
	If not Rs.eof then
		If Lcase(BBS94KK.MyName)=Lcase(Rs(0)) Then
			BBS94KK.execute("Update [KK_sms] set MyFlag=2 where ID="&ID)
		Else
			BBS94KK.execute("Update [KK_sms] set Flag=2 where ID="&ID)
		End If
		BBS94KK.Execute("Delete from [KK_sms] where MyFlag=2 And Flag=2")
		BBS94KK.Execute("Update [KK_User] set SmsSize=SmsSize-1 where ID="&BBS94KK.MyID)
	End If
	Rs.close
	Set Rs=Nothing
	Response.Redirect "sms.asp"
End Sub

Sub DelAll
	Dim ID,I
	ID=BBS94KK.CheckNum(request("ID"))
	I=0
	If ID=1 Then'删收箱
		I=BBS94KK.Execute("select count(*) From[KK_Sms] where Name='"&MyName&"' And Flag=0" )(0)
		BBS94KK.Execute("Update [KK_sms] Set MyFlag=2 where MyName='"&BBS94KK.MyName&"'")
	ElseIf ID=2 Then'删发箱
		I=BBS94KK.Execute("select count(*) From[KK_Sms] where MyName='"&MyName&"' And Flag<>2" )(0)
		BBS94KK.Execute("Update [KK_sms] Set Flag=2 where Name='"&BBS94KK.MyName&"'")
	Else
		BBS94KK.Execute("Update [KK_sms] Set Flag=2 where Name='"&BBS94KK.MyName&"'")
		BBS94KK.Execute("Update [KK_sms] Set MyFlag=2 where MyName='"&BBS94KK.MyName&"'")
	End If
	If isnull(I) Then I=0
	BBS94KK.Execute("Update [KK_User] set SmsSize="&i&" where ID="&BBS94KK.MyID)
	BBS94KK.Execute("Delete from [KK_sms] where MyFlag=2 And Flag=2")
	Session(CacheName & "MyInfo") = Empty
	BBS94KK.Alert"清空所有信件成功！","Sms.asp"
End Sub

Sub ShowMySmsInfo()
	Dim SmsSize,content
	SmsSize=int(SESSION(CacheName & "MyInfo")(20))
	AllSmsSize=SmsSize/Int(SESSION(CACHENAME & "MYGRADEINFO")(18))*100
	If AllSmsSize>100 Then AllSmsSize=100
	IF AllSmsSize<0 Then AllSmsSize=0
	IF AllSmsSize>0 And AllSmsSize<1 Then AllSmsSize=1
	Content=SmsSize/SESSION(CacheName & "MyGradeInfo")(18)*250
	If Content>250 Then Content=250
	Content="<div style='padding:3px;'><div style=""float:right;""><div style=""float:left; width:auto"">信箱容量：</div><div style=""float:left;width:250px;height:12px;border:#CCCCCC 1px dotted; background:#CCFFFF""><img src='Images/hr1.gif' width='"&Content&"' height='12'></div>已使用 <span style='color:#F00'>"&Int(AllSmsSize)&" </span>%</div><a href='Sms.asp'><img src='Images/Icon/sms.gif' width='16' height='16' border='0' /> 收件箱</a> <a href='Sms.asp?Action=elapse'><img src='Images/Icon/elapse.gif' border='0' /> 发件箱</a> <a href='?Action=write'><img border='0' src='Images/Icon/add.gif'> 写新留言</a>&nbsp;<a href='#this' onclick=""if(confirm('按确定将清空邮箱的所有信件！！\n\n您确定要删除吗？'))window.location.href='?Action=delall'"" ><img src='Images/Icon/recycle.gif' border='0'> 清空信箱</a></div>"
	Response.Write BBS94KK.ReadSkins("用户控制面版")
	BBS94KK.ShowTable"论坛留言信箱",Content
End Sub



Sub ReadSms()
	Dim S,div,Content,Temp,UserPic,Rs,P,strPageInfo,Arr_Rs,I,Caption,bgColor,BBS94KK_ubb,Sqlwhere,title,UserName
	If Action="elapse" Then
		Title="发送的信件记录"
		Sqlwhere="Name='"&BBS94KK.MyName&"' and Flag=0"
	ElseIf Action="colloquy" Then
		UserName=Request.querystring("Name")
		If Not BBS94KK.Fun.CheckName(UserName) Then BBS94KK.GoToErr(1)
		Title="和"&UserName&"的交谈记录"
		Sqlwhere="(MyName='"&BBS94KK.MyName&"' and Name='"&UserName&"' and MyFlag<2) or (Name='"&BBS94KK.MyName&"' And  MyName='"&UserName&"' and Flag=0)"
	Else
		Title="收取信件"
		Sqlwhere="MyName='"&BBS94KK.MyName&"' and MyFlag<2"
	End If
	Set P = New Cls_PageView
	P.strTableName = "[KK_Sms]"
	P.strFieldsList = "ID,Name,Content,AddTime,MyFlag,UbbString,Flag,MyName"
	P.strCondiction = Sqlwhere
	P.strOrderList = "ID desc"
	P.strPrimaryKey = "ID"
	P.intPageSize = 10
	P.intPageNow = Request.querystring("page")
	P.strCookiesName = "Sms"&Action
	P.InitClass
	Arr_Rs = P.arrRecordInfo
	strPageInfo = P.strPageInfo
	Set P = nothing
	If IsArray(Arr_Rs) Then
		Set BBS94KK_ubb=New BBS94KKubb_Cls
		Div="<div style=""margin-left : 170px;min-height:150px;padding:10px;font-size:9pt;line-height:normal;word-wrap : break-word ;word-break : break-all ;border-left: 1px solid "&BBS94KK.SkinsPIC(0)&""" onload=""this.style.overflowX='auto';"">"
		If BBS94KK.MSIE Then
			Div=Replace(Div,"min-","padding-right:0px; overflow-x: hidden;")
		End If
		For i = 0 to UBound(Arr_Rs, 2)
			BBS94KK_ubb.UbbString=Arr_Rs(5,I)
			If lcase(Arr_Rs(1,I))=lcase(BBS94KK.MyName) Then
				Temp="发送给 <a href='UserInfo.asp?Name="&Arr_Rs(7,I)&"'><strong>"&Arr_Rs(7,I)&"</strong></a> 的信件&nbsp; "
				If Action="elapse" Then Temp=Temp&"<a href='?action=colloquy&name="&Arr_Rs(7,I)&"'><img src='images/icon/book.gif' border='0' alt='查看会话记录' title='查看会话记录' /></a> "
				If Session(CacheName & "MyInfo")(11)="1" Then
					UserPic="<img src='http://qqshow-user.tencent.com/"&Session(CacheName & "MyInfo")(10)&"/11/' alt='QQ头像' />"
				Else
					UserPic="<img src="&Session(CacheName & "MyInfo")(12)&" width="&Session(CacheName & "MyInfo")(13)&" height="&Session(CacheName & "MyInfo")(14)&" alt='' />"
				End if
			Else
				Set Rs=BBS94KK.execute("select top 1 IsQQpic,QQ,Pic,PicW,PicH from [KK_User] where Name='"&Arr_Rs(1,I)&"'")
				 If Not Rs.eof then
					Temp="<a href='UserInfo.asp?Name="&Arr_Rs(1,I)&"'><img border='0' src='images/Icon/info.GIF' alt='查看资料' /></a> <a href='?Action=write&Name="&Arr_Rs(1,I)&"&id="&Arr_Rs(0,I)&"'><img border='0' src='Images/Icon/reply.gif' alt='回复' title='回复' /></a> <a href='?action=colloquy&name="&Arr_Rs(1,I)&"'><img src='images/icon/book.gif' border='0' alt='查看会话记录' title='查看会话记录' /></a> "
					IF Rs(0)=1 then
						UserPic="<img src='http://qqshow-user.tencent.com/"&Rs(1)&"/11/' alt='QQ头像' />"
					Else
						UserPic="<img border='0' src='"&rs(2)&"' width='"&rs(3)&"' height='"&rs(4)&"' alt='' />"
					End If
				Else
					UserPic="<img src='Images/AutoSms.gif' border='0' alt='' />"
				End if
				Rs.Close
				Set Rs=nothing
			End If
			
			If I mod 2 <>0 Then bgColor="background-color: "&BBS94KK.SkinsPIC(1)&";" Else bgColor=""
			S="<div style="""&bgColor&";text-align:left;border-bottom:1px solid "&BBS94kk.SkinsPIC(0)&"""><div style='float:left;text-indent:24px;width:170px'><br /><div><b>"&Arr_Rs(1,I)&"</b></div><div>"&UserPic&"</div></div>"
			S=S&DIV&Temp&"<a href='#this' onclick=""if(confirm('按确定将删除这条留言！！\n\n您确定要删除吗？'))window.location.href='?id="&Arr_Rs(0,I)&"&Action=del'"" ><img border='0' alt='删除' src='Images/Icon/delete.gif' /></a> "
			IF Arr_Rs(4,I)=1 Then S=S&"<img src='Images/Icon/New.Gif' alt='新的留言' />"
			S=S&"<hr width='98%' size='1' color="""&BBS94kk.SkinsPIC(0)&""" ><blockquote>"&BBS94KK_Ubb.UBB(Arr_Rs(2,I),2)&"<p></p><div align=""right""><img src='Images/Icon/add.gif' border='0' atl='' /> 留言时间： "&Arr_Rs(3,I)&"</div></blockquote></div></div>"
			Content=Content&S
		Next
		Content=Content&"<div style=""height:25px;BACKGROUND: "&BBS94KK.SkinsPIC(2)&";"">"&strPageInfo&"</div>"
		Set BBS94KK_ubb=Nothing
	End If
	BBS94KK.ShowTable Title,Content
	If Session(CacheName&"updateSms")="" or Int(Session(CacheName & "MyInfo")(27))>0 then
		BBS94KK.ExeCute("Update [KK_user] Set NewSmsNum=0 Where Name='"&BBS94KK.MyName&"'")
		BBS94KK.ExeCute("Update [KK_Sms] Set MyFlag=0 Where MyFlag=1 and MyName='"&BBS94KK.MyName&"'")
		Session(CacheName&"updateSms")="Y"
		Session(CacheName & "MyInfo") = Empty
	End If
End Sub

Sub WriteSms()
	If AllSmsSize=100 Then
		Temp="系统警告":S="<br><P>&nbsp;&nbsp;亲爱的用户，您的论坛留言信箱容量已满，请尽快删除一些信件！</p><br>"
	Else
		Dim Name,Rs,S,Temp,Content,ID
		ID=BBS94KK.CheckNum(request("ID"))
		Name=request.querystring("Name")
		If Not BBS94KK.Fun.CheckName(Name) Then BBS94KK.GoToErr(1)
		Set Rs=BBS94KK.execute("select Content from [KK_sms] where name='"&Name&"' and Id="&ID&"")
		if not Rs.eof then 
		Content=Rs("Content")
		End if
		Rs.Close
		Set Rs=nothing
		S="<form style='margin:0;' method='POST' action='?Action=save' name='say'>"
		S=S&BBS94KK.Row("<b>留言对象：</b>","<textarea id='content' name='content' style='display:none'>"&Content&"</textarea><input type=hidden name='safecode' id='safecode' value='94kk' /><input name='caption' type='text' class='text' id='caption' size='30' value='"&Name&"'>","75%","")
		Temp="<b>信件内容：</b><br /> <a href=""javascript:CheckLength("&Session(CacheName & "MyGradeInfo")(19)&")"">内容限制"&Session(CacheName & "MyGradeInfo")(19)&"个字节</a><br />"
		Temp=Temp&"每天最多可以发送"&Session(CacheName & "MyGradeInfo")(13)&"封"
		If Int(BBS94KK.Info(123)) >0 Then Temp=Temp & "<br />每封收取发送费："&BBS94KK.Info(123)&BBS94KK.Info(120)
	If BBS94KK.Info(60)="1" Then Content="UbbEdit()" Else Content="HtmlEdit()"
	Content="<script type=""text/javascript"">"&Content&"</script>"
	S=S&BBS94KK.Row(""&Temp,Content,"75%","")
	S=S&"<div align='center' style=""padding:5px;BACKGROUND: "&BBS94KK.SkinsPIC(1)&";"">"
	S=S&"&nbsp;<input type='button' value=' 发 送！' id='sayb' onclick='checkform("&Session(CacheName & "MyGradeInfo")(19)&")' class='button' /> <input type='reset' value=' 重 写 ' onclick='Goreset()' class='button' />" 
	S=S&"</div></form>"
	Temp="签写发送留言"
	End If
	BBS94KK.ShowTable Temp,S
End Sub

Sub SaveSms()
	'BBS94KK.CheckMake()
	Dim S,Content,ToName,TmpUbbString
	If int(SESSION(CacheName & "MyInfo")(7))<int(BBS94KK.Info(123)) Then BBS94KK.GoToErr(52)
	If Session(CacheName&"SmsTime")+1/1440>now() then BBS94KK.GoToErr(53)
	ToName=BBS94KK.Fun.GetForm("caption")
	Content=BBS94KK.Fun.GetForm("Content")
	If ToName="" or Content=""  then BBS94KK.GoToErr(36)
	If BBS94KK.Fun.CheckIsEmpty(Content) Then BBS94KK.GoToErr(50)
	If BBS94KK.Info(60)="1" Then Content=BBS94KK.Fun.Replacehtml(Content)
	TmpUbbString=BBS94KK.Fun.UbbString(Content)
	If Not BBS94KK.Fun.CheckName(ToName) Then BBS94KK.GoToErr(41)
	IF Len(Content)>Int(Session(CacheName & "MyGradeInfo")(19)) Then BBS94KK.GoToErr(29)
	S=BBS94KK.Execute("Select Count(*) From[KK_Sms] where Name='"&BBS94KK.MyName&"' And DATEDIFF('d',AddTime,'"&BBS94KK.NowBbsTime&"')<1")(0)
	If Isnull(S) Then S=0
	If S>Int(Session(CacheName & "MyGradeInfo")(13)) Then BBS94KK.GoToErr(55)
	If BBS94KK.execute("select Name From [KK_User] where name='"&ToName&"'and IsDel=0").eof Then BBS94KK.GoToErr(54)
	BBS94KK.execute("insert into [KK_sms](name,Content,Myname,ubbString,MyFlag)values('"&BBS94KK.MyName&"','"&Content&"','"&ToName&"','"&TmpUbbString&"',1)")
	BBS94KK.execute("update [KK_user] Set Coin=Coin-"&int(BBS94KK.Info(123))&" where ID="&BBS94KK.MyID)
	BBS94KK.ExeCute("Update [KK_user] Set NewSmsNum=NewSmsNum+1,SmsSize=SmsSize+1 Where Name='"&ToName&"'")
	Session(CacheName&"SmsTime")=Now()
	'在线通知
	BBS94KK.UpdageOnline ToName,1
	Content="<div style='margin:15px;line-height:150%'><li>已经成功的给 <b>"&ToName&"</b> 留言</li><li>本站扣除手续费 "&BBS94KK.Info(123)&BBS94KK.Info(120)&"</li><li><a href=""index.asp"">返回首页</a> </li><li><a href=""Sms.asp"">返回我的信箱</a></li></Div>"
	BBS94KK.ShowTable"发送成功",Content
End Sub
%>
