<!--#include file="sdcms_check.asp"-->
<base target="_self">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>附件</title>
<style>
body{margin:10px;padding:0;overflow:hidden;}
table,td,div{font-size:12px;font-family:arial;}
</style>
<base target="_self">
</head>

<body>
 <form method=post name="Form1" id="Form1">
        <input type="hidden" name="files" ID="Hidden1">
        <input type="hidden" name="ffilter" ID="Hidden2">
    </form>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="30">目录选择：
<%
response.Expires=0
currFolder=request("files")
ffilter=request("ffilter")
filetype=",media,image,flash"
if currFolder="" then currFolder=sdcms_upfiledir
if currFolder<>"" then
    if instr(currFolder,sdcms_upfiledir)=0 then
		currFolder=sdcms_root&sdcms_upfiledir
	end if
end if

set oFSO = server.CreateObject ("Scripting.FileSystemObject")
set oFolder_base0 = oFSO.GetFolder(server.MapPath(sdcms_root&sdcms_upfiledir)) 
response.Write "<select  name='selCurrFolder' id='selCurrFolder' onchange=""changeFolder()"">"
recursive oFolder_base0,oFolder_base0,sdcms_upfiledir
response.Write "</select>"

%></td>
    <td align="right"><select name='file_type' id='file_type' onChange="changeFolder()">
<%
filetype=split(filetype,",")
for i=0 to ubound(filetype)
	select case filetype(i)
		case "media":title="多媒体"
		case "image":title="图象"
		case "flash":title="Flash"
		case else:title="全部文档"
	end select
%>
<option value="<%=filetype(i)%>" <%if ffilter=filetype(i) then%>selected="selected"<%end if%>><%=title%></option>
<%next%>
</select></td>
  </tr>
  <tr>
    <td width="24%"><div id="idPreview" style="text-align:center;overflow:auto;width:297px;height:245px;border:#d7d7d7 5px solid;border-bottom:#d7d7d7 3px solid;background:#ffffff;margin-right:2;"></div>
                  <div align=center>
                    <input type="text" id="inpSource" name="inpSource" style="border:#cfcfcf 1px solid;width:302px">
    </div></td>
    <td valign="top"><%writeFileSelections%></td>
  </tr>
    <tr>
    <td height="30" colspan="2"><input name="btnOk" id="btnOk" type="button" value="确定" style="float:right" onClick="doOk()" ><%admin_upfile 0,"80%","30",1%></td>
  </tr>
</table>
<%


function recursive(oFolder,oFolder_base,sName)
  set oSubFolders = oFolder.SubFolders

    if InStr(1,oFolder.path,"_vti_cnf")=0 then
      sDisplayed = sName & Replace(Replace(oFolder.path,oFolder_base.path,""),"\","/")
      if CStr(currFolder)=CStr(sDisplayed) then isselect="selected"
        sOptions = sOptions & "<option value=""" & sDisplayed & """ "&isselect&">" & sDisplayed & "</option>" & vbCrLf
    end if

  for each item in oSubFolders
      recursive item,oFolder_base,sName
    next

    sOptions = sOptions & vbCrLf
    recursive = sOptions
	response.Write sOptions
end function

function getExt(sFile)'ffilter
  dim sExt
  sExt=""
  for each Item In split(sFile,".")
    sExt = Item
  next
  getExt=sExt
end function

function writeFileSelections()
  on error resume next
  set oFolder = oFSO.GetFolder(Server.Mappath(sdcms_root&currFolder))
  set oFiles = oFolder.files
  if err then
  response.Write("<br>请勿打歪注意")
  response.End()
  err.clear
  end if
  nIndex=0

  bFileFound=false

  Response.Write "<div style='overflow:auto;height:270px;width:100%;margin-top:3px;margin-bottom:2px;'>" & VbCrLf
  sColor = "#e7e7e7"
  for each oFile in oFiles

    bDisplay=false
    sExt=getExt(oFile.path)
    if ffilter="flash" then
      if LCase(sExt)="swf" then bDisplay=true
    elseif ffilter="media" then
      if LCase(sExt)="avi" or LCase(sExt)="wmv" or LCase(sExt)="mpg" or _
         LCase(sExt)="mpeg" or LCase(sExt)="wav" or LCase(sExt)="wma" or _
         LCase(sExt)="mid" or LCase(sExt)="mp3" then bDisplay=true
    elseif ffilter="image" then
      if LCase(sExt)="gif" or LCase(sExt)="jpg" or LCase(sExt)="png" then bDisplay=true
    else 'all
      bDisplay=true
    end if
    '~~~~~~~~~~~~~~~~~~

    if bDisplay then

      bFileFound=true

      nIndex=nIndex+1
  

      if sColor = "#EFEFF5" then
        sColor = ""
      else
        sColor = "#EFEFF5"
      end if
 

      if(LCase(oFile.name)=LCase(sUploadedFile))then
        sColorResult="yellow"
        iSelected=nIndex
      else
        sColorResult=sColor
      end if

      Response.Write "<div style='background:" & sColorResult & ";line-height:20px;cursor:pointer;margin:2px 10px;padding:0 6px;'  onclick=""selectFile(" & nIndex & ",0)"" align=""absmiddle"" ><span style=""float:right"">" & FormatNumber(oFile.size/1000,1) & " kb</span><u>" & oFile.name & "</u><input type=hidden name=inpFile" & nIndex & " id=inpFile" & nIndex & " value=""" & oFile.name & """></div>" & VbCrLf  
     

   
    end if
  next
  if bFileFound=false then
    Response.Write "<div style='margin:2px 10px;padding:0 6px;color:#f30;'>没有内容</div></div>"
  else
    Response.Write "</div>"
  end if
 
end function
%>
<script>
function changeFolder()
  {
  var Form1 = document.forms.Form1;

  Form1.elements.files.value=document.getElementById("selCurrFolder").value;
  Form1.elements.ffilter.value=document.getElementById("file_type").value;

  Form1.action="?";
  Form1.submit();
  }
function upload(fpath)
	{
		selectFile(fpath,1);
	}
function selectFile(index,ordnum)
  {
  if (ordnum==0)
  {
  sFile_RelativePath = document.getElementById("inpFile"+index).value;
  sFile_RelativePath = '<%=sdcms_root%><%=CurrFolder%>/' + sFile_RelativePath
  }
  else
  {sFile_RelativePath=index;}
  document.getElementById("inpSource").value=sFile_RelativePath;

  var arrTmp = sFile_RelativePath.split(".");
  var sFile_Extension = arrTmp[arrTmp.length-1]
  var sHTML="";

  //Image
  if(sFile_Extension.toUpperCase()=="GIF" || sFile_Extension.toUpperCase()=="JPG" || sFile_Extension.toUpperCase()=="PNG")
    {
    sHTML = "<img src=\"" + sFile_RelativePath + "\" onclick=window.open(this.src) style=cursor:pointer >"
    }
  //SWF
  else if(sFile_Extension.toUpperCase()=="SWF")
    {
    sHTML = "<object "+
      "classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' " +
      "width='100%' "+
      "height='100%' " +
      "codebase='http://active.macromedia.com/flash6/cabs/swflash.cab#version=6.0.0.0'>"+
      " <param name=movie value='"+sFile_RelativePath+"'>" +
      " <param name=quality value='high'>" +
      " <embed src='"+sFile_RelativePath+"' " +
      "   width='100%' " +
      "   height='100%' " +
      "   quality='high' " +
      "   pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'>" +
      " </embed>"+
      "</object>";
    }
  //Video
  else if(sFile_Extension.toUpperCase()=="WMV"||sFile_Extension.toUpperCase()=="AVI"||sFile_Extension.toUpperCase()=="MPG")
    {
    sHTML = "<embed src='"+sFile_RelativePath+"' hidden=false autostart='true' type='video/avi' loop='true'></embed>";
    }
  //Sound
  else if(sFile_Extension.toUpperCase()=="WMA"||sFile_Extension.toUpperCase()=="WAV"||sFile_Extension.toUpperCase()=="MID")
    {
    sHTML = "<embed src='"+sFile_RelativePath+"' hidden=false autostart='true' type='audio/wav' loop='true'></embed>";
    }
  //Files (Hyperlinks)
  else
    {
    sHTML = "<br><br><br><br><br><br>不可预览"
    }

  document.getElementById("idPreview").innerHTML = sHTML;
  }
  
 function doOk()
  {
  if(navigator.appName.indexOf('Microsoft')!=-1)
    window.returnValue=inpSource.value;
  else
    window.opener.setAssetValue(document.getElementById("inpSource").value);
  bOk=true;
  self.close();
  }
</script>
</body>
</html>
