5 =head2 new Webmin::Page(subheading, title, [help-name], [show-config],
6 [no-module-index], [no-webmin-index], [rightside],
7 [header], [body-tags], [below-text])
8 Create a new page object, with the given heading and other details
12 if (defined(&Webmin::Theme::Page::new) && caller() !~ /Webmin::Theme::Page/) {
13 return new Webmin::Theme::Page(@_[1..$#_]);
15 my ($self, $subheading, $title, $help, $config, $noindex, $nowebmin, $right,
16 $header, $body, $below) = @_;
17 $self = { 'index' => 1, 'webmin' => 1, 'image' => "" };
19 $self->set_subheading($subheading);
20 $self->set_title($title);
21 $self->set_help($help);
22 $self->set_config($config);
23 $self->set_index(!$noindex);
24 $self->set_webmin(!$nowebmin);
25 $self->set_right($right);
26 $self->set_header($header);
27 $self->set_body($body);
28 $self->set_below($below);
33 Actually outputs this page
40 # Work out if we need buffering/table
41 foreach my $c (@{$self->{'contents'}}) {
42 if (ref($c) =~ /Dynamic/) {
44 if ($c->needs_unbuffered()) {
45 $self->{'unbuffered'} = 1;
50 # Show the page header
51 my $func = $self->{'unbuffered'} ? \&ui_print_unbuffered_header
54 foreach my $s (@{$self->{'scripts'}},
55 (map { @{$_->{'scripts'}} } @{$self->{'contents'}})) {
56 $scripts .= "<script>\n".$s."\n</script>\n";
59 my @onloads = ( @{$self->{'onloads'}},
60 map { @{$_->{'onloads'}} } @{$self->{'contents'}} );
62 $onload = "onLoad='".join(" ", @onloads)."'";
64 my @args = ( $self->{'subheading'}, $self->{'title'}, $self->{'image'},
65 $self->{'help'}, $self->{'config'}, $self->{'index'} ? undef : 1,
66 $self->{'webmin'} ? undef : 1, $self->{'right'},
67 $self->{'header'}.$scripts, $self->{'body'}.$onload,
69 while(!defined($args[$#args])) {
72 if ($self->get_refresh()) {
73 print "Refresh: ",$self->get_refresh(),"\r\n";
75 &ui_print_header(@args);
78 if ($self->{'tabs'}) {
79 print $self->{'tabs'}->top_html();
82 # Add any pre-content stuff
83 print $self->pre_content();
85 if ($self->{'errormsg'}) {
87 print $self->get_errormsg_html();
90 # Generate the forms and other stuff
91 foreach my $c (@{$self->{'contents'}}) {
98 eval { print $c->html(); };
100 print "<pre>$@</pre>";
102 if (ref($c) =~ /Dynamic/ && $c->get_wait()) {
103 # Dynamic object .. execute now
109 # Generate buttons row
110 if ($self->{'buttons'}) {
112 print &ui_buttons_start();
113 foreach my $b (@{$self->{'buttons'}}) {
114 print &ui_buttons_row(@$b);
116 print &ui_buttons_end();
120 # Add any post-content stuff
121 print $self->post_content();
124 if ($self->{'tabs'}) {
125 print $self->{'tabs'}->bottom_html();
130 foreach my $f (@{$self->{'footers'}}) {
131 push(@footerargs, $f->[0], $f->[1]);
133 &ui_print_footer(@footerargs);
135 # Start any dynamic objects
136 foreach my $c (@{$self->{'contents'}}) {
137 if (ref($c) =~ /Dynamic/ && !$c->get_wait()) {
143 =head2 add_footer(link, title)
144 Adds a return link, typically for display at the end of the page.
148 my ($self, $link, $title) = @_;
149 push(@{$self->{'footers'}}, [ $link, $title ]);
152 =head2 get_footer(index)
153 Returns the link for the numbered footer
157 my ($self, $num) = @_;
158 return $self->{'footers'}->[$num]->[0];
161 =head2 add_message(text, ...)
162 Adds a text message, to appear at this point on the page
166 my ($self, @message) = @_;
167 push(@{$self->{'contents'}}, join("", @message));
170 =head2 add_error(text, [command-output])
171 Adds a an error message, possible accompanied by the command output
175 my ($self, $message, $out) = @_;
176 $message = "<font color=#ff0000>$message</font>";
178 $message .= "<pre>$out</pre>";
180 push(@{$self->{'contents'}}, $message);
183 =head2 add_message_after(&object, text, ...)
184 Adds a message after some existing object
186 sub add_message_after
188 my ($self, $object, @message) = @_;
189 splice(@{$self->{'contents'}}, $self->position_of($object)+1, 0,
193 =head2 add_error_after(&object, text, [command-output])
194 Adds an error message after some existing object
198 my ($self, $object, $message, $out) = @_;
199 $message = "<font color=#ff0000>$message</font>";
201 $message .= "<pre>$out</pre>";
203 splice(@{$self->{'contents'}}, $self->position_of($object)+1, 0,
209 my ($self, $object) = @_;
210 for(my $i=0; $i<@{$self->{'contents'}}; $i++) {
211 if ($self->{'contents'}->[$i] eq $object) {
215 print STDERR "Could not find $object in ",join(" ",@{$self->{'contents'}}),"\n";
216 return scalar(@{$self->{'contents'}});
219 =head2 add_form(Webmin::Form)
220 Adds a form to be displayed on this page
224 my ($self, $form) = @_;
225 push(@{$self->{'contents'}}, $form);
226 $form->set_page($self);
229 =head2 add_separator()
230 Adds some kind of separation between parts of this page, like an <hr>
234 my ($self, $message) = @_;
235 push(@{$self->{'contents'}}, "<hr>");
238 =head2 add_button(cgi, label, description, [&hiddens], [before-button],
240 Adds an action button associated with this page, typically for display at the end
244 my ($self, $cgi, $label, $desc, $hiddens, $before, $after) = @_;
245 push(@{$self->{'buttons'}}, [ $cgi, $label, $desc, join(" ", @$hiddens),
249 =head2 add_tabs(Webmin::Tags)
250 Tells the page to display the given set of tabs at the top
254 my ($self, $tabs) = @_;
255 $self->{'tabs'} = $tabs;
258 =head2 add_dynamic(Webmin::DynamicText|Webmin::DynamicProgress)
259 Adds an object that is dynamically generated, such as a text box or progress bar.
263 my ($self, $dyn) = @_;
264 push(@{$self->{'contents'}}, $dyn);
265 $dyn->set_page($self);
270 my ($self, $subheading) = @_;
271 $self->{'subheading'} = $subheading;
276 my ($self, $title) = @_;
277 $self->{'title'} = $title;
282 my ($self, $help) = @_;
283 $self->{'help'} = $help;
288 my ($self, $config) = @_;
289 $self->{'config'} = $config;
294 my ($self, $index) = @_;
295 $self->{'index'} = $index;
300 my ($self, $webmin) = @_;
301 $self->{'webmin'} = $webmin;
306 my ($self, $right) = @_;
307 $self->{'right'} = $right;
312 my ($self, $header) = @_;
313 $self->{'header'} = $header;
318 my ($self, $body) = @_;
319 $self->{'body'} = $body;
324 my ($self, $below) = @_;
325 $self->{'below'} = $below;
330 my ($self, $unbuffered) = @_;
331 $self->{'unbuffered'} = $unbuffered;
334 =head2 set_popup(popup?)
335 If set to 1, then this is a popup window
339 my ($self, $popup) = @_;
340 $self->{'popup'} = $popup;
344 Returns the path part of the URL for this page, like /foo/bar.cgi
349 if ($ENV{'QUERY_STRING'} && $ENV{'REQUEST_METHOD'} ne 'POST') {
352 foreach my $i (keys %in) {
354 foreach my $v (split(/\0/, $in{$i})) {
355 push(@args, &urlize($i)."=".
361 return @args ? $ENV{'SCRIPT_NAME'}."?".join("&", @args)
362 : $ENV{'SCRIPT_NAME'};
365 =head2 set_refresh(seconds)
366 Sets the number of seconds between automatic page refreshes
370 my ($self, $refresh) = @_;
371 $self->{'refresh'} = $refresh;
377 return $self->{'refresh'};
380 =head2 add_onload(code)
381 Adds some Javascript code for inclusion in the onLoad tag
385 my ($self, $code) = @_;
386 push(@{$self->{'onloads'}}, $code);
389 =head2 add_script(code)
390 Adds some Javascript code for putting in the <head> section
394 my ($self, $script) = @_;
395 push(@{$self->{'scripts'}}, $script);
410 =head2 set_errormsg(message)
411 Sets an error message to be displayed instead of the page contents
415 my ($self, $errormsg) = @_;
416 $self->{'errormsg'} = $errormsg;
419 sub get_errormsg_html
422 return $self->{'errormsg'}."<p>\n";