How to create a calendar by php?

<?php
function getCalendar($year,$month){

global $current_user;
$first_day = get_option(‘start_of_week’);
$first_of_month = gmmktime(0,0,0,$month,1,$year);
$per_line = 7;
$total_days = date(‘t’,strtotime(“$year-$month”));

//echo “$year-$month-2″;
//$first_day = date(‘N’,strtotime(“$year-$month-1″))
$line = 1;
for($i=1;$i<=$total_days;$i++){
$day = date(‘w’,strtotime(“$year-$month-$i”));
$array_data[$line][$day] = $i;
if($day==6){
$line++;
}
}
return $array_data;
}
$iid = $_REQUEST['iid'];
$did = “d_vfcalendar”;
$year= ($_REQUEST['year']==”")?date(“Y”,strtotime(“now”)):$_REQUEST['year'];
$month = ($_REQUEST['month']==”")?date(“n”,strtotime(“now”)):$_REQUEST['month'];
$calendar = getCalendar($year,$month);
$prev_month = date(“n”,strtotime(“$year-$month -1 month”));
$next_month = date(“n”,strtotime(“$year-$month +1 month”));
$prev_year = date(“Y”,strtotime(“$year-$month -1 month”));
$next_year = date(“Y”,strtotime(“$year-$month +1 month”));
$prev_month_name = date(“M”,strtotime(“$year-$month -1 month”));
$next_month_name = date(“M”,strtotime(“$year-$month +1 month”));

?>


<div style=”z-index:9999;background-color:#FAD6C7;”>
<table border=”0″ cellpadding=”1″ cellspacing=”1″ style=” font-family:monospace;font-size: 12px; border:dotted; border-width:thin”>
<tr><th colspan=”7″  bgcolor=”#CCCCFD” height=”25px” align=”center” valign=”middle”><a href=”#” onclick=”jcalendar.vfgoto(<?php echo “‘$iid’,$year-1,$month”?>);return false;”>&lt;&lt;</a>&nbsp;&nbsp;<a href=”#” onclick=”jcalendar.vfgoto(<?php echo “‘$iid’,$prev_year,$prev_month”?>);return false;”>&lt;</a>&nbsp;&nbsp;<?php echo(date(“m/Y”,strtotime(“$year-$month”)))?>&nbsp;&nbsp;<a href=”#” onclick=”jcalendar.vfgoto(<?php echo “‘$iid’,$next_year,$next_month”?>);return false;”>&gt;</a>&nbsp;&nbsp;<a href=”#” onclick=”jcalendar.vfgoto(<?php echo “‘$iid’,$year+1,$month”?>);return false;”>&gt;&gt;</a></tr></tr>
<tr style=”padding-left:2px” bgcolor=”#E7E7FE”>
<th bordercolor=”#E7E7FE” bgcolor=”#E7E7FE”><div align=”center”>Sun</div></th>
<th bordercolor=”#E7E7FE” bgcolor=”#E7E7FE”><div align=”center”>Mon</div></th>
<th bordercolor=”#E7E7FE” bgcolor=”#E7E7FE”><div align=”center”>Tue</div></th>
<th bordercolor=”#E7E7FE” bgcolor=”#E7E7FE”><div align=”center”>Wen</div></th>
<th bordercolor=”#E7E7FE” bgcolor=”#E7E7FE”><div align=”center”>Thu</div></th>
<th bordercolor=”#E7E7FE” bgcolor=”#E7E7FE”><div align=”center”>Fri</div></th>
<th bordercolor=”#E7E7FE” bgcolor=”#E7E7FE”><div align=”center”>Sat</div></th>
</tr>
<?php
if(is_array($calendar)):
for($i=1;$i<=count($calendar);$i++){
$sub_calendar = $calendar[$i];
?>
<tr>
<?php
for($j=0;$j<7;$j++){

?>
<td align=”center” bgcolor=”#F5F5FE” <?php echo (date(“Y-m-d”,strtotime(“now”))==date(“Y-m-d”,strtotime(“$year-$month-”.$sub_calendar[$j])))?”bgcolor=”#D3F4FF”":”" ?> ><?php
if(date(“Y-m-d”,strtotime(“now”))>date(“Y-m-d”,strtotime(“$year-$month-”.$sub_calendar[$j]))){
echo $sub_calendar[$j];
}else{
$tmp_date = date(“Y-m-d”,strtotime(“$year-$month-”.$sub_calendar[$j]));
echo “<a href=”#” onclick=”document.getElementById(‘$iid’).value=’$tmp_date’;document.getElementById(‘$did’).style.display=’none’;return false;”>$sub_calendar[$j]</a>”;
}
?></td>
<?php }?>
</tr>
<?php
}
endif
?>
</table>
</div>

Share

Comments are closed.