Jeg har et problem med en kalender jeg har lavet.
Den fatter ikke hvis et måned starter på en søndag.
Og jeg fatter ikke hvad der er galt :p
<?
class calendar {
function days_in_month($month, $year) {
if(checkdate($month, 31, $year)) return 31;
if(checkdate($month, 30, $year)) return 30;
if(checkdate($month, 29, $year)) return 29;
if(checkdate($month, 28, $year)) return 28;
return 0;
}
function draw($month=null,$year=null,$day=null,$events=null, $cid) {
if (!$month) $month = date('m');
if (!$year) $year = date('Y');
$nextyear = $year;
$prevyear = $year;
$nextmonth = $month+1;
if ($nextmonth >= 13) {
$nextmonth = 1;
$nextyear = $year+1;
}
$prevmonth = $month-1;
if ($prevmonth <= 0) {
$prevmonth = 12;
$prevyear = $year-1;
}
if (is_array($events)) {
$dates = $events[0];
$times = $events[2];
$events = $events[1];
}
$months = array(
1=>'Januar',
'Februar',
'Marts',
'April',
'Maj',
'Juni',
'Juli',
'August',
'September',
'Oktober',
'November',
'December'
);
$days = calendar::days_in_month($month,$year);
$day = date("w", mktime(0, 0, 0, $month, 1, $year));
$tbl = '<table width="" cellpadding="2" cellspacing="2" border="0" align="center" class="calendar">';
$tbl .= '<tr>
<td class="calendar_heading" colspan="7"> <a href="index.php?pid='.$_GET['pid'].'&from='.$_GET['from'].'&cid='.$cid.'&m='.$prevmonth.'&y='.$prevyear.'">«</a> '.$months[$month].' - '.$year.' <a href="index.php?pid='.$_GET['pid'].'&from='.$_GET['from'].'&cid='.$cid.'&m='.$nextmonth.'&y='.$nextyear.'">»</a> </td>
</tr>';
$tbl .= '<tr>
<td class="calendar_day">Søn</td>
<td class="calendar_day">Man</td>
<td class="calendar_day">Tir</td>
<td class="calendar_day">Ons</td>
<td class="calendar_day">Tor</td>
<td class="calendar_day">Fre</td>
<td class="calendar_day">Lør</td>
</tr>';
for ($i = 0; $i <= $days; $i++) {
if ($day > 6) {
$tbl .= '</tr><tr>';
$day = 0;
}
$style = 'calendar_date';
$stylea = '';
if ($i == date("j") && $month == date("m") && $year == date("Y")) {
$style .= ' calendar_this_date';
$stylea .= ' calendar_this_date';
}
$content = '';
if (is_array($dates) && is_array($times)) {
$key = array_search($year.'-'.($month-1).'-'.$i,$dates);
if ($key !== false) {
$style .= ' calendar_event';
$stylea .= ' calendar_event';
$num = 2;
$content .= '<br>';
$content .= '<br>'.$times[$key];
if (count($times) > 1) $content .= '...';
}
}
if ($i > 0) {
$tbl .= '<td class="'.$style.'"><a href="#" class="'.$stylea.'">['.$i.']'.$content.'</a></td>';
$day++;
} else {
$tbl .= '<td colspan="'.$day.'"></td>';
}
if ($i == $days && $day < 6) {
$tbl .= '<td colspan="'.(7-$day).'"></td>';
}
}
$tbl .= '</table>';
return $tbl;
}
}
?>
min kode.
http://bookingbureau.dk/cms2/dinside/index.php?pid=19&from=0&cid=19&m=5&y=2005min kalender, maj 2005, som starter på en søndag, ligeså gør f.eks. januar 2006.
Mvh Bob