#!/usr/local/bin/perl5 -w
#	List Parameter Sets
#
require "cgi-lib.pl";
#
$statusofread =  &ReadParse(*formdata);
#
if( $statusofread )	{
	$userdir = 'defaultuser';
	if( exists($formdata{"username"}) ) {
	        $userdir = $formdata{"username"} if( defined($formdata{"username"}) );
	}
	$testuserdir = $userdir;
	$testuserdir =~ tr/A-Z/a-z/;
	if( ($testuserdir eq 'guest') || ($testuserdir =~ m%^anon%) )   {
	        $userdir = 'defaultuser';
	}
#
#       Base URL
	$fileforparmstore = "/usr/local/archives/public/html/users/gcf/nobody/webwisdom/";
#
	$today =`date`;
	chomp($today);
#
	$fileforparmstore .= $userdir . '/parmsets';
	&getlist();
#
	$parmstoreerrorflag=0;
#
	print <<EOF;
Content-Type: text/html

<html>
<head>
<title>Returned List of Available Parameter Sets</title>
<script language="JavaScript">
<!--scriptbegin
function sethostfilevalues()     {
	var totalnumber = document.forms[0].elements[0].value;
	top.bigboss.hostfilemenu.count = totalnumber;
	top.bigboss.hostfilemenu.menuselection =1;
	for( var i=0; i < totalnumber; i++)     {
		var whatwewant = document.forms[0].elements[i+1].value;
		top.bigboss.hostfilemenu.options[i+1] = whatwewant;
		if( whatwewant == top.bigboss.currentparameters.hostfilename )
			top.bigboss.hostfilemenu.menuselection = i+1;
	}
}
//scriptend-->
</script>
</head>
<script language="JavaScript">
<!--scriptbegin
document.writeln('<body background="' + top.bigboss.wisdomhomeurl + '../background/' + top.bigboss.currentparameters.bgfile + '"  >');
document.writeln('<font size=3 color="' + top.bigboss.currentparameters.imgfgcolor + '" >');
//scriptend-->
</script>
<H2>This File lists Available Files for UserName $userdir in a Form</H2>
<b>Only First 20 Files are Listed -- Most recent Selected</b>
<form name="listoffiles" >
EOF
#
	print 'Number of Files<input name="numfiles" type="text" size="40" value="' . $countoffiles . '" ><br>' ."\n";
	for($i=0;$i<$countoffiles;$i++)	{
		$file = $chompedfiles[$i];
		print 'File '.$i. '<input name="file' .$i. '" type="text" size="40" value="' . $file . '" ><br>' ."\n";
	}
        print <<EOF;
</form>
<script language="JavaScript">
<!--scriptbegin
sethostfilevalues();
//scriptend-->
</script>
</body>
</html>
EOF
#
}
else	{
	$parmstoreerrorflag=1;
	print "Location: http://www.npac.syr.edu/users/gcf/webwisdom/ListError.html\n\n";
}
#
sub getlist	{
#
	@listoffiles = `ls -t $fileforparmstore`;
	$countoffiles=0;
	foreach $file (@listoffiles)	{
	        chomp($file);
	        next unless $file;
		$chompedfiles[$countoffiles] = $file;
	        $countoffiles++;
	}
	$countoffiles =20 if( $countoffiles > 20 );
}
#
1;

