Kalenderwoche neben Kalender einfügen

jatop

Mitglied
Hallo!

Ich habe ein Kalender! *freu* :)

PHP:
<?php
   $today = date(d);
   $days = date(t);
   $month = date(m);
   $year = date(y);
   $firstday = mktime(0,0,1,$month,1,$year);
   $lastday = mktime(0,0,1,$month,$days,$year);
   $first = date(w,$firstday);
   $last = date(w,$lastday);
   $diff = 7-$last;
   $jahr = date(Y);   

   $months = array("Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");

   $monat  = $months[date("n", time())-1];
   if($first == 0) $first = 7;   
   if($last == 0) $last = 7;

   for($i=1;$i<$first;$i++) {
   $begin.= "<td>-</td>";
   } 
   for($i=0;$i<$diff;$i++) {
   $end.= "<td></td>";    
   }
   echo "<table border= '0' cellspacing= '0' cellpadding= '1 '>
            <colgroup>
            <col width= '22 '>			
            <col width= '22 '>
            <col width= '22 '>
            <col width= '22 '>
            <col width= '22 '>
            <col bgcolor=\"#CCCCCC\" width= '22 '>
            <col bgcolor=\"#CCCCCC\" width= '22 '>			
         </colgroup>
        <tr bgcolor= '#FFCC00 '>
           <th>Mo</th>
           <th>Di</th>
           <th>Mi</th>
           <th>Do</th>
           <th>Fr</th>
           <th bgcolor=\"#FF0000\">Sa</th>
           <th bgcolor=\"#FF0000\">So</th>
        </tr><tr>
        $begin";		 															   
   for($i=1;$i<($days+1);$i++) {
      if($first==0):
         echo "<tr>";
		 endif;
      if($i == $today) {
         echo "<td align='center' bordercolor=\"#FF0000\" bgcolor='red' border=\"1\">$i</td>";
      }
	    else {
         echo "<td align= 'center'>$i</td>";
     }
      if($first==7):
      echo "</tr>";
	  $first=0;
      endif;
      $first++;   
 }
 echo "$end</tr>";
echo "<tr bgcolor='#FFCC00'><td colspan='7' align='center'><b>$monat $jahr</b></td></tr>";
echo "</table>";
?>

und ich habe ein script zum anzeigen der Kalenderwoche

PHP:
<?php
//aktuelle Kalenderwoche ausgeben
function date2timestamp ($a = '') {
       if (empty($a)) return;
	   $a = explode ('.', $a);
	   return mktime (0,0,0, $a[1], $a[0], $a[2]);
} 
$tst = date2timestamp(date('d.m.Y')); 
printf ('%s)', // hab das überflüssige was nach s stand entfernt, nämlich: Kalenderwoche (%s - %s)
date('W', $tst),
date('d.m.Y', strtotime ("last Sunday", $tst)),
date('d.m.Y', strtotime ("+6 day", $tst))); 
?>

Wie mache ich das nun so, das im Kalender die Kalenderwoche angezeigt wird? (in der ersten Zelle, also vor Montag)



Vielen Dank im Vorraus
 
Zuletzt bearbeitet:
Mein Vorschlag:
PHP:
<?php

	$month = date('m');
	$year  = date('Y');

	$firstdate = mktime(0, 0, 0, $month, 1, $year);
	$lastdate  = mktime(0, 0, 0, $month, date('t', $firstdate), $year);
  
	$monthNames = array('Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember');
	$trans = array(6, 0, 1, 2, 3, 4, 5);

?>
<table id="calendar" border="1">
	<caption><?php echo $monthNames[(int)$month-1].' '.$year; ?></caption>
	<thead>
		<tr>
			<th scope="col" title="Kalenderwoche">W</th>
			<th scope="col" title="Montag">Mo</th>
			<th scope="col" title="Dienstag">Di</th>
			<th scope="col" title="Mittwoch">Mi</th>
			<th scope="col" title="Donnerstag">Do</th>
			<th scope="col" title="Freitag">Fr</th>
			<th scope="col" title="Samstag">Sa</th>
			<th scope="col" title="Sonntag">So</th>
		</tr>
	</thead>
	<tbody>
<?php

	for( $i=-$trans[date('w', $firstdate)]; $i<date('t', $firstdate); ) {
		$woy = date('W', mktime(0, 0, 0, $month, $i<0 ? 1 : $i+1, $year));
		echo '		<tr title="'.$woy.'. Kalenderwoche">';
		echo '<th scope="row">'.$woy.'</th>';
		for( $j=0; $j<7; $j++ ) {
			$i++;
			if( $i <= 0 || $i > date('t', $firstdate) ) {
				echo '<td></td>';
				continue;
			}
			if( mktime(0, 0, 0, $month, $i, $year) == mktime(0, 0, 0, date('m'), date('d'), date('Y')) ) {
				echo '<td id="today" title="heutiges Datum">'.$i.'</td>';
			} else {
				echo '<td>'.$i.'</td>';
			}
		}
		echo '</tr>'."\n";
	}

?>
	</tbody>
</table>
 
Zurück