<!-- #include file=../inc/BBSsetup.asp -->
<!-- #include file=../inc/Board_Popfun.asp -->
<!-- #include file=../inc/Limit_fun.asp -->
<%DEF_BBS_HomeUrl = "../"%>
<!-- #include file=../inc/Upload_Fun.asp -->
<!-- #include file=inc/upload1_fun.asp -->
<%
If DEF_EnableUpload = 0 Then Response.End

Dim TempStr
%>
<script language=javascript>
<!--

	function addcontent(tmpstr)
	{
		if(parent.EFlag == 1)
		{parent.document.LeadBBSFm.Form_Content.value = parent.document.LeadBBSFm.Form_Content.value + tmpstr;}
		else
		{
			var re = /(\n)/gi;
			tmpstr = tmpstr.replace(re,"<br>");
			parent.insertHTML2(tmpstr);
		}
	}

//-->
</script>
<%
GBL_UploadFlag = 1
Rem 缩小图像模式,0-缩小到预定宽或高,1,如果大于预定宽或高则成倍缩小
Const DEF_ResizeMode = 1
initDatabase

SiteHead("   ")
%>
<body bgcolor=<%=DEF_BBS_LightestColor%> leftmargin="0" topmargin="0" class=TBBG9>
<%
CheckUploadEnable

%>
<body bgcolor=<%=DEF_BBS_LightestColor%> leftmargin="0" topmargin="0" class=TBBG9>
<%

If Request.QueryString("submitflag") = "" Then
	photoUpformFunction
Else
	If GBL_CHK_LastWriteTime < DEF_WriteEventSpace*5 Then
		Response.Write "<b><font color=Red Class=RedFont>您的操作太频，请稍候再上传!</font></b> <br>" & VbCrLf
		CloseDatabase
		Response.End
	End If
	SaveUploadFile
End If%>
</body>
</html>
<%
CloseDatabase

Sub CheckUploadEnable

	If GBL_UserID < 1 Then
		CloseDatabase
		Response.End
	End If

	Dim N

	N = 1
	If GBL_UserID < 1 Then N = 0
	CheckisBoardMaster
	Select Case DEF_EnableUpload
		Case 0: N = 0
		case 2: If CheckSupervisorUserName = 0 Then N = 0
		Case 3: If GBL_BoardMasterFlag < 4 Then N = 0
		Case 4: If GetBinarybit(GBL_CHK_UserLimit,2) = 0 Then N = 0
		Case 5: If GBL_BoardMasterFlag < 4 and GetBinarybit(GBL_CHK_UserLimit,2) = 0 Then N = 0
	End Select
	If N = 1 and (GBL_CHK_OnlineTime >= DEF_NeedOnlineTime or DEF_NeedOnlineTime = 0) Then
	Else
		CloseDatabase
		Response.End
	End If

	If CheckUserAnnounceLimit = 0 Then
		Response.Write GBL_CHK_TempStr
		CloseDatabase
		Response.End
	End If

	GBL_CHK_TempStr = ""
	CheckisBoardMaster
	CheckAccessLimit
	CheckAccessLimit_TimeLimit
	If GBL_CHK_OnlineTime < DEF_NeedOnlineTime and DEF_NeedOnlineTime > 0 and CheckSupervisorUserName = 0 Then
		GBL_CHK_TempStr = "论坛限制在线时间(经验)" & Fix(DEF_NeedOnlineTime/60) & "分钟以上用户才能发言。<br>" & VbCrLf
	End If

	If GBL_CHK_TempStr <> "" Then
		CloseDatabase
		Response.End
	End If

	If DEF_UploadSpendPoints > 0 and DEF_UploadSpendPoints > GBL_CHK_Points Then
		Response.Write DEF_PointsName & "值不足，上传附件需要花费" & DEF_PointsName & DEF_UploadSpendPoints & "！"
		CloseDatabase
		Response.End
	End If

	If DEF_UploadOneDayMaxNum > 0 Then
		Dim Rs,Num
		Num = 0
		Set Rs = Con.ExeCute("Select top " & DEF_UploadOneDayMaxNum & " NdateTime from LeadBBS_Upload where UserID=" & GBL_UserID & " order by id DESC")
		If Not Rs.Eof Then
			Do While Not Rs.Eof and Num < DEF_UploadOneDayMaxNum - 1
				Num = Num + 1
				Rs.MoveNext
			Loop
			If Not Rs.Eof Then
				Num = RestoreTime(Rs(0))
				If Year(Num) = Year(DEF_Now) and Month(Num) = Month(DEF_Now) and Day(Num) = Day(DEF_Now) Then
					Response.Write "<img src=../images/null.gif width=2 height=5><br>无法再上传附件，每天最多可传" & DEF_UploadOneDayMaxNum & "个附件！"
					CloseDatabase
					Response.End
				End If
			End If
		End If
		Rs.Close
		Set Rs = Nothing
	End If

End Sub

Function photoUpformFunction

	%>
	<script language=JavaScript>
	<!--
	ValidationPassed = true;
	function visagePhotoForm_onsubmit(obj)
	{
		ValidationPassed = true;
		if(obj.photo.value =="")
		{
			alert("请点击浏览按钮选择要上传的文件!\n");
			ValidationPassed = false;
			obj.photo.focus();
			return;
		}
		if(parent.EFlag == 0)
		{
			if (!parent.validateMode()){
				ValidationPassed = false;
				return;
			}
		}
		ValidationPassed = true;
		return true;
	}

	function submitonce(theform)
	{
		if(ValidationPassed == false)return;
		if (document.all||document.getElementById)
		{
			for (i=0;i<theform.length;i++)
			{
				var tempobj=theform.elements[i];
				if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
				tempobj.disabled=true;
			}
		}
	}
	-->
	</script>
	<table cellspacing=1 cellpadding=0 width="100%" border=0 valign=absmiddle height=100%>
	<tbody>
	<form method=POST action=uploadFile.asp?submitflag=yes&dontRequestFormFlag=<%="Guest" & Second(time) & hour(time) & minute(time)%>&BoardID=<%=GBL_Board_ID%> name=visagePhotoForm enctype=multipart/form-data onSubmit="submitonce(this);return ValidationPassed;">
	<tr>
		<td valign=absmiddle align=absmiddle>
			<input type=file name=photo class=fminpt>
			<input type=submit value=上传 name=send onclick="visagePhotoForm_onsubmit(this.form)" class=fmbtn> [限制：<%=int(DEF_FileMaxBytes/1024)%>K<%
			If DEF_UploadOneDayMaxNum > 0 Then Response.Write "，每天" & DEF_UploadOneDayMaxNum & "个"%>]
			<br>
	</td>
	</tr>
	</form>
	</table>

<%End Function

Function SaveUploadFile

	UploadFileNow

	If CheckSupervisorUserName = 0 Then
		Con.ExeCute("Update LeadBBS_User Set LastWriteTime=" & GetTimeValue(DEF_Now) & " where ID=" & GBL_UserID)
		GBL_DBNum = GBL_DBNum + 1
		UpdateSessionValue 13,GetTimeValue(DEF_Now),0
	End If
	Response.Write "<p><img sc=../images/blank.gif height=6 width=1><br><a href=uploadFile.asp>" & TempStr & "</a>"

End Function

Function GetSaveFileName(name)

	Dim ExtendFileName,TempNum,Temp
	name = Lcase(name)
	name = "1" & Mid(name,inStrRev(name,"."))
	ExtendFileName = Mid(name,inStrRev(name,"."))
	TempNum = Right(GetTimeValue(DEF_Now),6)

	GetSaveFileName = TempNum & ExtendFileName
	Pic_Name2 = TempNum & "s" & ExtendFileName
	
	On Error Resume Next
	Dim FSFlag
	FSFlag = 1
	If DEF_FSOString <> "" Then
		Set fs = Server.CreateObject(DEF_FSOString)
		If Err Then
			FSFlag = 0
			Err.Clear
			Set fs = Nothing
		End If
	Else
		FSFlag = 0
	End If

	If FSFlag = 0 Then
		Err.Clear
		GetSaveFileName = Left(GetTimeValue(DEF_Now),8) & GetSaveFileName
		Pic_Name2 = Left(GetTimeValue(DEF_Now),8) & Pic_Name2
		PhotoDir = Server.MapPath(PhotoDirectory) & "\"
		Set Fs = Nothing
		Exit Function
	End If

	Dim TDir,FS
	TDir = Server.MapPath(PhotoDirectory) & "\"
	If Not FS.FolderExists(TDir) then
		GetSaveFileName = 0
		TempStr = TempStr & "<img src=../images/null.gif width=2 height=5><br>&nbsp;错误，存放图标的目录不存在，请联系网站中心！<br>" & VbCrLf
	End If
	
	TDir = TDir & year(DEF_Now) & "\"
	UploadPhotoUrl = UploadPhotoUrl & year(DEF_Now) & "/"
	If Not FS.FolderExists(TDir) then
		FS.CreateFolder(TDir)
	End If

	TDir = TDir & Right("0" & month(DEF_Now),2) & "\"
	UploadPhotoUrl = UploadPhotoUrl & Right("0" & month(DEF_Now),2) & "/"
	If Not FS.FolderExists(TDir) then
		FS.CreateFolder(TDir)
	End If
	
	TDir = TDir & Right("0" & day(DEF_Now),2) & "\"
	UploadPhotoUrl = UploadPhotoUrl & Right("0" & day(DEF_Now),2) & "/"
	If Not FS.FolderExists(TDir) then
		FS.CreateFolder(TDir)
	End If
	
	PhotoDir = TDir

	If FS.FileExists(TDir & GetSaveFileName) then
		For Temp = 0 To 99
			GetSaveFileName = TempNum & "_" & Temp & ExtendFileName
			Pic_Name2 = TempNum & "_" & Temp & "s" & ExtendFileName
			If FS.FileExists(TDir & GetSaveFileName) then
			Else
				Set FS = Nothing
				Exit For
			End If
		Next
		Set FS = Nothing
	Else
		Set FS = Nothing
	End If

End Function

Dim FileUp,Pic_Name1,Pic_Name,PhotoDir,Pic_Name2,UploadPhotoUrl2,NewFileName

Function Upload_FileUp

	'On Error Resume Next
	Set FileUp = server.createobject("FileUp.upload")
	If Err Then
		TempStr = TempStr & "<img src=../images/null.gif width=2 height=5><br>&nbsp;请后退再重新提交表单一次，如果多次重试仍未成功，请联系管理员，可能未安装此组件！<br>" & VbCrLf
		Err.Clear
		CloseDatabase
		Response.End
	End If

	NewFileName = FileUp.UserFilename
	If Instr(NewFileName,"\") or inStr(NewFileName,"/") Then
		NewFileName = LCase(Mid(NewFileName,InstrRev(Replace(NewFileName & "","/","\"), "\") + 1))
	End If
		
	If inStr(NewFileName,".") = 0 Then
		TempStr = TempStr & "<img src=../images/null.gif width=2 height=5><br>&nbsp;没有正确地选择要上传的文件, 注意上传的文件格式!"
		CloseDatabase
		Response.End
	End If

	Pic_Name1 = GetSaveFileName(NewFileName)
	UploadPhotoUrl2 = UploadPhotoUrl & Pic_Name2
	UploadPhotoUrl = UploadPhotoUrl & Pic_Name1
	If FileUp.FileFound(server.mappath(NewFileName)) = False then
		If inStr(DEF_UploadFileType,":" & Mid(NewFileName,InstrRev(NewFileName, ".")) & ":") Then
				Pic_Name = Pic_Name1
				FileUp.SaveAs PhotoDir & Pic_Name
				If err Then
					Set FileUp = Nothing
					TempStr = TempStr & "<img src=../images/null.gif width=2 height=5><br>&nbsp;上传错误,请正确选择上传文件.<br>" & VbCrLf
					err.clear
					CloseDatabase
					Response.End
				End If

				If FileUp.TotalBytes <> 0 then
				Else
						TempStr =  TempStr &  "<img src=../images/null.gif width=2 height=5><br>&nbsp;提示：文件内容为空，可能是此文件不存在! 上传失败！请重新上传。<br>" & VbCrLf
						CloseDatabase
						Response.End
				End If

				If FileUp.TotalBytes > DEF_FileMaxBytes then	
					TempStr =  TempStr & "<img src=../images/null.gif width=2 height=5><br>&nbsp;上传文件太大，超过了" & CLng(DEF_FileMaxBytes/1024) & "K!<br>" & VbCrLf
					CloseDatabase
					Response.End
				End If
		Else
			TempStr =  TempStr &  "<img src=../images/null.gif width=2 height=5><br>&nbsp;提示：文件类型错误，请选择正确类型的文件重新上传！<br>" & VbCrLf
			CloseDatabase
			Response.End
		End If
	Else
		TempStr =  TempStr &  "<img src=../images/null.gif width=2 height=5><br>&nbsp;提示：该文件已经存在，不能覆盖！<br>" & VbCrLf
		CloseDatabase
		Response.End
	End If
	Set FileUp = Nothing

End Function

Function Upload_NoComponent

	'On Error Resume Next
	Dim formName,file

	set FileUp = new UpFile_Class
	If (CheckSupervisorUserName = 1 or GBL_CHK_User = "Angel") and DEF_FileMaxBytes < 1024000 Then
		FileUp.GetData (1024*1000)
	Else
		FileUp.GetData (DEF_FileMaxBytes)
	End If

	If FileUp.err > 0 then
	    Select Case FileUp.err
			Case 1
					Response.Write "<img src=../images/null.gif width=2 height=5><br>&nbsp;请先选择你要上传的文件　[ <a href=#3234 onclick=history.go(-1)>重新上传</a> ]"
			Case 2
					Response.Write "<img src=../images/null.gif width=2 height=5><br>&nbsp;文件大小超过了限制 " & DEF_FileMaxBytes & "K　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
		End Select
		CloseDatabase
		Response.End
	Else
		For Each formName in FileUp.file ''列出所有上传了的文件
			Set file = FileUp.file(formName)  ''生成一个文件对象
			If file.filesize<1 then
				Response.write "<img src=../images/null.gif width=2 height=5><br>&nbsp;请先选择你要上传的文件　[ <a href=#s334 onclick=history.go(-1)>重新上传</a> ]"
				CloseDatabase
				Response.End
	 		End if
	
	 		NewFileName="." & LCase(file.FileExt)
			If inStr(DEF_UploadFileType,":" & NewFileName & ":") = 0 then
	 			Response.Write "<img src=../images/null.gif width=2 height=5><br>&nbsp;文件格式不正确　[ <a href=#3333 onclick=history.go(-1)>重新上传</a> ]"
	 			CloseDatabase
				Response.End
			End If

			Pic_Name1 = GetSaveFileName(NewFileName)
			UploadPhotoUrl2 = UploadPhotoUrl & Pic_Name2
			UploadPhotoUrl = UploadPhotoUrl & Pic_Name1
			Pic_Name = Pic_Name1

			If file.FileSize>0 then
				file.SaveToFile PhotoDir & Pic_Name
			End If
			Set File = Nothing
		Next
		Set FileUp = Nothing
	End If

End Function

Function UploadFileNow

	If DEF_EnableDotNetUpload = 2 Then
		Upload_NoComponent
	Else
		Upload_FileUp
	End If
	If TempStr <> "" Then Exit Function%>
	<script language=javascript>
	<!--
	<%
	Dim HeadStr,Temp,Old_Pic_Name
	Old_Pic_Name = Pic_Name
	If inStrRev(Pic_Name,".")>0 Then Pic_Name = Mid(Pic_Name,inStrRev(Pic_Name,".")+1)
	
	HeadStr = "\n[img]../images/fileType/"  & Replace(Pic_Name,".","") & ".gif[/img]"
	Temp = 0
	If DEF_EnableGFL = 1 Then
		If DEF_EnableImagesUBB = 1 and inStr(":jpg:gif:jpeg:jpe:png:bmp:psd:tif:sgi:tga:iff:pcx:dcx:pbm:pgm:ppm:pnm:miff:xbm:xpm:ico:icl:emf:hru:jif:prc:wrl:wbmp:",Pic_Name) > 0 Then
			Temp = SaveSmallPic(PhotoDir & Old_Pic_Name,PhotoDir & Pic_Name2,570,5700)
			If Temp = 4 Then
				If inStrRev(UploadPhotoUrl2,".")>0 Then
					UploadPhotoUrl2 = Left(UploadPhotoUrl2,inStrRev(UploadPhotoUrl2,".")) & "jpg"
				Else
					UploadPhotoUrl2 = UploadPhotoUrl2 & "jpg"
				End if
			ElseIf Temp = 3 Then
				If inStrRev(UploadPhotoUrl2,".")>0 Then
					UploadPhotoUrl2 = Left(UploadPhotoUrl2,inStrRev(UploadPhotoUrl2,".")) & "gif"
				Else
					UploadPhotoUrl2 = UploadPhotoUrl2 & "gif"
				End if
			Else
				If Temp = 1 Then
					If inStrRev(UploadPhotoUrl2,".")>0 Then
						UploadPhotoUrl2 = Left(UploadPhotoUrl2,inStrRev(UploadPhotoUrl2,".")) & "jpg"
					Else
						UploadPhotoUrl2 = UploadPhotoUrl2 & "jpg"
					End if
				End If
			End If
			If Temp = 1 or Temp = 3 or Temp = 4 Then
				Response.Write "addcontent(""" & HeadStr & "此主题相关图片\n[url=" & htmlencode(UploadPhotoUrl) & "][img]" & htmlencode(UploadPhotoUrl2) & "[/img][/url]\n"");"
			Else
				If Temp = 2 Then
					Response.Write "addcontent(""" & HeadStr & "此主题相关图片\n[imga]" & htmlencode(UploadPhotoUrl) & "[/imga]\n"");"
				Else
					Response.Write "addcontent(""" & HeadStr & "此主题相关文件 [url=" & htmlencode(UploadPhotoUrl) & "]" & Pic_Name1 & "[/url]\n"");"
				End If
			End If
		ElseIf Pic_Name="swf" and DEF_EnableFlashUBB =  1 Then
			Response.Write "addcontent(""[flash]" & htmlencode(UploadPhotoUrl) & "[/flash]\n"");"
		ElseIf (Pic_Name="mp3" or Pic_Name="mid" or Pic_Name="asf" or Pic_Name="wma" or Pic_Name="wav") and DEF_EnableFlashUBB =  1 Then
			Response.Write "addcontent(""[mp=320,240]" & htmlencode(UploadPhotoUrl) & "[/mp]\n"");"
		ElseIf (Pic_Name="ra" or Pic_Name="ram" or Pic_Name="rm") and DEF_EnableFlashUBB =  1 Then
			Response.Write "addcontent(""[rm=320,240]" & htmlencode(UploadPhotoUrl) & "[/rm]\n"");"
		Else
			Response.Write "addcontent(""" & HeadStr & "此主题相关文件 [url=" & htmlencode(UploadPhotoUrl) & "]" & Pic_Name1 & "[/url]\n"");"
		End If
	Else
		If (Pic_Name = "gif" or Pic_Name = "jpg" or Pic_Name = "jpeg" or Pic_Name = "jpe" or Pic_Name = "bmp" or Pic_Name = "png") and DEF_EnableImagesUBB = 1 Then
			Response.Write "addcontent(""" & HeadStr & "此主题相关图片\n[imga]" & htmlencode(UploadPhotoUrl) & "[/imga]\n"");"
		ElseIf Pic_Name="swf" and DEF_EnableFlashUBB =  1 Then
			Response.Write "addcontent(""[flash]" & htmlencode(UploadPhotoUrl) & "[/flash]\n"");"
		ElseIf (Pic_Name="mp3" or Pic_Name="mid" or Pic_Name="asf" or Pic_Name="wma" or Pic_Name="wav") and DEF_EnableFlashUBB =  1 Then
			Response.Write "addcontent(""[mp=320,240]" & htmlencode(UploadPhotoUrl) & "[/mp]\n"");"
		ElseIf (Pic_Name="ra" or Pic_Name="ram" or Pic_Name="rm") and DEF_EnableFlashUBB =  1 Then
			Response.Write "addcontent(""[rm=320,240]" & htmlencode(UploadPhotoUrl) & "[/rm]\n"");"
		Else
			Response.Write "addcontent(""" & HeadStr & "此主题相关文件 [url=" & htmlencode(UploadPhotoUrl) & "]" & Pic_Name1 & "[/url]\n"");"
		End If
	End If
	
	If Temp = 1 or Temp = 3 or Temp = 4 Then
		CheckUploadDatabase UploadPhotoUrl,UploadPhotoUrl2
	Else
		CheckUploadDatabase UploadPhotoUrl,""
	End if%>

	//-->
	</script>
	<p><img src=../images/null.gif width=2 height=5><br>&nbsp;文件上传成功,要<a href=uploadFile.asp>继续上传请点这里</a>
	<%

End Function%>