
<?php include("header.php");
 include("side.php");
$admin_id=$_SESSION['id2'];
extract($_POST);
if(isset($submit)){
$sql=mysqli_query($conn,"UPDATE `users` SET `image`='$image', `name`='$name', `email`='$email', `mobile`='$mobile', `address`='$address' WHERE status='admin'");
$alert='<div class="alert alert-success alert-dismissible">
  <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
  <strong>Profile successfully update</strong>
</div>';
}
?>
<!-- ?name=salim+saifi&email=salimsaifi61%40gmail.com&mobile=%2B919911983098&address=C-44+Main+100ft+Road+Maujpur&submit= -->

            <div id="layoutSidenav_content">
                <main>
                    <div class="container-fluid">
                        <h2 class="mt-30 page-title">Edit Profile</h2>
                        <ol class="breadcrumb mb-30">
                            <li class="breadcrumb-item"><a href="index.html">Dashboard</a></li>
                            <li class="breadcrumb-item active">Edit Profile</li>
                        </ol>
                        <?php if(isset($alert)){ echo  $alert; } ?>
                        <div class="row">
							<div class="col-lg-4 col-md-5">
								<div class="card card-static-2 mb-30">
									<div class="card-body-table">
									
										<div class="shopowner-content-left text-center pd-20">
											<?php	$sql=mysqli_query($conn,"SELECT * FROM `shops` WHERE status='admin'");
											while ($row=mysqli_fetch_object($sql)) { ?>
											<div class="shop_img mb-3">
												<img src="<?php if(!empty($row->image)){ echo '../uploads/'.$row->image;} else{ echo 'images/avatar/img-1.jpg'; } ?>" alt="">
											</div>
											<div class="shopowner-dt-left">
												<h4>Supermarket (Admin)</h4>
												<span><?=$row->name;?></span>
											</div>
											<div class="shopowner-dts">
												<div class="shopowner-dt-list">
													<span class="left-dt">Username</span>
													<span class="right-dt"><?=$row->name;?> (Admin)</span>
												</div>
												<div class="shopowner-dt-list">
													<span class="left-dt">Phone</span>
													<span class="right-dt"><?=$row->mobile;?></span>
												</div>
												<div class="shopowner-dt-list">
													<span class="left-dt">Email</span>
													<span class="right-dt"><?=$row->email;?></span>
												</div>
												<div class="shopowner-dt-list">
													<span class="left-dt">Address</span>
													<span class="right-dt"><?=$row->address;?></span>
												</div>
											</div>
											
										</div>
									</div>
								
								</div>
							</div>
							<div class="col-lg-8 col-md-7">
								<div class="card card-static-2 mb-30">
									<div class="card-title-2">
										<h4>Edit Profile</h4>
									</div>
									<div class="card-body-table">
										<div class="news-content-right pd-20">
											<form action="" method="post">
											<div class="row">
												<div class="col-lg-6">
													<div class="form-group mb-3">
														<label class="form-label">Full Name*</label>
														<input type="text" name="name" class="form-control" value="<?=$row->name;?>" placeholder="Enter First Name">
													</div>
												</div>
												
												<div class="col-lg-6">
													<div class="form-group mb-3">
														<label class="form-label">Email*</label>
														<input type="email" name="email" class="form-control" value="<?=$row->email;?>" placeholder="Enter Email Address">
													</div>
												</div>
												<div class="col-lg-6">
													<div class="form-group mb-3">
														<label class="form-label">Phone*</label>
														<input type="text" name="mobile" class="form-control" value="<?=$row->mobile;?>" placeholder="Enter Phone Number">
													</div>
												</div>
												
												<div class="col-lg-6">
													<div class="form-group mb-3">
														<label class="form-label">Address*</label>
														<textarea class="form-control" name="address" placeholder="Address"><?=$row->address;?></textarea>														
													</div>
												</div>
												<div class="col-lg-6">
													<div class="form-group mb-3">
														<label class="form-label">Profile Image*</label>
														<div class="input-group">
															<div class="custom-file">
																<!-- <input type="file" class="custom-file-input" name="image" id="profile-img" aria-describedby="inputGroupFileAddon04"> -->
																
																<input id="file" type="file" name="image" class="custom-file-input" aria-describedby="inputGroupFileAddon04" name="image" >
																<label class="custom-file-label" for="file">Choose Image</label>
															</div>
														</div>
													</div>
												</div>
												<div class="col-lg-6">
													<div class="form-group mb-3">
														<div class="add-cate-img-1">
															<span id="uploaded_image">

															<img class="im" src=<?php if(!empty($row->image)){ echo '../uploads/'.$row->image;} else{ echo 'images/avatar/img-1.jpg'; } ?> >
														</span>
														</div>
													</div>
												</div>
												<?php } ?>
												<div class="col-lg-12">
													<button class="save-btn hover-btn" name="submit" type="submit">Save Changes</button>
												</div>
											</div>
										</form>
											
										</div>
									</div>
								</div>
							</div>
                        </div>
                    </div>
                </main>
               <?php include("footer.php"); ?>

           <script>
$(document).ready(function(){
 $(document).on('change', '#file', function(){
  var name = document.getElementById("file").files[0].name;
  var form_data = new FormData();
  var ext = name.split('.').pop().toLowerCase();
  if(jQuery.inArray(ext, ['gif','png','jpg','jpeg']) == -1) 
  {
   alert("Invalid Image File");
  }
  var oFReader = new FileReader();
  oFReader.readAsDataURL(document.getElementById("file").files[0]);
  var f = document.getElementById("file").files[0];
  var fsize = f.size||f.fileSize;
  if(fsize > 2000000)
  {
   alert("Image File Size is very big");
  }
  else
  {
   form_data.append("file", document.getElementById('file').files[0]);
   $.ajax({
    url:"upload.php",
    method:"POST",
    data: form_data,
    contentType: false,
    cache: false,
    processData: false,
    beforeSend:function(){
     $('#uploaded_image').html("<label class='text-success'>Image Uploading...</label>");
    },   
    success:function(data)
    {
     $('#uploaded_image').html(data);
     // alert("successfully upload Click ( OK ) to submit");
     
    }
   });
  }
 });
});
</script>

<script>
  new FroalaEditor('textarea#froala-editor')
</script>