|
<? Php
Class Calendar
{
Private $ year;
Private $ month;
Private $ weeks = array ('day', 'yi', '2', '3', '4', '5', '6 ');
Function _ construct ($ options = array ()){
$ This-> year = date ('y ');
$ This-> month = date ('M ');
$ Vars = get_class_vars (get_class ($ this ));
Foreach ($ options as $ key => $ value ){
If (array_key_exists ($ key, $ vars )){
$ This-> $ key = $ value;
}
}
}
Function display ()
{
Echo '<table class = "calendar"> ';
$ This-> showChangeDate ();
$ This-> showWeeks ();
$ This-> showDays ($ this-> year, $ this-> month );
Echo '</table> ';
}
Private function showWeeks ()
{
Echo '<tr> ';
Foreach ($ this-> weeks as $ title)
{
Echo '<th>'. $ title. '</th> ';
}
Echo '</tr> ';
}
Private function showDays ($ year, $ month)
{
$ FirstDay = mktime (0, 0, 0, $ month, 1, $ year );
$ StarDay = date ('w', $ firstDay );
$ Days = date ('T', $ firstDay );
Echo '<tr> ';
For ($ I = 0; $ I <$ starDay; $ I ++ ){
Echo '<td> & nbsp; </td> ';
}
For ($ j = 1; $ j <= $ days; $ j ++ ){
$ I ++;
If ($ j = date ('D ')){
Echo '<td class = "today">'. $ j. '</td> ';
} Else {
Echo '<td>'. $ j. '</td> ';
}
If ($ I % 7 = 0 ){
Echo '</tr> <tr> ';
}
}
Echo '</tr> ';
}
Private function showChangeDate ()
{
$ Url = basename ($ _ SERVER ['php _ SELF ']);
Echo '<tr> ';
Echo '<td> <a href = "? '. $ This-> preYearUrl ($ this-> year, $ this-> month ). '"> '. '<'. '</a> </td> ';
Echo '<td> <a href = "? '. $ This-> preMonthUrl ($ this-> year, $ this-> month ). '"> '. '<'. '</a> </td> ';
Echo '<td colspan = "3"> <form> ';
Echo '<select name = "year" onchange = "window. location =''. $ url .'? Year = '+ this. options [selectedIndex]. value +' & month = '. $ this-> month. ''"> ';
For ($ ye = 1970; $ ye <= 2038; $ ye ++ ){
$ Selected = ($ ye = $ this-> year )? 'Selected ':'';
Echo '<option'. $ selected. 'value = "'. $ ye.'"> '. $ ye.' </option> ';
}
Echo '</select> ';
Echo '<select name = "month" onchange = "window. location =''. $ url .'? Year = '. $ this-> year.' & month = '+ this. options [selectedIndex]. value + ''"> ';
For ($ mo = 1; $ mo <= 12; $ mo ++ ){
$ Selected = ($ mo = $ this-> month )? 'Selected ':'';
Echo '<option'. $ selected. 'value = "'. $ mo.'"> '. $ mo.' </option> ';
}
Echo '</select> ';
Echo '</form> </td> ';
Echo '<td> <a href = "? '. $ This-> nextMonthUrl ($ this-> year, $ this-> month ). '"> '. '> '. '</a> </td> ';
Echo '<td> <a href = "? '. $ This-> nextYearUrl ($ this-> year, $ this-> month ). '"> '. '> '. '</a> </td> ';
Echo '</tr> ';
}
Private function preYearUrl ($ year, $ month)
{
$ Year = ($ this-> year <= 1970 )? 1970: $ year-1;
Return 'year = '. $ year.' & month = '. $ month;
}
Private function nextYearUrl ($ year, $ month)
{
$ Year = ($ year> = 2038 )? 2038: $ year + 1;
Return 'year = '. $ year.' & month = '. $ month;
}
Private function preMonthUrl ($ year, $ month)
{
If ($ month = 1 ){
$ Month = 12;
$ Year = ($ year <= 1970 )? 1970: $ year-1;
} Else {
$ Month --;
}
Return 'year = '. $ year.' & month = '. $ month;
}
Private function nextMonthUrl ($ year, $ month)
{
If ($ month = 12 ){
$ Month = 1;
$ Year = ($ year> = 2038 )? 2038: $ year + 1;
} Else {
$ Month ++;
}
Return 'year = '. $ year.' & month = '. $ month;
}
}
|