<?php

	$char = (isset($_GET['char']) && $_GET['char']!='') ? substr($_GET['char'], 0, 1) : '';
	$search = (isset($_GET['search']) && $_GET['search']!='') ? $_GET['search'] : '';
	$i = (isset($_GET['i']) && $_GET['i']!='') ? intval($_GET['i']) : 1;
	
	$nastranu = 10;
	
	if($search != '')
	{
		$final_query = "SELECT * FROM mobile_slovnik WHERE pojem LIKE '%".addslashes($search)."%' OR vysvetlenie LIKE '%".addslashes($search)."%' ORDER BY pojem ASC limit 0, 20";
		$chunk[2] = 1;
	}
	else 
	{
		if($char!='')
		{
			$query = "SELECT ID FROM mobile_slovnik WHERE pojem LIKE '$char%'";
			$chunk = $dba->GetLimit($query);
			$lim = $chunk[0];
			$final_query = "SELECT * FROM mobile_slovnik WHERE pojem LIKE '$char%' ORDER BY pojem ASC limit $lim, $nastranu";
		}
		else 
		{
			$query = "SELECT ID FROM mobile_slovnik";
			$chunk = $dba->GetLimit($query);
			$lim = $chunk[0];
			$final_query = "SELECT * FROM mobile_slovnik ORDER BY pojem ASC limit $lim, $nastranu";
			
		}
	}
	
	function fnVypisSlovnik($result)
	{
		if($result)
		{
			while($row = mysql_fetch_array($result))
			{
				echo "
					<div class='slovnik_container'>
						<div class='slovnik_pojem'>
							".$row['pojem']."
						</div>
						<div class='slovnik_vysvetlenie'>
							".$row['vysvetlenie']."
						</div>
					</div>
					";
			}
		}
	}
	
?>

	<div id="register_form01">
	  <div id="menu01_head"><h1 class='h1_header'>:: slovník pojmov</h1></div>
	  <div id="melodie_01">
	    <?php 
	    
	    	$result = $dba->GetResult($final_query);
	    	$num = mysql_num_rows($result);
	    	$stranok = $chunk[2];
	    	if(mysql_num_rows($result) > 0)
	    	{
	    		fnNavi($i, $stranok, "module=slovnik&amp;char=$char");
	    		fnVypisSlovnik($result);
		    	fnNavi($i, $stranok, "module=slovnik&amp;char=$char");
	    	}
	    	else echo "Prepáčte, ale pojem podľa zadaných kritérií sa tu nenachádza.";
	    	?>
	  </div>
	</div>