<?php
require 'vendor/autoload.php';
use Google\Cloud\Translate\V2\TranslateClient;

include "library.php";
$obj=new Library();

$url=@$_GET['pybjx'];

/*
trafiqerp.in/ydx/upfh?pybjx=MXxvbmlvbnxhcg%3D%3D
*/

/*$url="";*/
$url_dec=base64_decode(urldecode($url));
$val_arr=explode("|",$url_dec);

$transaction=$val_arr[0];
$word=$val_arr[1];
$target=$val_arr[2];

/*echo  $transaction."|".$word."|".$target;*/

/*$transaction=1;
$word="watermelon";
$target="ml";*/

if($transaction==1)
{
$query="select trans_word from translate where eng_word='$word' AND target_ln='$target' ;";
$sql=$obj->generalquery($query);
$arr=mysqli_fetch_array($sql);
$count=mysqli_num_rows($sql);

	if($count==0)
	{
	$translate = new TranslateClient(['key' => 'AIzaSyDrSZq3mBTH9WXqHdWPIDtbCSOPF0ySezo']);
	$result = $translate->translate($word, ['target' => $target]);
	$trans_word=$result['text'];	
	$data=array("eng_word"=>$word,"target_ln"=>$target,"trans_word"=>$trans_word);	
	$ins=$obj->insert("translate",$data);
		if($ins)
		{
		echo $trans_word;
		}
	
	}
	else
	{
		echo $arr['trans_word'];
	}
}
?>