#!/bin/csh -f

# /bin/csh -xv

# doupate  Update the U.S. GLOBEC Georges Bank Inventory files
# December 16, 1996 rcg

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

echo "<title>Update to U.S. GLOBEC Georges Bank Inventory, level 1</title>"
echo "<h2 align=center>Update to U.S. GLOBEC Georges Bank Inventory,"
echo "<br>level 1</h2>"

setenv HD /data/globec
set script_loc=/data/rgroman/Inventory/scripts

set datatop = /data/rgroman/Inventory
#set datatop = /data/rgroman/Inventory/debug
#echo "<p> *** Note: you are in DEBUG mode, datatop = $datatop <p>"

set inventorytop=$datatop/toplevel.dat

#set scriptcgi="invtest"
set scriptcgi="inv"

set sinames="/data/rgroman/Inventory/sinames"
cd $script_loc

setenv PATH_INFO /globec/gb/inventory.html0

set tmp=$PATH_INFO
setenv OBJ $tmp:r
unsetenv PATH_INFO

#set POSTDATA=(`$HD/httpd.alt/cgi-bin/test-env`)
set  POSTDATA=(`$HD/httpd.alt/cgi-bin/poststring`)

setenv TMP `date '+%Y.%m.%d'`

#set existing=`/data/globec/bin/transfer http://globec.whoi.edu/jg/serv/globec/gb/inventory.htm0 | grep "$POSTDATA[1]"`

set existing="`grep $POSTDATA[1] ${inventorytop}`"
set dolist=yes

if($#existing == 0) then

#	Do update of new record
###	set curopt="`cat inventoryopt | tr ' ' '\011' `"
	echo "You are adding the following <b>new</b> record to the top level inventory:"
	echo " <ul>"
	echo " <br><li>project = $POSTDATA[1]"
	echo " <br><li>platform = $POSTDATA[2]"
	echo " <br><li>year_p_start = $POSTDATA[3]"
	echo " <br><li>month_p_start = $POSTDATA[4]"
	echo " <br><li>day_p_start = $POSTDATA[5]"
	echo " <br><li>year_p_end = $POSTDATA[6]"
	echo " <br><li>month_p_end = $POSTDATA[7]"
	echo " <br><li>day_p_end = $POSTDATA[8]"
	echo " <br><li>name_prin = $POSTDATA[9]"
	echo " <br><li>brief_desc = $POSTDATA[10]"
	echo " </ul>"
	set dolist=no
	set datafile="$POSTDATA[1].dat"
##	echo "<p>**debug, datafile = $datafile"
	if(-e inventoryopt) \rm inventoryopt
	echo "$POSTDATA[1-10]	$datafile" > inventoryopt
	$script_loc/addinventory-level0
endif

# Do updating of existing record
##echo "<p>**debug - after set EXISTING"
##echo "<p>**debug EXISTING = ${EXISTING} <p>"

if($dolist == "yes") then
	set EXISTING="`grep $POSTDATA[1] ${inventorytop} | head -1 | tr ' ' '\012' | tr '\011' '\012' `"
	echo "You are updating an existing inventory record with "
	echo "the following values:"
	echo " <ul>"
	echo " <br><li>project = $EXISTING[1]"
	echo " <br><li>platform = $EXISTING[2]"
	echo " <br><li>year_p_start = $EXISTING[3]"
	echo " <br><li>month_p_start = $EXISTING[4]"
	echo " <br><li>day_p_start = $EXISTING[5]"
	echo " <br><li>year_p_end = $EXISTING[6]"
	echo " <br><li>month_p_end = $EXISTING[7]"
	echo " <br><li>day_p_end = $EXISTING[8]"
	echo " <br><li>name_prin = $EXISTING[9]"
	echo " <br><li>brief_desc = $EXISTING[10]"
	echo " </ul>"
	set datafile="$EXISTING[1].dat"
##	echo "<p>**debug, datafile = $datafile"
endif

#Create the so called level 2 (really level 1) file if necessary
if( -e ${datatop}/{$datafile} ) then
	echo "<p> The ${datatop}/${datafile} level 1 data file "
	echo "already exists. "
	echo "The existing file will be used."
else
	cp ${datatop}/level2-stub.dat ${datatop}/${datafile}
	echo "<p> Successfully created the ${datatop}/${datafile} "
	echo "level 1 data file stub."
endif

echo "<p>Fill in the form below to add additional "
echo "information about the $POSTDATA[1] project.<p>"
set dolist=no

echo "<p><hr>Check off the appropriate data type(s) and select an investigator name.  <p>"

echo "When your are satisfied with your choices, "

echo "click on <form action="\""/$scriptcgi/doupdate-level1 "\"" method="\""POST"\"">"

	echo "<input type="\""submit"\""value="\""Add to Level 1"\""><p>"

echo "For the project: <input name="\""project"\"" size="\""15"\"
echo "value="\""$POSTDATA[1]"\""> "
echo "<p>"


echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""ADCP"\""> ADCP"
echo " ... ... SI name: <select name="\""ADCP_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"



echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""Biomapper"\""> Biomapper"
echo " ... ... SI name: <select name="\""Biomapper_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""Bongo"\""> Bongo"
echo " ... ... SI name: <select name="\""Bongo_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""Crest_mooring"\""> Crest_mooring"
echo " ... ... SI name: <select name="\""Crest_mooring_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""cruise_report"\""> cruise_report"
echo " ... ... SI name: <select name="\""cruise_report_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""CTD"\""> CTD"
echo " ... ... SI name: <select name="\""CTD_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""DPP"\""> DPP"
echo " ... ... SI name: <select name="\""DPP_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""Drifter"\""> Drifter"
echo " ... ... SI name: <select name="\""Drifter_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""Drogue"\""> Drogue"
echo " ... ... SI name: <select name="\""Drogue_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""eventlog"\""> eventlog"
echo " ... ... SI name: <select name="\""eventlog_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""Greene_Bomber"\""> Greene_Bomber"
echo " ... ... SI name: <select name="\""Greene_Bomber_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""Hand_net"\""> Hand_net"
echo " ... ... SI name: <select name="\""Hand_net_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""hygrography"\""> hygrography"
echo " ... ... SI name: <select name="\""hygrography_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""MkIIICTD"\""> MkIIICTD"
echo " ... ... SI name: <select name="\""MkIIICTD_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""MkVCTD"\""> MkVCTD"
echo " ... ... SI name: <select name="\""MkVCTD_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""MOC1/4"\""> MOC1/4"
echo " ... ... SI name: <select name="\""MOC1/4_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""MOC1"\""> MOC1"
echo " ... ... SI name: <select name="\""MOC1_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""MOC10"\""> MOC10"
echo " ... ... SI name: <select name="\""MOC10_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"



echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""Mooring"\""> Mooring"
echo " ... ... SI name: <select name="\""Mooring_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""NBCTD"\""> NBCTD"
echo " ... ... SI name: <select name="\""NBCTD_SI"\"">"
$script_loc/nawkscr nd $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""PAR"\""> PAR"
echo " ... ... SI name: <select name="\""PAR_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""PNN"\""> PPN"
echo " ... ... SI name: <select name="\""PNN_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""Pump"\""> Pump"
echo " ... ... SI name: <select name="\""Pump_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""SeabirdCTD"\""> SeabirdCTD"
echo " ... ... SI name: <select name="\""SeabirdCTD_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""TAPS"\""> TAPS"
echo " ... ... SI name: <select name="\""TAPS_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""Test_System"\""> Test_System"
echo " ... ... SI name: <select name="\""Test_System_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""VPR"\""> VPR"
echo " ... ... SI name: <select name="\""VPR_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""VPR_JASON"\""> VPR_JASON"
echo " ... ... SI name: <select name="\""VPR_JASON_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""ZPN"\""> ZPN"
echo " ... ... SI name: <select name="\""ZPN_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"

echo "<p> <input type="\""checkbox"\"" name="\""data_type"\"" value="\""other"\""> other"
echo " ... ... SI name: <select name="\""other_SI"\"">"
$script_loc/nawkscr < $sinames
echo "</select>"


echo "<p>"


####endif
