Handle hostnames with upper-case letters
[webmin.git] / Webmin / Tabs.pm
1 package Webmin::Tabs;
2 use WebminCore;
3
4 =head2 new Webmin::Tabs([&tabs])
5 Displayed at the top of a page, to allow selection of various pages
6 =cut
7 sub new
8 {
9 my ($self, $tabs) = @_;
10 if (defined(&Webmin::Theme::Tabs::new)) {
11         return new Webmin::Theme::Tabs(@_[1..$#_]);
12         }
13 $self = { 'tabs' => [ ],
14           'tab' => 0 };
15 bless($self);
16 $self->set_tabs($tabs) if (defined($tabs));
17 return $self;
18 }
19
20 =head2 add_tab(name, link)
21 =cut
22 sub add_tab
23 {
24 my ($self, $name, $link) = @_;
25 push(@{$self->{'tabs'}}, [ $name, $link ]);
26 }
27
28 =head2 html()
29 Returns the HTML for the top of the page
30 =cut
31 sub top_html
32 {
33 my ($self) = @_;
34 my $rv;
35 $rv .= "<table border=0 cellpadding=0 cellspacing=0 width=100% height=20><tr>";
36 $rv .= "<td valign=bottom>";
37 $rv .= "<table border=0 cellpadding=0 cellspacing=0 height=20><tr>";
38 my $i = 0;
39 my ($high, $low) = ("#cccccc", "#9999ff");
40 my ($lowlc, $lowrc) = ( "/images/lc1.gif", "/images/rc1.gif" );
41 my ($highlc, $highrc) = ( "/images/lc2.gif", "/images/rc2.gif" );
42 foreach my $t (@{$self->get_tabs()}) {
43         if ($i == $self->get_tab()) {
44                 # This is the selected tab
45                 $rv .= "<td valign=top bgcolor=$high>".
46                        "<img src=$highlc alt=\"\"></td>";
47                 if ($self->get_link()) {
48                         # Link
49                         $rv .= "<td bgcolor=$high>&nbsp;".
50                                "<a href=$t->[1]><b>$t->[0]</b></a>&nbsp;</td>";
51                         }
52                 else {
53                         # Don't link
54                         $rv .= "<td bgcolor=$high>&nbsp;<b>$t->[0]</b>&nbsp;</td>";
55                         }
56                 $rv .= "<td valign=top bgcolor=$high>".
57                        "<img src=$highrc alt=\"\"></td>\n";
58                 }
59         else {
60                 # Not selected
61                 $rv .= "<td valign=top bgcolor=$low>".
62                        "<img src=$lowlc alt=\"\"></td>";
63                 $rv .= "<td bgcolor=$low>&nbsp;".
64                        "<a href=$t->[1]><b>$t->[0]</b></a>&nbsp;</td>";
65                 $rv .= "<td valign=top bgcolor=$low>".
66                        "<img src=$lowrc alt=\"\"></td>\n";
67                 }
68         $i++;
69         if ($self->{'wrap'} && $i%$self->{'wrap'} == 0) {
70                 # New row
71                 $rv .= "</tr><tr>";
72                 }
73         }
74 $rv .= "</tr></table></td>\n";
75 $rv .= "</tr></table>\n";
76 $rv .= "<table border=1 cellpadding=10 cellspacing=0 width=100%><tr><td>\n";
77 return $rv;
78 }
79
80 =head2 bottom_html()
81 Returns the HTML for the bottom of the page
82 =cut
83 sub bottom_html
84 {
85 my ($self) = @_;
86 my $rv = "</td></tr></table>\n";
87 return $rv;
88 }
89
90 =head2 set_tab(number|link)
91 Sets the tab that is currently highlighted
92 =cut
93 sub set_tab
94 {
95 my ($self, $tab) = @_;
96 if ($tab =~ /^\d+$/) {
97         $self->{'tab'} = $tab;
98         }
99 else {
100         for(my $i=0; $i<@{$self->{'tabs'}}; $i++) {
101                 if ($self->{'tabs'}->[$i]->[1] eq $tab) {
102                         $self->{'tab'} = $i;
103                         }
104                 }
105         }
106 }
107
108 sub get_tab
109 {
110 my ($self) = @_;
111 return $self->{'tab'};
112 }
113
114 =head2 set_link(link)
115 If called with a non-zero parameter, even the highlighted tab will be a link
116 =cut
117 sub set_link
118 {
119 my ($self, $link) = @_;
120 $self->{'link'} = $link;
121 }
122
123 sub get_link
124 {
125 my ($self) = @_;
126 return $self->{'link'};
127 }
128
129 sub set_tabs
130 {
131 my ($self, $tabs) = @_;
132 $self->{'tabs'} = $tabs;
133 }
134
135 sub get_tabs
136 {
137 my ($self) = @_;
138 return $self->{'tabs'};
139 }
140
141 1;
142