Приглашаем посетить
Classified Ads
#!/usr/bin/perl
###########################################################################
# #
# Classifieds.pl - Perl Script for Posting Classified Ads #
# #
# Written by Michael Hall - mikeh@isaac.biola.edu #
# Written for Virtual Marketing Technologies - vmt@airmail.net #
# Copyright ©1996 by Virtual Marketing Technologies, All Rights Reserved. #
# #
###########################################################################
###########################################################################
#
# Define the following variables in the form:
#
# ClassifiedsDir - Base path to the directory that will hold the ads
# ErrorReturn - HTML address to return to in case of an error
# ReturnURL - HTML address to return to after a successful post
&UnWeb;
$AdNumber = 0;
# Get the Date for Entry
$date = `date +"%A, %B %d, %Y at %T (%Z)"`;
chop($date);
$shortdate = `date +"%D %T %Z"`;
chop($shortdate);
if ($in{'Selection'} eq "ViewAds") {
if ($in{'Department'} eq "") {
# User did not choose a department to view so return the error message and quit
&PrintHeader;
print "<html>\n";
print "<head>\n";
print "<title>Error Message</title>\n";
print "</head>\n";
print "<body bgcolor=\"FFFFFF\">\n";
print "\n";
print "<h1>An Error Has Occurred:</h1><p>\n";
print "You did not choose a department to view ads in.
Please choose one by selecting the button next to the appropriate department.<p>\n";
print "<hr><p><center><a href=$in{'ErrorReturn'}>
Return to the Form</a><p><hr>\n";
print "© 1996 and Designed and Programmed by <a
href=\"http://www-students.biola.edu/~mikeh/scripts/\">Michael Hall</a>.
All Rights Reserved.<br>\n";
print "</body>\n";
print "</html>\n";
# make a call to exit to end the script now, we had an error
exit;
}
print "Location: $in{'ViewDir'}$in{'Department'}.html\n\n";
exit;
}
if (($in{'RealName'} eq "") || ($in{'E-MailAddress'} eq "") || ($in{'Address1'} eq "")
|| ($in{'City'} eq "") || ($in{'State'} eq "") || ($in{'ZipCode'} eq "")
|| ($in{'Phone'} eq "") || ($in{'Department'} eq "") || ($in{'Description'} eq "")) {
# something was blank, return the error message
&PrintHeader;
print "<html>\n";
print "<head>\n";
print "<title>Error Message</title>\n";
print "</head>\n";
print "<body bgcolor=\"FFFFFF\">\n";
print "\n";
print "<h1>An Error Has Occurred:</h1><p>\n";
print "A field was left empty. All rields must be filled in completely
before the ad can be posted.<p>\n";
print "<hr><p><center><a href=$in{'ErrorReturn'}>Return to
the Form</a><p><hr>\n";
print "© 1996 and Designed and Programmed by <a
href=\"http://www-students.biola.edu/~mikeh/scripts/\">Michael Hall</a>.
All Rights Reserved.<br>\n";
print "</body>\n";
print "</html>\n";
# make a call to exit to end the script now, we had an error
exit;
}
# Lock the file for security so the file is not damaged if more than one user tries to access it at the same time.
$quit = 0;
while ($quit != 1) {
if (-e "$in{'ClassifiedsDir'}.$in{'Department'}lock") {
# The file exists, time to take a nap
sleep(1);
}
else {
# Create the lock file, thereby locking the Classified Ad file
open (LOCK,">$in{'ClassifiedsDir'}.$in{'Department'}lock");
close LOCK;
}
# Open the data file to read the number of the last post
open (ADFILE, "$in{'ClassifiedsDir'}AdNumber.dta");
$AdNumber = <ADFILE>;
# chop $AdNumber;
# Update the Ad Number by one
$AdNumber = $AdNumber + 1;
# Rewrite the data file
open (ADFILE, ">$in{'ClassifiedsDir'}AdNumber.dta");
print ADFILE $AdNumber;
close ADFILE;
# Append the user's ad and description to the ad file
open (ADFILE,">>$in{'ClassifiedsDir'}$in{'Department'}.html");
print ADFILE "<b>Ad No.: </b>$AdNumber - <b>Subject: </b>$in{'AdSubject'} - <b>Posted on: </b>$shortdate<br>\n";
print ADFILE "<b>Reply to: </b>$in{'RealName'} at <a href=\"mailto: $in{'E-MailAddress'}\">$in{'E-MailAddress'}</a><br>\n";
print ADFILE "$in{'Description'}<p><hr><p>\n";
close(ADFILE);
# Appen the user's personal data to the data file
open (DATAFILE,">>$in{'ClassifiedsDir'}UserDataFile.html");
print DATAFILE "<b>$in{'RealName'} - <a href=mailto:$in{'E-MailAddress'}>$in{'E-MailAddress'}</a><br>\n";
print DATAFILE "$in{'Address1'}<br>\n";
if ($in{'Address2'} ne "") {
print DATAFILE "$in{'Address2'}<br>\n";
}
print DATAFILE "$in{'City'}, $in{'State'} $in{'ZipCode'} - $in{'Phone'}</b><br>\n";
print DATAFILE "<b>Ad No.: </b>$AdNumber - <b>Department: </b>$in{'Department'} on $shortdate<br>\n";
if ($in{'DesiredDepartment'} ne "") {
print DATAFILE "<b>Desired Department: </b>$in{'DesiredDepartment'}<br>\n";
}
print DATAFILE "<b>Description: </b>$in{'Description'}<p><hr><p>\n";
close(DATAFILE);
# unlock the lock file
unlink("$in{'ClassifiedsDir'}.$in{'Department'}lock");
# Return the user to the Return URL
print "Location: $in{'ReturnURL'}\n\n";
$quit = 1;
}
sub UnWeb {
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
# Un-Webify plus signs and %-encoding
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
if ($allow_html != 1) {
$value =~ s/<([^>]|\n)*>//g;
}
else {
unless ($name eq 'body') {
$value =~ s/<([^>]|\n)*>//g;
}
}
$in{$name} = $value;
}
}
#######################
# Print HTML Header
sub PrintHeader {
print "Content-type: text/html\n\n";
}