
<?php include('../conn.php');
if (isset($_GET['id'])) {
$id=mysqli_real_escape_string($conn, $_GET['id']);
$id2=base64_decode($id); }
?>

<!DOCTYPE html>
<html lang="en">
  <?php $page='Edit Store Details';?> 
<?php include("../common/head.php")?>
<style>

 
    label{
        font-size:15px;

    }
    .edit-body {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);

    border-radius: 20px;

    width:500px;
   
  }
    @media only screen and (max-width: 425px){
    .edit-body {
     
        width: 100%;
      }
    }

    input,select{
        background-color:rgba(0, 0, 0, 0) !important;
}
</style>
<body>
                 <!-- Modal -->
                 <?php 
$sql = "SELECT * FROM store_details WHERE id='$id2' ";
$result=mysqli_query($conn,$sql);
    $row=mysqli_fetch_array($result);
?>
        
        <div class="edit-body card  p-2">
        <div class="edit-header ">
          <h3 class="edit-tittle text-center " id="exampleModalLabel">Edit Store</h3>
        </div>
            <form method="post" enctype="multipart/form-data"  class=" ">


              <div class="row no-gutters">
              <div class="form-group col-12">
                  <label for="exampleFormControlInput1">Store Name:</label>
                  <input type="text" class="form-control" name="name" id="exampleFormControlInput1" value="<?php echo $row['name']?>">
                </div>
                <div class="form-group  col-6">
                  <label for="exampleFormControlInput1">First Contac:t</label>
                  <input type="text" class="form-control" name="c1" id="exampleFormControlInput1" value="<?php echo $row['first_contact']?>">
                </div>
                <div class="form-group col-6">
                  <label for="exampleFormControlInput1">Second Contact:</label>
                  <input type="text" class="form-control" name="c2" id="exampleFormControlInput1" value="<?php echo $row['second_contact']?>">
                </div>

                <div class="form-group col-12">
                  <label for="exampleFormControlInput1">Email Address:</label>
                  <input type="email" class="form-control" name="email" id="exampleFormControlInput1"  value="<?php echo $row['email']?>">
                </div>
                <div class="form-group col-12 ">
                  <label for="exampleFormControlInput1">Location:</label>
                  <input type="text" class="form-control" name="location" id="exampleFormControlInput1"    value="<?php echo $row['location']?>">
                </div>

                <div class="form-group col-12 ">
                    <label class="form-label" for="form6Example2">Logo:</label>
                    <input type="file" class="form-control-file border" name="image">
                    <small class="text-warning">please re-select your logo !!!</small>
                </div>  

                <div class="form-group col-6 ">
                  <label for="exampleFormControlInput1">Working Hours:</label>
                  <input type="text" class="form-control" name="w/h"    value="<?php echo $row['working_hours']?>">
                </div>

                <div class="form-group col-6 ">
                  <label for="exampleFormControlInput1">Website:</label>
                  <input type="text" class="form-control" name="website"     value="<?php echo $row['website']?>">
                </div>
              </div>
            

                <input type="hidden" name="date" value="<?php echo date("F j, Y") ?>">
                
                  <button class="btn btn-primary "  name="submit">Submit</button>
              </form>
        </div>
        <div class="modal-footer">
        </div>

        <?php 





if(isset($_POST['submit'])){
 
    $name=addslashes($_POST['name']);
    $c1=$_POST['c1'];
    $c2=$_POST['c2'];
     $email=$_POST['email'];
    $location=$_POST['location'];
    $filename = $_FILES['image']['name'];
     $w_h=$_POST['w/h'];
    $website=$_POST['website'];
     $date=$_POST['date'];


	// Select file type
	$imageFileType = strtolower(pathinfo($filename,PATHINFO_EXTENSION));
	
	// valid file extensions
	$extensions_arr = array("jpg","jpeg","png","jfif");
 
	// Check extension
	if( in_array($imageFileType,$extensions_arr) ){
 
	// Upload files and store in database
	if(move_uploaded_file($_FILES["image"]["tmp_name"],'../logo/'.$filename)){
     $sql = "UPDATE `store_details` SET `name`='$name',`first_contact`='$c1',`second_contact`='$c2',`email`='$email',`location`='$location',`logo`='$filename',`working_hours`='$w_h',`date`='$date',`website`='$website' WHERE id='$id2'";
     $result = $conn->query($sql);
    
     if(mysqli_query($conn,$sql)){
      echo"<script>alert('You Have Successfully Updated Store Details'); window.location='../settings'</script>";
		}
		else{
		  echo 'Error: '.mysqli_error($conn);
		}

}

else{
  echo 'Error in uploading file - '.$_FILES['image']['name'].'<br/>';
}
  }
}
?>

    </body>
</html>