#!/usr/bin/perl
# author: C. Edward Chow
# date: 11/9/2000
# copyright © 2000
# free distribution for research and education
# but please retain the above author, date and copyright lines.
#
use CGI qw(:standard);
print header('text/html');
print "
CS691c Lab Reservation Result";
print "CS691c Lab Reservation Result
";
print hr;
@names = param;
foreach $name (@names) {
$value = param($name);
if ($name ne "passwd") { print "$name=$value
";}
if ($value eq "Reserve") {
$reserveSlot=$name;
$command = $value;
}
$_ = $value;
if (/Cancel reservation by (\w+)/) {
$command = "Cancel";
$reservedBy = $1;
$reserveSlot=$name;
print "cancel the reservation by $1\n
";
}
}
print "reserveSlot=$reserveSlot\n
";
$login = param('login');
$passwd =param('passwd');
print "verify login=$login\n
";
if ($login eq "") {
print "You need to enter login for reservation.\n
\n";
open(WEBPAGE, "reserve/cs691creserve.htm");
while() {
print $_;
}
close(WEBPAGE);
exit(1);
} else {
open(FILEREAD, "password.txt");
$search = 1;
while(($passwdline=) && $search) { # with () $passwdline will be 1
@fields = split(/:/, $passwdline); # split $line using : as delimiter
if ($login eq $fields[1]) {
print "login entry exist!\n";
if ($passwd eq $fields[2]) {
$fullname = $fields[0];
$fullname =~ s/,.*//; # throw away everything after comma,
print "passwd correct! fullname=$fullname\n
";
} else {
print "password not correct! encpasswd=$fields[2]; passwd=$passwd\n
\n";
open(WEBPAGE, "reserve/cs691creserve.htm");
while() {
print $_;
}
close(WEBPAGE);
exit(1);
}
$search = 0;
}
}
if ($search) {
print "login/passwd incorrect!\n
\n";
open(WEBPAGE, "reserve/cs691creserve.htm");
while() {
print $_;
}
close(WEBPAGE);
exit(1);
}
close(FILEREAD);
}
dbmopen(%reserve, "reserve/cs691chw1", 0666);
$slot = $reserve{$reserveSlot};
#print "slot=$slot
/n";
if ($command eq "Reserve") {
if ($slot eq "") {
print "$reserveSlot not reserved; reserving...";
$reserve{$reserveSlot} = $login;
print "
$fullname: the slot $reserveSlot is reserved for you!\n
";
# move up the above print line for better web page look.
# logically it should be after the web page is updated.
# update the web page
open(WEBPAGE, "reserve/cs691creserve.htm");
open(UPDATE, ">reserve/updatecs691creserve.htm");
while() {
if (/$reserveSlot/) {
s/Reserve/Cancel reservation by $login/;
}
print UPDATE $_;
print $_;
}
close(WEBPAGE); close(UPDATE);
system("mv reserve/updatecs691creserve.htm reserve/cs691creserve.htm");
} else {
print "$reserveSlot reserved by $slot! Try different time slot\n
";
}
} else { # Cancel
if ($login eq $slot) {
print "prepare to cancel...";
$reserve{$reserveSlot} = ""; # reset
print "
$fullname: the reservation on slot $reserveSlot is canceled!\n
";
# move up the above print line for better web page look.
# logically it should be after the web page is updated.
# update web page
open(WEBPAGE, "reserve/cs691creserve.htm");
open(UPDATE, ">reserve/updatecs691creserve.htm");
while() {
if (/$reserveSlot/) {
s/Cancel reservation by $login/Reserve/;
}
print UPDATE $_;
print $_;
}
close(WEBPAGE); close(UPDATE);
system("mv reserve/updatecs691creserve.htm reserve/cs691creserve.htm");
} else { # login and reserveby not matched
print "The slot is reserved by others. Please select the timeslot
reserved by you.
";
}
}
print "";