<?php
// home.php
error_reporting(E_ALL);
ini_set('display_errors', 1);

$host = 'localhost';
$user = 'ahmeuesz_dino';
$pwd  = 'X39IW2ho3^5h6d_5';
$db   = 'ahmeuesz_myapp';
$conn = mysqli_connect($host, $user, $pwd, $db);
if (!$conn) die("DB Conn Error: " . mysqli_connect_error());

if (!isset($_GET['user']) || !is_numeric($_GET['user'])) {
    // missing user id -> go to login
    header("Location: login.php");
    exit();
}

$uid = intval($_GET['user']);
$sql = "SELECT * FROM users WHERE id = $uid LIMIT 1";
$res = mysqli_query($conn, $sql);
if (!$res || mysqli_num_rows($res) == 0) {
    header("Location: login.php");
    exit();
}

$user = mysqli_fetch_assoc($res);

// Determine image path to show (full path)
$imageUrl = 'https://'. $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/uploads/';
$imageTag = '';
if (!empty($user['profile_image'])) {
    $imageTag = 'uploads/' . $user['profile_image'];
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Home</title>
<link rel="stylesheet" href="style/home.css">
</head>
<body>
<div class="dashboard">
  <div class="card">
    <div class="profile-area">
      <?php if ($imageTag !== ''): ?>
        <img src="<?php echo htmlspecialchars($imageTag); ?>" alt="Profile" class="profile-img">
      <?php else: ?>
        <div class="placeholder">No Image</div>
      <?php endif; ?>
    </div>

    <h1 class="name"><?php echo htmlspecialchars($user['name']); ?></h1>
    <p class="email"><?php echo htmlspecialchars($user['email']); ?></p>

    <div class="actions">
      <a href="login.php" class="btn">Logout</a>
    </div>
  </div>
</div>
</body>
</html>
