<?php
function returnNameValue($Field, $Table, $IDField, $ID){
	
	$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){
    $strQry="SELECT $Field FROM $Table WHERE $IDField='$ID' $cond";
	$nResult =mysqli_query($connect,$strQry);
	$rowre=mysqli_fetch_array($nResult);
    $retRes=$rowre[$Field];
	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 Mobilink($mask,$number,$message)
{
    $password = urlencode('FaiRamUsman@1282aa');
    $message = urlencode($message);
    $mask = urlencode($mask);
    $number = urlencode($number);
  //  echo "JAZZ<br>";

    $url = "https://connect.jazzcmt.com/sendsms_url.html?Username=03028503264&Password=".$password."&From=".$mask."&To=".$number."&Message=".$message."";
    $new = str_replace(" ", "%20", $url);
	//echo "<script>window.open(".$new.", '_blank')</script>";
	echo $new."<br>";
	//$file = exec('lynx -dump '.$new);
	//$file = popen('lynx '.$new,'r');
	//$file = popen('php '.$new,'r');
	
	//$file = exec($new);
	//echo $file."<br>";
	//$file = fopen($new,'r');	
	//fclose($file);
		
   // $response = fopen($new,'r');
  // echo '<pre>';print_r($response);
    return true;
   
}
function Ufone($mask,$number,$message)
{
	$message = urlencode($message);
    $mask = urlencode($mask);
    $number = urlencode($number);
  
   // echo "UFONE<br>";

    $url = "https://bsms.ufone.com/bsms_v8_api/sendapi-0.3.jsp?id=03359708151&password=1412607132&shortcode=".$mask."&mobilenum=".$number."&message=".$message."&messagetype=Transactional&lang=English";
    $new = str_replace(" ", "%20", $url);
  //  $response = fopen($new,'r');
  //echo "<script>window.open(".$new.", '_blank')</script>";
	//exec($new);
  // echo '<pre>';print_r($response);
    return true;

}
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 Telenor($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; 
    } 
     
    $xml=sendApiCall($urlWithSessionKey); 
	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 Zong($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" => 1, "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)));
				
	//return true;
	return 'Zong =='.$resultBulkSMS->BulkSmsv2Result; 
	    
}
?>