<?
	header("Content-Type: text/html; charset=utf-8");
	
	$g_path = '../../my/';
	
	include $g_path."u_globals.php";
	include $g_path."html/f.php";
	include $g_path."u_spoj_na_bazu.php";
	
	include $g_path."u_headers.php";
	
	
	
	$result = '';
	
	$la_all = explode(':', rawurldecode($_GET['connect']));
	$la_tmp = explode(';', $la_all[0]);
	
	$la_polje = array();
	
	$result .= '<table cellpadding="2" cellspacing="1" border="0" bgcolor="#aaaaaa" width="100%"><tr bgcolor="#aaaaaa">'.
		'<tr colspan="2"><td>'.$la_all[2].'</td></tr>';
	$result .= '<tr bgcolor="#dddddd">';
	for($i = 0; $i < sizeof($la_tmp); $i++){
		$la2_tmp = explode('-', $la_tmp[$i]);
		$x = get_data('select ime_polja, label, tip_polja, tip_polja_maska from meta_prikaz_item where rbr = '.$la2_tmp[0].' and rbr_atribut = '.$la2_tmp[1]);
		$result .= '<td>'.$x['label'].'</td>';
		$la_polje []= $x;
	}
	$result .= '</tr>';
	
	$l_table = get_item('select meta_tablica_list.ime_tablice '.
		' from meta_prikaz_item, meta_prikaz, meta_tablica_list '.
		' where meta_prikaz_item.rbr_meta_prikaz = meta_prikaz.rbr '.
		' and meta_prikaz.rbr_meta_tablica_list = meta_tablica_list.rbr '.
		' and meta_prikaz_item.rbr = '.$la2_tmp[0].
		' and meta_prikaz_item.rbr_atribut = '.$la2_tmp[1]);
	
	$la2_tmp = explode('-', $la_all[1]);
	$l_field = get_item('select ime_polja from meta_prikaz_item where rbr = '.$la2_tmp[0].' and rbr_atribut = '.$la2_tmp[1]);
	
	
	
	$l_polje_txt = '';
	for($i = 0; $i < sizeof($la_polje); $i++){
		$l_polje_txt .= ', '.$la_polje[$i]['ime_polja'];
	}
	$l_polje_txt = substr($l_polje_txt, 2);
	
	$y = get_data('select '.$l_polje_txt.' from '.$l_table.' where '.$l_field.' = "'.rawurldecode($_GET['value']).'"', 1);
	
	//print 'select '.$l_polje_txt.' from '.$l_table.' where '.$l_field.' = "'.rawurldecode($_GET['value']).'" <br>';
	
	
	for($i = 0; $i < sizeof($y[$la_polje[0]['ime_polja']]); $i++){
		$result .= '<tr bgcolor="#ffffff">';
		for($j = 0; $j < sizeof($la_polje); $j++){
			
			
			if($la_polje[$j]['tip_polja_maska']){
				$la_polje[$j]['tip_polja'] = $la_polje[$j]['tip_polja_maska'];
			}
			switch($la_polje[$j]['tip_polja']){
				case 'date':
					$la_tmp = explode('-', substr($y[$la_polje[$j]['ime_polja']][$i], 0, 10));
					$l_value = $la_tmp[2].'-'.$la_tmp[1].'-'.$la_tmp[0];
					break;
					
				default:
					$l_value = $y[$la_polje[$j]['ime_polja']][$i];
			}
			$result .= '<td>'.$l_value.'</td>';
		}
		$result .= '</tr>';
	}
	
	$result .= '</table>';
	
	print $result;
?>
