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

<?php
if(isset($_POST['send']))
{	
	$sql_update = "UPDATE `sc_users` SET `full_name` = '".addslashes($_POST['name'])."',`email` = '".addslashes($_POST['email'])."',`phone` = '".addslashes($_POST['phone'])."',`address` = '".addslashes($_POST['address'])."',`landmark` = '".addslashes($_POST['landmark'])."' WHERE `user_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 `sc_users` WHERE `user_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('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('landmark').value == "")
			{
				alert("Please enter landmark");
				document.getElementById('landmark').focus();
				return false;
			}
			
			return true;
		}
		</script>

		<!-- content area start -->
		<section id="about">
			<div class="container mt-0 pb-0 pt-5">	
				<div class="row">
					<div class="col-lg-12">
				        <h1 class="title mt-0 mb-10" style="text-align:center;">Edit Profile</h1>
						<?php if(isset($_SESSION['ep_succ_msg'])) { ?>
						<p style="text-align:center; margin-bottom:10px;"><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 Name *" class="common-input form-control" type="text" value="<?php echo stripslashes($getUser['full_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" maxlength="10" value="<?php echo stripslashes($getUser['phone']);?>" readonly>
							</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 *" style="height:100px;"><?php echo stripslashes($getUser['address']);?></textarea>
							</div>
							<div class="col-lg-12 form-group">
								<input name="landmark" id="landmark" placeholder="Enter Landmark *" class="common-input form-control" type="text" value="<?php echo stripslashes($getUser['landmark']);?>">
							</div>
							<div class="col-lg-12 form-group">
								<button class="btn btn-flat btn-theme-colored 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");?>