<?php 
if (!isset($_SESSION))
{
	session_start();
}
require_once ('header.php');
if ($aangemeld == "ja")
{
	$jouwrechten = $member_status;
	$topicrechten = halen("SELECT rechten FROM topics WHERE id = '".$_GET['id']."'"); 
	if ($topicrechten == "all")
	{
		$toon = "ja";
		$topicsoort = "gwn";
	}
	else
	{
		$topicsoort = "special";
		if (($jouwrechten == "manager") or ($jouwrechten == "staff"))
		{
			$toon = "ja";
		}
		else
		{
			$toon = "nee";
		}
	}
	if ($toon == "ja")
	{
		$geblokt = halen("SELECT geblokt FROM topics WHERE id = '".$_GET['id']."';");
    	if ($geblokt == "old")
    	{
		    $geblokt = "ja";
	    	$archief = "ja";
    	}
    	else
    	{
	    	$archief = "nee";
    	}
?>
<link rel="stylesheet" href="style/forum.css" type="text/css" media="all"> 
<style type="text/css">
.titlemedium
{
	background-image: url(img/forum/tile_sub.gif) 
}
.maintitle
{
	background-image: url(img/forum/tile_back.gif) 
}
</style> 
<br>
<table width="90%" border="0" cellspacing="0" cellpadding="0" align="center" class='forum'>
<tr>
<td colspan="3">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="77"><img src="img/forum/topleft.gif" alt="" /></td>
<td width="100%"  background="img/forum/topbg.gif"><center>Forum</center></td>
<td width="503" align="right"><img src="img/forum/topright.gif" alt="" /></td>
</tr>
</table>
</td></tr>
<tr>
<td width="10" valign="top" background="img/forum/leftbg.gif"><img src="img/forum/leftbg.gif" alt="" /></td>
<td align="left" valign="top" bgcolor="#c5bdbb" width="100%">
<table cellpadding="0" cellspacing="0" border="0" width="100%" bgcolor="#c5bdbb" align="center">
<tr>
<td class="post1">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="100%" background="img/forum/logobg.gif"><div align="center" class="copyright"></div></td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="29"><img src="img/forum/membarleft.gif" width="29" height="38" alt="" /></td>
<td width="100%" background="img/forum/membarbg.gif"><table width='100%' cellpadding='0' cellspacing='0' border='0' align='center'>
<tr>
<td align='left' class='memberbar' valign='middle' style='padding: 0px 0px 4px 0px;'><strong>Welkom <?php echo $_SESSION['naam']; ?></strong></td>
<td align='right' class='memberbar' valign='middle' style='padding: 0px 0px 4px 0px;'><?php echo $_SESSION['member_posts']; ?> posts</td></tr></table></td>
<td width="21" align="right"><img src="img/forum/membarright.gif" width="21" height="38" alt="" /></td>
</tr>
</table>
<?php
	echo '<div align="right">';
	if ($archief == "ja")
	{
		echo '<a href="oldforum.php"><img src="img/forum/t_topic.gif"></a>';
	}
	else
	{
		echo '<a href="topics.php"><img src="img/forum/t_topic.gif"></a>';
	}
	if (($archief != "ja") AND ($member_status == "manager"))
	{
		echo '<a href="addtopic.php"><img src="img/forum/t_new.gif"></a>';
	}
	echo '</div>';
	$reacties = mysql_query("SELECT * FROM replys WHERE tid = '".$_GET['id']."';");
	$hoeveel = mysql_num_rows($reacties);
	$hoeveel = $hoeveel / 10;
	$hoeveel = ceil($hoeveel);
 	if (ISSET($_GET['pag'])) 
 	{ 
	 	$beginpag = $_GET['pag']; 
    } 
	else 
	{ 
		for ($i = 1; $i <= $hoeveel; $i++) 
		{
			$lolbroek = $i;
   		}
   		if (ISSET($lolbroek))
   		{
	   		$beginpag = $lolbroek;
   		}
   		else
   		{
	   		$beginpag = 1;
   		}
	}
	$totwaar = $beginpag * 10;
    $vanwaar = $totwaar - 10;
    if ($geblokt == "ja")
    {
	    echo '<div align="left" class="maintitle" style="padding: 0px 0px 6px 5px;"><img src="img/bluelock.gif" border="0" align="bottom">&nbsp;';
	}
	else
	{
		echo '<div align="left" class="maintitle"><img src="img/forum/nav_m.gif" border="0" alt="&gt;" width="23" height="11">&nbsp;';
	}
    $sql = "SELECT id, titel, bericht, datum, naam FROM topics WHERE id = '".$_GET['id']."'"; 
    $res = mysql_query($sql); 
    $row = mysql_fetch_array($res); 
 	$titel_forum = $row['titel'];
 	if ($topicsoort == "special")
	{
		action("kijkt in het staff topic '".$titel_forum."'");
	}
	else
	{
		action("kijkt in het topic '".$titel_forum."'");
	}
	if ($_GET['id'] != 88)
	{
		$row['bericht'] = htmlentities($row['bericht']); 
	}
    $bericht = $row['bericht']; 
    require("ubbc.php");
    $row['bericht'] = $bericht;
    $posts = halen("SELECT posts FROM members WHERE naam='".$row['naam']."'");
    $status = status($row['naam']);
    if ($topicsoort=="special")
	{
		echo "<font color='green'>";
	}
    echo $titel_forum;
    if ($topicsoort=="special")
	{
		echo "</font>";
		echo " <b>(Site staff only topic)</b>";
	}
    if ($geblokt == "ja") { echo ' (gesloten)'; }
    echo '</div>';
    if (($member_status == "manager") or ($member_status == "staff"))
	{
		if ($archief == "ja")
		{
			echo '<div align="right"><b>Admin/Forum-mod functies:</b>&nbsp; ';
		}
		else
		{
			echo '<div align="right"><b>Admin/Mod functies:</b>&nbsp; ';
		}
		if ($archief != "ja")
		{
			if ($geblokt == "ja")
			{
				echo '<a href="opensluit.php?id='.$_GET['id'].'&action=open"><img src="img/icon_unlock.gif" alt="Open topic"></a>';
			}
			else
			{
				echo '<a href="opensluit.php?id='.$_GET['id'].'&action=sluit"><img src="img/icon_lock.gif" alt="Sluit topic"></a>';
			}
		}
		if ($member_status == "manager")
		{
			if ($archief == "ja")
			{
				echo ' <a href="delrecover.php?id='.$_GET['id'].'&action=open"><img src="img/recover.gif" alt="Recover topic"></a>';
			}
			else
			{
				echo ' <a href="delrecover.php?id='.$_GET['id'].'&action=sluit"><img src="img/del.gif" alt="Verwijder topic"></a>';
			}
		}
		echo ' &nbsp;&nbsp;</div>';
	}
	echo '<div align="center" class="maintitle"><font size="2">';
    $paginaprint = "";
    $trollensnot = 0;
    $beginminder = $beginpag -1;
    $beginmeer = $beginpag +1;
    $vorige = "<a href='?id=".$_GET['id']."&pag=".$beginminder."'>Vorige</a> ";
    $volgende = "<a href='?id=".$_GET['id']."&pag=".$beginmeer."'>Volgende</a> ";
    for ($i = 1; $i <= $hoeveel; $i++) 
	{
   		if ($i != $beginpag)
   		{
	   		$paginaprint = $paginaprint."<a href='?id=".$_GET['id']."&pag=".$i."'>".$i."</a> ";
	    }
	    $trollensnot++;
	}
    if ($paginaprint == "")
    {
        echo "<a href='?id=".$_GET['id']."&pag=1'>1</a> ";
    }
    else
    {
        if ($beginminder < 1)
        {
	    	$vorige = "";
	    }
	    if ($beginmeer > $trollensnot)
        {
	    	$volgende = "";
	    }
	    echo $vorige.$paginaprint.$volgende;
    }
	echo '</font></div><br>';  
	if ($beginpag == 1)
    {
        echo '
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="100%" background="img/forum/postopbg.gif"><img src="img/forum/postopbg.gif" alt="" width="1" height="10" /></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" class="post2" width="85">
<br><table border="0" cellspacing="0" cellpadding="0" align="left">
<tr>
<td colspan="3">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="32" bgcolor="#dfd8d7"><img src="img/forum/posttopleft.gif" alt="" /></td>
<td background="img/forum/posttopbg.gif" width="100%"><center><span class="normalname"><a href="profiel.php?naam='.$row['naam'].'">'.$row['naam'];
    	echo '
    </a></span></center></td>
<td width="29" align="right"><img src="img/forum/posttopright.gif" alt="" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" background="img/forum/posttopleftbg.gif"><img src="img/forum/posttopleftbg.gif" alt="" /></td>
<td align="left" valign="top" bgcolor="#3A3E40" width="100%">
<table cellpadding="0" cellspacing="0" border="0" bgcolor="#fd8d7" align="center">
<tr>
<td bgcolor="#cabfbe">
<table border="0" cellspacing="0" cellpadding="0" align="center" width="85" class="post1"><tr><td height="5"></td></tr>
<tr><td align="center">
<span><center>';
echo "<img src='img/badges/".$status.".gif' class='forum'>";
echo '    </center></span><table border="0" style="border-collapse: collapse" cellpadding="0"><tr><td height="5"></td></tr>';
echo '<tr><td align="center"><b>'.$status.'</b></td></tr><tr><td height="5"></td></tr>';
if ($posts != "")
{
	echo '<tr><td align="center">Berichten: '.$posts.'</td></tr><tr><td height="5"></td></tr>';
}
echo '
</tr></td></table>
</td>
</td></tr>
</table></td></tr>
</table>
<td width="21" background="img/forum/posttoprightbg.gif"><img src="img/forum/posttoprightbg.gif" alt="" /></td>
</tr>
<tr>
<td valign="middle" align="right" width="100%" colspan="3">
<table cellpadding="0" border="0" cellspacing="0" width="100%">
<tr>
<td width="21" background="img/forum/postbotleft.gif"><img src="img/forum/postbotleft.gif" alt="" /></td>
<td background="img/forum/postbotbg.gif"><img src="img/forum/postbotbg.gif" alt="" /></td>
<td width="18"><img src="img/forum/postbotright.gif" alt="" border="0" /></td>
</tr>
</table>
</td></tr>
</table>
<br />
<td valign="top" class="post2"><table width="100%" border="0" cellspacing="0" cellpadding="7">
<tr><td>
<table width="100%" border="0" bgcolor="#D6DBE0" cellspacing="0" cellpadding="0">
   <tr> 
      <td class="post2"><span class="postdetails"><b><u>Geplaatst:</u></b> ';
    echo $row['datum']; 
    echo '
</span></td>
<td class="post2" align="right">
   </tr>
   </table>
			<img src="img/forum/spacer.gif" width="1" height="5" alt="" /><br />
			<div class="postcolor"> ';
    
    echo $row['bericht']; 
    echo '</div>
		  <br><br><hr width="100px" align="left">
		  <div class="signature"></div>
		  </td></tr></table></td>
		  </tr>
		  </table>
		  <table border="0" cellspacing="0" cellpadding="0" bgcolor="#e0d6d6">
		  <tr>
		  <td width="22"><img src="img/forum/catleft.gif" width="22" height="24" alt="" /></td>
		  <td width="100%" background="img/forum/catbg.gif"></td>
		  <td width="22" align="right"><img src="img/forum/catright.gif" width="22" height="24" alt="" /></td>
		  </tr>
		  </td></tr>
          </table>';
	}
	$csql = "SELECT id, naam, bericht, datum FROM replys WHERE tid = '".$_GET['id']."' ORDER BY id ASC LIMIT ".$vanwaar.", 10"; 
	$cres = mysql_query($csql); 
    if (mysql_num_rows($cres) >= 1) 
    { 
        while ($row = mysql_fetch_array($cres)) 
		{
			$posts = halen("SELECT posts FROM members WHERE naam='".$row['naam']."'");
			$status = status($row['naam']);
			if ($_GET['id'] != 88)
			{
				$row['bericht'] = htmlentities($row['bericht']); 
			}
    		$bericht = $row['bericht']; 
    		require("ubbc.php");
    		$row['bericht'] = $bericht;
		    echo '
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="100%" background="img/forum/postopbg.gif"><img src="img/forum/postopbg.gif" alt="" width="1" height="10" /></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" class="post2" width="85">
<br><table border="0" cellspacing="0" cellpadding="0" align="left">
<tr>
<td colspan="3">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="32" bgcolor="#dfd8d7"><img src="img/forum/posttopleft.gif" alt="" /></td>
<td background="img/forum/posttopbg.gif" width="100%"><center><span class="normalname"><a href="profiel.php?naam='.$row['naam'].'">';
echo $row['naam'];
echo '
</a></span></center></td>
<td width="29" align="right"><img src="img/forum/posttopright.gif" alt="" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" background="img/forum/posttopleftbg.gif"><img src="img/forum/posttopleftbg.gif" alt="" /></td>
<td align="left" valign="top" width="100%">
<table cellpadding="0" cellspacing="0" border="0" bgcolor="#fd8d7" align="center">
<tr>
<td class="post1">
<table border="0" cellspacing="0" cellpadding="0" align="center" width="85"><tr><td height="5"></td></tr>
<tr><td align="center">
<span><center>';
echo "<img src='img/badges/".$status.".gif' class='forum'>";
echo '</center></span><table border="0" style="border-collapse: collapse" cellpadding="0"><tr><td height="5"></td></tr>';
echo '<tr><td align="center"><b>'.$status.'</b></td></tr><tr><td height="5"></td></tr>';
if ($posts != "") { echo '<tr><td align="center">Berichten: '.$posts.'</td></tr><tr><td height="5"></td></tr>'; }
echo '
</tr></td></table>
</td>
</td></tr>
</table></td></tr>
</table>
<td width="21" background="img/forum/posttoprightbg.gif"><img src="img/forum/posttoprightbg.gif" alt="" /></td>
</tr>
<tr>
<td valign="middle" align="right" width="100%" colspan="3">
<table cellpadding="0" border="0" cellspacing="0" width="100%">
<tr>
<td width="21" background="img/forum/postbotleft.gif"><img src="img/forum/postbotleft.gif" alt="" /></td>
<td background="img/forum/postbotbg.gif"><img src="img/forum/postbotbg.gif" alt="" /></td>
<td width="18"><img src="img/forum/postbotright.gif" alt="" border="0" /></td>
</tr>
</table>
</td></tr>
</table>
<br />
<td valign="top" class="post2"><table width="100%" border="0" cellspacing="0" cellpadding="7">
<tr><td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
   <tr> 
      <td class="post2"><span class="postdetails"><b><u>Geplaatst:</u></b> ';
    echo $row['datum']; 
    echo '
</span></td>
<td class="post2" align="right">
';
if ($_SESSION['naam'] == $row['naam'])
{
	echo '<a href="editpost.php?post='.$row['id'].'" title="Bewerk"><img src="img/edit.gif" border="0"  alt="Bewerk post" width="12" height="12"></a>';
}
echo '</td>
   </tr>
   </table>
			<img src="img/forum/spacer.gif" width="1" height="5" alt="" /><br />
			<div class="postcolor"> ';
    echo $row['bericht']; 
    echo '</div>
		  <br><br><hr width="100px" align="left">
		  <div class="signature"></div>
		  </td></tr></table></td>
		  </tr>
		  </table>
		  <table border="0" cellspacing="0" cellpadding="0">
		  <tr>
		  <td width="22"><img src="img/forum/catleft.gif" width="22" height="24" alt="" /></td>
		  <td width="100%" background="img/forum/catbg.gif"></td>
		  <td width="22" align="right"><img src="img/forum/catright.gif" width="22" height="24" alt="" /></td>
		  </tr>
		  </td></tr>
          </table>';
        } } else { 
	        
	        echo '<div align="center" class="maintitle">Er zijn nog geen reacties.</div><br>'; } 
            echo '<div align="center" class="maintitle"><font size="2">';
       
        if ($paginaprint == "")
        {
	        echo "<a href='?id=".$_GET['id']."&pag=1'>1</a> ";
        }
        else
        {
	        if ($beginminder < 1)
	        {
		    	$vorige = "";
		    }
		    if ($beginmeer > $trollensnot)
	        {
		    	$volgende = "";
		    }
		    echo $vorige.$paginaprint.$volgende;
        }
   		echo '</font></div><br>';
   		if ($geblokt != "ja")
		{
			echo '
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="100%" background="img/forum/postopbg.gif"><img src="img/forum/postopbg.gif" alt="" width="1" height="10" /></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" align="center" class="post2">';
echo '<table width="490" border="0" cellspacing="0" cellpadding="8">';
echo '<tr><td colspan="2"><center><script language="JavaScript1.2" type="text/javascript" src="javascript/ubbc.js"></script>';
require('knoppen.php');
echo '<br><script language="JavaScript1.2" type="text/javascript" src="javascript/smileys.js"></script></center></td></tr>';
echo '<form name="formulier" method="post" action="addreply.php?id=' . $_GET['id'] . '"><tr><td width="120" valign="top"><small>Bericht: </small></td><td valign="top"><textarea name="script1" rows="10" cols="50"></textarea></td></tr><tr><td width="120" valign="top">&nbsp;</td><td>';
echo '<input type="submit" name="submit" value="Bericht plaatsen"></td></tr></form></table>';
echo '</td></tr></table><table border="0" cellspacing="0" cellpadding="0" bgcolor="#e0d6d6"><tr>
<td width="22"><img src="img/forum/catleft.gif" width="22" height="24" alt="" /></td>
<td width="100%" background="img/forum/catbg.gif"></td>
<td width="22" align="right"><img src="img/forum/catright.gif" width="22" height="24" alt="" /></td>
</tr>
</td></tr>
</table>';
}
?>

<table border="0" cellspacing="0" cellpadding="0" width="100%" bgcolor="#e0d6d6">
</table>
</td></tr>
</table></td>
<td width="9" background="img/forum/rightbg.gif"><img src="img/forum/rightbg.gif" alt="" /></td>
</tr>
<tr>
<td valign="middle" align="right" width="100%" colspan="3">
<table cellpadding="0" border="0" cellspacing="0" width="100%">
<tr>
<td width="12"><img src="img/forum/botleft.gif" width="12" height="14" alt="" /></td>
<td width="100%" background="img/forum/botbg.gif"></td>
<td width="10"><img src="img/forum/botright.gif" width="10" height="14" alt="" /></td>
</tr>
</table>

<table cellpadding="0" border="0" cellspacing="0" width="100%">
<tr>
<td width="46"><img src="img/forum/bottomleft.gif" alt="" /></td>
<td width="100%" background="img/forum/bottombg.gif"><!-- Copyright Information -->
<div align='center' class='copyright'></div>
<!-- / Copyright --></td>
<td width="46"><map name="topmap" id="topmap"><area shape="rect" coords="21,13,40,26" alt="Top" href="javascript:scroll(0,0);" /></map>
<img src="img/forum/bottomright.gif" width="46" height="29" alt="" border="0" usemap="#topmap" /></td>
</tr>
</table>
</td></tr>
</table>
<?php
}
else
{
	echo "<h1>Forum</h1>";
	echo "<center>Oeps! Dit is een topic alleen voor <b>managers</b> en <b>staffs</b>!</center>";
}
}
else
{
	echo "<h1>Forum</h1>";
	echo "Oeps! Hiervoor moet je aangemeld zijn!";
}
require_once ('footer.php');
?>