<? Php
Date_default_timezone_set ("Asia/shanghai ");
Class CalendarForm {
Private $ year;
Private $ month;
Private $ day;
Private $ weekend;
Private $ currentdate;
Private $ dayofmonth;
Private $ day_count;
Private $ num;
Private $ week = array ();
Private $ retunrhtml = "";
Function _ construct ($ year, $ month ){
$ This-> makeWeeks ($ year, $ month );
}
Public function setYearMonth ($ year, $ month ){
$ This-> year = $ year;
$ This-> month = $ month;
}
Private function resetDayCount (){
$ This-> day_count = 1;
}
Private function setFirstWeek (){
$ This-> num = 0;
}
Public function getDayOfMonth ($ year, $ month ){
$ This-> resetDayCount ();
Return date ('T', mktime (0, 0, 0, $ month, $ this-> day_count, $ year ));
}
Private function setDayOfMonth ($ year, $ month ){
$ This-> dayofmonth = $ this-> getDayOfMonth ($ year, $ month );
}
Private function getDayOfWeek (){
Return date ('w', mktime (0, 0, 0, $ this-> month, $ this-> day_count, $ this-> year ));
}
Public function getNextMonth (){
Return date ('M', mktime (0, 0, 0, $ this-> month, 28, $ this-> year) + 432000 );
}
Public function getNextYear (){
Return date ('y', mktime (0, 0, 0, $ this-> month, 28, $ this-> year) + 432000 );
}
Public function getPrevMonth (){
Return date ('M', mktime (0, 0, 0, $ this-> month, 1, $ this-> year)-432000 );
}
Public function getPrevYear (){
Return date ('y', mktime (0, 0, 0, $ this-> month, 1, $ this-> year)-432000 );
}
Private function makeWeeks ($ year, $ month ){
$ This-> setYearMonth ($ year, $ month );
$ This-> setDayOfMonth ($ this-> year, $ this-> month );
$ This-> setFirstWeek ();
$ This-> num = 0;
For ($ I = 0; $ I <7; $ I ++ ){
$ Dayofweek = $ this-> getDayOfWeek ();
$ Dayofweek = $ dayofweek-1;
If ($ dayofweek =-1) $ dayofweek = 6;
If ($ dayofweek ==$ I ){
$ This-> week [$ this-> num] [$ I] = $ this-> day_count;
$ This-> day_count ++;
} Else {
$ This-> week [$ this-> num] [$ I] = "";
}
}
While (true ){
$ This-> num ++;
For ($ I = 0; $ I <7; $ I ++ ){
$ This-> week [$ this-> num] [$ I] = $ this-> day_count;
$ This-> day_count ++;
If ($ this-> day_count> $ this-> dayofmonth) break;
}
If ($ this-> day_count> $ this-> dayofmonth) break;
}
}
Public function getCalendarHeader (){
$ This-> retunrhtml =
"<Table cellpadding = 2 cellspacing = 0 border = 1 style = \" margin-left: auto; margin-right: 0px; \ "> ".
"<Tbody> ".
"<Tr> <th colspan = \" 7 \ "> ". $ this-> month. "/". $ this-> year. "</th> </tr> ".
"<Tr> ".
"<Th style = \" text-align: center; \ "> Monday </th> ".
"<Th style = \" text-align: center; \ "> Tuesday </th> ".
"<Th style = \" text-align: center; \ "> Wednesday </th> ".
"<Th style = \" text-align: center; \ "> Thursday </th> ".
"<Th style = \" text-align: center; \ "> Friday </th> ".
"<Th style = \" text-align: center; \ "> <span style = \" color: # ff0000; \ "> Saturday </span> </th> ".
"<Th style = \" text-align: center; \ "> <span style = \" color: # ff0000; \ "> Sunday </span> </th> ".
"</Tr> ";
}
Public function getCalendarFooter (){
$ This-> retunrhtml. = "</tbody> </table> ";
}
Public function getBeginTR (){
$ This-> retunrhtml. = "<tr> ";
}
Public function getEndTR (){
$ This-> retunrhtml. = "</tr> ";
}
Protected function getDay (){
Return $ this-> day;
}
Protected function getMonth (){
Return $ this-> month;
}
Protected function getYear (){
Return $ this-> year;
}
Protected function isWeekend (){
Return $ this-> weekend;
}
Protected function isCurrent (){
Return $ this-> currentdate;
}
Public function getTDHref (){
Return $ this-> getDay ();
}
Public function getTD (){
$ Td = "td"; if ($ this-> isCurrent () $ td = "th ";
$ This-> retunrhtml. = "<$ td style = \" text-align: right; \ "> ". $ this-> getTDHref (). "</$ td> ";
}
Public function getTDWeekend (){
$ Td = "td"; if ($ this-> isCurrent () $ td = "th ";
$ This-> retunrhtml. = "<$ td style = \" text-align: right; \ "> <font color = red> ". $ this-> getTDHref (). "</font> </$ td> ";
}
Protected function makeCodeMonth ($ year, $ month ){
$ This-> makeWeeks ($ year, $ month );
$ This-> getCalendarHeader ();
For ($ I = 0; $ I <count ($ this-> week); $ I ++ ){
$ This-> getBeginTR ();
For ($ j = 0; $ j <7; $ j ++ ){
If (! Empty ($ this-> week [$ I] [$ j]) {
$ This-> day = $ this-> week [$ I] [$ j];
$ This-> currentdate = 0;
If ($ this-> year = date ('y') & $ this-> month = date ('M ') & $ this-> day = date ('J') $ this-> currentdate = 1;
If ($ j = 5 | $ j = 6 ){
$ This-> weekend = 1;
$ This-> getTDWeekend ();
} Else {
$ This-> weekend = 0;
$ This-> getTD ();
}
} Else $ this-> retunrhtml. = "<td> & nbsp; </td> ";
}
$ This-> getEndTR ();
}
$ This-> getCalendarFooter ();
}
Public function getCodeMonth (){
$ This-> makeCodeMonth ($ this-> year, $ this-> month );
Return $ this-> retunrhtml;
}
Public function showCodeMonth (){
Echo $ this-> getCodeMonth ();
}
}
Class TechCalendarForm extends CalendarForm {
Public function getTDHref (){
If ($ this-> isWeekend () $ font = "<font color = \" # FF3F4F \ "> "; else $ font = "<font color = \" # 4A5B6C \ "> ";
Return "<a href = \" ". $ _ SERVER [" PHP_SELF "]."? Action = showdate & date = ". parent: getYear (). "-". parent: getMonth (). "-". parent: getDay (). "\"> ". $ font. parent: getDay (). "</font> </a> ";
}
}
?>
<Html>
<Head>
<Style type = "text/css">
. Align-center {
Margin: 0 auto;/* center. Other attributes are not required */
Width: 789px;/* The center effect cannot be seen when the width is pushed to either side of the browser */
// Background: red;/* background Color */
Text-align: center;/* center text and other content */
}
</Style>
</Head>
<Body>
<Div class = "align-center">
<? Php
// $ Cal = new TechCalendarForm (2009,10 );
$ Cal = new CalendarForm (2009,10 );
$ Cal-> showCodeMonth ();
?>
</Div>
</Body>
</Html>