📄 ch17.htm
字号:
<TD VALIGN=TOP ALIGN=LEFT COLSPAN=1><BR>
<INPUT TYPE=SUBMIT NAME="submit" VALUE="Register
a New User"><BR>
</TD></TR></TABLE><BR>
</FORM><BR>
<HR><BR>
<FORM METHOD=POST ACTION=$ref_url><BR>
<TABLE><BR>
<TR><TD VALIGN=TOP ALIGN=LEFT COLSPAN=1><B>Email
Address:</B></TD><BR>
<TD VALIGN=TOP ALIGN=LEFT COLSPAN=2><INPUT TYPE=TEXT
NAME="email"></TD><BR>
<TD VALIGN=CENTER ALIGN=LEFT COLSPAN=1 ROWSPAN=2><BR>
<INPUT TYPE=SUBMIT NAME="submit" VALUE="Registered
Users Proceed"></TR><BR>
<TR><TD VALIGN=TOP ALIGN=LEFT COLSPAN=1><B>Password:</B></TD>
<BR>
<TD VALIGN=TOP ALIGN=LEFT COLSPAN=1><INPUT TYPE=PASSWORD
NAME="password"></TD><BR>
</TD></TR></TABLE><BR>
</FORM><BR>
<HR><BR>
</BODY></HTML><BR>
END<BR>
}<BR>
<BR>
<BR>
#<BR>
# a user has asked for a new account. Gives a fairly
random 6 digit<BR>
# number to them as their password via email<BR>
# Also, creates an empty .cdd file -- this file will sort this
users<BR>
# vote information<BR>
#<BR>
sub new_user {<BR>
<BR>
local ($email);<BR>
($email) = @_;<BR>
<BR>
# <BR>
# Trap for no email address entry. It's still very
possible for someone<BR>
# to feed the program a non-existant email address, or a random
string of<BR>
# characters for that matter, but it won't crash the program and
it won't<BR>
# do the offending person any good, either, as their password
will be<BR>
# provided to them by email anyhow<BR>
#<BR>
$email =~ s/\s//g; #
eliminates all whitespace in email address<BR>
if ( $email eq '' ) {<BR>
print "Content-type:
text/html\n\n";<BR>
print <<END;<BR>
<HTML><HEAD><TITLE>No Email Address was entered</TITLE></HEAD>
<BR>
<BODY><BR>
<P><BR>
Either nothing was entered into the email address field or only
whitespace<BR>
characters were entered. Return to the <A HREF=$ref_url>home
page</A> of this<BR>
site to re-start the process.<BR>
</BODY></HTML><BR>
END<BR>
} else {<BR>
<BR>
#<BR>
# create a password of 6 mostly random digits... check to see
if a data file <BR>
# with that password already take exists... if so, add one to
the password <BR>
# and check to see if that exists... repeat until available password
is found<BR>
#<BR>
$pswd = rand; #
put a random number into pswd<BR>
substr($pswd,$[,2) = ''; #
remove 2 digits from its front<BR>
# to this number, add the number of seconds since 1970 & the
current PID<BR>
$pswd = $pswd + time + $$;
<BR>
reverse $pswd; #
reorder string back to front<BR>
substr($pswd,$[+6) = ''; #
take the first 6 characters<BR>
while ( -e ($pswd . '.cdd')
) { $pswd++; } # checks for file Existance<BR>
<BR>
#<BR>
# create the datafile with name "PASSWORD.cdd"<BR>
# Store email address and password as data fields<BR>
#<BR>
$passfilename = $pswd . '.cdd';
<BR>
open(DF,"> $passfilename");
<BR>
print DF "Email Address\t$email\n";
<BR>
print DF "Password\t$pswd\n";
<BR>
close(DF);<BR>
chmod 0660, $passfilename;
<BR>
<BR>
#<BR>
# Send email to new subscriber telling them what their password
is<BR>
#<BR>
open(EM,"| /usr/sbin/sendmail
-t");<BR>
print EM <<END;<BR>
To: $email<BR>
Cc: $admin<BR>
From: "Richard's Music Database Program"<BR>
Reply-To: "Richard Dice" <rdice\@anadas.com><BR>
Subject: Welcome, new subscriber!<BR>
<BR>
You are now a subscriber to Richard's Music Database. This
allows you to<BR>
vote on what you think of his music collection.<BR>
<BR>
To access your account, go to:<BR>
$ref_url<BR>
<BR>
Email Address : $email<BR>
Password : $pswd<BR>
<BR>
Hope it's fun for you!<BR>
END<BR>
close(EM);<BR>
<BR>
#<BR>
# Output a message to the Web providing further instructions<BR>
#<BR>
print "Content-type:
text/html\n\n";<BR>
print <<END;<BR>
<HTML><BR>
<HEAD><TITLE>Welcome, New Registered User!</TITLE></HEAD>
<BR>
<BODY><BR>
<P><BR>
<H3>Welcome, New Registered User!</H3><BR>
<P><BR>
You will be receiving an email shortly which will tell you your
password.<BR>
Once you have that information, please go back to the <BR>
<A HREF=$ref_url>home page</A> and enter as a registered
user.<BR>
</BODY></HTML><BR>
END<BR>
}<BR>
}<BR>
<BR>
sub view_stats {<BR>
<BR>
$num_votes = 0;<BR>
<BR>
#<BR>
# construct @line array of all cd.txt datafile lines which have
voted-upon<BR>
# albums, and @shortlist array of all such lines which are also
marked<BR>
# as being on the short list (that is, the 3rd datafield is a
"*").<BR>
# Also, create running total of the number of votes recorded and
the total<BR>
# 0-10 votes submitted <BR>
#<BR>
open(CD,"cd.txt");<BR>
while ( <CD> ) {<BR>
chop;<BR>
@field = split(/\t/,$_,5);
<BR>
if ( $field[3] != 0 ) {<BR>
push(@line,$_);
<BR>
$vote_total
+= $field[4];<BR>
$num_votes
+= $field[3];<BR>
push(@shortlist,$_)
if $field[2] eq '*';<BR>
}<BR>
}<BR>
close(CD);<BR>
if ($num_votes != 0 ) {<BR>
$average = $vote_total / $num_votes;
<BR>
} else { $average = 0; }<BR>
<BR>
#<BR>
# order both @line and @shortlist arrays by descending order of
album<BR>
# average vote score<BR>
#<BR>
(@line = sort by_average @line) if defined(@line);
<BR>
(@shortlist = sort by_average @shortlist) if
defined(@shortlist);<BR>
<BR>
#<BR>
# output reports to the Web -- first is total # of voters, then
Average Vote,<BR>
# then table of @line-related information... all pretty straightforward
stuff<BR>
#<BR>
print "Content-type: text/html\n\n";
<BR>
print <<END;<BR>
<HTML><BR>
<HEAD><TITLE>Historical Voting Record</TITLE></HEAD>
<BR>
<BODY><BR>
<P><BR>
Here is the historical record of all votes taken regarding Richard's
Music.<BR>
<P><BR>
END<BR>
<BR>
print "<B>Number of votes cast: $num_votes
<BR>\n";<BR>
printf("Average Score of Album: %5.2f </B>\n",$average);
<BR>
print "<H3>All Albums</H3>\n";
<BR>
print "<TABLE BORDER WIDTH=100%><TR>\n";
<BR>
print "<TR><TH>Artist</TH><TH>Album</TH><TH>#
of Votes</TH>",<BR>
"<TH>Vote Ave.</TH></TR>\n";
<BR>
foreach ( @line ) {<BR>
@field = split(/\t/,$_,5);
<BR>
print "<TD ALIGN=LEFT
VALIGN=TOP>$field[0]</TD>\n";<BR>
print "<TD ALIGN=LEFT
VALIGN=TOP>$field[1]</TD>\n";<BR>
if ( $field[2] eq '*' ) {
<BR>
<BR>
$shortcut
= &hash($field[0],$field[1]);<BR>
print "<TD
ALIGN=CENTER VALIGN=TOP COLSPAN=2><A HREF=\"#$shortcut\">",
<BR>
"See
Short List</A></TD></TR>\n";<BR>
} else {<BR>
print "<TD
ALIGN=LEFT VALIGN=TOP>$field[3]</TD>\n";<BR>
printf("<TD
ALIGN=LEFT VALIGN=TOP>%5.2f</TD></TR>\n",
<BR>
$field[4]/$field[3]);
<BR>
}<BR>
}<BR>
print "</TABLE>\n";<BR>
<BR>
#<BR>
# generate "short-list" table... same as above, but
also includes standard<BR>
# deviation in votes. Also, contains <A NAME>
information which is refered<BR>
# to by links in the standard list. This hashing scheme
of <BR>
# "ARTIST _ ALBUM" and then remove all characters not
in the range a-z, A-Z,<BR>
# 0-9 and _ is used as a standard throughout this program to uniquely
<BR>
# identify any album.<BR>
#<BR>
<BR>
#<BR>
# create an array with the file names of all .cdd files within
<BR>
#<BR>
@cddfile = <*.cdd>;<BR>
<BR>
print "<H3>The Short List</H3>\n";
<BR>
print "<TABLE BORDER WIDTH=100%><TR>\n";
<BR>
print "<TR><TH>Artist</TH><TH>Album</TH><TH>#
Votes</TH><TH>Vote Ave.</TH>",<BR>
"<TH>Std. Dev.</TH></TR>\n";
<BR>
foreach ( @shortlist ) {<BR>
@field = split(/\t/,$_,5);
<BR>
<BR>
#<BR>
# Create the standard deviation for an entry in the short list. This
is<BR>
# done using the formula:<BR>
# StDev = ( (1/n) * sigma(i=1,i=n,(VOTE_i
- Average Vote)^2) ) ^ 1/2<BR>
#<BR>
# VOTE_i is determined by parsing each and every .cdd file and
checking for<BR>
# references to the album currently being parsed for<BR>
#<BR>
$stdev = 0;<BR>
$n = 0;<BR>
$average = $field[4]/$field[3];
<BR>
<BR>
foreach $cddf ( @cddfile )
{<BR>
open(CDD,$cddf);
<BR>
while (
<CDD> ) {<BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -