<?php
/*from http://www.zhuoda.org/meiking/10783.html */
$year = $_GET[y];
$month = $_GET[m];
if($month == null) $month = date("m");
if($day == null) $day = date("d");
if($year == null) $year = date("Y");
$weekOneDay = date("w",mktime(0,0,0,$month,1,$year)); //算出本月份第一天是周几??
$dayNum = date("t",mktime(0,0,0,$month,1,$year)); //取得本月的天数
$weekNum = ceil(($dayNum+$weekOneDay+1)/7); //算出本月份的周数!!
$fileName = "calendarphp.php";
$nextYear = ($year+1);
$prevYear = ($year-1);
if(substr($month,0,1) == 0)
$month = substr($month,1,1);
if(($month+1) > 12) {
$nextMonth = 1;
$nextLinkYear = ($year+1);
}else{
$nextMonth = ($month+1);
$nextLinkYear = $year;
}
if(($month-1) < 1) {
$prevMonth = 12;
$prevLinkYear = ($year-1);
}else{
$prevMonth = ($month-1);
$prevLinkYear = $year;
}
$nextYearUrl = $fileName."?y=".$nextYear."&m=".$month;
$prevYearUrl = $fileName."?y=".$prevYear."&m=".$month;
$nextMonthUrl = $fileName."?y=".$nextLinkYear."&m=".$nextMonth;
$prevMonthUrl = $fileName."?y=".$prevLinkYear."&m=".$prevMonth;
?>
<table width="152" border="0" cellpadding="1" cellspacing="1" bgcolor="#006699">
<Tr>
<Td colspan=7 align="center">
<a href="<?php echo $prevYearUrl;?>"><<</a>年份 <a href="<?php echo $nextYearUrl; ?>">>></a></td>
</tr>
<tr align="center" valign="middle" bgcolor="#FFFFFF">
<td colspan="7"><?php echo $year."年-".$month."月"; ?></td>
</tr>
<tr align="center" valign="middle" bgcolor="#FFFFFF">
<td>日</td>
<td>一</td>
<td>二</td>
<td>三</td>
<td>四</td>
<td>五</td>
<td>六</td>
</tr>
<?php
$d = 1;
for($i = 1;$i <= $weekNum*7;$i+=7){
?>
<tr align="center" valign="middle" bgcolor="#FFFFFF">
<?php for($j = $i;$j < $i+7;$j++) { ?>
<?php
if($j >= $weekOneDay+1 && $d <= $dayNum){
if(strlen($d) == 1)
$nowDay = "0".$d;
else
$nowDay = $d;
if($year == date("Y") && $month == date("m") && $nowDay == $day) {
echo "<td bgcolor=#CCCCCC>";
}else{
echo "<td bgcolor=#ffffff>";
}
echo $d;
$d++;
}else{
echo "<td bgcolor=#ffffff> ";
}
?></td>
<?php } ?>
</tr>
<?php
}
?>
</td>
</tr>
<Tr>
<td colspan="7" align="Center"><a href="<?php echo $prevMonthUrl; ?>"><</a> 月份 <a href="<?php echo $nextMonthUrl; ?>">></a></td>
</tr>
</table>