<?xml version="1.0" encoding="UTF-8"?>
<maxdQL version="0.1" name="ViewOneField" >
	<description>Lists a specific field in a table</description>
	
	<pfunction id="parseResult" comment="formats a list of entries from an enumeration output" method="xml" >
			<![CDATA[
				
				// create a new dom
				$domNew = new DOMDocument();	
				$root = $domNew->createElement("result");
				$rootDom = $domNew->appendChild($root);
				
				$table = $domNew->createElement("table");
				$tableDom = $rootDom->appendChild($table);
				
				
				$tr = $domNew->createElement("tr");
				$trDom = $tableDom->appendChild($tr);
				
				$th = $domNew->createElement("th");
				$thDom = $trDom->appendChild($th);
				$text = $domNew->createTextNode($TableName . " Entry");
				$textDom = $thDom->appendChild($text);
				
				$th = $domNew->createElement("th");
				$thDom = $trDom->appendChild($th);
				$text = $domNew->createTextNode($TableName . "." . $FieldName);
				$textDom = $thDom->appendChild($text);
				
				$fieldConcat = $TableName . "." . $FieldName;
				//print $fieldConcat . "\n";
				
				$nodeList = $input->getElementsByTagName($TableName);
				
				foreach ($nodeList as $nodeType => $node)
				{
					//print $node->nodeName . "\n";
					
					$name = $node->getAttribute("Name");
					
					$tr = $domNew->createElement("tr");
					$trDom = $tableDom->appendChild($tr);
					
					$td = $domNew->createElement("td");
					$tdDom = $trDom->appendChild($td);
					$text = $domNew->createTextNode($name);
					$textDom = $tdDom->appendChild($text);
					
					foreach ($node->childNodes as $childNode)
					{
						//
						if ( ($childNode->nodeType == 1 ) )
						{	//&& ($childNode->getAttribute("Name") == $fieldConcat) 
							// 
							// print $childNode->getAttribute("Name") . "\t" . $fieldConcat . "\n";
							if ($childNode->getAttribute("Name") == $fieldConcat ) 
							{
								//print $childNode->nodeValue . "\n";
								
								$value = $childNode->nodeValue ;
								
								$td = $domNew->createElement("td");
								$tdDom = $trDom->appendChild($td);
								$text = $domNew->createTextNode($value);
								$textDom = $tdDom->appendChild($text);
							}
							
						}
					}
					
				}
				
				print $domNew->saveXML();die();
		]]>
	</pfunction>
	
	<arguments type="user">  
		<var name="TableName" comment="the name of the table you wish to search" />
		<var name="FieldName" comment="the name of the field you wish to retrieve" />
	</arguments>
	
	<query id="1" name="ListSourceTable" comment="list entries in a table" type="maxdBrowse" >
		<table uref="user" name="TableName" />
		<action>browse</action>
		<ids>*</ids>
		<attributes>yes</attributes>
	</query>
	
	<query id="2" name="DisplayResults" type="export" >
		
		
		
		<h1>Your Browse Results</h1>
		<b uref="user" name="TableName" >Looking at table: </b>
		<b> and field: </b>
		<b uref="user" name="FieldName" /> 
		
		<h3 pref="parseResult" processResultID="1" >
			<var name="TableName" uref="user" />
			<var name="FieldName" uref="user" />
		</h3>
	</query>

</maxdQL>
