<?php
	include(__DIR__.'/../includes/sysinit.php');
	$html	= '<option value="0">Select Service</option>';
	if ($_POST['id'])
	{
		$sql = 'select area.area_id, area_name 
									from building 
									inner join area on area.area_id = building.area_id 
									where building_id = '.$_POST['id'];

		$area = $sableDB->getRow($sql);
		$sql = 'select service.service_id, service_name, service_price 
				from service 
				inner join service__area on service__area.service_id = service.service_id 
				where area_id = '.$area['area_id'];
		$rows = $sableDB->getRows($sql);
		if (empty($rows))
		{
			$html	= '<option value="0">No services linked to area "'.$area['area_name'].'".</option>';
		}
		else
		{
			foreach($rows as $row) 
			{
				$html .= '<option value="'.$row['service_id'].'">'.$row['service_name'].' (R'.number_format($row['service_price'], 2).')</option>';
			}
		}
	}
	$data['output_list'] = $html;
	SableSystem::ajaxFillField($html, $_POST['field']);