#!/usr/bin/perl
# mon_accdef.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_acc'}, "", "monitor_acc" );
&ReadParse();

 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 "   <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 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 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=\"$mon_condition_value\" cols=\"4\" size=\"4\" ALIGN=left onChange=\"isNroThis(this)\">\n";

 print "   <tr><td valign=top>",&hlink("<b>$text{'f_mon_acctions'}</b>","fmon_acctions"),"&nbsp;</td><td valign=top><select NAME=\"monAcction\">\n"; 
 print " 		<option VALUE=\"none\">",&hlink("<b>$text{'f_mon_acctions_sel'}</b>","fmon_acctions_sel"),"\n"; 

@l_acctions = split(/,/,$text{'mon_acctions_value'}, -1);
@l_acctions_tit = split(/,/,$text{'mon_acctions_desc'}, -1);
$nItems=0;
foreach $item (@l_acctions) {
     print "         <option VALUE=\"$item\" ";
     print ">$l_acctions_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 VALUE=\"".$scr->{'name'}."\" >".$scr->{'name'}.": ".$scr->{'desc'}."\n";
        }
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";
if ( "$postform" ne "winldapusers") {  
   &footer($config{'back_return'},$text{'index'}); 
}
 print "<p><p><p>\n";
 do "footer.pl";
 exit;


