<?php
function fn_table_m($aql)
{
	$data = $aql->Consume(1);		
	
	$tablename = "";
	$filtercol = "";
	$filtervalue = "";
	$sortorder = "";
	
	//print_r($data);
	
	global $installfolder;
	include_once($installfolder.'/addons/table/api/tables.php');
	
	$values = array();
	
	foreach($data[0]->value as $k => $v)
	{
		if ($k == 'table') 
		{
			$tablename = $v;
		}
		if ($k == 'column') 
		{
			$filtercol = $v;
		}
		if ($k == 'value')
		{				
			$filtervalue = $v;			
		}
		if ($k == 'sort')
		{
			$sortorder = $v;
		}
	}
	
	global $siteroot;
	global $installfolder;
	
	if ($tablename != "")
	{
		$req = $_REQUEST;
		$_REQUEST = array();
		$_REQUEST['table'] = $tablename;
		$_REQUEST['format'] = 'json';
		if ($sortorder != "")
		{
			$_REQUEST['sortby'] = $sortorder;
		}
		
		ob_start();
		
		include($installfolder.'/addons/table/api/get.php');
		
		$content = ob_get_clean();		
		//print_r($content);
		
		$values = json_decode($content,true)['data'];
		
		$_REQUEST = $req;
				
		
		$a = new AQLStackElement();
		$a->typename = "map";
		$a->islist = true;
		$a->value = $values;
		array_push($aql->stack,$a);
	}
	else
	{
		$a = new AQLStackElement();
		$a->typename = "map";
		$a->islist = false;
		$a->value = $values;
		array_push($aql->stack,$a);
	}
	
	return;
}
