<?php 

	//povolene akcie pre pozadia
	$actions = array('new', 'top', 'dload', 'moje_pozadia');	
	
	$_SESSION['pass_file'] = true;

	(key_exists('action', $_GET) && $_GET['action']<>'' && in_array($_GET['action'], $actions) && session_is_registered('mobile_logged_in')) ? $action = $_GET['action'] : $action = '';
	(key_exists('res', $_GET) && $_GET['res']<>'') ? $res = $_GET['res'] : $res = '';
	(key_exists('cat', $_GET) && $_GET['cat']<>'') ? $cat = $_GET['cat'] : $cat = 1;
	(key_exists('i', $_GET) && $_GET['i']<>'') ? $i = $_GET['i'] : $i = 1;
	
	if(session_is_registered('mobile_logged_in') && session_is_registered('mobile_page_pozadia') && $_SESSION['mobile_page_pozadia']!=0)
	{
		$nastranu = $_SESSION['mobile_page_pozadia'];
	}
	else
	{
		$nastranu = 9;
		$res = 1;
	}
	
	$resolution = array
	(
		0 => array ( 'width' => 200, 'height' => 200 ),
		1 => array ( 'width' => 128, 'height' => 128 ),
		2 => array ( 'width' => 174, 'height' => 130 ),
		3 => array ( 'width' => 128, 'height' => 160 ),
		4 => array ( 'width' => 128, 'height' => 80 ),
		5 => array ( 'width' => 176, 'height' => 220 ),
		6 => array ( 'width' => 132, 'height' => 176 ),
		7 => array ( 'width' => 208, 'height' => 208 )
	);
	
	// zvysenie statistiky poctu zobrazenych kategorii a rozliseni
	if(!session_is_registered("mobile_cat_".$cat) && $cat<>'')
	{
		$dba->Increment('mobile_img_cat', 'status', $cat, 1);
		session_register("mobile_cat_".$cat);
	}
	if(!session_is_registered("mobile_res_".$res) && $res<>'')
	{
		$dba->Increment('mobile_img_res', 'status', $res, 1);
		session_register("mobile_res_".$res);
	}
	
	if($action=='new')
	{
		$inc = '';
		if($res<>'') $inc = "mobile_pozadia.res=$res AND";

		$final_query = "
		SELECT mobile_pozadia.*, mobile_users.login as pridal_user 
		FROM mobile_pozadia, mobile_users 
		WHERE $inc mobile_pozadia.pridal=mobile_users.id AND mobile_pozadia.visible=1
		ORDER by ID DESC limit 0, 9";
		$stranok = 0;
	}
	
	if($action=='top')
	{
		$final_query = "
		SELECT mobile_pozadia.*, mobile_users.login as pridal_user 
		FROM mobile_pozadia, mobile_users 
		WHERE hlasov>10 AND mobile_pozadia.pridal=mobile_users.id AND mobile_pozadia.visible=1
		ORDER by priemer DESC limit 0, 9";
		$stranok = 0;
	}
	
	if($action=='dload')
	{
		$final_query = "
		SELECT mobile_pozadia.*, mobile_users.login as pridal_user 
		FROM mobile_pozadia, mobile_users 
		WHERE mobile_pozadia.dload>0 AND mobile_pozadia.ID<>'-1' AND mobile_pozadia.pridal=mobile_users.id AND mobile_pozadia.visible=1
		ORDER by dload DESC limit 0, 9";
		$stranok = 0;
	}
	
	if($action=='')
	{
		$inc = '';
		if($res<>'') $inc = " AND res=$res";
		$query = "SELECT ID FROM mobile_pozadia WHERE cat=$cat".$inc;
		
		$chunk = $dba->GetLimit($query);
		$lim = $chunk[0];
		$stranok = $chunk[2];
		
		$inc = '';
		if($res<>'') $inc = "AND mobile_pozadia.res=$res ";
		$final_query = "
		SELECT mobile_pozadia.*, mobile_users.login as pridal_user  
		FROM mobile_pozadia, mobile_users 
		WHERE mobile_pozadia.cat=$cat ".$inc."AND mobile_pozadia.pridal=mobile_users.id AND mobile_pozadia.visible=1
		ORDER by mobile_pozadia.ID DESC limit $lim, $nastranu";
	}
	
	if($action=='moje_pozadia')
	{
		$query = "SELECT ID FROM mobile_pozadia WHERE pridal=".$_SESSION['my_id'];
		$chunk = $dba->GetLimit($query);
		$lim = $chunk[0];
		$stranok = $chunk[2];
		$final_query = "
		SELECT mobile_pozadia.*, mobile_users.login as pridal_user  
		FROM mobile_pozadia, mobile_users 
		WHERE pridal=".$_SESSION['my_id']." AND mobile_pozadia.pridal=mobile_users.id 
		ORDER by mobile_pozadia.ID DESC limit $lim, $nastranu";
	}
	
	$nadpisy = array
	(
		'new' => 'NEW 9 pozadia',
		'top' => 'TOP 9 pozadia',
		'dload' => 'TOP DOWNLOAD 9 pozadia',
		'moje_pozadia' => 'moje pozadia'
	);
	
?>
	
	<div id="register_form01">
	  <div id="menu01_head">:: <?php if(key_exists($action, $nadpisy)) echo $nadpisy[$action]; else echo 'pozadia'; ?></div>
	  <div id="pozadia_01">
	  <div id="pozadia_info_div">http://4mobile.sk/pozadie.php?id=<i>ID pozadia</i></div>
	  	
	    <?php 
	    
	    	if(!session_is_registered('mobile_logged_in')) echo "<br />Zaregistrovaní používatelia získajú prístup ku všetkým pozadiam a rozlíšeniam! </br>";
	    	$max = $dba->GetNums($final_query);
	    	if($max>0)
	    	{
	    		if(($action == '' || $action == 'moje_pozadia') && session_is_registered('mobile_logged_in')) fnNavi($i, $stranok, "module=pozadia&amp;action=$action&amp;cat=$cat&amp;res=$res");
		    	$result = $dba->GetResult($final_query);
		    	fnVypisPozadia2($result);
		    	if(($action == '' || $action == 'moje_pozadia') && session_is_registered('mobile_logged_in')) fnNavi($i, $stranok, "module=pozadia&amp;action=$action&amp;cat=$cat&amp;res=$res");
	    	}
	    	elseif($action != 'moje_pozadia') 
	    	{
	    		echo "V tejto kategórii nie sú pozadia s rozlíšením ".$resolution[$res]['width']."x".$resolution[$res]['height']."px pre Váš mobil, vyskúšajte inú kategóriu alebo rozlíšenie.";
	    	}
	    	else 
	    	{
	    		echo "Ešte ste nepridali žiadne pozadie.";
	    	}
	    	?>
	  </div>
	</div>
	
<?php

//	if(in_array($_SESSION['my_id'], $admins))
//	{
//		if($_SESSION['pass_file'])
//		{
//			echo "<img src='file.php?id=2'/>";
//		}
//		else echo 'false';
//	}
	
	
?>
