<?php
	include("client_func.php");
	$hddnClientId = $_SESSION['caller']['args'][1];
	if ($_SESSION['user']['access_level'] < SABLE_ACCESS_MANAGER)
	{
		SableGeneralFunctions::divertFromPage();
	}
	$row = $sableDB->getRow("select * from client where client_id = ".$hddnClientId);
	$address = $sableDB->getRow("select * from address where address_id = ".$row['address_id']);
?>
<script src="<?php SableGeneralFunctions::printModuleJS('client'); ?>"></script>

<?php include(SABLE_INCLUDES_PATH.'googleMaps.php'); ?>

<!--// Client -->
<form id="frmClient" name="frmClient" autocomplete="on">
	<input type="hidden" value="<?php echo(SableSystem::sableEncode($hddnClientId)); ?>" id="hddnClientId" name="hddnClientId" />
	<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 Client</h3>
					<p></p>
				</div>
			</div>
			<!--// edtClientName -->
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
					<input name="edtClientName" type="text" id="edtClientName" onfocus="showHint('edtClientName'); validate_edtClientName();" onblur="hideHint('edtClientName');" placeholder="Name" onkeypress="handleEnter(this, event);" value="<?php echo($row['client_name']); ?>" >
					<label for="edtClientName" class="fieldHint hintUnder" id="hint_edtClientName">Name</label>
				</div>
				<div class="col-md-8">
				</div>
			</div>
			<p></p>
			<!-- edtClientName //-->
			<p></p>
			<!--// edtClientSurname -->
			<div class="row forms-grid" style="display:none;">
				<div class="col-md-4 forms-grid">
					<input name="edtClientSurname" type="text" id="edtClientSurname" onfocus="showHint('edtClientSurname'); validate_edtClientSurname();" onblur="hideHint('edtClientSurname');" placeholder="Surname" onkeypress="handleEnter(this, event);" value="<?php echo($row['client_surname']); ?>" >
					<label for="edtClientSurname" class="fieldHint hintUnder" id="hint_edtClientSurname">Surname</label>
				</div>
				<div class="col-md-8">
				</div>
			</div>
			<p></p>
			<!-- edtClientSurname //-->
			<p></p>
			<!--// txtAddressId -->
			<div class="row forms-grid">
				<div class="col-md-4 forms-grid">
					<textarea name="txtAddressId" type="textarea" id="txtAddressId" onfocus="showHint('txtAddressId');" 
							  onblur="hideHint('txtAddressId'); validate_txtAddressId()" placeholder="Address" 
							  onChange="updateMapData();" ><?php echo($address['address'] ?? 'unknown'); ?></textarea>
					<label for="txtAddressId" class="fieldHint hintUnder" id="hint_txtAddressId">Address</label>
				</div>
				<div class="col-md-4 forms-grid">
					<textarea name="txtAddressNote" type="date" id="txtAddressNote" onfocus="showHint('txtAddressNote'); validate_txtAddressNote();" onblur="hideHint('txtAddressNote');" placeholder="Address Note" onkeypress="handleEnter(this, event);" ><?php echo($row['client_address_note']); ?></textarea>
					<label for="txtAddressNote" class="fieldHint hintUnder" id="hint_txtAddressNote">Address Note</label>
				</div>
				<div class="col-md-4 forms-grid"></div>
			</div>		
			<p></p>
			<!-- txtAddressId //-->
			<div class="row forms-grids">
				<div class="col-md-12 forms-grid">
					<div id="searchResults"></div>
				</div>
			</div>
			<p></p>

			<!--// edtClientCell -->
			<div class="row">
				<div class="col-md-4 forms-grid" style="padding:0;">
					<div class="col-md-12">
						<input name="edtClientCell" type="text" id="edtClientCell" onfocus="showHint('edtClientCell'); validate_edtClientCell();" onblur="hideHint('edtClientCell');" placeholder="Cell No." onkeypress="handleEnter(this, event);"  value="<?php echo($row['client_cell']); ?>">
						<label for="edtClientCell" class="fieldHint hintUnder" id="hint_edtClientCell">Cell No.</label>
					</div>
					<div class="col-md-12">
						<input name="edtClientPhone" type="text" id="edtClientPhone" onfocus="showHint('edtClientPhone'); validate_edtClientPhone();" onblur="hideHint('edtClientPhone');" placeholder="Phone No." onkeypress="handleEnter(this, event);"  value="<?php echo($row['client_phone']); ?>">	
						<label for="edtClientPhone" class="fieldHint hintUnder" id="hint_edtClientPhone">Phone No.</label>
					</div>				
					<div class="col-md-12">
						<input name="edtClientEmail" type="email" id="edtClientEmail" onfocus="showHint('edtClientEmail'); validate_edtClientEmail();" onblur="hideHint('edtClientEmail');" placeholder="Email" onkeypress="handleEnter(this, event);"  value="<?php echo($row['client_email']); ?>">
						<label for="edtClientEmail" class="fieldHint hintUnder" id="hint_edtClientEmail">Email</label>
					</div>
				</div>
				<div class="col-md-4 forms-grid">
					<textarea name="txtClientBookingNote" type="date" id="txtClientBookingNote" style="height:13.5em;" onfocus="showHint('txtClientBookingNote'); validate_txtClientBookingNote();" onblur="hideHint('txtClientBookingNote');" placeholder="Booking Notes" onkeypress="handleEnter(this, event);" ><?= $row['client_booking_note']; ?></textarea>
					<label for="txtClientBookingNote" class="fieldHint hintUnder" id="hint_txtClientBookingNote">Booking Notes</label>
				</div>				
			</div>
			<p></p>
			<!-- edtClientCell //-->
			
			<p><h3><i class="fa fa-comment"></i>&nbsp;Client Notes</h3></p>
			<div class="row forms-grid">
				<div class="col-md-8 forms-grid">
					<textarea name="txtClientNotes" type="textarea" id="txtClientNotes" size="7" ><?php echo($row['client_notes']); ?></textarea>
				</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 = '<?php SableSystem::printCallPageLink('/client/'); ?>'"/>
				</div>
				<div class="col-md-2 forms-grid">
					<input id="btnOk" type="button" onclick="modifyClient();" value="Update Client" class="submit"/>
				</div>
			</div>
		<!-- buttons //-->
		<?php include(SABLE_INCLUDES_PATH.'googleMapsDisplay.php'); ?>
		</div>
	</div>
</form>
<!-- Client //-->
<script>showAddress('<?= ($address['address_lng'] ?? 0) ?>', '<?= ($address['address_lat'] ?? 0) ?>', '<?= ($address['address'] ?? '') ?>');</script>
