[ Root System Explorer ]
Location:
Root
/
home
/
u456045770
/
domains
/
momoeshop.com
/
public_html
/
ads
+ Folder
+ File
Upload
Editing: property.php
<?php error_reporting(E_ALL); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); // Ensure user is logged in if(!isset($_SESSION['userdata']['id'])){ header("Location: ./?p=login"); exit; } $user_id = $_SESSION['userdata']['id']; // If editing, fetch existing property only if created by current user $property = []; if(isset($_GET['id'])){ $id = intval($_GET['id']); $qry = $conn->query("SELECT * FROM properties WHERE id = '$id' AND created_by = '$user_id'"); if($qry && $qry->num_rows > 0){ $property = $qry->fetch_assoc(); } else { // Not found or not owner – redirect with error $_SESSION['error'] = "Property not found or you don't have permission to edit it."; header("Location: ./?p=properties"); exit; } } // Fetch sectors grouped by city $sectors = []; $q = $conn->query("SELECT id, sector, city FROM `sectors` WHERE status = 1 ORDER BY city, sector"); while($r = $q->fetch_assoc()){ $city_name = $r['city']; if(!isset($sectors[$city_name])) $sectors[$city_name] = []; $sectors[$city_name][] = $r; } // Default listing type $default_listing_type = $property['listing_type'] ?? 'For Rent'; // Parse selected amenities $selected_amenities = []; if(!empty($property['amenities'])){ $selected_amenities = explode(',', $property['amenities']); } // Helper function function e($str){ return htmlspecialchars($str ?? '', ENT_QUOTES, 'UTF-8'); } ?> <section class="py-5"> <div class="container"> <div class="card rounded-0"> <div class="card-body"> <div class="w-100 justify-content-between d-flex"> <h4><b><?php echo isset($property['id']) ? 'Edit' : 'Add New'; ?> Property</b></h4> <a href="./?p=properties" class="btn btn-dark btn-flat"><i class="fa fa-angle-left"></i> Back to Listings</a> </div> <hr class="border-warning"> <form action="" id="property_form" enctype="multipart/form-data"> <input type="hidden" name="id" value="<?php echo e($property['id'] ?? '') ?>"> <input type="hidden" name="listing_type" id="listing_type_hidden" value="<?php echo e($default_listing_type) ?>"> <!-- Listing Type Toggle --> <div class="form-group mb-4"> <label class="control-label d-block">Listing Type</label> <div class="btn-group btn-group-toggle" data-toggle="buttons"> <label class="btn btn-outline-primary <?php echo ($default_listing_type == 'For Rent') ? 'active' : '' ?>"> <input type="radio" name="listing_type_toggle" value="For Rent" autocomplete="off" <?php echo ($default_listing_type == 'For Rent') ? 'checked' : '' ?>> For Rent </label> <label class="btn btn-outline-success <?php echo ($default_listing_type == 'For Sale') ? 'active' : '' ?>"> <input type="radio" name="listing_type_toggle" value="For Sale" autocomplete="off" <?php echo ($default_listing_type == 'For Sale') ? 'checked' : '' ?>> For Sale </label> </div> </div> <!-- Basic Info Row --> <div class="row"> <div class="col-md-8"> <div class="form-group"> <label for="property_title" class="control-label">Property Title *</label> <input type="text" name="property_title" id="property_title" class="form-control" required value="<?php echo e($property['property_title'] ?? '') ?>"> </div> </div> <div class="col-md-4"> <div class="form-group"> <label for="category" class="control-label">Category *</label> <select name="category" id="category" class="custom-select" required> <option value="">-- Select Category --</option> <?php $cats = ["Apartment","Independent House","Builder Floor","Villa", "Shop","Office Space","PG / Hostel","Land","Commercial Building"]; foreach($cats as $c): ?> <option value="<?php echo e($c) ?>" <?php echo (isset($property['category']) && $property['category'] == $c) ? "selected" : "" ?>><?php echo e($c) ?></option> <?php endforeach; ?> </select> </div> </div> </div> <!-- Property Type (depends on category) --> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label for="property_type" class="control-label">Property Type *</label> <select name="property_type" id="property_type" class="custom-select" required> <option value="">-- Select Type --</option> <?php if(isset($property['property_type'])): ?> <option value="<?php echo e($property['property_type']) ?>" selected><?php echo e($property['property_type']) ?></option> <?php endif; ?> </select> </div> </div> <div class="col-md-4"> <div class="form-group"> <label for="city" class="control-label">City *</label> <select name="city" id="city" class="custom-select" required> <option value="">-- Select City --</option> <option value="Noida" <?php echo (isset($property['city']) && $property['city']=="Noida")?"selected":"" ?>>Noida</option> <option value="Greater Noida" <?php echo (isset($property['city']) && $property['city']=="Greater Noida")?"selected":"" ?>>Greater Noida</option> <option value="Ghaziabad" <?php echo (isset($property['city']) && $property['city']=="Ghaziabad")?"selected":"" ?>>Ghaziabad</option> </select> </div> </div> <div class="col-md-4"> <div class="form-group"> <label for="sector_id" class="control-label">Sector *</label> <select name="sector_id" id="sector_id" class="custom-select" required> <option value="">-- Select City First --</option> </select> </div> </div> </div> <!-- Price Section (dynamic) --> <div class="card mb-3 border"> <div class="card-header bg-light"> <span id="priceSectionTitle"><?php echo ($default_listing_type == 'For Rent') ? 'Rental Details' : 'Sale Details' ?></span> </div> <div class="card-body"> <!-- Rent fields --> <div id="rentFields" class="<?php echo ($default_listing_type == 'For Rent') ? '' : 'd-none' ?>"> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label>Monthly Rent (₹) *</label> <input type="number" step="0.01" name="rent_amount" class="form-control rent-field" value="<?php echo e($property['rent_amount'] ?? '') ?>"> </div> </div> <div class="col-md-4"> <div class="form-group"> <label>Security Deposit (₹)</label> <input type="number" step="0.01" name="security_deposit" class="form-control rent-field" value="<?php echo e($property['security_deposit'] ?? '') ?>"> </div> </div> <div class="col-md-4"> <div class="form-group"> <label>Maintenance (₹/month)</label> <input type="number" step="0.01" name="maintenance_charge" class="form-control rent-field" value="<?php echo e($property['maintenance_charge'] ?? '') ?>"> </div> </div> </div> </div> <!-- Sale fields --> <div id="saleFields" class="<?php echo ($default_listing_type == 'For Sale') ? '' : 'd-none' ?>"> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label>Sale Price (₹) *</label> <input type="number" step="0.01" name="sale_price" class="form-control sale-field" value="<?php echo e($property['sale_price'] ?? '') ?>"> </div> </div> <div class="col-md-4"> <div class="form-group"> <label>Down Payment %</label> <input type="number" step="0.1" min="0" max="100" name="down_payment_percent" class="form-control sale-field" value="<?php echo e($property['down_payment_percent'] ?? '20') ?>"> </div> </div> <div class="col-md-4"> <div class="form-group"> <label>Price per sqft (₹)</label> <input type="number" step="0.01" name="price_per_sqft" class="form-control sale-field" value="<?php echo e($property['price_per_sqft'] ?? '') ?>" readonly> </div> </div> </div> <div class="form-check mt-2"> <input type="checkbox" name="mortgage_available" id="mortgage_available" value="1" class="form-check-input sale-field" <?php echo (isset($property['mortgage_available']) && $property['mortgage_available']==1)?'checked':'' ?>> <label class="form-check-label" for="mortgage_available">Mortgage Available</label> </div> </div> </div> </div> <!-- Property Specifications --> <div class="card mb-3 border"> <div class="card-header bg-light">Property Specifications</div> <div class="card-body"> <div class="row"> <div class="col-md-3"> <div class="form-group"> <label>Total Area (sqft) *</label> <input type="number" step="0.01" name="area_sqft" class="form-control" required value="<?php echo e($property['area_sqft'] ?? '') ?>"> </div> </div> <div class="col-md-3"> <div class="form-group"> <label>Built-up Area (sqft)</label> <input type="number" step="0.01" name="built_up_area_sqft" class="form-control" value="<?php echo e($property['built_up_area_sqft'] ?? '') ?>"> </div> </div> <div class="col-md-3"> <div class="form-group"> <label>Plot Area (sqft)</label> <input type="number" step="0.01" name="plot_area_sqft" class="form-control" value="<?php echo e($property['plot_area_sqft'] ?? '') ?>"> </div> </div> <div class="col-md-3"> <div class="form-group"> <label>Condition</label> <select name="property_condition" class="custom-select"> <option value="">Select</option> <?php $conds = ["New","Like New","Good","Needs Renovation"]; foreach($conds as $c): ?> <option value="<?php echo $c ?>" <?php echo (isset($property['property_condition']) && $property['property_condition']==$c)?"selected":"" ?>><?php echo $c ?></option> <?php endforeach; ?> </select> </div> </div> </div> <div class="row"> <div class="col-md-3"> <div class="form-group"> <label>Bedrooms *</label> <select name="bedrooms" class="custom-select" required> <option value="">Select</option> <?php for($i=1;$i<=10;$i++): ?> <option value="<?php echo $i ?>" <?php echo (isset($property['bedrooms']) && $property['bedrooms']==$i)?"selected":"" ?>><?php echo $i ?> <?php echo $i==1?'Bedroom':'Bedrooms' ?></option> <?php endfor; ?> </select> </div> </div> <div class="col-md-3"> <div class="form-group"> <label>Bathrooms *</label> <select name="bathrooms" class="custom-select" required> <option value="">Select</option> <?php for($i=1;$i<=10;$i++): ?> <option value="<?php echo $i ?>" <?php echo (isset($property['bathrooms']) && $property['bathrooms']==$i)?"selected":"" ?>><?php echo $i ?> <?php echo $i==1?'Bathroom':'Bathrooms' ?></option> <?php endfor; ?> </select> </div> </div> <div class="col-md-3"> <div class="form-group"> <label>Balconies</label> <select name="balconies" class="custom-select"> <option value="">Select</option> <option value="0" <?php echo (isset($property['balconies']) && $property['balconies']==0)?"selected":"" ?>>No Balcony</option> <?php for($i=1;$i<=5;$i++): ?> <option value="<?php echo $i ?>" <?php echo (isset($property['balconies']) && $property['balconies']==$i)?"selected":"" ?>><?php echo $i ?> <?php echo $i==1?'Balcony':'Balconies' ?></option> <?php endfor; ?> </select> </div> </div> <div class="col-md-3"> <div class="form-group"> <label>Furnishing *</label> <select name="furnishing_status" class="custom-select" required> <option value="">Select</option> <option value="Unfurnished" <?php echo (isset($property['furnishing_status']) && $property['furnishing_status']=='Unfurnished')?"selected":"" ?>>Unfurnished</option> <option value="Semi-Furnished" <?php echo (isset($property['furnishing_status']) && $property['furnishing_status']=='Semi-Furnished')?"selected":"" ?>>Semi-Furnished</option> <option value="Fully-Furnished" <?php echo (isset($property['furnishing_status']) && $property['furnishing_status']=='Fully-Furnished')?"selected":"" ?>>Fully-Furnished</option> </select> </div> </div> </div> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label>Floor *</label> <select name="floor" class="custom-select" required> <option value="">Select</option> <option value="Ground" <?php echo (isset($property['floor']) && $property['floor']=='Ground')?"selected":"" ?>>Ground Floor</option> <option value="Basement" <?php echo (isset($property['floor']) && $property['floor']=='Basement')?"selected":"" ?>>Basement</option> <?php for($i=1;$i<=50;$i++): ?> <option value="<?php echo $i ?>" <?php echo (isset($property['floor']) && $property['floor']==$i)?"selected":"" ?>><?php echo $i ?>th Floor</option> <?php endfor; ?> </select> </div> </div> <div class="col-md-4"> <div class="form-group"> <label>Total Floors *</label> <input type="number" name="total_floors" class="form-control" required min="1" value="<?php echo e($property['total_floors'] ?? '') ?>"> </div> </div> <div class="col-md-4"> <div class="form-group"> <label>Age of Property (years)</label> <input type="number" name="age_of_property" class="form-control" min="0" value="<?php echo e($property['age_of_property'] ?? '') ?>"> </div> </div> </div> </div> </div> <!-- Address & Description --> <div class="card mb-3 border"> <div class="card-header bg-light">Location & Description</div> <div class="card-body"> <div class="form-group"> <label>Landmark</label> <input type="text" name="landmark" class="form-control" value="<?php echo e($property['landmark'] ?? '') ?>"> </div> <div class="form-group"> <label>Full Address *</label> <textarea name="address" class="form-control" rows="2" required><?php echo e($property['address'] ?? '') ?></textarea> </div> <div class="form-group"> <label>Description *</label> <textarea name="description" class="form-control" rows="4" required><?php echo e($property['description'] ?? '') ?></textarea> </div> <div class="form-group"> <label>Available From *</label> <input type="date" name="available_from" class="form-control" required value="<?php echo e($property['available_from'] ?? date('Y-m-d')) ?>"> </div> </div> </div> <!-- Amenities --> <div class="card mb-3 border"> <div class="card-header bg-light">Amenities</div> <div class="card-body"> <div class="row"> <?php $amenities_list = [ "Parking","Power Backup","Lift/Elevator","24/7 Security", "Swimming Pool","Gym","Club House","Garden", "Children's Play Area","Water Supply","Park","Air Conditioning", "Heating","WiFi","Pet Friendly","Laundry","Balcony/Terrace" ]; $counter = 0; foreach($amenities_list as $amenity): if($counter % 4 == 0) echo '<div class="col-md-3">'; ?> <div class="form-check mb-2"> <input class="form-check-input" type="checkbox" name="amenities[]" value="<?php echo e($amenity) ?>" id="amenity_<?php echo $counter ?>" <?php echo in_array($amenity, $selected_amenities)?'checked':'' ?>> <label class="form-check-label" for="amenity_<?php echo $counter ?>"><?php echo e($amenity) ?></label> </div> <?php $counter++; if($counter % 4 == 0 || $counter == count($amenities_list)) echo '</div>'; endforeach; ?> </div> <div class="form-group mt-3"> <label>Custom Amenities (comma separated)</label> <textarea name="custom_amenities" class="form-control" rows="2"><?php echo e($property['custom_amenities'] ?? '') ?></textarea> </div> </div> </div> <!-- Owner Details --> <div class="card mb-3 border"> <div class="card-header bg-light">Contact Information</div> <div class="card-body"> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label>Your Name *</label> <input type="text" name="owner_name" class="form-control" required value="<?php echo e($property['owner_name'] ?? ($_SESSION['userdata']['name'] ?? '')) ?>"> </div> </div> <div class="col-md-4"> <div class="form-group"> <label>Phone *</label> <input type="text" name="owner_phone" class="form-control" required pattern="[0-9]{10}" value="<?php echo e($property['owner_phone'] ?? ($_SESSION['userdata']['mobile'] ?? '')) ?>"> </div> </div> <div class="col-md-4"> <div class="form-group"> <label>Email</label> <input type="email" name="owner_email" class="form-control" value="<?php echo e($property['owner_email'] ?? ($_SESSION['userdata']['email'] ?? '')) ?>"> </div> </div> </div> </div> </div> <!-- Image Upload --> <div class="card mb-3 border"> <div class="card-header bg-light">Property Images</div> <div class="card-body"> <div class="form-group"> <div class="custom-file"> <input type="file" class="custom-file-input" id="propertyImages" name="img[]" multiple accept="image/*"> <label class="custom-file-label" for="propertyImages">Choose images (first will be main)</label> </div> <small class="text-muted">You can upload multiple images. Max 5MB each, JPG/PNG.</small> </div> <div id="imagePreview" class="mt-3"></div> <?php if(isset($property['id'])): $upload_path = "uploads/property_".$property['id']; $full_path = '../'.$upload_path; if(is_dir($full_path)): $files = array_values(array_diff(scandir($full_path), ['.','..'])); if(count($files)>0): ?> <div class="mt-3"> <label>Existing Images</label> <div class="d-flex flex-wrap"> <?php foreach($files as $img): $img_url = base_url.$upload_path.'/'.$img; $is_primary = isset($property['primary_image']) && basename($property['primary_image'])==$img; ?> <div class="border rounded m-2 p-2" style="width:150px;"> <img src="<?php echo $img_url ?>" style="width:100%;height:100px;object-fit:cover;"> <?php if($is_primary): ?><span class="badge badge-success">Primary</span><?php endif; ?> <button type="button" class="btn btn-sm btn-outline-danger delete-image-btn mt-2" data-path="<?php echo $full_path.'/'.$img ?>"><i class="fa fa-trash"></i></button> </div> <?php endforeach; ?> </div> </div> <?php endif; endif; endif; ?> </div> </div> <!-- Settings (simplified for user) --> <div class="card mb-3 border"> <div class="card-header bg-light">Listing Settings</div> <div class="card-body"> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label>Featured?</label> <select name="is_featured" class="custom-select"> <option value="0" <?php echo (isset($property['is_featured']) && $property['is_featured']==0)?"selected":"" ?>>No</option> <option value="1" <?php echo (isset($property['is_featured']) && $property['is_featured']==1)?"selected":"" ?>>Yes</option> </select> </div> </div> <div class="col-md-4"> <div class="form-group"> <label>Status</label> <select name="status" class="custom-select"> <option value="1" <?php echo (!isset($property['status']) || $property['status']==1)?"selected":"" ?>>Active</option> <option value="0" <?php echo (isset($property['status']) && $property['status']==0)?"selected":"" ?>>Inactive</option> </select> </div> </div> </div> </div> </div> <div class="form-group d-flex justify-content-end"> <button class="btn btn-dark btn-flat">Save Property</button> </div> </form> </div> </div> </div> </section> <script> // Pass data to JavaScript var sectors = <?php echo json_encode($sectors); ?>; var propertyTypes = { "Apartment": ["1 BHK","2 BHK","3 BHK","4 BHK","Studio","1 RK","Penthouse"], "Independent House": ["1 BHK","2 BHK","3 BHK","4 BHK","Bungalow"], "Builder Floor": ["1 BHK","2 BHK","3 BHK","4 BHK"], "Villa": ["Duplex","Triplex","4 BHK","Bungalow","Farm House"], "Shop": ["Retail Shop","Showroom","Boutique","Kiosk"], "Office Space": ["Furnished Office","Unfurnished Office","Co-working","IT Park"], "PG / Hostel": ["Private Room","Double Sharing","Triple Sharing","Dormitory"], "Land": ["Residential Plot","Commercial Plot","Agricultural Land","Industrial Land"], "Commercial Building": ["Shopping Complex","Mall","Warehouse","Showroom"] }; $(function(){ // Initialize Select2 if available if($.fn.select2) $('.select2').select2({ width: '100%' }); // Listing type toggle function toggleListingType(type){ $('#listing_type_hidden').val(type); if(type === 'For Rent'){ $('#rentFields').removeClass('d-none'); $('#saleFields').addClass('d-none'); $('#priceSectionTitle').text('Rental Details'); $('.rent-field').prop('required', true); $('.sale-field').prop('required', false); } else { $('#saleFields').removeClass('d-none'); $('#rentFields').addClass('d-none'); $('#priceSectionTitle').text('Sale Details'); $('.rent-field').prop('required', false); $('.sale-field').prop('required', true); } } $('input[name="listing_type_toggle"]').on('change', function(){ toggleListingType($(this).val()); }); toggleListingType('<?php echo $default_listing_type ?>'); // Category -> Property type function loadPropertyTypes(){ var cat = $('#category').val(); var $pt = $('#property_type'); $pt.html('<option value="">-- Select Type --</option>'); if(propertyTypes[cat]){ propertyTypes[cat].forEach(function(t){ $pt.append('<option value="'+t+'">'+t+'</option>'); }); } // Preselect existing var existing = '<?php echo addslashes($property['property_type'] ?? '') ?>'; if(existing) $pt.val(existing); } $('#category').on('change', loadPropertyTypes); loadPropertyTypes(); // City -> Sector $('#city').on('change', function(){ var city = $(this).val(); var $sector = $('#sector_id'); $sector.html('<option value="">-- Select Sector --</option>'); if(sectors[city]){ sectors[city].forEach(function(s){ var selected = (s.id == '<?php echo $property['sector_id'] ?? '' ?>') ? 'selected' : ''; $sector.append('<option value="'+s.id+'" '+selected+'>'+s.sector+'</option>'); }); } else { $sector.html('<option value="">No sectors available</option>'); } }); <?php if(isset($property['city'])): ?> $('#city').trigger('change'); <?php endif; ?> // Calculate price per sqft $('input[name="sale_price"], input[name="area_sqft"]').on('input', function(){ var price = parseFloat($('input[name="sale_price"]').val()) || 0; var area = parseFloat($('input[name="area_sqft"]').val()) || 0; if(price && area){ $('input[name="price_per_sqft"]').val((price/area).toFixed(2)); } else { $('input[name="price_per_sqft"]').val(''); } }); // Image preview $('#propertyImages').on('change', function(){ var files = this.files; $(this).siblings('.custom-file-label').text(files.length ? files.length+' files selected' : 'Choose images'); var preview = $('#imagePreview'); preview.html(''); if(files.length){ var html = '<div class="row">'; $.each(files, function(i, file){ var reader = new FileReader(); reader.onload = function(e){ html += '<div class="col-md-3 mb-2"><img src="'+e.target.result+'" style="width:100%;height:100px;object-fit:cover;" class="border"></div>'; preview.html(html+'</div>'); }; reader.readAsDataURL(file); }); } }); // Delete existing image (AJAX) $(document).on('click', '.delete-image-btn', function(){ if(!confirm('Delete this image?')) return; var btn = $(this); var path = btn.data('path'); $.ajax({ url: _base_url_ + 'classes/Master.php?f=delete_image', method: 'POST', data: { path: path }, dataType: 'json', success: function(resp){ if(resp.status == 'success'){ btn.closest('.border').remove(); } else { alert('Failed to delete image'); } }, error: function(){ alert('Error deleting image'); } }); }); // Form submit $('#property_form').submit(function(e){ e.preventDefault(); start_loader(); $('.err-msg').remove(); // Basic validation var city = $('#city').val(); var sector = $('#sector_id').val(); if(city && !sector){ showError('Please select a sector for the chosen city.'); end_loader(); return false; } var type = $('#listing_type_hidden').val(); if(type == 'For Rent' && !$('input[name="rent_amount"]').val()){ showError('Rent amount is required for rental listings.'); end_loader(); return false; } if(type == 'For Sale' && !$('input[name="sale_price"]').val()){ showError('Sale price is required for sale listings.'); end_loader(); return false; } var formData = new FormData(this); $.ajax({ url: _base_url_ + 'classes/Ads.php?f=save_property', method: 'POST', data: formData, dataType: 'json', cache: false, contentType: false, processData: false, error: err => { console.log(err); alert_toast('An error occurred', 'error'); end_loader(); }, success: function(resp){ if(resp.status == 'success'){ alert_toast('Property saved successfully', 'success'); setTimeout(function(){ location.href = './?p=properties'; }, 1000); } else if(resp.status == 'failed' && resp.msg){ showError(resp.msg); end_loader(); } else { alert_toast('An error occurred', 'error'); end_loader(); } } }); }); function showError(msg){ var el = $('<div>').addClass('alert alert-danger err-msg').text(msg); $('#property_form').prepend(el); $('html, body').animate({scrollTop:0}, 'fast'); } }); </script>
SAVE CHANGES
[ CANCEL ]
Name
Type
Actions
.. (Parent Directory)
📄 job.php
FILE
Ren
[EDIT]
DEL
📄 listing.php
FILE
Ren
[EDIT]
DEL
📄 myads.php
FILE
Ren
[EDIT]
DEL
📄 property.php
FILE
Ren
[EDIT]
DEL