<?
session_start();
(key_exists('id', $_GET) && $_GET['id']<>'') ? $id=$_GET["id"] : $id = 0;
(key_exists('hlas', $_GET) && $_GET['hlas']<>'') ? $hlas=$_GET["hlas"] : $hlas = 0;
(key_exists('action', $_GET) && $_GET['action']<>'') ? $action=$_GET["action"] : $action = 0;

$vote_actions = array('image', 'melody', 'game', 'video');

if($id!=0 && $hlas>0 && $hlas<=5 && in_array($action, $vote_actions))
{
	if($action=='image') $session_name='mobile_image_'.$id;
	if($action=='melody') $session_name='mobile_melody_'.$id;
	if($action=='game') $session_name='mobile_game_'.$id;
	if($action=='video') $session_name='mobile_video_'.$id;
	
	
	if($action=='image'){$query="SELECT hlasov, sucet FROM mobile_pozadia WHERE ID=$id";}
	if($action=='melody'){$query="SELECT hlasov, sucet FROM mobile_melody WHERE ID=$id";}
	if($action=='game'){$query="SELECT hlasov, sucet FROM mobile_games WHERE ID=$id";}
	if($action=='video'){$query="SELECT hlasov, sucet FROM mobile_video WHERE ID=$id";}
	
	if($query<>'')
	{
		$result = $dba->GetResult($query);
		$row = mysql_fetch_array($result);
		$hlasov = $row["hlasov"] + 1;
		$sucet = $row["sucet"] + $hlas;
		$priemer = round($sucet/$hlasov,2);
	}
		
	$query='';
	if($action=='image' && !session_is_registered($session_name)){$query="UPDATE mobile_pozadia SET hlasov='$hlasov', sucet='$sucet', priemer='$priemer' WHERE ID=$id"; session_register($session_name);}
	if($action=='melody' && !session_is_registered($session_name)){$query="UPDATE mobile_melody SET hlasov='$hlasov', sucet='$sucet', priemer='$priemer' WHERE ID=$id"; session_register($session_name);}
	if($action=='game' && !session_is_registered($session_name)){$query="UPDATE mobile_games SET hlasov='$hlasov', sucet='$sucet', priemer='$priemer' WHERE ID=$id"; session_register($session_name);}
	if($action=='video' && !session_is_registered($session_name)){$query="UPDATE mobile_video SET hlasov='$hlasov', sucet='$sucet', priemer='$priemer' WHERE ID=$id"; session_register($session_name);}
	if($query<>'')
	{
		//$dba->ExecuteQuery($query);
	}
}
if($_SERVER['REMOTE_ADDR'] == '62.168.101.9')
{
    echo $hlas;   
}
else {
header("location: ".$HTTP_REFERER);
}
 ?>
