<?php 

   function checkDuplicateID($array,$id) {
      $found = false;
      foreach ($array as $item) {
         if ($item[0] == $id) $found = true;
      }
      return $found;
   }

    define('USER', 'inese.andersone@gatewaybaltic.com');
         define('TOKEN', 'F274va12MeWcTdUfPfB9r7X3=3b0naF9I7=003r0'); 
         require 'Solve360Service.php';
		 $solve360Service = new Solve360Service(USER, TOKEN);
		 $caller=$_GET["c"];
       //'searchmode' => 'S4471833'
		 $projects = $solve360Service->searchProjectblogs(array('layout' => '1','searchmode' => 'S4471833','searchvalue' => "$caller",'special' => 'OR')); 
       $projects_owned = $solve360Service->searchProjectblogs(array('layout' => '1','searchmode' => 'S9401708','searchvalue' => "$caller",'special' => 'OR'));
       //$projects = (object) array_merge($projects->children(),$projects_owned->children());
		 $dats = array();
		foreach ($projects->children() as $ch) {
			$title=$ch->title;
            $statusStr=$ch->custom9401709;
                  switch ($statusStr) {
                     case 'Unstarted':
                        $status=0;
                        break;
                     case 'Selection':
                     case 'Preparation':
                        $status=1;
                        break;
                     case 'Attraction':
                        $status=2;
                        break;
                     case 'Finalisation':
                     case 'Reports':
                        $status=3;
                        break;
                     case 'Completed':
                        $status=4;
                        break;
                     default:
                        $status=-1;
                  }
			if (strlen($title)>0 && ($status!=1 || $caller!='Sandra Gudrite')) {
                  //if (strlen($title)>0) {
                     $id=$ch->id;
                     $clientEmail=$ch->custom9484073;
                     $coord=$ch->custom9401708;
						$dats[]=array("$id","$title",$status,"$coord","$caller","$clientEmail",false);
				  }
		}
      foreach ($projects_owned->children() as $ch) {
         $title=$ch->title;
            $statusStr=$ch->custom9401709;
                  switch ($statusStr) {
                     case 'Unstarted':
                        $status=0;
                        break;
                     case 'Selection':
                     case 'Preparation':
                        $status=1;
                        break;
                     case 'Attraction':
                        $status=2;
                        break;
                     case 'Finalisation':
                     case 'Reports':
                        $status=3;
                        break;
                     case 'Completed':
                        $status=4;
                        break;
                     default:
                        $status=-1;
                  }
         if (strlen($title)>0 && ($status!=1 || $caller!='Sandra Gudrite')) {
                  //if (strlen($title)>0) {
                     if (!checkDuplicateID($dats,$ch->id)) {
                        $id=$ch->id;
                        $clientEmail=$ch->custom9484073;
                        $coord=$ch->custom9401708;
                        $dats[]=array("$id","$title",$status,"$coord","$caller","$clientEmail",false);
                     }
              }
      }
			foreach ($dats as $row) {
				echo "<pre>";
				print_r($row);
				echo "</pre>";
			}
         /* foreach ($projects->children() as $ch) {
            echo "<pre>";
            print_r($ch);
            echo "</pre>";
         } */
?>