#!C:/perl/bin/perl.exe use CGI::Carp qw(fatalsToBrowser); use CGI; $query = new CGI; $pass = $query->param('pass'); $pin = $query->param('pin'); $password = $query->param('password'); $v01= $query->param('v01'); $v02= $query->param('v02'); $v03= $query->param('v03'); $v04= $query->param('v04'); $v05= $query->param('v05'); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year = 1900 + $year; $mon= $mon+1; $hour = $hour - 1; $date1= "$mon/$mday/$year"; $date2= "$hour:$min:$sec"; print $query->header; print $query->start_html(-title=>'Homework 7'); print " \n\n"; if($pass < 1) { $pass = 0; } if ($pass == 3) { open(INFO, "$ENV{'DOCUMENT_ROOT_OLD'}/www/P593/userlist.txt"); @passdata = ; close(INFO); $check = 0; foreach $key (@passdata) { @a=split(/,/,$key); if($a[0] eq $pin && $a[1] eq $password) { $check = 1; } } if ($check == 0) { print ""; print "The username and/or password you entered appear to be invalid. Please re-enter your username and password"; print ""; print ""; print ""; } else { open(INFO, ">>$ENV{'DOCUMENT_ROOT_OLD'}/www/heplerlabs.com/P593/$pin-participation.txt"); print INFO "$date1,$date2,$v01,$v02,$v03,$v04,$v05,endline\n"; close(INFO); open(INFO, "$ENV{'DOCUMENT_ROOT_OLD'}/www/heplerlabs.com/P593/$pin-participation.txt"); @data = ; close(INFO); $total_count = 0; $j = 0; foreach $row (@data) { $total_count = $total_count + 1; } print "Thanks for participating!"; print "So far you have participated $total_count times!"; print ""; print "AttemptDateTime"; foreach $row (@data) { #($date1,$date2,$v0,$v1,$v2,$v3,$v4,endline\n) $j++; @participant = split(/,/,$row); print "$j$participant[0]$participant[1]"; } print ""; print "Return to Hepler Labs\n"; } } elsif ($pass == 2) { open(INFO, "$ENV{'DOCUMENT_ROOT_OLD'}/www/P593/userlist.txt"); @passdata = ; close(INFO); $check = 0; foreach $key (@passdata) { @a=split(/,/,$key); if($a[0] eq $pin && $a[1] eq $password) { $check = 1; } } if ($check == 0) { print ""; print "The username and/or password you entered appear to be invalid. Please re-enter your username and password"; print ""; print ""; print ""; } else { print ""; @items = ('The mind is equivalent to the brain', 'The mind is a non-physical property', 'It is impossible for science to ever have a complete understanding of the mind', 'My thoughts, personality, preferences, and choices are all just a product of my brain functions', 'Whether one is a good or bad person can be completely altered by changes in the brain'); @variables = (v01, v02, v03, v04, v05); @numbers1 = &randomize(0,1,2,3,4); $k = 1; print "Attitudes Toward Dualism"; for($i = 0; $i <= 4; $i++) { print "$k. $items[$numbers1[$i]]"; print "Strongly Disagree"; print ""; print ""; print ""; print ""; print ""; print "Stronlgy Agree"; $k++; } print ""; $pass = 3; &passhidden(); print ""; } } elsif ($pass == 1) { open(INFO, "$ENV{'DOCUMENT_ROOT_OLD'}/www/P593/userlist.txt"); @passdata = ; close(INFO); $error = 0; foreach $key (@passdata) { @a=split(/,/,$key); if($a[0] eq $pin) { $error = 1; } } if ($error == 1) { print "That username has already been taken."; print ""; print ""; $pass = 0; &passhidden(); print ""; } else { open(INFO, ">>$ENV{'DOCUMENT_ROOT_OLD'}/www/P593/userlist.txt"); print INFO "$pin,$password,$date1,$date2,endline\n"; close(INFO); print "Your username will be $pin."; print ""; print ""; print ""; &passhidden(); print ""; } } elsif ($pass == 0) { print ""; print "Create new account Enter a username Choose a name to use to login to this site in the future. Please use only lower case letters and/or numbers and no spaces. Enter a password Be sure to write this down. "; $pass = 1; print ""; &passhidden(); print ""; print ""; print "If you already have an account, log in here: Enter a username Enter a password "; print ""; print ""; &passhidden(); print ""; } print $query->end_html; #Passes variables that the user has entered sub passhidden { print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; } sub randomize { # this subroutine randomizes the elements of an array and returns the new array srand; my(@new) = (); while (@_){ push(@new, splice(@_, rand @_,1)); } return @new; }