<?php
	
	require_once("mysqlconnect.php");
	require_once("global/functions.php");
	require_once("global/constants.php");
	session_start();
	
	$u=$_GET['u'];
	
	if($u<>$uhash || $_SESSION['mobile_admin_logged_in']==false)
	{
		header("location: index.php");
	}
	
	$action=$_GET['action'];
	
	if(!$action) 
	{
		header('location: '.$HTTP_REFERER);
		die();
	}
	
	if($action=='submit')
	{
		$id=$_GET['id'];
		if(is_numeric($id))
		{
			$nazov=$_POST['nazov'];
			$file=$_POST['file'];
			$image=$_POST['image'];
			$poznamka=$_POST['poznamka'];
			$typ=$_POST['typ'];
			
			if($nazov && $file)
			{
				$query="UPDATE mobile_games 
						SET nazov='".$nazov."', file='".$file."', image='".$image."', poznamka='".$poznamka."', typ='".$typ."'
						WHERE ID=$id limit 1";
				mysql_query($query, $link);
				if(mysql_affected_rows($link)>1) mysqli_rollback($link);
			}
		}
	$action='edit';
	}
			
	$id=$_GET['id'];
	if($_POST['napisane_id']<>'') $id=$_POST['napisane_id'];
	if(!fnIDexists($id, 'mobile_games')) header("location: melody_edit.php?u=$u&action=edit&id=".($id+1));
	
	
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><title>4mobile - backoffice2</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<link rel="stylesheet" href="style.css">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
<script language="JavaScript" src="script.js"></script>
</head>
<body bgcolor="#000000" align=center>
	
<?php

	
	if($action=='edit')
	{			
		if($id<>'')
		{
			$query="SELECT ID, nazov, file, image, poznamka, typ
					FROM mobile_games
					WHERE ID=$id limit 0, 1";
			$result=mysql_query($query, $link);
			if($result)
			{
				$row=mysql_fetch_array($result);
				echo "<div align=center>\n";
				echo "<img src='../images/games/".$row['image']."'>\n";
				echo "<form name=edit action=game_edit.php?u=$u&action=submit&id=$id method=POST>\n";
				echo "<table width=400 cellspacing=1 cellpadding=1 border=0>\n";
				echo "<tr><td colspan=2 align=center><a href=game_action.php?u=$u&action=delete&id=".$row['ID']." class=image_table_link>Zmaž</a><br><br></td></tr>";
				
				echo "<tr>\n";
				echo "<td align=right class=field_identifier>ID:&nbsp;</td>\n";
				echo "<td align=left><input type=text class=field name=new_ID size=5 maxlength=5 value=".$row['ID']."></td>
					  </tr>\n";
				
				echo "<tr>";
				echo "<td class=field_identifier align=right>Názov:&nbsp;</td>";
				echo "<td align=left><input type=text class=field name=nazov size=30 maxlength=50 value='".$row['nazov']."'></td>
					  </tr>";
				
				echo "<tr>";
				echo "<td class=field_identifier align=right>Súbor:&nbsp;</td>";
				echo "<td align=left><input type=text class=field name=file size=30 maxlength=30 value='".$row['file']."'></td>
					  </tr>";
				
				echo "<tr>";
				echo "<td class=field_identifier align=right>Obrázok:&nbsp;</td>";
				echo "<td align=left><input type=text class=field name=image size=30 maxlength=15 value='".$row['image']."'></td>
					 </tr>\n";
				
				echo "<tr>";
				echo "<td class=field_identifier align=right>Poznámka:&nbsp;</td>";
				echo "<td align=left><textarea class=field name=poznamka rows=6 cols=40>".$row['poznamka']."</textarea></td>
					  </tr>\n";
				
				echo "<tr>";
				echo "<td class=field_identifier align=right>Typ:&nbsp;</td>";
				echo "<td align=left><select name='typ' class=field>";
					  for($i=1; $i<=sizeof($typy); $i++)
					  {
					  		echo "<option value='$i'";
					  		if($i==$row['typ']) echo " selected";
					  		echo ">".$typy[$i]['type']."</option>";
					  }
				echo "
					  </select>
					  </td>
					  </tr>\n";
				
				echo "<tr>";
				echo "<td class=field_identifier align=right>&nbsp;</td>";
				echo "<td align=left><input type=submit class=button name=Submit value='Ulož'></td>
					  </tr>\n";
				
				echo "</table></form>";
				echo "<table width=400 border=0>";
				echo "<tr><td width=100>";
				
				$prev=$id-1;
				while(!fnIDexists($prev, 'mobile_games') && $prev>0) { $prev--; }
				$max=fnGetMaxID('mobile_games');
				
				$next=$id+1;
				while(!fnIDexists($next, 'mobile_games') && $next<$max) { $next++; }
				
				if($prev>0) echo "<a href=game_edit.php?u=$u&i=$i&action=edit&id=".$prev." class=image_table_link><<</a>";
				echo "</td><td width=200 align=center>";
				echo "<a href=games_admin.php?u=$u&i=".fnGetPage('mobile_games', $id, GAMES_NASTRANU)." class=image_table_link>späť na všetky</a>";
				echo "</td>";
				echo "<td width=100 align=right>";
				
				if($next<=$max) echo "<a href=game_edit.php?u=$u&i=$i&action=edit&id=".$next." class=image_table_link>>></a>";
				echo "</td></tr>";
				echo "</table>";
				echo "</div>";
			}
		}
	}

?>

</body>
</html>
<?php
	mysql_close($link);
?>