<?php
// We need to use sessions, so you should always initialize sessions using the below function
session_start();
// If the user is not logged in, redirect to the login page
if (!isset($_SESSION['account_loggedin'])) {
	header('Location: ../index.php');
	exit;
}
?>

<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,minimum-scale=1">
	<title>Dashboard</title>
	<link href="../style.css" rel="stylesheet" type="text/css">
	<link rel="stylesheet" href="../style.css">
	<style>
		body {
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;
		}

		.dropdown {
			position: relative;
			display: inline-block;
		}

		.dropbtn {
			background-color: #f1f1f1;
			color: black;
			padding: 10px 20px;
			font-size: 16px;
			border: none;
			cursor: pointer;
		}

		.dropdown-content {
			box-shadow: 0 0 10px 0;
			display: none;
			position: absolute;
			min-width: 160px;
			border: 1px solid #ddd;
			z-index: 1;
			overflow-y: auto;
		}

		.dropdown:hover .dropdown-content {
			display: block;
		}

		input[type=checkbox] {
			margin-right: 5px;
		}

		label {
			display: block;
			margin-bottom: 5px;
		}

		.submit-btn {
			margin-top: 10px;
		}

		table {
			width: 100%;
		}
	</style>
</head>

<body>

	<header class="header">

		<div class="wrapper">

			<h1>File Management System</h1>

			<nav class="menu">
				<a href="index.php">Home</a>
				<img src="" alt="image" style="border-radius: 50%; width: 40px; background: white">
				<div class="dropdown">
					<button class="dropbtn">^</button>
					<div class="dropdown-content">
						<a href="profile.php">Profile</a>
						<a href="../logout.php">
							<svg width="12" height="12" xmlns="http://www.w3.org/2000/svg"
								viewBox="0 0 512 512"><!--!Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.-->
								<path
									d="M377.9 105.9L500.7 228.7c7.2 7.2 11.3 17.1 11.3 27.3s-4.1 20.1-11.3 27.3L377.9 406.1c-6.4 6.4-15 9.9-24 9.9c-18.7 0-33.9-15.2-33.9-33.9l0-62.1-128 0c-17.7 0-32-14.3-32-32l0-64c0-17.7 14.3-32 32-32l128 0 0-62.1c0-18.7 15.2-33.9 33.9-33.9c9 0 17.6 3.6 24 9.9zM160 96L96 96c-17.7 0-32 14.3-32 32l0 256c0 17.7 14.3 32 32 32l64 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-64 0c-53 0-96-43-96-96L0 128C0 75 43 32 96 32l64 0c17.7 0 32 14.3 32 32s-14.3 32-32 32z" />
							</svg>
							Logout
						</a>
					</div>
				</div>

			</nav>

		</div>

	</header>

	<div class="content">

		<div class="page-title">
			<div class="wrap">
				<h2>Home</h2>
				<p>Welcome back, <?= htmlspecialchars($_SESSION['account_name'], ENT_QUOTES) ?>!</p>
			</div>
		</div>

		<div class="block">
			
			<?php

			$search = $_POST['search'];
			// $column = $_POST['column'];
			
			$servername = "localhost";
			$username = "root";
			$password = "Joshua2@3";
			$db = "file";

			$conn = new mysqli($servername, $username, $password, $db);


			if ($conn->connect_error) {
				die("Connection failed: " . $conn->connect_error);
			}

			$sql = "select * from file_manager where real_name like '%$search%'";

			$result = $conn->query($sql);

			?>

			<table id="example" class="display">
				<thead>
					<tr>
						<td>Name</td>
						<td>Date</td>
						<td>Type</td>
						<td>Size</td>
						<td>Action</td>
					</tr>
				</thead>
				<?php
				if ($result->num_rows > 0) {
					while ($row = $result->fetch_assoc()) {
						?>
						<tbody>
							<tr>
								<td><a target="_blank"
										href="http://localhost/filemgt/dashboard/uploads/<?php echo $row['file_name']; ?>"><?php echo $row["real_name"]; ?></a>
								</td>
								<td><?php echo $row["createdOn"]; ?></td>
								<td><?php echo $row["file_size"]; ?></td>
								<td><?php echo $row["file_type"]; ?></td>


							<?php } ?>
						</tr>
					</tbody>
				<?php } else {
					echo "0 records";
				}

				$conn->close();
				?>

		</div>
	</div>
</body>

</html>