#! /usr/local/bin/perl # defaults, change these and the #! line to move $datadir = "."; $dataurl = "/challenge/Archive/98-99/awardsday"; $header = "header.html"; $footer = "footer.html"; $mail = "chidhkra\@mode.lanl.k12.nm.us"; $datafile = "data.txt"; # the all important error sub routine sub error { ($title, @rest) = @_; $myform = "
"; foreach $key (sort(keys(%form))) { $myform .= ""; } $myform .= "
keyvalue
$key$form{$key}
"; print <<"ERROR"; Content-Type: Text/html $title

Ooops...

$title

The following error has occurred:
@rest

Form data:
$myform

If you were not expecting this error, please report it to chidhkra\@mode.lanl.k12.nm.us.

Sorry for the problem

$foot ERROR exit(0); } sub checkperson { local($pre, %form) = @_; local($pres) = sprintf("%ss", $pre); error("$pre missing or incomplete", "$pres entry was missing or incomplete from the submission") unless $form{$pres}; error("form sent wrong data", "$pres was out of range") unless ($form{$pres} eq "Male" || $form{$pres} eq "Female" || $form{$pres} eq "-"); } #from sanity check needs check person sub formsanity { local(%form) = @_; local($pre); foreach $pre ("t1", "t2", "a", "d", "s1", "s2", "s3", "s4", "s5") { checkperson($pre, %form); } } # setsexopt, sets up the html options for different Genders passed in sub setsexopt { local($sex) = @_; $sexopt = "


"; } print <<"ENDFORM"; If you plan to attend, please fill out and submit this form by APRIL 7.

Note: Teams must submit a final report in order to attend Awards Day


School Name:

Team Number:


Notes: Students and Teachers Not on this list will Not be allowed to go on the tours. Your name on this form must be exactly as it appears on your picture identification, which you must bring to be admitted to the program.


Coming:First:Last:Username:Gender:US Citizen:
Teachers:
Project Advisor:
Driver or Chaperone (If not teacher):
Students:

Team Contact Person:
(Person to contact about registration)
First:Last:Email:Phone:

Are you traveling more than 150 miles to get to Los Alamos?

Tours will take place from 1:00 to 5:00 on Tuesday, from 8:00 to 9:30 on Wednesday, and from 1:00 to 5:00 on Wednesday. The afternoon tours each day will be the same. Which afternoon would your team like to go on a tour? (select just one day)


Once you are done filling out this form, please it. Or you can start over.

Thank You

ENDFORM } sub checkdata { local(%form) = @_; local($msg) = ""; if($form{'team'} > 128 || $form{'team'} < 1) {$msg .= "
  • Team number $form{'team'} is out of range

    ";} foreach $pre ("t1", "t2", "a", "d", "s1", "s2", "s3", "s4", "s5") { $coming = sprintf("%sc", $pre); $last = sprintf("%sl", $pre); $first = sprintf("%sf", $pre); $middle = sprintf("%sm", $pre); $sex = sprintf("%ss", $pre); if($form{$coming} eq "on") { $msg .= "

  • Last name missing for $form{$first}

    " unless $form{$last}; $msg .= "

  • First name missing for $form{$last}

    " unless $form{$first}; $msg .= "

  • Gender missing for $form{$last}

    " unless ($form{$sex} ne "-"); } } $msg .= "

  • Contact name was missing

    " unless ($form{'contactf'} && $form{'contactl'}); $msg .= "

  • Contact email was missing

    " unless $form{'contactm'}; $msg .= "

  • Contact phone number was missing

    " unless $form{'contactp'}; return($msg); } sub escape { local(@list) = @_; foreach $var (@list) { $var =~ s/\\/\\\\/g; $var =~ s/:/\\:/g; $var =~ s/!/\\!/g } return(@list); } sub saveindividual { local($title, $pre, %form) = @_; local($last) = sprintf("%sl", $pre); local($first) = sprintf("%sf", $pre); local($middle) = sprintf("%sm", $pre); local($sex) = sprintf("%ss", $pre); local($us) = sprintf("%sh", $pre); $us = $form{$us} eq "on" ? "US" : "foreign"; #error("We made it this far!"); ($title, $last, $first, $middle, $sex) = escape($title, $form{$last}, $form{$first}, $form{$middle}, $form{$sex}); return "$title:$last:$first:$middle:$sex:$us\n"; } sub savedata { local(%form) = @_; error("Datafile missing", "The data file $datafile does not exist") unless -e $datafile; open(datafile, ">> $datafile") || error("Problem opening datafile", "Cannot open datafile $datafile: $!"); ($form{'team'}, $form{'school'}) = escape($form{'team'}, $form{'school'}); $form{'distance'} = $form{'distance'} eq "on" ? "far" : "near"; print datafile "#$form{'team'}:$form{'school'}:$form{'distance'}\n"; print datafile saveindividual("teacher", "t1", %form) unless $form{'t1c'} ne "on"; print datafile saveindividual("teacher", "t2", %form) unless $form{'t2c'} ne "on"; print datafile saveindividual("advisor", "a", %form) unless $form{'ac'} ne "on"; print datafile saveindividual("driver", "d", %form) unless $form{'dc'} ne "on"; print datafile saveindividual("student", "s1", %form) unless $form{'s1c'} ne "on"; print datafile saveindividual("student", "s2", %form) unless $form{'s2c'} ne "on"; print datafile saveindividual("student", "s3", %form) unless $form{'s3c'} ne "on"; print datafile saveindividual("student", "s4", %form) unless $form{'s4c'} ne "on"; print datafile saveindividual("student", "s5", %form) unless $form{'s5c'} ne "on"; ($form{'contactf'}, $form{'contactl'}, $form{'contactm'}, $form{'contactp'}) = escape($form{'contactf'}, $form{'contactl'}, $form{'contactm'}, $form{'contactp'}); print datafile "contact:$form{'contactf'}:$form{'contactl'}:$form{'contactm'}:$form{'contactp'}\n"; print datafile "Tour day:$form{'tourday'}\n"; # print datafile saveindividual("contact", "con", %form); close(datafile); } sub printthanks { local(%form) = @_; local($seeyou) = "April 27th"; $seeyou = "April 28th" unless $form{'distance'} eq "on"; print<<"THANKS"; Your registration is complete. If you have any problems or have any changes, please send mail to chidhkra\@mode.lanl.k12.nm.us. We're looking forward to seeing you on $seeyou.

    THANKS } # get the header and footer, report errors if necessary -e "$datadir/$header" || &error("Cannot open header file", "Header file $datadir/$header does not exist."); open(header, "$datadir/$header") || &error("Cannot open header file", "Cannot open header file $datafile/$header because $!."); $head = ""; while(

    ) {$head .= $_; } close(header); -e "$datadir/$footer" || &error("Cannot open footer file", "Footer file $datadir/$footer does not exist."); open(footer, "$datadir/$footer") || &error("Cannot open footer file", "Cannot open footer file $datafile/$footer because $!."); $foot = ""; while(