<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
$message = urlencode($_GET["message"]);
$mask = urlencode($_GET["mask"]);
$number = urlencode($_GET["number"]);
$smsID = urlencode($_GET["messageId"]);
$Uname = urlencode($_GET["Uname"]);
$Upass = urlencode($_GET["Upass"]);
$api_unicode= urlencode($_GET['api_unicode']);
$tablesname= urlencode($_GET['tablesname']);
$filedname= urlencode($_GET['filedname']);
//echo phpinfo(); die ;
error_reporting(E_ALL);
//echo 'im here '; die ; 
$currentdatetime = date("Y:m:d H:i:s");

// $weburl = "https://connect.jazzcmt.com/sendsms_url.html?Username=".$Uname."&Password=".$Upass."&From=".$mask."&To=".$number."&Message=".$message."&Unicode=".$api_unicode;
$weburl = "https://connect.jazzcmt.com/sendsms_url.html?Username=".$Uname."&Password=".$Upass."&From=".$mask."&To=".$number."&Message=".$message."";
//echo $weburl ; 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $weburl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
//var_dump($result);   // die ; 
//$result = "Promotional block number " ; 
//var_dump(curl_getinfo($ch));
// also get the error and response code

include_once("config.php");
//$sqlUpdateSMSa="UPDATE ".$tablesname." SET ".$filedname."='resa',response_time='".$currentdatetime."' where id='$smsID'";
//$queryUpdateSMSa=mysqli_query($connect,$sqlUpdateSMSa);
$currentdatetimeb = date("Y:m:d H:i:s");
$sqlUpdateSMSb="UPDATE ".$tablesname." SET ".$filedname."='".urlencode($result)."',response_time='".$currentdatetimeb."' where id='$smsID'";
echo $sqlUpdateSMSb ; 
$queryUpdateSMSb=mysqli_query($connect,$sqlUpdateSMSb);
$errors = curl_error($ch);
if(!$result){
    //die("Connection Failure");
    $result =  curl_error($ch) ; 
    $currentdatetimec = date("Y:m:d H:i:s");
$sqlUpdateSMSc="UPDATE ".$tablesname." SET ".$filedname."='".urlencode($errors)."',response_time='".$currentdatetimec."' , ending_time = '".$currentdatetime."'  where id='$smsID'";
echo $sqlUpdateSMSc ; 
$queryUpdateSMSc=mysqli_query($connect,$sqlUpdateSMSc);
    
}


if(strpos($result, 'Promotional') !== false){
  // echo 'true'; 

$stopQueryskh = "select   customer , message_id  from ".$tablesname."  where id='$smsID'";
//echo $stopQueryskh ;

$start_que_skh = mysqli_query($connect,$stopQueryskh);
$cData = mysqli_fetch_array($start_que_skh);
//echo 'hghg hghgh ___ '.$cData['customer'] ;
$customerid = $cData['customer'] ; 

$sqlUpdateSMSc="UPDATE sentmessages_".$customerid." SET error  ='Promotional message is blocked as per customer instructions' where id='".$cData['message_id']."'";
//echo $sqlUpdateSMSc ; 
$queryUpdateSMSc=mysqli_query($connect,$sqlUpdateSMSc);
}

   curl_close($ch);
?>