#!/usr/bin/perl -w

use strict;
use CGI;
use SBF_2004;
use Image::Size;
use FileHandle;

our $REVIEWS_DIR = "/web/www.strictlybluegrass.com/www/2004/reviews";
our $DISPLAY_TIMES = 1;

sub header
{
    my $title = shift;

    if ( ! $title )
	{ $title = "Hardly Strictly Bluegrass Festival 4: Oct 1 - 3, 2004"; }

    print <<_EOF_;
<HTML>

<HEAD>
<TITLE>
$title
</TITLE>
</HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!--

function photo_popup (which, num)
{
    window.open ("gallery/photoshow.cgi?show=" + which + "&num=" + num, 'sbf_pix',
        'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=1,width=630,height=630');
    return false;
}

function art_popup (artist)
{
    var win = window.open ("$ENV{SCRIPT_NAME}?show=artists&key=" + artist + "&popup=1",
	'art_popup',
	'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=300,height=300');
    win.focus();
    return false;
}
// -->
</SCRIPT>

<STYLE TYPE="text/css">
<!-- 
body, p, table, div {
    font-family: Trebuchet MS, arial, helvetica, sans-serif;
    font-size: 11px;
}
b.artist_name { font-size: 14px; }

ul.artist_list { margin: 0.5em 0 0 0; padding: 0; }
ul.artist_list li {
    list-style-type: none;
    margin: 0 0 0.5em 1em;
    padding: 0;
    text-indent: -1em;
}

.table_header {
    border: 1px solid black;
    text-transform: uppercase;
    font-size: 11px;
    color: #4C4C19;
    background-color: #C8C296;
}

a:link { color: #473E16; text-decoration: none; }
a:link:hover { color: #0000FF; text-decoration: underline; }
a:visited { color: #473E16; text-decoration: none; }
a:visited:hover { color: #0000FF; text-decoration: underline; }

// -->
</STYLE>

</HEAD>


_EOF_

    print <<_EOF_;
<BODY BGCOLOR="#000000">
<DIV ALIGN="center">

<TABLE WIDTH="600" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
    <TD WIDTH="600" COLSPAN="3"><IMG ALT="" SRC="/2003/images/frame-top.jpg" WIDTH=600 HEIGHT="25"></TD>
</TR>

<TR>
    <TD BACKGROUND="/2003/images/frame-left.jpg" WIDTH="25"><IMG
	ALT=""
	WIDTH=25 HEIGHT="350"
	SRC="/2003/images/frame-left.jpg"></TD>
    <TD BGCOLOR="#F2E9C0" WIDTH="550">
	<IMG SRC="/2003/images/spacer.gif" WIDTH="550" HEIGHT="1"><BR>
	<FONT FACE="times">
	<TABLE WIDTH=550 BORDER=0 CELLPADDING=0 CELLSPACING=0>
	<TR>
	    <TD><IMG
		BORDER="0"
		ALT=""
		SRC="/2003/images/header-pic.gif"
		WIDTH=118 HEIGHT=150 BORDER=0></TD>
	    <TD><A HREF="/"><IMG
		BORDER="0"
		ALT=""
		WIDTH=432 HEIGHT=126
		SRC="images/header-txt.gif"></A></TD>
	</TR>
	</TABLE>

	<BR>

	<TABLE WIDTH="550" HEIGHT="444" BACKGROUND="/2003/images/bg-house.gif" CELLSPACING="0" CELLPADDING="0">
	<TR VALIGN="top">
	    <TD WIDTH="550">

	    <P ALIGN=center>
	    <FONT SIZE=3>
	    Hardly Strictly Bluegrass 4 Reviews
	    </FONT>
	    </P>

_EOF_
}

sub footer
{
    print <<_EOF_;
	    <P>
	    </TD>
	</TR>
	<TR>
	    <TD VALIGN=bottom>

	    <TABLE WIDTH="550" BORDER="0" CELLSPACING="0" CELLPADDING="0">
	    <TR>
		<TD ALIGN=left>
		    [ <A HREF="/">home page</A> ]
		</TD>
		<TD ALIGN=right>
		    [ site by <A TARGET="chime"
			HREF="http://www.chimeinteractive.com/">chime interactive</A> ]
		</TD>
	    </TR>
	    </TABLE>

	    </TD>
	</TR>
	</TABLE>
	</FONT>
    </TD>
    <TD BACKGROUND="/2003/images/frame-right.jpg" WIDTH="25"><IMG
	ALT="" WIDTH="25" HEIGHT="350"
	SRC="/2003/images/frame-right.jpg"></TD>
</TR>

<TR>
    <TD WIDTH="600" COLSPAN="3"><IMG ALT="" SRC="/2003/images/frame-bottom.jpg" WIDTH=600 HEIGHT="25"></TD>
</TR>
</TABLE>

</DIV>
</BODY>
</HTML>
_EOF_
}

sub plays
{
    my $artist = shift;
    my $inc_link = shift;
    my @schedule = (@_);
    my $str = '';

    foreach my $dref ( @schedule )
    {
#	print "DATE: $dref->{DATE}\n";
	foreach my $sref ( @{$dref->{STAGES}} )
	{
#	    print "Stage: $sref->{NAME}\n";
	    foreach my $art ( @{$sref->{ARTISTS}} )
	    {
		my $st = '';
		my $aname = $art;

		if ( $art =~ /^(.+)\|(.+)$/ )
		{
		    $aname = $1;
		    $st = " ($2)";
		}

		if ( ! $DISPLAY_TIMES )
		    { undef $st; }
		     
		if ( $artist eq $aname )
		{
		    my $ed = CGI::escape ($dref->{DATE});
		    if ( $str ) { $str .= "<BR>\n"; }
		    if ( $inc_link )
		    {
			$str .= "  <A TARGET='sbf_main' HREF=\"$ENV{SCRIPT_NAME}?show=day&key=$ed\">$dref->{DATE}</A>, $sref->{NAME}${st}\n";
		    }
		    else
		    {
			$str .= "  $dref->{DATE}, $sref->{NAME}${st}\n";
		    }
		}
	    }
	}
    }

    return $str;
}

###
## MAIN BODY
###

my $query = new CGI;
my $artist = $query->param('artist');
my $title;

print $query->header;

$title = "SBF 2004: Reviews";

if ( $artist && -e "$REVIEWS_DIR/${artist}.html" )
    { $title = "SBF 2004: $SBF_2004::ARTISTS{$artist}->{NAME} Review"; }

header ($title);

if ( $artist )
{
    my $fh = new FileHandle ("$REVIEWS_DIR/${artist}.html");
    while ( <$fh> ) { print; }
    print "<P><A HREF=\"$ENV{SCRIPT_NAME}\">[ More Reviews ]</A></P><BR>\n";
}
else # ( ! $artist ) 
{
    print <<_EOF_;
<P>
Please select one of the following reviews from the 2004 festival:
</P>
_EOF_

    foreach my $key ( sort { 
	    my $cmp_a = uc($SBF_2004::ARTISTS{$a}->{NAME});
	    my $cmp_b = uc($SBF_2004::ARTISTS{$b}->{NAME});

	    ## skip over any leading html tags
	    $cmp_a =~ s/^<[^>]+>//;
	    $cmp_b =~ s/^<[^>]+>//;

	    ## skip leading "the"
	    $cmp_a =~ s/^The //i;
	    $cmp_b =~ s/^The //i;

	    $cmp_a cmp $cmp_b;
	} keys (%SBF_2004::ARTISTS) )
    {
	my $art = $SBF_2004::ARTISTS{$key};

	if ( ! -e "$REVIEWS_DIR/${key}.html" )
	    { next; }

	print <<_EOF_;
<A HREF="$ENV{SCRIPT_NAME}?artist=$key">$art->{NAME}</A>
_EOF_
	print "<BR>\n";

    }
}

print "<BR>\n";
footer ();
