<?
$link='http://www.davu.hr/pregled_fondova_i_zbirki.php?stranica=32';

$nivo1=$_REQUEST['nivo1'];
$nivo2=$_REQUEST['nivo2'];


$izlist='nivo1';

if (is_numeric($nivo2))
{
	$sql="select * from lvl3 where id_lvl2='$nivo2' and vidljivost='1' order by sort asc";
	$rez99=mysql_query($sql,$conn); 
	$num99=mysql_num_rows($rez99);
	if ($num99>0)
	{
		$izlist='nivo3';	
	}
	
	
} else {
	if (is_numeric($nivo1))
	{
		$sql="select * from lvl2 where id_lvl1='$nivo1' and vidljivost='1' order by sort asc";
		$rez99=mysql_query($sql,$conn); 
		$num99=mysql_num_rows($rez99);
		if ($num99>0)
		{
			$izlist='nivo2';	
		}
	}
}



if ($izlist=='nivo1')
{
	$sql="select * from lvl1 where vidljivost='1' order by sort asc";	
	$rez99=mysql_query($sql,$conn);
	$num99=mysql_num_rows($rez99);
}
$cur99=1;
echo '<ul>'."\n";
while ($num99>=$cur99) {
	$row99=mysql_fetch_array($rez99);	
	$id_lvl3=$row99['id_lvl3'];
	$opis_lvl3=$row99['opis_lvl3'];
	$id_lvl2=$row99['id_lvl2'];
	$opis_lvl2=$row99['opis_lvl2'];
	$id_lvl1=$row99['id_lvl1'];
	$opis_lvl1=$row99['opis_lvl1'];
	$arhinet=$row99['arhinet'];
	switch ($izlist)
	{
		case 'nivo3':
			echo '<li>';
			if ($arhinet=='')
			{
				echo $opis_lvl3; 
			} else {
				echo '<a href="'.$arhinet.'" target="_blank">'.$opis_lvl3.'</a>';
			}
			echo '</li>'."\n";
		break;
		case 'nivo2':
			echo '<li>';
			//da li postoji dijete?
			$sql="select id_lvl3 from lvl3 where id_lvl2='$id_lvl2' and vidljivost='1'";
			$rez=mysql_query($sql,$conn); 
			$num=mysql_num_rows($rez);
			if ($num>0)
			{
				echo '<a href="'.$link.'&amp;nivo1='.$nivo1.'&amp;nivo2='.$id_lvl2.'">'.$opis_lvl2.'</a>'; 
			} else {
				echo $opis_lvl2;
			}
			echo '</li>'."\n";
			
		break;
		default:
			echo '<li>';
			//da li postoji dijete?
			$sql="select id_lvl2 from lvl2 where id_lvl1='$id_lvl1' and vidljivost='1'";
			$rez=mysql_query($sql,$conn); 
			$num=mysql_num_rows($rez);
			if ($num>0)
			{
				echo '<a href="'.$link.'&amp;nivo1='.$id_lvl1.'">'.$opis_lvl1.'</a>'; 
			} else {
				echo $opis_lvl1;
			}
			echo '</li>'."\n";
		break;
	}	
	$cur99++;
}
echo '</ul>'."\n";
switch ($izlist)
{
	case 'nivo3':
		echo '<br /><br />'."\n";
		echo '<hr />';
		echo '<br /><br />'."\n";
		echo '<a href="'.$link.'&amp;nivo1='.$nivo1.'">Povratak na prethodnu stranicu</a>';
	break;
	case 'nivo2':
		echo '<br /><br />'."\n";
		echo '<hr />';
		echo '<br /><br />'."\n";
		echo '<a href="'.$link.'">Povratak na prethodnu stranicu</a>';
	break;
	default:
	
	break;
}
?>