Version: 2
Type: Full Script
Category: Calendars/Dates
License: Other
Description: This is a simple calendar that displays a nice, attractive calendar with month forward and backward buttons (you supply icons).
<? /* Author: Jason Loretz [email protected] Description: A simple calendar. License: NONE, Except to include this header. Editing/Updating Programmers: Chris Heald - 5/10/01 - [email protected] Questions/comments welcome! Updated 09/17/2003 Chris Weisiger - 09/17/03 [email protected] #### CHANGE LOG #### Change log created - CMH 5/10/01 05/10/01 - CMH Added 1 pixel transparent GIF to headers for absolute spacing Added stylesheet to HTML header function Added "highlight today" functionality Changed foward and backward buttons to text links Changed script references so that $PHP_SELF is used rather than a hardcoded script name Fixed leftover row problem - caused a thick border at the bottom on months that ended on Sat. Removed "created on" text Changed "Thurs" to "Thu" and "Tues" to "Tue" for standardization Changed date() parameters to literals to avoid warnings. Compacted calendar for inclusion on a page. Size is now approximately 165 pixels wide. 01/08/02 - CMH Fixed several warnings Fixed severe issue with table rows on Saturday Pared down day loop code - more efficient now */ /* 09/17/2003 - CRW Edited style to remove underline for hover of previous/next links. Added additional style for day if it has data for that day in database to set to bold with no underline. Removed <b> tag from days so not to conflict with days that are linked to additional data. Added mySQL database functionality with the addition of a function. If a day has data and is linked...it goes to info.php page passing the id of the information. Being I ran this on win32 environment I had to make changes on how the date was initially. retrieved if it wasnt already set by using the next/previous links. Have not tested on weither this change is necessary in linux evironment. Changes made on lines 115, 116, 122, 123 mySQL table information Tablename: calendarData; Columns: cdid integer(12) auto_increment primary key; cddate date; cdinfo text; */ function getData($currMonth, $currDay, $currYear, $resID) { $query = "select * from calendarData where cddate='" . $currYear . "-" . $currMonth . "-" . $currDay . "'"; $result = mysql_query($query, $resID); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_array($result); $linkedData = "<b><a class='link' href='info.php?id=" . $row["cdid"] . "'>$currDay</a></b>"; } else { $linkedData = "$currDay"; } return $linkedData; } $hostname = "localhost"; $username = "root"; $password = ""; $dbname = "calendarInfo"; $conn = mysql_connect($hostname, $username, $password); mysql_select_db($dbname); // HTML Color Schemes $header_bgcolor = "#000000"; $header_txtcolor = "#FFFFFF"; $title_bgcolor = "#660000"; $title_txtcolor = "#FFFFFF"; $text_bgcolor = "#FFFFFF"; $text_txtcolor = "#000000"; $date_bgcolor = "#FFFFFF"; $extra_bgcolor = "#CCCCCC"; $weekend_txtcolor = "#996666"; $highlight_today = 1; //1 = yes; 0 = no; - CMH 5/10/01 $today_bgcolor = "#660000"; //background color for today's date - CMH 5/10/01 $today_txtcolor = "#FFFFFF"; //foreground for today's date - CMH 5/10/01 $image_dir = "."; //path to the 1pix.gif picture used for spacing $image_name = "1pix.gif"; $table_width = 150; //mostly irrevelant now, unless you want a table wider than [(7px * column_width) + borders] $column_width = 22; ####################### ## Program Functions ## ####################### // Generate the month text for the numbers (returns a string) function genMonth_Text($month) { switch ($month) { case 1: $month_text = "January"; break; case 2: $month_text = "February"; break; case 3: $month_text = "March"; break; case 4: $month_text = "April"; break; case 5: $month_text = "May"; break; case 6: $month_text = "June"; break; case 7: $month_text = "July"; break; case 8: $month_text = "August"; break; case 9: $month_text = "September"; break; case 10: $month_text = "October"; break; case 11: $month_text = "November"; break; case 12: $month_text = "December"; break; } return ($month_text); } // Set Today's Month (returns numerical value) function genSet_Month() { //$month = date("m",mktime(0,0,0,1,12,2)); $month = date("m"); return ($month); } // Set Today's Year (returns numerical value) function genSet_Year() { //$year = date("Y",mktime(0,0,0,1,12,2)); $year = date("Y"); return ($year); } // Generate the Stop Value (returns the number of days in the month) function genSet_Stop($month,$year) { if ($month == '12') { $month = 1; $year++; } else { $month++; } $stop = mktime(0,0,0,$month,0,$year); $stop = date("d",$stop); return ($stop); } // Generate the top HTML (returns HTML string) function genTop_HTML() { $string = "<html>n<head>nt<title>phpCalendar.php</title>n</head>n" . "<body bgcolor="#FFFFFF">n" . "<center>n" . "<STYLE> BODY {font-family:arial;} TD {font-family:arial; font-size:10pt;} A.cal_nav {color:white; text-decoration:none;} A.cal_nav:hover {color:white; text-decoration:none;} A.link {color=black; text-decoration:none;} </STYLE>"; return ($string); } // Generate the end HTML (returns HTML string) function genEnd_HTML() { $string = "</center>n" . "</body>n</html>"; return ($string); } // Generate the table header (returns HTML string) function genTable_Header($table_width,$header_bgcolor) { $string = "<table width="$table_width" cellpadding="1" cellspacing="0">" . "<tr><td bgcolor="$header_bgcolor">n" . "<table width="$table_width" cellpadding="0" cellspacing="1" BORDER=0>n"; return ($string); } // Generate the table footer (returns HTML string) function genTable_Footer() { $string = "</table></td></tr></table>n"; return ($string); } // Generates the information to be displayed function genCalendar_Month($month,$year,$stop, $column_width,$extra_bgcolor,$weekend_txtcolor,$date_bgcolor, $header_bgcolor,$header_txtcolor, $title_bgcolor, $title_txtcolor) { $conn = mysql_connect("localhost", "root", ""); mysql_select_db("calendarInfo"); global $PHP_SELF, $today_bgcolor, $today_txtcolor, $highlight_today, $image_dir, $image_name; if ($month == 12) { $prev_month = $month - 1; $prev_year = $year; $next_month = 1; $next_year = $year + 1; } elseif ($month == 1) { $prev_month = 12; $prev_year = $year - 1; $next_month = $month + 1; $next_year = $year; } else { $prev_month = $month - 1; $prev_year = $year; $next_month = $month + 1; $next_year = $year; } $start = mktime(0,0,0,$month,1,$year); $start = date("w",$start); $month_text = genMonth_Text($month); $date_string = $month_text . " " . $year; $string = "<tr><td colspan="1" bgcolor="$header_bgcolor" align="right" valign="center">n" . "<a href="$PHP_SELF?month=$prev_month&year=$prev_year&mode=month" class="cal_nav"><<</a>" . "</td><td colspan="5" bgcolor="$header_bgcolor" align="center">n" . "<font color="$header_txtcolor" size="2"><b>$date_string</b></font>n" . "</td><td colspan="1" bgcolor="$header_bgcolor" align="left" valign="center">n" . "<a href="$PHP_SELF?month=$next_month&year=$next_year&mode=month" class="cal_nav">>></a>" . "</td></tr>n" . "<tr><td width="$column_width" bgcolor="$title_bgcolor" align="center">" . "<font color="$title_txtcolor">Sun<IMG border=0 SRC="$image_dir/$image_name" height=1 width="$column_width"></font></td>n" . "<td width="$column_width" bgcolor="$title_bgcolor" align="center">" . "<font color="$title_txtcolor">Mon<IMG border=0 SRC="$image_dir/$image_name" height=1 width="$column_width"></font></td>n" . "<td width="$column_width" bgcolor="$title_bgcolor" align="center">" . "<font color="$title_txtcolor">Tue<IMG border=0 SRC="$image_dir/$image_name" height=1 width="$column_width"></font></td>n" . "<td width="$column_width" bgcolor="$title_bgcolor" align="center">" . "<font color="$title_txtcolor">Wed<IMG border=0 SRC="$image_dir/$image_name" height=1 width="$column_width"></font></td>n" . "<td width="$column_width" bgcolor="$title_bgcolor" align="center">" . "<font color="$title_txtcolor">Thu<IMG border=0 SRC="$image_dir/$image_name" height=1 width="$column_width"></font></td>n" . "<td width="$column_width" bgcolor="$title_bgcolor" align="center">" . "<font color="$title_txtcolor">Fri<IMG border=0 SRC="$image_dir/$image_name" height=1 width="$column_width"></font></td>n" . "<td width="$column_width" bgcolor="$title_bgcolor" align="center">" . "<font color="$title_txtcolor">Sat<IMG border=0 SRC="$image_dir/$image_name" height=1 width="$column_width"></font></td></tr>n"; $string .= "<tr>"; for ($i = 0; $i < $start; $i++) { $string .= "<td bgcolor="$extra_bgcolor" align="center"> </td>n"; } //echo "Start: $start"; $frame = $start - 1; //date("w",$day); for ($i = 1; $i <= $stop; $i++) { $day = mktime(0,0,0,date("m",time()),$i,date("Y",time())); $frame++; if($frame > 6) { $string .= "</TR>n"; if($i < $stop) $string .= "<TR>"; $frame = 0; } if(($month) == date("m",$day) && $year == date("Y",$day) && date("d",$day) == date("d",time()) && $highlight_today == 1) { $string .= "<td width="$column_width" bgcolor="$today_bgcolor" align="center">" . "<FONT COLOR="$today_txtcolor">" . getData($month, $i, $year, $conn) . "</FONT></td>n"; continue; } if ($frame == 6 || $frame == 0) { $string .= "<td width="$column_width" bgcolor="$date_bgcolor" align="center">" . "<font color="$weekend_txtcolor">" . "" . getData($month, $i, $year, $conn) . "</font></td>"; } else { $string .= "<td width="$column_width" bgcolor="$date_bgcolor" align="center">" . "" . getData($month, $i, $year, $conn) . "</td>n"; } } for ($i = 1; $frame < 6; $frame++) { $string .= "<td bgcolor="$extra_bgcolor" align="center"> </td>n"; } if ($frame < 6) { $string .= "</tr>n"; } return ($string); } ###################### ## Script Execution ## ###################### print $top_html = genTop_HTML(); print $top_html = genTable_Header($table_width,$header_bgcolor); if (@!$month) { $month = genSet_Month(); $year = genSet_Year(); } $day_number = genSet_Stop($month,$year); print $mid_html = genCalendar_Month($month,$year,$day_number, $column_width,$extra_bgcolor, $weekend_txtcolor,$date_bgcolor, $header_bgcolor,$header_txtcolor, $title_bgcolor,$title_txtcolor); print $end_html = genTable_Footer(); print $end_html = genEnd_HTML(); mysql_close($conn); ?> </body> </html>