<?php
function returnNameValue($Field, $Table, $IDField, $ID){
	//echo 'dev4'; die ; 
	$strQry="SELECT $Field FROM $Table WHERE $IDField=$ID";
	$nResult =mysqli_query($strQry);
	$rowre=mysqli_fetch_array($nResult);
	$retRes=$rowre[$Field];
	return $retRes;		

}
function returnName1($Field, $Table, $IDField, $ID,$connect, $cond =false){
    //echo 'dev'; die ; 
    $strQry="SELECT $Field FROM $Table WHERE $IDField='$ID' $cond";
	//echo $strQry ; die ;
	$nResult =mysqli_query($connect,$strQry);
	$rowre=mysqli_fetch_array($nResult);
    $retRes=$rowre[$Field];
    //echo $retRes; ; die; 
	return $retRes;		
}


function sendSMSLinkKanel($smsURL)
{
$totalURL = $smsURL;
$handle = fopen($totalURL,"r");
fclose($handle); 
//$date = @file($totalURL);
}

function checkMobile($mobile)
{
	

	if(strlen($mobile)==11 && substr($mobile,0,2)=="03")
		return true;
	else
		return false;
}

function checkMobile2($mobile)
{
	if(strlen($mobile)==11 && substr($mobile,0,2)=="03")
	{
		return $mobile2 =  substr($mobile,1,11);
	}
	else
	{
		return $mobile;
	}
}


function sendApiCall($url)
{
$response = file_get_contents($url);
//print_r($response);
$xml=simplexml_load_string($response) or die("Error: Cannot create object");
if($xml && !isEmpty($xml->response))
{
return $xml;
}
return "";
}

function TelenorOLD($mask,$number,$message)
{
    $userName="923454997768"; 
    $Password="128160813"; 
    $message = urlencode($message);
    $mask = urlencode($mask);
    $number = urlencode($number);
   // echo "Telenor<br>";
    
    $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; 
    } 
    // 	echo "<br>".$urlWithSessionKey."<br>";
   // $xml=sendApiCall($urlWithSessionKey); 
   exec("lynx --dump '".$urlWithSessionKey."' > /dev/null &");
	return true;
  // echo $xml->data;
  //  return $xml->data;

}


function getSessionId($userName,$Password,$planetbeyondApiUrl) 
{ 

 $url=str_replace("#username#",$userName,$planetbeyondApiUrl); 
 $url=str_replace("#password#",$Password,$url); 
 
 $response = file_get_contents($url);
 $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; 
} 
//.................................................................................. Zong ..............................................................//

function testsk($SK){
   error_reporting(E_ALL);
    $url = "http://192.254.192.194:13013/cgi-bin/sendsms?username=faizan&password=faizan123&from=COUGAR&to=923324830192&text=AOA+test+message+%40+4%3A20+pm&dlr-mask=3&smsc=jazz1&dlr-url=https://fastsmsalerts.com/users/smppresponse?userid=1798&messageid=364331&dstatus=";
    
    $message = urlencode("عسعودی ولی");
    
    $url = "http://192.254.192.194:13013/cgi-bin/sendsms?username=faizan&password=faizan123&from=COUGAR&to=923455555613&text=".$message."&smsc=jazz1&charset=UTF-8&coding=2";
    
    
   // http://192.254.192.194:13013/cgi-bin/sendsms?username=faizan&password=faizan123&from=COUGAR&to=923324830192&text=%D8%B3%D8%B9%D9%88%D8%AF%DB%8C%20%D9%88%D9%84%DB%8C%20%D8%B9%DB%81%D8%AF%20%D9%86%DB%92%20%D8%B1%DB%8C%D8%A7%D8%B6%20%D9%85%DB%8C%DA%BA%20%DA%A9%D9%86%DA%AF%20%D8%B3%D9%84%D9%85%D8%A7%D9%86&smsc=jazz1&charset=UTF-8&coding=2
    echo $url ; 
    
     //echo $SK ; die ;
    
    $response = file_get_contents($url);
        $response = json_encode($response);
        print_r($response); die ; 
}

// ------------------ smppmobilink

function  MobilinkSMPP($tablesname,$filedname ,$api_username , $api_password , $api_unicode  , $mask,$number,$message,$messageId , $userid ,$smpp_report , $smpp_url ,$connect){
    
    
    $message = urlencode($message);
    $mask = urlencode($mask);
    $number = ($number);
	$api_username = urlencode($api_username);
	$api_password = urlencode($api_password);
	$api_unicode = urlencode($api_unicode);
	//echo 'jjj '.$smpp_report ;
	//$smpp_report = 'yes';
	//$smpp_report  = 'no';
	$smpurl = "http://192.254.192.194:13013/cgi-bin/sendsms";
	if(!empty($smpp_url)){
	$smpurl = $smpp_url ;  // "http://192.254.192.194:13013";    
	    
	}
	
	
if($smpp_report == 'yes'){
      //     $url ="http://192.254.192.194:13013/cgi-bin/sendsms?username=".$api_username."&password=".$api_password."&from=".$mask."&to=".$number."&text=".$message."&dlr-mask=3&smsc=jazz1&dlr-url=" ;
           /* woring 
		   $url ="".$smpurl."?username=".$api_username."&password=".$api_password."&from=".$mask."&to=".$number."&text=".$message."&dlr-mask=3&smsc=jazz1&dlr-url=" ;
		   
           //$url  .= "https://fastsmsalerts.com/users/smppresponse?userid%3D$userid%26messageid%3D$messageId%26dstatus%3D%25d";  
		   */
		   //$url ="".$smpurl."?username=$api_username&password=$api_password&to=$number&from=$mask&text=$message&dlr-mask=3&smsc=jazzapi&dlr-url=";
		   $url ="".$smpurl."?username=".$api_username."&password=".$api_password."&from=".$mask."&to=".$number."&text=".$message."&dlr-mask=3&smsc=jazz1&dlr-url=" ;
		   $url  .= "https://fastsmsalerts.com/users/smppresponse?userid=".urlencode($userid."&messageid=".$messageId."&dstatus=%d")   ;  
           //https://fastsmsalerts.com/users/smppresponse?userid=1561&messageid=1087769&dstatus=
           // https%3A%2F%2Ffastsmsalerts.com%2Fusers%2Fsmppresponse%3Fuserid%253D1561%2526messageid%253D1087769%2526dstatus%253D%2525d&response="0: Accepted for delivery"&messageId=1087769&tablesname=portal_quicksms&filednametelecom_response
//http://192.254.192.194:13013/cgi-bin/sendsms?username=faizan&password=faizan123&to=923001277444&from=COUGAR&text=direct
        
        }else{
            
        //$url ="http://192.254.192.194:13013/cgi-bin/sendsms?username=$user&password=$password&to=$to_list&from=$senderID&text=$textMessage";    
        $url ="".$smpurl."?username=".$api_username."&password=".$api_password."&from=".$mask."&to=".$number."&text=".$message."";
            }
        
        if($api_unicode !=  '0'){  // uudu
            $url = $url."&".$api_unicode ; 
            //charset=UTF-8&coding=2
            $url = $url."&charset=UTF-8&coding=2" ; 
            }
       // echo ' urls '.$url ; 
      //die ; 
    //    echo '<br>';
        $response = file_get_contents($url);
        $response = json_encode($response);
        //print_r($response); die ; 
        //return  $url ; // 
        //return $response; 
    // =============  3may2025
     //$sms_url1 = "http://trustscoring.com/backuuuu/cronha/smpp_save.php?url=".urlencode($url)."&response=".$response."&messageId=".$messageId."&tablesname=".$tablesname."&filedname=".$filedname;
    
    $currentdatetime = date("Y:m:d H:i:s");
$sqlUpdateSMSa="UPDATE ".$tablesname." SET ".$filedname."='".$url.'=== response==='.$response."',response_time='".$currentdatetime."' where id='$messageId'";
echo "<br>".$sqlUpdateSMS."<br>" ; 
$queryUpdateSMSa=mysqli_query($connect, $sqlUpdateSMSa);
    	//echo "<br>".$messageId." => ".$sms_url1."<br>";
        //exec("lynx --dump '".$sms_url1."' > /dev/null &");
	    //flush();
    
    
    //  =============  3may2025 END
    	
        
        
        //print_r($response); die ; 
        
	//flush();
	//ob_flush();
	//ob_clean ();
	//ob_end_clean(); 
  // echo '<pre>';print_r($response);
    return true;
   

}


// ------- 16august2024 sk
function mobilinkA($tablesname,$filedname ,$api_username , $api_password , $api_unicode ,$mask,$number,$message,$messageId ,$connect ){
    
    
	$sms_url1='';
	$message = urlencode($message);
	$mask = urlencode($mask);
    $number = urlencode($number);
    $Uname = urlencode($api_username);
    $Upass = urlencode($api_password);
    $api_unicode= urlencode($api_unicode);
   
   /*$sms_url1 = "http://trustscoring.com/backuuuu/cronha/mobilinkA.php?Uname=".$Uname."&Upass=".$Upass."&mask=".$mask."&number=".$number."&message=".$message."&messageId=".$messageId."&api_unicode=".$api_unicode."&tablesname=".$tablesname."&filedname=".$filedname;
    	echo "<br>".$messageId." => ".$sms_url1."<br>";
   
  
  
  
  	exec("lynx --dump '".$sms_url1."' > /dev/null &");
	flush();*/
	// ---------------- 3may2025 sk
	$currentdatetime = date("Y:m:d H:i:s");
// ----------------------------
$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_URL => 'https://'.$Uname.'/sms/3/messages',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS =>'{"messages":[{"sender":"'.$mask.'","destinations":[{"to":"'.$number.'"}],"content":{"text":"'.$message.'"}}]}',
    CURLOPT_HTTPHEADER => array(
        'Authorization: '.' App '.$Upass.'', // Replace with your actual token App 175ff49f9815c99e0c97d8c5c4baa3f7-ce0631b6-d484-4dd9-8779-4e22848f7a0d
        'Content-Type: application/json',
        'Accept: application/json'
    ),
));

$response = curl_exec($curl);


echo "<br>" ; print_r($response); echo  "<br>"; 
if(curl_errno($curl)){
 $result = curl_error($curl); //die ;//
}
$result =  $response; ; 
$currentdatetimeb = date("Y:m:d H:i:s");
$sqlUpdateSMSb="UPDATE ".$tablesname." SET ".$filedname."='".urlencode($result)."',response_time='".$currentdatetimeb."' where id='$smsID'";
echo "<br>".$sqlUpdateSMSb ."<br>"; 
$queryUpdateSMSb=mysqli_query($connect,$sqlUpdateSMSb);
$errors = curl_error($curl);
if(!$result){
    //die("Connection Failure");
    $result =  curl_error($curl) ; 
    $currentdatetimec = date("Y:m:d H:i:s");
$sqlUpdateSMSc="UPDATE ".$tablesname." SET ".$filedname."='".urlencode($errors)."',response_time='".$currentdatetimec."' where id='$messageId'";
//echo $sqlUpdateSMSc ; 
$queryUpdateSMSc=mysqli_query($connect,$sqlUpdateSMSc);
    
}
if(strpos($result, 'Promotional') !== false){
  // echo 'true'; 
$stopQueryskh = "select   customer , message_id  from ".$tablesname."  where id='$messageId'";
//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($curl);
	
//	ob_flush();
    return true;
}

function Mobilinkbiz($tablesname,$filedname ,$api_username , $api_password , $api_unicode ,$mask,$number,$message,$messageId  , $connect)
{
	$sms_url1=''; 
	$message = urlencode($message);
	$mask = urlencode($mask);
    $number = urlencode($number);
    $Uname = urlencode($api_username);
    $Upass = urlencode($api_password);
    $api_unicode= urlencode($api_unicode);
   
   /*$sms_url1 = "http://trustscoring.com/backuuuu/cronha/jazzapi2.php?Uname=".$Uname."&Upass=".$Upass."&mask=".$mask."&number=".$number."&message=".$message."&messageId=".$messageId."&api_unicode=".$api_unicode."&tablesname=".$tablesname."&filedname=".$filedname;
    	echo "<br>".$messageId." => ".$sms_url1."<br>";
  	exec("lynx --dump '".$sms_url1."' > /dev/null &");
	flush();*/
	
	// -------------- 3may 2025
	$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."";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $weburl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
//echo "<br>" ; print_r($result); echo  "<br>"; 
$errors = curl_error($ch);

//die ;
/*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='$messageId'";
//echo  '<br>'.$sqlUpdateSMSc.'<br>' ; 
$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='$messageId'";
//echo $sqlUpdateSMSc ; 
$queryUpdateSMSc=mysqli_query($connect,$sqlUpdateSMSc);
}
if(strpos($result, 'Promotional') !== false){
$stopQueryskh = "select  customer , message_id  from ".$tablesname."  where id='$messageId'";
$nResult =mysqli_query($connect,$stopQueryskh);
	$cData=mysqli_fetch_array($nResult);
$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);
	
	
//	ob_flush();
    return true;
}

function Mobilink($tablesname,$filedname ,$api_username , $api_password , $api_unicode ,$mask,$number,$message,$messageId , $connect)
{
	$sms_url1='';
	$message = urlencode($message);
	$mask = urlencode($mask);
    $number = urlencode($number);
    $Uname = urlencode($api_username);
    $Upass = urlencode($api_password);
    $api_unicode= urlencode($api_unicode);
   /*
    $sms_url1 = "http://trustscoring.com/backuuuu/cronha/jazz_api.php?Uname=".$Uname."&Upass=".$Upass."&mask=".$mask."&number=".$number."&message=".$message."&messageId=".$messageId."&api_unicode=".$api_unicode."&tablesname=".$tablesname."&filedname=".$filedname;
    	echo "<br>".$messageId." => ".$sms_url1."<br>";
    		exec("lynx --dump '".$sms_url1."' > /dev/null &");
	flush();
	*/
  // ---------- 3may2025
  $currentdatetime = date("Y:m:d H:i:s");
$sqlUpdateSMSa="UPDATE ".$tablesname." SET ".$filedname."='resa',response_time='".$currentdatetime."' where id='$messageId'";

$queryUpdateSMSa=mysqli_query($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='$messageId'";
//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='$messageId'";
//echo $sqlUpdateSMSc ; 
$queryUpdateSMSc=mysqli_query($connect,$sqlUpdateSMSc);
    
}
   curl_close($ch);
 // ---------- 3may2025 end 
  
//	ob_flush();
    return true;
}

function Mobilinkbizme($tablesname,$filedname ,$api_username , $api_password , $api_unicode ,$mask,$number,$message,$messageId ,$connect )
{
	$sms_url1='';
	$message = urlencode($message);
	$mask = urlencode($mask);
    $number = urlencode($number);
    $Uname = urlencode($api_username);
    $Upass = urlencode($api_password);
    $api_unicode= urlencode($api_unicode);
   
   // 15 - july 2024  $sms_url1 = "http://trustscoring.com/backuuuu/cronha/jazzapi2.php?Uname=".$Uname."&Upass=".$Upass."&mask=".$mask."&number=".$number."&message=".$message."&messageId=".$messageId."&api_unicode=".$api_unicode."&tablesname=".$tablesname."&filedname=".$filedname;
    //	
  /* $sms_url1 = "http://trustscoring.com/backuuuu/cronha/testsk.php?Uname=".$Uname."&Upass=".$Upass."&mask=".$mask."&number=".$number."&message=".$message."&messageId=".$messageId."&api_unicode=".$api_unicode."&tablesname=".$tablesname."&filedname=".$filedname;
  echo "<br>".$messageId." => ".$sms_url1."<br>";
  
  
  	exec("lynx --dump '".$sms_url1."' > /dev/null &");
	flush(); */
	// --------------- 3may2025 sk
	// ------------ 3may2025 sk
	$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."";
//echo $weburl ; 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $weburl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$errors = curl_error($ch);
echo "<br>" ; print_r($result); echo  "<br>";
if(!empty($result)){
   
    $currentdatetimec = date("Y:m:d H:i:s");
$sqlUpdateSMSc="UPDATE ".$tablesname." SET ".$filedname."='sksk --- ".urlencode($result)."',response_time='".$currentdatetimec."' where id='$messageId'";
echo 'me<br>'.$sqlUpdateSMSc.'<br>' ; 
$queryUpdateSMSc=mysqli_query($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='$messageId'";
//echo $sqlUpdateSMSc ; 
$queryUpdateSMSc=mysqli_query($connect,$sqlUpdateSMSc);
}

if(strpos($result, 'Promotional') !== false){
$stopQueryskh = "select  customer , message_id  from ".$tablesname."  where id='$messageId'";

	$nResult =mysqli_query($connect,$stopQueryskh);
$rowre=mysqli_fetch_array($nResult);
	$cData=$rowre[$Field];
$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 ';
}   
	
//	ob_flush();
    return true;
}


function Mobilinkme($tablesname,$filedname ,$api_username , $api_password , $api_unicode ,$mask,$number,$message,$messageId ,$connect)
{
	$sms_url1='';
	$message = urlencode($message);
	$mask = urlencode($mask);
    $number = urlencode($number);
    $Uname = urlencode($api_username);
    $Upass = urlencode($api_password);
    $api_unicode= urlencode($api_unicode);
   
   
    // 15 - july 2024 $sms_url1 = "http://trustscoring.com/backuuuu/cronha/jazz_api.php?Uname=".$Uname."&Upass=".$Upass."&mask=".$mask."&number=".$number."&message=".$message."&messageId=".$messageId."&api_unicode=".$api_unicode."&tablesname=".$tablesname."&filedname=".$filedname;
    
  
  /*$sms_url1 = "http://trustscoring.com/backuuuu/cronha/testsk.php?Uname=".$Uname."&Upass=".$Upass."&mask=".$mask."&number=".$number."&message=".$message."&messageId=".$messageId."&api_unicode=".$api_unicode."&tablesname=".$tablesname."&filedname=".$filedname;
  	echo "<br>".$messageId." => ".$sms_url1."<br>";
  
  	exec("lynx --dump '".$sms_url1."' > /dev/null &");
	flush();*/
	// ------------ 3may2025 sk
	$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."";
//echo $weburl ; 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $weburl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$errors = curl_error($ch);
if(!empty($result)){
   
    $currentdatetimec = date("Y:m:d H:i:s");
$sqlUpdateSMSc="UPDATE ".$tablesname." SET ".$filedname."='sksk --- ".urlencode($result)."',response_time='".$currentdatetimec."' where id='$messageId'";
//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='$messageId'";
//echo $sqlUpdateSMSc ; 
$queryUpdateSMSc=mysqli_query($connect,$sqlUpdateSMSc);
}

if(strpos($result, 'Promotional') !== false){
$stopQueryskh = "select  customer , message_id  from ".$tablesname."  where id='$messageId'";

	$nResult =mysqli_query($connect,$stopQueryskh);
$rowre=mysqli_fetch_array($nResult);
	$cData=$rowre[$Field];
$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 ';
}    

	// ------------ 3may2025 end
//	ob_flush();
    return true;
}


function Ufone($tablesname,$filedname ,$api_username , $api_password , $api_unicode ,$mask,$number,$message,$messageId ,$connect)
{
	$sms_url1='';
	$message = urlencode($message);
	$mask = urlencode($mask);
    $number = urlencode($number);
    $Uname = urlencode($api_username);
    $Upass = urlencode($api_password);
    $api_unicode= urlencode($api_unicode);
   
   /*$sms_url1 = "http://trustscoring.com/backuuuu/cronha/ufone_api.php?Uname=".$Uname."&Upass=".$Upass."&mask=".$mask."&number=".$number."&message=".$message."&messageId=".$messageId."&api_unicode=".$api_unicode."&tablesname=".$tablesname."&filedname=".$filedname;
    
   	echo "<br>ufone:".$messageId." => ".$sms_url1."<br>";
  
  	exec("lynx --dump '".$sms_url1."' > /dev/null &");

	flush(); */
	
	// ---------- 3may2025 sk 
	$weburl = "https://bsms.ufone.com/bsms_v8_api/sendapi-0.3.jsp?id=".$Uname."&password=".$Upass."&shortcode=".$mask."&mobilenum=".$number."&message=".$message."&messagetype=Transactional&lang=".$api_unicode;
echo $weburl;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $weburl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
//var_dump($result); die ; 
//var_dump(curl_getinfo($ch));
$errors = curl_error($ch);
if(!$result){
 $result = $errors ; 
}
//echo $result ; 
 //$errors. "= Api Connection Failure";
 curl_close($ch);
$currentdatetime = date("Y:m:d H:i:s");

$sqlUpdateSMS="UPDATE ".$tablesname." SET ".$filedname."='".urlencode($result)."',response_time='".$currentdatetime."' where id='$messageId'";
//echo $sqlUpdateSMS ; 
$queryUpdateSMS=mysqli_query($connect,$sqlUpdateSMS);
	
//	ob_flush();
    return true;

}
function Telenor($tablesname,$filedname ,$api_username , $api_password , $api_unicode ,$mask,$number,$message,$messageId ,$connect)
{
	$sms_url1='';
	$message = urlencode($message);
	$mask = urlencode($mask);
    $number = urlencode($number);
    $Uname = urlencode($api_username);
    $Upass = urlencode($api_password);
    $api_unicode= urlencode($api_unicode);
    
    $sms_url1 = "http://trustscoring.com/backuuuu/cronha/telenor_api.php?Uname=".$Uname."&Upass=".$Upass."&mask=".$mask."&number=".$number."&message=".$message."&messageId=".$messageId."&api_unicode=".$api_unicode."&tablesname=".$tablesname."&filedname=".$filedname;
    
  echo "<br>telenor:".$messageId." => ".$sms_url1."<br>";  
  	exec("lynx --dump '".$sms_url1."' > /dev/null &");
	flush();
//	ob_flush();
    return true;

}
function Zong($tablesname,$filedname ,$api_username , $api_password , $api_unicode ,$mask,$number,$message,$messageId,$connect)
{
	$sms_url1='';

	$message = urlencode($message);
	$mask = urlencode($mask);
    $number = urlencode($number);
    $Uname = urlencode($api_username);
    $Upass = urlencode($api_password);
    $api_unicode= urlencode($api_unicode);
    
     $sms_url1 = "https://trustscoring.com/backuuuu/cronha/zong_api.php?Uname=".$Uname."&Upass=".$Upass."&mask=".$mask."&number=".$number."&message=".$message."&messageId=".$messageId."&api_unicode=".$api_unicode."&tablesname=".$tablesname."&filedname=".$filedname;
    
    	echo "<br>".$messageId." => ".$sms_url1."<br>";
  
  	exec("lynx --dump '".$sms_url1."' > /dev/null &");

	flush();
//	ob_flush();
    return true;

}


function Zongmmm($mask,$number,$message)
{
	$sms_url1='';
	$message = urlencode($message);
	$mask = urlencode($mask);
    $number = urlencode($number);
	$sub_req_url ="https://cbs.zong.com.pk/reachrestapi/home/SendQuickSMS";
    //echo "ZONG<br>";
   //https://cbs.zong.com.pk/reachrestapi/home/SendQuickSMS?loginId=92315404939&loginPassword=123456&Destination=923137474837&Message=Sample&uniCode=0&ShortCodePrefered=n&mask=SMS2Connect
    $sms_url1 = "https://cbs.zong.com.pk/reachrestapi/home/SendQuickSMS?curl&mask=".$mask."&Destination=".$number."&Message=".$message."&uniCode=0&ShortCodePrefered=n";
    $postfields = "loginId=923154092450&loginPassword=Zong123456!@&mask=".$mask."&Destination=".$number."&Message=".$message."&uniCode=0&ShortCodePrefered=n";
    //exec("curl --show-error --silent --output /dev/null --data '".$postfields."' https://cbs.zong.com.pk/reachrestapi/home/SendQuickSMS");
    //exec("curl --show-error --data '".$postfields."' https://cbs.zong.com.pk/reachrestapi/home/SendQuickSMS");
    //exec("wget --post-data='".$postfields."' https://cbs.zong.com.pk/reachrestapi/home/SendQuickSMS");
    //exec("curl -A 'text/html; charset=utf-8' -d '".$postfields."' https://cbs.zong.com.pk/reachrestapi/home/SendQuickSMS > /dev/null &");
    
	//echo "<br>".$sms_url1."<br>";
	
	$ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://cbs.zong.com.pk/reachrestapi/home/SendQuickSMS');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);       
    //curl_setopt($ch, CURLOPT_TIMEOUT_MS, 10000);
    curl_exec($ch);
    curl_close($ch);
    
	flush();
	//ob_flush();

    return true;

}


function Zongold($mask,$number,$message)
{

    //print_r($mask);
	
	$Date = date("Y-m-d H:i:s", strtotime('+11 hours'));
	$date2 =  date("n/j/Y h:i:s a", strtotime($Date ) );		
	ini_set("soap.wsdl_cache_enabled", 0);
	$url         = 'http://cbs.zong.com.pk/ReachCWSv2/CorporateSmsV2.svc?wsdl';
	$client     = new SoapClient($url, array("trace" => 0, "exception" => 0)); 
	/*
	$resultBulkSMS = $client->BulkSmsv2(
	 array('objBulkSms' => 
		array(	'LoginId'=>  '923154092450', //here type your account name
				'LoginPassword'=>'Zong123456!@', //here type your password
				'Mask'=>$mask, //here set allowed mask against your account or you will get invalid mask
				'Message'=>$message,
				'UniCode'=>'0',
				'CampaignName'=>uniqid(),
				'CampaignDate'=>$date2, // data from where sms will start sending, if not sure type current date in m/d/y hh:mm:ss tt format.
				'ShortCodePrefered'=>'n',
				'NumberCsv'=>$number)));
	*/
	$data_info="array('objBulkSms' => 
		array(	'LoginId'=>  '923154092450', 
				'LoginPassword'=>'Zong123456!@', 
				'Mask'=>$mask, 
				'Message'=>$message,
				'UniCode'=>'0',
				'CampaignName'=>uniqid(),
				'CampaignDate'=>$date2, 
				'ShortCodePrefered'=>'n',
				'NumberCsv'=>$number))";
//	exec("lynx --dump '".$client->BulkSmsv2($data_info)."' > /dev/null &");
    //curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:urn:GetVehicleLimitedInfo" --data @request.xml http://11.22.33.231:9080/VehicleInfoQueryService.asmx
    //exec("curl --header 'Content-Type: text/xml;charset=UTF-8' --header 'SOAPAction:urn:BulkSmsv2' --data ".data_info." http://cbs.zong.com.pk/ReachCWSv2/CorporateSmsV2.svc?wsdl >  /dev/null 2>&1 & echo $!");
    //exec("curl --header 'Content-Type: text/xml;charset=UTF-8' --header 'SOAPAction:urn:BulkSmsv2' --data ".$data_info." http://cbs.zong.com.pk/ReachCWSv2/CorporateSmsV2.svc?wsdl");
	//exec("lynx --dump '".$client->BulkSmsv2($data_info)."' > /dev/null &");
 //  echo $data_info;		
   //echo $client->BulkSmsv2(array('objBulkSms' => array('LoginId'=>'923154092450','LoginPassword'=>'Zong123456!@','Mask'=>$mask,'Message'=>$message,'UniCode'=>'0','CampaignName'=>uniqid(),'CampaignDate'=>$date2, 'ShortCodePrefered'=>'n','NumberCsv'=>$number)))->BulkSmsv2Result;
    $client->BulkSmsv2(array('objBulkSms' => array('LoginId'=>'923154092450','LoginPassword'=>'Zong123456!@','Mask'=>$mask,'Message'=>$message,'UniCode'=>'0','CampaignName'=>uniqid(),'CampaignDate'=>$date2, 'ShortCodePrefered'=>'n','NumberCsv'=>$number)))->BulkSmsv2Result;
//	echo 'Zong =='.$client->BulkSmsv2($data_info)->BulkSmsv2Result; 
     //echo 'Zong =='.$resultBulkSMS->BulkSmsv2Result;
	return true;
	//return 'Zong =='.$resultBulkSMS->BulkSmsv2Result; 
	    
}
?>