<!DOCTYPE html>
<html>
   <head>
      <?php
         define('USER', 'jesse.turner@gatewaybaltic.com');
         define('TOKEN', 'reNaj8P1B4r3y9=fD8RaM0a4Lf30sdBda1d210we'); 
         require 'Solve360Service.php';
         
         $solve360Service = new Solve360Service(USER, TOKEN);
      	
      	$companies=array();
      	$contacts=array();
      	
         $comps = $solve360Service->getAllCompanies();
         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");
         }
         
         $cons = $solve360Service->getAllContacts();
         foreach ($cons->children() as $ch) {
            $conId=$ch->id;
            $conName=$ch->name;
            $conWebsite=$ch->website;
            $conCountry=$ch->custom4698752;
            $conCompany=$ch->company;
            if (strlen($conName)>0) $contacts[]=array("$conId","$conName","$conWebsite","$conCountry","$conCompany");
         }
      ?>
      <script type="text/javascript" src="library_functions.js"></script>
      <script type="text/javascript">
         var companies=new Array();
         var contacts=new Array();
         var allCompanies;
         var allContacts;
         var ID=0;
         var NAME=1;
         var WEBSITE=2;
         var COUNTRY=3;
         var COMPANY=4;
         
         function _extractDataFromAll() {
            var i;
            for (i=0;i<allCompanies.length;i++) {
               if (allCompanies[i][WEBSITE]=="" || allCompanies[i][COUNTRY]=="") {
                  companies.push(allCompanies[i]);
                  alert(allCompanies[i].toSource());
               }
            }
            for (i=0;i<allContacts.length;i++) {
               if (allContacts[i][WEBSITE]=="" || allContacts[i][COUNTRY]=="") {
                  contacts.push(allContacts[i]);
               }
            }
         }
      </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>
      <script type="text/javascript">
         allCompanies = <?php echo json_encode($companies); ?>;
         allContacts = <?php echo json_encode($contacts); ?>;
         _extractDataFromAll();
         alert("allcomps="+allCompanies.length+" | comps="+companies.length+" ... allcons="+allContacts.length+" | cons="+contacts.length);
      </script>
   </body>
</html>    