<?php
   define('USER', 'jesse.turner@gatewaybaltic.com');
   define('TOKEN', 'reNaj8P1B4r3y9=fD8RaM0a4Lf30sdBda1d210we'); 
   require 'Solve360Service.php';
   
   $id=$_GET["id"];
   $contRef=$_GET["cont"];
   $solve360Service = new Solve360Service(USER, TOKEN);
   
   $cont = $solve360Service->getCompany($id);
   
   /*
   foreach ($cont->categories->children() as $cat) {
      if ($cat->id=='17487432' || $cat->id=='17487426' || $cat->id=='17487420') $isClient=true;
   }
   */

   // fields
   $title=$cont->item->fields->jobtitle;
   $phone=$cont->item->fields->businessphonedirect;
   $mobile=$cont->item->fields->cellularphone;
   $website=$cont->item->fields->website;
   $email=$cont->item->fields->businessemail;
   $country=$cont->item->fields->custom4698752;
        
   // related to contacts' IDs
   $companies=array();
   foreach ($cont->relateditems->children() as $rel) {
      if ($rel->typeid==40) {
         $companyName=$rel->name;
         $companyId=$rel->id;
         if (strlen($companyName)>0) $companies[]=array("$companyId","$companyName");
      }
   }
   
   echo json_encode(array("$contRef","$website","$phone","$country",$companies));
?>