<?php
declare(strict_types=1);
require_once __DIR__ . '/app/Helpers/bootstrap.php';

$viewer = require_login();
$userId = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
$image = '';
if ($userId) {
    $query = db()->prepare('SELECT profile_image FROM ' . table('users') . ' WHERE id = :id AND status = \'active\' AND deleted_at IS NULL');
    $query->execute([':id' => $userId]);
    $image = (string)($query->fetchColumn() ?: '');
}
if (!str_starts_with($image, 'uploads/profile-images/')) {
    $image = 'placeholder.php?type=profile';
}
header('Location: /' . $image, true, 302);
exit;
