<?php
require_once 'includes/config.php';
requireLogin();
$user = getCurrentUser();
$db = getDB();
header('Content-Type: application/json');

// Check what user id is logged in
$uid = $user['id'];

// Check commission transactions for this user
$comms = $db->prepare("SELECT * FROM transactions WHERE user_id=? AND type='commission' LIMIT 5");
$comms->execute([$uid]);
$rows = $comms->fetchAll();

echo json_encode([
    'logged_in_user_id' => $uid,
    'logged_in_user_name' => $user['name'],
    'commission_count' => count($rows),
    'commissions' => $rows,
], JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);
