<?php
/**
 * get_user_photo.php
 * সরাসরি Database থেকে User-এর Saved Photo আনে —
 * GetUserInfo.php-এর Bug (সবসময় "1" পাঠায়) এড়িয়ে।
 */
include __DIR__ . "/deepanshu/conn.php";
include __DIR__ . "/deepanshu/functions2.php";
header('Content-Type: application/json; charset=utf-8');

$bearer = explode(" ", $_SERVER['HTTP_AUTHORIZATION'] ?? '');
$author = $bearer[1] ?? '';
$is_jwt_valid = is_jwt_valid($author);
$data_auth = json_decode($is_jwt_valid, true);

if (($data_auth['status'] ?? '') !== 'Success') {
    echo json_encode(['code' => 1, 'msg' => 'Unauthorized']);
    exit;
}

$userId = intval($data_auth['payload']['id']);
$row = $conn->query("SELECT user_photo FROM shonu_subjects WHERE id = '$userId'")->fetch_assoc();

echo json_encode(['code' => 0, 'photo' => $row['user_photo'] ?? '']);
