	<?php
	include_once "connect.php";
	
	
	
	function correctURL($negeren) {
		$querystring = "?"; // de querystring
		if(sizeof($_GET) > 1 || !in_array($negeren, array_keys($_GET))) {
			// meer queryvariabelen te onthouden dan enkel $_GET[$nav_var]
			foreach($_GET as $k => $v) {
				if($k != $negeren) {
					$querystring .= $k."=".$v."&amp;";
				}
			}
		}
		return $querystring;
	}
	
	
	
	
	function navigatie($op, $max)
	{
	if (isset($_GET['aantal']) && (($_GET['aantal'] == 8) || ($_GET['aantal'] == 10) || ($_GET['aantal'] == 15) || ($_GET['aantal'] == 20)) && is_numeric($_GET['aantal'])) //Juiste vorm controlen
	{
	$max = $_GET['aantal']; //Als het OK is, $max instellen
	}
	global $aantal_items_per_pagina;
	global $offset;
	global $huidige_pagina;
	global $aantal_paginas;
	$sql1 = mysql_query("SELECT COUNT(id) FROM ".$op) or die("SQL1:". mysql_error());
	$totaal_aantal = mysql_result($sql1, 0);
	mysql_free_result($sql1);
	$aantal_items_per_pagina = $max;
	$aantal_paginas = ceil($totaal_aantal / $aantal_items_per_pagina);
	$aantal_paginas+=1;
	$huidige_pagina = 0;
	if(isset($_GET['navigatiepagina']) && is_numeric($_GET['navigatiepagina']) && $_GET['navigatiepagina'] > 0 && $_GET['navigatiepagina'] < $aantal_paginas) {
	$huidige_pagina = $_GET['navigatiepagina'];
	$huidige_pagina-=1;
	}
	$offset = $huidige_pagina * $aantal_items_per_pagina;
	}
	
	
	
	
	
	function navigatietonen()
	{
	global $huidige_pagina;
	global $aantal_paginas;
	$plaats = $_SERVER['PHP_SELF'].correctURL("navigatiepagina"); //URL nakijken (met var's enzo)
	?>
		<form name="navigatie" action="<? echo $_SERVER['PHP_SELF'] ;?>" method="post">
	<?php if ($huidige_pagina != 0) //De terugknoppen
	{
	?>
			<input name="button" type="button" class="navigatie" onClick="window.location='<? echo $plaats ;?>navigatiepagina=1'" value="<<" />
			<input name="button" type="button" class="navigatie" onClick="window.location='<? echo $plaats ;?>navigatiepagina=<? echo $huidige_pagina ;?>'" value="<" />
	<?php
	}
	?>
			<select onChange="window.location=''+this.form.elements['navigatiebox'].value;" name="navigatiebox">
	<?php
		for($i=1; $i < $aantal_paginas; $i++)  //Selectbox
		{
	?>
				<option value="<? echo $plaats ;?>navigatiepagina=<? echo $i ;?>"<?= ($i - 1 == $huidige_pagina) ? " selected=\"selected\"" : "" ?>><? echo $i ;?></option>
	<?
		}
	?>
			</select>
	<?php
	if ($huidige_pagina != $aantal_paginas - 2) //De vooruitknoppen
	{
	?>
			<input name="button" type="button" class="navigatie" onClick="window.location='<? echo $plaats ;?>navigatiepagina=<? echo $huidige_pagina + 2 ;?>'" value=">" />
			<input name="button" type="button" class="navigatie" onClick="window.location='<? echo $plaats ;?>navigatiepagina=<? echo $aantal_paginas - 1 ;?>'" value=">>" />
	<?php
	}
	?>
		<br>
		<select name="aantal" onChange="window.location=''+this.form.elements['aantal'].value;">
		<option value="<? echo $plaats ;?>navigatiepagina=<? echo $huidige_pagina + 1 ;?>">- Aantal: -</option>
		<?php
		$max = $_GET['aantal']; //Aantallen selecteren (aantal hier aanpassen ==> bovenaan ook aanpassen)
		?>
		<option value="?navigatiepagina=1&aantal=8"<?= ($max == 8) ? " selected=\"selected\"" : "" ?>>8 berichten</option>
		<option value="?navigatiepagina=1&aantal=10"<?= ($max == 10) ? " selected=\"selected\"" : "" ?>>10 berichten</option>
		<option value="?navigatiepagina=1&aantal=15"<?= ($max == 15) ? " selected=\"selected\"" : "" ?>>15 berichten</option>
		<option value="?navigatiepagina=1&aantal=20"<?= ($max == 20) ? " selected=\"selected\"" : "" ?>>20 berichten</option>
		</select>
		</form>
	<?php
	}
	?> 