<?php
	require_once('schedule_func.php');
	include(SABLE_INCLUDES_PATH.'googleMaps.php');
	$bsid = $_SESSION['caller']['args'][1];
	$sqry = 'select client_id 
			from booking_schedule 
			inner join booking on booking.booking_id = booking_schedule.booking_id 
			where booking_schedule.bs_id = '.$bsid;
	$clientId = $sableDB->getValue($sqry);

	$sql = "select booking__service.building_id, booking__service.service_id, building_name, service_name 
			from booking__service 
			inner join booking_schedule on booking_schedule.booking_id = booking__service.booking_id 
			inner join building on building.building_id = booking__service.building_id 
			inner join service on service.service_id = booking__service.service_id 
			where booking_schedule.bs_id = ".$bsid." and booking__service.service_active = 1";

	$serv	= $sableDB->getRows($sql);

	$js = '<script>';
	foreach($serv as $itm)
	{
		$js .= 'buildServiceList('.$itm['building_id'].', '.$itm['service_id'].', "'.$itm['building_name'].'", "'.$itm['service_name'].'");'.PHP_EOL;
	}
	$js .= '$(document).ready(function(e){getClientBuildingList();})';
	$js .= '</script>'.PHP_EOL;
?>
<script src="<?php echo(SABLE_THEME_ROOT.'mobi/mobi.js'); ?>?v=<?php echo(SABLE_VERSION); ?>"></script>
<script src="<?php SableGeneralFunctions::printModuleJS('booking'); ?>"></script>
<div class="sable-tab-bar">
	<div class="container">
		<div class="row" style="background: white; padding: 2px 0 0 0;">
			<div class="col-xs-2 pointer" onclick='window.location = "<?php SableSystem::printThemeLinkPath('dashboard/index.php'); ?>"'>
				<i class='fa fa-2x fa-arrow-left' title="Back"></i>
			</div>
			<div class="col-xs-2">
			</div>
			<div class="col-xs-8"></div>
		</div>
    </div>			
</div>

<!--// Booking -->
<form id="frmBooking" name="frmBooking" autocomplete="on">
	<input type="hidden" value="<?php echo($clientId); ?>" id="selClientId">
	<div class="forms">
		<div class="container forms-grids">
			<div class="row forms-grid">
				<div class="col-md-12">
					<h3 class="title"><i class="fa fa-plus" aria-hidden="true"></i>&nbsp;Add Service</h3>
					<p></p>
				</div>
			</div>
		
			<div class="row forms-grid">
				<!--// selBuildingId -->
					<div class="col-md-4 forms-grid">
						<div class="dropdown">
							<select name="selBuildingId" type="select" id="selBuildingId" onfocus="showHint('selBuildingId');" 
									onblur="hideHint('selBuildingId');" onkeypress="handleEnter(this, event)" placeholder="Building" onChange="setBuildingServiceList()">
								<?php SableDBFunctions::printOptions('building', 'building_id', 'building_name', -1, 'where client_id = '.$clientId); ?>
							</select>
						</div>
					</div>
					<div class="col-md-4 forms-grid">
						<div class="dropdown">
							<select name="selServiceId" type="select" id="selServiceId" onfocus="showHint('selServiceId');" 
									onblur="hideHint('selServiceId');" onkeypress="handleEnter(this, event)" placeholder="Service" onChange="setServiceItem();">
								<option>Select Building First</option>
							</select>
						</div>
					</div>
				<!-- selBuildingId //-->	
			</div>
	
			<div class="row forms-grid">
				<!--// selServiceId -->
					<div class="col-md-4">
						<div class="fieldHint hintUnder" id="hint_selBuildingId">Building</div>
					</div>
					<div class="col-md-4">
						<div class="fieldHint hintUnder" id="hint_selServiceId">Service</div>
					</div>
				<!-- selServiceId //-->	
			</div>
			
			<div class="row forms-grid">
				<div id="ServiceElement">
					<!--// Selected elements will be placed here. -->
				</div>
			</div>
			<p></p>	
		
			<!--// buttons -->
			<div class="row forms-grid">
				<div class="col-md-2">
					<input type="button" id="btnCancel" value="Cancel" class="submit" 
						   onclick="window.location.reload();"/>
				</div>
				<div class="col-md-2 forms-grid">
					<input id="btnOk" type="button" onclick="updateServices(<?php echo($bsid); ?>, <?php echo($clientId); ?>);" value="Add Service(s)" class="submit"/>
				</div>
			</div>
			<!-- buttons //-->
		</div>
	</div>
</form>
<!-- Booking //-->
<?php
	require_once('schedule_bottom.php');
	echo($js);
