<?php
function fn_istype_aa($aql)
{
	$data = $aql->Consume(2);
	
	global $db;
	$apool = array();
	
	$mt = microtime(true);
	
	$sources = $data[1]->value;
	$types = $data[0]->value;
	
	if (count($sources) == 0)
	{
		$a = new AQLStackElement();
		$a->typename = "assetlist";
		$a->islist = true;
		$a->value = array();
		array_push($aql->stack,$a);
	}
	
	if (count($types) == 0)
	{
		$a = new AQLStackElement();
		$a->typename = "assetlist";
		$a->islist = true;
		$a->value = array();
		array_push($aql->stack,$a);
	}
		
		
	if ((count($sources) != 0) && (count($types) != 0))
	{
		$query = $db->query("SELECT childasset FROM assetrelclosures WHERE relationship=3 AND childasset IN (".implode(',',$sources).") AND parentasset IN (".implode(',',$types).")");
		
		//echo "SELECT childasset FROM assetrelclosures WHERE relationship=3 AND childasset IN (".implode(',',$sources).") AND parentasset IN (".implode(',',$types).")";
		
		$typelist = array();
		if ($query !== FALSE)
		{
			while($row = $query->fetch(PDO::FETCH_ASSOC)) 
			{		
				if (!in_array($row['childasset'],$apool))
					$apool[] = $row['childasset'];
			}
		}
	}
		
	$a = new AQLStackElement();
	$a->typename = "assetlist";
	$a->islist = true;
	$a->value = $apool;
	array_push($aql->stack,$a);
}

function fn_istype_a($aql)
{
	$data = $aql->Consume(1);
	
	global $db;
	$apool = array();
	
	$mt = microtime(true);
	
	$types = $data[0]->value;
	if (count($types) > 0)
	{		
		$query = $db->query("SELECT childasset FROM assetrelclosures WHERE relationship=3 AND parentasset IN (".implode(',',$types).")");
		
		//echo "SELECT childasset FROM assetrelclosures WHERE relationship=3 AND childasset IN (".implode(',',$sources).") AND parentasset IN (".implode(',',$types).")";
		
		$typelist = array();
		if ($query !== FALSE)
		{
			while($row = $query->fetch(PDO::FETCH_ASSOC)) 
			{
				//$apool = 
				//$typelist[strtolower($row['name'])] = $row['id'];
				$apool[] = $row['childasset'];
			}
		}
	}
		
	$a = new AQLStackElement();
	$a->typename = "assetlist";
	$a->islist = true;
	$a->value = $apool;
	array_push($aql->stack,$a);

}
?>