#!/usr/bin/perl
# mon_actdef.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"); }
&header($text{'index_monitor_act'}, "", "monitor_act" );
&ReadParse();
if ( $in{postform} ) {
     $aliasAct=$in{aliasAct};
     $descrip=$in{descrip};
     $postform=$in{postform};
     foreach $action (&list_actions()) {    
        if ( $action->{alias} eq $aliasAct ) {
             $monAlias=$action->{alias};
             $monName=$action->{name};
             $monObject=$action->{object};
             $monTarget=$action->{target};
             $monObject=$action->{object};
             $monCondition=$action->{condition};
             $monConditionValue=$action->{conditionValue};
             $monAction=$action->{action};
             $monScript=$action->{script};
             $monHow=$action->{how};
             $monWhen=$action->{when};
        }
    }
}

 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.monAction);\n";
 print "     if ( actObj == \"none\" ) {\n";
 print "          alert(obj.monAction.name+\":\"+msg1);\n";
 print "                    obj.monAction.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 "     if ( get_value(\"select\",obj.monHow) == \"none\" ) {\n";
 print "          alert(obj.monHow.name+\":\"+msg1);\n";
 print "                    obj.monHow.focus();\n";
 print "          return false;\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>";
 if ( $postform eq "modify" ) {
      print "<i>$text{'titidx_monitor_modact'}:</i><b> $monAlias - $monName ";
 } elsif ( $postform eq "delete" ) {
      print "<i>$text{'titidx_monitor_delact'}:</i><b> $monAlias - $monName ";
 } else {
      print "<b>$text{'titidx_monitor_defact'}";
 }
 print " </b></td> </tr>\n";
 print "<tr $cb> <td><table width=100%>\n";
 print "<form METHOD=POST name=mon_actdef ACTION=\"mon_actarget.cgi\" onSubmit=\"return Chek_fields(this)\">\n"; 
 if ( $postform ne "" ) {
    print "  <input TYPE=\"hidden\" NAME=\"aliasAct\" VALUE=\"",$aliasAct,"\">\n";
    print "  <input TYPE=\"hidden\" NAME=\"descrip\" VALUE=\"",$descrip,"\">\n";
    print "  <input TYPE=\"hidden\" NAME=\"postform\" VALUE=\"$postform\">\n";
 }
 print "   <tr><td valign=top>",&hlink("<b>$text{'f_mon_target'}</b>","fmon_target"),"&nbsp;</td><td valign=top><select NAME=\"monTarget\">\n";
 print "                <option VALUE=\"none\">",&hlink("<b>$text{'f_mon_target_sel'}</b>","fmon_target_sel"),"\n";
 
@l_target = split(/,/,$text{'mon_target_value'}, -1);
$nItems=0;
foreach $item (@l_target) {
     print "         <option ";
     if ( $postform ne "" && $item eq $monTarget ) { print "selected " ; }
     print "VALUE=\"$item\" ";
     $targetext='mon_'.$item.'_sess';
     print ">$text{$targetext}</b>\n";
     $nItems++;
}
 print "        </select></td></tr>\n";

 print "   <tr><td valign=top>",&hlink("<b>$text{'f_mon_condition'}</b>","fmon_condition"),"&nbsp;</td><td valign=top><select NAME=\"monCondition\">\n";
 print "                <option VALUE=\"none\">",&hlink("<b>$text{'f_mon_condition_sel'}</b>","fmon_condition_sel"),"\n";
 
@l_conditions = split(/,/,$text{'mon_conditions_value'}, -1);
@l_conditions_tit = split(/,/,$text{'mon_conditions_desc'}, -1);
$nItems=0;
foreach $item (@l_conditions) {
     print "         <option ";
     if ( $postform ne "" && $item eq $monCondition ) { print "selected " ; }
     print "VALUE=\"$item\" ";
     print ">$l_conditions_tit[$nItems]</b>\n";
     $nItems++;
}
 print "        </select></td></tr>\n";
 print "        <td valign=top>",&hlink("<b>$text{'f_mon_condition_value'}</b>","fmon_condition_value"),"&nbsp;</td>\n";
 print "        <td valign=top><input TYPE=\"text\" NAME=\"monConditionValue\" VALUE=\"$monConditionValue\" cols=\"6\" size=\"6\" ALIGN=left onChange=\"isNroThis(this)\">\n";

 print "   <tr><td valign=top>",&hlink("<b>$text{'f_mon_actions'}</b>","fmon_actions"),"&nbsp;</td><td valign=top><select NAME=\"monAction\">\n"; 
 print " 		<option VALUE=\"none\">",&hlink("<b>$text{'f_mon_actions_sel'}</b>","fmon_actions_sel"),"\n"; 

@l_actions = split(/,/,$text{'mon_actions_value'}, -1);
@l_actions_tit = split(/,/,$text{'mon_actions_desc'}, -1);
$nItems=0;
foreach $item (@l_actions) {
     print "         <option ";
     if ( $postform ne "" && $item eq $monAction ) { print "selected " ; }
     print "VALUE=\"$item\" ";
     print ">$l_actions_tit[$nItems]</b>\n";
     $nItems++;
}
 print "	</select></td></tr>\n"; 
 print "   <tr><td valign=top>",&hlink("<b>$text{'f_mon_script'}</b>","fmon_script"),"&nbsp;</td><td valign=top><select NAME=\"monScript\">\n";
 print " 		<option VALUE=\"none\">",&hlink("<b>$text{'f_mon_script_sel'}</b>","fmon_script_sel"),"\n"; 
foreach $scr (&load_scriptlist()) {
        print "         <option ";
        if ( $postform ne "" && $scr->{name} eq $monScript ) { print "selected " ; }
        print "VALUE=\"".$scr->{'name'}."\" >".$scr->{'name'}.": ".$scr->{'desc'}."\n";
        }
print "        </select></td></tr>\n";
 print "   <tr><td valign=top>",&hlink("<b>$text{'f_mon_how'}</b>","fmon_how"),"&nbsp;</td><td valign=top><select NAME=\"monHow\">\n"; 
 print " 		<option VALUE=\"none\">",&hlink("<b>$text{'f_mon_how_sel'}</b>","fmon_how_sel"),"\n"; 
@l_how = split(/,/,$text{'mon_how_value'}, -1);
@l_how_tit = split(/,/,$text{'mon_how_desc'}, -1);
$nItems=0;
foreach $item (@l_how) {
     print "         <option ";
     if ( $postform ne "" && $item eq $monHow ) { print "selected " ; }
     print "VALUE=\"$item\" ";
     print ">$l_how_tit[$nItems]</b>\n";
     $nItems++;
}
 print "	</select></td></tr>\n"; 
 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;


