<?php
function fn_filterprop_c($aql)
{
	$data = $aql->Consume(1);
	
	$propshortlist = array();	
	$bing = array();
	
	$allprops = Properties::GetAllProperties();
	if ($data[0]->islist == true)
		$propset = $data[0]->value;
	else
		$propset = array($data[0]->value);
	
	$targetscore = count($propset);
	
	foreach($allprops as $pr)
	{
		$bing[$pr->id] = 0;
		foreach($propset as $psx)
		{			
			//echo 'Checking '.$pr->name.' for '.$psx;
			if (strpos(strtolower($pr->name),strtolower($psx)) !== FALSE)
			{
				//echo $psx.' hit on '.$pr->name.'<br/>';
				$bing[$pr->id]++;
			}
		}
	}
	
	foreach($bing as $k => $v)
	{
		if ($v == $targetscore)
		{
			$propid = $k;			
			$propshortlist[] = $k;
		}
	}
	
	$a = new AQLStackElement();
	$a->typename = "proplist";
	$a->islist = true;
	$a->value = $propshortlist;
	array_push($aql->stack,$a);
	
	//echo "Found ...";
	//print_r($propshortlist);
	return;
}

function fn_filterprop_pc($aql)
{
	$data = $aql->Consume(2);
	
	$propshortlist = array();	
	$bing = array();
	
	$allprops = Properties::GetAllProperties();
	if ($data[1]->islist == true)
		$propset = $data[1]->value;
	else
		$propset = array($data[1]->value);
	
	$existing = $data[0]->value;
	
	$targetscore = count($propset);
	
	foreach($allprops as $pr)
	{
		if (!isset($pr->id,$existing)) continue;
		$bing[$pr->id] = 0;
		foreach($propset as $psx)
		{			
			if (strpos(strtolower($pr->name),$psx) !== FALSE)
			{
				//echo $psx.' hit on '.$pr->name.'<br/>';
				$bing[$pr->id]++;
			}
		}
	}
	
	foreach($bing as $k => $v)
	{
		if ($v == $targetscore)
		{
			$propid = $k;			
			$propshortlist[] = $k;
		}
	}
	
	$a = new AQLStackElement();
	$a->typename = "proplist";
	$a->islist = true;
	$a->value = $propshortlist;
	array_push($aql->stack,$a);
	
	//echo "Found ...";
	//print_r($propshortlist);
	return;
}
?>