<?php
	include("service_func.php");
	$hddnServiceId = $_SESSION['caller']['args'][1];
	if ($_SESSION['user']['access_level'] < SABLE_ACCESS_MANAGER)
	{
		SableGeneralFunctions::divertFromPage();
	}
	$row = $sableDB->getRow("select * from service where service_id = ".$hddnServiceId);
	$areas = $sableDB->getRows("select * from service__area where service_id = ".$hddnServiceId);
	$js = '<script>';
	//$js = '$(document).ready(function(e){';
	foreach($areas as $area)
	{
		$js .= "document.getElementById('selAreaId').value = '".$area['area_id']."';".PHP_EOL;
		$js .= "areaItem.addItem(document.getElementById('selAreaId'));".PHP_EOL;
		//$js .= "console.log(areaItem);".PHP_EOL;
	}
	//$js .= "});"; //areaItem.addItem(this)
	$js .= '</script>';
?>
<script src="<?php SableGeneralFunctions::printModuleJS('service'); ?>"></script>

<!--// Service -->
<form id="frmService" name="frmService" autocomplete="on">
	<input type="hidden" value="<?php echo(SableSystem::sableEncode($hddnServiceId)); ?>" id="hddnServiceId" name="hddnServiceId" />
	<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-edit" aria-hidden="true"></i>&nbsp;Modify Service</h3>
					<p></p>
				</div>
			</div>
			<p></p>
			<!--// edtServiceName -->
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
					<input name="edtServiceName" type="text" id="edtServiceName" onfocus="showHint('edtServiceName'); validate_edtServiceName();" onblur="hideHint('edtServiceName');" placeholder="Service" onkeypress="handleEnter(this, event);" value="<?php echo($row['service_name']); ?>" >
				</div>
				<div class="col-md-8">
					<div class="fieldHint" id="hint_edtServiceName">Service</div>
				</div>
			</div>
			<p></p>
			<!-- edtServiceName //-->
			<p></p>
			<!--// edtServiceDuration -->
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
					<input name="edtServiceDuration" type="number" id="edtServiceDuration" class="mod"  onfocus="showHint('edtServiceDuration'); validate_edtServiceDuration();" onblur="hideHint('edtServiceDuration');" placeholder="Duration" onkeypress="handleEnter(this, event);" value="<?php echo($row['service_duration']); ?>" >
				</div>
				<div class="col-md-8">
					<div class="fieldHint" id="hint_edtServiceDuration">Duration</div>
				</div>
			</div>
			<p></p>
			<!-- edtServiceDuration //-->
			<p></p>
			<!--// edtServicePrice -->
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
					<input name="edtServicePrice" type="number" id="edtServicePrice" class="mod"  onfocus="showHint('edtServicePrice'); validate_edtServicePrice();" onblur="hideHint('edtServicePrice');" placeholder="Price" onkeypress="handleEnter(this, event);" value="<?php echo($row['service_price']); ?>" >
				</div>
				<div class="col-md-8">
					<div class="fieldHint" id="hint_edtServicePrice">Price</div>
				</div>
			</div>
			<p></p>
			<!-- edtServicePrice //-->
			<p></p>
			
			<!--// edtAreaName -->
			<div class="row forms-grids">
				<div class="col-md-4 forms-grid">
					<input type="text" id="edtAreaName" name="edtAreaName" placeholder="SEARCH..." onKeyUp="doAreaRefinement(this)" style="border-bottom: none;" autocomplete="off"/>
				</div>
				<div class="col-md-8">
					<div class="fieldHint" id="hint_edtAreaName">Search by area</div>
				</div>   
			</div>
			<!-- edtAreaName //-->		
			<!--// selAreaId -->
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
					<div class="dropdown">
						<select name="selAreaId" type="select" id="selAreaId" onfocus="showHint('selAreaId');" 
								onblur="hideHint('selAreaId'); validate_selAreaId()" onkeypress="handleEnter(this, event)" placeholder="Area" size="6" class="noArrow"  onClick="setAreaName()" onChange="areaItem.addItem(this);">
						<?php echo(SableDBFunctions::getOptions("area", "area_id", "area_name", $row['area_id'])); ?>
						</select>
					</div>
				</div>
				<div class="col-md-8">
					<div class="fieldHint" id="hint_selAreaId">Area</div>
				</div>
			</div>

			<div class="row forms-grid">
				<div id="AreaElement">
					<!--// Selected elements will be placed here. -->
				</div>
			</div>
			<p></p>
			<!-- selAreaId //-->			
			
		<!--// buttons -->
			<div class="row forms-grid">
				<div class="col-md-2">
					<input type="button" id="btnCancel" value="Cancel"
					class="submit" onclick="window.location = '<?php SableSystem::printCallPageLink('/service/'); ?>'"/>
				</div>
				<div class="col-md-2 forms-grid">
					<input id="btnOk" type="button" onclick="modifyService();" value="Update Service" class="submit"/>
				</div>
			</div>
		<!-- buttons //-->
		</div>
	</div>
</form>
<!-- Service //-->
<?php echo($js); ?>
