Zend - The PHP Company




Calendars

Add Code


Database Calendar  

Type: application
Added by: griswold
Entered: 16/04/2001
Last modified: 04/12/2000
Rating: *** (4 votes)
Views: 13925
I wrote this calendar in ASP and converted it when we switched to Linux. It displays just like a wall calendar. I designed it so you could select from a database and display events in the calendar cells.


<?
if ("$monthnum== "") {
$monthnum date("m");
}

if (
"$theyear== "") {
$theyear date("Y");
}

$dt date("m/j/Y");
$work_date mktime(0,0,0,$monthnum,1,$theyear);
$themonth date("F",$work_date);
$monthnext $monthnum 1;
$monthback $monthnum 1;
$nextyear $theyear;
$backyear $theyear;

if (
"$monthnext== 13) {
$monthnext 1;
$nextyear $theyear 1;
}
$work_date2 mktime(0,0,0,$monthnext,1,$nextyear);
$nextmonth date("F",$work_date2);

if (
"$monthback== 0) {
$monthback 12;
$backyear $theyear 1;
}
$work_date3 mktime(0,0,0,$monthback,1,$backyear);
$backmonth date("F",$work_date3);

if (
"$monthmun== || "$monthnum== || "$monthnum== || "&monthnum" == 11) {
$days 30;
} elseif (
"$monthnum== 2) {
if (
is_int($theyear 4)) {
$days 29;
} else {
$days 28;
}
} else {
$days 31;
}

$work_date4 mktime(0,0,0,$monthnum,01,$theyear);
$startdaynum date("w",$work_date4);
$today date(Ynj);
echo 
"$today";
?>
<CENTER>

            <TABLE WIDTH="525" BORDER="0">
                <TR>
                    <TD WIDTH="10%" valign="bottom"><P ALIGN="CENTER"><FONT SIZE="2"><A href="newcal.php?monthnum=<?echo "$monthback";?>&theyear=<?echo "$backyear";?>"><?echo "$backmonth";?></A></FONT></TD>
                    <TD WIDTH="80%" ALIGN="CENTER"><B><FONT SIZE="4" FACE="Arial"><?echo "$themonth";?>&nbsp;<?echo "$theyear";?></FONT></B><br><A href="calendar3.asp"><small>view all listings</small></A></TD>
                    <TD WIDTH="10%" ALIGN="RIGHT" valign="bottom"><FONT SIZE="2"><A href="newcal.php?monthnum=<?echo "$monthnext";?>&theyear=<?echo "$nextyear";?>"><?echo "$nextmonth";?></A></FONT></TD>
                </TR>
            </TABLE>
            <TABLE BORDER="1" WIDTH="550">
                <TR>
                    <TD HEIGHT="20" BGCOLOR="#FFFFCC">
                        <P ALIGN="CENTER"><FONT FACE="Arial">Sun</FONT>
                    </TD>
                    <TD HEIGHT="20" BGCOLOR="#FFFFCC">
                        <P ALIGN="CENTER"><FONT FACE="Arial">Mon</FONT>
                    </TD>
                    <TD HEIGHT="20" BGCOLOR="#FFFFCC">
                        <P ALIGN="CENTER"><FONT FACE="Arial">Tues</FONT>
                    </TD>
                    <TD HEIGHT="20" BGCOLOR="#FFFFCC">
                        <P ALIGN="CENTER"><FONT FACE="Arial">Wed</FONT>
                    </TD>
                    <TD HEIGHT="20" BGCOLOR="#FFFFCC">
                        <P ALIGN="CENTER"><FONT FACE="Arial">Thur</FONT>
                    </TD>
                    <TD HEIGHT="20" BGCOLOR="#FFFFCC">
                        <P ALIGN="CENTER"><FONT FACE="Arial">Fri</FONT>
                    </TD>
                    <TD HEIGHT="20" BGCOLOR="#FFFFCC">
                        <P ALIGN="CENTER"><FONT FACE="Arial">Sat</FONT>
                    </TD>
                </TR>
                <TR>
                    <?
                    
/* THIS KOUNTER SETS THE TOTAL NUMBER OF CELLS
                       IT FILLS IN FOR THE EMPTY CELLS BEFORE THE FIRST DAY
                       IT ALSO CONTINUES ON TO KOUNT THE NUMBER OF DAYS IN THE WEEK
                       KOUNTER2 KOUNTS THE NUMBERED DAYS OF THE MONTH
                    */
                    
$kounter 0;
                    
$kounter2 0;
                    while (
$kounter $startdaynum) {
                      
$kounter $kounter 1;
                    echo 
"<TD WIDTH=75 HEIGHT=75 bgcolor='#efefef'>&nbsp;</TD>";
                    }
                    while (
$kounter2 $days) {
                    ++
$kounter;
                    ++
$kounter2;
                    if (
$kounter == 7) {
                    
$thisDate "$theyear$monthnum$kounter2";
                    if (
$thisDate == $today) {
                    echo 
"<TD WIDTH=75 HEIGHT=75 VALIGN='TOP' BGCOLOR='#FFFFCC'><font face='arial' color='red'>";
                    } else {
                    echo 
"<TD WIDTH=78 HEIGHT=78 VALIGN='TOP'><font face='arial' color='#000000'>";
                    }
                    echo 
"$kounter2";
                    echo 
"</font><br></TD><TR></TR>";
                    
$kounter 0;
                    } else {
                    
$thisDate "$theyear$monthnum$kounter2";
                    if (
$thisDate == $today) {
                    echo 
"<TD WIDTH=75 HEIGHT=75 VALIGN='TOP' BGCOLOR='#FFFFCC'><font face='arial' color='red'>";
                    } else {
                    echo 
"<TD WIDTH=78 HEIGHT=78 VALIGN='TOP'><font face='arial' color='#000000'>";
                    }
                    echo 
"$kounter2";
                    echo 
"</font><br></TD>";
                    }
                    }
                    
$theTotal = ($days $startdaynum);
                    while (
$theTotal 42) {
                    ++
$theTotal;
                    ++
$kounter;
                    ++
$kounter2;
                    if (
$kounter == 7) {
                    echo 
"<TD WIDTH=78 HEIGHT=78 VALIGN='TOP' bgcolor='#efefef'>&nbsp;";
                    echo 
"</TD><TR></TR>";
                    
$kounter 0;
                    } else {
                    echo 
"<TD WIDTH=78 HEIGHT=78 VALIGN='TOP' bgcolor='#efefef'>&nbsp;";
                    echo 
"</TD>";
                    }
                    }
                    echo 
"</TABLE>";?>
</CENTER>


Usage Example


<?
if ("$monthnum== "") {
$monthnum date("m");
}

if (
"$theyear== "") {
$theyear date("Y");
}

$dt date("m/j/Y");
$work_date mktime(0,0,0,$monthnum,1,$theyear);
$themonth date("F",$work_date);
$monthnext $monthnum 1;
$monthback $monthnum 1;
$nextyear $theyear;
$backyear $theyear;

if (
"$monthnext== 13) {
$monthnext 1;
$nextyear $theyear 1;
}
$work_date2 mktime(0,0,0,$monthnext,1,$nextyear);
$nextmonth date("F",$work_date2);

if (
"$monthback== 0) {
$monthback 12;
$backyear $theyear 1;
}
$work_date3 mktime(0,0,0,$monthback,1,$backyear);
$backmonth date("F",$work_date3);

if (
"$monthmun== || "$monthnum== || "$monthnum== || "&monthnum" == 11) {
$days 30;
} elseif (
"$monthnum== 2) {
if (
is_int($theyear 4)) {
$days 29;
} else {
$days 28;
}
} else {
$days 31;
}

$work_date4 mktime(0,0,0,$monthnum,01,$theyear);
$startdaynum date("w",$work_date4);
$today date(Ynj);
echo 
"$today";
?>
<CENTER>

            <TABLE WIDTH="525" BORDER="0">
                <TR>
                    <TD WIDTH="10%" valign="bottom"><P ALIGN="CENTER"><FONT SIZE="2"><A href="newcal.php?monthnum=<?echo "$monthback";?>&theyear=<?echo "$backyear";?>"><?echo "$backmonth";?></A></FONT></TD>
                    <TD WIDTH="80%" ALIGN="CENTER"><B><FONT SIZE="4" FACE="Arial"><?echo "$themonth";?>&nbsp;<?echo "$theyear";?></FONT></B><br><A href="calendar3.asp"><small>view all listings</small></A></TD>
                    <TD WIDTH="10%" ALIGN="RIGHT" valign="bottom"><FONT SIZE="2"><A href="newcal.php?monthnum=<?echo "$monthnext";?>&theyear=<?echo "$nextyear";?>"><?echo "$nextmonth";?></A></FONT></TD>
                </TR>
            </TABLE>
            <TABLE BORDER="1" WIDTH="550">
                <TR>
                    <TD HEIGHT="20" BGCOLOR="#FFFFCC">
                        <P ALIGN="CENTER"><FONT FACE="Arial">Sun</FONT>
                    </TD>
                    <TD HEIGHT="20" BGCOLOR="#FFFFCC">
                        <P ALIGN="CENTER"><FONT FACE="Arial">Mon</FONT>
                    </TD>
                    <TD HEIGHT="20" BGCOLOR="#FFFFCC">
                        <P ALIGN="CENTER"><FONT FACE="Arial">Tues</FONT>
                    </TD>
                    <TD HEIGHT="20" BGCOLOR="#FFFFCC">
                        <P ALIGN="CENTER"><FONT FACE="Arial">Wed</FONT>
                    </TD>
                    <TD HEIGHT="20" BGCOLOR="#FFFFCC">
                        <P ALIGN="CENTER"><FONT FACE="Arial">Thur</FONT>
                    </TD>
                    <TD HEIGHT="20" BGCOLOR="#FFFFCC">
                        <P ALIGN="CENTER"><FONT FACE="Arial">Fri</FONT>
                    </TD>
                    <TD HEIGHT="20" BGCOLOR="#FFFFCC">
                        <P ALIGN="CENTER"><FONT FACE="Arial">Sat</FONT>
                    </TD>
                </TR>
                <TR>
                    <?
                    
/* THIS KOUNTER SETS THE TOTAL NUMBER OF CELLS
                       IT FILLS IN FOR THE EMPTY CELLS BEFORE THE FIRST DAY
                       IT ALSO CONTINUES ON TO KOUNT THE NUMBER OF DAYS IN THE WEEK
                       KOUNTER2 KOUNTS THE NUMBERED DAYS OF THE MONTH
                    */
                    
$kounter 0;
                    
$kounter2 0;
                    while (
$kounter $startdaynum) {
                      
$kounter $kounter 1;
                    echo 
"<TD WIDTH=75 HEIGHT=75 bgcolor='#efefef'>&nbsp;</TD>";
                    }
                    while (
$kounter2 $days) {
                    ++
$kounter;
                    ++
$kounter2;
                    if (
$kounter == 7) {
                    
$thisDate "$theyear$monthnum$kounter2";
                    if (
$thisDate == $today) {
                    echo 
"<TD WIDTH=75 HEIGHT=75 VALIGN='TOP' BGCOLOR='#FFFFCC'><font face='arial' color='red'>";
                    } else {
                    echo 
"<TD WIDTH=78 HEIGHT=78 VALIGN='TOP'><font face='arial' color='#000000'>";
                    }
                    echo 
"$kounter2";
                    echo 
"</font><br></TD><TR></TR>";
                    
$kounter 0;
                    } else {
                    
$thisDate "$theyear$monthnum$kounter2";
                    if (
$thisDate == $today) {
                    echo 
"<TD WIDTH=75 HEIGHT=75 VALIGN='TOP' BGCOLOR='#FFFFCC'><font face='arial' color='red'>";
                    } else {
                    echo 
"<TD WIDTH=78 HEIGHT=78 VALIGN='TOP'><font face='arial' color='#000000'>";
                    }
                    echo 
"$kounter2";
                    echo 
"</font><br></TD>";
                    }
                    }
                    
$theTotal = ($days $startdaynum);
                    while (
$theTotal 42) {
                    ++
$theTotal;
                    ++
$kounter;
                    ++
$kounter2;
                    if (
$kounter == 7) {
                    echo 
"<TD WIDTH=78 HEIGHT=78 VALIGN='TOP' bgcolor='#efefef'>&nbsp;";
                    echo 
"</TD><TR></TR>";
                    
$kounter 0;
                    } else {
                    echo 
"<TD WIDTH=78 HEIGHT=78 VALIGN='TOP' bgcolor='#efefef'>&nbsp;";
                    echo 
"</TD>";
                    }
                    }
                    echo 
"</TABLE>";?>
</CENTER>


Rate This Script





Search



This Category All Categories