<%
Function ShowImageForType(strName)
Dim strTemp
strTemp = strName
If strTemp <> "dir" Then
	strTemp = LCase(Right(strTemp, Len(strTemp) - InStrRev(strTemp, ".", -1, 1)))
End If
Select Case strTemp
	Case "asp"
		strTemp = "asp"
	Case "dir"
		strTemp = "dir"
	Case "htm", "html"
		strTemp = "htm"
	Case "gif"
		strTemp = "img"
	Case "jpg","tga"
		strTemp = "jpg"
	Case "txt"
		strTemp = "txt"
	Case "exe"
		strTemp = "exe"
	Case "wav"
		strTemp = "wav"
	Case "mp3","mpeg","avi","mid","m3u"
		strTemp = "mp3"
	Case "shader", "c","pl","cfg"
		strTemp = "c"
	Case "zip", "pk3"
		strTemp = "zip"
	Case Else
		strTemp = "misc"
End Select
strTemp = "<img src=""images/dir_" & strTemp & ".gif"" width=""16"" height=""16"" border=""0"">"
ShowImageForType = strTemp
End Function
Dim strPath   'Path of directory to show
Dim objFSO    'FileSystemObject variable
Dim objFolder 'Folder variable
Dim objItem   'Variable used to loop through the contents of the folder
Dim rstFiles
Const adVarChar = 200
Const adInteger = 3
Const adDate = 7
strPath = "../temp/" & Request.QueryString("dir")
p_tosort = Request.QueryString("sort")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath(strPath))
p_sds	=	Request.QueryString("csds")
p_sd = Request.QueryString("csd")
if p_sd = 1 then
	p_text1	=	"</b>&nbsp;&nbsp;&nbsp;<a href=""?csd=0"">Hide Directories</a><b>"
	p_sds		=	1
	p_sdsh		=	"&csds=1"
	else
	p_text1	=	"</b>&nbsp;&nbsp;&nbsp;<a href=""?csd=1"">Show Directories</a><b>"
	p_sds		=	0
	p_sdsh		=	"&csds=0"
end if
p_d = Request.QueryString("d")
if p_d <> "" then
	if p_d = "d" then
		p_d1		=	"d=a"
		p_sort2	=	"date ASC"
	else
		p_d1		=	"d=d"
		p_sort2	=	"date DESC"
	end if
else
	p_d1		=	"d=a"
end if
p_s = Request.QueryString("s")
if p_s <> "" then
	if p_s = "d" then
		p_s1		=	"s=a"
		p_sort2	=	"size ASC"
	else
		p_s1		=	"s=d"
		p_sort2	=	"size DESC"
	end if
else
	p_s1		=	"s=a"
end if
p_n = Request.QueryString("n")
if p_n <> "" then
	if p_n = "d" then
		p_n1		=	"n=a"
		p_sort2	=	"name ASC"
	else
		p_n1		=	"n=d"
		p_sort2	=	"name DESC"
	end if
else
	p_n1		=	"n=a"
end if
p_f = Request.QueryString("f")
if p_f <> "" then
	if p_f = "d" then
		p_f1		=	"f=a"
		p_sort2	=	"type ASC"
	else
		p_f1		=	"f=d"
		p_sort2	=	"type DESC"
	end if
else
	p_f1		=	"f=a"
end if
%>
<head>
<link rel="stylesheet" type="text/css" href="../beta/style.css">
</head>
<b>
<font face="Arial" size="4">www.shadowspawn.net<br>
</font><font face="Arial" size="3">Contents of <%= strPath %></font></b><br />
<a href="<%= strPath %>../">Back to parent</a>
<br />
&nbsp;
<table border="0" cellspacing="0" cellpadding="2">
<tr>
<td><b><a href="?<%= p_n1 & p_sdsh%>">File Name</a><%= p_text1 %></b></td>
	<td><b><a href="?<%= p_s1 & p_sdsh%>">Size</a></b></td>
	<td><b><a href="?<%= p_d1 & p_sdsh	%>">Date</a></b></td>
	<td><b><a href="?<%= p_f1 & p_sdsh	%>">File Type</a></b></td>
</tr>
<%
if p_sds		=	1 then
p_text1	=	"<a href=""?showfiles=0"">&nbsp;Hide Directories</a>"
For Each objItem In objFolder.SubFolders
If InStr(1, objItem, "_vti", 1) = 0 Then
	p_fosize = objItem.Size/1024
	p_totdirsize=p_totdirsize + objItem.Size
	p_fosize = round(p_fosize,2)
	p_dircount = p_dircount+1
 		p_char1 = "k"
	if p_fosize > 1000 then
		p_fosize = round((p_fosize / 1000),1)
		p_char1 = "m"
		p_href = "<font color= ""FF0000"">"
		p_href2 = "</font>"
	else
		p_char1 = "k"
		p_href = "<font color= ""000000"">"
	end if		
%>
<tr>
	<td bgcolor="#C0C0C0" ><%= ShowImageForType("dir") %>&nbsp;<a href="<%= "?dir=" & objItem.Name & "/"%>"><%= objItem.Name %></a></td>
	<td bgcolor="#C0C0C0" align="right"><%= p_href & p_fosize & p_char1 & p_href2 %>&nbsp;</td>
	<td bgcolor="#C0C0C0" ><%= objItem.DateCreated %></td>
	<td bgcolor="#C0C0C0" ><%= objItem.Type %></td>
</tr>
<%
End If
Next 'objItem
else
p_text1	=	"<a href=""?showfiles=1"">&nbsp;Show Directories</a>"
end if
Set rstFiles = Server.CreateObject("ADODB.Recordset")
rstFiles.Fields.Append "name", adVarChar, 255
rstFiles.Fields.Append "size", adInteger
rstFiles.Fields.Append "date", adDate
rstFiles.Fields.Append "type", adVarChar, 255
rstFiles.Open
For Each objItem In objFolder.Files
rstFiles.AddNew
rstFiles.Fields("name").Value = objItem.Name
rstFiles.Fields("size").Value = objItem.Size
rstFiles.Fields("date").Value = objItem.DateCreated
rstFiles.Fields("type").Value = objItem.Type
Next 'objItem
Set objItem = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
rstFiles.Sort = p_sort2
rstFiles.MoveFirst
Do While Not rstFiles.EOF
p_fsize = (rstFiles.Fields("size").Value)/1024
p_fsize = round(p_fsize,1)
p_totdirsize=p_totdirsize + rstFiles.Fields("size")
p_fcount=p_fcount+1
If InStr(1, rstFiles.Fields("name"), "asp", 1) = 0 Then
%>
<tr>
	<td bgcolor="#C0C0C0" ><%= ShowImageForType(rstFiles.Fields("name").Value) %>&nbsp;<a href="<%= strPath & rstFiles.Fields("name").Value %>"><%= rstFiles.Fields("name").Value %></a></td>
<% 		p_char1 = "k"
if p_fsize > 1000 then
	p_fsize = round((p_fsize / 1000),1)
	p_char1 = "m"
	p_href = "<font color= ""FF0000"">"
	p_href2 = "</font>"
else
	p_char1 = "k"
	p_href = "<font color= ""000000"">"
end if		
%>		
	<td bgcolor="#C0C0C0" align="right"><%= p_href & p_fsize & p_char1 & p_href2 %>&nbsp;</td>
	<td bgcolor="#C0C0C0" ><%= rstFiles.Fields("date").Value %></td>
	<td bgcolor="#C0C0C0" ><%= rstFiles.Fields("type").Value %></td>
</tr>
<%
end if
rstFiles.MoveNext
Loop
rstFiles.Close
Set rstFiles = Nothing
%>
</table>
<font size="-1" color="#800000">Total Directories: <%=p_dircount%>&nbsp;&nbsp;&nbsp;&nbsp; Total Files: <%=p_fcount%>&nbsp;&nbsp;&nbsp;&nbsp; Total Size: <%=round((p_totdirsize/1024000),2)%>MB</font>