Handle hostnames with upper-case letters
[webmin.git] / date_chooser.cgi
1 #!/usr/local/bin/perl
2 # date_chooser.cgi
3 # Display a table of days in the current month
4
5 BEGIN { push(@INC, ".."); };
6 use WebminCore;
7 use Time::Local;
8
9 $trust_unknown_referers = 1;
10 &init_config();
11 &ReadParse();
12
13 @daysin = ( 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
14 $daysin[1] = $in{'year'}%400 == 0 ? 29 :
15              $in{'year'}%100 == 0 ? 28 :
16              $in{'year'}%4 == 0 ? 29 : 28;
17
18 @tm = localtime(time());
19 if ($in{'day'} !~ /^\d+$/ || $in{'day'} < 1 || $in{'year'} !~ /^\d+$/) {
20         $in{'day'} = $tm[3];
21         $in{'month'} = $tm[4];
22         $in{'year'} = $tm[5]+1900;
23         }
24 if ($in{'day'} > $daysin[$in{'month'}]) {
25         $in{'day'} = $daysin[$in{'month'}];
26         }
27 $tm = timelocal(0, 0, 12, $in{'day'}, $in{'month'}, $in{'year'});
28
29 &popup_header($text{'chooser_date'});
30 $uday = &urlize($in{'day'});
31 $umonth = &urlize($in{'month'});
32 $uyear = &urlize($in{'year'});
33 print <<EOF;
34 <script>
35 function newmonth(m)
36 {
37 location = "date_chooser.cgi?day=$uday&month="+m.selectedIndex+"&year=$uyear";
38 }
39 function newyear(y)
40 {
41 location = "date_chooser.cgi?day=$uday&month=$umonth&year="+(y.selectedIndex+$in{'year'}-10);
42 }
43 function newday(d)
44 {
45 opener.dfield.value = d;
46 opener.mfield.selectedIndex = $umonth;
47 opener.yfield.value = $uyear;
48 close();
49 }
50 </script>
51 <form><table border width=100%>
52 <tr> <td colspan=7 align=center><select name=year onChange='newyear(this)'>
53 EOF
54 for($i=$in{'year'}-10; $i<=$in{'year'}+10; $i++) {
55         printf "<option %s>%s\n",
56                 $i == $in{'year'} ? 'selected' : '', $i;
57         }
58 print "</select> <select name=month onChange='newmonth(this)'>\n";
59 for($i=0; $i<12; $i++) {
60         printf "<option value=%s %s>%s\n",
61                 $i, $i == $in{'month'} ? 'selected' : '',
62                 $text{"month_".($i+1)};
63         }
64 print "</select></td> </tr>\n";
65
66 print "<tr>\n";
67 for($i=0; $i<7; $i++) {
68         print "<td><b>",$text{"sday_$i"},"</b></td>\n";
69         }
70 print "</tr>\n";
71
72 @first = localtime($tm - ($in{'day'}-1)*24*60*60);
73 $count = -$first[6] + 1;
74 for($y=0; $y<6; $y++) {
75         print "<tr>\n";
76         for($x=0; $x<7; $x++) {
77                 if ($count < 1 || $count > $daysin[$in{'month'}]) {
78                         print "<td align=center></td>\n";
79                         }
80                 else {
81                         printf "<td align=center %s><a href='' onClick='newday($count)'>%s</a></td>\n", $in{'day'} == $count ? $cb : '', $count;
82                         }
83                 $count++;
84                 }
85         print "</tr>\n";
86         }
87 print "</table></form>\n";
88 &popup_footer();
89