<?php
function activeSender($userAccount,$passAccount,$senderId,$activeKey)
{
	$str = explode("#",$senderId);
	$senderId = $str[1];
	
	$stringToPost = "mobile=".$userAccount."&password=".$passAccount."&senderId=".$senderId."&activeKey=".$activeKey;
	$stringToPostLength = strlen($stringToPost);
	$fsockParameter = "POST /activeSender.php HTTP/1.0 \r\n";
	$fsockParameter.= "Host: api.taqnyat.sa \r\n";
	$fsockParameter.= "Content-type: application/x-www-form-urlencoded \r\n";
	$fsockParameter.= "Content-length: $stringToPostLength \r\n";
	$fsockParameter.= "$stringToPost \r\n";

	$fsockConn = fsockopen("https://api.taqnyat.sa", 80, $errno, $errstr, 30);
	fputs($fsockConn,$fsockParameter);
	
	$result = ""; 
	$clearResult = false; 
	
	while(!feof($fsockConn))
	{
		$line = fgets($fsockConn, 10240);
		if($line == "\r\n" && !$clearResult)
		$clearResult = true;
		
		if($clearResult)
			$result .= trim($line); 
	}
	return $result;
}
function addSender($userAccount,$passAccount,$sender,$siteSender)
{
	if (empty($siteSender))
	{
		$siteSender  = $_SERVER['SERVER_NAME'];
	}
	$stringToPost = "mobile=".$userAccount."&password=".$passAccount."&sender=".$sender."&siteSender=".$siteSender;
	$stringToPostLength = strlen($stringToPost);
	$fsockParameter = "POST /addSender.php HTTP/1.0 \r\n";
	$fsockParameter.= "Host: api.taqnyat.sa \r\n";
	$fsockParameter.= "Content-type: application/x-www-form-urlencoded \r\n";
	$fsockParameter.= "Content-length: $stringToPostLength \r\n\r\n";
	$fsockParameter.= "$stringToPost"; 
	$fsockConn = fsockopen("https://api.taqnyat.sa", 80, $errno, $errstr, 30);
	fputs($fsockConn,$fsockParameter);
	$result = ""; 
	$clearResult = false; 
	
	while(!feof($fsockConn))
	{
		$line = fgets($fsockConn, 10240);
		if($line == "\r\n" && !$clearResult)
		$clearResult = true;
		
		if($clearResult)
			$result .= trim($line); 
	}
	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 = "";
	$stringToPost = "mobile=".$userAccount."&password=".$passAccount."&numbers=".$numbers."&sender=".$sender."&msg=".$msg."&timeSend=".$timeSend."&dateSend=".$dateSend."&applicationType=".$applicationType."&domainName=".$domainName."&returnJson=1&msgId=".$MsgID."&deleteKey=".$deleteKey;
	$stringToPostLength = strlen($stringToPost);
	$fsockParameter = "POST /msgSend.php HTTP/1.0 \r\n";
	$fsockParameter.= "Host: api.taqnyat.sa \r\n";
	$fsockParameter.= "Content-type: application/x-www-form-urlencoded \r\n";
	$fsockParameter.= "Content-length: $stringToPostLength \r\n\r\n";
	$fsockParameter.= "$stringToPost";
	$fsockConn = fsockopen("https://api.taqnyat.sa", 80, $errno, $errstr, 30);
	fputs($fsockConn, $fsockParameter);
	$result = ""; 
	$clearResult = false; 
	while(!feof($fsockConn))
	{
		$line = fgets($fsockConn, 10240);
		if($line == "\r\n" && !$clearResult)
		$clearResult = true;
		
		if($clearResult)
			$result .= trim($line); 
	}
    return $result;
}
function balanceSMS($userAccount,$passAccount)
{
	$stringToPost = "mobile=".$userAccount."&password=".$passAccount;
	$stringToPostLength = strlen($stringToPost);
	$fsockParameter = "POST /balance.php HTTP/1.0 \r\n";
	$fsockParameter.= "Host: api.taqnyat.sa \r\n";
	$fsockParameter.= "Content-type: application/x-www-form-urlencoded \r\n";
	$fsockParameter.= "Content-length: $stringToPostLength \r\n\r\n";
	$fsockParameter.= "$stringToPost";

	$fsockConn = fsockopen("https://api.taqnyat.sa", 80, $errno, $errstr, 5);
	fputs($fsockConn,$fsockParameter);
	
	$result = ""; 
	$clearResult = false; 
	while(!feof($fsockConn))
	{
		$line = fgets($fsockConn, 10240);
		if($line == "\r\n" && !$clearResult)
		$clearResult = true;
		
		if($clearResult)
			$result .= trim($line); 
	}
	list($part1,$part2) = explode("/",$result);
	$result = $part1."/".$part2;
	return $result;
}
function forgetAccountPassword($mobile,$type)
{
	if ($type == "email")
	{
		$type= "2";
	}
	if ($type == "mobile")
	{
		$type= "1";
	}
	$stringToPost = "mobile=".$userAccount."&type=".$type;
	$stringToPostLength = strlen($stringToPost);
	$fsockParameter = "POST /forgetPassword.php HTTP/1.0 \r\n";
	$fsockParameter.= "Host: api.taqnyat.sa \r\n";
	$fsockParameter.= "Content-type: application/x-www-form-urlencoded \r\n";
	$fsockParameter.= "Content-length: $stringToPostLength \r\n\r\n";
	$fsockParameter.= "$stringToPost";

	$fsockConn = fsockopen("https://api.taqnyat.sa", 80, $errno, $errstr, 5);
	fputs($fsockConn,$fsockParameter);
	
	$result = ""; 
	$clearResult = false; 
	while(!feof($fsockConn))
	{
		$line = fgets($fsockConn, 10240);
		if($line == "\r\n" && !$clearResult)
		$clearResult = true;
		
		if($clearResult)
			$result .= trim($line); 
	}
	return $result;
}
function changeAccountPassword($mobile,$password,$newPassword)
{
	$stringToPost = "mobile=".$userAccount."&password=".$passAccount."&newPassword=".$newPassAccount;
	$stringToPostLength = strlen($stringToPost);
	$fsockParameter = "POST /changePassword.php HTTP/1.0 \r\n";
	$fsockParameter.= "Host: api.taqnyat.sa \r\n";
	$fsockParameter.= "Content-type: application/x-www-form-urlencoded \r\n";
	$fsockParameter.= "Content-length: $stringToPostLength \r\n\r\n";
	$fsockParameter.= "$stringToPost";

	$fsockConn = fsockopen("https://api.taqnyat.sa", 80, $errno, $errstr, 5);
	fputs($fsockConn,$fsockParameter);
	
	$result = ""; 
	$clearResult = false; 
	while(!feof($fsockConn))
	{
		$line = fgets($fsockConn, 10240);
		if($line == "\r\n" && !$clearResult)
		$clearResult = true;
		
		if($clearResult)
			$result .= trim($line); 
	}
	return $result;
}
function mobilyProgImgAd($path,$mobile,$version)
{
	global $applicationType;
	$posHttp=strpos($path,'http://');
	if($posHttp)
	{
		$newPath=explode('http://',$path);
		$path=$newPath[1];
	}
	$end=strpos($path,'/');
  	$path1=substr($path,0,$end);
	$path2=substr($path,$end);
	$StringHttpPost="userName=".$mobile."&version=".$version."&applicationType=".$applicationType."";
	$len = strlen($StringHttpPost);
	$p = "POST ".$path2." HTTP/1.0\r\n"; 	// Use This String
	$p.= "Host: ".$path1." \r\n";
	$p.= "Content-type: application/x-www-form-urlencoded\r\n";
	$p.= "Content-length: $len\r\n\r\n";
	$p.= "$StringHttpPost\r\n";
	$p.= "\r\n";
	$fp = fsockopen ($path1, 80, $errno, $errstr, 30);
	fputs ($fp,$p);
 	$result = ""; 
	$clearResult = false; 
	while(!feof($fp))
	{
		$line = fgets($fp, 10240);
		if($line == "\r\n" && !$clearResult)
			$clearResult = true;
		if($clearResult)
			$result .= trim($line); 
	}
	fclose($fp);
	if( substr($result,0,11) != '<mobilyAds>')
		$result='';
	return $result;
}
function sendStatus()
{
	$fsockParameter = "POST /sendStatus.php HTTP/1.0 \r\n";
	$fsockParameter.= "Host: api.taqnyat.sa \r\n";
	$fsockParameter.= "Content-type: application/x-www-form-urlencoded \r\n";
	$fsockParameter.= "Content-length: 0 \r\n\r\n";
	$fsockConn = fsockopen("https://api.taqnyat.sa", 80, $errno, $errstr, 5);
	fputs($fsockConn,$fsockParameter);
	
	$result = ""; 
	$clearResult = false; 
	
	while(!feof($fsockConn))
	{
		$line = fgets($fsockConn, 10240);
		if($line == "\r\n" && !$clearResult)
		$clearResult = true;
		
		if($clearResult)
			$result .= trim($line); 
	}
	return $result;
}
function prefixDeny()
{
	$fsockParameter = "POST /prefixDeny.php HTTP/1.0 \r\n";
	$fsockParameter.= "Host: api.taqnyat.sa \r\n";
	$fsockParameter.= "Content-type: application/x-www-form-urlencoded \r\n";
	$fsockParameter.= "Content-length: 0 \r\n\r\n";
	$fsockConn = fsockopen("https://api.taqnyat.sa", 80, $errno, $errstr, 5);
	fputs($fsockConn,$fsockParameter);

	$result = ""; 
	$clearResult = false; 
	
	while(!feof($fsockConn))
	{
		$line = fgets($fsockConn, 10240);
		if($line == "\r\n" && !$clearResult)
		$clearResult = true;
		
		if($clearResult)
			$result .= trim($line); 
	}
	return $result;
}
function getSenderAvailability($userAccount)
{
	$stringToPost = "mobile=".$userAccount;
	$stringToPostLength = strlen($stringToPost);
	$fsockParameter = "POST /senderAvailability.php HTTP/1.0 \r\n";
	$fsockParameter.= "Host: api.taqnyat.sa \r\n";
	$fsockParameter.= "Content-type: application/x-www-form-urlencoded \r\n";
	$fsockParameter.= "Content-length: $stringToPostLength \r\n\r\n";
	$fsockParameter.= "$stringToPost";

	$fsockConn = fsockopen("https://api.taqnyat.sa", 80, $errno, $errstr, 5);
	fputs($fsockConn,$fsockParameter);
	
	$result = ""; 
	$clearResult = false; 
	while(!feof($fsockConn))
	{
		$line = fgets($fsockConn, 10240);
		if($line == "\r\n" && !$clearResult)
		$clearResult = true;
		
		if($clearResult)
			$result .= trim($line); 
	}
	return $result;
}
function checkMsgLength($msg)
{
	$msg = convertToUnicode($msg);
	$stringToPost = "msg=".$msg;
	$stringToPostLength = strlen($stringToPost);
	$fsockParameter = "POST /msgLength.php HTTP/1.0 \r\n";
	$fsockParameter.= "Host: api.taqnyat.sa \r\n";
	$fsockParameter.= "Content-type: application/x-www-form-urlencoded \r\n";
	$fsockParameter.= "Content-length: $stringToPostLength \r\n\r\n";
	$fsockParameter.= "$stringToPost";

	$fsockConn = fsockopen("https://api.taqnyat.sa", 80, $errno, $errstr, 5);
	fputs($fsockConn,$fsockParameter);
	
	$result = ""; 
	$clearResult = false; 
	while(!feof($fsockConn))
	{
		$line = fgets($fsockConn, 10240);
		if($line == "\r\n" && !$clearResult)
		$clearResult = true;
		
		if($clearResult)
			$result .= trim($line); 
	}
	return $result;
}
function checkUser($userAccount,$passAccount,$activeKey)
{
	if (empty($siteSender))
	{
		$siteSender  = $_SERVER['SERVER_NAME'];
	}
	$stringToPost = "mobile=".$userAccount."&password=".$passAccount."&activeKey=".$activeKey;
	$stringToPostLength = strlen($stringToPost);
	$fsockParameter = "POST /checkUser.php HTTP/1.0 \r\n";
	$fsockParameter.= "Host: api.taqnyat.sa \r\n";
	$fsockParameter.= "Content-type: application/x-www-form-urlencoded \r\n";
	$fsockParameter.= "Content-length: $stringToPostLength \r\n\r\n";
	$fsockParameter.= "$stringToPost"; 
	$fsockConn = fsockopen("https://api.taqnyat.sa", 80, &$errno, &$errstr, 30);
	fputs($fsockConn,$fsockParameter);
	$result = ""; 
	$clearResult = false; 
	
	while(!feof($fsockConn))
	{
		$line = fgets($fsockConn, 10240);
		if($line == "\r\n" && !$clearResult)
		$clearResult = true;
		
		if($clearResult)
			$result .= trim($line); 
	}
	return $result;
}
function checkSMS($userAccount, $passAccount, $numbers, $sender, $msg, $MsgID, $timeFirst, $msgUniqe)
{
	global $conn;
    global $applicationType;
	if(empty($applicationType))
		$applicationType = '17';
    $msg = convertToUnicode($msg);
    $sender = urlencode($sender);
	$timeSend = 0;
	$dateSend = 0;
    $stringToPost = "mobile=" . $userAccount . "&password=" . $passAccount . "&numbers=" . $numbers . "&sender=" . $sender . "&msg=" . $msg . "&timeSend=" . $timeSend . "&dateSend=" . $dateSend . "&applicationType=" . $applicationType . "&msgId=" . $MsgID . "&sendDate=" . $timeFirst;
    $stringToPostLength = strlen($stringToPost);
    $fsockParameter = "POST /msgCheck.php HTTP/1.0 \r\n";
    $fsockParameter .= "Host: api.taqnyat.sa \r\n";
    $fsockParameter .= "Content-type: application/x-www-form-urlencoded \r\n";
    $fsockParameter .= "Content-length: $stringToPostLength \r\n\r\n";
    $fsockParameter .= "$stringToPost";
    $fsockConn = fsockopen("https://api.taqnyat.sa", 80, $errno, $errstr, 30);
    fputs($fsockConn, $fsockParameter);
    $result = "";
    $clearResult = false;
    while (!feof($fsockConn))
    {
        $line = fgets($fsockConn, 10240);
        if ($line == "\r\n" && !$clearResult)
            $clearResult = true;
        if ($clearResult)
            $result .= trim($line);
    }
    return $result;
}
function checkAlphasSender($userAccount, $passAccount)
{
    $stringToPost = "mobile=".$userAccount."&password=".$passAccount;
    $stringToPostLength = strlen($stringToPost);
    $fsockParameter = "POST /checkAlphasSender.php HTTP/1.0 \r\n";
    $fsockParameter.= "Host: api.taqnyat.sa \r\n";
    $fsockParameter.= "Content-type: application/x-www-form-urlencoded \r\n";
    $fsockParameter.= "Content-length: $stringToPostLength \r\n";
    $fsockParameter.= "$stringToPost \r\n";

    $fsockConn = fsockopen("https://api.taqnyat.sa", 80, &$errno, &$errstr, 30);
    fputs($fsockConn,$fsockParameter);

    $result = "";
    $clearResult = false;

    while(!feof($fsockConn))
    {
        $line = fgets($fsockConn, 10240);
        if($line == "\r\n" && !$clearResult)
            $clearResult = true;

        if($clearResult)
            $result .= trim($line);
    }
    return $result;
}
?>