#!/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-schedule-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 fuck 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__
SID:
First Name:
Last Name:
Email Address:

Enrollment Status:

Sections Available...
Mon 10 - 11am
Mon 2 - 3pm
Mon 3 - 4pm
Mon 4 - 5pm
Tue 12 - 1pm
Tue 1 - 2pm
Tue 4 - 5pm
Wed 9 - 10am
Wed 10 - 11am
Thur 12 - 1pm
Thur 1 - 2pm

I can't make any of these