#!/usr/bin/perl -w
#
# cruise-report-list script

# Creates html output from inventory data of available cruise reports.

# July 27, 2009.  V2.01.  Changed selection criteria to look for "line"
#  	instead of "on-line" to catch new entries.  mda + rcg
# June 3, 2005.  V2.00.  Rewrite as Perl script.  Replace defrpt_url
#	with call to openJGdata.pl.  rcg
# June 23, 1999.  V1.41  Revert back to using defrpt_url.  Cannot get
#	object to be read in.  rcg
# June 23, 1999.  V1.4 Use list to get at data rather than defrpt_url.  
#	Data in is changed to an object rather than the data file. RCG
# January 19, 1999.  V1.3 Move start of hlml header to beginning of script
# so any error messages might appear to user.  Change REMOTE_HOST to
# REMOTE_ADDR in defining temporary file name since not all systems
# make the host name available.  Replace temp-dir with /tmp and add
# script name to file name.  rcg
# December 1, 1998.  Replace underscores with blanks before output. rcg
# March 20, 1998.  Use /data5 not /data.  Try using defgb, but nogood.
#	Still need defrpt_url.
# 1996/01/23 RCG

$version="July 27, 2009-V2.01";

unshift (@INC, "/data/rgroman/perllib");
        require ('openJGdata.pl');

print STDOUT ("Content-type: text/html\n\n");

$projection = 'project, platform, description';
$selection = 'data_type=cruise_report, status%20contains%20line';

$status = &openJGdata(1, '/globec/gb/inventory', $projection,
	$selection, '-c -n -b -t');

unless ($status) {
	print STDOUT ("<p>There was a problem accessing the inventory.  ",
		"The error message was <p><dir>$status</dir><p>\n");
	exit;
}

print STDOUT <<INTRO;
<title> Cruise Reports</title>
<head>"
<h2 align=center>Cruise Reports</h2>
</head>
Click on the link to review on-line cruise reports.  Note that in
some cases the figures, tables and other images may not yet be
available and you will receive a message that the link 
has not been
found.  The text is searchable using whatever search (or find)
capabilities are available in your browser.

<body>
<p>Many of these reports were converted directly to 
Web format and would
benefit from  tailoring for on-line use. 

<hr>

<p>
<table border=0 width=75%>
<tr align=center><th colspan=3><font size=+1>
	Cruise reports available on-line</font></th></tr>
<tr><td colspan=3><br></td></tr>
<tr align=left><th>Project</th> <th>Platform</th> <th>Description</th></tr>


INTRO


foreach $record (<JGDATA1>) {
	chomp $record;
	$record =~ s/"//g;
#	print STDOUT ("<br>***debug, record=$record<br>\n");
	@record = split /\t/, $record;
	print STDOUT ("<tr>");
	foreach $item (@record) {
		$item =~ s/_/ /g;
		print STDOUT ("<td>$item</td> ");
	}
	print STDOUT ("</tr>\n");
}
print STDOUT (	"</table>\n");

print STDOUT ("</p><p><hr>\n");

close JGDATA1;

$projection = 'project, platform, siname, description';
$selection = 'data_type=cruise_report, status=printed';

$status = &openJGdata(1, '/globec/gb/inventory', $projection,
	$selection, '-c -n -b -t');

unless ($status) {
	print STDOUT ("<p>There was a problem accessing the inventory.  ",
		"The error message was <p><dir>$status</dir><p>\n");
	exit;
}

print STDOUT ("<p>", 
	"<table border=0 width=80%>");
print STDOUT ("<tr align=center><th colspan=3><font size=+1>Cruise reports ",
	"will be available for all cruises</font></th></tr>\n");
print STDOUT ("<tr><td colspan=3><br></td></tr>\n");
print STDOUT ("<tr align=left><th>Project</th> <th>Platform</th> <th>SI Name</th>",
			" <th>Length</th></tr>\n");

foreach $record (<JGDATA1>) {
	chomp $record;
	$record =~ s/"//g;
	@record = split /\t/, $record;
	print STDOUT ("<tr>");
	foreach $item (@record) {
		$item =~ s/_/ /g;
		print STDOUT ("<td>$item</td> ");
	}
	print STDOUT ("</tr>\n");
}
print STDOUT (	"</table>\n");

close JGDATA1;

print STDOUT ("<p><hr><i>Version: $version</i><p>\n</body>\n</html>\n");


