<?php

function tag_start($parser, $attr, $params)
{
	global $xml_name;
	global $xml_array;

	if ($attr == $xml_name) $xml_array = array();
	else $xml_array[] = $params;
}

function keytag_start($parser, $attr, $params)
{
	global $xml_name;
	global $xml_array;
	global $xml_key;

	if ($attr == $xml_name) $xml_array = array();
	else $xml_array[$params[$xml_key]] = $params;
}

function tag_end($parser, $attr) {}

function pobierzDane($name, $params, $key=NULL)
{
	global $xml_name;
	global $xml_array;
	global $xml_key;

	$xml_name = strtoupper($name);
	$xml_array = NULL;
	$xml_key = strtoupper($key);

	$xml_file = fopen('http://sarmacja.org/integracja/xml/'.$name.'.php?'.$params, 'r');

	if ($xml_file)
	{
		$parser = xml_parser_create();
		xml_set_element_handler($parser, (empty($key) ? 'tag_start' : 'keytag_start'), 'tag_end');

		while (!feof($xml_file))
		{
			$dane = fread($xml_file, 4096);
		     	if (!xml_parse($parser, $dane, feof($xml_file))) break;
		}

		xml_parser_free($parser);
		return $xml_array;
	}

	return 'BRAK_POLACZANIA';
}

?>