<?php 
include('lib/config.php');

//--------------- Organisation Info ----------------							  								  
$selQry_orgs = "SELECT * FROM ".TBL_ORGANIZATIONS." WHERE organization_id ='1' LIMIT 1";
$orgsInfo =  $con->getSingleRow($selQry_orgs, __FILE__,__LINE__);
//--------------- Category Info ----------
$category_counter = 0;
$selQry_cat = "SELECT * FROM ".TBL_CATEGORIES." WHERE status='1' ORDER BY category_title";
$catInfo =  $con->getMultiRow($selQry_cat, __FILE__,__LINE__);
$totSHCatListings = count($catInfo);

if($totSHCatListings>0)
{	
	for($shcat=0;$shcat<$totSHCatListings;$shcat++)
	{
		$category_counter++;
		
		$categoryOrientation = !empty($catInfo[$shcat]['category_orientation'])?$catInfo[$shcat]['category_orientation']:'#a9b7af';
		//-----------------------------------------------------------
		$selQry_sh = "SELECT * FROM ".TBL_STAKEHOLDERS." WHERE category_id='".$catInfo[$shcat]['category_id']."' AND status='1' ORDER BY name";
		$shInfo =  $con->getMultiRow($selQry_sh, __FILE__,__LINE__);
		$totSHListings = count($shInfo);
		
		if( $totSHListings>0 )
		{
			//$stakeholders = array();
		}		
		//-----------------------------------------------------------			
		$categoryChildrens = array(["name"=>"","title"=>"","value"=>""]);
		
		$categories[] = array(
			"name"=>$catInfo[$shcat]['category_title'],
			"id"=>$catInfo[$shcat]['category_id'],
			"value"=>isset($catInfo[$shcat]['category_influence'])?$catInfo[$shcat]['category_influence']:'500',
			"title"=>$catInfo[$shcat]['category_title'].'('.$totSHListings.')',
			"off"=>true,
			"type"=>"Cat",
			"color"=>$categoryOrientation,
			"togglable"=>false,
			"children"=>$categoryChildrens
		);
		//-----------------------------------------------------------
		
	}
	
	$data[] = array("name"=>"","id"=>"","value"=>"5000","title"=>"Click to expand!","x"=>"50%","y"=>"50%","image"=>isset($orgsInfo['logo'])?"uploads/organizations/".$orgsInfo['logo']:'',"fixed"=>true,"off"=>false,"children"=>$categories);
	
	$results = $data;
}
else
{
	$results = '0 results found.';
}

echo json_encode($results);
?>