<?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']);
include_once("config.php");
error_reporting(E_ALL);
//echo 'im here '; die ; 
$currentdatetime = date("Y:m:d H:i:s");
$sqlUpdateSMSa="UPDATE ".$tablesname." SET ".$filedname."='resa',response_time='".$currentdatetime."' where id='$smsID'";

$queryUpdateSMSa=mysqli_query($connect,$sqlUpdateSMSa);
//$password = urlencode('FaiRamUsman@1282aazz');

$weburl = "https://connect.jazzcmt.com/sendsms_url.html?Username=".$Uname."&Password=".$Upass."&From=".$mask."&To=".$number."&Message=".$message."&Unicode=".$api_unicode;

$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
$currentdatetimeb = date("Y:m:d H:i:s");
$sqlUpdateSMSb="UPDATE ".$tablesname." SET ".$filedname."='".urlencode($result)."',response_time='".$currentdatetimeb."' where id='$smsID'";
//echo $sqlUpdateSMS ; 
$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."' where id='$smsID'";
echo $sqlUpdateSMSc ; 
$queryUpdateSMSc=mysqli_query($connect,$sqlUpdateSMSc);
    
}
   curl_close($ch);

//var_dump($errors);
//var_dump($response);
/*
echo "<pre>";
echo var_dump($result);
echo "</pre>";
die ("im here ");
*/
//var_dump($result);




//$currentdatetime = date("Y:m:d H:i:s");
//$sqlUpdateSMS="UPDATE ".$tablesname." SET ".$filedname."='".urlencode($result)."',response_time='".$currentdatetime."' where id='$smsID'";
//echo $sqlUpdateSMS ; 
//$queryUpdateSMS=mysqli_query($connect,$sqlUpdateSMS);
?>