sub render_add_to_group_component2 { my $self = shift; my $list_id = shift; my $header = $self->{'cfg'}->param("www.header"); my %args = ( name => 'Group_Actions', method => 'post', keepextras => 1, sticky => 0, template => $self->{'cfg'}->param("tmpl.tmpl_group_action_component"), stylesheet => $self->{'cfg'}->param("www.css"), javascript => 0, validate => { group => 'WORD' } ); # print STDERR Dumper(\%args); my $form = CGI::FormBuilder->new( \%args ); # print STDERR "The \$form object includes: \n" . Dumper($form); my $groups = $self->_get_group_options(); unless(ref($groups) eq 'ARRAY'){ $groups = \(); } # print STDERR Dumper($groups); if(@{$groups}){ $form->field( name => 'group', label => 'Call Group: ', type => 'select', options => $groups, ); } $form->field( name => 'group_action', label => 'Action', type => 'select', options => { 'add_to_group' => 'Add to Group', 'remove_from_group' => 'Remove from Group', 'edit_group' => 'Edit Group', 'delete_from_list' => 'Delete from List' } ); my $insert_record = $self->render_insert_new_record_component($list_id); my $sql = $self->{'cfg'}->param("sql.get_phones_for_list_id"); my $sth = $self->{'dbh_client_lists'}->prepare($sql); $sth->execute($list_id); my @loop_data; while (my $phone = $sth->fetchrow_hashref()){ my %row_data; my $name = 'group_action_' . $phone->{'phone_number_id'}; $row_data{'CHECKBOX'} = $form->field( name => $name, label => '', type => 'checkbox', options => [ 'perform_group_action' ], sticky => 0, value => 'perform_group_action', ); $row_data{'FNAME'} = $phone->{'fname'}; $row_data{'LNAME'} = $phone->{'lname'}; $row_data{'EMAIL'} = $phone->{'email'}; $row_data{'PHONE'} = $phone->{'phone'}; $row_data{'LINKS'} = $self->_get_links_for_phone_list($phone->{'phone_number_id'}); push (@loop_data, \%row_data); } $form->tmpl_param(PHONES => \@loop_data); print STDERR "The loop_data incldes: \n" . Dumper(\@loop_data); my ($html,$html_record); if(defined($self->{'q'}->param("action")) && defined($self->{'q'}->param("record"))) { if ($self->{'q'}->param("action") eq 'edit') { $html_record = $self->_edit_phone_record($self->{'q'}->param("record")); } elsif ($self->{'q'}->param("action") eq 'delete') { $html_record = $self->_delete_phone_record($self->{'q'}->param("record")); } } else { $html_record = "\n"; } if ($form->submitted && $form->validate) { my $field = $self->{'q'}->Vars; if($form->submitted eq 'Process Group Action'){ if($field->{'group_action'} eq 'add_to_group'){ $self->_add_phone_numbers_to_group($field); $self->{'q'}->delete('_submitted_Group_Actions'); } elsif($field->{'group_action'} eq 'remove_from_group'){ $self->_remove_phone_numbers_from_group($field); $self->{'q'}->delete('_submitted_Group_Actions'); } elsif($field->{'group_action'} eq 'edit_group'){ $self->_edit_group($field); $self->{'q'}->delete('_submitted_Group_Actions'); } elsif($field->{'group_action'} eq 'delete_from_list'){ $self->_delete_phone_numbers_from_list($field); $self->{'q'}->delete('_submitted_Group_Actions'); } } $html = $form->render( header => $header, submit => [ 'Process Group Action' ] ); $html =~ s/INSERT_NEW_RECORD_HERE/$html_record$insert_record/; } else { $html = $form->render( header => $header, submit => [ 'Process Group Action' ] ); $html =~ s/INSERT_NEW_RECORD_HERE/$html_record$insert_record/; } # print STDERR Dumper($self->{'q'}->Vars); foreach my $key (keys %{$self->{'q'}->Vars}){ # print STDERR "The \$key is: $key \n"; if($key =~ m/group_action_/){ print STDERR "Now deleting \$key: $key \n"; $self->{'q'}->delete($key); } } return $html; }