<?php 
ob_start();

include("configa.php");


session_start();

if(!isset($_SESSION['username'])){header('location:index.php');}

 $username = $_SESSION['username'];
 $id_no =   $_SESSION['id_no'];




// $first_name = '';
// $last_name  = '';
// $division   = '';
// $district   = '';
// $upazila    = '';
// $up         = '';
// $shopName   = '';
// $address    = '';



$sql = "SELECT * FROM seller WHERE username = $username";
$result = mysqli_query($conn, $sql);

if ($result) {
    if (mysqli_num_rows($result) === 1) {
        $row = mysqli_fetch_object($result);
        $first_name = $row->first_name;
        $last_name = $row->last_name;
        $division = $row->division;
        $district = $row->district;
        $upazila = $row->upazila;
        $up = $row->up;
        $shopName = $row->shopName;
        $address = $row->address;

    } else {
        // কোন row পাওয়া যায়নি
        echo "User not found.";
        $first_name = '';
    }
} else {
    // Query ত্রুটি
    echo "Query Error: " . mysqli_error($conn);
    $first_name = '';
}
?>


<style>



.product_and_information {
    max-width: 600px;
    margin: 20px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    padding: 30px 40px;
    box-sizing: border-box;
  }

  .info h1 {
    font-size: 20px;
    margin-bottom: 15px;
    color: #111827;
    border-bottom: 2px solid #e5e7eb;
    padding-bottom: 8px;
  }

  label {
    display: block;
    margin: 10px 0 5px;
    font-weight: 600;
    color: #374151;
  }

  input[type="text"], select {
    width: 100%;
    padding: 10px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border 0.2s ease;
  }

  input[type="text"]:focus, select:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.2);
  }

  .location-select {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 10px;
  }

  .buttonsInfo {
    text-align: center;
    margin-top: 20px;
  }

  .order_button {
    display: inline-block;
    background: #2563eb;
    color: #fff;
    font-size: 16px;
    font-weight: bold;
    padding: 12px 25px;
    border-radius: 50px;
    cursor: pointer;
    transition: background 0.3s ease, transform 0.2s;
  }

  .order_button:hover {
    background: #1e40af;
    transform: translateY(-2px);
  }

  .displayBox{
    display: none;
    width: 60%;
    height: 100%;
  }



  .displayBox {
    width: 100%;
    height: 5in;
    margin: 20px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    padding: 30px 40px;
    box-sizing: border-box;
    font-size: 15pt;
  }



    .displayBox > p {
    line-height: 15pt;
  }

  .sucessNotice{
    font-size: 15pt;
    color: green;
    line-height: 15pt;
  }

</style>
 



<div style="display: block;" class="product_and_information">

  <div class="info">
    <h1>ব্যক্তিগত তথ্য :</h1>

    <label>ID No</label>
    <input type="text" class="id_no" name="id_no" readonly="" value="<?php echo isset($_SESSION['id_no']) ? $_SESSION['id_no'] : '' ?>">

    <label>নামের অংশ :</label>
    <input type="text" class="first_name" name="first_name" value="<?php echo isset($first_name) ? htmlspecialchars($first_name, ENT_QUOTES) : '' ?>">  

    <label>নামের শেষ অংশ :</label>
    <input type="text" class="last_name" name="last_name" value="<?php echo isset($last_name) ? htmlspecialchars($last_name, ENT_QUOTES) : '' ?>">

    <label>মোবাইল :</label>
    <input type="text" class="mobile" name="mobile" readonly="" value="<?php echo isset($_SESSION['username']) ? $_SESSION['username'] : '' ?>" >

    <div class="location-select">
      <div>
        <label for="division">বিভাগ</label>
        <select id="division" class="division" name="division">
          <option value="<?php echo isset($division) ? htmlspecialchars($division, ENT_QUOTES) : '' ?>">
            <?php echo isset($division) ? htmlspecialchars($division, ENT_QUOTES) : '' ?>
          </option>
          <option value="">--নির্বাচন করুন--</option>
        </select>
      </div>
      <div>
        <label for="district">জেলা</label>
        <select id="district" class="district" name="district">
          <option value="<?php echo isset($district) ? htmlspecialchars($district, ENT_QUOTES) : '' ?>">
            <?php echo isset($district) ? htmlspecialchars($district, ENT_QUOTES) : '' ?>
          </option>
          <option value="">--নির্বাচন করুন--</option>
        </select>
      </div>
      <div>
        <label for="upazila">উপজেলা</label>
        <select id="upazila" class="upazila" name="upazila">
          <option value="<?php echo isset($upazila) ? htmlspecialchars($upazila, ENT_QUOTES) : '' ?>"><?php echo isset($upazila) ? htmlspecialchars($upazila, ENT_QUOTES) : '' ?></option>
          <option value="">--নির্বাচন করুন--</option>
        </select>
      </div>
      <div>
        <label for="union">ইউনিয়ন/পৌরসভা</label>
        <select id="union" class="union" name="union">
          <option value="<?php echo isset($up) ? htmlspecialchars($up, ENT_QUOTES) : '' ?>">
            <?php echo isset($up) ? htmlspecialchars($up, ENT_QUOTES) : '' ?>
          </option>
          <option value="">--নির্বাচন করুন--</option>
        </select>
      </div>
    </div>

    <label>দোকানের নাম :</label>
    <input type="text" class="shopName" name="shopName" required value="<?php echo isset($shopName) ? htmlspecialchars($shopName, ENT_QUOTES) : '' ?>">

    <label>ঠিকানা :</label>
    <input type="text" class="address" name="address" required value="<?php echo isset($address) ? htmlspecialchars($address, ENT_QUOTES) : '' ?>">
  </div>

  <div class="buttonsInfo">
    <span class="order_button"><span class="order_button_text" name="submitButton">অর্ডার করুন</span></span>
  </div>

</div>



<div class="displayBox">

 <span class="sucessNotice"> নিবন্ধন সফল হয়েছে;</span><br><br>

  <p> আপনার আইডি নং: <span class="show_id_no"></span><br>
  নামের প্রথম অংশ: <span class="show_first_name"></span><br>
  নামের শেষের অংশ: <span class="show_last_name"></span><br>
  মোবাইল নং: <span class="show_mobile"></span><br>

  দোকানের নাম : <span class="show_shopName"></span><br>
  ঠিকানা : <span class="show_address"></span><br>
  ইউনিয়ন: <span class="show_union"></span><br>

  উপজেলা : <span class="show_upazila"></span><br>
  জেলা : <span class="show_district"></span><br>
  বিভাগ : <span class="show_division"></span><br>
  </p>


</div>





<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
  document.querySelector(".order_button").addEventListener("click", function() {

    const formData = new FormData();

    formData.append("first_name", document.querySelector(".first_name").value);
    formData.append("last_name", document.querySelector(".last_name").value);
    formData.append("mobile", document.querySelector(".mobile").value);
    formData.append("division", document.querySelector(".division").value);
    formData.append("district", document.querySelector(".district").value);
    formData.append("upazila", document.querySelector(".upazila").value);
    formData.append("union", document.querySelector(".union").value);
    formData.append("shopName", document.querySelector(".shopName").value);
    formData.append("address", document.querySelector(".address").value);
    formData.append("id_no", document.querySelector(".id_no").value);

    fetch('seller_insert.php', {
        method: 'POST',
        body: formData
    })
    .then(response => response.json())
    .then(data => {
        console.log('Server Response:', data);
        if (data.status === 'success') {
            document.querySelector(".product_and_information").style.display = 'none';
            document.querySelector(".displayBox").style.display = 'block';

            const first_name = document.querySelector(".first_name").value;
            document.querySelector(".show_first_name").textContent = first_name;

            const last_name = document.querySelector(".last_name").value;
            document.querySelector(".show_last_name").textContent = last_name;

            const mobile = document.querySelector(".mobile").value;
            document.querySelector(".show_mobile").textContent = mobile;

            const division = document.querySelector(".division").value;
            document.querySelector(".show_division").textContent = division;

            const district = document.querySelector(".district").value;
            document.querySelector(".show_district").textContent = district;

            const upazila = document.querySelector(".upazila").value;
            document.querySelector(".show_upazila").textContent = upazila;

            const union = document.querySelector(".union").value;
            document.querySelector(".show_union").textContent = union;

            const shopName = document.querySelector(".shopName").value;
            document.querySelector(".show_shopName").textContent = shopName;

            const address = document.querySelector(".address").value;
            document.querySelector(".show_address").textContent = address;

            const idNoValue = document.querySelector(".id_no").value;
            document.querySelector(".show_id_no").textContent = idNoValue;



        } else {
            alert(data.message);
        }
    })
    .catch(error => {
        console.error('Fetch Error:', error);
        alert('সার্ভারে সমস্যা হয়েছে।');
    });
  });
});
</script>



<script>
let data; // পুরো JSON ডেটা এখানে রাখা হবে

const divisionSelect = document.getElementById('division');
const districtSelect = document.getElementById('district');
const upazilaSelect = document.getElementById('upazila');
const unionSelect = document.getElementById('union');

// ✅ JSON ফাইল থেকে fetch করে data লোড করা
fetch('bd-dd-ui-bn.JSON')
  .then(response => response.json())
  .then(jsonData => {
    data = jsonData;
    const divisions = data["বিভাগ"];
    divisions.forEach(div => {
      const option = document.createElement('option');
      option.value = div.নাম;
      option.textContent = div.নাম;
      divisionSelect.appendChild(option);
    });
  })
  .catch(error => {
    console.error('ডেটা লোড করতে সমস্যা:', error);
  });

// Division সিলেকশন
divisionSelect.addEventListener('change', function () {
  districtSelect.innerHTML = '<option value="">-- নির্বাচন করুন --</option>';
  upazilaSelect.innerHTML = '<option value="">-- নির্বাচন করুন --</option>';
  unionSelect.innerHTML = '<option value="">-- নির্বাচন করুন --</option>';
  districtSelect.disabled = true;
  upazilaSelect.disabled = true;
  unionSelect.disabled = true;

  const selectedDivision = data["বিভাগ"].find(div => div.নাম === this.value);
  if (selectedDivision) {
    selectedDivision.জেলা.forEach(dist => {
      const option = document.createElement('option');
      option.value = dist.নাম;
      option.textContent = dist.নাম;
      districtSelect.appendChild(option);
    });
    districtSelect.disabled = false;
  }
});

// District সিলেকশন
districtSelect.addEventListener('change', function () {
  upazilaSelect.innerHTML = '<option value="">-- নির্বাচন করুন --</option>';
  unionSelect.innerHTML = '<option value="">-- নির্বাচন করুন --</option>';
  upazilaSelect.disabled = true;
  unionSelect.disabled = true;

  const selectedDivision = data["বিভাগ"].find(div => div.নাম === divisionSelect.value);
  const selectedDistrict = selectedDivision?.জেলা.find(dist => dist.নাম === this.value);

  if (selectedDistrict) {
    selectedDistrict.উপজেলা.forEach(upz => {
      const option = document.createElement('option');
      option.value = upz.নাম;
      option.textContent = upz.নাম;
      upazilaSelect.appendChild(option);
    });
    upazilaSelect.disabled = false;
  }
});

// Upazila সিলেকশন
upazilaSelect.addEventListener('change', function () {
  unionSelect.innerHTML = '<option value="">-- নির্বাচন করুন --</option>';
  unionSelect.disabled = true;

  const selectedDivision = data["বিভাগ"].find(div => div.নাম === divisionSelect.value);
  const selectedDistrict = selectedDivision?.জেলা.find(dist => dist.নাম === districtSelect.value);
  const selectedUpazila = selectedDistrict?.উপজেলা.find(upz => upz.নাম === this.value);

  if (selectedUpazila) {
    selectedUpazila.ইউনিয়ন.forEach(union => {
      const option = document.createElement('option');
      option.value = union;
      option.textContent = union;
      unionSelect.appendChild(option);
    });
    unionSelect.disabled = false;
  }
});
</script>




<script>
document.addEventListener("DOMContentLoaded", function () {
    const divisionSelect = document.querySelector(".division");
    const districtSelect = document.querySelector(".district");

    // JSON ফাইল লোড
    fetch("bd-dd-ui-bn.JSON")
        .then(response => response.json())
        .then(data => {
            const selectedDivision = divisionSelect.value.trim();

            if (selectedDivision && data[selectedDivision]) {
                // জেলা dropdown পরিষ্কার করে নতুন option যোগ করবো
                districtSelect.innerHTML = "";

                // প্রথম default option
                const defaultOption = document.createElement("option");
                defaultOption.value = "";
                defaultOption.textContent = "-- নির্বাচন করুন * Select your option --";
                districtSelect.appendChild(defaultOption);

                // JSON থেকে জেলা list নিয়ে append করা
                data[selectedDivision].districts.forEach(district => {
                    const option = document.createElement("option");
                    option.value = district.name;
                    option.textContent = district.name;
                    
                    // যদি আগের district value match করে তাহলে selected
                    if (district.name === "<?php echo $district; ?>") {
                        option.selected = true;
                    }
                    
                    districtSelect.appendChild(option);
                });
            }
        })
        .catch(err => {
            console.error("JSON লোড করতে সমস্যা:", err);
        });
});
</script>



<!-- 
<script>
document.addEventListener("DOMContentLoaded", function () {
    const mobileInput = document.querySelector(".mobile");
    const idNoInput = document.querySelector(".id_no");

    // ৬ ডিজিটের র‌্যান্ডম নাম্বার তৈরি ফাংশন
    function generateRandom6() {
        return Math.floor(100000 + Math.random() * 900000); 
    }

    // mobile ইনপুটে টাইপ করলে id_no অটো-ফিল হবে
    mobileInput.addEventListener("input", function () {
        const mobile = mobileInput.value.trim();
        if (mobile.length >= 4) {
            const last4 = mobile.slice(-4); // শেষের ৪ সংখ্যা
            const random6 = generateRandom6();
            idNoInput.value = random6 + last4;
        } else {
            idNoInput.value = ""; // যদি মোবাইল ৪ সংখ্যার কম হয়
        }
    });
});
</script>
 -->

<?php
// End capturing the output and store it in a variable
$seller_display_content = ob_get_clean();

// Now include frameForAll.php, which will use $catagory_display_content
include("frameForAll.php");

// mysqli_close($conn); // You might want to close the connection after all database operations
ob_end_flush();
?>



<!DOCTYPE html>
<html>
<head>

  <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

<meta name="theme-color" content="#FF0000">
    
<title>অনলাইন শপ</title>
    

  
</head>
<body>


<style type="text/css">




</style>

<!----------------------------->
<script>
  flatpickr("#start_date", {
    dateFormat: "d/m/Y", // DD/MM/YYYY format
    position: "below"     // Force show calendar below
  });

  flatpickr("#end_date", {
    dateFormat: "d/m/Y",
    position: "below"
  });
</script>

<!-- ------------------------- -->
  

</body>
</html>