其实这篇文章也不能算作是原创,只是在原作者的基础上修改的比较多,几乎重写了一遍。
<?php
/**
*在原作者的基础上修改的,呵呵,不过忘记了原作者是谁了,
*如果原作者看到的话,给我一个提示,o(∩_∩)o...
*我的blog:http://etongchina.blogcn.com
*我的邮箱:etongchina@gmail.com
**/
function calendar($year='',$month='',$linkurl='',$checkurl=''){
//处理日期
$year = $year?$year:date("Y");
$month = ($month!=='')?$month:date("m");
$day = $day?$day:date("d");
// if(date("Y-m") < ($year.'-'.$month)){
// showmessage("查询日期大于当前日期,请检查输入");
// }
if($year<2000){
showmessage("日期出错了,请检查输入",$_SESSION[url_forward],1);
}
if($month==0) {
$month=12; $year--;
}
if($month==13) {
$month=1; $year++;
}
$str = '';
$str .='<div style="width:300px; margin-top:50px;">';
$str .= '<div style="float:left">';
$str .= '<span class="calendar" style="width:30px;height:28px;">';
$str .= '<a href="javascript:getResponse('."'".$linkurl."&month=".($month-1)."&year=".$year."'".')">'."<<</a></span>";
$str .= '<span class="calendar" style="width:158px; height:28px;font-size:12px">';
$str .="<a><b>".$year."年".$month."月</b></a></span>";
$str .='<span class="calendar" style="width:30px;height:28px;">';
$str .= '<a href="javascript:getResponse('."'".$linkurl."&month=".($month+1)."&year=".$year."'".')">'.">></a></span>";
$str .= '<span class="calendar" style="width:60px;height:28px; line-height:27px;">生成图表</span>';
$str .='</div>';
$str .='
<div style="clear:both">
<span class="calendar" style="color:#FF0000">日</span>
<span class="calendar">一</span>
<span class="calendar">二</span>
<span class="calendar">三</span>
<span class="calendar">四</span>
<span class="calendar">五</span>
<span class="calendar">六</span>';
$str .= '<span class="calendar" style="width:60px;height:25px;line-height:25px;"></span>';
$str .= '</div><div style="clear:both;">';
$d=date("d");
$countLastMonth=date("t",mktime(0,0,0,($month-1),1,$year));//上个月总天数
$FirstDay=date("w",mktime(0,0,0,$month,1,$year));//取得任何一个月的一号是星期几,用于计算一号是由表格的第几格开始
$bgtoday=date("d");
if($FirstDay!=0){ //判断1号是否星期日
for($i=($countLastMonth-$FirstDay+1);$i<=$countLastMonth;$i++){ //此for用于输出某个月的一号前位置
$str .='<span class="calendar" style="color:#CCCCCC">'.$i.'</span>';
}
for($i=1;$i<=7-$FirstDay;$i++){ //此for用于输出某个月的一号位置
$str .='<span class="calendar">'.$i.'</span>';
}
}else{
for($i=1;$i<=7;$i++){ //此for用于输出某个月的一号前位置
$str .='<span class="calendar">'.$i.'</span>';
}
}
$str .= '<span class="calendar" style="width:60px;height:25px;line-height:25px;">';
$str .= '<a href="javascript:getResponse('."'".$checkurl."&start=".$year.'- '.$month.'-'.(7-$FirstDay)."'".')">'."查询本周</a></span>";
$str .= '</div><div style="clear:both;">';
$countMonth=date("t",mktime(0,0,0,$month,1,$year));//某月的总天数
for($i=7-$FirstDay+1;$i<=$countMonth;$i++){ //输出由1号定位,随后的X(周日)号直至月尾的所有号数
$str .= "<span class='calendar' style='".bgcolor($month,$bgtoday,$i,$year)."'>".($i+$j)."</span>";
if( ($i+$FirstDay)%7 == 0){
$str .= '<span class="calendar" style="width:60px;height:25px;line-height:25px;">';
$str .= '<a href="javascript:getResponse('."'".$checkurl."&start=".$year.'- '.$month.'-'.$i."'".')">'."查询本周</a></span>";
$str.='</div><div style="clear:both;">';
}
}
$LastDay=date("w",mktime(0,0,0,$month,$countMonth,$year));//取得任何一个月的一号是星期几,用于计算一号是由表格的第几格开
if($LastDay!=6){
for($i=1;$i<7-$LastDay;$i++){ //此for用于输出某个月的一号前位置
$str .='<span class="calendar" style="color:#CCCCCC">'.$i.'</span>';
}
$str .= '<span class="calendar" style="width:60px;height:25px;line-height:25px;">';
$str .= '<a href="javascript:getResponse('."'".$checkurl."&start=".$year.'-'. ($month+1).'-'.(7-$LastDay+1)."'".')">'."查询本周</a>< /span>";
}
$str .= '</div>';
return $str;
}
/***用于计算当日的背景颜色***/
function bgcolor($month,$bgtoday,$today_i,$year)
{
$show_today=date("d",mktime(0,0,0,$month,$today_i,$year));
$sys_today=date("d",mktime(0,0,0,$month,$bgtoday,$year));
if($show_today==$sys_today) {
$bgcolor=" background-color: #6699FF";
}else{
$bgcolor="";
}
return $bgcolor;
}
?>