Доброго времени суток!
Пытаюсь на страницу вставить календарь, который бы работал с БД (при нажатии на день на этой же странице под календарём выдавал выборку из БД с евентами на этот день). И чтобы в админке можно было эти евенты заносить.
Тестовый код календаря написал такой:
<?php
$m = (!$m) ? date("m",mktime()) : "$m";
$y = (!$y) ? date("Y",mktime()) : "$y";
?>
<table><tr>
<td valign="top">
<? mk_drawCalendar($m,$y); ?>
</td>
</tr>
</table>
<?
$form = "<form name=\"f\" action=\"$SCRIPT_NAME?m=$m&y=$y\" method=\"POST\">
<input type=hidden name=\"eventdate\" value=\"\">
</form>";
print "$form";
print "Сделать выборку на $eventdate";
//*********************************************************
// DRAW CALENDAR
//*********************************************************
function mk_drawCalendar($m,$y)
{
if ((!$m) || (!$y))
{
$m = date("m",mktime());
$y = date("Y",mktime());
}
/*== get what weekday the first is on ==*/
$tmpd = getdate(mktime(0,0,0,$m,7,$y));
$month = $tmpd["month"];
$firstwday= $tmpd["wday"];
$lastday = mk_getLastDayofMonth($m,$y);
switch ($m){
case "01":
$mr="Январь";
break;
case "02":
$mr="Февраль";
break;
case "03":
$mr="Март";
break;
case "04":
$mr="Апрель";
break;
case "05":
$mr="Май";
break;
case "06":
$mr="Июнь";
break;
case "07":
$mr="Июль";
break;
case "08":
$mr="Август";
break;
case "09":
$mr="Сентябрь";
break;
case "10":
$mr="Октябрь";
break;
case "11":
$mr="Ноябрь";
break;
case "12":
$mr="Декабрь";
break;
}
?>
<table cellpadding=2 cellspacing=0 border=0 background="fon.gif">
<tr><td colspan=7>
<table cellpadding=0 cellspacing=0 border=0 width="100%">
<tr><th width="20"><a href="<?=$SCRIPT_NAME?>?m=<?=(($m-1)<1) ? 12 : $m-1 ?>&y=<?=(($m-1)<1) ? $y-1 : $y ?>"><<</a></th>
<th><?="$mr $y"?></th>
<th width="20"><a href="<?=$SCRIPT_NAME?>?m=<?=(($m+1)>12) ? 1 : $m+1 ?>&y=<?=(($m+1)>12) ? $y+1 : $y ?>">>></a></th>
</tr></table>
</td></tr>
<tr><th width=32 class="tcell">Пн</th><th width=32 class="tcell">Вт</th>
<th width=32 class="tcell">Ср</th><th width=32 class="tcell">Чт</th>
<th width=32 class="tcell">Пт</th><th width=32 class="tcell">Сб</th>
<th width=32 class="tcell">Вс</th></tr>
<? $d = 1;
$wday = $firstwday;
$firstweek = true;
/*== loop through all the days of the month ==*/
while ( $d <= $lastday)
{
/*== set up blank days for first week ==*/
if ($firstweek) {
print "<tr>";
for ($i=1; $i<=$firstwday; $i++)
{ print "<td><font size=2> </font></td>"; }
$firstweek = false;
}
/*== Sunday start week with <tr> ==*/
if ($wday==0) { print "<tr>"; }
/*== check for event ==*/
if (($m==date("m")) and ($d==date("d")) and ($y==date("Y"))){
$bld="bgcolor=\"#BBBBBB\"";
}
else
{
$bld="";
}
print "<td $bld class=’tcell’ align=’center’>";
print "<a href=\"#\" onClick=\"document.f.eventdate.value=’$d-$m-$y’; document.f.submit();\">$d</a>";
print "</td>\n";
/*== Saturday end week with </tr> ==*/
if ($wday==6) { print "</tr>\n"; }
$wday++;
$wday = $wday % 7;
$d++;
}
?>
</tr></table>
<?
/*== end drawCalendar function ==*/
}
/*== get the last day of the month ==*/
function mk_getLastDayofMonth($mon,$year)
{
for ($tday=28; $tday <= 31; $tday++)
{
$tdate = getdate(mktime(0,0,0,$mon,$tday,$year));
if ($tdate["mon"] != $mon)
{ break; }
}
$tday--;
return $tday;
}
?>
Вот такой простой календарь.
Может и кривенько, но на "пустом месте" работает вполне корректно (
http://studiobegemot.ru/ )
Делаю в MODx сниппет, в котором этот код, вызываю его просто на странице, но при нажатии на любую ссылку (переключение месяца, или на число) - нужные переменные передаются не туда, или не правильно, я пока не разобрался. Короче в результате любого щёлка по ссылке мы вываливаемся на заглавную страницу...
Я недавно начал разбираться с CMS вообще и MODx в частности. Подскажите, плиз, как решить задачку?