<?php require_once("header.php");?>

<?php
if(isset($_POST['send']))
{	
	$sql_update = "UPDATE `usertable` SET `name` = '".addslashes($_POST['name'])."',`postal_state` = '".addslashes($_POST['state'])."',`email` = '".addslashes($_POST['email'])."',`phone` = '".addslashes($_POST['phone'])."',`postal_area` = '".addslashes($_POST['address'])."',`postal_city` = '".addslashes($_POST['city'])."',`postal_pin` = '".addslashes($_POST['zip'])."',`nationality` = '".addslashes($_POST['nationality'])."',`religion` = '".addslashes($_POST['religion'])."' WHERE `id` = '".$_SESSION['USER_ID']."'";
	$exe_update = mysqli_query($connection,$sql_update);
	
	$_SESSION['ep_succ_msg'] = 'Profile updated successfully.';
	header("location: edit-profile.php");
	exit;
}

$getUser = mysqli_fetch_array(mysqli_query($connection,"SELECT * FROM `usertable` WHERE `id` = '".$_SESSION['USER_ID']."'"));
?>

		<script language="javascript" type="text/javascript">
		function form_validation()
		{
			if(document.getElementById('name').value == "")
			{
				alert("Please enter name");
				document.getElementById('name').focus();
				return false;
			}
			
			if(document.getElementById('phone').value == "")
			{
				alert("Please enter phone no.");
				document.getElementById('phone').focus();
				return false;
			}
			
			if(document.getElementById('email').value == "")
			{
				alert("Please enter email address");
				document.getElementById('email').focus();
				return false;
			}
			
			if(document.getElementById('address').value == "")
			{
				alert("Please enter address");
				document.getElementById('address').focus();
				return false;
			}

			if(document.getElementById('city').value == "")
			{
				alert("Please enter city");
				document.getElementById('city').focus();
				return false;
			}
		   
			if(document.getElementById('zip').value == "")
			{
				alert("Please enter postcode");
				document.getElementById('zip').focus();
				return false;
			}
			
			if(document.getElementById('nationality').value == "")
			{
				alert("Please enter nationality");
				document.getElementById('nationality').focus();
				return false;
			}
			
			if(document.getElementById('religion').value == "")
			{
				alert("Please enter religion");
				document.getElementById('religion').focus();
				return false;
			}
			
			return true;
		}
		</script>

		<!-- content area start -->
		<section id="about">
			<div class="container mt-10 pb-10 pt-0">			
				<div class="row">
					<div class="col-lg-4">
						<?php require_once("user_left_panel.php");?>
					</div>
					<div class="col-lg-8">
					    <h1 class="title mt-5 mb-15">Edit Profile</h1>
						<?php if(isset($_SESSION['ep_succ_msg'])) { ?>
						<p><img src="images/tick.png" alt="" /> <?php echo $_SESSION['ep_succ_msg'];?></p>
						<?php 
						unset($_SESSION['ep_succ_msg']);
						} 
						?>	
						<form id="" action="" method="post" enctype="multipart/form-data" class="contact-form text-right" onsubmit="return form_validation();">
						<div class="row">
							<div class="col-lg-12 form-group">
								<input name="name" id="name" placeholder="Enter first name *" class="common-input form-control" type="text" value="<?php echo stripslashes($getUser['name']);?>">
							</div>
							<div class="col-lg-12 form-group">
								<input name="phone" id="phone" placeholder="Enter Phone No. *" class="common-input form-control" type="text" value="<?php echo stripslashes($getUser['phone']);?>">
							</div>
							<div class="col-lg-12 form-group">
								<input name="email" id="email" placeholder="Enter Email Address *" class="common-input form-control" type="text" value="<?php echo stripslashes($getUser['email']);?>">
							</div>
							<div class="col-lg-12 form-group">
								<textarea name="address" id="address" class="common-input form-control" placeholder="Enter Address *"><?php echo stripslashes($getUser['postal_area']);?></textarea>
							</div>
							<div class="col-lg-12 form-group">
								<input name="city" id="city" placeholder="Enter City *" class="common-input form-control" type="text" value="<?php echo stripslashes($getUser['postal_city']);?>">
							</div>
							<div class="col-lg-12 form-group">
								<input name="state" id="state" placeholder="Enter State *" class="common-input form-control" type="text" value="<?php echo stripslashes($getUser['postal_state']);?>">
							</div>
							<div class="col-lg-12 form-group">
								<input name="zip" id="zip" placeholder="Enter Pincode *" class="common-input form-control" type="text" value="<?php echo stripslashes($getUser['postal_pin']);?>">
							</div>
							<div class="col-lg-12 form-group">
								<input name="nationality" id="nationality" placeholder="Enter Nationality *" class="common-input form-control" type="text" value="<?php echo stripslashes($getUser['nationality']);?>">
							</div>
							<div class="col-lg-12 form-group">
								<input name="religion" id="religion" placeholder="Enter Religion *" class="common-input form-control" type="text" value="<?php echo stripslashes($getUser['religion']);?>">
							</div>
							<div class="col-lg-12 form-group">
								<button class="btn btn-flat btn-theme-colored mb-sm-30 border-left-theme-color-2-4px" type="submit" style="float: left;">Save</button>
							</div>
						</div>
						<input type="hidden" name="send" id="send" value="1" />
						</form>	
					</div>
				</div>
			</div>	
		</section>
		<!-- content area end -->

<?php require_once("footer.php");?>