#!/bin/csh -f

# /bin/csh -xv

# doupate_get_desc 
# Update the U.S. GLOBEC Georges Bank Inventory level 2 files
# Adding descriptions for each status line.

# Edited March 17 1998 Change /data to /data5 & httpd.alt reference. rcg
# February 20 1997 rcg
#
# Parameters include
#	1 = project
#	2 = data type
#	3-end = status types

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

echo "<title>Update to U.S. GLOBEC Georges Bank Inventory, doupdate-level 2, "
echo "get descriptions</title>"
echo "<h2 align=center>Update to U.S. GLOBEC Georges Bank Inventory, "
echo "<br>doupdate-level 2, get descriptions</h2>"

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

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

#echo " <p>**DEBUG - doupdate_get_desc"
set POSTDATA=(`/data/rgroman/Inventory/scripts/poststring`)
#echo "<p>**debug POSTDATA = $POSTDATA <p>"

set numb_words = ${#POSTDATA}
#echo "<p>**debug numb_words = $numb_words <p>"

set inventorytop=$datadir/toplevel.dat

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

cd $script_loc

setenv TMP `date '+%Y.%m.%d'`
#echo "<p> **debug TMP = $TMP <p>"

set current_project=$POSTDATA[1]
#echo "<p>**DEBUG current_project = $current_project <p>"

#For each data type, add data line in level 2 file, create data 
#file at level 3, make entries in level 3 file 

if ( $#POSTDATA <= 2 ) then
	echo "<p>You have not specified any status lines to add."
	echo "Ending inventory update procedure."
	exit 0
endif

echo "<p><hr> Enter a description field for each status line below."
echo "<p>When you are satisfied with your choices, "
echo "click on <form action="\""/$scriptcgi/doupdate-level2 "\"" "
echo "method="\""POST"\"">"
echo "<input type="\""submit"\""value="\""Add to Level 2"\""><p> "
	
echo "For the project: <input name="\""project"\"" size="\""15"\"" "
echo "value="\""$current_project"\""> "
echo "<p>"

set datatype=$POSTDATA[2]
echo "For data type: <input name="\""datatype"\"" size="\""20"\"" "
echo "value="\""$datatype"\""> "
echo "<p>"


foreach statustype ($POSTDATA[3-])
#	echo " <p>**DEBUG statustype = $statustype"
#	Create stub datafile (called level3_stub), but really level 2
	if ( ! -e ${datadir}/${current_project}-${datatype}.dat ) then
		cp ${datadir}/level3-stub.dat ${datadir}/${current_project}-${datatype}.dat
#		echo " <br>Created file ${datadir}/${current_project}-${datatype}.dat"
	else
		:
#		echo " <br>File ${datadir}/${current_project}-${datatype}.dat exists."
#		echo " Will use existing version."
	endif
	echo "<p>"
	echo "For status <input name="\""${statustype}"\"" "
	echo "size="\""15"\"
	echo "value="\""$statustype"\""> "

	echo " ... ... Description: <input type="\""text"\"" "
	echo " name="\""${statustype}_description"\"" value="\""nd"\"" "
	echo " size="\""40"\"" >"

end

exit 0
