#!/usr/local/bin/perl
use CGI;
$query = new CGI;
# Print the necessary HTML stuff.
print $query->header;
print $query->start_html;
# Get the value of each field.
$firstname = $query->param('firstName');
$lastname = $query->param('lastName');
$email = $query->param('email');
$major = $query->param('major');
$year = $query->param('year');
$experience = $query->param('experience');
$employer = $query->param('employer');
$presdate = $query->param('presdate');
$prestopic = $query->param('prestopic');
$color = $query->param('color');
$bearcatID = $query->param('bearcatID');
# Print the page that appears after the user submits the form.
print "<html><head><title>Interesting Page</title></head>";
print "<body>";
print "<p>First Name: $firstname</p>";
# Open the HTML page to which we will write user data. Note that
we are using a scalar variable, $bearcatID,
# in the open statement. This is perfectly fine, and will generate
a unique HTML page for each bearcat ID entered.
# Also, note the scalars used in the print statements.
# The backslash character [\] is the escape character in Perl.
Note that we use the backslash to signify that the following
# character must be printed as is. For example, in the e-mail
line, we use the backslash before the double quote to tell
# Perl that we are not ending the string, but instead to print this
as it is.
open(PAGE, ">>../$bearcatID.html");
print PAGE "<HTML><HEAD><TITLE>" . $firstname . "'s Homepage</TITLE></HEAD>";
print PAGE "<body bgcolor = $color>";
print PAGE "<h3>Welcome to " . $firstname . "'s Home Page!</h3><br>";
print PAGE "Full Name: $firstname $lastname <br>";
print PAGE "E-mail: <a href = \"mailto:$email\">$email</a><br>";
print PAGE "Major: $major<br>";
print PAGE "year: $year<br>";
print PAGE "Presentation Date: $presdate<br>";
print PAGE "Presentation Topic: $prestopic<br>";
print PAGE "</body></html>";
close(PAGE);
# We've closed the page, now let's change the permissions so that the world can see it.
chmod (0755, "../$bearcatID.html");
# Now, we make a link to the page we just created on the classlist.html
page.
# classlist.html has links to each student who has registered.
# Note the >> tells Perl to append, but not overwrite, the contents
of classlist.html
open(BLJPAGE, ">>../classlist.html");
print BLJPAGE "<a href=\"http://homepages.uc.edu/~jonesbr/" . $bearcatID
. ".html\">";
print BLJPAGE $firstname . " " . $lastname;
print BLJPAGE "</a><br>";
close(BLJPAGE);
# Now, for more confidential information, we will write to a file in
a different directory.
# This file can only be accessed by the owner of the account (me).
# The syntax is similar to what we see above.
open(CPAGE, ">>../classdata/$bearcatID.html");
print CPAGE "<HTML><HEAD><TITLE>" . $firstname . "'s Homepage</TITLE></HEAD>";
print CPAGE "<body>";
print CPAGE "<h3>Welcome to " . $firstname . "'s Home Page!</h3><br>";
print CPAGE "Full Name: $firstname $lastname <br>";
print CPAGE "E-mail: <a href = \"mailto:$email\">$email</a><br>";
print CPAGE "Major: $major<br>";
print CPAGE "year: $year<br>";
print CPAGE "Presentation Date: $presdate<br>";
print CPAGE "Presentation Topic: $prestopic<br>";
print CPAGE "Employer: $employer Experience $experience";
print CPAGE "</body></html>";
close(CPAGE);
# Generate an e-mail. Start by making the body of the e-mail.
# Note the use of a scalar in a constant.
$contents = "$firstname has registered.";
# Open a filehandle, MAIL, and "pipe" it to our sendmail program at
UC.
# Copy this same syntax if you wish to generate an e-mail.
# Note that the sendmail program interprets the special lines To:,
From:, and Subject: appropriately.
# The $contents scalar writes to the body of the e-mail.
open (MAIL, "|/usr/sbin/sendmail -t");
print MAIL "To: jonesbl\@one.net\n $email\n";
print MAIL "From: $email\n";
print MAIL "Subject: $bearcatID\n";
print MAIL "$contents\n";
close(MAIL);
# Print out the HTML confirmation page.
print "<br>Your page is complete! ";
print "Click <a href=\"http://homepages.uc.edu/~jonesbr/" . $bearcatID
.
".html\">Here</a> to see it.";
# And we're complete! Easy as that.
print "</body></head>";