HTML Calendar Creation 2.0 - Show a whole year's calendar with easy visual effects to contrast between different day types (weekend, festivities...)
<!DOCTYPE html> <html> <head> <title>HTML Calendar Creation 2.0</title> </head> <body> <?php // Begin HTML Calendar Creation 2.0 // == This Script Free To Use Providing This Notice Remains == // == This Script Has Been Found In The Free Public Codes Library == // == NOTICE: Though This Material May Have Been In A Public Depository, Certain Author Copyright Restrictions May Apply == // Name: Patrick Ingle's HTML Calendar Creation 2.0 // By: Alvaro Alvaro Peñalba function daytype($month, $day, $year){ // function that returns the kind of day, the days could be stored in arrays, filled from a db or in the script if (date("w",mktime(0,0,0,$month, $day, $year))==5||date("w",mktime(0,0,0,$month, $day, $year))==6) return 1; // weekend elseif ($day==5&&$month==1) return 2; // festive elseif ($day==8&&$month==4) return 3; // this year's holydays elseif ($day==13&&$month==8) return 4; // last year's holydays elseif ($day==3&&$month==9) return 5; // permission else return 6; // work day } function daycolor($daytype){ // function that returns the bgcolor depending on the kind of day switch ($daytype){ case 1: return '#008080'; // set color to your choice break; case 2: return '#0000cd'; // set color to your choice break; case 3: return '#006400'; // set color to your choice break; case 4: return '#48d1cc'; // set color to your choice break; case 5: return '#cccccc'; // set color to your choice break; case 6: return '#ffffff'; // set color to your choice break; } } echo "<center><table>\n"; if (!isset($year))$year = date("Y"); // we loop through the year days for ($z=1; $z<=12; $z++){ // we begin one line for each three rows (months) if ($z%3==1) echo "<tr>"; // we open this months row echo "<td witdh=33% valign=top>"; // Initialize some variables $month_name = date("F",mktime(0,0,0,$z,1,$year)); $month = date("m",mktime(0,0,0,$z,1,$year)); $day = date("d",mktime(0,0,0,$z,1,$year)); $hour = date("h"); $minute = date("i"); $second = date("s"); $daysInMonth = date("t",mktime(0,0,0,$z,1,$year)); echo "<center><h2><b>$month_name $year</b></h2></center>\n"; // determine the weekday of the first day of the month if ($day != 1) { $first_weekday = date("w", mktime($hour,$minute,$second,$month,1,$year)); } else { $first_weekday = date("w", mktime($hour,$minute,$second,$month,$day,$year)); } // begin the table definition used to construct the calendar, starting with the header. echo "<center>\n"; echo "<table border=1>\n"; echo "<tr align=center>\n"; echo "<th>Sun</th>\n"; echo "<th>Mon</th>\n"; echo "<th>Tue</th>\n"; echo "<th>Wed</th>\n"; echo "<th>Thr</th>\n"; echo "<th>Fri</th>\n"; echo "<th>Sat</th>\n"; echo "</tr>\n"; // loop for each day in the month, day counter for ($j = 1;$j <= $daysInMonth;$j++) { echo "<tr align=center>\n"; // loop for a week for ($i = 0;$i < 7; $i++) { if ($j <= (7-$first_weekday)){ // if we are processing the first week, put blanks in the table cols until we have the first weekday for the first day in the month if ($i < $first_weekday) { echo "<td> </td>\n"; } else { echo "<td bgcolor=".daycolor(daytype($z,$j,$year)).">$j</td>\n"; // for the day counter index to increment $j++; } } else if ($j > $daysInMonth) { // if our day counter has exceeded the maximum days from the month but not exceed the week we pad the remaining week with spaces echo "<td> </td>\n"; } else { echo "<td bgcolor=".daycolor(daytype($z,$j,$year)).">$j</td>\n"; // then force the day counter to increment $j++; } } echo "</tr>\n"; // adjusting the day counter for over-incrementing // error $j--; } // closing table definition echo "</table>\n"; echo "</center>\n"; if ($z%3==0) echo "</tr>"; } // for 1 to 12 echo "</table>\n"; echo "</center>\n"; ?> </body> </html>