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

   // fields
   $website=$comp->item->fields->website;
   $phone=$comp->item->fields->phone;
   $country=$comp->item->fields->custom4593431;
   $address=$comp->item->fields->mainaddress;
   $turnover=$comp->item->fields->custom4656526;
   $employees=$comp->item->fields->custom10891353;
   $profile=$comp->item->fields->custom4593433;
   $industry=$comp->item->fields->custom4593432;
   $background=$comp->item->fields->background;
     
   // related to contacts' IDs
   $contacts=array();
   foreach ($comp->relateditems->children() as $rel) {
      if ($rel->typeid==1) {
         $contactName=$rel->name;
         $contactId=$rel->id;
         if (strlen($contactName)>0) $contacts[]=array("$contactId","$contactName");
      }
   }
   
   echo json_encode(array("$compRef","$website","$phone","$country",$contacts,"$address","$turnover","$employees","$profile","$industry","$background"));
?>