<?php
require_once 'connect.php';
        // opening db connection 
       
if(isset($_POST['suggest'])){
	$query = $_POST['suggest'];
	$result = mysqli_query($conn,$query);
		$row = mysqli_fetch_array($result);
		echo $row['name']." ".$row['middle']." ".$row['last'];;	
      
}

if(isset($_POST['send_otp'])){
	 $query = $_POST['send_otp'];
	$result = mysqli_query($conn,$query);
		$row = mysqli_fetch_array($result);
		 $otp = '';
		 for($i = 0; $i < 4; $i++){
	     $otp .= mt_rand(0,9);
	      }
	echo $otp;
$name = $row['name'];		
 $user_unique_id = $row['user_unique_id'];		
 $mobile_no = $row['mobile_no'];		
		$mess ="Dear  (".$name.") $user_unique_id, OTP is ".$otp." for withdrawal.";
			$curl = curl_init();
$authentication_key = "249381AQ6wW1NxH3K5bfe30aa";
curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.msg91.com/api/v2/sendsms",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{ \"sender\": \"SOCKET\", \"route\": \"4\", \"country\": \"91\", \"sms\": [ { \"message\": \"$mess\", \"to\": [ \"$mobile_no\"] } ] }",
  CURLOPT_SSL_VERIFYHOST => 0,
  CURLOPT_SSL_VERIFYPEER => 0,
  CURLOPT_HTTPHEADER => array(
    "authkey: $authentication_key",
    "content-type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);

/*
$curl = curl_init();
$apikey = 'somerandomkey';//if you use apikey then userid and password is not required
$userId = 'Wowmoney';
$password = 'txjwLkb8';
$sendMethod = 'simpleMsg'; //(simpleMsg|groupMsg|excelMsg)
$messageType = 'text'; //(text|unicode|flash)
$senderId = 'WOWMNY';
$mobile = '91'.$mobile_no;//comma separated
//$msg = "Dear Associate, welcome to Wowmoney. Your id is 45435 login user name is ggdfh password is 23dfddf.Visit: https://wowmoney.live
//Take the biggest opportunity ever!";
$scheduleTime = '';//mention time if you want to schedule else leave blank

curl_setopt_array($curl, array(
  CURLOPT_URL => "http://www.smsgateway.center/SMSApi/rest/send",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "userId=$userId&password=$password&senderId=$senderId&sendMethod=$sendMethod&msgType=$messageType&mobile=$mobile&msg=$mess&duplicateCheck=true&format=json",
  CURLOPT_HTTPHEADER => array(
    "apikey: $apikey",
    "cache-control: no-cache",
    "content-type: application/x-www-form-urlencoded"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);*/

      	
}

if(isset($_POST['username'])){
	$query = $_POST['username'];
	$result = mysqli_query($conn,$query);
		//$row = mysqli_fetch_array($result);
		$num = mysqli_num_rows($result);
		if($num == 0){
		echo "0";
		}else{
		echo "1";	
		}
      
}if(isset($_POST['pin_num'])){
	$query = $_POST['pin_num'];
	$result = mysqli_query($conn,$query);
		//$row = mysqli_fetch_array($result);
		$num = mysqli_num_rows($result);
		if($num == 0){
		echo "0";
		}else{
		echo "1";	
		}
      
}

if(isset($_POST['product_price'])){
	$query = $_POST['product_price'];
	$result = mysqli_query($conn,$query);
		$row = mysqli_fetch_array($result);
		echo $row['mrp'];	
      
}if(isset($_POST['product_price1'])){
	$query = $_POST['product_price1'];
	$result = mysqli_query($conn,$query);
		$row = mysqli_fetch_array($result);
		echo $row['dp_offer'];	
      
}


?>