<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    import="javazoom.download.*,javazoom.download.util.*, java.util.*" %>
<jsp:useBean id="downloadbean" class="javazoom.download.DownloadBean" scope="page" />
<%
   Repository repository = Repository.getInstance();
   Keys.BLACKLIST = null;
   String type = "UNKNOWN";
   String info = "No info available";
   String properties = "No info available";
   String desc = "No description available";
   Config conf = null;
   Vector items = null;
   String uid = request.getParameter("id");
   if (uid == null) uid = repository.getFirstId();
   if (uid != null)
   {
   	conf = repository.get(uid);
	if (conf != null)
	{
   		if (conf instanceof FolderConfig)
   		{
   	 		type = "Folder";
   	 		info = ((FolderConfig)conf).getPath();
   		}
   		else if (conf instanceof ZipConfig)
   		{
   			 type = "Zip";
   	 		info = ((ZipConfig)conf).getPath();
   		}
   		else if (conf instanceof DatabaseConfig)
   		{
   			type = "Database";
   	 		info = ((DatabaseConfig)conf).getUrl();
   		}
   		desc = conf.getDescription();
   		if (conf.getProperties().getProperty("LOGIN") != null)
   		{
	  		properties = "Login/Password protected";
   		}
                items = conf.listFiles();
                // Enable subfolders support.
                //items = conf.listFiles(true);
                //downloadbean.setStandardLink(true);
   		downloadbean.setConfig(conf);
   		downloadbean.setVirtualPath(request.getContextPath()+"/download");
   	}
   }
%>
<html>
<head>
<script language="JavaScript" type="text/JavaScript"><!--
function loadconfig(id)
{
	location.href="<%= response.encodeURL("admin.jsp?rand="+System.currentTimeMillis()) %>&id="+escape(id);
}
//--></script>
<title>Download Sample : Folder List</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.s {  font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt}
.xs {  font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt}
.xsb {  font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; font-weight: bold}
-->
</style>
</head>

<body bgcolor="#FFFFFF" text="#000000">
<div align="center">
  <p><font face="Verdana, Arial, Helvetica, sans-serif" size="-1"><b><font color="#FF0000">-
    Download4J administration sample -</font></b></font></p>
  <form method="post" action="">
    <table width="100%" border="0" cellspacing="1" cellpadding="1" class="stable">
      <tr class="s">
        <td nowrap valign="top">Select <b>config</b> :
          <select name="selectconfig" onchange="loadconfig(this.options[selectedIndex].value);" class="xs">
            <%
          	Map configs = Repository.getInstance().getAll();
          	Iterator it = configs.keySet().iterator();
          	while (it.hasNext())
          	{
          		String id = (String) it.next();
          		if (id.equals(uid)) {
          		%>
            <option value="<%= id %>" selected><%= id %></option>
            <% } else { %>
            <option value="<%= id %>"><%= id %></option>
            <% } %> <% }
          %>
          </select>
          from repository.</td>
      </tr>
      <tr class="s">
        <td nowrap valign="top"><b>Description</b> : <%= desc %></td>
      </tr>
      <tr class="s">
        <td nowrap valign="top"><b>Type</b> : <%= type %></td>
      </tr>
      <tr class="s">
        <td nowrap valign="top"><b>Info</b> : <%= info %></td>
      </tr>
      <tr class="s">
        <td nowrap valign="top"><b>Properties</b> : <%= properties %></td>
      </tr>
      <tr>
        <td nowrap valign="top"><font face="Verdana, Arial, Helvetica, sans-serif" size="-2"><a href="javascript:loadconfig('<%= uid %>')">refresh</a></font>
        </td>
      </tr>
      <tr>
        <td>
          <table border="0" cellspacing="0" cellpadding="0" width="100%">
            <tr>
              <td bgcolor="#CCCCCC">
                <table border="0" cellspacing="1" cellpadding="2" align="center" class="xs" width="100%">
                  <tr align="center" bgcolor="#EEEEEE" valign="top" class="xsb">
                    <td> Filename </td>
                    <td> Size in bytes </td>
                    <td> Content type </td>
                    <td> Content disposition </td>
                    <td> Download Link </td>
                    <td> Total<br>
                      complete<br>
                      downloads</td>
                    <td> Total<br>
                      incomplete<br>
                      downloads</td>
                    <td> Download<br>
                      limits </td>
                    <td> Zip on fly </td>
                    <td> Password<br>
                      protected</td>
                  </tr>
                  <%
                  if (items != null)
                  {
                    for (int i=0;i<items.size();i++)
         		    {
           			  FileInfo fi = (FileInfo) items.elementAt(i);
      			  %>
                  <tr align="center" bgcolor="#FFFFFF">
                    <td> <%= fi.getFilename() %></td>
                    <td> <%= fi.getSize() %> </td>
                    <td nowrap> <%= fi.getContentType() %> </td>
                    <td nowrap> <%= fi.getContentDisposition() %> </td>
                    <td> <a href="<%= downloadbean.getDownloadLink(fi.getUrlMapping()) %>"><%= fi.getUrlMapping() %></a>
                    <td> <%= fi.getTotalDownload() %> </td>
                    <td> <%= fi.getTotalIncompleteDownload() %> </td>
                    <td> <%= fi.getMaxDownload() %> </td>
                    <td> <%= fi.isZipEnabled() %> </td>
                    <td> <% if (fi.getLogin() != null) { out.print("true"); } else { out.print("false"); } %>
                    </td>
                  </tr>
                  <% }
                  } %>
                </table>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
  </form>
</div>
</body>
</html>
