<?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($id!=0)
		{
			$file=$_POST['file'];
			$cat=$_POST['cat'];
			$res=$_POST['res'];
			$dload=$_POST['dload'];
			$pridal=$_POST['pridal'];
			if($file && $cat && $pridal)
			{
				$query="UPDATE mobile_pozadia 
						SET file='".$file."', cat='$cat', res='$res', dload='$dload', pridal='".$pridal."'
						WHERE ID=$id limit 1";
				mysql_query($query, $link);
				if(mysql_affected_rows($link)>1) mysqli_rollback($link);
			} else $query = 'asdfg';
		}
	$action='edit';
	}
			
	$id=$_GET['id'];
	if($_POST['napisane_id']<>'') $id=$_POST['napisane_id'];
	if(!fnIDexists($id, 'mobile_pozadia')) header("location: image_edit.php?u=$u&action=edit&id=".($id+1));
	
	
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><title>4mobile - backoffice</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

	echo 'kvera: '.$query;
	if($action=='edit')
	{
		$resolution=array
			(
			0 =>  'iné' ,
			1 =>  '128 x 128' ,
			2 =>  '174 x 130' ,
			3 =>  '128 x 160' ,
			4 =>  '101 x 80' ,
			5 =>  '176 x 220' ,
			6 =>  '132 x 176',
			7 =>  '208 x 208' 
			);
			
		$category=array
			(
			1 =>  'Auto-moto' ,
			2 =>  'Erotika' ,
			3 =>  'Modelky' ,
			4 =>  'Autá & ženy' ,
			5 =>  'Funny' ,
			6 =>  'Animované' ,
			7 =>  'Bábätká' ,
			8 =>  'Pre ženy' ,
			9 =>  'Rozprávky & film' ,
			10 =>  'Príroda' ,
			11 =>  'Mix' ,
			12 =>  'Láska' ,
			13 =>  'Zvieratká' ,
			14 =>  'Šport' ,
			15 =>  'Art' ,
			16 =>  'Logá' ,
			17 =>  'Celebrity' ,
			18 =>  'Vianoce' ,
			19 =>  'hudba' ,
			);
		
			
		if($id<>'')
		{
			$query="SELECT ID, file, cat, res, dload, pridal
					from mobile_pozadia
					WHERE ID=$id limit 0, 1";
			$result=mysql_query($query, $link);
			if($result)
			{
				$row=mysql_fetch_array($result);
				echo "<div align=center>\n";
				if($row["ID"]>4922){$path='pozadia2/';}
				if($row["ID"]<4922){$path='pozadia/';}
				echo "<img src=../".$path.$row['file'].">";
				echo "<form name=edit action=image_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=images_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><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>\n";
				echo "<tr><td class=field_identifier align=right>Kategória:&nbsp;</td>";
				echo "<td align=left><select name=cat class=field>\n";
				echo "<option value=".$row['cat'].">".$category[$row['cat']]."</option>\n";
					for($j=1;$j<=sizeof($category);$j++)
					{
						echo "<option value=$j>".$category[$j]."</option>\n";
					}
				echo "</select></td></tr>";
				echo "<tr><td class=field_identifier align=right>Rozlíšenie:&nbsp;</td>";
				echo "<td align=left><select name=res class=field>\n";
				echo "<option value=".$row['res'].">".$resolution[$row['res']]."</option>\n";
					for($j=0;$j<=sizeof($resolution)-1;$j++)
					{
						echo "<option value=$j>".$resolution[$j]."</option>\n";
					}
				echo "</select></td></tr>";
				echo "<tr><td class=field_identifier align=right>Stiahnuté:&nbsp;</td>";
				echo "<td align=left><input type=text class=field name=dload size=5 maxlength=5 value=".$row['dload']."></td></tr>\n";
				echo "<tr><td class=field_identifier align=right>Pridal:&nbsp;</td>";
				echo "<td align=left><input type=text class=field name=pridal size=15 maxlength=15 value=".$row['pridal']."></td></tr>\n";
				echo "<tr><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_pozadia') && $prev>0) { $prev--; }
				$max=fnGetMaxID('mobile_pozadia');
				$next=$id+1;
				while(!fnIDexists($next, 'mobile_pozadia') && $next<$max) { $next++; }
				if($prev>0) echo "<a href=image_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=images_admin.php?u=$u&i=".fnGetPage('mobile_pozadia', $id, IMAGES_NASTRANU)." class=image_table_link>späť na všetky</a>";
				echo "</td>";
				echo "<td width=100 align=right>";
				
				if($next<=$max) echo "<a href=image_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);
?>