<?php
	include(__DIR__.'/../includes/sysinit.php');
	$sql = "select concat('U',user_code) as user_contact_id, concat(user_name, ' ', user_surname, ' [', company_name, ']') as user_full_name
			from user 
			inner join company on company.company_id = user.company_id 
			where (user.company_id = 1 or user.company_id = 2) and (user.deleted = 0)
			UNION
			select concat('C', contact_id) as user_contact_id, concat(contact_name, ' ', contact_surname, ' [', company_name, ']') as user_full_name
			from company__contact 
			inner join company on company.company_id = company__contact.company_id 
			where company__contact.company_id = ".$_POST['company_id']." and company__contact.contact_enabled = true ";
	
	//SableDebug::debug($sql);
	
	$rows = $sableDB->getRows($sql);
	$html = "<option value=0>Select Contact</option>";
	$cnt = 0;
	foreach($rows as $row)
	{
		$html .= '<option value="'.SableSystem::sableEncode($row['user_contact_id']).'">'.$row['user_full_name'].'</option>';
		$cnt++;
	}
	$data['output_list'] = $html;
	//echo(json_encode($data));	
	SableSystem::ajaxFillField($html, $_POST['field_id']);
?>