<!-- #include file=../inc/BBSsetup.asp -->
<!-- #include file=../inc/Board_Popfun.asp -->
<!-- #include file=inc/UserTopic.asp -->
<%
DEF_BBS_HomeUrl = "../"

initDatabase
GBL_CHK_TempStr = ""

Dim Sdm_FromUser,Sdm_ToUser,Sdm_Title,Sdm_Content
Sdm_FromUser = GBL_CHK_User

SiteHead(DEF_SiteNameString & " - 用户会员区")
UpdateOnlineUserAtInfo GBL_board_ID,"我的收件箱"
GBL_CHK_TempStr=""
If GBL_UserID=0 or Sdm_FromUser = "" Then
	GBL_CHK_TempStr = GBL_CHK_TempStr & "你没有登录<br>" & VbCrLf
End If

Dim Start
Start = Left(Trim(Request("Start")),14)
If isNumeric(Start)=0 or Start="" Then Start=0
Start = cCur(Start)
If Start < 0 Then Start = 0

UserTopicTopInfo
DisplayUserNavigate("我的收件箱")
If GBL_CHK_TempStr <> "" Then
	Response.Write "<br><p align=left><font color=ff0000 class=RedFont><b>" & GBL_CHK_TempStr & "</b></font>"
Else%>
	<table width=100%>
	<tr>
	<td>
		<br><%PersonalInfoManage%>
	</td>
	</tr>
	</table>
	<table width=100%>
	<tr>
	<td>
		<script language=javascript>
			function killall(str)
			{
				window.open('DeleteMessage.asp?kasdie=3&ClearFlag='+str,'','width=450,height=37,scrollbars=auto,status=no');
			}
		</script><a href=SendMessage.asp>发送短消息</a>
		<a href='javascript:killall("dkeJje5");'><img src=../images/<%=GBL_DefineImage%>clear.gif width=16 border=0 align=absmiddle>清空我的收件箱</a>
		<%If GBL_UserID>0 and CheckSupervisorUserName = 1 Then%>
		<a href='javascript:killall("dkeJje6");'><img src=../images/<%=GBL_DefineImage%>clear.gif width=16 border=0 align=absmiddle>清空所有人的收件箱</a>
		<form action=MyInfoBox.asp method=Get>
		查看用户<input class=fminpt type=text name=ToUser size=14>的收件箱
		<input type=submit value=查看 name=查看 class=fmbtn></form>
		<%End If%>
		<a href='PrintMessage.asp'><img src=../images/<%=GBL_DefineImage%>print.gif width=16 border=0 align=absmiddle>打印全部短消息及清空收件箱</a>
		<br><br><!-- #include file=../inc/IncHtm/BoardJump.asp -->
	</td>
	</tr>
	</table>
<%
End If
UserTopicBottomInfo
closeDataBase
SiteBottom
If GBL_ShowBottomSure = 1 Then Response.Write GBL_SiteBottomString


Function PersonalInfoManage

	Dim ToUser
	If CheckSupervisorUserName = 0 Then
		ToUser = GBL_CHK_User
	Else
		ToUser = Trim(Left(Request.QueryString("ToUser"),14))
		If ToUser <> "" Then
			ToUser = ToUser
		Else
			ToUser = GBL_CHK_User
		End If
	End If

	Dim Rs,SQL,NewNum
	
	Dim CheckBoxValue
	CheckBoxValue = Request("CheckBoxValue")
	Dim AllPrintingString
	If Request("AllPrinting")="Yesing" and CheckSupervisorUserName = 1 Then
		sql="select count(*) from LeadBBS_InfoBox where Readflag=0"
		AllPrintingString = "&AllPrinting=Yesing"
	Else
		sql="select count(*) from LeadBBS_InfoBox where Readflag=0 and toUser='" & Replace(ToUser,"'","''") & "'"
		AllPrintingString = ""
	End If
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	If Rs.eof Then
		NewNum = 0
	Else
		NewNum=rs(0)
		If isNull(NewNum) or len(NewNum&"")<1 Then NewNum=0
	End If
	Rs.close
	Set Rs = Nothing
	If GBL_CHK_MessageFlag = True or GBL_CHK_MessageFlag = 1 Then GBL_CHK_MessageFlag = 1
	If NewNum = 0 and GBL_CHK_MessageFlag = 1 and AllPrintingString = "" and ToUser = GBL_CHK_User Then
		Con.ExeCute("Update LeadBBS_User Set MessageFlag=0 where ID=" & GBL_UserID)
		GBL_DBNum = GBL_DBNum + 1
		UpdateSessionValue 6,0,0
	End If

	GBL_CHK_TempStr=""
	Dim UpDownPageFlag
	UpDownPageFlag = Request("UpDownPageFlag")

	Dim Start,recordCount
	recordCount=0
	
	
	Dim SQLendString

	Start = Left(Trim(Request("Start")),14)
	Start = start
	If isNumeric(Start)=0 or Start="" Then Start=999999999
	Start = cCur(Start)
	If Start = 0 Then Start=999999999

	Dim SQLCountString,whereFlag
	whereFlag = 0
	
	If CheckBoxValue = "yes" Then
		If WhereFlag = 1 Then
			SQLendString = SQLendString & " and Readflag=0 "
		Else
			SQLendString = SQLendString & " where Readflag=0 "
			WhereFlag = 1
		End If
	End If

	If Request("AllPrinting")="Yesing" and CheckSupervisorUserName = 1 Then
	Else
		If WhereFlag = 0 Then
			SQLendString = " where (ToUser='" & Replace(ToUser,"'","''") & "')"
			WhereFlag = 1
		Else
			SQLendString = SQLendString & " and (ToUser='" & Replace(ToUser,"'","''") & "')"
		End If
	End If

	SQLCountString = SQLendString
	If UpDownPageFlag = "1" and Start>0 then
		If whereFlag = 1 Then
			SQLendString = SQLendString & " and ID>" & Start
		Else
			SQLendString = SQLendString & " where ID>" & Start
			whereFlag = 1
		End If
	Else
		If whereFlag = 1 Then
			SQLendString = SQLendString & " and ID<" & Start
		Else
			SQLendString = SQLendString & " where ID<" & Start
			whereFlag = 1
		End If
	end If

	If UpDownPageFlag = "1" then
		SQLendString = SQLendString & " Order by  ID ASC"
	Else
		SQLendString = SQLendString & " Order by ID DESC"
	End If

	Dim MaxRecordID,MinRecordID
	MaxRecordID = 0

	SQL = "select Max(id) from LeadBBS_InfoBox " & SQLCountString
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1

	If not Rs.Eof Then
		If Rs(0) <> "" Then
			MaxRecordID = cCur(Rs(0))
		Else
			MaxRecordID = 0
		End If
	End If
	Rs.Close
	Set Rs = Nothing
	
	SQL = "select Min(id) from LeadBBS_InfoBox " & SQLCountString
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1

	If not Rs.Eof Then
		If Rs(0) <> "" Then
			MinRecordID = cCur(Rs(0))
		else
			MinRecordID = 0
		end If
	End If
	Rs.Close
	Set Rs = Nothing

	Dim FirstID,LastID	
	SQL = "select count(*) from LeadBBS_InfoBox " & SQLCountString
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	if rs.eof then
		recordCount=0
	else
		recordCount=rs(0)
		if recordCount="" or isNull(recordCount) or len(recordCount)<1 Then recordCount=0
	End If
	Set Rs = Nothing

	If RecordCount >= LMT_MaxMessageNumber and Start=999999999 and CheckSupervisorUserName = 0 Then
		%>
		<script language=javascript>
			alert("你的收件箱已满，不能再接收新消息，\n收件箱最多允许存放<%=LMT_MaxMessageNumber%>条消息．");
		</script>
	<%
	End If

	SQL = "select TOP "&DEF_MaxListNum&" ID,FromUser,Title,SendTime,Readflag,ToUser from LeadBBS_InfoBox " & SQLendString
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	Dim Num
	Dim GetData
	If Not rs.Eof Then
		GetData = Rs.GetRows(-1)
		Num = Ubound(GetData,2)
	Else
		Num = -1
	End If
	Rs.close
	Set Rs = Nothing
	
	
	Dim i,N
	If Num>=0 Then
		i=1
	
		Dim MinN,MaxN,StepValue
		SQL = ubound(getdata,2)
		If UpDownPageFlag = "1" then
			MinN = SQL
			MaxN = 0
			StepValue = -1
		Else
			MinN = 0
			MaxN = SQL
			StepValue = 1
		End If
		
		LastID = cCur(GetData(0,MaxN))
		FirstID = cCur(GetData(0,MinN))
	
		Dim EndwriteQueryString,PageSplictString
		EndwriteQueryString = "?Z38=0"
		If CheckSupervisorUserName = 1 and ToUser <> GBL_CHK_User Then EndwriteQueryString = EndwriteQueryString & "&ToUser=" & urlencode(ToUser)
	
		PageSplictString = PageSplictString & "<table width=100% ><tr><td>&nbsp;"
		If FirstID >= MaxRecordID Then
			PageSplictString = PageSplictString & "<font color=999999 class=GrayFont>首页</font> " & VbCrLf
			PageSplictString = PageSplictString & " <font color=999999 class=GrayFont>上页</font> " & VbCrLf
		else
			PageSplictString = PageSplictString & "<a href=MyInfoBox.asp" & EndwriteQueryString & AllPrintingString & "&Start=0>首页</a> " & VbCrLf
			PageSplictString = PageSplictString & " <a href=MyInfoBox.asp" & EndwriteQueryString & "&Start=" & FirstID & AllPrintingString & "&UpDownPageFlag=1>上页</a> " & VbCrLf
		end if
	
		if LastID<MaxRecordID and LastID<>0 then
		else
		end if
	
		If LastID <= MinRecordID Then
			PageSplictString = PageSplictString & " <font color=999999 class=GrayFont>下页</font> " & VbCrLf
			PageSplictString = PageSplictString & " <font color=999999 class=GrayFont>尾页</font> " & VbCrLf
		else
			PageSplictString = PageSplictString & " <a href=MyInfoBox.asp" & EndwriteQueryString & "&Start=" & LastID & AllPrintingString &">下页</a> " & VbCrLf
			PageSplictString = PageSplictString & " <a href=MyInfoBox.asp" & EndwriteQueryString & AllPrintingString & "&Start=1&UpDownPageFlag=1>尾页</a> " & VbCrLf
		end if
		
		PageSplictString = PageSplictString & "共<b>" & recordCount & "</b>条信息"
		If (recordCount mod DEF_MaxListNum)=0 Then
			PageSplictString = PageSplictString & " 计<b>" & clng(recordCount/DEF_MaxListNum) & "</b>页"
		Else
			If recordCount>=DEF_MaxListNum Then
				PageSplictString = PageSplictString & " 计<b>" & clng(recordCount/DEF_MaxListNum)+1 & "</b>页"
			Else
				PageSplictString = PageSplictString & " 计<b>1</b>页"
			End If
		End If
		PageSplictString = PageSplictString & " 每页<b>" & DEF_MaxListNum & "</b>条记录"
		If CheckBoxValue="yes" Then
			PageSplictString = PageSplictString & "</td><td width=100 height=20><a href=MyInfoBox.asp?CheckBoxValue=no" & AllPrintingString & ">显示所有消息</a></td></tr></table>"
		Else
			PageSplictString = PageSplictString & "</td><td width=100 height=20><a href=MyInfoBox.asp?CheckBoxValue=yes" & AllPrintingString & ">只显示新消息</a></td></tr></table>"
		End If
	End If
	%>
	
	<script language=javascript>
		function kill(killID)
		{
			window.open('DeleteMessage.asp?kasdie=3<%=AllPrintingString%>&MessageID='+killID,'','width=450,height=37,scrollbars=auto,status=no');
		}
	</script>
	<table cellspacing=0 cellpadding=0 width=100% border=0 height=5>
	<tr> 
		<td colspan="2" height="0"><img src="img/BLANK.GIF" width="1" height="1"></td>
	</tr>
	</table>
	<b title="人家发给你的消息"><%=htmlencode(ToUser)%>的收件箱</b>
	<%If recordCount>0 Then
		Response.Write "共<b>" & recordCount & "</b>条消息"
		If NewNum=0 Then
			response.write "， 所有消息您都已经浏览过"
		Else
			response.write "， 您未浏览过的消息有<b>" & NewNum & "</b>条"
		End if
	End If

	If CheckSupervisorUserName = 1 Then
		If Request("AllPrinting")<>"Yesing" Then
			Response.Write " (<a href=MyInfoBox.asp?AllPrinting=Yesing>查看全部消息</a>)"
		Else
			Response.Write " (<a href=MyInfoBox.asp>查看自己的消息</a>)"
		End If
	End If%>
	<table width="100%" border="0" cellspacing="1" cellpadding="2" bordercolor="#000000" bgcolor=<%=DEF_BBS_LightColor%> class=TBBG1>
	  <tbody> 
	  <tr height="19" bgcolor="<%=DEF_BBS_TableHeadColor%>" class=TBfour>
	    <td width=50><img src=img/blank.gif width=1 height=3><br>&nbsp;编号&nbsp;</td>
	    <td><img src=img/blank.gif width=150 height=3><br>&nbsp;主题&nbsp;</td>
	    <td width=85><img src=img/blank.gif width=1 height=3><br>&nbsp;发送者</td>
	    <td width=132><img src=img/blank.gif width=1 height=3><br>&nbsp;发送时间</td>
	    <td width=20 align=center valign=top><img src=img/blank.gif width=1 height=3><br>删</td>
	  </tr>
	<%
	If Num = -1 Then
		Response.Write "<tr bgcolor=" & DEF_BBS_LightestColor & " class=TBBG9><td colspan=5 height=30>&nbsp; 没有任何消息!</td></tr>"
	End If

	Dim TempN

	if Num <> -1 then
		i=1
		LastID = GetData(0,ubound(getdata,2))
		For n= MinN to MaxN Step StepValue
			Response.Write "<tr height=19 bgcolor=" & DEF_BBS_LightestColor & " class=TBBG9><td>&nbsp;"
			Response.Write GetData(0,n)
			Response.Write "</td><td>&nbsp;<a href=LookMessage.asp?MessageID=" & GetData(0,n) & AllPrintingString & ">"
			If GetData(5,N) = "" Then Response.Write "<b>"
			If Len(getData(2,n)&"")>0 Then
				Response.Write Htmlencode(getData(2,n))
			Else
				response.Write "<font color=888888 class=GrayFont>无</font>"
			End if
			If GetData(5,N) = "" Then
				Response.Write "</b>"
			Else
				If GetData(4,N) = 0 Then Response.Write "<img src=../images/" & GBL_DefineImage & "new.gif align=absmiddle border=0 height=11>"
			End If
			Response.Write "</a>"
			Response.Write "</td><td valign=top width=85>&nbsp;"
			Response.Write "<a href=LookUserInfo.asp?Name=" & urlencode(GetData(1,n)) & ">" & GetData(1,n) & "</a>"
			Response.Write "</td>" & VbCrLf & "<td valign=top width=132>&nbsp;"
			Response.Write RestoreTime(GetData(3,n)) & "</td>"
			Response.Write "<td valign=top align=center width=20>"
			If (GetData(5,N) <> "" or CheckSupervisorUserName = 1) Then Response.Write "<a href='javascript:kill(" & GetData(0,n) & ");'>删</a>"
			Response.Write "</tr>" & VbCrLf
			i=i+1
		next
	End If
	If PageSplictString<>"" Then Response.Write "<tr bgcolor=" & DEF_BBS_TableHeadColor & " class=TBfour><td colspan=5>" & PageSplictString & "</td></tr>"
	%>
	      </table>
	<br><%

End Function%>