<!-- #include file=../inc/BBSsetup.asp -->
<!-- #include file=../inc/Board_Popfun.asp -->
<!-- #include file=inc/UserTopic.asp -->
<%
DEF_BBS_HomeUrl = "../"
Dim SdM_ID,SdM_Fromuser,SdM_toUser,SdM_Title,SdM_Content,SdM_IP,SdM_SendTime,SdM_ReadFlag

initDatabase
GBL_CHK_TempStr = ""

SiteHead(DEF_SiteNameString & " - 我的收件箱 - 查看信息")
UpdateOnlineUserAtInfo GBL_board_ID,"查看收件箱信息"
GBL_CHK_TempStr=""
If GBL_UserID = 0 Then
	GBL_CHK_TempStr = GBL_CHK_TempStr & "你没有登录<br>" & VbCrLf
End If

Dim MessageID
MessageID = Left(Request("MessageID"),14)
If isNumeric(MessageID) = 0 or MessageID = "" or InStr(MessageID,",") > 0 Then MessageID = 0
MessageID = Fix(cCur(MessageID))

If MessageID < 0 Then MessageID = 0

Dim AllPrintingString
AllPrintingString = ""
If Request.QueryString("AllPrinting")="Yesing" and CheckSupervisorUserName = 1 Then AllPrintingString = "&AllPrinting=Yesing"

UserTopicTopInfo
DisplayUserNavigate("<a href=MyInfoBox.asp>我的收件箱</a> &gt;&gt; 查看短消息")
%><p><%
If MessageID = 0 Then
	LookPubMessage
Else
	If GBL_CHK_TempStr <> "" Then
		Response.Write "<br><p align=left><font color=ff0000 class=RedFont><b>" & GBL_CHK_TempStr & "</b></font>"
	Else
		If MessageID = 0 Then
			GBL_CHK_TempStr = GBL_CHK_TempStr & "错误，找不到这条消息<br>" & VbCrLf
			Response.Write "<p align=left><font color=ff0000 class=RedFont><b>&nbsp; &nbsp; " & GBL_CHK_TempStr & "</b>"
		Else
			GBL_CHK_TempStr = ""
			GetMessageValue(MessageID)
			If GBL_CHK_TempStr = "" Then
				LookMessage
			Else
				Response.Write "<p align=left><font color=ff0000 class=RedFont><b>&nbsp; &nbsp; " & GBL_CHK_TempStr & "</b>"
			End If
		End if
	End If
End If
UserTopicBottomInfo
closeDataBase
SiteBottom
If GBL_ShowBottomSure = 1 Then Response.Write GBL_SiteBottomString

Function GetMessageValue(MessageID)

	Dim Rs,SQL
	Dim go
	go = Left(Request.QueryString("go"),4)
	If go = "pre" Then
		If CheckSupervisorUserName = 1 and AllPrintingString <> "" Then
			SQL = "Select top 1 ID,FromUser,toUser,Title,Content,IP,SendTime,ReadFlag from LeadBBS_InfoBox where ID>" & MessageID & " order by ID ASC"
		Else
			SQL = "Select top 1 ID,FromUser,toUser,Title,Content,IP,SendTime,ReadFlag from LeadBBS_InfoBox where ToUser='" & Replace(GBL_CHK_User,"'","''") & "' and ID>" & MessageID & " order by ID ASC"
		End If
		Set Rs = Con.ExeCute(SQL)
		GBL_DBNum = GBL_DBNum + 1
		If Rs.Eof Then
			Rs.Close
			Set Rs = Nothing
			SQL = "Select top 1 ID,FromUser,toUser,Title,Content,IP,SendTime,ReadFlag from LeadBBS_InfoBox where ID=" & MessageID
			Set Rs = Con.ExeCute(SQL)
			GBL_DBNum = GBL_DBNum + 1
		End If
	ElseIf go = "next" Then
		If CheckSupervisorUserName = 1 and AllPrintingString <> "" Then
			SQL = "Select top 1 ID,FromUser,toUser,Title,Content,IP,SendTime,ReadFlag from LeadBBS_InfoBox where ID<" & MessageID & " order by ID DESC"
		Else
			SQL = "Select top 1 ID,FromUser,toUser,Title,Content,IP,SendTime,ReadFlag from LeadBBS_InfoBox where ToUser='" & Replace(GBL_CHK_User,"'","''") & "' and ID<" & MessageID & " order by ID DESC"
		End If
		Set Rs = Con.ExeCute(SQL)
		GBL_DBNum = GBL_DBNum + 1
		If Rs.Eof Then
			Rs.Close
			Set Rs = Nothing
			SQL = "Select top 1 ID,FromUser,toUser,Title,Content,IP,SendTime,ReadFlag from LeadBBS_InfoBox where ID=" & MessageID
			Set Rs = Con.ExeCute(SQL)
			GBL_DBNum = GBL_DBNum + 1
		End If
	Else
		SQL = "Select top 1 ID,FromUser,toUser,Title,Content,IP,SendTime,ReadFlag from LeadBBS_InfoBox where ID=" & MessageID
		Set Rs = Con.ExeCute(SQL)
		GBL_DBNum = GBL_DBNum + 1
	End If

	If Rs.Eof Then
		Rs.Close
		Set Rs = Nothing
		GBL_CHK_TempStr = "错误，找不到这条消息相关资料．"
	Else
		SdM_ID = cCur(Rs(0))
		SdM_FromUser = Rs(1)
		SdM_toUser = Rs(2)
		SdM_Title = Rs(3)
		SdM_Content = Rs(4)
		SdM_IP = Rs(5)
		SdM_SendTime = cCur(Rs(6))
		SdM_ReadFlag = cCur(Rs(7))
		Rs.Close
		Set Rs = Nothing
		If SdM_FromUser <> GBL_CHK_User and SdM_toUser <> GBL_CHK_User Then
			GBL_CHK_TempStr = "错误，找不到这条消息相关资料．"
		Else
			If SdM_ReadFlag = 0 and SdM_toUser = GBL_CHK_User Then
				Con.ExeCute("Update LeadBBS_InfoBox Set readFlag=1 where ID=" & SdM_ID)
				GBL_DBNum = GBL_DBNum + 1
			End If
		End If
	End If

	If GBL_CHK_MessageFlag = 1 or GBL_CHK_MessageFlag = True Then
		SQL = "Select top 1 ID from LeadBBS_InfoBox where ReadFlag=0 and ToUser='" & Replace(GBL_CHK_User,"'","''") & "'"
		Set Rs = Con.exeCute(SQL)
		GBL_DBNum = GBL_DBNum + 1
		If Rs.Eof Then
			Rs.Close
			Set Rs = Nothing
			Con.Execute("Update LeadBBS_User Set MessageFlag=0 where ID=" & GBL_UserID)
			GBL_DBNum = GBL_DBNum + 1
			UpdateSessionValue 6,0,0
		Else
			Rs.Close
			Set Rs = Nothing
		End If
	End If

End Function


Function LookMessage

	Dim TempN
%>
	<%If SdM_Title<>"" Then Response.Write "<br><p align=center><b>" & htmlencode(SdM_Title) & "</b><p>"%>
	<table width=100% height=100% style="table-layout:fixed; word-break:break-all"><tr><td width=2><img src=<%=DEF_BBS_HomeUrl%>images/blank.gif width=2 height=2></td><td valign=top>
	<table border=0 cellpadding=8 cellspacing=1 width=100% bgcolor="<%=DEF_BBS_Color%>" style="WORD-BREAK: break-all;" class=TBBG1>
	<%If SdM_toUser = "" Then%>
	<tr bgcolor="<%=DEF_BBS_LightestColor%>" class=TBBG9> 
		<td width=60><img src=../images/blank.gif height=2 width=60><br>
			发布公告人</td>
		<td valign=top><img src=../images/null.gif width=299 height=2><br>
			<%=htmlencode(SdM_fromUser)%>
		</td>
	</tr>
	<tr bgcolor="<%=DEF_BBS_LightestColor%>" class=TBBG9> 
		<td align=left width=60>发布时间</td>
		<td height=24 valign=top>
			<%=htmlencode(RestoreTime(SdM_SendTime))%>
		</td>
	</tr>
	<tr bgcolor="<%=DEF_BBS_LightestColor%>" class=TBBG9> 
		<td align=left width=60>公告内容</td>
		<td height=24 valign=top>
			<%
			Response.Write VbCrLf & Replace(Replace(htmlencode(SdM_Content & ""),VbCrLf,"<br>"),"  ","&nbsp;&nbsp;")
			%>
		</td>
	</tr><%
	Else%>
	<tr bgcolor="<%=DEF_BBS_LightestColor%>" class=TBBG9>
		<td valign=top colspan=2>
			<img src=../images/null.gif width=2 height=3><br>
			<%
			If Trim(SdM_Content) = "" Then
				Response.Write "<font color=Gray class=GrayFont>短消息内容为空。</font>"
			Else
			   	If DEF_UBBiconNumber > 0 then
			   		SdM_Content = PrintTrueText(SdM_Content)
					For TempN = 1 to DEF_UBBiconNumber
			   			SdM_Content=replace(SdM_Content,"[EM" & Right(("0" & TempN),2) & "]","<img src=""../images/UBBicon/em" & Right("0" & TempN,2) & ".GIF"" width=20 height=20 align=absmiddle border=0>",1,10,0)
			   			SdM_Content=replace(SdM_Content,"[em" & Right(("0" & TempN),2) & "]","<img src=""../images/UBBicon/em" & Right("0" & TempN,2) & ".GIF"" width=20 height=20 align=absmiddle border=0>",1,10,0)
			   		Next
			   		Response.Write Message_Code(SdM_Content)
			   	Else
			   		Response.Write PrintTrueText(SdM_Content)
			   	End If
		   	End If
		   	%><br><img src=../images/null.gif width=2 height=3><br>
		   	<table width=332 border=0 cellspacing=0 cellpadding=0 style='table-layout:fixed; word-break:break-all'><tr><td><img src=../images/<%=GBL_DefineImage%>signature.gif width=500 height=17 border=0><br></td></tr></table>
		   	<font color=Gray class=GrayFont>发 件 人：</font><a href=../User/LookUserInfo.asp?name=<%=urlencode(SdM_fromUser)%>><%=htmlencode(SdM_fromUser)%></a>
		   	<br><img src=../images/null.gif width=2 height=3><br>
			<font color=Gray class=GrayFont>接 收 人：</font><a href=../User/LookUserInfo.asp?name=<%=urlencode(SdM_toUser)%>><%=SdM_toUser%></a><%
			If SdM_ReadFlag = 0 Then
				Response.write "， <b><font color=008800 class=GreenFont>您首次浏览此消息，请仔细处理</font></b>"
			End If%>
			<br><img src=../images/null.gif width=2 height=3><br>
			<font color=Gray class=GrayFont>发出时间：</font><%=htmlencode(RestoreTime(SdM_SendTime))%>
		</td>
	</tr>
	<%End If
	If SdM_toUser = GBL_CHK_User or CheckSupervisorUserName = 1 Then%>
	<tr bgcolor="<%=DEF_BBS_LightestColor%>" class=TBBG9> 
		<td colspan=2>
			<script language=javascript>
				function kill(killID)
				{
					window.open('DeleteMessage.asp?MessageID='+killID,'','width=450,height=37,scrollbars=auto,status=no');
				}
			</script>
			<a href='javascript:kill(<%=SdM_ID%>);'>删除短消息</a>，<a href=SendMessage.asp?ModifyMessageID=<%=SdM_ID%>>编辑短消息</a>，<a href=SendMessage.asp?SdM_toUser=<%=urlencode(SdM_fromUser)%>&ReplyMessageID=<%=SdM_ID%>>回复此消息请点击这里</a>
			<%If SdM_ID = MessageID and Request("go") = "pre" Then%> <font color=888888 class=GrayFont>上一条</font><%Else%>
			<a href=LookMessage.asp?MessageID=<%=SdM_ID%>&go=pre<%=AllPrintingString%>>上一条</a><%End If%>
			<%If SdM_ID = MessageID and Request("go") = "next" Then%> <font color=888888 class=GrayFont>下一条</font><%Else%>
			<a href=LookMessage.asp?MessageID=<%=SdM_ID%>&go=next<%=AllPrintingString%>>下一条</a><%End If%>
		</td>
	</tr><%End If%>
	</table>
	</td></tr></table>
	<br>

<%End Function

function Message_Code(Str)

	Dim UBBStrCnt
	UBBStrCnt = Str
	dim re
	set re = New RegExp
	re.Global = True
	re.IgnoreCase = True
    If DEF_EnableImagesUBB = 1 then
    	UBBStrCnt = OneLevelCode(UBBStrCnt, "[IMG]", "[/IMG]", "<IMG SRC="," border=0 onLoad=""javascript:if(this.width>450)this.width=450;"" onMouseover=""javascript:if(this.width>450)this.width=450;"" align=absmiddle>")
    	UBBStrCnt = OneLevelCode(UBBStrCnt, "[IMGA]", "[/IMGA]", "<IMG SRC="," border=0 alt=按此在新窗口浏览图片 onclick=""javascript:window.open(this.src);"" onLoad=""javascript:if(this.width>450)this.width=450;"" onMouseover=""javascript:if(this.width>450)this.width=450;"" style=""cursor:hand"" align=absmiddle>")
    End If
    Message_Code = UBBStrCnt

End Function

Function OneLevelCode(fString, Str1, Str2, ReStr1, ReStr2)

	If Lcase(Str1) = Ucase(Str1) and Lcase(Str2) = Ucase(Str2) Then
		OneLevelCode = OneLevelCode2(fString, Str1, Str2, ReStr1, ReStr2)
	Else
		OneLevelCode = OneLevelCode2(fString, Lcase(Str1), Lcase(Str2), ReStr1, ReStr2)
		OneLevelCode = OneLevelCode2(fString, Ucase(Str1), Ucase(Str2), ReStr1, ReStr2)
	End If

End Function

function OneLevelCode2(fString, Str1, Str2, ReStr1, ReStr2)

    Dim Str1Pos,Str2Pos
    Str1Pos = Instr(1, fString, Str1, 0)
    Str2Pos = Instr(Str1Pos + 1, fString, Str2, 0)

    Dim LenY,LenX
    LenY = Len(ReStr2) - len(Str2)
    LenX = Len(ReStr1) - len(Str1)

	Dim Flag,Tmp
	Flag = 0
    while (Str2Pos > 0 and Str1Pos > 0)
    	If (Ucase(Str1) = "[IMG]" or Ucase(Str1) = "[IMGA]") Then
    		Tmp = Trim(Lcase(Mid(fString,Str1Pos+Len(str1),15)))
    		'If Left(Tmp,2) = "&#" or Left(Tmp,14) = "&#106avascript" or Left(Tmp,10) = "javascript" or Left(Tmp,12)="&#106script:" or Left(Tmp,8)="jscript:" or Left(Tmp,7)="&#106s:" or Left(Tmp,3)="js:" or Left(Tmp,9)="about&#58" or Left(Tmp,6)="about:" or Left(Tmp,8)="file&#58" or Left(Tmp,5)="file:" or Left(Tmp,13)="&#118bscript:" or Left(Tmp,9)="vbscript:" or Left(Tmp,8)="&#118bs:" or Left(Tmp,4)="vbs:" Then Flag = 1
    		If Left(Tmp,1) <> "/" and Left(Tmp,3) <> "../" and Left(Tmp,7) <> "http://" and Left(Tmp,8) <> "https://" and Left(Tmp,6) <> "ftp://" Then Flag = 1
    	End If
    	If Flag = 1 Then
    		Flag = 0
    	Else
			fString = Left(fString,Str1Pos-1) & replace(fString, Str1, ReStr1, Str1Pos, 1, 0)
			'fString = Left(fString,Str2Pos-1) & replace(fString, Str2, ReStr2, Str2Pos, 1, 0)
			Str2Pos = Str2Pos + LenX
			fString = Left(fString,Str2Pos-1) & replace(fString, Str2, ReStr2, Str2Pos, 1, 0)
			Str2Pos = Str2Pos + LenY
		End If
		Str1Pos = Instr(Str2Pos + 1, fString, Str1, 0)
		Str2Pos = Instr(Str1Pos + 1, fString, Str2, 0)
    wend
    OneLevelCode2 = fString

End Function

Function LookPubMessage

	GBL_CHK_TempStr = ""
	Dim Rs,SQL,GetData
	Set Rs = Server.CreateObject("ADODB.RecordSet")
	SQL = "Select top " & DEF_TopicContentMaxListNum & " ID,FromUser,toUser,Title,Content,IP,SendTime,ReadFlag from LeadBBS_InfoBox where ToUser='' order by ID DESC"
	Set Rs = Con.ExeCute(SQL)
	GBL_DBNum = GBL_DBNum + 1

	If Rs.Eof Then
		GBL_CHK_TempStr = "错误，找不到这条消息相关资料．"
	Else
		GetData = Rs.GetRows(-1)
	End If
	Rs.Close
	Set Rs = Nothing

	If GBL_CHK_TempStr <> "" Then
		Response.Write "<p align=left><font color=ff0000 class=RedFont><b>&nbsp; &nbsp; " & GBL_CHK_TempStr & "</b>"
		Exit Function
	End If

	Dim TempN,N,SuperFlag
	SuperFlag = CheckSupervisorUserName
	If GBL_UserID < 1 Then SuperFlag = 0
	For N = 0 to Ubound(GetData,2)
		Response.Write "<a name=" & N & "></a>"
%>
	
	<br>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr> 
		<td> 
			<div align="center">
				<%
				If GetData(3,N)<>"" Then Response.Write "<b>" & GetData(3,N) & "</b>"%>
			</div>
		</td>
		<td> 
		</td>
	</tr>
	</table>
	<br>
	<table border=0 cellpadding=5 cellspacing=1 width=100% bgcolor="<%=DEF_BBS_Color%>" style="WORD-BREAK: break-all;" class=TBBG1 align=center>
	
	<tr bgcolor="<%=DEF_BBS_LightestColor%>" class=TBBG9> 
		<td align=center>
			发布人： <a href=LookUserinfo.asp?name=<%=urlencode(GetData(1,N))%>><%=htmlencode(GetData(1,N))%></a> &nbsp;公告时间： <%=htmlencode(RestoreTime(GetData(6,N)))%>
		</td>
	</tr>
	<tr bgcolor="<%=DEF_BBS_LightestColor%>" class=TBBG9> 
		<td height=24 valign=top>
			<%
		   	If DEF_UBBiconNumber > 0 then
		   		If inStr(GetData(4,N),"[em") > 0 or inStr(GetData(4,N),"[EM") > 0 then
					For TempN = 1 to DEF_UBBiconNumber
			   			GetData(4,N)=replace(GetData(4,N),"[EM" & Right(("0" & TempN),2) & "]","<img src=""../images/UBBicon/em" & Right("0" & TempN,2) & ".GIF"" width=20 height=20 align=absmiddle border=0>",1,10,0)
			   			GetData(4,N)=replace(GetData(4,N),"[em" & Right(("0" & TempN),2) & "]","<img src=""../images/UBBicon/em" & Right("0" & TempN,2) & ".GIF"" width=20 height=20 align=absmiddle border=0>",1,10,0)
			   		Next
			   	End If
		   	End If
			Response.Write VbCrLf & Replace(Replace(GetData(4,N) & "",VbCrLf,"<br>"),"  ","&nbsp;&nbsp;")
			%>
		</td>
	</tr>
	<%
	If SuperFlag = 1 Then%>
	<tr bgcolor="<%=DEF_BBS_LightestColor%>" class=TBBG9> 
		<td>
			<script language=javascript>
				function kill(killID)
				{
					window.open('DeleteMessage.asp?MessageID='+killID,'','width=450,height=37,scrollbars=auto,status=no');
				}
			</script>
			<a href='javascript:kill(<%=GetData(0,N)%>);'>删除公告</a>，<a href=SendMessage.asp?ModifyMessageID=<%=GetData(0,N)%>>编辑短消息</a>，发布公告人IP：<%=GetData(5,N)%>
		</td>
	</tr><%End If%>
	</table>
	<br>
<%
	Next

End Function

Function PrintTrueText(tempString)

	If tempString<>"" Then
		PrintTrueText=Replace(Replace(Replace(Replace(Replace(htmlEncode(tempString),VbCrLf & " ","<br>" & "&nbsp;"),VbCrLf,"<br>" & VbCrLf),"   "," &nbsp; "),"  "," &nbsp;"),chr(9)," &nbsp; &nbsp; &nbsp;")

		If Left(PrintTrueText,1) = chr(32) Then
			PrintTrueText = "&nbsp;" & Mid(PrintTrueText,2)
		End If
	Else
		PrintTrueText=""
	End If

End Function%>