<?php
class Calendar {
	var $res;
	var $curent_time;

        function Calendar($satrt=0, $end=0) {
		function f($x) {
			return ($x==0 ? 7 : $x);
		}

		global $link, $d, $m, $y, $PATH;
		$array=array(
			1 => "Январь",
			2 => "Февраль",
			3 => "Март",
			4 => "Апрель",
			5 => "Май",
			6 => "Июнь",
			7 => "Июль",
			8 => "Август",
			9 => "Сентябрь",
			10 => "Октябрь",
			11 => "Ноябрь",
			12 => "Декабрь");
		$y=intval(!$y ? 2006 : $y);
		$m=intval(!$m ? date("m") : $m);
		$d=intval(!$d ? date("d") : $d);
		$cur=mktime(0, 0, 0, $m, $d, $y);
		$n=date("t", $cur);

		$page=new Template("templates/calendar2/calendar.tpl");
		$page->dictionary("common/dict.ru");
		for ($i=1; $i<=12; $i++) {
			$page->addrow("MONTH_SELECT", array(
				"id"		=> $i,
				"title"		=> $array[$i],
				"selected"	=> ($i==$m ? " selected" : ""),
			));
		}
		for ($i=2006; $i<=date("Y")+1; $i++) {
			$page->addrow("YEAR_SELECT", array(
				"title"		=> $i,
				"selected"	=> ($i==$y ? " selected" : ""),
			));
		}
		$page->assign(array(
			"d"			=> $d,
			"LINK"			=> $link->get(),
			"PATH"			=> $PATH,
		));
		$_page=new Template("templates/calendar/calendar_line.tpl");
		$_page->dictionary("common/dict.ru");
		$_page->assign(array(
			"LINK"		=> $link->get(),
			"PATH"		=> $PATH,
		));
		for ($i=1; $i<f(date("w", mktime(0, 0, 0, $m, 1, $y))); $i++) $_page->addrow("LINE", array());
		$w=date("W", mktime(0, 0, 0, $m, 1, $y));
		for ($i=1; $i<=$n; $i++) {
			$t=mktime(0, 0, 0, $m, $i, $y);
			if ($w!=date("W", $t)) {
				$w=date("W", $t);
				$page->addrow("LINE", array("line" => $_page->evaluate()));
				$_page=new Template("templates/calendar/calendar_line.tpl");
				$_page->dictionary("common/dict.ru");
				$_page->assign(array(
					"LINK"		=> $link->get(),
					"PATH"		=> $PATH,
				));
			}
			$_page->addrow("LINE", array(
				"selected"	=> ($t==$cur),
				"day"		=> $i,
				"link"		=> "d.".$i."/m.".$m."/y.".$y."/",
				"disabled"	=> ($t<$start or ($end ? ($t>$end) : 0)),
				"t"		=> $t,
			));
		}
		for ($i=f(date("w", mktime(0, 0, 0, $m, $n, $y)));$i<7; $i++) $_page->addrow("LINE", array());
		$page->addrow("LINE", array("line" => $_page->evaluate()));
		$this->res=$page->evaluate();
		$this->curent_time=$cur;
	}

	function get() {
		return $this->res;
	}
}
?>