<?php
	class Calendar{
		private $year;
		private $month;
		private $weeks  = array('日','一','二','三','四','五','六');
		function __construct($time =''){
			$this->year  = substr($time,0,4);
			$this->month = substr($time,4,2);
			$this->day   = substr($time,6,2);
		}
		function getMonth(){
			$year = date('Y');
			$month = date('m');
			$start = C('buildTime');
			$startYear = substr($start,0,4);
			$startMonth = substr($start,4,2);
			$startDay = substr($start,6,2);
			for($i=$startYear;$i<=$year;$i++){
				for($j=1;$j<13;$j++){
					if($j<10) $k = '0'.$j;
					else $k = $j;
					
					if($j==$startMonth) $d = $startDay;
					else $d = '01';
					if($i<$year){
						if($j == $this->month && $i == $this->year){
							$getMonth.= '<option selected="selected" value="">'.$i.'年'.$j.'月</option>';
						}else if($i==$startYear && $j>=$startMonth){
							$getMonth.= '<option value="'.U('Index/history?time='.$i.$k.$d).'">'.$i.'年'.$j.'月</option>';
						}elseif($i>$startYear){
							$getMonth.= '<option value="'.U('Index/history?time='.$i.$k.$d).'">'.$i.'年'.$j.'月</option>';
						}
					}elseif($startYear==$year){
						if($i==$this->year && $j == $this->month){
							$getMonth.= '<option selected="selected" value="">'.$i.'年'.$j.'月</option>';
						}else if($j>=$startMonth && $j<=$month){
							$getMonth.= '<option value="'.U('Index/history?time='.$i.$k.$d).'">'.$i.'年'.$j.'月</option>';
						}
					}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('Index/history?time='.$i.$k.$d).'">'.$i.'年'.$j.'月</option>';
						}
					}
				}
			}
			return $getMonth;
		}
		function getDay($time){
			$t = date('t',$time);
			$year = date('Y');
			$month = date('m');
			$day = date('d');
			$start = C('buildTime');
			$startYear = substr($start,0,4);
			$startMonth = substr($start,4,2);
			$startDay = substr($start,6,2);
			
			$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>';
			for($i=1;$i<=$t;$i++){
				if($i<10) $k='0'.$i;
				else $k = $i;
				$j = $this->year.$this->month.$k;
				if($this->year==$startYear){
					if($this->year != $year){
						if($this->month==$startMonth){
							if($this->day == $i) $d='<a class="today">'.$i.'</a>';
							else if($i<$startDay) $d='<a style="color:#ccc;">'.$i.'</a>';
							else $d= '<a href="'.U('Index/history?time='.$j).'">'.$i.'</a>';
						}elseif($this->month>$startMonth){
							if($this->day == $i) $d='<a class="today">'.$i.'</a>';
							else $d= '<a href="'.U('Index/history?time='.$j).'">'.$i.'</a>';
						}else{
							$d='<a style="color:#ccc;">'.$i.'</a>';
						}
					}else{
						if($this->month==$startMonth){
							if($this->day == $i) $d='<a class="today">'.$i.'</a>';
							else if($i<$startDay) $d='<a style="color:#ccc;">'.$i.'</a>';
							else if($i>$day) $d='<a style="color:#ccc;">'.$i.'</a>';
							else $d= '<a href="'.U('Index/history?time='.$j).'">'.$i.'</a>';
						}elseif($this->month == $month){
							if($i>$day) $d='<a style="color:#ccc;">'.$i.'</a>';
							else $d= '<a href="'.U('Index/history?time='.$j).'">'.$i.'</a>';
						}elseif($this->month>$startMonth){
							$d= '<a href="'.U('Index/history?time='.$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('Index/history?time='.$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('Index/history?time='.$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('Index/history?time='.$j).'">'.$i.'</a>';
					}
				}
				$getDay.= $d;
			}
			return $getDay;
		}
	}
?>	