<!--#include file="conn.asp"-->
<!-- #include file="inc/const.asp" -->
<!-- #include file="inc/dv_clsother.asp" -->
<!-- #include File="inc/Upload_Class.asp" -->
<!--#include file="Dv_Plus/Avatar/Plus_Avatar_Const.asp"-->
<%
If Request("t")="1" Then
	Upfile_Main()
Else
	Main()
End If

Sub Main()
	Dvbbs.Loadtemplates("")
	Dvbbs.Head()
	Dvbbs.ShowErr
%>
<script>
if (parent.location==self.location){
	parent.location="index.asp"
}
</script>
<table border=0 cellspacing=0 cellpadding=0 style="width:100%;height:100%">
<form name="form" method="post" action="Plus_Avatar_upload.asp?t=1" enctype="multipart/form-data">
<tr>
<%
If Cint(Dvbbs.Groupsetting(7))=0 Then
	Response.Write "<TD class=tablebody2 valign=top>您没有在本论坛上传文件的权限!</td>"
Else
	Dim PostRanNum
	Randomize
	PostRanNum = Int(900*rnd)+1000
	Session("AvatarUploadCode") = Cstr(PostRanNum)
%>
<INPUT TYPE="hidden" NAME="AvatarUploadCode" value="<%=PostRanNum%>">
<TD id="upid" class=tablebody2 valign=top><input type="file" name="file1" width=200 value="" size="40"><input type="submit" name="Submit" value="上传" onclick="parent.document.getElementById('Submit').disabled=true;parent.document.getElementById('Clear').disabled=true;"></td>
<%end if%>
</tr>
</form>
</table>
</body>
</html>
<%
End Sub

Sub Upfile_Main()
	Dvbbs.Loadtemplates("")
	Dvbbs.Head()
	Dvbbs.ShowErr()
	Server.ScriptTimeOut=999999'要是你的论坛支持上传的文件比较大，就必须设置。
	If Not Dvbbs.ChkPost Then
		Response.End
	End If
	If Dvbbs.Userid=0 Then
		Response.write "你还未登陆！"
		Response.End
	End If
	If Cint(Dvbbs.GroupSetting(7))=0 then
		Response.write "您没有在本论坛上传文件的权限"
		Response.End
	End If
%>
	<script>
	parent.document.getElementById('Submit').disabled=false;
	parent.document.getElementById('Clear').disabled=false;
	</script>
	<table width="100%" height="100%" border=0 cellspacing=0 cellpadding=0>
	<tr><td class=tablebody2 height=24><%UploadFile%></td></tr>
	</table>
</body>
</html>
<%End Sub

Sub UploadFile()
	Dim Upload,FormName,FilePath
	Dim File,F_FileName,F_ViewName,F_Filesize,F_FileExt,F_Type
	Dim InceptMaxFile,TotalAmount,CurAmount, CanUploadSize

	'删除原有之尚未使用的背景
	Call DelOldBg()
	
	'上传目录
	FilePath = CheckFolder

	Set Upload = New UpFile_Cls
	Upload.UploadType = Cint(Dvbbs.Forum_UploadSetting(2))         '设置上传组件类型
	Upload.UploadPath = FilePath                                   '设置上传路径
	Upload.InceptFileType = "gif,jpg,jpeg,png"                     '设置上传文件限制
	If v_MyVip <> 1 Then
		CanUploadSize = v_MyMoney \ CLng(AvatarXMLDOM.documentElement.selectSingleNode("AvatarInfo").attributes.getNamedItem("NormalUploadPrice").Text)
	Else
		CanUploadSize = v_MyMoney \ CLng(AvatarXMLDOM.documentElement.selectSingleNode("AvatarInfo").attributes.getNamedItem("VIPUploadPrice").Text)
	End If
	If CanUploadSize < CLng(AvatarXMLDOM.documentElement.selectSingleNode("AvatarInfo").attributes.getNamedItem("PhotoBgSize").Text) Then
		Upload.MaxSize = CanUploadSize
	Else
		Upload.MaxSize = CLng(AvatarXMLDOM.documentElement.selectSingleNode("AvatarInfo").attributes.getNamedItem("PhotoBgSize").Text)
	End If
	Upload.InceptMaxFile = 1                                       '每次上传文件个数上限
	If Dvbbs.UserID <> 0 Then Upload.RName = Dvbbs.UserID & "_"
	Upload.ChkSessionName = "AvatarUploadCode"                     '防止重复提交，SESSION名与提交的表单要一致。

	'执行上传
	Upload.SaveUpFile
	TotalAmount = 0
	For Each FormName In Upload.UploadFiles
		Set File = Upload.UploadFiles(FormName)
		If v_MyVip <> 1 Then
			CurAmount = (File.FileSize + 1023) \ 1024 * CLng(AvatarXMLDOM.documentElement.selectSingleNode("AvatarInfo").attributes.getNamedItem("NormalUploadPrice").Text)
		Else
			CurAmount = (File.FileSize + 1023) \ 1024 * CLng(AvatarXMLDOM.documentElement.selectSingleNode("AvatarInfo").attributes.getNamedItem("VIPUploadPrice").Text)
		End IF
		TotalAmount = TotalAmount + CurAmount
		Set File = Nothing
	Next
	If Upload.ErrCodes=4 Then
		If CanUploadSize < CLng(AvatarXMLDOM.documentElement.selectSingleNode("AvatarInfo").attributes.getNamedItem("PhotoBgSize").Text) Then
			Response.Write "错误：上传需要" & TotalAmount & "元，您的现金不足 [ <a href=""Plus_Avatar_Upload.asp"">重新上传</a> ]"
		Else
			Response.write "错误：图片大小超出了上传背景的限制 [ <a href=""Plus_Avatar_Upload.asp"">重新上传</a> ]"
		End If
		Exit Sub
	ElseIf Upload.ErrCodes<>0 Then
		Response.write "错误："& Upload.Description & "[ <a href=""Plus_Avatar_Upload.asp"">重新上传</a> ]"
		Exit Sub
	End If
	If Upload.Count > 0 Then
		For Each FormName In Upload.UploadFiles
			Set File = Upload.UploadFiles(FormName)
			SetUploadBg File.FileName, v_MyMoney - TotalAmount
			Set File = Nothing
		Next
	Else
		Response.write "请正确选择要上传的文件。[ <a href=""Plus_Avatar_Upload.asp"">重新上传</a> ]"
		Exit Sub
	End If
	Call UpdateUserWealth(Dvbbs.MemberName, -TotalAmount)
	Call Suc_upload(Upload.Count)
	Set Upload = Nothing
End Sub

Sub DelOldBg()
	'On Error Resume Next
	'Dim objFSO, OldUserBg
	'OldUserBg = Server.MapPath(CheckFolder & Dvbbs.UserID & "_") & "*.*"
	'Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'	
'		objFSO.DeleteFile OldUserBg
'		If Err<>0 Then Err.Clear
'	Set objFSO = Nothing
End Sub

Sub SetUploadBg(FileName, CurMyMoney)
	Response.write "<script>parent.SetUploadBg('" & FileName & "','" & CurMyMoney & "');</script>"
End Sub

Sub Suc_upload(UpCount)
	Response.write UpCount & "个文件上传成功！ [ <a href=""Plus_Avatar_Upload.asp"">继续上传</a> ]"
End Sub

Function CheckFolder()
	CheckFolder = Replace(AvatarXMLDOM.documentElement.selectSingleNode("AvatarInfo").attributes.getNamedItem("PhotoPath").Text,Chr(0),"")
	If Right(CheckFolder,1)<>"/" Then CheckFolder=CheckFolder&"/"
End Function
%>