D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home3
/
encodto1
/
sg.encodersunlimited.com
/
sgadminpr
/
Filename :
create-listing.php
back
Copy
<?php include 'config.php'; if ($_SERVER["REQUEST_METHOD"] == "POST") { // Function to generate the next property ID function generatePropertyId($conn) { // Get the highest existing property ID $result = $conn->query("SELECT property_id FROM properties ORDER BY id DESC LIMIT 1"); $row = $result->fetch_assoc(); $max_id = $row['property_id'] ?? ''; // If no properties exist yet, start from sgb_00100 if (empty($max_id)) { return 'sgb_00100'; } // Extract the numeric part $numeric_part = (int) substr($max_id, 4); $next_number = $numeric_part + 1; // Format with leading zeros return 'sgb_' . str_pad($next_number, 5, '0', STR_PAD_LEFT); } // Generate the new property ID $property_id = generatePropertyId($conn); // Sanitize and collect form inputs safely $title = $_POST['title'] ?? ''; $description = $_POST['description'] ?? ''; $type = $_POST['type'] ?? ''; $status = $_POST['status'] ?? ''; $price = isset($_POST['price']) ? floatval($_POST['price']) : 0; $area = isset($_POST['area']) ? floatval($_POST['area']) : 0; $rooms = $_POST['rooms'] ?? ''; $address = $_POST['address'] ?? ''; $state = $_POST['state'] ?? ''; $city = $_POST['city'] ?? ''; $neighborhood = $_POST['neighborhood'] ?? ''; $zip = $_POST['zip'] ?? ''; $country = $_POST['country'] ?? ''; $garage = $_POST['garage'] ?? ''; $year_built = $_POST['year_built'] ?? ''; $video_url = $_POST['video_url'] ?? ''; $created_at = date('Y-m-d H:i:s'); // Insert property - now including the property_id in the INSERT $stmt = $conn->prepare("INSERT INTO properties (property_id, title, description, type, status, price, area, rooms, address, state, city, neighborhood, zip, country, garage, year_built, video_url, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->bind_param( "sssssdssssssssssss", $property_id, $title, $description, $type, $status, $price, $area, $rooms, $address, $state, $city, $neighborhood, $zip, $country, $garage, $year_built, $video_url, $created_at ); if ($stmt->execute()) { $db_id = $stmt->insert_id; // This is the auto-increment ID from the database // Now insert amenities (AFTER we get the property_id) if (!empty($_POST['amenities'])) { foreach ($_POST['amenities'] as $amenity_id) { $stmt_am = $conn->prepare("INSERT INTO property_amenities (property_id, amenity_id) VALUES (?, ?)"); $stmt_am->bind_param("ii", $db_id, $amenity_id); $stmt_am->execute(); $stmt_am->close(); } } // Handle image upload if (!empty($_FILES['images']['name'][0])) { $upload_dir = "uploads/"; if (!is_dir($upload_dir)) { mkdir($upload_dir, 0777, true); } foreach ($_FILES['images']['name'] as $key => $image_name) { if ($key >= 10) break; // Limit to 10 images $tmp_name = $_FILES['images']['tmp_name'][$key]; $image_ext = pathinfo($image_name, PATHINFO_EXTENSION); $new_name = uniqid("img_") . "." . $image_ext; $image_path = $upload_dir . $new_name; if (move_uploaded_file($tmp_name, $image_path)) { $stmt_img = $conn->prepare("INSERT INTO property_images (property_id, image_path) VALUES (?, ?)"); $stmt_img->bind_param("is", $db_id, $image_path); $stmt_img->execute(); $stmt_img->close(); } } } $success_message = "✅ Property inserted successfully with ID: " . $property_id; } else { $error_message = "❌ Error inserting property: " . $stmt->error; } } ?> <!doctype html> <html lang="en"> <head> <title>SG Property Partner</title> <?php include('../style2.php'); ?> <script> // On page load or when changing themes, best to add inline in `head` to avoid FOUC if (localStorage.getItem("theme-color") === "dark" || (!("theme-color" in localStorage) && window.matchMedia("(prefers-color-scheme: dark)").matches)) { document.documentElement.classList.add("dark"); } if (localStorage.getItem("theme-color") === "light") { document.documentElement.classList.remove("dark"); } </script> </head> <body> <!-- Preloader start --> <div id="preloader"> <div class="loader--border"></div> </div> <!-- Preloader end --> <div class="dashboard__page--wrapper"> <!-- Dashboard sidebar --> <?php include('sidebar.php'); ?> <!-- Dashboard sidebar .\ --> <div class="page__body--wrapper" id="dashbody__page--body__wrapper"> <!-- Start header area --> <header class="header__section"> <div class="main__header d-flex justify-content-between align-items-center"> <div class="header__left d-flex align-items-center"> <a class="collaps__menu" href="javascript:void(0)"><svg width="26" height="20" viewBox="0 0 26 20" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M12.5 16.5999L7.0667 11.1666C6.42503 10.5249 6.42503 9.4749 7.0667 8.83324L12.5 3.3999" stroke="currentColor" stroke-width="1.3" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round" /> <path d="M18.5 16.5999L13.0667 11.1666C12.425 10.5249 12.425 9.4749 13.0667 8.83324L18.5 3.3999" stroke="currentColor" stroke-width="1.3" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round" /> </svg> </a> <div class="search__box"> <form class="search__box--form laptop__hidden" action="#"> <input class="search__box--input__field" placeholder="Search for ...." type="text"> <span class="search__box--icon"><svg width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M4.79171 8.74992C6.97783 8.74992 8.75004 6.97771 8.75004 4.79159C8.75004 2.60546 6.97783 0.833252 4.79171 0.833252C2.60558 0.833252 0.833374 2.60546 0.833374 4.79159C0.833374 6.97771 2.60558 8.74992 4.79171 8.74992Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" /> <path d="M9.16671 9.16659L8.33337 8.33325" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" /> </svg> </span> </form> <button class="search__btn--field hidden__btn" type="submit"><svg width="14" height="14" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"> <g clip-path="url(#clip0_46_1375)"> <path d="M8.80758 0C3.95121 0 0 3.95121 0 8.80758C0 13.6642 3.95121 17.6152 8.80758 17.6152C13.6642 17.6152 17.6152 13.6642 17.6152 8.80758C17.6152 3.95121 13.6642 0 8.80758 0ZM8.80758 15.9892C4.84769 15.9892 1.62602 12.7675 1.62602 8.80762C1.62602 4.84773 4.84769 1.62602 8.80758 1.62602C12.7675 1.62602 15.9891 4.84769 15.9891 8.80758C15.9891 12.7675 12.7675 15.9892 8.80758 15.9892Z" fill="currentColor"></path> <path d="M19.762 18.6124L15.1007 13.9511C14.7831 13.6335 14.2687 13.6335 13.9511 13.9511C13.6335 14.2684 13.6335 14.7834 13.9511 15.1007L18.6124 19.762C18.7711 19.9208 18.979 20.0002 19.1872 20.0002C19.395 20.0002 19.6031 19.9208 19.762 19.762C20.0796 19.4446 20.0796 18.9297 19.762 18.6124Z" fill="currentColor"></path> </g> <defs> <clipPath id="clip0_46_1375"> <rect width="20" height="20" fill="currentColor"></rect> </clipPath> </defs> </svg> </button> </div> <div class="main__logo logo-desktop-block"> <a class="main__logo--link" href="index.php"> <img class="main__logo--img desktop light__logo" src="../assets/img/logo/Somelogo.png" alt="logo-img"> <img class="main__logo--img mobile" src="../assets/img/logo/Somelogo.png" alt="logo-img"> </a> </div> </div> <div class="header__right d-flex align-items-center"> <div class="main__menu d-none d-xl-block"> </div> </div> </div> </header> <!-- End header area --> <main class="main__content_wrapper"> <!-- dashboard container --> <div class="dashboard__container add__property--container"> <div class="add__property--heading mb-30"> <h2 class="add__property--heading__title">Add New Property</h2> <p class="add__property--desc">We are glad to see you again!</p> </div> <?php if (isset($success_message)): ?> <div class="alert alert-success mb-30"><?php echo $success_message; ?></div> <?php endif; ?> <?php if (isset($error_message)): ?> <div class="alert alert-danger mb-30"><?php echo $error_message; ?></div> <?php endif; ?> <div class="add__property__inner d-flex"> <div class=""> <div class="add__property--step__inner"> <div class="add__property--box mb-30"> <h3 class="add__property--box__title mb-20">Create Listing</h3> <form class="add__property--form" action="" method="POST" enctype="multipart/form-data"> <div class="row"> <!-- Property ID Display (readonly) --> <div class="col-12"> <div class="add__listing--input__box mb-20"> <input class="add__listing--input__field" value="<?php echo isset($property_id) ? $property_id : 'Will be generated automatically'; ?>" type="text" hidden> <small class="form-text text-muted">Property ID will be generated automatically</small> </div> </div> <!-- Title --> <div class="col-12"> <div class="add__listing--input__box mb-20"> <label class="add__listing--input__label">Title</label> <input class="add__listing--input__field" name="title" placeholder="Property Title" type="text" required> </div> </div> <!-- Description --> <div class="col-12"> <div class="add__listing--textarea__box mb-15"> <label class="add__listing--input__label">Description</label> <textarea class="add__listing--textarea__field" name="description" placeholder="Description" required></textarea> </div> </div> <!-- Type --> <div class="col-lg-6"> <div class="add__listing--input__box mb-20"> <label class="add__listing--input__label">Category</label> <select class="add__listing--form__select" name="type" required> <?php $sql = "SELECT id, category_name FROM categories ORDER BY category_name ASC"; $result = $conn->query($sql); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { echo '<option value="' . htmlspecialchars($row['id']) . '">' . htmlspecialchars($row['category_name']) . '</option>'; } } else { echo '<option value="">No categories found</option>'; } ?> </select> </div> </div> <!-- Status --> <div class="col-lg-6"> <div class="add__listing--input__box mb-20"> <label class="add__listing--input__label">Status</label> <select class="add__listing--form__select" name="status" required> <option value="Processing">Processing</option> <option value="Published">Published</option> </select> </div> </div> <!-- Price --> <div class="col-lg-4"> <div class="add__listing--input__box mb-20"> <label class="add__listing--input__label">Price</label> <input class="add__listing--input__field" name="price" placeholder="Price" type="text" required> </div> </div> <!-- Area --> <div class="col-lg-4"> <div class="add__listing--input__box mb-20"> <label class="add__listing--input__label">Area (sqft)</label> <input class="add__listing--input__field" name="area" placeholder="Area in sqft" type="text" required> </div> </div> <!-- Rooms --> <div class="col-lg-4"> <div class="add__listing--input__box mb-20"> <label class="add__listing--input__label">Rooms</label> <select class="add__listing--form__select" name="rooms" required> <option value="1RK">1RK</option> <option value="1BHK">1BHK</option> <option value="2BHK">2BHK</option> <option value="3BHK">3BHK</option> </select> </div> </div> <!-- Address --> <div class="col-12"> <div class="add__listing--input__box mb-20"> <label class="add__listing--input__label">Address</label> <input class="add__listing--input__field" name="address" placeholder="Street Address" type="text" required> </div> </div> <!-- State --> <div class="col-lg-6"> <div class="add__listing--input__box mb-20"> <label class="add__listing--input__label">State</label> <select class="add__listing--form__select" name="state" required> <option value="West Bengal">West Bengal</option> <option value="Assam">Assam</option> <option value="Bihar">Bihar</option> <option value="Jharkhand">Jharkhand</option> <option value="Odisha">Odisha</option> <option value="Sikkim">Sikkim</option> <option value="Other">Other</option> </select> </div> </div> <!-- City --> <div class="col-lg-6"> <div class="add__listing--input__box mb-20"> <label class="add__listing--input__label">City</label> <select class="add__listing--form__select" name="city" required> <option value="Siliguri">Siliguri</option> <option value="Mainaguri">Mainaguri</option> <option value="Jalpaiguri">Jalpaiguri</option> <option value="Batabari">Batabari</option> <option value="Chalsha">Chalsha</option> <option value="Malbazar">Malbazar</option> </select> </div> </div> <!-- Neighborhood --> <div class="col-lg-6"> <div class="add__listing--input__box mb-20"> <label class="add__listing--input__label">Neighborhood</label> <input class="add__listing--input__field" name="neighborhood" placeholder="Neighborhood" type="text"> </div> </div> <!-- Zip --> <div class="col-lg-6"> <div class="add__listing--input__box mb-20"> <label class="add__listing--input__label">Zip</label> <input class="add__listing--input__field" name="zip" placeholder="Zip Code" type="text"> </div> </div> <!-- Country --> <div class="col-lg-6"> <div class="add__listing--input__box mb-20"> <label class="add__listing--input__label">Country</label> <input class="add__listing--input__field" name="country" value="India" type="text" readonly> </div> </div> <!-- Year Built --> <div class="col-lg-6"> <div class="add__listing--input__box mb-20"> <label class="add__listing--input__label">Year Built</label> <input class="add__listing--input__field" name="year_built" placeholder="e.g., 2020" type="text"> </div> </div> <!-- Garage --> <div class="col-lg-6"> <div class="add__listing--input__box mb-20"> <label class="add__listing--input__label">Garage</label> <select class="add__listing--form__select" name="garage"> <option value="Yes">Yes</option> <option value="No">No</option> </select> </div> </div> <!-- Video URL --> <div class="col-lg-6"> <div class="add__listing--input__box mb-20"> <label class="add__listing--input__label">Video URL</label> <input class="add__listing--input__field" name="video_url" placeholder="YouTube or video link" type="url"> </div> </div> <!-- Amenities Section --> <div class="col-12"> <h3 class="mb-4">Amenities</h3> <div class="advance__apeartment--inner d-flex justify-content-between"> <?php $result = $conn->query("SELECT * FROM amenities"); $count = 0; $columns = [[], [], [], []]; // for 4 columns layout while ($row = $result->fetch_assoc()) { $columns[$count % 4][] = $row; $count++; } foreach ($columns as $index => $column) { echo '<ul class="interior__amenities--check">'; foreach ($column as $i => $amenity) { $id = "check" . ($index * 4 + $i + 1); echo ' <li class="interior__amenities--check__list"> <label class="interior__amenities--check__label" for="' . $id . '">' . htmlspecialchars($amenity['name']) . '</label> <input class="interior__amenities--check__input" id="' . $id . '" type="checkbox" name="amenities[]" value="' . $amenity['id'] . '"> <span class="interior__amenities--checkmark"></span> </li>'; } echo '</ul>'; } ?> </div> </div> <!-- Images --> <div class="col-12"> <div class="add__listing--input__box mb-20"> <label class="add__listing--input__label">Upload Images (max 10)</label> <input class="add__listing--input__field" name="images[]" type="file" multiple accept="image/*" required> </div> </div> <!-- Submit --> <div class="col-12"> <button class="solid__btn add__property--btn" type="submit">Save</button> </div> </div> </form> </div> </div> </div> </div> </div> </main> </div> </div> <!-- Scroll top bar --> <?php include 'footer.php' ?> </body> </html>