<?php
require_once 'config/database.php';

header('Content-Type: text/plain; charset=UTF-8');

echo "=== Sender ID Configuration Check ===\n\n";

// Check all sender ID related settings
$stmt = $pdo->query("SELECT setting_key, setting_value FROM settings WHERE setting_key LIKE '%sender%' OR setting_key LIKE '%sender_id%' ORDER BY setting_key");
echo "All Sender ID Settings:\n";
echo "-----------------------\n";
while($row = $stmt->fetch()) {
    echo $row['setting_key'] . ': ' . $row['setting_value'] . "\n";
}

echo "\nNon-Musking Specific Settings:\n";
echo "------------------------------\n";
$stmt = $pdo->query("SELECT setting_key, setting_value FROM settings WHERE setting_key LIKE 'non_musking_%' ORDER BY setting_key");
while($row = $stmt->fetch()) {
    echo $row['setting_key'] . ': ' . $row['setting_value'] . "\n";
}

echo "\nChecking non_musking_sender_id specifically:\n";
echo "-------------------------------------------\n";
$stmt = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = 'non_musking_sender_id'");
$stmt->execute();
$result = $stmt->fetch();
if ($result) {
    echo "non_musking_sender_id: " . $result['setting_value'] . "\n";
} else {
    echo "non_musking_sender_id: NOT SET\n";
}

// Check what's being used in the actual SMS sending
echo "\n=== Testing Actual SMS Sending ===\n";
require_once 'includes/sms_helper.php';

$non_musking_config = non_musking_config();
echo "Non-Musking Config Sender ID: " . ($non_musking_config['sender_id'] ?? 'NOT SET') . "\n";

// Test a dummy SMS send to see what sender ID would be used
echo "\nTesting API URL construction:\n";
echo "-----------------------------\n";
if (!empty($non_musking_config['api_url']) && !empty($non_musking_config['api_key'])) {
    $api_key = $non_musking_config['api_key'];
    $sender_id = $non_musking_config['sender_id'] ?? 'SCHOOL';
    $test_message = urlencode("Test message");
    $test_numbers = "8801712345678";
    
    $apiUrl = "https://sms.mram.com.bd/smsapi?api_key={$api_key}&type=text&contacts={$test_numbers}&senderid={$sender_id}&msg={$test_message}&label=transactional";
    echo "Constructed API URL:\n";
    echo $apiUrl . "\n";
    echo "\nSender ID being used: " . $sender_id . "\n";
} else {
    echo "Missing API configuration\n";
}

echo "\n=== End Check ===\n";
?>