<?
// ===========================
// forum in shape of guestbook
// ===========================
// variables
// set table of database
$table = "vb_forum";
// set webmaster's e-mail address
$set_email = "webmaster@domein.nl";
// set name of forum
$set_forum = "Het DOMEIN forum";
// set color for name of forum
$set_head = "<font color=\"#006600\">";
$set_head2 = "</font>";
// main topic (leave blanc for no styles)
$set_main = "<b>";
$set_main2 = "</b>";
// replies (leave blanc for no styles)
$set_reply = "";
$set_reply2 = "";
// decide date style (leave blanc for no styles)
$set_date = "<span class=\"small\"><i>";
$set_date2 = "</i></span>";
// decide name style (leave blanc for no style)
$set_name = "<font color=\"blue\">";
$set_name2 = "</font>";
// set bgcolor of active title bar
$set_title = "#cccfff";
// set bgcolor of inactive title bar
$set_titlebar = "#cccccc";
// give border color for bottom volgende/volgende page
$set_bcolor = "#000000";
// show (define here) threads per page
$set_next = "15";
// define image path ZONDER SLASH!!!!!
$set_path = "imgs";
// make database connection
$host = "localhost";
$user = "mysqluser";
$pass = "mysqlpass";
$dbdb = "databasename";
// check if database connection's valid
if (!mysql_select_db($dbdb, mysql_connect($host, $user, $pass)))
{
echo "Er kon geen connectie gemaakt worden met de database.<P>";
echo "Probeer het opnieuw, of waarschuw de webmaster op $set_email.<p>";
exit();
}
// echo name of forum
echo "<h2>$set_head" . "$set_forum" . "$set_head2</h2>";
if (!$_GET["cat"])
$cat = 1;
else
$cat = $_GET[cat];
echo "<table width=\"500\" border=\"0\" cellspacing=\"10\" cellpadding=\"0\">";
echo "<tr valign=\"top\">";
echo "<td width=\"10%\">";
//===============================
// show overview
//===============================
if (!$_GET["id"] && !$_GET["add"] && !$_POST["add"] && !$_POST["id"])
{
// set threads
if (!$_GET["p"])
$p = "0";
else
$p = $_GET[p];
echo "<p><a href=" . $_SERVER['PHP_SELF'] . "?add=1>Voeg een nieuw bericht toe</a></p>";
// check for threads
$sql = "select id from $table where rid = '' and cat = $cat";
$res = mysql_query($sql);
$threads = mysql_num_rows($res);
// unset vars
$sql = "";
$res = "";
// show topics with replies
$sql = "SELECT * FROM $table WHERE rid = '' AND cat = '$cat' ORDER BY id DESC LIMIT $p,$set_next";
$res = mysql_query($sql);
$thispage = mysql_num_rows($res);
// show vorige / volgende
if (($threads > $p) && ($thispage >= $set_next))
{
echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";
echo "<tr>";
echo "<td align=left>";
if (!$p)
echo "<a href=" . $_SERVER['PHP_SELF'] . "?p=$set_next&cat=$cat><img src=$set_path/arrow_left.gif border=0></a> <a href=\"" . $_SERVER['PHP_SELF'] . "?p=$set_next&cat=$cat\">vorige</a>";
else
{
$next = $p - $set_next;
$p = $p + $set_next;
echo "<a href=" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat><img src=$set_path/arrow_left.gif border=0></a> <a href=\"" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat\">vorige</a> | ";
echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=$next&cat=$cat\">volgende</a> <a href=" . $_SERVER['PHP_SELF'] . "?p=$next&cat=$cat><img src=$set_path/arrow.gif border=0></a>";
}
echo "</tr>";
echo "</table><p>";
}
elseif ($p)
{
echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";
echo "<tr>";
echo "<td align=left>";
$p = $p - $set_next;
echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat\">volgende</a> <a href=" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat><img src=$set_path/arrow.gif border=0></a>";
echo "</td></tr>";
echo "</table>";
}
// begin table for threads
echo "<table width=\"100%\" border=\"1\" cellpadding=\"8\" cellspacing=\"0\">";
echo "<tr>";
echo "<td>";
echo "<table border=0 cellspacing=0 cellpadding=0>\n";
// loop trough results
while ($row = mysql_fetch_array($res))
{
$row[title] = htmlentities($row[title]);
$row[title] = nl2br($row[title]);
$row[name] = htmlentities($row[name]);
$row[name] = nl2br($row[name]);
echo "<tr><td colspan=\"2\">$set_main<a href=\"" . $_SERVER['PHP_SELF'] . "?id=$row[id]&p=$p&cat=$cat\">$row[title]</a>$set_main2 - $set_name" . "$row[name]" . "$set_name2 $set_date" . "$row[date]" . "$set_date2</td></tr>\n";
$r_sql = "SELECT * FROM $table WHERE rid = $row[id] AND cat = $cat ORDER BY id";
$r_res = mysql_query($r_sql);
if ($r_res)
{
while ($r_row = mysql_fetch_array($r_res))
{
$r_row[title] = htmlentities($r_row[title]);
$r_row[title] = nl2br($r_row[title]);
$r_row[name] = htmlentities($r_row[name]);
$r_row[name] = nl2br($r_row[name]);
echo "<tr><td> </td><td>$set_reply<a href=\"" . $_SERVER['PHP_SELF'] . "?id=$r_row[id]&rid=$r_row[rid]&p=$p&cat=$cat\">$r_row[title]</a>$set_reply2 - $set_name" . "$r_row[name]" . "$set_name2 $set_date" . "$r_row[date]" . "$set_date2</td></tr>\n";
}
}
echo "<tr><td colspan=\"2\"> </td></tr>\n";
}
echo "</table>\n";
echo "</td></tr></table>";
// show vorige / volgende
if (($threads > $p) && ($thispage >= $set_next))
{
echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";
echo "<tr>";
echo "<td align=left>";
if (!$p)
echo "<a href=" . $_SERVER['PHP_SELF'] . "?p=$set_next&cat=$cat><img src=$set_path/arrow_left.gif border=0></a> <a href=\"" . $_SERVER['PHP_SELF'] . "?p=$set_next&cat=$cat\">vorige</a>";
else
{
echo "<a href=" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$_GET[cat]><img src=$set_path/arrow_left.gif border=0></a> <a href=\"" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat\">vorige</a> | ";
echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=$next&cat=$_GET[cat]\">volgende</a> <a href=" . $_SERVER['PHP_SELF'] . "?p=$next&cat=$_GET[cat]><img src=$set_path/arrow.gif border=0></a>";
}
echo "</tr>";
echo "</table><p>";
}
elseif ($p)
{
echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";
echo "<tr>";
echo "<td align=left>";
echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat\">volgende</a> <a href=" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat><img src=$set_path/arrow.gif border=0></a>";
echo "</td></tr>";
echo "</table>";
}
}
//===============================
// show details
//===============================
elseif ($_GET["id"] && !$_GET["add"] && !$_POST["add"])
{
$sql = "select * from $table where id = $id";
$res = mysql_query($sql);
$row = mysql_fetch_array($res);
$holdid = $row[id];
$row[msg] = htmlentities($row[msg]);
$row[msg] = nl2br($row[msg]);
$row[title] = htmlentities($row[title]);
$row[title] = nl2br($row[title]);
$row[name] = htmlentities($row[name]);
$row[name] = nl2br($row[name]);
if (!$row[email] || !strpos($row[email], "@") && !is_numeric($row[email]))
$author = "$row[name]";
elseif (is_numeric($row[email]))
$author = "<a href=\"$path/profile/?id=$row[email]\">$row[name]</a>";
else
$author = "<a href=\"mailto:$row[email]\">$row[name]</a>";
if ($rid)
$holdit = $rid;
else
$holdit = $id;
echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";
echo "<tr>";
echo "<td align=left><a href=" . $_SERVER['PHP_SELF'] . "?add=1&id=$holdit&p=$p&cat=$cat><img src=$set_path/arrow.gif border=0></a> <a href=\"" . $_SERVER['PHP_SELF'] . "?add=1&id=$holdit&p=$p&cat=$cat\">Reageer op dit bericht</a></td>";
echo "</tr>";
echo "</table><p>";
echo "<table width=\"100%\" border=\"1\" cellpadding=\"8\" cellspacing=\"0\">";
echo "<tr>";
echo "<td>";
echo "<table border=0 cellspacing=0 cellpadding=0 width=\"100%\">";
echo "<tr><td height=\"20\" bgcolor=\"$set_title\"><b>$row[title] | $author | $row[date]</b></td></tr>";
echo "<tr><td>$row[msg]</td></tr>";
echo "</table><p>";
echo "</td></tr></table><p>";
$sql = "";
$res = "";
$row = "";
echo "<table border=0 cellspacing=0 cellpadding=0 width=\"100%\">";
echo "<tr><td height=\"20\" bgcolor=\"$set_titlebar\">Berichten overzicht</td></tr>";
// get main topic
if ($rid)
$h_sql = "select id,title,name,date from $table where id = $rid AND cat = '$cat'";
else
$h_sql = "select id,title,name,date from $table where id = $holdid AND cat = '$cat'";
$h_res = mysql_query($h_sql);
$h_row = mysql_fetch_array($h_res);
$h_row[title] = htmlentities($h_row[title]);
$h_row[title] = nl2br($h_row[title]);
$h_row[name] = htmlentities($h_row[name]);
$h_row[name] = nl2br($h_row[name]);
if ($h_row[id] == $holdid)
echo "<tr><td><img src=\"$set_path/arrow.gif\"> $set_reply<a href=\"" . $_SERVER['PHP_SELF'] . "?id=$h_row[id]&rid=$h_row[rid]&p=$p&cat=$cat\">$h_row[title]</a>$set_reply2 - $set_name" . "$h_row[name]" . "$set_name2 $set_date" . "$h_row[date]" . "$set_date2</td></tr>\n";
else
echo "<tr><td>$set_reply<a href=\"" . $_SERVER['PHP_SELF'] . "?id=$h_row[id]&rid=$h_row[rid]&p=$p&cat=$cat\">$h_row[title]</a>$set_reply2 - $set_name" . "$h_row[name]" . "$set_name2 $set_date" . "$h_row[date]" . "$set_date2</td></tr>\n";
// mysql for reactions
if ($rid)
$sql = "select id,title,name,date,rid from $table where rid = $rid and cat = $cat ORDER BY id";
else
$sql = "select id,title,name,date,rid from $table where rid = $id and cat = $cat ORDER BY id";
$res = mysql_query($sql);
if (mysql_num_rows($res) >= 1)
{
while ($row = mysql_fetch_array($res))
{
$row[title] = htmlentities($row[title]);
$row[title] = nl2br($row[title]);
$row[name] = htmlentities($row[name]);
$row[name] = nl2br($row[name]);
// show reactions on it
if ($row[id] == $holdid)
echo "<tr><td><img src=\"$set_path/arrow.gif\"> $set_reply<a href=\"" . $_SERVER['PHP_SELF'] . "?id=$row[id]&rid=$row[rid]&p=$p&cat=$cat\">$row[title]</a>$set_reply2 - $set_name" . "$row[name]" . "$set_name2 $set_date" . "$row[date]" . "$set_date2</td></tr>\n";
else
echo "<tr><td>$set_reply<a href=\"" . $_SERVER['PHP_SELF'] . "?id=$row[id]&rid=$row[rid]&p=$p&cat=$cat\">$row[title]</a>$set_reply2 - $set_name" . "$row[name]" . "$set_name2 $set_date" . "$row[date]" . "$set_date2</td></tr>\n";
}
}
else
{
echo "<tr><td> </td></tr>";
echo "<tr><td><b><i>Er zijn nog geen reacties op dit bericht</a></td></tr>\n";
}
echo "</table>";
echo "<p> </p>";
if ($rid)
$holdit = $rid;
else
$holdit = $id;
echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";
echo "<tr>";
echo "<td align=left><a href=" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat><img src=$set_path/arrow_left.gif border=0></a> <a href=\"" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat\">Vorige pagina</a> <a href=" . $_SERVER['PHP_SELF'] . "?add=1&id=$holdit&p=$p&cat=$cat><img src=$set_path/arrow.gif border=0></a> <a href=\"" . $_SERVER['PHP_SELF'] . "?add=1&id=$holdit&p=$p&cat=$cat\">Reageer op dit bericht</a></td>";
echo "</tr>";
echo "</table><p>";
}
//===============================
// add thread or reply
//===============================
elseif ($_GET["add"] || $_POST["add"])
{
if ($_POST["submit"] && ($_POST["name"] && $_POST["title"] && $_POST["msg"]))
{
// set date
$date = date("d.m.Y [H:i]");
$sql = "INSERT INTO $table (id, name, email, title, msg, date, rid, cat) VALUES ('', '$_POST[name]', '$POST[email]', '$_POST[title]', '$_POST[msg]', '$date', '$rid', '$cat')";
$res = mysql_query($sql);
if ($res)
{
echo "<table width=\"100%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">";
echo "<tr>";
echo "<td>";
echo "Bedankt voor je bericht <b>$_POST[name]</b>!!<p>";
if ($rid)
echo "<a href=" . $_SERVER['PHP_SELF'] . "?p=$p&id=$rid&cat=$cat><img src=$set_path/arrow_left.gif border=0></a> <a href=" . $_SERVER['PHP_SELF'] . "?id=$rid&p=$p&cat=$cat>Ga terug naar het bericht</a>";
else
echo "<a href=" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat><img src=$set_path/arrow_left.gif border=0></a> <a href=" . $_SERVER['PHP_SELF'] . "?p=$p&cat=$cat>Ga terug naar de berichten</a>";
echo "</td>";
echo "</tr>";
echo "</table><p>";
}
else
{
echo "Je bericht kon niet worden toegevoegd, probeer het opnieuw.";
}
}
else
{
if ($_GET["id"] || $_POST["id"])
{
if ($_GET["id"])
$sql = "SELECT title FROM $table WHERE id = $_GET[id]";
else
$sql = "SELECT title FROM $table WHERE id = $_POST[id]";
$res = mysql_query($sql);
if (substr(mysql_result($res, 0), 0, 3) != "Re:")
$title = "Re: " . mysql_result($res, 0);
else
$title = mysql_result($res, 0);
}
if ($_POST["submit"] && (!$_POST["name"] || !$_POST["title"] || !$_POST["msg"]))
{
$err = "<b>Je bent vergeten enkele velden in te vullen</b><p>";
}
echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";
echo "<tr>";
echo "<td align=left>";
if ($id)
echo "<a href=" . $_SERVER['PHP_SELF'] . "?id=$id&cat=$cat&p=$p><img src=$set_path/arrow_left.gif border=0></a> <a href=\"" . $_SERVER['PHP_SELF'] . "?id=$id&cat=$cat&p=$p\">terug naar het bericht</a></a>";
else
echo "<a href=" . $_SERVER['PHP_SELF'] . "&cat=$cat&p=$p><img src=$set_path/arrow_left.gif border=0></a> <a href=\"" . $_SERVER['PHP_SELF'] . "?&cat=$cat&p=$p\">terug naar de berichten</a></a>";
echo "</td>";
echo "</tr>";
echo "</table><p>";
// begin table with form
echo "<table width=\"100%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">";
echo "<tr>";
echo "<td>";
echo "<p> </p>";
echo "<p> </p>";
echo "<table border=0 cellspacing=0 cellpadding=0 border=0>\n";
echo "<tr><td>$err</td></tr>";
echo "<tr><td>";
echo "<form method=post action=" . $_SERVER['PHP_SELF'] . ">";
echo "<input type=hidden name=add value=1>";
if ($_GET["id"] || $_POST["id"])
{
if ($_GET["id"])
echo "<input type=hidden name=rid value=$_GET[id]>";
else
echo "<input type=hidden name=rid value=$_POST[id]>";
}
else
{
if ($_GET["rid"])
echo "<input type=hidden name=rid value=$_GET[rid]>";
else
echo "<input type=hidden name=rid value=$_POST[rid]>";
}
if ($_GET["p"])
echo "<input type=hidden name=p value=$_GET[p]>";
else
echo "<input type=hidden name=p value=$_POST[p]>";
if ($_GET["cat"])
echo "<input type=hidden name=cat value=$_GET[cat]>";
else
echo "<input type=hidden name=cat value=$_POST[cat]>";
echo "<b>Naam*:</b><br>";
echo "<input type=text name=name value=\"$_POST[name]\" $disabled><p>";
if (!$disabled)
{
echo "<b>Email</b><br>";
echo "<input type=text name=email value=\"$_POST[email]\"><p>";
}
echo "<b>Titel*</b><br>";
if ($title)
echo "<input type=text name=title value=\"$title\"><p>";
else
{
if ($_GET["title"])
echo "<input type=text name=title value=\"$_GET[title]\"><p>";
else
echo "<input type=text name=title value=\"$_POST[title]\"><p>";
}
echo "<b>Bericht*</b><br>";
echo "<textarea name=msg cols=55 rows=6>$_POST[msg]</textarea><p>";
echo "<input type=submit name=submit value=\"Plaats bericht!\"><p>";
echo "</form>";
echo "</td></tr>";
echo "</table>";
echo "<p> </p>";
echo "</td>";
echo "</tr>";
echo "</table><P>";
}
}
echo "</td></tr></table>";
?>