<?php

	$actions = array('new', 'top', 'dload');	

	(key_exists('action', $_GET) && $_GET['action']<>'' && in_array($_GET['action'], $actions) && session_is_registered('mobile_logged_in')) ? $action = $_GET['action'] : $action = '';
	(key_exists('i', $_GET) && $_GET['i']<>'') ? $i = intval($_GET['i']) : $i = 1;
	(key_exists('typ', $_GET) && $_GET['typ']<>'') ? $typ = intval($_GET['typ']) : $typ = 0;
	$cat = (isset($_GET['cat']) && array_key_exists($_GET['cat'], $theme_categories)) ? $_GET['cat'] : 0;
	
	if(session_is_registered('mobile_logged_in') && session_is_registered('mobile_page_temy') && $_SESSION['mobile_page_temy']!=0)
	{
		$nastranu = $_SESSION['mobile_page_temy'];
	}
	else
	{
		$nastranu = 9;
	}
	
	if($action=='top') 
	{
		$final_query = "SELECT * FROM mobile_themes WHERE hlasov>1 ORDER BY priemer DESC limit 0, $temy_charts";
	}

	if($action=='dload') 
	{
		$final_query = "SELECT * FROM mobile_themes WHERE dload>0 ORDER BY dload DESC limit 0, $temy_charts";
	}
	
	if($action=='new') 
	{
		$final_query = "SELECT * FROM mobile_themes ORDER BY ID DESC limit 0, $temy_charts";
	}
	
	if($action=='') 
	{
//		if(session_is_registered('mobile_logged_in'))
//		{
			$inc = '';
			if($typ != 0)
			{
				$inc .= " WHERE typ=$typ ";
			}
			if($cat != 0)
			{
				if($inc == '')
				{
					$inc = " WHERE cat=$cat ";
				}
				else 
				{
					$inc .= " AND cat=$cat ";
				}
			}
			$query = "SELECT * FROM mobile_themes $inc"; 
			$chunk = $dba->GetLimit($query);
			$lim = $chunk[0];
	    	$max = $chunk[1];
	    	$stranok = $chunk[2];
			$final_query = "SELECT * FROM mobile_themes $inc ORDER BY ID DESC limit $lim, $nastranu";
//		}
//		else 
//		{
//			$query = "SELECT * FROM mobile_themes"; 
//			$chunk = $dba->GetLimit($query);
//			$lim = $chunk[0];
//	    	$max = $chunk[1];
//	    	$stranok = $chunk[2];
//			$final_query = "SELECT * FROM mobile_themes ORDER BY nazov ASC limit $lim, $nastranu";
//			if(!session_is_registered('mobile_logged_in')) $final_query = "SELECT * FROM mobile_themes ORDER BY nazov ASC limit $lim, 5";
//		}
	}

	$nadpisy = array
	(
		'new' => 'NEW '.$temy_charts.' témy',
		'top' => 'TOP '.$temy_charts.' témy',
		'dload' => 'TOP DOWNLOAD '.$temy_charts.' témy',
	);
	
	function  fnVypisTemy($result)
	{
		global $theme_types, $blocked_dloads, $theme_categories;
		
		if($result)
		{
			InitialzeReklama();
			while($row = mysql_fetch_array($result))
			{
				ShowReklama();
				$size=round(filesize('themes/'.$row["file"])/1024,2);		
				
				echo "<div id=\"melodia_div\">";
				echo "<table width=\"100%\" border=\"0\" cellspacing=\"2\"><tr><td valign=\"top\" width=\"128\">";
				echo "<img src=\"images/themes/".$row['image']."\" alt=\"\" />";
				echo "</td><td valign=\"top\" style='padding-left:5px;'>";
				echo"<b>".$row['nazov']."</b> - <span id=\"red_b\">ID: ".$row["ID"]."</span> (".$size." kB)<br />";
				echo "http://4mobile.sk/tema/".$row["ID"]."/<br />";
				echo "Kategória <b>".$theme_categories[$row['cat']]."</b><br/>";
				if($row["poznamka"]<>'') echo $row["poznamka"]."<br />";
				echo "<span id=\"red\"><b>Pre telefóny:</b></span> ".$theme_types[$row['typ']]['popis'].'<br />';
				$priemer = round($row["priemer"],2);
				fnShowStars($priemer);
				echo "&nbsp;".$row["hlasov"]." hlasov, priemer: ".$priemer.", ".$row["dload"]." stiahnutí <br /> <span id=\"red_b\">Hlasuj!</span> <img src=\"images/smile/17.gif\" alt=\"\" /> ";
				for($k=1;$k<=5;$k++) {echo"<a href='hlasuj.php?action=theme&amp;id=".$row['ID']."&amp;hlas=".$k."' id=\"hlasuj\">".$k."</a> ";}
				echo "<img src=\"images/smile/5.gif\" alt=\"\" />";
				if(session_is_registered('mobile_logged_in'))
				{
					echo " | <a href='http://4mobile.sk/tema/".$row["ID"]."/' class='tahaj'>STIAHNI</a>";
				}
				echo "</td></tr></table>";
				echo "</div>";
			}
		}
	}
?>

	<div id="register_form01">
	  <div id="menu01_head">:: <?php if(key_exists($action, $nadpisy)) echo $nadpisy[$action]; else echo 'témy';?></div>
	  <div id="melodie_01">
	    <?php 
	    
	    	if(!session_is_registered('mobile_logged_in')) echo "<br />Zaregistrovaní používatelia získajú prístup ku všetkým témam! <br />";
//	    	echo $final_query;
    		if(($action=='') && session_is_registered('mobile_logged_in')) fnNavi($i, $stranok, "module=temy&amp;action=$action&amp;typ=$typ&amp;cat=$cat");
	    	$result = $dba->GetResult($final_query);
	    	fnVypisTemy($result);
	    	if(($action=='') && session_is_registered('mobile_logged_in')) fnNavi($i, $stranok, "module=temy&amp;action=$action&amp;typ=$typ&amp;cat=$cat");
    	?>
	  </div>
	</div>