<?php

function dexplore_hook_diagramlist($ass,$rel)
{	
	global $siteroot;
	global $asset;
	global $installfolder;
	require_once($installfolder.'/model/relationship.php');	
		
		$ass->Load();
		if ($ass->type != 1)
		{
			$abb = array();
			$ax = array();
			$ax['name'] = 'Explore Data';
			$ax['url'] = $siteroot.'/dexplore/dash?id='.$ass->id;
			$abb[] = $ax;
				
			return $abb;
		}
	
	return array();
}

function dexplore_hook_contextrules()
{		
	$rules['Data Explorer:*|//dexplore/contextmenu?asset=[asset_id]&property=[property_id]'] = 'asset_id=*:property_id=*';	
	return $rules;
}

function dexplore_hook_fetch($wantsprops, $wantsmedia, $fetchlookup, &$fetchprops, &$fetchmedia)
{
	global $siteroot;
	global $asset;
	global $installfolder;
	require_once($installfolder.'/model/relationship.php');	
	
	foreach($fetchlookup as $f)
	{
		if ($f->id == -1)
		{
			$assetid = $f->value;
			$ass = new Asset($assetid);
			
			break;
		}
	}
	
	if ($assetid == 0) return;

	$ass = new Asset($assetid);
	
	
		if ($assetid != 0)
		{
			if ($wantsprops == true)
			{
				$row = array();
				$row['name'] = 'Data Explorer';
				$row['type'] = 'URL';
				$row['value'] = array();
				
				$row['value']['address'] = $siteroot.'/dexplore/dash?id='.$assetid;		
				
				$fetchprops[] = $row;
			}				
		}
		/*$abb = array();
		$ax = array();
		$ax['name'] = '360';
		$ax['url'] = $siteroot.'/360/client/asset?id='.$ass->id;
		$abb[] = $ax;
			
		return $abb;*/

}

function dexplore_filter_hook(&$existingmedia)
{
	global $sitefolder;
	global $installfolder;
	global $siteroot;
	
	//echo 'Finding ...';
	//exit;
			
	$extramedia = array();
	if ($existingmedia == null) return;
	if(@count($existingmedia) == 0) return;
	
	//print_r($existingmedia);
	for($x=0;$x<count($existingmedia);$x++)
	{
		$m = $existingmedia[$x];
		
		if ($m->localpath == null) continue;
		
		$pth = pathinfo($m->localpath);		
		if (isset($pth['extension']) && (strtolower($pth['extension']) == "dash"))
		{
			$it = new Media();
			$it->id = -1;
			$it->name = $m->name;
			$it->path = $siteroot.'/dexplore/dash?id='.$m->asset.'&board='.urlencode($m->name);
			$it->asset = $m->asset;				
			$it->category = 'Data Explorer';
			$extramedia[] = $it;		

			unset($existingmedia[$x]);
			$existingmedia = array_values($existingmedia);
			$x--;
		}
	}
	foreach($extramedia as $m)
	{
		//echo 'Adding Media Item!';
		$existingmedia[] = $m;
	}
	
	

}
?>