Initial checkin of Webmin
[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 require './web-lib.pl';
6 require 'timelocal.pl';
7 &init_config();
8 &ReadParse();
9
10 @daysin = ( 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
11 $daysin[1] = $in{'year'}%400 == 0 ? 29 :
12              $in{'year'}%100 == 0 ? 28 :
13              $in{'year'}%4 == 0 ? 29 : 28;
14
15 @tm = localtime(time());
16 if ($in{'day'} !~ /^\d+$/ || $in{'day'} < 1 || $in{'year'} !~ /^\d+$/) {
17         $in{'day'} = $tm[3];
18         $in{'month'} = $tm[4];
19         $in{'year'} = $tm[5]+1900;
20         }
21 if ($in{'day'} > $daysin[$in{'month'}]) {
22         $in{'day'} = $daysin[$in{'month'}];
23         }
24 $tm = timelocal(0, 0, 12, $in{'day'}, $in{'month'}, $in{'year'});
25
26 &popup_header($text{'chooser_date'});
27 print <<EOF;
28 <script>
29 function newmonth(m)
30 {
31 location = "date_chooser.cgi?day=$in{'day'}&month="+m.selectedIndex+"&year=$in{'year'}";
32 }
33 function newyear(y)
34 {
35 location = "date_chooser.cgi?day=$in{'day'}&month=$in{'month'}&year="+(y.selectedIndex+$in{'year'}-10);
36 }
37 function newday(d)
38 {
39 opener.dfield.value = d;
40 opener.mfield.selectedIndex = $in{'month'};
41 opener.yfield.value = $in{'year'};
42 close();
43 }
44 </script>
45 <form><table border width=100%>
46 <tr> <td colspan=7 align=center><select name=year onChange='newyear(this)'>
47 EOF
48 for($i=$in{'year'}-10; $i<=$in{'year'}+10; $i++) {
49         printf "<option %s>%s\n",
50                 $i == $in{'year'} ? 'selected' : '', $i;
51         }
52 print "</select> <select name=month onChange='newmonth(this)'>\n";
53 for($i=0; $i<12; $i++) {
54         printf "<option value=%s %s>%s\n",
55                 $i, $i == $in{'month'} ? 'selected' : '',
56                 $text{"month_".($i+1)};
57         }
58 print "</select></td> </tr>\n";
59
60 print "<tr>\n";
61 for($i=0; $i<7; $i++) {
62         print "<td><b>",$text{"sday_$i"},"</b></td>\n";
63         }
64 print "</tr>\n";
65
66 @first = localtime($tm - ($in{'day'}-1)*24*60*60);
67 $count = -$first[6] + 1;
68 for($y=0; $y<6; $y++) {
69         print "<tr>\n";
70         for($x=0; $x<7; $x++) {
71                 if ($count < 1 || $count > $daysin[$in{'month'}]) {
72                         print "<td align=center></td>\n";
73                         }
74                 else {
75                         printf "<td align=center %s><a href='' onClick='newday($count)'>%s</a></td>\n", $in{'day'} == $count ? $cb : '', $count;
76                         }
77                 $count++;
78                 }
79         print "</tr>\n";
80         }
81 print "</table></form>\n";
82 &popup_footer();
83