Zdravim borci, mam jeden kalendar v PHP, script som zobral hotovy a len upravil. Je tu vsak jeden problem s aktualnym dnom. Nezobrazuje ho spravne, vzdy +/- par dni... Eventy mi ukazuje v poriadku.
Pripajam zdrojak, je dost dlhy...
Kód:
$monthNames = Array("Január", "Február", "Marec", "Apríl", "Máj", "Jún", "Júl",
"August", "September", "Október", "November", "December");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
$replace = str_replace("&", "&", $_SERVER["QUERY_STRING"]);
?>
<table cellspacing="0" class='datum'>
<thead>
<tr align="center">
<td class='aktualny_mesiac' colspan="7">
<span class='left'>
<a href="<?php echo $_SERVER["PHP_SELF"]."?".$replace . "&month=". $prev_month . "&year=" . $prev_year; ?>"><<</a>
</span>
<strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong>
<span class='right'>
<a href="<?php echo $_SERVER["PHP_SELF"]."?".$replace . "&month=". $next_month . "&year=" . $next_year; ?>">>></a>
</span>
</td>
</tr>
<tr>
<th>Ne</th>
<th>Po</th><th>Ut</th><th>St</th>
<th>Št</th><th>Pi</th><th>So</th>
</tr>
</thead>
<tbody>
<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
$dnes = date("d");
$tento_mesiac = date("m");
$tento_rok = date("Y");
for ($i=0; $i<($maxday+$startday); $i++)
{
$d = $i - $startday + 1;
if(strlen($d)<2)
{
$d = "0".$d;
}
$m = $cMonth;
if(strlen($m)<2)
{
$m = "0".$m;
}
$tento_datum = $cYear."-".$m."-".$d;
$s_kal = mysql_query("SELECT * FROM calendar WHERE datum='$tento_datum' LIMIT 1");
$r_kal = mysql_fetch_assoc($s_kal);
if(($i % 7) == 0 )
{
echo "<tr>\n";
}
if($i < $startday)
{
echo "<td></td>\n";
}
else
{
if(($i == $dnes) AND ($cMonth == $tento_mesiac) AND ($cYear == $tento_rok))
{
if(is_array($r_kal) && array_key_exists("nazov", $r_kal))
{
echo "<td class='date_has_event'>";
echo "<div class='events'>";
echo "<ul>";
$s_udalosti = mysql_query("SELECT * FROM calendar WHERE datum='$tento_datum'");
while($r_udalosti = mysql_fetch_assoc($s_udalosti))
{
$url_name = toAscii($r_udalosti["nazov"], '-');
echo "<li>";
echo "<span class='title'><a href='".$web_url."/cat/17/kalendar-id/".$r_udalosti["id"]."/".$url_name."/' title='Zobraziť'>".$r_udalosti["nazov"]."</a></span><br />";
echo "<span class='desc'>".$r_udalosti["popis_short"]."</span>";
echo "</li>";
}
echo "</ul>";
echo "</div>";
}
else
{
echo "<td class='today'>";
}
}
else
{
if(is_array($r_kal) && array_key_exists("nazov", $r_kal))
{
echo "<td class='date_has_event'>";
echo "<div class='events'>";
echo "<ul>";
$s_udalosti = mysql_query("SELECT * FROM calendar WHERE datum='$tento_datum'");
while($r_udalosti = mysql_fetch_assoc($s_udalosti))
{
$url_name = toAscii($r_udalosti["nazov"], '-');
echo "<li>";
echo "<span class='title'><a href='".$web_url."/cat/17/kalendar-id/".$r_udalosti["id"]."/".$url_name."/' title='Zobraziť'>".$r_udalosti["nazov"]."</a></span><br />";
echo "<span class='desc'>".$r_udalosti["popis_short"]."</span>";
echo "</li>";
}
echo "</ul>";
echo "</div>";
}
else
{
echo "<td>";
}
}
echo ($i - $startday + 1) . "</td>\n";
}
if(($i % 7) == 6 )
{
echo "</tr>\n";
}
}
?>
</tbody>
</table>