<?php
   define('USER', 'jesse.turner@gatewaybaltic.com');
   define('TOKEN', 'reNaj8P1B4r3y9=fD8RaM0a4Lf30sdBda1d210we'); 
   require 'Solve360Service.php';
   
   $solve360Service = new Solve360Service(USER, TOKEN);

   $proj=$_GET["proj"];
   $blogId=$_GET["id"];
   $indx=$_GET["indx"];
   $blog = $solve360Service->getProjectblog($blogId);
   $comps[]="$blogId";
   $comps[]="$proj";
   $comps[]="$indx";

   // check project blog activities to see if files uploaded and worker note exist   
   $loadedFiles=array('NOTUPLOADED','NOTUPLOADED','NOTUPLOADED');
   $noteText='';
   foreach ($blog->activities->children() as $ch) {
      if ($ch->typeid==23) {
         $f=$ch->fields->filename;
         $file=$ch->fields->file;
         if (stripos($f,'info_profile')!==false || stripos($f,'info profile')!==false) {
            //info profile uploaded
            $loadedFiles[0]="$file";
         } else {
            if (stripos($f,'meeting_plan')!==false || stripos($f,'meeting plan')!==false) {
               // meeting plan uploaded
               $loadedFiles[1]="$file";
            } else {
               if (stripos($f,'final_report')!==false || stripos($f,'final report')!==false) {
                  // final report uploaded!
                  $loadedFiles[2]="$file";
               }
            }
         }
      } else {
         // look for program-created note with info about profiler, selector & HELPERS (add. select, calling)
         // [##] profiledeadline:ddmmyy selectiondeadline:ddmmyy calldeadline: meetingplandeadline: finalreportdeadline:
         //  profiler:NAME selector:? caller:NAME meetingplan:NAME finalreport:NAME selectionhelp:NAME callinghelp:NAME 
         // note: program will later check caller==assignedto, otherwise notify error!
         if ($ch->typeid==3) {
            $noteString=$ch->name;
            if (substr($noteString,0,3)=='[##]') $noteText=$noteString;
         }  
      }
   }
     
   $comps[]=$loadedFiles;
   $comps[]="$noteText";
   //
   // Get project blog details
   $contact=$blog->item->fields->custom9557786;
   $email=$blog->item->fields->custom9484073;
   $assignedto=$blog->item->fields->assignedto;
   $coord=$blog->item->fields->custom9401708;
   //
   $comps[]="$contact";
   $comps[]="$email";
   $comps[]="$assignedto";
   $comps[]="$coord";
   //
   // Get company ID list
   foreach ($blog->relateditems->children() as $comp) {
      if ($comp->typeid==40) {
         $compId=$comp->id;
         $compName=$comp->name;
         $comps[]=array("$compId","$compName");
      }
   }
   
   // projectID,proj,loadedFiles,noteText,contact,email,assignedto,coordinator, ...companies...
   //     0        1       2           3       4      5       6            7            8+
   echo json_encode($comps);
?>