#!/usr/bin/perl
#################################################################################
# Custom built report archive script
#
# Designed and coded by L-s-L for Brum2600.net v0.1
################################################################################
use CGI;
$q=CGI::new();
$month=$q->param("month");
$year=$q->param("year");

#####checking###########

if ($month=~/Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec/ && $year=~/11|10|09|08|07|06|05|04|03|02|01/){
&happy;
}
elsif ($month eq "latest"){
&happy
}
else{
&error("fuckyou");
}

sub happy{
if ($month eq "latest"){
open (IN, "latest.lsl");
@in=(<IN>);
close(IN);
$date=@in[0];
chomp($date);
}
else{
$date="$month$year";
}
#$file="$date";

open (REP, "../reports/$date") || &filenotfound;
@rep=(<REP>);
close(REP);
foreach $elem (@rep){
if($elem eq "\n"){	
$elem="$elem<p/>";
}
else{
$elem="$elem<br/>";
}
for($elem){s/€/"/g; };
push @rep2,$elem;
}
############################IMG Processing################
opendir(IMG,"../Photos/$date");
# ||die &error;
@imglist=readdir(IMG);

#shift (@imglist);
#shift (@imglist);

foreach $img (@imglist){
if ($img =~ /JPG|jpg|gif|GIF/){
$imstr=qq{<a href="../Photos/$date/$img"><img src="../Photos/$date/$img" height="100" width="100"></a>};
push @dispimg,$imstr;
} #new
}


#########################################################
print "Content-type:text/html\n\n";
print <<"END";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<title>Brum 2600 Report for $date</title>
<link href="../stylesheet.css" rel="stylesheet">

</head>
<body>
<div id="top">
<img src="../brumnet.gif">
</div>

<div id="nav">
<ul>
<li><strong><a href="http://www.brum2600.net">Home</a></strong>
<li><a href="../cgi-bin/brum2600.cgi?month=latest">Latest Report</a>
<li><a href="../reports.html">Report Archive</a>
<li><a href="../info.html">Meeting Info</a>
<li><a href="../projects">Projects</a>
<li><a href="../links.html">Links</a>


<li><a href="http://mail.brum2600.net/mailman/listinfo/crew_brum2600.net">Mailing Lists</a>
</ul>
</div>
<div id="center">
<div class="par1">
$date Meeting Report.
</div>

@rep2
<p/>
<div class="par1">
Images.
</div>
<p/>
@dispimg
</div>
<div id="footer">
All Pages (C) Brum2600 2005.  Brum2600 is a non profit making organisation that exists for free information exhange. We do not commit or condone actions illegal under British or International law.
</div>
</body>
</html>

END
exit;
}#end of happy

sub error{
print "Content-type:text/html\n\n";
print <<"END";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<title>Brum 2600 Report for $date</title>
<link href="../stylesheet.css" rel="stylesheet">

</head>
<body>
<div id="top">
<img src="../brumnet.gif">
</div>

<div id="nav">
<ul>

<li><strong><a href="http://www.brum2600.net">Home</a></strong>
<li><a href="../cgi-bin/brum2600.cgi?month=latest">Latest Report</a>
<li><a href="../reports.html">Report Archive</a>
<li><a href="../info.html">Meeting Info</a>
<li><a href="../projects">Projects</a>
<li><a href="../links.html">Links</a>


<li><a href="http://mail.brum2600.net/mailman/listinfo/crew_brum2600.net">Mailing Lists</a>
</ul>
</div>
<div id="center">
<div class="par1">
Stop!!
</div>
Something has gone wrong. Please report cause of error to webmaster. $date
</div>
<div id="footer">
All Pages (C) Brum2600 2005.  Brum2600 is a non profit making organisation that exists for free information exhange. We do not commit or condone actions illegal under British or International law.
</div>
</body>
</html>
END
exit;
}



sub filenotfound{
print "Content-type:text/html\n\n";
print <<"END";
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<title>Brum 2600 Report for $date</title>
<link href="../stylesheet.css" rel="stylesheet">

</head>
<body>
<div id="top">
<img src="../brumnet.gif">
</div>

<div id="nav">
<ul>

<li><strong><a href="http://www.brum2600.net">Home</a></strong>
<li><a href="../cgi-bin/brum2600.cgi?month=latest">Latest Report</a>
<li><a href="../reports.html">Report Archive</a>
<li><a href="../info.html">Meeting Info</a>
<li><a href="../projects">Projects</a>
<li><a href="../links.html">Links</a>


<li><a href="http://mail.brum2600.net/mailman/listinfo/crew_brum2600.net">Mailing Lists</a>
</ul>
</div>
<div id="center">
<div class="par1">
No Such File!
</div>
File not found. Report may not exist. Out of cheese error!
</div>
<div id="footer">
All Pages (C) Brum2600 2005.  Brum2600 is a non profit making organisation that exists for free information exhange. We do not commit or condone actions illegal under British or International law.
</div>
</body>
</html>
END
exit;
}