#!/usr/local/bin/perl
use POSIX strftime;
require "weblib.lib";
$avatars="/home/todd/public_html/pictures/avatars";
htmlopen("Upload an Avatar");
&getparams(0,"date");
@first=(0,0,0,1,1,2003);
@last=localtime(time);
$selecteddate=strftime("%Y%m",@last);
$selecteddate=$param{date} if $param{date};
&ReadParse;
if($in{avatar}){
	$fn=time;
	open(TMP,">/tmp/$fn");
	print TMP $in{avatar};
	close(TMP);
	$avatarname="jpeg:$avatars/$fn.jpg";
	system("/usr/bin/convert -geometry '95x95>' /tmp/$fn $avatarname");
	chmod 0644,"$avatars/$fn.jpg";
	unlink "/tmp/$fn";
	print qq{<img src="http://TRConnection.com/trc/pictures/avatars/$fn.jpg" align="left">},
		qq{Your avatar URL is http://TRConnection.com/trc/pictures/avatars/$fn.jpg},
		qq{<br clear="left">\n};
}
print <<EOF;
To Upload your own Avatar (the picture that appears with each message you post) following these instructions:
<ol>
<li>Use a photo that is already on your local computer. It will be reduced to a thumbnail size (largest dimension 95 pixels), so be sure the detail can be seen at that size.
<li>Browse to the picture using the "Browse" button below
<li>Click on the "Upload Avatar"
<li>Note the URL and paste that into your profile
</ol>
<form action="$weblib::URL" method="POST" enctype="multipart/form-data">
<input type="file" name="avatar"><br>
<input type="submit" value="Upload Avatar">
</form>
EOF
chdir $avatars;
opendir(DIR,".");
$count=0;
print qq{Back to <a href="http://forum.trconnection.com">The Forums</a>\n};
print "<center><h2>The Rogue's Gallery</h2></center>\n";
print qq{To use any of these as your own avatar, prefix the name with "http://TRConnection.com/trc/pictures/avatars/"<br>\n};
print qq{Because of the large number of avatars on file, they have been broken up by the month they were added. The default display are those added during the current month<br>\n};
print "<hr>\n";
$last[5]+=1900;
for($year=$first[5];$year<=$last[5];$year++){
	for($month=$first[4];$month<12;$month++){
		last if $year==$last[5] && $month>$last[4];
		print "<br>" if $year != $previousyear;
		printf(qq{<a href="%s/%4d%02d">%02d/%4d</a>\n},$weblib::URL,$year,$month+1,$month+1,$year);
		$previousyear=$year;
	}
}
print "<hr>\n";
while($file=readdir(DIR)){
	next if $file=~/^\./;
	@stat=stat($file);
	$date=strftime("%Y%m",localtime($stat[9]));
	next if $date ne $selecteddate;
	$count++;
	print qq{<table style="display: inline; border: 1px solid black;" align="left"><tr><th>$file</th></tr>},
		qq{<tr><td><img src="http://TRConnection.com/trc/pictures/avatars/$file" title="$file"></td></tr></table>\n};
	print qq{<br clear="left">} if $count % 6 == 0;
}
&htmlclose;
