<?php session_start();
	include_once("../../functions/init.php"); 
	include ($thisUrl."adm1n/functions/access.php");
	include_once ($thisUrl."adm1n/functions/koneksi.php");

	function listNegara (&$list_data) {
		$sql8 = 
		" SELECT distinct valueID, valueName ".
		" FROM kontak_dagang_header, kontak_dagang_transaksi, form_element_value ".
		" WHERE header_id = to_kontak_dagang_header ".
		" AND to_negara = valueID ".
		" AND elementSubParentID = '1' ".
		" ORDER BY valueName ";
		//echo "<br>sql8: ".$sql8;
		if ($hasil8 = mysql_query($sql8)) {
			if (mysql_num_rows(mysql_query($sql8))){
				while ($data8 = mysql_fetch_array($hasil8)) {
					$list_data[$data8["valueID"]] = $data8["valueName"];
				}
			}
		}
	}
	
	function listPerusahaan (&$list_data) {
		$sql8 = 
		" SELECT distinct exhibitorID, companyName ".
		" FROM kontak_dagang_header, kontak_dagang_transaksi, exhibitor_list ".
		" WHERE header_id = to_kontak_dagang_header ".
		" AND to_exhibitor_id = exhibitorID ".
		" ORDER BY companyName ";
		//echo "<br>sql8: ".$sql8;
		if ($hasil8 = mysql_query($sql8)) {
			if (mysql_num_rows(mysql_query($sql8))){
				while ($data8 = mysql_fetch_array($hasil8)) {
					$list_data[$data8["exhibitorID"]] = $data8["companyName"];
				}
			}
		}
	}
	
	function listUser (&$list_data) {
		$sql8 = 
		" SELECT distinct username ".
		" FROM kontak_dagang_header as a, kontak_dagang_transaksi as b, user ".
		" WHERE header_id = to_kontak_dagang_header ".
		" AND b.updated_by = username ".
		" ORDER BY username ";
		//echo "<br>sql8: ".$sql8;
		if ($hasil8 = mysql_query($sql8)) {
			if (mysql_num_rows(mysql_query($sql8))){
				while ($data8 = mysql_fetch_array($hasil8)) {
					$list_data[$data8["username"]] = $data8["username"];
				}
			}
		}
	}
?>
<?php
	if (isset($list_data)) unset($list_data);
	$list_data = array();	
	
	$selectedID = $_POST["selectedID"];
	if ($selectedID == "1") listNegara ($list_data);
	else if ($selectedID == "2") listPerusahaan ($list_data);
	else if ($selectedID == "3") listUser ($list_data);
	
    print json_encode($list_data);
	//var_dump($product_name[9]);
	unset($list_data);
	exit;	
?>
