<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<% Option Explicit %>
<!--#include file="FS_Inc/Const.asp" -->
<!--#include file="FS_InterFace/MF_Function.asp" -->
<!--#include file="FS_Inc/Function.asp" -->
<%session.CodePage="936"%>
<%
	Response.Buffer = True
	Response.Expires = -1
	Response.ExpiresAbsolute = Now() - 1
	Response.Expires = 0
	Response.CacheControl = "no-cache"
	response.Charset = "gb2312"
	Dim Conn,User_Conn,Page_Sql,Page_RS,strShowErr,Cookie_Domain
	Dim Server_Name,Server_V1,Server_V2
	Dim TmpStr,TmpArr,tmprs_,tmpStr1,TmpStr_2
	Dim stype,Id,PageType

	MF_Default_Conn

	Cookie_Domain = Get_MF_Domain()
	if Cookie_Domain="" then
		Cookie_Domain = "localhost"
	else
		if left(lcase(Cookie_Domain),len("http://"))="http://" then Cookie_Domain = mid(Cookie_Domain,len("http://")+1)
		if right(Cookie_Domain,1)="/" then Cookie_Domain = mid(Cookie_Domain,1,len(Cookie_Domain) - 1)
	end if
	''防盗连
	Dim Main_Name,Name_Str1,V_MainName,V_Str
	Server_Name = NoHtmlHackInput(NoSqlHack(LCase(Trim(Request.ServerVariables("SERVER_NAME")))))
	IF Server_Name <> LCase(Split(Cookie_Domain,"/")(0)) Then
		Response.Write ("没有权限访问")
		Response.End
	End If
	Server_V1 = NoHtmlHackInput(NoSqlHack(Trim(Replace(Lcase(Cstr(Request.ServerVariables("HTTP_REFERER"))),"http://",""))))
	Server_V1 = Replace(Replace(Server_V1,"//","/"),"///","/")
	IF Server_V1 = "" Then
		Response.Write ("没有权限访问")
		Response.End
	End If
	IF Instr(Server_V1,"/") = 0 Then
		Server_V2 = Server_V1
	Else
		Server_V2 = Split(Server_V1,"/")(0)
	End If	
	If Instr(Server_Name,".") = 0 Then
		Main_Name = Server_Name
	Else
		Name_Str1 = Split(Server_Name,".")(0)
		Main_Name = Trim(Replace(Server_Name,Name_Str1 & ".",""))
	End If
	If Instr(Server_V2,".") = 0 Then
		V_MainName = Server_V2
	Else
		V_Str = Split(Server_V2,".")(0)
		V_MainName = Trim(Replace(Server_V2,V_Str & ".",""))
	End If
	If Main_Name <> V_MainName And (Main_Name = "" OR V_MainName = "") Then
		Response.Write ("没有权限访问")
		Response.End
	End If

	stype = NoSqlHack(request.QueryString("type")) 'NS
	Id = NoSqlHack(replace(request.QueryString("Id"),"'","")) 'NewsId
	PageType = NoSqlHack(replace(request.QueryString("PageType"),"'","")) 'PageType

	if stype="" then stype="NS"
	if Id="" then call response.Write("Error:Id is null!"):response.End()

	select case stype
		case "NS"
			'同时取栏目ID
			set tmprs_ = Conn.execute("select ID,ClassID from FS_NS_News where NewsID='"&Id&"'")
			if tmprs_.eof then
				TmpStr = "错误：不存在的新闻ID."
			else
				If PageType = "PrevPage" Then
					set Page_RS=Conn.execute("select top 1 ID,NewsID,NewsTitle from FS_NS_News where ID < "&tmprs_("ID")&" and ClassID='"&tmprs_("ClassID")&"' And isRecyle=0  order by ID desc")
					if Page_RS.eof then
						TmpStr = "无"
					else
						if isnull(Page_RS("NewsTitle")) or Page_RS("NewsTitle")="" then
							TmpStr = "无标题！"
						else
							tmpStr1 = Page_RS("NewsTitle")
							TmpStr = "<a href="""&get_NewsLink(Page_RS("NewsID"))&""">"&tmpStr1&"</a>"
						end if
					end If
				Else
					''''''''''''''''''''''''''''''''''''''''''
					set Page_RS=Conn.execute("select top 1 ID,NewsID,NewsTitle from FS_NS_News where ID > "&tmprs_("ID")&" and ClassID='"&tmprs_("ClassID")&"'  And isRecyle=0  order by ID")
					if Page_RS.eof then
						TmpStr = "无"
					else
						if isnull(Page_RS("NewsTitle")) or Page_RS("NewsTitle")="" then
							TmpStr= "无标题！"
						else
							tmpStr1 = Page_RS("NewsTitle")
							TmpStr = "<a href="""&get_NewsLink(Page_RS("NewsID"))&""">"&tmpStr1&"</a>"
						end if
					end If
				End If
				Page_RS.close
			End If
			tmprs_.close
		case else
			response.Write("Error:"&stype&" is not found.")
	end select
	response.Write(TmpStr)
	ConnClose()


	'得到新闻单个地址____________________________________________________________
	 Public Function get_NewsLink(f_id)
		get_NewsLink = ""
		dim rs,config_rs,config_mf_rs,class_rs
		dim SaveNewsPath,FileName,FileExtName,ClassId,LinkType,MF_Domain,Url_Domain,ClassEName,c_Domain,c_SavePath,IsDomain
		set rs = Conn.execute("select ID,IsURL,URLAddress,ClassId,NewsId,SaveNewsPath,FileName,FileExtName From FS_NS_News where NewsId='"&f_id&"'")
		if not rs.eof then
			SaveNewsPath = rs("SaveNewsPath")
			FileName = rs("FileName")
			FileExtName = rs("FileExtName")
			ClassId = rs("ClassId")
			LinkType = Request.Cookies("FoosunNSCookies")("FoosunNSLinkType")
			IsDomain = Request.Cookies("FoosunNSCookies")("FoosunNSDomain")
			MF_Domain = Request.Cookies("FoosunMFCookies")("FoosunMFDomain")
			set class_rs = Conn.execute("select ClassEName,IsURL,URLAddress,[Domain],SavePath From FS_NS_NewsClass where ClassId='"&ClassId&"'")
			if not class_rs.eof then
				ClassEName = class_rs("ClassEName")
				c_Domain = class_rs("Domain")
				c_SavePath = class_rs("SavePath")
				class_rs.close:set class_rs=nothing
			else
				ClassEName = ""
				class_rs.close:set class_rs=nothing
			end if
			if rs("IsURL")=0 then
				if LinkType = 1 then
					if trim(c_Domain)<>"" then
						Url_Domain = "http://"&c_Domain
					else
						if trim(IsDomain)<>"" then
							Url_Domain = "http://"&IsDomain
							c_SavePath = ""
						else
							Url_Domain = "http://"&MF_Domain
							c_SavePath = c_SavePath
						end if
					end if
				else
					if trim(c_Domain)<>"" then
						Url_Domain = "http://"&c_Domain
					else
						if trim(IsDomain)<>"" then
							Url_Domain = "http://"&IsDomain
							c_SavePath = ""
						else
							if G_VIRTUAL_ROOT_DIR<>"" then
								Url_Domain = "/"& G_VIRTUAL_ROOT_DIR
							else
								Url_Domain = ""
							end if
							c_SavePath = c_SavePath
						end if
					end if
				end if
				if trim(c_Domain)<>"" then
					get_NewsLink = Url_Domain & replace(SaveNewsPath &"/"&FileName&"."&FileExtName,"//","/")
				else
					get_NewsLink = Url_Domain & replace(c_SavePath& "/" & ClassEName &SaveNewsPath &"/"&FileName&"."&FileExtName,"//","/")
				end if
			else
				get_NewsLink = rs("URLAddress")
			end if
			rs.close:set rs=nothing
		else
			get_NewsLink = ""
			rs.close:set rs=nothing
		end if
	End Function


	Sub ConnClose()
		Set Conn = Nothing
		response.End()
	End Sub
%>
