|
<html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php class XCalendar { var $MAX_DAYS; var $dayPointer = 0; var $weekPointer = 0; var $currentDay; var $dayArray = array(); var $skipEnds =false; var $ERR_MSG;
//********************** // konstruktor //********************** function XCalendar($month,$year) { $tmp = date("d | w",mktime(0,0,0,$month,1,$year)); $firstDay = explode(" | ",$tmp); $this->MAX_DAYS = $this->DaysInMonth($month,$year);
// fill in week with blanks until first of month for($x=0; $x < $firstDay[1]; $x++) { $this->dayArray[] = array("",-1); } // fill in rest of days $y = $firstDay[1]; for($x=1; $x <= $this->MAX_DAYS; $x++) { $this->dayArray[] = array($x,$y); if( $y == 6 ) {$y = 0;} else { $y++;} } for($x=$y;$x <= 6; $x++) { $this->dayArray[] = array("",-1); } } //********* // metode //*********
function nextDay() { if( $this->dayPointer > count($this->dayArray) ) { $this->ERR_MSG = "no more days"; $this->currentDay = array("",-1); return false; } $curDay = $this->dayArray[$this->dayPointer]; if( $this->skipEnds ) { if( $curDay[1] == 6 ) { $this->dayPointer +=2 ;} if( $curDay[1] == 0 ) { $this->dayPointer ++; } $curDay = $this->dayArray[$this->dayPointer]; } $this->dayPointer++; $this->currentDay = $curDay; return true; } function hasMoreDays() { return ($this->dayPointer < count($this->dayArray)); } function DaysInMonth($month,$year) { return 31-((($month-(($month<8)?1:0))%2)+(($month==2)?((!($year%((!($year%100))?400 :4)))?1:2):0)); } } ?> <? function constructTable($m,$y) { include("XCalendar.php"); $calendar = new XCalendar($m,$y); $HTML = "<table border=2>n"; while($calendar->hasMoreDays()) { $HTML .=" <tr>"; for($z=0;$z < 7; $z++) { $calendar->nextDay(); $day = $calendar->currentDay; if( $day[1] == 6 || $day[1] == 0 ) { $HTML .= "<td bgcolor="#C0C0C0">".$day[0]."</td>"; } else { $HTML .= "<td>".$day[0]."</td>"; } } $HTML .=" </tr>nn"; } $HTML .="</table>n"; return $HTML; } $july = constructTable(7,2000); print $july; ?> </body> </html> |