|
<? Php
// Calendar
Class calendar {
// Current year
Private $ year;
// Current Month
Private $ month;
// The first day of a month is the day of the week
Private $ start_weekday;
// Number of days in the current month
Private $ days;
// Maximum and minimum number of years, maximum and minimum number of months
Private $ yearMonth = array (2080,190 0, 12, 1 );
// Constructor
Function _ construct (){
If (isset ($ _ GET ['Year']) {
$ This-> year = $ _ GET ['Year'];
}
If (isset ($ _ GET ['month']) {
$ This-> month = $ _ GET ['month'];
}
$ This-> pnYm ($ this-> year, $ this-> month );
$ This-> days = date ('t', mktime (0, 0, 0, $ this-> month, 1, $ this-> year ));
$ This-> start_weekday = date ('W', mktime (0, 0, 0, $ this-> month, 1, $ this-> year ));
$ This-> style ();
}
// Output
Private function style (){
Echo '<table id = "calendar"> ';
$ This-> weeklist ();
$ This-> daylist ();
Echo '<table> ';
}
// Date and month parameter determination
Private function ymCheck ($ year, $ month ){
If (! Is_numeric ($ year )){
$ Year = date ('Y ');
}
If (! Is_numeric ($ month )){
$ Month = date ('M ');
}
If ($ month <$ this-> yearMonth [3]) {
$ Month = $ this-> yearMonth [2];
$ Year-= 1;
}
If ($ month> $ this-> yearMonth [2]) {
$ Month = $ this-> yearMonth [3];
$ Year = intval ($ year) + 1;
}
$ Year = $ year <$ this-> yearMonth [1]? $ This-> yearMonth [1]: $ year;
$ Year = $ year> $ this-> yearMonth [0]? $ This-> yearMonth [0]: $ year;
Return array ($ year, $ month );
}
// Last year, next year, last month, and next month
Private function pnYm ($ year, $ month ){
$ Ym = $ this-> ymCheck ($ year, $ month );
$ This-> year = $ ym [0];
$ This-> month = $ ym [1];
}
// Weeklist weekly list
Private function weeklist (){
$ Week = array ('day', 'yi', '2', '3', '4', '5', '6 ');
Echo '<tr> ';
Foreach ($ week as $ val ){
Echo '<th>'. $ val. '</th> ';
}
Echo '</tr> ';
}
// Daylist day list
Private function daylist (){
// Year, month, and day navigation
Echo '<tr> ';
Echo '<td> <a title = "previous year" href = "? Year = '. ($ this-> year-1 ). '& month = '. $ this-> month. '"> </a> </td> ';
Echo '<td> <a title = "January" href = "? Year = '. $ this-> year.' & month = '. ($ this-> month-1).' "> </a> </td> ';
Echo '<td colspan = "3"> ';
Echo '<form action = "? "Method =" get "id =" form "> ';
Echo '<select name = "year" onchange = "formaction ()"> ';
For ($ I = $ this-> yearMonth [1]; $ I <= $ this-> yearMonth [0]; $ I ++ ){
If ($ I ==$ this-> year ){
Echo '<option value = "'. $ I. '" selected = "selected">'. $ I. '</option> ';
} Else {
Echo '<option value = "'. $ I. '">'. $ I. '</option> ';
}
}
Echo '</select> ';
Echo '<select name = "month" onchange = "formaction ()"> ';
For ($ I = $ this-> yearMonth [3]; $ I <= $ this-> yearMonth [2]; $ I ++ ){
If ($ I ==$ this-> month ){
Echo '<option value = "'. $ I. '" selected = "selected">'. $ I. 'month </option> ';
} Else {
Echo '<option value = "'. $ I. '">'. $ I. 'month </option> ';
}
}
Echo '</select> </form> </td> ';
Echo '<td> <a title = "Next Month" href = "? Year = '. $ this-> year.' & month = '. ($ this-> month + 1).' ">></a> </td> ';
Echo '<td> <a title = "Next year" href = "? Year = '. ($ this-> year + 1 ). '& month = '. $ this-> month. '">>></a> </td> ';
Echo '</tr> ';
Echo '<tr> ';
// Output space (the space to be blank before the first day of the current month)
For ($ I = 0; $ I <$ this-> start_weekday; $ I ++ ){
Echo '<td> & nbsp; </td> ';
}
For ($ k = 1; $ k <= $ this-> days; $ k ++ ){
$ I ++;
If ($ k = date ('D ')){
Echo '<td>'. $ k. '</td> ';
} Else {
Echo '<td>'. $ k. '</td> ';
}
If ($ I % 7 = 0 ){
If ($ k! = $ This-> days ){
Echo '</tr> <tr> ';
}
}
}
Echo '</tr> ';
}
}
?> |