<?php Class Calendar { Private $year; Private $month; Private $weeks = Array (' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six ');
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> </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; }
} |