#!/bin/csh -f

#regworkshop1997-test.csh Register people for the 1997 Scientific 
#	Investigators' workshop

#July 9, 1997 Move file updating and mail sending to before confirmation
#	message rcg
#June 13, 1997 rcg

#Check for data validity
#Provide feedback to registrant
#Save information in data file(s)
##Note: Next time, add test for last name and/or first name not valid. 7/7/97

echo "Content-type: text/html"
echo ""

echo "<title>Confirming your 1997 SI Workshop Registration Information</title>"
echo "<h2 align=center>Confirming your 1997 SI Workshop<br>"
echo "Registration Information</h2>"

set workarea=/data/rgroman/siworkshop1997
set postdata=(`/data/globec/httpd.alt/cgi-bin/poststring`)

set registration_file=/ftp/pub/si1997registration
set email_file=/ftp/pub/si1997email

#Make copies of all files
set unique="`date +%Y%b%d_%I%M%S`"

set backupreg=/ftp/pub/incoming/si1997registration.$unique
set backupemail=/ftp/pub/incoming/si1997email.$unique
cp $registration_file $backupreg
cp $email_file $backupemail 

set numb_entries=${#postdata}

##echo "debug: numb_entries=$numb_entries"
##echo "debug: postdata=$postdata"

cd $workarea

echo " <br>"
echo "The following reservation information has been submitted by"
echo "<b>$postdata[1] $postdata[2]</b> (email=$postdata[3]).<p>"

#Add mail as backup to registration file
set mailfile=/ftp/pub/incoming/mail-tmp.$unique
echo "$postdata" | tr '\015' ' ' >> $mailfile
mail rgroman@whoi.edu < $mailfile
#\rm $mailfile


##echo "debug: writing to registration file=$registration_file<br>"
echo "$postdata" | tr '\015' ' ' >> $registration_file

##echo "debug: writing to email file=$email_file<br>"
echo "# $postdata[1] $postdata[2]" >> $email_file
echo "$postdata[3],\" >> $email_file

echo " You are planning to attend <b>$postdata[4]</b> of the days.<p>"

@ meals = 0
foreach i ( 5 6 7 8 9 )
        if ($postdata[$i] == "yes") @ meals++
end

if ($meals == 0) then
	echo "You are not planning to purchase any meals<p>"
else
	echo "The $meals <b>meals</b> we will plan for you are:<br>"
	echo "<ul>"
	if ( $postdata[5] == "yes" ) echo "<li>Monday lunch<br>"
	if ( $postdata[6] == "yes" ) echo "<li>Tuesday lunch<br>"
	if ( $postdata[7] == "yes" ) echo "<li>Wednesday lunch<br>"
	if ( $postdata[8] == "yes" ) echo "<li>Monday dinner<br>"
	if ( $postdata[9] == "yes" ) echo "<li>Tuesday dinner<br>"	
	
	echo "</ul>"
endif	
echo "<p>"

echo "Dietary requirements: <b>$postdata[10]</b><p>"

echo "You <b>$postdata[11]</b> need need time (up to 15 minutes) for a talk.</p>"

echo "You <b>$postdata[12]</b> need space for posters.</p>"



##echo "debug: end of script, write out success message"
echo "<h2 align=center>You have been successfully registered.</h2>"


