Simple php calender component




<html>
<!--author : alsodirex-->
<body>
<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");

$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];

$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;

if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}

?>

<table width="250px" border="2">
<tr>
<td align="center">
<?php echo date("Y")." - ".$monthNames[$cMonth-1]." - ".date("d"); ?>
</td>
</tr>
</table>

<table width="250px" border="2">
<tr>

<td width="50%" align="left"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>">Previous</a></td>
<td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>">Next</a></td>

</tr>
</table>

<table width="250px" border="2" bgcolor="#CCFFCC">
<tr>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
</tr>


<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
$today=date("d");
//echo "start".$startday."</br>";
//echo "$timestamp</br>";
//echo "$maxday";

//echo "<table width='250px' border='2'>";
echo "<tr>";
$e=42-($startday+$maxday);
//echo $e;
for($j=0;$j<$startday;$j++){
echo "<td></td>";
}
$seven=$startday;
for($i=1;$i<$maxday+1;$i++){

if($i==$today){
echo "<td align='center' style='color:#FF0000'>".$i."</td>";
}
else{
echo "<td align='center' style='color:#000066'>".$i."</td>";
}
$seven++;
if(($seven%7)==0){
echo "</tr>";
echo "<tr>";
}
}
for($k=0;$k<42-($startday+$maxday);$k++){

echo "<td></td>";
$seven++;
if(($seven%7)==0){
echo "</tr>";
echo "<tr>";
}
}
?>

</table>

<body>

</html>
if you find any bugs please let me know. leave a comment and express your ideas...
SHARE

Harsha Jayamanna

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment