<% Option Explicit %>
<!--#include file="../../Inc/Const.asp" -->
<!--#include file="../../Inc/Cls_DB.asp" -->
<!--#include file="../../Inc/Function.asp" -->
<%
call limitUserNotLogin(Session("Name"))  

Dim DBC,Conn
Set DBC = New DataBaseClass
Set Conn = DBC.OpenConnection()
Set DBC = Nothing
Dim CurrPath,FsoObj,SubFolderObj,FolderObj,FileObj,i,FsoItem
Dim ParentPath,FileExtName,AllowShowExtNameStr
AllowShowExtNameStr = "jpg,txt,gif"
CurrPath = Request("CurrPath")
if CurrPath = "" then
	CurrPath = "/"
	ParentPath = ""
else
	ParentPath = Mid(CurrPath,1,InstrRev(CurrPath,"/")-1)
	if ParentPath = "" then
		ParentPath = "/"
	end if
end if
Set FsoObj = Server.CreateObject("Scripting.FileSystemObject")
Set FolderObj = FsoObj.GetFolder(Server.MapPath(CurrPath))
Set SubFolderObj = FolderObj.SubFolders
Set FileObj = FolderObj.Files
Function CheckFileShowTF(AllowShowExtNameStr,ExtName)
	if ExtName="" then
		CheckFileShowTF = False
	else
		if InStr(1,AllowShowExtNameStr,ExtName) = 0 then
			CheckFileShowTF = False
		else
			CheckFileShowTF = True
		end if
	end if
End Function
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>文件和目录列表</title>
</head>
<link href="../../CSS/css.css" rel="stylesheet">
<body topmargin="0" leftmargin="0">
<table width="99%" border="0" align="center" cellpadding="2" cellspacing="0">
  <tr> 
    <td width="30%" class="ButtonList"> <div align="center">名称</div></td>
    <td width="40%" class="ButtonList"> <div align="center">类型</div></td>
    <td class="ButtonList"> <div align="center">大小</div></td>
  </tr>
  <%
if (CurrPath <> "/" & UpFiles) and (ParentPath <> "") then
%>
  <tr title="上级目录<% = ParentPath %>" onClick="SelectUpFolder(this);" Path="<% = ParentPath %>" onDblClick="OpenParentFolder(this);"> 
    <td><table width="62" border="0" cellpadding="0" cellspacing="0">
        <tr> 
          <td><font color="#FFFFFF"><img src="image/Folder.gif" width="18" height="18"></font></td>
          <td><font color="#FFFFFF">...</font></td>
        </tr>
      </table></td>
    <td><div align="center"><font color="#FFFFFF">-</font></div></td>
    <td><div align="center"><font color="#FFFFFF">-</font></div></td>
  </tr>
  <%
end if
for each FsoItem In SubFolderObj
%>
  <tr> 
    <td width="30%"><table border="0" cellspacing="0" cellpadding="0">
        <tr title="双击鼠标进入此目录"> 
          <td><img src="image/Folder.gif" width="18" height="18"></td>
          <td> <span class="TempletItem" Path="<% = FsoItem.name %>" onDblClick="OpenFolder(this);" onClick="SelectFolder(this);"> 
            <% = FsoItem.name %>
            </span> </td>
        </tr>
      </table></td>
    <td><div align="center">文件夹</div></td>
    <td><div align="center"> 
        <% = FsoItem.Size %>
      </div></td>
  </tr>
  <%
next
for each FsoItem In FileObj
	FileExtName = LCase(Mid(FsoItem.name,InstrRev(FsoItem.name,".")+1))
	if True then 'CheckFileShowTF(AllowShowExtNameStr,FileExtName) = 
%>
  <tr title="双击鼠标选择此文件"> 
    <td> <span class="TempletItem" File="<% = FsoItem.name %>" onDblClick="SetFile(this);" onClick="SelectFile(this);"> 
      <% = FsoItem.name %>
      </span> </td>
    <td><div align="center"> 
        <% = FsoItem.Type %>
      </div></td>
    <td><div align="center"> 
        <% = FsoItem.Size %>
        字节 </div></td>
  </tr>
  <%
  	end if
next
%>
</table>
</body>
</html>
<%
Set FsoObj = Nothing
Set SubFolderObj = Nothing
Set FileObj = Nothing
%>
<script language="JavaScript">
var SysRootDir='<% = SysRootDir %>';
var CurrPath='<% = CurrPath %>';
function SelectFolder(Obj)
{
	for (var i=0;i<document.all.length;i++)
	{
		if (document.all(i).className=='TempletSelectItem') document.all(i).className='TempletItem';
	}
	Obj.className='TempletSelectItem';
}
function SelectFile(Obj)
{
	for (var i=0;i<document.all.length;i++)
	{
		if (document.all(i).className=='TempletSelectItem') document.all(i).className='TempletItem';
	}
	Obj.className='TempletSelectItem';
	PreviewFile(Obj);
}
function OpenParentFolder(Obj)
{
	location.href='FolderImageList.asp?CurrPath='+Obj.Path;
	SearchOptionExists(parent.document.all.FolderSelectList,Obj.Path);
}

function OpenFolder(Obj)
{
	var SubmitPath='';
	if (CurrPath=='/') SubmitPath=CurrPath+Obj.Path;
	else SubmitPath=CurrPath+'/'+Obj.Path;
	location.href='FolderImageList.asp?CurrPath='+SubmitPath;
	AddFolderList(parent.document.all.FolderSelectList,SubmitPath,SubmitPath);
}

function SelectUpFolder(Obj)
{
	for (var i=0;i<document.all.length;i++)
	{
		if (document.all(i).className=='TempletSelectItem') document.all(i).className='TempletItem';
	}
	Obj.className='TempletSelectItem';
}
function PreviewFile(Obj)
{
	var Url='';
	var Path=escape();
	if (CurrPath=='/') Path=escape(CurrPath+Obj.File);
	else Path=escape(CurrPath+'/'+Obj.File);
	Url='PreviewImage.asp?FilePath='+Path;
	parent.frames["PreviewArea"].location=Url;
}
function AddFolderList(SelectObj,Lable,LableContent)
{
	var i=0,AddOption;
	if (!SearchOptionExists(SelectObj,Lable))
	{
		AddOption = document.createElement("OPTION");
		AddOption.text=Lable;
		AddOption.value=LableContent;
		SelectObj.add(AddOption);
		SelectObj.options(SelectObj.length-1).selected=true;
	}
}
function SearchOptionExists(Obj,SearchText)
{
	var i;
	for(i=0;i<Obj.length;i++)
	{
		if (Obj.options(i).text==SearchText)
		{
			Obj.options(i).selected=true;
			return true;
		}
	}
	return false;
}
function SetFile(Obj)
{
	var PathInfo='',TempPath='';
	if (SysRootDir!='')
	{
		TempPath=CurrPath;
		PathInfo=TempPath.substr(TempPath.indexOf(SysRootDir)+SysRootDir.length);
	}
	else
	{
		PathInfo=CurrPath;
	}
	if (CurrPath=='/')	window.returnValue=PathInfo+Obj.File;
	else window.returnValue=PathInfo+'/'+Obj.File;
	window.close();
}
window.onunload=CheckReturnValue;
function CheckReturnValue()
{
	if (typeof(window.returnValue)!='string') window.returnValue='';
}
</script>