<?php $fileinfo = "kalender.php created 03 Jan 08 14:08:24 by thk
      Time-stamp: <2017-01-09 21:22:30 thk>";
  $LastChangeTime = $fileinfo;
  $LastChangeTime = preg_replace("/^[^<]+<([0-9-]+ [0-9:]+).*$/i","\\1",$LastChangeTime);
  $Creator = "Thomas Krauß";
  $Titel = "Kalender";
  $RightBox = "../sgs/inc/terminebox.php";
  include("header.php");
  // include("inc/db.php");
  $db = new dbclass;

  print "<h2>Kalender ".($actm>0 ? $monate[$actm-1]:"")." ".$acty."</h2>\n";
  print <<<EOT
<script language="JavaScript"><!--
function showinfo(e,text)
{ eid = document.getElementById("infobox");
  if (text)
  { // eid.position = "absolute";
    // eid.left = e.clientX+"px";
    // eid.top = e.clientY+"px";
    eid.innerHTML = text;
  }
}
//--></script>
EOT;

  print "<p class=klein align=center>";
  for ($i=0; $i<12; $i++)
  { if ($i!=$actm-1) print "<a href=\"$myname?datum=".sprintf("%04d%02d%02d",$acty,$i+1,1)."\">";
    print $monate[$i];
    if ($i!=$actm-1) print "</a>";
    print " &nbsp; ";
  }
  print "<a href=\"$myname?datum=".sprintf("%04d%02d%02d",$acty,0,0)."\">Jahres&uuml;bersicht</a>";
  print "<br>";
  for ($i=$acty-5; $i<=$acty+5; $i++)
  { if ($i!=$acty) print "<a href=\"$myname?datum=".sprintf("%04d%02d%02d",$i,$actm,1)."\">";
    print $i;
    if ($i!=$acty) print "</a>";
    print " &nbsp; ";
  }
  print "</p>\n";
  getnamenstage();
  setfeiertage($acty);
  readtermine($acty);
  print "<p align=center>";
  if ($actm==0)
  { print "<table>";
    for ($actm=1; $actm<=12; $actm++)
    { if ($actm%3==1) print "<tr>";
      print "<td valign=top width=25%><p align=center>".$monate[$actm-1]." ".$acty."</p>\n";
      insertmonth($actm,$acty);
      print "</td>";
      if ($actm==3) print "<td rowspan=3 width=25%><p align=center id=\"infobox\"></p></td>";
      if ($actm%3==0) print "</tr>";
    }
    print "</table>";
  } else
  { insertmonth($actm,$acty);
    print "<p align=center id=\"infobox\"></p>\n";
  }
  
  // ksort($ft); foreach ($ft as $k=>$v) print "ft[$k] = $v<br>\n";
  include("footer.php");


function insertmonth($actm,$acty)
{ global $ft, $term, $nt, $monlen, $wochentage, $termid;

  print "<table class=tabelle><tr>";
  // style=\"color: ".wtcolor(($i+1)%7).";\"
  for ($i=0; $i<7; $i++) print "<th>".substr($wochentage[($i+1)%7],0,2)."</th>";
  print "</tr>\n";
  $wt = (wochentag(1,$actm,$acty)+6)%7;
  // print "<p class=error>Wochentag 1.$actm.$acty ist $wt = ".$wochentage[$wt]."</p>\n";

  $mon = sprintf("%04d%02d",$acty,$actm);
  print "<tr>";
  for ($i=0; $i<$wt; $i++) print "<td>&nbsp;</td>";
  for ($i=1, $tij=tagimjahr(1,$actm,$acty); $i<=$monlen[$actm-1]; $i++,$wt++, $tij++)
  { $id = $mon.sprintf("%02d",$i);
    $col = "background-color: ".(isset($ft[$tij]) ? "#ff0000":($wt>4 ? "#ffcc00":"#ffffff"))."; "; // wtcolor(($wt+1)%7)."; ";
    print "<td align=center onMouseOver=\"showinfo(event,'".$nt[substr($id,4)].
	(isset($ft[$tij]) ? "<br><i>".$ft[$tij]."</i>":"").
	(isset($term[$id]) ? "<br><br><b>".(preg_replace("/[\"\']/","&quot;",$term[$id]))."</b>\\n":"")."');\" onMouseOut=\"showinfo('');\" style=\"{$col}\"\>".
	(isset($term[$id]) ? "<a href=\"termine.php?show={$termid[$id]}\"><b>":"").$i.
	(isset($term[$id]) ? "</b></a>":"")."</td>";
    if ($wt==6) { print "</tr>\n"; if ($i<$monlen[$actm-1]) { "<tr>"; $wt=-1; } }
  }
  for (;$wt<7; $wt++) print "<td>&nbsp;</td>";
  print "</tr>\n</table>";
}


function readtermine_old()
{ global $termine, $term, $termid;

  $fn=readhead($termine);
  $maxnum=readnumds($termine);
  for ($i=1; $i<$maxnum; $i++)
  { $ds = readds($termine,$i);
    if ($ds[$fn["Flag"]]=="*")
    { if (isset($term[$ds[$fn["Datum"]]])) $term[$ds[$fn["Datum"]]].="; ";
      $term[$ds[$fn["Datum"]]] .= $ds[$fn["Text"]];
      if (isset($termid[$ds[$fn["Datum"]]])) $termid[$ds[$fn["Datum"]]].=",".$ds[$fn["ID"]];
      else $termid[$ds[$fn["Datum"]]] = $ds[$fn["ID"]];

// "Termin: <a href=\"termine.php?show=".$ds[$fn["ID"]]."\">".
// ($ds[$fn["Langtext"]]!="" ? "<b>":"").
// .($ds[$fn["Langtext"]]!="" ? "</b>":"")."</a>, ".
// ($ds[$fn["DatumText"]]!="" ? $ds[$fn["DatumText"]] :
// substr($ds[$fn["Datum"]],6,2).".".substr($ds[$fn["Datum"]],4,2).".".substr($ds[$fn["Datum"]],0,4));
    }
  }
}


function readtermine($acty)
{ global $termid, $db, $term;

  $datelim="";
  if ($acty!=0 && $acty>1900) $datelim = " where ( Date>=".$acty."0000 and Date<".$acty."9999 ) or ( EndDate>=".$acty."0000 and EndDate<".$acty."9999 )";

  $db->query("select ID,Date,EndDate,Text,Title from termine ".$datelim." order by Date");
  for ($i=0; $i<$db->NumRows; $i++)
  { $db->getrecord();
    $id   = $db->Record["ID"];
    $date = $db->Record["Date"]."";
    $text = $db->Record["Title"];
    if (isset($term[$date])) $term[$date].="<br>".$text;
    else $term[$date] = $text;
    if (isset($termid[$date])) $termid[$date].=",".$id;
    else $termid[$date] = $id;
  }
}

?>
