Handle hostnames with upper-case letters
[webmin.git] / bacula-backup / schedule_chooser.cgi
1 #!/usr/local/bin/perl
2 # Show a popup window for selecting a Bacula schedule
3
4 $trust_unknown_referers = 1;
5 require './bacula-backup-lib.pl';
6 &ReadParse();
7 &popup_header($text{'chooser_title'});
8
9 # Parse into month, day and hour parts
10 if ($in{'schedule'}) {
11         $sched = &parse_schedule($in{'schedule'});
12         }
13 else {
14         $sched = { 'months_all' => 1,
15                    'weekdays_all' => 1,
16                    'weekdaynums_all' => 1,
17                    'days_all' => 1,
18                    'hour' => '00',
19                    'minute' => '00',
20                  };
21         }
22 ref($sched) || &error($sched);
23 print &ui_form_start("schedule_select.cgi", "post");
24 @tds = ( "width=30%", "width=70%" );
25
26 # Show months section
27 @months = map { [ $_-1, $text{'month_'.$_} ] } (1 .. 12);
28 print &ui_table_start($text{'chooser_monthsh'}, "width=100%", 2);
29 print &ui_table_row($text{'chooser_months'},
30         &ui_radio("months_all", $sched->{'months_all'} ? 1 : 0,
31                   [ [ 1, $text{'chooser_all'} ],
32                     [ 0, $text{'chooser_sel'} ] ])."<br>".
33         &select_chooser("months", \@months, $sched->{'months'}),
34         1, \@tds);
35 print &ui_table_end();
36
37 # Show days of month section
38 @days = map { [ $_, $_ ] } (1 .. 31);
39 print &ui_table_start($text{'chooser_daysh'}, "width=100%", 2);
40 print &ui_table_row($text{'chooser_days'},
41         &ui_radio("days_all", $sched->{'days_all'} ? 1 : 0,
42                   [ [ 1, $text{'chooser_all'} ],
43                     [ 0, $text{'chooser_sel'} ] ])."<br>".
44         &select_chooser("days", \@days, $sched->{'days'}, 8),
45         1, \@tds);
46 print &ui_table_end();
47
48 # Show days of week section
49 @weekdays = map { [ $_, $text{'day_'.$_} ] } (0 .. 6);
50 @weekdaynums = map { [ $_, $text{'weekdaynum_'.$_} ] } (1 .. 5);
51 print &ui_table_start($text{'chooser_weekdaysh'}, "width=100%", 2);
52 print &ui_table_row($text{'chooser_weekdays'},
53         &ui_radio("weekdays_all", $sched->{'weekdays_all'} ? 1 : 0,
54                   [ [ 1, $text{'chooser_all'} ],
55                     [ 0, $text{'chooser_sel'} ] ])."<br>".
56         &select_chooser("weekdays", \@weekdays, $sched->{'weekdays'}),
57         1, \@tds);
58 print &ui_table_row($text{'chooser_weekdaynums'},
59         &ui_radio("weekdaynums_all", $sched->{'weekdaynums_all'} ? 1 : 0,
60                   [ [ 1, $text{'chooser_all'} ],
61                     [ 0, $text{'chooser_sel'} ] ])."<br>".
62         &select_chooser("weekdaynums", \@weekdaynums,$sched->{'weekdaynums'},5),
63         1, \@tds);
64 print &ui_table_end();
65
66 # Show time section
67 print &ui_table_start($text{'chooser_timeh'}, "width=100%", 2);
68 print &ui_table_row($text{'chooser_time'},
69                     &ui_textbox("hour", $sched->{'hour'}, 3).":".
70                     &ui_textbox("minute", $sched->{'minute'}, 3),
71                     1, \@tds);
72 print &ui_table_end();
73
74 print &ui_form_end([ [ "ok", $text{'chooser_ok'} ] ]);
75
76 &popup_footer();
77
78 # select_chooser(name, &opts, &selected, [cols])
79 sub select_chooser
80 {
81 local ($name, $opts, $sel, $cols) = @_;
82 $cols ||= 4;
83 local %sel = map { $_, 1 } @$sel;
84 local $rv = "<table>\n";
85 for(my $i=0; $i<@$opts; $i++) {
86         $rv .= "<tr>\n" if ($i%$cols == 0);
87         $rv .= "<td>".&ui_checkbox($name, $opts->[$i]->[0], $opts->[$i]->[1],
88                                   $sel{$opts->[$i]->[0]})."</td>\n";
89         $rv .= "</tr>\n" if ($i%$cols == $cols-1);
90         }
91 $rv .= "</table>\n";
92 return $rv;
93 }