#!/usr/local/bin/perl
# $Id: class-schedule-form.cgi,v 1.7 2004/08/18 18:31:12 hossman Exp $
# $Source: /home/hossman/cvs_archive/code/perl/class-scheduler/class-s
+chedule-fo
rm.cgi,v $
#
use warnings;
use strict;
use Fcntl qw(:flock :seek);
use CGI;
use vars qw($file $thank);
use vars qw($email $fname $lname $sid $status @sections $none);
use vars qw($q @err);
# the file all of our data goes to
$file = "./class-schedule-data.txt";
# the thank you page
$thank = "./thanks.html";
eval {
$q = new CGI;
# get our section list, ensure all be numbers
# (don't bother reporting errors, only comes from spoofers, so fuc
+k them)
@sections = $q->param('section');
$_ =~ s/[^\d]//g foreach @sections;
# get all vals, and strip out colon, and line enders
($email = $q->param('email') || '') =~ s/:|\n|\r//g;
($fname = $q->param('fname') || '') =~ s/:|\n|\r//g;
($lname = $q->param('lname') || '') =~ s/:|\n|\r//g;
($sid = $q->param('sid') || '') =~ s/:|\n|\r//g;
($status = $q->param('status') || '') =~ s/:|\n|\r//g;
($none = $q->param('none') || '') =~ s/:|\n|\r//g;
push @err, "You must specify a valid Student ID"
unless $sid =~ /^\d+$/;
push @err, "You must specify your First Name" unless $fname =~
+/.+/;
push @err, "You must specify your Last Name" unless $lname =~
+/.+/;
push @err, "You must specify your Email Address" unless $email =~
+/.+/;
push @err, "You must specify your Enrollment Status"
unless $status =~ /^(W|E|N)$/;
if (0 == @sections and ! $none) {
push @err, "You must check the sections you can attend " .
"or indicate that you can't attend any";
} elsif (0 < @sections and $none) {
push @err, "You can not check sections that you can attend " .
"AND indicate that you can't attend any";
}
die "User Input Errors" if @err;
# lock our file, and write out to it
open(FILE, ">>$file") or die "couldn't open data file to append";
flock(FILE, LOCK_EX) or die "can't lock data file";
seek(FILE, 0, SEEK_END) or die "can't see data file";
print FILE "$sid:$lname:$fname:$email:$status:",join(" ",@sections
+),"\n";
close FILE;
print $q->redirect($thank);
};
if ($@) {
my $msg = $@;
push @err, "There was a server problem. Please contact your GSI."
unless @err;
print
$q->header(-status=>500),
$q->start_html('Something Went Wrong'),
$q->h2('Something Went Wrong'),
$q->ul(map { $q->li($_) } @err ),
$q->end_html;
die $msg;
}
__DATA__
<form action="./class-schedule-form.cgi">
SID: <input type="text" name="sid" /></td>
<br/>
First Name: <input type="text" name="fname" />
<br/>
Last Name: <input type="text" name="lname" />
<br/>
Email Address: <input type="text" name="email" />
<br/>
<p>
Enrollment Status:
<select name="status">
<option value="none" selected>Pick One</option>
<option value="E">Enrolled</option>
<option value="W">Waitlisted</option>
<option value="N">Neither</option>
</select>
<br/>
<p>
Sections Available...<br/>
<input type="checkbox" name="section" value="0" /> Mon 10 - 11am<br/>
<input type="checkbox" name="section" value="1" /> Mon 2 - 3pm<br/>
<input type="checkbox" name="section" value="2" /> Mon 3 - 4pm<br/>
<input type="checkbox" name="section" value="3" /> Mon 4 - 5pm<br/>
<input type="checkbox" name="section" value="4" /> Tue 12 - 1pm<br/>
<input type="checkbox" name="section" value="5" /> Tue 1 - 2pm<br/>
<input type="checkbox" name="section" value="6" /> Tue 4 - 5pm<br/>
<input type="checkbox" name="section" value="7" /> Wed 9 - 10am<br/>
<input type="checkbox" name="section" value="8" /> Wed 10 - 11am<br/>
<input type="checkbox" name="section" value="9" /> Thur 12 - 1pm<br/>
<input type="checkbox" name="section" value="10" /> Thur 1 - 2pm<br/>
<p>
<input type="checkbox" name="none" value="1" /> I can't make any of th
+ese<br/>
<p>
<input type="submit" value="Submit"/>
</form>
|