[!
use strict;
use Carp;
use DBI;
use Proxmox::RuleDB;
use Proxmox::RuleDB::Group;
use Proxmox::Utils;
use Proxmox::HTMLTable;
use Proxmox::HTMLDropDown;
use Proxmox::Form;
!]
[$ if !defined ($fdat{ruleid}) $]
[- Execute ('help.epl') -]
[$ else $]
[-
my @cellwidth = ( '20px','490px');
my @cellwidth3 = ( '60px','450px');
my @header2 = ( '2', '510px', __("Available Objects"));
# class initialization
my $table = Proxmox::HTMLTable->new (\@cellwidth);
my $table2 = Proxmox::HTMLTable->new (\@cellwidth);
my $ddown = Proxmox::HTMLDropDown->new ();
my $frm = Proxmox::Form->new (\%fdat);
my $rdb = Proxmox::RuleDB->new();
my $rule = $rdb->load_rule($fdat{ruleid});
$fdat{m3} = 0 if !defined($fdat{m3});
my ($from, $to, $when, $what, $action) = $rdb->load_groups($rule);
my @sg;
if (defined ($action)) {
@sg = sort {$a->{action}->otype <=> $b->{action}->otype} @$action;
}
my $tmap = [[undef, 0, 'summary'], [$from, 0, 'who'], [$to, 1, 'who'],
[$what, 3, 'what'], [$when, 2, 'when'], [\@sg, 4, 'action']];
my ($groups, $gtype, $_class) = @{@$tmap[$fdat{m3}]};
sub create_groups_summary {
my ($table, $gtype, $groups) = @_;
my $txt = "";
my $gmap = [[__('From'), 1, __('Anybody')], [__('To'), 2, __('Anybody')],
[__('When'), 4, __('Always')], [__('What'), 3, __('Anything')],
[__('Action'), 5, __('Do Nothing')]];
my ($name, $ind, $def) = @{@$gmap[$gtype]};
foreach my $g (@$groups) {
$txt .= ", " if $txt;
$txt .= Proxmox::Utils::escape_html ($g->{name})
}
$txt = $def if !$txt;
my %par = (m3 => $ind);
my $lnk = Proxmox::Utils::modify_url ($req_rec->uri, %{$fdat{__args}}, %par);
$table->set_row_link ($lnk);
$table->add_row (0, "$name:", $txt);
}
if ($_class eq 'summary') {
my $table3 = Proxmox::HTMLTable->new (\@cellwidth3);
my $html = "";
create_groups_summary ($table3, 0, $from);
create_groups_summary ($table3, 1, $to);
create_groups_summary ($table3, 2, $when);
create_groups_summary ($table3, 3, $what);
create_groups_summary ($table3, 4, \@sg);
$html .= $table3->out_table();
print OUT $html;
return;
}
sub get_row_link {
my ($gid, $_class) = @_;
if ($_class eq 'action') {
return "/action/index.htm?gid=$gid";
} else {
return "/objects/$_class/index.htm?gid=$gid";
}
}
# dropdowns
my %par = (action => 'removegroup', gtype => $gtype, gid => undef);
my $lnk = Proxmox::Utils::modify_url('index.htm', %{$fdat{__args}}, %par);
$ddown->add_item("remove_group", $lnk, __("Remove Object"));
%par = (action => 'addgroup', gtype => $gtype, gid => undef);
$lnk = Proxmox::Utils::modify_url('index.htm', %{$fdat{__args}}, %par);
$ddown->add_item("add_group", $lnk, __("Add Object"));
foreach my $g (@$groups) {
$table->set_row_link (get_row_link ($g->{id}, $_class));
$table->add_row (0, $ddown->out_symbol('remove_group', '', "&gid=$g->{id}"),
Proxmox::Utils::escape_html ($g->{name}));
}
$table2->add_headline (\@header2);
my $og = $rdb->load_objectgroups($_class);
my @sg;
if ($_class eq 'action') {
@sg = sort {$a->{action}->otype <=> $b->{action}->otype} @$og;
} else {
@sg = @$og;
}
foreach my $g (@sg) {
my $isin=0;
foreach my $g1 (@$groups) {
$isin = 1 if $g1->{id} == $g->{id};
}
if (!$isin) {
$table2->set_row_link (get_row_link ($g->{id}, $_class));
$table2->add_row (0, $ddown->out_symbol("add_group", '', "&gid=$g->{id}"),
Proxmox::Utils::escape_html ($g->{name}));
}
}
$table->add_row (0, '', __('No Objects selected')) if !$table->{rowcount};
$table2->add_row(0, '', __('No other objects available')) if !$table2->{rowcount};
print OUT $ddown->out_dropdown_menu("remove_group") .
$ddown->out_dropdown_menu("add_group") .
$table->out_table() ."
" .
$table2->out_table();
-]
[$ endif $]