#!/bin/ksh
#
#ident	"@(#)test_opt	1.13	05/06/15 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#


hctsdir=SUNWhcts            # base directory
prgdir=prgs             # program directory
act=                  # action to be taken
bname=`basename $0`     # shell name
gotocgi="http://$HTTP_HOST/cgi-bin/$hctsdir/`basename $0`"      # program name
i=0                     # loop counter
mdir=menu               # menu directory
rdir=results            # results directory
hname=$1                  # test system
option=$2               # option selected
fdir=forms              # forms directory
dname=                  # display system
trigger=.trig.tmp	# flag file for STAF start

technology=$3

lvfile=/tmp/level.dat
stfile=/tmp/suite.dat

if [ -s $stfile ]
then
    suite=`cat $stfile`
fi

if [ -s $lvfile ]
then
    level=`cat $lvfile`
fi


# functions

# do function
go_fun()
{
        $prgdir/funcs "$*" 2>&1
}



do_button()
{
        echo '<FORM METHOD="POST" ACTION="'$gotocgi'">'
                echo '<UL><INPUT TYPE="submit" VALUE="'$2'"></UL>'
                echo '<INPUT TYPE="hidden" NAME="act" VALUE="'$1'">'
                echo '<INPUT TYPE="hidden" NAME="hostn" VALUE="'$hname'">'
                echo '<INPUT TYPE="hidden" NAME="opt" VALUE="'$option'">'
                echo '<INPUT TYPE="hidden" NAME="tech" VALUE="'$technology'">'
        echo "</FORM>"
}


### MAIN ###

# change to base directory
cd `dirname $0`
while [ `basename $PWD` != $hctsdir ]
do
        cd ..
done

# parse input
if [ -n "$CONTENT_LENGTH" ]
then
        eval `$prgdir/pq.p`
        CONTENT_LENGTH=
fi

# to fix 5005395, will putback in 2.4
#is_console=`$prgdir/is_console.sh`
#if [ ! $is_console ]
#then
#	if [ -n "$hostn" ]
#	then
#		hname=$hostn
#	fi
#	go_fun bhtml $hname $0 $technology
#	go_fun err_pg "You are not console now."
#	go_fun ehtml
#	exit 1
#fi


if [ -z "$act" ]
then
       go_fun bhtml $hname $0 $technology
       echo '<P><B>Click the button below to continue.</B>'
       if [ $suite = CC ]; then
               do_button menu10 "Certify Controller"
       elif [ $suite = SC ]; then
		#add for motherboard certification
		if [ $option = "system" ];then
               		do_button menu10 "Certify System"
		elif [ $option = "motherboard" ];then
			do_button menu10 "Certify Motherboard"
		fi
		#end add
       fi
#       do_button menu12 "Create Custom Test Configuration"
       go_fun ehtml
else
	hname=$hostn
	option=$opt
	technology=$tech
	
	if [ $act = menu10 ]; then
		if [ -d $rdir/$hname ]
		then
			touch $rdir/$hname/$trigger
		else
			mkdir $rdir/$hname
			touch $rdir/$hname/$trigger
		fi
	fi

	exec $mdir/$act $hname $option $technology
		
fi


