#!/usr/bin/perl
# tta_selhosts.cgi
# Select Host
# STTA Rev. 1.3 Copyright (c) 2001-2004 Jesús Pérez Lorenzo  --- license GNU GPL 
# stta: (@#) 1.31051043346- [2004_01_29_102036]

require './stta-lib.pl';

&ReadParse();
$postform = ($in{form}) ? $in{form} : "modhosts"; 
$hostname=$in{hostname};
$multihost=$in{multi} || "0";
if ( "$postform" eq "alivehosts" ) {
     &headerstta($text{'index_alivehosts'}, "", $postform ,undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" );
}
if ( "$postform" eq "delhosts" ) {
     &headerstta($text{'index_delhosts'}, "", $postform ,undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" );
}
if ( "$postform" eq "modhosts" ) {
      &headerstta($text{'index_modhosts'}, "", $postform,undef,1,0,"$text{'headpage_right'}"."$text{'head_logout'}",undef,undef,"$text{head_below}" );
}
 if ( $hostname eq "" ) { $hostname="all" };
 if ( $multihost ne "1" ) { $hostname="" };
 print "<hr><p>\n";
 print "<SCRIPT SRC=\"global.js\">\n"; 
 print "</SCRIPT>\n"; 
 print "<SCRIPT LANGUAGE=\"JavaScript\">\n"; 
 print "<!--\n"; 
 print "/*  Strings for locales  */\n"; 
 print "var msg0=\"".$text{'msg_0'},"\";\n";
 print "var msg1=\"".$text{'msg_1'},"\";\n";
 print "var msg2=\"".$text{'msg_2'},"\";\n";
 print "var msg3=\"".$text{'msg_3'},"\";\n";
 print "var msg4=\"".$text{'msg_4'},"\";\n";
 print "var msg5=\"".$text{'msg_5'},"\";\n";
 print "var msg6=\"".$text{'msg_6'},"\";\n";
 print "var msg7=\"".$text{'msg_7'},"\";\n";
 print "var ask_confadmin=true;\n"; 
 print "\n"; 
 print "/******************************************************************\n"; 
 print "   Check_fields(obj)\n"; 
 print "*******************************************************************/\n"; 
 print "function Check_fields(obj) {\n"; 
# print "     if ( get_value(\"select\",obj.hostname) == \"none\" ) {\n";
# print "          alert(obj.hostname.name+\":\"+msg1);\n";
# print "                    obj.hostname.focus();\n";
# print "          return false;\n";
# print "     }         \n";
# print "\n"; 
 print "     return true;\n"; 
 print "}\n"; 
 print "//-->\n"; 
 print "</SCRIPT>\n"; 
 print "\n"; 
 print "<table width=100% border>\n";
if ( "$postform" eq "delhosts") { print "<tr $tb> <td><font color='$revtext'><b>$text{'titidx_delhosts'}</b></td> </tr>\n" };
if ( "$postform" eq "alivehosts") { print "<tr $tb> <td><font color='$revtext'><b>$text{'titidx_alivehosts'}</b></td> </tr>\n" };
if ( "$postform" eq "modhosts") { print "<tr $tb> <td><font color='$revtext'><b>$text{'titidx_modhosts'}</b></td> </tr>\n" };
 print "<tr $cb> <td><table align=left>\n";
 print "<form METHOD=POST name=tta_$postform ACTION=\"tta_$postform.cgi\" onSubmit=\"return Check_fields(this)\">\n"; 
 print "  <input TYPE=\"hidden\" NAME=\"postform\" VALUE=\"tta_selhosts\">\n";
 print "   <tr><td valign=top>",&hlink("<b>$text{'f_hostname'}</b>","fhostname"),"&nbsp;</td>\n";
 print "   <td valign=top>";
 if ( $multihost eq "1" ) {
      print "<textarea wrap=auto name=hostname rows=5 cols=10>",
          join("\n", split(/,/ , $hostname)),"</textarea>\n";
      print "<input type=button onClick='ifield = document.forms[0].hostname; if ( ifield.value == \"$hostname\" ) { ifield.value = \"\" } ; chooser = window.open(\"/stta/host_chooser.cgi?multi=$multihost&f=textarea&host=\"+escape(ifield.value), \"chooser\", \"toolbar=no,menubar=no,scrollbars=yes,width=800,height=500\"); chooser.ifield = ifield; window.ifield = ifield' value=\"...\">\n";
      print "<input type=button onClick='ifield = document.forms[0].hostname; if ( ifield.value == \"$hostname\" ) { ifield.value = \"\" } ; chooser = window.open(\"/stta/obj_chooser.cgi?type=hosts&multi=$multihost&ord=ens&deft=alias&f=textarea&obj=\"+escape(ifield.value), \"chooser\", \"toolbar=no,menubar=no,scrollbars=yes,width=800,height=500\"); chooser.ifield = ifield; window.ifield = ifield' value=\"$text{browse}\"></td>\n";

 } else {
      print "   <td valign=top><select NAME=\"hostname\">\n";
      print "                <option VALUE=\"none\">",&hlink("<b>$text{'f_selechosts'}</b>","fselechosts"),"\n";
      print "                 <option VALUE=\"all\">". $text{'edit_all'}."\n";
      %h_host=&list_hosts();
      &out_htmlselobj(\%h_host,"descrip","alias",$hostname);
      print "        </select>\n";
      print "<input type=button onClick='selfield = document.forms[0].hostname; ifield = document.forms[0].hostname.options[document.forms[0].hostname.selectedIndex]; if ( ifield.value == \"$hostname\" ) { ifield.value = \"\" } ; chooser = window.open(\"/stta/host_chooser.cgi?multi=$multihost&f=select&host=\"+escape(ifield.value), \"chooser\", \"toolbar=no,menubar=no,scrollbars=yes,width=800,height=500\"); chooser.ifield = ifield; window.ifield = ifield' value=\"...\">\n";
      print "<input type=button onClick='selfield = document.forms[0].hostname; ifield = document.forms[0].hostname.options[document.forms[0].hostname.selectedIndex]; if ( ifield.value == \"$hostname\" ) { ifield.value = \"\" } ; chooser = window.open(\"/stta/obj_chooser.cgi?type=hosts&multi=$multihost&ord=ens&deft=alias&f=select&obj=\"+escape(ifield.value), \"chooser\", \"toolbar=no,menubar=no,scrollbars=yes,width=800,height=500\"); chooser.ifield = ifield; window.ifield = ifield' value=\"$text{browse}\"></td>\n";
 }
 print "</tr>";
 print "        <tr><td valign=top><input TYPE=\"submit\" NAME=\"",$text{'f_sendreq'},"\" VALUE=\"",$text{'f_sendreq'},"\">\n";
 print "        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>\n";
 print "        <td valign=top><input TYPE=\"reset\" NAME=\"",$text{'f_cancelreq'},"\" VALUE=\"",$text{'f_cancelreq'},"\"></td></tr>\n";
 print "	</form>\n"; 
 print "<tr><tr></table></table><hr><p>\n"; 
 &footer($config{'back_return'},$text{'index'}); 
 print "<p><p><p>\n";
 do "footer.pl";
 exit;



