#
# html header
#

$TYPE = "\U$ARGV[0]";

$POST        = $ENV{SERVER_CGI_URL}; 
$SERVER_HOME = $ENV{SERVER_HOME};
$SERVER_NAME = $ENV{SERVER_NAME};
$BASE_HREF   = $ENV{SERVER_WWW_URL};
$BACKGROUND  = $ENV{BACKGROUND};


chdir("$ENV{SERVER_SOLVERS}/$TYPE");

print "<HTML>\n";

# Title of Form

chop($TITLE = `cat TITLE`);
print "<HEAD>\n";
print "<BASE HREF = \"$BASE_HREF\/\">\n";
print "<TITLE> $SERVER_NAME Server: $TITLE WWW Interface </TITLE>\n";
print "<META name=\"description\" 
       content=\"$SERVER_NAME Server: $TITLE WWW Interface\">\n";
print "<META name=\"keywords\" 
       content=\"$TITLE, $SERVER_NAME Server, optimization, 
       algorithms, software, problem solving environments\">\n";
print "</HEAD>\n";
print "<BODY $BACKGROUND >\n";
print  "<A HREF=\"\"><IMG align=left border=0 SRC=\"images/globe_small.jpg\" alt=\"NEOS Server Home\"></a>\n";
print "<center><H1>\nWWW Interface\n<p>\n$TITLE\n</H1></center>\n";
print "<br clear=left>\n";
print "<br><br><hr><br>\n";

#
# Read in config file and generate entries
#

print "<FORM METHOD=\"POST\" ACTION=\"$POST/$TYPE/nph-solver-www.cgi\" ENCTYPE=\"multipart/form-data\" NAME=\"WWW Interface\">\n";

if (-s "config") {
  chomp(@CONFIG = `cat config`);
} else {
  $CONSTR = 1;
}
if (-s "web-help") {
  $EXPLAIN = `cat web-help`;
} else {
  $CONSTR = 1;
}

if ($CONSTR) {
  print "<center>\n";
  print "<IMG vspace=10 SRC=\"images/construction2.gif\">\n";
  print "$TITLE is still under construction.";
  print "</center>\n";
  print "<br><br>"
}


@EXPLAIN = split(/<NEXT ENTRY>/, $EXPLAIN); 

$COUNT = 1;
foreach (@CONFIG) {
  $explain = shift(@EXPLAIN);
  if($ENV{SERVER_SOLVER_GROUPS}) {
    $explain =~ s/.*<SERVER_SOLVER_GROUPS>.*//g;
  } else {
    if($explain =~ /<!--<SERVER_SOLVER_GROUPS>/) {
      next;
    }
  }
  if ($explain =~ /\S+/) {
    print "$explain<br>\n";
  }
  $VAR = "field.$COUNT";
  $COUNT++;
  @field = split(/:/);
  $field[3] =~ s/\s//g;
  #$field[1] =~ s/\s//g;
  if ($field[1] =~ /BINARY-ON/) {
    if ($field[0] =~ /\S+/) {
	print "<b>$field[0]</b>\n";
    }
    print "<INPUT TYPE=\"checkbox\" NAME=\"$VAR\" VALUE=\"yes\" CHECKED>\n";
  } elsif ($field[1] =~ /BINARY-OFF/) {
    if ($field[0] =~ /\S+/) {
	print "<b>$field[0]</b>\n";
    }
    print "<INPUT TYPE=\"checkbox\" NAME=\"$VAR\" VALUE=\"yes\">\n";
  } elsif ($field[1] =~ /RADIO/) {
    @list = split(/\./, $field[1]);
    shift(@list);
    if ($field[0] =~ /\S+/) {
	print "<b>$field[0]:</b><br>\n";
    }
    $FLAG = 1;
    print "<ul>\n";
    foreach $item (@list) {
      ($title, $value) = split(/,/, $item); 
      unless ($value =~ /\S+/) {
	$value = $title;
      }
      if ($FLAG) {
        print "<INPUT TYPE=\"RADIO\" NAME=\"$VAR\" VALUE=\"$value\" CHECKED>\n";
	print "$title<br>\n";
	$FLAG = 0;
      } else {
        print "<INPUT TYPE=\"RADIO\" NAME=\"$VAR\" VALUE=\"$value\">\n";
	print "$title<br>\n";
      }
    }
    print "</ul>\n";
  } elsif ("\U$field[3]" eq "NULL") {
      if ($field[0] =~ /\S+/) {
	  print "<b>$field[0]:</b><br>";
      }
      print "<INPUT TEXT NAME=\"$VAR\" size=50 VALUE=\"$field[1]\">\n";
  } elsif ($field[1] =~ /TEXT/) {
      if ($field[0] =~ /\S+/) {
	  print "<b>$field[0]:</b><br>\n";
      }
      print "<TEXTAREA NAME=\"$VAR\" ROWS=8 COLS=60></TEXTAREA>\n";
  } else {
      if ($field[0] =~ /\S+/) {
	  print "<b>$field[0]</b>(local file):<br>\n";
      }
      print "<INPUT TYPE=\"file\" name=\"$VAR\" size=50>\n";
  }			     
  print "<br>\n";
}
if(defined( $explain = shift(@EXPLAIN)))
   {
       if ($explain =~ /\S+/) 
       {
	   print "$explain<br>\n";
       }
   }
   print "<br>\n";

#
# Create Action Bar
#

print "<P><hr><P>\n";
print "<center>\n";
print "<table cols=2><tr><td colspan=2 align=center>";
print "e-mail address:<BR> <INPUT TEXT NAME=field.0 size=36\"><P></td>\n</tr><tr><td align=right>";
print "<INPUT TYPE=\"submit\" VALUE=\"Submit to $SERVER_NAME\">";  
print "</td><td align=left>";
print "<INPUT TYPE=\"reset\" VALUE=\"Clear this Form\">\n";  
print "</td></tr></table>\n";
print "</center>\n";


print "<p><hr>\n";
print "<center><a href = \"\" ><img src=\"images/neos_home.jpg\" border=0 alt=\"$SERVER_NAME Server Home\" hspace=40></a>\n<br>\n";
print "<a href=\"solvers/$TYPE/solver-comment.html\">\n";
print "<img border=0 src=\"images/comments.jpg\"\n";
print "ALT=\"Submit comments and questions\"></a>\n";
print "</center><p>\n";

#
# end html
#

print "</BODY>\n";
print "</HTML>\n";
