<?php
require_once 'ApiGlobalFunctions.php';

$usuario=$_POST['uid'];
$password=$_POST['key'];
$url=$_POST['url'];

$include=includec($url);
include $include;

$validate=loginkey($usuario,$password,$url);


if($validate==1){
    
	mysqli_set_charset($link, "utf8");
    $campo=diccionario($url,'vendorcode');
    $query=mysqli_query($link, "SELECT vendorname, vendor_no,email,country,".$campo.",crmid 
        FROM vtiger_vendor 
        INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_vendor.vendorid 
        INNER JOIN vtiger_vendorcf ON vtiger_vendorcf.vendorid=vtiger_vendor.vendorid 
        WHERE deleted='0'");
    $num=mysqli_num_rows($query);    	
    $z=0;                  
    //print_r(mysqli_fetch_array($query));
    while ($row = mysqli_fetch_array($query)) {           
        $vendorname=$row['vendorname'];
        $Vendorno=$row['vendor_no'];
        $email=$row['email'];
        $pais=$row['country'];
        $cf_1938=$row['4'];
        $vendorid=$row['crmid'];
        
        $docs[$z]=array('VendorName'=>$vendorname,'VendorNum'=>$Vendorno,'VendorEmail'=>$email,'VendorPais'=>$pais,'VendorCode'=>$cf_1938,'VendorID'=>$vendorid);
        $z++;            
        }    
     echo json_encode(setDataJSON($docs,1));
}
