#!/usr/bin/perl -w

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

our $REVIEWS_DIR = "/web/www.strictlybluegrass.com/www/2005/reviews";
our $DISPLAY_TIMES = 0;

sub header
{
    my $title = shift;

    if ( ! $title )
	{ $title = "Hardly Strictly Bluegrass Festival 5: Sep 30 - Oct 2, 2005"; }

    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 5 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 $key = $query->param('key');
my $title;

print $query->header;

$title = "SBF 2005: Reviews";

if ( $key && -e "$REVIEWS_DIR/${key}.txt" )
    { $title = "SBF 2005: $SBF_2005::ARTISTS{$key}->{NAME} Review"; }

header ($title);

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

    foreach my $dref ( @SBF_2005::SCHEDULE )
    {
        if ( $key && $key ne $dref->{DATE} )
            { next; }

        print <<_EOF_;
<TABLE CLASS="schedule" CELLPADDING=4 CELLSPACING=1 BORDER=0 WIDTH="550">
<TR>
    <TH COLSPAN=3 WIDTH="25%" BGCOLOR="#C8C296" CLASS="table_header">
    $dref->{DATE} ($dref->{TIME})
    </TH>
</TR>
<TR VALIGN="top">
_EOF_

        if ( $dref->{NOTES} )
        {
            print <<_EOF_;
<TD COLSPAN=3>
$dref->{NOTES}
</TD>
</TR>
_EOF_
        }

        print <<_EOF_;
</TABLE>
_EOF_

        my $stages_per_line = 2;
        my $cur_stage_num = 0;

        print <<_EOF_;
<TABLE CLASS="schedule" CELLPADDING=4 CELLSPACING=1 BORDER=0 WIDTH="550">
_EOF_

        foreach my $sref ( @{$dref->{STAGES}} )
        {
	    my $file = sprintf "%s-%s", $sref->{NAME}, $dref->{DATE};
	    my $first = 1;

	    $file =~ s/ /_/g;

	    if ( ! -e "$REVIEWS_DIR/${file}.txt" )
	    {
		print "<TR><TD><B>$sref->{NAME} - REVIEW COMING SOON</B><BR>\n";
		next;
	    }

	    print "<TR><TD><U><B><A HREF=\"$ENV{SCRIPT_NAME}?key=${file}\">$sref->{NAME} - READ REVIEW</A></B></U><BR>\n";

            foreach my $art ( @{$sref->{ARTISTS}} )
            {
                my $showtime;
                if ( $art =~ /^(.+)\|(.+)$/ )
                {
                    $art = $1;
                    $showtime = $2;
                }

                if ( ! $DISPLAY_TIMES )
                    { undef $showtime; }

                my $aref = $SBF_2005::ARTISTS{$art};
		if ( ! $first ) { print ", "; }
                if ( $showtime )
                    { print "$showtime "; }
                printf "%s\n", $aref ? $aref->{NAME} : $art;

		$first = 0;
            }

	    print "</TD></TR>\n";
	}
    }
    print "</TABLE>\n";

}

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