#!/usr/bin/perl
# mon_acctarget.cgi
# filter Monitor to Tarantella Services

require './tarantella-lib.pl';
if ( ! $access{'monitor'} )   { &redirect("index.cgi"); }
if ( $config{'has_monitor'} ne "true" )  { &redirect("index.cgi"); }
&ReadParse();
&header($text{'index_monitor_acc'}, "", "monitor_acc" );
$monTarget=$in{monTarget};
if ( !$monTarget ) { &redirect("mon_accdef.cgi"); }
$monCondition=$in{monCondition};
if ( !$monCondition ) { &redirect("mon_accdef.cgi"); }
$monAcction=$in{monAcction};
if ( !$monAcction ) { &redirect("mon_accdef.cgi"); }
$monConditionValue=$in{monConditionValue};
$monScript=$in{monScript};

 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 "/******************************************************************\n"; 
 print "   Chek_fields(obj)\n"; 
 print "*******************************************************************/\n"; 
 print "function Chek_fields(obj) {\n"; 
 print "     if ( get_value(\"select\",obj.monTarget) == \"none\" ) {\n";
 print "          alert(obj.monTarget.name+\":\"+msg1);\n";
 print "                    obj.monTarget.focus();\n";
 print "          return false;\n";
 print "     }         \n";
 print "     if ( get_value(\"select\",obj.monCondition) == \"none\" ) {\n";
 print "          alert(obj.monCondition.name+\":\"+msg1);\n";
 print "                    obj.monCondition.focus();\n";
 print "          return false;\n";
 print "     }         \n";
 print "     nro=parseInt(obj.monConditionValue.value);\n";
 print "     if ( nro+1 > 0) { \n";
 print "          obj.monConditionValue.value=nro;\n"; 
 print "     } else {;\n";
 print "          alert(obj.monConditionValue.name+\":\"+msg1+\"->\"+obj.monConditionValue.value+\"<-\");\n"; 
 print "          obj.monConditionValue.focus();\n"; 
 print "          return false;\n"; 
 print "     };\n";
 print "     actObj=get_value(\"select\",obj.monAcction);\n";
 print "     if ( actObj == \"none\" ) {\n";
 print "          alert(obj.monAcction.name+\":\"+msg1);\n";
 print "                    obj.monAcction.focus();\n";
 print "          return false;\n";
 print "     } else {; \n";
 print "        if ( actObj == \"run-script\" ) {\n";
 print "           if ( get_value(\"select\",obj.monScript) == \"none\" ) {\n";
 print "                 alert(obj.monScript.name+\":\"+msg1);\n";
 print "                     obj.monScript.focus();\n";
 print "                 return false;\n";
 print "           };\n";
 print "        };\n";
 print "     };\n";
 print "     return true;\n";
 print "}\n"; 
 print "//-->\n"; 
 print "</SCRIPT>\n"; 
 print "<p>\n"; 
 print "<table width=100% border>\n";
 print "<tr $tb> <td><b>$text{'titidx_monitor_acc'}  </b></td> </tr>\n";
 print "<tr $cb> <td><table width=100%>\n";
 print "<form METHOD=POST name=mon_accdef ACTION=\"mon_acctarget.cgi\" onSubmit=\"return Chek_fields(this)\">\n"; 

print "<input TYPE=\"hidden\" NAME=\"monTarget\" VALUE=\"$monTarget\">\n";
print "<input TYPE=\"hidden\" NAME=\"monCondition\" VALUE=\"$monCondition\">\n";
print "<input TYPE=\"hidden\" NAME=\"monConditionValue\" VALUE=\"$monConditionValue\">\n";
print "<input TYPE=\"hidden\" NAME=\"monAcction\" VALUE=\"$monAcction\">\n";
print "<input TYPE=\"hidden\" NAME=\"monScript\" VALUE=\"$monScript\">\n";

print "   <tr><td valign=top>",&hlink("<b>$text{'f_mon_target'}</b>","fmon_target"),"&nbsp;</td>\n";
@l_target = split(/,/,$text{'mon_target_value'}, -1);
$nItems=0;
foreach $item (@l_target) {
     if ( $item eq $monTarget ) {
        $targetext='mon_'.$item.'_sess';
        print "  <td valign=top><b>$text{$targetext} </b></td></tr>\n";
        last;
     }
     $nItems++;
}

 print "   <tr><td valign=top>",&hlink("<b>$text{'f_mon_condition'}</b>","fmon_condition"),"&nbsp;</td>\n";
@l_conditions = split(/,/,$text{'mon_conditions_value'}, -1);
@l_conditions_tit = split(/,/,$text{'mon_conditions_desc'}, -1);
$nItems=0;
foreach $item (@l_conditions) {
     if ( $item eq $monCondition ) {
        print "  <td valign=top><b>$l_conditions_tit[$nItems] </b></td></tr>\n";
        last;
     }
     $nItems++;
}
 print "  <td valign=top>",&hlink("<b>$text{'f_mon_condition_value'}</b>","fmon_condition_value"),"&nbsp;</td>\n";
 print "  <td valign=top><b> $monConditionValue </b></td></tr>\n";

 print "   <tr><td valign=top>",&hlink("<b>$text{'f_mon_acctions'}</b>","fmon_acctions"),"&nbsp;</td>\n";
@l_acctions = split(/,/,$text{'mon_acctions_value'}, -1);
@l_acctions_tit = split(/,/,$text{'mon_acctions_desc'}, -1);
$nItems=0;
foreach $item (@l_acctions) {
     if ( $item eq $monAcction ) {
        print "  <td valign=top><b>$l_acctions_tit[$nItems] </b></td></tr>\n";
        last;
     }
     $nItems++;
}

 print "   <tr><td valign=top>",&hlink("<b>$text{'f_mon_script'}</b>","fmon_script"),"&nbsp;</td>\n";
foreach $scr (&load_scriptlist()) { 
     if ( $scr->{'name'} eq $monScript ) {
        print "  <td valign=top><b>".$scr->{'name'}.": ".$scr->{'desc'}." </b></td></tr>\n";
        last;
     }
}
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></td></tr>\n"; 
 print "<tr><tr></table></table><hr><p>\n";
 &footer($config{'back_return'},$text{'index'}); 
 print "<p><p><p>\n";
 do "footer.pl";
 exit;


