print MAILOUT "Date_Time: "."$date\n"; # For each form field, print the form field and value. foreach $field (@Field_Order) { print MAILOUT "$field: $Form{$field}\n"; } # Print blank line after each form print MAILOUT "\n"; close(MAILOUT); } else { print "Content-type: text/html\n\n"; print ""; print ""; print " $studyname "; print ""; print ""; print ""; print "
"; print "
"; print "The server is busy.
"; print "Please press the Back button on your browser and try again."; print "
"; print "
"; print "
"; print ""; print ""; close(STDOUT); exit 0; } } # ----------------------------------------------------------------------------- # --------- Remove bookmark and add id=xxx from the end of nexturl link ------- # --------- Format: url?id=xxx ------- # ----------------------------------------------------------------------------- $bookmark=''; $Position = index($nexturl,"#"); if ($Position > 0) { $bookmark = substr($nexturl,$Position+1); $nextpage = substr($nexturl,0,$Position); } else { $nextpage = $nexturl; } $finalurl = $nextpage."?id=".$respondentID; # ------------------------------------------------------------------ # ---- Load the next page and substitute the hidden variable(s) ---- # ------------------------------------------------------------------ # ---- Substitute the hidden fields ---- $P = get($finalurl); $hidden = ""; $substring = "\n"; if ($currentpage > $highestpage) { $highestpage = $currentpage; } $substring .= "\n"; # ----------------------------------------------------------------------------- # ----- Write the retain fields as a hidden field on the next survey page ----- # ---- Format for the retain field is: "/VARNAME/VARNAME/VARNAME/" ----- # ----------------------------------------------------------------------------- foreach $field (@Field_Order) { $lookfor = "/".$field."/"; if ($retain =~ m/$lookfor/i) { $substring .= "\n"; } } $P =~ s/$hidden/$substring/gis; # ------------------------------------------------------------- # -------------- Do a substitution for any pipes -------------- # ------------------------------------------------------------- while (index($P, "\(*") != -1) { $startpos = index($P, "(*"); $endpos = index($P, "*)", startpos); $replacethis = substr($P, $startpos, $endpos - $startpos + 2); $varname = substr($P, $startpos + 2, $endpos - $startpos - 2); # Find the hidden field that contains the current value of $varname $lookfor = "hidden\" name=\"".$varname."\" value=\""; $startpos = index($P, $lookfor); if ($startpos == -1) { $currentvalue = ""; } else { $startpos += length($lookfor); $endpos = index($P, "\"", $startpos); $currentvalue = substr($P, $startpos, $endpos - $startpos); } # Find the $pipe for variable $varname_pipe value field - Format: ^^1=abc^^2=xyz^^ $lookfor = "hidden\" name=\"".$varname."_pipe\" value=\""; $startpos = index($P, $lookfor); if ($startpos == -1) { $pipetext = $currentvalue; } else { $startpos += length($lookfor); $lookfor = "^^".$currentvalue."="; $startpos = index($P, $lookfor, $startpos); if ($startpos == -1) { $pipetext = ""; } else { $startpos += length($lookfor); $endpos = index($P, "^^", $startpos); $pipetext = substr($P, $startpos, $endpos - $startpos); } } $P =~ s/\Q$replacethis/$pipetext\E/gs; } # ----------------------------------------------------------------- # ---- Rotate value labels for radio button rotation variables ---- # ----------------------------------------------------------------- # Variable names to be rotated are stored in $rotate_radio # Format for $rotate-radio is: VARNAMEx^^VARNAMEy^^VARNAMEz^^ # Where the x, y, and z are the number of value labels not rotated (holdouts) # Are there any radio button rotations on this page? $lookfor = "hidden\" name=\"rotate_radio\" value=\""; $startpos = index($P, $lookfor); if ($startpos != -1) { $startpos += length($lookfor); $endpos = index($P, "\"", $startpos); $rotate_vars = substr($P, $startpos, $endpos - $startpos); @rotate_variables = split(/\^\^/,$rotate_vars); $number_rotate_variables = scalar(@rotate_variables); $var_counter = 0; # Do for each variable on this page to be rotated while ($var_counter < $number_rotate_variables) { $varname = $rotate_variables[$var_counter]; $varname =~ s/\^\^//g; # Remove number at end of name (x, y, z) $holdouts = substr($varname,length($varname)-1,1); $varname = substr($varname,0,length($varname)-1); # Do for each occurance of the varname in the html # Find position in html for value and substitute (*RBPos*) # Html example: Yes< $startpos = 0; $sub_counter = 0; while ($startpos != -1) { $lookfor = "radio\" name=\"".$varname."\" value=\""; $startpos = index($P, $lookfor); if ($startpos != -1) { $endpos = index($P, "\<", $startpos); $lookfor = "\ 0) { $tmp = $sub_counter - 1; $lookfor = "(*RBPos".$tmp."*)"; $startpos = index($P, $lookfor); if ($startpos != -1) { $endpos = index($P, "\<", $startpos); $P = substr($P,0,$startpos).$rotatetext[$sub_counter - 1].substr($P,$endpos); $sub_counter = $sub_counter - 1; } $holdouts = $holdouts - 1; } # Initialize $used[] to zero for($counter=0 ; $counter < $sub_counter ; $counter++) { $used[$counter] = 0; } $remaining = $sub_counter; # Generate a random integer between 0 and $sub_counter - 1 # Find (*RBPos?*) in html and substitute the random selection while ($remaining > 0) { $random = int(rand($sub_counter)); if ($used[$random] != 1) { $tmp = $remaining - 1; $lookfor = "(*RBPos".$tmp."*)"; $startpos = index($P, $lookfor); if ($startpos != -1) { $endpos = index($P, "\<", $startpos); $P = substr($P,0,$startpos).$rotatetext[$random].substr($P,$endpos); } $used[$random] = 1; $remaining = $remaining - 1; } } $var_counter += 1; } } # ---------------------------------------------------------- # ---- Rotate variables and value labels for checkboxes ---- # ---------------------------------------------------------- # Variable name of rotation is held in $rotate_checkbox # Format $rotate_checkbox field is: "VARNAME1^^VARNAME2^^VARNAME3^^::VARNAME1^^VARNAME2^^" # # looks like this in the html # Internet
# Magazine or Newsletter
# Word of mouth
# Other< # Are there are any checkbox rotations on this page? $lookfor = "hidden\" name=\"rotate_checkbox\" value=\""; $startpos = index($P, $lookfor); if ($startpos != -1) { $startpos += length($lookfor); $endpos = index($P, "\"", $startpos); $rotate_vars = substr($P, $startpos, $endpos - $startpos); @rotate_groups = split(/\:\:/,$rotate_vars); $number_rotate_groups = scalar(@rotate_groups); $group_counter = 0; # Do for each group of checkbox variables while ($group_counter < $number_rotate_groups) { @rotate_variables = split(/\^\^/,$rotate_groups[$group_counter]); $number_rotate_variables = scalar(@rotate_variables); $var_counter = 0; # Do for each checkbox rotation in this group while ($var_counter < $number_rotate_variables) { $varname = $rotate_variables[$var_counter]; $varname =~ s/\^\^//g; # Find the checkbox tag in the html - "checkbox" name="Hear_1" value="1">Internet<" # Load $rotatetext[] with the current and make it easy to find in the next pass $lookfor = "checkbox\" name=\"".$varname."\" value=\""; $startpos = index($P, $lookfor); if ($startpos != -1) { $endpos = index($P, "\<", $startpos); $lookfor = "\ 0) { $random = int(rand($number_rotate_variables)); if ($used[$random] != 1) { $tmp = $remaining - 1; $lookfor = "(*CBPos".$tmp."*)"; $startpos = index($P, $lookfor); if ($startpos != -1) { $endpos = index($P, "\<", $startpos); $P = substr($P,0,$startpos).$rotatetext[$random].substr($P,$endpos); } $used[$random] = 1; $remaining = $remaining - 1; } } $group_counter += 1; } } # ------------------------------------------------- # ---- Rotate variables in a horizontal format ---- # ------------------------------------------------- # Looks like this: # # 5e. Power and completeness. # # # # # # # Search for: type="radio" name="Power" # Substitute all of them with CBPosX # Variable name of rotation is held in $rotate_radio_horizontal # Format $rotate_checkbox field is: "VARNAME1^^VARNAME2^^VARNAME3^^::VARNAME1^^VARNAME2^^" # # Are there are any radio_horizontal rotations on this page? $lookfor = "hidden\" name=\"rotate_radio_horizontal\" value=\""; $startpos = index($P, $lookfor); if ($startpos != -1) { $startpos += length($lookfor); $endpos = index($P, "\"", $startpos); $rotate_vars = substr($P, $startpos, $endpos - $startpos); @rotate_groups = split(/\:\:/,$rotate_vars); $number_rotate_groups = scalar(@rotate_groups); $group_counter = 0; # Do for each group of horizontal radio buttons while ($group_counter < $number_rotate_groups) { @rotate_variables = split(/\^\^/,$rotate_groups[$group_counter]); $number_rotate_variables = scalar(@rotate_variables); $var_counter = 0; # Do for each checkbox rotation in this group while ($var_counter < $number_rotate_variables) { $varname = $rotate_variables[$var_counter]; $varname =~ s/\^\^//g; # Find the 1st horizonal radio tag in the html # Load $rotatetext[] and make it easy to find in the next pass $lookfor = "radio\" name=\"".$varname."\" value=\""; $startpos = index($P, $lookfor); if ($startpos != -1) { $endpos = index($P, "\<\/tr>", $startpos); $lookfor = "\"; $startpos = rindex($P, $lookfor, $startpos) + 4; if ($endpos != -1) { $rotatetext[$var_counter] = substr($P, $startpos, $endpos - $startpos); $P = substr($P,0,$startpos)."(*HRPos".$var_counter."*)".substr($P,$endpos); # Need to store color and bgcolor so the bar colors can be replaced $lookfor = " color\=\""; $startpos = index($rotatetext[$var_counter], $lookfor); $lookfor = "\""; $endpos = index($rotatetext[$var_counter], $lookfor, $startpos + 8); $color[$var_counter] = substr($rotatetext[$var_counter], $startpos, $endpos - $startpos); $lookfor = " bgcolor\=\""; $startpos = index($rotatetext[$var_counter], $lookfor); $lookfor = "\""; $endpos = index($rotatetext[$var_counter], $lookfor, $startpos + 10); $bgcolor[$var_counter] = substr($rotatetext[$var_counter], $startpos, $endpos - $startpos); } } $var_counter += 1; } # Initialize $used() to zero for($counter=0 ; $counter < $number_rotate_variables ; $counter++) { $used[$counter] = 0; } $remaining = $number_rotate_variables; # Generate a random integer between 0 and $number_rotate_variables - 1 # Find (*HRPos?*) in html and substitute while ($remaining > 0) { $random = int(rand($number_rotate_variables)); if ($used[$random] != 1) { $tmp = $remaining - 1; $lookfor = "(*HRPos".$tmp."*)"; $startpos = index($P, $lookfor); if ($startpos != -1) { $endpos = index($P, "\<", $startpos); # Replace color="xx" in $rotatetext[$random] with $color[$remaining-1] $rotatetext[$random] =~s/$color[$random]/$color[$remaining-1]/g; # Replace bgcol