3 Common functions for generating HTML for Webmin user interface elements.
6 require '../ui-lib.pl';
7 ui_print_header(undef, 'My Module', '');
9 print ui_form_start('save.cgi');
10 print ui_table_start('My form', undef, 2);
12 print ui_table_row('Enter your name',
13 ui_textbox('name', undef, 40));
16 print ui_form_end([ [ undef, 'Save' ] ]);
18 ui_print_footer('/', 'Webmin index');
22 ####################### table generation functions
24 =head2 ui_table_start(heading, [tabletags], [cols], [&default-tds], [right-heading])
26 Returns HTML for the start of a form block into which labelled inputs can
27 be placed. By default this is implemented as a table with another table inside
28 it, but themes may override this with their own layout.
32 =item heading - Text to show at the top of the form.
34 =item tabletags - HTML attributes to put in the outer <table>, typically something like width=100%.
36 =item cols - Desired number of columns for labels and fields. Defaults to 4, but can be 2 for forms with lots of wide inputs.
38 =item default-tds - An optional array reference of HTML attributes for the <td> tags in each row of the table.
40 =item right-heading - HTML to appear in the heading, aligned to the right.
45 return &theme_ui_table_start(@_) if (defined(&theme_ui_table_start));
46 my ($heading, $tabletags, $cols, $tds, $rightheading) = @_;
47 if (defined($main::ui_table_cols)) {
48 # Push on stack, for nested call
49 push(@main::ui_table_cols_stack, $main::ui_table_cols);
50 push(@main::ui_table_pos_stack, $main::ui_table_pos);
51 push(@main::ui_table_default_tds_stack, $main::ui_table_default_tds);
55 $rv .= "<table class='ui_table' border $tabletags>\n";
56 if (defined($heading) || defined($rightheading)) {
57 $rv .= "<tr $tb class='ui_table_head'>";
58 if (defined($heading)) {
59 $rv .= "<td><b>$heading</b></td>"
61 if (defined($rightheading)) {
62 $rv .= "<td align=right>$rightheading</td>";
67 $rv .= "<tr $cb class='ui_table_body'> <td colspan=$colspan>".
68 "<table width=100%>\n";
69 $main::ui_table_cols = $cols || 4;
70 $main::ui_table_pos = 0;
71 $main::ui_table_default_tds = $tds;
77 Returns HTML for the end of a block started by ui_table_start.
82 return &theme_ui_table_end(@_) if (defined(&theme_ui_table_end));
84 if ($main::ui_table_cols == 4 && $main::ui_table_pos) {
85 # Add an empty block to balance the table
86 $rv .= &ui_table_row(" ", " ");
88 if (@main::ui_table_cols_stack) {
89 $main::ui_table_cols = pop(@main::ui_table_cols_stack);
90 $main::ui_table_pos = pop(@main::ui_table_pos_stack);
91 $main::ui_table_default_tds = pop(@main::ui_table_default_tds_stack);
94 $main::ui_table_cols = undef;
95 $main::ui_table_pos = undef;
96 $main::ui_table_default_tds = undef;
98 $rv .= "</table></td></tr></table>\n";
102 =head2 ui_table_row(label, value, [cols], [&td-tags])
104 Returns HTML for a row in a table started by ui_table_start, with a 1-column
105 label and 1+ column value. The parameters are :
107 =item label - Label for the input field. If this is undef, no label is displayed.
109 =item value - HTML for the input part of the row.
111 =item cols - Number of columns the value should take up, defaulting to 1.
113 =item td-tags - Array reference of HTML attributes for the <td> tags in this row.
118 return &theme_ui_table_row(@_) if (defined(&theme_ui_table_row));
119 my ($label, $value, $cols, $tds) = @_;
121 $tds ||= $main::ui_table_default_tds;
123 if ($main::ui_table_pos+$cols+1 > $main::ui_table_cols &&
124 $main::ui_table_pos != 0) {
125 # If the requested number of cols won't fit in the number
126 # remaining, start a new row
128 $main::ui_table_pos = 0;
130 $rv .= "<tr class='ui_table_row'>\n"
131 if ($main::ui_table_pos%$main::ui_table_cols == 0);
132 $rv .= "<td valign=top $tds->[0] class='ui_label'><b>$label</b></td>\n"
133 if (defined($label));
134 $rv .= "<td valign=top colspan=$cols $tds->[1] class='ui_value'>$value</td>\n";
135 $main::ui_table_pos += $cols+(defined($label) ? 1 : 0);
136 if ($main::ui_table_pos%$main::ui_table_cols == 0) {
138 $main::ui_table_pos = 0;
145 Returns HTML for a row in a block started by ui_table_row, with a horizontal
146 line inside it to separate sections.
151 return &theme_ui_table_hr(@_) if (defined(&theme_ui_table_hr));
157 $rv .= "<tr class='ui_table_hr'> ".
158 "<td colspan=$main::ui_table_cols><hr></td> </tr>\n";
162 =head2 ui_table_span(text)
164 Outputs a table row that spans the whole table, and contains the given text.
170 return &theme_ui_table_hr(@_) if (defined(&theme_ui_table_hr));
176 $rv .= "<tr class='ui_table_span'> ".
177 "<td colspan=$main::ui_table_cols>$text</td> </tr>\n";
181 =head2 ui_columns_start(&headings, [width-percent], [noborder], [&tdtags], [heading])
183 Returns HTML for the start of a multi-column table, with the given headings.
186 =item headings - An array reference of headers for the table's columns.
188 =item width-percent - Desired width as a percentage, or undef to let the browser decide.
190 =item noborder - Set to 1 if the table should not have a border.
192 =item tdtags - An optional reference to an array of HTML attributes for the table's <td> tags.
194 =item heading - An optional heading to put above the table.
199 return &theme_ui_columns_start(@_) if (defined(&theme_ui_columns_start));
200 my ($heads, $width, $noborder, $tdtags, $title) = @_;
202 $rv .= "<table".($noborder ? "" : " border").
203 (defined($width) ? " width=$width%" : "")." class='ui_columns'>\n";
205 $rv .= "<tr $tb class='ui_columns_heading'>".
206 "<td colspan=".scalar(@$heads)."><b>$title</b></td></tr>\n";
208 $rv .= "<tr $tb class='ui_columns_heads'>\n";
210 for($i=0; $i<@$heads; $i++) {
211 $rv .= "<td ".$tdtags->[$i]."><b>".
212 ($heads->[$i] eq "" ? "<br>" : $heads->[$i])."</b></td>\n";
218 =head2 ui_columns_row(&columns, &tdtags)
220 Returns HTML for a row in a multi-column table. The parameters are :
222 =item columns - Reference to an array containing the HTML to show in the columns for this row.
224 =item tdtags - An optional array reference containing HTML attributes for the row's <td> tags.
229 return &theme_ui_columns_row(@_) if (defined(&theme_ui_columns_row));
230 my ($cols, $tdtags) = @_;
232 $rv .= "<tr $cb class='ui_columns_row'>\n";
234 for($i=0; $i<@$cols; $i++) {
235 $rv .= "<td ".$tdtags->[$i].">".
236 ($cols->[$i] !~ /\S/ ? "<br>" : $cols->[$i])."</td>\n";
242 =head2 ui_columns_header(&columns, &tdtags)
244 Returns HTML for a row in a multi-column table, styled as a header. Parameters
245 are the same as ui_columns_row.
248 sub ui_columns_header
250 return &theme_ui_columns_header(@_) if (defined(&theme_ui_columns_header));
251 my ($cols, $tdtags) = @_;
253 $rv .= "<tr $tb class='ui_columns_header'>\n";
255 for($i=0; $i<@$cols; $i++) {
256 $rv .= "<td ".$tdtags->[$i]."><b>".
257 ($cols->[$i] eq "" ? "<br>" : $cols->[$i])."</b></td>\n";
263 =head2 ui_checked_columns_row(&columns, &tdtags, checkname, checkvalue, [checked?], [disabled])
265 Returns HTML for a row in a multi-column table, in which the first column
270 sub ui_checked_columns_row
272 return &theme_ui_checked_columns_row(@_) if (defined(&theme_ui_checked_columns_row));
273 my ($cols, $tdtags, $checkname, $checkvalue, $checked, $disabled) = @_;
275 $rv .= "<tr $cb class='ui_checked_columns'>\n";
276 $rv .= "<td class='ui_checked_checkbox' ".$tdtags->[0].">".
277 &ui_checkbox($checkname, $checkvalue, undef, $checked, undef, $disabled).
280 for($i=0; $i<@$cols; $i++) {
281 $rv .= "<td ".$tdtags->[$i+1].">";
282 if ($cols->[$i] !~ /<a\s+href|<input|<select|<textarea/) {
283 $rv .= "<label for=\"".
284 "e_escape("${checkname}_${checkvalue}")."\">";
286 $rv .= ($cols->[$i] !~ /\S/ ? "<br>" : $cols->[$i]);
287 if ($cols->[$i] !~ /<a\s+href|<input|<select|<textarea/) {
296 =head2 ui_radio_columns_row(&columns, &tdtags, checkname, checkvalue, [checked], [disabled])
298 Returns HTML for a row in a multi-column table, in which the first
299 column is a radio button
302 sub ui_radio_columns_row
304 return &theme_ui_radio_columns_row(@_) if (defined(&theme_ui_radio_columns_row));
305 my ($cols, $tdtags, $checkname, $checkvalue, $checked, $dis) = @_;
307 $rv .= "<tr $cb class='ui_radio_columns'>\n";
308 $rv .= "<td class='ui_radio_radio' ".$tdtags->[0].">".
309 &ui_oneradio($checkname, $checkvalue, "", $checked, undef, $dis)."</td>\n";
311 for($i=0; $i<@$cols; $i++) {
312 $rv .= "<td ".$tdtags->[$i+1].">";
313 if ($cols->[$i] !~ /<a\s+href|<input|<select|<textarea/) {
314 $rv .= "<label for=\"".
315 "e_escape("${checkname}_${checkvalue}")."\">";
317 $rv .= ($cols->[$i] !~ /\S/ ? "<br>" : $cols->[$i]);
318 if ($cols->[$i] !~ /<a\s+href|<input|<select|<textarea/) {
327 =head2 ui_columns_end
329 Returns HTML to end a table started by ui_columns_start
334 return &theme_ui_columns_end(@_) if (defined(&theme_ui_columns_end));
338 =head2 ui_columns_table(&headings, width-percent, &data, &types, no-sort, title, empty-msg)
340 Returns HTML for a complete table.
341 headings - An array ref of heading HTML
342 width-percent - Preferred total width
343 data - A 2x2 array ref of table contents. Each can either be a simple string,
345 { 'type' => 'group', 'desc' => 'Some section title' }
346 { 'type' => 'string', 'value' => 'Foo', 'colums' => 3,
348 { 'type' => 'checkbox', 'name' => 'd', 'value' => 'foo',
349 'label' => 'Yes', 'checked' => 1, 'disabled' => 1 }
350 { 'type' => 'radio', 'name' => 'd', 'value' => 'foo', ... }
351 types - An array ref of data types, such as 'string', 'number', 'bytes'
353 no-sort - Set to 1 to disable sorting by theme
354 title - Text to appear above the table
355 empty-msg - Message to display if no data
360 return &theme_ui_columns_table(@_) if (defined(&theme_ui_columns_table));
361 my ($heads, $width, $data, $types, $nosort, $title, $emptymsg) = @_;
364 # Just show empty message if no data
365 if ($emptymsg && !@$data) {
366 $rv .= &ui_subheading($title) if ($title);
367 $rv .= "<span class='ui_emptymsg'><b>$emptymsg</b></span><p>\n";
371 # Are there any checkboxes in each column? If so, make those columns narrow
372 my @tds = map { "valign=top" } @$heads;
374 foreach my $r (@$data) {
376 foreach my $c (@$r) {
378 ($c->{'type'} eq 'checkbox' || $c->{'type'} eq 'radio')) {
379 $tds[$cc] .= " width=5" if ($tds[$cc] !~ /width=/);
383 $maxwidth = $cc if ($cc > $maxwidth);
385 $rv .= &ui_columns_start($heads, $width, 0, \@tds, $title);
388 foreach my $r (@$data) {
390 if (ref($r->[0]) && ($r->[0]->{'type'} eq 'checkbox' ||
391 $r->[0]->{'type'} eq 'radio')) {
392 # First column is special
394 $r = [ @$r[1..(@$r-1)] ];
396 # Turn data into HTML
401 foreach my $c (@$r) {
406 elsif ($c->{'type'} eq 'checkbox') {
407 # Checkbox in non-first column
408 push(@cols, &ui_checkbox($c->{'name'}, $c->{'value'},
409 $c->{'label'}, $c->{'checked'},
410 undef, $c->{'disabled'}));
412 elsif ($c->{'type'} eq 'radio') {
413 # Radio button in non-first column
414 push(@cols, &ui_oneradio($c->{'name'}, $c->{'value'},
415 $c->{'label'}, $c->{'checked'},
416 undef, $c->{'disabled'}));
418 elsif ($c->{'type'} eq 'group') {
419 # Header row that spans whole table
420 $rv .= &ui_columns_header([ $c->{'desc'} ],
421 [ "colspan=$width" ]);
424 elsif ($c->{'type'} eq 'string') {
425 # A string, which might be special
426 push(@cols, $c->{'value'});
427 if ($c->{'columns'} > 1) {
428 splice(@rtds, $cn, $c->{'columns'},
429 "colspan=".$c->{'columns'});
431 if ($c->{'nowrap'}) {
432 $rtds[$cn] .= " nowrap";
439 $rv .= &ui_columns_row(\@cols, \@rtds);
441 elsif ($c0->{'type'} eq 'checkbox') {
442 $rv .= &ui_checked_columns_row(\@cols, \@rtds, $c0->{'name'},
443 $c0->{'value'}, $c0->{'checked'},
446 elsif ($c0->{'type'} eq 'radio') {
447 $rv .= &ui_radio_columns_row(\@cols, \@rtds, $c0->{'name'},
448 $c0->{'value'}, $c0->{'checked'},
453 $rv .= &ui_columns_end();
457 =head2 ui_form_columns_table(cgi, &buttons, select-all, &otherlinks, &hiddens, &headings, width-percent, &data, &types, no-sort, title, empty-msg)
459 Similar to ui_columns_table, but wrapped in a form. Args are :
460 cgi - URL to submit the form to
461 buttons - An array ref of buttons at the end of the form, similar to
462 that taken by ui_form_end
463 select-all - If set to 1, include select all / invert links
464 otherslinks - An array ref of other links to put at the top of the table,
465 each of which is a 3-element hash ref of url, text and
466 alignment (left or right)
467 hiddens - An array ref of hidden fields, each of which is a 2-element array
468 ref containing the name and value
469 All other parameters are the same as ui_columns_table
472 sub ui_form_columns_table
474 return &theme_ui_form_columns_table(@_)
475 if (defined(&theme_ui_form_columns_table));
476 my ($cgi, $buttons, $selectall, $others, $hiddens,
477 $heads, $width, $data, $types, $nosort, $title, $emptymsg) = @_;
481 my @leftlinks = map { "<a href='$_->[0]'>$_->[1]</a>" }
482 grep { $_->[2] ne 'right' } @$others;
483 my @rightlinks = map { "<a href='$_->[0]'>$_->[1]</a>" }
484 grep { $_->[2] eq 'right' } @$others;
491 foreach my $r (@$data) {
492 foreach my $c (@$r) {
493 if (ref($c) && $c->{'type'} eq 'checkbox') {
494 $cbname = $c->{'name'};
500 unshift(@leftlinks, &select_all_link($cbname),
501 &select_invert_link($cbname));
508 $links = &ui_grid_table([ &ui_links_row(\@leftlinks),
509 &ui_links_row(\@rightlinks) ], 2, 100,
510 [ undef, "align=right" ]);
513 $links = &ui_links_row(\@leftlinks);
516 # Start the form, if we need one
518 $rv .= &ui_form_start($cgi, "post");
519 foreach my $h (@$hiddens) {
520 $rv .= &ui_hidden(@$h);
526 $rv .= &ui_columns_table($heads, $width, $data, $types, $nosort, $title,
532 $rv .= &ui_form_end($buttons);
538 ####################### form generation functions
540 =head2 ui_form_start(script, method, [target], [tags])
542 Returns HTML for a form that submits to some script
547 return &theme_ui_form_start(@_) if (defined(&theme_ui_form_start));
548 my ($script, $method, $target, $tags) = @_;
550 $rv .= "<form class='ui_form' action='".&html_escape($script)."' ".
551 ($method eq "post" ? "method=post" :
552 $method eq "form-data" ?
553 "method=post enctype=multipart/form-data" :
555 ($target ? " target=$target" : "").
561 =head2 ui_form_end([&buttons], [width])
563 Returns HTML for the end of a form, optionally with a row of submit buttons
568 return &theme_ui_form_end(@_) if (defined(&theme_ui_form_end));
569 my ($buttons, $width) = @_;
571 if ($buttons && @$buttons) {
572 $rv .= "<table class='ui_form_end_buttons' ".($width ? " width=$width" : "")."><tr>\n";
574 foreach $b (@$buttons) {
576 $rv .= "<td".(!$width ? "" :
577 $b eq $buttons->[0] ? " align=left" :
578 $b eq $buttons->[@$buttons-1] ?
579 " align=right" : " align=center").">".
580 &ui_submit($b->[1], $b->[0], $b->[3], $b->[4]).
581 ($b->[2] ? " ".$b->[2] : "")."</td>\n";
584 $rv .= "<td>$b</td>\n";
587 $rv .= "<td> </td>\n";
590 $rv .= "</tr></table>\n";
596 =head2 ui_textbox(name, value, size, [disabled?], [maxlength], [tags])
598 Returns HTML for a text input
603 return &theme_ui_textbox(@_) if (defined(&theme_ui_textbox));
604 my ($name, $value, $size, $dis, $max, $tags) = @_;
605 $size = &ui_max_text_width($size);
606 return "<input class='ui_textbox' name=\""."e_escape($name)."\" ".
607 "value=\""."e_escape($value)."\" ".
608 "size=$size ".($dis ? "disabled=true" : "").
609 ($max ? " maxlength=$max" : "").
614 =head2 ui_filebox(name, value, size, [disabled?], [maxlength], [tags], [dir-only])
616 Returns HTML for a text box for choosing a file
621 return &theme_ui_filebox(@_) if (defined(&theme_ui_filebox));
622 my ($name, $value, $size, $dis, $max, $tags, $dironly) = @_;
623 return &ui_textbox($name, $value, $size, $dis, $max, $tags)." ".
624 &file_chooser_button($name, $dironly);
627 =head2 ui_bytesbox(name, bytes, [size], [disabled?])
629 Returns HTML for entering a number of bytes, but with friendly kB/MB/GB
630 options. May truncate values to 2 decimal points!
635 my ($name, $bytes, $size, $dis) = @_;
637 if ($bytes >= 10*1024*1024*1024*1024) {
638 $units = 1024*1024*1024*1024;
640 elsif ($bytes >= 10*1024*1024*1024) {
641 $units = 1024*1024*1024;
643 elsif ($bytes >= 10*1024*1024) {
646 elsif ($bytes >= 10*1024) {
653 $bytes = sprintf("%.2f", ($bytes*1.0)/$units);
656 $size = &ui_max_text_width($size || 8);
657 return &ui_textbox($name, $bytes, $size, $dis)." ".
658 &ui_select($name."_units", $units,
662 [ 1024*1024*1024, "GB" ],
663 [ 1024*1024*1024*1024, "TB" ] ], undef, undef, undef, $dis);
666 =head2 ui_upload(name, size, [disabled?], [tags])
668 Returns HTML for a file upload input
673 return &theme_ui_upload(@_) if (defined(&theme_ui_upload));
674 my ($name, $size, $dis, $tags) = @_;
675 $size = &ui_max_text_width($size);
676 return "<input class='ui_upload' type=file name=\""."e_escape($name)."\" ".
678 ($dis ? "disabled=true" : "").
679 ($tags ? " ".$tags : "").">";
682 =head2 ui_password(name, value, size, [disabled?], [maxlength])
684 Returns HTML for a password text input
689 return &theme_ui_password(@_) if (defined(&theme_ui_password));
690 my ($name, $value, $size, $dis, $max) = @_;
691 $size = &ui_max_text_width($size);
692 return "<input class='ui_password' ".
693 "type=password name=\""."e_escape($name)."\" ".
694 "value=\""."e_escape($value)."\" ".
695 "size=$size ".($dis ? "disabled=true" : "").
696 ($max ? " maxlength=$max" : "").
700 =head2 ui_hidden(name, value)
702 Returns HTML for a hidden field
707 return &theme_ui_hidden(@_) if (defined(&theme_ui_hidden));
708 my ($name, $value) = @_;
709 return "<input class='ui_hidden' type=hidden ".
710 "name=\""."e_escape($name)."\" ".
711 "value=\""."e_escape($value)."\">\n";
714 =head2 ui_select(name, value|&values, &options, [size], [multiple], [add-if-missing], [disabled?], [javascript])
716 Returns HTML for a drop-down menu or multiple selection list
721 return &theme_ui_select(@_) if (defined(&theme_ui_select));
722 my ($name, $value, $opts, $size, $multiple, $missing, $dis, $js) = @_;
724 $rv .= "<select class='ui_select' name=\""."e_escape($name)."\"".
725 ($size ? " size=$size" : "").
726 ($multiple ? " multiple" : "").
727 ($dis ? " disabled=true" : "")." ".$js.">\n";
729 my %sel = ref($value) ? ( map { $_, 1 } @$value ) : ( $value, 1 );
730 foreach $o (@$opts) {
731 $o = [ $o ] if (!ref($o));
732 $rv .= "<option value=\""."e_escape($o->[0])."\"".
733 ($sel{$o->[0]} ? " selected" : "")." ".$o->[2].">".
734 ($o->[1] || $o->[0])."\n";
737 foreach $s (keys %sel) {
738 if (!$opt{$s} && $missing) {
739 $rv .= "<option value=\""."e_escape($s)."\"".
740 "selected>".($s eq "" ? " " : $s)."\n";
743 $rv .= "</select>\n";
747 =head2 ui_multi_select(name, &values, &options, size, [add-if-missing], [disabled?], [options-title, values-title], [width])
749 Returns HTML for selecting many of many from a list. By default, this is
750 implemented using two <select> lists and Javascript buttons to move elements
751 between them. The resulting input value is \n separated.
756 return &theme_ui_multi_select(@_) if (defined(&theme_ui_multi_select));
757 my ($name, $values, $opts, $size, $missing, $dis,
758 $opts_title, $vals_title, $width) = @_;
760 my %already = map { $_->[0], $_ } @$values;
761 my $leftover = [ grep { !$already{$_->[0]} } @$opts ];
763 my %optsalready = map { $_->[0], $_ } @$opts;
764 push(@$opts, grep { !$optsalready{$_->[0]} } @$values);
766 if (!defined($width)) {
769 my $wstyle = $width ? "style='width:$width'" : "";
771 if (!$main::ui_multi_select_donejs++) {
772 $rv .= &ui_multi_select_javascript();
774 $rv .= "<table cellpadding=0 cellspacing=0 class='ui_multi_select'>";
775 if (defined($opts_title)) {
776 $rv .= "<tr class='ui_multi_select_heads'> ".
777 "<td><b>$opts_title</b></td> ".
778 "<td></td> <td><b>$vals_title</b></td> </tr>";
780 $rv .= "<tr class='ui_multi_select_row'>";
781 $rv .= "<td>".&ui_select($name."_opts", [ ], $leftover,
782 $size, 0, 0, $dis, $wstyle)."</td>\n";
783 $rv .= "<td>".&ui_button("->", undef, $dis,
784 "onClick='multi_select_move(\"$name\", form, 1)'")."<br>".
785 &ui_button("<-", undef, $dis,
786 "onClick='multi_select_move(\"$name\", form, 0)'")."</td>\n";
787 $rv .= "<td>".&ui_select($name."_vals", [ ], $values,
788 $size, 0, 0, $dis, $wstyle)."</td>\n";
789 $rv .= "</tr></table>\n";
790 $rv .= &ui_hidden($name, join("\n", map { $_->[0] } @$values));
794 =head2 ui_multi_select_javascript
796 Returns <script> section for left/right select boxes
799 sub ui_multi_select_javascript
801 return &theme_ui_multiselect_javascript()
802 if (defined(&theme_ui_multiselect_javascript));
805 // Move an element from the options list to the values list, or vice-versa
806 function multi_select_move(name, f, dir)
808 var opts = f.elements[name+"_opts"];
809 var vals = f.elements[name+"_vals"];
810 var opts_idx = opts.selectedIndex;
811 var vals_idx = vals.selectedIndex;
812 if (dir == 1 && opts_idx >= 0) {
813 // Moving from options to selected list
814 var o = opts.options[opts_idx];
815 vals.options[vals.options.length] = new Option(o.text, o.value);
816 opts.remove(opts_idx);
818 else if (dir == 0 && vals_idx >= 0) {
819 // Moving the other way
820 var o = vals.options[vals_idx];
821 opts.options[opts.options.length] = new Option(o.text, o.value);
822 vals.remove(vals_idx);
824 // Fill in hidden field
825 var hid = f.elements[name];
827 var hv = new Array();
828 for(var i=0; i<vals.options.length; i++) {
829 hv.push(vals.options[i].value);
831 hid.value = hv.join("\\n");
838 =head2 ui_radio(name, value, &options, [disabled?])
840 Returns HTML for a series of radio buttons
845 return &theme_ui_radio(@_) if (defined(&theme_ui_radio));
846 my ($name, $value, $opts, $dis) = @_;
849 foreach $o (@$opts) {
850 my $id = "e_escape($name."_".$o->[0]);
851 my $label = $o->[1] || $o->[0];
853 if ($label =~ /^(.*?)((<a\s+href|<input|<select|<textarea)[\000-\377]*)$/i) {
857 $rv .= "<input class='ui_radio' type=radio ".
858 "name=\""."e_escape($name)."\" ".
859 "value=\""."e_escape($o->[0])."\"".
860 ($o->[0] eq $value ? " checked" : "").
861 ($dis ? " disabled=true" : "").
863 " $o->[2]> <label for=\"$id\">".
864 $label."</label>".$after."\n";
869 =head2 ui_yesno_radio(name, value, [yes], [no], [disabled?])
871 Like ui_yesno, but always displays just two inputs (yes and no)
876 my ($name, $value, $yes, $no, $dis) = @_;
877 return &theme_ui_yesno_radio(@_) if (defined(&theme_ui_yesno_radio));
878 $yes = 1 if (!defined($yes));
879 $no = 0 if (!defined($no));
880 $value = int($value);
881 return &ui_radio($name, $value, [ [ $yes, $text{'yes'} ],
882 [ $no, $text{'no'} ] ], $dis);
885 =head2 ui_checkbox(name, value, label, selected?, [tags], [disabled?])
887 Returns HTML for a single checkbox
892 return &theme_ui_checkbox(@_) if (defined(&theme_ui_checkbox));
893 my ($name, $value, $label, $sel, $tags, $dis) = @_;
895 if ($label =~ /^([^<]*)(<[\000-\377]*)$/) {
899 return "<input class='ui_checkbox' type=checkbox ".
900 "name=\""."e_escape($name)."\" ".
901 "value=\""."e_escape($value)."\" ".
902 ($sel ? " checked" : "").($dis ? " disabled=true" : "").
903 " id=\""."e_escape("${name}_${value}")."\"".
905 ($label eq "" ? $after :
906 "<label for=\""."e_escape("${name}_${value}").
907 "\">$label</label>$after")."\n";
910 =head2 ui_oneradio(name, value, label, selected?, [tags], [disabled?])
912 Returns HTML for a single radio button
917 return &theme_ui_oneradio(@_) if (defined(&theme_ui_oneradio));
918 my ($name, $value, $label, $sel, $tags, $dis) = @_;
919 my $id = "e_escape("${name}_${value}");
921 if ($label =~ /^([^<]*)(<[\000-\377]*)$/) {
925 return "<input class='ui_radio' type=radio name=\""."e_escape($name)."\" ".
926 "value=\""."e_escape($value)."\" ".
927 ($sel ? " checked" : "").($dis ? " disabled=true" : "").
929 " $tags> <label for=\"$id\">$label</label>$after\n";
932 =head2 ui_textarea(name, value, rows, cols, [wrap], [disabled?], [tags])
934 Returns HTML for a multi-line text input
939 return &theme_ui_textarea(@_) if (defined(&theme_ui_textarea));
940 my ($name, $value, $rows, $cols, $wrap, $dis, $tags) = @_;
941 $cols = &ui_max_text_width($cols, 1);
942 return "<textarea class='ui_textarea' name=\""."e_escape($name)."\" ".
943 "rows=$rows cols=$cols".($wrap ? " wrap=$wrap" : "").
944 ($dis ? " disabled=true" : "").
945 ($tags ? " $tags" : "").">".
946 &html_escape($value).
950 =head2 ui_user_textbox(name, value, [form], [disabled?], [tags])
952 Returns HTML for a Unix user input
957 return &theme_ui_user_textbox(@_) if (defined(&theme_ui_user_textbox));
958 return &ui_textbox($_[0], $_[1], 13, $_[3], undef, $_[4])." ".
959 &user_chooser_button($_[0], 0, $_[2]);
962 =head2 ui_group_textbox(name, value, [form], [disabled?], [tags])
964 Returns HTML for a Unix group input
969 return &theme_ui_group_textbox(@_) if (defined(&theme_ui_group_textbox));
970 return &ui_textbox($_[0], $_[1], 13, $_[3], undef, $_[4])." ".
971 &group_chooser_button($_[0], 0, $_[2]);
974 =head2 ui_opt_textbox(name, value, size, option1, [option2], [disabled?], [&extra-fields], [max])
976 Returns HTML for a text field that is optional
981 return &theme_ui_opt_textbox(@_) if (defined(&theme_ui_opt_textbox));
982 my ($name, $value, $size, $opt1, $opt2, $dis, $extra, $max) = @_;
983 my $dis1 = &js_disable_inputs([ $name, @$extra ], [ ]);
984 my $dis2 = &js_disable_inputs([ ], [ $name, @$extra ]);
986 $size = &ui_max_text_width($size);
987 $rv .= &ui_radio($name."_def", $value eq '' ? 1 : 0,
988 [ [ 1, $opt1, "onClick='$dis1'" ],
989 [ 0, $opt2 || " ", "onClick='$dis2'" ] ], $dis)."\n";
990 $rv .= "<input class='ui_opt_textbox' name=\""."e_escape($name)."\" ".
991 "size=$size value=\""."e_escape($value)."\" ".
992 ($value eq "" || $dis ? "disabled=true" : "").
993 ($max ? " maxlength=$max" : "").">\n";
997 =head2 ui_submit(label, [name], [disabled?], [tags])
999 Returns HTML for a form submit button
1004 return &theme_ui_submit(@_) if (defined(&theme_ui_submit));
1005 my ($label, $name, $dis, $tags) = @_;
1006 return "<input class='ui_submit' type=submit".
1007 ($name ne '' ? " name=\""."e_escape($name)."\"" : "").
1008 " value=\""."e_escape($label)."\"".
1009 ($dis ? " disabled=true" : "").
1010 ($tags ? " ".$tags : "").">\n";
1014 =head2 ui_reset(label, [disabled?])
1016 Returns HTML for a form reset button
1021 return &theme_ui_reset(@_) if (defined(&theme_ui_reset));
1022 my ($label, $dis) = @_;
1023 return "<input type=reset value=\""."e_escape($label)."\"".
1024 ($dis ? " disabled=true" : "").">\n";
1028 =head2 ui_button(label, [name], [disabled?], [tags])
1030 Returns HTML for a form button
1035 return &theme_ui_button(@_) if (defined(&theme_ui_button));
1036 my ($label, $name, $dis, $tags) = @_;
1037 return "<input type=button".
1038 ($name ne '' ? " name=\""."e_escape($name)."\"" : "").
1039 " value=\""."e_escape($label)."\"".
1040 ($dis ? " disabled=true" : "").
1041 ($tags ? " ".$tags : "").">\n";
1044 =head2 ui_date_input(day, month, year, day-name, month-name, year-name, [disabled?])
1046 Returns HTML for a date-selection field
1051 my ($day, $month, $year, $dayname, $monthname, $yearname, $dis) = @_;
1053 $rv .= "<span class='ui_data'>";
1054 $rv .= &ui_textbox($dayname, $day, 3, $dis);
1056 $rv .= &ui_select($monthname, $month,
1057 [ map { [ $_, $text{"smonth_$_"} ] } (1 .. 12) ],
1060 $rv .= &ui_textbox($yearname, $year, 5, $dis);
1065 sub ui_buttons_start
1067 return &theme_ui_buttons_start(@_) if (defined(&theme_ui_buttons_start));
1068 return "<table width=100% class='ui_buttons_table'>\n";
1073 return &theme_ui_buttons_end(@_) if (defined(&theme_ui_buttons_end));
1074 return "</table>\n";
1077 =head2 ui_buttons_row(script, button-label, description, [hiddens], [after-submit], [before-submit])
1079 MISSING DOCUMENTATION
1084 return &theme_ui_buttons_row(@_) if (defined(&theme_ui_buttons_row));
1085 my ($script, $label, $desc, $hiddens, $after, $before) = @_;
1086 return "<form action=$script class='ui_buttons_form'>\n".
1088 "<tr class='ui_buttons_row'> ".
1089 "<td nowrap width=20% valign=top class=ui_buttons_label>".
1090 ($before ? $before." " : "").
1091 &ui_submit($label).($after ? " ".$after : "")."</td>\n".
1092 "<td valign=top width=80% valign=top class=ui_buttons_value>".
1093 $desc."</td> </tr>\n".
1097 =head2 ui_buttons_hr([title])
1099 MISSING DOCUMENTATION
1105 return &theme_ui_buttons_hr(@_) if (defined(&theme_ui_buttons_hr));
1107 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";
1110 return "<tr class='ui_buttons_hr'> <td colspan=2><hr></td> </tr>\n";
1114 ####################### header and footer functions
1116 =head2 ui_post_header([subtext])
1118 Returns HTML to appear directly after a standard header() call
1123 return &theme_ui_post_header(@_) if (defined(&theme_ui_post_header));
1126 $rv .= "<center class='ui_post_header'><font size=+1>$text</font></center>\n" if (defined($text));
1127 if (!$tconfig{'nohr'} && !$tconfig{'notophr'}) {
1128 $rv .= "<hr id='post_header_hr'>\n";
1133 =head2 ui_pre_footer
1135 Returns HTML to appear directly before a standard footer() call
1140 return &theme_ui_pre_footer(@_) if (defined(&theme_ui_pre_footer));
1142 if (!$tconfig{'nohr'} && !$tconfig{'nobottomhr'}) {
1143 $rv .= "<hr id='pre_footer_hr'>\n";
1148 =head2 ui_print_header(subtext, args...)
1150 Print HTML for a header with the post-header line. The args are the same
1151 as those passed to header()
1156 &load_theme_library();
1157 return &theme_ui_print_header(@_) if (defined(&theme_ui_print_header));
1158 my ($text, @args) = @_;
1160 print &ui_post_header($text);
1163 =head2 ui_print_unbuffered_header(subtext, args...)
1165 Like ui_print_header, but ensures that output for this page is not buffered
1166 or contained in a table.
1169 sub ui_print_unbuffered_header
1171 &load_theme_library();
1172 return &theme_ui_print_unbuffered_header(@_) if (defined(&theme_ui_print_unbuffered_header));
1174 $theme_no_table = 1;
1175 &ui_print_header(@_);
1178 =head2 ui_print_footer(args...)
1180 Print HTML for a footer with the pre-footer line. Args are the same as those
1186 return &theme_ui_print_footer(@_) if (defined(&theme_ui_print_footer));
1188 print &ui_pre_footer();
1192 =head2 ui_config_link(text, &subs)
1194 Returns HTML for a module config link. The first non-null sub will be
1195 replaced with the appropriate URL.
1200 return &theme_ui_config_link(@_) if (defined(&theme_ui_config_link));
1201 my ($text, $subs) = @_;
1202 my @subs = map { $_ || "../config.cgi?$module_name" }
1203 ($subs ? @$subs : ( undef ));
1204 return "<p>".&text($text, @subs)."<p>\n";
1207 =head2 ui_print_endpage(text)
1209 Prints HTML for an error message followed by a page footer with a link to
1210 /, then exits. Good for main page error messages.
1213 sub ui_print_endpage
1215 return &theme_ui_print_endpage(@_) if (defined(&theme_ui_print_endpage));
1217 print $text,"<p class='ui_footer'>\n";
1219 &ui_print_footer("/", $text{'index'});
1223 =head2 ui_subheading(text, ...)
1225 Returns HTML for a section heading
1230 return &theme_ui_subheading(@_) if (defined(&theme_ui_subheading));
1231 return "<h3 class='ui_subheading'>".join("", @_)."</h3>\n";
1234 =head2 ui_links_row(&links)
1236 Returns HTML for a row of links, like select all / invert selection / add..
1241 return &theme_ui_links_row(@_) if (defined(&theme_ui_links_row));
1243 return @$links ? join("\n|\n", @$links)."<br>\n"
1247 ########################### collapsible section / tab functions
1249 =head2 ui_hidden_javascript
1251 Returns <script> and <style> sections for hiding functions and CSS
1254 sub ui_hidden_javascript
1256 return &theme_ui_hidden_javascript(@_)
1257 if (defined(&theme_ui_hidden_javascript));
1259 my $imgdir = "$gconfig{'webprefix'}/images";
1260 my ($jscb, $jstb) = ($cb, $tb);
1266 .opener_shown {display:inline}
1267 .opener_hidden {display:none}
1270 // Open or close a hidden section
1271 function hidden_opener(divid, openerid)
1273 var divobj = document.getElementById(divid);
1274 var openerobj = document.getElementById(openerid);
1275 if (divobj.className == 'opener_shown') {
1276 divobj.className = 'opener_hidden';
1277 openerobj.innerHTML = '<img border=0 src=$imgdir/closed.gif>';
1280 divobj.className = 'opener_shown';
1281 openerobj.innerHTML = '<img border=0 src=$imgdir/open.gif>';
1286 function select_tab(name, tabname, form)
1288 var tabnames = document[name+'_tabnames'];
1289 var tabtitles = document[name+'_tabtitles'];
1290 for(var i=0; i<tabnames.length; i++) {
1291 var tabobj = document.getElementById('tab_'+tabnames[i]);
1292 var divobj = document.getElementById('div_'+tabnames[i]);
1293 var title = tabtitles[i];
1294 if (tabnames[i] == tabname) {
1296 tabobj.innerHTML = '<table cellpadding=0 cellspacing=0><tr>'+
1297 '<td valign=top $jscb>'+
1298 '<img src=$imgdir/lc2.gif alt=""></td>'+
1299 '<td $jscb nowrap>'+
1300 ' <b>'+title+'</b> </td>'+
1301 '<td valign=top $jscb>'+
1302 '<img src=$imgdir/rc2.gif alt=""></td>'+
1304 divobj.className = 'opener_shown';
1308 tabobj.innerHTML = '<table cellpadding=0 cellspacing=0><tr>'+
1309 '<td valign=top $jstb>'+
1310 '<img src=$imgdir/lc1.gif alt=""></td>'+
1311 '<td $jstb nowrap>'+
1312 ' <a href=\\'\\' onClick=\\'return select_tab("'+
1313 name+'", "'+tabnames[i]+'")\\'>'+title+'</a> </td>'+
1314 '<td valign=top $jstb>'+
1315 '<img src=$imgdir/rc1.gif alt=""></td>'+
1317 divobj.className = 'opener_hidden';
1320 if (document.forms[0] && document.forms[0][name]) {
1321 document.forms[0][name].value = tabname;
1329 =head2 ui_hidden_start(title, name, status, thisurl)
1331 Returns HTML for the start of a collapsible hidden section, such as for
1337 return &theme_ui_hidden_start(@_) if (defined(&theme_ui_hidden_start));
1338 my ($title, $name, $status, $url) = @_;
1340 if (!$main::ui_hidden_start_donejs++) {
1341 $rv .= &ui_hidden_javascript();
1343 my $divid = "hiddendiv_$name";
1344 my $openerid = "hiddenopener_$name";
1345 my $defimg = $status ? "open.gif" : "closed.gif";
1346 my $defclass = $status ? 'opener_shown' : 'opener_hidden';
1347 $rv .= "<a href=\"javascript:hidden_opener('$divid', '$openerid')\" id='$openerid'><img border=0 src='$gconfig{'webprefix'}/images/$defimg' alt='*'></a>\n";
1348 $rv .= "<a href=\"javascript:hidden_opener('$divid', '$openerid')\">$title</a><br>\n";
1349 $rv .= "<div class='$defclass' id='$divid'>\n";
1353 =head2 ui_hidden_end(name)
1355 Returns HTML for the end of a hidden section
1360 return &theme_ui_hidden_end(@_) if (defined(&theme_ui_hidden_end));
1365 =head2 ui_hidden_table_row_start(title, name, status, thisurl)
1367 Similar to ui_hidden_start, but for use within a table started with
1371 sub ui_hidden_table_row_start
1373 return &theme_ui_hidden_table_row_start(@_)
1374 if (defined(&theme_ui_hidden_table_row_start));
1375 my ($title, $name, $status, $url) = @_;
1377 if (!$main::ui_hidden_start_donejs++) {
1378 $rv .= &ui_hidden_javascript();
1380 my $divid = "hiddendiv_$name";
1381 my $openerid = "hiddenopener_$name";
1382 my $defimg = $status ? "open.gif" : "closed.gif";
1383 my $defclass = $status ? 'opener_shown' : 'opener_hidden';
1384 $rrv .= "<a href=\"javascript:hidden_opener('$divid', '$openerid')\" id='$openerid'><img border=0 src='$gconfig{'webprefix'}/images/$defimg'></a>\n";
1385 $rrv .= "<a href=\"javascript:hidden_opener('$divid', '$openerid')\">$title</a><br>\n";
1386 $rv .= &ui_table_row(undef, $rrv, $main::ui_table_cols);
1387 $rv .= "</table>\n";
1388 $rv .= "<div class='$defclass' id='$divid'>\n";
1389 $rv .= "<table width=100%>\n";
1393 =head2 ui_hidden_table_row_end(name)
1395 MISSING DOCUMENTATION
1398 sub ui_hidden_table_row_end
1400 return &theme_ui_hidden_table_row_end(@_)
1401 if (defined(&theme_ui_hidden_table_row_end));
1403 return "</table></div><table width=100%>\n";
1406 =head2 ui_hidden_table_start(heading, [tabletags], [cols], name, status, [&default-tds], [rightheading])
1408 A table with a heading and table inside, and which is collapsible
1411 sub ui_hidden_table_start
1413 return &theme_ui_hidden_table_start(@_)
1414 if (defined(&theme_ui_hidden_table_start));
1415 my ($heading, $tabletags, $cols, $name, $status, $tds, $rightheading) = @_;
1417 if (!$main::ui_hidden_start_donejs++) {
1418 $rv .= &ui_hidden_javascript();
1420 my $divid = "hiddendiv_$name";
1421 my $openerid = "hiddenopener_$name";
1422 my $defimg = $status ? "open.gif" : "closed.gif";
1423 my $defclass = $status ? 'opener_shown' : 'opener_hidden';
1424 my $text = defined($tconfig{'cs_text'}) ? $tconfig{'cs_text'} :
1425 defined($gconfig{'cs_text'}) ? $gconfig{'cs_text'} : "000000";
1426 $rv .= "<table class='ui_table' border $tabletags>\n";
1428 if (defined($heading) || defined($rightheading)) {
1429 $rv .= "<tr $tb> <td>";
1430 if (defined($heading)) {
1431 $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>";
1433 if (defined($rightheading)) {
1434 $rv .= "<td align=right>$rightheading</td>";
1437 $rv .= "</td> </tr>\n";
1439 $rv .= "<tr $cb> <td colspan=$colspan><div class='$defclass' id='$divid'><table width=100%>\n";
1440 $main::ui_table_cols = $cols || 4;
1441 $main::ui_table_pos = 0;
1442 $main::ui_table_default_tds = $tds;
1446 =head2 ui_hidden_table_end(name)
1448 Returns HTML for the end of table with hiding, as started by
1449 ui_hidden_table_start
1452 sub ui_hidden_table_end
1455 return &theme_ui_hidden_table_end(@_) if (defined(&theme_ui_hidden_table_end));
1456 return "</table></div></td></tr></table>\n";
1459 =head2 ui_tabs_start(&tabs, name, selected, show-border)
1461 Render a row of tabs from which one can be selected. Each tab is an array
1462 ref containing a name, title and link.
1467 return &theme_ui_tabs_start(@_) if (defined(&theme_ui_tabs_start));
1468 my ($tabs, $name, $sel, $border) = @_;
1470 if (!$main::ui_hidden_start_donejs++) {
1471 $rv .= &ui_hidden_javascript();
1474 # Build list of tab titles and names
1475 my $tabnames = "[".join(",", map { "\"".&html_escape($_->[0])."\"" } @$tabs)."]";
1476 my $tabtitles = "[".join(",", map { "\"".&html_escape($_->[1])."\"" } @$tabs)."]";
1477 $rv .= "<script>\n";
1478 $rv .= "document.${name}_tabnames = $tabnames;\n";
1479 $rv .= "document.${name}_tabtitles = $tabtitles;\n";
1480 $rv .= "</script>\n";
1483 my $imgdir = "$gconfig{'webprefix'}/images";
1484 $rv .= &ui_hidden($name, $sel)."\n";
1485 $rv .= "<table border=0 cellpadding=0 cellspacing=0 class='ui_tabs'>\n";
1486 $rv .= "<tr><td bgcolor=#ffffff colspan=".(scalar(@$tabs)*2+1).">";
1487 if ($ENV{'HTTP_USER_AGENT'} !~ /msie/i) {
1488 # For some reason, the 1-pixel space above the tabs appears huge on IE!
1489 $rv .= "<img src=$imgdir/1x1.gif>";
1491 $rv .= "</td></tr>\n";
1493 $rv .= "<td bgcolor=#ffffff width=1><img src=$imgdir/1x1.gif></td>\n";
1494 foreach my $t (@$tabs) {
1495 if ($t ne $tabs[0]) {
1497 $rv .= "<td width=2 bgcolor=#ffffff class='ui_tab_spacer'>".
1498 "<img src=$imgdir/1x1.gif></td>\n";
1500 my $tabid = "tab_".$t->[0];
1501 $rv .= "<td id=${tabid} class='ui_tab'>";
1502 $rv .= "<table cellpadding=0 cellspacing=0 border=0><tr>";
1503 if ($t->[0] eq $sel) {
1505 $rv .= "<td valign=top $cb class='selectedTabLeft'>".
1506 "<img src=$imgdir/lc2.gif alt=\"\"></td>";
1507 $rv .= "<td $cb nowrap class='selectedTabMiddle'>".
1508 " <b>$t->[1]</b> </td>";
1509 $rv .= "<td valign=top $cb class='selectedTabRight'>".
1510 "<img src=$imgdir/rc2.gif alt=\"\"></td>";
1513 # Other tab (which has a link)
1514 $rv .= "<td valign=top $tb>".
1515 "<img src=$imgdir/lc1.gif alt=\"\"></td>";
1516 $rv .= "<td $tb nowrap>".
1517 " <a href='$t->[2]' ".
1518 "onClick='return select_tab(\"$name\", \"$t->[0]\")'>".
1519 "$t->[1]</a> </td>";
1520 $rv .= "<td valign=top $tb>".
1521 "<img src=$imgdir/rc1.gif ".
1525 $rv .= "</tr></table>";
1528 $rv .= "<td bgcolor=#ffffff width=1><img src=$imgdir/1x1.gif></td>\n";
1529 $rv .= "</table>\n";
1532 # All tabs are within a grey box
1533 $rv .= "<table width=100% cellpadding=0 cellspacing=0 border=0 ".
1534 "class='ui_tabs_box'>\n";
1535 $rv .= "<tr> <td bgcolor=#ffffff rowspan=3 width=1><img src=$imgdir/1x1.gif></td>\n";
1536 $rv .= "<td $cb colspan=3 height=2><img src=$imgdir/1x1.gif></td> </tr>\n";
1537 $rv .= "<tr> <td $cb width=2><img src=$imgdir/1x1.gif></td>\n";
1538 $rv .= "<td valign=top>";
1540 $main::ui_tabs_selected = $sel;
1544 =head2 ui_tabs_end(border)
1546 MISSING DOCUMENTATION
1551 return &theme_ui_tabs_end(@_) if (defined(&theme_ui_tabs_end));
1554 my $imgdir = "$gconfig{'webprefix'}/images";
1557 $rv .= "<td $cb width=2><img src=$imgdir/1x1.gif></td>\n";
1559 $rv .= "<tr> <td $cb colspan=3 height=2><img src=$imgdir/1x1.gif></td> </tr>\n";
1560 $rv .= "</table>\n";
1565 =head2 ui_tabs_start_tab(name, tab)
1567 Must be called before outputting the HTML for the named tab
1570 sub ui_tabs_start_tab
1572 return &theme_ui_tabs_start_tab(@_) if (defined(&theme_ui_tabs_start_tab));
1573 my ($name, $tab) = @_;
1574 my $defclass = $tab eq $main::ui_tabs_selected ?
1575 'opener_shown' : 'opener_hidden';
1576 my $rv = "<div id='div_$tab' class='$defclass ui_tabs_start'>\n";
1580 =head2 ui_tabs_start_tabletab(name, tab)
1582 Behaves like ui_tabs_start_tab, but for use within a ui_table_start block
1585 sub ui_tabs_start_tabletab
1587 return &theme_ui_tabs_start_tabletab(@_)
1588 if (defined(&theme_ui_tabs_start_tabletab));
1589 my $div = &ui_tabs_start_tab(@_);
1590 return "</table>\n".$div."<table width=100%>\n";
1595 return &theme_ui_tabs_end_tab(@_) if (defined(&theme_ui_tabs_end_tab));
1599 sub ui_tabs_end_tabletab
1601 return &theme_ui_tabs_end_tabletab(@_)
1602 if (defined(&theme_ui_tabs_end_tabletab));
1603 return "</table></div><table width=100%>\n";
1606 =head2 ui_max_text_width(width, [text-area?])
1608 Returns a new width for a text field, based on theme settings
1611 sub ui_max_text_width
1614 my $max = $ta ? $tconfig{'maxareawidth'} : $tconfig{'maxboxwidth'};
1615 return $max && $w > $max ? $max : $w;
1618 ####################### radio hidden functions
1620 =head2 ui_radio_selector(&opts, name, selected)
1622 Returns HTML for a set of radio buttons, each of which shows a different
1623 block of HTML when selected. &opts is an array ref to arrays containing
1624 [ value, label, html ]
1627 sub ui_radio_selector
1629 return &theme_ui_radio_selector(@_) if (defined(&theme_ui_radio_selector));
1630 my ($opts, $name, $sel) = @_;
1632 if (!$main::ui_radio_selector_donejs++) {
1633 $rv .= &ui_radio_selector_javascript();
1636 "[".join(",", map { "\"".&html_escape($_->[0])."\"" } @$opts)."]";
1637 foreach my $o (@$opts) {
1638 $rv .= &ui_oneradio($name, $o->[0], $o->[1], $sel eq $o->[0],
1639 "onClick='selector_show(\"$name\", \"$o->[0]\", $optnames)'");
1642 foreach my $o (@$opts) {
1643 my $cls = $o->[0] eq $sel ? "selector_shown" : "selector_hidden";
1644 $rv .= "<div id=sel_${name}_$o->[0] class=$cls>".$o->[2]."</div>\n";
1649 sub ui_radio_selector_javascript
1653 .selector_shown {display:inline}
1654 .selector_hidden {display:none}
1657 function selector_show(name, value, values)
1659 for(var i=0; i<values.length; i++) {
1660 var divobj = document.getElementById('sel_'+name+'_'+values[i]);
1661 divobj.className = value == values[i] ? 'selector_shown'
1662 : 'selector_hidden';
1669 ####################### grid layout functions
1671 =head2 ui_grid_table(&elements, columns, [width-percent], [tds], [tabletags], [title])
1673 Given a list of HTML elements, formats them into a table with the given
1674 number of columns. However, themes are free to override this to use fewer
1675 columns where space is limited.
1680 return &theme_ui_grid_table(@_) if (defined(&theme_ui_grid_table));
1681 my ($elements, $cols, $width, $tds, $tabletags, $title) = @_;
1682 return "" if (!@$elements);
1683 my $rv = "<table class='ui_grid_table'".
1684 ($width ? " width=$width%" : "").
1685 ($tabletags ? " ".$tabletags : "").
1688 for($i=0; $i<@$elements; $i++) {
1689 $rv .= "<tr class='ui_grid_row'>" if ($i%$cols == 0);
1690 $rv .= "<td ".$tds->[$i%$cols]." valign=top class='ui_grid_cell'>".
1691 $elements->[$i]."</td>\n";
1692 $rv .= "</tr>" if ($i%$cols == $cols-1);
1696 $rv .= "<td ".$tds->[$i%$cols]." class='ui_grid_cell'>".
1702 $rv .= "</table>\n";
1703 if (defined($title)) {
1704 $rv = "<table class=ui_table border ".
1705 ($width ? " width=$width%" : "").">\n".
1706 ($title ? "<tr $tb> <td><b>$title</b></td> </tr>\n" : "").
1707 "<tr $cb> <td>$rv</td> </tr>\n".
1713 =head2 ui_radio_table(name, selected, &rows)
1715 Returns HTML for a table of radio buttons, each of which has a label and
1716 some associated inputs to the right.
1721 return &theme_ui_radio_table(@_) if (defined(&theme_ui_radio_table));
1722 my ($name, $sel, $rows) = @_;
1723 return "" if (!@$rows);
1724 my $rv = "<table class='ui_radio_table'>\n";
1725 foreach my $r (@$rows) {
1727 $rv .= "<td valign=top".(defined($r->[2]) ? "" : " colspan=2").
1729 &ui_oneradio($name, $r->[0], $r->[1], $r->[0] eq $sel).
1731 if (defined($r->[2])) {
1732 $rv .= "<td valign=top>".$r->[2]."</td>\n";
1736 $rv .= "</table>\n";
1740 =head2 ui_up_down_arrows(uplink, downlink, up-show, down-show)
1742 Returns HTML for moving some objects in a table up or down
1745 sub ui_up_down_arrows
1747 return &theme_ui_up_down_arrows(@_) if (defined(&theme_ui_up_down_arrows));
1748 my ($uplink, $downlink, $upshow, $downshow) = @_;
1750 my $imgdir = "$gconfig{'webprefix'}/images";
1752 $mover .= "<a href=\"$downlink\">".
1753 "<img src=$imgdir/movedown.gif border=0></a>";
1756 $mover .= "<img src=$imgdir/movegap.gif>";
1759 $mover .= "<a href=\"$uplink\">".
1760 "<img src=$imgdir/moveup.gif border=0></a>";
1763 $mover .= "<img src=$imgdir/movegap.gif>";
1770 Returns a horizontal row tag
1775 return &theme_ui_hr() if (defined(&theme_ui_hr));
1779 =head2 ui_nav_link(direction, url, disabled)
1781 Returns an arrow icon linking to provided url
1786 return &theme_ui_nav_link(@_) if (defined(&theme_ui_nav_link));
1787 my ($direction, $url, $disabled) = @_;
1788 my $alt = $direction eq "left" ? '<-' : '->';
1790 return "<img alt=\"$alt\" align=\"middle\""
1791 . "src=\"$gconfig{'webprefix'}/images/$direction-grey.gif\">\n";
1794 return "<a href=\"$url\"><img alt=\"$alt\" align=\"middle\""
1795 . "src=\"$gconfig{'webprefix'}/images/$direction.gif\"></a>\n";
1799 =head2 ui_confirmation_form(cgi, message, &hiddens, [&buttons], [&otherinputs], [extra-warning])
1801 Returns HTML for a form asking for confirmation before performing some
1802 action, such as deleting a user.
1805 sub ui_confirmation_form
1807 my ($cgi, $message, $hiddens, $buttons, $others, $warning) = @_;
1809 $rv .= "<center class=ui_confirmation>\n";
1810 $rv .= &ui_form_start($cgi, "post");
1811 foreach my $h (@$hiddens) {
1812 $rv .= &ui_hidden(@$h);
1814 $rv .= "<b>$message</b><p>\n";
1816 $rv .= "<b><font color=#ff0000>$warning</font></b><p>\n";
1819 $rv .= $others."<p>\n";
1821 $rv .= &ui_form_end($buttons);
1822 $rv .= "</center>\n";
1826 ####################### javascript functions
1828 =head2 js_disable_inputs
1830 js_disable_input(&disable-inputs, &enable-inputs, [tag])
1831 Returns Javascript to disable some form elements and enable others
1834 sub js_disable_inputs
1838 foreach $f (@{$_[0]}) {
1839 $rv .= "e = form.elements[\"$f\"]; e.disabled = true; ";
1840 $rv .= "for(i=0; i<e.length; i++) { e[i].disabled = true; } ";
1842 foreach $f (@{$_[1]}) {
1843 $rv .= "e = form.elements[\"$f\"]; e.disabled = false; ";
1844 $rv .= "for(i=0; i<e.length; i++) { e[i].disabled = false; } ";
1846 foreach $f (@{$_[1]}) {
1847 if ($f =~ /^(.*)_def$/ && &indexof($1, @{$_[1]}) >= 0) {
1848 # When enabling both a _def field and its associated text field,
1849 # disable the text if the _def is set to 1
1851 $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 } } ";
1854 return $_[2] ? "$_[2]='$rv'" : $rv;
1857 =head2 ui_page_flipper(message, [inputs, cgi], left-link, right-link, [far-left-link], [far-right-link], [below])
1859 Returns HTML for moving left and right in some large list, such as an inbox
1860 or database table. If only 5 parameters are given, no far links are included.
1861 If any link is undef, that array will be greyed out.
1866 return &theme_ui_page_flipper(@_) if (defined(&theme_ui_page_flipper));
1867 my ($msg, $inputs, $cgi, $left, $right, $farleft, $farright, $below) = @_;
1868 my $rv = "<center>";
1869 $rv .= &ui_form_start($cgi) if ($cgi);
1871 # Far left link, if needed
1874 $rv .= "<a href='$farleft'><img src=/images/first.gif ".
1875 "border=0 align=middle></a>\n";
1878 $rv .= "<img src=/images/first-grey.gif ".
1879 "border=0 align=middle></a>\n";
1885 $rv .= "<a href='$left'><img src=/images/left.gif ".
1886 "border=0 align=middle></a>\n";
1889 $rv .= "<img src=/images/left-grey.gif ".
1890 "border=0 align=middle></a>\n";
1893 # Message and inputs
1895 $rv .= " ".$inputs if ($inputs);
1899 $rv .= "<a href='$right'><img src=/images/right.gif ".
1900 "border=0 align=middle></a>\n";
1903 $rv .= "<img src=/images/right-grey.gif ".
1904 "border=0 align=middle></a>\n";
1907 # Far right link, if needed
1910 $rv .= "<a href='$farright'><img src=/images/last.gif ".
1911 "border=0 align=middle></a>\n";
1914 $rv .= "<img src=/images/last-grey.gif ".
1915 "border=0 align=middle></a>\n";
1919 $rv .= "<br>".$below if ($below);
1920 $rv .= &ui_form_end() if ($cgi);
1921 $rv .= "</center>\n";
1925 =head2 js_checkbox_disable(name, &checked-disable, &checked-enable, [tag])
1927 MISSING DOCUMENTATION
1930 sub js_checkbox_disable
1934 foreach $f (@{$_[1]}) {
1935 $rv .= "form.elements[\"$f\"].disabled = $_[0].checked; ";
1937 foreach $f (@{$_[2]}) {
1938 $rv .= "form.elements[\"$f\"].disabled = !$_[0].checked; ";
1940 return $_[3] ? "$_[3]='$rv'" : $rv;
1943 =head2 js_redirect(url, [window-object])
1945 Returns HTML to trigger a redirect to some URL
1950 my ($url, $window) = @_;
1951 if (defined(&theme_js_redirect)) {
1952 return &theme_js_redirect(@_);
1954 return "<script>${window}.location = '"."e_escape($url)."';</script>\n";