<%@language=vbscript codepage=936 %>
<!--#include file="../Conn.asp"-->
<!--#include file="../Inc/Cl_ClsSysTem.asp"-->
<!--#include file="../Inc/Cl_ClsUpfile.asp"-->
<%
if Not Cl.ChkUserLogin then
	Response.write "<font color=red>您未登录，或者从外部提交信息，操作已被禁止。</font>"
	Response.end
end if
Cl.Page_Admin	= True
Cl.GetWeb_Setting
Dim sTrSetting,strJs
Dim IsReName,IsAutoSort
Dim sTrFilePath,InceptType,InceptMaxSize
Dim ModuleID,ChannelID,UpFileType
Dim Upload,FormName,FilePath,ChildFilePath
Dim File,F_FileName,F_ViewName,F_Filesize,F_FileExt,F_Type
Dim Previewpath,DrawInfo,InceptMaxFile
Dim IsTrueUpfiles,ComeUrl
Dim JsObjName,JsObjName2,JsTempObjName
Dim sProgressID
IsTrueUpfiles=0:IsReName=1:IsAutoSort=1  '默认
if Cl.Upload_Setting(1)="999" then
	Response.write "<font color=red>系统未开放文件上传功能</font>"
	Response.end
end if
%>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
BODY{BACKGROUND-COLOR: #def0fa;font-size:9pt;}
INPUT {FONT-SIZE: 12px;HEIGHT: 20px;}
-->
</style>
<script language=javascript>
function SaveFilesUrl(sModuleID,type,arr,objname,objname2){
	if(objname!=''){
		//alert("OK!");
		var obj = parent.document.getElementById(objname);
		var strT=arr.split('|');
		if (sModuleID=='2'&&type=='3'){
			if (parent.document.getElementById('UseServer').checked==true){
			obj.value=strT[0];}
			else{
			var url='下载地址'+(obj.length+1)+'|'+strT[0];
			obj.options[obj.length]=new Option(url,url);}
		}
		else if (sModuleID=='3'&&type=='4'){
			var url='图片地址'+(obj.length+1)+'|'+strT[0];
			obj.options[obj.length]=new Option(url,url);
		}
		else if (sModuleID=='4'&&type=='2'){
			var url='影片地址'+(obj.length+1)+'|'+strT[0];
			obj.options[obj.length]=new Option(url,url);
		}
		else if (sModuleID=='5'&&type=='3'){
			var url='下载地址'+(obj.length+1)+'|'+strT[0];
			obj.options[obj.length]=new Option(url,url);
		}
		else {
			obj.value=strT[0];
		}
		if (objname2!='') {parent.document.getElementById(objname2).value=strT[1];}
	}
}
function AddUploadFiles(objname,files,filesv){
	if(objname!=''){
		//alert("OK!");
		var obj = parent.document.getElementById(objname);
		obj.options[obj.length]=new Option(filesv,files);
	}
}
</script>
</head>
<body leftmargin="0" topmargin="2" marginwidth="0" marginheight="0">
<%
if Request("Action")="P" then
	call Upfile_Main()
else
	Call UpLoad_Main()
end if
%>
</body>
</html>
<%
Sub UpLoad_Main()
	Dim PostRanNum,cID,sType,sObj,sObj2,sTObj
	Dim UploadProgress,sPID,Barref
	cID=Cl.ChkClng(request.QueryString("ID"))
	sType=Trim(request.QueryString("Type"))
	sObj=Trim(request.QueryString("Obj"))
	sObj2=Trim(request.QueryString("Obj2"))
	sTObj=Trim(request.QueryString("TObj"))
	Randomize
	PostRanNum = Int(900*rnd)+1000
	Session("UpCode_" & cID & sType & sObj) = Cstr(PostRanNum)

	Response.write "<script language=javascript>" & vbcrlf
	Response.write "function check() " & vbcrlf
	Response.write "{" & vbcrlf
	Response.write "	var strFileName=document.form1.FileName.value;" & vbcrlf
	Response.write "	if (strFileName=='')" & vbcrlf
	Response.write "	{" & vbcrlf
	Response.write "    	alert('请选择要上传的文件');" & vbcrlf
	Response.write "		document.form1.FileName.focus();" & vbcrlf
	Response.write "    	return false;" & vbcrlf
	Response.write "  	}" & vbcrlf
	if Cint(Cl.Upload_Setting(1))=1 then
		Set UploadProgress = Server.CreateObject("Persits.UploadProgress")
		sPID = "&PID=" & UploadProgress.CreateProgressID()
		Barref = "UploadBar.Asp?T=10" & sPID

		Response.write "	var strAppVersion = navigator.appVersion;" & vbcrlf
		Response.write "    if (strAppVersion.indexOf('MSIE') != -1 && strAppVersion.substr(strAppVersion.indexOf('MSIE')+5,1) > 4)" & vbcrlf
		Response.write "    {" & vbcrlf
		Response.write "      window.showModelessDialog('"&barref&"&b=IE',null,'dialogWidth=375px; dialogHeight:150px; center:yes');" & vbcrlf
		Response.write "    }" & vbcrlf
		'Response.write "    else" & vbcrlf
		'Response.write "    {" & vbcrlf
		'Response.write "      window.open('"&barref&"&b=NN','','width=370,height=165', true);" & vbcrlf
		'Response.write "    }" & vbcrlf
	end if
	Response.write "}" & vbcrlf
	Response.write "function SelectFiles(sModuleID,type,objname,objname2){" & vbcrlf
	Response.write "  var arr=showModalDialog('../"&Cl.Web_Info(14)&"Admin_Files.asp?FileType=select&ChannelID="&cID&"', '', 'dialogWidth:760px; dialogHeight:600px; help: no; scroll: yes; status: yes');" & vbcrlf
	Response.write "	if(arr!=null){" & vbcrlf
	Response.write "		SaveFilesUrl(sModuleID,type,arr,objname,objname2)" & vbcrlf
	Response.write "	}" & vbcrlf
	Response.write "}" & vbcrlf
	Response.write "</script>" & vbcrlf
	Cl.GetChannelSetting(cID)
	%>
	<form action="UpLoad.asp?Action=P&ID=<%=cID%>&Type=<%=sType%>&Obj=<%=sObj%>&Obj2=<%=sObj2%>&TObj=<%=sTObj%><%=sPID%>" method="post" name="form1" onSubmit="return check()" enctype="multipart/form-data">
		<INPUT TYPE="hidden" NAME="UpCode_<%=cID&sType&sObj%>" value="<%=PostRanNum%>">
		<input name="FileName" type="FILE" size="35">
		<input type="submit" name="Submit" value="上传">
		<%if Cl.UserLevel=1 then%>
		<Input type="button" Name="selectfile" Onclick="SelectFiles('<%=Cl.Channel_Setting(20)%>','<%=sType%>','<%=sObj%>','<%=sObj2%>')" Value="从已上传文件中选择">
		<%end if%>
	</form>
<%
End Sub

Sub Upfile_Main()
	if Cl.UserID=0 or Cl.ChkIsOuter then
		Response.write "<font color=red>您未登录，或者从外部提交信息，操作已被禁止。</font>"
		Response.end
	end if
	ComeUrl			= Request.ServerVariables("HTTP_REFERER")
	ChannelID		= Request.QueryString("ID")
	sProgressID		= Request.QueryString("PID")
	ChannelID		= Clng(ChannelID)
	UpFileType		= Trim(Request.QueryString("Type"))
	JsObjName		= Trim(Request.QueryString("Obj"))
	JsObjName2		= Trim(Request.QueryString("Obj2"))
	JsTempObjName	= Trim(request.QueryString("TObj"))
	if ComeUrl="" then ComeUrl="javascript:history.go(-1)"
	if ChannelID="" or Not IsNumeric(ChannelID) then
		Call Cl.OutMsg("未正确指定所属频道或者你无上传文件权限！",ComeUrl)
	end if
	if UpFileType="" or Not IsNumeric(UpFileType) then
		Call Cl.OutMsg("未正确指定上传文件类型或者你无上传文件权限！",ComeUrl)
	end if
	Cl.GetChannelSetting(ChannelID)
	ModuleID		= Clng(Cl.Channel_Setting(20))
	sTrSetting		= Split(Cl.Channel_Setting(22),"@")
	IsTrueUpfiles	= Trim(sTrSetting(0))		'允许上传权限
	sTrFilePath		= Trim(sTrSetting(1))		'上传目录
	IsAutoSort		= Cint(sTrSetting(2))		'自动分类 0不使用，1按年，2年-月，3年-月-日
	Select Case Cint(UpFileType)
	Case 0
		InceptType		= Trim(sTrSetting(4))	'允许上传类型
		InceptMaxSize	= Clng(sTrSetting(5))	'允许上传大小
		IsReName		= Cint(sTrSetting(6))	'是否重命名
	Case 1
		InceptType		= Trim(sTrSetting(7))	'允许上传类型
		InceptMaxSize	= Clng(sTrSetting(8))	'允许上传大小
		IsReName		= Cint(sTrSetting(9))	'是否重命名
	Case 2
		InceptType		= Trim(sTrSetting(10))	'允许上传类型
		InceptMaxSize	= Clng(sTrSetting(11))	'允许上传大小
		IsReName		= Cint(sTrSetting(12))	'是否重命名
	Case 3
		InceptType		= Trim(sTrSetting(13))	'允许上传类型
		InceptMaxSize	= Clng(sTrSetting(14))	'允许上传大小
		IsReName		= Cint(sTrSetting(15))	'是否重命名
	Case else
		InceptType		= Trim(sTrSetting(4))	'允许上传类型
		InceptMaxSize	= Clng(sTrSetting(5))	'允许上传大小
		IsReName		= Cint(sTrSetting(6))	'是否重命名
	End Select
	'判断上传文件权限
	if Not Cl.ChkUserLevel(IsTrueUpfiles,Cl.UserLevel) then
		Call Cl.OutMsg("本频道上传功能已禁用或者你无上传文件权限！",ComeUrl)
	end if
	Previewpath=Replace(Cl.UpLoadDir & "/PreviewImage/" & sTrFilePath & "/","//","/")
	sTrFilePath=Replace(Cl.UpLoadDir & "/" & sTrFilePath & "/","//","/")
	FilePath = Cl.CreatePath(sTrFilePath,IsAutoSort) '按年月分类目录
	Previewpath = Cl.CreatePath(Previewpath,IsAutoSort) '按年月分类目录
	If Cl.Upload_Setting(3)="1" Then
		DrawInfo = Cl.Upload_Setting(4)
	ElseIf Cl.Upload_Setting(3)="2" Then
		DrawInfo = Replace(Cl.Upload_Setting(9),"{%webdir%}",Cl.WebDir)
	Else
		DrawInfo = ""
	End If
	If DrawInfo = "" Then Cl.Upload_Setting(3) = 0
	Server.ScriptTimeOut=999999	'要是上传的文件比较大，就必须设置。
	Set Upload = New UpFile_Cls
	Upload.UploadType			= Cint(Cl.Upload_Setting(1))	'设置上传组件类型
	Upload.ProgressID			= sProgressID'by 梅傲风。
	Upload.UploadPath			= FilePath						'设置上传路径
	Upload.InceptFileType		= Replace(InceptType,"|",",")	'设置上传文件限制
	Upload.MaxSize				= Int(InceptMaxSize)			'单位 KB
	Upload.InceptMaxFile		= 10							'每次上传文件个数上限
	Upload.ChkSessionName		= "UpCode_"&ChannelID&UpFileType&JsObjName'防止重复提交。
	Upload.IsReName             = IsReName						'是否重命名，by 梅傲风。
	Upload.PreviewType			= Cint(Cl.Upload_Setting(2))	'设置预览图片组件类型
	Upload.PreviewImageWidth	= Cl.Upload_Setting(15)		'设置预览图片宽度
	Upload.PreviewImageHeight	= Cl.Upload_Setting(16)		'设置预览图片高度
	Upload.DrawImageWidth		= Cl.Upload_Setting(12)			'设置水印图片或文字区域宽度
	Upload.DrawImageHeight		= Cl.Upload_Setting(13)			'设置水印图片或文字区域高度
	Upload.DrawGraph			= Cl.Upload_Setting(10)			'设置水印透明度
	Upload.DrawFontColor		= Cl.Upload_Setting(6)			'设置水印文字颜色
	Upload.DrawFontFamily		= Cl.Upload_Setting(7)			'设置水印文字字体格式
	Upload.DrawFontSize			= Cl.Upload_Setting(5)			'设置水印文字字体大小
	Upload.DrawFontBold			= Cl.Upload_Setting(8)			'设置水印文字是否粗体
	Upload.DrawInfo				= DrawInfo				'设置水印文字信息或图片信息
	Upload.DrawType				= Cl.Upload_Setting(3)			'0=不加载水印 ，1=加载水印文字，2=加载水印图片
	Upload.DrawXYType			= Cl.Upload_Setting(14)		'"0" =左上，"1"=左下,"2"=居中,"3"=右上,"4"=右下
	Upload.DrawSizeType			= Cl.Upload_Setting(17)		'"0"=固定缩小，"1"=等比例缩小
	If Cl.Upload_Setting(11)<>"" Then
		Upload.TransitionColor	= Cl.Upload_Setting(11)		'透明度颜色设置
	End If
	If Upload.ErrCodes<>0 Then
		Call Cl.OutMsg("错误："& Upload.Description,ComeUrl)
	Else
		Upload.SaveUpFile
		If Upload.ErrCodes<>0 Then
			Call Cl.OutMsg("错误："& Upload.Description,ComeUrl)
		End If
	End IF
	If Upload.Count > 0 Then
		F_Filesize=0
		For Each FormName In Upload.UploadFiles
			Set File = Upload.UploadFiles(FormName)
			F_FileName = FilePath & File.FileName
			'创建预览及水印图片
			If Upload.PreviewType<>999 and File.FileType=1 then
				F_Viewname = Previewpath & "pre" & Replace(File.FileName,File.FileExt,"") & "jpg"
				'创建预览图片:Call CreateView(原始文件的路径,预览文件名及路径,原文件后缀)
				Upload.CreateView F_FileName,F_Viewname,File.FileExt
			End If
			dim strSaveUrl
			if sTrSetting(3) = "1" then
				strSaveUrl=Cl.RootPath2DomainPath(Trim(F_FileName))
			else
				if Lcase(left(F_FileName,Len(Cl.UpLoadDir)))=Lcase(Cl.UpLoadDir) then
					strSaveUrl="{%uploaddir%}" & mid(F_FileName,Len(Cl.UpLoadDir)+1) 
				elseif left(F_FileName,1)="/" then
					strSaveUrl="{%webdir%}" & mid(F_FileName,2)
				else
					strSaveUrl=Trim(F_FileName)
				end if
			end if
			F_Filesize=File.FileSize
			F_FileExt=File.FileExt
			response.write "<script language=javascript>SaveFilesUrl('"&ModuleID&"','"&UpFileType&"','"&strSaveUrl&"|"&cstr(round(F_Filesize/1024))&"','"&JsObjName&"','"&JsObjName2&"');AddUploadFiles('"&JsTempObjName&"','"&strSaveUrl&"','"&File.FileName&"');</script>"
			Cl.InToColumn "Cl_UpFileLog","UserID,UserName,UserLevel,UserIP,UpFileName,SaveFileName,UpFileTime,ChannelID","'"&Cl.User_Info(4)&"','"&Cl.User_Info(5)&"','"&Cl.User_Info(21)&"','"&Cl.UserTrueIP&"','"&File.OldFileName&"','"&strSaveUrl&"','"&Now&"',"&ChannelID&""
			Set File = Nothing
		Next
	Else
		Call Cl.OutMsg("请正确选择要上传的文件。",ComeUrl)
	End If
	Set Upload = Nothing
	Response.write "恭喜您，文件上传成功，文件格式：<font color=red>"&F_FileExt&"</font>，大小：<font color=red>"&cstr(round(F_Filesize/1024))&"</font> KB ！&nbsp;我要[<a href='"&ComeUrl&"'><font color=blue>继续上传</font></a>]"',ComeUrl)
End Sub

'===================================================
' CreateLive CMS Version 3.1
'							Powered by Aspoo.CoM
'===================================================
' Mail: aspoo@126.com, Info@aspoo.cn
' Q  Q: 3315263, 596197794
' Msn : aspoo@126.com, Clw866@hotmail.com
' Web : http://www.aspoo.com, http://www.aspoo.net
' Bbs : http://bbs.aspoo.com, http://bbs.aspoo.net
' Copyright (C) 2005 Aspoo.CoM All Rights Reserved.
'===================================================
%>