<!DOCTYPE html>
<html>
   <head>
      <?php
         define('USER', 'jesse.turner@gatewaybaltic.com');
         define('TOKEN', 'reNaj8P1B4r3y9=fD8RaM0a4Lf30sdBda1d210we'); 
         require 'Solve360Service.php';
         
         $solve360Service = new Solve360Service(USER, TOKEN);
      	
         $cons = $solve360Service->searchContacts(array('layout' => '1', 
                        'searchmode' => 'Sany','searchvalue' => "",
                        'limit' => '99999', 'sortfield' => '', 'sortdir' => 'ASC','special' => 'OR'));
         
         foreach ($cons->children() as $ch) {
            echo $ch->getName(). ' = '.$ch.'<br/>';
            foreach ($ch->children() as $gch) {
               echo $gch->getName(). ' = '.$gch.'<br/>';
               foreach ($gch->children() as $ggch) {
                  echo $ggch->getName(). ' = '.$ggch.'<br/>';
                  foreach ($ggch->children() as $gggch) {
                     echo $gggch->getName(). ' = '.$gggch.'<br/>';
                  }
               }
            }
         }
         
         $contacts=array();
         foreach ($cons->children() as $ch) {
            $con=$solve360Service->getContact($ch->id);
            $isRelated=false;
            $store='#';
            foreach ($con->relateditems->children() as $conrel) {
               if ($conrel->typeid==2) {
                  $store.=$conrel->name.',';
                  if ($conrel->name=='B2B Norway') $isRelated=true;
               }
            }
            if ($isRelated==true || $isRelated==false) {
               $conId=$ch->id;
               $conName=$ch->name;
               $conWebsite=$ch->website;
               $conCompany=$ch->company;
               $conCountry=$ch->custom4698752;
               //if (strlen($conName)>0) $contacts[]=array("$conId","$conName","$conWebsite","$conCountry","$conCompany");
            }
            echo $conName.' = '.$conCompany.' -> '.$store.'<br>';
       	}
       	
         /*
       	$comps = $solve360Service->searchCompanies(array('layout' => '1', 
                        'searchmode' => 'Sany','searchvalue' => "",
                        'limit' => '99999', 'sortfield' => '', 'sortdir' => 'ASC','special' => 'OR'));
         
         $companies=array();
      
         foreach ($comps->children() as $ch) {
            $compId=$ch->id;
            $compName=$ch->name;
            $compWebsite=$ch->website;
            $compCountry=$ch->custom4593431;
            if (strlen($compName)>0) $companies[]=array("$compId","$compName","$compWebsite","$compCountry");
         }
         */
      
       	//echo json_encode(array($companies,$contacts));
      ?>
      <script type="text/javascript" src="library_functions.js"></script>
      <script type="text/javascript">
         var companies;
         var contacts;
      </script>
      <style type="text/css">
         body { padding:0 20px 20px 20px; font-family:arial,sans-serif; font-size:100%; }
         h1 { font-size:2.5em; }
         h2 { font-size:1.25em; }
         h3 { font-size:1.0em; }
         p { font-size:0.75em; }
         .bold { font-weight:bold; }
         .italic { font-style:italic; }
         
      </style>
   </head>
   <body>
      <p id="infobox">Loading...</p>
      <div id="container"></div>
      <script type="text/javascript">
         //companies = <?php echo json_encode($companies); ?>;
         /*contacts = <?php echo json_encode($contacts); ?>;
         table=new myTable("compTable");
         table.newRow();
         for (var i=0;i<contacts.length;i++) {
            _newt("p",contacts[i][1]+" = "+contacts[i][4],"","listItem"+i);
         }*/
      </script>
   </body>
</html>    