// databasequery.inc
[code]
CREATE TABLE `gastenboek` (
`ip` varchar( 20 ) NOT NULL default '',
`id` int( 50 ) NOT NULL AUTO_INCREMENT ,
`bericht` text NOT NULL ,
`auteur` varchar( 250 ) NOT NULL default '',
`email` varchar( 250 ) NOT NULL default '',
`datum` varchar( 23 ) NOT NULL default '',
PRIMARY KEY ( `id` )
) TYPE = MYISAM;
[/code]

// dbconnect.php

<?
$gebruiker = "user";
$wachtwoord = "pass";
$database = "database";
$host = "localhost";

mysql_connect($host, $gebruiker, $wachtwoord) or die("Er is geen connectie met de database");
mysql_select_db($database) or die("Er is geen database geselecteerd");

?>


// gastenboek.php

[code]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Gastenboek</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script src="scripts.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php

// Database gegevens includen.
include('dbconnect.php');

$ip = $_SERVER['REMOTE_ADDR']; 

// Alternating row kleuren.
$color1 = "#222222";
$color2 = "#333333";
$row_count = 0; 

// Het indelen in pagina's.
$max_b = "10";
$result = mysql_query("SELECT COUNT(id) FROM gastenboek");
$aantal = mysql_result($result, 0);
$paginas = ceil($aantal/$max_b);

// Als p ingesteld is, stel dan start waarde in.
if(isset($_GET['p'])) {
	// Kijken of p nummeriek is.
	if(is_numeric($_GET['p'])) {
	   $page = $_GET['p'];
	  $start = addslashes(($_GET['p']-1)*$max_b);
	}
	else {
	    $page = 1;
	    $start = 0;
	}
}
else {
    $page = 1;
    $start = 0;
}

// Pagina links maken.
$p = "";
for($a = 1; $a <= $paginas; $a++)  {
    // Kijken of dit de huidige pagina is
    if($page == $a) {
        $p .= $a.' ';
    }
    // Is het dan niet dan word het een linkje
    else {
        $p .= '<a href="gastenboek.php?p='.$a.'">'.$a.'</a> ';
    }
}

// Haal de berichten op.
$sql_g = "SELECT * FROM gastenboek ORDER BY datum DESC LIMIT ".$start." , ".$max_b."";
$res_g = mysql_query($sql_g);

echo "Welkom in het gastenboek<br /><br /><hr>";
echo "".$p."<hr>";

// Laat alle berichten zien.
if (mysql_num_rows($res_g) >= 1) {
	echo "<table width=\"500\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
	while ($row = mysql_fetch_array($res_g)) {
		$bericht = $row['bericht'];
		$g_datum = $row['datum'];
		$g_auteur = $row['auteur'];
		$g_email = $row['email'];
		$row_color = ($row_count % 2) ? $color1 : $color2;
		

		// Als er geen emailadres is, dan word er geen link gemaakt.
		if(empty($g_email)){
			$auteurmail = "".$g_auteur."";
		} 
		else {
			$auteurmail = "<a href=\"mailto:".$g_email."\">".$g_auteur."</a>";
        }
		// Het bericht.
		echo "<tr><td style=\"border-bottom: 1px solid Black; padding: 5px\" bgcolor=\"$row_color\">";
		echo "<b>".$auteurmail."</b> op ".$g_datum."<br />";
		echo "".$bericht."<br /></td></tr>";

		$row_count++;
	}
	echo "</table>";
} 
else {
	echo "Er zijn geen berichten in het gastenboek<br /><br />";
}

// Laat het formulier zien.
?>
<hr><br /><form method="post" name="addbericht" action="bericht.php">
<input type="hidden" value="<?php echo "".$ip."" ?>" name="ip">
Naam:<br /><input type="text" name="auteur"><br />
Email:<br /><input type="text" name="email"><br />
Bericht:<br /><table border="0" cellpadding="0" cellspacing="0"><tr><td><textarea rows="4" name="bericht" cols="22"></textarea></td><td style="width: 5px"></td>
<td><img style="margin: 1px; margin-left: 0px" onMouseover="this.style.cursor='pointer'" onClick="sendtext(document.addbericht.bericht, ':)')" src="images/smilies/smile.gif" alt="Emoticon">
<img style="margin: 1px" onMouseover="this.style.cursor='pointer'" onClick="sendtext(document.addbericht.bericht, ':D')" src="images/smilies/biggrin.gif" alt="Emoticon">
<img style="margin: 1px" onMouseover="this.style.cursor='pointer'" onClick="sendtext(document.addbericht.bericht, ':p')" src="images/smilies/tongue.gif" alt="Emoticon">
<img style="margin: 1px" onMouseover="this.style.cursor='pointer'" onClick="sendtext(document.addbericht.bericht, ':(')" src="images/smilies/sad.gif" alt="Emoticon">
<img style="margin: 1px" onMouseover="this.style.cursor='pointer'" onClick="sendtext(document.addbericht.bericht, ';)')" src="images/smilies/wink.gif" alt="Emoticon">
<img style="margin: 1px" onMouseover="this.style.cursor='pointer'" onClick="sendtext(document.addbericht.bericht, ':angry')" src="images/smilies/angry.gif" alt="Emoticon"><br />
<img style="margin: 1px; margin-left: 0px" onMouseover="this.style.cursor='pointer'" onClick="sendtext(document.addbericht.bericht, ':roll')" src="images/smilies/rolleyes.gif" alt="Emoticon">
<img style="margin: 1px" onMouseover="this.style.cursor='pointer'" onClick="sendtext(document.addbericht.bericht, ':kiss')" src="images/smilies/kiss.gif" alt="Emoticon">
<img style="margin: 1px" onMouseover="this.style.cursor='pointer'" onClick="sendtext(document.addbericht.bericht, ':cool')" src="images/smilies/cool.gif" alt="Emoticon">
<img style="margin: 1px" onMouseover="this.style.cursor='pointer'" onClick="sendtext(document.addbericht.bericht, ':cry')" src="images/smilies/cry.gif" alt="Emoticon">
<img style="margin: 1px" onMouseover="this.style.cursor='pointer'" onClick="sendtext(document.addbericht.bericht, ':huh')" src="images/smilies/huh.gif" alt="Emoticon">
<img style="margin: 1px" onMouseover="this.style.cursor='pointer'" onClick="sendtext(document.addbericht.bericht, ':omg')" src="images/smilies/omg.gif" alt="Emoticon"><br /><br />
<a href="javascript:popup('bbcodes.html')">BBcode</a> is ON<br />HTML is OFF</td></tr></table><br />
<input type="submit" value="Verzenden" name="submit">
</form>
</body>
</html>[/code]

// bericht.php

[code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Bericht</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<script src="scripts.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php

// Database gegevens includen.
include('dbconnect.php');

// Include de functies (BBcode, Mailcheck).
include('functies.php');

// Als het formulier is verzonden, voeg reactie toe in database.
if($_POST['submit']) {

	// Als auteur leeg is, auteur is anoniem.
	if(empty($_POST['auteur'])) {
	  $auteur = "Anoniem";
	} 
	else {
	  $auteur = htmlspecialchars($_POST['auteur']);
	}

	// Als er geen reactie is geschreven, geef melding en vermoord script.
	if(empty($_POST['bericht'])) {
		echo "Je moet een bericht schrijven! Klik <a href=\"gastenboek.php\">hier</a> om terug te gaan";
		die();
	} 
	else {
		$bericht = bbcode($_POST['bericht']);
    }

	// Check of het email adres klopt.
	if(checkmail($_POST['email']) == "true") {
		$email = $_POST['email'];
	}
	else {
		echo "Je hebt een vals email adres ingevuld! Klik <a href=\"gastenboek.php\">hier</a> om terug te gaan";
		die();
	}
	$ip = $_POST['ip'];
	$datum = date("d-m-Y");
	$tijd = date("H:i:s");
	$datumtijd = "".$datum." om ".$tijd."";

	// De mysql query om de reactie in db te zetten.
	$insert = mysql_query("INSERT INTO gastenboek (ip, auteur, bericht, email, datum) VALUES ('$ip', '$auteur', '$bericht', '$email', '$datumtijd')");

	// Als $insert lukt, geef melding, anders geef error
    if($insert) {
		echo "Uw bericht is succesvol toegevoegd, klik <a href=\"gastenboek.php\">hier</a> om terug te gaan";
    } 
	else {
		echo "Er is iets misgegaan, uw bericht is niet toegevoegd";
    }
}
?>
</body>
</html>[/code]


// functies.php

[code]<?
function bbcode($reactie) {
	$reactie = nl2br(htmlspecialchars($reactie));

	$bbcode = array(
		"'\[b\](.*?)\[/b\]'",
		"'\[i\](.*?)\[/i\]'",
		"'\[u\](.*?)\[/u\]'",
		"'\[img\](.*?)\[/img\]'",
		"'\[url=(.*?)\](.*?)\[/url\]'",
		"'\[url\](.*?)\[/url\]'",
		"'\[email=(.*?)\](.*?)\[/email\]'",
		"'\[email\](.*?)\[/email\]'",
		"':p'",
		"':\('",
		"':\)'",
		"':D'",
		"';\)'",
		"':roll'",
		"':kiss'",
		"':angry'",
		"':cry'",
		"':huh'",
		"':omg'",
		"':cool'"
	);

	$html = array(
		"<b>\\1</b>", 
		"<i>\\1</i>", 
		"<u>\\1</u>", 
		"<img border=\"0\" src=\"\\1\">", 
		"<a href=\"\\1\" target=\"_blank\">\\2</a>", 
		"<a href=\"\\1\" target=\"_blank\">\\1</a>", 
		"<a href=\"mailto:\\1\">\\2</a>", 
		"<a href=\"mailto:\\1\">\\1</a>", 
		"<img src=\"images/smilies/tongue.gif\" style=\"margin: 1px; \" alt=\"Emoticon\">", 
		"<img src=\"images/smilies/sad.gif\" style=\"margin: 1px; \" alt=\"Emoticon\">", 
		"<img src=\"images/smilies/smile.gif\" style=\"margin: 1px; \" alt=\"Emoticon\">", 
		"<img src=\"images/smilies/biggrin.gif\" style=\"margin: 1px; \" alt=\"Emoticon\">", 
		"<img src=\"images/smilies/wink.gif\" style=\"margin: 1px; \" alt=\"Emoticon\">", 
		"<img src=\"images/smilies/rolleyes.gif\" style=\"margin: 1px; \" alt=\"Emoticon\">", 
		"<img src=\"images/smilies/kiss.gif\" style=\"margin: 1px; \" alt=\"Emoticon\">", 
		"<img src=\"images/smilies/angry.gif\" style=\"margin: 1px; \" alt=\"Emoticon\">", 
		"<img src=\"images/smilies/cry.gif\" style=\"margin: 1px; \" alt=\"Emoticon\">", 
		"<img src=\"images/smilies/huh.gif\" style=\"margin: 1px; \" alt=\"Emoticon\">", 
		"<img src=\"images/smilies/omg.gif\" style=\"margin: 1px; \" alt=\"Emoticon\">", 
		"<img src=\"images/smilies/cool.gif\" style=\"margin: 1px; \" alt=\"Emoticon\">" 
	);

	$reactie = preg_replace($bbcode, $html, $reactie);
	return $reactie;
}

function checkmail($email)
{
    if (eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$",$email))
    {
        $valid = "true";
    }
    else
    {
        $valid = "false";
    }
    return $valid;
}
?>[/code]

// bbcode.html

[code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>BBcode Overzicht</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
Opmaak:
<table border="0" cellpadding="0" cellspacing="0" width="400">
  <tr>
    <td width="50%" style="border-bottom: 1px solid Black; border-bottom: 1px solid Black; padding-left: 5px;" height="35" bordercolor="#333333" bgcolor="#333333">[b] tekst [/b]</td>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px; padding-right: 5px;" height="35" bordercolor="#333333" bgcolor="#333333">Maak tekst vetgedrukt</td>
  </tr>
  <tr>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px;" height="35" bgcolor="#666666">[i] tekst [/i]</td>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px; padding-right: 5px;" height="35" bgcolor="#666666">Maak tekst schuingedrukt</td>
  </tr>
  <tr>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px;" height="35" bgcolor="#333333">[u] tekst [/u]</td>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px; padding-right: 5px;" height="35" bgcolor="#333333">Maak tekst onderlijnd</td>
  </tr>
  <tr>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px;" height="35" bgcolor="#666666">[url=http://] tekst [url]</td>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px; padding-right: 5px;" height="35" bgcolor="#666666">Maak een link, achter het = teken is de url, tussen de tags is de tekst</td>
  </tr>
  <tr>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px;" height="35" bgcolor="#333333">[url] http:// [/url]</td>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px; padding-right: 5px;" height="35" bgcolor="#333333">Maak een link zonder tekst, maar gewoon als url</td>
  </tr>
  <tr>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px;" height="35" bgcolor="#666666">[email=a@b.c] tekst [/email]</td>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px; padding-right: 5px;" height="35" bgcolor="#666666">Maak een mailto: link, achter het = teken is het emailadres, tussen de tags is de tekst</td>
  </tr>
  <tr>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px;" height="35" bgcolor="#333333">[email] a@b.c [/email]</td>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px; padding-right: 5px;" height="35" bgcolor="#333333">Maak een mailto: link zonder tekst, maar gewoon als emailadres</td>
  </tr>
  <tr>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px;" height="35" bgcolor="#666666">[img] http:// [/img]</td>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px; padding-right: 5px;" height="35" bgcolor="#666666">Laat een plaatje zien, dit plaatje moet wel op internet 
    staan</td>
  </tr>
</table>
<br>Smilies:<br>
<table border="0" cellpadding="0" cellspacing="0" width="400">
  <tr>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px;" height="35" bgcolor="#333333">:)</td>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px; padding-right: 5px;" height="35" bgcolor="#333333"><img border="0" src="images/smilies/smile.gif" width="15" height="15"> Blij</td>
  </tr>
  <tr>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px;" height="35" bgcolor="#666666">:(</td>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px; padding-right: 5px;" height="35" bgcolor="#666666"><img border="0" src="images/smilies/sad.gif" width="15" height="15"> Verdrietig</td>
  </tr>
  <tr>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px;" height="35" bgcolor="#333333">:p</td>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px; padding-right: 5px;" height="35" bgcolor="#333333"><img border="0" src="images/smilies/tongue.gif" width="15" height="15"> Steekt tong uit</td>
  </tr>
  <tr>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px;" height="35" bgcolor="#666666">:D</td>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px; padding-right: 5px;" height="35" bgcolor="#666666"><img border="0" src="images/smilies/biggrin.gif" width="15" height="15"> Lachen</td>
  </tr>
  <tr>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px;" height="35" bgcolor="#333333">;)</td>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px; padding-right: 5px;" height="35" bgcolor="#333333"><img border="0" src="images/smilies/wink.gif" width="15" height="15"> Knipoog</td>
  </tr>
  <tr>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px;" height="35" bgcolor="#666666">:roll</td>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px; padding-right: 5px;" height="35" bgcolor="#666666"><img border="0" src="images/smilies/rolleyes.gif" width="15" height="15"> Rollende ogen</td>
  </tr>
  <tr>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px;" height="35" bgcolor="#333333">:kiss</td>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px; padding-right: 5px;" height="35" bgcolor="#333333"><img border="0" src="images/smilies/kiss.gif" width="15" height="15"> Geeft kusje</td>
  </tr>
  <tr>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px;" height="35" bgcolor="#666666">:cry</td>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px; padding-right: 5px;" height="35" bgcolor="#666666"><img border="0" src="images/smilies/cry.gif" width="15" height="15"> Huilen</td>
  </tr>
  <tr>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px;" height="35" bgcolor="#333333">:cool</td>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px; padding-right: 5px;" height="35" bgcolor="#333333"><img border="0" src="images/smilies/cool.gif" width="15" height="15"> Cool</td>
  </tr>
  <tr>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px;" height="35" bgcolor="#666666">:angry</td>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px; padding-right: 5px;" height="35" bgcolor="#666666"><img border="0" src="images/smilies/angry.gif" width="15" height="15"> Boos</td>
  </tr>
  <tr>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px;" height="35" bgcolor="#333333">:huh</td>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px; padding-right: 5px;" height="35" bgcolor="#333333"><img border="0" src="images/smilies/huh.gif" width="15" height="15"> Vraagteken</td>
  </tr>
  <tr>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px;" height="35" bgcolor="#666666">:omg</td>
    <td width="50%" style="border-bottom: 1px solid Black; padding-left: 5px; padding-right: 5px;" height="35" bgcolor="#666666"><img border="0" src="images/smilies/omg.gif" width="15" height="15"> Schokkend</td>
  </tr>
</table>
</body>
</html>[/code]


// scripts.js

[code]function sendtext(e, text) {
	e.value += text
}

function popup(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=437,height=500');");
}[/code]


// style.css

[code]body {
	background: Black;
	color: White;
	font: 8pt Tahoma, Verdana, Geneva, Arial, sans-serif;
}
input {
	border: 1px solid Silver;
	background: #333333;
	color: White;
	font: 8pt Tahoma, Verdana, Geneva, Arial, sans-serif;
	margin-top: 1px;
}
textarea {
	border: 1px solid Silver;
	background: #333333;
	color: White;
	font: 8pt Tahoma, Verdana, Geneva, Arial, sans-serif;
	overflow: auto;
	height: 70px;
}
hr {
	height: 1px;
	border: 0px;
	color: White;
	background-color: White;
}
a, a:active, a:focus, a:link, a:visited{
	color: White;
	text-decoration: Underline;
}
a:hover {
	color: Silver;
	text-decoration: None;
}
table {
	font: 8pt Tahoma, Verdana, Geneva, Arial, sans-serif;
}[/code]

