#!perllocation
#
# getobj2
#  purpose is to assign the second join object after a user selects
#  it from a 'dir'-like window, and then to issue a form allowing
#  the user to subselect from among the object's variables, which
#  are sent on to get2andjoin
#
# NB: this file belongs in the directory configured as ScriptAlias /jg/
#     on this HTTPD server.  (typically htmlbin or optbin)
#     Generated from a template by a makefile in the source tree
#  
do 'build-opt-env.pl';

$pathinfo=$ENV{'PATH_INFO'};
$mainlocation = "$realtempdir"."/";
$LISTVAR="$topdir/bin/listvar";

MAIN:
{
  &printtop;
# 
# if there is an extension on the object name, remove it
#
   if (rindex($pathinfo,".") > rindex($pathinfo,"/")) {
     $object2=substr($pathinfo,0,rindex($pathinfo,"."));
     $EXT=substr($pathinfo,rindex($pathinfo,".")+1);
   } else {
     $object2=$pathinfo;
     $EXT="html0";
   }
#
# if object has been served with a set of projections/selections
#
   if ($ENV{'QUERY_STRING'} && $ENV{'QUERY_STRING'} ne "") {
	$obj2origsels=$ENV{'QUERY_STRING'};
   } else {
	$obj2origsels="none";
   }

   print "<b><font size=\"4\">Second object is: $object2</font></b>\n";

   @object2vars = `$LISTVAR \"$object2\"`;
   &getprojs4obj2;

}
################### printtop
sub printtop{
 print "Content-type: text/html\n\n";
 print "<HTML><HEAD><TITLE>Offer projections on Object 2</TITLE></HEAD>\n";
 print "<BODY BGCOLOR=\"ffffff\">\n";
}
################### askforprojs
sub getprojs4obj2 {
#
# ask user if any projections from second object are desired
#

print "<form method=\"POST\" action=\"/jg/get2andjoin$object2\" TARGET=\"_top\">";

print <<ENDOFTEXT;
 <input type="hidden" name="obj2origsels" value="$obj2origsels">
 <input type="hidden" name="ext" value="$EXT">
<p>
<b>You may control which parameters from this object are included in the result.<br><font color="0000ff">Note: DO include the parameters in common with the first object!</font></b>
<p>
<table align="center">
<tr>

<td border=0>
<font size="4">
<input type="radio" name="quant" value="only" CHECKED>Use <b>only selected</b> parameters
</font>
</td>

<td border=0>
<font size="5" color="0000ff"><b>Or  </b></font>
<font size="4">
<input type="radio" name="quant" value="all">Keep <b>all</b> parameters
</font>
</td>

<tr>
<td align="center" border=0>
<select multiple name="obj2newsels" size=10 align=middle>
ENDOFTEXT

foreach (@object2vars) {
  print "<option>$_";
};

print <<ENDOFSUB;
</select>
</td>

<td valign="middle" colspan=2>
        <b><font size="5" bgcolor="Silver" color="0000ff">
        <input type="submit" value="Continue">
</td>
</table>

</form>
</BODY>
</HTML>
ENDOFSUB
}
