[code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<!-- ik heb wat opmaak dingetjes laten vallen... niet nodig en het wordt
  zo bont -->
	 
		 
<head>
 <style type="text/css">
  input {border : 1px #000000 solid;}
  th {background-color: #eeeeee;}
	.line {border: 3px #000000 solid;}
	.dik {font-weight:bolt ;background-color: #ffffff;}		 
  </style>
  <title>Calendar 2.0</title>
</head>

<?php

$table = "bbhc_calendar";

/* voordat we verder gaan, eerst even de structuur van de tabel printen:
 copy-paste dit maar in je phpmyadmin of mysql-control-center
 
# phpMyAdmin MySQL-Dump
# version 2.2.3
# http://phpwizard.net/phpMyAdmin/
# http://phpmyadmin.sourceforge.net/ (download page)
#
# Host: localhost
# Generatie Tijd: May 04, 2004 at 08:10 PM
# Server versie: 3.23.49
# PHP Versie: 4.1.2
# Database : `gius`
# --------------------------------------------------------

#
# Tabel structuur voor tabel `bbhc_calendar`
#

CREATE TABLE bbhc_calendar (
  date date NOT NULL default '2000-00-00',
  body blob NOT NULL,
  PRIMARY KEY  (date)
) TYPE=MyISAM;

INSERT INTO bbhc_calendar (date, body) values ('2004-01-01','Nieuwjaarsdag');
INSERT INTO bbhc_calendar (date, body) values ('2004-12-24','Eerste Kerstdag');
INSERT INTO bbhc_calendar (date, body) values ('2004-12-25','Tweede Kerstdag');
INSERT INTO bbhc_calendar (date, body) values ('2004-05-04','Datum dat ik deze kalender gepost heb, groeten van Remi');

*/


function alias($monthnr){

//------------- 
// pre: monthnr is een integer 
// post: retourneerd de naam van de maand 

  switch ($monthnr){
     case "01": return "Januari";
     case "02": return "Februari";
     case "03": return "Maart";
     case "04": return "April";
     case "05": return "Mei";
     case "06": return "Juni";
     case "07": return "Juli";
     case "08": return "Augustus";
     case "09": return "September";
     case "10": return "Oktober";
     case "11": return "November";
     case "12": return "December";				
     }	//einde switch
}// einde function alias

function calendar($day,$month,$year,$mode){

/*------------- 
 pre: - 
 post: retourneerd een overzicht van een maand met wat knopjes
 			 als mode = 0 dan niets bijzonders
			 als mode = 1 extra invoerveld voor de datum 
*/
  // eerst zorgen we dat de gearceerde dag vaststaat in $today
	$today=$day;

	// handig als we weten op welke weekdag de maand begint
  $firstdayofthemonth= date ("w", mktime(0, 0, 0, $month, 0, $year));
	
	// dus hoeveel moeten we printen van de vorige maand?
  $dayforloop = 1 - $firstdayofthemonth;
	
  // de laatste dag van de maand is het getal...
  $lastdayofthemonth= date ("d", mktime(0, 0, 0, $month+1, 0, $year));
	
	// de laatste dag van de maand valt op een ...	
  $endweekday =	date ("w", mktime(0, 0, 0, $month+1, -1, $year));
	
	// als de laatste dag van de maand niet op een zondag valt...
	if (!($endweekday==6))
	  
		// dan moeten we zoveel rotzooi van de volgende maand weergeven:
	  $endday = $lastdayofthemonth + (6-$endweekday);
	
	// in elk ander geval: (de volgende maand begint op een volgende regel)
	else $endday = $lastdayofthemonth;
  
	//echo "laatste dag: $lastdayofthemonth, doornummeren tot: $endday";
	
  echo "<form method=\"post\">";
	echo "<input type=\"hidden\" name=\"day\" value=\"$day\"></input>";
	echo "<input type=\"hidden\" name=\"month\" value=\"$month\"></input>";
	echo "<input type=\"hidden\" name=\"year\" value=\"$year\"></input>";
		  
  echo "<table class=\"line\" border=\"0\" cellpadding=\"03\" cellspacing=\"0\">";
	
  echo "<tr><th align=\"center\" colspan=\"6\"><input type=\"text\" align=\"center\" name=\"date\" value=\"".
			 date ("d/m/y", mktime(0, 0, 0, $month, $day, $year))."\"></input></th><th>".
			 "<input type=\"submit\" name=\"button\" title=\"Go to this date\" value=\"go\"></input>".
			 "</th></tr>";
	
	echo "<tr><th colspan=\"7\">".alias($month)."/$year</th></tr>";
			 
  echo "<tr>
  		  <th align=\"center\">ma </th>
  			<th align=\"center\">di </th>
  			<th align=\"center\">wo </th>
  			<th align=\"center\">do </th>
  			<th align=\"center\">vr </th>
  			<th align=\"center\">za </th>
  			<th align=\"center\">zo </th>
  			</tr>";
  echo "<tr>";

	
  while ($dayforloop<=$endday){
   $body = get_body("$year-$month-$dayforloop");
	 // als de dag niet bij de huidige maand hoort, andere kleur geven
	 if ( ($dayforloop<=0)|(($dayforloop-1)>=$lastdayofthemonth) ) {echo "<td align=\"center\">";
	   echo "<font color=\"#dddddd\">".date ("d", mktime(0, 0, 0, $month, $dayforloop, $year))."</font></td>";}

   
	
	 /*als het vandaag is, dan een mooi randje om de cel maken	 
	 elseif ($dayforloop==$today){ 
	   echo "<td class=\"line\" align=\"center\">";
	   echo "<input title=\"on selected date is no entry\" name=\"this_date\" type=\"submit\" value=\"".
		 date ("d", mktime(0, 0, 0, $month, $dayforloop, $year)).
		 "\"></input></td>";
	   }*/
		 
     // zoniet, dan printen met button	 
	 	 else {
		   echo "<td align=\"center\"";
			 
			 // als het vandaag is, dan een mooi randje om de cel maken
			 if ($dayforloop==$today) echo " class=\"line\" ";
			 echo " ><input ";
			 if (!($body=="no entry")) echo " class=\"dik\" ";
			 echo "title=\"$body\" name=\"this_date\" type=\"submit\" value=\"".
			 date ("d", mktime(0, 0, 0, $month, $dayforloop, $year))."\"></input></td>";
     }
		
	 // wel of niet een nieuwe tablerow starten
	 if (date ("w", mktime(0, 0, 0, $month, $dayforloop, $year))==0)
	 if (($endday>=dayforloop)|(date("w",mktime(0,0,0,$month,$endday,$year))==0)) 
	   echo"</tr>";
	 else echo"</tr><tr>";

   	$dayforloop++; // niet vergeten op te hogen
  }// einde while lus
	
	// nog wat knopjes voor navigatie
	if ($mode=="1"){
	  echo "<tr><td colspan=\"7\"><textarea name=\"body\" rows=\"3\">".get_body("$year-$month-$today")."</textarea></td></tr>";
		echo "<tr><td colspan=\"7\" align=\"center\"><input type=\"submit\" name=\"button\" value=\"edit\"></input></td></tr>";
	}

	echo "<tr><th><input type=\"submit\" title=\"go to previous month\" name=\"button\" value=\"&lt;\"></input></th>";
  echo "<th align=\"center\" colspan =\"5\"><input type=\"submit\" title=\"go to today\" name=\"button\" value=\"today\"></input></th>";
  echo "<th><input type=\"submit\" title=\"go to next month\" name=\"button\" value=\"&gt;\"></input></th>";
  echo "</tr>";
	
  echo "</table>";
	echo "</form>";
}

function edit_date($date,$body){
//------------------------------------
//pre: - 
//post: print een formulier om de inhoud van de datum aan te passen

  // verbinding maken
	connect2db();
	
	// lege records afvangen
	if (($body=="")|($body=="no entry")){ 
		$query = "delete from bbhc_calendar where date = \"$date\"";
		mysql_query($query) or die ("Delete failed: $query");
	} 
	
	//kijken of het update of insert is
	$query = "select * from bbhc_calendar where date=\"$date\"";
	$result = mysql_query($query) or die ("Update failed");
	if (mysql_num_rows($result)==0){
	  $query = "insert into bbhc_calendar (body,date) values (\"$body\",\"$date\")";
		mysql_query($query) or die ("Insert failed: $query");
	}	 
	else { 
	  $query = "update bbhc_calendar set body= \"$body\" where date =\"$date\"";
		mysql_query($query) or die ("Update failed: $query");
	}
}

function get_body($date){
  /*------------------------------------
  pre: - 
  post: geeft een array terug met een resultset van alle data
*/
	  // maak verbinding:
  	connect2db();
	
  $query = "select body from bbhc_calendar where date=\"$date\"";
	$result = mysql_query($query) or die ("Query failed");
	$body = mysql_fetch_array($result);
	if ($body[0]==null) return "no entry"; 
	else return $body[0];
}


function connect2db(){
  
	$user="user";
  $pass="password";
  $db="db";
  $host="localhost";
	
  // ----------
	// pre: -
	// post: maakt verbinding met de database
	
  if (!@mysql_select_db("$db", @mysql_connect("$host", "$user", "$pass"))) { 
    echo "Er kon geen connectie worden gemaakt met de database."; 
    exit(); 
  }
}

////////////////// 
// main 
////////////////// 

// formulier afvangen

// datums afvangen
if (isset($_POST['this_date'])){ 
	 calendar(substr($_POST['this_date'],0,2),substr($_POST['date'],3,2),
		  substr($_POST['date'],6,2),1);
  }
else switch ($_POST['button']){
  case "<":
	  //down
		if ($_POST['month']==1) {$month=12; $year=$_POST['year']-1; $year="0".$year;}
		else {$month = $_POST['month']-1; $year=$_POST['year'];}
		calendar($_POST['day'],$month,$year,0);
	  break;
	case ">":
	  //up
		if ($_POST['month']==12) {$month=1; $year=$_POST['year']+1;$year="0".$year;}
		else {$month = $_POST['month']+1; $year=$_POST['year'];}
		calendar($_POST['day'],$month,$year,0);
	  break;
	case "today":
	  calendar(date("d"),date("m"),date("y"),0);
	  break;
	case "go":
		calendar(substr($_POST['date'],0,2),substr($_POST['date'],3,2),
		  substr($_POST['date'],6,2),0);
		break;
	case "edit": 
	  edit_date(substr($_POST['date'],6,2)."-".substr($_POST['date'],3,2).
		  "-".substr($_POST['date'],0,2),$_POST['body']);
		calendar(substr($_POST['date'],0,2),substr($_POST['date'],3,2),
		  substr($_POST['date'],6,2),0);
		break;	 	
	default:

	  calendar(date("d"),date("m"),date("y"),0);
	  break;
}
?>[/code]
