<?php
require_once 'ApiGlobalFunctions.php';

$usuario=$_POST['uid'];
$password=$_POST['key'];
$url=$_POST['url'];
$producto=$_POST['ProductCode'];
$include=includec($url);
include $include;

$validate=loginkey($usuario,$password,$url);
if($validate==1){
    mysqli_set_charset($link, "utf8");
    $campo=diccionario($url,'codproduct');    
    $query=mysqli_query($link,"SELECT vtiger_products.productid,createdtime, productname, ".$campo.", productcategory,qtyinstock,description 
        FROM vtiger_products 
        INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_products.productid 
        INNER JOIN vtiger_productcf ON vtiger_productcf.productid=vtiger_products.productid
        WHERE deleted='0' AND ".$campo."='$producto'");
    $data= mysqli_fetch_array($query);      
    $productid=$data['productid'];
    $creacion=explode(" ",$data['createdtime']);
    $creacion=$creacion[0];
    $productname=$data['productname'];
    $productcode=$data[3];
    $productcategory=$data['productcategory'];
    $qtyinstock=stock($data['qtyinstock']);
    $description=$data['description'];
    $docs[0]=array('productid'=>$productid,'FechaCreado'=>$creacion,'productname'=>$productname,'productcode'=>$productcode,'productcategory'=>$productcategory,'qtyinstock'=>$qtyinstock,'Descripcion'=>$description);
    echo json_encode(setDataJSON($docs,1));
}
?>
