1 use vars qw($theme_no_table $ui_radio_selector_donejs $module_name
2 $ui_multi_select_donejs);
6 Common functions for generating HTML for Webmin user interface elements.
11 ui_print_header(undef, 'My Module', '');
13 print ui_form_start('save.cgi');
14 print ui_table_start('My form', undef, 2);
16 print ui_table_row('Enter your name',
17 ui_textbox('name', undef, 40));
20 print ui_form_end([ [ undef, 'Save' ] ]);
22 ui_print_footer('/', 'Webmin index');
26 ####################### table generation functions
28 =head2 ui_table_start(heading, [tabletags], [cols], [&default-tds], [right-heading])
30 Returns HTML for the start of a form block into which labelled inputs can
31 be placed. By default this is implemented as a table with another table inside
32 it, but themes may override this with their own layout.
36 =item heading - Text to show at the top of the form.
38 =item tabletags - HTML attributes to put in the outer <table>, typically something like width=100%.
40 =item cols - Desired number of columns for labels and fields. Defaults to 4, but can be 2 for forms with lots of wide inputs.
42 =item default-tds - An optional array reference of HTML attributes for the <td> tags in each row of the table.
44 =item right-heading - HTML to appear in the heading, aligned to the right.
49 return &theme_ui_table_start(@_) if (defined(&theme_ui_table_start));
50 my ($heading, $tabletags, $cols, $tds, $rightheading) = @_;
51 if (defined($main::ui_table_cols)) {
52 # Push on stack, for nested call
53 push(@main::ui_table_cols_stack, $main::ui_table_cols);
54 push(@main::ui_table_pos_stack, $main::ui_table_pos);
55 push(@main::ui_table_default_tds_stack, $main::ui_table_default_tds);
59 $rv .= "<table class='ui_table' border $tabletags>\n";
60 if (defined($heading) || defined($rightheading)) {
61 $rv .= "<tr $tb class='ui_table_head'>";
62 if (defined($heading)) {
63 $rv .= "<td><b>$heading</b></td>"
65 if (defined($rightheading)) {
66 $rv .= "<td align=right>$rightheading</td>";
71 $rv .= "<tr $cb class='ui_table_body'> <td colspan=$colspan>".
72 "<table width=100%>\n";
73 $main::ui_table_cols = $cols || 4;
74 $main::ui_table_pos = 0;
75 $main::ui_table_default_tds = $tds;
81 Returns HTML for the end of a block started by ui_table_start.
86 return &theme_ui_table_end(@_) if (defined(&theme_ui_table_end));
88 if ($main::ui_table_cols == 4 && $main::ui_table_pos) {
89 # Add an empty block to balance the table
90 $rv .= &ui_table_row(" ", " ");
92 if (@main::ui_table_cols_stack) {
93 $main::ui_table_cols = pop(@main::ui_table_cols_stack);
94 $main::ui_table_pos = pop(@main::ui_table_pos_stack);
95 $main::ui_table_default_tds = pop(@main::ui_table_default_tds_stack);
98 $main::ui_table_cols = undef;
99 $main::ui_table_pos = undef;
100 $main::ui_table_default_tds = undef;
102 $rv .= "</table></td></tr></table>\n";
106 =head2 ui_table_row(label, value, [cols], [&td-tags])
108 Returns HTML for a row in a table started by ui_table_start, with a 1-column
109 label and 1+ column value. The parameters are :
111 =item label - Label for the input field. If this is undef, no label is displayed.
113 =item value - HTML for the input part of the row.
115 =item cols - Number of columns the value should take up, defaulting to 1.
117 =item td-tags - Array reference of HTML attributes for the <td> tags in this row.
122 return &theme_ui_table_row(@_) if (defined(&theme_ui_table_row));
123 my ($label, $value, $cols, $tds) = @_;
125 $tds ||= $main::ui_table_default_tds;
127 if ($main::ui_table_pos+$cols+1 > $main::ui_table_cols &&
128 $main::ui_table_pos != 0) {
129 # If the requested number of cols won't fit in the number
130 # remaining, start a new row
132 $main::ui_table_pos = 0;
134 $rv .= "<tr class='ui_table_row'>\n"
135 if ($main::ui_table_pos%$main::ui_table_cols == 0);
136 $rv .= "<td valign=top $tds->[0] class='ui_label'><b>$label</b></td>\n"
137 if (defined($label));
138 $rv .= "<td valign=top colspan=$cols $tds->[1] class='ui_value'>$value</td>\n";
139 $main::ui_table_pos += $cols+(defined($label) ? 1 : 0);
140 if ($main::ui_table_pos%$main::ui_table_cols == 0) {
142 $main::ui_table_pos = 0;
149 Returns HTML for a row in a block started by ui_table_row, with a horizontal
150 line inside it to separate sections.
155 return &theme_ui_table_hr(@_) if (defined(&theme_ui_table_hr));
161 $rv .= "<tr class='ui_table_hr'> ".
162 "<td colspan=$main::ui_table_cols><hr></td> </tr>\n";
166 =head2 ui_table_span(text)
168 Outputs a table row that spans the whole table, and contains the given text.
174 return &theme_ui_table_hr(@_) if (defined(&theme_ui_table_hr));
180 $rv .= "<tr class='ui_table_span'> ".
181 "<td colspan=$main::ui_table_cols>$text</td> </tr>\n";
185 =head2 ui_columns_start(&headings, [width-percent], [noborder], [&tdtags], [heading])
187 Returns HTML for the start of a multi-column table, with the given headings.
190 =item headings - An array reference of headers for the table's columns.
192 =item width-percent - Desired width as a percentage, or undef to let the browser decide.
194 =item noborder - Set to 1 if the table should not have a border.
196 =item tdtags - An optional reference to an array of HTML attributes for the table's <td> tags.
198 =item heading - An optional heading to put above the table.
203 return &theme_ui_columns_start(@_) if (defined(&theme_ui_columns_start));
204 my ($heads, $width, $noborder, $tdtags, $title) = @_;
206 $rv .= "<table".($noborder ? "" : " border").
207 (defined($width) ? " width=$width%" : "")." class='ui_columns'>\n";
209 $rv .= "<tr $tb class='ui_columns_heading'>".
210 "<td colspan=".scalar(@$heads)."><b>$title</b></td></tr>\n";
212 $rv .= "<tr $tb class='ui_columns_heads'>\n";
214 for($i=0; $i<@$heads; $i++) {
215 $rv .= "<td ".$tdtags->[$i]."><b>".
216 ($heads->[$i] eq "" ? "<br>" : $heads->[$i])."</b></td>\n";
222 =head2 ui_columns_row(&columns, &tdtags)
224 Returns HTML for a row in a multi-column table. The parameters are :
226 =item columns - Reference to an array containing the HTML to show in the columns for this row.
228 =item tdtags - An optional array reference containing HTML attributes for the row's <td> tags.
233 return &theme_ui_columns_row(@_) if (defined(&theme_ui_columns_row));
234 my ($cols, $tdtags) = @_;
236 $rv .= "<tr $cb class='ui_columns_row'>\n";
238 for($i=0; $i<@$cols; $i++) {
239 $rv .= "<td ".$tdtags->[$i].">".
240 ($cols->[$i] !~ /\S/ ? "<br>" : $cols->[$i])."</td>\n";
246 =head2 ui_columns_header(&columns, &tdtags)
248 Returns HTML for a row in a multi-column table, styled as a header. Parameters
249 are the same as ui_columns_row.
252 sub ui_columns_header
254 return &theme_ui_columns_header(@_) if (defined(&theme_ui_columns_header));
255 my ($cols, $tdtags) = @_;
257 $rv .= "<tr $tb class='ui_columns_header'>\n";
259 for($i=0; $i<@$cols; $i++) {
260 $rv .= "<td ".$tdtags->[$i]."><b>".
261 ($cols->[$i] eq "" ? "<br>" : $cols->[$i])."</b></td>\n";
267 =head2 ui_checked_columns_row(&columns, &tdtags, checkname, checkvalue, [checked?], [disabled])
269 Returns HTML for a row in a multi-column table, in which the first column
270 contains a checkbox. The parameters are :
272 =item columns - Reference to an array containing the HTML to show in the columns for this row.
274 =item tdtags - An optional array reference containing HTML attributes for the row's <td> tags.
276 =item checkname - Name for the checkbox input. Should be the same for all rows.
278 =item checkvalue - Value for this checkbox input.
280 =item checked - Set to 1 if it should be checked by default.
282 =item disabled - Set to 1 if the checkbox should be disabled and thus un-clickable.
285 sub ui_checked_columns_row
287 return &theme_ui_checked_columns_row(@_) if (defined(&theme_ui_checked_columns_row));
288 my ($cols, $tdtags, $checkname, $checkvalue, $checked, $disabled) = @_;
290 $rv .= "<tr $cb class='ui_checked_columns'>\n";
291 $rv .= "<td class='ui_checked_checkbox' ".$tdtags->[0].">".
292 &ui_checkbox($checkname, $checkvalue, undef, $checked, undef, $disabled).
295 for($i=0; $i<@$cols; $i++) {
296 $rv .= "<td ".$tdtags->[$i+1].">";
297 if ($cols->[$i] !~ /<a\s+href|<input|<select|<textarea/) {
298 $rv .= "<label for=\"".
299 "e_escape("${checkname}_${checkvalue}")."\">";
301 $rv .= ($cols->[$i] !~ /\S/ ? "<br>" : $cols->[$i]);
302 if ($cols->[$i] !~ /<a\s+href|<input|<select|<textarea/) {
311 =head2 ui_radio_columns_row(&columns, &tdtags, checkname, checkvalue, [checked], [disabled])
313 Returns HTML for a row in a multi-column table, in which the first
314 column is a radio button. The parameters are :
316 =item columns - Reference to an array containing the HTML to show in the columns for this row.
318 =item tdtags - An optional array reference containing HTML attributes for the row's <td> tags.
320 =item checkname - Name for the radio button input. Should be the same for all rows.
322 =item checkvalue - Value for this radio button option.
324 =item checked - Set to 1 if it should be checked by default.
326 =item disabled - Set to 1 if the radio button should be disabled and thus un-clickable.
329 sub ui_radio_columns_row
331 return &theme_ui_radio_columns_row(@_) if (defined(&theme_ui_radio_columns_row));
332 my ($cols, $tdtags, $checkname, $checkvalue, $checked, $dis) = @_;
334 $rv .= "<tr $cb class='ui_radio_columns'>\n";
335 $rv .= "<td class='ui_radio_radio' ".$tdtags->[0].">".
336 &ui_oneradio($checkname, $checkvalue, "", $checked, undef, $dis)."</td>\n";
338 for($i=0; $i<@$cols; $i++) {
339 $rv .= "<td ".$tdtags->[$i+1].">";
340 if ($cols->[$i] !~ /<a\s+href|<input|<select|<textarea/) {
341 $rv .= "<label for=\"".
342 "e_escape("${checkname}_${checkvalue}")."\">";
344 $rv .= ($cols->[$i] !~ /\S/ ? "<br>" : $cols->[$i]);
345 if ($cols->[$i] !~ /<a\s+href|<input|<select|<textarea/) {
354 =head2 ui_columns_end
356 Returns HTML to end a table started by ui_columns_start.
361 return &theme_ui_columns_end(@_) if (defined(&theme_ui_columns_end));
365 =head2 ui_columns_table(&headings, width-percent, &data, &types, no-sort, title, empty-msg)
367 Returns HTML for a complete table, typically generated internally by
368 ui_columns_start, ui_columns_row and ui_columns_end. The parameters are :
370 =item headings - An array ref of heading HTML.
372 =item width-percent - Preferred total width
374 =item data - A 2x2 array ref of table contents. Each can either be a simple string, or a hash ref like :
376 { 'type' => 'group', 'desc' => 'Some section title' }
377 { 'type' => 'string', 'value' => 'Foo', 'colums' => 3,
379 { 'type' => 'checkbox', 'name' => 'd', 'value' => 'foo',
380 'label' => 'Yes', 'checked' => 1, 'disabled' => 1 }
381 { 'type' => 'radio', 'name' => 'd', 'value' => 'foo', ... }
383 =item types - An array ref of data types, such as 'string', 'number', 'bytes' or 'date'
385 =item no-sort - Set to 1 to disable sorting by theme.
387 =item title - Text to appear above the table.
389 =item empty-msg - Message to display if no data.
394 return &theme_ui_columns_table(@_) if (defined(&theme_ui_columns_table));
395 my ($heads, $width, $data, $types, $nosort, $title, $emptymsg) = @_;
398 # Just show empty message if no data
399 if ($emptymsg && !@$data) {
400 $rv .= &ui_subheading($title) if ($title);
401 $rv .= "<span class='ui_emptymsg'><b>$emptymsg</b></span><p>\n";
405 # Are there any checkboxes in each column? If so, make those columns narrow
406 my @tds = map { "valign=top" } @$heads;
408 foreach my $r (@$data) {
410 foreach my $c (@$r) {
412 ($c->{'type'} eq 'checkbox' || $c->{'type'} eq 'radio')) {
413 $tds[$cc] .= " width=5" if ($tds[$cc] !~ /width=/);
417 $maxwidth = $cc if ($cc > $maxwidth);
419 $rv .= &ui_columns_start($heads, $width, 0, \@tds, $title);
422 foreach my $r (@$data) {
424 if (ref($r->[0]) && ($r->[0]->{'type'} eq 'checkbox' ||
425 $r->[0]->{'type'} eq 'radio')) {
426 # First column is special
428 $r = [ @$r[1..(@$r-1)] ];
430 # Turn data into HTML
435 foreach my $c (@$r) {
440 elsif ($c->{'type'} eq 'checkbox') {
441 # Checkbox in non-first column
442 push(@cols, &ui_checkbox($c->{'name'}, $c->{'value'},
443 $c->{'label'}, $c->{'checked'},
444 undef, $c->{'disabled'}));
446 elsif ($c->{'type'} eq 'radio') {
447 # Radio button in non-first column
448 push(@cols, &ui_oneradio($c->{'name'}, $c->{'value'},
449 $c->{'label'}, $c->{'checked'},
450 undef, $c->{'disabled'}));
452 elsif ($c->{'type'} eq 'group') {
453 # Header row that spans whole table
454 $rv .= &ui_columns_header([ $c->{'desc'} ],
455 [ "colspan=$width" ]);
458 elsif ($c->{'type'} eq 'string') {
459 # A string, which might be special
460 push(@cols, $c->{'value'});
461 if ($c->{'columns'} > 1) {
462 splice(@rtds, $cn, $c->{'columns'},
463 "colspan=".$c->{'columns'});
465 if ($c->{'nowrap'}) {
466 $rtds[$cn] .= " nowrap";
473 $rv .= &ui_columns_row(\@cols, \@rtds);
475 elsif ($c0->{'type'} eq 'checkbox') {
476 $rv .= &ui_checked_columns_row(\@cols, \@rtds, $c0->{'name'},
477 $c0->{'value'}, $c0->{'checked'},
480 elsif ($c0->{'type'} eq 'radio') {
481 $rv .= &ui_radio_columns_row(\@cols, \@rtds, $c0->{'name'},
482 $c0->{'value'}, $c0->{'checked'},
487 $rv .= &ui_columns_end();
491 =head2 ui_form_columns_table(cgi, &buttons, select-all, &otherlinks, &hiddens, &headings, width-percent, &data, &types, no-sort, title, empty-msg, form-no)
493 Similar to ui_columns_table, but wrapped in a form. Parameters are :
495 =item cgi - URL to submit the form to.
497 =item buttons - An array ref of buttons at the end of the form, similar to that taken by ui_form_end.
499 =item select-all - If set to 1, include select all / invert links.
501 =item otherslinks - An array ref of other links to put at the top of the table, each of which is a 3-element hash ref of url, text and alignment (left or right).
503 =item hiddens - An array ref of hidden fields, each of which is a 2-element array ref containing the name and value.
505 All other parameters are the same as ui_columns_table.
508 sub ui_form_columns_table
510 return &theme_ui_form_columns_table(@_)
511 if (defined(&theme_ui_form_columns_table));
512 my ($cgi, $buttons, $selectall, $others, $hiddens,
513 $heads, $width, $data, $types, $nosort, $title, $emptymsg, $formno) = @_;
517 my @leftlinks = map { "<a href='$_->[0]'>$_->[1]</a>" }
518 grep { $_->[2] ne 'right' } @$others;
519 my @rightlinks = map { "<a href='$_->[0]'>$_->[1]</a>" }
520 grep { $_->[2] eq 'right' } @$others;
527 foreach my $r (@$data) {
528 foreach my $c (@$r) {
529 if (ref($c) && $c->{'type'} eq 'checkbox') {
530 $cbname = $c->{'name'};
536 unshift(@leftlinks, &select_all_link($cbname, $formno),
537 &select_invert_link($cbname, $formno));
544 $links = &ui_grid_table([ &ui_links_row(\@leftlinks),
545 &ui_links_row(\@rightlinks) ], 2, 100,
546 [ undef, "align=right" ]);
549 $links = &ui_links_row(\@leftlinks);
552 # Start the form, if we need one
554 $rv .= &ui_form_start($cgi, "post");
555 foreach my $h (@$hiddens) {
556 $rv .= &ui_hidden(@$h);
562 $rv .= &ui_columns_table($heads, $width, $data, $types, $nosort, $title,
568 $rv .= &ui_form_end($buttons);
574 ####################### form generation functions
576 =head2 ui_form_start(script, method, [target], [tags])
578 Returns HTML for the start of a a form that submits to some script. The
581 =item script - CGI script to submit to, like save.cgi.
583 =item method - HTTP method, which must be one of 'get', 'post' or 'form-data'. If form-data is used, the target CGI must call ReadParseMime to parse parameters.
585 =item target - Optional target window or frame for the form.
587 =item tags - Additional HTML attributes for the form tag.
592 return &theme_ui_form_start(@_) if (defined(&theme_ui_form_start));
593 my ($script, $method, $target, $tags) = @_;
595 $rv .= "<form class='ui_form' action='".&html_escape($script)."' ".
596 ($method eq "post" ? "method=post" :
597 $method eq "form-data" ?
598 "method=post enctype=multipart/form-data" :
600 ($target ? " target=$target" : "").
606 =head2 ui_form_end([&buttons], [width])
608 Returns HTML for the end of a form, optionally with a row of submit buttons.
609 These are specified by the buttons parameter, which is an array reference
610 of array refs, with the following elements :
612 =item HTML value for the submit input for the button, or undef for none.
614 =item Text to appear on the button.
616 =item HTML or other inputs to appear after the button.
618 =item Set to 1 if the button should be disabled.
620 =item Additional HTML attributes to appear inside the button's input tag.
625 return &theme_ui_form_end(@_) if (defined(&theme_ui_form_end));
626 my ($buttons, $width) = @_;
628 if ($buttons && @$buttons) {
629 $rv .= "<table class='ui_form_end_buttons' ".($width ? " width=$width" : "")."><tr>\n";
631 foreach $b (@$buttons) {
633 $rv .= "<td".(!$width ? "" :
634 $b eq $buttons->[0] ? " align=left" :
635 $b eq $buttons->[@$buttons-1] ?
636 " align=right" : " align=center").">".
637 &ui_submit($b->[1], $b->[0], $b->[3], $b->[4]).
638 ($b->[2] ? " ".$b->[2] : "")."</td>\n";
641 $rv .= "<td>$b</td>\n";
644 $rv .= "<td> </td>\n";
647 $rv .= "</tr></table>\n";
653 =head2 ui_textbox(name, value, size, [disabled?], [maxlength], [tags])
655 Returns HTML for a text input box. The parameters are :
657 =item name - Name for this input.
659 =item value - Initial contents for the text box.
661 =item size - Desired width in characters.
663 =item disabled - Set to 1 if this text box should be disabled by default.
665 =item maxlength - Maximum length of the string the user is allowed to input.
667 =item tags - Additional HTML attributes for the <input> tag.
672 return &theme_ui_textbox(@_) if (defined(&theme_ui_textbox));
673 my ($name, $value, $size, $dis, $max, $tags) = @_;
674 $size = &ui_max_text_width($size);
675 return "<input class='ui_textbox' name=\""."e_escape($name)."\" ".
676 "value=\""."e_escape($value)."\" ".
677 "size=$size ".($dis ? "disabled=true" : "").
678 ($max ? " maxlength=$max" : "").
683 =head2 ui_filebox(name, value, size, [disabled?], [maxlength], [tags], [dir-only])
685 Returns HTML for a text box for choosing a file. Parameters are the same
686 as ui_textbox, except for the extra dir-only option which limits the chooser
692 return &theme_ui_filebox(@_) if (defined(&theme_ui_filebox));
693 my ($name, $value, $size, $dis, $max, $tags, $dironly) = @_;
694 return &ui_textbox($name, $value, $size, $dis, $max, $tags)." ".
695 &file_chooser_button($name, $dironly);
698 =head2 ui_bytesbox(name, bytes, [size], [disabled?])
700 Returns HTML for entering a number of bytes, but with friendly kB/MB/GB
701 options. May truncate values to 2 decimal points! The parameters are :
703 =item name - Name for this input.
705 =item bytes - Initial number of bytes to show.
707 =item size - Desired width of the text box part.
709 =item disabled - Set to 1 if this text box should be disabled by default.
711 =item tags - Additional HTML attributes for the <input> tag.
716 my ($name, $bytes, $size, $dis, $tags) = @_;
718 if ($bytes >= 10*1024*1024*1024*1024) {
719 $units = 1024*1024*1024*1024;
721 elsif ($bytes >= 10*1024*1024*1024) {
722 $units = 1024*1024*1024;
724 elsif ($bytes >= 10*1024*1024) {
727 elsif ($bytes >= 10*1024) {
734 $bytes = sprintf("%.2f", ($bytes*1.0)/$units);
737 $size = &ui_max_text_width($size || 8);
738 return &ui_textbox($name, $bytes, $size, $dis, undef, $tags)." ".
739 &ui_select($name."_units", $units,
743 [ 1024*1024*1024, "GB" ],
744 [ 1024*1024*1024*1024, "TB" ] ], undef, undef, undef, $dis);
747 =head2 ui_upload(name, size, [disabled?], [tags])
749 Returns HTML for a file upload input, for use in a form with the form-data
750 method. The parameters are :
752 =item name - Name for this input.
754 =item size - Desired width in characters.
756 =item disabled - Set to 1 if this text box should be disabled by default.
758 =item tags - Additional HTML attributes for the <input> tag.
763 return &theme_ui_upload(@_) if (defined(&theme_ui_upload));
764 my ($name, $size, $dis, $tags) = @_;
765 $size = &ui_max_text_width($size);
766 return "<input class='ui_upload' type=file name=\""."e_escape($name)."\" ".
768 ($dis ? "disabled=true" : "").
769 ($tags ? " ".$tags : "").">";
772 =head2 ui_password(name, value, size, [disabled?], [maxlength], [tags])
774 Returns HTML for a password text input. Parameters are the same as ui_textbox,
775 and behaviour is identical except that the user's input is not visible.
780 return &theme_ui_password(@_) if (defined(&theme_ui_password));
781 my ($name, $value, $size, $dis, $max, $tags) = @_;
782 $size = &ui_max_text_width($size);
783 return "<input class='ui_password' ".
784 "type=password name=\""."e_escape($name)."\" ".
785 "value=\""."e_escape($value)."\" ".
786 "size=$size ".($dis ? "disabled=true" : "").
787 ($max ? " maxlength=$max" : "").
792 =head2 ui_hidden(name, value)
794 Returns HTML for a hidden field with the given name and value.
799 return &theme_ui_hidden(@_) if (defined(&theme_ui_hidden));
800 my ($name, $value) = @_;
801 return "<input class='ui_hidden' type=hidden ".
802 "name=\""."e_escape($name)."\" ".
803 "value=\""."e_escape($value)."\">\n";
806 =head2 ui_select(name, value|&values, &options, [size], [multiple], [add-if-missing], [disabled?], [javascript])
808 Returns HTML for a drop-down menu or multiple selection list. The parameters
811 =item name - Name for this input.
813 =item value - Either a single initial value, or an array reference of values if this is a multi-select list.
815 =item options - An array reference of possible options. Each element can either be a scalar, or a two-element array ref containing a submitted value and displayed text.
817 =item size - Desired vertical size in rows, which defaults to 1. For multi-select lists, this must be set to something larger.
819 =item multiple - Set to 1 for a multi-select list, 0 for single.
821 =item add-if-missing - If set to 1, any value that is not in the list of options will be automatically added (and selected).
823 =item disabled - Set to 1 to disable this input.
825 =item javascript - Additional HTML attributes for the <select> input.
830 return &theme_ui_select(@_) if (defined(&theme_ui_select));
831 my ($name, $value, $opts, $size, $multiple, $missing, $dis, $js) = @_;
833 $rv .= "<select class='ui_select' name=\""."e_escape($name)."\"".
834 ($size ? " size=$size" : "").
835 ($multiple ? " multiple" : "").
836 ($dis ? " disabled=true" : "")." ".$js.">\n";
838 my %sel = ref($value) ? ( map { $_, 1 } @$value ) : ( $value, 1 );
839 foreach $o (@$opts) {
840 $o = [ $o ] if (!ref($o));
841 $rv .= "<option value=\""."e_escape($o->[0])."\"".
842 ($sel{$o->[0]} ? " selected" : "")." ".$o->[2].">".
843 ($o->[1] || $o->[0])."\n";
846 foreach $s (keys %sel) {
847 if (!$opt{$s} && $missing) {
848 $rv .= "<option value=\""."e_escape($s)."\"".
849 "selected>".($s eq "" ? " " : $s)."\n";
852 $rv .= "</select>\n";
856 =head2 ui_multi_select(name, &values, &options, size, [add-if-missing], [disabled?], [options-title, values-title], [width])
858 Returns HTML for selecting many of many from a list. By default, this is
859 implemented using two <select> lists and Javascript buttons to move elements
860 between them. The resulting input value is \n separated.
864 =item name - HTML name for this input.
866 =item values - An array reference of two-element array refs, containing the submitted values and descriptions of items that are selected by default.
868 =item options - An array reference of two-element array refs, containing the submitted values and descriptions of items that the user can select from.
870 =item size - Vertical size in rows.
872 =item add-if-missing - If set to 1, any entries that are in values but not in options will be added automatically.
874 =item disabled - Set to 1 to disable this input by default.
876 =item options-title - Optional text to appear above the list of options.
878 =item values-title - Optional text to appear above the list of selected values.
880 =item width - Optional width of the two lists in pixels.
885 return &theme_ui_multi_select(@_) if (defined(&theme_ui_multi_select));
886 my ($name, $values, $opts, $size, $missing, $dis,
887 $opts_title, $vals_title, $width) = @_;
889 my %already = map { $_->[0], $_ } @$values;
890 my $leftover = [ grep { !$already{$_->[0]} } @$opts ];
892 my %optsalready = map { $_->[0], $_ } @$opts;
893 push(@$opts, grep { !$optsalready{$_->[0]} } @$values);
895 if (!defined($width)) {
898 my $wstyle = $width ? "style='width:$width'" : "";
900 if (!$main::ui_multi_select_donejs++) {
901 $rv .= &ui_multi_select_javascript();
903 $rv .= "<table cellpadding=0 cellspacing=0 class='ui_multi_select'>";
904 if (defined($opts_title)) {
905 $rv .= "<tr class='ui_multi_select_heads'> ".
906 "<td><b>$opts_title</b></td> ".
907 "<td></td> <td><b>$vals_title</b></td> </tr>";
909 $rv .= "<tr class='ui_multi_select_row'>";
910 $rv .= "<td>".&ui_select($name."_opts", [ ], $leftover,
911 $size, 0, 0, $dis, $wstyle)."</td>\n";
912 $rv .= "<td>".&ui_button("->", $name."_add", $dis,
913 "onClick='multi_select_move(\"$name\", form, 1)'")."<br>".
914 &ui_button("<-", $name."_remove", $dis,
915 "onClick='multi_select_move(\"$name\", form, 0)'")."</td>\n";
916 $rv .= "<td>".&ui_select($name."_vals", [ ], $values,
917 $size, 0, 0, $dis, $wstyle)."</td>\n";
918 $rv .= "</tr></table>\n";
919 $rv .= &ui_hidden($name, join("\n", map { $_->[0] } @$values));
923 =head2 ui_multi_select_javascript
925 Returns <script> section for left/right select boxes. For internal use only.
928 sub ui_multi_select_javascript
930 return &theme_ui_multiselect_javascript()
931 if (defined(&theme_ui_multiselect_javascript));
934 // Move an element from the options list to the values list, or vice-versa
935 function multi_select_move(name, f, dir)
937 var opts = f.elements[name+"_opts"];
938 var vals = f.elements[name+"_vals"];
939 var opts_idx = opts.selectedIndex;
940 var vals_idx = vals.selectedIndex;
941 if (dir == 1 && opts_idx >= 0) {
942 // Moving from options to selected list
943 var o = opts.options[opts_idx];
944 vals.options[vals.options.length] = new Option(o.text, o.value);
945 opts.remove(opts_idx);
947 else if (dir == 0 && vals_idx >= 0) {
948 // Moving the other way
949 var o = vals.options[vals_idx];
950 opts.options[opts.options.length] = new Option(o.text, o.value);
951 vals.remove(vals_idx);
953 // Fill in hidden field
954 var hid = f.elements[name];
956 var hv = new Array();
957 for(var i=0; i<vals.options.length; i++) {
958 hv.push(vals.options[i].value);
960 hid.value = hv.join("\\n");
967 =head2 ui_radio(name, value, &options, [disabled?])
969 Returns HTML for a series of radio buttons, of which one can be selected. The
972 =item name - HTML name for the radio buttons.
974 =item value - Value of the button that is selected by default.
976 =item options - Array ref of radio button options, each of which is an array ref containing the submitted value and description for each button.
978 =item disabled - Set to 1 to disable all radio buttons by default.
983 return &theme_ui_radio(@_) if (defined(&theme_ui_radio));
984 my ($name, $value, $opts, $dis) = @_;
987 foreach $o (@$opts) {
988 my $id = "e_escape($name."_".$o->[0]);
989 my $label = $o->[1] || $o->[0];
991 if ($label =~ /^(.*?)((<a\s+href|<input|<select|<textarea)[\000-\377]*)$/i) {
995 $rv .= "<input class='ui_radio' type=radio ".
996 "name=\""."e_escape($name)."\" ".
997 "value=\""."e_escape($o->[0])."\"".
998 ($o->[0] eq $value ? " checked" : "").
999 ($dis ? " disabled=true" : "").
1001 " $o->[2]> <label for=\"$id\">".
1002 $label."</label>".$after."\n";
1007 =head2 ui_yesno_radio(name, value, [yes], [no], [disabled?])
1009 Like ui_radio, but always displays just two inputs (yes and no). The parameters
1012 =item name - HTML name of the inputs.
1014 =item value - Option selected by default, typically 1 or 0.
1016 =item yes - The value for the yes option, defaulting to 1.
1018 =item no - The value for the no option, defaulting to 0.
1020 =item disabled - Set to 1 to disable all radio buttons by default.
1025 my ($name, $value, $yes, $no, $dis) = @_;
1026 return &theme_ui_yesno_radio(@_) if (defined(&theme_ui_yesno_radio));
1027 $yes = 1 if (!defined($yes));
1028 $no = 0 if (!defined($no));
1029 $value = int($value);
1030 return &ui_radio($name, $value, [ [ $yes, $text{'yes'} ],
1031 [ $no, $text{'no'} ] ], $dis);
1034 =head2 ui_checkbox(name, value, label, selected?, [tags], [disabled?])
1036 Returns HTML for a single checkbox. Parameters are :
1038 =item name - HTML name of the checkbox.
1040 =item value - Value that will be submitted if it is checked.
1042 =item label - Text to appear next to the checkbox.
1044 =item selected - Set to 1 for it to be checked by default.
1046 =item tags - Additional HTML attributes for the <input> tag.
1048 =item disabled - Set to 1 to disable the checkbox by default.
1053 return &theme_ui_checkbox(@_) if (defined(&theme_ui_checkbox));
1054 my ($name, $value, $label, $sel, $tags, $dis) = @_;
1056 if ($label =~ /^([^<]*)(<[\000-\377]*)$/) {
1060 return "<input class='ui_checkbox' type=checkbox ".
1061 "name=\""."e_escape($name)."\" ".
1062 "value=\""."e_escape($value)."\" ".
1063 ($sel ? " checked" : "").($dis ? " disabled=true" : "").
1064 " id=\""."e_escape("${name}_${value}")."\"".
1066 ($label eq "" ? $after :
1067 "<label for=\""."e_escape("${name}_${value}").
1068 "\">$label</label>$after")."\n";
1071 =head2 ui_oneradio(name, value, label, selected?, [tags], [disabled?])
1073 Returns HTML for a single radio button. The parameters are :
1075 =item name - HTML name of the radio button.
1077 =item value - Value that will be submitted if it is selected.
1079 =item label - Text to appear next to the button.
1081 =item selected - Set to 1 for it to be selected by default.
1083 =item tags - Additional HTML attributes for the <input> tag.
1085 =item disabled - Set to 1 to disable the radio button by default.
1090 return &theme_ui_oneradio(@_) if (defined(&theme_ui_oneradio));
1091 my ($name, $value, $label, $sel, $tags, $dis) = @_;
1092 my $id = "e_escape("${name}_${value}");
1094 if ($label =~ /^([^<]*)(<[\000-\377]*)$/) {
1098 return "<input class='ui_radio' type=radio name=\""."e_escape($name)."\" ".
1099 "value=\""."e_escape($value)."\" ".
1100 ($sel ? " checked" : "").($dis ? " disabled=true" : "").
1102 " $tags> <label for=\"$id\">$label</label>$after\n";
1105 =head2 ui_textarea(name, value, rows, cols, [wrap], [disabled?], [tags])
1107 Returns HTML for a multi-line text input. The function parameters are :
1109 =item name - Name for this HTML <textarea>.
1111 =item value - Default value. Multiple lines must be separated by \n.
1113 =item rows - Number of rows, in lines.
1115 =item cols - Number of columns, in characters.
1117 =item wrap - Wrapping mode. Can be one of soft, hard or off.
1119 =item disabled - Set to 1 to disable this text area by default.
1121 =item tags - Additional HTML attributes for the <textarea> tag.
1126 return &theme_ui_textarea(@_) if (defined(&theme_ui_textarea));
1127 my ($name, $value, $rows, $cols, $wrap, $dis, $tags) = @_;
1128 $cols = &ui_max_text_width($cols, 1);
1129 return "<textarea class='ui_textarea' name=\""."e_escape($name)."\" ".
1130 "rows=$rows cols=$cols".($wrap ? " wrap=$wrap" : "").
1131 ($dis ? " disabled=true" : "").
1132 ($tags ? " $tags" : "").">".
1133 &html_escape($value).
1137 =head2 ui_user_textbox(name, value, [form], [disabled?], [tags])
1139 Returns HTML for an input for selecting a Unix user. Parameters are the
1145 return &theme_ui_user_textbox(@_) if (defined(&theme_ui_user_textbox));
1146 return &ui_textbox($_[0], $_[1], 13, $_[3], undef, $_[4])." ".
1147 &user_chooser_button($_[0], 0, $_[2]);
1150 =head2 ui_group_textbox(name, value, [form], [disabled?], [tags])
1152 Returns HTML for an input for selecting a Unix group. Parameters are the
1156 sub ui_group_textbox
1158 return &theme_ui_group_textbox(@_) if (defined(&theme_ui_group_textbox));
1159 return &ui_textbox($_[0], $_[1], 13, $_[3], undef, $_[4])." ".
1160 &group_chooser_button($_[0], 0, $_[2]);
1163 =head2 ui_opt_textbox(name, value, size, option1, [option2], [disabled?], [&extra-fields], [max])
1165 Returns HTML for a text field that is optional, implemented by default as
1166 a field with radio buttons next to it. The parameters are :
1168 =item name - HTML name for the text box. The radio buttons will have the same name, but with _def appended.
1170 =item value - Initial value, or undef if you want the default radio button selected initially.
1172 =item size - Width of the text box in characters.
1174 =item option1 - Text for the radio button for selecting that no input is being given, such as 'Default'.
1176 =item option2 - Text for the radio button for selecting that you will provide input.
1178 =item disabled - Set to 1 to disable this input by default.
1180 =item extra-fields - An optional array ref of field names that should be disabled by Javascript when this field is disabled.
1182 =item max - Optional maximum allowed input length, in characters.
1184 =item tags - Additional HTML attributes for the text box
1189 return &theme_ui_opt_textbox(@_) if (defined(&theme_ui_opt_textbox));
1190 my ($name, $value, $size, $opt1, $opt2, $dis, $extra, $max, $tags) = @_;
1191 my $dis1 = &js_disable_inputs([ $name, @$extra ], [ ]);
1192 my $dis2 = &js_disable_inputs([ ], [ $name, @$extra ]);
1194 $size = &ui_max_text_width($size);
1195 $rv .= &ui_radio($name."_def", $value eq '' ? 1 : 0,
1196 [ [ 1, $opt1, "onClick='$dis1'" ],
1197 [ 0, $opt2 || " ", "onClick='$dis2'" ] ], $dis)."\n";
1198 $rv .= "<input class='ui_opt_textbox' name=\""."e_escape($name)."\" ".
1199 "size=$size value=\""."e_escape($value)."\" ".
1200 ($value eq "" || $dis ? "disabled=true" : "").
1201 ($max ? " maxlength=$max" : "").
1207 =head2 ui_submit(label, [name], [disabled?], [tags])
1209 Returns HTML for a form submit button. Parameters are :
1211 =item label - Text to appear on the button.
1213 =item name - Optional HTML name for the button. Useful if the CGI it submits to needs to know which of several buttons was clicked.
1215 =item disabled - Set to 1 if this button should be disabled by default.
1217 =item tags - Additional HTML attributes for the <input> tag.
1222 return &theme_ui_submit(@_) if (defined(&theme_ui_submit));
1223 my ($label, $name, $dis, $tags) = @_;
1224 return "<input class='ui_submit' type=submit".
1225 ($name ne '' ? " name=\""."e_escape($name)."\"" : "").
1226 " value=\""."e_escape($label)."\"".
1227 ($dis ? " disabled=true" : "").
1228 ($tags ? " ".$tags : "").">\n";
1232 =head2 ui_reset(label, [disabled?])
1234 Returns HTML for a form reset button, which clears all fields when clicked.
1237 =item label - Text to appear on the button.
1239 =item disabled - Set to 1 if this button should be disabled by default.
1244 return &theme_ui_reset(@_) if (defined(&theme_ui_reset));
1245 my ($label, $dis) = @_;
1246 return "<input type=reset value=\""."e_escape($label)."\"".
1247 ($dis ? " disabled=true" : "").">\n";
1251 =head2 ui_button(label, [name], [disabled?], [tags])
1253 Returns HTML for a form button, which doesn't do anything when clicked unless
1254 you add some Javascript to it. The parameters are :
1256 =item label - Text to appear on the button.
1258 =item name - HTML name for this input.
1260 =item disabled - Set to 1 if this button should be disabled by default.
1262 =item tags - Additional HTML attributes for the <input> tag, typically Javascript inside an onClick attribute.
1267 return &theme_ui_button(@_) if (defined(&theme_ui_button));
1268 my ($label, $name, $dis, $tags) = @_;
1269 return "<input type=button".
1270 ($name ne '' ? " name=\""."e_escape($name)."\"" : "").
1271 " value=\""."e_escape($label)."\"".
1272 ($dis ? " disabled=true" : "").
1273 ($tags ? " ".$tags : "").">\n";
1276 =head2 ui_date_input(day, month, year, day-name, month-name, year-name, [disabled?])
1278 Returns HTML for a date-selection field, with day, month and year inputs.
1279 The parameters are :
1281 =item day - Initial day of the month.
1283 =item month - Initial month of the year, indexed from 1.
1285 =item year - Initial year, four-digit.
1287 =item day-name - Name of the day input field.
1289 =item month-name - Name of the month select field.
1291 =item year-name - Name of the year input field.
1293 =item disabled - Set to 1 to disable all fields by default.
1298 my ($day, $month, $year, $dayname, $monthname, $yearname, $dis) = @_;
1300 $rv .= "<span class='ui_data'>";
1301 $rv .= &ui_textbox($dayname, $day, 3, $dis);
1303 $rv .= &ui_select($monthname, $month,
1304 [ map { [ $_, $text{"smonth_$_"} ] } (1 .. 12) ],
1307 $rv .= &ui_textbox($yearname, $year, 5, $dis);
1312 =head2 ui_buttons_start
1314 Returns HTML for the start of a block of action buttoms with descriptions, as
1315 generated by ui_buttons_row. Some example code :
1317 print ui_buttons_start();
1318 print ui_buttons_row('start.cgi', 'Start server',
1319 'Click this button to start the server process');
1320 print ui_buttons_row('stop.cgi', 'Stop server',
1321 'Click this button to stop the server process');
1322 print ui_buttons_end();
1325 sub ui_buttons_start
1327 return &theme_ui_buttons_start(@_) if (defined(&theme_ui_buttons_start));
1328 return "<table width=100% class='ui_buttons_table'>\n";
1331 =head2 ui_buttons_end
1333 Returns HTML for the end of a block started by ui_buttons_start.
1338 return &theme_ui_buttons_end(@_) if (defined(&theme_ui_buttons_end));
1339 return "</table>\n";
1342 =head2 ui_buttons_row(script, button-label, description, [hiddens], [after-submit], [before-submit])
1344 Returns HTML for a button with a description next to it, and perhaps other
1345 inputs. The parameters are :
1347 =item script - CGI script that this button submits to, like start.cgi.
1349 =item button-label - Text to appear on the button.
1351 =item description - Text to appear next to the button, describing in more detail what it does.
1353 =item hiddens - HTML for hidden fields to include in the form this function generates.
1355 =item after-submit - HTML for text or inputs to appear after the submit button.
1357 =item before-submit - HTML for text or inputs to appear before the submit button.
1362 return &theme_ui_buttons_row(@_) if (defined(&theme_ui_buttons_row));
1363 my ($script, $label, $desc, $hiddens, $after, $before) = @_;
1364 return "<form action=$script class='ui_buttons_form'>\n".
1366 "<tr class='ui_buttons_row'> ".
1367 "<td nowrap width=20% valign=top class=ui_buttons_label>".
1368 ($before ? $before." " : "").
1369 &ui_submit($label).($after ? " ".$after : "")."</td>\n".
1370 "<td valign=top width=80% valign=top class=ui_buttons_value>".
1371 $desc."</td> </tr>\n".
1375 =head2 ui_buttons_hr([title])
1377 Returns HTML for a separator row, for use inside a ui_buttons_start block.
1383 return &theme_ui_buttons_hr(@_) if (defined(&theme_ui_buttons_hr));
1385 return "<tr class='ui_buttons_hr'> <td colspan=2><table cellpadding=0 cellspacing=0 width=100%><tr> <td width=50%><hr></td> <td nowrap>$title</td> <td width=50%><hr></td> </tr></table></td> </tr>\n";
1388 return "<tr class='ui_buttons_hr'> <td colspan=2><hr></td> </tr>\n";
1392 ####################### header and footer functions
1394 =head2 ui_post_header([subtext])
1396 Returns HTML to appear directly after a standard header() call. This is never
1397 called directly - instead, ui_print_header calls it. But it can be overridden
1403 return &theme_ui_post_header(@_) if (defined(&theme_ui_post_header));
1406 $rv .= "<center class='ui_post_header'><font size=+1>$text</font></center>\n" if (defined($text));
1407 if (!$tconfig{'nohr'} && !$tconfig{'notophr'}) {
1408 $rv .= "<hr id='post_header_hr'>\n";
1413 =head2 ui_pre_footer
1415 Returns HTML to appear directly before a standard footer() call. This is never
1416 called directly - instead, ui_print_footer calls it. But it can be overridden
1422 return &theme_ui_pre_footer(@_) if (defined(&theme_ui_pre_footer));
1424 if (!$tconfig{'nohr'} && !$tconfig{'nobottomhr'}) {
1425 $rv .= "<hr id='pre_footer_hr'>\n";
1430 =head2 ui_print_header(subtext, image, [help], [config], [nomodule], [nowebmin], [rightside], [head-stuff], [body-stuff], [below])
1432 Print HTML for a header with the post-header line. The args are the same
1433 as those passed to header(), defined in web-lib-funcs.pl, with the addition
1434 of the subtext parameter :
1436 =item subtext - Text to display below the title
1438 =item title - The text to show at the top of the page
1440 =item image - An image to show instead of the title text. This is typically left blank.
1442 =item help - If set, this is the name of a help page that will be linked to in the title.
1444 =item config - If set to 1, the title will contain a link to the module's config page.
1446 =item nomodule - If set to 1, there will be no link in the title section to the module's index.
1448 =item nowebmin - If set to 1, there will be no link in the title section to the Webmin index.
1450 =item rightside - HTML to be shown on the right-hand side of the title. Can contain multiple lines, separated by <br>. Typically this is used for links to stop, start or restart servers.
1452 =item head-stuff - HTML to be included in the <head> section of the page.
1454 =item body-stuff - HTML attributes to be include in the <body> tag.
1456 =item below - HTML to be displayed below the title. Typically this is used for application or server version information.
1463 &load_theme_library();
1464 return &theme_ui_print_header(@_) if (defined(&theme_ui_print_header));
1465 my ($text, @args) = @_;
1467 print &ui_post_header($text);
1470 =head2 ui_print_unbuffered_header(subtext, args...)
1472 Like ui_print_header, but ensures that output for this page is not buffered
1473 or contained in a table. This should be called by scripts that are producing
1474 output while performing some long-running process.
1477 sub ui_print_unbuffered_header
1479 &load_theme_library();
1480 return &theme_ui_print_unbuffered_header(@_) if (defined(&theme_ui_print_unbuffered_header));
1482 $theme_no_table = 1;
1483 &ui_print_header(@_);
1486 =head2 ui_print_footer(args...)
1488 Print HTML for a footer with the pre-footer line. Args are the same as those
1494 return &theme_ui_print_footer(@_) if (defined(&theme_ui_print_footer));
1496 print &ui_pre_footer();
1500 =head2 ui_config_link(text, &subs)
1502 Returns HTML for a module config link. The first non-null sub will be
1503 replaced with the appropriate URL for the module's config page.
1508 return &theme_ui_config_link(@_) if (defined(&theme_ui_config_link));
1509 my ($text, $subs) = @_;
1510 my @subs = map { $_ || "../config.cgi?$module_name" }
1511 ($subs ? @$subs : ( undef ));
1512 return "<p>".&text($text, @subs)."<p>\n";
1515 =head2 ui_print_endpage(text)
1517 Prints HTML for an error message followed by a page footer with a link to
1518 /, then exits. Good for main page error messages.
1521 sub ui_print_endpage
1523 return &theme_ui_print_endpage(@_) if (defined(&theme_ui_print_endpage));
1525 print $text,"<p class='ui_footer'>\n";
1527 &ui_print_footer("/", $text{'index'});
1531 =head2 ui_subheading(text, ...)
1533 Returns HTML for a section heading whose message is the given text strings.
1538 return &theme_ui_subheading(@_) if (defined(&theme_ui_subheading));
1539 return "<h3 class='ui_subheading'>".join("", @_)."</h3>\n";
1542 =head2 ui_links_row(&links)
1544 Returns HTML for a row of links, like select all / invert selection / add..
1545 Each element of the links array ref should be an HTML fragment like :
1547 <a href='user_form.cgi'>Create new user</a>
1552 return &theme_ui_links_row(@_) if (defined(&theme_ui_links_row));
1554 return @$links ? join("\n|\n", @$links)."<br>\n"
1558 ########################### collapsible section / tab functions
1560 =head2 ui_hidden_javascript
1562 Returns <script> and <style> sections for hiding functions and CSS. For
1566 sub ui_hidden_javascript
1568 return &theme_ui_hidden_javascript(@_)
1569 if (defined(&theme_ui_hidden_javascript));
1571 my $imgdir = "$gconfig{'webprefix'}/images";
1572 my ($jscb, $jstb) = ($cb, $tb);
1578 .opener_shown {display:inline}
1579 .opener_hidden {display:none}
1582 // Open or close a hidden section
1583 function hidden_opener(divid, openerid)
1585 var divobj = document.getElementById(divid);
1586 var openerobj = document.getElementById(openerid);
1587 if (divobj.className == 'opener_shown') {
1588 divobj.className = 'opener_hidden';
1589 openerobj.innerHTML = '<img border=0 src=$imgdir/closed.gif>';
1592 divobj.className = 'opener_shown';
1593 openerobj.innerHTML = '<img border=0 src=$imgdir/open.gif>';
1598 function select_tab(name, tabname, form)
1600 var tabnames = document[name+'_tabnames'];
1601 var tabtitles = document[name+'_tabtitles'];
1602 for(var i=0; i<tabnames.length; i++) {
1603 var tabobj = document.getElementById('tab_'+tabnames[i]);
1604 var divobj = document.getElementById('div_'+tabnames[i]);
1605 var title = tabtitles[i];
1606 if (tabnames[i] == tabname) {
1608 tabobj.innerHTML = '<table cellpadding=0 cellspacing=0><tr>'+
1609 '<td valign=top $jscb>'+
1610 '<img src=$imgdir/lc2.gif alt=""></td>'+
1611 '<td $jscb nowrap>'+
1612 ' <b>'+title+'</b> </td>'+
1613 '<td valign=top $jscb>'+
1614 '<img src=$imgdir/rc2.gif alt=""></td>'+
1616 divobj.className = 'opener_shown';
1620 tabobj.innerHTML = '<table cellpadding=0 cellspacing=0><tr>'+
1621 '<td valign=top $jstb>'+
1622 '<img src=$imgdir/lc1.gif alt=""></td>'+
1623 '<td $jstb nowrap>'+
1624 ' <a href=\\'\\' onClick=\\'return select_tab("'+
1625 name+'", "'+tabnames[i]+'")\\'>'+title+'</a> </td>'+
1626 '<td valign=top $jstb>'+
1627 '<img src=$imgdir/rc1.gif alt=""></td>'+
1629 divobj.className = 'opener_hidden';
1632 if (document.forms[0] && document.forms[0][name]) {
1633 document.forms[0][name].value = tabname;
1641 =head2 ui_hidden_start(title, name, status, thisurl)
1643 Returns HTML for the start of a collapsible hidden section, such as for
1644 advanced options. When clicked on, the section header will expand to display
1645 whatever is between this function and ui_hidden_end. The parameters are :
1647 =item title - Text for the start of this hidden section.
1649 =item name - A unique name for this section.
1651 =item status - 1 if it should be initially open, 0 if not.
1653 =item thisurl - URL of the current page. This is used by themes on devices that don't support Javascript to implement the opening and closing.
1658 return &theme_ui_hidden_start(@_) if (defined(&theme_ui_hidden_start));
1659 my ($title, $name, $status, $url) = @_;
1661 if (!$main::ui_hidden_start_donejs++) {
1662 $rv .= &ui_hidden_javascript();
1664 my $divid = "hiddendiv_$name";
1665 my $openerid = "hiddenopener_$name";
1666 my $defimg = $status ? "open.gif" : "closed.gif";
1667 my $defclass = $status ? 'opener_shown' : 'opener_hidden';
1668 $rv .= "<a href=\"javascript:hidden_opener('$divid', '$openerid')\" id='$openerid'><img border=0 src='$gconfig{'webprefix'}/images/$defimg' alt='*'></a>\n";
1669 $rv .= "<a href=\"javascript:hidden_opener('$divid', '$openerid')\">$title</a><br>\n";
1670 $rv .= "<div class='$defclass' id='$divid'>\n";
1674 =head2 ui_hidden_end(name)
1676 Returns HTML for the end of a hidden section, started by ui_hidden_start.
1681 return &theme_ui_hidden_end(@_) if (defined(&theme_ui_hidden_end));
1686 =head2 ui_hidden_table_row_start(title, name, status, thisurl)
1688 Similar to ui_hidden_start, but for use within a table started with
1689 ui_table_start. I recommend against using this where possible, as it can
1690 be difficult for some themes to implement.
1693 sub ui_hidden_table_row_start
1695 return &theme_ui_hidden_table_row_start(@_)
1696 if (defined(&theme_ui_hidden_table_row_start));
1697 my ($title, $name, $status, $url) = @_;
1699 if (!$main::ui_hidden_start_donejs++) {
1700 $rv .= &ui_hidden_javascript();
1702 my $divid = "hiddendiv_$name";
1703 my $openerid = "hiddenopener_$name";
1704 my $defimg = $status ? "open.gif" : "closed.gif";
1705 my $defclass = $status ? 'opener_shown' : 'opener_hidden';
1706 $rrv .= "<a href=\"javascript:hidden_opener('$divid', '$openerid')\" id='$openerid'><img border=0 src='$gconfig{'webprefix'}/images/$defimg'></a>\n";
1707 $rrv .= "<a href=\"javascript:hidden_opener('$divid', '$openerid')\">$title</a><br>\n";
1708 $rv .= &ui_table_row(undef, $rrv, $main::ui_table_cols);
1709 $rv .= "</table>\n";
1710 $rv .= "<div class='$defclass' id='$divid'>\n";
1711 $rv .= "<table width=100%>\n";
1715 =head2 ui_hidden_table_row_end(name)
1717 Returns HTML to end a block started by ui_hidden_table_start.
1720 sub ui_hidden_table_row_end
1722 return &theme_ui_hidden_table_row_end(@_)
1723 if (defined(&theme_ui_hidden_table_row_end));
1725 return "</table></div><table width=100%>\n";
1728 =head2 ui_hidden_table_start(heading, [tabletags], [cols], name, status, [&default-tds], [rightheading])
1730 Returns HTML for the start of a form block into which labelled inputs can
1731 be placed, which is collapsible by clicking on the header. Basically the same
1732 as ui_table_start, and must contain HTML generated by ui_table_row.
1734 The parameters are :
1736 =item heading - Text to show at the top of the form.
1738 =item tabletags - HTML attributes to put in the outer <table>, typically something like width=100%.
1740 =item cols - Desired number of columns for labels and fields. Defaults to 4, but can be 2 for forms with lots of wide inputs.
1742 =item name - A unique name for this table.
1744 =item status - Set to 1 if initially open, 0 if initially closed.
1746 =item default-tds - An optional array reference of HTML attributes for the <td> tags in each row of the table.
1748 =item right-heading - HTML to appear in the heading, aligned to the right.
1751 sub ui_hidden_table_start
1753 return &theme_ui_hidden_table_start(@_)
1754 if (defined(&theme_ui_hidden_table_start));
1755 my ($heading, $tabletags, $cols, $name, $status, $tds, $rightheading) = @_;
1757 if (!$main::ui_hidden_start_donejs++) {
1758 $rv .= &ui_hidden_javascript();
1760 my $divid = "hiddendiv_$name";
1761 my $openerid = "hiddenopener_$name";
1762 my $defimg = $status ? "open.gif" : "closed.gif";
1763 my $defclass = $status ? 'opener_shown' : 'opener_hidden';
1764 my $text = defined($tconfig{'cs_text'}) ? $tconfig{'cs_text'} :
1765 defined($gconfig{'cs_text'}) ? $gconfig{'cs_text'} : "000000";
1766 $rv .= "<table class='ui_table' border $tabletags>\n";
1768 if (defined($heading) || defined($rightheading)) {
1769 $rv .= "<tr $tb> <td>";
1770 if (defined($heading)) {
1771 $rv .= "<a href=\"javascript:hidden_opener('$divid', '$openerid')\" id='$openerid'><img border=0 src='$gconfig{'webprefix'}/images/$defimg'></a> <a href=\"javascript:hidden_opener('$divid', '$openerid')\"><b><font color=#$text>$heading</font></b></a></td>";
1773 if (defined($rightheading)) {
1774 $rv .= "<td align=right>$rightheading</td>";
1777 $rv .= "</td> </tr>\n";
1779 $rv .= "<tr $cb> <td colspan=$colspan><div class='$defclass' id='$divid'><table width=100%>\n";
1780 $main::ui_table_cols = $cols || 4;
1781 $main::ui_table_pos = 0;
1782 $main::ui_table_default_tds = $tds;
1786 =head2 ui_hidden_table_end(name)
1788 Returns HTML for the end of a form block with hiding, as started by
1789 ui_hidden_table_start.
1792 sub ui_hidden_table_end
1795 return &theme_ui_hidden_table_end(@_) if (defined(&theme_ui_hidden_table_end));
1796 return "</table></div></td></tr></table>\n";
1799 =head2 ui_tabs_start(&tabs, name, selected, show-border)
1801 Returns a row of tabs from which one can be selected, displaying HTML
1802 associated with that tab. The parameters are :
1804 =item tabs - An array reference of array refs, each of which contains the value and user-visible text for a tab.
1806 =item name - Name of the HTML field into which the selected tab will be placed.
1808 =item selected - Value for the tab selected by default.
1810 =item show-border - Set to 1 if there should be a border around the contents of the tabs.
1814 @tabs = ( [ 'list', 'List services' ],
1815 [ 'install', 'Install new service' ] );
1816 print ui_tabs_start(\@tabs, 'mode', 'list');
1818 print ui_tabs_start_tab('mode', 'list');
1819 generate_service_list();
1820 print ui_tabs_end_tab('mode', 'list');
1822 print ui_tabs_start_tab('mode', 'install');
1823 generate_install_form();
1824 print ui_tabs_end_tab('mode', 'install);
1826 print ui_tabs_end();
1831 return &theme_ui_tabs_start(@_) if (defined(&theme_ui_tabs_start));
1832 my ($tabs, $name, $sel, $border) = @_;
1834 if (!$main::ui_hidden_start_donejs++) {
1835 $rv .= &ui_hidden_javascript();
1838 # Build list of tab titles and names
1839 my $tabnames = "[".join(",", map { "\"".&html_escape($_->[0])."\"" } @$tabs)."]";
1840 my $tabtitles = "[".join(",", map { "\"".&html_escape($_->[1])."\"" } @$tabs)."]";
1841 $rv .= "<script>\n";
1842 $rv .= "document.${name}_tabnames = $tabnames;\n";
1843 $rv .= "document.${name}_tabtitles = $tabtitles;\n";
1844 $rv .= "</script>\n";
1847 my $imgdir = "$gconfig{'webprefix'}/images";
1848 $rv .= &ui_hidden($name, $sel)."\n";
1849 $rv .= "<table border=0 cellpadding=0 cellspacing=0 class='ui_tabs'>\n";
1850 $rv .= "<tr><td bgcolor=#ffffff colspan=".(scalar(@$tabs)*2+1).">";
1851 if ($ENV{'HTTP_USER_AGENT'} !~ /msie/i) {
1852 # For some reason, the 1-pixel space above the tabs appears huge on IE!
1853 $rv .= "<img src=$imgdir/1x1.gif>";
1855 $rv .= "</td></tr>\n";
1857 $rv .= "<td bgcolor=#ffffff width=1><img src=$imgdir/1x1.gif></td>\n";
1858 foreach my $t (@$tabs) {
1859 if ($t ne $$tabs[0]) {
1861 $rv .= "<td width=2 bgcolor=#ffffff class='ui_tab_spacer'>".
1862 "<img src=$imgdir/1x1.gif></td>\n";
1864 my $tabid = "tab_".$t->[0];
1865 $rv .= "<td id=${tabid} class='ui_tab'>";
1866 $rv .= "<table cellpadding=0 cellspacing=0 border=0><tr>";
1867 if ($t->[0] eq $sel) {
1869 $rv .= "<td valign=top $cb class='selectedTabLeft'>".
1870 "<img src=$imgdir/lc2.gif alt=\"\"></td>";
1871 $rv .= "<td $cb nowrap class='selectedTabMiddle'>".
1872 " <b>$t->[1]</b> </td>";
1873 $rv .= "<td valign=top $cb class='selectedTabRight'>".
1874 "<img src=$imgdir/rc2.gif alt=\"\"></td>";
1877 # Other tab (which has a link)
1878 $rv .= "<td valign=top $tb>".
1879 "<img src=$imgdir/lc1.gif alt=\"\"></td>";
1880 $rv .= "<td $tb nowrap>".
1881 " <a href='$t->[2]' ".
1882 "onClick='return select_tab(\"$name\", \"$t->[0]\")'>".
1883 "$t->[1]</a> </td>";
1884 $rv .= "<td valign=top $tb>".
1885 "<img src=$imgdir/rc1.gif ".
1889 $rv .= "</tr></table>";
1892 $rv .= "<td bgcolor=#ffffff width=1><img src=$imgdir/1x1.gif></td>\n";
1893 $rv .= "</table>\n";
1896 # All tabs are within a grey box
1897 $rv .= "<table width=100% cellpadding=0 cellspacing=0 border=0 ".
1898 "class='ui_tabs_box'>\n";
1899 $rv .= "<tr> <td bgcolor=#ffffff rowspan=3 width=1><img src=$imgdir/1x1.gif></td>\n";
1900 $rv .= "<td $cb colspan=3 height=2><img src=$imgdir/1x1.gif></td> </tr>\n";
1901 $rv .= "<tr> <td $cb width=2><img src=$imgdir/1x1.gif></td>\n";
1902 $rv .= "<td valign=top>";
1904 $main::ui_tabs_selected = $sel;
1908 =head2 ui_tabs_end(show-border)
1910 Returns HTML to end a block started by ui_tabs_start. The show-border parameter
1911 must match the parameter with the same name in the start function.
1916 return &theme_ui_tabs_end(@_) if (defined(&theme_ui_tabs_end));
1919 my $imgdir = "$gconfig{'webprefix'}/images";
1922 $rv .= "<td $cb width=2><img src=$imgdir/1x1.gif></td>\n";
1924 $rv .= "<tr> <td $cb colspan=3 height=2><img src=$imgdir/1x1.gif></td> </tr>\n";
1925 $rv .= "</table>\n";
1930 =head2 ui_tabs_start_tab(name, tab)
1932 Must be called before outputting the HTML for the named tab, and returns HTML
1933 for the required <div> block.
1936 sub ui_tabs_start_tab
1938 return &theme_ui_tabs_start_tab(@_) if (defined(&theme_ui_tabs_start_tab));
1939 my ($name, $tab) = @_;
1940 my $defclass = $tab eq $main::ui_tabs_selected ?
1941 'opener_shown' : 'opener_hidden';
1942 my $rv = "<div id='div_$tab' class='$defclass ui_tabs_start'>\n";
1946 =head2 ui_tabs_start_tabletab(name, tab)
1948 Behaves like ui_tabs_start_tab, but for use within a ui_table_start block.
1949 I recommend against using this where possible, as it is difficult for themes
1953 sub ui_tabs_start_tabletab
1955 return &theme_ui_tabs_start_tabletab(@_)
1956 if (defined(&theme_ui_tabs_start_tabletab));
1957 my $div = &ui_tabs_start_tab(@_);
1958 return "</table>\n".$div."<table width=100%>\n";
1961 =head2 ui_tabs_end_tab
1963 Returns HTML for the end of a block started by ui_tabs_start_tab.
1968 return &theme_ui_tabs_end_tab(@_) if (defined(&theme_ui_tabs_end_tab));
1972 =head2 ui_tabs_end_tabletab
1974 Returns HTML for the end of a block started by ui_tabs_start_tabletab.
1977 sub ui_tabs_end_tabletab
1979 return &theme_ui_tabs_end_tabletab(@_)
1980 if (defined(&theme_ui_tabs_end_tabletab));
1981 return "</table></div><table width=100%>\n";
1984 =head2 ui_max_text_width(width, [text-area?])
1986 Returns a new width for a text field, based on theme settings. For internal
1990 sub ui_max_text_width
1993 my $max = $ta ? $tconfig{'maxareawidth'} : $tconfig{'maxboxwidth'};
1994 return $max && $w > $max ? $max : $w;
1997 ####################### radio hidden functions
1999 =head2 ui_radio_selector(&opts, name, selected)
2001 Returns HTML for a set of radio buttons, each of which shows a different
2002 block of HTML when selected. The parameters are :
2004 =item opts - An array ref to arrays containing [ value, label, html ]
2006 =item name - HTML name for the radio buttons
2008 =item selected - Value for the initially selected button.
2011 sub ui_radio_selector
2013 return &theme_ui_radio_selector(@_) if (defined(&theme_ui_radio_selector));
2014 my ($opts, $name, $sel) = @_;
2016 if (!$main::ui_radio_selector_donejs++) {
2017 $rv .= &ui_radio_selector_javascript();
2020 "[".join(",", map { "\"".&html_escape($_->[0])."\"" } @$opts)."]";
2021 foreach my $o (@$opts) {
2022 $rv .= &ui_oneradio($name, $o->[0], $o->[1], $sel eq $o->[0],
2023 "onClick='selector_show(\"$name\", \"$o->[0]\", $optnames)'");
2026 foreach my $o (@$opts) {
2027 my $cls = $o->[0] eq $sel ? "selector_shown" : "selector_hidden";
2028 $rv .= "<div id=sel_${name}_$o->[0] class=$cls>".$o->[2]."</div>\n";
2033 sub ui_radio_selector_javascript
2037 .selector_shown {display:inline}
2038 .selector_hidden {display:none}
2041 function selector_show(name, value, values)
2043 for(var i=0; i<values.length; i++) {
2044 var divobj = document.getElementById('sel_'+name+'_'+values[i]);
2045 divobj.className = value == values[i] ? 'selector_shown'
2046 : 'selector_hidden';
2053 ####################### grid layout functions
2055 =head2 ui_grid_table(&elements, columns, [width-percent], [&tds], [tabletags], [title])
2057 Given a list of HTML elements, formats them into a table with the given
2058 number of columns. However, themes are free to override this to use fewer
2059 columns where space is limited. Parameters are :
2061 =item elements - An array reference of table elements, each of which can be any HTML you like.
2063 =item columns - Desired number of columns in the grid.
2065 =item width-percent - Optional desired width as a percentage.
2067 =item tds - Array ref of HTML attributes for <td> tags in the tables.
2069 =item tabletags - HTML attributes for the <table> tag.
2071 =item title - Optional title to add to the top of the grid.
2076 return &theme_ui_grid_table(@_) if (defined(&theme_ui_grid_table));
2077 my ($elements, $cols, $width, $tds, $tabletags, $title) = @_;
2078 return "" if (!@$elements);
2079 my $rv = "<table class='ui_grid_table'".
2080 ($width ? " width=$width%" : "").
2081 ($tabletags ? " ".$tabletags : "").
2084 for($i=0; $i<@$elements; $i++) {
2085 $rv .= "<tr class='ui_grid_row'>" if ($i%$cols == 0);
2086 $rv .= "<td ".$tds->[$i%$cols]." valign=top class='ui_grid_cell'>".
2087 $elements->[$i]."</td>\n";
2088 $rv .= "</tr>" if ($i%$cols == $cols-1);
2092 $rv .= "<td ".$tds->[$i%$cols]." class='ui_grid_cell'>".
2098 $rv .= "</table>\n";
2099 if (defined($title)) {
2100 $rv = "<table class=ui_table border ".
2101 ($width ? " width=$width%" : "").">\n".
2102 ($title ? "<tr $tb> <td><b>$title</b></td> </tr>\n" : "").
2103 "<tr $cb> <td>$rv</td> </tr>\n".
2109 =head2 ui_radio_table(name, selected, &rows, [no-bold])
2111 Returns HTML for a table of radio buttons, each of which has a label and
2112 some associated inputs to the right. The parameters are :
2114 =item name - Unique name for this table, which is also the radio buttons' name.
2116 =item selected - Value for the initially selected radio button.
2118 =item rows - Array ref of array refs, one per button. The elements of each are the value for this option, a label, and option additional HTML to appear next to it.
2120 =item no-bold - When set to 1, labels in the table will not be bolded
2125 return &theme_ui_radio_table(@_) if (defined(&theme_ui_radio_table));
2126 my ($name, $sel, $rows, $nobold) = @_;
2127 return "" if (!@$rows);
2128 my $rv = "<table class='ui_radio_table'>\n";
2129 foreach my $r (@$rows) {
2131 $rv .= "<td valign=top".(defined($r->[2]) ? "" : " colspan=2").">".
2132 ($nobold ? "" : "<b>").
2133 &ui_oneradio($name, $r->[0], $r->[1], $r->[0] eq $sel, $r->[3]).
2134 ($nobold ? "" : "</b>").
2136 if (defined($r->[2])) {
2137 $rv .= "<td valign=top>".$r->[2]."</td>\n";
2141 $rv .= "</table>\n";
2145 =head2 ui_up_down_arrows(uplink, downlink, up-show, down-show)
2147 Returns HTML for moving some objects in a table up or down. The parameters are :
2149 =item uplink - URL for the up-arrow link.
2151 =item downlink - URL for the down-arrow link.
2153 =item up-show - Set to 1 if the up-arrow should be shown, 0 if not.
2155 =item down-show - Set to 1 if the down-arrow should be shown, 0 if not.
2158 sub ui_up_down_arrows
2160 return &theme_ui_up_down_arrows(@_) if (defined(&theme_ui_up_down_arrows));
2161 my ($uplink, $downlink, $upshow, $downshow) = @_;
2163 my $imgdir = "$gconfig{'webprefix'}/images";
2165 $mover .= "<a href=\"$downlink\">".
2166 "<img src=$imgdir/movedown.gif border=0></a>";
2169 $mover .= "<img src=$imgdir/movegap.gif>";
2172 $mover .= "<a href=\"$uplink\">".
2173 "<img src=$imgdir/moveup.gif border=0></a>";
2176 $mover .= "<img src=$imgdir/movegap.gif>";
2183 Returns a horizontal row tag, typically just an <hr>
2188 return &theme_ui_hr() if (defined(&theme_ui_hr));
2192 =head2 ui_nav_link(direction, url, disabled)
2194 Returns an arrow icon linking to the provided url.
2199 return &theme_ui_nav_link(@_) if (defined(&theme_ui_nav_link));
2200 my ($direction, $url, $disabled) = @_;
2201 my $alt = $direction eq "left" ? '<-' : '->';
2203 return "<img alt=\"$alt\" align=\"middle\""
2204 . "src=\"$gconfig{'webprefix'}/images/$direction-grey.gif\">\n";
2207 return "<a href=\"$url\"><img alt=\"$alt\" align=\"middle\""
2208 . "src=\"$gconfig{'webprefix'}/images/$direction.gif\"></a>\n";
2212 =head2 ui_confirmation_form(cgi, message, &hiddens, [&buttons], [otherinputs], [extra-warning])
2214 Returns HTML for a form asking for confirmation before performing some
2215 action, such as deleting a user. The parameters are :
2217 =item cgi - Script to which the confirmation form submits, like delete.cgi.
2219 =item message - Warning message for the user to see.
2221 =item hiddens - Array ref of two-element array refs, containing hidden form field names and values.
2223 =item buttons - Array ref of two-element array refs, containing form button names and labels.
2225 =item otherinputs - HTML for extra inputs to include in ther form.
2227 =item extra-warning - An additional separate warning message to show.
2230 sub ui_confirmation_form
2232 my ($cgi, $message, $hiddens, $buttons, $others, $warning) = @_;
2234 $rv .= "<center class=ui_confirmation>\n";
2235 $rv .= &ui_form_start($cgi, "post");
2236 foreach my $h (@$hiddens) {
2237 $rv .= &ui_hidden(@$h);
2239 $rv .= "<b>$message</b><p>\n";
2241 $rv .= "<b><font color=#ff0000>$warning</font></b><p>\n";
2244 $rv .= $others."<p>\n";
2246 $rv .= &ui_form_end($buttons);
2247 $rv .= "</center>\n";
2251 ####################### javascript functions
2253 =head2 js_disable_inputs(&disable-inputs, &enable-inputs, [tag])
2255 Returns Javascript to disable some form elements and enable others. Mainly
2259 sub js_disable_inputs
2263 foreach $f (@{$_[0]}) {
2264 $rv .= "e = form.elements[\"$f\"]; e.disabled = true; ";
2265 $rv .= "for(i=0; i<e.length; i++) { e[i].disabled = true; } ";
2267 foreach $f (@{$_[1]}) {
2268 $rv .= "e = form.elements[\"$f\"]; e.disabled = false; ";
2269 $rv .= "for(i=0; i<e.length; i++) { e[i].disabled = false; } ";
2271 foreach $f (@{$_[1]}) {
2272 if ($f =~ /^(.*)_def$/ && &indexof($1, @{$_[1]}) >= 0) {
2273 # When enabling both a _def field and its associated text field,
2274 # disable the text if the _def is set to 1
2276 $rv .= "e = form.elements[\"$f\"]; for(i=0; i<e.length; i++) { if (e[i].checked && e[i].value == \"1\") { form.elements[\"$tf\"].disabled = true } } ";
2279 return $_[2] ? "$_[2]='$rv'" : $rv;
2282 =head2 ui_page_flipper(message, [inputs, cgi], left-link, right-link, [far-left-link], [far-right-link], [below])
2284 Returns HTML for moving left and right in some large list, such as an inbox
2285 or database table. If only 5 parameters are given, no far links are included.
2286 If any link is undef, that array will be greyed out. The parameters are :
2288 =item message - Text or display between arrows.
2290 =item inputs - Additional HTML inputs to show after message.
2292 =item cgi - Optional CGI for form wrapping arrows to submit to.
2294 =item left-link - Link for left-facing arrow.
2296 =item right-link - Link for right-facing arrow.
2298 =item far-left-link - Link for far left-facing arrow, optional.
2300 =item far-right-link - Link for far right-facing arrow, optional.
2302 =item below - HTML to display below the arrows.
2307 return &theme_ui_page_flipper(@_) if (defined(&theme_ui_page_flipper));
2308 my ($msg, $inputs, $cgi, $left, $right, $farleft, $farright, $below) = @_;
2309 my $rv = "<center>";
2310 $rv .= &ui_form_start($cgi) if ($cgi);
2312 # Far left link, if needed
2315 $rv .= "<a href='$farleft'>".
2316 "<img src=$gconfig{'webprefix'}/images/first.gif ".
2317 "border=0 align=middle></a>\n";
2320 $rv .= "<img src=$gconfig{'webprefix'}/images/first-grey.gif ".
2321 "border=0 align=middle></a>\n";
2327 $rv .= "<a href='$left'>".
2328 "<img src=$gconfig{'webprefix'}/images/left.gif ".
2329 "border=0 align=middle></a>\n";
2332 $rv .= "<img src=$gconfig{'webprefix'}/images/left-grey.gif ".
2333 "border=0 align=middle></a>\n";
2336 # Message and inputs
2338 $rv .= " ".$inputs if ($inputs);
2342 $rv .= "<a href='$right'>".
2343 "<img src=$gconfig{'webprefix'}/images/right.gif ".
2344 "border=0 align=middle></a>\n";
2347 $rv .= "<img src=$gconfig{'webprefix'}/images/right-grey.gif ".
2348 "border=0 align=middle></a>\n";
2351 # Far right link, if needed
2354 $rv .= "<a href='$farright'>".
2355 "<img src=$gconfig{'webprefix'}/images/last.gif ".
2356 "border=0 align=middle></a>\n";
2359 $rv .= "<img src=$gconfig{'webprefix'}/images/last-grey.gif ".
2360 "border=0 align=middle></a>\n";
2364 $rv .= "<br>".$below if ($below);
2365 $rv .= &ui_form_end() if ($cgi);
2366 $rv .= "</center>\n";
2370 =head2 js_checkbox_disable(name, &checked-disable, &checked-enable, [tag])
2372 For internal use only.
2375 sub js_checkbox_disable
2379 foreach $f (@{$_[1]}) {
2380 $rv .= "form.elements[\"$f\"].disabled = $_[0].checked; ";
2382 foreach $f (@{$_[2]}) {
2383 $rv .= "form.elements[\"$f\"].disabled = !$_[0].checked; ";
2385 return $_[3] ? "$_[3]='$rv'" : $rv;
2388 =head2 js_redirect(url, [window-object])
2390 Returns HTML to trigger a redirect to some URL.
2395 my ($url, $window) = @_;
2396 if (defined(&theme_js_redirect)) {
2397 return &theme_js_redirect(@_);
2399 $window ||= "window";
2400 return "<script>${window}.location = '"."e_escape($url)."';</script>\n";