#!/usr/bin/perl
require "/home/todd/toddweb.env";
require "weblib.lib";
$URL="/pictures/rememberme";
$PHOTODIR="/home/todd/www$URL";
$TNDIR="$PHOTODIR/tn";
$TNURL="$URL/tn";
$viewport="viewport=width=device-width, initial-scale=1.0";
$style=<<EOF;
style=http://TRConnection.com/trc.css%%.float {
	display: inline-block;
	text-align: center;
	border: 5px black ridge;
	padding: 5px;
	margin: 3px;
}
img.memorial {
	display: block;
	margin-left: auto;
	margin-right: auto;
}
img.display {
	margin: auto;
	display: relative;
	width: 75%;
	max-width: 5in;
	border: 5px black ridge;
	padding: 5px;
	margin: 3px;
}
div.display{
	margin: auto;
	width: 80%;
	text-align: center;
}
EOF
&getparams;
if($param{upload}){
	$style.=<<EOF;
label {
	display: inline-block;
	width: 10em;
}
EOF
	$UPLOADDIR="/home/todd/www/uploadedimages";
	&ReadParse;
	htmlopen("Remember Me - Upload an image+",$style,$viewport);
	if($in{prefix}){
		$photo="$in{year}_$in{name}.jpg";
#		$photo=~s/ /\\ /g;
		if(-f "$UPLOADDIR/$in{prefix}-full.jpg" && -f "$UPLOADDIR/$in{prefix}-thumb.jpg"){
			rename("$UPLOADDIR/$in{prefix}-full.jpg","$PHOTODIR/$photo");
			rename("$UPLOADDIR/$in{prefix}-thumb.jpg","$PHOTODIR/tn/$photo");
		}
		else{
			print "Sorry, uploaded images do not exist!<br>\n";
		}
	}
	print <<EOF;
<ol>
<li><a href="http://trconnection.com/cgi-bin/tn" target="RememberMe">Upload Image and Create Thumbnail</a></li>
<li>Copy the photo prefix and return to this page</li>
<li>
<form action="$weblib::URL/upload" method="POST">
<label>Photo Prefix</label><input name="prefix"><br>
<label>Year of Death</label><input name="year"><br>
<label>Name</label><input name="name"><br>
<input type="submit">
</form></li>
<li><a href="$weblib::URL">Return to <i>Remember Me</i></a></li>
</ol>
EOF
&htmlclose;
exit;
}
elsif($pic=$paramposition[0]){
	($year,$name)=split(/_/,$pic);
	$name=~s/.jpg//;
	htmlopen("$year - $name|",$style,$viewport);
	print qq{<div class="display">\n};
	print qq{<img src="$URL/$pic" class="display">\n};
	print "<br>$year - $name";
	print "</div>\n";
	&htmlclose;
	exit;
}
htmlopen("Remember Me+",$style,$viewport);
print $paramposition[0];
print "<h2>A place to honor Todd Rundgren fans who have passed away</h2>";
opendir(DIR,$PHOTODIR);
foreach $dir(readdir(DIR)){
	next unless -d "$PHOTODIR/$dir";
	next if $dir eq "tn";
	open(INFO,"$PHOTODIR/$dir/info");
	while(<INFO>){
		chop;
		($label,$value)=split(/:\s*/);
		$info{$label}=$value;
	}
	$memorial{"$info{Death}%%$info{Name}"}=1;
}
opendir(DIR,$PHOTODIR);
@PIC=reverse sort grep(/\.jpg/,readdir(DIR));
print <<EOF;
Know of a Todd Rundgren fan you would like to honor? Please e-mail a name, photo and date of death to
<a href="mailto:RememberMe\@TRConnection.com">RememberMe\@TRConnection.com</a> and it will be posted here.
<p>
EOF
foreach $pic(@PIC){
	($year,$name)=split(/_/,$pic);
	$name=~s/.jpg//;
	print <<EOF;
<div class="float"><a href="$weblib::URL/$pic"><img class="memorial" src="$TNURL/$pic"></a>
$year - $name
</div>
EOF
}
print <<EOF;
$PAGETAIL
EOF
&htmlclose;
