#!/usr/local/bin/perl
#
# join-form, a CGI
#    purpose:  to read several files from /jgofsopt/port_no/remote_host:
#                join-object-1, parameters and from_loc
#              and display the contents of the first 2
#              then, to allow users to return to previous screen
#              by presenting a 'Cancel' button pointing to from_loc
#
#
{
  $remote=$ENV{'REMOTE_HOST'};
  $port=$ENV{'SERVER_PORT'};
  if (!$port) {
    $port=80;
  }

  $mainlocation="/jgofsopt/$port/$remote/";

  print "Content-type: text/html\n\n";
  print "<BODY BGCOLOR=\"ffffff\">\n";

  &getfilevars;
  &print_top_frame;

}
################### getfilevars
sub getfilevars {
#
# open the file /jgofsopt/port_no/remote_host/join-object-1
#
$objnamefile="$mainlocation"."join-object-1";
open(OBJ,"$objnamefile") || die "Cannot open object $!<p>\n";
  while (<OBJ>) {
    $object = $_;
  }
chomp($object);
close(OBJ);

#
# open the file /jgofsopt/port_no/remote_host/parameters, containing
#    the subselections active, if any, for object 1
#    Note that we are 'positive reporting' here, expecting
#    to see 'none' if there are no subselections active.
#    See '/jg/putjoinenv' for code to create these files
#
$paramfile="$mainlocation"."parameters";
open(IN,"$paramfile") || die "Cannot open parameters $!<p>\n";
   while (<IN>) {
     $params = $_;
   }
  chomp($params);
  close(IN);

  if ($params ne "none") {
    $object.="("."$params".")";
  }

#
#  open the file /jgofsopt/port_no/remote_machine/from_loc, containing
#    the referring URL, probably optserv1's Plotting and OO menu
#
$from_location="$mainlocation"."from_loc";
open(IN,"$from_location") || die "Cannot open fromlocation $!<p>\n";
  while (<IN>) {
    $refloc = $_;
  }
close(IN);
chomp($refloc);

}
################### print_top_frame
sub print_top_frame{

  print "<FORM METHOD=\"POST\" ACTION=\"$refloc\" TARGET=\"_top\">\n";
  print "<DL><DT><B><FONT SIZE=\"4\">Join object: \n";
  print "$object\n";
  print "<DD>  with:  </FONT> 
    [ second object ] <FONT COLOR=\"FF0000\">
        please choose from  
        below, by clicking on the hyperlinks</FONT><P>\n";

  print "   Or, you may choose to <FONT COLOR=\"0000FF\">
            <INPUT ALIGN=\"right\" TYPE=\"submit\" VALUE=\"Cancel\">
            </FONT>\n";
  print "</B></DL>\n";
  print "</FORM>\n";

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

}

