<?php
function activeSender($userAccount,$passAccount,$senderId,$activeKey)
{
	$str = explode("#",$senderId);
	$senderId = $str[1];
	$url = "https://api.taqnyat.sa/activeSender.php?mobile=".$userAccount."&password=".$passAccount."&senderId=".$senderId."&activeKey=".$activeKey;
	$handle = fopen($url,"r");
	$result = fread($handle, 10240);
	return $result;
}
function addSender($userAccount,$passAccount,$sender,$siteSender)
{
	if (empty($siteSender))
	{
		$siteSender  = $_SERVER['SERVER_NAME'];
	}
	$url = "https://api.taqnyat.sa/addSender.php?mobile=".$userAccount."&password=".$passAccount."&sender=".$sender."&siteSender=".$siteSender;
	$handle = fopen($url,"r");
	$result = fread($handle, 10240);
	return $result;
}
function SendSMS($userAccount,$passAccount,$numbers, $sender, $msg, $MsgID,$msgUniqe, $timeSend=0, $dateSend=0, $deleteKey=0)
{
    global $applicationType;
	if(empty($applicationType))
		$applicationType = '17'; 
    $msg = convertToUnicode($msg);
	$sender = trim($sender);
	$sender = urlencode($sender);
	$domainName = "";
	$url = "https://api.taqnyat.sa/msgSend.php?mobile=".$userAccount."&password=".$passAccount."&numbers=".$numbers."&sender=".$sender."&msg=".$msg."&timeSend=".$timeSend."&dateSend=".$dateSend."&applicationType=".$applicationType."&domainName=".$domainName."&returnJson=1&msgId=".$MsgID."&deleteKey=".$deleteKey;
	$handle = fopen($url,"r");
	$result = fread($handle, 10240);
	return $result;
}
function balanceSMS($userAccount,$passAccount)
{
	$url = "https://api.taqnyat.sa/balance.php?mobile=".$userAccount."&password=".$passAccount;
	$handle = fopen($url,"r");
	$result = fread($handle, 10240);
	list($part1,$part2)= explode("/",$result);
	$result = $part1."/".$part2;
	return $result;
}
function forgetAccountPassword($mobile,$type)
{
	if ($type == "email")
	{
		$type= "2";
	}
	if ($type == "mobile")
	{
		$type= "1";
	}	
	$url = "https://api.taqnyat.sa/forgetPassword.php?mobile=".$mobile."&type=".$type;
	$handle = fopen($url,"r");
	$result = fread($handle, 10240);
	return $result;
}
function changeAccountPassword($mobile,$password,$newPassword)
{
	$url = "https://api.taqnyat.sa/changePassword.php?mobile=".$mobile."&password=".$password."&newPassword=".$newPassword;
	$handle = fopen($url,"r");
	$result = fread($handle, 10240);
	return $result;
}
function mobilyProgImgAd($path,$mobile,$version)
{
	global $applicationType;
	$posHttp=strpos($path,'http://');
	if($posHttp)
	{
		$newPath=explode('http://',$path);
		$path=$newPath[1];
	}
    $url = $path."?userName=".$mobile."&version=".$version."&applicationType=".$applicationType.""; 
    if (!(@$fp =fopen($url,"r")))
		echo "<br><center>Erorr</center><br>";
    else
    {
       @$result=@fread($fp,10);
       @fclose(@$fp);
    }
	if( substr($result,0,11) != '<mobilyAds>' )
	$result='';	
	return $result;
}
function sendStatus()
{
	$url = "https://api.taqnyat.sa/sendStatus.php";
	$handle = fopen($url,"r");
	$result = fread($handle, 10240);
	return $result;
}
function prefixDeny()
{
    $url = "https://api.taqnyat.sa/prefixDeny.php";    
	$handle = fopen($url,"r");
	$result = fread($handle, 10240);   
    return $result;
}
function getSenderAvailability($userAccount)
{
	$url = "https://api.taqnyat.sa/senderAvailability.php?mobile=".$userAccount;
	$handle = fopen($url,"r");
	$result = fread($handle, 10240);
	return $result;
}
function checkMsgLength($msg)
{
	$msg = convertToUnicode($msg);
	$url = "https://api.taqnyat.sa/msgLength.php?msg=".$msg;
	$handle = fopen($url,"r");
	$result = fread($handle, 10240);
	return $result;
}
function checkUser($userAccount,$passAccount,$activeKey)
{
	$url = "https://api.taqnyat.sa/checkUser.php?mobile=".$userAccount."&password=".$passAccount."&activeKey=".$activeKey;
	$handle = fopen($url,"r");
	$result = fread($handle, 10240);
	list($part1,$part2)= explode("/",$result);
	$result = $part1."/".$part2;
	return $result;
}
function checkSMS($userAccount,$passAccount,$numbers, $sender, $msg, $MsgID,$timeFirst, $msgUniqe)
{
	global $conn;
	global $applicationType;
	if(empty($applicationType))
		$applicationType = '17';
	$numbers = str_replace(" ","", $numbers);
	$numbers = str_replace(",,",",", $numbers);
	$msg = convertToUnicode($msg);
	$sender = urlencode($sender);
	$timeSend = 0;
	$dateSend = 0;
	$contextPostValues = http_build_query(array('mobile'=>$userAccount, 'password'=>$passAccount, 'numbers'=>$numbers, 'sender'=>$sender, 'msg'=>$msg, 'timeSend'=>$timeSend, 'dateSend'=>$dateSend, 'applicationType'=>$applicationType, 'domainName'=>$domainName, 'msgId'=>$MsgID, 'sendDate'=>$timeFirst));
	$contextOptions['http'] = array('method' => 'POST', 'header'=>'Content-type: application/x-www-form-urlencoded', 'content'=> $contextPostValues, 'max_redirects'=>0, 'protocol_version'=> 1.0, 'timeout'=>10, 'ignore_errors'=>TRUE);
	$contextResouce  = stream_context_create($contextOptions);
	$url = "https://api.taqnyat.sa/msgCheck.php";
	$handle = fopen($url, 'r', false, $contextResouce);
	$result = stream_get_contents($handle);
	return $result;
}
function checkAlphasSender($userAccount, $passAccount)
{
    $url = "https://api.taqnyat.sa/checkAlphasSender.php?mobile=".$userAccount."&password=".$passAccount;
    $handle = fopen($url,"r");
    $result = fread($handle, 10240);
    return $result;
}
?>