<?php
   define('USER', 'inese.andersone@gatewaybaltic.com');
         define('TOKEN', 'F274va12MeWcTdUfPfB9r7X3=3b0naF9I7=003r0'); 
   require 'Solve360Service.php';
   
   $solve360Service = new Solve360Service(USER, TOKEN);
	   
   $proj=$_GET["proj"];
   $comp=$_GET["comp"];
   $subProj=$_GET["subProj"];
   $cont=$_GET["cont"];
   $contId=$_GET["contId"];
   $toCorrect=$_GET["toCorrect"];
   
   $toCorrect=str_replace('*plus*','+',$toCorrect);
   $corrections=explode(';;',$toCorrect);
   
   $contactData = array();
   
   for ($i=0;$i<count($corrections);$i++) {
      $corr=explode("==",$corrections[$i]);
      if ($corr[0]=='phone') $contactData['businessphonedirect'] = "$corr[1]";
      if ($corr[0]=='website') $contactData['website'] = "$corr[1]";
      if ($corr[0]=='country') $contactData['custom4698752'] = "$corr[1]";
      if ($corr[0]=='assigned') $contactData['assignedto'] = (integer)$corr[1];

      if ($corr[0]=='related') $rel=$solve360Service->addContactRelation($contId, "$corr[1]");
      
      if ($corr[0]=='con')  {
         $noteText=stripslashes($corr[1]);
         $noteData = array('details' => "$noteText");
         $note = $solve360Service->addActivity($contId, 'note', $noteData);
      }
   }
   
   $contact = $solve360Service->editContact($contId, $contactData);
   
   echo json_encode(array("OK","$proj","$comp","$subProj","$cont","$toCorrect")); 
?>