<?php
// load_recipients.php
require_once 'php/adminconfig.php';

try {
    $stmt = $conn->prepare("
        SELECT id, firstname, lastname, email, currency_symbol, country 
        FROM users 
        WHERE email IS NOT NULL AND email != '' 
        ORDER BY firstname, lastname
    ");
    $stmt->execute();
    $users = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    foreach ($users as $user) {
        $fullName = trim($user['firstname'] . ' ' . $user['lastname']);
        $currency = $user['currency_symbol'] ?: '$';
        echo '<div class="tw_recipient_option">';
        echo '<input type="checkbox" name="recipients[]" value="' . htmlspecialchars($user['id']) . '" data-currency="' . htmlspecialchars($currency) . '">';
        echo '<div class="tw_recipient_info">';
        echo '<span class="tw_recipient_name">' . htmlspecialchars($fullName) . '</span>';
        echo '<span class="tw_recipient_email">' . htmlspecialchars($user['email']) . ' (' . htmlspecialchars($user['country']) . ' - ' . htmlspecialchars($currency) . ')</span>';
        echo '</div>';
        echo '</div>';
    }
    
} catch (PDOException $e) {
    echo '<div style="color: red; padding: 10px;">Error loading recipients: ' . htmlspecialchars($e->getMessage()) . '</div>';
}
?>