#!C:/perl/bin/perl.exe use CGI::Carp qw(fatalsToBrowser); use CGI; $query = new CGI; # Read in the variables $pass= $query->param('pass'); $pin= $query->param('pin'); $password= $query->param('password'); $r0= $query->param('r0'); $r1= $query->param('r1'); $r2= $query->param('r2'); $r3= $query->param('r3'); $r4= $query->param('r4'); $r5= $query->param('r5'); $FNL= $query->param('FNL'); $Castle= $query->param('Castle'); $Modfam= $query->param('Modfam'); @itemIndex= $query->param('itemIndex'); print $query->header; print $query->start_html(-title=>'Login'); print " \n\n"; #----------------------------------- # Check login status #----------------------------------- # Open the txt file containing the usernames and passwords and dump those data to # @passdata open(INFO, "$ENV{'DOCUMENT_ROOT_OLD'}/www/relationshipsresearch.com/P593/data/userlist.txt"); @passdata = ; close(INFO); # Sort through each line of @passdata until we find a match between both the username and password # If a match is found, change the value of $match to 1. It is set to 0 by default. $match = 0; foreach $key (@passdata){ @a=split(/,/,$key); if($a[0] eq $pin && $a[1] eq $password){ $match=1; } } # If no match was found, provide an error msg. if($match !=1){ print "We cannot find a record of either that user name ($pin) or password.

"; print "If you think you may have made a typo, please click your browser's Back button and try again.

"; } # If the username/password match those stored on the master list on the server, # move forward and present the survey and do other things. if($match == 1){ # Set pass = 0 if($pass < 1){ $pass = 0; } #----------- # pass = 1 #----------- if($pass == 1){ print "
"; # Get the average scores for each television show # Friday Night Lights $FNL = &averageScores($r0,$r3); # Castle $Castle = &averageScores($r1,$r4); # Modern Family $Modfam = &averageScores($r2,$r5); # save the data to a text file open(INFO, ">>$ENV{'DOCUMENT_ROOT_OLD'}/www/relationshipsresearch.com/P593/data/HW7.txt"); print INFO "$pin,$password"; print INFO "$date1,$date2"; print INFO "$r0,$r1,$r2,$r3,$r4,$r5,$FNL,$Castle,$Modfam,"; print INFO "endline\n"; close (INFO); # Participant Feedback # Friday Night Lights if($FNL >= $Castle && $FNL >= $Modfam) { print ""; print ""; print ""; print ""; print ""; print ""; print "
"; print ""; print ""; print "
You should watch...
"; print "
"; print ""; print "
Friday Night Lights!
"; print "
"; } # Castle elsif($Castle >= $Modfam) { print ""; print ""; print ""; print ""; print ""; print ""; print "
"; print ""; print ""; print "
You should watch...
"; print "
"; print ""; print "
Castle!
"; print "
"; } # Modern Family elsif($Modfam >= $Castle) { print ""; print ""; print ""; print ""; print ""; print ""; print "
"; print ""; print ""; print "
You should watch...
"; print "
"; print ""; print "
Modern Family!
"; print "
"; } } # end pass = 1 print "
"; #----------- # pass = 0 #----------- if($pass == 0){ print "
"; print "
Discover your new favorite television show!
"; print "Answer the following questions and we will tell you what television shows you should be watching.

"; # randomly present items $v0 = "The characters are the most important part of a TV show."; $v1 = "I prefer crime mysteries."; $v2 = "I enjoy comedies about family life."; $v3 = "Handsome football players in a TV show is a bonus."; $v4 = "If a TV show opened with a bridesmaid getting murdered on the night of the rehearsal dinner, I'd have to watch to see who killed her."; $v5 = "Eavesdropping on the neighbors via a faulty baby monitor sounds like something I would do."; @itemIndex = &randomize(0,1,2,3,4,5); @variableNames = (r0,r1,r2,r3,r4,r5); @items = ($v0,$v1,$v2,$v3,$v4,$v5); for ($i=0;$i<=5;$i++) { print "$items[$itemIndex[$i]]

"; &printLikert5($variableNames[$itemIndex[$i]]); } print ""; print ""; &passHidden(); print "
"; } # end pass = 0 } # end match == 1 #---------------------- # SUBROUTINES #---------------------- #----------------------- # passHidden Subroutine #----------------------- sub passHidden { print $query->hidden(itemIndex, @itemIndex); print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; } #----------------------- # randomize Subroutine #----------------------- 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; } #----------------------- # printLikert5 Subroutine #----------------------- sub printLikert5 { # Subroutine by Jenn Smith print " Strongly Disagree
\n Disagree
\n Neutral
\n Agree
\n Strongly Agree


\n\n"; } #----------------------- # averageScores Subroutine #----------------------- sub averageScores { # sub for averaging scores and adjusting denom for missing cases # fraley march 26 2005 # returns mean, takes as param an array or seq of values # returns zero if no valid cases $nSUB = @_; $validnSUB = 0; $sumSUB = 0; for($iSUB=0;$iSUB<=($nSUB-1);++$iSUB){ if($_[$iSUB] > 0){ $sumSUB = $sumSUB + $_[$iSUB]; $validnSUB = $validnSUB + 1; } } $mean = 0; if($validnSUB > 0){ $mean = $sumSUB/$validnSUB; } return $mean; } # end sub print $query->end_html;