#! /dcs/bin/perl # # this perl script makes the signup sheet. use strict; use CGI; $|=1; #-------------- globals---------- STARTS ------------------ my $progName="signup.pl"; my $query=new CGI; my $g_debug=0; my $g_title="Sign-up for the Final Presentation (3/22/02)"; # # time slot info # my @times = ( 'time '. "8:00am!8:15am!8:30am!8:45am!9:00am!9:15am!9:30am!9:45am ", 'time '. "10:00am!10:15am!10:30am!10:45am!11:00am!11:15am ", 'time '. "13:00pm!13:15pm!13:30pm!13:45pm!14:00pm!14:15pm!14:30pm!14:45pm ", # 'time '. # "1:30pm!2:30pm!3:30pm ", ); #-------------- globals---------- ENDS ------------------ my $debugPrefix = ""; my $rosterDB = "roster.db"; # name and student ID my $scheduleDB = "schedule.db"; # groups and time slots. my $groupDB = "group.db"; # definition of groups my @students=(); my @teams=(); my %sInfo = (); # multiply indexed by $id, 'name' or 'email' my %schedule=(); # maps date!hour!min to team string. &readRoster; &readGroups; &readSchedule; print $query->header; &printHTMLHeader(); # decide what to do based on the input if ($query->param("login")) { &printLoginPage(); } elsif ($query->param("new")) { &processNewPage(); } elsif ($query->param("debug")) { # &printRoster(@students); &printGroups(); } elsif ($query->param("register")) { ®isterTeam(); } elsif ($query->param("signup")) { &signUp(); } else { &printDefaultPage(); } &printHTMLTrailer(); sub printHTMLTrailer { my $e3 = "http://e3.uci.edu"; print << "EOF";
Back to ECE 145 homepage
[ EEE Home | UCI Home | Site Search | Help ]
Links on these pages to commercial sites do not represent endorsement by the University of California or its affiliates. See UCI Administrative Policies & Procedures Section 800-16 for the World Wide Web Publishing Policy
EOF ; } # called to login as a user. make sure the ID is correct. # then print a version of the schedule that can be edited. sub printLoginPage { $_ = $query->param("sid"); s/\s//g; my $sid = $_; if (!defined($sInfo{$sid,'name'})) { &alertHeading("Invalid login"); print << "EOF";
$sid

Please try again:

EOF ; &printLoginForm; &printHeading("Team registration"); &printTeamForm; return; } if (!defined($sInfo{$sid,'team'})) { &alertHeading("Unknown team"); print << "EOF";

$sInfo{$sid,'name'}: You must register your team before you can schedule a time slot.

EOF ; &printHeading("Team registration"); &printTeamForm; &printHeading("User login"); &printLoginForm; return; } # print the current info: my $team = $sInfo{$sid,'team'}; &printTeamInfo($team); # print the schedule in an editable form. &printCurrentSchedule($team); } sub printTeamInfo { my ($team) = @_; print "

Your team:

\n
    \n"; for (split(/,/, $team)) { print "
  1. $sInfo{$_,'name'}"; } print "
\n"; if (defined($sInfo{$team,'schedule'})) { print "

is scheduled for $sInfo{$team,'schedule'}

\n"; &printHeading("Click to reschedule:"); } else { &printHeading("Pick a time slot:"); } } # this is called when they submit member names and ID's # need to make sure they are not already signed up, and that they are # all valid students. sub processNewPage { my @good = (); # list of good sid's my @bad = (); # list of bad sid's for (1..3) { my $sid = $query->param("sid$_"); # get rid of blank spaces $_ = $sid; s/\s+//g; $sid = $_; if ($sInfo{$sid,'name'}) { push(@good, $sid); } elsif ($sid =~ /\S+/) { # at least a nonblank push(@bad, $sid); } } if (@bad) { &printRoster(@good) if (@good); my $plural=(@bad == 1)? "" : "s"; &alertHeading("Invalid student ID$plural"); print << "EOF";
EOF
;
		for (@bad) { print "$_\n"; }
		print << "EOF";

Please check your ID$plural and try again.

EOF ; &printTeamForm; return 0; } if (!@good) { # no valid one entered print << "EOF";

No valid team member information submitted. Please try again:

EOF ; &printTeamForm; return 0; } # check to make sure the team members are not already # on other teams. print << "EOF"; EOF ; my $repeatCount =0; for (@good) { if (defined($sInfo{$_,'team'})) { alertHeading("Duplicate sign up"); $repeatCount++; print << "EOF";

$sInfo{$_,'name'} already signed up for a team!

EOF ; } } if ($repeatCount) { printHeading("Login as another user:"); &printLoginForm; printHeading("Team registration:"); &printTeamForm; return 0; } &printHeading("Team members:"); print << "EOF";
    EOF ; my $i = 0; for (@good) { $i++; print << "EOF";
  1. $sInfo{$_,'name'} EOF ; } print << "EOF";
EOF ; if ($query->param('register')) { return join(",", @good); } print << "EOF";

If this information is correct, register your team now.


If this information is not correct, please try again:

EOF ; &printTeamForm; return 0; } # processNewPage # write this to the group database file. however, this could be stale # when submitted, so it is good to check the teams again. sub registerTeam { unless (open (GBF, ">>$debugPrefix$groupDB")) { &printError("Warning: Could not write to group file"); return; } my $team=&processNewPage(); return if (!$team); # write it to the file print GBF "$team\n"; close(GBF); &printHeading("Team Registration was successful."); print << "EOF";

Your team may now sign up for one of the following grading slots:

EOF ; &printCurrentSchedule($team); } # end of program. sub printDefaultPage { &printHeading($g_title); &printCurrentSchedule; &printHeading("New Sign-up"); print << "EOF";

If you have not signed up before, register your team first before you pick a time slot:

EOF ; &printTeamForm; &printHeading("Login to Edit/View schedule"); print << "EOF";

Enter one team member's student ID and login here

EOF ; &printLoginForm; print << "EOF";

Anyone on your team can make changes for the whole team.

EOF ; } # printDefaultPage #
# sub printLoginForm { print << "EOF";
EOF ; } sub printTeamForm { print << "EOF";

EOF ; } # print the time slots. # if the caller passes a team, then we want to not only highlight it # but also make available slots clickable. sub printCurrentSchedule { my ($team) = @_; print << "EOF"; EOF ; for (@times) { my ($day, $appointment) = split(/\t/); print << "EOF"; EOF ; } print << "EOF";
EOF ; for (split(/!/, $appointment)) { my $set = defined($sInfo{$team,'schedule'}) ? "change" : "signup"; my $slot = "$day $_"; my $evt = $schedule{$slot}; my $bg = $evt ? " bgcolor=\"#888888\"" : ""; if ($team) { if ($team eq $evt) { $bg = " bgcolor=\"#FFFF88\""; $evt = "your team"; } else { # make a button $evt = $evt ? "
taken
" : << "EOF"; EOF ; } } else { $evt = $evt ? "taken" : "free"; } print << "EOF"; EOF ; } print << "EOF";
$daystatus
$_

$evt


EOF ; } # called to sign up for team at a given slot. sub signUp { my $slot = $query->param("slot"); my $team = $query->param("team"); # need to make sure the target slot is still available. if (defined($schedule{$slot})) { if ($schedule{$slot} eq $team) { # it is us. &printHeading("Schedule reloaded."); } else { # otherwise, it is not us! &alertHeading("Time Slot was taken!"); print << "EOF";

The time slot you wanted ($slot) has been taken by another group since you last loaded this page, and it is no longer available. Please pick another slot.

EOF ; } } else { if (defined($sInfo{$team,'schedule'})) { # we have an existing slot. # clear it to make it available undef($schedule{$sInfo{$team,'schedule'}}); } $sInfo{$team,'schedule'} = $slot; $schedule{$slot} = $team; # for now, just echo it if (!open (SBF, ">>$debugPrefix$scheduleDB")) { &printError("Warning: Could not write to schedule file"); print "

Please try again later.

"; } else { print SBF "$slot\t$team\n"; &printHeading("Schedule submitted successfully."); } } # in all cases, print out the new schedule. &printTeamInfo($team); &printCurrentSchedule($team); } sub printHeading { my ($t)=@_; print << "EOF";

$t

EOF ; } sub alertHeading { my ($t)=@_; print << "EOF";

$t

EOF ; } sub printHTMLHeader { print $query->start_html( -title=>"$g_title", #-script=>$JSCRIPT, -bgcolor=>"#ffffff" #-link=>"#ffff00", -vlink=>"#00ffff", -alink=>"#ffff00", -text=>"#000000" ); print << "EOF";

ENGRECE 145

Senior Design Project

Course Number: ENGRECE 145, Quarter: 02w, Course Code: 15303

Instructors: P. Chou (PHCHOU\@uci.edu)

EOF ; } ##------ # printError() - print error message ##------ sub printError { my $em=shift; print<
Error - $em
EOF ; } # debugging - this is the simpler printGroups sub simplePrintGroups { print << "EOF"; EOF ; for(@teams) { print ""; for (split(/,/)) { print ""; } print "\n"; } print << "EOF";
123
$sInfo{$_,'name'}
EOF ; } # debugging - this is the nicer printGroups sub printGroups { print << "EOF"; EOF ; for (@times) { my ($day, $appointment) = split(/\t/); for (split(/!/, $appointment)) { my $slot = "$day $_"; next if (!defined($schedule{$slot})); print << "EOF"; EOF ; for (split(/,/,$schedule{$slot})) { print ""; } print "\n"; } } print << "EOF";
$slot$sInfo{$_,'name'}
EOF ; } # read from the group file. each line has a tab-separate list of ID's sub readGroups { unless (open (GBF, "$debugPrefix$groupDB")) { &printError("Warning: Could not open group file"); return; } my $lineNo=0; while () { $lineNo++; if (!/\S+/) { next; } chomp; my $teamMembers = $_; push(@teams, $teamMembers); my @team = split(/,/); # sanity check: make sure these are valid for (@team) { if (!defined($sInfo{$_,'name'})) { # make sure every one is known &printError("line $lineNo: unknown $_ found"); } elsif (defined($sInfo{$_,'team'})) { # make sure they're not already on another team &printError("$sInfo{$_,'name'} ($_) repeated"); } else { $sInfo{$_,'team'} = $teamMembers; } } } } # read from the roster file. it has student ID, name, and email sub readRoster { unless (open(RBF, "$debugPrefix$rosterDB")) { &printError("Warning: Could not open roster file"); return; } while () { if (!/\S+/) { next; } chomp; my ($sid, $name, $email) = split(/\t/); push(@students, $sid); $sInfo{$sid,'name'} = $name; $sInfo{$sid,'email'} = $email; } } # read from the schedule file. it has date and team. sub readSchedule { unless (open(SDF, "$debugPrefix$scheduleDB")) { &printError("Warning: Could not open schedule file"); return; } while () { if (!/\S+/) { next; } chomp; my ($date, $team) = split(/\t/); # assume log file structure: overwrite if already defined if (defined($sInfo{$team,'schedule'})) { # free up that time slot undef($schedule{$sInfo{$team,'schedule'}}); } # overwrite or define for the first time $sInfo{$team,'schedule'} = $date; $schedule{$date} = $team; } } # debug only sub printRoster { print << "EOF"; EOF ; for (@_) { print << "EOF"; EOF ; } print "
sIDnameemail
$_$sInfo{$_,'name'}$sInfo{$_,'email'}
\n"; }