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

try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    echo "<h2>Adding Fee Payment Template to Non-Musking SMS System</h2>";
    
    // Add fee payment template for non-musking system
    $feePaymentTemplate = 'প্রিয় {name}, আপনার ফি {paid_amount} টাকা গৃহীত হয়েছে। বর্তমান বকেয়া: {due_amount} টাকা। ধন্যবাদ।';
    
    $stmt = $pdo->prepare("INSERT INTO settings (setting_key, setting_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE setting_value = ?");
    $result = $stmt->execute([
        'non_musking_tpl_fee_payment', 
        $feePaymentTemplate, 
        $feePaymentTemplate
    ]);
    
    if ($result) {
        echo "<p style='color:green;'>✅ Fee payment template added successfully!</p>";
        echo "<p><strong>Template:</strong> " . htmlspecialchars($feePaymentTemplate) . "</p>";
    } else {
        echo "<p style='color:red;'>❌ Failed to add fee payment template</p>";
    }
    
    // Also make sure non-musking is enabled
    $stmt = $pdo->prepare("INSERT INTO settings (setting_key, setting_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE setting_value = ?");
    $stmt->execute(['non_musking_enabled', '1', '1']);
    
    echo "<p>✅ Non-musking SMS system enabled.</p>";
    
    // Display current non-musking settings
    echo "<h3>Current Non-Musking Settings:</h3>";
    $stmt = $pdo->prepare("SELECT setting_key, setting_value FROM settings WHERE setting_key LIKE 'non_musking_%'");
    $stmt->execute();
    $results = $stmt->fetchAll();
    
    if ($results) {
        echo "<ul>";
        foreach ($results as $row) {
            echo "<li><strong>{$row['setting_key']}:</strong> " . htmlspecialchars($row['setting_value']) . "</li>";
        }
        echo "</ul>";
    }
    
} catch (Exception $e) {
    echo "<p style='color:red;'>Error: " . $e->getMessage() . "</p>";
}
?>