#!/usr/bin/perl -T
################################################################################
# sign-up.pl, a simple, but ugly, cgi script for a sign up event
# Distributed under NO liscence, go ahead and have your way with my
# code, I don't care. *grin*
#
# all the script requires to implement is a subdirectory called 'data' that
# it can write to, so that it can create the dbm
#
# download the file here
################################################################################
# include
use CGI qw(:standard :html3 :netscape);
# variable declaration
my $max=0;
my @times;
my %mydata;
my @values;
my $tmp;
# open the database
dbmopen %data, "data/signup", 0666 or die "Content-type: text/text\n\nCan not open data file, fatal error";
# what to do if we have parameters
if (param()){
my $start = param('start');
my $finish = param('finish');
# okay, since the finish time is actually represented as a block,
# we want to subtract a half hour from it, and this is how we do
# it /crack
unless ($current =~ s/:3/:0/ ){
( $temp, $trash ) = split /:/, $current, 2;
$temp = ($temp == 1)?12:--$temp;
$current = $temp . ":00";
}
my @values = ($start);
my $max = 0;
my $current = $start;
# internally, the arrays are actually colon seperated lists, so just
# include our seperator with the value we want to insert
my $name = param('name') . ":";
# this little loop gives us an array of times for the start and finish
# times, converting a range into a set of values like we want
while ($current ne $finish) {
unless ( $current =~ s/:0/:3/g ) {
( $temp, $trash ) = split /:/, $current, 2;
$temp = ($temp == 12)?1:++$temp;
$current = $temp . ":00";
}
push @values, $current;
}
# Okay, more crack. To prevent stuff like:
# +----------+--------------+-------------------+
# | 9:30 | Fred | |
# +----------+--------------+-------------------+
# | 10:00 | Joe | Fred |
# +----------+--------------+-------------------+
# (We want the names to line up nice) we have to count
# the maximum number of seperators in each line and
# put pad with seperators to line up, so max is the
# maximum number of seperators /morecrack
$max = $data{$start} =~ tr/:/:/;
foreach $value (@values) {
my $currentmatch = $data{$value} =~ tr/:/:/ ;
$max = ($currentmatch > $max)?$currentmatch:$max;
}
# for every value, update the list by correctly padding and then
# inserting the name
foreach $key (@values) {
$pattern = $data{$key};
$colons = $pattern =~ tr/:/:/;
$colons = $max - $colons;
$colonstring = ":" x $colons;
$data{$key} .= $colonstring . $name;
}
# finally, add people to the list for other crap, fortunately we
# don't have to worry about padding here
my @others = param('other');
foreach $other (@others) {
if ($other eq 'computer'){$data{'computer'} .= $name}
if ($other eq 'documentation'){$data{'documentation'} .= $name}
if ($other eq 'signs'){$data{'signs'} .= $name}
if ($other eq 'wallpaper'){$data{'wallpaper'} .= $name}
}
#change $name for our new purpose
$name = param('name') . "(" . param('burn') . "):";
#force burn into numeric context
my $burn = param('burn') +0;
if ($burn){ $data{'burn'} .= $name}
}
# okay, now if someone screwed up, this routine delets them from the database.
# it could be nicer but as of now it doesn't worry about correcting the colon
# padding deal
if (param('delete')) {
my $name = param('name');
foreach $key (keys %data) {
if ($key eq 'burn'){ $data{$key} =~ s/$name.+://ig }
else {$data{$key} =~ s/$name://ig }
}
}
# now we can convert the database into a nice perl structure (hash of arrays)
# since we aren't goinng to deal with a finicky dbm anymore
foreach $key (keys (%data)){
my @temp = split /:/, $data{$key};
$mydata{$key} = \@temp;
}
# close the database
dbmclose %data;
#print a pretty header
print header;
print start_html('Open Source Software Awareness Day signup');
if (param()){ print h2("Thank you for helping out"), hr; }
print h1('Open Source Software Awareness Day signup'), "Welcome to the
OpenSource Club's Open Source Software Awareness Day (Feb 17, 2000).
You can see below
who is signed up for what responsibilities. If you can help in anyway,
please sign in below. For other developments, be sure you are",
a({href=>'http://www.cis.ohio-state.edu/opensource/contact.html'}, " subscribed "),
" to ", a({href=>'mailto:Open Source Mailing List <opensource@cis.ohio-state.edu>'},
" the OpenSource list"), p;
#here is the table, taking values from our internal data structure
print table({-border=>undef},
caption(strong('Time signin')),
Tr({-align=>CENTER,-valign=>TOP},
[
th('9:00').td([@{$mydata{'9:00'}}]),
th('9:30').td([@{$mydata{'9:30'}}]),
th('10:00').td([@{$mydata{'10:00'}}]),
th('10:30').td([@{$mydata{'10:30'}}]),
th('11:00').td([@{$mydata{'11:00'}}]),
th('11:30').td([@{$mydata{'11:30'}}]),
th('12:00').td([@{$mydata{'12:00'}}]),
th('12:30').td([@{$mydata{'12:30'}}]),
th('1:00').td([@{$mydata{'1:00'}}]),
th('1:30').td([@{$mydata{'1:30'}}]),
th('2:00').td([@{$mydata{'2:00'}}]),
th('2:30').td([@{$mydata{'2:30'}}]),
th('3:00').td([@{$mydata{'3:00'}}]),
th('3:30').td([@{$mydata{'3:30'}}]),
th('4:00').td([@{$mydata{'4:00'}}]),
th('4:30').td([@{$mydata{'4:30'}}])
]
));
# fore each of the other responsibilities, a space joined list is fine to
# print out
print p, strong('Lending Computers: '), (join ' ', @{$mydata{'computers'}}), p;
print strong('Doing Documentation: '), (join ' ', @{$mydata{'documentation'}}), p;
print strong('Making Signs: '), (join ' ', @{$mydata{'signs'}}), p;
print strong('Making X11 Wallpaper: '), (join ' ', @{$mydata{'wallpaper'}}), p;
print strong('Burning CDs (number to burn): '), (join ' ', @{$mydata{'burn'}}), p;
print hr, em("Now do your part"), p;
# and this is basic form stuff
print start_form,
"What's your name? (required) ",textfield('name'),
p;
print "When can you work",
p,
"Start: ",
popup_menu(-name=>'start',
-values=>['9:00', '9:30', '10:00', '10:30', '11:00', '11:30', '12:00',
'12:30', '1:00', '1:30', '2:00', '2:30', '3:00', '3:30']);
print p,
"End: ",
popup_menu(-name=>'finish',
-values=>['9:00', '9:30', '10:00', '10:30', '11:00', '11:30', '12:00',
'12:30', '1:00', '1:30', '2:00', '2:30', '3:00', '3:30',
'4:00', '4:30', '5:00']);
print p,
"Can you do other projects?",
checkbox_group(-name=>'other',
-values=>['computer','documentation','signs','wallpaper'],
-defaults=>[]);
print p,
"Number of CD's you could burn: ",
textfield(-name=>'burn', -default=>'0', -size=>2), p,
submit(-name=>'submit'),
hr, $tmp, " if you have messed up, and would like your name removed,
select the checkbox below", p,
checkbox(-name=>'delete',
-checked=>'',
-value=>'OFF',
-label=>'Delete my information'),
end_form, end_html;
# whew, hope you got all that. Ghetto, but it does the job