<?php
require 'app/config.php';
require 'function.php';
require './vendor/autoload.php';

date_default_timezone_set("Asia/Tehran");
$now = date('Y-m-d H:i:s');
//$inTwentyMinutes = date('Y-m-d H:i:s', strtotime('+30 minutes'));
$stmt = $db->prepare("SELECT * FROM users WHERE status = 'pending' AND send_time < ?");
$stmt->execute([$now]);
while ($row = $stmt->fetch()) {
    if(!empty($row['id'])){
        if (empty($row['patterncode'])) {
            send_sms($row['phone'], utf8_decode($row['massage']));
            send_to_whatsapp($row['phone'], utf8_decode($row['massage']));
            send_to_telegram($row['telegram_usern'], utf8_decode($row['massage']) , $db);
           update_send_status($row['id'] , $db);
        } else {
            send_sms_bypattern($row['phone'], $row['patterncode']);
            send_to_whatsapp($row['phone'], utf8_decode($row['massage']));
            send_to_telegram($row['telegram_usern'], utf8_decode($row['massage']),$db);
            update_send_status($row['id'] , $db);
        }

    }
    
}


