So hier jetzt die Finale-Version!
contents/kalender.php
<?php
# Kalender Script © by Nickel
defined ('main') or die ( 'no direct access' );
//-----------------------------------------------------------|
$title = $allgAr['title'].' :: Kalender';
$hmenu = 'Kalender';
$design = new design ( $title , $hmenu );
$design->header();
$tpl = new tpl ( 'kalender.htm' );
//-----------------------------------------------------------|
//Daten
$month = date('n');
$year = date('Y');
$gday = 0;
$view = 0;
$eid = 0;
if ($menu->getA(1) == 'v' AND is_numeric($menu->getE(1))) { $view = $menu->getE(1); }
if ($menu->getA(2) == 'y' AND is_numeric($menu->getE(2)) AND $menu->getE(2) > 2000 AND $menu->getE(2) < 3000) { $year = $menu->getE(2); }
if ($menu->getA(2) == 'm' AND is_numeric($menu->getE(2)) AND $menu->getE(2) > 0 AND $menu->getE(2) < 13) { $month = $menu->getE(2); }
if ($menu->getA(4) == 'd' AND is_numeric($menu->getE(4)) AND $menu->getE(4) > 0 AND $menu->getE(4) < 32) { $gday = $menu->getE(4); }
if ($menu->getA(3) == 'y' AND is_numeric($menu->getE(3)) AND $menu->getE(3) > 2000 AND $menu->getE(3) < 3000) { $year = $menu->getE(3); }
if ($menu->getA(2) == 'e' AND is_numeric($menu->getE(1))) { $eid = $menu->getE(2); }
//-----------------------------------------------------------|
$next_mon = $month +1;
$last_mon = $month -1;
$next_jahr = $year;
$last_jahr = $year;
if ($next_mon > 12) { $next_jahr = $year +1; $next_mon = 1; }
if ($last_mon == 0) { $last_jahr = $year -1; $last_mon = 12; }
//-----------------------------------------------------------|
$arr_month = array('1'=>'Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember');
$arr_day = array('So','Mo','Di','Mi','Do','Fr','Sa');
$days = date('t',mktime(0,0,0,$month,1,$year));
$start_col = date('w',mktime(0,0,0,$month,1,$year))-1;
$rows = ceil($days/7);
$day = 1;
$data = array ();
$data_id = array ();
$aus = array();
// Geburtstage
$ueid = 0;
if (substr($eid, 0, 3) == 999) { $ueid = substr ($eid, 3); }
if ($view == 2)
{
$result = db_query("SELECT
name, gebdatum, id
FROM prefix_user
WHERE YEAR(gebdatum) != '0000'
OR id = ".$ueid."
ORDER BY MONTH(gebdatum), DAYOFMONTH(gebdatum)");
while ($r = db_fetch_assoc($result))
{
list($y,$m,$d) = explode('-',$r['gebdatum']);
$date = mktime(0,0,0,$m,$d,$year);
$dateA = mktime(0,0,0,$m,$d,$y);
$am = date('m'); $at = date('d');
$jetzt = mktime(0,0,0,$am,$ad,$year);
$alter = $jetzt - $dateA;
if ($date > $jetzt)
{
$alter = date("Y",$alter) - 1970 +1;
} else {
$alter = date("Y",$alter) - 1970;
}
$row = array(
'text' => '<table style="width: 100%; border:0px;" cellspacing="0" cellpadding="0"><tr><td style="width:15px; vertical-align:top;"><b>•</b></td><td><a href="index.php?user-details-'.$r['id'].'">Der '.$alter.'. Geburtstag von <b>'.$r['name'].'</b></a></td></tr></table>',
'time' => $date + 99,
'id' => '999'.$r['id']
);
$data_id['999'.$r['id']] = $row;
$data[$date][] = $row;
}
} else {
$result = db_query("SELECT
name, gebdatum, id
FROM prefix_user
WHERE MONTH(gebdatum) = ".$month."
OR id = ".$ueid."
ORDER BY MONTH(gebdatum), DAYOFMONTH(gebdatum) LIMIT 200");
while ($r = db_fetch_assoc($result))
{
list($y,$m,$d) = explode('-',$r['gebdatum']);
$date = mktime(0,0,0,$m,$d,date('Y'));
$dateA = mktime(0,0,0,$m,$d,$y);
$jetzt = time();
$alter = $jetzt - $dateA;
if ($date > $jetzt)
{
$alter = date("Y",$alter) - 1970 +1;
} else {
$alter = date("Y",$alter) - 1970;
}
$row = array(
'text' => '<table style="width: 100%; border:0px;" cellspacing="0" cellpadding="0"><tr><td style="width:15px; vertical-align:top;"><b>•</b></td><td><a href="index.php?user-details-'.$r['id'].'">Der '.$alter.'. Geburtstag von <b>'.$r['name'].'</b></a></td></tr></table>',
'time' => $date + 99,
'id' => '999'.$r['id']
);
$data_id['999'.$r['id']] = $row;
$data[$date][] = $row;
}
}
//Daten aus der MySQL
if ($view == 2)
{
$where1 = mktime(0 ,0,0,1,1,$year);
$where2 = mktime(24,0,0,12,31,$year);
}
else
{
$where1 = mktime(0 ,0,0,$month,1,$year);
$where2 = mktime(24,0,0,$month,date('t',$where1),$year);
}
$result = db_query("SELECT *
FROM prefix_kalender
WHERE ((time >= ".$where1." AND time < ".$where2.") OR id = ".$eid.")
AND ".$_SESSION['authright']." <= recht
ORDER BY time LIMIT 200");
while ($row = db_fetch_assoc($result))
{
$t_id = $row['id'];
$t_d = date('j', $row['time']);
$t_m = date('n', $row['time']);
$t_y = date('Y', $row['time']);
$date = mktime(0,0,0,$t_m,$t_d,$t_y);
$data_id[$t_id] = $row;
$data[$date][] = $row;
}
if ($view == 0) { $title_liste = $arr_month[$month].' '.$year; }
elseif ($view == 1 && !empty($gday)) { $title_liste = 'Nur am '.$gday.'. '.$arr_month[$month].' '.$year; }
elseif ($view == 1) { $title_liste = 'Termine vom '.$arr_month[$month].' '.$year; }
elseif ($view == 2) { $title_liste = 'Termine von '.$year; }
//Template Ausgabe
if ($eid)
{
$aus['MONTH'] = $arr_month[$month];
$aus['YEAR'] = $year;
$aus['TITLE'] = $data_id[$eid]['title'];
$aus['TITLE_ALIGN'] = ' align="center"';
$aus['NEXTM'] = '';
$aus['LASTM'] = '';
$tpl->set_ar_out($aus,0);
unset($aus);
}
elseif ($view == 0 OR $view == 1)
{
$aus['MONTH'] = $arr_month[$month];
$aus['YEAR'] = $year;
$aus['TITLE'] = $title_liste;
$aus['TITLE_ALIGN'] = ' align="center"';
$aus['NEXTM'] = '<a href="index.php?kalender-v'.$view.'-m'.$next_mon.'-y'.$next_jahr.'" title="Nächster Monat"><font style="font-size: 7pt">- '.$arr_month[$next_mon].' -</font>»</a>';
$aus['LASTM'] = '<a href="index.php?kalender-v'.$view.'-m'.$last_mon.'-y'.$last_jahr.'" title="Letzter Monat">«<font style="font-size: 7pt">- '.$arr_month[$last_mon].' -</font></a>';
$tpl->set_ar_out($aus,0);
unset($aus);
}
elseif ($view == 2)
{
$aus['MONTH'] = $arr_month[$month];
$aus['YEAR'] = $year;
$aus['TITLE'] = $title_liste;
$aus['TITLE_ALIGN'] = ' align="center"';
$next_jahr++; $last_jahr--;
$aus['NEXTM'] = '<a href="index.php?kalender-v2-y'.$next_jahr.'" title="Nächstes Jahr"><font style="font-size: 7pt">- '.$next_jahr.' -</font>»</a>';
$aus['LASTM'] = '<a href="index.php?kalender-v2-y'.$last_jahr.'" title="Letztes Jahr">«<font style="font-size: 7pt">- '.$last_jahr.' -</font></a>';
$tpl->set_ar_out($aus,0);
unset($aus);
}
//Deatilansicht
if ($eid)
{
$aus['DEATIL_DATE'] = date('d.m.Y',$data_id[$eid]['time']);
$aus['DEATIL_TIME'] = date('H:i',$data_id[$eid]['time']);
$aus['DEATIL_TEXT'] = BBcode($data_id[$eid]['text']);
$tpl->set_ar_out($aus,2);
unset($aus);
}
//Liste der Tage (Monats-Ansicht)
elseif ($view == 0)
{
for($i=0;$i<$days;$i++)
{
$date = mktime(0,0,0,$month,$i+1,$year);
$text = '';
if (isset($data[$date]))
{
foreach($data[$date] as $info)
{
if (substr($info['id'], 0, 3) == 999)
{
$text .= $info['text'];
} else {
$text .= '<table style="width: 100%; border:0px;" cellspacing="0" cellpadding="0"><tr><td style="width:15px; vertical-align:top;"><b>•</b></td><td><a href="?kalender-v'.$view.'-e'.$info['id'].'">'.$info['title'].'</a></td></tr></table>';
}
}
}
$aus['LIST_I'] = $i+1;
$aus['LIST_D'] = $arr_day[date('w',mktime(0,0,0,$month,$i+1,$year))];
$aus['LIST_T'] = $text;
$class = ($i % 2) ? 'Cnorm' : 'Cmite' ;
$aus['LIST_CLASS'] = ($i+1 == date('j') && $month == date('n') && $year == date('Y')) ? 'Cdark' : $class;
$tpl->set_ar_out($aus,1);
unset($aus);
}
}
// Ganzes Jahr
elseif ($view == 2)
{
$vdate = mktime(0,0,0,1,2,$year);
$bdate = mktime(0,0,0,1,1,$year+1);
for ($x = $vdate; $x <= $bdate; $x += 86400)
{
$month = gmdate("n",$x);
$day = gmdate("d",$x);
$date = mktime(0,0,0,$month,$day,$year);
$text = '';
if (isset($data[$date]))
{
foreach($data[$date] as $info)
{
if (substr($info['id'], 0, 3) == 999)
{
$text .= $info['text'];
} else {
$text .= '<table style="width: 100%; border:0px;" cellspacing="0" cellpadding="0"><tr><td style="width:15px; vertical-align:top;"><b>•</b></td><td><a href="?kalender-v'.$view.'-e'.$info['id'].'">'.$info['title'].'</a></td></tr></table>';
}
}
$aus['LIST_I'] = date('d.m.Y',$date);
$aus['LIST_D'] = $arr_day[date('w',$date)];
$aus['LIST_T'] = $text;
$aus['LIST_CLASS'] = ($i % 2) ? 'Cnorm' : 'Cmite' ;
$tpl->set_ar_out($aus,1);
unset($aus);
$i++;
}
}
}
//Liste der Tage (Listenansicht)
elseif ($view == 1)
{
//Nur ein Tag
if (isset($data) && !empty($gday))
{
$date = mktime(0,0,0,$month,$gday,$year);
if (isset($data[$date]))
{
foreach($data[$date] as $info)
{
$text = '';
if (substr($info['id'], 0, 3) == 999)
{
$text .= $info['text'];
} else {
$text .= '<table style="width: 100%; border:0px;" cellspacing="0" cellpadding="0"><tr><td style="width:15px; vertical-align:top;"><b>•</b></td><td><a href="?kalender-v'.$view.'-e'.$info['id'].'">'.$info['title'].'</a></td></tr></table>';
}
$aus['LIST_I'] = $arr_day[date('w',$date)];
$aus['LIST_D'] = date('H:i',$info['time']);
$aus['LIST_T'] = $text;
$class = ($i % 2) ? 'Cnorm' : 'Cmite' ;
$aus['LIST_CLASS'] = ($i+1 == date('j') && $month == date('n') && $year == date('Y')) ? 'Cdark' : $class;
$tpl->set_ar_out($aus,1);
unset($aus);
$i++;
}
}
//Ganze Liste
}
elseif (isset($data))
{
$c = 1;
for($i=0;$i<32;$i++)
{
$date = mktime(0,0,0,$month,$i,$year);
$text = '';
if (isset($data[$date]))
{
foreach($data[$date] as $info)
{
if (substr($info['id'], 0, 3) == 999)
{
$text .= $info['text'];
} else {
$text .= '<table style="width: 100%; border:0px;" cellspacing="0" cellpadding="0"><tr><td style="width:15px; vertical-align:top;"><b>•</b></td><td><a href="?kalender-v'.$view.'-e'.$info['id'].'">'.$info['title'].'</a></td></tr></table>';
}
}
$aus['LIST_I'] = date('d.m.Y',$date);
$aus['LIST_D'] = $arr_day[date('w',$date)];
$aus['LIST_T'] = $text;
$aus['LIST_CLASS'] = ($c % 2) ? 'Cnorm' : 'Cmite' ;
$tpl->set_ar_out($aus,1);
unset($aus);
$c++;
}
}
} else {
$aus['LIST_I'] = '-';
$aus['LIST_D'] = '-';
$aus['LIST_T'] = '-';
$aus['LIST_CLASS'] = 'Cnorm';
$tpl->set_ar_out($aus,1);
unset($aus);
}
}
# kalender
$tpl->set('calender', getCalendar($month,$year, 'index.php?kalender-v1-m{mon}-y{jahr}-d{tag}', 'index.php?kalender-v'.$view.'-m{mon}-y{jahr}', $data));
$tpl->out(3);
$design->footer();
?>
templates/kalender.htm
<table align="center" border="0" cellpadding="3" cellspacing="0" width="100%">
<tr>
<td width="100%" valign="top" nowrap="nowrap" align="center" id="menubox">
<a href="index.php?kalender-v0">Kalender</a> |
<a href="index.php?kalender-v1">Termine pro Monat</a> |
<a href="index.php?kalender-v2">Termine pro Jahr</a>
</td>
</tr>
</table>
<table width="100%" cellpadding="0" border="0" cellspacing="0">
<tr>
<td width="100%" valign="top">
<table width="100%" cellpadding="3" border="0" cellspacing="1" class="border">
<tr id="menu2">
<td align="center" valign="middle" colspan="3"><b>{LASTM} {TITLE} {NEXTM}</b></td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
{EXPLODE}
<tr class="{LIST_CLASS}">
<td align="center" valign="top" width="25" nowrap="nowrap">{LIST_I}</td>
<td align="center" valign="top" width="25" nowrap="nowrap">{LIST_D}</td>
<td width="100%">{LIST_T}</td>
</tr>
{EXPLODE}
<tr class="Cdark">
<td colspan="3">{DEATIL_DATE} - {DEATIL_TIME} Uhr</td>
</tr>
<tr class="Cnorm">
<td colspan="3">{DEATIL_TEXT}</td>
</tr>
<tr class="Cmite">
<td colspan="3" align="center"><a href="javascript:history.back()">{_lang_back}</a></td>
</tr>
{EXPLODE}
</table>
</td>
</tr>
</table>
Ich habe noch ein paar Änderungen eingebaut und Fehler mit den Geburtstagsdaten der Zukunft behoben!