<?php
include("config/config.php");
if($_POST['associateId'])
{
	$associateId =htmlentities($_POST['associateId']);
	$contactNo =htmlentities($_POST['contactNo']);
	
	$str="Select * from  tbl_memberreg where member_user_id='$associateId'";
	$result=mysqli_query($connection,$str);
	if(mysqli_num_rows($result)==1)
	{
    	$row=mysqli_fetch_array($result);
    	$password=$row['password'];
    	$contact=$row['contact'];
    	if($contactNo==$contact)
    	{
    	    $message="Dear ".$associateId." Your Login Password is : ".$password;
    	    echo mysms($contactNo,$message);
    	    echo "Your Password is Send Your xxxxxx".substr($contactNo,6,4);
    	}
	}
	else
	{
	    echo "Associate Id Not Exist Our Record";
	}
}

function mysms($contact_no,$message)
{
    //Your authentication key
    $apikey = "VrwjbAOjL02IulEK84aivQ";
     
	$user="MAXWELL";

	$password="q12345";
     
    //Approved sender id(6 characters string only).
    $senderid = "MVDELP";
   
    //Message channel Promotional=1 or Transactional=2.
    $channel = "2";
   
     //Default is 0 for normal message, Set 8 for unicode sms.
    $DCS = "0";
   
     //Default is 0 for normal sms, Set 1 for immediate display.
    $flashsms = "0";
   
     //Recipient mobile number (pass with comma seprated if need to send on more then one number).
    $number = $contact_no;
   // ok kro ok chk kro aaya
   
    //Your message to send. //Long Message Test
    $message = $message;
 
    // = "Welcome to $company_name Dear $member_name your id is $member_user_id and pass is $password Login here ";
   
   
    //Define route
    $route = "02";

	//Prepare you post parameters
	$postData = array(
			'User' => $user,
			'Password' => $password,
			'SenderId' => $senderid,
			'Channel' => $channel,
			'DCS' => $DCS,
			'FlashSms' => $flashsms,
			'Number' => $number,
			'Text' => $message,
			'Route' => $route
		);
	   
		//API URL
	$url="http://37.59.76.46/api/mt/SendSMS";
	   
	$send_data = http_build_query($postData);

	$gateway_url = $url . "?" . $send_data;

	try {
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $gateway_url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_HTTPGET, 1);
		$output = curl_exec($ch);

		if (curl_errno($ch)) {
		$output = curl_error($ch);
		}
		curl_close($ch);

		//var_dump($output);

	}catch (Exception $exception){
		echo $exception->getMessage();
	}


		if($output == FALSE)
		{
		echo $action = "In-valid Contact";
		}
		else
		{
		echo $action = "OTP Send Successfully";
		}
}
?>

