<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>FatRat - browse files</title>
<link rel="icon" href="/favicon.png" type="image/png"/>
<link rel="stylesheet" type="text/css" href="/style.css"/>
</head>
<body>

<p style="text-align: center"><b>Browse files</b></p>
<pre style="text-align: center"><?qs print(GET.path); ?></pre>

<table class="transfers">
<thead>
<tr><td>File name</td><td>Size</td></tr>
</thead>

<tbody>
<?qs
	var queue, transfer;
	for(var i=0;i<QUEUES.length;i++)
	{
		queue = QUEUES[i];
		for(var j=0;j<queue.size;j++)
		{
			if(queue.at(j).uuid == GET.transfer)
			{
				transfer = queue.at(j);
				break;
			}
		}
	}
	
	var files = listDirectory(transfer.dataPath + GET.path);
	
	function list(dirs)
	{
		for(i=0;i<files.length;i++)
		{
			path = GET.path + '/' + files[i];
			info = fileInfo(transfer.dataPath + path);
			
			if(info.directory != dirs)
				continue;
			
			if(info.directory)
			{
				print('<tr><td><a href="?transfer='+GET.transfer+'&amp;path='+path+'">['+ files[i] + ']</a></td><td>&lt;DIR&gt;</td></tr>');
			}
			else
			{
				size = formatSize(info.size, false);
				print('<tr><td><a href="/download?transfer='+GET.transfer+'&amp;path='+path+'">'+files[i]+'</a></td><td>'+size+'</td></tr>');
			}
		}
	}
	
	if(GET.path != '')
	{
		x = GET.path.lastIndexOf('/');
		path = GET.path.substring(0, x);
		
		print('<tr><td><a href="?transfer='+GET.transfer+'&amp;path='+path+'">[..]</a></td><td>&lt;DIR&gt;</td></tr>');
	}
	
	list(true);
	list(false);
?>
</tbody>
</table>

<p style="text-align: center">
	<input type="button" value="Close" onclick="javascript:window.close()"/>
</p>

</body></html>
