<!--#include FILE="upload.inc"-->
<!--#include FILE="base.asp"-->
<!--#include FILE="testCookies.asp"-->
<!--#include File="upsub.asp"-->

<%
	const thisPage = "explorer.asp"

	Dim ServName, NowFolder, VNowFolder, VDir, Vpath
	Dim EnterFolder,UpFolder
	Dim upload,file,formName,formPath,iCount,filename,fileExt
	Dim NumFolder,NumFile,TotalSize
	Dim fsize '文件及文件夹大小

	Dim ActionDo
	ActionDo = ""
	action = Trim(request("action"))
	if action <> "" then
		ActionDo = "&action=" & action
	end if


	'if not isLogin then	
        'Response.Redirect("http://www."&HOST&"")
	'end if
	if not isOpenCookies then
		PrintMsg "本系统需要 Cookies 支持，请先将 Cookies 打开！"
	end if


	'获取初始目录
	'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	dim v_path_s, NumMax, cookies_path
	v_path_s = split( Request.ServerVariables("PATH_INFO") , "/" )
	NumMax = ubound( v_path_s )
        strUserName=Session("UserName")
	 ' cookies_path =   Session("UserName") & "/"
       cookies_path =    "/"
	for i=1 to NumMax-1
		cookies_path = cookies_path & v_path_s(i) & "/"
	next


	'获取当前目录，VNowFolder 是虚拟目录
	'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	VDir = Trim( request("dir") )
	if VDir = "" then
		VDir = request.Cookies("XingWorld_net")("MemoryVDir")
	end if
	

	if VDir<>"" then
		if not IsValidVDir( VDir ) then
			PrintMsg "操作非法，目录名只能是英文和下划线。"
		end if
	end if

	if Right( VDir,1 ) <> "/" then
		VDir = VDir & "/"
	end if
	if VDir = "" then
		'VNowFolder = cookies_path & "/home/" & Cook_UserName & "/"
                 VNowFolder = cookies_path & "/home/" & strUserName & "/UpFile/"
	else
		VNowFolder = cookies_path & "/home/" & strUserName  & "/UpFile/" & VDir
	end if

	'记忆用户刚刚访问的路径
	'-------------------------------------------------------------------
	response.Cookies("XingWorld_net")("MemoryVDir") = VDir




	On Error Resume Next
	Set objFSO = Server.CreateObject( Const_ScriptFileSystem )

	'检查目录是否存在的函数
	'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	sub CheckFolder( Folder,is_not,AlertInfo ) 'is_not 是布尔值
		if objFSO.FolderExists( Folder )=is_not then
			PrintMsg (AlertInfo)
		end if
	end sub


	'检查文件是否存在
	'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	sub CheckFile( File,is_not,AlertInfo )
		if objFSO.FileExists(File)=is_not then
			PrintMsg (AlertInfo)
		end if
	end sub





	'处理当前目录，向上 和 进入某目录
	'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	if Right(VNowFolder,1)<>"/" then
		VNowFolder = VNowFolder & "/"
	end if
	While inStr(VNowFolder,"//")<>0
		VNowFolder = Replace( VNowFolder ,"//","/" )
	Wend




	'保存当前目录到 Cookies，NowFolder 为服务器物理目录
	'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	NowFolder = Server.MapPath( VNowFolder )
	if Right(NowFolder,1)<>"\" then
		NowFolder=NowFolder & "\"
	end if




	'处理重命名、新建、删除等操作
	'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	if request("NewFolderName")<>"" and request("OldFolderName")<>"" then '文件夹 重命名
		if not IfEnglish( request("NewFolderName") ) then	'检查文件名是否合法
			PrintMsg "文件夹名不合法，只能是英文和下划线。"
		end if
		source = NowFolder & request("OldFolderName")
		destination = NowFolder & request("NewFolderName")
		call CheckFolder(destination,True,"您要重命名的新文件夹已经存在！")

		response.write "|source=" & source & "-----destination=" & destination

		objFSO.MoveFolder source , destination

		response.redirect thisPage & "?dir=" & VDir & "&msg=文件夹: """ & request("OldFolderName") & """ -> """ & request("NewFolderName") & """ 重命名成功！"
	end if



	if request("NewFileName")<>"" and request("OldFileName")<>"" then '文件 重命名
		NewFileName = trim(request("NewFileName"))
		OldFileName = trim(request("OldFileName"))
		ArrNewFileName = split( NewFileName, "." )
		if ubound(ArrNewFileName)>1 then
			PrintMsg "文件名中不允许含有：“.”。"
		end if
		if not IfEnglish( ArrNewFileName(0) ) then	'检查文件名是否合法
			PrintMsg "文件名不合法，只能是英文和下划线。"
		end if
		if not ChkFileExt( NewFileName ) then '检查文件的扩展名是否合法
			PrintMsg "文件的扩展名不合法，只允许使用：" & PermitedExt & " 文件。"
		end if
		source = NowFolder & OldFileName
		destination = NowFolder & NewFileName
		call CheckFile(destination,True,"您要重命名的新文件已经存在！")

		'如果输入的新文件（目标文件）无扩展名，则加上源文件的扩展名
		if inStr( NewFileName , "." )=0 and AutoAddExt then
			ArrOldFileName = split( OldFileName , "." )
			Ext = ArrOldFileName( ubound(ArrOldFileName) )
			destination = destination & "." & Ext
		end if
		objFSO.MoveFile source , destination
		response.redirect thisPage & "?dir=" & VDir & "&msg=文件重命名成功！"
	end if


	dim DFolder, DelFolder
	if request("DelFolder")<>"" then	'删除文件夹
		DFolder = request("DelFolder")
		if not IfEnglish(DFolder) then
			PrintMsg "操作非法，文件名只能是英文和下划线。"
		end if
		DelFolder = NowFolder & DFolder
		call CheckFolder(DelFolder,false,"您要删除的文件夹不存在！")

		objFSO.DeleteFolder( DelFolder )
		response.redirect thisPage & "?dir=" & VDir & "&msg=文件夹 """ & DFolder & """ 删除成功！"
	end if

	if request("DelFile")<>"" then		'删除文件
		DFile = trim(request("DelFile"))
		ArrDFile = split(DFile,".")
		if ubound(ArrDFile)>1 then
			PrintMsg "被删除的文件名中不能含有：“.”，请先重命名文件。"
		end if
		if not IfEnglish( ArrDFile(0) ) then
			PrintMsg "提交被删除的文件名只能是英文和下划线。如果不是，请先重命名。"
		end if
		DelFile = NowFolder & DFile
		call CheckFile( DelFile,false,"没有找到您要删除的文件！")

		objFSO.DeleteFile( DelFile )
		response.redirect thisPage & "?dir=" & VDir & "&msg=文件删除成功！"
	end if

	dim CFolder, CreateFolderName
	if request("CreateFolder")<>"" then		'新建文件夹
		CFolder = Trim( request("CreateFolder") )
		if not IfEnglish( CFolder ) then	'检查文件名是否合法
			PrintMsg "文件夹名不合法，只能是英文和下划线。"
		end if
		CreateFolderName = NowFolder & CFolder
		call CheckFolder(CreateFolderName,True,"您要创建的新文件夹已经存在！")

		objFSO.CreateFolder(CreateFolderName)
		response.redirect thisPage & "?dir=" & VDir & "&msg=文件夹 """ & CFolder & """ 创建成功！"
	end if



	'检查当前正要浏览的目录是否存在
	'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	CheckFolder NowFolder, false, ""& strUserName &"对不起，您要浏览的目录不存在！"


	'主操纵台
	'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	if Request.QueryString("action")="up" then
		call up() '文件上传
	end if

%>
<style>
td{font-size:13px;line-height:150%}
</style>
<SCRIPT language=JavaScript>
function imgclick(url){
		var url = dialogArguments.eWebEditor1.relativePath2setPath(url)
		window.dialogArguments.eWebEditor1.insertHTML("<IMG id=eWebEditor_TempElement_Img SRC=" + url + ">");

		var oTempElement = dialogArguments.eWebEditor1.eWebEditor.document.getElementById("eWebEditor_TempElement_Img");
		oTempElement.src = url;
		oTempElement.removeAttribute("id");

		window.returnValue = null;
		window.close();
}

function swfclick(url){
	var url = dialogArguments.eWebEditor1.relativePath2setPath(url)

	var sHTML = "<OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
	sHTML+="><PARAM NAME=movie VALUE='"+url+"'><PARAM NAME=quality VALUE=high><embed src='"+url+"' quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash'";
	sHTML+=">"+url+"</embed></OBJECT>";
	
	dialogArguments.eWebEditor1.insertHTML(sHTML);

	window.returnValue = null;
	window.close();
}
</script>
<table width=752 align="center" cellPadding=1 cellSpacing=1 bgcolor="#FFFFFF">
  <tr>
	<td bgcolor=#D9D9D9 height=1 width=688 colSpan=7><font color=red><b><%=request("msg")%></b></font></td>
  </tr>
  <tr bgcolor=#F1F1F1 height=25>
	<td width=30 align=center>操作</td>
	<td width=220 colSpan=2>文件/文件夹名</td>
	<td width=80 align=left>大小(Byte)</b></td>
	<td width=160 align=left> 文件类型</b></td>
	<td width=150 align=left> 最后修改时间</b></td>
	<td width=40 align=left> 选择</b></td>
  </tr>

<%
	if VNowFolder <> "/" then
		call GoUpFolder() '当处于非根目录时，打印“向上...”按钮
	end if
	call ShowFolderList( NowFolder ) '列出当前文件夹中的所有文件夹
	call ShowFileList( NowFolder ) '列出当前文件夹中的所有文件

%>

</table>
<table width=752 align="center" cellPadding=1 cellSpacing=1 bgcolor="#FFFFFF">
  <tr>
    <td height=30 Valign=bottom bgcolor=#FFFFFF><b>→</b> <font color=#888888>
	当前目录共有 <span class=gface><%=NumFile%></span> 个文件，
	<span class=gface><%=NumFolder%></span> 个文件夹，占用空间
<%
	fsize = TotalSize
	call Pfsize()
	response.write "<span class=gface>" & fsize & "</span>"
%>。</td>
  </tr>

  <tr><td bgcolor=#D9D9D9 height=1> </td></tr>
  <tr><td height=5> </td></tr>
  <tr>
    <td align=left>
      <form action="<%=ThisPage%>?action=<%=request.QueryString("action")%>" name="CreateNewFolder" method=post>
	<b>新建文件夹</b>
	<input type=text name="CreateFolder">
	<input type=hidden name="dir" value="<%=VDir%>">
	<input type="submit" value="新建" onClick = "return submitchecken();" style="background-color: buttonface">
	&nbsp;&nbsp;<b>使用说明</b>：请单击相应文件图标进行编辑，单击文件名浏览.
      </form>
    </td>
  </tr>
</table>

<%
	call interface() '打印界面
%>
