<? if (isset($_GET['date'])) echo "<HTML><HEAD>
<META HTTP-EQUIV='Refresh' CONTENT='0; URL=daty.php?id=".$_GET['date']."'>
</HEAD>";
$result=mysql_query("SELECT DISTINCT DATE_FORMAT(daty, '%Y-%m-%d') as date_format FROM sobyt");
while($row=mysql_fetch_array($result))
{
$test[] = $row['date_format'];
}
//функция рисования календаря
my_calendar($test);
?>
<?
function my_calendar($fill='') {
$month_names=array("январь","февраль","март","апрель","май","июнь",
"июль","август","сентябрь","октябрь","ноябрь","декабрь");
if (isset($_GET['y'])) $y=$_GET['y'];
if (isset($_GET['m'])) $m=$_GET['m'];
if (isset($_GET['date']) AND strstr($_GET['date'],"-")) list($y,$m)=explode("-",$_GET['date']);
if (!isset($y) OR $y < 1970 OR $y > 2037) $y=date("Y");
if (!isset($m) OR $m < 1 OR $m > 12) $m=date("m");
$month_stamp=mktime(0,0,0,$m,1,$y);
$day_count=date("t",$month_stamp);
$weekday=date("w",$month_stamp);
if ($weekday==0) $weekday=7;
$start=-($weekday-2);
$last=($day_count+$weekday-1) % 7;
if ($last==0) $end=$day_count; else $end=$day_count+7-$last;
$today=date("Y-m-d");
$prev=date('?\m=m&\y=Y',mktime (0,0,0,$m-1,1,$y));
$next=date('?\m=m&\y=Y',mktime (0,0,0,$m+1,1,$y));
$i=0;
?>
<br>
<table border="0" cellpadding="0" cellspacing="0" id="calendar">
<caption>
<a href="<? echo $prev; ?>"><<< </a><? echo $month_names[$m-1]," ",$y ?><a href="<? echo $next; ?>"> >>></a>
</caption>
<thead>
<tr>
<th scope="col" class="mon">Пн</th>
<th scope="col" class="tue">Вт</th>
<th scope="col" class="wed">Ср</th>
<th scope="col" class="thu">Чт</th>
<th scope="col" class="fri">Пт</th>
<th scope="col" class="sat">Сб</th>
<th scope="col" class="sun">Вс</th>
</tr>
</thead>
<tbody>
<?
for($d=$start;$d<=$end;$d++) {
if (!($i++ % 7)) echo " <tr>\n";
echo ' <td>';
if ($d < 1 OR $d > $day_count) {
echo " ";
} else {
$now="$y-$m-".sprintf("%02d",$d);
if (is_array($fill) AND in_array($now,$fill)) {
echo '<b><a href="'.$_SERVER['PHP_SELF'].'?date='.$now.'">'.$d.'</a></b>';
} else {
echo $d;
}
}
echo "</td>\n";
if (!($i % 7)) echo " </tr>\n";
}
?>
</tbody>
</table>
<? } ?>
|