<!-- #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 -->
<%
Dim TempStr
If DEF_FSOString = "" Then Response.End
If DEF_EnableUpload = 0 Then Response.End
If DEF_EnableDotNetUpload <> 2 Then Response.End%>
<script language=javascript>
<!--

	function addcontent(tmpstr)
	{
		parent.document.LeadBBSFm.Form_Content.value = parent.document.LeadBBSFm.Form_Content.value + tmpstr;
	}

//-->
</script>
<%
GBL_UploadFlag = 1
Rem 缩小图像模式,0-缩小到预定宽或高,1,如果大于预定宽或高则成倍缩小
Const DEF_ResizeMode = 1
initDatabase
If GBL_UserID < 1 Then
	CloseDatabase
	Response.End
End If
If DEF_EnableUpload = 2 Then
	If GBL_UserID<1 or CheckSupervisorUserName = 0 Then
		CloseDatabase
		Response.End
	End If
End If

SiteHead("   ")

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
	'Response.Write GBL_CHK_TempStr
	CloseDatabase
	Response.End
End If%>
<body bgcolor=<%=DEF_BBS_LightestColor%> leftmargin="0" topmargin="0" class=TBBGbody>
<%
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


Function SaveUploadFile

	uploadfilenow
	
	If CheckSupervisorUserName = 0 Then
		Con.ExeCute("Update LeadBBS_User Set LastWriteTime=" & GetTimeValue(now) & " where ID=" & GBL_UserID)
	End If
	Response.Write "<img sc=../images/blank.gif height=6 width=1><br><a href=uploadFile1.asp>" & TempStr & "</a>"

End Function


function getfilenameloop(name)

	Dim fs
	Set fs = CreateObject(DEF_FSOString)
	dim tempname,n,extendFileName
	name = Lcase(name)
	tempname = name
	name = "1" & Mid(name,inStrRev(name,"."))
	extendFileName = Mid(name,inStrRev(name,"."))
	n=0
	dim tdir
	tdir=server.mappath(PhotoDirectory) & "\"
	if Not fs.FolderExists(tdir) then
		getfilenameloop = 0
		TempStr = TempStr & "错误，存放图标的目录不存在，请联系网站中心！<br>" & VbCrLf
		'fs.CreateFolder(tdir)
	end if
	
	tdir = tdir & year(date) & "\"
	UploadPhotoUrl = UploadPhotoUrl & year(date) & "/"
	If Not fs.FolderExists(tdir) then
		fs.CreateFolder(tdir)
	End If

	tdir = tdir & right("0" & month(date),2) & "\"
	UploadPhotoUrl = UploadPhotoUrl & right("0" & month(date),2) & "/"
	if Not fs.FolderExists(tdir) then
		fs.CreateFolder(tdir)
	end if
	
	tdir = tdir & right("0" & day(date),2) & "\"
	UploadPhotoUrl = UploadPhotoUrl & right("0" & day(date),2) & "/"
	if Not fs.FolderExists(tdir) then
		fs.CreateFolder(tdir)
	end if
	
	PhotoDir = tdir

	Dim TempNum,Temp
	
	TempNum = right(GetTimeValue(now),6)
	
	getfilenameloop = TempNum & extendFileName
	pic_name2 = TempNum & "s" & extendFileName

	if fs.FileExists(tdir & getfilenameloop) then
		for Temp = 0 to 99
			getfilenameloop = TempNum & "_" & Temp & extendFileName
			pic_name2 = TempNum & "_" & Temp & "s" & extendFileName
			if fs.FileExists(tdir & getfilenameloop) then
			Else
				set fs = nothing
				Exit Function
			End If
		Next
		'delphotofromharddisk(stemp)
		'TempStr =  TempStr &  "错误！目标文件已经存在，请重新刷新一次！<br>" & VbCrLf
		set fs = nothing
	else
		set fs = nothing
	end if

end function

dim fileup,pic_name1,pic_name,PhotoDir,pic_name2,UploadPhotoUrl2

function uploadfilenow

	Dim NewFileName
	'on error resume next
	Dim iCount,formPath,formName,file,FileExt

	set fileup=new UpFile_Class ''建立上传对象
	If CheckSupervisorUserName = 1 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 "请先选择你要上传的文件　[ <a href=#3234 onclick=history.go(-1)>重新上传</a> ]"
			case 2
					Response.Write "图片大小超过了限制 " & DEF_FileMaxBytes & "K　[ <a href=# onclick=history.go(-1)>重新上传</a> ]"
		end select
		exit function
	Else
		For each formName in fileup.file ''列出所有上传了的文件
			set file=fileup.file(formName)  ''生成一个文件对象
			if file.filesize<1 then
				response.write "请先选择你要上传的文件　[ <a href=#s334 onclick=history.go(-1)>重新上传</a> ]"
				response.end
	 		end if
	
	 		NewFileName="." & lcase(file.FileExt)
			if inStr(":.ra:.ram:.rm:.asf:.wma:.jpg:.gif:.jpeg:.jpe:.png:.zip:.rar:.bmp:.mp3:.swf:.wav:.txt:.doc:.rtf:.exe:.psd:.tif:.mid:.sgi:.tga:.iff:.pcx:.dcx:.pbm:.pgm:.ppm:.pnm:.miff:.xbm:.xpm:.ico:.icl:.emf:.hru:.jif:.prc:.wrl:.wbmp:.mpeg:",":" & NewFileName & ":") = 0 then
	 			response.write "文件格式不正确　[ <a href=#3333 onclick=history.go(-1)>重新上传</a> ]"
				response.end
			end if
	
			pic_name1=getfilenameloop(NewFileName)
			UploadPhotoUrl2 = UploadPhotoUrl & pic_name2
			UploadPhotoUrl = UploadPhotoUrl & pic_name1
			pic_name = pic_name1
			
			if file.FileSize>0 then         ''如果 FileSize > 0 说明有文件数据
				file.SaveToFile PhotoDir & pic_name   ''保存文件
			end if
			Set File = Nothing
		Next
		Set Fileup = Nothing
	End If
	%>
	<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 Then
		CheckUploadDatabase UploadPhotoUrl,UploadPhotoUrl2
	Else
		CheckUploadDatabase UploadPhotoUrl,""
	End if%>

	//-->
	</script>
	<p>文件上传成功,要<a href=uploadFile1.asp>继续上传请点这里</a>
	<%

end function

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;
		}
		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=uploadFile1.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]
			<br>
	</td>
	</tr>
	</form>
	</table>

<%End Function%>