#!/usr/bin/perl
# mon_selacts.cgi
# Select Actions to Services with Tarantella
# STTA Rev. 1.3 Copyright (c) 2001-2002 Jesús Pérez Lorenzo  --- license GNU GPL 

require './stta-lib.pl';
&ReadParse();
$postform="selact";
if ($in{form}) { $postform = $in{form}; }
if ( ! $access{'monitor'} )   { &redirect("index.cgi"); }
if ( $config{'has_monitor'} ne "true" )  { &redirect("index.cgi"); }
do "ldap-lib.pl"; 
$sort_on = ($in{sort_on}) ? $in{sort_on} : "name";
&headerstta($text{'index_monitor_act'}, "", "monitor_act",undef,1,1,$text{headpage_rigth} );
 print "<hr>\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 "var ask_confpassmon=true;\n"; 
 print "/******************************************************************\n";
 print "   showValue(formObj)\n";
 print "   Show Password value from form.\n";
 print "*******************************************************************/\n";
 print "function showValue() {\n";
 print "   alert(document.mon_$postform.dn.value);\n";
 print "}\n";
 print "/******************************************************************\n"; 
 print "   set_actionName(ialias,iname)\n"; 
 print "*******************************************************************/\n"; 
 print "function set_actionName(ialias,iname) {\n"; 
 print "    document.mon_$postform.elements[0].value=ialias;\n";
 print "    document.mon_$postform.elements[1].value=iname;\n";
 print "    return;\n"; 
 print "}\n"; 
 print "//-->\n"; 
 print "/******************************************************************\n";
 print "   set_cmd(cmd)\n";
 print "*******************************************************************/\n";
 print "function set_cmd(cmd) {\n";
 print "    document.mon_$postform.elements[2].value=cmd;\n";
 print "    document.mon_$postform.elements[3].value=cmd;\n";
 print "    if (cmd ==  \"delete\" ) {;\n";
 print "       document.mon_$postform.action=\"mon_delact.cgi\";\n";
 print "    }\n";
 print "    if (cmd ==  \"modify\" ) {;\n";
 print "       document.mon_$postform.action=\"mon_actdef.cgi\";\n";
 print "    }\n";
 print "    if (cmd ==  \"run\" ) {;\n";
 print "       document.mon_$postform.action=\"mon_runact.cgi\";\n";
 print "    }\n";
 print "    return;\n";
 print "}\n";
 print "//-->\n";
 print "/******************************************************************\n"; 
 print "   Chek_fields(obj)\n"; 
 print "*******************************************************************/\n"; 
 print "function Chek_fields(obj) {\n"; 
 print "     if ( emptyField(obj.actionName) == true ) {\n"; 
 print "          alert(obj.actionName.name+\":\"+msg1+\"->\"+obj.actionName.value+\"<-\");\n"; 
 print "		    obj.actionName.focus();\n"; 
 print "          return false;\n"; 
 print "     }         \n"; 
 print "     if ( get_value(\"select\",obj.userou) == \"none\" ) {\n";
 print "          alert(obj.userou.name+\":\"+msg1);\n";
 print "                    obj.userou.focus();\n";
 print "          return false;\n";
 print "     }         \n";
 print "     return true;\n"; 
 print "}\n"; 
 print "//-->\n"; 
 print "</SCRIPT>\n"; 

print "<table width=100% border>\n";
if ( "$postform" eq "selact") { print "<tr $tb> <td><b>$text{'titidx_selact'}</b></td> </tr>\n" };
if ( "$postform" eq "delact") { print "<tr $tb> <td><b>$text{'titidx_delact'}</b></td> </tr>\n" };
if ( "$postform" eq "modact") { print "<tr $tb> <td><b>$text{'titidx_modact'}</b></td> </tr>\n" };
if ( "$postform" eq "runact") { print "<tr $tb> <td><b>$text{'titidx_runact'}</b></td> </tr>\n" };

    %h_actions=&list_actions();
    foreach $item (keys (%h_actions)) { push (@all_actions,$h_actions{$item}); }
    print "<tr><td><B>-- $text{'l_orderby'}  ";
    if ($sort_on eq "alias") {
       @actions = sort {$a->{$sort_on} cmp $b->{$sort_on}} @all_actions;
       print $text{l_monalias} . "\n";
    }
    elsif ($sort_on eq "name") {
       @actions = sort {$a->{$sort_on} cmp $b->{$sort_on}} @all_actions;
       print $text{l_monname} . "\n";
    }
    elsif ($sort_on eq "target") {
       @actions = sort {$a->{$sort_on} cmp $b->{$sort_on}} @all_actions;
       print $text{l_montarget} . "\n";
    }
    elsif ($sort_on eq "object") {
       @actions = sort {$a->{$sort_on} cmp $b->{$sort_on}} @all_actions;
       print $text{l_monobject} . "\n";
    }
    elsif ($sort_on eq "condition") {
       @actions = sort {$a->{$sort_on} cmp $b->{$sort_on}} @all_actions;
       print $text{l_moncondition} . "\n";
    }
    elsif ($sort_on eq "conditionvalue") {
       @actions = sort {$a->{$sort_on} cmp $b->{$sort_on}} @all_actions;
       print $text{l_monconditionvalue} . "\n";
    }
    elsif ($sort_on eq "action") {
       @actions = sort {$a->{$sort_on} cmp $b->{$sort_on}} @all_actions;
       print $text{l_monaction} . "\n";
    }
    elsif ($sort_on eq "script") {
       @actions = sort {$a->{$sort_on} cmp $b->{$sort_on}} @all_actions;
       print $text{l_monscript} . "\n";
    }
    elsif ($sort_on eq "how") {
       @actions = sort {$a->{$sort_on} cmp $b->{$sort_on}} @all_actions;
       print $text{l_monhow} . "\n";
    }
    elsif ($sort_on eq "when") {
       @actions = sort {$a->{$sort_on} cmp $b->{$sort_on}} @all_actions;
       print $text{l_monwhen} . "\n";
    }
    print "</td></tr><tr> <td><table width=100%>\n";
    print "<hr>\n";
    print "<tr><td>\n";

    print "</b><TR $tb><TD><center><B>";
    print "<A href=\"mon_selact.cgi?sort_on=alias&form=$postform\">";
    print $text{l_monalias}."</A></B></center></TD>\n";
    print "<TD><center><B>";
    print "<A href=\"mon_selact.cgi?sort_on=name&form=$postform\">";
    print $text{l_monname}."</A></B></center></TD>\n";
    print "<TD><center><B>";
    print "<A href=\"mon_selact.cgi?sort_on=target&form=$postform\">";
    print $text{l_montarget}."</A></B></center></TD>\n";
    print "<TD><center><B>";
    print "<A href=\"mon_selact.cgi?sort_on=object&form=$postform\">";
    print $text{l_monobject}."</A></B></center></TD>\n";
    print "<TD><center><B>";
    print "<A href=\"mon_selact.cgi?sort_on=condition&form=$postform\">";
    print $text{l_moncondition}."</A></B></center></TD>\n";
    print "<TD><center><B>";
    print "<A href=\"mon_selact.cgi?sort_on=conditionvalue&form=$postform\">";
    print $text{l_monconditionvalue}."</A></B></center></TD>\n";
    print "<TD><center><B>";
    print "<A href=\"mon_selact.cgi?sort_on=action&form=$postform\">";
    print $text{l_monaction}."</A></B></center></TD>\n";
    print "<TD><center><B>";
    print "<A href=\"mon_selact.cgi?sort_on=script&form=$postform\">";
    print $text{l_monscript}."</A></B></center></TD>\n";
    print "<TD><center><B>";
    print "<A href=\"mon_selact.cgi?sort_on=how&form=$postform\">";
    print $text{l_monhow}."</A></B></center></TD>\n";
    print "<TD><center><B>";
    print "<A href=\"mon_selact.cgi?sort_on=when&form=$postform\">";
    print $text{l_monwhen}."</A></B></center></TD>\n";

    foreach $action (@actions) {
        $monAlias=$action->{alias};
        $monName=$action->{name};
        $monObject=$action->{object};
        $monTarget=$action->{target};
        $monObject=$action->{object};
        $monCondition=$action->{condition};
        $monAction=$action->{action};
        $monScript=$action->{script};
        $monHow=$action->{how};
        $monWhen=$action->{when};
        &get_acttitles();
        print "<TR $cb>";
        print "<TD><A href=\"javascript:set_actionName('".$monAlias."','".$monName."')";
        print "\">".$action->{alias}."</A></TD>";
        print "<TD>" . $action->{name}."</TD>";
        print "<TD> $t_monTarget</TD>";
        print "<TD> $t_monObject</TD>";
        print "<TD> $t_monCondition</TD>";
        print "<TD>" . $action->{conditionValue}."</TD>";
        print "<TD> $t_monAction</TD>";
        print "<TD> $t_monScript</TD>";
        print "<TD> $t_monHow</TD>";
        print "<TD> $t_monWhen</TD>";
        print "\n";
    }
    print "<tr><tr></table></table><hr><p>\n";
    print "<center><form METHOD=POST name=mon_".$postform." ACTION=\"mon_".$postform.".cgi\" onSubmit=\"return Chek_fields(this)\">\n"; 
    print "  <td valign=top>",&hlink("<b>$text{'f_actionName'}</b>","factionName"),"&nbsp;</td>\n";
    print "  <td valign=top><input TYPE=\"text\" NAME=\"aliasAct\" VALUE=\"$aliasAct\" cols=\"23\" size=\"12\" ALIGN=left></td></tr>\n";
    print "  <input TYPE=\"hidden\" NAME=\"descrip\" VALUE=\"",$descrip,"\">\n";
    print "  <input TYPE=\"hidden\" NAME=\"cmd\" VALUE=\"",$cmd,"\">\n";
    print "  <input TYPE=\"hidden\" NAME=\"postform\" VALUE=\"",$postform,"\">\n";
    print "  <td valign=top><input TYPE=\"button\" NAME=\"?\" VALUE=\"?\" onClick=\"showValue();\" ></td>\n";
    print "   <tr><td valign=top><input TYPE=\"submit\" NAME=\"",$text{'edit_run'},"\" VALUE=\"",$text{'edit_run'},"\" onClick=\"set_cmd('run')\"></td>\n";
    print "        <td valign=top><input TYPE=\"submit\" NAME=\"",$text{'modify'},"\" VALUE=\"",$text{'modify'},"\" onClick=\"set_cmd('modify')\">\n";
    print "        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>\n";
    print "        <td valign=top><input TYPE=\"submit\" NAME=\"",$text{'delete'},"\" VALUE=\"",$text{'delete'},"\" onClick=\"set_cmd('delete')\"></td></tr>\n";
    print "	</form></td></tr>\n"; 

 print "</center><tr><tr></table></table><hr><p>\n";
 &footer($config{'back_return'},$text{'index'});
 print "<p><p><p>\n";
 do "footer.pl";
 exit;




