#! /usr/bin/perl -w
# **** calander_calc1.pl ******
# **** program to give calander and to return date picked *****
# **** Generic cgi date picker by Jim Massey 8/2000 **************

use CGI qw/:all/;
use Date::Calc qw(:all);
print "days in month: $days \n";
$j = 1;

$today = localtime(time);
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
$year = (1900 + $year);
$year_this = $year;
$month_this = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec) [$mon];
$month = ($mon + 1);

$query_params = new CGI;
if ($query_params->param('month')) { $month = $query_params->param('month') }
if ($query_params->param('year')) { $year = $query_params->param('year') }
$days = Days_in_Month($year, $month);

# ****** Web Interface ******
print header, start_html("Date::Calc Calander");
print $query_params->Dump;
print system("date");
$this_month = Month_to_Text($month);
  $day_name = Day_of_Week_to_Text($wday);
print ("<table border=5 bgcolor=white col=7 align=left>
        <tr>
          <th colspan=7 align=center bgcolor=white ><a href=".">
             today is $day_name - $month_this / $mday / $year_this</a></th></tr>
        <tr>
         <th colspan=7 align=center bgcolor=yellow>
            CALANDER $this_month $year </th>
        </tr><tr bgcolor=aqua>
         <th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th>
         <th>Thr</th><th>Fri</th><th>Sat</th>
        </tr><tr>");

for ($i = 1 ; $i <= $days; $i++) {
    $weekday = Day_of_Week($year,$month,$i);
   if ($weekday ne 7){
    if ($weekday >= 1 and $i eq 1) {
	for ($j = 1; $j lt $weekday + 1; $j++) {
	    print ("<td> &nbsp </td>");
	}
     }
   }
    print ("<form method=post><td align=center>
             <input type=hidden name=year value=$year>
             <input type=hidden name=month value=$month>
             <input type=hidden name=day value=$i>
             <input type=submit value=$i>
             </td></form> ");
    if ($weekday eq '6') {
	print ("</tr><tr>");
    }
}
print ("</table>");

print ("<form method=post>
        <table border align=center bgcolor=white>
         <tr><th align=center colspan=2>Select Calander</th></tr>
         <tr>
           <td align=center>Month</td><td align=center>Year</td></tr>
          <tr>
            <td><select name=month size=1>");
for ($i = 1; $i < 13; $i++) {
    print ("<option>$i");
}
print ("</select></td><td><select name=year size=1>
         <option>2000<option>2001<option>2002<option>2003<option>2004
        </select></td>
        </tr>
        <tr><td colspan=2 align=center>
             <input type=submit value='Get Calander'></td></tr>
        </table></form>");
                  
print end_html;







