#! /usr/local/bin/perl

# 6.837
# Created by JP Mellor for Fall 1995
# Modified by KB (kaybee@graphics.lcs.mit.edu) for Fall 1996

do '6837-cgihacks.pl';
chdir "/u2/graphics/WWW/classes/6.837/F97";

&find_form_args('name|nickname|course|year|email|url|learn|graphics|calculus|linear|probability|dsp|sgi|cp|c|gl|mm|me|tm|te|wm|we|hm|he|fm|fe|credit|picture|incpic|algorithms|java|banana');

#supply default value for removed field in form
$banana = "no";

#check for empty fields.
if ("$mm" eq "UNDEFINED" ||
    "$me" eq "UNDEFINED" ||
    "$tm" eq "UNDEFINED" ||
    "$te" eq "UNDEFINED" ||
    "$wm" eq "UNDEFINED" ||
    "$we" eq "UNDEFINED" ||
    "$hm" eq "UNDEFINED" ||
    "$he" eq "UNDEFINED" ||
    "$fm" eq "UNDEFINED" ||
    "$fe" eq "UNDEFINED") {
    $timeconstraints = "UNDEFINED";
}

if ("$sgi" eq "UNDEFINED" ||
    "$cp"  eq "UNDEFINED" ||
    "$c"   eq "UNDEFINED" ||
    "$java" eq "UNDEFINED" ||
    "$banana" eq "UNDEFINED" ||
    "$gl"  eq "UNDEFINED") {
    $experience = "UNDEFINED";
}


if ("$graphics" eq "UNDEFINED" ||
    "$calculus"  eq "UNDEFINED" ||
    "$linear"   eq "UNDEFINED" ||
    "$algorithms"   eq "UNDEFINED" ||
    "$dsp"   eq "UNDEFINED" ||
    "$probability"  eq "UNDEFINED") {
    $acadexperience = "UNDEFINED";
}


#########################################################
#  do some basic error checking
#
&cgidie ('You forgot to specify your name!') if "$name" eq '';
&cgidie ('You forgot to specify your course!') if "$course" eq "UNDEFINED";
&cgidie ('You forgot to specify your year!') if "$year" eq "UNDEFINED";
&cgidie ('You forgot to specify your email address!') if "$email" eq '';
&cgidie ('You forgot to fully specify the courses you have taken previously!') if "$acadexperience" eq "UNDEFINED";
&cgidie ('You forgot to fully specify your experience with C/C++/GL/SGI machines!') if "$experience" eq "UNDEFINED";
&cgidie ('You forgot to specify scheduling constraints for reviews etc.!') if "$timeconstraints" eq "UNDEFINED";
&cgidie ('You forgot to specify where your picture is!') if "$picture" eq '';
&cgidie ('You forgot to specify if we can include your picture!') if "$incpic" eq '';
&cgidie ('You forgot to specify if you will take this course for credit!') if "$credit" eq 'UNDEFINED';

#########################################################
#  write out the data
#

#
#  fix formattting on a few fields
#
$name =~s/\n/\013/g;		# change newline to ^K (vert. tab)
$name =~s/\t/\040/g;		# change a tab to a space
# 
#
#  now open and write
#

chdir "/u2/graphics/WWW/classes/6.837/F97";

if (!open(PENDING, ">/u2/graphics/WWW/classes/6.837/F97/data/$email"))
{
    print "Content-type: text/html\n\n";
    print "Error: Could not write data file.\n";
    exit;
}

print PENDING "full name: $name\n";
print PENDING "prefered name: $nickname\n";
print PENDING "course: $course\n";
print PENDING "year: $year\n";
print PENDING "email: $email\n";
print PENDING "url: $url\n";
print PENDING "graphics: $graphics\n";
print PENDING "calculus: $calculus\n";
print PENDING "linear: $linear\n";
print PENDING "probability: $probability\n";
print PENDING "dsp: $dsp\n";
print PENDING "sgi: $sgi\n";
print PENDING "c++: $cp\n";
print PENDING "c: $c\n";
print PENDING "gl: $gl\n";
print PENDING "monday morning: $mm\n";
print PENDING "monday evening: $me\n";
print PENDING "tuesday morning: $tm\n";
print PENDING "tuesday evening: $te\n";
print PENDING "wednesday morning: $wm\n";
print PENDING "wednesday evening: $we\n";
print PENDING "thursday morning: $hm\n";
print PENDING "thursday evening: $he\n";
print PENDING "friday morning: $fm\n";
print PENDING "friday evening: $fe\n";
print PENDING "credit: $credit\n";
print PENDING "picture: $picture\n";
print PENDING "incpic: $incpic\n";
print PENDING "algorithms: $algorithms\n";
print PENDING "java: $java\n";
print PENDING "banana: $banana\n";
print PENDING "learn: $learn\n";
close PENDING;


# change ownership to user "legakis" and group "ta6873":
@filenames[0] = "/u2/graphics/WWW/classes/6.837/F97/data/$email";
$uid = 13182;
$gid = 15102;
chmod(0666, @filenames);
chown($uid, $gid, @filenames);


$host = $ENV{'REMOTE_HOST'};

print <<EOF;
Content-type: text/html

<title>Thank you for completing our registration form</title>
<h1>Thanks for completing our registration form</h1><p>

Is this the picture you wish to submit?<p>

<img src=$picture><p>

If so, you are done.<p>

If not, obtain a new picture and complete the registration form again.<p>

Thank you completing our registration form.<p>

EOF












