<?php
ini_set('display_errors', 1);
$user_key = 'only_for_dev_or_pro';
$endpoint = 'https://api.upcitemdb.com/prod/trial/lookup';


		if(isset($_POST['Submit']))
		{

			if (empty($_POST["upc"])) 
			{
				echo "Champ vide !.";
			} 
			
			else {

						$ch = curl_init();

						curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
						curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
						curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
						curl_setopt($ch, CURLOPT_HEADER, 1);
						curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
						curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
						curl_setopt($ch, CURLOPT_HEADER, false);
						curl_setopt($ch, CURLOPT_HTTPHEADER, array(

						));

						//http://www.upcitemdb.com/wp/docs/main/development/getting-started/
						
						// http://www.upcitemdb.com/api/explorer#!/lookup/get_trial_lookup
						
						$upc = $_POST["upc"];	
						$cmd = "https://api.upcitemdb.com/prod/trial/lookup?upc=" .$upc;	
						
						$cmd2 ="https://api.upcitemdb.com/prod/trial/search?s=War%20of%20the%20Ring&match_mode=0&type=product";
						
						$cmd3 = "https://api.upcitemdb.com/prod/trial/search?s=War%20of%20the%20Ring&category=board%20game&match_mode=0&type=product";
						
						$title = "War of the Ring";
						
						$cmd3 = "https://api.upcitemdb.com/prod/trial/search?s=" .$title  ."&category=board%20game&match_mode=0&type=product";
						
						echo $cmd3;
						
						
						curl_setopt($ch, CURLOPT_POST, 0);
						
						//curl_setopt($ch, CURLOPT_URL, $endpoint.'?upc=4002293401102');
						curl_setopt($ch, CURLOPT_URL, $cmd3);
						
						
						$response = curl_exec($ch);
						$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
						if ($httpcode != 200)
						  echo "error status $httpcode...\n";
						else 
						//  echo $response."\n";

						/* if you need to run more queries, do them in the same connection.
						* use rawurlencode() instead of URLEncode(), if you set search string
						 * as url query param
						 */
						 
						 
						//sleep(2);
						
						
						// proceed with other queries
						curl_close($ch);

						$result=json_decode($response,true);
/*
						echo "<br>";
						echo $title=$result['items'][0]["ean"];
						echo "<br>";
						echo $title=$result['items'][0]["title"];
						echo "<br>";
						echo $title=$result['items'][0]["brand"];
*/						
				}
			}			
			
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Description" content="Site perso,cours,ouvrages" />
<meta name="Keywords" content="WEBSITE perso " />
<meta name="Distribution" content="Global" />
<meta name="Robots" content="" />
<meta http-equiv="Content-Language" content="fr" />
<meta name="rating" content="general" />
<meta name="author" content="Patrice DELPY" />
<meta name="copyright" content="Copyright 2013" />
<meta name="generator" content="Patoche" />
<title>Patoche WEBSITE - 2013 - Template du site - en cours de développemment ...</title>


<style type="text/css">

<!--https://stackoverflow.com/questions/31587326/how-to-show-hidden-div-after-hitting-submit-button-in-form -->

#my_id {
    display: none;
}

fieldset {
    display: block;
    margin-left: 200px;
    margin-right: 200px;
    padding-top: 0.35em;
    padding-bottom: 0.625em;
    padding-left: 0.75em;
    padding-right: 0.75em;
    border: 2px groove (internal value);
}

</style>


</head>

<body>

			<fieldset>
			<legend> Recherche un produits à partir du code bar : </legend>

			<br><br>
			
			<form action="ean05.php" method="post">
			Code bar: <input type='text' name='upc' size='20'>
			<input type='submit' name='Submit' value='Submit' onclick="document.getElementById('my_id').style.display = 'block' ;">
			</form>
			
			</fieldset>

			<div id="my_id" style="display: none">
<?php
						echo "<br>";
						echo $title=$result['items'][0]["ean"];
						echo "<br>";
						echo $title=$result['items'][0]["title"];
						echo "<br>";
						echo $title=$result['items'][0]["brand"];
?>
			My text </div>
			
			<!--<div id="my_id"> My text </div>-->


</body>
</html>


