#!/usr/bin/perl -w

# $Id: linksearch.cgi,v 1.2 1996/10/23 21:56:06 sandusky Exp $

# This script was created by Signore Yarger 7/25/96.

# Add the CGI module.
require cgi_head;
# Add Mysql module.
use Mysql;
# connect to Mysql database server.
$dbh = Mysql->connect();
# Select the H-Net database.
SelectDB $dbh "H-Net";

%icons = (
	'I1' => 'Documents',
	'I2' => 'Maps',
	'I3' => 'Images',
	'I4' => 'Syllabi',
	'I5' => 'Educational Sites'
);

# If $view does not exist set $view to 'brief.'
$view = "full";

# Ask database for url titles and descriptions  that match %$key%s.
$out = Query $dbh "SELECT url, title, descr, icon FROM revlinks";

# Print the HTTP header.
&cgi_header;
print "<HTML><HEAD><TITLE>Revolution Links</title></head><BODY BACKGROUND=../PAPER01M.GIF BGCOLOR=#FFFFFF>\n";

@link = ();
$i = 0;
# Get information from $out and put into @out.
while (@out = FetchRow $out) {
	# Make three separate arrays each containing corresponding
	# information.
	$link[$i]->{'url'} = $out[0];
	$link[$i]->{'title'} = $out[1];
	$link[$i]->{'descr'} = $out[2];
	$link[$i]->{'icon'} = $out[3];
	$i++;
}

@link = sort { if ($$a{'icon'} ne $$b{'icon'}) {
		$$a{'icon'} cmp $$b{'icon'};
	} else {
		$$a{'title'} cmp $$b{'title'};
	}
} @link;

#&end("S: $#link");

print "<FONT SIZE=+4>Revolution Links</font>\n";
print "<hr>\n";
# Loop through @title until reaching the end.
foreach $i (0..$#link) {
	my $url = $link[$i]->{'url'};
	my $title = $link[$i]->{'title'};
	my $descr = $link[$i]->{'descr'};
	my $icon = $link[$i]->{'icon'};
#	&end("U: $icon{$icon}");
	if (not $i) {
		print "<UL>" . "<LI><b>$icons{$icon}</b>\n<UL>\n";
	} elsif ($icon ne $link[$i-1]->{'icon'}) {
		print "</ul></li><LI><B>$icons{$icon}</b>\n<UL>\n";
	}

	print qq%<LI><A HREF=\"$url\">$title</a><br>\n%;
	print $descr;
	print "</li>\n";
}
# print HTML stuff.
print "</ul></li></ul></body></html>";
