<?php
include_once('../data/@data@.php');

if(isset($_GET['shopreg']))
{
  $stalluuid = $_GET['shopreg'];
  $stalluuid;

  $base64Encoded = $stalluuid; 
  echo $decodedData = base64_decode($base64Encoded);

 $sel = "SELECT * FROM `stall` WHERE `uuid`= '$stalluuid'";
  $res = mysqli_query($conn, $sel);
  $data=mysqli_fetch_assoc($res);

}
else
{
  header('location:/');
}

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  ob_start(); 

  // Retrieve and sanitize form data using mysqli_real_escape_string
  $name = mysqli_real_escape_string($conn, $_POST['name']);
  $mobile = mysqli_real_escape_string($conn, $_POST['mobile']);
  $profession = mysqli_real_escape_string($conn, $_POST['profession']);
  $company = mysqli_real_escape_string($conn, $_POST['company']);
  $city = mysqli_real_escape_string($conn, $_POST['city']);


  // SQL query to insert data into the database
  $sql = "INSERT INTO form (`name`, `mobile`, `profession`, `company`, `city`, `uuid`) 
          VALUES ('$name', '$mobile', '$profession', '$company', '$city', '$decodedData')";

  if ($conn->query($sql) === TRUE) {
      header("Location: getpdf.php");
      exit(); // Stop further script execution
  } else {
      echo "Error: " . $conn->error;
  }

  ob_end_flush(); // Send output buffer content
}



// Close the connection
$conn->close();
?>

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Form</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
  <link rel="stylesheet" type="text/css" href="../style/index.css">
</head>
<body>
<div class="container-fluid bg-image vh-100 d-flex justify-content-center align-items-center">
  <div class="container">
    <div class="row justify-content-center">
      <div class="col-12 col-md-6">
        <form class="row g-3 needs-validation border p-5 rounded bg-light" novalidate method="post">
          <img src="<?php echo $data['stall_logo'] ?>" style="width: 200px;" class="m-auto img-fluid mb-3 d-block">
          
          <div class="col-md-12 d-none">
            <label for="inputName" class="form-label"></label>
            <input type="text" class="form-control" name="uuid" id="uuid" placeholder="Enter Your Name" value="<?php echo $stalluuid ?>" required>
      
          </div>

         

          <div class="col-md-12">
            <label for="inputName" class="form-label">Name</label>
            <input type="text" class="form-control" name="name" id="inputName" placeholder="Enter Your Name" required>
            <div class="valid-feedback">Looks good!</div>
          </div>

          <div class="col-md-12">
            <label for="inputMobile" class="form-label">Mobile No</label>
            <input type="text" class="form-control" name="mobile" id="inputMobile" pattern="\d{10}" placeholder="Enter Mobile Number" required>
            <div class="invalid-feedback">Please provide a valid Mobile No (10 digits).</div>
          </div>

          <div class="col-md-12">
            <label for="inputProfession" class="form-label">Profession</label>
            <input type="text" class="form-control" name="profession" id="inputProfession" placeholder="Enter Profession" required>
            <div class="invalid-feedback">Please provide a valid Profession.</div>
          </div>

          <div class="col-md-12">
            <label for="inputCompany" class="form-label">Company Name</label>
            <input type="text" class="form-control" name="company" id="inputCompany" placeholder="Enter Company Name" required>
            <div class="invalid-feedback">Please provide a valid Company Name.</div>
          </div>

          <div class="col-md-12">
            <label for="inputCity" class="form-label">City</label>
            <input type="text" class="form-control" name="city" id="inputCity" placeholder="Enter City" required>
            <div class="invalid-feedback">Please provide a valid city.</div>
          </div>

          <div class="col-12">
            <button class="btn btn-danger m-auto d-block" type="submit">Submit</button>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<script type="text/javascript">
  // Example starter JavaScript for disabling form submissions if there are invalid fields
  (() => {
    'use strict'

    // Fetch all the forms we want to apply custom Bootstrap validation styles to
    const forms = document.querySelectorAll('.needs-validation')

    // Loop over them and prevent submission
    Array.from(forms).forEach(form => {
      form.addEventListener('submit', event => {
        if (!form.checkValidity()) {
          event.preventDefault()
          event.stopPropagation()
        }

        form.classList.add('was-validated')
      }, false)
    })
  })()
</script>
</body>
</html>
