<?php require("check.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<title>Administratoriaus prisijungimas</title>
<link href="stilius.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="js/lightbox.js"></script>


<?php
	require("configas.php");
	global $dbhost, $dbuname, $dbpass, $dbname; 
	mysql_connect($dbhost, $dbuname, $dbpass); 

	mysql_query("SET NAMES utf8");
	@mysql_select_db($dbname) or die ("Unable to select database !"); 
?>
</head>
<body>

<?php

if (isset($_POST['keisti'])) {
	$apie = $_POST['apie'];
	$id = $POST['id'];
	while (list($id, $apie) = each($array)) {
	$uzklausa = "UPDATE fotos SET apie='$apie' WHERE id='$id'";
	$rezultatas = mysql_query($uzklausa) or die(mysql_error());
	
	}
}

?>

<table id="pagr" align="center">
	<tr valign="top">
		<td class="meniu">
			<table class="meniu2" width="200px">
				<?php require("meniu.php"); ?>
			</table>			
		</td>
		<td class="turinys">
			<table border="0" class="turinys2">
				<tr>
					<td colspan="2" class="t1">Nuotraukos esan&#269;ios puslapyje</td>
				</tr>
				<tr>
					<td valign="top" class="lentele">
					<?php 
					$id=$_GET["id"];
					if ($id==NULL){
						rodyti();
					}else {
						trinti($id);
					}	
					
					function trinti ($id){
						$uzklausa2 = "SELECT name FROM fotos WHERE id='$id'";
						$rezultatas2 = mysql_query($uzklausa2) or die(mysql_error());
						$eilute = mysql_fetch_array($rezultatas2);
						$failas = $eilute['name'];
						$myFile = "../fotos/".$failas;
						unlink($myFile);					
					
						$sql = "DELETE FROM fotos WHERE id='$id'";
						$rez = mysql_query($sql) or die(mysql_error());
						rodyti();
					}
					function rodyti(){ ?>
						<form action="<? echo $php_self ?>" method="post">
						
					<?php
						$sql2 = "SELECT * FROM fotos";
						$rez2 = mysql_query($sql2) or die(mysql_error());
						$num_rows = mysql_num_rows($rez2);
						$eilutes = intval ($num_rows / 2);
						
						$sql = "SELECT * FROM fotos ORDER BY id DESC LIMIT 0, $eilutes";
						$rez = mysql_query($sql) or die(mysql_error());
						echo "<table>";
						while ($row = mysql_fetch_array($rez)){
							    
							echo "<tr valign='top'><td><a href='../fotos/".$row['name']."' rel='lightbox[roadtrip]' title='".$row['apie']."'><img src='../fotos/".$row['name']."' alt='img' width='80' height='60' border='0'  /></a> <a href='fgalerija.php?id=".$row['id']."' class='busena'><img src='images/stop.png' border='0'/></a></td></tr>";
							}
						echo "</table></td>";
						
						$sql3 = "SELECT * FROM fotos ORDER BY id DESC LIMIT $eilutes, $num_rows";
						$rez3 = mysql_query($sql3) or die(mysql_error());
						echo "<td class='lentele'><table>";
						while ($row = mysql_fetch_array($rez3)){
							    
							echo "<tr valign='top'><td><a href='../fotos/".$row['name']."' rel='lightbox[roadtrip]' title='".$row['apie']."'><img src='../fotos/".$row['name']."' alt='img' width='80' height='60' border='0'  /></a> <a href='fgalerija.php?id=".$row['id']."' class='busena'><img src='images/stop.png' border='0'/></a></td></tr>";
							}
						echo "</table>";
					}

					?>
						</form>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>

</body>
</html>