PHP complete calendar CLASS)

Source: Internet
Author: User

Copy codeThe Code is as follows:
<? Php
Class Calendar {
/*
* Www.jb51.net revised version
*/
Var $ YEAR, $ MONTH, $ DAY;
Var $ WEEK = array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday ");
Var $ _ MONTH = array (
"01" => "August January ",
"02" => "August February ",
"03" => "August March ",
"04" => "August April ",
"05" => "August May ",
"06" => "August June ",
"07" => "August July ",
"08" => "August ",
"09" => "August September ",
"10" => "August October ",
"11" => "August November ",
"12" => "August December"
);
// Set the year
Function setYear ($ year ){
$ This-> YEAR = $ year;
}
// Obtain the year
Function getYear (){
Return $ this-> YEAR;
}
// Set the month
Function setMonth ($ month ){
$ This-> MONTH = $ month;
}
// Obtain the month
Function getMonth (){
Return $ this-> MONTH;
}
// Set the date
Function setDay ($ day ){
$ This-> DAY = $ day;
}
// Obtain the date
Function getDay (){
Return $ this-> DAY;
}
// Print the calendar
Function OUT (){
$ This-> _ env ();
$ Week = $ this-> getWeek ($ this-> YEAR, $ this-> MONTH, $ this-> DAY ); // obtain the day of the week (for example, today is, Friday)
$ Fweek = $ this-> getWeek ($ this-> YEAR, $ this-> MONTH, 1); // obtain the day of the week on the first day of the MONTH.
Echo "<div style = \" margin: 0; border: 1 solid black; width: 300; font: 9pt \ "> <form action =$ _ SERVER [PHP_SELF] method = \" post \ "style = \" margin: 0 \ "> <select name = \" month \ "onchange = \" this. form. submit (); \ "> ";
For ($ ttmpa = 1; $ ttmpa <13; $ ttmpa ++) {// print for 12 months
$ Ttmpb = sprintf ("% 02d", $ ttmpa );
If (strcmp ($ ttmpb, $ this-> MONTH) = 0 ){
$ Select = "selected style = \" background-color: # c0c0c0 \"";
} Else {
$ Select = "";
}
Echo "<option value = \". $ ttmpb \ ". $ select>". $ this-> MONTH [$ ttmpb]. "</option> \ r \ n ";
}
Echo "</select> <select name = \" year \ "onchange = \" this. form. submit (); \ ">"; // print the year, before and after 10 years
For ($ ctmpa = $ this-> YEAR-10; $ ctmpa <$ this-> YEAR + 10; $ ctmpa ++ ){
If ($ ctmic> 2037 ){
Break;
}
If ($ ctmpa <1970 ){
Continue;
}
If (strcmp ($ ctmpa, $ this-> YEAR) = 0 ){
$ Select = "selected style = \" background-color: # c0c0c0 \"";
} Else {
$ Select = "";
}
Echo "<option value = \" $ ctmpa \ "$ select >$ ctmpa </option> \ r \ n ";
}
Echo "</select>
</Form>
<Table border = 0 align = center> ";
For ($ Tmpa = 0; $ Tmpa <count ($ this-> WEEK); $ Tmpa ++) {// print the WEEK Header
Echo "<td>". $ this-> WEEK [$ Tmpa];
}
For ($ Tmpb = 1; $ Tmpb <= date ("t", mktime (0, 0, $ this-> MONTH, $ this-> DAY, $ this-> YEAR); $ Tmpb ++) {// print all dates
If (strcmp ($ Tmpb, $ this-> DAY) = 0) {// obtain the current date and mark it
$ Flag = "bgcolor = '# ff0000 '";
} Else {
$ Flag = 'bgcolor = # ffff ';
}
If ($ Tmpb = 1 ){
Echo "<tr>"; // supplemental print
For ($ tnmpc = 0; $ tnmpc <$ fweek; $ Tmpc ++ ){
Echo "<td> ";
}
}
If (strcmp ($ this-> getWeek ($ this-> YEAR, $ this-> MONTH, $ Tmpb), 0) = 0 ){
Echo "<tr> <td align = center $ flag> $ Tmpb ";
} Else {
Echo "<td align = center $ flag> $ Tmpb ";
}
}
Echo "</table> </div> ";
}
// Obtain the number of weeks of the specified date in the method.
Function getWeek ($ year, $ month, $ day ){
$ Week = date ("w", mktime (0, 0, 0, $ month, $ day, $ year); // obtain the week
Return $ week; // obtain the week
}
Function _ env (){
If (isset ($ _ POST ["month"]) {// has a specified month
$ Month = $ _ POST ["month"];
} Else {
$ Month = date ("m"); // The default value is this month.
}
If (isset ($ _ POST ["year"]) {// year
$ Year = $ _ POST ["year"];
} Else {
$ Year = date ("Y"); // The default value is this year.
}
$ This-> setYear ($ year );
$ This-> setMonth ($ month );
$ This-> setDay (date ("d "));
}
}
$ D = new Calendar;
$ D-> OUT ();
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.