<?php
SESSION_START();
include 'mysql.php';

if(isset($_GET['logout'])){
    session_destroy();
    // echo '<META HTTP-EQUIV="refresh" CONTENT="0">';
    header('Location: ../index.php');
}

if(!isset($_SESSION['admin'])):
	header('Location: ../404.html');

	

else:
?>
<html>
	<?php include '../includes/header.html'; ?>
	<?php include '../includes/navigation.php'; ?>
<body style="background-color: #eceff4;">
<div class="container" style="padding-top: 6em;">
	<div class="row">
		<?php
		$sql = "SELECT id, name, title, description FROM images";
		$result = $dbc->query($sql);
		$row = mysqli_fetch_array($result);
		if($result->num_rows > 0):
			while($row = $result->fetch_assoc()):
				$id = $row['id'];
				$image = $row['name'];
				$title = $row['title'];
				$description = $row['description'];
				$path = '../images/work/';

				if(isset($_POST[$id])){
					$delete = "DELETE FROM images WHERE id='$id'";
					if(mysqli_query($dbc, $delete)){
						echo '<meta http-equiv="refresh" content="0.0001">';
					}
				}
		?>
			<div class="col-sm-6 col-md-4">
			  <div class="thumbnail" style="height: 50%;">
			    <div class="fancy-image" style="background-image: url(<?php echo $path.$image ?>); background-size: cover; height: 235px;; background-position: center;"> </div>
			    <div class="caption">
			      <h4 style="font-size: 15pt;"><?php echo $title ?></h4>
			      <p style="font-size: 9pt;"><?php echo $description ?></p>
			      <form method="post" action="" style="position: absolute; bottom: 0;"><button name="<?php echo $id; ?>" class="btn btn-danger" style="margin-right: 15px;">Delete</button><a class="btn btn-info" href="edit_image.php?id=<?php echo $id;?>" style="color: black !important;">Edit</a></form>
			    </div>
			  </div>
			</div>
		<?php
		endwhile;
		endif;
		?>
	</div>

</div>

<?php
endif;
?>
<?php include '../includes/scripts.html'; ?>
</body>
</html>