<?php
function weekNumber($year, $month, $day)
{
$timestamp = mktime(0,0,0, $month, $day, $year);
return date("W", $timestamp);
}
$months=array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$current_month=date('n');
$current_year=date('Y');;
$year=date('Y');
if (isset($_GET['year']))
$year = $_GET['year'];
$current_day=date('d');
$month=0;?>
<div class="calendar row">
<div class="col-xs-12"><?php echo $year ?></div>
<?php for ($row=1; $row<=3; $row++) {
for ($column=1; $column<=4; $column++) {
echo '<div class="month col-xs-12 col-sm-9 col-md-4 col-lg-4">';
$month++;
$first_day_in_month=date('w',mktime(0,0,0,$month,1,$year));
$month_days=date('t',mktime(0,0,0,$month,1,$year));
// in PHP, Sunday is the first day in the week with number zero (0)
// to make our calendar works we will change this to (7)
if ($first_day_in_month==0){
$first_day_in_month=7;
}
echo '<table>';
echo '<th colspan="7">'.$months[$month-1].'</th>';
echo '<tr class="days"><td> </td><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td>';
echo '<td class="sat">Sa</td><td class="sun">Su</td></tr>';
echo '<tr>';
// Eerste week van de maand is een speciaal geval, maar daar kunnen we gewoon de 1e van de dag invullen
$weeknum = weekNumber($year, $month, 1);
echo '<td class="week">'. $weeknum ."($year-$month-1)" .'</td>';
for($i=1; $i<$first_day_in_month; $i++) {
echo '<td> </td>';
}
$day = 0;
for($day=1; $day<=$month_days; $day++) {
$pos=($day+$first_day_in_month-1)%7;
$class = (($day==$current_day) && ($month==$current_month) && ($current_year==$year)) ? 'today' : 'day';
$class .= ($pos==6) ? ' sat' : '';
$class .= ($pos==0) ? ' sun' : '';
echo '<td class="'.$class.'">'.$day.'</td>';
// Je stelt hier het weeknummer in van de volgende week
// Echter staat $day nog op de laatste datum van de huidige week
// Je moet dus 1 bij de dag optellen
if ($pos==0)
{
echo '</tr>';
// Als de volgende week begint met de 1e van de maand wordt er een onnodige rij ingevoegd
// Daarom extra check erover!
$last_day_of_month = $month_days;
if ($day < $last_day_of_month){
$weeknum = weekNumber($year, $month, 1+$day);
echo '<tr><td class="week">'.$weeknum."($year-$month-" . (1+$day). ")" .'</td>';
}
}
}
echo '</tr>';
echo '</table>';
echo '</div>';
}
}?>