#!/usr/bin/perl

use CGI qw/:standard -no_xhtml -debug/;
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) {
	window.open( '/si.cgi?pic=' + fu + '&title=' + title, '', 'scrollbars,resizable,width=600,height=600');
}
END
# default_dtd( '-//W3C//DTD HTML 4.01 Transitional//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd' );

$DEFAULT_DTD = [ '-//W3C//DTD HTML 4.01 Transitional//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd' ] ;
		     
		     
print header(-charset=>'iso8859-2');
print start_html(	-title=>'partylist',
			-lang=>'cs',
			-author=>'marasan',
			-style=>{'src'=>'/style01.css'},
			-script=>$JSCRIPT,
			-text=>'white',
			-topmargin=>'0',
			-leftmargin=>'0',
			-rightmargin=>'0',
			-bottommargin=>'0',
			-BGCOLOR=>'#161616',
			-dtd=>'-//W3C//DTD HTML 4.01 Transitional//EN');


print <<END;
<table border="0" cellpadding="25" cellspacing="0" width="100%">
<tr><td>
END

#			0      1       2      3     4     5      6       7     8      9
my $dotaz = "select bdate, edate, tstamp, place, name, purl, nabbr, genre, pics+0, descr from party where bdate >= NOW() order by bdate";

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

my $datum = '';

while($radek = $sth->fetchrow_arrayref()) {
	if ($$radek[0] eq $$radek[1]) {
		$datum = $$radek[0];
		$datum =~ s/(....)-(..)-(..)/$3.$2.$1/ ;
	} else {
		$datum = "$$radek[0]<br>- $$radek[1]";
		$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">';
	} else { 		# zadna ikona
		$flicon = '<img src="/parties/ico_empty.jpg" border="0">';
	}

	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[4] . "')" . '">'. $flicon . '</a>';
		} else {		# neni ikona
			$flline = '<br><font size="1"><a title="flyer" href="javascript:sf(' . "'" . $$radek[5] 
				. "/flyer.jpg','" . $$radek[4] . "')" . '">flyer</a></font>';
		}
	} else {		# neni flyer
		$flline = $flicon;
	}
	print <<END;
	<a name="$$radek[6]"></a>
	<table width="100%" cellpadding="3" cellspacing="1">
	<tr>	<td bgcolor="#2c2c2c" valign="top" width="90">
			<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[4]</b></font><font size="1"> ($$radek[7])</font></td></tr>
				<td valign="top" class="ztw"><font size="1">místo: $$radek[3] $$radek[9]</font></td></tr>
		</table></td>
	</tr>
	</table>
		
END
	
}

$dbh->disconnect();

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