<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
 error_reporting(0);
$message = urlencode($_GET["message"]);
//echo $message ; die ; 
$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']);
//$customerid  = urlencode($_GET['customerid']);
include_once("config.php");
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 ; 
//var_dump(curl_getinfo($ch));
// also get the error and response code

//error_reporting(E_ALL);
//$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(!empty($result)){
    //die("Connection Failure");
  //  $result =  curl_error($ch) ; 
 // echo 'here ';
    $currentdatetimec = date("Y:m:d H:i:s");
$sqlUpdateSMSc="UPDATE ".$tablesname." SET ".$filedname."='sksk --- ".urlencode($result)."',response_time='".$currentdatetimec."' where id='$smsID'";
//echo $sqlUpdateSMSc ; 
$queryUpdateSMSc=mysqli_query($connect,$sqlUpdateSMSc);

// update sent table 
//$customerid = $stopData['customer'] ;
}else{
     $currentdatetimec = date("Y:m:d H:i:s");
$sqlUpdateSMSc="UPDATE ".$tablesname." SET ".$filedname."='sksk --- ".urlencode($errors)."',response_time='".$currentdatetimec."' where id='$smsID'";
//echo $sqlUpdateSMSc ; 
$queryUpdateSMSc=mysqli_query($connect,$sqlUpdateSMSc);
}




//if(strpos($result, 'Promotional') !== false){
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'] ; 
$mid = $cData['message_id'];

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


$sqlin = "insert into  promotional_blocked_numbers set mobile_number= '".$number."' , user_id='".$customerid."'";
		//echo $sqlendtimesave ; 
		$savein = mysqli_query($connect,$sqlin);
}else{
    echo 'els part ';
}    

   curl_close($ch);
?>