<?php
	class Calendar{
		private $year;
		private $month;
		private $day;
		private $startYear;
		private $startMonth;
		private $startDay;
		function __construct($year,$month,$day,$startYear,$startMonth,$startDay){
			$this->year  = $year;
			$this->month = $month;
			$this->day   = $day;
			$this->startYear = $startYear;
			$this->startMonth = $startMonth;
			$this->startDay = $startDay;
		}
		function getMonth(){
			$year = date('Y');
			$month = date('m');
			if($GLOBALS['config']['site_html']){
				for($i=$this->startYear;$i<=$year;$i++){
					for($j=1;$j<13;$j++){
						if($i==$this->startYear && $j==$this->startMonth) $d = $this->startDay;
						else $d = '1';
						if($i<$year){
							if($j == $this->month && $i == $this->year){
								$getMonth.= '<option selected="selected" value="">'.$i.'年'.$j.'月</option>';
							}else if($i==$this->startYear && $j>=$this->startMonth){
								$getMonth.= '<option value="'.$GLOBALS['config']['site_url'].'/history/'.$i.'/'.$j.'/'.$d.'/">'.$i.'年'.$j.'月</option><a href="/history/'.$i.'/'.$j.'/'.$d.'/">'.$i.'年'.$j.'月</a>';
							}elseif($i>$this->startYear){
								$getMonth.= '<option value="'.$GLOBALS['config']['site_url'].'/history/'.$i.'/'.$j.'/'.$d.'/">'.$i.'年'.$j.'月</option><a href="/history/'.$i.'/'.$j.'/'.$d.'/">'.$i.'年'.$j.'月</a>';
							}
						}elseif($this->startYear==$year){
							if($i==$this->year && $j == $this->month){
								$getMonth.= '<option selected="selected" value="">'.$i.'年'.$j.'月</option>';
							}else if($j>=$this->startMonth && $j<=$month){
								$getMonth.= '<option value="'.$GLOBALS['config']['site_url'].'/history/'.$i.'/'.$j.'/'.$d.'/">'.$i.'年'.$j.'月</option><a href="/history/'.$i.'/'.$j.'/'.$d.'/">'.$i.'年'.$j.'月</a>';
							}
						}elseif($i==$year){
							if($i==$this->year && $j == $this->month){
								$getMonth.= '<option selected="selected" value="">'.$i.'年'.$j.'月</option>';
							}elseif($j<=$month){
								$getMonth.= '<option value="'.$GLOBALS['config']['site_url'].'/history/'.$i.'/'.$j.'/'.$d.'/">'.$i.'年'.$j.'月</option><a href="/history/'.$i.'/'.$j.'/'.$d.'/">'.$i.'年'.$j.'月</a>';
							}
						}
					}
				}
			}else{
				for($i=$this->startYear;$i<=$year;$i++){
					for($j=1;$j<13;$j++){
						if($i==$this->startYear && $j==$this->startMonth) $d = $this->startDay;
						else $d = '1';
						if($i<$year){
							if($j == $this->month && $i == $this->year){
								$getMonth.= '<option selected="selected" value="">'.$i.'年'.$j.'月</option>';
							}else if($i==$this->startYear && $j>=$this->startMonth){
								$getMonth.= '<option value="'.U('History/index?year='.$i.'&month='.$j.'&day='.$d).'">'.$i.'年'.$j.'月</option><a href="'.U('History/index?year='.$i.'&month='.$j.'&day='.$d).'">'.$i.'年'.$j.'月</a>';
							}elseif($i>$this->startYear){
								$getMonth.= '<option value="'.U('History/index?year='.$i.'&month='.$j.'&day='.$d).'">'.$i.'年'.$j.'月</option><a href="'.U('History/index?year='.$i.'&month='.$j.'&day='.$d).'">'.$i.'年'.$j.'月</a>';
							}
						}elseif($this->startYear==$year){
							if($i==$this->year && $j == $this->month){
								$getMonth.= '<option selected="selected" value="">'.$i.'年'.$j.'月</option>';
							}else if($j>=$this->startMonth && $j<=$month){
								$getMonth.= '<option value="'.U('History/index?year='.$i.'&month='.$j.'&day='.$d).'">'.$i.'年'.$j.'月</option><a href="'.U('History/index?year='.$i.'&month='.$j.'&day='.$d).'">'.$i.'年'.$j.'月</a>';
							}
						}elseif($i==$year){
							if($i==$this->year && $j == $this->month){
								$getMonth.= '<option selected="selected" value="">'.$i.'年'.$j.'月</option>';
							}elseif($j<=$month){
								$getMonth.= '<option value="'.U('History/index?year='.$i.'&month='.$j.'&day='.$d).'">'.$i.'年'.$j.'月</option><a href="'.U('History/index?year='.$i.'&month='.$j.'&day='.$d).'">'.$i.'年'.$j.'月</a>';
							}
						}
					}
				}
			}
			return $getMonth;
		}
		function getDay($time){
			$t = date('t',$time);
			$year = date('Y');
			$month = date('m');
			$day = date('d');
			
			$week = date('w',mktime(0,0,0,$this->month,1,$this->year));
			$getDay = '<div class="off">';
			for($i=0;$i<$week;$i++){
				$getDay.= '<a>&nbsp</a>';
			}
			$getDay.= '</div>';
			if($GLOBALS['config']['site_html']){
				for($i=1;$i<=$t;$i++){
					$j = $this->year.'/'.$this->month.'/'.$i.'/';
					if($this->year==$this->startYear){
						if($this->year != $year){
							if($this->month==$this->startMonth){
								if($this->day == $i) $d='<a class="today">'.$i.'</a>';
								else if($i<$this->startDay) $d='<a style="color:#ccc;">'.$i.'</a>';
								else $d= '<a href="'.$GLOBALS['config']['site_url'].'/history/'.$j.'">'.$i.'</a>';
							}elseif($this->month>$this->startMonth){
								if($this->day == $i) $d='<a class="today">'.$i.'</a>';
								else $d= '<a href="'.$GLOBALS['config']['site_url'].'/history/'.$j.'">'.$i.'</a>';
							}else{
								$d='<a style="color:#ccc;">'.$i.'</a>';
							}
						}else{
							if($this->month==$this->startMonth && $this->month != $month){
								if($this->day == $i) $d = '<a class="today">'.$i.'</a>';
								else if($i<$this->startDay) $d = '<a style="color:#ccc;">'.$i.'</a>';
								else if($i>$day) $d= '<a href="'.$GLOBALS['config']['site_url'].'/history/'.$j.'">'.$i.'</a>';
								else $d= '<a href="'.$GLOBALS['config']['site_url'].'/history/'.$j.'">'.$i.'</a>';
							}elseif($this->month == $this->startMonth){
								if($i==$this->day) $d='<a class="today">'.$i.'</a>';
								else if($i>=$day || $i < $this->startDay) $d='<a style="color:#ccc;">'.$i.'</a>';
								else if($i) $d= '<a href="'.$GLOBALS['config']['site_url'].'/history/'.$j.'">'.$i.'</a>';
							}elseif($this->month == $month){
								if($i==$this->day) $d='<a class="today">'.$i.'</a>';
								else if($i>=$day) $d='<a style="color:#ccc;">'.$i.'</a>';
								else if($i) $d= '<a href="'.$GLOBALS['config']['site_url'].'/history/'.$j.'">'.$i.'</a>';
							}elseif($this->month>$this->startMonth){
								if($i==$this->day) $d='<a class="today">'.$i.'</a>';
								else $d= '<a href="'.$GLOBALS['config']['site_url'].'/history/'.$j.'">'.$i.'</a>';
							}else{
								$d='<a style="color:#ccc;">'.$i.'</a>';
							}
						}
					}elseif($this->year<$year){
						if($this->day == $i) $d='<a class="today">'.$i.'</a>';
						else $d= '<a href="'.$GLOBALS['config']['site_url'].'/history/'.$j.'">'.$i.'</a>';
					}elseif($this->year==$year){
						if($this->month == $month){
							if($this->day == $i) $d='<a class="today">'.$i.'</a>';
							else if($i <= $day) $d= '<a href="/history/'.$j.'">'.$i.'</a>';
							else $d='<a style="color:#ccc;">'.$i.'</a>';
						}else{
							if($this->day == $i) $d='<a class="today">'.$i.'</a>';
							else $d= '<a href="'.$GLOBALS['config']['site_url'].'/history/'.$j.'">'.$i.'</a>';
						}
					}
					$getDay.= $d;
				}
			}else{
				for($i=1;$i<=$t;$i++){
					$j = '?year='.$this->year.'&month='.$this->month.'&day='.$i;
					if($this->year==$this->startYear){
						if($this->year != $year){
							if($this->month==$this->startMonth){
								if($this->day == $i) $d='<a class="today">'.$i.'</a>';
								else if($i<$this->startDay) $d='<a style="color:#ccc;">'.$i.'</a>';
								else $d= '<a href="'.U('History/index'.$j).'">'.$i.'</a>';
							}elseif($this->month>$this->startMonth){
								if($this->day == $i) $d='<a class="today">'.$i.'</a>';
								else $d= '<a href="'.U('History/index'.$j).'">'.$i.'</a>';
							}else{
								$d='<a style="color:#ccc;">'.$i.'</a>';
							}
						}else{
							if($this->month==$this->startMonth && $this->month != $month){
								if($this->day == $i) $d = '<a class="today">'.$i.'</a>';
								else if($i<$this->startDay) $d = '<a style="color:#ccc;">'.$i.'</a>';
								else if($i>$day) $d= '<a href="'.U('History/index'.$j).'">'.$i.'</a>';
								else $d= '<a href="'.U('History/index'.$j).'">'.$i.'</a>';
							}elseif($this->month == $this->startMonth){
								if($i==$this->day) $d='<a class="today">'.$i.'</a>';
								else if($i>=$day || $i < $this->startDay) $d='<a style="color:#ccc;">'.$i.'</a>';
								else if($i) $d= '<a href="'.U('History/index'.$j).'">'.$i.'</a>';
							}elseif($this->month == $month){
								if($i==$this->day) $d='<a class="today">'.$i.'</a>';
								else if($i>=$day) $d='<a style="color:#ccc;">'.$i.'</a>';
								else if($i) $d= '<a href="'.U('History/index'.$j).'">'.$i.'</a>';
							}elseif($this->month>$this->startMonth){
								if($i==$this->day) $d='<a class="today">'.$i.'</a>';
								else $d= '<a href="'.U('History/index'.$j).'">'.$i.'</a>';
							}else{
								$d='<a style="color:#ccc;">'.$i.'</a>';
							}
						}
					}elseif($this->year<$year){
						if($this->day == $i) $d='<a class="today">'.$i.'</a>';
						else $d= '<a href="'.U('History/index'.$j).'">'.$i.'</a>';
					}elseif($this->year==$year){
						if($this->month == $month){
							if($this->day == $i) $d='<a class="today">'.$i.'</a>';
							else if($i <= $day) $d= '<a href="'.U('History/index'.$j).'">'.$i.'</a>';
							else $d='<a style="color:#ccc;">'.$i.'</a>';
						}else{
							if($this->day == $i) $d='<a class="today">'.$i.'</a>';
							else $d= '<a href="'.U('History/index'.$j).'">'.$i.'</a>';
						}
					}
					$getDay.= $d;
				}			
			}
			return $getDay;
		}
	}
?>	