<?php
include('include.php');
$bad=array('.', '(', ')', '<', '>', ':', '/', '"', "'");
$word = substr(addslashes(strip_tags(str_replace($bad, '', ''.$_GET['word']))), 0, 20);
//die($word);
echo '<body>';

echo '<form name="slovnik" method="get" action="/"><label>Prelož: <input type="text" id="word" name="word" value="'.$word.'"></label><input type="submit" value="preložiť"></form>';
if(strlen($word)<2) echo '<script>document.getElementById("word").focus();</script>';
function slovnik($row) {
	return '<br>(<a href="/slovniky.php?slovnik='.$row['database'].'" title="'.$row['description'].'">'.$row['database'].'</a>)';
	}
$i=0;
$conf=array('word'=>"slovo",'definition'=>"definícia");//,'database'=>"slovník");
if(strlen($word)>2) {
	echo '<table><tr><td>';
	$res = $dict->define($word);
	echo "<table>";
	vypis_riadok($conf,$conf);
	if(is_array($res)) foreach($res as $key => $row) {
	//	vypis_riadok($row,$conf);
		echo '<tr><td>'.$row['word'].slovnik($row).'</td><td>'.text($row['definition']).'</td></tr>'."\n\n";
		}
	echo "</table>";
	echo '</td><td>';
	// podobne slova:
	$res = $dict->match($word);
	echo "<table>";
	vypis_riadok(array('word'=>"podobné slovo",'definition'=>"definícia"),$conf);
	foreach($res as $key => $row) {
	//	vypis_riadok($row,$conf);
		//$def = implode("\n\n",$dict->define($row['word'],$row['database'])); print_r($def);
		if($row['word'] == $word) continue;
		$defs=array();
		$defs = $dict->define($row['word'],$row['database']);
		$def='';
		foreach($defs as $key=>$val) {$def .= "".$val['definition']; $i++; }
		if(strlen($def)>2) echo '<tr><td><a href="?word='.urlencode($row['word']).'">'.$row['word'].'</a>'.slovnik($row).'</td><td>'.text($def).'</td></tr>'."\n\n";
		//vypis_riadok($row,$conf);
		if($i>80) break;
		}
	echo "</table>";
	//print_r($val);
	echo "</td></tr></table>";
	}

//print_r($res);
//print_r($row);
paticka();
?>
