<?php 

	//povolene akcie pre smskz
	$actions = array('new', 'top', 'moje_smsky');	
	
//	$action = (isset($_GET['action']) && in_array($_GET['action'], $actions) && isset($_SESSION['mobile_logged_in'])) ? $_GET['action'] : '';
	$action = (isset($_GET['action']) && in_array($_GET['action'], $actions)) ? $_GET['action'] : '';
	$cat = (isset($_GET['cat']) && array_key_exists($_GET['cat'], $sms_cats)) ? $_GET['cat'] : 1;
//	$i = (isset($_GET['i']) && is_numeric($_GET['i']) && isset($_SESSION['mobile_logged_in'])) ? intval($_GET['i']) : 1;
	$i = (isset($_GET['i']) && is_numeric($_GET['i'])) ? intval($_GET['i']) : 1;
	
	
	if(isset($_SESSION['mobile_logged_in']) && isset($_SESSION['mobile_page_sms']) && $_SESSION['mobile_page_sms']!=0)
	{
		$nastranu = $_SESSION['mobile_page_sms'];
	}
	else
	{
		$nastranu = 9;
	}
	
	// zvysenie statistiky poctu zobrazenych kategorii a rozliseni
	
	if($action=='new')
	{
		$final_query = "
		SELECT mobile_sms.*, mobile_users.login as pridal_user 
		FROM mobile_sms, mobile_users 
		WHERE 
			mobile_sms.pridal = mobile_users.id AND
			mobile_sms.confirmed = 'a'
		ORDER by ID DESC limit 0, $sms_charts";
		$stranok = 0;
	}
	
	if($action=='top')
	{
		$final_query = "
		SELECT mobile_sms.*, mobile_users.login as pridal_user 
		FROM mobile_sms, mobile_users 
		WHERE 
			mobile_sms.pridal = mobile_users.id AND
			mobile_sms.confirmed = 'a'
		ORDER by priemer DESC limit 0, $sms_charts";
		$stranok = 0;
	}
	
	if($action=='')
	{
		$query = "SELECT ID FROM mobile_sms WHERE cat='$cat' AND confirmed='a'";
		
		$chunk = $dba->GetLimit($query);
		$lim = $chunk[0];
		$stranok = $chunk[2];
		
		$final_query = "
		SELECT mobile_sms.*, mobile_users.login as pridal_user  
		FROM mobile_sms, mobile_users 
		WHERE 
			mobile_sms.cat = $cat AND 
			mobile_sms.pridal = mobile_users.ID AND
			mobile_sms.confirmed = 'a' 
		ORDER by mobile_sms.ID DESC limit $lim, $nastranu";
//		dump($final_query);
	}
	
	if($action=='moje_smsky')
	{
		$query = "SELECT ID FROM mobile_sms WHERE pridal='".$_SESSION['my_id']."'";
		$chunk = $dba->GetLimit($query);
		$lim = $chunk[0];
		$stranok = $chunk[2];
		$final_query = "
		SELECT mobile_sms.*, mobile_users.login as pridal_user  
		FROM mobile_sms, mobile_users 
		WHERE 
			pridal='".$_SESSION['my_id']."' AND 
			mobile_sms.pridal=mobile_users.id AND
			mobile_sms.confirmed = 'a' 
		ORDER by mobile_sms.ID DESC limit $lim, $nastranu";
	}
	
	$nadpisy = array
	(
		'new' => 'NEW '.$sms_charts.' SMSKY',
		'top' => 'TOP '.$sms_charts.' SMSKY',
		'moje_smsky' => 'Moje smsky'
	);
	
	function  fnVypisSmsky($result)
	{
		global $cat;
		if($result)
		{
			while($row = mysql_fetch_array($result))
			{
				if($cat == 3)
				{
					$row['text'] = str_replace(' ', '&nbsp;', $row['text']);
				}
				$ascii = ($cat == 3) ? ' sms_ascii' : '';
				echo "<div class=\"sms_div\">";
					echo "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
						echo "<tr>";
							echo "<td valign='top' class='sms_header'>Pridal <strong>".$row['pridal_user']."</strong></td>";
							echo "<td align='right' class='sms_header'>".$row['time']."</td>";
						echo "</tr>";
						echo "<tr>";
							echo "<td colspan='2' class='sms_body$ascii'>".nl2br(stripslashes($row['text']))."</td>";
						echo "</tr>";
						echo "<tr>";
							echo "<td class='sms_popis sms_pad'>";
							fnShowStars($row['priemer']);
							echo '&nbsp;'.$row['hlasov']." hlasov, priemer: ".$row['priemer']."</td>";
							echo "<td align='right' class='sms_popis sms_pad'>".strlen($row['text'])." znakov</td>";
						echo "</tr>";
						echo "<tr>";
							echo "<td class='sms_pad'>Hlasuj! <img src=\"images/smile/17.gif\" alt=\"\" /> "; for($k=1;$k<=5;$k++) {echo"<a href='hlasuj.php?action=sms&amp;id=".$row['ID']."&amp;hlas=".$k."' id=\"hlasuj\">".$k."</a> ";} echo "<img src=\"images/smile/5.gif\" alt=\"\" /></td>";
							echo "<td class='sms_pad' align='right'>"; 
							if(isset($_SESSION['mobile_logged_in']))
							{
								echo "<a href='index.php?module=stlac&amp;id=".$row['ID']."' class=''>Prenes do SMS editora</a>";
							}
							echo "</td>";
						echo "</tr>";
						echo "</table>";
				echo "</div>";
			}
		}
	}
	
?>
	
	<div id="register_form01">
	  <div id="menu01_head"><h1 class='h1_header'>:: <?php if(array_key_exists($action, $nadpisy)) echo $nadpisy[$action]; else echo 'smsky'; ?></h1></div>
	  <div id="pozadia_01">
	  	
	    <?php 
	    
//	    	dump($final_query);
	    	if(!isset($_SESSION['mobile_logged_in'])) echo "<br />Zaregistrovaní používatelia získajú prístup ku všetkým smskám! </br>";
	    	$max = $dba->GetNums($final_query);
	    	if($max>0)
	    	{
//	    		if(($action == '' || $action == 'moje_smsky') && isset($_SESSION['mobile_logged_in'])) fnNavi($i, $stranok, "module=smsky&amp;action=$action&amp;cat=$cat");
	    		if(($action == '' || $action == 'moje_smsky')) fnNavi($i, $stranok, "module=smsky&amp;action=$action&amp;cat=$cat");
		    	$result = $dba->GetResult($final_query);
		    	fnVypisSmsky($result);
//		    	if(($action == '' || $action == 'moje_smsky') && isset($_SESSION['mobile_logged_in'])) fnNavi($i, $stranok, "module=smsky&amp;action=$action&amp;cat=$cat");
		    	if(($action == '' || $action == 'moje_smsky')) fnNavi($i, $stranok, "module=smsky&amp;action=$action&amp;cat=$cat");
	    	}
	    	elseif($action != 'moje_smsky') 
	    	{
	    		echo "V tejto kategórii nie sú žiadne smsky";
	    	}
	    	else 
	    	{
	    		echo "Ešte ste nepridali žiadne smsky.";
	    	}
	    	?>
	  </div>
	</div>
	
<?php
//
//	if(in_array($_SESSION['my_id'], $admins))
//	{
//		if($_SESSION['pass_file'])
//		{
//			echo "<img src='file.php?id=2'/>";
//		}
//		else echo 'false';
//	}
	
	
?>
