jm0285
09-28-2003, 11:15 PM
Hi all! I am having 2 problems with this module I wrote for a distance learning program. The first is that if a user has more than one session entered int the users database and returned to the @results array I only come up with the second user listing and not the first. Second is that i cannot seem to make the return pages for links to the modules adjust to an unlimited amount (I currently have them at 10). I have included the user database and program database that this module accesses. If you guys can point me in the right direction it would be a great help! Thanks in advance!
sub user_access {
# Opens the user database and sends data to the raw_data array and closes file
open(DAT, "/export/home/blahblah/public_html/cgi-bin/userdb.txt") || die("Could not open file!");
@raw_data=<DAT>;
close(DAT);
# Prints the html response page header
print "Content-type: text/html\n\n";
print "<html>\n <head><title>Welcome to the blah blah Academy</title>\n";
print "</head>\n <body>\n";
print "<center>\n";
print "<table cellpadding=10 width=100% bgcolor=#3A9FED>\n";
print "<tr><th><font color=white size=+2>Welcome to the blah blah Academy!</font></th></tr>\n";
print "</table>
\n";
# converts usename from login page to the searchstr variable
$searchstr = $Form{'username'};
# uses grep function to search raw_data and return the line item to the results array
@results = grep(/$searchstr/,@raw_data);
# if results are greater than or equal to 0 then run sub routine, else non-user message
if ($#results >= 0) {
# for each line of returned data from results array run sub routine
foreach $i (@results){
# remove any line returns
chop($i);
# split line data at pipe and assign variable names to split data
($user,$name,$userpass,$program1,$program2,$program3,$program4,$program5,$program6,$program7,$progra m8,$program9,$program10,$endmonth,$endday,$endyear)=split(/\|/,$i);
}
# Converts to yyyymmdd format
$date2 = $endyear . $endmonth . $endday;
# check for matching username and password, else return no match message
if ($Form{'username'} eq $user && $Form{'password'} eq $userpass){
# print personalized message
print "<table>\n";
print "<tr><td><center>Welcome $name!
</center></td></tr>\n";
# compare current system date to program end date, else expired message
if ($date1 <= $date2){
# Print list header
print "<tr><td><center>Please click on the links below to access your modules.
</center></td></tr>\n";
# Opens the program database and sends data to the prog_data array and closes file
open(DAT, "/export/home/blahblah/public_html/cgi-bin/programs.txt") || die("Could not open file!");
@prog_data=<DAT>;
close(DAT);
foreach $line (@prog_data){
chop($line);
($dircode,$progname,$progdescr)=split(/\|/,$line);
if ($dircode eq $program1){
print "<tr><td>$progname (http://www.blahblah.org/restricted/$dircode/launchmodule.html)
</td></tr>\n";
}
elsif ($dircode eq $program2){
print "<tr><td>$progname (http://www.blahblah.org/restricted/$dircode/launchmodule.html)
</td></tr>\n";
}
elsif ($dircode eq $program3){
print "<tr><td>$progname (http://www.blahblah.org/restricted/$dircode/launchmodule.html)
</td></tr>\n";
}
elsif ($dircode eq $program4){
print "<tr><td>$progname (http://www.blahblah.org/restricted/$dircode/launchmodule.html)
</td></tr>\n";
}
elsif ($dircode eq $program5){
print "<tr><td>$progname (http://www.blahblah.org/restricted/$dircode/launchmodule.html)
</td></tr>\n";
}
elsif ($dircode eq $program6){
print "<tr><td>$progname (http://www.blahblah.org/restricted/$dircode/launchmodule.html)
</td></tr>\n";
}
elsif ($dircode eq $program7){
print "<tr><td>$progname (http://www.blahblah.org/restricted/$dircode/launchmodule.html)
</td></tr>\n";
}
elsif ($dircode eq $program8){
print "<tr><td>$progname (http://www.blahblah.org/restricted/$dircode/launchmodule.html)
</td></tr>\n";
}
elsif ($dircode eq $program9){
print "<tr><td>$progname (http://www.blahblah.org/restricted/$dircode/launchmodule.html)
</td></tr>\n";
}
elsif ($dircode eq $program10){
print "<tr><td>$progname (http://www.blahblah.org/restricted/$dircode/launchmodule.html)
</td></tr>\n";
}
}
# print list footer
print "<tr><td><center>
You have until $endmonth/$endday/$endyear to complete your modules.
<hr>\n";
print "$date1
<hr></center></td></tr>\n";
}
# print expired message
else {
print "<tr><td><center>Your 30 day session expired on $endmonth/$endday/$endyear.
\n";
print "Please re-register on-line or call
\n";
print "blahblah Ext. 133.
<hr></center></td></tr>\n";
}
}
# print no match message
else {
print "<tr><td><center>Sorry, your username and password do not match.
\n";
print "If you are having trouble logging in please call
\n";
print "blahblah Ext. 133.
<hr></center></td></tr>\n";
}
}
# print non-user message
elsif ($#results < 0) {
print "<td><tr><center>
You are not a registered user.[/b]</center></td></tr>\n";
}
# Print the html response page footer
print "[/b]</center></table></body></html>\n";
}
The user database:
murphy|James M|2bon2b|h2h|itm|fp||||||||10|01|2003|
mckeefe|John M|lawyer|h2h|freezer|nfpa25|nfpa13|coc||||||10|21|2003|
dawn|Dawn F|admin|coc|nfpa25|itm|fp|h2h||||||01|02|2004|
murphy|James M|2bon2b|coc|freezer|nfpa13||||||||10|30|2003|
The program database:
h2h|Homes To High-Rise|Residential Sprinkler Program|
itm|Inspection, Testing and maintenance|Maintenance of Fire Protection Systems|
nfpa13|NFPA 13 requirements|NFPA Standards of 13D Systems|
coc|Classification of Commodities|Classifying Commodities Into Groups|
fp|Fire Pumps|Selection and Uses of Fire Sprinkler Pumps|
hydraulics|Hydraulics for Fire Potection|Calculation to Ensure Proper Pressures|
freezer|Freezer Protection|Protecting Freezers with Fire Sprinklers|
nfpa25|NFPA 25 ITM Course|ITM course using standards of NFPA25|
sub user_access {
# Opens the user database and sends data to the raw_data array and closes file
open(DAT, "/export/home/blahblah/public_html/cgi-bin/userdb.txt") || die("Could not open file!");
@raw_data=<DAT>;
close(DAT);
# Prints the html response page header
print "Content-type: text/html\n\n";
print "<html>\n <head><title>Welcome to the blah blah Academy</title>\n";
print "</head>\n <body>\n";
print "<center>\n";
print "<table cellpadding=10 width=100% bgcolor=#3A9FED>\n";
print "<tr><th><font color=white size=+2>Welcome to the blah blah Academy!</font></th></tr>\n";
print "</table>
\n";
# converts usename from login page to the searchstr variable
$searchstr = $Form{'username'};
# uses grep function to search raw_data and return the line item to the results array
@results = grep(/$searchstr/,@raw_data);
# if results are greater than or equal to 0 then run sub routine, else non-user message
if ($#results >= 0) {
# for each line of returned data from results array run sub routine
foreach $i (@results){
# remove any line returns
chop($i);
# split line data at pipe and assign variable names to split data
($user,$name,$userpass,$program1,$program2,$program3,$program4,$program5,$program6,$program7,$progra m8,$program9,$program10,$endmonth,$endday,$endyear)=split(/\|/,$i);
}
# Converts to yyyymmdd format
$date2 = $endyear . $endmonth . $endday;
# check for matching username and password, else return no match message
if ($Form{'username'} eq $user && $Form{'password'} eq $userpass){
# print personalized message
print "<table>\n";
print "<tr><td><center>Welcome $name!
</center></td></tr>\n";
# compare current system date to program end date, else expired message
if ($date1 <= $date2){
# Print list header
print "<tr><td><center>Please click on the links below to access your modules.
</center></td></tr>\n";
# Opens the program database and sends data to the prog_data array and closes file
open(DAT, "/export/home/blahblah/public_html/cgi-bin/programs.txt") || die("Could not open file!");
@prog_data=<DAT>;
close(DAT);
foreach $line (@prog_data){
chop($line);
($dircode,$progname,$progdescr)=split(/\|/,$line);
if ($dircode eq $program1){
print "<tr><td>$progname (http://www.blahblah.org/restricted/$dircode/launchmodule.html)
</td></tr>\n";
}
elsif ($dircode eq $program2){
print "<tr><td>$progname (http://www.blahblah.org/restricted/$dircode/launchmodule.html)
</td></tr>\n";
}
elsif ($dircode eq $program3){
print "<tr><td>$progname (http://www.blahblah.org/restricted/$dircode/launchmodule.html)
</td></tr>\n";
}
elsif ($dircode eq $program4){
print "<tr><td>$progname (http://www.blahblah.org/restricted/$dircode/launchmodule.html)
</td></tr>\n";
}
elsif ($dircode eq $program5){
print "<tr><td>$progname (http://www.blahblah.org/restricted/$dircode/launchmodule.html)
</td></tr>\n";
}
elsif ($dircode eq $program6){
print "<tr><td>$progname (http://www.blahblah.org/restricted/$dircode/launchmodule.html)
</td></tr>\n";
}
elsif ($dircode eq $program7){
print "<tr><td>$progname (http://www.blahblah.org/restricted/$dircode/launchmodule.html)
</td></tr>\n";
}
elsif ($dircode eq $program8){
print "<tr><td>$progname (http://www.blahblah.org/restricted/$dircode/launchmodule.html)
</td></tr>\n";
}
elsif ($dircode eq $program9){
print "<tr><td>$progname (http://www.blahblah.org/restricted/$dircode/launchmodule.html)
</td></tr>\n";
}
elsif ($dircode eq $program10){
print "<tr><td>$progname (http://www.blahblah.org/restricted/$dircode/launchmodule.html)
</td></tr>\n";
}
}
# print list footer
print "<tr><td><center>
You have until $endmonth/$endday/$endyear to complete your modules.
<hr>\n";
print "$date1
<hr></center></td></tr>\n";
}
# print expired message
else {
print "<tr><td><center>Your 30 day session expired on $endmonth/$endday/$endyear.
\n";
print "Please re-register on-line or call
\n";
print "blahblah Ext. 133.
<hr></center></td></tr>\n";
}
}
# print no match message
else {
print "<tr><td><center>Sorry, your username and password do not match.
\n";
print "If you are having trouble logging in please call
\n";
print "blahblah Ext. 133.
<hr></center></td></tr>\n";
}
}
# print non-user message
elsif ($#results < 0) {
print "<td><tr><center>
You are not a registered user.[/b]</center></td></tr>\n";
}
# Print the html response page footer
print "[/b]</center></table></body></html>\n";
}
The user database:
murphy|James M|2bon2b|h2h|itm|fp||||||||10|01|2003|
mckeefe|John M|lawyer|h2h|freezer|nfpa25|nfpa13|coc||||||10|21|2003|
dawn|Dawn F|admin|coc|nfpa25|itm|fp|h2h||||||01|02|2004|
murphy|James M|2bon2b|coc|freezer|nfpa13||||||||10|30|2003|
The program database:
h2h|Homes To High-Rise|Residential Sprinkler Program|
itm|Inspection, Testing and maintenance|Maintenance of Fire Protection Systems|
nfpa13|NFPA 13 requirements|NFPA Standards of 13D Systems|
coc|Classification of Commodities|Classifying Commodities Into Groups|
fp|Fire Pumps|Selection and Uses of Fire Sprinkler Pumps|
hydraulics|Hydraulics for Fire Potection|Calculation to Ensure Proper Pressures|
freezer|Freezer Protection|Protecting Freezers with Fire Sprinklers|
nfpa25|NFPA 25 ITM Course|ITM course using standards of NFPA25|