Codice PHP:
## change to the previous month
if ($command == "prev_month")
{
if (--$month == 0)
{
$month = 12;
$year--;
}
}
## change to the next month
else if ($command == "next_month")
{
if (++$month == 13)
{
$month = 1;
$year++;
}
}
## if no month has been passed
if ($month == "")
{
$year= date("Y");
$month= date("n");
$month_name = date("F",mktime(0,0,0,$month,1,$year));
}
## use current date if no month is passed
else
{
$year= date("Y",mktime(0,0,0,$month,1,$year));
$month= date("n",mktime(0,0,0,$month,1,$year));
$month_name = date("F",mktime(0,0,0,$month,1,$year));
}
$giorni = date("t",mktime(0, 0, 0, $month, 1, $year)); //giorni del mese in questione
//echo$giorni;
$array=array('Dom','Lun','Mar','Mer','Gio','Ven','Sab','Dom','Lun','Mar','Mer','Gio','Ven','Sab','Dom','Lun','Mar','Mer','Gio','Ven','Sab','Dom','Lun','Mar','Mer','Gio','Ven','Sab','Dom','Lun','Mar','Mer','Gio','Ven','Sab');
$dow = date("w",mktime(0,0,0,$month,1,$year)); //which day 1 falls on in the week
("0" == Sun);
$dim = date("d",mktime (0,0,0,$month+1,0,$year)); //days in the current month
## modification to only print the number of weeks in a month
$wim = ceil(($dim+$dow)/7); //weeks in month
$ct=0;
echo "
<table border='0' cellpadding='1' cellspacing='1' width='425' align='center'>
<tr>
<td align='center'><h1>[url='index.php?command=prev_month&month=$month&year=$year']<<[/url] $month_name $year [url='index.php?command=next_month&month=$month&year=$year']>>[/url]</h1></td>
</tr>
</table>
<table border='1' cellpadding='1' cellspacing='1' width='425' align='center'>
<tr> ";
$s=7-$wim;
for($r=$s;$r<$giorni+$s;$r++)
{
echo" <td align='center'>[b]$array[$r][/b]</td>";
}
echo"</tr> ";
## print only the number of weeks needed
for($row=1;$row<2;$row++)
{
echo ".<tr height='60'>";
## prints week (Sun to Sat)
for($week=1;$week<31+$wim;$week++)
{
$ct++;
$value=mktime(0,0,0,$month,$ct,$year);
## if $value is part of current month
if (date("m",$value)==$month)
{
echo "
<td align='center' class='body' width='85' valign='top'>
<div align='center'>[b]".date("j",$value)."</a>[/b]</div>
<div align='center'><input name=\"$value\" type=\"text\" size=\"3\"></div>
</td>";
}
## print previous and next month dates, but grayed out
else
{
// echo "<td align='center' class='body' width='85' valign='top'
//bgcolor='#CCCCCC'><div
//align='right'>[b]".date("j",$value)."</a>[/b]</div>
</td>";
}
}
echo "</tr>";
}
echo "</table>";