<?php
require ("includes/check_auth_user.php");
require ("includes/dbconnect.php");
include ('includes/function.php');

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
//mysqli_select_db($conn, $zdb);

if (isset($_POST["submit"])) {


    $message = substr($_POST["sms"], 0, 320);

    $part1 = $_POST["part1"];
    $part2 = $_POST["part2"];
    $msg = $_POST["sms"];
    
    // $getcomp = mysqli_query($conn, "Select user, password from company ") or die(mysqli_error($conn));
    // $fetcomp = mysqli_fetch_array($getcomp);
    // $muser = mysqli_real_escape_string($conn, $fetcomp['user']);
    // $mpassword = mysqli_real_escape_string($conn, $fetcomp['password']);
    $user = "SMGJKM";
    $password = "SMGJKM2023";
    //    $message = "$msg";
    $senderid = "SMGJKM";
    $alert = $_POST["alert"];
//    $url = "144.76.39.175/api.php?";
    // $url = "http://vas.mobilogi.com/api.php?";
    $url = "http://vas.mobilogi.com/unicodeapi.php?";


//    browse($mobilenumbers);

//        $message = urlencode($message);
    $mobile = implode(",", $_POST["check_list"]);

       $message = $msg ;
    foreach ($_POST['check_list'] as $to) {

        browse($mobile);
        // $mobilenumbers = $mobile;
        $mobilenumbers = "$to";


        $ch = curl_init();
        if (!$ch) {
            die("Couldn't initialize a cURL handle");
        }


        $ret = curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "username=$user&password=$password&route=1&sender=$senderid&mobile[]=$mobilenumbers&message[]=$message");

        $ret = curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        $curlresponse = curl_exec($ch);
        if (curl_errno($ch)) {
            echo 'curl error : ' . curl_error($ch);
        }
        if (empty($ret)) {

            die(curl_error($ch));
            curl_close($ch);
        } else {
            $info = curl_getinfo($ch);
            curl_close($ch);

            echo $curlresponse;
        }
    }
   header("refresh: 1;menu.php?action=smsaddress");
echo "<script>
            parent.window.location.reload();
            </script>";        
}
?>
    
