<?php function send_sms($sms_type, $sms_provider, $numbers, $message)
{
    global $db;
    if ($sms_provider == 1)
    {
        $tempNumbers = "";
        $numbers = explode("\n", $numbers);
        foreach ($numbers as $number)
        {
            $tempNumbers .= '<no>' . $number . '</no>';
        }
        $numbers = $tempNumbers;
        $sms = $db->from('integrations')
            ->where('app_id', 5)
            ->first();
        $sms = json_decode($sms['app_data'], true);
        $postUrl = "http://sms.bizimsms.mobi:8080/api/smspost/v1";
        $postData = "<sms><username>" . $sms["username"] . "</username><password>" . $sms["password"] . "</password><header>" . $sms["sms_title"] . "</header><validity>2880</validity><message><gsm>" . $numbers . "</gsm><msg><![CDATA[-" . $message . "-]]></msg></message></sms>";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $postUrl);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, Array(
            "Content-Type: text/xml; charset=UTF-8"
        ));
        $r = curl_exec($ch);
        curl_close($ch);
        $result = "Dönüş değeri: " . $r;
    }
    elseif ($sms_provider == 2)
    {
        
        $tempNumbers = "";
        $numbers = explode("\n", $numbers);
        foreach ($numbers as $number)
        {
            $tempNumbers .= '<no>' . $number . '</no>';
        }
        $numbers = $tempNumbers;
        $sms = $db->from('integrations')
            ->where('app_id', 3)
            ->first();
        $sms = json_decode($sms['app_data'], true);
        $postUrl = "https://api.netgsm.com.tr/sms/send/xml";
        $postData = '<?xml version="1.0" encoding="UTF-8"?><mainbody><header><company dil="TR">Netgsm</company><usercode>' . $sms["username"] . '</usercode><password>' . $sms["password"] . '</password><type>1:n</type><msgheader>' . $sms["sms_title"] . '</msgheader></header><body><msg><![CDATA[' . $message . ']]></msg>' . $numbers . '</body></mainbody>';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $postUrl);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, Array(
            "Content-Type: text/xml; charset=UTF-8"
        ));
        $r = curl_exec($ch);
        curl_close($ch);
        $result = "Dönüş değeri: " . $r;
    }
    
    
    
    
    
    
    
    
    elseif ($sms_provider == 3)
    {
        $tempNumbers = "";
        $numbers = explode("\n", $numbers);
        foreach ($numbers as $number)
        {
            $tempNumbers .= '<number>' . $number . '</number>';
        }
        $numbers = $tempNumbers;
        $sms = $db->from('integrations')
            ->where('app_id', 4)
            ->first();
        $sms = json_decode($sms['app_data'], true);
        $postUrl = "http://api.iletimerkezi.com/v1/send-sms";
        $username = $sms["username"];
        $password = $sms["password"];
        $orgin_name = $sms["sms_title"];
        $postData = "<request><authentication><username>" . $username . "</username><password>" . $password . "</password></authentication><order><sender>" . $orgin_name . "</sender><sendDateTime></sendDateTime><message><text>" . $message . "</text><receipents>" . $numbers . "</receipents></message></order></request>";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $postUrl);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, Array(
            "Content-Type: text/xml; charset=UTF-8"
        ));
        $r = curl_exec($ch);
        curl_close($ch);
        $result = "Dönüş değeri: " . $r;
    }
    else
    {
        $result = "Eksik parametre mevcut.";
    }
    return $result;
}

