<?php
// Set default timezone
date_default_timezone_set('Asia/Kolkata');

// Database configuration
require_once('../database/dbconfig.php');

// Database connection
$pdo = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

// Official SMS template
$sms_template = "Dear {NAME},\n\nYour WebUPI account (Username: {USERNAME}) is pending activation.\n\nTo activate:\n1. Visit: https://fastpay.us.cc/activate\nOR\n2. Reply 'YES' to this SMS\n\n- WebUPI Team";

// Get pending accounts
$stmt = $pdo->query("SELECT username, mobile_no, owner_name FROM loginusers WHERE status = 'pending' AND mobile_no REGEXP '^[6-9][0-9]{9}$'");

while ($user = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $message = str_replace(
        ['{NAME}', '{USERNAME}'], 
        [$user['owner_name'], $user['username']], 
        $sms_template
    );
    
    $api_url = "https://bulk.quickbulksms.in.net/send-message?" . http_build_query([
        'api_key' => 'HRM2n3B25y2lzu6bsZAxVzwwsj8Het',
        'sender' => '919157455623',
        'number' => '91' . $user['mobile_no'],
        'message' => $message
    ]);
    
    // Send SMS (simple method)
    @file_get_contents($api_url);
}

echo "Pending account notifications sent";
?>