<?php
	@session_start();
	if (!isset($_SESSION["admin"]["id"])) {
		echo "<script>location.href='index.php';</script>";
	}
	$id = "";
	if (isset($param[2])) $id = (int)$param[2];

	$sql = "select * from galeria where id = ? limit 1";
	$consulta2 = $db->prepare($sql); 
	$consulta2->bindParam(1, $id); 
	$consulta2->execute();
	$r = $consulta2->fetch(PDO::FETCH_OBJ);	
?>
<h1 class="page-header">
	Adicionar Fotos na Galeria <?=$r->nome;?>
</h1>
<form name="form1" method="post" enctype="multipart/form-data" target="iframe">
	<fieldset>
		<legend>Preencha todos os dados corretamente:</legend>

		<div class="control-group">
			<label for="imagem">Imagem:</label>
			<div class="controls">
				<input type="hidden" name="galeria_id" value="<?=$r->id;?>">
				<input type="file" name="image[]" multiple="" required class="form-control">
			</div>
		</div>
		<button type="submit" class="btn btn-success">Enviar Imagem</button>
	</fieldset>
</form>

<iframe name="frame" width="100%" height="50px"></iframe>

<div class="thumbnail">
	<h3>Fotos Cadastradas:</h3>
	<div class="row">
	<?php
		$sql = "select * from foto where galeria_id = ? order by id";
		$consulta2 = $db->prepare($sql); 
		$consulta2->bindParam(1, $id); 
		$consulta2->execute();
		while ($r = $consulta2->fetch(PDO::FETCH_OBJ)) {
			echo "<div class='cols-md-3 text-center'>";
			$id = $r->id;
			$img = $pastaFotos."/".$r->foto."p.jpg";
			if (!file_exists($img)) $img = $pastaFotos."/semfoto.jpg";
			echo "<img src='$img'><br>
			<input type='text' class='form-control' onblur='gravar($id,this)'>
			<button type='button' class='btn btn-danger' onclick='deletarFoto($id)'><i class='glyphicon glyphicon-trash'></i></button>";
			echo "</div>";
		}
	?>
	</div>
</div>