<?php require("calendar.php"); $cal = new Calendar(2002, 8); $cal->display(); ?>
Fichier : calendar.inc
<? class Calendar { // // class variables //
// list of names for days and months var $days = array("Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"); var $months = array("", "Janvier", "Fevrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aout", "Septembre", "Octobre", "Novembre", "Decembre"); // number of days in each month var $totalDays = array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
// variables to hold current month, day and year var $currYear; var $currMonth; var $currDay; // // class methods //
// constructor function Calendar($year, $month) { // current values $this->currYear = $year; $this->currMonth = $month; $this->currDay = date("j"); // if leap year, modify $totalDays array appropriately if (date("L", mktime(0, 0, 0, $this->currMonth, 1, $this->currYear))) { $this->totalDays[2] = 29; } } // this prints the HTML code to display the calendar function display() { $rowCount = 0; // find out which day the first of the month falls on $firstDayOfMonth = date("w", mktime(0, 0, 0, $this->currMonth, 1, $this->currYear));
// start printing table echo "<table border=0 cellpadding=2 cellspacing=5>\n"; // header echo "<tr>\n"; echo "<td colspan=7 align=center> <font face=Arial size=-1><b>" . $this->months[$this->currMonth] . " " . $this->currYear . "</b></font></td>\n"; echo "</tr>\n";
// day names echo "<tr>\n"; for ($x=0; $x<7; $x++) { echo "<td><font face=Arial size=-2>" . substr($this->days[$x],0,3) . "</font></td>\n"; } echo "</tr>\n";
// start printing dates echo "<tr>\n";
// display blank spaces until the first day of the month for ($x=1; $x<=$firstDayOfMonth; $x++) { // this comes in handy to find the end of each 7-day block $rowCount++; echo "<td><font face=Arial size=-2> </font></td>\n"; } // counter to track the current date $dayCount=1; while ($dayCount <= $this->totalDays[$this->currMonth]) { // use this to find out when the 7-day block //is complete and display a new row if ($rowCount % 7 == 0) { echo "</tr>\n<tr>\n"; } // print date // if today, display in different colour if ($dayCount == date("j") && $this->currYear == date("Y") && $this->currMonth == date("n")) { echo "<td align=center bgcolor=Silver> <font face=Arial size=-1>$dayCount</font>"; } else { echo "<td align=center> <font face=Arial size=-1>$dayCount</font>"; } echo "</td>\n"; // increment counters $dayCount++; $rowCount++; } echo "</tr>\n"; echo "</table>\n"; }
// end of class } ?>
|
Aout 2002 |
Dim |
Lun |
Mar |
Mer |
Jeu |
Ven |
Sam |
|
|
|
|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
|