// sms oye
<?php
//echo phpinfo() ;  die ;
//ini_set('display_errors', 1);
$message = urlencode($_GET["message"]);
$mask = urlencode($_GET["mask"]);
$number = urlencode($_GET["number"]);
$smsID = urlencode($_GET["messageId"]);
$userName = urlencode($_GET["Uname"]);
$Password = urlencode($_GET["Upass"]);
$api_unicode= urlencode($_GET['api_unicode']);
$tablesname= urlencode($_GET['tablesname']);
$filedname= urlencode($_GET['filedname']);
$planetbeyondApiUrl="https://telenorcsms.com.pk:27677/corporate_sms2/api/auth.jsp?msisdn=".$userName."&password=".$Password.""; 

$sessionKey=getSessionId($userName,$Password,$planetbeyondApiUrl); 
//print($sessionKey);
//exit;

$planetbeyondApiSendSmsUrl="https://telenorcsms.com.pk:27677/corporate_sms2/api/sendsms.jsp?session_id=".$sessionKey."&to=".$number."&text=".$message.""; 
$url=str_replace("#message_text#",urlencode($message),$planetbeyondApiSendSmsUrl); 
$url=str_replace("#to_number_csv#",$number,$url); 
$url=str_replace("#from_number#",$userName,$url); 
$urlWithSessionKey=str_replace("#session_id#",$sessionKey,$url); 
if($mask!=null) 
{ 
 $urlWithSessionKey = $urlWithSessionKey . "&mask=" . $mask; 
} 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urlWithSessionKey);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
//var_dump($result);
//var_dump(curl_getinfo($ch));
// also get the error and response code
$errors = curl_error($ch);
if(!$result){
    //die("Connection Failure");
    $result = $errors ; 
    
}
   curl_close($ch);
//var_dump($errors); die ; 
//var_dump($response);
//echo "<pre>";
//echo var_dump($response);
//echo "</pre>";
//var_dump($result);
include("config.php");
$currentdatetime = date("Y:m:d H:i:s");
$sqlUpdateSMS="UPDATE ".$tablesname." SET ".$filedname."='".urlencode($result)."',response_time='".$currentdatetime."' where id='$smsID'";
$queryUpdateSMS=mysqli_query($connect,$sqlUpdateSMS);
//echo $sqlUpdateSMS ; 

function getSessionId($userName,$Password,$planetbeyondApiUrl) 
{ 
error_reporting(E_ALL);
 $url=str_replace("#username#",$userName,$planetbeyondApiUrl); 
 $url=str_replace("#password#",$Password,$url); 
 
 $response = file_get_contents($url);
// echo $url ; echo '<br>';
 //echo 'abc'.$response  ; die ;
 $response=@simplexml_load_string($response) or die("Error: Cannot create object");
 
 //print_r($response);

    if($response && substr($response->response,0,5)!=="Error") 
    { 
        return $response->data; 
    } 
 return -1; 
} 
?>