<!--#include file="const.asp"-->
<!--#include file="../../inc/ubbcode.asp"-->
<!--#include file="../inc/cls_tags.asp"-->
<%
Admin_header
'=====================================================================
' 软件名称：新云网站管理系统
' 当前版本：NewAsp Content Management System Version 4.0
' 文件名称：admin_save.asp
' 更新日期：2008-06-16
' 官方网站：新云网络(www.NewAsp.net www.NewAsp.cn) QQ：94022511
'=====================================================================
' Copyright 2003-2008 NewAsp.net - All Rights Reserved.
' newasp is a trademark of NewAsp.net
'=====================================================================
Dim TextContent,flashid
Dim Action,AlphaTitle,Taglist,Tagstring
If Not ChkAdmin("PostFlash_"&ChannelID) Then
	Call Transfer_error()
End If
Action = LCase(Request("action"))
Select Case Trim(Action)
Case "save"
	Call saveNewSoft()
Case "modify"
	Call ModifySoft()
Case Else
	'Call showmain
End Select
If FoundErr = True Then
	ReturnError(ErrMsg)
End If
Admin_footer
SaveLogInfo(AdminName)
NewAsp.PageEnd

Sub AddUpdateTags(act)
	Tag.ChannelID=ChannelID
	Tag.Modules=NewAsp.Modules
	Tag.classid=NewAsp.CheckNumeric(Request.Form("ClassID"))
	Tag.Taghits=NewAsp.CheckNumeric(Request.Form("AllHits"))
	Tag.IsBest=NewAsp.ChkNumeric(Request.Form("IsBest"))
	Tag.IsTop=NewAsp.ChkNumeric(Request.Form("isTop"))
	Tag.TagString=Trim(Request.Form("Tagstring"))
	Tag.tagList=Trim(Request.Form("Taglist"))
	If act=1 Then
		Tag.AddNewTags()
	Else
		Tag.UpdateTags()
	End If
	Taglist=Tag.tagList&"|"&Tag.checkTagString(Request.Form("Tagstring"))
End Sub

Sub saveNewSoft()
	CheckSave
	If Founderr = True Then Exit Sub
	Call AddUpdateTags(1)
	Dim Rs,SQL,i
	Set Rs = NewAsp.CreateAXObject("ADODB.Recordset")
	SQL = "SELECT * FROM NC_FlashList WHERE (flashid is null)"
	Rs.Open SQL,Conn,1,3
	Rs.Addnew
		Rs("ChannelID") = ChannelID
		Rs("classid") = NewAsp.CheckNumeric(Request.Form("classid"))
		Rs("SpecialID") = NewAsp.CheckNumeric(Request.Form("SpecialID"))
		Rs("title") = NewAsp.RequestForm(Request.Form("title"),255)
		Rs("subtitle") = NewAsp.RequestForm(Request.Form("subtitle"),200)
		Rs("ColorMode") = NewAsp.CheckNumeric(Request.Form("ColorMode"))
		Rs("FontMode") = NewAsp.CheckNumeric(Request.Form("FontMode"))
		Rs("Introduce") = TextContent
		Rs("OuterLinks") = NewAsp.RequestForm(Request.Form("OuterLinks"),255)
		Rs("Related") = NewAsp.RequestForm(Request.Form("Related"),255)
		Rs("Describe") = NewAsp.RequestForm(Request.Form("Describe"),255)
		If UCase(Request.Form("SizeUnit")) = "MB" Then
			Rs("filesize") = CLng(NewAsp.CheckNumeric(Request.Form("filesize")) * 1024)
		Else
			Rs("filesize") = NewAsp.CheckNumeric(Request.Form("filesize"))
		End If
		Rs("Author") = Trim(Request.Form("Author"))
		Rs("ComeFrom") = Trim(Request.Form("ComeFrom"))
		Rs("star") = NewAsp.ChkNumeric(Request.Form("star"))
		Rs("miniature") = Trim(Request.Form("miniature"))
		Rs("UserGroup") = Newasp.ChkNumeric(Request.Form("UserGroup"))
		Rs("PointNum") = Newasp.ChkNumeric(Request.Form("PointNum"))
		Rs("UserName") = Trim(AdminName)
		Rs("addTime") = Formatime(Trim(Request.Form("addTime")))
		Rs("HtmlFileDate") = Trim(NewAsp.HtmlRndFileName)
		Rs("AllHits") = NewAsp.CheckNumeric(Request.Form("AllHits"))
		Rs("DayHits") = NewAsp.CheckNumeric(Request.Form("AllHits"))
		Rs("WeekHits") = NewAsp.CheckNumeric(Request.Form("AllHits"))
		Rs("MonthHits") = NewAsp.CheckNumeric(Request.Form("AllHits"))
		Rs("HitsTime") = Now()
		Rs("grade") = 0
		Rs("showmode") = NewAsp.ChkNumeric(Request.Form("showmode"))
		Rs("isTop") = NewAsp.ChkNumeric(Request.Form("IsTop"))
		Rs("IsBest") = NewAsp.ChkNumeric(Request.Form("IsBest"))
		Rs("downid") = NewAsp.ChkNumeric(Request.Form("downid"))
		Rs("showurl") = Trim(Request.Form("showurl"))
		Rs("DownAddress") = Trim(Request.Form("DownAddress"))
		Rs("isUpdate") = 1
		Rs("isAccept") = NewAsp.ChkNumeric(Request("isAccept"))
		Rs("ForbidEssay") = NewAsp.ChkNumeric(Request.Form("ForbidEssay"))
		Rs("AlphaIndex") = Newasp.ReadAlpha(AlphaTitle)
		Rs("good") = NewAsp.CheckNumeric(Request.Form("good"))
		Rs("bad") = NewAsp.CheckNumeric(Request.Form("bad"))
		Rs("Taglist")=Taglist
	Rs.update
	Rs.Close
	Rs.Open "SELECT TOP 1 flashid FROM NC_FlashList WHERE ChannelID=" & ChannelID & " ORDER BY flashid DESC", Conn, 1, 1
	flashid = Rs("flashid")
	Rs.Close:Set Rs = Nothing
	
	ClassUpdateCount NewAsp.CheckNumeric(Request.Form("classid")),1
	Call RemoveCache
	If CInt(NewAsp.IsCreateHtml) <> 0 Then
		Dim url
		url = "admin_makeshow.asp?ChannelID=" & ChannelID & "&inflashid=" & flashid & "&t=2&u=1"	
		Call ScriptCreation(url)
		SQL = "SELECT TOP 1 flashid FROM NC_FlashList WHERE ChannelID=" & ChannelID & " And isAccept <> 0 And flashid < " & flashid & " ORDER BY flashid DESC"
		Set Rs = NewAsp.Execute(SQL)
		If Not (Rs.EOF And Rs.BOF) Then
			url = "admin_makeshow.asp?ChannelID=" & ChannelID & "&inflashid=" & Rs("flashid") & "&t=2&u=1"	
			Call ScriptCreation(url)
		End If
		Rs.Close
		Set Rs = Nothing
	End If
	Succeed("<li>恭喜您！添加新的" & NewAsp.ModuleName & "成功。</li><li><a href=""admin_list.asp?action=view&ChannelID=" & ChannelID & "&flashid=" & flashid & """>点击此处查看该" & NewAsp.ModuleName & "</a></li><li><a href=""admin_post.asp?action=add&ChannelID=" & ChannelID & "&classid=" & Request.Form("classid") & """><font color=""blue"">点击此处继续添加" & NewAsp.ModuleName & "</font></a></li>")
End Sub

Sub ModifySoft()
	CheckSave
	If Founderr = True Then Exit Sub
	Call AddUpdateTags(0)
	Dim Auditing
	Dim Rs,SQL,i
	Set Rs = NewAsp.CreateAXObject("ADODB.Recordset")
	SQL = "SELECT * FROM NC_FlashList WHERE flashid=" & NewAsp.ChkNumeric(Request("flashid"))
	Rs.Open SQL,Conn,1,3
		Auditing = Rs("isAccept")
		Rs("ChannelID") = ChannelID
		Rs("classid") = NewAsp.CheckNumeric(Request.Form("classid"))
		Rs("SpecialID") = NewAsp.CheckNumeric(Request.Form("SpecialID"))
		Rs("title") = NewAsp.RequestForm(Request.Form("title"),255)
		Rs("subtitle") = NewAsp.RequestForm(Request.Form("subtitle"),200)
		Rs("ColorMode") = NewAsp.CheckNumeric(Request.Form("ColorMode"))
		Rs("FontMode") = NewAsp.CheckNumeric(Request.Form("FontMode"))
		Rs("Introduce") = TextContent
		Rs("OuterLinks") = NewAsp.RequestForm(Request.Form("OuterLinks"),255)
		Rs("Related") = NewAsp.RequestForm(Request.Form("Related"),255)
		Rs("Describe") = NewAsp.RequestForm(Request.Form("Describe"),255)
		If UCase(Request.Form("SizeUnit")) = "MB" Then
			Rs("filesize") = CLng(NewAsp.CheckNumeric(Request.Form("filesize")) * 1024)
		Else
			Rs("filesize") = NewAsp.CheckNumeric(Request.Form("filesize"))
		End If
		Rs("Author") = Trim(Request.Form("Author"))
		Rs("ComeFrom") = Trim(Request.Form("ComeFrom"))
		Rs("star") = NewAsp.ChkNumeric(Request.Form("star"))
		Rs("miniature") = Trim(Request.Form("miniature"))
		Rs("UserGroup") = NewAsp.ChkNumeric(Request.Form("UserGroup"))
		Rs("PointNum") = NewAsp.ChkNumeric(Request.Form("PointNum"))
		If NewAsp.ChkNumeric(Request.Form("Update")) = 1 Then 
			Rs("addTime") = Now()
		Else
			Rs("addTime") = Formatime(Trim(Request.Form("addTime")))
		End If
		Rs("AllHits") = NewAsp.ChkNumeric(Request.Form("AllHits"))
		Rs("showmode") = NewAsp.ChkNumeric(Request.Form("showmode"))
		Rs("isTop") = NewAsp.ChkNumeric(Request.Form("IsTop"))
		Rs("IsBest") = NewAsp.ChkNumeric(Request.Form("IsBest"))
		Rs("downid") = NewAsp.ChkNumeric(Request.Form("downid"))
		Rs("showurl") = Trim(Request.Form("showurl"))
		Rs("DownAddress") = Trim(Request.Form("DownAddress"))
		Rs("isUpdate") = 1
		Rs("isAccept") = NewAsp.ChkNumeric(Request("isAccept"))
		Rs("ForbidEssay") = NewAsp.ChkNumeric(Request.Form("ForbidEssay"))
		Rs("AlphaIndex") = Newasp.ReadAlpha(AlphaTitle)
		Rs("good") = NewAsp.CheckNumeric(Request.Form("good"))
		Rs("bad") = NewAsp.CheckNumeric(Request.Form("bad"))
		Rs("Taglist")=Taglist
	Rs.update
	flashid = Rs("flashid")
	
	If NewAsp.ChkNumeric(Request("isAccept")) = 1 And Auditing = 0 Then
		AddUserPointNum Rs("username"),1
	End If
	If NewAsp.ChkNumeric(Request("isAccept")) = 0 And Auditing = 1 Then
		AddUserPointNum Rs("username"),0
	End If
	Rs.Close:Set Rs = Nothing
	ClassUpdateCount NewAsp.CheckNumeric(Request.Form("classid")),2
	If CInt(NewAsp.IsCreateHtml) <> 0 Then
		Dim url
		url = "admin_makeshow.asp?ChannelID=" & ChannelID & "&inflashid=" & flashid & "&t=2&u=1"
		Call ScriptCreation(url)
	End If
	Succeed("<li>恭喜您！修改" & NewAsp.ModuleName & "成功。</li><li><a href=""admin_list.asp?action=view&ChannelID=" & ChannelID & "&flashid=" & flashid & """>点击此处查看该" & NewAsp.ModuleName & "</a></li>")
End Sub

Sub CheckSave()
	Dim i
	If Trim(Request.Form("title")) = "" Then
		FoundErr = True
		ErrMsg = ErrMsg + "<li>" & NewAsp.ModuleName & "标题不能为空！</li>"
	Else
		AlphaTitle = ubb.CheckSpecialChar(Trim(Request.Form("title")))
	End If
	If Trim(Request.Form("title")) = "" Then
		FoundErr = True
		ErrMsg = ErrMsg + "<li>" & NewAsp.ModuleName & "名称不能为空！</li>"
	End If
	If Len(Request.Form("title")) => 200 Then
		FoundErr = True
		ErrMsg = ErrMsg + "<li>" & NewAsp.ModuleName & "名称不能超过200个字符！</li>"
	End If
	If Trim(Request.Form("ColorMode")) = "" Then
		FoundErr = True
		ErrMsg = ErrMsg + "<li>标题颜色参数错误！</li>"
	End If
	If Trim(Request.Form("FontMode")) = "" Then
		FoundErr = True
		ErrMsg = ErrMsg + "<li>标题字体参数错误！</li>"
	End If
	If Trim(Request.Form("PointNum")) = "" Then
		FoundErr = True
		ErrMsg = ErrMsg + "<li>下载" & NewAsp.ModuleName & "所需的点数不能为空！如果不想设置请输入零。</li>"
	End If
	If Not IsNumeric(Request.Form("star")) Then
		FoundErr = True
		ErrMsg = ErrMsg + "<li>" & NewAsp.ModuleName & "星级不能为空。</li>"
	End If
	If Not IsNumeric(Request.Form("UserGroup")) Then
		FoundErr = True
		ErrMsg = ErrMsg + "<li>" & NewAsp.ModuleName & "等级参数错误！</li>"
	End If
	If Not IsNumeric(Request.Form("ClassID")) Then
		FoundErr = True
		ErrMsg = ErrMsg + "<li>该一级分类已经有下属分类，不能添加" & NewAsp.ModuleName & "！</li>"
	End If
	If Newasp.ChkNumeric(Request.Form("ClassID")) = 0 Then
		FoundErr = True
		ErrMsg = ErrMsg + "<li>该分类是外部连接，不能添加" & NewAsp.ModuleName & "！</li>"
	End If
	If Trim(Request.Form("filesize")) = "" Then
		Founderr = True
		ErrMsg = ErrMsg + "<li>" & NewAsp.ModuleName & "大小不能为空！</li>"
	End If
	TextContent = ""
	For i = 1 To Request.Form("content").Count
		TextContent = TextContent & Request.Form("content")(i)
	Next
	If Trim(TextContent) = "" Then
		FoundErr = True
		ErrMsg = ErrMsg + "<li>" & NewAsp.ModuleName & "简介不能为空！</li>"
	End If
	If NewAsp.setAdminEditor(0) <> 0 Then
		TextContent = NewAsp.HTMLEncodes(TextContent)
	End If
	TextContent = CheckHtmlCode(Re_Replace(TextContent, InstallDir_ChannelDir, "[InstallDir_ChannelDir]"))
End Sub

Function ClassUpdateCount(sortid,stype)
	Dim rscount,Parentstr
	On Error Resume Next
	Set rscount = NewAsp.Execute("SELECT ClassID,Parentstr FROM [NC_Classify] WHERE ChannelID=" & ChannelID & " And ClassID=" & CLng(sortid))
	If Not (rscount.BOF And rscount.EOF) Then
		Parentstr = rscount("Parentstr") &","& rscount("ClassID")
		If stype = 1 Then
			NewAsp.Execute ("UPDATE [NC_Classify] SET ShowCount=ShowCount+1,isUpdate=1 WHERE ChannelID="& ChannelID &" And ClassID in (" & Parentstr & ")")
		ElseIf stype = 2 Then
			NewAsp.Execute ("UPDATE [NC_Classify] SET isUpdate=1 WHERE ChannelID="& ChannelID &" And ClassID in (" & Parentstr & ")")
		Else
			NewAsp.Execute ("UPDATE [NC_Classify] SET ShowCount=ShowCount-1,isUpdate=1 WHERE ChannelID="& ChannelID &" And ClassID in (" & Parentstr & ")")
		End If
	End If
	Set rscount = Nothing
End Function

Function AddUserPointNum(username,stype)
	On Error Resume Next
	Dim rsuser,GroupSetting,userpoint
	Set rsuser = NewAsp.Execute("SELECT userid,UserGrade,userpoint FROM NC_User WHERE username='"& username &"'")
	If Not(rsuser.BOF And rsuser.EOF) Then
		GroupSetting = Split(NewAsp.UserGroupSetting(rsuser("UserGrade")), "|||")(13)
		If stype = 1 Then
			userpoint = CLng(rsuser("userpoint") + GroupSetting)
			NewAsp.Execute ("UPDATE NC_User SET userpoint="& userpoint &",experience=experience+2,charm=charm+1 WHERE userid="& rsuser("userid"))
		Else
			userpoint = CLng(rsuser("userpoint") - GroupSetting)
			NewAsp.Execute ("UPDATE NC_User SET userpoint="& userpoint &",experience=experience-2,charm=charm-1 WHERE userid="& rsuser("userid"))
		End If
	End If
	Set rsuser = Nothing
End Function

Sub RemoveCache()
	RemoveAppCache "statistic_soft"
	RemoveLabelCache 5
End Sub
%>