<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Webmin::Section;
use WebminCore;

=head2 new Webmin::Section(header, [columns], [title], [width])
Create a new form section, which has a header and contains some inputs
=cut
sub new
{
if (defined(&amp;Webmin::Theme::Section::new) &amp;&amp;
    caller() !~ /Webmin::Theme::Section/) {
        return new Webmin::Theme::Section(@_[1..$#_]);
        }
my ($self, $header, $columns, $title, $width) = @_;
$self = { 'columns' =&gt; 4 };
bless($self);
$self-&gt;set_header($header);
$self-&gt;set_columns($columns) if (defined($columns));
$self-&gt;set_title($title) if (defined($title));
$self-&gt;set_width($width) if (defined($width));
return $self;
}

=head2 html()
Returns the HTML for this form section
=cut
sub html
{
my ($self) = @_;
my $rv;
$rv .= &amp;ui_table_start($self-&gt;{'header'},
		     $self-&gt;{'width'} ? "width=$self-&gt;{'width'}" : undef,
		     $self-&gt;{'columns'});
foreach my $i (@{$self-&gt;{'inputs'}}) {
	if (is_input($i-&gt;[1])) {
		my $errs;
		my @errs = $self-&gt;{'form'}-&gt;field_errors($i-&gt;[1]-&gt;get_name());
		if (@errs) {
			foreach my $e (@errs) {
				$errs .= "&lt;br&gt;&lt;font color=#ff0000&gt;$e&lt;/font&gt;\n";
				}
			}
		$rv .= &amp;ui_table_row($i-&gt;[0], $i-&gt;[1]-&gt;html().$errs,
					   $i-&gt;[2]);
		}
	else {
		$rv .= &amp;ui_table_row($i-&gt;[0],
			ref($i-&gt;[1]) ? $i-&gt;[1]-&gt;html() : $i-&gt;[1], $i-&gt;[2]);
		}
	}
$rv .= &amp;ui_table_end();
return $rv;
}

=head2 add_input(label, input, [columns])
Adds some Webmin::Input object to this form section
=cut
sub add_input
{
my ($self, $label, $input, $cols) = @_;
push(@{$self-&gt;{'inputs'}}, [ $label, $input, $cols ]);
$input-&gt;set_form($self-&gt;{'form'});
}

=head2 add_row(label, text, [columns])
Adds a non-editable row to this form section
=cut
sub add_row
{
my ($self, $label, $text, $cols) = @_;
push(@{$self-&gt;{'inputs'}}, [ $label, $text, $cols ]);
}

=head2 add_separator()
Adds some kind of separator at this point in the section
=cut
sub add_separator
{
my ($self) = @_;
push(@{$self-&gt;{'inputs'}}, [ undef, "&lt;hr&gt;", $self-&gt;{'columns'} ]);
}

sub set_header
{
my ($self, $header) = @_;
$self-&gt;{'header'} = $header;
}

sub set_columns
{
my ($self, $columns) = @_;
$self-&gt;{'columns'} = $columns;
}

sub set_title
{
my ($self, $title) = @_;
$self-&gt;{'title'} = $title;
}

=head2 set_width([number|number%])
Sets the width of this section. Can be called with 100%, 500, or undef to use
the minimum possible width.
=cut
sub set_width
{
my ($self, $width) = @_;
$self-&gt;{'width'} = $width;
}

=head2 validate()
Validates all form inputs, based on the given CGI input hash. Returns a list
of errors, each of which is field name, error message and field label.
=cut
sub validate
{
my ($self) = @_;
my @errs;
foreach my $i (@{$self-&gt;{'inputs'}}) {
	if (is_input($i-&gt;[1])) {
		foreach my $e ($i-&gt;[1]-&gt;validate()) {
			push(@errs, [ $i-&gt;[1]-&gt;get_name(), $e, $i-&gt;[0] ]);
			}
		}
	}
return @errs;
}

=head2 get_value(input-name)
Returns the value of the input with the given name.
=cut
sub get_value
{
my ($self, $name) = @_;
foreach my $i (@{$self-&gt;{'inputs'}}) {
	if (is_input($i-&gt;[1]) &amp;&amp; $i-&gt;[1]-&gt;get_name() eq $name) {
		return $i-&gt;[1]-&gt;get_value();
		}
	}
return undef;
}

=head2 set_form(form)
Called by the Webmin::Form object when this section is added to it
=cut
sub set_form
{
my ($self, $form) = @_;
$self-&gt;{'form'} = $form;
foreach my $i (@{$self-&gt;{'inputs'}}) {
	if (is_input($i-&gt;[1])) {
		$i-&gt;[1]-&gt;set_form($form);
		}
	}
}

sub list_inputs
{
my ($self) = @_;
return map { $_-&gt;[1] } grep { is_input($_-&gt;[1]) } @{$self-&gt;{'inputs'}};
}

=head2 is_input(object)
=cut
sub is_input
{
my ($object) = @_;
return ref($object) &amp;&amp; ref($object) =~ /::/ &amp;&amp;
       $object-&gt;isa("Webmin::Input");
}

1;

</pre></body></html>