#!/usr/bin/perl

use CGI qw/:standard -no_xhtml/;
use CGI::Carp qw(fatalsToBrowser);
use DBI;

$driver   = "mysql";
$database = "booyone";
$host     = "localhost";

$dsn = "DBI:$driver:database=$database;$host;";
$dbh = DBI->connect($dsn, 'booy', 'yone') || die $DBI::errstr;


$JSCRIPT=<<END;
function sf(fu,title) {
	win1 = 'scrollbars,resizable,width=600,height=600')
	window.open( '/si.cgi?pic=' + fu + '&title=' + title, '', win1);
}
END

print header(-charset=>'iso-8859-2',-Pragma=>'no-cache');

print <<END;
<!DOCTYPE html
        PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="cs"><head><title>reports</title>
<meta HTTP-EQUIV="content-type" CONTENT="text/html; charset=iso-8859-2">
<link rev="made" href="mailto:marasan">
<link rel="stylesheet" type="text/css" href="/style01.css">
<script language="JavaScript" type="text/javascript">
<!-- Hide script
function sf(fu,title) {
        window.open( '/si.cgi?pic=' + fu + '&title=' + title, '', 'scrollbars,resizable,width=600,height=600');
}
// End script hiding -->
</script>
</head><body text="white" leftmargin="0" topmargin="0" bottommargin="0" bgcolor="#161616" rightmargin="0">
END

#print start_html(	-title=>'reports',
#			-lang=>'cs',
#			-author=>'marasan',
#			-style=>{'src'=>'/style01.css'},
#			-script=>$JSCRIPT,
#			-text=>'white',
#			-topmargin=>'0',
#			-leftmargin=>'0',
#			-rightmargin=>'0',
#			-bottommargin=>'0',
#			-BGCOLOR=>'#161616');

print <<END;
<table border="0" cellpadding="25" cellspacing="0" width="100%">
<tr>	<td>
END
#                    0     1      2      3       4     5      6      7       8      9
$dotaz = "select nabbr, name, bdate, edate, rprt+0, purl, place, genre, pics+0, descr from party where bdate < NOW() order by bdate desc";

$sth = $dbh->prepare($dotaz) || die $sth->errstr;
$sth->execute || die $sth->errstr;

my $datum = '';

# konstanty
# 2 .. ikona
# 1 .. flyer
# 4 .. mapa

while($radek = $sth->fetchrow_arrayref()) {
        if ($$radek[2] eq $$radek[3]) {
                $datum = $$radek[2];
                $datum =~ s/(....)-(..)-(..)/$3.$2.$1/ ;
        } else {
                $datum = "$$radek[2]<br>- $$radek[3]";
                $datum =~ s/(....)-(..)-(..)(......)(....)-(..)-(..)/$3.$2.$1$4$7.$6.$5/ ;
        }

        my $flicon;

        if ($$radek[8] & 2) {   # existuje ikona
                $flicon = '<img src="'.$$radek[5].'/flyer_ico.jpg" border="0" alt="flyer icon">';
        } else {                # zadna ikona
                $flicon = '<img src="/parties/ico_empty.jpg" border="0" alt="flyer icon">';
        }

        my $flline;

        if ($$radek[8] & 1) {   # existuje flyer
                if ($$radek[8] & 2) {   # je i ikona
                        $flline = '<a title="flyer" href="javascript:sf(' . "'" . $$radek[5] . "/flyer.jpg','" . $$radek[1] . "')" . '">'. $flicon . '</a>';
                } else {                # neni ikona
                        $flline = '<br><font size="1"><a title="flyer" href="javascript:sf(' . "'" . $$radek[5]
                                . "/flyer.jpg','" . $$radek[1] . "')" . '">flyer</a></font>';
                }
        } else {                # neni flyer
                $flline = $flicon;
        }

	my $reporty = '';

# konstanty - reporty
# 4 .. partyreport
#
	if ($$radek[4] & 1) {	# je pplrep
		$reporty .= <<END;
		<a title="people (fotoreport)" href="$$radek[5]/people.html" target="if0"><img src="$$radek[5]/rep_people/repico.jpg" border="0" alt="report icon"></a>

END
	}
		
	if ($$radek[4] & 4) {	# je partyrep
		$reporty .= <<END;
		<a title="party (fotoreport)" href="$$radek[5]/party.html" target="if0"><img src="$$radek[5]/rep_party/repico.jpg" border="0" alt="report icon"></a>
		
END
	}


	if ($$radek[4] & 2) {	# je techrep
		$reporty .= <<END;
		<a title="tech (fotoreport)" href="$$radek[5]/tech.html" target="if0"><img src="$$radek[5]/rep_tech/repico.jpg" border="0" alt="report icon"></a>
		
END
	}
	
	print <<END;
	<a name="$$radek[0]"></a>
	<table width="100%" cellpadding="3" cellspacing="1">
	<tr>	<td bgcolor="#2c2c2c" valign="top" width="80">
			<table width="100%" cellpadding="3" cellspacing="0">
			<tr>	<td align="right"><font size="1">$datum</font></td></tr>
			<tr>	<td align="center">$flline</td></tr>
			</table></td>
		<td valign="top" bgcolor="#242424">
			<table width="100%" cellpadding="3" cellspacing="0">
			<tr>	<td><font size="2"><b>$$radek[1]</b></font><font size="1"> ($$radek[7])</font></td></tr>
			<tr>	<td>$reporty</td></tr>
			<tr>	<td valign="top" class="stw"><font size="1">$$radek[9]<br><br>$$radek[6]</font></td></tr>
		</table></td>
	</tr>
	</table>
END
}



$dbh->disconnect();

print "\n</td></tr></table>\n",end_html;
