#!/usr/local/bin/perl5.001
############################################################################
#                                                                          #
# The contents of this file are subject to the WebStone Public License     #
# Version 1.0 (the "License"); you may not use this file except in         #
# compliance with the License. You may obtain a copy of the License        #
# at http://www.mindcraft.com/webstone/license10.html                      #
#                                                                          #
# Software distributed under the License is distributed on an "AS IS"      #
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See      #
# the License for the specific language governing rights and limitations   #
# under the License.                                                       #
#                                                                          #
# The Original Code is WebStone 2.5.                                       #
#                                                                          #
# The Initial Developer of the Original Code is Silicon Graphics, Inc.     #
# and Mindcraft, Inc.. Portions created by Silicon Graphics. and           #
# Mindcraft. are Copyright (C) 1995#1998 Silicon Graphics, Inc. and        #
# Mindcraft, Inc. All Rights Reserved.                                     #
#                                                                          #
# Contributor(s): ______________________________________.                  #
#                                                                          #
############################################################################

# @(#) WebStone-testbed.wpl 1.2@(#)

push(@INC, "$wd/bin");
require('WebStone-common.pl');

@keylist = ();

html_begin("Edit The WebStone Configuration");

print CLIENT <<EOF
<FORM METHOD="POST" ACTION="$wd/bin/write-testbed.wpl">
<H2>Edit the WebStone Configuration:</H2>
EOF
    ;

&gettestbed();

# Clear the values from the variable list, because the form won't
# reliably return an empty string.
foreach $key (@keylist) {
	$$key = "" ;
}

print CLIENT <<EOF
</DL>
<B>
<FONT SIZE=+1>
<P><INPUT TYPE="SUBMIT" VALUE="Write conf/testbed">
</FONT>
</B>
</FORM>
EOF
    ;

html_end();

# end of main program

sub gettestbed {
    open(TESTBED, "$wd/conf/testbed");
    while (<TESTBED>) {
	if (/^\#|^(\w)*$/) { # do nothing
	}
	else {
	    ( $textvalue, $thevalue ) = split( '=', $_ );
	    ( $thevalue ) = split( '#', $thevalue);	    
	    $testbed{$textvalue} = $thevalue;
	    push(@keylist, $textvalue);
	}
    }
    close(TESTBED);

    open(HELPFILE, "$wd/doc/testbed.help");
    while (<HELPFILE>) {
	( $key, $textvalue ) = split( ':', $_ );
	$helptext{$key} = $textvalue;
    }
    close(HELPFILE);

    foreach $key (@keylist) {
	print CLIENT "<P><DT>$helptext{$key}";
	$thesize = length($testbed{$key}) + 5;
	print CLIENT "<DD>$key <INPUT TYPE=TEXT NAME=$key ";
	print CLIENT "SIZE=$thesize VALUE=$testbed{$key}>\n";
    }
}

# end
