<!--#include file="conn.asp"-->
<!--#include file="inc/const.asp"-->
<!--#include file="inc/check.asp"-->
<!--#include file="inc/ubbcode.asp"-->
<%
Dim HtmlContent,Action,sharePoints,shareExperience
Dim classid,classname,parentid,parentstr,TopicID,TopicMode,PostsID
Dim TopicUseTable,PostUsername,Quserid,strTopic,Reward
Dim AnonymPoints,BroadPoints,islock
classid = NewAsp.ChkNumeric(Request("classid"))
TopicID = NewAsp.ChkNumeric(Request("TopicID"))
PostsID = NewAsp.ChkNumeric(Request("PostsID"))
sharePoints = NewAsp.ChkNumeric(NewAsp.Point_Setting(14))
shareExperience = NewAsp.ChkNumeric(NewAsp.Point_Setting(15))
AnonymPoints = NewAsp.CheckNumeric(NewAsp.Point_Setting(18))
BroadPoints = NewAsp.CheckNumeric(NewAsp.Point_Setting(19))
islock = 0

'--检测是否代理服务器提交
NewAsp.ChcekProxy(NewAsp.Asked_Setting(21))
If Not CheckShareClass(classid) Then
	Response.Write "<script>alert('友情提示!\n\n错误的系统参数,请选择正确的分类!');</script>"
End If
Action = NewAsp.CheckBadstr(Request("action"))
Select Case LCase(Action)
	Case "save"
		Call saveshare()
	Case "reply"
		Call ReplyShare()
	Case Else
		Call showmain()
End Select

Sub showmain()
	If NewAsp.FoundErr = True Then Exit Sub
	HtmlContent = NewAsp.LoadTemplate("postshare")
	HtmlContent = Replace(HtmlContent, "{$IndexMenulist}", NewAsp.IndexMenulist)
	HtmlContent = Replace(HtmlContent, "{$HeadTitle}", "发表主题")
	HtmlContent = Replace(HtmlContent, "{$UserPoints}", UserPoints)
	HtmlContent = Replace(HtmlContent, "{$AnonymPoints}", AnonymPoints)
	HtmlContent = Replace(HtmlContent, "{$BroadPoints}", BroadPoints)
	HtmlContent = Replace(HtmlContent, "{$UserID}", NewAsp.UserID)
	HtmlContent = Replace(HtmlContent, "{$ClassID}", classid)
	HtmlContent = Replace(HtmlContent, "{$TopicID}", TopicID)
	HtmlContent = Replace(HtmlContent, "{$PostsID}", PostsID)
	Response.Write NewAsp.ArchiveHtml(HtmlContent)
End Sub

Function CheckShareClass(cid)
	Dim Rs
	Set Rs = Newasp.Execute("SELECT classid,classname,parentid,parentstr FROM NC_Ask_Class WHERE classid="&CLng(cid))
	If Rs.BOF And Rs.EOF Then
		NewAsp.FoundErr = True
		CheckShareClass = False
	Else
		classname = Rs(1)
		parentid = Rs(2)
		parentstr = Rs(3)
		CheckShareClass = True
	End If
	Rs.Close:Set Rs = Nothing
End Function

Sub saveshare()
	If NewAsp.FoundErr = True Then Exit Sub
	Dim Rs,SQL
	Dim ShareTopic,TextContent,TitleLength,TextLength
	Dim UserNowPoint
	If NewAsp.Posts_Setting(3) = "0" Then
		Response.Write "<script>alert('友情提示!\n\n禁止发表主题!');</script>"
		Exit Sub
	End If
	UserNowPoint = UserPoints + sharePoints
	ShareTopic = NewAsp.RequestForm("topic",220)
	TextContent = Request.Form("content")
	If Len(TextContent) < 2 Then
		Response.Write "<script>alert('友情提示!\n\n您提交的内容不能为空!');</script>"
		Exit Sub
	End If
	TextContent = UBB2Html(TextContent)
	TitleLength = NewAsp.strLength(ShareTopic)
	TextLength = NewAsp.strLength(TextContent)
	If TitleLength < CLng(NewAsp.Posts_Setting(20)) Then
		Response.Write "<script>alert('友情提示!\n\n标题不能小于 " & NewAsp.Posts_Setting(20) & " 个字节!');</script>"
		Exit Sub
	End If
	If TitleLength > CLng(NewAsp.Posts_Setting(21)) Then
		Response.Write "<script>alert('友情提示!\n\n标题不能大于 " & NewAsp.Posts_Setting(21) & " 个字节!');</script>"
		Exit Sub
	End If
	If TextLength < CLng(NewAsp.Posts_Setting(22)) Then
		Response.Write "<script>alert('友情提示!\n\n您提交的内容不能小于 " & NewAsp.Posts_Setting(22) & " 个字节!');</script>"
		Exit Sub
	End If
	If TextLength > CLng(NewAsp.Posts_Setting(23)) Then
		Response.Write "<script>alert('友情提示!\n\n您提交的内容不能大于 " & NewAsp.Posts_Setting(23) & " 个字节!');</script>"
		Exit Sub
	End If
	If NewAsp.ChkRefresh Then
		Response.Write "<script>alert('友情提示!\n\n本页面起用了防刷新机制,请不要连续刷新本页面!');</script>"
		Exit Sub
	End If
	Set Rs = Newasp.Execute("SELECT TopicID FROM NC_Ask_Topic WHERE TopicMode=3 And userid="&NewAsp.UserID&" And title='"&NewAsp.Checkstr(ShareTopic)&"'")
	If Not (Rs.BOF And Rs.EOF) Then
		Response.Write "<script>alert('友情提示!\n\n请不要发布相同的内容!');</script>"
		Exit Sub
	End If
	Rs.Close:Set Rs = Nothing
	If NewAsp.ChkBadword(TextContent) Then
		islock=0
	Else
		islock=1
	End If
	Set Rs = NewAsp.CreateAXObject("ADODB.Recordset")
	SQL = "SELECT * FROM NC_Ask_Topic WHERE (TopicID is null)"
	Rs.Open SQL,Conn,1,3
	Rs.Addnew
		Rs("classid") = classid
		Rs("userid") = NewAsp.UserID
		Rs("classname") = classname
		Rs("title") = ShareTopic
		Rs("PostUsername") = NewAsp.UserName
		Rs("Expired") = 0
		Rs("Closed") = 0
		Rs("PostTable") = NewAsp.NowUseTable
		Rs("DateAndTime") = Now()
		Rs("LastPostTime") = Now()
		Rs("ExpiredTime") = Now()
		Rs("LockTopic") = islock
		Rs("Reward") = 0'RewardPoints
		Rs("Hits") = 0
		Rs("PostNum") = 0
		Rs("CommentNum") = 0
		Rs("TopicMode") = 3
		Rs("AskedMode") = 0
		Rs("Highlight") = 0
		Rs("Broadcast") = 0'Broadcast
		Rs("Anonymous") = 0'Anonymous
		Rs("IsTop") = 0
		Rs("supplement") = 0
	Rs.Update
	Rs.Close:Set Rs = Nothing
	Set Rs=NewAsp.Execute("SELECT TOP 1 TopicID FROM [NC_Ask_Topic] ORDER BY TopicID DESC")
		TopicID = Rs(0)
	Rs.Close
	Set Rs = Nothing
	Set Rs = NewAsp.CreateAXObject("ADODB.Recordset")
	SQL = "SELECT * FROM " & NewAsp.NowUseTable & " WHERE (postsid is null)"
	Rs.Open SQL,Conn,1,3
	Rs.Addnew
		Rs("classid") = classid
		Rs("TopicID") = TopicID
		Rs("userid") = NewAsp.UserID
		Rs("UserName") = NewAsp.UserName
		Rs("topic") = ShareTopic
		Rs("content") = TextContent
		Rs("addText") = ""
		Rs("PostTime") = Now()
		Rs("DoneTime") = Now()
		Rs("length") = TextLength
		Rs("star") = 0
		Rs("satis") = 0
		Rs("LockTopic") = islock
		Rs("PostsMode") = 0
		Rs("VoteNum") = 0
		Rs("Plus") = 0
		Rs("Minus") = 0
		Rs("UserIDlist") = ""
		Rs("PostIP") = NewAsp.UserTrueIP
		Rs("Report") = 0
	Rs.Update
	Rs.Close:Set Rs = Nothing
	NewAsp.Execute ("UPDATE NC_Ask_Users SET Points=" & UserNowPoint & ",Experience=Experience+" & shareExperience & ",SharePoint=SharePoint+" & NewAsp.ChkNumeric(NewAsp.Point_Setting(14)) & ",Askshare=Askshare+1 WHERE userid="& NewAsp.UserID)
	Newasp.Execute ("UPDATE NC_Ask_Setup SET MaxshareNum=MaxshareNum+1")
	Newasp.Execute ("UPDATE NC_Ask_Class SET AskshareNum=AskshareNum+1 WHERE classid="& classid)
	NewAsp.ReloadSetupCache Clng(NewAsp.MaxshareNum)+1,10
	Dim strReturnURL,Direct
	Direct = NewAsp.ChkNumeric(Request.Form("direct"))
	strReturnURL = NewAsp.RewriteHtmlURL(NewAsp.InstallDir & "showlist.asp?classid=" & classid & "&topicmode=3")
	Response.Write "<script language=""JavaScript"">"
	If Direct = 0 Then Response.Write "alert('恭喜您!发表主题成功');"
	Response.Write "try{top.location='" & strReturnURL & "';"
	Response.Write "}catch(e){}"
	Response.Write "</script>"
End Sub

Sub ReplyShare()
	If NewAsp.FoundErr = True Then Exit Sub
	Dim Rs,SQL
	Dim TextContent,TitleLength,TextLength
	Dim UserNowPoint
	TopicID = NewAsp.ChkNumeric(Request.Form("TopicID"))
	If NewAsp.Posts_Setting(4) = "0" Then
		Response.Write "<script>alert('友情提示!\n\n禁止回复!');</script>"
		Exit Sub
	End If
	TextContent = Request.Form("content")
	If Len(TextContent) < 2 Then
		Response.Write "<script>alert('友情提示!\n\n您提交的内容不能为空!');</script>"
		Exit Sub
	End If
	TextContent = UBB2Html(TextContent)
	TextLength = NewAsp.strLength(TextContent)
	If TextLength < CLng(NewAsp.Posts_Setting(24)) Then
		Response.Write "<script>alert('友情提示!\n\n您提交的内容不能小于 " & NewAsp.Posts_Setting(24) & " 个字节!');</script>"
		Exit Sub
	End If
	If TextLength > CLng(NewAsp.Posts_Setting(25)) Then
		Response.Write "<script>alert('友情提示!\n\n您提交的内容不能大于 " & NewAsp.Posts_Setting(25) & " 个字节!');</script>"
		Exit Sub
	End If
	If NewAsp.ChkRefresh Then
		Response.Write "<script>alert('友情提示!\n\n本页面起用了防刷新机制,请不要连续刷新本页面!');</script>"
		Exit Sub
	End If
	LoadTopicInfo(3)
	If TopicMode <> 3 Then
		Response.Write "<script>alert('友情提示!\n\n错误的系统参数!');</script>"
		Exit Sub
	End If
	If NewAsp.ChkBadword(TextContent) Then
		islock=0
	Else
		islock=1
	End If
	If NewAsp.FoundErr Then Exit Sub
	Set Rs = NewAsp.CreateAXObject("ADODB.Recordset")
	SQL = "SELECT * FROM NC_Ask_Answer WHERE TopicID="& TopicID &" And userid="& NewAsp.UserID
	Rs.Open SQL,Conn,1,3
	If Rs.BOF And Rs.EOF Then
		Rs.Addnew
		Rs("TopicID") = TopicID
		Rs("classid") = classid
		Rs("classname") = classname
		Rs("userid") = NewAsp.UserID
		Rs("Username") = NewAsp.UserName
		Rs("PostUserID") = Quserid
		Rs("PostUsername") = PostUsername
		Rs("title") = strTopic
		Rs("AnswerTime") = Now()
		Rs("PostTable") = TopicUseTable
		Rs("AnswerNum") = 1
		Rs("AnswerMode") = 3
		Rs("TopicMode") = 3
		Rs.Update
	Else
		Rs("AnswerTime") = Now()
		Rs("AnswerNum") = Rs("AnswerNum") + 1
		Rs.Update
	End If
	Rs.Close:Set Rs = Nothing
	Set Rs = NewAsp.CreateAXObject("ADODB.Recordset")
	SQL = "SELECT * FROM " & TopicUseTable & " WHERE (postsid is null)"
	Rs.Open SQL,Conn,1,3
	Rs.Addnew
		Rs("classid") = classid
		Rs("TopicID") = TopicID
		Rs("userid") = NewAsp.UserID
		Rs("UserName") = NewAsp.UserName
		Rs("topic") = strTopic
		Rs("content") = TextContent
		Rs("addText") = ""
		Rs("PostTime") = Now()
		Rs("DoneTime") = Now()
		Rs("length") = TextLength
		Rs("star") = 0
		Rs("satis") = 0
		Rs("LockTopic") = islock
		Rs("PostsMode") = 1
		Rs("VoteNum") = 0
		Rs("Plus") = 0
		Rs("Minus") = 0
		Rs("PostIP") = NewAsp.UserTrueIP
		Rs("Report") = 0
	Rs.Update
	Rs.Close:Set Rs = Nothing
	UserNowPoint = UserPoints + sharePoints
	
	NewAsp.Execute ("UPDATE NC_Ask_Users SET Points=" & UserNowPoint & ",Experience=Experience+" & shareExperience & ",SharePoint=SharePoint+" & NewAsp.ChkNumeric(NewAsp.Point_Setting(14)) & " WHERE userid="& NewAsp.UserID)
	NewAsp.Execute ("UPDATE NC_Ask_Topic SET PostNum=PostNum+1,LastPostTime=" & NowString & " WHERE TopicID="& TopicID)
	Dim Direct
	Direct = NewAsp.ChkNumeric(Request.Form("direct"))
	Response.Write "<script>"
	If Direct = 0 Then Response.Write "alert('恭喜您!提交回复成功');"
	Response.Write "try{top.location.replace(document.referrer);}catch(e){}</script>"
End Sub

Sub LoadTopicInfo(iMode)
	Dim SQL,Rs
	SQL = "SELECT TopicID,classid,classname,userid,title,PostUsername,Expired,Closed,PostTable,DateAndTime,Reward,PostNum,CommentNum,TopicMode,supplement FROM NC_Ask_Topic WHERE TopicID="&TopicID&" And TopicMode="&iMode&" And LockTopic=0"
	Set Rs = Newasp.Execute(SQL)
	If Rs.BOF And Rs.EOF Then
		NewAsp.FoundErr = True
		Response.Write "<script>alert('友情提示!\n\n非法操作!');</script>"
		Exit Sub
	Else
		TopicID = Rs("TopicID")
		classid = Rs("classid")
		classname = Rs("classname")
		Quserid = Rs("userid")
		strTopic = Rs("title")
		PostUsername = Rs("PostUsername")
		TopicUseTable = Trim(Rs("PostTable"))
		Reward = Rs("Reward")
		TopicMode = Rs("TopicMode")
	End If
	Set Rs = Nothing
End Sub
%>