#!/usr/bin/perl

require "/hfradio/html/cgi-bin/get_form_data.pl";		#sub for getting form data

$databasePath = "/hfradio/database/links/";
$ham_cat_dx_personal = $databasePath . "swl_master.txt\tShortwave Listing Links";
$ham_cat_dx_resource = $databasePath . "dx_rsrc.txt\tDX Resources";

$styleSheet = "/home/hfradio/html/cgi-bin/styles.format";
$theMenu = "/home/hfradio/html/cgi-bin/menu.format";

###

$theLinks = "<a href=\"http://hfradio.org/hffreq\" target=\"swlWin\">Lookup International Shortwave Broadcast Stations by Frequency, etc.</a>";

$html_header = "Content-type: text/html\n\n";

$mail_prog = "/usr/lib/sendmail";
$email_ID_to = "nw7us\@hfradio.org";
$email_ID_from = "nw7us\@hfradio.org";

$theDate = `date +%m-%d-%Y`;
$theDate =~ tr/\n\r//d;
$theTime = `date +%H:%M:%S`;
 
print $html_header;

#&get_form_data (*form_data);	# Get form data

#$date = $form_data{'date'};

open (STYLE, "$styleSheet") || die "Could not read $styleSheet: $!\n";
$_style = "";
while (<STYLE>) {
	$_style .= $_;
}
close (STYLE);

open (MENU, "$theMenu") || die "Could not read $theMenu: $!\n";
$_menu = "";
while (<MENU>) {
	$_menu .= $_;
}
close (MENU);

$solarReport = "";

doSolarData();


sub doSolarData {

	$solarReport = "";

	$solarReport = "<small>| Current Solar Flux: <b>";
	open (PIN, "/hfradio/html/prop/.flux.txt");
	my ($line) = "";
	while (<PIN>) {
		$line = $_;
		$line =~ tr/\n\r\t//d;
		$solarReport .= $line;
	};
	close(PIN);
	$solarReport .= "</b> |<br>\n| A-index: <b>";
	open (PIN, "/hfradio/html/prop/.aindex.txt");
	while (<PIN>) {
		$line = $_;
		$line =~ tr/\n\r\t//d;
		$solarReport .= $line;
	};
	close(PIN);
	$solarReport .= "</b> | K-index: <b>";
	open (PIN, "/hfradio/html/prop/.kindex.txt");
	while (<PIN>) {
		$line = $_;
		$line =~ tr/\n\r\t//d;
		$solarReport .= $line;
	};
	close(PIN);
	$solarReport .= "</b> | Aurora: <b>";
	open (PIN, "/hfradio/html/prop/.aurora_level.txt");
	while (<PIN>) {
		$line = $_;
		$line =~ tr/\n\r\t//d;
		$solarReport .= $line;
	};
	close(PIN);
	$solarReport .= "</b> | <a href=\"http://hfradio.org/propagation.html\">more...</a> |</small>\n";

}

sub mailIt {
	open (MAIL, "|$mail_prog -t -oi") || die "Can't open mail_prog: $mail_prog\n";

	print MAIL "To: $email_ID_to\n";
	print MAIL "Reply-To: $email_ID_to\n";
	print MAIL "Subject: hfradio.org survey\n";
	print MAIL "From: $email_ID_from\n\n";

	print MAIL "Submitted on $theDate at $theTime\n\n";
	close (MAIL);
}

# --- start

sub getCat {

	my ($dataIn) = @_;

	my ($fileName,$theCatName) = split(/\t/,$dataIn);
	
	open (INP, "$fileName") || die "Could not open $fileName\n";

	my (%catListing) = ();

	while (<INP>) {
		my ($link,$desc,$isActive) = split(/\t/,$_);
		$isActive =~ tr/\n\r//d;
		if ($isActive =~ m|a|i) {
			$catListing{$desc} = $link;
#			print "\n[$link] => [$desc]\n";
		}
	}
	
	close (INP);

	%catListing;
}

sub htmlStart {

	my ($theTitle) = @_;

	print qq^
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>$theTitle</title>
$_style
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
^;
	print qq!
<BODY background="http://hfradio.org/graphics/backmap.gif" bgcolor="#FFFFFF">
!;

	print <<F2;
<table width="100%"><tr>
<td valign=top>
<img src="http://hfradio.org/graphics/hfr-l.gif" width=171 height=82 border=0 alt="hfradio.org" vspace="0"><br>
<img src="http://hfradio.org/graphics/links.gif" width=168 height=30 border=0 alt="SWL Links from NW7US" vspace="0">
</td>
<td>
$_menu
<br>
<div class="menu" align="center">
$solarReport
</div>
</td>
</tr>
</table>
<hr noshade>
F2

}

sub htmlEnd {

	print <<F3;
<br clear=all>
<hr noshade>
$_menu
<hr noshade>
<br>
<div align="center" class="menu">
copyright, 1999, 2000, 2001, 2002, 2003, <a href="http://hfradio.org/commentform.html">Tomas Hood</a> (NW7US), all rights reserved.<br><br>
</div>

<!-- BEGIN LINKEXCHANGE CODE --> 
<center><iframe src="http://leader.linkexchange.com/11/X1063193/showiframe?" width="468" height="60" marginwidth="0" marginheight="0" frameborder="0" scrolling="no">
<a href="http://leader.linkexchange.com/11/X1063193/clickle" target="leWin"><img width="468" height="60" border="0" ismap alt="" src="http://leader.linkexchange.com/11/X1063193/showle?"></a></iframe><br><a href="http://leader.linkexchange.com/11/X1063193/clicklogo" target="leWin"><img src="http://leader.linkexchange.com/11/X1063193/showlogo?" width="468" height="16" border="0" ismap alt=""></a><br></center>
<!-- END LINKEXCHANGE CODE -->

F3
	print "</body></html>\n";
}

sub htmlCatHead {

	my ($theTitle) = @_;

	print qq!<div align="center">
<b>$theTitle</b>
</div>
<br>
!;
}

$fontStart = "";
$fontEnd   = "";

&htmlStart("HF Radio - SWL Links");

print <<F1;
<div align="center">
<b>Shortwave Listing Links</b>
<br><br>
If you wish to be listed, please <a href='http://hfradio.org/commentform.html'>email me</a>.
<br><br>
This page is generated from a database.  I will be adding links that I feel are of great value and quality.
I am looking for great pages, so please let me know if you have one, or know of one I should list.
<br><br>
Check out my new <a href="http://swl.hfradio.org/" target="newWin">Shortwave Radio Resource Center</a>.

<br><br>
See: $theLinks<br>
<br>
Another place to visit:<br>
<a href="http://hfradio.org/redir/?redir=www.w9wze.org/SWL/" target="oWin"><img src="http://hfradio.org/graphics/Jeepwco.gif" width=600 height=73 border=0 alt="the Hallicrafters Radio collector website"><br>
The Hallicrafters Radio fan site</a>
<br>
</div>
<br>
F1

%curListing = &getCat($ham_cat_dx_personal);

($fname,$listName) = split(/\t/,$ham_cat_dx_personal);

&htmlCatHead($listName);

print "<blockquote>\n";
print "<ul>\n";

foreach $key (sort(keys(%curListing))) {
	my $listing = $curListing{$key};
	if ($listing =~ m|^http\://|i) {
		$listing =~ m|^http://(.*)|i;
		$listing = $1;
	}
	print "<li><a href=\"http://$listing\" target=\"linkWin\">$key</a><br>\n";
}

print "</ul>\n";
print "</blockquote>\n\n";


&htmlEnd;
